Skip to content

Commit 530fbdb

Browse files
committed
smoke: add IPv4 fragmentation test
Add a smoke test that verifies IPv4 packet fragmentation behavior by configuring asymmetric MTUs between two TAP interfaces (1500 and 1280 bytes) and sending packets through grout. The test validates three scenarios: normal forwarding without fragmentation, ICMP error generation when a large packet has the DF flag set, and successful fragmentation when the DF flag is not set. This ensures both the fragmentation logic and the DF flag handling work correctly. Signed-off-by: Anthony Harivel <[email protected]>
1 parent d2d5785 commit 530fbdb

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

modules/ip/datapath/ip_fragment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ ip_fragment_process(struct rte_graph *graph, struct rte_node *node, void **objs,
3939
uint16_t frag_size, frag_data_len;
4040
const struct iface *iface;
4141
uint16_t data_len, offset;
42-
uint16_t ip_hdr_len;
4342
uint16_t num_frags, i;
43+
uint16_t ip_hdr_len;
4444
rte_edge_t edge;
4545
void *payload;
4646

smoke/ip_fragment_test.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright (c) 2025 Anthony Harivel
4+
# Test IPv4 fragmentation
5+
6+
. $(dirname $0)/_init.sh
7+
8+
p0=${run_id}0
9+
p1=${run_id}1
10+
11+
grcli interface add port $p0 devargs net_tap0,iface=$p0 mac f0:0d:ac:dc:00:00
12+
# Set smaller MTU on p1 (egress) to force fragmentation
13+
grcli interface add port $p1 devargs net_tap1,iface=$p1 mac f0:0d:ac:dc:00:01 mtu 1280
14+
grcli address add 172.16.0.1/24 iface $p0
15+
grcli address add 172.16.1.1/24 iface $p1
16+
17+
for n in 0 1; do
18+
p=$run_id$n
19+
netns_add $p
20+
ip link set $p mtu 1500
21+
ip link set $p netns $p
22+
ip -n $p link set $p address ba:d0:ca:ca:00:0$n
23+
ip -n $p link set $p up
24+
ip -n $p link set lo up
25+
ip -n $p addr add 172.16.$n.2/24 dev $p
26+
ip -n $p route add default via 172.16.$n.1
27+
# Clear PMTU cache to ensure kernel uses interface MTU
28+
ip -n $p route flush cache
29+
done
30+
31+
# Test 1: Ping with default packet size (should work without fragmentation)
32+
ip netns exec $p0 ping -i0.01 -c3 -n 172.16.1.2
33+
34+
# Test 2: Large packet with DF flag set (should get ICMP fragmentation needed error)
35+
# Send 1260-byte packet with DF=1 (Don't Fragment)
36+
# Packet size: 1260 + 8 (ICMP) + 20 (IP) = 1288 bytes
37+
# Fits in p0 MTU (1500) but exceeds p1 MTU (1280)
38+
# Expected: ICMP Type 3 Code 4 (Fragmentation Needed and DF Set)
39+
ip netns exec $p0 ping -i0.01 -c3 -s 1260 -M do -n 172.16.1.2 && fail "ping with DF flag should have failed"
40+
41+
# Test 3: Large packet without DF flag (should fragment and succeed)
42+
# Send 1260-byte packet with DF=0 (fragmentation allowed)
43+
# Packet size: 1260 + 8 (ICMP) + 20 (IP) = 1288 bytes
44+
# Fits in p0 MTU (1500) but needs fragmentation for p1 MTU (1280)
45+
# Expected: Packet is fragmented into 2 fragments (1276 + 32 bytes) and ping succeeds
46+
ip netns exec $p0 ip route flush cache
47+
ip netns exec $p0 ping -i0.01 -c3 -s 1260 -M dont -n 172.16.1.2

0 commit comments

Comments
 (0)