Re: [PATCH] ipv4/raw: support binding to nonlocal addresses
From: David Ahern <hidden>
Date: 2021-03-21 17:07:09
Also in:
lkml
On 3/20/21 6:20 PM, Riccardo Paolo Bestetti wrote:
quoted hunk ↗ jump to hunk
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 50a73178d63a..734c0332b54b 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c@@ -717,6 +717,7 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) { struct inet_sock *inet = inet_sk(sk); struct sockaddr_in *addr = (struct sockaddr_in *) uaddr; + struct net *net = sock_net(sk); u32 tb_id = RT_TABLE_LOCAL; int ret = -EINVAL; int chk_addr_ret;@@ -732,7 +733,8 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) tb_id); ret = -EADDRNOTAVAIL; - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL && + if (!inet_can_nonlocal_bind(net, inet) && + addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL && chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) goto out; inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
Please add test cases to ipv4_addr_bind and ipv6_addr_bind in tools/testing/selftests/net/fcnal-test.sh. The latter will verify if IPv6 works the same or needs a change. Also, this check duplicates the ones in __inet_bind and __inet6_bind; it would be good to use an inline helper to reduce the duplication.