|
| 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