Skip to contentSkip to conversation

selftests: Mark auto-deferring functions clearly

PATCH Applied Petr Machata 3 participants 28 messages Sep 25, 2025 – Sep 27, 2025

Subsystems (5)
lore
Share & tools
lore

Petr Machata

author maintainer
#0 lore raw

cover selftests: Mark auto-deferring functions clearly

selftests/net/lib.sh contains a suite of iproute2 wrappers that automatically schedule the corresponding cleanup through defer. The fact they do so is however not immediately obvious, one needs to know which functions are handling the deferral behind the scenes, and which expect the caller to handle cleanups themselves.

A convention for these auto-deferring functions would help both writing and patch review. This patchset does so by marking these functions with an adf_ prefix. We already have a few such functions: forwarding/lib.sh has adf_mcd_start() and a few selftests add private helpers that conform to this convention.

Patches #1 to #8 gradually convert individual functions, one per patch.

Patch #9 renames an auto-deferring private helpers named dfr_* to adf_*. The plan is not to retro-rename all private helpers, but I happened to know about this one.

Patches #10 to #12 introduce several autodefer helpers for commonly used forwarding/lib.sh functions, and opportunistically convert straightforward instances of 'action; defer counteraction' to the new helpers.

Patch #13 adds some README verbiage to pitch defer and the adf_* convention.

Petr Machata (13):
selftests: net: lib: Rename ip_link_add() to adf_*
selftests: net: lib: Rename ip_link_set_master() to adf_*
selftests: net: lib: Rename ip_link_set_addr() to adf_*
selftests: net: lib: Rename ip_link_set_up() to adf_*
selftests: net: lib: Rename ip_link_set_down() to adf_*
selftests: net: lib: Rename ip_addr_add() to adf_*
selftests: net: lib: Rename ip_route_add() to adf_*
selftests: net: lib: Rename bridge_vlan_add() to adf_*
selftests: net: vlan_bridge_binding: Rename dfr_set_binding_*() to

    adf_*

selftests: forwarding: lib: Add an autodefer variant of vrf_prepare()
selftests: forwarding: lib: Add an autodefer variant of
simple_if_init()
selftests: forwarding: lib: Add an autodefer variant of
forwarding_enable()
selftests: forwarding: README: Mention defer, adf_

 .../drivers/net/mlxsw/devlink_trap_policer.sh |   9 +-
 .../drivers/net/mlxsw/qos_ets_strict.sh       |  12 +-
 .../drivers/net/mlxsw/qos_max_descriptors.sh  |   9 +-
 .../drivers/net/mlxsw/qos_mc_aware.sh         |  12 +-
 .../drivers/net/mlxsw/sch_red_core.sh         |   6 +-
 tools/testing/selftests/net/fdb_notify.sh     |  26 ++--
 tools/testing/selftests/net/forwarding/README |  15 ++
 .../net/forwarding/bridge_activity_notify.sh  |  21 ++-
 .../net/forwarding/bridge_fdb_local_vlan_0.sh |  65 ++++----
 tools/testing/selftests/net/forwarding/lib.sh |  18 +++
 .../selftests/net/forwarding/sch_ets_core.sh  |   9 +-
 .../selftests/net/forwarding/sch_red.sh       |  12 +-
 .../selftests/net/forwarding/sch_tbf_core.sh  |   6 +-
 .../net/forwarding/vxlan_bridge_1q_mc_ul.sh   | 141 +++++++++---------
 .../net/forwarding/vxlan_reserved.sh          |  33 ++--
 tools/testing/selftests/net/lib.sh            |  16 +-
 .../net/test_vxlan_fdb_changelink.sh          |   8 +-
 .../selftests/net/vlan_bridge_binding.sh      |  44 +++---
 18 files changed, 225 insertions(+), 237 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/13 selftests: net: lib: Rename ip_link_add() to adf_*

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 tools/testing/selftests/net/fdb_notify.sh     | 20 ++++++-------
 .../net/forwarding/bridge_activity_notify.sh  |  2 +-
 .../net/forwarding/bridge_fdb_local_vlan_0.sh |  8 +++---
 .../net/forwarding/vxlan_bridge_1q_mc_ul.sh   | 28 +++++++++----------
 .../net/forwarding/vxlan_reserved.sh          |  4 +--
 tools/testing/selftests/net/lib.sh            |  2 +-
 .../net/test_vxlan_fdb_changelink.sh          |  6 ++--
 .../selftests/net/vlan_bridge_binding.sh      |  6 ++--
 8 files changed, 38 insertions(+), 38 deletions(-)
