ipv6: replace ipcm6_init calls with ipcm6_init_sk
authorWillem de Bruijn <willemb@google.com>
Fri, 14 Feb 2025 22:27:03 +0000 (17:27 -0500)
committerJakub Kicinski <kuba@kernel.org>
Wed, 19 Feb 2025 02:27:20 +0000 (18:27 -0800)
This initializes tclass and dontfrag before cmsg parsing, removing the
need for explicit checks against -1 in each caller.

Leave hlimit set to -1, because its full initialization
(in ip6_sk_dst_hoplimit) requires more state (dst, flowi6, ..).

This also prepares for calling sockcm_init in a follow-on patch.

Signed-off-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20250214222720.3205500-7-willemdebruijn.kernel@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/ipv6.h
net/ipv6/raw.c
net/ipv6/udp.c
net/l2tp/l2tp_ip6.c

index f5c43ad..46a679d 100644 (file)
@@ -363,15 +363,6 @@ struct ipcm6_cookie {
        struct ipv6_txoptions *opt;
 };
 
-static inline void ipcm6_init(struct ipcm6_cookie *ipc6)
-{
-       *ipc6 = (struct ipcm6_cookie) {
-               .hlimit = -1,
-               .tclass = -1,
-               .dontfrag = -1,
-       };
-}
-
 static inline void ipcm6_init_sk(struct ipcm6_cookie *ipc6,
                                 const struct sock *sk)
 {
index a45aba0..ae68d3f 100644 (file)
@@ -777,7 +777,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
        fl6.flowi6_mark = READ_ONCE(sk->sk_mark);
        fl6.flowi6_uid = sk->sk_uid;
 
-       ipcm6_init(&ipc6);
+       ipcm6_init_sk(&ipc6, sk);
        ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags);
        ipc6.sockc.mark = fl6.flowi6_mark;
        ipc6.sockc.priority = READ_ONCE(sk->sk_priority);
@@ -891,9 +891,6 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
        if (hdrincl)
                fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH;
 
-       if (ipc6.tclass < 0)
-               ipc6.tclass = np->tclass;
-
        fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
 
        dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p);
@@ -904,9 +901,6 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
        if (ipc6.hlimit < 0)
                ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
 
-       if (ipc6.dontfrag < 0)
-               ipc6.dontfrag = inet6_test_bit(DONTFRAG, sk);
-
        if (msg->msg_flags&MSG_CONFIRM)
                goto do_confirm;
 
index c6ea438..7096b7e 100644 (file)
@@ -1494,7 +1494,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
        int is_udplite = IS_UDPLITE(sk);
        int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
 
-       ipcm6_init(&ipc6);
+       ipcm6_init_sk(&ipc6, sk);
        ipc6.gso_size = READ_ONCE(up->gso_size);
        ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags);
        ipc6.sockc.mark = READ_ONCE(sk->sk_mark);
@@ -1704,9 +1704,6 @@ do_udp_sendmsg:
 
        security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6));
 
-       if (ipc6.tclass < 0)
-               ipc6.tclass = np->tclass;
-
        fl6->flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6->flowlabel);
 
        dst = ip6_sk_dst_lookup_flow(sk, fl6, final_p, connected);
@@ -1752,8 +1749,6 @@ back_from_confirm:
        WRITE_ONCE(up->pending, AF_INET6);
 
 do_append_data:
-       if (ipc6.dontfrag < 0)
-               ipc6.dontfrag = inet6_test_bit(DONTFRAG, sk);
        up->len += ulen;
        err = ip6_append_data(sk, getfrag, msg, ulen, sizeof(struct udphdr),
                              &ipc6, fl6, dst_rt6_info(dst),
index f4c1da0..b98d135 100644 (file)
@@ -547,7 +547,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
        fl6.flowi6_mark = READ_ONCE(sk->sk_mark);
        fl6.flowi6_uid = sk->sk_uid;
 
-       ipcm6_init(&ipc6);
+       ipcm6_init_sk(&ipc6, sk);
 
        if (lsa) {
                if (addr_len < SIN6_LEN_RFC2133)
@@ -634,9 +634,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
        security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6));
 
-       if (ipc6.tclass < 0)
-               ipc6.tclass = np->tclass;
-
        fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
 
        dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p);
@@ -648,9 +645,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
        if (ipc6.hlimit < 0)
                ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
 
-       if (ipc6.dontfrag < 0)
-               ipc6.dontfrag = inet6_test_bit(DONTFRAG, sk);
-
        if (msg->msg_flags & MSG_CONFIRM)
                goto do_confirm;