netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 5/7] icmp: reflect tos through ip cookie rather than updating inet_sk
Date: Tue, 11 Feb 2025 21:09:51 -0500	[thread overview]
Message-ID: <20250212021142.1497449-6-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20250212021142.1497449-1-willemdebruijn.kernel@gmail.com>

From: Willem de Bruijn <willemb@google.com>

Do not modify socket fields if it can be avoided.

The current code predates the introduction of ip cookies in commit
aa6615814533 ("ipv4: processing ancillary IP_TOS or IP_TTL"). Now that
cookies exist and support tos, update that field directly.

v1->v2:
  - remove no longer used local variable inet

Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 net/ipv4/icmp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 094084b61bff..c42030fb4ff6 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -405,7 +405,6 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
 	bool apply_ratelimit = false;
 	struct flowi4 fl4;
 	struct sock *sk;
-	struct inet_sock *inet;
 	__be32 daddr, saddr;
 	u32 mark = IP4_REPLY_MARK(net, skb->mark);
 	int type = icmp_param->data.icmph.type;
@@ -424,12 +423,11 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
 	sk = icmp_xmit_lock(net);
 	if (!sk)
 		goto out_bh_enable;
-	inet = inet_sk(sk);
 
 	icmp_param->data.icmph.checksum = 0;
 
 	ipcm_init(&ipc);
-	inet->tos = ip_hdr(skb)->tos;
+	ipc.tos = ip_hdr(skb)->tos;
 	ipc.sockc.mark = mark;
 	daddr = ipc.addr = ip_hdr(skb)->saddr;
 	saddr = fib_compute_spec_dst(skb);
@@ -735,8 +733,8 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,
 	icmp_param.data.icmph.checksum	 = 0;
 	icmp_param.skb	  = skb_in;
 	icmp_param.offset = skb_network_offset(skb_in);
-	inet_sk(sk)->tos = tos;
 	ipcm_init(&ipc);
+	ipc.tos = tos;
 	ipc.addr = iph->saddr;
 	ipc.opt = &icmp_param.replyopts.opt;
 	ipc.sockc.mark = mark;
-- 
2.48.1.502.g6dc24dfdaf-goog


  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 ` [PATCH net-next v2 2/7] net: initialize mark in sockcm_init Willem de Bruijn
2025-02-13 14:48   ` 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 ` Willem de Bruijn [this message]
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-6-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).