Skip to contentSkip to conversation

tools/ebpf: Fix IPv4 fragmentation identify

PATCH In review luwenpeng 2 participants 3 messages Apr 21, 2023 – Apr 28, 2023 1 message not in the archive

lore
Share & tools
lore

luwenpeng

author
#0 lore raw

PATCH 1/1 tools/ebpf: Fix IPv4 fragmentation identify

The meaning of the bit flag in ip.frag_off is Don`t fragmented When judging IPv4 is_fragmented according to ip.frag_off, should use !(bpf_ntohs(ip.frag_off) & 0x4000) instead of !!ip.frag_off

---
 tools/ebpf/rss.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ebpf/rss.bpf.c +1 -1
index 20f227e2ac..e77b764f3d 100644
@@ -317,7 +317,7 @@ static inline int parse_packet(struct __sk_buff *skb,
 
         info->in_src = ip.saddr;
         info->in_dst = ip.daddr;
-        info->is_fragmented = !!ip.frag_off;
+        info->is_fragmented = !(bpf_ntohs(ip.frag_off) & 0x4000);
 
         l4_protocol = ip.protocol;
         l4_offset = ip.ihl * 4;
Signature · 1 line
2.30.1 (Apple Git-130)

A message that is not in the archive (sent off-list or not yet received): CAGoVJZx2T6C37UTiaO5xL78vMKweJYyEVZse72t0LNv3-kV3_Q@mail.gmail.com

#2 lore raw

Hi all,
I don't think that checking DF flag is a case for figuring out that the packet is a fragment of some big datagram.
For nonfragmented packets, DF may not be set.
We need to check that the fragment offset is 0.
Actually, it's a good idea to check that MF flag is not set too. So we can find the first fragment that doesn't require steering. So the code may look something like this:

```
info->is_fragmented = !!(bpf_ntohs(ip.frag_off) & (0x2000 | 0x1fff));
// checking MF and frag offset.
 OR
info->is_fragmented = !!(bpf_ntohs(ip.frag_off) & ~0x4000); // if we
consider that CE always 0(which is always should be)
```
Quoted 37 lines · Yan Vugenfirer

FYI

---------- Forwarded message ---------
From: luwenpeng <[email protected]>
Date: Fri, Apr 21, 2023 at 3:21 PM
Subject: [PATCH] tools/ebpf: Fix IPv4 fragmentation identify
To: <[email protected]>
Cc: <[email protected]>, luwenpeng <[email protected]>

The meaning of the bit flag in ip.frag_off is Don`t fragmented When judging IPv4 is_fragmented according to ip.frag_off, should use !(bpf_ntohs(ip.frag_off) & 0x4000) instead of !!ip.frag_off

---
 tools/ebpf/rss.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ebpf/rss.bpf.c +1 -2
index 20f227e2ac..e77b764f3d 100644
@@ -317,7 +317,7 @@ static inline int parse_packet(struct __sk_buff *skb,
 
         info->in_src = ip.saddr;
         info->in_dst = ip.daddr;
-        info->is_fragmented = !!ip.frag_off;
+        info->is_fragmented = !(bpf_ntohs(ip.frag_off) & 0x4000);
 
         l4_protocol = ip.protocol;
         l4_offset = ip.ihl * 4;
--

2.30.1 (Apple Git-130)

#3 lore raw

Hi all,
Also, for those changes to have an effect, a new eBPF skeleton must be generated.

Quoted 55 lines · Andrew Melnichenko

Hi all,
I don't think that checking DF flag is a case for figuring out that the packet is a fragment of some big datagram.
For nonfragmented packets, DF may not be set.
We need to check that the fragment offset is 0.
Actually, it's a good idea to check that MF flag is not set too. So we can find the first fragment that doesn't require steering. So the code may look something like this:

```
info->is_fragmented = !!(bpf_ntohs(ip.frag_off) & (0x2000 | 0x1fff));
// checking MF and frag offset.
 OR
info->is_fragmented = !!(bpf_ntohs(ip.frag_off) & ~0x4000); // if we
consider that CE always 0(which is always should be)
```
Quoted 37 lines · Yan Vugenfirer

FYI

---------- Forwarded message ---------
From: luwenpeng <[email protected]>
Date: Fri, Apr 21, 2023 at 3:21 PM
Subject: [PATCH] tools/ebpf: Fix IPv4 fragmentation identify
To: <[email protected]>
Cc: <[email protected]>, luwenpeng <[email protected]>

The meaning of the bit flag in ip.frag_off is Don`t fragmented When judging IPv4 is_fragmented according to ip.frag_off, should use !(bpf_ntohs(ip.frag_off) & 0x4000) instead of !!ip.frag_off

---
 tools/ebpf/rss.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ebpf/rss.bpf.c +1 -2
index 20f227e2ac..e77b764f3d 100644
@@ -317,7 +317,7 @@ static inline int parse_packet(struct __sk_buff *skb,
 
         info->in_src = ip.saddr;
         info->in_dst = ip.daddr;
-        info->is_fragmented = !!ip.frag_off;
+        info->is_fragmented = !(bpf_ntohs(ip.frag_off) & 0x4000);
 
         l4_protocol = ip.protocol;
         l4_offset = ip.ihl * 4;
--

2.30.1 (Apple Git-130)