Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: forwarding.config.sample: Move overrides to lib.sh

forwarding.config.sample, net/lib.sh and net/forwarding/lib.sh contain
definitions and redefinitions of some of the same variables. The overlap
between net/forwarding/lib.sh and forwarding.config.sample is especially
large. This duplication is a potential source of confusion and problems.

It would be overall less error prone if each variable were defined in one
place only. In this patch set, that place is the library itself. Therefore
move all comments from forwarding.config.sample to net/forwarding/lib.sh.

Move over also a definition of TC_FLAG, which was missing from lib.sh
entirely.

Additionally, add to lib.sh a default definition of the topology variables.
The logic behind this is that forgetting to specify forwarding.config was a
frequent source of frustration for the selftest users. But really, most of
the time the default veth based topology is just fine. We considered just
sourcing forwarding.config.sample instead if forwarding.config is not
available, but this is a cleaner solution.

That means the syntax of the forwarding.config.sample override has to
change to an array assignment, so that the whole variable is overwritten,
not just individual keys, which could leave the value of some keys
unchanged. Do the same in lib.sh for any cut'n'pasters out there.

The config file is then given a sort of carte blanche to redefine whatever
variables it sees fit from the libraries. This is described in a comment in
the file. Only a handful of variables are left behind, to illustrate the
customization.

The fact that the variables are now missing from forwarding.config.sample,
and therefore would miss from forwarding.config derived from that file as
well, should not change anything. This is just the sample file. Users that
keep their own forwarding.config would retain it as before.

The only observable change is introduction of TC_FLAG to lib.sh, because
now the filters would not be attempted to install to HW datapath. For veth
pairs this does not change anything. For HW deployments, users presumably
have forwarding.config with this value overridden.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Benjamin Poirier <bpoirier@nvidia.com>
Link: https://lore.kernel.org/r/b9b8a11a22821a7aa532211ff461a34f596e26bf.1711464583.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Petr Machata and committed by
Jakub Kicinski
fd36fd26 fa61e9ae

