From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, edumazet@google.com,
pabeni@redhat.com, Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH net-next 4/7] ipv4: remove get_rttos
Date: Thu, 06 Feb 2025 19:59:39 -0500 [thread overview]
Message-ID: <67a55afb822cc_25109e294cc@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20250206193521.2285488-5-willemdebruijn.kernel@gmail.com>
Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.com>
>
> Initialize the ip cookie tos field when initializing the cookie, in
> ipcm_init_sk.
>
> The existing code inverts the standard pattern for initializing cookie
> fields. Default is to initialize the field from the sk, then possibly
> overwrite that when parsing cmsgs (the unlikely case).
>
> This field inverts that, setting the field to an illegal value and
> after cmsg parsing checking whether the value is still illegal and
> thus should be overridden.
>
> Be careful to always apply mask INET_DSCP_MASK, as before.
>
> Signed-off-by: Willem de Bruijn <willemb@google.com>
> ---
> include/net/ip.h | 11 +++--------
> net/ipv4/ip_sockglue.c | 4 ++--
> net/ipv4/ping.c | 1 -
> net/ipv4/raw.c | 1 -
> net/ipv4/udp.c | 1 -
> 5 files changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/include/net/ip.h b/include/net/ip.h
> index 6af16545b3e3..6819704e2642 100644
> --- a/include/net/ip.h
> +++ b/include/net/ip.h
> @@ -92,7 +92,9 @@ static inline void ipcm_init(struct ipcm_cookie *ipcm)
> static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,
> const struct inet_sock *inet)
> {
> - ipcm_init(ipcm);
> + *ipcm = (struct ipcm_cookie) {
> + .tos = READ_ONCE(inet->tos) & INET_DSCP_MASK,
> + };
>
> sockcm_init(&ipcm->sockc, &inet->sk);
>
> @@ -256,13 +258,6 @@ static inline u8 ip_sendmsg_scope(const struct inet_sock *inet,
> return RT_SCOPE_UNIVERSE;
> }
>
> -static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
> -{
> - u8 dsfield = ipc->tos != -1 ? ipc->tos : READ_ONCE(inet->tos);
> -
> - return dsfield & INET_DSCP_MASK;
> -}
> -
> /* datagram.c */
> int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
> int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> index 6d9c5c20b1c4..98b1e4a8b72e 100644
> --- a/net/ipv4/ip_sockglue.c
> +++ b/net/ipv4/ip_sockglue.c
> @@ -314,8 +314,8 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
> return -EINVAL;
> if (val < 0 || val > 255)
> return -EINVAL;
> - ipc->tos = val;
> - ipc->sockc.priority = rt_tos2priority(ipc->tos);
> + ipc->sockc.priority = rt_tos2priority(val);
> + ipc->tos = val & INET_DSCP_MASK;
> break;
> case IP_PROTOCOL:
> if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
> diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
> index 619ddc087957..0215885c6df5 100644
> --- a/net/ipv4/ping.c
> +++ b/net/ipv4/ping.c
> @@ -768,7 +768,6 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> }
> faddr = ipc.opt->opt.faddr;
> }
> - tos = get_rttos(&ipc, inet);
Here and elsewhere, subsequent code needs to use ipc.tos directly.
next prev parent reply other threads:[~2025-02-07 0:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 19:34 [PATCH net-next 0/7] net: deduplicate cookie logic Willem de Bruijn
2025-02-06 19:34 ` [PATCH net-next 1/7] tcp: only initialize sockcm tsflags field Willem de Bruijn
2025-02-06 19:34 ` [PATCH net-next 2/7] net: initialize mark in sockcm_init Willem de Bruijn
2025-02-06 19:34 ` [PATCH net-next 3/7] ipv4: initialize inet socket cookies with sockcm_init Willem de Bruijn
2025-02-06 19:34 ` [PATCH net-next 4/7] ipv4: remove get_rttos Willem de Bruijn
2025-02-07 0:59 ` Willem de Bruijn [this message]
2025-02-07 17:33 ` Willem de Bruijn
2025-02-08 9:24 ` kernel test robot
2025-02-06 19:34 ` [PATCH net-next 5/7] icmp: reflect tos through ip cookie rather than updating inet_sk Willem de Bruijn
2025-02-07 1:01 ` Willem de Bruijn
2025-02-08 10:40 ` kernel test robot
2025-02-06 19:34 ` [PATCH net-next 6/7] ipv6: replace ipcm6_init calls with ipcm6_init_sk Willem de Bruijn
2025-02-06 19:34 ` [PATCH net-next 7/7] ipv6: initialize inet socket cookies with sockcm_init 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=67a55afb822cc_25109e294cc@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--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