linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipv4/raw: support binding to nonlocal addresses
@ 2021-03-21  0:20 Riccardo Paolo Bestetti
  2021-03-21 17:06 ` David Ahern
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Riccardo Paolo Bestetti @ 2021-03-21  0:20 UTC (permalink / raw)
  Cc: Riccardo Paolo Bestetti, David S. Miller, Hideaki YOSHIFUJI,
	David Ahern, Jakub Kicinski, netdev, linux-kernel

Add support to inet raw sockets for binding to nonlocal addresses
through the IP_FREEBIND and IP_TRANSPARENT socket options, as well as
the ipv4.ip_nonlocal_bind kernel parameter.

Signed-off-by: Riccardo Paolo Bestetti <pbl@bestov.io>
---
 net/ipv4/raw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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;
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-11-18  4:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21  0:20 [PATCH] ipv4/raw: support binding to nonlocal addresses Riccardo Paolo Bestetti
2021-03-21 17:06 ` David Ahern
2021-11-02 14:19 ` [PATCH v2] " Riccardo Paolo Bestetti
2021-11-04 15:59   ` David Ahern
2021-11-04 17:34   ` Jakub Kicinski
2021-11-17  9:00   ` Riccardo Paolo Bestetti
2021-11-17 15:14     ` Denis Kirjanov
2021-11-18  0:14       ` Riccardo Paolo Bestetti
2021-11-18  3:59         ` David Ahern
2021-11-18  4:23           ` Jakub Kicinski
     [not found] ` <CFPVQWNG02LG.3DHWUZ0JCAMVS@enhorning>
2021-11-17  3:44   ` Jakub Kicinski
2021-11-17  8:05     ` Riccardo Paolo Bestetti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).