tools/testing/selftests/net/fdb_notify.sh +10 -10
index c159230c9b62..0a70f6383bfc 100755
@@ -40,15 +40,15 @@ do_test_dup()
 
 test_dup_bridge()
 {
-	ip_link_add br up type bridge vlan_filtering 1
+	adf_ip_link_add br up type bridge vlan_filtering 1
 	do_test_dup add "bridge" dev br self
 	do_test_dup del "bridge" dev br self
 }
 
 test_dup_vxlan_self()
 {
-	ip_link_add br up type bridge vlan_filtering 1
-	ip_link_add vx up type vxlan id 2000 dstport 4789
+	adf_ip_link_add br up type bridge vlan_filtering 1
+	adf_ip_link_add vx up type vxlan id 2000 dstport 4789
 	ip_link_set_master vx br
 
 	do_test_dup add "vxlan" dev vx self dst 192.0.2.1
@@ -57,8 +57,8 @@ test_dup_vxlan_self()
 
 test_dup_vxlan_master()
 {
-	ip_link_add br up type bridge vlan_filtering 1
-	ip_link_add vx up type vxlan id 2000 dstport 4789
+	adf_ip_link_add br up type bridge vlan_filtering 1
+	adf_ip_link_add vx up type vxlan id 2000 dstport 4789
 	ip_link_set_master vx br
 
 	do_test_dup add "vxlan master" dev vx master
@@ -67,8 +67,8 @@ test_dup_vxlan_master()
 
 test_dup_macvlan_self()
 {
-	ip_link_add dd up type dummy
-	ip_link_add mv up link dd type macvlan mode passthru
+	adf_ip_link_add dd up type dummy
+	adf_ip_link_add mv up link dd type macvlan mode passthru
 
 	do_test_dup add "macvlan self" dev mv self
 	do_test_dup del "macvlan self" dev mv self
@@ -76,9 +76,9 @@ test_dup_macvlan_self()
 
 test_dup_macvlan_master()
 {
-	ip_link_add br up type bridge vlan_filtering 1
-	ip_link_add dd up type dummy
-	ip_link_add mv up link dd type macvlan mode passthru
+	adf_ip_link_add br up type bridge vlan_filtering 1
+	adf_ip_link_add dd up type dummy
+	adf_ip_link_add mv up link dd type macvlan mode passthru
 	ip_link_set_master mv br
 
 	do_test_dup add "macvlan master" dev mv self
tools/testing/selftests/net/forwarding/bridge_activity_notify.sh +1 -1
index a20ef4bd310b..6f7df6325da5 100755
@@ -38,7 +38,7 @@ h2_create()
 
 switch_create()
 {
-	ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0 \
+	adf_ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0 \
 		ageing_time "$LOW_AGEING_TIME"
 	ip_link_set_up br1
 
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +4 -4
index 65f74c46c2f3..d9de3ad6e162 100755
@@ -134,7 +134,7 @@ adf_bridge_create()
 {
 	local mac
 
-	ip_link_add br up type bridge vlan_default_pvid 0 "$@"
+	adf_ip_link_add br up type bridge vlan_default_pvid 0 "$@"
 	mac=$(mac_get br)
 	adf_bridge_configure
 	ip_link_set_addr br "$mac"
@@ -142,8 +142,8 @@ adf_bridge_create()
 
 check_fdb_local_vlan_0_support()
 {
-	if ip_link_add XXbr up type bridge vlan_filtering 1 fdb_local_vlan_0 1 \
-		    &>/dev/null; then
+	if adf_ip_link_add XXbr up type bridge vlan_filtering 1 \
+			fdb_local_vlan_0 1 &>/dev/null; then
 		return 0
 	fi
 
@@ -375,7 +375,7 @@ test_q_sharing()
 
 adf_addr_set_bridge_create()
 {
-	ip_link_add br up type bridge vlan_filtering 0
+	adf_ip_link_add br up type bridge vlan_filtering 0
 	ip_link_set_addr br "$(mac_get br)"
 	adf_bridge_configure
 }
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +14 -14
index 462db0b603e7..503b1176d55f 100755
@@ -122,11 +122,11 @@ h1_create()
 	simple_if_init "$h1"
 	defer simple_if_fini "$h1"
 
-	ip_link_add "$h1.10" master "v$h1" link "$h1" type vlan id 10
+	adf_ip_link_add "$h1.10" master "v$h1" link "$h1" type vlan id 10
 	ip_link_set_up "$h1.10"
 	ip_addr_add "$h1.10" 192.0.2.1/28
 
-	ip_link_add "$h1.20" master "v$h1" link "$h1" type vlan id 20
+	adf_ip_link_add "$h1.20" master "v$h1" link "$h1" type vlan id 20
 	ip_link_set_up "$h1.20"
 	ip_addr_add "$h1.20" 2001:db8:1::1/64
 }
@@ -161,7 +161,7 @@ h2_create()
 	ip_link_set_up "v$h2"
 
 	# br2
-	ip_link_add br2 type bridge vlan_filtering 0 mcast_snooping 0
+	adf_ip_link_add br2 type bridge vlan_filtering 0 mcast_snooping 0
 	ip_link_set_master br2 "v$h2"
 	ip_link_set_up br2
 
@@ -186,7 +186,7 @@ h3_create()
 	ip_link_set_up "v$h3"
 
 	# br3
-	ip_link_add br3 type bridge vlan_filtering 0 mcast_snooping 0
+	adf_ip_link_add br3 type bridge vlan_filtering 0 mcast_snooping 0
 	ip_link_set_master br3 "v$h3"
 	ip_link_set_up br3
 
@@ -205,17 +205,17 @@ switch_create()
 
 	# br1
 	swp1_mac=$(mac_get "$swp1")
-	ip_link_add br1 type bridge vlan_filtering 1 \
+	adf_ip_link_add br1 type bridge vlan_filtering 1 \
 			    vlan_default_pvid 0 mcast_snooping 0
 	ip_link_set_addr br1 "$swp1_mac"
 	ip_link_set_up br1
 
 	# A dummy to force the IPv6 OIF=0 test to install a suitable MC route on
 	# $IPMR to be deterministic. Also used for the IPv6 RX!=TX ping test.
-	ip_link_add "X$IPMR" up type dummy
+	adf_ip_link_add "X$IPMR" up type dummy
 
 	# IPMR
-	ip_link_add "$IPMR" up type dummy
+	adf_ip_link_add "$IPMR" up type dummy
 	ip_addr_add "$IPMR" 192.0.2.100/28
 	ip_addr_add "$IPMR" 2001:db8:4::1/64
 
@@ -241,7 +241,7 @@ vx_create()
 	local name=$1; shift
 	local vid=$1; shift
 
-	ip_link_add "$name" up type vxlan dstport "$VXPORT" \
+	adf_ip_link_add "$name" up type vxlan dstport "$VXPORT" \
 		nolearning noudpcsum tos inherit ttl 16 \
 		"$@"
 	ip_link_set_master "$name" br1
@@ -295,7 +295,7 @@ ns_init_common()
 	ip_addr_add "$if_in" "$ipv6_in"
 
 	# br1
-	ip_link_add br1 type bridge vlan_filtering 1 \
+	adf_ip_link_add br1 type bridge vlan_filtering 1 \
 		    vlan_default_pvid 0 mcast_snooping 0
 	ip_link_set_up br1
 
@@ -304,7 +304,7 @@ ns_init_common()
 	vx20_create local "${ipv6_in%/*}" group "$GROUP6" dev "$if_in"
 
 	# w1
-	ip_link_add w1 type veth peer name w2
+	adf_ip_link_add w1 type veth peer name w2
 	ip_link_set_master w1 br1
 	ip_link_set_up w1
 	bridge_vlan_add vid 10 dev w1
@@ -315,12 +315,12 @@ ns_init_common()
 	defer simple_if_fini w2
 
 	# w2.10
-	ip_link_add w2.10 master vw2 link w2 type vlan id 10
+	adf_ip_link_add w2.10 master vw2 link w2 type vlan id 10
 	ip_link_set_up w2.10
 	ip_addr_add w2.10 "$ipv4_host"
 
 	# w2.20
-	ip_link_add w2.20 master vw2 link w2 type vlan id 20
+	adf_ip_link_add w2.20 master vw2 link w2 type vlan id 20
 	ip_link_set_up w2.20
 	ip_addr_add w2.20 "$ipv6_host"
 }
@@ -377,8 +377,8 @@ setup_prepare()
 	forwarding_enable
 	defer forwarding_restore
 
-	ip_link_add "v1$h2" type veth peer name "v2$h2"
-	ip_link_add "v1$h3" type veth peer name "v2$h3"
+	adf_ip_link_add "v1$h2" type veth peer name "v2$h2"
+	adf_ip_link_add "v1$h3" type veth peer name "v2$h3"
 
 	h1_create
 	h2_create
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +2 -2
index 46c31794b91b..692644c3a489 100755
@@ -60,7 +60,7 @@ h1_create()
 
 switch_create()
 {
-	ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0
+	adf_ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0
 	# Make sure the bridge uses the MAC address of the local port and not
 	# that of the VxLAN's device.
 	ip_link_set_addr br1 $(mac_get $swp1)
@@ -200,7 +200,7 @@ vxlan_ping_do()
 
 vxlan_device_add()
 {
-	ip_link_add vx1 up type vxlan id 1000		\
+	adf_ip_link_add vx1 up type vxlan id 1000		\
 		local 192.0.2.17 dstport "$VXPORT"	\
 		nolearning noudpcsum tos inherit ttl 100 "$@"
 	ip_link_set_master vx1 br1
tools/testing/selftests/net/lib.sh +1 -1
index fea9c37fe338..7fbd9e5ce2be 100644
@@ -543,7 +543,7 @@ require_command()
 	fi
 }
 
-ip_link_add()
+adf_ip_link_add()
 {
 	local name=$1; shift
 
tools/testing/selftests/net/test_vxlan_fdb_changelink.sh +3 -3
index 062f957950af..1443b57a6501 100755
@@ -21,7 +21,7 @@ test_set_remote()
 {
 	RET=0
 
-	ip_link_add vx up type vxlan id 2000 dstport 4789
+	adf_ip_link_add vx up type vxlan id 2000 dstport 4789
 	bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.20 self permanent
 	bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.30 self permanent
 	check_remotes "fdb append"
@@ -74,12 +74,12 @@ test_change_mc_remote()
 {
 	check_command netstat || return
 
-	ip_link_add v1 up type veth peer name v2
+	adf_ip_link_add v1 up type veth peer name v2
 	ip_link_set_up v2
 
 	RET=0
 
-	ip_link_add vx up type vxlan dstport 4789 \
+	adf_ip_link_add vx up type vxlan dstport 4789 \
 		local 192.0.2.1 $(fmt_remote 224.1.1.1) dev v1 vni 1000
 
 	check_membership "group=224.1.1.1 fail=0" \
tools/testing/selftests/net/vlan_bridge_binding.sh +3 -3
index e7cb8c678bde..7797507cd14f 100755
@@ -18,10 +18,10 @@ setup_prepare()
 {
 	local port
 
-	ip_link_add br up type bridge vlan_filtering 1
+	adf_ip_link_add br up type bridge vlan_filtering 1
 
 	for port in d1 d2 d3; do
-		ip_link_add $port type veth peer name r$port
+		adf_ip_link_add $port type veth peer name r$port
 		ip_link_set_up $port
 		ip_link_set_up r$port
 		ip_link_set_master $port br
@@ -74,7 +74,7 @@ add_one_vlan()
 	local link=$1; shift
 	local id=$1; shift
 
-	ip_link_add $link.$id link $link type vlan id $id "$@"
+	adf_ip_link_add $link.$id link $link type vlan id $id "$@"
 }
 
 add_vlans()
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH 2/13 selftests: net: lib: Rename ip_link_set_master() to adf_*

In reply to Petr Machata

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 tools/testing/selftests/net/fdb_notify.sh      |  6 +++---
 .../net/forwarding/bridge_activity_notify.sh   |  4 ++--
 .../net/forwarding/bridge_fdb_local_vlan_0.sh  |  2 +-
 .../net/forwarding/vxlan_bridge_1q_mc_ul.sh    | 18 +++++++++---------
 .../selftests/net/forwarding/vxlan_reserved.sh |  4 ++--
 tools/testing/selftests/net/lib.sh             |  2 +-
 .../selftests/net/vlan_bridge_binding.sh       |  2 +-
 7 files changed, 19 insertions(+), 19 deletions(-)
tools/testing/selftests/net/fdb_notify.sh +3 -3
index 0a70f6383bfc..0b8a2465dd04 100755
@@ -49,7 +49,7 @@ test_dup_vxlan_self()
 {
 	adf_ip_link_add br up type bridge vlan_filtering 1
 	adf_ip_link_add vx up type vxlan id 2000 dstport 4789
-	ip_link_set_master vx br
+	adf_ip_link_set_master vx br
 
 	do_test_dup add "vxlan" dev vx self dst 192.0.2.1
 	do_test_dup del "vxlan" dev vx self dst 192.0.2.1
@@ -59,7 +59,7 @@ test_dup_vxlan_master()
 {
 	adf_ip_link_add br up type bridge vlan_filtering 1
 	adf_ip_link_add vx up type vxlan id 2000 dstport 4789
-	ip_link_set_master vx br
+	adf_ip_link_set_master vx br
 
 	do_test_dup add "vxlan master" dev vx master
 	do_test_dup del "vxlan master" dev vx master
@@ -79,7 +79,7 @@ test_dup_macvlan_master()
 	adf_ip_link_add br up type bridge vlan_filtering 1
 	adf_ip_link_add dd up type dummy
 	adf_ip_link_add mv up link dd type macvlan mode passthru
-	ip_link_set_master mv br
+	adf_ip_link_set_master mv br
 
 	do_test_dup add "macvlan master" dev mv self
 	do_test_dup del "macvlan master" dev mv self
tools/testing/selftests/net/forwarding/bridge_activity_notify.sh +2 -2
index 6f7df6325da5..3d5f868b261a 100755
@@ -42,10 +42,10 @@ switch_create()
 		ageing_time "$LOW_AGEING_TIME"
 	ip_link_set_up br1
 
-	ip_link_set_master "$swp1" br1
+	adf_ip_link_set_master "$swp1" br1
 	ip_link_set_up "$swp1"
 
-	ip_link_set_master "$swp2" br1
+	adf_ip_link_set_master "$swp2" br1
 	ip_link_set_up "$swp2"
 }
 
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +1 -1
index d9de3ad6e162..561cb9f253b6 100755
@@ -123,7 +123,7 @@ adf_bridge_configure()
 	bridge_vlan_add dev br vid 3 self
 
 	for dev in "$swp1" "$swp2"; do
-		ip_link_set_master "$dev" br
+		adf_ip_link_set_master "$dev" br
 		bridge_vlan_add dev "$dev" vid 1 pvid untagged
 		bridge_vlan_add dev "$dev" vid 2
 		bridge_vlan_add dev "$dev" vid 3
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +9 -9
index 503b1176d55f..9fc956caf961 100755
@@ -162,16 +162,16 @@ h2_create()
 
 	# br2
 	adf_ip_link_add br2 type bridge vlan_filtering 0 mcast_snooping 0
-	ip_link_set_master br2 "v$h2"
+	adf_ip_link_set_master br2 "v$h2"
 	ip_link_set_up br2
 
 	# $h2
-	ip_link_set_master "$h2" br2
+	adf_ip_link_set_master "$h2" br2
 	install_capture "$h2"
 
 	# v1$h2
 	ip_link_set_up "v1$h2"
-	ip_link_set_master "v1$h2" br2
+	adf_ip_link_set_master "v1$h2" br2
 }
 
 h3_create()
@@ -187,16 +187,16 @@ h3_create()
 
 	# br3
 	adf_ip_link_add br3 type bridge vlan_filtering 0 mcast_snooping 0
-	ip_link_set_master br3 "v$h3"
+	adf_ip_link_set_master br3 "v$h3"
 	ip_link_set_up br3
 
 	# $h3
-	ip_link_set_master "$h3" br3
+	adf_ip_link_set_master "$h3" br3
 	install_capture "$h3"
 
 	# v1$h3
 	ip_link_set_up "v1$h3"
-	ip_link_set_master "v1$h3" br3
+	adf_ip_link_set_master "v1$h3" br3
 }
 
 switch_create()
@@ -221,7 +221,7 @@ switch_create()
 
 	# $swp1
 	ip_link_set_up "$swp1"
-	ip_link_set_master "$swp1" br1
+	adf_ip_link_set_master "$swp1" br1
 	bridge_vlan_add vid 10 dev "$swp1"
 	bridge_vlan_add vid 20 dev "$swp1"
 
@@ -244,7 +244,7 @@ vx_create()
 	adf_ip_link_add "$name" up type vxlan dstport "$VXPORT" \
 		nolearning noudpcsum tos inherit ttl 16 \
 		"$@"
-	ip_link_set_master "$name" br1
+	adf_ip_link_set_master "$name" br1
 	bridge_vlan_add vid "$vid" dev "$name" pvid untagged
 }
 export -f vx_create
@@ -305,7 +305,7 @@ ns_init_common()
 
 	# w1
 	adf_ip_link_add w1 type veth peer name w2
-	ip_link_set_master w1 br1
+	adf_ip_link_set_master w1 br1
 	ip_link_set_up w1
 	bridge_vlan_add vid 10 dev w1
 	bridge_vlan_add vid 20 dev w1
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +2 -2
index 692644c3a489..839def391b6e 100755
@@ -70,7 +70,7 @@ switch_create()
 	ip_addr_add $rp1 192.0.2.17/28
 	ip_route_add 192.0.2.32/28 nexthop via 192.0.2.18
 
-	ip_link_set_master $swp1 br1
+	adf_ip_link_set_master $swp1 br1
 	ip_link_set_up $swp1
 }
 
@@ -203,7 +203,7 @@ vxlan_device_add()
 	adf_ip_link_add vx1 up type vxlan id 1000		\
 		local 192.0.2.17 dstport "$VXPORT"	\
 		nolearning noudpcsum tos inherit ttl 100 "$@"
-	ip_link_set_master vx1 br1
+	adf_ip_link_set_master vx1 br1
 }
 
 vxlan_all_reserved_bits()
tools/testing/selftests/net/lib.sh +1 -1
index 7fbd9e5ce2be..c9a15fe5448a 100644
@@ -551,7 +551,7 @@ adf_ip_link_add()
 		defer ip link del dev "$name"
 }
 
-ip_link_set_master()
+adf_ip_link_set_master()
 {
 	local member=$1; shift
 	local master=$1; shift
tools/testing/selftests/net/vlan_bridge_binding.sh +1 -1
index 7797507cd14f..ad02d406039c 100755
@@ -24,7 +24,7 @@ setup_prepare()
 		adf_ip_link_add $port type veth peer name r$port
 		ip_link_set_up $port
 		ip_link_set_up r$port
-		ip_link_set_master $port br
+		adf_ip_link_set_master $port br
 	done
 
 	bridge_vlan_add vid 11 dev br self
Signature · 1 line
2.49.0
author maintainer
#5 lore raw

PATCH 3/13 selftests: net: lib: Rename ip_link_set_addr() to adf_*

In reply to Petr Machata

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 .../selftests/net/forwarding/bridge_fdb_local_vlan_0.sh     | 6 +++---
 .../selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh       | 2 +-
 tools/testing/selftests/net/forwarding/vxlan_reserved.sh    | 2 +-
 tools/testing/selftests/net/lib.sh                          | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +3 -3
index 561cb9f253b6..07e07a266c80 100755
@@ -137,7 +137,7 @@ adf_bridge_create()
 	adf_ip_link_add br up type bridge vlan_default_pvid 0 "$@"
 	mac=$(mac_get br)
 	adf_bridge_configure
-	ip_link_set_addr br "$mac"
+	adf_ip_link_set_addr br "$mac"
 }
 
 check_fdb_local_vlan_0_support()
@@ -296,7 +296,7 @@ change_mac()
 	cur_mac=$(mac_get "$dev")
 
 	log_info "Change $dev MAC $cur_mac -> $mac"
-	ip_link_set_addr "$dev" "$mac"
+	adf_ip_link_set_addr "$dev" "$mac"
 	defer log_info "Change $dev MAC back"
 }
 
@@ -376,7 +376,7 @@ test_q_sharing()
 adf_addr_set_bridge_create()
 {
 	adf_ip_link_add br up type bridge vlan_filtering 0
-	ip_link_set_addr br "$(mac_get br)"
+	adf_ip_link_set_addr br "$(mac_get br)"
 	adf_bridge_configure
 }
 
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +1 -1
index 9fc956caf961..e344cb2a5f04 100755
@@ -207,7 +207,7 @@ switch_create()
 	swp1_mac=$(mac_get "$swp1")
 	adf_ip_link_add br1 type bridge vlan_filtering 1 \
 			    vlan_default_pvid 0 mcast_snooping 0
-	ip_link_set_addr br1 "$swp1_mac"
+	adf_ip_link_set_addr br1 "$swp1_mac"
 	ip_link_set_up br1
 
 	# A dummy to force the IPv6 OIF=0 test to install a suitable MC route on
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +1 -1
index 839def391b6e..c0c96fdb16e6 100755
@@ -63,7 +63,7 @@ switch_create()
 	adf_ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0
 	# Make sure the bridge uses the MAC address of the local port and not
 	# that of the VxLAN's device.
-	ip_link_set_addr br1 $(mac_get $swp1)
+	adf_ip_link_set_addr br1 $(mac_get $swp1)
 	ip_link_set_up br1
 
 	ip_link_set_up $rp1
tools/testing/selftests/net/lib.sh +1 -1
index c9a15fe5448a..21b998b7330f 100644
@@ -560,7 +560,7 @@ adf_ip_link_set_master()
 		defer ip link set dev "$member" nomaster
 }
 
-ip_link_set_addr()
+adf_ip_link_set_addr()
 {
 	local name=$1; shift
 	local addr=$1; shift
Signature · 1 line
2.49.0
author maintainer
#7 lore raw

PATCH 4/13 selftests: net: lib: Rename ip_link_set_up() to adf_*

In reply to Petr Machata

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 .../net/forwarding/bridge_activity_notify.sh  |  6 +--
 .../net/forwarding/bridge_fdb_local_vlan_0.sh |  6 +--
 .../net/forwarding/vxlan_bridge_1q_mc_ul.sh   | 38 +++++++++----------
 .../net/forwarding/vxlan_reserved.sh          |  6 +--
 tools/testing/selftests/net/lib.sh            |  2 +-
 .../net/test_vxlan_fdb_changelink.sh          |  2 +-
 .../selftests/net/vlan_bridge_binding.sh      |  4 +-
 7 files changed, 32 insertions(+), 32 deletions(-)
tools/testing/selftests/net/forwarding/bridge_activity_notify.sh +3 -3
index 3d5f868b261a..8ceb205fdca0 100755
@@ -40,13 +40,13 @@ switch_create()
 {
 	adf_ip_link_add br1 type bridge vlan_filtering 0 mcast_snooping 0 \
 		ageing_time "$LOW_AGEING_TIME"
-	ip_link_set_up br1
+	adf_ip_link_set_up br1
 
 	adf_ip_link_set_master "$swp1" br1
-	ip_link_set_up "$swp1"
+	adf_ip_link_set_up "$swp1"
 
 	adf_ip_link_set_master "$swp2" br1
-	ip_link_set_up "$swp2"
+	adf_ip_link_set_up "$swp2"
 }
 
 setup_prepare()
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +3 -3
index 07e07a266c80..202eee16ac19 100755
@@ -78,13 +78,13 @@ h3_create()
 
 switch_create()
 {
-	ip_link_set_up "$swp1"
+	adf_ip_link_set_up "$swp1"
 
-	ip_link_set_up "$swp2"
+	adf_ip_link_set_up "$swp2"
 
 	ip_addr_add "$swp3" 192.0.2.17/28
 	ip_addr_add "$swp3" 2001:db8:2::1/64
-	ip_link_set_up "$swp3"
+	adf_ip_link_set_up "$swp3"
 }
 
 setup_prepare()
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +19 -19
index e344cb2a5f04..20366c61944e 100755
@@ -123,11 +123,11 @@ h1_create()
 	defer simple_if_fini "$h1"
 
 	adf_ip_link_add "$h1.10" master "v$h1" link "$h1" type vlan id 10
-	ip_link_set_up "$h1.10"
+	adf_ip_link_set_up "$h1.10"
 	ip_addr_add "$h1.10" 192.0.2.1/28
 
 	adf_ip_link_add "$h1.20" master "v$h1" link "$h1" type vlan id 20
-	ip_link_set_up "$h1.20"
+	adf_ip_link_set_up "$h1.20"
 	ip_addr_add "$h1.20" 2001:db8:1::1/64
 }
 
@@ -152,50 +152,50 @@ install_capture()
 h2_create()
 {
 	# $h2
-	ip_link_set_up "$h2"
+	adf_ip_link_set_up "$h2"
 
 	# H2
 	vrf_create "v$h2"
 	defer vrf_destroy "v$h2"
 
-	ip_link_set_up "v$h2"
+	adf_ip_link_set_up "v$h2"
 
 	# br2
 	adf_ip_link_add br2 type bridge vlan_filtering 0 mcast_snooping 0
 	adf_ip_link_set_master br2 "v$h2"
-	ip_link_set_up br2
+	adf_ip_link_set_up br2
 
 	# $h2
 	adf_ip_link_set_master "$h2" br2
 	install_capture "$h2"
 
 	# v1$h2
-	ip_link_set_up "v1$h2"
+	adf_ip_link_set_up "v1$h2"
 	adf_ip_link_set_master "v1$h2" br2
 }
 
 h3_create()
 {
 	# $h3
-	ip_link_set_up "$h3"
+	adf_ip_link_set_up "$h3"
 
 	# H3
 	vrf_create "v$h3"
 	defer vrf_destroy "v$h3"
 
-	ip_link_set_up "v$h3"
+	adf_ip_link_set_up "v$h3"
 
 	# br3
 	adf_ip_link_add br3 type bridge vlan_filtering 0 mcast_snooping 0
 	adf_ip_link_set_master br3 "v$h3"
-	ip_link_set_up br3
+	adf_ip_link_set_up br3
 
 	# $h3
 	adf_ip_link_set_master "$h3" br3
 	install_capture "$h3"
 
 	# v1$h3
-	ip_link_set_up "v1$h3"
+	adf_ip_link_set_up "v1$h3"
 	adf_ip_link_set_master "v1$h3" br3
 }
 
@@ -208,7 +208,7 @@ switch_create()
 	adf_ip_link_add br1 type bridge vlan_filtering 1 \
 			    vlan_default_pvid 0 mcast_snooping 0
 	adf_ip_link_set_addr br1 "$swp1_mac"
-	ip_link_set_up br1
+	adf_ip_link_set_up br1
 
 	# A dummy to force the IPv6 OIF=0 test to install a suitable MC route on
 	# $IPMR to be deterministic. Also used for the IPv6 RX!=TX ping test.
@@ -220,18 +220,18 @@ switch_create()
 	ip_addr_add "$IPMR" 2001:db8:4::1/64
 
 	# $swp1
-	ip_link_set_up "$swp1"
+	adf_ip_link_set_up "$swp1"
 	adf_ip_link_set_master "$swp1" br1
 	bridge_vlan_add vid 10 dev "$swp1"
 	bridge_vlan_add vid 20 dev "$swp1"
 
 	# $swp2
-	ip_link_set_up "$swp2"
+	adf_ip_link_set_up "$swp2"
 	ip_addr_add "$swp2" 192.0.2.33/28
 	ip_addr_add "$swp2" 2001:db8:2::1/64
 
 	# $swp3
-	ip_link_set_up "$swp3"
+	adf_ip_link_set_up "$swp3"
 	ip_addr_add "$swp3" 192.0.2.65/28
 	ip_addr_add "$swp3" 2001:db8:3::1/64
 }
@@ -290,14 +290,14 @@ ns_init_common()
 	local ipv6_host=$1; shift
 
 	# v2$h2 / v2$h3
-	ip_link_set_up "$if_in"
+	adf_ip_link_set_up "$if_in"
 	ip_addr_add "$if_in" "$ipv4_in"
 	ip_addr_add "$if_in" "$ipv6_in"
 
 	# br1
 	adf_ip_link_add br1 type bridge vlan_filtering 1 \
 		    vlan_default_pvid 0 mcast_snooping 0
-	ip_link_set_up br1
+	adf_ip_link_set_up br1
 
 	# vx10, vx20
 	vx10_create local "${ipv4_in%/*}" group "$GROUP4" dev "$if_in"
@@ -306,7 +306,7 @@ ns_init_common()
 	# w1
 	adf_ip_link_add w1 type veth peer name w2
 	adf_ip_link_set_master w1 br1
-	ip_link_set_up w1
+	adf_ip_link_set_up w1
 	bridge_vlan_add vid 10 dev w1
 	bridge_vlan_add vid 20 dev w1
 
@@ -316,12 +316,12 @@ ns_init_common()
 
 	# w2.10
 	adf_ip_link_add w2.10 master vw2 link w2 type vlan id 10
-	ip_link_set_up w2.10
+	adf_ip_link_set_up w2.10
 	ip_addr_add w2.10 "$ipv4_host"
 
 	# w2.20
 	adf_ip_link_add w2.20 master vw2 link w2 type vlan id 20
-	ip_link_set_up w2.20
+	adf_ip_link_set_up w2.20
 	ip_addr_add w2.20 "$ipv6_host"
 }
 export -f ns_init_common
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +3 -3
index c0c96fdb16e6..c7d17fff9575 100755
@@ -64,14 +64,14 @@ switch_create()
 	# Make sure the bridge uses the MAC address of the local port and not
 	# that of the VxLAN's device.
 	adf_ip_link_set_addr br1 $(mac_get $swp1)
