From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, edumazet@google.com,
pabeni@redhat.com, dsahern@kernel.org, horms@kernel.org,
Willem de Bruijn <willemb@google.com>
Subject: [PATCH net-next v2 2/7] net: initialize mark in sockcm_init
Date: Tue, 11 Feb 2025 21:09:48 -0500 [thread overview]
Message-ID: <20250212021142.1497449-3-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20250212021142.1497449-1-willemdebruijn.kernel@gmail.com>
From: Willem de Bruijn <willemb@google.com>
Avoid open coding initialization of sockcm fields.
Avoid reading the sk_priority field twice.
This ensures all callers, existing and future, will correctly try a
cmsg passed mark before sk_mark.
This patch extends support for cmsg mark to:
packet_spkt and packet_tpacket and net/can/raw.c.
This patch extends support for cmsg priority to:
packet_spkt and packet_tpacket.
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
include/net/sock.h | 1 +
net/can/raw.c | 2 +-
net/packet/af_packet.c | 9 ++++-----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 8036b3b79cd8..767a60e80086 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1828,6 +1828,7 @@ static inline void sockcm_init(struct sockcm_cookie *sockc,
const struct sock *sk)
{
*sockc = (struct sockcm_cookie) {
+ .mark = READ_ONCE(sk->sk_mark),
.tsflags = READ_ONCE(sk->sk_tsflags),
.priority = READ_ONCE(sk->sk_priority),
};
diff --git a/net/can/raw.c b/net/can/raw.c
index 46e8ed9d64da..9b1d5f036f57 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -963,7 +963,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
skb->dev = dev;
skb->priority = sockc.priority;
- skb->mark = READ_ONCE(sk->sk_mark);
+ skb->mark = sockc.mark;
skb->tstamp = sockc.transmit_time;
skb_setup_tx_timestamp(skb, &sockc);
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c131e5ceea37..3e9ddf72cd03 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2102,8 +2102,8 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
skb->protocol = proto;
skb->dev = dev;
- skb->priority = READ_ONCE(sk->sk_priority);
- skb->mark = READ_ONCE(sk->sk_mark);
+ skb->priority = sockc.priority;
+ skb->mark = sockc.mark;
skb_set_delivery_type_by_clockid(skb, sockc.transmit_time, sk->sk_clockid);
skb_setup_tx_timestamp(skb, &sockc);
@@ -2634,8 +2634,8 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
skb->protocol = proto;
skb->dev = dev;
- skb->priority = READ_ONCE(po->sk.sk_priority);
- skb->mark = READ_ONCE(po->sk.sk_mark);
+ skb->priority = sockc->priority;
+ skb->mark = sockc->mark;
skb_set_delivery_type_by_clockid(skb, sockc->transmit_time, po->sk.sk_clockid);
skb_setup_tx_timestamp(skb, sockc);
skb_zcopy_set_nouarg(skb, ph.raw);
@@ -3039,7 +3039,6 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
goto out_unlock;
sockcm_init(&sockc, sk);
- sockc.mark = READ_ONCE(sk->sk_mark);
if (msg->msg_controllen) {
err = sock_cmsg_send(sk, msg, &sockc);
if (unlikely(err))
--
2.48.1.502.g6dc24dfdaf-goog
next prev parent reply other threads:[~2025-02-12 2:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 2:09 [PATCH net-next v2 0/7] net: deduplicate cookie logic Willem de Bruijn
2025-02-12 2:09 ` [PATCH net-next v2 1/7] tcp: only initialize sockcm tsflags field Willem de Bruijn
2025-02-12 2:09 ` Willem de Bruijn [this message]
2025-02-13 14:48 ` [PATCH net-next v2 2/7] net: initialize mark in sockcm_init Paolo Abeni
2025-02-13 15:35 ` Willem de Bruijn
2025-02-13 18:12 ` Paolo Abeni
2025-02-12 2:09 ` [PATCH net-next v2 3/7] ipv4: initialize inet socket cookies with sockcm_init Willem de Bruijn
2025-02-12 2:09 ` [PATCH net-next v2 4/7] ipv4: remove get_rttos Willem de Bruijn
2025-02-13 15:10 ` Paolo Abeni
2025-02-13 16:23 ` Willem de Bruijn
2025-02-13 16:29 ` Willem de Bruijn
2025-02-13 17:23 ` Paolo Abeni
2025-02-12 2:09 ` [PATCH net-next v2 5/7] icmp: reflect tos through ip cookie rather than updating inet_sk Willem de Bruijn
2025-02-12 2:09 ` [PATCH net-next v2 6/7] ipv6: replace ipcm6_init calls with ipcm6_init_sk Willem de Bruijn
2025-02-12 2:09 ` [PATCH net-next v2 7/7] ipv6: initialize inet socket cookies with sockcm_init Willem de Bruijn
2025-02-12 20:11 ` [PATCH net-next v2 0/7] net: deduplicate cookie logic David Ahern
2025-02-14 21:06 ` Jakub Kicinski
2025-02-14 22:34 ` Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250212021142.1497449-3-willemdebruijn.kernel@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).