Thread (13 messages) 13 messages, 2 authors, 2025-02-08

Re: [PATCH net-next 5/7] icmp: reflect tos through ip cookie rather than updating inet_sk

From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: 2025-02-07 01:01:44

Willem de Bruijn wrote:
quoted hunk ↗ jump to hunk
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.

Signed-off-by: Willem de Bruijn <willemb@google.com>

---

Tested with ping -Q 32 127.0.0.1 and tcpdump

The existing logic works because inet->tos is read if ipc.tos (and
with that cork->tos) is left unitialized:

  iph->tos = (cork->tos != -1) ? cork->tos : READ_ONCE(inet->tos);
---
 net/ipv4/icmp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 094084b61bff..9c5e052a7802 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -429,7 +429,7 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb)
 	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);
local variable inet is no longer used, needs to be removed.

Will fix in v2.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help