-	ip_link_set_up br1
+	adf_ip_link_set_up br1
 
-	ip_link_set_up $rp1
+	adf_ip_link_set_up $rp1
 	ip_addr_add $rp1 192.0.2.17/28
 	ip_route_add 192.0.2.32/28 nexthop via 192.0.2.18
 
 	adf_ip_link_set_master $swp1 br1
-	ip_link_set_up $swp1
+	adf_ip_link_set_up $swp1
 }
 
 vrp2_create()
tools/testing/selftests/net/lib.sh +1 -1
index 21b998b7330f..691f58fad0e3 100644
@@ -585,7 +585,7 @@ ip_link_is_up()
 	ip_link_has_flag "$1" UP
 }
 
-ip_link_set_up()
+adf_ip_link_set_up()
 {
 	local name=$1; shift
 
tools/testing/selftests/net/test_vxlan_fdb_changelink.sh +1 -1
index 1443b57a6501..8b414d0edada 100755
@@ -75,7 +75,7 @@ test_change_mc_remote()
 	check_command netstat || return
 
 	adf_ip_link_add v1 up type veth peer name v2
-	ip_link_set_up v2
+	adf_ip_link_set_up v2
 
 	RET=0
 
tools/testing/selftests/net/vlan_bridge_binding.sh +2 -2
index ad02d406039c..c6f5d63384f3 100755
@@ -22,8 +22,8 @@ setup_prepare()
 
 	for port in d1 d2 d3; do
 		adf_ip_link_add $port type veth peer name r$port
-		ip_link_set_up $port
-		ip_link_set_up r$port
+		adf_ip_link_set_up $port
+		adf_ip_link_set_up r$port
 		adf_ip_link_set_master $port br
 	done
 
Signature · 1 line
2.49.0
author maintainer
#9 lore raw

PATCH 5/13 selftests: net: lib: Rename ip_link_set_down() to adf_*

In reply to Petr Machata

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 tools/testing/selftests/net/lib.sh                 | 2 +-
 tools/testing/selftests/net/vlan_bridge_binding.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/net/lib.sh +1 -1
index 691f58fad0e3..98c62ff4bccf 100644
@@ -595,7 +595,7 @@ adf_ip_link_set_up()
 	fi
 }
 
