Skip to content

Commit 0962085

Browse files
wdebruijkuba-moo
authored andcommitted
ipv6: replace ipcm6_init calls with ipcm6_init_sk
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 <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e848591 commit 0962085

File tree

4 files changed

+3
-29
lines changed

4 files changed

+3
-29
lines changed

include/net/ipv6.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,6 @@ struct ipcm6_cookie {
363363
struct ipv6_txoptions *opt;
364364
};
365365

366-
static inline void ipcm6_init(struct ipcm6_cookie *ipc6)
367-
{
368-
*ipc6 = (struct ipcm6_cookie) {
369-
.hlimit = -1,
370-
.tclass = -1,
371-
.dontfrag = -1,
372-
};
373-
}
374-
375366
static inline void ipcm6_init_sk(struct ipcm6_cookie *ipc6,
376367
const struct sock *sk)
377368
{

net/ipv6/raw.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
777777
fl6.flowi6_mark = READ_ONCE(sk->sk_mark);
778778
fl6.flowi6_uid = sk->sk_uid;
779779

780-
ipcm6_init(&ipc6);
780+
ipcm6_init_sk(&ipc6, sk);
781781
ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags);
782782
ipc6.sockc.mark = fl6.flowi6_mark;
783783
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)
891891
if (hdrincl)
892892
fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH;
893893

894-
if (ipc6.tclass < 0)
895-
ipc6.tclass = np->tclass;
896-
897894
fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
898895

899896
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)
904901
if (ipc6.hlimit < 0)
905902
ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
906903

907-
if (ipc6.dontfrag < 0)
908-
ipc6.dontfrag = inet6_test_bit(DONTFRAG, sk);
909-
910904
if (msg->msg_flags&MSG_CONFIRM)
911905
goto do_confirm;
912906

net/ipv6/udp.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
14941494
int is_udplite = IS_UDPLITE(sk);
14951495
int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
14961496

1497-
ipcm6_init(&ipc6);
1497+
ipcm6_init_sk(&ipc6, sk);
14981498
ipc6.gso_size = READ_ONCE(up->gso_size);
14991499
ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags);
15001500
ipc6.sockc.mark = READ_ONCE(sk->sk_mark);
@@ -1704,9 +1704,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
17041704

17051705
security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6));
17061706

1707-
if (ipc6.tclass < 0)
1708-
ipc6.tclass = np->tclass;
1709-
17101707
fl6->flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6->flowlabel);
17111708

17121709
dst = ip6_sk_dst_lookup_flow(sk, fl6, final_p, connected);
@@ -1752,8 +1749,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
17521749
WRITE_ONCE(up->pending, AF_INET6);
17531750

17541751
do_append_data:
1755-
if (ipc6.dontfrag < 0)
1756-
ipc6.dontfrag = inet6_test_bit(DONTFRAG, sk);
17571752
up->len += ulen;
17581753
err = ip6_append_data(sk, getfrag, msg, ulen, sizeof(struct udphdr),
17591754
&ipc6, fl6, dst_rt6_info(dst),

net/l2tp/l2tp_ip6.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
547547
fl6.flowi6_mark = READ_ONCE(sk->sk_mark);
548548
fl6.flowi6_uid = sk->sk_uid;
549549

550-
ipcm6_init(&ipc6);
550+
ipcm6_init_sk(&ipc6, sk);
551551

552552
if (lsa) {
553553
if (addr_len < SIN6_LEN_RFC2133)
@@ -634,9 +634,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
634634

635635
security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6));
636636

637-
if (ipc6.tclass < 0)
638-
ipc6.tclass = np->tclass;
639-
640637
fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
641638

642639
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)
648645
if (ipc6.hlimit < 0)
649646
ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst);
650647

651-
if (ipc6.dontfrag < 0)
652-
ipc6.dontfrag = inet6_test_bit(DONTFRAG, sk);
653-
654648
if (msg->msg_flags & MSG_CONFIRM)
655649
goto do_confirm;
656650

0 commit comments

Comments
 (0)