linux/tools/testing/selftests/net/forwarding
Petr Machata 040a6cbead selftests: forwarding: lib: Add an autodefer variant of forwarding_enable()
Most forwarding tests invoke forwarding_enable() to enable the router and
forwarding_restore() to restore the original configuration. Add a helper,
adf_forwarding_enable(), which is like forwarding_enable(), but takes care
of scheduling the cleanup automatically.

Convert the tests that currently use defer to schedule the cleanup.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/78b752c40069cde21c44dcf4c7b966a76a0eef2c.1758821127.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-09-26 17:48:40 -07:00
..
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
bridge_activity_notify.sh selftests: forwarding: lib: Add an autodefer variant of simple_if_init() 2025-09-26 17:48:40 -07:00
bridge_fdb_learning_limit.sh selftests: forwarding: skip if kernel not support setting bridge fdb learning limit 2024-07-24 12:50:28 +01:00
bridge_fdb_local_vlan_0.sh selftests: forwarding: lib: Add an autodefer variant of forwarding_enable() 2025-09-26 17:48:40 -07:00
bridge_igmp.sh selftests: net/bridge : add tests for per vlan snooping with stp state changes 2025-04-23 13:02:20 +01:00
bridge_locked_port.sh selftests: forwarding: Fix bridge locked port test flakiness 2024-02-09 11:32:14 -08:00
bridge_mdb_host.sh selftests: forwarding: Rename bridge_mdb test 2022-12-12 15:33:37 -08:00
bridge_mdb_max.sh selftests: forwarding: bridge_mdb_max: Fix failing test with old libnet 2023-08-09 14:53:36 -07:00
bridge_mdb_port_down.sh selftest: net: bridge mdb add/del entry to port that is down 2022-07-04 10:30:06 +01:00
bridge_mdb.sh bridge: mdb: Allow replace of a host-joined group 2025-02-05 17:50:03 -08:00
bridge_mld.sh selftests: net/bridge : add tests for per vlan snooping with stp state changes 2025-04-23 13:02:20 +01:00
bridge_port_isolation.sh selftests: forwarding: test for bridge port isolation 2018-07-04 21:40:02 +09:00
bridge_sticky_fdb.sh selftests: forwarding: test for bridge sticky flag 2018-09-28 10:45:04 -07:00
bridge_vlan_aware.sh selftests: net: bridge_vlan_aware: test untagged/8021p-tagged with and without PVID 2025-04-25 18:45:43 -07:00
bridge_vlan_mcast.sh selftests: bridge_vlan_mcast: Delete qdiscs during cleanup 2022-10-19 14:01:08 +01:00
bridge_vlan_unaware.sh selftests: forwarding: add a pvid_change test to bridge_vlan_unaware 2024-12-12 12:16:39 +01:00
config selftests: net/bridge : add tests for per vlan snooping with stp state changes 2025-04-23 13:02:20 +01:00
custom_multipath_hash.sh selftests: forwarding: Reorder (ar)ping arguments to obey POSIX getopt 2025-09-22 11:37:20 -07:00
devlink_lib.sh selftests: net: lib: Add kill_process 2024-11-15 16:39:19 -08:00
dual_vxlan_bridge.sh selftests: forwarding: dual_vxlan_bridge: Disable IPv6 autogen on bridges 2023-06-21 14:02:52 -07:00
fib_offload_lib.sh selftests: fib offload: use sensible tos values 2022-02-03 19:11:21 -08:00
forwarding.config.sample selftests: forwarding.config.sample: Move overrides to lib.sh 2024-03-28 18:03:41 -07:00
gre_custom_multipath_hash.sh selftests: forwarding: Reorder (ar)ping arguments to obey POSIX getopt 2025-09-22 11:37:20 -07:00
gre_inner_v4_multipath.sh selftests: forwarding: Parametrize mausezahn delay 2024-03-05 09:18:04 -08:00
gre_inner_v6_multipath.sh selftests: forwarding: Make {, ip6}gre-inner-v6-multipath tests more robust 2024-03-05 09:18:17 -08:00
gre_multipath_nh_res.sh selftests: forwarding: Parametrize mausezahn delay 2024-03-05 09:18:04 -08:00
gre_multipath_nh.sh selftests: forwarding: Parametrize mausezahn delay 2024-03-05 09:18:04 -08:00
gre_multipath.sh selftests: forwarding: Parametrize mausezahn delay 2024-03-05 09:18:04 -08:00
ip6_forward_instats_vrf.sh selftests: forwarding: Reorder (ar)ping arguments to obey POSIX getopt 2025-09-22 11:37:20 -07:00
ip6gre_custom_multipath_hash.sh selftests: forwarding: Reorder (ar)ping arguments to obey POSIX getopt 2025-09-22 11:37:20 -07:00
ip6gre_flat_key.sh selftests: forwarding: Add IPv6 GRE remote change tests 2024-10-30 18:24:40 -07:00
ip6gre_flat_keys.sh selftests: forwarding: Add IPv6 GRE remote change tests 2024-10-30 18:24:40 -07:00
ip6gre_flat.sh selftests: forwarding: Add IPv6 GRE remote change tests 2024-10-30 18:24:40 -07:00
ip6gre_hier_key.sh selftests: forwarding: Add IPv6 GRE remote change tests 2024-10-30 18:24:40 -07:00
ip6gre_hier_keys.sh selftests: forwarding: Add IPv6 GRE remote change tests 2024-10-30 18:24:40 -07:00
ip6gre_hier.sh selftests: forwarding: Add IPv6 GRE remote change tests 2024-10-30 18:24:40 -07:00
ip6gre_inner_v4_multipath.sh selftests: forwarding: Parametrize mausezahn delay 2024-03-05 09:18:04 -08:00
ip6gre_inner_v6_multipath.sh selftests: forwarding: Make {, ip6}gre-inner-v6-multipath tests more robust 2024-03-05 09:18:17 -08:00
ip6gre_lib.sh selftests: forwarding: Add IPv6 GRE remote change tests 2024-10-30 18:24:40 -07:00
ipip_flat_gre_key.sh selftests: forwarding: Add IP-in-IP GRE flat topology with key test 2019-01-20 11:12:58 -08:00
ipip_flat_gre_keys.sh selftests: forwarding: Add IP-in-IP GRE flat topology with keys test 2019-01-20 11:12:58 -08:00
ipip_flat_gre.sh selftests: forwarding: Add IP-in-IP GRE flat topology test 2019-01-20 11:12:58 -08:00
ipip_hier_gre_key.sh selftests: forwarding: Add IP-in-IP GRE hierarchical topology with key test 2019-01-20 11:12:58 -08:00
ipip_hier_gre_keys.sh selftests: forwarding: Add IP-in-IP GRE hierarchical topology with keys test 2019-01-20 11:12:58 -08:00
ipip_hier_gre.sh selftests: forwarding: Add IP-in-IP GRE hierarchical topology test 2019-01-20 11:12:58 -08:00
ipip_lib.sh selftests: forwarding: ipip_lib: Do not import lib.sh 2024-03-28 18:03:42 -07:00
lib_sh_test.sh selftests: forwarding: Add a test for testing lib.sh functionality 2024-03-28 18:03:43 -07:00
lib.sh selftests: forwarding: lib: Add an autodefer variant of forwarding_enable() 2025-09-26 17:48:40 -07:00
local_termination.sh selftests: net: local_termination: require mausezahn 2024-12-20 11:48:21 -08:00
Makefile selftests: forwarding: Add test for BR_BOOLOPT_FDB_LOCAL_VLAN_0 2025-09-11 19:02:51 -07:00
min_max_mtu.sh selftests: forwarding: Add test for minimum and maximum MTU 2024-06-14 19:30:34 -07:00
mirror_gre_bound.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_bridge_1d_vlan.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_bridge_1d.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_bridge_1q_lag.sh selftests: forwarding: Reorder (ar)ping arguments to obey POSIX getopt 2025-09-22 11:37:20 -07:00
mirror_gre_bridge_1q.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_changes.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_flower.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_lag_lacp.sh selftests/net/forwarding: teamd command not found 2025-01-15 14:14:40 -08:00
mirror_gre_lib.sh selftests: libs: Drop unused functions 2024-06-28 10:55:38 +01:00
mirror_gre_neigh.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_nh.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre_topo_lib.sh selftests: forwarding: Redefine relative_path variable 2024-01-31 10:55:11 +00:00
mirror_gre_vlan_bridge_1q.sh selftests: forwarding: Reorder (ar)ping arguments to obey POSIX getopt 2025-09-22 11:37:20 -07:00
mirror_gre_vlan.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_gre.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
mirror_lib.sh selftests: libs: Drop unused functions 2024-06-28 10:55:38 +01:00
mirror_topo_lib.sh selftests: forwarding: mirror_gre_*: Disable IPv6 autogen on bridges 2023-06-21 14:02:52 -07:00
mirror_vlan.sh selftests: mirror: Drop dual SW/HW testing 2024-06-28 10:55:37 +01:00
no_forwarding.sh selftests: net: no_forwarding: fix VID for $swp2 in one_bridge_two_pvids() test 2024-10-04 13:13:02 -07:00
pedit_dsfield.sh selftests: forwarding: skbedit_priority: Disable IPv6 autogen on a bridge 2023-06-21 14:02:52 -07:00
pedit_ip.sh selftests: forwarding: Add a test for pedit munge SIP and DIP 2022-02-07 11:59:57 +00:00
pedit_l4port.sh selftests: Clean forgotten resources as part of cleanup() 2021-06-08 14:39:07 -07:00
q_in_vni_ipv6.sh selftests: forwarding: Add Q-in-VNI test for IPv6 2021-12-22 17:14:34 -08:00
q_in_vni.sh selftests: forwarding: q_in_vni: Disable IPv6 autogen on bridges 2023-06-21 14:02:51 -07:00
README net: rename netns_local to netns_immutable 2025-03-04 12:44:48 +01:00
router_bridge_1d_lag.sh selftests/net/forwarding: teamd command not found 2025-01-15 14:14:40 -08:00
router_bridge_1d.sh selftests: router_bridge_1d: Add a new selftest 2023-08-02 09:18:18 +01:00
router_bridge_lag.sh selftests/net/forwarding: teamd command not found 2025-01-15 14:14:40 -08:00
router_bridge_pvid_vlan_upper.sh selftests: router_bridge_pvid_vlan_upper: Add a new selftest 2023-07-14 10:20:15 +01:00
router_bridge_vlan_upper_pvid.sh selftests: router_bridge_vlan_upper_pvid: Add a new selftest 2023-07-14 10:20:15 +01:00
router_bridge_vlan_upper.sh selftests: router_bridge_vlan_upper: Add a new selftest 2023-08-02 09:18:18 +01:00
router_bridge_vlan.sh selftests: router_bridge_vlan: Add PVID change test 2023-07-14 10:20:15 +01:00
router_bridge.sh selftests: router_bridge: Add remastering tests 2023-08-02 09:18:18 +01:00
router_broadcast.sh selftests: set sysctl bc_forwarding properly in router_broadcast.sh 2019-06-03 15:15:01 -07:00
router_mpath_nh_lib.sh selftests: router_mpath_nh: Test 16-bit next hop weights 2024-08-12 17:50:34 -07:00
router_mpath_nh_res.sh selftests: router_mpath_nh_res: Test 16-bit next hop weights 2024-08-12 17:50:34 -07:00
router_mpath_nh.sh selftests: router_mpath_nh: Test 16-bit next hop weights 2024-08-12 17:50:34 -07:00
router_mpath_seed.sh selftests: forwarding: router_mpath_hash: Add a new selftest 2024-06-12 16:42:12 -07:00
router_multicast.sh selftests: forwarding: lib: Move smcrouted helpers here 2025-06-17 18:18:46 -07:00
router_multipath.sh selftests: router_mpath: Sleep after MZ 2024-08-12 17:50:34 -07:00
router_nh.sh selftests: forwarding: router_nh: Add a diagram 2024-04-16 12:14:41 +02:00
router_vid_1.sh selftests: router_vid_1: Add a diagram, fix coding style 2022-05-04 11:21:32 +01:00
router.sh selftest: forwarding: router: Add a test case for IPv4 link-local source IP 2025-08-15 10:44:48 -07:00
sch_ets_core.sh selftests: forwarding: lib: Add an autodefer variant of simple_if_init() 2025-09-26 17:48:40 -07:00
sch_ets_tests.sh selftests: net/forwarding: test purge of active DWRR classes 2025-08-13 18:11:48 -07:00
sch_ets.sh selftests: net/forwarding: test purge of active DWRR classes 2025-08-13 18:11:48 -07:00
sch_red.sh selftests: forwarding: lib: Add an autodefer variant of simple_if_init() 2025-09-26 17:48:40 -07:00
sch_tbf_core.sh selftests: forwarding: lib: Add an autodefer variant of simple_if_init() 2025-09-26 17:48:40 -07:00
sch_tbf_ets.sh selftests: mlxsw: Add a TBF selftest 2020-01-25 10:56:31 +01:00
sch_tbf_etsprio.sh selftests: TBF: Use defer for test cleanup 2024-10-22 13:33:47 +02:00
sch_tbf_prio.sh selftests: mlxsw: Add a TBF selftest 2020-01-25 10:56:31 +01:00
sch_tbf_root.sh selftests: TBF: Use defer for test cleanup 2024-10-22 13:33:47 +02:00
settings selftests: forwarding: Switch off timeout 2023-08-09 14:53:34 -07:00
skbedit_priority.sh selftests: forwarding: pedit_dsfield: Disable IPv6 autogen on a bridge 2023-06-21 14:02:52 -07:00
tc_actions.sh selftests: tc_actions: test egress 2nd vlan push 2024-08-27 11:37:43 +02:00
tc_chains.sh selftests: forwarding: Fix spelling mistake "succeded" -> "succeeded" 2021-01-19 17:44:09 -08:00
tc_common.sh selftests: net: libs: Change variable fallback syntax 2024-03-28 18:03:41 -07:00
tc_flower_cfm.sh selftests: net: add tc flower cfm test 2023-06-12 17:01:45 -07:00
tc_flower_l2_miss.sh selftests: forwarding: Fix layer 2 miss test flakiness 2024-02-09 11:32:14 -08:00
tc_flower_port_range.sh selftests/net/forwarding: Add a test case for tc-flower of mixed port and port-range 2025-02-19 18:54:59 -08:00
tc_flower_router.sh selftests: tc: add ingress device matching support 2019-06-19 10:09:22 -04:00
tc_flower.sh selftests: tc: Add generic erspan_opts matching support for tc-flower 2025-07-21 16:12:09 -07:00
tc_mpls_l2vpn.sh selftests: forwarding: Add MPLS L2VPN test 2020-12-04 17:44:06 -08:00
tc_police.sh selftests: net: lib: Add kill_process 2024-11-15 16:39:19 -08:00
tc_shblocks.sh selftests: tc: add ingress device matching support 2019-06-19 10:09:22 -04:00
tc_taprio.sh selftests: net: tc_taprio: new test 2025-04-29 14:44:34 -07:00
tc_tunnel_key.sh selftests: lib: Define more kselftest exit codes 2024-03-28 18:03:42 -07:00
tc_vlan_modify.sh selftests: forwarding: Test action VLAN modify 2019-03-28 17:20:52 -07:00
tsn_lib.sh selftests: net: tc_taprio: new test 2025-04-29 14:44:34 -07:00
vxlan_asymmetric_ipv6.sh selftests: forwarding: Add a test for VxLAN asymmetric routing with IPv6 2021-12-22 17:14:34 -08:00
vxlan_asymmetric.sh selftests: net: Fix typo 'the the' in comment 2022-07-26 20:26:58 -07:00
vxlan_bridge_1d_ipv6.sh selftests: forwarding: Fix ping failure due to short timeout 2024-03-21 12:33:04 +01:00
vxlan_bridge_1d_port_8472_ipv6.sh selftests: forwarding: Add VxLAN tests with a VLAN-unaware bridge for IPv6 2021-12-22 17:14:32 -08:00
vxlan_bridge_1d_port_8472.sh selftests: forwarding: vxlan_bridge_1d_port_8472: New test 2018-11-19 17:59:44 -08:00
vxlan_bridge_1d.sh selftests: vxlan_bridge: Test flood with unresolved FDB entry 2025-03-24 15:09:31 -07:00
vxlan_bridge_1q_ipv6.sh selftests: forwarding: Fix ping failure due to short timeout 2024-03-21 12:33:04 +01:00
vxlan_bridge_1q_mc_ul.sh selftests: forwarding: lib: Add an autodefer variant of forwarding_enable() 2025-09-26 17:48:40 -07:00
vxlan_bridge_1q_port_8472_ipv6.sh selftests: forwarding: Add VxLAN tests with a VLAN-aware bridge for IPv6 2021-12-22 17:14:33 -08:00
vxlan_bridge_1q_port_8472.sh selftests: forwarding: Add VxLAN test with a VLAN-aware bridge 2018-11-30 17:06:29 -08:00
vxlan_bridge_1q.sh selftests: vxlan_bridge: Test flood with unresolved FDB entry 2025-03-24 15:09:31 -07:00
vxlan_reserved.sh selftests: forwarding: lib: Add an autodefer variant of forwarding_enable() 2025-09-26 17:48:40 -07:00
vxlan_symmetric_ipv6.sh selftests: forwarding: Add a test for VxLAN symmetric routing with IPv6 2021-12-22 17:14:34 -08:00
vxlan_symmetric.sh selftests: forwarding: Add missing 'rp_filter' configuration 2020-10-18 12:47:32 -07:00

