net: use inet_rcv_saddr_any() in udp_tunnel and ping
Subsystems (4)
PATCH 1/1 net: use inet_rcv_saddr_any() in udp_tunnel and ping
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.
---
@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(-)
include/net/addrconf.h +11 -1
@@ -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);
net/ipv4/inet_connection_sock.c +0 -9
@@ -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
net/ipv4/ping.c +2 -6
@@ -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 ;
net/ipv4/udp_tunnel_core.c +2 -10
@@ -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
Signature · 1 line
2.56.1
Quoted 11 lines · Antonio Quartulli
udp_tunnel_core.ccarries its own copy ofinet_rcv_saddr_any(),sk_saddr_any(), as it can be built as a module whileinet_rcv_saddr_any()is not exported, andping_bind()open-codes the same check for itsAF_INETandAF_INET6sockets.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 <[email protected]>Signed-off-by Antonio Quartulli <[email protected]>
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 16 Nov 2026 21:08:53 +0100 you wrote:
udp_tunnel_core.ccarries its own copy ofinet_rcv_saddr_any(),sk_saddr_any(), as it can be built as a module whileinet_rcv_saddr_any()is not exported, andping_bind()open-codes the same check for itsAF_INETandAF_INET6sockets.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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html