Add a portid argument to __vxlan_fdb_notify(), vxlan_fdb_notify(), vxlan_fdb_destroy(), vxlan_fdb_dst_destroy(), vxlan_fdb_update() and its _existing() and _create() helpers, __vxlan_fdb_delete(), vxlan_flush() and vxlan_fdb_flush_match_remotes(), and use it as the netlink port ID of the resulting RTM_NEWNEIGH / RTM_DELNEIGH notifications. Where both portid and swdev_notify are passed, portid comes first: it is part of the message metadata, similarly to the message type, whereas swdev_notify merely toggles whether the switchdev notifiers are called. vxlan_fdb_add() and vxlan_fdb_delete() pass on the port ID of the requester. All other callers (snooping, device stop, changelink, VNI filtering, switchdev events, as well as vxlan_fdb_delete_bulk()) pass zero, as before. As rtnl_fdb_add() and rtnl_fdb_del() do not yet fill in the port ID in struct ndo_fdb_parms, all notifications are still sent with zero. No functional change intended. I considered passing struct ndo_fdb_parms down to vxlan_fdb_update() instead of the individual address and flags, but eventually decided against that. Only vxlan_fdb_add() has the structure at hand, whereas the other callers would have to construct a throwaway one just to pass the address and flags. This makes them longer, not shorter, and the callee would still need most of the VXLAN-specific arguments separately. Packing the VXLAN-specific parameters (remote IP, port, VNI, ifindex, ...) into a dedicated VXLAN-specific structure might benefit the VXLAN driver in a similar way to how it cleaned up the NDO interface. However this was left out for potential future patchset. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Reviewed-by: Nikolay Aleksandrov --- drivers/net/vxlan/vxlan_core.c | 89 +++++++++++++++-------------- drivers/net/vxlan/vxlan_private.h | 5 +- drivers/net/vxlan/vxlan_vnifilter.c | 6 +- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index c014307a693b..9df9f7a8cde7 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -265,7 +265,7 @@ static inline size_t vxlan_nlmsg_size(void) } static void __vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, - struct vxlan_rdst *rd, int type) + struct vxlan_rdst *rd, int type, u32 portid) { struct net *net = dev_net(vxlan->dev); struct sk_buff *skb; @@ -275,7 +275,7 @@ static void __vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, if (skb == NULL) goto errout; - err = vxlan_fdb_info(skb, vxlan, fdb, 0, 0, type, 0, rd); + err = vxlan_fdb_info(skb, vxlan, fdb, portid, 0, type, 0, rd); if (err < 0) { /* -EMSGSIZE implies BUG in vxlan_nlmsg_size() */ WARN_ON(err == -EMSGSIZE); @@ -329,8 +329,8 @@ static int vxlan_fdb_switchdev_call_notifiers(struct vxlan_dev *vxlan, } static int vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, - struct vxlan_rdst *rd, int type, bool swdev_notify, - struct netlink_ext_ack *extack) + struct vxlan_rdst *rd, int type, u32 portid, + bool swdev_notify, struct netlink_ext_ack *extack) { int err; @@ -349,7 +349,7 @@ static int vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb, } } - __vxlan_fdb_notify(vxlan, fdb, rd, type); + __vxlan_fdb_notify(vxlan, fdb, rd, type, portid); return 0; } @@ -364,7 +364,7 @@ static void vxlan_ip_miss(struct net_device *dev, union vxlan_addr *ipa) .remote_vni = cpu_to_be32(VXLAN_N_VID), }; - vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, true, NULL); + vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, 0, true, NULL); } static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN]) @@ -376,7 +376,7 @@ static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN]) memcpy(f.key.eth_addr, eth_addr, ETH_ALEN); - vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, true, NULL); + vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, 0, true, NULL); } /* Look up Ethernet address in forwarding table */ @@ -945,7 +945,7 @@ static void vxlan_fdb_free(struct rcu_head *head) } static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f, - bool do_notify, bool swdev_notify) + bool do_notify, u32 portid, bool swdev_notify) { struct vxlan_rdst *rd; @@ -955,11 +955,11 @@ static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f, if (do_notify) { if (rcu_access_pointer(f->nh)) vxlan_fdb_notify(vxlan, f, NULL, RTM_DELNEIGH, - swdev_notify, NULL); + portid, swdev_notify, NULL); else list_for_each_entry(rd, &f->remotes, list) vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH, - swdev_notify, NULL); + portid, swdev_notify, NULL); } hlist_del_init_rcu(&f->fdb_node); @@ -983,7 +983,7 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, __be16 port, __be32 vni, __u32 ifindex, __u16 ndm_flags, struct vxlan_fdb *f, u32 nhid, - bool swdev_notify, + u32 portid, bool swdev_notify, struct netlink_ext_ack *extack) { __u16 fdb_flags = (ndm_flags & ~NTF_USE); @@ -1057,7 +1057,7 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan, WRITE_ONCE(f->updated, jiffies); err = vxlan_fdb_notify(vxlan, f, rd, RTM_NEWNEIGH, - swdev_notify, extack); + portid, swdev_notify, extack); if (err) goto err_notify; } @@ -1081,7 +1081,7 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan, __u16 state, __u16 flags, __be16 port, __be32 src_vni, __be32 vni, __u32 ifindex, __u16 ndm_flags, u32 nhid, - bool swdev_notify, + u32 portid, bool swdev_notify, struct netlink_ext_ack *extack) { __u16 fdb_flags = (ndm_flags & ~NTF_USE); @@ -1100,14 +1100,14 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan, return rc; rc = vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH, - swdev_notify, extack); + portid, swdev_notify, extack); if (rc) goto err_notify; return 0; err_notify: - vxlan_fdb_destroy(vxlan, f, false, false); + vxlan_fdb_destroy(vxlan, f, false, 0, false); return rc; } @@ -1117,7 +1117,7 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan, __u16 state, __u16 flags, __be16 port, __be32 src_vni, __be32 vni, __u32 ifindex, __u16 ndm_flags, u32 nhid, - bool swdev_notify, + u32 portid, bool swdev_notify, struct netlink_ext_ack *extack) { struct vxlan_fdb *f; @@ -1132,23 +1132,26 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan, return vxlan_fdb_update_existing(vxlan, ip, state, flags, port, vni, ifindex, ndm_flags, f, - nhid, swdev_notify, extack); + nhid, portid, swdev_notify, + extack); } else { if (!(flags & NLM_F_CREATE)) return -ENOENT; return vxlan_fdb_update_create(vxlan, mac, ip, state, flags, port, src_vni, vni, ifindex, - ndm_flags, nhid, swdev_notify, - extack); + ndm_flags, nhid, portid, + swdev_notify, extack); } } static void vxlan_fdb_dst_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f, - struct vxlan_rdst *rd, bool swdev_notify) + struct vxlan_rdst *rd, u32 portid, + bool swdev_notify) { list_del_rcu(&rd->list); - vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH, swdev_notify, NULL); + vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH, portid, swdev_notify, + NULL); call_rcu(&rd->rcu, vxlan_dst_free); } @@ -1276,7 +1279,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], parms->flags, port, src_vni, vni, ifindex, ndm->ndm_flags | NTF_VXLAN_ADDED_BY_USER, - nhid, true, extack); + nhid, parms->portid, true, extack); spin_unlock_bh(&vxlan->hash_lock); if (!err) @@ -1288,7 +1291,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], int __vxlan_fdb_delete(struct vxlan_dev *vxlan, const unsigned char *addr, union vxlan_addr ip, __be16 port, __be32 src_vni, __be32 vni, - u32 ifindex, bool swdev_notify) + u32 ifindex, u32 portid, bool swdev_notify) { struct vxlan_rdst *rd = NULL; struct vxlan_fdb *f; @@ -1308,11 +1311,11 @@ int __vxlan_fdb_delete(struct vxlan_dev *vxlan, * otherwise destroy the fdb entry */ if (rd && !list_is_singular(&f->remotes)) { - vxlan_fdb_dst_destroy(vxlan, f, rd, swdev_notify); + vxlan_fdb_dst_destroy(vxlan, f, rd, portid, swdev_notify); goto out; } - vxlan_fdb_destroy(vxlan, f, true, swdev_notify); + vxlan_fdb_destroy(vxlan, f, true, portid, swdev_notify); out: return 0; @@ -1337,7 +1340,7 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], spin_lock_bh(&vxlan->hash_lock); err = __vxlan_fdb_delete(vxlan, parms->addr, ip, port, src_vni, vni, - ifindex, true); + ifindex, parms->portid, true); spin_unlock_bh(&vxlan->hash_lock); if (!err) @@ -1480,7 +1483,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, src_mac, &rdst->remote_ip.sa, &src_ip->sa); rdst->remote_ip = *src_ip; - vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, true, NULL); + vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, 0, true, NULL); } else { /* learned new entry */ spin_lock(&vxlan->hash_lock); @@ -1493,7 +1496,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, cfg->dst_port, vni, cfg->vni, - ifindex, NTF_SELF, 0, true, NULL); + ifindex, NTF_SELF, 0, 0, true, NULL); spin_unlock(&vxlan->hash_lock); } @@ -2943,7 +2946,7 @@ static void vxlan_cleanup(struct timer_list *t) netdev_dbg(vxlan->dev, "garbage collect %pM\n", f->key.eth_addr); f->state = NUD_STALE; - vxlan_fdb_destroy(vxlan, f, true, true); + vxlan_fdb_destroy(vxlan, f, true, 0, true); } spin_unlock(&vxlan->hash_lock); } else if (time_before(timeout, next_timer)) { @@ -3138,7 +3141,7 @@ vxlan_fdb_flush_remote_matches(const struct vxlan_fdb_flush_desc *desc, static void vxlan_fdb_flush_match_remotes(struct vxlan_fdb *f, struct vxlan_dev *vxlan, const struct vxlan_fdb_flush_desc *desc, - bool *p_destroy_fdb) + u32 portid, bool *p_destroy_fdb) { struct vxlan_rdst *rd, *tmp; @@ -3151,13 +3154,13 @@ vxlan_fdb_flush_match_remotes(struct vxlan_fdb *f, struct vxlan_dev *vxlan, return; } - vxlan_fdb_dst_destroy(vxlan, f, rd, true); + vxlan_fdb_dst_destroy(vxlan, f, rd, portid, true); } } /* Purge the forwarding table */ static void vxlan_flush(struct vxlan_dev *vxlan, - const struct vxlan_fdb_flush_desc *desc) + const struct vxlan_fdb_flush_desc *desc, u32 portid) { bool match_remotes = vxlan_fdb_flush_should_match_remotes(desc); struct vxlan_fdb *f; @@ -3174,14 +3177,14 @@ static void vxlan_flush(struct vxlan_dev *vxlan, if (match_remotes) { bool destroy_fdb = false; - vxlan_fdb_flush_match_remotes(f, vxlan, desc, + vxlan_fdb_flush_match_remotes(f, vxlan, desc, portid, &destroy_fdb); if (!destroy_fdb) goto unlock; } - vxlan_fdb_destroy(vxlan, f, true, true); + vxlan_fdb_destroy(vxlan, f, true, portid, true); unlock: spin_unlock_bh(&vxlan->hash_lock); } @@ -3263,7 +3266,7 @@ static int vxlan_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev, desc.dst_ip = ip; } - vxlan_flush(vxlan, &desc); + vxlan_flush(vxlan, &desc, 0); return 0; } @@ -3283,7 +3286,7 @@ static int vxlan_stop(struct net_device *dev) timer_delete_sync(&vxlan->age_timer); - vxlan_flush(vxlan, &desc); + vxlan_flush(vxlan, &desc, 0); vxlan_sock_release(vxlan); return 0; @@ -4143,7 +4146,7 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev, cfg->vni, cfg->vni, cfg->remote_ifindex, - NTF_SELF, 0, true, extack); + NTF_SELF, 0, 0, true, extack); spin_unlock_bh(&vxlan->hash_lock); if (err) goto unlink; @@ -4606,7 +4609,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], cfg->dst_port, conf.vni, conf.vni, conf.remote_ifindex, - NTF_SELF, 0, true, extack); + NTF_SELF, 0, 0, true, extack); if (err) { spin_unlock_bh(&vxlan->hash_lock); if (lowerdev_changed) @@ -4623,7 +4626,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], cfg->vni, cfg->vni, cfg->remote_ifindex, - true); + 0, true); spin_unlock_bh(&vxlan->hash_lock); /* If vni filtering device, also update default fdb entries of @@ -4687,7 +4690,7 @@ static void vxlan_dellink(struct net_device *dev, struct list_head *head) struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_fdb_flush_desc desc = {}; - vxlan_flush(vxlan, &desc); + vxlan_flush(vxlan, &desc, 0); list_del(&vxlan->next); unregister_netdevice_queue(dev, head); @@ -4960,7 +4963,7 @@ vxlan_fdb_external_learn_add(struct net_device *dev, fdb_info->remote_vni, fdb_info->remote_ifindex, NTF_USE | NTF_SELF | NTF_EXT_LEARNED, - 0, false, extack); + 0, 0, false, extack); spin_unlock_bh(&vxlan->hash_lock); return err; @@ -4986,7 +4989,7 @@ vxlan_fdb_external_learn_del(struct net_device *dev, fdb_info->vni, fdb_info->remote_vni, fdb_info->remote_ifindex, - false); + 0, false); spin_unlock_bh(&vxlan->hash_lock); @@ -5044,7 +5047,7 @@ static void vxlan_fdb_nh_flush(struct nexthop *nh) WARN_ON(!vxlan); spin_lock_bh(&vxlan->hash_lock); if (!hlist_unhashed(&fdb->fdb_node)) - vxlan_fdb_destroy(vxlan, fdb, false, false); + vxlan_fdb_destroy(vxlan, fdb, false, 0, false); spin_unlock_bh(&vxlan->hash_lock); } rcu_read_unlock(); diff --git a/drivers/net/vxlan/vxlan_private.h b/drivers/net/vxlan/vxlan_private.h index f0ee85f83732..632e1880c0b9 100644 --- a/drivers/net/vxlan/vxlan_private.h +++ b/drivers/net/vxlan/vxlan_private.h @@ -196,13 +196,14 @@ int vxlan_fdb_create(struct vxlan_dev *vxlan, int __vxlan_fdb_delete(struct vxlan_dev *vxlan, const unsigned char *addr, union vxlan_addr ip, __be16 port, __be32 src_vni, __be32 vni, - u32 ifindex, bool swdev_notify); + u32 ifindex, u32 portid, bool swdev_notify); int vxlan_fdb_update(struct vxlan_dev *vxlan, const u8 *mac, union vxlan_addr *ip, __u16 state, __u16 flags, __be16 port, __be32 src_vni, __be32 vni, __u32 ifindex, __u16 ndm_flags, u32 nhid, - bool swdev_notify, struct netlink_ext_ack *extack); + u32 portid, bool swdev_notify, + struct netlink_ext_ack *extack); void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, const struct vxlan_config *cfg, __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc); diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index c5cc6cd08545..927b63db3b5b 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -550,7 +550,7 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, vni, vni, new_ifindex, - NTF_SELF, 0, true, extack); + NTF_SELF, 0, 0, true, extack); if (err && extack) { spin_unlock_bh(&vxlan->hash_lock); return err; @@ -563,7 +563,7 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, cfg->dst_port, vni, vni, old_ifindex, - true); + 0, true); } spin_unlock_bh(&vxlan->hash_lock); @@ -727,7 +727,7 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, cfg->dst_port, vninode->vni, vninode->vni, cfg->remote_ifindex, - true); + 0, true); spin_unlock_bh(&vxlan->hash_lock); } -- 2.56.1