-ip_link_set_down()
+adf_ip_link_set_down()
 {
 	local name=$1; shift
 
tools/testing/selftests/net/vlan_bridge_binding.sh +1 -1
index c6f5d63384f3..09081bcbfcc7 100755
@@ -98,7 +98,7 @@ down_netdevs()
 	local dev
 
 	for dev in "$@"; do
-		ip_link_set_down $dev
+		adf_ip_link_set_down $dev
 	done
 }
 
Signature · 1 line
2.49.0
author maintainer
#11 lore raw

PATCH 6/13 selftests: net: lib: Rename ip_addr_add() to adf_*

In reply to Petr Machata

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 .../net/forwarding/bridge_fdb_local_vlan_0.sh |  8 ++---
 .../net/forwarding/vxlan_bridge_1q_mc_ul.sh   | 32 +++++++++----------
 .../net/forwarding/vxlan_reserved.sh          |  2 +-
 tools/testing/selftests/net/lib.sh            |  2 +-
 4 files changed, 22 insertions(+), 22 deletions(-)
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +4 -4
index 202eee16ac19..868f2fa5f9d2 100755
@@ -82,8 +82,8 @@ switch_create()
 
 	adf_ip_link_set_up "$swp2"
 
-	ip_addr_add "$swp3" 192.0.2.17/28
-	ip_addr_add "$swp3" 2001:db8:2::1/64
+	adf_ip_addr_add "$swp3" 192.0.2.17/28
+	adf_ip_addr_add "$swp3" 2001:db8:2::1/64
 	adf_ip_link_set_up "$swp3"
 }
 
@@ -115,8 +115,8 @@ adf_bridge_configure()
 {
 	local dev
 
-	ip_addr_add br 192.0.2.3/28
-	ip_addr_add br 2001:db8:1::3/64
+	adf_ip_addr_add br 192.0.2.3/28
+	adf_ip_addr_add br 2001:db8:1::3/64
 
 	bridge_vlan_add dev br vid 1 pvid untagged self
 	bridge_vlan_add dev br vid 2 self
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +16 -16
index 20366c61944e..091833541b06 100755
@@ -124,11 +124,11 @@ h1_create()
 
 	adf_ip_link_add "$h1.10" master "v$h1" link "$h1" type vlan id 10
 	adf_ip_link_set_up "$h1.10"
-	ip_addr_add "$h1.10" 192.0.2.1/28
+	adf_ip_addr_add "$h1.10" 192.0.2.1/28
 
 	adf_ip_link_add "$h1.20" master "v$h1" link "$h1" type vlan id 20
 	adf_ip_link_set_up "$h1.20"
-	ip_addr_add "$h1.20" 2001:db8:1::1/64
+	adf_ip_addr_add "$h1.20" 2001:db8:1::1/64
 }
 
 install_capture()
@@ -216,8 +216,8 @@ switch_create()
 
 	# IPMR
 	adf_ip_link_add "$IPMR" up type dummy
-	ip_addr_add "$IPMR" 192.0.2.100/28
-	ip_addr_add "$IPMR" 2001:db8:4::1/64
+	adf_ip_addr_add "$IPMR" 192.0.2.100/28
+	adf_ip_addr_add "$IPMR" 2001:db8:4::1/64
 
 	# $swp1
 	adf_ip_link_set_up "$swp1"
