Skip to content

Commit 7e2da03

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]> Reviewed-by: Robin Jarry <[email protected]>
1 parent e2b94d5 commit 7e2da03

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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)