vxlan: convert configuration to RCU and enable lockless dumps
v3 cover vxlan: convert configuration to RCU and enable lockless dumps
This patch series converts struct vxlan_config to RCU protection, eliminates redundant destination fields, and enables lockless RTNL-free link dumping in vxlan_fill_info().
Changes in v3:
- Folded configuration conversion patches into a single patch to maintain clean bisectability and avoid intermediate mutable state.
- In vxlan_changelink(), pass lowerdev to vxlan_config_apply() to prevent truncating dev->needed_headroom and dev->needed_tailroom when lowerdev does not change.
- In vxlan_changelink(), ensure default FDB updates for VNI filters trigger when remote_ifindex changes, even if remote_ip is unchanged.
- Pass old and new ifindex to vxlan_vnilist_update_group() and vxlan_update_default_fdb_entry() so newly added FDB entries point to the new interface and deletions target the old interface.
- Cleaned up redundant NULL checks and unreachable error paths.
Eric Dumazet (6):
vxlan: vnifilter: use list_for_each_entry_rcu() in
vxlan_vnifilter_dump_dev()
vxlan: pass vxlan_config pointer to helper functions
vxlan: move VXLAN_F_MDB to struct vxlan_dev flags
vxlan: convert configuration to RCU protection
vxlan: remove default_dst and use vxlan_config and lowerdev
vxlan: no longer rely on RTNL in vxlan_fill_info()
.../mellanox/mlx5/core/en/tc_tun_vxlan.c | 11 +- .../mellanox/mlxsw/spectrum_nve_vxlan.c | 14 +- .../mellanox/mlxsw/spectrum_switchdev.c | 57 +- drivers/net/vxlan/vxlan_core.c | 717 +++++++++++------- drivers/net/vxlan/vxlan_mdb.c | 45 +- drivers/net/vxlan/vxlan_multicast.c | 76 +- drivers/net/vxlan/vxlan_private.h | 19 +- drivers/net/vxlan/vxlan_vnifilter.c | 96 ++- include/net/vxlan.h | 12 +- 9 files changed, 638 insertions(+), 409 deletions(-)
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog
PATCH v3 1/6 vxlan: vnifilter: use list_for_each_entry_rcu() in vxlan_vnifilter_dump_dev()
RTM_GETTUNNEL dumps currently run under RTNL lock, but vxlan_vnifilter_dump() also acquires rcu_read_lock().
1) Currently vxlan_vnifilter_dump_dev() traverses vg->vni_list using list_for_each_entry_safe(). Even though RTNL is held today, writers modify vg->vni_list with list_add_rcu() and list_del_rcu(). Switch to list_for_each_entry_rcu() for proper RCU traversal and as preparation for future lockless dump support.
2) During a paginated dump, RTNL is released between dump skbs. If vxlan_vnifilter_dump_dev() returns early because VXLAN_F_VNIFILTER is not set or vg has no VNIs, cb->args[1] was not cleared. This leaked a non-zero VNI offset to subsequent devices, silently skipping their first N VNIs.
Furthermore, if devices are added or removed between dump calls, ordinal device indexes can shift. Track the current device ifindex in cb->args[2] and reset cb->args[1] if the device changes.
--- drivers/net/vxlan/vxlan_vnifilter.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/net/vxlan/vxlan_vnifilter.c +18 -5
@@ -333,22 +333,34 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev,struct sk_buff *skb, struct netlink_callback *cb) { - struct vxlan_vni_node *tmp, *v, *vbegin = NULL, *vend = NULL; + struct vxlan_vni_node *v, *vbegin = NULL, *vend = NULL;struct vxlan_dev *vxlan =netdev_priv (dev);struct tunnel_msg *new_tmsg, *tmsg; -int idx =0 , s_idx = cb->args[1 ];struct vxlan_vni_group *vg;struct nlmsghdr *nlh; +int idx =0 , s_idx;bool dump_stats;int err =0 ; -if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +if (cb->args[2 ] != dev->ifindex) { + cb->args[1 ] =0 ; + cb->args[2 ] = dev->ifindex; + } + s_idx = cb->args[1 ]; + +if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) { + cb->args[1 ] =0 ; + cb->args[2 ] =0 ;return -EINVAL ; + }/* RCU needed because of the vni locking rules (rcu || rtnl) */ vg =rcu_dereference (vxlan->vnigrp); -if (!vg || !vg->num_vnis) +if (!vg || !vg->num_vnis) { + cb->args[1 ] =0 ; + cb->args[2 ] =0 ;return 0 ; + } tmsg =nlmsg_data (cb->nlh); dump_stats = !!(tmsg->flags &TUNNEL_MSG_FLAG_STATS );
@@ -362,7 +374,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, new_tmsg->family =PF_BRIDGE ; new_tmsg->ifindex = dev->ifindex; -list_for_each_entry_safe (v, tmp, &vg->vni_list, vlist) { +list_for_each_entry_rcu (v, &vg->vni_list, vlist) {if (idx < s_idx) { idx++;continue ;
@@ -394,6 +406,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, } cb->args[1 ] = err ? idx :0 ; + cb->args[2 ] = err ? dev->ifindex :0 ;nlmsg_end (skb, nlh);
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog
PATCH v3 2/6 vxlan: pass vxlan_config pointer to helper functions
In reply to Eric DumazetIn preparation for converting vxlan->cfg to an RCU-protected pointer, refactor internal helper functions in the RX, TX, MDB, and VNIFILTER paths to accept a pointer to struct vxlan_config (or pass flags/ saddr_family where appropriate) rather than directly accessing vxlan->cfg.
No functional changes.
--- drivers/net/vxlan/vxlan_core.c | 343 +++++++++++++++------------- drivers/net/vxlan/vxlan_mdb.c | 21 +- drivers/net/vxlan/vxlan_private.h | 8 +- drivers/net/vxlan/vxlan_vnifilter.c | 5 +- 4 files changed, 206 insertions(+), 171 deletions(-)
drivers/net/vxlan/vxlan_core.c +184 -159
@@ -377,14 +377,15 @@ static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN])/* Look up Ethernet address in forwarding table */ static struct vxlan_fdb *vxlan_find_mac_rcu (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,const u8 *mac,__be32 vni) {struct vxlan_fdb_key key;memset (&key,0 ,sizeof (key));memcpy (key.eth_addr, mac,sizeof (key.eth_addr)); -if (!(vxlan->cfg.flags &VXLAN_F_COLLECT_METADATA )) - key.vni = vxlan->default_dst.remote_vni; +if (!(cfg->flags &VXLAN_F_COLLECT_METADATA )) + key.vni = cfg->vni;else key.vni = vni;
@@ -393,11 +394,12 @@ static struct vxlan_fdb *vxlan_find_mac_rcu(struct vxlan_dev *vxlan, }static struct vxlan_fdb *vxlan_find_mac_tx (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,const u8 *mac,__be32 vni) {struct vxlan_fdb *f; - f =vxlan_find_mac_rcu (vxlan, mac, vni); + f =vxlan_find_mac_rcu (vxlan, cfg, mac, vni);if (f) {unsigned long now = jiffies;
@@ -416,7 +418,7 @@ static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan,lockdep_assert_held_once (&vxlan->hash_lock);rcu_read_lock (); - f =vxlan_find_mac_rcu (vxlan, mac, vni); + f =vxlan_find_mac_rcu (vxlan, &vxlan->cfg, mac, vni);rcu_read_unlock ();return f;
@@ -457,7 +459,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,rcu_read_lock (); - f =vxlan_find_mac_rcu (vxlan, eth_addr, vni); + f =vxlan_find_mac_rcu (vxlan, &vxlan->cfg, eth_addr, vni);if (f) rdst =first_remote_rcu (f);if (!rdst) {
@@ -1416,7 +1418,7 @@ static int vxlan_fdb_get(struct sk_buff *skb,rcu_read_lock (); - f =vxlan_find_mac_rcu (vxlan, addr, vni); + f =vxlan_find_mac_rcu (vxlan, &vxlan->cfg, addr, vni);if (!f) {NL_SET_ERR_MSG (extack,"Fdb entry not found" ); err = -ENOENT ;
@@ -1434,6 +1436,7 @@ static int vxlan_fdb_get(struct sk_buff *skb,* and Tunnel endpoint. */ static enum skb_drop_reason vxlan_snoop (struct net_device *dev, +const struct vxlan_config *cfg,union vxlan_addr *src_ip,const u8 *src_mac,u32 src_ifindex,__be32 vni)
@@ -1452,7 +1455,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, ifindex = src_ifindex;#endif - f =vxlan_find_mac_rcu (vxlan, src_mac, vni); + f =vxlan_find_mac_rcu (vxlan, cfg, src_mac, vni);if (likely (f)) {struct vxlan_rdst *rdst =first_remote_rcu (f);unsigned long now = jiffies;
@@ -1488,9 +1491,9 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev,vxlan_fdb_update (vxlan, src_mac, src_ip,NUD_REACHABLE ,NLM_F_EXCL |NLM_F_CREATE , - vxlan->cfg.dst_port, + cfg->dst_port, vni, - vxlan->default_dst.remote_vni, + cfg->vni, ifindex,NTF_SELF ,0 , true,NULL );spin_unlock (&vxlan->hash_lock); }
@@ -1598,6 +1601,7 @@ static void vxlan_parse_gbp_hdr(struct sk_buff *skb, u32 vxflags, }static enum skb_drop_reason vxlan_set_mac (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,struct vxlan_sock *vs,struct sk_buff *skb,__be32 vni) {
@@ -1623,10 +1627,10 @@ static enum skb_drop_reason vxlan_set_mac(struct vxlan_dev *vxlan,#endif } -if (!(vxlan->cfg.flags &VXLAN_F_LEARN )) +if (!(cfg->flags &VXLAN_F_LEARN ))return SKB_NOT_DROPPED_YET ; -return vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, +return vxlan_snoop (skb->dev, cfg, &saddr,eth_hdr (skb)->h_source, ifindex, vni); }
@@ -1657,18 +1661,21 @@ static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,static int vxlan_rcv (struct sock *sk,struct sk_buff *skb) {struct vxlan_vni_node *vninode =NULL ; -const struct vxlanhdr *vh; -struct vxlan_dev *vxlan; -struct vxlan_sock *vs; -struct vxlan_metadata _md; -struct vxlan_metadata *md = &_md;__be16 protocol =htons (ETH_P_TEB ); +const struct vxlan_config *cfg;enum skb_drop_reason reason; +const struct vxlanhdr *vh; +struct vxlan_metadata *md; +struct vxlan_metadata _md; +struct vxlan_dev *vxlan;bool raw_proto = false; -void *oiph; +struct vxlan_sock *vs;__be32 vni =0 ; +void *oiph;int nh; + md = &_md; +/* Need UDP and VXLAN header to be present */ reason =pskb_may_pull_reason (skb,VXLAN_HLEN );if (reason)
@@ -1696,8 +1703,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) goto drop; } -if (vh->vx_flags & vxlan->cfg.reserved_bits.vx_flags || - vh->vx_vni & vxlan->cfg.reserved_bits.vx_vni) { + cfg = &vxlan->cfg; +if (vh->vx_flags & cfg->reserved_bits.vx_flags || + vh->vx_vni & cfg->reserved_bits.vx_vni) {/* If the header uses bits besides those enabled by the * netdevice configuration, treat this as a malformed packet. * This behavior diverges from VXLAN RFC (RFC7348) which
@@ -1709,12 +1717,12 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) reason =SKB_DROP_REASON_VXLAN_INVALID_HDR ;DEV_STATS_INC (vxlan->dev, rx_frame_errors);DEV_STATS_INC (vxlan->dev, rx_errors); -vxlan_vnifilter_count (vxlan, vni, vninode, +vxlan_vnifilter_count (vxlan, cfg, vni, vninode,VXLAN_VNI_STATS_RX_ERRORS ,0 ); goto drop; } -if (vxlan->cfg.flags &VXLAN_F_GPE ) { +if (cfg->flags &VXLAN_F_GPE ) {if (!vxlan_parse_gpe_proto (vh, &protocol)) goto drop; raw_proto = true;
@@ -1726,8 +1734,8 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) goto drop; } -if (vxlan->cfg.flags &VXLAN_F_REMCSUM_RX ) { - reason =vxlan_remcsum (skb, vxlan->cfg.flags); +if (cfg->flags &VXLAN_F_REMCSUM_RX ) { + reason =vxlan_remcsum (skb, cfg->flags);if (unlikely (reason)) goto drop; }
@@ -1752,14 +1760,14 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)memset (md,0 ,sizeof (*md)); } -if (vxlan->cfg.flags &VXLAN_F_GBP ) -vxlan_parse_gbp_hdr (skb, vxlan->cfg.flags, md); +if (cfg->flags &VXLAN_F_GBP ) +vxlan_parse_gbp_hdr (skb, cfg->flags, md);/* Note that GBP and GPE can never be active together. This is * ensured in vxlan_dev_configure. */ if (!raw_proto) { - reason =vxlan_set_mac (vxlan, vs, skb, vni); + reason =vxlan_set_mac (vxlan, cfg, vs, skb, vni);if (reason) goto drop; }else {
@@ -1780,7 +1788,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)if (reason) {DEV_STATS_INC (vxlan->dev, rx_length_errors);DEV_STATS_INC (vxlan->dev, rx_errors); -vxlan_vnifilter_count (vxlan, vni, vninode, +vxlan_vnifilter_count (vxlan, cfg, vni, vninode,VXLAN_VNI_STATS_RX_ERRORS ,0 ); goto drop; }
@@ -1792,7 +1800,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) reason =SKB_DROP_REASON_IP_TUNNEL_ECN ;DEV_STATS_INC (vxlan->dev, rx_frame_errors);DEV_STATS_INC (vxlan->dev, rx_errors); -vxlan_vnifilter_count (vxlan, vni, vninode, +vxlan_vnifilter_count (vxlan, cfg, vni, vninode,VXLAN_VNI_STATS_RX_ERRORS ,0 ); goto drop; }
@@ -1802,14 +1810,15 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)if (unlikely (!(vxlan->dev->flags &IFF_UP ))) {rcu_read_unlock ();dev_dstats_rx_dropped (vxlan->dev); -vxlan_vnifilter_count (vxlan, vni, vninode, +vxlan_vnifilter_count (vxlan, cfg, vni, vninode,VXLAN_VNI_STATS_RX_DROPS ,0 ); reason =SKB_DROP_REASON_DEV_READY ; goto drop; }dev_dstats_rx_add (vxlan->dev, skb->len); -vxlan_vnifilter_count (vxlan, vni, vninode,VXLAN_VNI_STATS_RX , skb->len); +vxlan_vnifilter_count (vxlan, cfg, vni, vninode,VXLAN_VNI_STATS_RX , + skb->len);gro_cells_receive (&vxlan->gro_cells, skb);rcu_read_unlock ();
@@ -1850,7 +1859,7 @@ static int vxlan_err_lookup(struct sock *sk, struct sk_buff *skb)return 0 ; } -static int arp_reduce (struct net_device *dev,struct sk_buff *skb,__be32 vni) +static int arp_reduce (struct net_device *dev,struct sk_buff *skb,__be32 vni,u32 flags) {struct neigh_table *tbl =arp_table (dev_net (dev));struct vxlan_dev *vxlan =netdev_priv (dev);
@@ -1864,7 +1873,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (!pskb_network_may_pull (skb,arp_hdr_len (dev))) {dev_dstats_tx_dropped (dev); -vxlan_vnifilter_count (vxlan, vni,NULL , +vxlan_vnifilter_count (vxlan, &vxlan->cfg, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 ); goto out; }
@@ -1905,7 +1914,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)neigh_ha_snapshot (ha, n, n->dev);rcu_read_lock (); - f =vxlan_find_mac_tx (vxlan, ha, vni); + f =vxlan_find_mac_tx (vxlan, &vxlan->cfg, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -1931,11 +1940,11 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (netif_rx (reply) ==NET_RX_DROP ) {dev_dstats_rx_dropped (dev); -vxlan_vnifilter_count (vxlan, vni,NULL , +vxlan_vnifilter_count (vxlan, &vxlan->cfg, vni,NULL ,VXLAN_VNI_STATS_RX_DROPS ,0 ); } - }else if (vxlan->cfg.flags &VXLAN_F_L3MISS ) { + }else if (flags &VXLAN_F_L3MISS ) {union vxlan_addr ipa = { .sin.sin_addr.s_addr = tip, .sin.sin_family = AF_INET,
@@ -2043,7 +2052,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request,return reply; } -static int neigh_reduce (struct net_device *dev,struct sk_buff *skb,__be32 vni) +static int neigh_reduce (struct net_device *dev,struct sk_buff *skb,__be32 vni,u32 flags) {struct vxlan_dev *vxlan =netdev_priv (dev);const struct in6_addr *daddr;
@@ -2077,7 +2086,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) }neigh_ha_snapshot (ha, n, n->dev); - f =vxlan_find_mac_tx (vxlan, ha, vni); + f =vxlan_find_mac_tx (vxlan, &vxlan->cfg, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -2096,10 +2105,10 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (netif_rx (reply) ==NET_RX_DROP ) {dev_dstats_rx_dropped (dev); -vxlan_vnifilter_count (vxlan, vni,NULL , +vxlan_vnifilter_count (vxlan, &vxlan->cfg, vni,NULL ,VXLAN_VNI_STATS_RX_DROPS ,0 ); } - }else if (vxlan->cfg.flags &VXLAN_F_L3MISS ) { + }else if (flags &VXLAN_F_L3MISS ) {union vxlan_addr ipa = { .sin6.sin6_addr = msg->target, .sin6.sin6_family = AF_INET6,
@@ -2115,9 +2124,9 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) }#endif -static bool route_shortcircuit (struct net_device *dev,struct sk_buff *skb) +static bool route_shortcircuit (struct net_device *dev,struct sk_buff *skb, +const struct vxlan_config *cfg) { -struct vxlan_dev *vxlan =netdev_priv (dev);struct neigh_table *tbl;struct neighbour *n;
@@ -2136,7 +2145,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) tbl =arp_table (dev_net (dev)); pip =ip_hdr (skb); n =neigh_lookup (tbl, &pip->daddr, dev); -if (!n && (vxlan->cfg.flags &VXLAN_F_L3MISS )) { +if (!n && (cfg->flags &VXLAN_F_L3MISS )) {union vxlan_addr ipa = { .sin.sin_addr.s_addr = pip->daddr, .sin.sin_family =AF_INET ,
@@ -2164,7 +2173,7 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) tbl =nd_table (dev_net (dev)); pip6 =ipv6_hdr (skb); n =neigh_lookup (tbl, &pip6->daddr, dev); -if (!n && (vxlan->cfg.flags &VXLAN_F_L3MISS )) { +if (!n && (cfg->flags &VXLAN_F_L3MISS )) {union vxlan_addr ipa = { .sin6.sin6_addr = pip6->daddr, .sin6.sin6_family =AF_INET6 ,
@@ -2282,20 +2291,21 @@ static int vxlan_build_skb(struct sk_buff *skb, struct dst_entry *dst,/* Bypass encapsulation if the destination is local */ static void vxlan_encap_bypass (struct sk_buff *skb,struct vxlan_dev *src_vxlan, -struct vxlan_dev *dst_vxlan,__be32 vni, -bool snoop) +struct vxlan_dev *dst_vxlan, +const struct vxlan_config *src_cfg, +__be32 vni,bool snoop) { +const struct vxlan_config *dst_cfg = &dst_vxlan->cfg;union vxlan_addr loopback; -union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip;unsigned int len = skb->len; -struct net_device *dev; +struct net_device *dev = dst_vxlan->dev; skb->pkt_type =PACKET_HOST ; skb->encapsulation =0 ; - skb->dev = dst_vxlan->dev; + skb->dev = dev;__skb_pull (skb,skb_network_offset (skb)); -if (remote_ip->sa.sa_family ==AF_INET ) { +if (dst_vxlan->default_dst.remote_ip.sa.sa_family ==AF_INET ) { loopback.sin.sin_addr.s_addr =htonl (INADDR_LOOPBACK ); loopback.sa.sa_family =AF_INET ;#if IS_ENABLED (CONFIG_IPV6 )
@@ -2306,26 +2316,25 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, }rcu_read_lock (); - dev = skb->dev;if (unlikely (!(dev->flags &IFF_UP ))) {kfree_skb_reason (skb,SKB_DROP_REASON_DEV_READY ); goto drop; } -if ((dst_vxlan->cfg.flags &VXLAN_F_LEARN ) && snoop) -vxlan_snoop (dev, &loopback,eth_hdr (skb)->h_source,0 , vni); +if ((dst_cfg->flags &VXLAN_F_LEARN ) && snoop) +vxlan_snoop (dev, dst_cfg, &loopback,eth_hdr (skb)->h_source,0 , vni);dev_dstats_tx_add (src_vxlan->dev, len); -vxlan_vnifilter_count (src_vxlan, vni,NULL ,VXLAN_VNI_STATS_TX , len); +vxlan_vnifilter_count (src_vxlan, src_cfg, vni,NULL ,VXLAN_VNI_STATS_TX , len);if (__netif_rx (skb) ==NET_RX_SUCCESS ) {dev_dstats_rx_add (dst_vxlan->dev, len); -vxlan_vnifilter_count (dst_vxlan, vni,NULL ,VXLAN_VNI_STATS_RX , +vxlan_vnifilter_count (dst_vxlan, dst_cfg, vni,NULL ,VXLAN_VNI_STATS_RX , len); }else { drop:dev_dstats_rx_dropped (dev); -vxlan_vnifilter_count (dst_vxlan, vni,NULL , +vxlan_vnifilter_count (dst_vxlan, dst_cfg, vni,NULL ,VXLAN_VNI_STATS_RX_DROPS ,0 ); }rcu_read_unlock ();
@@ -2333,6 +2342,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, struct vxlan_dev *vxlan, + const struct vxlan_config *cfg, int addr_family, __be16 dst_port, int dst_ifindex, __be32 vni, struct dst_entry *dst,
@@ -2348,22 +2358,22 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev,/* Bypass encapsulation if the destination is local */ if (rt_flags &RTCF_LOCAL && !(rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST )) && - vxlan->cfg.flags &VXLAN_F_LOCALBYPASS ) { + cfg->flags &VXLAN_F_LOCALBYPASS ) {struct vxlan_dev *dst_vxlan;dst_release (dst); dst_vxlan =vxlan_find_vni (vxlan->net, dst_ifindex, vni, addr_family, dst_port, - vxlan->cfg.flags); + cfg->flags);if (!dst_vxlan) {DEV_STATS_INC (dev, tx_errors); -vxlan_vnifilter_count (vxlan, vni,NULL , +vxlan_vnifilter_count (vxlan, cfg, vni,NULL ,VXLAN_VNI_STATS_TX_ERRORS ,0 );kfree_skb_reason (skb,SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND );return -ENOENT ; } -vxlan_encap_bypass (skb, vxlan, dst_vxlan, vni, true); +vxlan_encap_bypass (skb, vxlan, dst_vxlan, cfg, vni, true);return 1 ; }
@@ -2371,30 +2381,35 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, }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) { +unsigned int pkt_len = skb->len; +struct vxlan_metadata _md = {}; +__be16 src_port =0 , dst_port; +struct dst_entry *ndst =NULL ; +enum skb_drop_reason reason;struct dst_cache *dst_cache; +const struct iphdr *old_iph;struct ip_tunnel_info *info;struct ip_tunnel_key *pkey; +struct vxlan_metadata *md;struct ip_tunnel_key key; -struct vxlan_dev *vxlan =netdev_priv (dev); -const struct iphdr *old_iph; -struct vxlan_metadata _md = {}; -struct vxlan_metadata *md = &_md; -unsigned int pkt_len = skb->len; -__be16 src_port =0 , dst_port; -struct dst_entry *ndst =NULL ; +struct vxlan_dev *vxlan; +u32 flags = cfg->flags; +bool udp_sum = false; +bool no_eth_encap;int addr_family; +bool use_cache; +__be32 vni =0 ;__u8 tos, ttl;int ifindex;int err =0 ; -u32 flags = vxlan->cfg.flags; -bool use_cache; -bool udp_sum = false; -bool xnet = !net_eq (vxlan->net,dev_net (vxlan->dev)); -enum skb_drop_reason reason; -bool no_eth_encap; -__be32 vni =0 ; +bool xnet; + + vxlan =netdev_priv (dev); + xnet = !net_eq (vxlan->net,dev_net (vxlan->dev)); + md = &_md; no_eth_encap = flags &VXLAN_F_GPE && skb->protocol !=htons (ETH_P_TEB ); reason =skb_vlan_inet_prepare (skb, no_eth_encap);
@@ -2414,23 +2429,23 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (vxlan_addr_any (&rdst->remote_ip)) {if (did_rsc) {/* short-circuited back to local bridge */ -vxlan_encap_bypass (skb, vxlan, vxlan, +vxlan_encap_bypass (skb, vxlan, vxlan, cfg, default_vni, true);return ; } goto drop; } - addr_family = vxlan->cfg.saddr.sa.sa_family; - dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; + addr_family = cfg->saddr.sa.sa_family; + dst_port = rdst->remote_port ? rdst->remote_port : cfg->dst_port; vni = (rdst->remote_vni) ? : default_vni; ifindex = rdst->remote_ifindex;if (addr_family ==AF_INET ) { - key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr; + key.u.ipv4.src = cfg->saddr.sin.sin_addr.s_addr; key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr; }else { - key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr; + key.u.ipv6.src = cfg->saddr.sin6.sin6_addr; key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr; }
@@ -2439,11 +2454,11 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (flags &VXLAN_F_TTL_INHERIT ) { ttl =ip_tunnel_get_ttl (old_iph, skb); }else { - ttl = vxlan->cfg.ttl; + ttl = cfg->ttl;if (!ttl &&vxlan_addr_multicast (&rdst->remote_ip)) ttl =1 ; } - tos = vxlan->cfg.tos; + tos = cfg->tos;if (tos ==1 ) tos =ip_tunnel_get_dsfield (old_iph, skb);if (tos && !info)
@@ -2454,9 +2469,9 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,else udp_sum = !(flags &VXLAN_F_UDP_ZERO_CSUM6_TX );#if IS_ENABLED (CONFIG_IPV6 ) -switch (vxlan->cfg.label_policy) { +switch (cfg->label_policy) {case VXLAN_LABEL_FIXED : - key.label = vxlan->cfg.label; + key.label = cfg->label;break ;case VXLAN_LABEL_INHERIT : key.label =ip_tunnel_get_flowlabel (old_iph, skb);
@@ -2474,7 +2489,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, } pkey = &info->key; addr_family =ip_tunnel_info_af (info); - dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; + dst_port = info->key.tp_dst ? : cfg->dst_port; vni =tunnel_id_to_key32 (info->key.tun_id); ifindex =0 ; dst_cache = &info->dst_cache;
@@ -2487,8 +2502,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, tos = info->key.tos; udp_sum =test_bit (IP_TUNNEL_CSUM_BIT , info->key.tun_flags); } - src_port =udp_flow_src_port (dev_net (dev), skb, vxlan->cfg.port_min, - vxlan->cfg.port_max, true); + src_port =udp_flow_src_port (dev_net (dev), skb, cfg->port_min, + cfg->port_max, true);rcu_read_lock ();if (addr_family ==AF_INET ) {
@@ -2521,15 +2536,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (!info) {/* Bypass encapsulation if the destination is local */ - err =encap_bypass_if_local (skb, dev, vxlan,AF_INET , + err =encap_bypass_if_local (skb, dev, vxlan, cfg,AF_INET , dst_port, ifindex, vni, &rt->dst, rt->rt_flags);if (err) goto out_unlock; -if (vxlan->cfg.df ==VXLAN_DF_SET ) { +if (cfg->df ==VXLAN_DF_SET ) { df =htons (IP_DF ); - }else if (vxlan->cfg.df ==VXLAN_DF_INHERIT ) { + }else if (cfg->df ==VXLAN_DF_INHERIT ) {struct ethhdr *eth =eth_hdr (skb); if (ntohs(eth->h_proto) == ETH_P_IPV6 ||
@@ -2558,7 +2573,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, unclone->key.u.ipv4.src = pkey->u.ipv4.dst; unclone->key.u.ipv4.dst = saddr; } -vxlan_encap_bypass (skb, vxlan, vxlan, vni, false); +vxlan_encap_bypass (skb, vxlan, vxlan, cfg, vni, false);dst_release (ndst); goto out_unlock; }
@@ -2608,7 +2623,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (!info) {u32 rt6i_flags =dst_rt6_info (ndst)->rt6i_flags; - err =encap_bypass_if_local (skb, dev, vxlan,AF_INET6 , + err =encap_bypass_if_local (skb, dev, vxlan, cfg,AF_INET6 , dst_port, ifindex, vni, ndst, rt6i_flags);if (err)
@@ -2632,7 +2647,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, unclone->key.u.ipv6.dst = saddr; } -vxlan_encap_bypass (skb, vxlan, vxlan, vni, false); +vxlan_encap_bypass (skb, vxlan, vxlan, cfg, vni, false);dst_release (ndst); goto out_unlock; }
@@ -2653,14 +2668,14 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, ip6cb_flags);#endif } -vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX , pkt_len); +vxlan_vnifilter_count (vxlan, cfg, vni,NULL ,VXLAN_VNI_STATS_TX , pkt_len); out_unlock:rcu_read_unlock ();return ; drop:dev_dstats_tx_dropped (dev); -vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 ); +vxlan_vnifilter_count (vxlan, cfg, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 );kfree_skb_reason (skb, reason);return ;
@@ -2672,11 +2687,12 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,DEV_STATS_INC (dev, tx_carrier_errors);dst_release (ndst);DEV_STATS_INC (dev, tx_errors); -vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_ERRORS ,0 ); +vxlan_vnifilter_count (vxlan, cfg, vni,NULL ,VXLAN_VNI_STATS_TX_ERRORS ,0 );kfree_skb_reason (skb, reason); }static void vxlan_xmit_nh (struct sk_buff *skb,struct net_device *dev, +const struct vxlan_config *cfg,struct vxlan_fdb *f,__be32 vni,bool did_rsc) {struct vxlan_rdst nh_rdst;
@@ -2693,7 +2709,7 @@ static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev, do_xmit =vxlan_fdb_nh_path_select (nh, hash, &nh_rdst);if (likely (do_xmit)) -vxlan_xmit_one (skb, dev, vni, &nh_rdst, did_rsc); +vxlan_xmit_one (skb, dev, cfg, vni, &nh_rdst, did_rsc);else goto drop;
@@ -2701,15 +2717,15 @@ static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev, drop:dev_dstats_tx_dropped (dev); -vxlan_vnifilter_count (netdev_priv (dev), vni,NULL , +vxlan_vnifilter_count (netdev_priv (dev), cfg, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 );dev_kfree_skb (skb); }static netdev_tx_t vxlan_xmit_nhid (struct sk_buff *skb,struct net_device *dev, -u32 nhid,__be32 vni) +u32 nhid,__be32 vni, +const struct vxlan_config *cfg) { -struct vxlan_dev *vxlan =netdev_priv (dev);struct vxlan_rdst nh_rdst;struct nexthop *nh;bool do_xmit;
@@ -2727,11 +2743,11 @@ static netdev_tx_t vxlan_xmit_nhid(struct sk_buff *skb, struct net_device *dev, do_xmit =vxlan_fdb_nh_path_select (nh, hash, &nh_rdst);rcu_read_unlock (); -if (vxlan->cfg.saddr.sa.sa_family != nh_rdst.remote_ip.sa.sa_family) +if (cfg->saddr.sa.sa_family != nh_rdst.remote_ip.sa.sa_family) goto drop;if (likely (do_xmit)) -vxlan_xmit_one (skb, dev, vni, &nh_rdst, false); +vxlan_xmit_one (skb, dev, cfg, vni, &nh_rdst, false);else goto drop;
@@ -2739,7 +2755,7 @@ static netdev_tx_t vxlan_xmit_nhid(struct sk_buff *skb, struct net_device *dev, drop:dev_dstats_tx_dropped (dev); -vxlan_vnifilter_count (netdev_priv (dev), vni,NULL , +vxlan_vnifilter_count (netdev_priv (dev), cfg, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 );dev_kfree_skb (skb);return NETDEV_TX_OK ;
@@ -2756,34 +2772,41 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)struct vxlan_dev *vxlan =netdev_priv (dev);struct vxlan_rdst *rdst, *fdst =NULL ;const struct ip_tunnel_info *info; +const struct vxlan_config *cfg; +__be32 default_vni;struct vxlan_fdb *f;struct ethhdr *eth;__be32 vni =0 ; -u32 nhid =0 ;bool did_rsc; +u32 nhid =0 ; +u32 flags; + + cfg = &vxlan->cfg; + flags = cfg->flags; + default_vni = cfg->vni; info =skb_tunnel_info (skb);skb_reset_mac_header (skb); -if (vxlan->cfg.flags &VXLAN_F_COLLECT_METADATA ) { +if (flags &VXLAN_F_COLLECT_METADATA ) {if (info && info->mode &IP_TUNNEL_INFO_BRIDGE && info->mode &IP_TUNNEL_INFO_TX ) { vni =tunnel_id_to_key32 (info->key.tun_id); nhid = info->key.nhid; }else {if (info && info->mode &IP_TUNNEL_INFO_TX ) -vxlan_xmit_one (skb, dev, vni,NULL , false); +vxlan_xmit_one (skb, dev, cfg, vni,NULL , false);else kfree_skb_reason (skb,SKB_DROP_REASON_TUNNEL_TXINFO );return NETDEV_TX_OK ; } } -if (vxlan->cfg.flags &VXLAN_F_PROXY ) { +if (flags &VXLAN_F_PROXY ) { eth =eth_hdr (skb);if (ntohs (eth->h_proto) ==ETH_P_ARP ) -return arp_reduce (dev, skb, vni); +return arp_reduce (dev, skb, vni, flags); #if IS_ENABLED(CONFIG_IPV6) else if (ntohs(eth->h_proto) == ETH_P_IPV6 && pskb_network_may_pull(skb, sizeof(struct ipv6hdr) +
@@ -2793,23 +2816,23 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)if (m->icmph.icmp6_code ==0 && m->icmph.icmp6_type ==NDISC_NEIGHBOUR_SOLICITATION ) - return neigh_reduce(dev, skb, vni); + return neigh_reduce(dev, skb, vni, flags); }#endif }if (nhid) -return vxlan_xmit_nhid (skb, dev, nhid, vni); +return vxlan_xmit_nhid (skb, dev, nhid, vni, cfg); -if (vxlan->cfg.flags &VXLAN_F_MDB ) { +if (flags &VXLAN_F_MDB ) {struct vxlan_mdb_entry *mdb_entry;rcu_read_lock (); - mdb_entry =vxlan_mdb_entry_skb_get (vxlan, skb, vni); + mdb_entry =vxlan_mdb_entry_skb_get (vxlan, cfg, skb, vni);if (mdb_entry) {netdev_tx_t ret; - ret =vxlan_mdb_xmit (vxlan, mdb_entry, skb); + ret =vxlan_mdb_xmit (vxlan, cfg, mdb_entry, skb);rcu_read_unlock ();return ret; }
@@ -2818,27 +2841,27 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) eth =eth_hdr (skb);rcu_read_lock (); - f =vxlan_find_mac_tx (vxlan, eth->h_dest, vni); + f =vxlan_find_mac_tx (vxlan, cfg, eth->h_dest, vni); did_rsc = false; -if (f && (f->flags &NTF_ROUTER ) && (vxlan->cfg.flags &VXLAN_F_RSC ) && +if (f && (f->flags &NTF_ROUTER ) && (flags &VXLAN_F_RSC ) && (ntohs (eth->h_proto) ==ETH_P_IP ||ntohs (eth->h_proto) ==ETH_P_IPV6 )) { - did_rsc =route_shortcircuit (dev, skb); + did_rsc =route_shortcircuit (dev, skb, cfg); eth =eth_hdr (skb);if (did_rsc) - f =vxlan_find_mac_tx (vxlan, eth->h_dest, vni); + f =vxlan_find_mac_tx (vxlan, cfg, eth->h_dest, vni); }if (f ==NULL ) { - f =vxlan_find_mac_tx (vxlan, all_zeros_mac, vni); + f =vxlan_find_mac_tx (vxlan, cfg, all_zeros_mac, vni);if (f ==NULL ) { -if ((vxlan->cfg.flags &VXLAN_F_L2MISS ) && +if ((flags &VXLAN_F_L2MISS ) && !is_multicast_ether_addr (eth->h_dest))vxlan_fdb_miss (vxlan, eth->h_dest);dev_dstats_tx_dropped (dev); -vxlan_vnifilter_count (vxlan, vni,NULL , +vxlan_vnifilter_count (vxlan, cfg, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 );kfree_skb_reason (skb,SKB_DROP_REASON_NO_TX_TARGET ); goto out;
@@ -2846,8 +2869,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) }if (rcu_access_pointer (f->nh)) { -vxlan_xmit_nh (skb, dev, f, - (vni ? : vxlan->default_dst.remote_vni), did_rsc); +vxlan_xmit_nh (skb, dev, cfg, f, + (vni ? : default_vni), did_rsc); }else {list_for_each_entry_rcu (rdst, &f->remotes, list) {struct sk_buff *skb1;
@@ -2858,10 +2881,10 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev) } skb1 =skb_clone (skb,GFP_ATOMIC );if (skb1) -vxlan_xmit_one (skb1, dev, vni, rdst, did_rsc); +vxlan_xmit_one (skb1, dev, cfg, vni, rdst, did_rsc); }if (fdst) -vxlan_xmit_one (skb, dev, vni, fdst, did_rsc); +vxlan_xmit_one (skb, dev, cfg, vni, fdst, did_rsc);else kfree_skb_reason (skb,SKB_DROP_REASON_NO_TX_TARGET ); }
@@ -3734,7 +3757,7 @@ static int vxlan_sock_add(struct vxlan_dev *vxlan) }int vxlan_vni_in_use (struct net *src_net,struct vxlan_dev *vxlan, -struct vxlan_config *conf,__be32 vni) +const struct vxlan_config *conf,__be32 vni) {struct vxlan_net *vn =net_generic (src_net, vxlan_net_id);struct vxlan_dev *tmp;
@@ -4596,10 +4619,10 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) {const struct vxlan_dev *vxlan =netdev_priv (dev);const struct vxlan_rdst *dst = &vxlan->default_dst; -struct ifla_vxlan_port_range ports = { - .low =htons (vxlan->cfg.port_min), - .high =htons (vxlan->cfg.port_max), - }; +struct ifla_vxlan_port_range ports; +const struct vxlan_config *cfg; + + cfg = &vxlan->cfg;if (nla_put_u32 (skb,IFLA_VXLAN_ID ,be32_to_cpu (dst->remote_vni))) goto nla_put_failure;
@@ -4621,79 +4644,81 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)if (dst->remote_ifindex &&nla_put_u32 (skb,IFLA_VXLAN_LINK , dst->remote_ifindex)) goto nla_put_failure; -if (!vxlan_addr_any (&vxlan->cfg.saddr)) { -if (vxlan->cfg.saddr.sa.sa_family ==AF_INET ) { +if (!vxlan_addr_any (&cfg->saddr)) { +if (cfg->saddr.sa.sa_family ==AF_INET ) {if (nla_put_in_addr (skb,IFLA_VXLAN_LOCAL , - vxlan->cfg.saddr.sin.sin_addr.s_addr)) + cfg->saddr.sin.sin_addr.s_addr)) goto nla_put_failure;#if IS_ENABLED (CONFIG_IPV6 ) } else {if (nla_put_in6_addr (skb,IFLA_VXLAN_LOCAL6 , - &vxlan->cfg.saddr.sin6.sin6_addr)) + &cfg->saddr.sin6.sin6_addr)) goto nla_put_failure;#endif } } -if (nla_put_u8 (skb,IFLA_VXLAN_TTL , vxlan->cfg.ttl) || +if (nla_put_u8 (skb,IFLA_VXLAN_TTL , cfg->ttl) ||nla_put_u8 (skb,IFLA_VXLAN_TTL_INHERIT , - !!(vxlan->cfg.flags &VXLAN_F_TTL_INHERIT )) || -nla_put_u8 (skb,IFLA_VXLAN_TOS , vxlan->cfg.tos) || -nla_put_u8 (skb,IFLA_VXLAN_DF , vxlan->cfg.df) || -nla_put_be32 (skb,IFLA_VXLAN_LABEL , vxlan->cfg.label) || -nla_put_u32 (skb,IFLA_VXLAN_LABEL_POLICY , vxlan->cfg.label_policy) || + !!(cfg->flags &VXLAN_F_TTL_INHERIT )) || +nla_put_u8 (skb,IFLA_VXLAN_TOS , cfg->tos) || +nla_put_u8 (skb,IFLA_VXLAN_DF , cfg->df) || +nla_put_be32 (skb,IFLA_VXLAN_LABEL , cfg->label) || +nla_put_u32 (skb,IFLA_VXLAN_LABEL_POLICY , cfg->label_policy) ||nla_put_u8 (skb,IFLA_VXLAN_LEARNING , - !!(vxlan->cfg.flags &VXLAN_F_LEARN )) || + !!(cfg->flags &VXLAN_F_LEARN )) ||nla_put_u8 (skb,IFLA_VXLAN_PROXY , - !!(vxlan->cfg.flags &VXLAN_F_PROXY )) || + !!(cfg->flags &VXLAN_F_PROXY )) ||nla_put_u8 (skb,IFLA_VXLAN_RSC , - !!(vxlan->cfg.flags &VXLAN_F_RSC )) || + !!(cfg->flags &VXLAN_F_RSC )) ||nla_put_u8 (skb,IFLA_VXLAN_L2MISS , - !!(vxlan->cfg.flags &VXLAN_F_L2MISS )) || + !!(cfg->flags &VXLAN_F_L2MISS )) ||nla_put_u8 (skb,IFLA_VXLAN_L3MISS , - !!(vxlan->cfg.flags &VXLAN_F_L3MISS )) || + !!(cfg->flags &VXLAN_F_L3MISS )) ||nla_put_u8 (skb,IFLA_VXLAN_COLLECT_METADATA , - !!(vxlan->cfg.flags &VXLAN_F_COLLECT_METADATA )) || -nla_put_u32 (skb,IFLA_VXLAN_AGEING , vxlan->cfg.age_interval) || -nla_put_u32 (skb,IFLA_VXLAN_LIMIT , vxlan->cfg.addrmax) || -nla_put_be16 (skb,IFLA_VXLAN_PORT , vxlan->cfg.dst_port) || + !!(cfg->flags &VXLAN_F_COLLECT_METADATA )) || +nla_put_u32 (skb,IFLA_VXLAN_AGEING , cfg->age_interval) || +nla_put_u32 (skb,IFLA_VXLAN_LIMIT , cfg->addrmax) || +nla_put_be16 (skb,IFLA_VXLAN_PORT , cfg->dst_port) ||nla_put_u8 (skb,IFLA_VXLAN_UDP_CSUM , - !(vxlan->cfg.flags &VXLAN_F_UDP_ZERO_CSUM_TX )) || + !(cfg->flags &VXLAN_F_UDP_ZERO_CSUM_TX )) ||nla_put_u8 (skb,IFLA_VXLAN_UDP_ZERO_CSUM6_TX , - !!(vxlan->cfg.flags &VXLAN_F_UDP_ZERO_CSUM6_TX )) || + !!(cfg->flags &VXLAN_F_UDP_ZERO_CSUM6_TX )) ||nla_put_u8 (skb,IFLA_VXLAN_UDP_ZERO_CSUM6_RX , - !!(vxlan->cfg.flags &VXLAN_F_UDP_ZERO_CSUM6_RX )) || + !!(cfg->flags &VXLAN_F_UDP_ZERO_CSUM6_RX )) ||nla_put_u8 (skb,IFLA_VXLAN_REMCSUM_TX , - !!(vxlan->cfg.flags &VXLAN_F_REMCSUM_TX )) || + !!(cfg->flags &VXLAN_F_REMCSUM_TX )) ||nla_put_u8 (skb,IFLA_VXLAN_REMCSUM_RX , - !!(vxlan->cfg.flags &VXLAN_F_REMCSUM_RX )) || + !!(cfg->flags &VXLAN_F_REMCSUM_RX )) ||nla_put_u8 (skb,IFLA_VXLAN_LOCALBYPASS , - !!(vxlan->cfg.flags &VXLAN_F_LOCALBYPASS ))) + !!(cfg->flags &VXLAN_F_LOCALBYPASS ))) goto nla_put_failure; + ports.low =htons (cfg->port_min); + ports.high =htons (cfg->port_max);if (nla_put (skb,IFLA_VXLAN_PORT_RANGE ,sizeof (ports), &ports)) goto nla_put_failure; -if (vxlan->cfg.flags &VXLAN_F_GBP && +if (cfg->flags &VXLAN_F_GBP &&nla_put_flag (skb,IFLA_VXLAN_GBP )) goto nla_put_failure; -if (vxlan->cfg.flags &VXLAN_F_GPE && +if (cfg->flags &VXLAN_F_GPE &&nla_put_flag (skb,IFLA_VXLAN_GPE )) goto nla_put_failure; -if (vxlan->cfg.flags &VXLAN_F_REMCSUM_NOPARTIAL && +if (cfg->flags &VXLAN_F_REMCSUM_NOPARTIAL &&nla_put_flag (skb,IFLA_VXLAN_REMCSUM_NOPARTIAL )) goto nla_put_failure; -if (vxlan->cfg.flags &VXLAN_F_VNIFILTER && +if (cfg->flags &VXLAN_F_VNIFILTER &&nla_put_u8 (skb,IFLA_VXLAN_VNIFILTER , - !!(vxlan->cfg.flags &VXLAN_F_VNIFILTER ))) + !!(cfg->flags &VXLAN_F_VNIFILTER ))) goto nla_put_failure;if (nla_put (skb,IFLA_VXLAN_RESERVED_BITS , -sizeof (vxlan->cfg.reserved_bits), - &vxlan->cfg.reserved_bits)) +sizeof (cfg->reserved_bits), + &cfg->reserved_bits)) goto nla_put_failure;return 0 ;
drivers/net/vxlan/vxlan_mdb.c +13 -8
@@ -165,6 +165,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan,const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { + const struct vxlan_config *cfg = &vxlan->cfg;struct vxlan_rdst *rd =rtnl_dereference (remote->rd);struct br_mdb_entry e;struct nlattr *nest;
@@ -189,7 +190,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, vxlan_nla_put_addr(skb, MDBA_MDB_EATTR_DST, &rd->remote_ip)) goto nest_err; -if (rd->remote_port && rd->remote_port != vxlan->cfg.dst_port && +if (rd->remote_port && rd->remote_port != cfg->dst_port &&nla_put_u16 (skb,MDBA_MDB_EATTR_DST_PORT ,be16_to_cpu (rd->remote_port))) goto nest_err;
@@ -202,7 +203,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, nla_put_u32(skb, MDBA_MDB_EATTR_IFINDEX, rd->remote_ifindex)) goto nest_err; -if ((vxlan->cfg.flags &VXLAN_F_COLLECT_METADATA ) && +if ((cfg->flags &VXLAN_F_COLLECT_METADATA ) && mdb_entry->key.vni &&nla_put_u32 (skb,MDBA_MDB_EATTR_SRC_VNI ,be32_to_cpu (mdb_entry->key.vni))) goto nest_err;
@@ -613,6 +614,7 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, {struct br_mdb_entry *entry =nla_data (tb[MDBA_SET_ENTRY ]);struct vxlan_dev *vxlan =netdev_priv (dev); +const struct vxlan_config *vcfg = &vxlan->cfg;memset (cfg,0 ,sizeof (*cfg)); cfg->vxlan = vxlan;
@@ -622,7 +624,7 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, cfg->filter_mode =MCAST_EXCLUDE ; cfg->rt_protocol =RTPROT_STATIC ; cfg->remote_vni = vxlan->default_dst.remote_vni; - cfg->remote_port = vxlan->cfg.dst_port; + cfg->remote_port = vcfg->dst_port;if (entry->ifindex != dev->ifindex) {NL_SET_ERR_MSG_MOD (extack,"Port net device must be the VXLAN net device" );
@@ -957,6 +959,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan,const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { + const struct vxlan_config *cfg = &vxlan->cfg;const struct vxlan_mdb_entry_key *group = &mdb_entry->key;struct vxlan_rdst *rd =rtnl_dereference (remote->rd);size_t nlmsg_size;
@@ -978,7 +981,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan,/* MDBA_MDB_EATTR_DST */ nlmsg_size +=nla_total_size (vxlan_addr_size (&rd->remote_ip));/* MDBA_MDB_EATTR_DST_PORT */ -if (rd->remote_port && rd->remote_port != vxlan->cfg.dst_port) +if (rd->remote_port && rd->remote_port != cfg->dst_port) nlmsg_size +=nla_total_size (sizeof (u16));/* MDBA_MDB_EATTR_VNI */ if (rd->remote_vni != vxlan->default_dst.remote_vni)
@@ -987,7 +990,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan,if (rd->remote_ifindex) nlmsg_size +=nla_total_size (sizeof (u32));/* MDBA_MDB_EATTR_SRC_VNI */ -if ((vxlan->cfg.flags &VXLAN_F_COLLECT_METADATA ) && group->vni) +if ((cfg->flags &VXLAN_F_COLLECT_METADATA ) && group->vni) nlmsg_size +=nla_total_size (sizeof (u32));return nlmsg_size;
@@ -1621,6 +1624,7 @@ int vxlan_mdb_get(struct net_device *dev, struct nlattr *tb[], u32 portid, }struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,struct sk_buff *skb,__be32 src_vni) {
@@ -1634,7 +1638,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,/* When not in collect metadata mode, 'src_vni' is zero, but MDB * entries are stored with the VNI of the VXLAN device. */ -if (!(vxlan->cfg.flags &VXLAN_F_COLLECT_METADATA )) +if (!(cfg->flags &VXLAN_F_COLLECT_METADATA )) src_vni = vxlan->default_dst.remote_vni;memset (&group,0 ,sizeof (group));
@@ -1700,6 +1704,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan, }netdev_tx_t vxlan_mdb_xmit (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,const struct vxlan_mdb_entry *mdb_entry,struct sk_buff *skb) {
@@ -1721,12 +1726,12 @@ netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan, skb1 =skb_clone (skb,GFP_ATOMIC );if (skb1) -vxlan_xmit_one (skb1, vxlan->dev, src_vni, +vxlan_xmit_one (skb1, vxlan->dev, cfg, src_vni,rcu_dereference (remote->rd), false); }if (fremote) -vxlan_xmit_one (skb, vxlan->dev, src_vni, +vxlan_xmit_one (skb, vxlan->dev, cfg, src_vni,rcu_dereference (fremote->rd), false);else kfree_skb_reason (skb,SKB_DROP_REASON_NO_TX_TARGET );
drivers/net/vxlan/vxlan_private.h +6 -2
@@ -195,9 +195,10 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan, __u32 ifindex, __u16 ndm_flags, u32 nhid, 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);int vxlan_vni_in_use (struct net *src_net,struct vxlan_dev *vxlan, -struct vxlan_config *conf,__be32 vni); +const struct vxlan_config *conf,__be32 vni);/* vxlan_vnifilter.c */ int vxlan_vnigroup_init (struct vxlan_dev *vxlan);
@@ -205,7 +206,8 @@ void vxlan_vnigroup_uninit(struct vxlan_dev *vxlan);int vxlan_vnifilter_init (void );void vxlan_vnifilter_uninit (void ); -void vxlan_vnifilter_count (struct vxlan_dev *vxlan,__be32 vni, +void vxlan_vnifilter_count (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,__be32 vni,struct vxlan_vni_node *vninode,int type,unsigned int len);
@@ -241,9 +243,11 @@ int vxlan_mdb_del_bulk(struct net_device *dev, struct nlattr *tb[],int vxlan_mdb_get (struct net_device *dev,struct nlattr *tb[],u32 portid,u32 seq,struct netlink_ext_ack *extack);struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,struct sk_buff *skb,__be32 src_vni);netdev_tx_t vxlan_mdb_xmit (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,const struct vxlan_mdb_entry *mdb_entry,struct sk_buff *skb);int vxlan_mdb_init (struct vxlan_dev *vxlan);
drivers/net/vxlan/vxlan_vnifilter.c +3 -2
@@ -171,13 +171,14 @@ static void vxlan_vnifilter_stats_add(struct vxlan_vni_node *vninode,u64_stats_update_end (&pstats->syncp); } -void vxlan_vnifilter_count (struct vxlan_dev *vxlan,__be32 vni, +void vxlan_vnifilter_count (struct vxlan_dev *vxlan, +const struct vxlan_config *cfg,__be32 vni,struct vxlan_vni_node *vninode,int type,unsigned int len) {struct vxlan_vni_node *vnode; -if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +if (!cfg || !(cfg->flags &VXLAN_F_VNIFILTER ))return ;if (vninode) {
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog
PATCH v3 3/6 vxlan: move VXLAN_F_MDB to struct vxlan_dev flags
In reply to Eric DumazetVXLAN_F_MDB is an internal runtime state flag indicating whether any MDB entries are configured on the device, rather than a netlink configuration attribute.
In preparation for converting vxlan->cfg to an RCU-protected pointer, move VXLAN_F_MDB from struct vxlan_config to a dedicated 'flags' field in struct vxlan_dev as VXLAN_DEV_F_MDB, using atomic bitops (set_bit(), clear_bit(), test_bit()) to avoid KCSAN data races between the TX path and RTNL operations.
This avoids having to dynamically reallocate and publish a new vxlan_config structure via RCU whenever the first MDB entry is added or the last one is removed, and prevents potential memory allocation failures during MDB teardown under memory pressure.
--- drivers/net/vxlan/vxlan_core.c | 2 +- drivers/net/vxlan/vxlan_mdb.c | 6 +++--- include/net/vxlan.h | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/net/vxlan/vxlan_core.c +1 -1
@@ -2824,7 +2824,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)if (nhid)return vxlan_xmit_nhid (skb, dev, nhid, vni, cfg); -if (flags &VXLAN_F_MDB ) { +if (test_bit (VXLAN_DEV_F_MDB , &vxlan->flags)) {struct vxlan_mdb_entry *mdb_entry;rcu_read_lock ();
drivers/net/vxlan/vxlan_mdb.c +3 -3
@@ -1219,7 +1219,7 @@ vxlan_mdb_entry_get(struct vxlan_dev *vxlan, goto err_free_entry;if (hlist_is_singular_node (&mdb_entry->mdb_node, &vxlan->mdb_list)) - vxlan->cfg.flags |=VXLAN_F_MDB ; +set_bit (VXLAN_DEV_F_MDB , &vxlan->flags);return mdb_entry;
@@ -1236,7 +1236,7 @@ static void vxlan_mdb_entry_put(struct vxlan_dev *vxlan,return ;if (hlist_is_singular_node (&mdb_entry->mdb_node, &vxlan->mdb_list)) - vxlan->cfg.flags &= ~VXLAN_F_MDB ; +clear_bit (VXLAN_DEV_F_MDB , &vxlan->flags);rhashtable_remove_fast (&vxlan->mdb_tbl, &mdb_entry->rhnode, vxlan_mdb_rht_params);
@@ -1762,7 +1762,7 @@ void vxlan_mdb_fini(struct vxlan_dev *vxlan)struct vxlan_mdb_flush_desc desc = {};vxlan_mdb_flush (vxlan, &desc); -WARN_ON_ONCE (vxlan->cfg.flags &VXLAN_F_MDB ); +WARN_ON_ONCE (test_bit (VXLAN_DEV_F_MDB , &vxlan->flags));rhashtable_free_and_destroy (&vxlan->mdb_tbl, vxlan_mdb_check_empty,NULL ); }
include/net/vxlan.h +5 -1
@@ -300,6 +300,7 @@ struct vxlan_dev {spinlock_t hash_lock;unsigned int addrcnt;struct gro_cells gro_cells; +unsigned long flags;struct vxlan_config cfg;
@@ -313,6 +314,10 @@ struct vxlan_dev {unsigned int mdb_seq; }; +enum vxlan_dev_flags { +VXLAN_DEV_F_MDB , +}; +#define VXLAN_F_LEARN 0x01#define VXLAN_F_PROXY 0x02#define VXLAN_F_RSC 0x04
@@ -331,7 +336,6 @@ struct vxlan_dev {#define VXLAN_F_IPV6_LINKLOCAL 0x8000#define VXLAN_F_TTL_INHERIT 0x10000#define VXLAN_F_VNIFILTER 0x20000 -#define VXLAN_F_MDB 0x40000#define VXLAN_F_LOCALBYPASS 0x80000#define VXLAN_F_MC_ROUTE 0x100000
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog
PATCH v3 4/6 vxlan: convert configuration to RCU protection
In reply to Eric DumazetMove 'struct vxlan_config' from an embedded structure inside 'struct vxlan_dev' to a dynamically allocated RCU-protected pointer 'vxlan->cfg'.
Updating configuration via vxlan_changelink() or vxlan_dev_configure() allocates a new struct vxlan_config and publishes it with rcu_assign_pointer(), freeing the previous config with kfree_rcu().
Readers are converted to use rcu_dereference() or rtnl_dereference(). In vxlan_xmit(), acquire rcu_read_lock() to protect config access.
--- .../mellanox/mlxsw/spectrum_nve_vxlan.c | 14 +- .../mellanox/mlxsw/spectrum_switchdev.c | 57 ++-- drivers/net/vxlan/vxlan_core.c | 270 ++++++++++++------ drivers/net/vxlan/vxlan_mdb.c | 10 +- drivers/net/vxlan/vxlan_multicast.c | 12 +- drivers/net/vxlan/vxlan_vnifilter.c | 21 +- include/net/vxlan.h | 3 +- 7 files changed, 261 insertions(+), 126 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c +10 -4
@@ -59,8 +59,11 @@ static bool mlxsw_sp_nve_vxlan_can_offload(const struct mlxsw_sp_nve *nve,const struct mlxsw_sp_nve_params *params, struct netlink_ext_ack *extack) { - struct vxlan_dev *vxlan = netdev_priv(params->dev); -struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg; +struct vxlan_dev *vxlan; + + vxlan =netdev_priv (params->dev); + cfg =rtnl_dereference (vxlan->cfg);if (vxlan_addr_multicast (&cfg->remote_ip)) {NL_SET_ERR_MSG_MOD (extack,"VxLAN: Multicast destination IP is not supported" );
@@ -148,8 +151,11 @@ static void mlxsw_sp_nve_vxlan_config(const struct mlxsw_sp_nve *nve,const struct mlxsw_sp_nve_params *params, struct mlxsw_sp_nve_config *config) { - struct vxlan_dev *vxlan = netdev_priv(params->dev); -struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg; +struct vxlan_dev *vxlan; + + vxlan =netdev_priv (params->dev); + cfg =rtnl_dereference (vxlan->cfg); config->type =MLXSW_SP_NVE_TYPE_VXLAN ; config->ttl = cfg->ttl;
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +39 -18
130 lines not on this page · raw message
drivers/net/vxlan/vxlan_core.c +181 -89
785 lines not on this page · raw message
drivers/net/vxlan/vxlan_mdb.c +6 -4
@@ -165,7 +165,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan,const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { - const struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg = rcu_dereference_rtnl(vxlan->cfg);struct vxlan_rdst *rd =rtnl_dereference (remote->rd);struct br_mdb_entry e;struct nlattr *nest;
@@ -614,7 +614,9 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg, {struct br_mdb_entry *entry =nla_data (tb[MDBA_SET_ENTRY ]);struct vxlan_dev *vxlan =netdev_priv (dev); -const struct vxlan_config *vcfg = &vxlan->cfg; +const struct vxlan_config *vcfg; + + vcfg =rtnl_dereference (vxlan->cfg);memset (cfg,0 ,sizeof (*cfg)); cfg->vxlan = vxlan;
@@ -959,12 +961,12 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan,const struct vxlan_mdb_entry *mdb_entry, const struct vxlan_mdb_remote *remote) { - const struct vxlan_config *cfg = &vxlan->cfg; + const struct vxlan_config *cfg = rcu_dereference_rtnl(vxlan->cfg);const struct vxlan_mdb_entry_key *group = &mdb_entry->key;struct vxlan_rdst *rd =rtnl_dereference (remote->rd);size_t nlmsg_size; -/* MDBA_MDB_ENTRY_INFO */ +/* MDBA_MDB_ENTRY_INFO */ nlmsg_size =nla_total_size (sizeof (struct br_mdb_entry )) +/* MDBA_MDB_EATTR_TIMER */ nla_total_size (sizeof (u32));
drivers/net/vxlan/vxlan_multicast.c +9 -3
@@ -147,6 +147,8 @@ bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev,#endif list_for_each_entry (vxlan, &vn->vxlan_list, next) { +const struct vxlan_config *cfg; +if (!netif_running (vxlan->dev) || vxlan == dev)continue ;
@@ -158,7 +160,9 @@ bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, rtnl_dereference(vxlan->vn6_sock) != sock6)continue ;#endif -if (vxlan->cfg.flags &VXLAN_F_VNIFILTER ) { + cfg =rtnl_dereference (vxlan->cfg); + +if (cfg->flags &VXLAN_F_VNIFILTER ) {if (!vxlan_group_used_by_vnifilter (vxlan, ip, ifindex))continue ; }else {
@@ -233,6 +237,7 @@ static int vxlan_multicast_leave_vnigrp(struct vxlan_dev *vxlan)int vxlan_multicast_join (struct vxlan_dev *vxlan) { +const struct vxlan_config *cfg =rtnl_dereference (vxlan->cfg);int ret =0 ;if (vxlan_addr_multicast (&vxlan->default_dst.remote_ip)) {
@@ -244,7 +249,7 @@ int vxlan_multicast_join(struct vxlan_dev *vxlan)return ret; } -if (vxlan->cfg.flags &VXLAN_F_VNIFILTER ) +if (cfg->flags &VXLAN_F_VNIFILTER )return vxlan_multicast_join_vnigrp (vxlan);return 0 ;
@@ -252,6 +257,7 @@ int vxlan_multicast_join(struct vxlan_dev *vxlan)int vxlan_multicast_leave (struct vxlan_dev *vxlan) { +const struct vxlan_config *cfg =rtnl_dereference (vxlan->cfg);struct vxlan_net *vn =net_generic (vxlan->net, vxlan_net_id);int ret =0 ;
@@ -263,7 +269,7 @@ int vxlan_multicast_leave(struct vxlan_dev *vxlan)return ret; } -if (vxlan->cfg.flags &VXLAN_F_VNIFILTER ) +if (cfg->flags &VXLAN_F_VNIFILTER )return vxlan_multicast_leave_vnigrp (vxlan);return 0 ;
drivers/net/vxlan/vxlan_vnifilter.c +14 -7
@@ -178,7 +178,7 @@ void vxlan_vnifilter_count(struct vxlan_dev *vxlan, {struct vxlan_vni_node *vnode; -if (!cfg || !(cfg->flags &VXLAN_F_VNIFILTER )) +if (!(cfg->flags &VXLAN_F_VNIFILTER ))return ;if (vninode) {
@@ -337,6 +337,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev,struct vxlan_vni_node *v, *vbegin =NULL , *vend =NULL ;struct vxlan_dev *vxlan =netdev_priv (dev);struct tunnel_msg *new_tmsg, *tmsg; +const struct vxlan_config *cfg;struct vxlan_vni_group *vg;struct nlmsghdr *nlh;int idx =0 , s_idx;
@@ -349,7 +350,8 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, } s_idx = cb->args[1 ]; -if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) { + cfg =rcu_dereference (vxlan->cfg); +if (!(cfg->flags &VXLAN_F_VNIFILTER )) { cb->args[1 ] =0 ; cb->args[2 ] =0 ;return -EINVAL ;
@@ -489,6 +491,7 @@ static int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni,union vxlan_addr *remote_ip, struct netlink_ext_ack *extack) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg);struct vxlan_rdst *dst = &vxlan->default_dst;int err =0 ;
@@ -498,7 +501,7 @@ static int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni, remote_ip,NUD_REACHABLE |NUD_PERMANENT ,NLM_F_APPEND |NLM_F_CREATE , - vxlan->cfg.dst_port, + cfg->dst_port, vni, vni, dst->remote_ifindex,
@@ -512,7 +515,7 @@ static int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni,if (old_remote_ip && !vxlan_addr_any (old_remote_ip)) {__vxlan_fdb_delete (vxlan, all_zeros_mac, *old_remote_ip, - vxlan->cfg.dst_port, + cfg->dst_port, vni, vni, dst->remote_ifindex, true);
@@ -626,6 +629,7 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, struct vxlan_vni_node *vninode) {struct vxlan_net *vn =net_generic (vxlan->net, vxlan_net_id); +const struct vxlan_config *cfg =rtnl_dereference (vxlan->cfg);struct vxlan_rdst *dst = &vxlan->default_dst;/* if per vni remote_ip not present, delete the
@@ -637,7 +641,7 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan,__vxlan_fdb_delete (vxlan, all_zeros_mac, (vxlan_addr_any (&vninode->remote_ip) ? dst->remote_ip : vninode->remote_ip), - vxlan->cfg.dst_port, + cfg->dst_port, vninode->vni, vninode->vni, dst->remote_ifindex, true);
@@ -737,6 +741,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan, u32 vni, union vxlan_addr *group, struct netlink_ext_ack *extack) { + const struct vxlan_config *cfg = rtnl_dereference(vxlan->cfg);struct vxlan_vni_node *vninode;__be32 v =cpu_to_be32 (vni);bool changed = false;
@@ -745,7 +750,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan,if (vxlan_vnifilter_lookup (vxlan, v))return vxlan_vni_update (vxlan, vg, v, group, &changed, extack); - err =vxlan_vni_in_use (vxlan->net, vxlan, &vxlan->cfg, v); + err =vxlan_vni_in_use (vxlan->net, vxlan, cfg, v);if (err) {NL_SET_ERR_MSG (extack,"VNI in use" );return err;
@@ -954,6 +959,7 @@ static int vxlan_vnifilter_process(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk); +const struct vxlan_config *cfg;struct tunnel_msg *tmsg;struct vxlan_dev *vxlan;struct net_device *dev;
@@ -978,8 +984,9 @@ static int vxlan_vnifilter_process(struct sk_buff *skb, struct nlmsghdr *nlh, } vxlan =netdev_priv (dev); + cfg =rtnl_dereference (vxlan->cfg); -if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +if (!(cfg->flags &VXLAN_F_VNIFILTER ))return -EOPNOTSUPP ; nlmsg_for_each_attr_type(attr, VXLAN_VNIFILTER_ENTRY, nlh,
include/net/vxlan.h +2 -1
@@ -229,6 +229,7 @@ struct vxlan_config {bool no_share;enum ifla_vxlan_df df;struct vxlanhdr reserved_bits; +struct rcu_head rcu; };enum {
@@ -302,7 +303,7 @@ struct vxlan_dev {struct gro_cells gro_cells;unsigned long flags; -struct vxlan_config cfg; +struct vxlan_config __rcu *cfg;struct vxlan_vni_group __rcu *vnigrp;
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog
PATCH v3 5/6 vxlan: remove default_dst and use vxlan_config and lowerdev
In reply to Eric DumazetNow that vxlan->cfg is an RCU-protected pointer, storing default destination attributes (remote_ip, remote_vni, remote_ifindex) in vxlan->default_dst is redundant and creates potential data races for lockless readers.
Furthermore, several fields of struct vxlan_rdst (remote_dev, remote_port, offloaded, list, rcu, dst_cache) in default_dst were completely unused. Drop the now-unused remote_dev field from struct vxlan_rdst.
Replace vxlan->default_dst with a 'struct net_device *lowerdev' pointer in struct vxlan_dev to track adjacent upper/lower netdev topology under RTNL, and switch all remaining users over to reading configuration attributes from vxlan->cfg.
Also update mlx5e_tc_tun_get_remote_ifindex() to read remote_ifindex from vxlan->cfg under rcu_read_lock().
In vxlan_changelink(), pass lowerdev to vxlan_config_apply() to preserve needed_headroom and needed_tailroom, and update default FDB entries (including VNI filter entries) if remote_ifindex changed.
--- .../mellanox/mlx5/core/en/tc_tun_vxlan.c | 11 +- drivers/net/vxlan/vxlan_core.c | 163 ++++++++++-------- drivers/net/vxlan/vxlan_mdb.c | 14 +- drivers/net/vxlan/vxlan_multicast.c | 64 +++---- drivers/net/vxlan/vxlan_private.h | 11 +- drivers/net/vxlan/vxlan_vnifilter.c | 51 ++++-- include/net/vxlan.h | 3 +- 7 files changed, 178 insertions(+), 139 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_vxlan.c +9 -2
@@ -241,9 +241,16 @@ static bool mlx5e_tc_tun_encap_info_equal_vxlan(struct mlx5e_encap_key *a,static int mlx5e_tc_tun_get_remote_ifindex (struct net_device *mirred_dev) {const struct vxlan_dev *vxlan =netdev_priv (mirred_dev); -const struct vxlan_rdst *dst = &vxlan->default_dst; +const struct vxlan_config *cfg; +int ifindex =0 ; -return dst->remote_ifindex; +rcu_read_lock (); + cfg =rcu_dereference (vxlan->cfg); +if (cfg) + ifindex = cfg->remote_ifindex; +rcu_read_unlock (); + +return ifindex; }struct mlx5e_tc_tunnel vxlan_tunnel = {
drivers/net/vxlan/vxlan_core.c +87 -76
369 lines not on this page · raw message
drivers/net/vxlan/vxlan_mdb.c +8 -6
@@ -195,7 +195,7 @@ static int vxlan_mdb_entry_info_fill(const struct vxlan_dev *vxlan, be16_to_cpu(rd->remote_port))) goto nest_err; -if (rd->remote_vni != vxlan->default_dst.remote_vni && +if (rd->remote_vni != cfg->vni &&nla_put_u32 (skb,MDBA_MDB_EATTR_VNI ,be32_to_cpu (rd->remote_vni))) goto nest_err;
@@ -620,12 +620,12 @@ static int vxlan_mdb_config_init(struct vxlan_mdb_config *cfg,memset (cfg,0 ,sizeof (*cfg)); cfg->vxlan = vxlan; - cfg->group.vni = vxlan->default_dst.remote_vni; + cfg->group.vni = vcfg->vni;INIT_LIST_HEAD (&cfg->src_list); cfg->nlflags = nlmsg_flags; cfg->filter_mode =MCAST_EXCLUDE ; cfg->rt_protocol =RTPROT_STATIC ; - cfg->remote_vni = vxlan->default_dst.remote_vni; + cfg->remote_vni = vcfg->vni; cfg->remote_port = vcfg->dst_port;if (entry->ifindex != dev->ifindex) {
@@ -986,7 +986,7 @@ vxlan_mdb_nlmsg_remote_size(const struct vxlan_dev *vxlan,if (rd->remote_port && rd->remote_port != cfg->dst_port) nlmsg_size +=nla_total_size (sizeof (u16));/* MDBA_MDB_EATTR_VNI */ -if (rd->remote_vni != vxlan->default_dst.remote_vni) +if (rd->remote_vni != cfg->vni) nlmsg_size +=nla_total_size (sizeof (u32));/* MDBA_MDB_EATTR_IFINDEX */ if (rd->remote_ifindex)
@@ -1488,11 +1488,13 @@ static int vxlan_mdb_get_parse(struct net_device *dev, struct nlattr *tb[], {struct br_mdb_entry *entry =nla_data (tb[MDBA_GET_ENTRY ]);struct nlattr *mdbe_attrs[MDBE_ATTR_MAX +1 ]; +const struct vxlan_config *cfg;struct vxlan_dev *vxlan =netdev_priv (dev);int err; + cfg =rtnl_dereference (vxlan->cfg);memset (group,0 ,sizeof (*group)); - group->vni = vxlan->default_dst.remote_vni; + group->vni = cfg->vni;if (!tb[MDBA_GET_ENTRY_ATTRS ]) {vxlan_mdb_group_set (group, entry,NULL );
@@ -1641,7 +1643,7 @@ struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,* entries are stored with the VNI of the VXLAN device. */ if (!(cfg->flags &VXLAN_F_COLLECT_METADATA )) - src_vni = vxlan->default_dst.remote_vni; + src_vni = cfg->vni;memset (&group,0 ,sizeof (group)); group.vni = src_vni;
drivers/net/vxlan/vxlan_multicast.c +35 -29
161 lines not on this page · raw message
drivers/net/vxlan/vxlan_private.h +6 -5
@@ -216,8 +216,9 @@ void vxlan_vs_add_vnigrp(struct vxlan_dev *vxlan, bool ipv6);void vxlan_vs_del_vnigrp (struct vxlan_dev *vxlan);int vxlan_vnilist_update_group (struct vxlan_dev *vxlan, -union vxlan_addr *old_remote_ip, -union vxlan_addr *new_remote_ip, +const union vxlan_addr *old_remote_ip, +const union vxlan_addr *new_remote_ip, +u32 old_ifindex,u32 new_ifindex,struct netlink_ext_ack *extack);
@@ -225,10 +226,10 @@ int vxlan_vnilist_update_group(struct vxlan_dev *vxlan,int vxlan_multicast_join (struct vxlan_dev *vxlan);int vxlan_multicast_leave (struct vxlan_dev *vxlan);bool vxlan_group_used (struct vxlan_net *vn,struct vxlan_dev *dev, -__be32 vni,union vxlan_addr *rip,int rifindex); -int vxlan_igmp_join (struct vxlan_dev *vxlan,union vxlan_addr *rip, +__be32 vni,const union vxlan_addr *rip,int rifindex); +int vxlan_igmp_join (struct vxlan_dev *vxlan,const union vxlan_addr *rip,int rifindex); -int vxlan_igmp_leave (struct vxlan_dev *vxlan,union vxlan_addr *rip, +int vxlan_igmp_leave (struct vxlan_dev *vxlan,const union vxlan_addr *rip,int rifindex);/* vxlan_mdb.c */
drivers/net/vxlan/vxlan_vnifilter.c +32 -19
146 lines not on this page · raw message
include/net/vxlan.h +1 -2
@@ -204,7 +204,6 @@ struct vxlan_rdst { u8 offloaded:1;__be32 remote_vni;u32 remote_ifindex; -struct net_device *remote_dev;struct list_head list;struct rcu_head rcu;struct dst_cache dst_cache;
@@ -295,7 +294,7 @@ struct vxlan_dev {#endif struct net_device *dev;struct net *net;/* netns for packet i/o */ -struct vxlan_rdst default_dst;/* default destination */ +struct net_device *lowerdev;struct timer_list age_timer;spinlock_t hash_lock;
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog
PATCH v3 6/6 vxlan: no longer rely on RTNL in vxlan_fill_info()
In reply to Eric DumazetNow that vxlan->cfg is RCU-protected, we can update vxlan_fill_info() to run under RCU read lock instead of relying on RTNL.
This completes the transition to RTNL-less link info dumping for VXLAN.
--- drivers/net/vxlan/vxlan_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/vxlan/vxlan_core.c +4 -1
@@ -4725,7 +4725,8 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)struct ifla_vxlan_port_range ports;const struct vxlan_config *cfg; - cfg =rtnl_dereference (vxlan->cfg); +rcu_read_lock (); + cfg =rcu_dereference (vxlan->cfg);if (nla_put_u32 (skb,IFLA_VXLAN_ID ,be32_to_cpu (cfg->vni))) goto nla_put_failure;
@@ -4824,9 +4825,11 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev) &cfg->reserved_bits)) goto nla_put_failure; +rcu_read_unlock ();return 0 ; nla_put_failure: +rcu_read_unlock ();return -EMSGSIZE ; }
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog
Jakub Kicinski
maintainerRe: [PATCH v3 net-next 1/6] vxlan: vnifilter: use list_for_each_entry_rcu() in vxlan_vnifilter_dump_dev()
In reply to Eric DumazetThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
vxlan: vnifilter: use list_for_each_entry_rcu() in vxlan_vnifilter_dump_dev()
This switches the vg->vni_list walk in vxlan_vnifilter_dump_dev() to list_for_each_entry_rcu(), clears the saved VNI offset on the early return paths, and adds cb->args[2] to track the ifindex of the device currently being dumped so the VNI offset is reset when the device changes.
Quoted 15 lines
drivers/net/vxlan/vxlan_vnifilter.c +1
-2@@ -333,22 +333,34 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev,struct sk_buff *skb, struct netlink_callback *cb) { - struct vxlan_vni_node *tmp, *v, *vbegin = NULL, *vend = NULL; + struct vxlan_vni_node *v, *vbegin = NULL, *vend = NULL;struct vxlan_dev *vxlan =netdev_priv (dev);struct tunnel_msg *new_tmsg, *tmsg; -int idx =0 , s_idx = cb->args[1 ];struct vxlan_vni_group *vg;struct nlmsghdr *nlh;
drivers/net/vxlan/vxlan_vnifilter.c static int vxlan_vnifilter_dump_dev(const struct net_device *dev, · line 349
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c +6
-1+int idx =0 , s_idx;bool dump_stats;int err =0 ; -if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +if (cb->args[2 ] != dev->ifindex) { + cb->args[1 ] =0 ; + cb->args[2 ] = dev->ifindex; + } + s_idx = cb->args[1 ];
[Severity: High]
The commit message says the ifindex tracking handles the case where "devices are added or removed between dump calls, ordinal device indexes can shift". Can this new check actually observe that case?
In vxlan_vnifilter_dump() the device cursor is still a bare ordinal, and devices below it are skipped before vxlan_vnifilter_dump_dev() is ever called:
int idx = 0, err = 0, s_idx = cb->args[0];
...
for_each_netdev_rcu(net, dev) {
if (!netif_is_vxlan(dev))
continue;
if (idx < s_idx)
goto skip;
err = vxlan_vnifilter_dump_dev(dev, skb, cb);
if (err == -EMSGSIZE)
break;
skip:
idx++;
}
}
cb->args[0] = idx;On -EMSGSIZE the loop breaks before idx++, so cb->args[0] is the ordinal of the partially dumped device A while cb->args[1]/cb->args[2] hold A's VNI offset and ifindex. RTM_GETTUNNEL is registered with flags 0:
{THIS_MODULE, PF_BRIDGE, RTM_GETTUNNEL, NULL, vxlan_vnifilter_dump, 0},
so rtnl_dumpit takes and releases RTNL per dump skb. If a vxlan device preceding A is unregistered in that window, A shifts down to ordinal s_idx - 1 and is skipped by the "if (idx < s_idx) goto skip" test, so vxlan_vnifilter_dump_dev() never runs for A and the new cb->args[2] comparison never happens. A's remaining VNIs then disappear from the dump and the dump ends looking complete. Would an ifindex-keyed device walk (for_each_netdev_dump()) be needed to close that?
There is also the same-device case. The commit message says the stale offset "silently skipp[ed] their first N VNIs", but s_idx here is still a plain count of entries to skip in a freshly re-walked list, and the writers mutate that list while RTNL is dropped:
__vxlan_vni_add_list() list_add_rcu(&v->vlist, hpos); /* sorted by vni */ vg->num_vnis++; __vxlan_vni_del_list() list_del_rcu(&v->vlist); vg->num_vnis--;
Since the insertion is sorted by VNI it can land before the resume point, shifting ordinals up so an already dumped entry is emitted a second time; a deletion before the resume point shifts them down so an entry that was never dumped is skipped. In both cases cb->args[2] still equals dev->ifindex, so the new reset does not fire. Would resuming from the last dumped VNI value rather than an ordinal offset avoid this?
Finally, nothing signals the tear to user space. vxlan_vnifilter_dump_dev() calls nlmsg_end() without assigning cb->seq or calling nl_dump_check_consistent(), and the VNI list writers bump no generation counter, so NLM_F_DUMP_INTR is never set. The MDB dump in the same driver does do this:
drivers/net/vxlan/vxlan_mdb.c:vxlan_mdb_dump() {
...
nlmsg_end(skb, nlh);
cb->seq = vxlan->mdb_seq;
nl_dump_check_consistent(cb, nlh);
...
}Should the vnifilter dump publish a similar generation counter so a skipped or repeated VNI is at least visible to user space?
Quoted 3 lines
drivers/net/vxlan/vxlan_vnifilter.c +0
-0/* RCU needed because of the vni locking rules (rcu || rtnl) */ vg =rcu_dereference (vxlan->vnigrp);
[ ... ]
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c +1
-1@@ -362,7 +374,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, new_tmsg->family =PF_BRIDGE ; new_tmsg->ifindex = dev->ifindex; -list_for_each_entry_safe (v, tmp, &vg->vni_list, vlist) { +list_for_each_entry_rcu (v, &vg->vni_list, vlist) {if (idx < s_idx) { idx++;continue ;
drivers/net/vxlan/vxlan_vnifilter.c static int vxlan_vnifilter_dump_dev(const struct net_device *dev, · line 412
Quoted 7 lines
drivers/net/vxlan/vxlan_vnifilter.c +1
-0@@ -394,6 +406,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, } cb->args[1 ] = err ? idx :0 ; + cb->args[2 ] = err ? dev->ifindex :0 ;nlmsg_end (skb, nlh);
For reference, the ordinal cursors and the missing cb->seq / nl_dump_check_consistent() are still present at the end of the series (1c77987f9ffa), so no later patch appears to change this.
Jakub Kicinski
maintainerRe: [PATCH v3 net-next 3/6] vxlan: move VXLAN_F_MDB to struct vxlan_dev flags
In reply to Eric DumazetThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
vxlan: move VXLAN_F_MDB to struct vxlan_dev flags
This moves the internal VXLAN_F_MDB runtime state out of struct vxlan_config.flags into a new unsigned long flags field in struct vxlan_dev, accessed with set_bit()/clear_bit()/test_bit(), in preparation for making vxlan->cfg an RCU-protected pointer.
One question about an out-of-tree-of-this-patch consumer of cfg->flags below.
drivers/net/vxlan/vxlan_mdb.c vxlan_mdb_entry_get(struct vxlan_dev *vxlan, · line 1222
Quoted 10 lines
drivers/net/vxlan/vxlan_mdb.c +1
-1@@ -1219,7 +1219,7 @@ vxlan_mdb_entry_get(struct vxlan_dev *vxlan, goto err_free_entry;if (hlist_is_singular_node (&mdb_entry->mdb_node, &vxlan->mdb_list)) - vxlan->cfg.flags |=VXLAN_F_MDB ; +set_bit (VXLAN_DEV_F_MDB , &vxlan->flags);
[Severity: Medium]
Does this change relax the mlxsw NVE offload validation?
mlxsw checks cfg->flags with a deny-by-default mask, so the 0x40000 bit used to land in the "unsupported flag" test:
drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c:
#define MLXSW_SP_NVE_VXLAN_IPV4_SUPPORTED_FLAGS (VXLAN_F_UDP_ZERO_CSUM_TX | \ VXLAN_F_LEARN | \ VXLAN_F_LOCALBYPASS)
static bool mlxsw_sp_nve_vxlan_ipv4_flags_check(const struct vxlan_config *cfg,
struct netlink_ext_ack *extack)
{
...
if (cfg->flags & ~MLXSW_SP_NVE_VXLAN_IPV4_SUPPORTED_FLAGS) {
NL_SET_ERR_MSG_MOD(extack, "VxLAN: Unsupported flag");
return false;
}The same mask exists for the IPv6 underlay in mlxsw_sp_nve_vxlan_ipv6_flags_check(), and both are reached from mlxsw_sp_nve_vxlan_can_offload(), which only looks at &vxlan->cfg.
So for a device that already has an MDB entry:
bridge mdb add dev vxlan0 port vxlan0 grp 239.1.1.1 permanent \
dst 198.51.100.1
-> vxlan_mdb_add() -> __vxlan_mdb_add() -> vxlan_mdb_entry_get()before this patch that set VXLAN_F_MDB in cfg->flags, and a later enslavement to an mlxsw-offloaded bridge was refused with "VxLAN:
Unsupported flag". After the move, mlxsw_sp_nve_vxlan_can_offload() has no way to observe the MDB state, since nothing outside vxlan_core.c and vxlan_mdb.c tests VXLAN_DEV_F_MDB, and the device is accepted for offload while the configured MDB entries are not honoured by the hardware forwarding plane.
Note the previous rejection was already order-dependent: MDB entries added after the FID was enabled were never re-validated, because vxlan MDB emits no switchdev notification at all (git grep switchdev drivers/net/vxlan/ matches only vxlan_core.c).
Would it make sense to add a test_bit(VXLAN_DEV_F_MDB, &vxlan->flags) check in mlxsw_sp_nve_vxlan_can_offload(), or to state in the commit message that MDB presence is intentionally no longer a bar to offload?
Quoted 3 lines
drivers/net/vxlan/vxlan_mdb.c +0
-0return mdb_entry;
[ ... ]
Quoted 4 lines
include/net/vxlan.h +0
-0
[ ... ]
Quoted 18 lines
include/net/vxlan.h +4
-1@@ -313,6 +314,10 @@ struct vxlan_dev {unsigned int mdb_seq; }; +enum vxlan_dev_flags { +VXLAN_DEV_F_MDB , +}; +#define VXLAN_F_LEARN 0x01#define VXLAN_F_PROXY 0x02#define VXLAN_F_RSC 0x04@@ -331,7 +336,6 @@ struct vxlan_dev {#define VXLAN_F_IPV6_LINKLOCAL 0x8000#define VXLAN_F_TTL_INHERIT 0x10000#define VXLAN_F_VNIFILTER 0x20000 -#define VXLAN_F_MDB 0x40000#define VXLAN_F_LOCALBYPASS 0x80000#define VXLAN_F_MC_ROUTE 0x100000
Jakub Kicinski
maintainerRe: [PATCH v3 net-next 5/6] vxlan: remove default_dst and use vxlan_config and lowerdev
In reply to Eric DumazetThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
vxlan: remove default_dst and use vxlan_config and lowerdev
This removes vxlan->default_dst, moving the default destination attributes (remote_ip, remote_vni, remote_ifindex) over to the RCU-protected vxlan->cfg, and adds a plain struct net_device *lowerdev to struct vxlan_dev for upper/lower adjacency tracking under RTNL. It also drops the remote_dev field from struct vxlan_rdst and updates mlx5e_tc_tun_get_remote_ifindex() to read remote_ifindex from vxlan->cfg.
A few questions below.
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +0
-0
[ ... ]
Quoted 22 lines
drivers/net/vxlan/vxlan_core.c +0
-7@@ -4010,7 +4019,6 @@ static void vxlan_config_apply(struct net_device *dev, bool changelink) {struct vxlan_dev *vxlan =netdev_priv (dev); -struct vxlan_rdst *dst = &vxlan->default_dst;unsigned short needed_headroom =ETH_HLEN ;struct vxlan_config *old_cfg;int max_mtu =ETH_MAX_MTU ;@@ -4028,13 +4036,7 @@ static void vxlan_config_apply(struct net_device *dev, vxlan->net = src_net; } - dst->remote_vni = new_cfg->vni; - -memcpy (&dst->remote_ip, &new_cfg->remote_ip,sizeof (new_cfg->remote_ip)); -if (lowerdev) { - dst->remote_ifindex = new_cfg->remote_ifindex; -netif_inherit_tso_max (dev, lowerdev); needed_headroom = lowerdev->hard_header_len;
[ ... ]
Quoted 11 lines
drivers/net/vxlan/vxlan_core.c +0
-7@@ -4578,23 +4580,23 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],if (!new_cfg)return -ENOMEM ; -if (dst->remote_dev == lowerdev) - lowerdev =NULL ; - - err =netdev_adjacent_change_prepare (dst->remote_dev, lowerdev, dev, - extack); -if (err) { -kfree (new_cfg);
drivers/net/vxlan/vxlan_core.c static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], · line 4591
Quoted 10 lines
drivers/net/vxlan/vxlan_core.c +8
-1-return err; + lowerdev_changed = vxlan->lowerdev != lowerdev; +if (lowerdev_changed) { + err =netdev_adjacent_change_prepare (vxlan->lowerdev, lowerdev, + dev, extack); +if (err) { +kfree (new_cfg); +return err; + } }
[Severity: Medium]
Can dropping the "lowerdev = NULL" shortcut here silently shrink the MTU of a live vxlan device?
Previously, when the lower device was unchanged, lowerdev was set to NULL, so vxlan_config_apply() skipped its whole "if (lowerdev)" block, max_mtu stayed at ETH_MAX_MTU and the trailing clamp was a no-op:
if (lowerdev) {
...
max_mtu = lowerdev->mtu - vxlan_headroom(flags);
if (max_mtu < ETH_MIN_MTU)
max_mtu = ETH_MIN_MTU;
...
}
if (dev->mtu > max_mtu)
dev->mtu = max_mtu;Now the real lower device is always passed on changelink, so max_mtu is recomputed every time. vxlan_change_mtu() only validates against lowerdev->mtu at the time of the request, and vxlan_netdevice_event() handles only NETDEV_UNREGISTER and the udp tunnel port events, so nothing reacts to a lower device MTU reduction:
ip link add vxlan0 type vxlan id 10 dev eth0 dstport 4789 [mtu 1450]
ip link set eth0 mtu 1000 # vxlan0 mtu unchanged
ip link set dev vxlan0 type vxlan ageing 100
The last command inherits IFLA_VXLAN_LINK from the old config, so lowerdev is non-NULL and unchanged, and dev->mtu is clamped down to
1000 - vxlan_headroom(flags).
The commit message describes passing lowerdev only as needed "to preserve needed_headroom and needed_tailroom" and says nothing about MTU or the TSO limits from netif_inherit_tso_max(). Was the MTU effect intended?
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +1
-1- rem_ip_changed = !vxlan_addr_equal (&conf.remote_ip, &dst->remote_ip); + rem_ip_changed = !vxlan_addr_equal (&conf.remote_ip, &cfg->remote_ip); change_igmp = vxlan->dev->flags & IFF_UP &&
drivers/net/vxlan/vxlan_core.c static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], · line 4602
Quoted 10 lines
drivers/net/vxlan/vxlan_core.c +2
-2(rem_ip_changed || - dst->remote_ifindex != conf.remote_ifindex); + cfg->remote_ifindex != conf.remote_ifindex);/* handle default dst entry */ -if (rem_ip_changed) { +if (rem_ip_changed || cfg->remote_ifindex != conf.remote_ifindex) {spin_lock_bh (&vxlan->hash_lock);if (!vxlan_addr_any (&conf.remote_ip)) { err = vxlan_fdb_update(vxlan, all_zeros_mac,
[Severity: Medium]
Should this widened condition come with a Fixes: tag in a separate patch?
Before this change, a changelink that altered only the lower device (for example "ip link set dev vxlan0 type vxlan group 239.1.1.1 dev eth1") skipped this block because rem_ip_changed was false, while vxlan_config_apply() updated dst->remote_ifindex. The all-zeros-MAC rdst kept the old ifindex, and vxlan_xmit_one() uses it as the route oif:
ifindex = rdst->remote_ifindex;
so traffic kept leaving the old device. The same applies to the old_ifindex/new_ifindex plumbing added to vxlan_update_default_fdb_entry() in vxlan_vnifilter.c. These look like fixes of user-visible misbehaviour bundled into a refactor, so they will not be picked up for stable.
The same is true of needed_headroom/needed_tailroom no longer being reset to ETH_HLEN + vxlan_headroom() on changelink, which is mentioned only as an implementation detail.
There is also an undocumented behaviour change further down in this function:
when IFLA_VXLAN_LINK is explicitly set to 0, the new "else netdev_upper_dev_unlink(vxlan->lowerdev, dev);" branch now tears down the old upper/lower adjacency, whereas netdev_adjacent_change_prepare() and netdev_adjacent_change_commit() returned early for a NULL new device and the adjacency survived. Could that be called out in the changelog?
Quoted 40 lines
drivers/net/vxlan/vxlan_core.c +13
-9@@ -4607,19 +4609,20 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], NTF_SELF, 0, true, extack);if (err) {spin_unlock_bh (&vxlan->hash_lock); -netdev_adjacent_change_abort (dst->remote_dev, - lowerdev, dev); +if (lowerdev_changed) +netdev_adjacent_change_abort (vxlan->lowerdev, + lowerdev, dev);kfree (new_cfg);return err; } } -if (!vxlan_addr_any (&dst->remote_ip)) +if (!vxlan_addr_any (&cfg->remote_ip))__vxlan_fdb_delete (vxlan, all_zeros_mac, - dst->remote_ip, + cfg->remote_ip, cfg->dst_port, - dst->remote_vni, - dst->remote_vni, - dst->remote_ifindex, + cfg->vni, + cfg->vni, + cfg->remote_ifindex, true);spin_unlock_bh (&vxlan->hash_lock);@@ -4627,30 +4630,39 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],* all vnis that were using default remote ip */ if (cfg->flags &VXLAN_F_VNIFILTER ) { - err =vxlan_vnilist_update_group (vxlan, &dst->remote_ip, - &conf.remote_ip, extack); + err =vxlan_vnilist_update_group (vxlan, &cfg->remote_ip, + &conf.remote_ip, + cfg->remote_ifindex, + conf.remote_ifindex, + extack);if (err) {
drivers/net/vxlan/vxlan_core.c static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], · line 4646
Quoted 10 lines
drivers/net/vxlan/vxlan_core.c +3
-2-netdev_adjacent_change_abort (dst->remote_dev, - lowerdev, dev); +if (lowerdev_changed) +netdev_adjacent_change_abort (vxlan->lowerdev, + lowerdev, dev);kfree (new_cfg);return err; } } }
[Severity: Low]
Can this error path leave forwarding state half applied for an ifindex-only change?
By the time vxlan_vnilist_update_group() runs, the default destination has already been appended with the new remote/ifindex and the old one deleted, and the loop in vxlan_vnilist_update_group() commits each per-VNI update in turn and returns on the first failure without undoing the earlier ones. vxlan_fdb_append() can fail:
rd = kmalloc_obj(*rd, GFP_ATOMIC); if (rd == NULL) return -ENOMEM;
On that failure this branch only aborts the adjacency change and frees new_cfg, so vxlan_config_apply() is never reached: vxlan->cfg and vxlan->lowerdev keep the old values while the default fdb entry and some per-VNI entries already carry the requested ifindex. The rdsts allocated for the ifindex that was never committed stay linked until explicit fdb or device teardown. The append-then-delete rollback gap already existed for remote-IP changes, but ifindex-only changes are newly routed through it.
Quoted 20 lines
drivers/net/vxlan/vxlan_core.c +9
-4-if (change_igmp &&vxlan_addr_multicast (&dst->remote_ip)) +if (change_igmp &&vxlan_addr_multicast (&cfg->remote_ip)) err =vxlan_multicast_leave (vxlan);if (netif_running (dev) && conf.age_interval != cfg->age_interval)mod_timer (&vxlan->age_timer, jiffies); -netdev_adjacent_change_commit (dst->remote_dev, lowerdev, dev); -if (lowerdev && lowerdev != dst->remote_dev) - dst->remote_dev = lowerdev; +if (lowerdev_changed) { +if (lowerdev) +netdev_adjacent_change_commit (vxlan->lowerdev, lowerdev, + dev); +else +netdev_upper_dev_unlink (vxlan->lowerdev, dev); + vxlan->lowerdev = lowerdev; + }vxlan_config_apply (dev, new_cfg, lowerdev, vxlan->net, true);
[ ... ]
Quoted 24 lines
drivers/net/vxlan/vxlan_vnifilter.c +8
-3@@ -487,24 +487,31 @@ static const struct nla_policy vni_filter_policy[VXLAN_VNIFILTER_MAX + 1] = { };static int vxlan_update_default_fdb_entry (struct vxlan_dev *vxlan,__be32 vni, -union vxlan_addr *old_remote_ip, -union vxlan_addr *remote_ip, +const union vxlan_addr *old_remote_ip, +const union vxlan_addr *remote_ip, +u32 old_ifindex,u32 new_ifindex,struct netlink_ext_ack *extack) {const struct vxlan_config *cfg =rtnl_dereference (vxlan->cfg); -struct vxlan_rdst *dst = &vxlan->default_dst;int err =0 ; +if (old_remote_ip && remote_ip && +vxlan_addr_equal (old_remote_ip, remote_ip) && + old_ifindex == new_ifindex) +return 0 ; +
[ ... ]
Quoted 9 lines
drivers/net/vxlan/vxlan_vnifilter.c +2
-0@@ -563,6 +570,8 @@ static int vxlan_vni_update_group(struct vxlan_dev *vxlan, ret =vxlan_update_default_fdb_entry (vxlan, vninode->vni, oldrip, newrip, + cfg->remote_ifindex, + cfg->remote_ifindex, extack);if (ret) goto out;
[ ... ]
drivers/net/vxlan/vxlan_vnifilter.c int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, · line 633
Quoted 9 lines
drivers/net/vxlan/vxlan_vnifilter.c +2
-0@@ -616,6 +626,8 @@ int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, ret =vxlan_update_default_fdb_entry (vxlan, vent->vni, old_remote_ip, new_remote_ip, + old_ifindex, + new_ifindex, extack);if (ret)return ret;
[Severity: Medium]
Is the new ifindex refresh complete for VNI entries that carry their own group address?
The loop in vxlan_vnilist_update_group() only visits nodes whose remote_ip is "any":
if (vxlan_addr_any(&vent->remote_ip)) {
ret = vxlan_update_default_fdb_entry(...);But vxlan_vni_update_group() creates entries with an explicit group using the device configuration ifindex, as seen in the hunk above (cfg->remote_ifindex passed for both old and new), so those rdsts also store the device's remote_ifindex and are skipped here. After a changelink that alters remote_ifindex, vxlan_config_apply() publishes the new cfg while those rdsts keep the old value.
bridge vni add vni 100 group 239.1.1.1 dev vx # rdst ifindex = eth0
ip link set dev vxlan0 type vxlan dev eth1 # or IFLA_VXLAN_LINK = 0
bridge vni del vni 100 dev vx
vxlan_vni_delete_group() then calls __vxlan_fdb_delete() with the new cfg->remote_ifindex, and vxlan_fdb_find_rdst() requires an exact match:
if (vxlan_addr_equal(&rd->remote_ip, ip) && rd->remote_port == port && rd->remote_vni == vni && rd->remote_ifindex == ifindex) return rd;
so no rdst is found, __vxlan_fdb_delete() takes the "goto out; return 0" path and the all-zeros-MAC entry survives the vni delete. Re-adding the same vni appends a second rdst, duplicating transmitted BUM traffic. Meanwhile vxlan_xmit_one() keeps using the stale "ifindex = rdst->remote_ifindex" as route oif, and the vxlan_igmp_leave(vxlan, &vninode->remote_ip, 0) in the same function resolves rifindex 0 to the new cfg->remote_ifindex although the group was joined on the old one.
The IFLA_VXLAN_LINK = 0 variant looks newly broken: previously default_dst.remote_ifindex was left untouched when lowerdev was NULL, so the delete still matched. Given the commit message says default fdb entries "including VNI filter entries" are updated if remote_ifindex changed, should this loop also handle nodes with their own group?
Quoted 24 lines
drivers/net/vxlan/vxlan_vnifilter.c +3
-4@@ -630,20 +642,19 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan, {struct vxlan_net *vn =net_generic (vxlan->net, vxlan_net_id);const struct vxlan_config *cfg =rtnl_dereference (vxlan->cfg); -struct vxlan_rdst *dst = &vxlan->default_dst;/* if per vni remote_ip not present, delete the * default dst remote_ip previously added for this vni */ if (!vxlan_addr_any (&vninode->remote_ip) || - !vxlan_addr_any (&dst->remote_ip)) { + !vxlan_addr_any (&cfg->remote_ip)) {spin_lock_bh (&vxlan->hash_lock);__vxlan_fdb_delete (vxlan, all_zeros_mac, (vxlan_addr_any (&vninode->remote_ip) ? - dst->remote_ip : vninode->remote_ip), + cfg->remote_ip : vninode->remote_ip), cfg->dst_port, vninode->vni, vninode->vni, - dst->remote_ifindex, + cfg->remote_ifindex, true);spin_unlock_bh (&vxlan->hash_lock); }
[ ... ]
include/net/vxlan.h struct vxlan_rdst { · line 209
Quoted 12 lines
include/net/vxlan.h +0
-1@@ -204,7 +204,6 @@ struct vxlan_rdst { u8 offloaded:1;__be32 remote_vni;u32 remote_ifindex; -struct net_device *remote_dev;struct list_head list;struct rcu_head rcu;struct dst_cache dst_cache;
[Severity: Low]
The commit message says:
Furthermore, several fields of struct vxlan_rdst (remote_dev, remote_port, offloaded, list, rcu, dst_cache) in default_dst were completely unused.
Is that accurate for remote_dev? In the baseline, default_dst.remote_dev was the only user of that field: vxlan_dev_create() assigned it ("dst->remote_dev = remote_dev;"), vxlan_changelink() compared it ("if (dst->remote_dev == lowerdev) lowerdev = NULL;") and passed it to netdev_adjacent_change_prepare()/commit()/abort(), and vxlan_dellink() used it for netdev_upper_dev_unlink(). The patch moves that active role to vxlan->lowerdev rather than removing dead state, and changes the surrounding changelink logic along the way.
Quoted 9 lines
include/net/vxlan.h +1
-1@@ -295,7 +294,7 @@ struct vxlan_dev {#endif struct net_device *dev;struct net *net;/* netns for packet i/o */ -struct vxlan_rdst default_dst;/* default destination */ +struct net_device *lowerdev;struct timer_list age_timer;spinlock_t hash_lock;
Paolo Abeni
maintainerRe: [PATCH v3 net-next 1/6] vxlan: vnifilter: use list_for_each_entry_rcu() in vxlan_vnifilter_dump_dev()
In reply to Jakub KicinskiQuoted 30 lines · Jakub Kicinski
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
vxlan: vnifilter: uselist_for_each_entry_rcu()invxlan_vnifilter_dump_dev()This switches the
vg->vni_listwalk invxlan_vnifilter_dump_dev()tolist_for_each_entry_rcu(), clears the saved VNI offset on the early return paths, and adds cb->args[2] to track the ifindex of the device currently being dumped so the VNI offset is reset when the device changes.Quoted 19 lines
drivers/net/vxlan/vxlan_vnifilter.c +2
-2@@ -333,22 +333,34 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev,struct sk_buff *skb, struct netlink_callback *cb) { - struct vxlan_vni_node *tmp, *v, *vbegin = NULL, *vend = NULL; + struct vxlan_vni_node *v, *vbegin = NULL, *vend = NULL;struct vxlan_dev *vxlan =netdev_priv (dev);struct tunnel_msg *new_tmsg, *tmsg; -int idx =0 , s_idx = cb->args[1 ];struct vxlan_vni_group *vg;struct nlmsghdr *nlh; +int idx =0 , s_idx;bool dump_stats;int err =0 ;
Quoted 11 lines
drivers/net/vxlan/vxlan_vnifilter.c static int vxlan_vnifilter_dump_dev(const struct net_device *dev, · line 349
Quoted 6 lines
drivers/net/vxlan/vxlan_vnifilter.c +5
-1-if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +if (cb->args[2 ] != dev->ifindex) { + cb->args[1 ] =0 ; + cb->args[2 ] = dev->ifindex; + } + s_idx = cb->args[1 ];[Severity: High]
The commit message says the ifindex tracking handles the case where "devices are added or removed between dump calls, ordinal device indexes can shift". Can this new check actually observe that case?
I think this is the only comment possibly actionable. AFAICS addressing sashiko comments for good would require a significant refactor switching to ifindex based index. That in turn feels slightly overkill.
Possibly implementing a nl_dump_check_consistent() check would make sense?
/P
Re: [PATCH v3 net-next 1/6] vxlan: vnifilter: use list_for_each_entry_rcu() in vxlan_vnifilter_dump_dev()
Quoted 44 lines · Paolo Abeni
Quoted 30 lines · Jakub Kicinski
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
vxlan: vnifilter: uselist_for_each_entry_rcu()invxlan_vnifilter_dump_dev()This switches the
vg->vni_listwalk invxlan_vnifilter_dump_dev()tolist_for_each_entry_rcu(), clears the saved VNI offset on the early return paths, and adds cb->args[2] to track the ifindex of the device currently being dumped so the VNI offset is reset when the device changes.Quoted 19 lines
drivers/net/vxlan/vxlan_vnifilter.c +2
-2@@ -333,22 +333,34 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev,struct sk_buff *skb, struct netlink_callback *cb) { - struct vxlan_vni_node *tmp, *v, *vbegin = NULL, *vend = NULL; + struct vxlan_vni_node *v, *vbegin = NULL, *vend = NULL;struct vxlan_dev *vxlan =netdev_priv (dev);struct tunnel_msg *new_tmsg, *tmsg; -int idx =0 , s_idx = cb->args[1 ];struct vxlan_vni_group *vg;struct nlmsghdr *nlh; +int idx =0 , s_idx;bool dump_stats;int err =0 ;Quoted 11 lines
drivers/net/vxlan/vxlan_vnifilter.c static int vxlan_vnifilter_dump_dev(const struct net_device *dev, · line 349
Quoted 6 lines
drivers/net/vxlan/vxlan_vnifilter.c +5
-1-if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +if (cb->args[2 ] != dev->ifindex) { + cb->args[1 ] =0 ; + cb->args[2 ] = dev->ifindex; + } + s_idx = cb->args[1 ];[Severity: High]
The commit message says the ifindex tracking handles the case where "devices are added or removed between dump calls, ordinal device indexes can shift". Can this new check actually observe that case?
Quoted 5 lines
I think this is the only comment possibly actionable. AFAICS addressing sashiko comments for good would require a significant refactor switching to ifindex based index. That in turn feels slightly overkill.
Possibly implementing a
nl_dump_check_consistent()check would make sense?
I started looking at this and added a patch after the first one to implement this idea.
Thanks.