Re: [RFC PATCH 1/3] selftests: Add VRF icmp error route lookup test

2020-08-06 Thread David Ahern
On 7/29/20 3:12 PM, Mathieu Desnoyers wrote:
> From: Michael Jeanson 
> 
> The objective is to check that the incoming vrf routing table is selected
> to send an ICMP error back to the source when the ttl of a packet reaches 1
> while it is forwarded between different vrfs.
> 
> The first test sends a ping with a ttl of 1 from h1 to h2 and parses the
> output of the command to check that a ttl expired error is received.
> 
> [This may be flaky, I'm open to suggestions of a more robust approch.]
> 
> The second test runs traceroute from h1 to h2 and parses the output to check
> for a hop on r1.
> 
> Signed-off-by: Michael Jeanson 
> Cc: David Ahern 

Update the address to dsah...@kernel.org


> Cc: David S. Miller 
> Cc: net...@vger.kernel.org
> ---
>  tools/testing/selftests/net/Makefile  |   1 +
>  .../selftests/net/vrf_icmp_error_route.sh | 461 ++
>  2 files changed, 462 insertions(+)
>  create mode 100755 tools/testing/selftests/net/vrf_icmp_error_route.sh
> 

Test seems fine to me. you copied icmp_redirect.sh which is fine but
please clean up comments and functions not needed for this test.


[RFC PATCH 1/3] selftests: Add VRF icmp error route lookup test

2020-07-29 Thread Mathieu Desnoyers
From: Michael Jeanson 

The objective is to check that the incoming vrf routing table is selected
to send an ICMP error back to the source when the ttl of a packet reaches 1
while it is forwarded between different vrfs.

The first test sends a ping with a ttl of 1 from h1 to h2 and parses the
output of the command to check that a ttl expired error is received.

[This may be flaky, I'm open to suggestions of a more robust approch.]

The second test runs traceroute from h1 to h2 and parses the output to check
for a hop on r1.

Signed-off-by: Michael Jeanson 
Cc: David Ahern 
Cc: David S. Miller 
Cc: net...@vger.kernel.org
---
 tools/testing/selftests/net/Makefile  |   1 +
 .../selftests/net/vrf_icmp_error_route.sh | 461 ++
 2 files changed, 462 insertions(+)
 create mode 100755 tools/testing/selftests/net/vrf_icmp_error_route.sh

diff --git a/tools/testing/selftests/net/Makefile 
b/tools/testing/selftests/net/Makefile
index 895ec992b2f1..2fc72bc2908c 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -17,6 +17,7 @@ TEST_PROGS += route_localnet.sh
 TEST_PROGS += reuseaddr_ports_exhausted.sh
 TEST_PROGS += txtimestamp.sh
 TEST_PROGS += vrf-xfrm-tests.sh
+TEST_PROGS += vrf_icmp_error_route.sh
 TEST_PROGS_EXTENDED := in_netns.sh
 TEST_GEN_FILES =  socket nettest
 TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
diff --git a/tools/testing/selftests/net/vrf_icmp_error_route.sh 
b/tools/testing/selftests/net/vrf_icmp_error_route.sh
new file mode 100755
index ..faeedf9f9e1c
--- /dev/null
+++ b/tools/testing/selftests/net/vrf_icmp_error_route.sh
@@ -0,0 +1,461 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (c) 2019 David Ahern . All rights reserved.
+# Copyright (c) 2020 Michael Jeanson . All rights 
reserved.
+#
+# redirect test
+#
+# blue red
+# .253 ++ .253
+# +| r1 |+
+# |++|
+# ++  |  |  ++
+# | h1 |--+  +--| h2 |
+# ++ .1   |  |   .2 ++
+# 172.16.1/24 |++| 172.16.2/24
+#2001:db8:16:1/64 +| r2 |+ 2001:db8:16:2/64
+# .254 ++ .254
+#
+#
+# Route from h1 to h2 goes through r1, incoming vrf blue has a route to the
+# outgoing vrf red for the n2 network but red doesn't have a route back to n1.
+# Route from h2 to h1 goes through r2.
+#
+# The objective is to check that the incoming vrf routing table is selected
+# to send an ICMP error back to the source when the ttl of a packet reaches 1
+# while it is forwarded between different vrfs.
+#
+# The first test sends a ping with a ttl of 1 from h1 to h2 and parses the
+# output of the command to check that a ttl expired error is received.
+#
+# The second test runs traceroute from h1 to h2 and parses the output to check
+# for a hop on r1.
+#
+# Requires CONFIG_NET_VRF, CONFIG_VETH, CONFIG_BRIDGE and CONFIG_NET_NS.
+
+VERBOSE=0
+PAUSE_ON_FAIL=no
+
+H1_N1_IP=172.16.1.1
+R1_N1_IP=172.16.1.253
+R2_N1_IP=172.16.1.254
+
+H1_N1_IP6=2001:db8:16:1::1
+R1_N1_IP6=2001:db8:16:1::253
+R2_N1_IP6=2001:db8:16:1::254
+
+H2_N2=172.16.2.0/24
+H2_N2_6=2001:db8:16:2::/64
+
+H2_N2_IP=172.16.2.2
+R1_N2_IP=172.16.2.253
+R2_N2_IP=172.16.2.254
+
+H2_N2_IP6=2001:db8:16:2::2
+R1_N2_IP6=2001:db8:16:2::253
+R2_N2_IP6=2001:db8:16:2::254
+
+
+# helpers
+
+log_section()
+{
+   echo
+   echo 
"###"
+   echo "$*"
+   echo 
"###"
+   echo
+}
+
+log_test()
+{
+   local rc=$1
+   local expected=$2
+   local msg="$3"
+
+   if [ "${rc}" -eq "${expected}" ]; then
+   printf "TEST: %-60s  [ OK ]\n" "${msg}"
+   nsuccess=$((nsuccess+1))
+   else
+   ret=1
+   nfail=$((nfail+1))
+   printf "TEST: %-60s  [FAIL]\n" "${msg}"
+   if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
+   echo
+   echo "hit enter to continue, 'q' to quit"
+   read -r a
+   [ "$a" = "q" ] && exit 1
+   fi
+   fi
+}
+
+log_debug()
+{
+   if [ "$VERBOSE" = "1" ]; then
+   echo "$*"
+   fi
+}
+
+run_cmd()
+{
+   local cmd="$*"
+   local out
+   local rc
+
+   if [ "$VERBOSE" = "1" ]; then
+   echo "COMMAND: $cmd"
+   fi
+
+   out=$(eval $cmd 2>&1)
+   rc=$?
+   if [ "$VERBOSE" = "1" ] && [ -n "$out" ]; then
+   echo "$out"
+   fi
+
+   [ "$VERBOSE" = "1" ] && echo
+
+   return $rc
+}
+
+get_linklocal()
+{
+   local ns=$1
+