Motivation
==========

One of the nice things about network namespaces is that they allow one
to easily create and test complex environments.

Unfortunately, these namespaces can not be used with actual switching
ASICs, as their ports can not be migrated to other network namespaces
(dev->netns_immutable) and most of them probably do not support the
L1-separation provided by namespaces.

However, a similar kind of flexibility can be achieved by using VRFs and
by looping the switch ports together. For example:

                             br0
                              +
               vrf-h1         |           vrf-h2
                 +        +---+----+        +
                 |        |        |        |
    192.0.2.1/24 +        +        +        + 192.0.2.2/24
               swp1     swp2     swp3     swp4
                 +        +        +        +
                 |        |        |        |
                 +--------+        +--------+

The VRFs act as lightweight namespaces representing hosts connected to
the switch.

This approach for testing switch ASICs has several advantages over the
traditional method that requires multiple physical machines, to name a
few:

1. Only the device under test (DUT) is being tested without noise from
other system.

2. Ability to easily provision complex topologies. Testing bridging
between 4-ports LAGs or 8-way ECMP requires many physical links that are
not always available. With the VRF-based approach one merely needs to
loopback more ports.

These tests are written with switch ASICs in mind, but they can be run
on any Linux box using veth pairs to emulate physical loopbacks.

Guidelines for Writing Tests
============================

