🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Antonio Quartulli Mon, 16 Nov 2026 20:08
[PATCH net-next] net: use inet_rcv_saddr_any() in udp_tunnel and ping
#17444
Author: Antonio Quartulli
Date: Mon, 16 Nov 2026 20:08
141 lines
13549 bytes
udp_tunnel_core.c carries its own copy of inet_rcv_saddr_any(),
sk_saddr_any(), as it can be built as a module while
inet_rcv_saddr_any() is not exported, and ping_bind() open-codes the
same check for its AF_INET and AF_INET6 sockets.

Make inet_rcv_saddr_any() a static inline in <net/addrconf.h>, where it
is already declared, and use it in both places.

Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://lore.kernel.org/netdev/avVVzxL3pVZc6yQ5@google.com/
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---

@Kuniyuki:
the helper can't go to <net/sock.h> as suggested, since it needs
ipv6_addr_any() and <net/ipv6.h> includes <net/sock.h>.
I hope <net/addrconf.h> is fine too.


 include/net/addrconf.h          | 12 +++++++++++-
 net/ipv4/inet_connection_sock.c |  9 ---------
 net/ipv4/ping.c                 |  8 ++------
 net/ipv4/udp_tunnel_core.c      | 12 ++----------
 4 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/include/net/addrconf.h b/include/net/addrconf.h
index 6818057cf727..0ec4db881404 100644
--- a/include/net/addrconf.h
+++ b/include/net/addrconf.h
@@ -149,7 +149,17 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
 		    u32 banned_flags);
 bool inet_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2,
 			  bool match_wildcard);
-bool inet_rcv_saddr_any(const struct sock *sk);
+
+/* whether @sk is bound to the wildcard address of its family */
+static inline bool inet_rcv_saddr_any(const struct sock *sk)
+{
+#if IS_ENABLED(CONFIG_IPV6)
+	if (sk->sk_family == AF_INET6)
+		return ipv6_addr_any(&sk->sk_v6_rcv_saddr);
+#endif
+	return !sk->sk_rcv_saddr;
+}
+
 void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr);
 void addrconf_leave_solict(struct inet6_dev *idev, const struct in6_addr *addr);
 
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 5807067083c9..c6f7c3550013 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -109,15 +109,6 @@ bool inet_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2,
 				    match_wildcard);
 }
 
-bool inet_rcv_saddr_any(const struct sock *sk)
-{
-#if IS_ENABLED(CONFIG_IPV6)
-	if (sk->sk_family == AF_INET6)
-		return ipv6_addr_any(&sk->sk_v6_rcv_saddr);
-#endif
-	return !sk->sk_rcv_saddr;
-}
-
 /**
  *	inet_sk_get_local_port_range - fetch ephemeral ports range
  *	@sk: socket
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 223a0108b74c..ceb0af8c70a3 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -40,11 +40,11 @@
 #include <net/route.h>
 #include <net/inet_common.h>
 #include <net/checksum.h>
+#include <net/addrconf.h>
 
 #if IS_ENABLED(CONFIG_IPV6)
 #include <linux/in6.h>
 #include <linux/icmpv6.h>
-#include <net/addrconf.h>
 #include <net/ipv6.h>
 #include <net/transp_v6.h>
 #endif
@@ -439,12 +439,8 @@ int ping_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len)
 		 sk->sk_bound_dev_if);
 
 	err = 0;
-	if (sk->sk_family == AF_INET && isk->inet_rcv_saddr)
+	if (!inet_rcv_saddr_any(sk))
 		sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
-#if IS_ENABLED(CONFIG_IPV6)
-	if (sk->sk_family == AF_INET6 && !ipv6_addr_any(&sk->sk_v6_rcv_saddr))
-		sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
-#endif
 
 	if (snum)
 		sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c
index 29581c94fdcf..c2888aa2bbe6 100644
--- a/net/ipv4/udp_tunnel_core.c
+++ b/net/ipv4/udp_tunnel_core.c
@@ -3,6 +3,7 @@
 #include <linux/errno.h>
 #include <linux/socket.h>
 #include <linux/kernel.h>
+#include <net/addrconf.h>
 #include <net/dst_metadata.h>
 #include <net/flow.h>
 #include <net/udp.h>
@@ -59,15 +60,6 @@ int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
 }
 EXPORT_SYMBOL(udp_sock_create4);
 
-static bool sk_saddr_any(struct sock *sk)
-{
-#if IS_ENABLED(CONFIG_IPV6)
-	if (sk->sk_family == AF_INET6)
-		return ipv6_addr_any(&sk->sk_v6_rcv_saddr);
-#endif
-	return !sk->sk_rcv_saddr;
-}
-
 void setup_udp_tunnel_sock(struct net *net, struct sock *sk,
 			   struct udp_tunnel_sock_cfg *cfg)
 {
@@ -91,7 +83,7 @@ void setup_udp_tunnel_sock(struct net *net, struct sock *sk,
 
 	udp_tunnel_update_gro_rcv(sk, true);
 
-	if (!sk->sk_dport && !sk->sk_bound_dev_if && sk_saddr_any(sk) &&
+	if (!sk->sk_dport && !sk->sk_bound_dev_if && inet_rcv_saddr_any(sk) &&
 	    sk->sk_kern_sock)
 		udp_tunnel_update_gro_lookup(net, sk, true);
 }

base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
-- 
2.56.1
Re: [PATCH net-next] net: use inet_rcv_saddr_any() in udp_tunnel and ping
#19507
Author: patchwork-bot+netdevbpf
Date: Fri, 20 Nov 2026 00:30
25 lines
8702 bytes
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 16 Nov 2026 21:08:53 +0100 you wrote:
> udp_tunnel_core.c carries its own copy of inet_rcv_saddr_any(),
> sk_saddr_any(), as it can be built as a module while
> inet_rcv_saddr_any() is not exported, and ping_bind() open-codes the
> same check for its AF_INET and AF_INET6 sockets.
> 
> Make inet_rcv_saddr_any() a static inline in <net/addrconf.h>, where it
> is already declared, and use it in both places.
> 
> [...]

Here is the summary with links:
  - [net-next] net: use inet_rcv_saddr_any() in udp_tunnel and ping
    https://git.kernel.org/netdev/net-next/c/03c18e3989c4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads