vxlan_snoop() handles a known MAC that now arrives from another remote by rewriting the remote's IP address in place. It leaves the remote's dst_cache alone, so the next packet to that MAC is routed with the dst cached for the previous remote. When the two remotes have different next hops, the packet leaves the wrong way. For example, if the previous remote was on-link and the new one is behind a router, the device resolves the new remote's address on the local link, the neighbour stays incomplete, and traffic to the MAC is blackholed until the cached route is invalidated, such as by "ip route flush cache". The same branch also leaves remote_ifindex unchanged, although the early return compares it and vxlan_xmit_one() uses it as the output interface. When a MAC moves between an IPv6 link-local and another address, the remote keeps the previous interface, and every later packet from that remote enters the migration branch again. vxlan_fdb_replace(), which makes the same change through netlink, already resets the cache, updates remote_ifindex and clears offloaded. Do the same when snooping. vxlan_snoop() knows the interface only for IPv6 link-local sources and uses 0 for all others, but the early return compares remote_ifindex for every source. A packet from the remote of a dynamic entry that was added with a "via" device therefore enters the migration branch as well, which would now reset the device to 0. Compare remote_ifindex only for link-local sources. Two CPUs can snoop the same MAC from different remotes at the same time, and the plain stores to remote_ip and remote_ifindex can then mix, for example a global address with the interface of a link-local one. With the early return above, such an entry is never repaired. Update the remote under vxlan->hash_lock, which vxlan_fdb_replace() and the other writers of these fields hold, and check the entry again once the lock is held. The selftest added in the next patch moves a MAC from an on-link IPv4 remote to one behind a router, and from a global IPv6 remote to a link-local one. Both cases fail without this patch and pass with it. A third case checks that the "via" device of a dynamic entry stays set when its remote sends traffic. This was found by our AI-driven automated live migration tests. The fix and this changelog were written with the help of an AI coding assistant. Fixes: 0c1d70af924b ("net: use dst_cache for vxlan device") Fixes: 87613de95041 ("vxlan: fix snooping for link-local IPv6 addresses") Signed-off-by: Zhefu Peng --- drivers/net/vxlan/vxlan_core.c | 59 +++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index d11028b37..8738be39e 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1434,6 +1434,51 @@ static int vxlan_fdb_get(struct sk_buff *skb, return err; } +static bool vxlan_snoop_same_remote(const struct vxlan_rdst *rdst, + const union vxlan_addr *src_ip, + u32 ifindex) +{ + return vxlan_addr_equal(&rdst->remote_ip, src_ip) && + (!ifindex || rdst->remote_ifindex == ifindex); +} + +static enum skb_drop_reason vxlan_snoop_move(struct net_device *dev, + struct vxlan_fdb *f, + const u8 *src_mac, + union vxlan_addr *src_ip, + u32 ifindex) +{ + struct vxlan_dev *vxlan = netdev_priv(dev); + struct vxlan_rdst *rdst; + + lockdep_assert_held(&vxlan->hash_lock); + + /* The entry may have changed before the lock was taken */ + if (hlist_unhashed(&f->fdb_node)) + return SKB_NOT_DROPPED_YET; + + if (rcu_access_pointer(f->nh) || + (f->state & (NUD_PERMANENT | NUD_NOARP))) + return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; + + rdst = first_remote_rcu(f); + if (vxlan_snoop_same_remote(rdst, src_ip, ifindex)) + return SKB_NOT_DROPPED_YET; + + if (net_ratelimit()) + netdev_info(dev, + "%pM migrated from %pIS to %pIS\n", + src_mac, &rdst->remote_ip.sa, &src_ip->sa); + + dst_cache_reset(&rdst->dst_cache); + rdst->remote_ip = *src_ip; + rdst->remote_ifindex = ifindex; + rdst->offloaded = false; + vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, true, NULL); + + return SKB_NOT_DROPPED_YET; +} + /* Watch incoming packets to learn mapping between Ethernet address * and Tunnel endpoint. */ @@ -1461,6 +1506,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, if (likely(f)) { struct vxlan_rdst *rdst = first_remote_rcu(f); unsigned long now = jiffies; + enum skb_drop_reason reason; if (READ_ONCE(f->updated) != now) WRITE_ONCE(f->updated, now); @@ -1469,21 +1515,18 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, if (rcu_access_pointer(f->nh)) return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; - if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) && - rdst->remote_ifindex == ifindex)) + if (likely(vxlan_snoop_same_remote(rdst, src_ip, ifindex))) return SKB_NOT_DROPPED_YET; /* Don't migrate static entries, drop packets */ if (f->state & (NUD_PERMANENT | NUD_NOARP)) return SKB_DROP_REASON_VXLAN_ENTRY_EXISTS; - if (net_ratelimit()) - netdev_info(dev, - "%pM migrated from %pIS to %pIS\n", - src_mac, &rdst->remote_ip.sa, &src_ip->sa); + spin_lock(&vxlan->hash_lock); + reason = vxlan_snoop_move(dev, f, src_mac, src_ip, ifindex); + spin_unlock(&vxlan->hash_lock); - rdst->remote_ip = *src_ip; - vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, true, NULL); + return reason; } else { /* learned new entry */ spin_lock(&vxlan->hash_lock); -- 2.54.0