+77 -51
+15 -38
tools/testing/selftests/net/forwarding/forwarding.config.sample
··· 3 3 4 4 ############################################################################## 5 5 # Topology description. p1 looped back to p2, p3 to p4 and so on. 6 - declare -A NETIFS 7 6 8 - NETIFS[p1]=veth0 9 - NETIFS[p2]=veth1 10 - NETIFS[p3]=veth2 11 - NETIFS[p4]=veth3 12 - NETIFS[p5]=veth4 13 - NETIFS[p6]=veth5 14 - NETIFS[p7]=veth6 15 - NETIFS[p8]=veth7 16 - NETIFS[p9]=veth8 17 - NETIFS[p10]=veth9 7 + NETIFS=( 8 + [p1]=veth0 9 + [p2]=veth1 10 + [p3]=veth2 11 + [p4]=veth3 12 + [p5]=veth4 13 + [p6]=veth5 14 + [p7]=veth6 15 + [p8]=veth7 16 + [p9]=veth8 17 + [p10]=veth9 18 + ) 18 19 19 20 # Port that does not have a cable connected. 20 21 NETIF_NO_CABLE=eth8 21 22 22 23 ############################################################################## 23 - # Defines 24 + # In addition to the topology-related variables, it is also possible to override 25 + # in this file other variables that net/lib.sh, net/forwarding/lib.sh or other 26 + # libraries or selftests use. E.g.: 24 27 25 - # IPv4 ping utility name 26 - PING=ping 27 - # IPv6 ping utility name. Some distributions use 'ping' for IPv6. 28 28 PING6=ping6 29 - # Packet generator. Some distributions use 'mz'. 30 29 MZ=mausezahn 31 - # mausezahn delay between transmissions in microseconds. 32 - MZ_DELAY=0 33 - # Time to wait after interfaces participating in the test are all UP 34 30 WAIT_TIME=5 35 - # Whether to pause on failure or not. 36 - PAUSE_ON_FAIL=no 37 - # Whether to pause on cleanup or not. 38 - PAUSE_ON_CLEANUP=no 39 - # Type of network interface to create 40 - NETIF_TYPE=veth 41 - # Whether to create virtual interfaces (veth) or not 42 - NETIF_CREATE=yes 43 - # Timeout (in seconds) before ping exits regardless of how many packets have 44 - # been sent or received 45 - PING_TIMEOUT=5 46 - # Minimum ageing_time (in centiseconds) supported by hardware 47 - LOW_AGEING_TIME=1000 48 - # Flag for tc match, supposed to be skip_sw/skip_hw which means do not process 49 - # filter by software/hardware 50 - TC_FLAG=skip_hw 51 - # IPv6 traceroute utility name. 52 - TROUTE6=traceroute6 53 -
+62 -13
tools/testing/selftests/net/forwarding/lib.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 ############################################################################## 5 + # Topology description. p1 looped back to p2, p3 to p4 and so on. 6 + 7 + declare -A NETIFS=( 8 + [p1]=veth0 9 + [p2]=veth1 10 + [p3]=veth2 11 + [p4]=veth3 12 + [p5]=veth4 13 + [p6]=veth5 14 + [p7]=veth6 15 + [p8]=veth7 16 + [p9]=veth8 17 + [p10]=veth9 18 + ) 19 + 20 + # Port that does not have a cable connected. 21 + : "${NETIF_NO_CABLE:=eth8}" 22 + 23 + ############################################################################## 5 24 # Defines 6 25 7 - # Can be overridden by the configuration file. 26 + # Networking utilities. 8 27 : "${PING:=ping}" 9 - : "${PING6:=ping6}" 10 - : "${MZ:=mausezahn}" 11 - : "${MZ_DELAY:=0}" 28 + : "${PING6:=ping6}" # Some distros just use ping. 12 29 : "${ARPING:=arping}" 30 + : "${TROUTE6:=traceroute6}" 31 + 32 + # Packet generator. 33 + : "${MZ:=mausezahn}" # Some distributions use 'mz'. 34 + : "${MZ_DELAY:=0}" 35 + 36 + # Host configuration tools. 13 37 : "${TEAMD:=teamd}" 14 - : "${WAIT_TIME:=5}" 15 - : "${PAUSE_ON_FAIL:=no}" 16 - : "${PAUSE_ON_CLEANUP:=no}" 17 - : "${NETIF_TYPE:=veth}" 18 - : "${NETIF_CREATE:=yes}" 19 38 : "${MCD:=smcrouted}" 20 39 : "${MC_CLI:=smcroutectl}" 21 - : "${PING_COUNT:=10}" 22 - : "${PING_TIMEOUT:=5}" 23 - : "${WAIT_TIMEOUT:=20}" 40 + 41 + # Constants for netdevice bring-up: 42 + # Default time in seconds to wait for an interface to come up before giving up 43 + # and bailing out. Used during initial setup. 24 44 : "${INTERFACE_TIMEOUT:=600}" 45 + # Like INTERFACE_TIMEOUT, but default for ad-hoc waiting in testing scripts. 46 + : "${WAIT_TIMEOUT:=20}" 47 + # Time to wait after interfaces participating in the test are all UP. 48 + : "${WAIT_TIME:=5}" 49 + 50 + # Whether to pause on, respectively, after a failure and before cleanup. 51 + : "${PAUSE_ON_FAIL:=no}" 52 + : "${PAUSE_ON_CLEANUP:=no}" 53 + 54 + # Whether to create virtual interfaces, and what netdevice type they should be. 55 + : "${NETIF_CREATE:=yes}" 56 + : "${NETIF_TYPE:=veth}" 57 + 58 + # Constants for ping tests: 59 + # How many packets should be sent. 60 + : "${PING_COUNT:=10}" 61 + # Timeout (in seconds) before ping exits regardless of how many packets have 62 + # been sent or received 63 + : "${PING_TIMEOUT:=5}" 64 + 65 + # Minimum ageing_time (in centiseconds) supported by hardware 25 66 : "${LOW_AGEING_TIME:=1000}" 67 + 68 + # Whether to check for availability of certain tools. 26 69 : "${REQUIRE_JQ:=yes}" 27 70 : "${REQUIRE_MZ:=yes}" 28 71 : "${REQUIRE_MTOOLS:=no}" 72 + 73 + # Whether to override MAC addresses on interfaces participating in the test. 29 74 : "${STABLE_MAC_ADDRS:=no}" 75 + 76 + # Flags for tcpdump 30 77 : "${TCPDUMP_EXTRA_FLAGS:=}" 31 - : "${TROUTE6:=traceroute6}" 78 + 79 + # Flags for TC filters. 80 + : "${TC_FLAG:=skip_hw}" 32 81 33 82 net_forwarding_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") 34 83