@@ -227,13 +227,13 @@ switch_create()
 
 	# $swp2
 	adf_ip_link_set_up "$swp2"
-	ip_addr_add "$swp2" 192.0.2.33/28
-	ip_addr_add "$swp2" 2001:db8:2::1/64
+	adf_ip_addr_add "$swp2" 192.0.2.33/28
+	adf_ip_addr_add "$swp2" 2001:db8:2::1/64
 
 	# $swp3
 	adf_ip_link_set_up "$swp3"
-	ip_addr_add "$swp3" 192.0.2.65/28
-	ip_addr_add "$swp3" 2001:db8:3::1/64
+	adf_ip_addr_add "$swp3" 192.0.2.65/28
+	adf_ip_addr_add "$swp3" 2001:db8:3::1/64
 }
 
 vx_create()
@@ -291,8 +291,8 @@ ns_init_common()
 
 	# v2$h2 / v2$h3
 	adf_ip_link_set_up "$if_in"
-	ip_addr_add "$if_in" "$ipv4_in"
-	ip_addr_add "$if_in" "$ipv6_in"
+	adf_ip_addr_add "$if_in" "$ipv4_in"
+	adf_ip_addr_add "$if_in" "$ipv6_in"
 
 	# br1
 	adf_ip_link_add br1 type bridge vlan_filtering 1 \
@@ -317,12 +317,12 @@ ns_init_common()
 	# w2.10
 	adf_ip_link_add w2.10 master vw2 link w2 type vlan id 10
 	adf_ip_link_set_up w2.10
-	ip_addr_add w2.10 "$ipv4_host"
+	adf_ip_addr_add w2.10 "$ipv4_host"
 
 	# w2.20
 	adf_ip_link_add w2.20 master vw2 link w2 type vlan id 20
 	adf_ip_link_set_up w2.20
-	ip_addr_add w2.20 "$ipv6_host"
+	adf_ip_addr_add w2.20 "$ipv6_host"
 }
 export -f ns_init_common
 
@@ -720,7 +720,7 @@ ipv4_mcroute_fdb_oif0_sep()
 {
 	adf_install_sg_sep
 
-	ip_addr_add lo 192.0.2.120/28
+	adf_ip_addr_add lo 192.0.2.120/28
 	vx10_create_wait local 192.0.2.120 group "$GROUP4" dev "$IPMR" mcroute
 	bridge fdb del dev vx10 00:00:00:00:00:00
 	bridge fdb add dev vx10 00:00:00:00:00:00 self static dst "$GROUP4"
@@ -731,7 +731,7 @@ ipv4_mcroute_fdb_oif0_sep_rx()
 {
 	adf_install_sg_sep_rx lo
 
-	ip_addr_add lo 192.0.2.120/28
+	adf_ip_addr_add lo 192.0.2.120/28
 	vx10_create_wait local 192.0.2.120 group "$GROUP4" dev "$IPMR" mcroute
 	bridge fdb del dev vx10 00:00:00:00:00:00
 	bridge fdb add dev vx10 00:00:00:00:00:00 self static dst "$GROUP4"
@@ -742,7 +742,7 @@ ipv4_mcroute_fdb_sep_rx()
 {
 	adf_install_sg_sep_rx lo
 
-	ip_addr_add lo 192.0.2.120/28
+	adf_ip_addr_add lo 192.0.2.120/28
 	vx10_create_wait local 192.0.2.120 group "$GROUP4" dev "$IPMR" mcroute
 	bridge fdb del dev vx10 00:00:00:00:00:00
 	bridge fdb add \
@@ -754,7 +754,7 @@ ipv6_mcroute_fdb_sep_rx()
 {
 	adf_install_sg_sep_rx "X$IPMR"
 
-	ip_addr_add "X$IPMR" 2001:db8:5::1/64
+	adf_ip_addr_add "X$IPMR" 2001:db8:5::1/64
 	vx20_create_wait local 2001:db8:5::1 group "$GROUP6" dev "$IPMR" mcroute
 	bridge -6 fdb del dev vx20 00:00:00:00:00:00
 	bridge -6 fdb add dev vx20 00:00:00:00:00:00 \
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +1 -1
index c7d17fff9575..a726a9a9eb65 100755
@@ -67,7 +67,7 @@ switch_create()
 	adf_ip_link_set_up br1
 
 	adf_ip_link_set_up $rp1
-	ip_addr_add $rp1 192.0.2.17/28
+	adf_ip_addr_add $rp1 192.0.2.17/28
 	ip_route_add 192.0.2.32/28 nexthop via 192.0.2.18
 
 	adf_ip_link_set_master $swp1 br1
tools/testing/selftests/net/lib.sh +1 -1
index 98c62ff4bccf..70331c3baa47 100644
@@ -605,7 +605,7 @@ adf_ip_link_set_down()
 	fi
 }
 
-ip_addr_add()
+adf_ip_addr_add()
 {
 	local name=$1; shift
 
Signature · 1 line
2.49.0
author maintainer
#13 lore raw

PATCH 7/13 selftests: net: lib: Rename ip_route_add() to adf_*

In reply to Petr Machata

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 .../selftests/net/forwarding/bridge_fdb_local_vlan_0.sh   | 8 ++++----
 tools/testing/selftests/net/forwarding/vxlan_reserved.sh  | 2 +-
 tools/testing/selftests/net/lib.sh                        | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +4 -4
index 868f2fa5f9d2..b8fd85a20b78 100755
@@ -47,8 +47,8 @@ host_create()
 	simple_if_init "$h" "$ipv4" "$ipv6"
 	defer simple_if_fini "$h" "$ipv4" "$ipv6"
 
-	ip_route_add vrf "v$h" 192.0.2.16/28 nexthop via 192.0.2.3
-	ip_route_add vrf "v$h" 2001:db8:2::/64 nexthop via 2001:db8:1::3
+	adf_ip_route_add vrf "v$h" 192.0.2.16/28 nexthop via 192.0.2.3
+	adf_ip_route_add vrf "v$h" 2001:db8:2::/64 nexthop via 2001:db8:1::3
 }
 
 h3_create()
@@ -56,8 +56,8 @@ h3_create()
 	simple_if_init "$h3" 192.0.2.18/28 2001:db8:2::2/64
 	defer simple_if_fini "$h3" 192.0.2.18/28 2001:db8:2::2/64
 
-	ip_route_add vrf "v$h3" 192.0.2.0/28 nexthop via 192.0.2.17
-	ip_route_add vrf "v$h3" 2001:db8:1::/64 nexthop via 2001:db8:2::1
+	adf_ip_route_add vrf "v$h3" 192.0.2.0/28 nexthop via 192.0.2.17
+	adf_ip_route_add vrf "v$h3" 2001:db8:1::/64 nexthop via 2001:db8:2::1
 
 	tc qdisc add dev "$h3" clsact
 	defer tc qdisc del dev "$h3" clsact
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +1 -1
index a726a9a9eb65..6fa1668986cc 100755
@@ -68,7 +68,7 @@ switch_create()
 
 	adf_ip_link_set_up $rp1
 	adf_ip_addr_add $rp1 192.0.2.17/28
-	ip_route_add 192.0.2.32/28 nexthop via 192.0.2.18
+	adf_ip_route_add 192.0.2.32/28 nexthop via 192.0.2.18
 
 	adf_ip_link_set_master $swp1 br1
 	adf_ip_link_set_up $swp1
tools/testing/selftests/net/lib.sh +1 -1
index 70331c3baa47..208919a44703 100644
@@ -613,7 +613,7 @@ adf_ip_addr_add()
 		defer ip addr del dev "$name" "$@"
 }
 
-ip_route_add()
+adf_ip_route_add()
 {
 	ip route add "$@" && \
 		defer ip route del "$@"
Signature · 1 line
2.49.0
author maintainer
#15 lore raw

PATCH 8/13 selftests: net: lib: Rename bridge_vlan_add() to adf_*

In reply to Petr Machata

Rename this function to mark it as autodefer. For details, see the discussion in the cover letter.

---
 .../net/forwarding/bridge_fdb_local_vlan_0.sh | 12 +++++-----
 .../net/forwarding/vxlan_bridge_1q_mc_ul.sh   | 10 ++++-----
 tools/testing/selftests/net/lib.sh            |  2 +-
 .../selftests/net/vlan_bridge_binding.sh      | 22 +++++++++----------
 4 files changed, 23 insertions(+), 23 deletions(-)
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +6 -6
index b8fd85a20b78..c1a506370c4a 100755
@@ -118,15 +118,15 @@ adf_bridge_configure()
 	adf_ip_addr_add br 192.0.2.3/28
 	adf_ip_addr_add br 2001:db8:1::3/64
 
-	bridge_vlan_add dev br vid 1 pvid untagged self
-	bridge_vlan_add dev br vid 2 self
-	bridge_vlan_add dev br vid 3 self
+	adf_bridge_vlan_add dev br vid 1 pvid untagged self
+	adf_bridge_vlan_add dev br vid 2 self
+	adf_bridge_vlan_add dev br vid 3 self
 
 	for dev in "$swp1" "$swp2"; do
 		adf_ip_link_set_master "$dev" br
-		bridge_vlan_add dev "$dev" vid 1 pvid untagged
-		bridge_vlan_add dev "$dev" vid 2
-		bridge_vlan_add dev "$dev" vid 3
+		adf_bridge_vlan_add dev "$dev" vid 1 pvid untagged
+		adf_bridge_vlan_add dev "$dev" vid 2
+		adf_bridge_vlan_add dev "$dev" vid 3
 	done
 }
 
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +5 -5
index 091833541b06..a968a3ecbcbf 100755
@@ -222,8 +222,8 @@ switch_create()
 	# $swp1
 	adf_ip_link_set_up "$swp1"
 	adf_ip_link_set_master "$swp1" br1
-	bridge_vlan_add vid 10 dev "$swp1"
-	bridge_vlan_add vid 20 dev "$swp1"
+	adf_bridge_vlan_add vid 10 dev "$swp1"
+	adf_bridge_vlan_add vid 20 dev "$swp1"
 
 	# $swp2
 	adf_ip_link_set_up "$swp2"
@@ -245,7 +245,7 @@ vx_create()
 		nolearning noudpcsum tos inherit ttl 16 \
 		"$@"
 	adf_ip_link_set_master "$name" br1
-	bridge_vlan_add vid "$vid" dev "$name" pvid untagged
+	adf_bridge_vlan_add vid "$vid" dev "$name" pvid untagged
 }
 export -f vx_create
 
@@ -307,8 +307,8 @@ ns_init_common()
 	adf_ip_link_add w1 type veth peer name w2
 	adf_ip_link_set_master w1 br1
 	adf_ip_link_set_up w1
-	bridge_vlan_add vid 10 dev w1
-	bridge_vlan_add vid 20 dev w1
+	adf_bridge_vlan_add vid 10 dev w1
+	adf_bridge_vlan_add vid 20 dev w1
 
 	# w2
 	simple_if_init w2
tools/testing/selftests/net/lib.sh +1 -1
index 208919a44703..feba4ef69a54 100644
@@ -619,7 +619,7 @@ adf_ip_route_add()
 		defer ip route del "$@"
 }
 
