brintos

brintos / linux-shallow public Read only

0
0
Text · 2.5 KiB · 824cb0e Raw
73 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Test for checking ICMP response with dummy address instead of 0.0.0.0.5# Sets up two namespaces like:6# +----------------------+                          +--------------------+7# | ns1                  |    v4-via-v6 routes:     | ns2                |8# |                      |                  '       |                    |9# |             +--------+   -> 172.16.1.0/24 ->    +--------+           |10# |             | veth0  +--------------------------+  veth0 |           |11# |             +--------+   <- 172.16.0.0/24 <-    +--------+           |12# |           172.16.0.1 |                          | 2001:db8:1::2/64   |13# |     2001:db8:1::2/64 |                          |                    |14# +----------------------+                          +--------------------+15#16# And then tries to ping 172.16.1.1 from ns1. This results in a "net17# unreachable" message being sent from ns2, but there is no IPv4 address set in18# that address space, so the kernel should substitute the dummy address19# 192.0.0.8 defined in RFC7600.20 21source lib.sh22 23H1_IP=172.16.0.1/3224H1_IP6=2001:db8:1::125RT1=172.16.1.0/2426PINGADDR=172.16.1.127RT2=172.16.0.0/2428H2_IP6=2001:db8:1::229 30TMPFILE=$(mktemp)31 32cleanup()33{34    rm -f "$TMPFILE"35    cleanup_ns $NS1 $NS236}37 38trap cleanup EXIT39 40# Namespaces41setup_ns NS1 NS242 43# Connectivity44ip -netns $NS1 link add veth0 type veth peer name veth0 netns $NS245ip -netns $NS1 link set dev veth0 up46ip -netns $NS2 link set dev veth0 up47ip -netns $NS1 addr add $H1_IP dev veth048ip -netns $NS1 addr add $H1_IP6/64 dev veth0 nodad49ip -netns $NS2 addr add $H2_IP6/64 dev veth0 nodad50ip -netns $NS1 route add $RT1 via inet6 $H2_IP651ip -netns $NS2 route add $RT2 via inet6 $H1_IP652 53# Make sure ns2 will respond with ICMP unreachable54ip netns exec $NS2 sysctl -qw net.ipv4.icmp_ratelimit=0 net.ipv4.ip_forward=155 56# Run the test - a ping runs in the background, and we capture ICMP responses57# with tcpdump; -c 1 means it should exit on the first ping, but add a timeout58# in case something goes wrong59ip netns exec $NS1 ping -w 3 -i 0.5 $PINGADDR >/dev/null &60ip netns exec $NS1 timeout 10 tcpdump -tpni veth0 -c 1 'icmp and icmp[icmptype] != icmp-echo' > $TMPFILE 2>/dev/null61 62# Parse response and check for dummy address63# tcpdump output looks like:64# IP 192.0.0.8 > 172.16.0.1: ICMP net 172.16.1.1 unreachable, length 9265RESP_IP=$(awk '{print $2}' < $TMPFILE)66if [[ "$RESP_IP" != "192.0.0.8" ]]; then67    echo "FAIL - got ICMP response from $RESP_IP, should be 192.0.0.8"68    exit 169else70    echo "OK"71    exit 072fi73