o Where possible, reuse an existing topology for different tests instead
  of recreating the same topology.
o Tests that use anything but the most trivial topologies should include
  an ASCII art showing the topology.
o Where possible, IPv6 and IPv4 addresses shall conform to RFC 3849 and
  RFC 5737, respectively.
o Where possible, tests shall be written so that they can be reused by
  multiple topologies and added to lib.sh.
o Checks shall be added to lib.sh for any external dependencies.
o Code shall be checked using ShellCheck [1] prior to submission.

1. https://www.shellcheck.net/

Customization
=============

The forwarding selftests framework uses a number of variables that
influence its behavior and tools it invokes, and how it invokes them, in
various ways. A number of these variables can be overridden. The way these
overridable variables are specified is typically one of the following two
syntaxes:

	: "${VARIABLE:=default_value}"
	VARIABLE=${VARIABLE:=default_value}

Any of these variables can be overridden. Notably net/forwarding/lib.sh and
net/lib.sh contain a number of overridable variables.

One way of overriding these variables is through the environment:

	PAUSE_ON_FAIL=yes ./some_test.sh

The variable NETIFS is special. Since it is an array variable, there is no
way to pass it through the environment. Its value can instead be given as
consecutive arguments to the selftest:

	./some_test.sh swp{1..8}

A way to customize variables in a persistent fashion is to create a file
named forwarding.config in this directory. lib.sh sources the file if
present, so it can contain any shell code. Typically it will contain
assignments of variables whose value should be overridden.

forwarding.config.sample is available in the directory as an example of
how forwarding.config might look.