-bridge_vlan_add()
+adf_bridge_vlan_add()
 {
 	bridge vlan add "$@" && \
 		defer bridge vlan del "$@"
tools/testing/selftests/net/vlan_bridge_binding.sh +11 -11
index 09081bcbfcc7..794ba71c45cb 100755
@@ -27,20 +27,20 @@ setup_prepare()
 		adf_ip_link_set_master $port br
 	done
 
-	bridge_vlan_add vid 11 dev br self
-	bridge_vlan_add vid 11 dev d1 master
+	adf_bridge_vlan_add vid 11 dev br self
+	adf_bridge_vlan_add vid 11 dev d1 master
 
-	bridge_vlan_add vid 12 dev br self
-	bridge_vlan_add vid 12 dev d2 master
+	adf_bridge_vlan_add vid 12 dev br self
+	adf_bridge_vlan_add vid 12 dev d2 master
 
-	bridge_vlan_add vid 13 dev br self
-	bridge_vlan_add vid 13 dev d1 master
-	bridge_vlan_add vid 13 dev d2 master
+	adf_bridge_vlan_add vid 13 dev br self
+	adf_bridge_vlan_add vid 13 dev d1 master
+	adf_bridge_vlan_add vid 13 dev d2 master
 
-	bridge_vlan_add vid 14 dev br self
-	bridge_vlan_add vid 14 dev d1 master
-	bridge_vlan_add vid 14 dev d2 master
-	bridge_vlan_add vid 14 dev d3 master
+	adf_bridge_vlan_add vid 14 dev br self
+	adf_bridge_vlan_add vid 14 dev d1 master
+	adf_bridge_vlan_add vid 14 dev d2 master
+	adf_bridge_vlan_add vid 14 dev d3 master
 }
 
 operstate_is()
Signature · 1 line
2.49.0
author maintainer
#17 lore raw

PATCH 9/13 selftests: net: vlan_bridge_binding: Rename dfr_set_binding_*() to adf_*

In reply to Petr Machata

This test contains two autodefer-like helpers, but namespaces them as dfr_* instead of adf_* like this patchset. Rename them.

---
 tools/testing/selftests/net/vlan_bridge_binding.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/net/vlan_bridge_binding.sh +4 -4
index 794ba71c45cb..db481af9b6b3 100755
@@ -207,13 +207,13 @@ test_binding_toggle_off()
 	do_test_binding_off : "on->off"
 }
 
-dfr_set_binding_on()
+adf_set_binding_on()
 {
 	set_vlans type vlan bridge_binding on
 	defer set_vlans type vlan bridge_binding off
 }
 
-dfr_set_binding_off()
+adf_set_binding_off()
 {
 	set_vlans type vlan bridge_binding off
 	defer set_vlans type vlan bridge_binding on
@@ -223,14 +223,14 @@ test_binding_toggle_on_when_lower_down()
 {
 	add_vlans bridge_binding off
 	set_vlans up
-	do_test_binding_on dfr_set_binding_on "off->on when lower down"
+	do_test_binding_on adf_set_binding_on "off->on when lower down"
 }
 
 test_binding_toggle_off_when_lower_down()
 {
 	add_vlans bridge_binding on
 	set_vlans up
-	do_test_binding_off dfr_set_binding_off "on->off when lower down"
+	do_test_binding_off adf_set_binding_off "on->off when lower down"
 }
 
 test_binding_toggle_on_when_upper_down()
Signature · 1 line
2.49.0
author maintainer
#19 lore raw

PATCH 10/13 selftests: forwarding: lib: Add an autodefer variant of vrf_prepare()

In reply to Petr Machata

Most forwarding tests invoke vrf_prepare() to set up VRF forwarding and vrf_cleanup() to restore the original configuration. Add a helper, adf_vrf_prepare(), which is like vrf_prepare(), but takes care of scheduling the cleanup automatically.

Convert a number of tests that currently use defer to schedule the cleanup.

---

Notes:
CC: Andrew Lunn <[email protected]>
CC: Alessandro Zanni <[email protected]>
CC: Hangbin Liu <[email protected]>
CC: David Yang <[email protected]>
CC: Li Shuang <[email protected]>

 .../selftests/drivers/net/mlxsw/devlink_trap_policer.sh     | 3 +--
 tools/testing/selftests/drivers/net/mlxsw/qos_ets_strict.sh | 3 +--
 .../selftests/drivers/net/mlxsw/qos_max_descriptors.sh      | 3 +--
 tools/testing/selftests/drivers/net/mlxsw/qos_mc_aware.sh   | 3 +--
 tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh   | 3 +--
 .../selftests/net/forwarding/bridge_activity_notify.sh      | 3 +--
 .../selftests/net/forwarding/bridge_fdb_local_vlan_0.sh     | 3 +--
 tools/testing/selftests/net/forwarding/lib.sh               | 6 ++++++
 tools/testing/selftests/net/forwarding/sch_ets_core.sh      | 3 +--
 tools/testing/selftests/net/forwarding/sch_red.sh           | 3 +--
 tools/testing/selftests/net/forwarding/sch_tbf_core.sh      | 3 +--
 .../selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh       | 3 +--
 tools/testing/selftests/net/forwarding/vxlan_reserved.sh    | 3 +--
 13 files changed, 18 insertions(+), 24 deletions(-)
tools/testing/selftests/drivers/net/mlxsw/devlink_trap_policer.sh +1 -2
index 29a672c2270f..6cb5a7a7438b 100755
@@ -106,8 +106,7 @@ setup_prepare()
 	# Reload to ensure devlink-trap settings are back to default.
 	defer devlink_reload
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/drivers/net/mlxsw/qos_ets_strict.sh +1 -2
index d5b6f2cc9a29..ed217eb63cc7 100755
@@ -225,8 +225,7 @@ setup_prepare()
 
 	h3mac=$(mac_get $h3)
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/drivers/net/mlxsw/qos_max_descriptors.sh +1 -2
index 2b5d2c2751d5..d10df3a19300 100755
@@ -178,8 +178,7 @@ setup_prepare()
 
 	h2mac=$(mac_get $h2)
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/drivers/net/mlxsw/qos_mc_aware.sh +1 -2
index cd4a5c21360c..6aca01ebb1ee 100755
@@ -196,8 +196,7 @@ setup_prepare()
 
 	h3mac=$(mac_get $h3)
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh +1 -2
index 537d6baa77b7..a88d61a84b98 100644
@@ -250,8 +250,7 @@ setup_prepare()
 
 	h3_mac=$(mac_get $h3)
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/net/forwarding/bridge_activity_notify.sh +1 -2
index 8ceb205fdca0..afce1c964d5a 100755
@@ -57,8 +57,7 @@ setup_prepare()
 	swp2=${NETIFS[p3]}
 	h2=${NETIFS[p4]}
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +1 -2
index c1a506370c4a..052b2f757ff0 100755
@@ -98,8 +98,7 @@ setup_prepare()
 	swp3=${NETIFS[p5]}
 	h3=${NETIFS[p6]}
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	forwarding_enable
 	defer forwarding_restore
tools/testing/selftests/net/forwarding/lib.sh +6 -0
index 2c252423b326..1370d7a32655 100644
@@ -599,6 +599,12 @@ vrf_cleanup()
 	ip -4 rule del pref 32765
 }
 
+adf_vrf_prepare()
+{
+	vrf_prepare
+	defer vrf_cleanup
+}
+
 __last_tb_id=0
 declare -A __TB_IDS
 
tools/testing/selftests/net/forwarding/sch_ets_core.sh +1 -2
index 8f9922c695b0..f9d15b2f4615 100644
@@ -251,8 +251,7 @@ setup_prepare()
 	put=$swp2
 	hut=$h2
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/net/forwarding/sch_red.sh +1 -2
index af166662b78a..8f79a86cb15b 100755
@@ -125,8 +125,7 @@ setup_prepare()
 
 	h3_mac=$(mac_get $h3)
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/net/forwarding/sch_tbf_core.sh +1 -2
index ec309a5086bc..bce9ab3cb24a 100644
@@ -149,8 +149,7 @@ setup_prepare()
 
 	h2_mac=$(mac_get $h2)
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	h1_create
 	h2_create
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +1 -2
index a968a3ecbcbf..9beb5d512b8e 100755
@@ -371,8 +371,7 @@ setup_prepare()
 	swp3=${NETIFS[p5]}
 	h3=${NETIFS[p6]}
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	forwarding_enable
 	defer forwarding_restore
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +1 -2
index 6fa1668986cc..c564d7a3af0b 100755
@@ -88,8 +88,7 @@ setup_prepare()
 	rp1=${NETIFS[p3]}
 	rp2=${NETIFS[p4]}
 
-	vrf_prepare
-	defer vrf_cleanup
+	adf_vrf_prepare
 
 	forwarding_enable
 	defer forwarding_restore
Signature · 1 line
2.49.0
reviewer Reviewed-by on v1 10/13
#20 lore raw

Re: [PATCH net-next 10/13] selftests: forwarding: lib: Add an autodefer variant of vrf_prepare()

