Skip to content

Commit

Permalink
ipv6: initialize inet socket cookies with sockcm_init
Browse files Browse the repository at this point in the history
Avoid open coding the same logic.

Signed-off-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20250214222720.3205500-8-willemdebruijn.kernel@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Willem de Bruijn authored and Jakub Kicinski committed Feb 19, 2025
1 parent 0962085 commit 5cd2f78
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/net/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ static inline void ipcm6_init_sk(struct ipcm6_cookie *ipc6,
.tclass = inet6_sk(sk)->tclass,
.dontfrag = inet6_test_bit(DONTFRAG, sk),
};

sockcm_init(&ipc6->sockc, sk);
}

static inline struct ipv6_txoptions *txopt_get(const struct ipv6_pinfo *np)
Expand Down
3 changes: 0 additions & 3 deletions net/ipv6/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
return -EINVAL;

ipcm6_init_sk(&ipc6, sk);
ipc6.sockc.priority = READ_ONCE(sk->sk_priority);
ipc6.sockc.tsflags = READ_ONCE(sk->sk_tsflags);
ipc6.sockc.mark = READ_ONCE(sk->sk_mark);

fl6.flowi6_oif = oif;

Expand Down
9 changes: 3 additions & 6 deletions net/ipv6/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,19 +769,16 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)

hdrincl = inet_test_bit(HDRINCL, sk);

ipcm6_init_sk(&ipc6, sk);

/*
* Get and verify the address.
*/
memset(&fl6, 0, sizeof(fl6));

fl6.flowi6_mark = READ_ONCE(sk->sk_mark);
fl6.flowi6_mark = ipc6.sockc.mark;
fl6.flowi6_uid = sk->sk_uid;

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);

if (sin6) {
if (addr_len < SIN6_LEN_RFC2133)
return -EINVAL;
Expand Down
3 changes: 0 additions & 3 deletions net/ipv6/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,9 +1496,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)

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);
ipc6.sockc.priority = READ_ONCE(sk->sk_priority);

/* destination address check */
if (sin6) {
Expand Down

0 comments on commit 5cd2f78

Please sign in to comment.