Re: [PATCH net-next v2 1/2] net: vxlan: enable local address bind for vxlan sockets

From: Simon Horman
Date: Tue Jul 09 2024 - 08:09:36 EST


On Mon, Jul 08, 2024 at 01:11:02PM +0200, Richard Gobert wrote:
> This patch adds support for binding to a local address in vxlan sockets.
> It achieves this by using vxlan_addr union to represent a local address
> to bind to, and copying it to udp_port_cfg in vxlan_create_sock.
>
> Also change vxlan_find_sock to search the socket based on the listening address.
>
> Signed-off-by: Richard Gobert <richardbgobert@xxxxxxxxx>
> ---
> drivers/net/vxlan/vxlan_core.c | 53 ++++++++++++++++++++++++----------
> 1 file changed, 38 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
> index ba59e92ab941..9a797147beb7 100644
> --- a/drivers/net/vxlan/vxlan_core.c
> +++ b/drivers/net/vxlan/vxlan_core.c
> @@ -72,22 +72,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).
> + * bounded 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)

nit: Where it can trivially be achieved, please limit lines to 80 columns
wide as is still preferred in Networking code.

Flagged by ./scripts/checkpatch.pl --max-line-length=80

> {
> 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);
> +
> + if (inet->inet_sport == port &&
> vxlan_get_sk_family(vs) == family &&
> vs->flags == flags &&
> - vs->sock->sk->sk_bound_dev_if == ifindex)
> - return vs;
> + vs->sock->sk->sk_bound_dev_if == ifindex) {
> + if (family == AF_INET && inet->inet_rcv_saddr == saddr->sin.sin_addr.s_addr) {
> + return vs;
> + }
> +#if IS_ENABLED(CONFIG_IPV6)
> + else if (ipv6_addr_cmp(&sk->sk_v6_rcv_saddr, &saddr->sin6.sin6_addr) == 0)

1. There is a '{' missing form the line above, so this doesn't compile
(if IPV6 is configured).
2. Probably the '{}' can be dropped from this if / else if conditional.

> + return vs;
> + }
> +#endif
> + }
> +
> }
> return NULL;
> }

--
pw-bot: changes-requested