Quoted 8 lines · Petr Machata

Most forwarding tests invoke vrf_prepare() to set up VRF forwarding and vrf_cleanup() to restore the original configuration. Add a helper, adf_vrf_prepare(), which is like vrf_prepare(), but takes care of scheduling the cleanup automatically.

Convert a number of tests that currently use defer to schedule the cleanup.

author maintainer
#21 lore raw

PATCH 11/13 selftests: forwarding: lib: Add an autodefer variant of simple_if_init()

In reply to Petr Machata

Most forwarding tests invoke simple_if_init() to set up a VRF-based "host" and simple_if_fini() to tear it down again. Add a helper, adf_simple_if_init(), which is like simple_if_fini(), but takes care of scheduling the cleanup automatically.

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

---

Notes:
CC: Andrew Lunn <[email protected]>
CC: Alessandro Zanni <[email protected]>
CC: Hangbin Liu <[email protected]>
CC: David Yang <[email protected]>
CC: Li Shuang <[email protected]>

 .../selftests/drivers/net/mlxsw/devlink_trap_policer.sh  | 6 ++----
 .../selftests/drivers/net/mlxsw/qos_ets_strict.sh        | 9 +++------
 .../selftests/drivers/net/mlxsw/qos_max_descriptors.sh   | 6 ++----
 .../testing/selftests/drivers/net/mlxsw/qos_mc_aware.sh  | 9 +++------
 .../testing/selftests/drivers/net/mlxsw/sch_red_core.sh  | 3 +--
 .../selftests/net/forwarding/bridge_activity_notify.sh   | 6 ++----
 .../selftests/net/forwarding/bridge_fdb_local_vlan_0.sh  | 8 ++------
 tools/testing/selftests/net/forwarding/lib.sh            | 6 ++++++
 tools/testing/selftests/net/forwarding/sch_ets_core.sh   | 6 ++----
 tools/testing/selftests/net/forwarding/sch_red.sh        | 9 +++------
 tools/testing/selftests/net/forwarding/sch_tbf_core.sh   | 3 +--
 .../selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh    | 6 ++----
 tools/testing/selftests/net/forwarding/vxlan_reserved.sh | 6 ++----
 13 files changed, 31 insertions(+), 52 deletions(-)
