2 # SPDX-License-Identifier: GPL-2.0
4 # ShellCheck incorrectly believes that most of the code here is unreachable
5 # because it's invoked by variable name following ALL_TESTS.
7 # shellcheck disable=SC2317
9 ALL_TESTS
="check_accounting check_limit"
13 TEST_MAC_BASE
=de
:ad
:be
:ef
:42:
19 # name is counted? overrides learned?
29 printf "${TEST_MAC_BASE}%02x" "$1"
32 H1_DEFAULT_MAC
=$
(mac
42)
36 ip link add dev br0
type bridge
38 ip link
set dev
"$swp1" master br0
39 ip link
set dev
"$swp2" master br0
40 # swp3 is used to add local MACs, so do not add it to the bridge yet.
42 # swp2 is only used for replying when learning on swp1, its MAC should not be learned.
43 ip link
set dev
"$swp2" type bridge_slave learning off
45 ip link
set dev br0 up
47 ip link
set dev
"$swp1" up
48 ip link
set dev
"$swp2" up
49 ip link
set dev
"$swp3" up
54 ip link
set dev
"$swp3" down
55 ip link
set dev
"$swp2" down
56 ip link
set dev
"$swp1" down
63 ip link
set "$h1" addr
"$H1_DEFAULT_MAC"
65 simple_if_init
"$h1" 192.0.2.1/24
66 simple_if_init
"$h2" 192.0.2.2/24
71 simple_if_fini
"$h1" 192.0.2.1/24
72 simple_if_fini
"$h2" 192.0.2.2/24
105 ip
-d -j link show dev br0
type bridge | \
106 jq
'.[]["linkinfo"]["info_data"]["fdb_n_learned"]'
113 bridge
-j fdb show br br0 | \
114 jq
"map(select(.mac == \"${mac}\" and (has(\"vlan\") | not))) | length"
121 for i
in $
(seq 1 "$NUM_PKTS"); do
122 fdb_add learned
"$(mac "$i")"
128 bridge fdb flush dev br0
130 # Keep the default MAC address of h1 in the table. We set it to a different one when
131 # testing dynamic learning.
132 bridge fdb add
"$H1_DEFAULT_MAC" dev
"$swp1" master static use
141 ip link
set "$h1" addr
"$mac"
142 # Wait for a reply so we implicitly wait until after the forwarding
143 # code finished and the FDB entry was created.
144 PING_COUNT
=1 ping_do
"$h1" 192.0.2.2
145 check_err $?
"Failed to ping another bridge port"
146 ip link
set "$h1" addr
"$H1_DEFAULT_MAC"
149 ip link
set dev
"$swp3" addr
"$mac" && ip link
set "$swp3" master br0
152 bridge fdb replace
"$mac" dev
"$swp1" master static
155 bridge fdb replace
"$mac" dev
"$swp1" master static use
158 bridge fdb replace
"$mac" dev
"$swp1" master extern_learn
162 check_err $?
"Failed to add a FDB entry of type ${type}"
171 ip link
set "$swp3" nomaster
174 bridge fdb del
"$mac" dev
"$swp1" master
178 check_err $?
"Failed to remove a FDB entry of type ${type}"
181 check_fdb_n_learned_support
()
183 if ! ip link
help bridge
2>&1 |
grep -q "fdb_max_learned"; then
184 echo "SKIP: iproute2 too old, missing bridge max learned support"
188 ip link add dev br0
type bridge
189 local learned
=$
(fdb_get_n_learned
)
191 if [ "$learned" == "null" ]; then
192 echo "SKIP: kernel too old; bridge fdb_n_learned feature not supported."
197 check_accounting_one_type
()
199 local type=$1 is_counted
=$2 overrides_learned
=$3
204 fdb_add
"$type" "$(mac 0)"
205 learned
=$
(fdb_get_n_learned
)
206 [ "$learned" -ne "$is_counted" ]
207 check_fail $?
"Inserted FDB type ${type}: Expected the count ${is_counted}, but got ${learned}"
209 fdb_del
"$type" "$(mac 0)"
210 learned
=$
(fdb_get_n_learned
)
212 check_fail $?
"Removed FDB type ${type}: Expected the count 0, but got ${learned}"
214 if [ "$overrides_learned" -eq 1 ]; then
216 fdb_add learned
"$(mac 0)"
217 fdb_add
"$type" "$(mac 0)"
218 learned
=$
(fdb_get_n_learned
)
219 [ "$learned" -ne "$is_counted" ]
220 check_fail $?
"Set a learned entry to FDB type ${type}: Expected the count ${is_counted}, but got ${learned}"
221 fdb_del
"$type" "$(mac 0)"
224 log_test
"FDB accounting interacting with FDB type ${type}"
229 local type_args learned
233 learned
=$
(fdb_get_n_learned
)
235 check_fail $?
"Flushed the FDB table: Expected the count 0, but got ${learned}"
240 learned
=$
(fdb_get_n_learned
)
241 [ "$learned" -ne "$NUM_PKTS" ]
242 check_fail $?
"Filled the FDB table: Expected the count ${NUM_PKTS}, but got ${learned}"
244 log_test
"FDB accounting"
246 for type_args
in "${FDB_TYPES[@]}"; do
247 # This is intentional use of word splitting.
248 # shellcheck disable=SC2086
249 check_accounting_one_type
$type_args
253 check_limit_one_type
()
255 local type=$1 is_counted
=$2
256 local n_mac expected
=$
((1 - is_counted
))
262 fdb_add
"$type" "$(mac 0)"
263 n_mac
=$
(fdb_get_n_mac
"$(mac 0)")
264 [ "$n_mac" -ne "$expected" ]
265 check_fail $?
"Inserted FDB type ${type} at limit: Expected the count ${expected}, but got ${n_mac}"
267 log_test
"FDB limits interacting with FDB type ${type}"
275 ip link
set br0
type bridge fdb_max_learned
"$FDB_LIMIT"
280 learned
=$
(fdb_get_n_learned
)
281 [ "$learned" -ne "$FDB_LIMIT" ]
282 check_fail $?
"Filled the limited FDB table: Expected the count ${FDB_LIMIT}, but got ${learned}"
284 log_test
"FDB limits"
286 for type_args
in "${FDB_TYPES[@]}"; do
287 # This is intentional use of word splitting.
288 # shellcheck disable=SC2086
289 check_limit_one_type
$type_args
293 check_fdb_n_learned_support