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

selftests: net: fdb_notify: Add a test for FDB notifications

Check that only one notification is produced for various FDB edit
operations.

Regarding the ip_link_add() and ip_link_master() helpers. This pattern of
action plus corresponding defer is bound to come up often, and a dedicated
vocabulary to capture it will be handy. tunnel_create() and vlan_create()
from forwarding/lib.sh are somewhat opaque and perhaps too kitchen-sinky,
so I tried to go in the opposite direction with these ones, and wrapped
only the bare minimum to schedule a corresponding cleanup.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Amit Cohen <amcohen@nvidia.com>
Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Link: https://patch.msgid.link/910c5880ae6d3b558d6889cbdba2be690c2615c6.1731589511.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Petr Machata and committed by
Jakub Kicinski
15880bec 46f6569c

+114 -1
+1 -1
tools/testing/selftests/net/Makefile
··· 93 93 TEST_PROGS += test_bridge_neigh_suppress.sh 94 94 TEST_PROGS += test_vxlan_nolocalbypass.sh 95 95 TEST_PROGS += test_bridge_backup_port.sh 96 - TEST_PROGS += fdb_flush.sh 96 + TEST_PROGS += fdb_flush.sh fdb_notify.sh 97 97 TEST_PROGS += fq_band_pktlimit.sh 98 98 TEST_PROGS += vlan_hw_filter.sh 99 99 TEST_PROGS += bpf_offload.py
+96
tools/testing/selftests/net/fdb_notify.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + source lib.sh 5 + 6 + ALL_TESTS=" 7 + test_dup_bridge 8 + test_dup_vxlan_self 9 + test_dup_vxlan_master 10 + test_dup_macvlan_self 11 + test_dup_macvlan_master 12 + " 13 + 14 + do_test_dup() 15 + { 16 + local op=$1; shift 17 + local what=$1; shift 18 + local tmpf 19 + 20 + RET=0 21 + 22 + tmpf=$(mktemp) 23 + defer rm "$tmpf" 24 + 25 + defer_scope_push 26 + bridge monitor fdb &> "$tmpf" & 27 + defer kill_process $! 28 + 29 + sleep 0.5 30 + bridge fdb "$op" 00:11:22:33:44:55 vlan 1 "$@" 31 + sleep 0.5 32 + defer_scope_pop 33 + 34 + local count=$(grep -c -e 00:11:22:33:44:55 $tmpf) 35 + ((count == 1)) 36 + check_err $? "Got $count notifications, expected 1" 37 + 38 + log_test "$what $op: Duplicate notifications" 39 + } 40 + 41 + test_dup_bridge() 42 + { 43 + ip_link_add br up type bridge vlan_filtering 1 44 + do_test_dup add "bridge" dev br self 45 + do_test_dup del "bridge" dev br self 46 + } 47 + 48 + test_dup_vxlan_self() 49 + { 50 + ip_link_add br up type bridge vlan_filtering 1 51 + ip_link_add vx up type vxlan id 2000 dstport 4789 52 + ip_link_master vx br 53 + 54 + do_test_dup add "vxlan" dev vx self dst 192.0.2.1 55 + do_test_dup del "vxlan" dev vx self dst 192.0.2.1 56 + } 57 + 58 + test_dup_vxlan_master() 59 + { 60 + ip_link_add br up type bridge vlan_filtering 1 61 + ip_link_add vx up type vxlan id 2000 dstport 4789 62 + ip_link_master vx br 63 + 64 + do_test_dup add "vxlan master" dev vx master 65 + do_test_dup del "vxlan master" dev vx master 66 + } 67 + 68 + test_dup_macvlan_self() 69 + { 70 + ip_link_add dd up type dummy 71 + ip_link_add mv up link dd type macvlan mode passthru 72 + 73 + do_test_dup add "macvlan self" dev mv self 74 + do_test_dup del "macvlan self" dev mv self 75 + } 76 + 77 + test_dup_macvlan_master() 78 + { 79 + ip_link_add br up type bridge vlan_filtering 1 80 + ip_link_add dd up type dummy 81 + ip_link_add mv up link dd type macvlan mode passthru 82 + ip_link_master mv br 83 + 84 + do_test_dup add "macvlan master" dev mv self 85 + do_test_dup del "macvlan master" dev mv self 86 + } 87 + 88 + cleanup() 89 + { 90 + defer_scopes_cleanup 91 + } 92 + 93 + trap cleanup EXIT 94 + tests_run 95 + 96 + exit $EXIT_STATUS
+17
tools/testing/selftests/net/lib.sh
··· 442 442 # Suppress noise from killing the process. 443 443 { kill $pid && wait $pid; } 2>/dev/null 444 444 } 445 + 446 + ip_link_add() 447 + { 448 + local name=$1; shift 449 + 450 + ip link add name "$name" "$@" 451 + defer ip link del dev "$name" 452 + } 453 + 454 + ip_link_master() 455 + { 456 + local member=$1; shift 457 + local master=$1; shift 458 + 459 + ip link set dev "$member" master "$master" 460 + defer ip link set dev "$member" nomaster 461 + }