tools/testing/selftests/drivers/net/mlxsw/devlink_trap_policer.sh +2 -4
index 6cb5a7a7438b..e212ad8ccef6 100755
@@ -44,8 +44,7 @@ source $lib_dir/devlink_lib.sh
 
 h1_create()
 {
-	simple_if_init $h1 192.0.2.1/24
-	defer simple_if_fini $h1 192.0.2.1/24
+	adf_simple_if_init $h1 192.0.2.1/24
 
 	mtu_set $h1 10000
 	defer mtu_restore $h1
@@ -56,8 +55,7 @@ h1_create()
 
 h2_create()
 {
-	simple_if_init $h2 198.51.100.1/24
-	defer simple_if_fini $h2 198.51.100.1/24
+	adf_simple_if_init $h2 198.51.100.1/24
 
 	mtu_set $h2 10000
 	defer mtu_restore $h2
tools/testing/selftests/drivers/net/mlxsw/qos_ets_strict.sh +3 -6
index ed217eb63cc7..9ca340c5f3a6 100755
@@ -57,8 +57,7 @@ source qos_lib.sh
 
 h1_create()
 {
-	simple_if_init $h1
-	defer simple_if_fini $h1
+	adf_simple_if_init $h1
 
 	mtu_set $h1 10000
 	defer mtu_restore $h1
@@ -70,8 +69,7 @@ h1_create()
 
 h2_create()
 {
-	simple_if_init $h2
-	defer simple_if_fini $h2
+	adf_simple_if_init $h2
 
 	mtu_set $h2 10000
 	defer mtu_restore $h2
@@ -83,8 +81,7 @@ h2_create()
 
 h3_create()
 {
-	simple_if_init $h3
-	defer simple_if_fini $h3
+	adf_simple_if_init $h3
 
 	mtu_set $h3 10000
 	defer mtu_restore $h3
tools/testing/selftests/drivers/net/mlxsw/qos_max_descriptors.sh +2 -4
index d10df3a19300..a4a25637fe2a 100755
@@ -68,8 +68,7 @@ mlxsw_only_on_spectrum 2+ || exit
 
 h1_create()
 {
-	simple_if_init $h1
-	defer simple_if_fini $h1
+	adf_simple_if_init $h1
 
 	vlan_create $h1 111 v$h1 192.0.2.33/28
 	defer vlan_destroy $h1 111
@@ -78,8 +77,7 @@ h1_create()
 
 h2_create()
 {
-	simple_if_init $h2
-	defer simple_if_fini $h2
+	adf_simple_if_init $h2
 
 	vlan_create $h2 111 v$h2 192.0.2.34/28
 	defer vlan_destroy $h2 111
tools/testing/selftests/drivers/net/mlxsw/qos_mc_aware.sh +3 -6
index 6aca01ebb1ee..d8f8ae8533cd 100755
@@ -72,8 +72,7 @@ source qos_lib.sh
 
 h1_create()
 {
-	simple_if_init $h1 192.0.2.65/28
-	defer simple_if_fini $h1 192.0.2.65/28
+	adf_simple_if_init $h1 192.0.2.65/28
 
 	mtu_set $h1 10000
 	defer mtu_restore $h1
@@ -81,8 +80,7 @@ h1_create()
 
 h2_create()
 {
-	simple_if_init $h2
-	defer simple_if_fini $h2
+	adf_simple_if_init $h2
 
 	mtu_set $h2 10000
 	defer mtu_restore $h2
@@ -94,8 +92,7 @@ h2_create()
 
 h3_create()
 {
-	simple_if_init $h3 192.0.2.66/28
-	defer simple_if_fini $h3 192.0.2.66/28
+	adf_simple_if_init $h3 192.0.2.66/28
 
 	mtu_set $h3 10000
 	defer mtu_restore $h3
tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh +1 -2
index a88d61a84b98..47d2ffcf366e 100644
@@ -100,8 +100,7 @@ host_create()
 	local dev=$1; shift
 	local host=$1; shift
 
-	simple_if_init $dev
-	defer simple_if_fini $dev
+	adf_simple_if_init $dev
 
 	mtu_set $dev 10000
 	defer mtu_restore $dev
tools/testing/selftests/net/forwarding/bridge_activity_notify.sh +2 -4
index afce1c964d5a..522a5b1b046c 100755
@@ -26,14 +26,12 @@ source lib.sh
 
 h1_create()
 {
-	simple_if_init "$h1" 192.0.2.1/28
-	defer simple_if_fini "$h1" 192.0.2.1/28
+	adf_simple_if_init "$h1" 192.0.2.1/28
 }
 
 h2_create()
 {
-	simple_if_init "$h2" 192.0.2.2/28
-	defer simple_if_fini "$h2" 192.0.2.2/28
+	adf_simple_if_init "$h2" 192.0.2.2/28
 }
 
 switch_create()
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +2 -6
index 052b2f757ff0..78b6be513a2d 100755
@@ -44,18 +44,14 @@ host_create()
 	local ipv4=$1; shift
 	local ipv6=$1; shift
 
-	simple_if_init "$h" "$ipv4" "$ipv6"
-	defer simple_if_fini "$h" "$ipv4" "$ipv6"
-
+	adf_simple_if_init "$h" "$ipv4" "$ipv6"
 	adf_ip_route_add vrf "v$h" 192.0.2.16/28 nexthop via 192.0.2.3
 	adf_ip_route_add vrf "v$h" 2001:db8:2::/64 nexthop via 2001:db8:1::3
 }
 
 h3_create()
 {
-	simple_if_init "$h3" 192.0.2.18/28 2001:db8:2::2/64
-	defer simple_if_fini "$h3" 192.0.2.18/28 2001:db8:2::2/64
-
+	adf_simple_if_init "$h3" 192.0.2.18/28 2001:db8:2::2/64
 	adf_ip_route_add vrf "v$h3" 192.0.2.0/28 nexthop via 192.0.2.17
 	adf_ip_route_add vrf "v$h3" 2001:db8:1::/64 nexthop via 2001:db8:2::1
 
tools/testing/selftests/net/forwarding/lib.sh +6 -0
index 1370d7a32655..7d506cf81a32 100644
@@ -717,6 +717,12 @@ simple_if_fini()
 	vrf_destroy $vrf_name
 }
 
+adf_simple_if_init()
+{
+	simple_if_init "$@"
+	defer simple_if_fini "$@"
+}
+
 tunnel_create()
 {
 	local name=$1; shift
tools/testing/selftests/net/forwarding/sch_ets_core.sh +2 -4
index f9d15b2f4615..0453210271dc 100644
@@ -165,8 +165,7 @@ h1_create()
 {
 	local i;
 
-	simple_if_init $h1
-	defer simple_if_fini $h1
+	adf_simple_if_init $h1
 
 	mtu_set $h1 9900
 	defer mtu_restore $h1
@@ -182,8 +181,7 @@ h2_create()
 {
 	local i
 
-	simple_if_init $h2
-	defer simple_if_fini $h2
+	adf_simple_if_init $h2
 
 	mtu_set $h2 9900
 	defer mtu_restore $h2
tools/testing/selftests/net/forwarding/sch_red.sh +3 -6
index 8f79a86cb15b..f2a3d9254642 100755
@@ -52,8 +52,7 @@ PKTSZ=1400
 
 h1_create()
 {
-	simple_if_init $h1 192.0.2.1/28
-	defer simple_if_fini $h1 192.0.2.1/28
+	adf_simple_if_init $h1 192.0.2.1/28
 
 	mtu_set $h1 10000
 	defer mtu_restore $h1
@@ -65,8 +64,7 @@ h1_create()
 
 h2_create()
 {
-	simple_if_init $h2 192.0.2.2/28
-	defer simple_if_fini $h2 192.0.2.2/28
+	adf_simple_if_init $h2 192.0.2.2/28
 
 	mtu_set $h2 10000
 	defer mtu_restore $h2
@@ -74,8 +72,7 @@ h2_create()
 
 h3_create()
 {
-	simple_if_init $h3 192.0.2.3/28
-	defer simple_if_fini $h3 192.0.2.3/28
+	adf_simple_if_init $h3 192.0.2.3/28
 
 	mtu_set $h3 10000
 	defer mtu_restore $h3
tools/testing/selftests/net/forwarding/sch_tbf_core.sh +1 -2
index bce9ab3cb24a..070c17faa9e4 100644
@@ -59,8 +59,7 @@ host_create()
 	local dev=$1; shift
 	local host=$1; shift
 
-	simple_if_init $dev
-	defer simple_if_fini $dev
+	adf_simple_if_init $dev
 
 	mtu_set $dev 10000
 	defer mtu_restore $dev
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +2 -4
index 9beb5d512b8e..9974a93eb850 100755
@@ -119,8 +119,7 @@ source lib.sh
 
 h1_create()
 {
-	simple_if_init "$h1"
-	defer simple_if_fini "$h1"
+	adf_simple_if_init "$h1"
 
 	adf_ip_link_add "$h1.10" master "v$h1" link "$h1" type vlan id 10
 	adf_ip_link_set_up "$h1.10"
@@ -311,8 +310,7 @@ ns_init_common()
 	adf_bridge_vlan_add vid 20 dev w1
 
 	# w2
-	simple_if_init w2
-	defer simple_if_fini w2
+	adf_simple_if_init w2
 
 	# w2.10
 	adf_ip_link_add w2.10 master vw2 link w2 type vlan id 10
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +2 -4
index c564d7a3af0b..712f3367ee5a 100755
@@ -47,8 +47,7 @@ source lib.sh
 
 h1_create()
 {
-	simple_if_init $h1 192.0.2.1/28
-	defer simple_if_fini $h1 192.0.2.1/28
+	adf_simple_if_init $h1 192.0.2.1/28
 
 	tc qdisc add dev $h1 clsact
 	defer tc qdisc del dev $h1 clsact
@@ -76,8 +75,7 @@ switch_create()
 
 vrp2_create()
 {
-	simple_if_init $rp2 192.0.2.18/28
-	defer simple_if_fini $rp2 192.0.2.18/28
+	adf_simple_if_init $rp2 192.0.2.18/28
 }
 
 setup_prepare()
Signature · 1 line
2.49.0
reviewer Reviewed-by on v1 11/13
#22 lore raw

Re: [PATCH net-next 11/13] selftests: forwarding: lib: Add an autodefer variant of simple_if_init()

Quoted 8 lines · Petr Machata

Most forwarding tests invoke simple_if_init() to set up a VRF-based "host" and simple_if_fini() to tear it down again. Add a helper, adf_simple_if_init(), which is like simple_if_fini(), but takes care of scheduling the cleanup automatically.

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

author maintainer
#23 lore raw

PATCH 12/13 selftests: forwarding: lib: Add an autodefer variant of forwarding_enable()

In reply to Petr Machata

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.

---

Notes:
CC: Alessandro Zanni <[email protected]>
CC: Hangbin Liu <[email protected]>
CC: David Yang <[email protected]>
CC: Li Shuang <[email protected]>

 .../selftests/net/forwarding/bridge_fdb_local_vlan_0.sh     | 4 +---
 tools/testing/selftests/net/forwarding/lib.sh               | 6 ++++++
 .../selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh       | 4 +---
 tools/testing/selftests/net/forwarding/vxlan_reserved.sh    | 4 +---
 4 files changed, 9 insertions(+), 9 deletions(-)
tools/testing/selftests/net/forwarding/bridge_fdb_local_vlan_0.sh +1 -3
index 78b6be513a2d..694de8ba97e4 100755
@@ -95,9 +95,7 @@ setup_prepare()
 	h3=${NETIFS[p6]}
 
 	adf_vrf_prepare
-
-	forwarding_enable
-	defer forwarding_restore
+	adf_forwarding_enable
 
 	host_create "$h1" 192.0.2.1/28 2001:db8:1::1/64
 	host_create "$h2" 192.0.2.2/28 2001:db8:1::2/64
tools/testing/selftests/net/forwarding/lib.sh +6 -0
index 7d506cf81a32..a9034f0bb58b 100644
@@ -1023,6 +1023,12 @@ forwarding_restore()
 	sysctl_restore net.ipv4.conf.all.forwarding
 }
 
+adf_forwarding_enable()
+{
+	forwarding_enable
+	defer forwarding_restore
+}
+
 declare -A MTU_ORIG
 mtu_set()
 {
tools/testing/selftests/net/forwarding/vxlan_bridge_1q_mc_ul.sh +1 -3
index 9974a93eb850..6a570d256e07 100755
@@ -370,9 +370,7 @@ setup_prepare()
 	h3=${NETIFS[p6]}
 
 	adf_vrf_prepare
-
-	forwarding_enable
-	defer forwarding_restore
+	adf_forwarding_enable
 
 	adf_ip_link_add "v1$h2" type veth peer name "v2$h2"
 	adf_ip_link_add "v1$h3" type veth peer name "v2$h3"
tools/testing/selftests/net/forwarding/vxlan_reserved.sh +1 -3
index 712f3367ee5a..709845123727 100755
@@ -87,9 +87,7 @@ setup_prepare()
 	rp2=${NETIFS[p4]}
 
 	adf_vrf_prepare
-
-	forwarding_enable
-	defer forwarding_restore
+	adf_forwarding_enable
 
 	h1_create
 	switch_create
Signature · 1 line
2.49.0
reviewer Reviewed-by on v1 12/13
#24 lore raw

Re: [PATCH net-next 12/13] selftests: forwarding: lib: Add an autodefer variant of forwarding_enable()

Quoted 8 lines · Petr Machata

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.

author maintainer
#25 lore raw

PATCH 13/13 selftests: forwarding: README: Mention defer, adf_

In reply to Petr Machata

Mention how it would be nice if new code used defer. Also if it does that in dirtying helpers, how it would be nice if these were named adf_*.

---

Notes:
CC: Kuniyuki Iwashima <[email protected]>
CC: KuniyNicolas Dichtel <[email protected]>

 tools/testing/selftests/net/forwarding/README | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/testing/selftests/net/forwarding/README +15 -0
index 7b41cff993ad..392a5a91ed37 100644
@@ -57,6 +57,21 @@ o Code shall be checked using ShellCheck [1] prior to submission.
 
 1. https://www.shellcheck.net/
 
+Cleanups
+--------
+
+o lib.sh brings in defer.sh (by way of ../lib.sh) by default. Consider
+  making use of the defer primitive to schedule automatic cleanups. This
+  makes it harder to forget to remove a temporary netdevice, kill a running
+  process or perform other cleanup when the test script is interrupted.
+
+o When adding a helper that dirties the environment, but schedules all
+  necessary cleanups through defer, consider prefixing it adf_ for
+  consistency with lib.sh and ../lib.sh helpers. This serves as an
+  immediately visible bit of documentation about the helper API.
+
+o Definitely do the above for any new code in lib.sh, if practical.
+
 Customization
 =============
 
Signature · 1 line
2.49.0
#27 lore raw
In reply to Petr Machata
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 6 lines · On Thu, 25 Sep 2025 19:31:43 +0200 you wrote:

selftests/net/lib.sh contains a suite of iproute2 wrappers that automatically schedule the corresponding cleanup through defer. The fact they do so is however not immediately obvious, one needs to know which functions are handling the deferral behind the scenes, and which expect the caller to handle cleanups themselves.

Quoted 7 lines

A convention for these auto-deferring functions would help both writing and patch review. This patchset does so by marking these functions with an adf_ prefix. We already have a few such functions: forwarding/lib.sh has adf_mcd_start() and a few selftests add private helpers that conform to this convention.

[...]

Here is the summary with links:
- [net-next,01/13] selftests: net: lib: Rename ip_link_add() to adf_*

    https://git.kernel.org/netdev/net-next/c/191c4912f9c3
  - [net-next,02/13] selftests: net: lib: Rename ip_link_set_master() to adf_*
    https://git.kernel.org/netdev/net-next/c/c3cbd21fe18e
  - [net-next,03/13] selftests: net: lib: Rename ip_link_set_addr() to adf_*
    https://git.kernel.org/netdev/net-next/c/beb98a347762
  - [net-next,04/13] selftests: net: lib: Rename ip_link_set_up() to adf_*
    https://git.kernel.org/netdev/net-next/c/34d3f8b75e2b
  - [net-next,05/13] selftests: net: lib: Rename ip_link_set_down() to adf_*
    https://git.kernel.org/netdev/net-next/c/a55f9fb3432e
  - [net-next,06/13] selftests: net: lib: Rename ip_addr_add() to adf_*
    https://git.kernel.org/netdev/net-next/c/773603d6db30
  - [net-next,07/13] selftests: net: lib: Rename ip_route_add() to adf_*
    https://git.kernel.org/netdev/net-next/c/d85bcf6505d2
  - [net-next,08/13] selftests: net: lib: Rename bridge_vlan_add() to adf_*
    https://git.kernel.org/netdev/net-next/c/b628dfcd54cb
  - [net-next,09/13] selftests: net: vlan_bridge_binding: Rename dfr_set_binding_*() to adf_*
    https://git.kernel.org/netdev/net-next/c/14b72996ae80
  - [net-next,10/13] selftests: forwarding: lib: Add an autodefer variant of vrf_prepare()
    https://git.kernel.org/netdev/net-next/c/02aabe00b2e1
  - [net-next,11/13] selftests: forwarding: lib: Add an autodefer variant of simple_if_init()
    https://git.kernel.org/netdev/net-next/c/f53748d56d10
  - [net-next,12/13] selftests: forwarding: lib: Add an autodefer variant of forwarding_enable()
    https://git.kernel.org/netdev/net-next/c/040a6cbead5d
  - [net-next,13/13] selftests: forwarding: README: Mention defer, adf_
    https://git.kernel.org/netdev/net-next/c/fca6ff9191bd

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html