]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ipv6: make ipv6_pinfo.saddr_cache a boolean
authorEric Dumazet <edumazet@google.com>
Tue, 16 Sep 2025 16:09:42 +0000 (16:09 +0000)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 18 Sep 2025 08:17:09 +0000 (10:17 +0200)
ipv6_pinfo.saddr_cache is either NULL or &np->saddr.

We do not need 8 bytes, a boolean is enough.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250916160951.541279-2-edumazet@google.com
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/linux/ipv6.h
include/net/ip6_route.h
net/ipv6/af_inet6.c
net/ipv6/inet6_connection_sock.c
net/ipv6/ip6_output.c
net/ipv6/route.c
net/ipv6/tcp_ipv6.c

index f43314517396777105cc20ba30cac9c651b7dbf9..55c4d1e4dd7df803440e3a3cf18245a495ad949b 100644 (file)
@@ -216,10 +216,10 @@ struct inet6_cork {
 struct ipv6_pinfo {
        struct in6_addr         saddr;
        struct in6_pktinfo      sticky_pktinfo;
-       const struct in6_addr           *daddr_cache;
 #ifdef CONFIG_IPV6_SUBTREES
-       const struct in6_addr           *saddr_cache;
+       bool                    saddr_cache;
 #endif
+       const struct in6_addr           *daddr_cache;
 
        __be32                  flow_label;
        __u32                   frag_size;
index 59f48ca3abdf5a8aef6b4ece13f9a1774fc04f38..223c02d4268858cd3f1c83f949877dabc17efbc8 100644 (file)
@@ -230,7 +230,7 @@ static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb)
  */
 static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
                                 const struct in6_addr *daddr,
-                                const struct in6_addr *saddr)
+                                bool saddr_set)
 {
        struct ipv6_pinfo *np = inet6_sk(sk);
 
@@ -238,7 +238,7 @@ static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
        sk_setup_caps(sk, dst);
        np->daddr_cache = daddr;
 #ifdef CONFIG_IPV6_SUBTREES
-       np->saddr_cache = saddr;
+       np->saddr_cache = saddr_set;
 #endif
 }
 
index 1992621e3f3f4b5b5c63e857b7b1c90576d3766e..c342f8daea7fa9469fa7f3a2d1f0a78572b9ae9a 100644 (file)
@@ -857,7 +857,7 @@ int inet6_sk_rebuild_header(struct sock *sk)
                        return PTR_ERR(dst);
                }
 
-               ip6_dst_store(sk, dst, NULL, NULL);
+               ip6_dst_store(sk, dst, NULL, false);
        }
 
        return 0;
index 333e43434dd78d73f960708a327c704a185e88d3..1947ccdb00df2301be1a8ce651d635dafd08c3b4 100644 (file)
@@ -91,7 +91,7 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk,
                dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
 
                if (!IS_ERR(dst))
-                       ip6_dst_store(sk, dst, NULL, NULL);
+                       ip6_dst_store(sk, dst, NULL, false);
        }
        return dst;
 }
index 9d64c13bab5eacb4cc05c78cccd86a7aeb36d37e..82ff6e1293d04dc9d69a661080cd0ae965cf766c 100644 (file)
@@ -1102,7 +1102,8 @@ static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
         */
        if (ip6_rt_check(&rt->rt6i_dst, &fl6->daddr, np->daddr_cache) ||
 #ifdef CONFIG_IPV6_SUBTREES
-           ip6_rt_check(&rt->rt6i_src, &fl6->saddr, np->saddr_cache) ||
+           ip6_rt_check(&rt->rt6i_src, &fl6->saddr,
+                        np->saddr_cache ? &np->saddr : NULL) ||
 #endif
           (fl6->flowi6_oif && fl6->flowi6_oif != dst_dev(dst)->ifindex)) {
                dst_release(dst);
index 3371f16b7a3e615bbb41ee0d1a7c9187a761fc0c..e1b0aebf8bf92b711581ddb5cde8d9a840e33036 100644 (file)
@@ -3036,9 +3036,9 @@ void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
                      &sk->sk_v6_daddr : NULL,
 #ifdef CONFIG_IPV6_SUBTREES
                      ipv6_addr_equal(&fl6->saddr, &np->saddr) ?
-                     &np->saddr :
+                     true :
 #endif
-                     NULL);
+                     false);
 }
 
 static bool ip6_redirect_nh_match(const struct fib6_result *res,
index 5f0a138f4220e9634d3df87a1fb652aa80291c1b..ecc3a87cd8c4bcc8cd9da79f602479ccdf697d61 100644 (file)
@@ -299,7 +299,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
        inet->inet_rcv_saddr = LOOPBACK4_IPV6;
 
        sk->sk_gso_type = SKB_GSO_TCPV6;
-       ip6_dst_store(sk, dst, NULL, NULL);
+       ip6_dst_store(sk, dst, NULL, false);
 
        icsk->icsk_ext_hdr_len = 0;
        if (opt)
@@ -1459,7 +1459,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
 
        memcpy(newnp, np, sizeof(struct ipv6_pinfo));
 
-       ip6_dst_store(newsk, dst, NULL, NULL);
+       ip6_dst_store(newsk, dst, NULL, false);
 
        newnp->saddr = ireq->ir_v6_loc_addr;