From 204ee23112f821fe75ea4db322561882b09578bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 3 Jul 2025 09:33:52 -0700 Subject: [PATCH] bpf/progs/netd.c: 5.4+ uses skb->gso_segs > 1 instead of skb->len > 1500 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add a minor comment to clarify tcphdr and udphdr size. rename is_tcp to is_tcp_or_unknown to make the code more explicit. Bug: 263884894 Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski Change-Id: Ie3417299564bc712c2e78fc6665c979e48d3013b --- bpf/progs/netd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bpf/progs/netd.c b/bpf/progs/netd.c index 9f8ce3dbcd..d6b17eaa92 100644 --- a/bpf/progs/netd.c +++ b/bpf/progs/netd.c @@ -183,16 +183,18 @@ DEFINE_BPF_MAP_EXT(local_net_blocked_uid_map, HASH, uint32_t, bool, -1000, value = bpf_##the_stats_map##_lookup_elem(key); \ } \ if (value) { \ + const bool is5_4 = KVER_IS_AT_LEAST(kver, 5, 4, 0); \ const int mtu = 1500; \ uint64_t packets = 1; \ uint64_t bytes = skb->len; \ - if (bytes > mtu) { \ - const bool is5_4 = KVER_IS_AT_LEAST(kver, 5, 4, 0); \ + if ((!is5_4 && bytes > mtu) || (is5_4 && skb->gso_segs > 1)) { \ const bool is_ipv6 = (skb->protocol == htons(ETH_P_IPV6)); \ const int ip_overhead = is_ipv6 ? sizeof(struct ipv6hdr) : sizeof(struct iphdr); \ struct bpf_sock * const sk = is5_4 && skb->sk ? bpf_sk_fullsock(skb->sk) : NULL; \ - const bool is_tcp = !sk || sk->protocol == IPPROTO_TCP; \ - const int L4_size = is_tcp ? sizeof(struct tcphdr) + 12 : sizeof(struct udphdr); \ + const bool is_tcp_or_unknown = !sk || sk->protocol == IPPROTO_TCP; \ + const int tcphdr_size = sizeof(struct tcphdr); \ + const int udphdr_size = sizeof(struct udphdr); \ + const int L4_size = is_tcp_or_unknown ? tcphdr_size + 12 : udphdr_size; \ const int overhead = ip_overhead + L4_size; \ const int mss = mtu - overhead; \ const uint64_t payload = bytes - overhead; \