2 # Copyright (c) 2014 Spectra Logic Corporation
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions, and the following disclaimer,
10 # without modification.
11 # 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 # substantially similar to the "NO WARRANTY" disclaimer below
13 # ("Disclaimer") and any redistribution must be conditioned upon
14 # including a substantially similar Disclaimer requirement for further
15 # binary redistribution.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGES.
30 # Authors: Alan Somers (Spectra Logic Corporation)
34 atf_test_case create cleanup
37 atf_set "descr" "Create a lagg and assign an address"
38 atf_set "require.user" "root"
42 local TAP0 TAP1 LAGG MAC
44 # Configure the lagg interface to use an RFC5737 nonrouteable addresses
55 atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
57 atf_check -o match:"inet ${ADDR}" ifconfig $LAGG
58 atf_check -o match:"laggport: ${TAP0}" ifconfig $LAGG
59 atf_check -o match:"laggport: ${TAP1}" ifconfig $LAGG
61 # Check that all members have the same MAC
62 MAC=`ifconfig $LAGG | awk '/ether/ {print $2}'`
63 atf_check -o match:"ether ${MAC}" ifconfig $TAP0
64 atf_check -o match:"ether ${MAC}" ifconfig $TAP1
66 # Check that no members have an IPv6 link-local address. IPv6
67 # link-local addresses should never be merged in any way to prevent
69 atf_check -o not-match:"inet6 fe80:" ifconfig $TAP0
70 atf_check -o not-match:"inet6 fe80:" ifconfig $TAP1
77 atf_test_case status_stress cleanup
80 atf_set "descr" "Simultaneously query a lagg while also creating or destroying it."
81 atf_set "require.user" "root"
85 local TAP0 TAP1 LAGG MAC
87 # Configure the lagg interface to use an RFC5737 nonrouteable addresses
97 # Up the lagg's children
98 ifconfig $TAP0 inet6 ifdisabled up
99 ifconfig $TAP1 inet6 ifdisabled up
100 ifconfig $TAP2 inet6 ifdisabled up
101 ifconfig $TAP3 inet6 ifdisabled up
103 # First thread: create and destroy the lagg
105 ifconfig $LAGG destroy 2>&1
106 ifconfig $LAGG create 2>/dev/null
107 ifconfig $LAGG inet6 ifdisabled
108 ifconfig $LAGG up laggport $TAP0 laggport $TAP1 laggport $TAP2\
109 laggport $TAP3 ${ADDR}/${MASK} 2>/dev/null
110 echo -n . >> creator_count.txt
114 # Second thread: Query the lagg's status
116 ifconfig -am 2> /dev/null > /dev/null
117 echo -n . >> querier_count.txt
124 echo "Created the lagg `stat -f %z creator_count.txt` times."
125 echo "Queried its status `stat -f %z querier_count.txt` times"
127 status_stress_cleanup()
132 atf_test_case create_destroy_stress cleanup
133 create_destroy_stress_head()
135 atf_set "descr" "Simultaneously create and destroy a lagg"
136 atf_set "require.user" "root"
138 create_destroy_stress_body()
140 local TAP0 TAP1 LAGG MAC
142 atf_skip "Skipping this test because it easily panics the machine"
150 # Up the lagg's children
151 ifconfig $TAP0 inet6 ifdisabled up
152 ifconfig $TAP1 inet6 ifdisabled up
153 ifconfig $TAP2 inet6 ifdisabled up
154 ifconfig $TAP3 inet6 ifdisabled up
156 # First thread: create the lagg
158 ifconfig $LAGG create 2>/dev/null && \
159 echo -n . >> creator_count.txt
163 # Second thread: destroy the lagg
165 ifconfig $LAGG destroy 2>/dev/null && \
166 echo -n . >> destroyer_count.txt
173 echo "Created the lagg `stat -f %z creator_count.txt` times."
174 echo "Destroyed it `stat -f %z destroyer_count.txt` times."
176 create_destroy_stress_cleanup()
181 # This test regresses a panic that is particular to LACP. If the child's link
182 # state changes while the lagg is being destroyed, lacp_linkstate can
183 # use-after-free. The problem is compounded by two factors:
184 # 1) In SpectraBSD, downing the parent will also down the child
185 # 2) The cxgbe driver will show the link state as "no carrier" as soon as you
186 # down the interface.
187 # TeamTrack: P2_30328
188 atf_test_case lacp_linkstate_destroy_stress cleanup
189 lacp_linkstate_destroy_stress_head()
191 atf_set "descr" "Simultaneously destroy an LACP lagg and change its childrens link states"
192 atf_set "require.user" "root"
194 lacp_linkstate_destroy_stress_body()
196 if [ "$(atf_config_get ci false)" = "true" ] && \
197 [ "$(uname -p)" = "i386" ]; then
198 atf_skip "https://bugs.freebsd.org/244168"
201 local TAP0 TAP1 LAGG MAC SRCDIR
203 # Configure the lagg interface to use an RFC5737 nonrouteable addresses
206 # ifconfig takes about 10ms to run. To increase race coverage,
207 # randomly delay the two commands relative to each other by 5ms either
209 MEAN_SLEEP_SECONDS=.005
210 MAX_SLEEP_USECS=10000
216 # Up the lagg's children
217 ifconfig $TAP0 inet6 ifdisabled up
218 ifconfig $TAP1 inet6 ifdisabled up
220 SRCDIR=$( atf_get_srcdir )
222 ifconfig $LAGG inet6 ifdisabled
223 # We must open the tap devices to change their link states
224 cat /dev/$TAP0 > /dev/null &
226 cat /dev/$TAP1 > /dev/null &
228 ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
229 ${ADDR}/${MASK} 2> /dev/null &&
230 { sleep ${MEAN_SLEEP_SECONDS} && \
233 echo -n . >> linkstate_count.txt ; } &
234 { ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
235 ifconfig $LAGG destroy &&
236 echo -n . >> destroy_count.txt ; } &
238 ifconfig $LAGG create
244 echo "Disconnected the children `stat -f %z linkstate_count.txt` times."
245 echo "Destroyed the lagg `stat -f %z destroy_count.txt` times."
247 lacp_linkstate_destroy_stress_cleanup()
252 atf_test_case up_destroy_stress cleanup
253 up_destroy_stress_head()
255 atf_set "descr" "Simultaneously up and destroy a lagg"
256 atf_set "require.user" "root"
258 up_destroy_stress_body()
260 local TAP0 TAP1 LAGG MAC SRCDIR
262 atf_skip "Skipping this test because it panics the machine fairly often"
264 # Configure the lagg interface to use an RFC5737 nonrouteable addresses
267 # ifconfig takes about 10ms to run. To increase race coverage,
268 # randomly delay the two commands relative to each other by 5ms either
270 MEAN_SLEEP_SECONDS=.005
271 MAX_SLEEP_USECS=10000
279 # Up the lagg's children
280 ifconfig $TAP0 inet6 ifdisabled up
281 ifconfig $TAP1 inet6 ifdisabled up
282 ifconfig $TAP2 inet6 ifdisabled up
283 ifconfig $TAP3 inet6 ifdisabled up
285 SRCDIR=$( atf_get_srcdir )
287 ifconfig $LAGG inet6 ifdisabled
288 { sleep ${MEAN_SLEEP_SECONDS} && \
289 ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
290 laggport $TAP2 laggport $TAP3 \
291 ${ADDR}/${MASK} 2> /dev/null &&
292 echo -n . >> up_count.txt ; } &
293 { ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
294 ifconfig $LAGG destroy &&
295 echo -n . >> destroy_count.txt ; } &
297 ifconfig $LAGG create
303 echo "Upped the lagg `stat -f %z up_count.txt` times."
304 echo "Destroyed it `stat -f %z destroy_count.txt` times."
306 up_destroy_stress_cleanup()
311 atf_test_case set_ether cleanup
314 atf_set "descr" "Set a lagg's ethernet address"
315 atf_set "require.user" "root"
319 local TAP0 TAP1 LAGG MAC
321 # Configure the lagg interface to use an RFC5737 nonrouteable addresses
324 MAC="00:11:22:33:44:55"
333 atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
336 # Change the lagg's ethernet address
337 atf_check ifconfig $LAGG ether ${MAC}
339 # Check that all members have the same MAC
340 atf_check -o match:"ether ${MAC}" ifconfig $LAGG
341 atf_check -o match:"ether ${MAC}" ifconfig $TAP0
342 atf_check -o match:"ether ${MAC}" ifconfig $TAP1
349 atf_test_case updown cleanup
352 atf_set "descr" "upping or downing a lagg ups or downs its children"
353 atf_set "require.user" "root"
357 local TAP0 TAP1 LAGG MAC
359 atf_expect_fail "PR 226144 Upping a lagg interrface should automatically up its children"
360 # Configure the lagg interface to use an RFC5737 nonrouteable addresses
363 MAC="00:11:22:33:44:55"
372 atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
377 atf_check -o not-match:"flags=.*\<UP\>" ifconfig $LAGG
378 atf_check -o not-match:"flags=.*\<UP\>" ifconfig $TAP0
379 atf_check -o not-match:"flags=.*\<UP\>" ifconfig $TAP1
382 atf_check -o match:"flags=.*\<UP\>" ifconfig $LAGG
383 atf_check -o match:"flags=.*\<UP\>" ifconfig $TAP0
384 atf_check -o match:"flags=.*\<UP\>" ifconfig $TAP1
386 # Check that no members have acquired an IPv6 link-local address by
387 # virtue of being upped. IPv6 link-local addresses should never be
388 # merged in any way to prevent scope violation.
389 atf_check -o not-match:"inet6 fe80:" ifconfig $TAP0
390 atf_check -o not-match:"inet6 fe80:" ifconfig $TAP1
397 # Check for lock-order reversals. For best results, this test should be run
399 atf_test_case witness
402 atf_set "descr" "Check witness(4) for lock-order reversals in if_lagg"
406 if [ "$(atf_config_get ci false)" = "true" ] && \
407 [ "$(uname -p)" = "i386" ]; then
408 atf_skip "https://bugs.freebsd.org/244163"
410 if [ `sysctl -n debug.witness.watch` -ne 1 ]; then
411 atf_skip "witness(4) is not enabled"
413 if `sysctl -n debug.witness.badstacks | grep -q 'at lagg_'`; then
414 sysctl debug.witness.badstacks
415 atf_fail "Lock-order reversals involving if_lagg.c detected"
419 atf_init_test_cases()
421 atf_add_test_case create
422 atf_add_test_case create_destroy_stress
423 atf_add_test_case lacp_linkstate_destroy_stress
424 atf_add_test_case set_ether
425 atf_add_test_case status_stress
426 atf_add_test_case up_destroy_stress
427 atf_add_test_case updown
428 # For best results, keep the witness test last
429 atf_add_test_case witness
433 # Creates a new tap(4) interface, registers it for cleanup, and echoes it
437 while ! ifconfig tap${TAPN} create > /dev/null 2>&1; do
438 if [ "$TAPN" -ge 8 ]; then
439 atf_skip "Could not create a tap(4) interface"
444 local TAPD=tap${TAPN}
445 # Record the TAP device so we can clean it up later
446 echo ${TAPD} >> "devices_to_cleanup"
450 # Creates a new lagg(4) interface, registers it for cleanup, and echoes it
454 while ! ifconfig lagg${LAGGN} create > /dev/null 2>&1; do
455 if [ "$LAGGN" -ge 8 ]; then
456 atf_skip "Could not create a lagg(4) interface"
458 LAGGN=$(($LAGGN + 1))
461 local LAGGD=lagg${LAGGN}
462 # Record the lagg device so we can clean it up later
463 echo ${LAGGD} >> "devices_to_cleanup"
467 cleanup_tap_and_lagg()
471 for DEV in `cat "devices_to_cleanup"`; do
472 ifconfig ${DEV} destroy