Re: [PATCH net-next v5 3/5] net: vxlan: bind vxlan sockets to their local address if configured
From: Ido Schimmel
Date: Wed Aug 13 2025 - 05:28:53 EST
On Tue, Aug 12, 2025 at 02:51:53PM +0200, Richard Gobert wrote:
> Bind VXLAN sockets to the local addresses if the IFLA_VXLAN_LOCALBIND
> option is set. This is the new default.
Drop the last sentence?
>
> Change vxlan_find_sock to search for the socket using the listening
> address.
>
> This is implemented by copying the VXLAN local address to the udp_port_cfg
> passed to udp_sock_create. The freebind option is set because VXLAN
> interfaces may be UP before their outgoing interface is.
>
> This fixes multiple VXLAN selftests that fail because of that race.
This sentence is no longer relevant as well.
>
> Signed-off-by: Richard Gobert <richardbgobert@xxxxxxxxx>
> ---
> drivers/net/vxlan/vxlan_core.c | 59 ++++++++++++++++++++++++++--------
> 1 file changed, 46 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
> index 15fe9d83c724..12da9595436e 100644
> --- a/drivers/net/vxlan/vxlan_core.c
> +++ b/drivers/net/vxlan/vxlan_core.c
> @@ -78,18 +78,34 @@ static inline bool vxlan_collect_metadata(struct vxlan_sock *vs)
> }
>
> /* Find VXLAN socket based on network namespace, address family, UDP port,
> - * enabled unshareable flags and socket device binding (see l3mdev with
> - * non-default VRF).
> + * bound address, enabled unshareable flags and socket device binding
> + * (see l3mdev with non-default VRF).
> */
> static struct vxlan_sock *vxlan_find_sock(struct net *net, sa_family_t family,
> - __be16 port, u32 flags, int ifindex)
> + __be16 port, u32 flags, int ifindex,
> + union vxlan_addr *saddr)
> {
> struct vxlan_sock *vs;
>
> flags &= VXLAN_F_RCV_FLAGS;
>
> hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) {
> - if (inet_sk(vs->sock->sk)->inet_sport == port &&
> + struct sock *sk = vs->sock->sk;
> + struct inet_sock *inet = inet_sk(sk);
https://docs.kernel.org/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs
> +
> + if (flags & VXLAN_F_LOCALBIND) {
> + if (family == AF_INET &&
> + inet->inet_rcv_saddr != saddr->sin.sin_addr.s_addr)
> + continue;
> +#if IS_ENABLED(CONFIG_IPV6)
> + else if (family == AF_INET6 &&
> + ipv6_addr_cmp(&sk->sk_v6_rcv_saddr,
> + &saddr->sin6.sin6_addr) != 0)
> + continue;
> +#endif
> + }
> +
> + if (inet->inet_sport == port &&
> vxlan_get_sk_family(vs) == family &&
> vs->flags == flags &&
> vs->sock->sk->sk_bound_dev_if == ifindex)