xref: /freebsd-src/tests/sys/net/if_lagg_test.sh (revision 0089d83b3a21a7f5f7140b6c8f55c900f9d27589)
14b40bdbdSAlan Somers#
24b40bdbdSAlan Somers#  Copyright (c) 2014 Spectra Logic Corporation
34b40bdbdSAlan Somers#  All rights reserved.
44b40bdbdSAlan Somers#
54b40bdbdSAlan Somers#  Redistribution and use in source and binary forms, with or without
64b40bdbdSAlan Somers#  modification, are permitted provided that the following conditions
74b40bdbdSAlan Somers#  are met:
84b40bdbdSAlan Somers#  1. Redistributions of source code must retain the above copyright
94b40bdbdSAlan Somers#     notice, this list of conditions, and the following disclaimer,
104b40bdbdSAlan Somers#     without modification.
114b40bdbdSAlan Somers#  2. Redistributions in binary form must reproduce at minimum a disclaimer
124b40bdbdSAlan Somers#     substantially similar to the "NO WARRANTY" disclaimer below
134b40bdbdSAlan Somers#     ("Disclaimer") and any redistribution must be conditioned upon
144b40bdbdSAlan Somers#     including a substantially similar Disclaimer requirement for further
154b40bdbdSAlan Somers#     binary redistribution.
164b40bdbdSAlan Somers#
174b40bdbdSAlan Somers#  NO WARRANTY
184b40bdbdSAlan Somers#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
194b40bdbdSAlan Somers#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
204b40bdbdSAlan Somers#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
214b40bdbdSAlan Somers#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
224b40bdbdSAlan Somers#  HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
234b40bdbdSAlan Somers#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
244b40bdbdSAlan Somers#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
254b40bdbdSAlan Somers#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
264b40bdbdSAlan Somers#  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
274b40bdbdSAlan Somers#  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
284b40bdbdSAlan Somers#  POSSIBILITY OF SUCH DAMAGES.
294b40bdbdSAlan Somers#
304b40bdbdSAlan Somers#  Authors: Alan Somers         (Spectra Logic Corporation)
314b40bdbdSAlan Somers#
324b40bdbdSAlan Somers
334b40bdbdSAlan Somersatf_test_case create cleanup
344b40bdbdSAlan Somerscreate_head()
354b40bdbdSAlan Somers{
364b40bdbdSAlan Somers	atf_set "descr" "Create a lagg and assign an address"
374b40bdbdSAlan Somers	atf_set "require.user" "root"
384b40bdbdSAlan Somers}
394b40bdbdSAlan Somerscreate_body()
404b40bdbdSAlan Somers{
414b40bdbdSAlan Somers	local TAP0 TAP1 LAGG MAC
424b40bdbdSAlan Somers
434b40bdbdSAlan Somers	# Configure the lagg interface to use an RFC5737 nonrouteable addresses
444b40bdbdSAlan Somers	ADDR="192.0.2.2"
454b40bdbdSAlan Somers	MASK="24"
464b40bdbdSAlan Somers
474b40bdbdSAlan Somers	TAP0=`get_tap`
484b40bdbdSAlan Somers	TAP1=`get_tap`
494b40bdbdSAlan Somers	LAGG=`get_lagg`
504b40bdbdSAlan Somers
514b40bdbdSAlan Somers	# Create the lagg
524b40bdbdSAlan Somers	ifconfig $TAP0 up
534b40bdbdSAlan Somers	ifconfig $TAP1 up
544b40bdbdSAlan Somers	atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
554b40bdbdSAlan Somers		${ADDR}/${MASK}
564b40bdbdSAlan Somers	atf_check -o match:"inet ${ADDR}" ifconfig $LAGG
574b40bdbdSAlan Somers	atf_check -o match:"laggport: ${TAP0}" ifconfig $LAGG
584b40bdbdSAlan Somers	atf_check -o match:"laggport: ${TAP1}" ifconfig $LAGG
594b40bdbdSAlan Somers
604b40bdbdSAlan Somers	# Check that all members have the same MAC
614b40bdbdSAlan Somers	MAC=`ifconfig $LAGG | awk '/ether/ {print $2}'`
624b40bdbdSAlan Somers	atf_check -o match:"ether ${MAC}" ifconfig $TAP0
634b40bdbdSAlan Somers	atf_check -o match:"ether ${MAC}" ifconfig $TAP1
644b40bdbdSAlan Somers
654b40bdbdSAlan Somers	# Check that no members have an IPv6 link-local address. IPv6
664b40bdbdSAlan Somers	# link-local addresses should never be merged in any way to prevent
674b40bdbdSAlan Somers	# scope violation.
684b40bdbdSAlan Somers	atf_check -o not-match:"inet6 fe80:" ifconfig $TAP0
694b40bdbdSAlan Somers	atf_check -o not-match:"inet6 fe80:" ifconfig $TAP1
704b40bdbdSAlan Somers}
714b40bdbdSAlan Somerscreate_cleanup()
724b40bdbdSAlan Somers{
734b40bdbdSAlan Somers	cleanup_tap_and_lagg
744b40bdbdSAlan Somers}
754b40bdbdSAlan Somers
764b40bdbdSAlan Somersatf_test_case status_stress cleanup
774b40bdbdSAlan Somersstatus_stress_head()
784b40bdbdSAlan Somers{
794b40bdbdSAlan Somers	atf_set "descr" "Simultaneously query a lagg while also creating or destroying it."
804b40bdbdSAlan Somers	atf_set "require.user" "root"
814b40bdbdSAlan Somers}
824b40bdbdSAlan Somersstatus_stress_body()
834b40bdbdSAlan Somers{
844b40bdbdSAlan Somers	local TAP0 TAP1 LAGG MAC
854b40bdbdSAlan Somers
864b40bdbdSAlan Somers	# Configure the lagg interface to use an RFC5737 nonrouteable addresses
874b40bdbdSAlan Somers	ADDR="192.0.2.2"
884b40bdbdSAlan Somers	MASK="24"
894b40bdbdSAlan Somers
904b40bdbdSAlan Somers	TAP0=`get_tap`
914b40bdbdSAlan Somers	TAP1=`get_tap`
924b40bdbdSAlan Somers	TAP2=`get_tap`
934b40bdbdSAlan Somers	TAP3=`get_tap`
944b40bdbdSAlan Somers	LAGG=`get_lagg`
954b40bdbdSAlan Somers
964b40bdbdSAlan Somers	# Up the lagg's children
974b40bdbdSAlan Somers	ifconfig $TAP0 inet6 ifdisabled up
984b40bdbdSAlan Somers	ifconfig $TAP1 inet6 ifdisabled up
994b40bdbdSAlan Somers	ifconfig $TAP2 inet6 ifdisabled up
1004b40bdbdSAlan Somers	ifconfig $TAP3 inet6 ifdisabled up
1014b40bdbdSAlan Somers
1024b40bdbdSAlan Somers	# First thread: create and destroy the lagg
1034b40bdbdSAlan Somers	while true; do
1044b40bdbdSAlan Somers		ifconfig $LAGG destroy 2>&1
1054b40bdbdSAlan Somers		ifconfig $LAGG create 2>/dev/null
1064b40bdbdSAlan Somers		ifconfig $LAGG inet6 ifdisabled
1074b40bdbdSAlan Somers		ifconfig $LAGG up laggport $TAP0 laggport $TAP1 laggport $TAP2\
1084b40bdbdSAlan Somers			laggport $TAP3 ${ADDR}/${MASK} 2>/dev/null
1094b40bdbdSAlan Somers		echo -n . >> creator_count.txt
1104b40bdbdSAlan Somers	done &
1114b40bdbdSAlan Somers	CREATOR_PID=$!
1124b40bdbdSAlan Somers
1134b40bdbdSAlan Somers	# Second thread: Query the lagg's status
1144b40bdbdSAlan Somers	while true; do
1154b40bdbdSAlan Somers		ifconfig -am 2> /dev/null > /dev/null
1164b40bdbdSAlan Somers		echo -n . >> querier_count.txt
1174b40bdbdSAlan Somers	done &
1184b40bdbdSAlan Somers	QUERIER_PID=$!
1194b40bdbdSAlan Somers
1204b40bdbdSAlan Somers	sleep 60
1214b40bdbdSAlan Somers	kill $CREATOR_PID
1224b40bdbdSAlan Somers	kill $QUERIER_PID
1234b40bdbdSAlan Somers	echo "Created the lagg `stat -f %z creator_count.txt` times."
1244b40bdbdSAlan Somers	echo "Queried its status `stat -f %z querier_count.txt` times"
1254b40bdbdSAlan Somers}
1264b40bdbdSAlan Somersstatus_stress_cleanup()
1274b40bdbdSAlan Somers{
1284b40bdbdSAlan Somers	cleanup_tap_and_lagg
1294b40bdbdSAlan Somers}
1304b40bdbdSAlan Somers
1314b40bdbdSAlan Somersatf_test_case create_destroy_stress cleanup
1324b40bdbdSAlan Somerscreate_destroy_stress_head()
1334b40bdbdSAlan Somers{
1344b40bdbdSAlan Somers	atf_set "descr" "Simultaneously create and destroy a lagg"
1354b40bdbdSAlan Somers	atf_set "require.user" "root"
1364b40bdbdSAlan Somers}
1374b40bdbdSAlan Somerscreate_destroy_stress_body()
1384b40bdbdSAlan Somers{
1394b40bdbdSAlan Somers	local TAP0 TAP1 LAGG MAC
1404b40bdbdSAlan Somers
1414b40bdbdSAlan Somers	TAP0=`get_tap`
1424b40bdbdSAlan Somers	TAP1=`get_tap`
1434b40bdbdSAlan Somers	TAP2=`get_tap`
1444b40bdbdSAlan Somers	TAP3=`get_tap`
1454b40bdbdSAlan Somers	LAGG=`get_lagg`
1464b40bdbdSAlan Somers
1474b40bdbdSAlan Somers	# Up the lagg's children
1484b40bdbdSAlan Somers	ifconfig $TAP0 inet6 ifdisabled up
1494b40bdbdSAlan Somers	ifconfig $TAP1 inet6 ifdisabled up
1504b40bdbdSAlan Somers	ifconfig $TAP2 inet6 ifdisabled up
1514b40bdbdSAlan Somers	ifconfig $TAP3 inet6 ifdisabled up
1524b40bdbdSAlan Somers
1534b40bdbdSAlan Somers	# First thread: create the lagg
1544b40bdbdSAlan Somers	while true; do
1554b40bdbdSAlan Somers		ifconfig $LAGG create 2>/dev/null && \
1564b40bdbdSAlan Somers			echo -n . >> creator_count.txt
1574b40bdbdSAlan Somers	done &
1584b40bdbdSAlan Somers	CREATOR_PID=$!
1594b40bdbdSAlan Somers
1604b40bdbdSAlan Somers	# Second thread: destroy the lagg
1614b40bdbdSAlan Somers	while true; do
1624b40bdbdSAlan Somers		ifconfig $LAGG destroy 2>/dev/null && \
1634b40bdbdSAlan Somers			echo -n . >> destroyer_count.txt
1644b40bdbdSAlan Somers	done &
1654b40bdbdSAlan Somers	DESTROYER_PID=$!
1664b40bdbdSAlan Somers
1674b40bdbdSAlan Somers	sleep 60
1684b40bdbdSAlan Somers	kill $CREATOR_PID
1694b40bdbdSAlan Somers	kill $DESTROYER_PID
1704b40bdbdSAlan Somers	echo "Created the lagg `stat -f %z creator_count.txt` times."
1714b40bdbdSAlan Somers	echo "Destroyed it `stat -f %z destroyer_count.txt` times."
1724b40bdbdSAlan Somers}
1734b40bdbdSAlan Somerscreate_destroy_stress_cleanup()
1744b40bdbdSAlan Somers{
1754b40bdbdSAlan Somers	cleanup_tap_and_lagg
1764b40bdbdSAlan Somers}
1774b40bdbdSAlan Somers
1784b40bdbdSAlan Somers# This test regresses a panic that is particular to LACP.  If the child's link
1794b40bdbdSAlan Somers# state changes while the lagg is being destroyed, lacp_linkstate can
1804b40bdbdSAlan Somers# use-after-free.  The problem is compounded by two factors:
1814b40bdbdSAlan Somers# 1) In SpectraBSD, downing the parent will also down the child
1824b40bdbdSAlan Somers# 2) The cxgbe driver will show the link state as "no carrier" as soon as you
1834b40bdbdSAlan Somers#    down the interface.
1844b40bdbdSAlan Somers# TeamTrack: P2_30328
1854b40bdbdSAlan Somersatf_test_case lacp_linkstate_destroy_stress cleanup
1864b40bdbdSAlan Somerslacp_linkstate_destroy_stress_head()
1874b40bdbdSAlan Somers{
1884b40bdbdSAlan Somers	atf_set "descr" "Simultaneously destroy an LACP lagg and change its childrens link states"
1894b40bdbdSAlan Somers	atf_set "require.user" "root"
1904b40bdbdSAlan Somers}
1914b40bdbdSAlan Somerslacp_linkstate_destroy_stress_body()
1924b40bdbdSAlan Somers{
193435166f8SLi-Wen Hsu	if [ "$(atf_config_get ci false)" = "true" ]; then
194f1cabcd3SLi-Wen Hsu		atf_skip "https://bugs.freebsd.org/244168"
195f1cabcd3SLi-Wen Hsu	fi
196f1cabcd3SLi-Wen Hsu
1974b40bdbdSAlan Somers	local TAP0 TAP1 LAGG MAC SRCDIR
1984b40bdbdSAlan Somers
1994b40bdbdSAlan Somers	# Configure the lagg interface to use an RFC5737 nonrouteable addresses
2004b40bdbdSAlan Somers	ADDR="192.0.2.2"
2014b40bdbdSAlan Somers	MASK="24"
2024b40bdbdSAlan Somers	# ifconfig takes about 10ms to run.  To increase race coverage,
2034b40bdbdSAlan Somers	# randomly delay the two commands relative to each other by 5ms either
2044b40bdbdSAlan Somers	# way.
2054b40bdbdSAlan Somers	MEAN_SLEEP_SECONDS=.005
2064b40bdbdSAlan Somers	MAX_SLEEP_USECS=10000
2074b40bdbdSAlan Somers
2084b40bdbdSAlan Somers	TAP0=`get_tap`
2094b40bdbdSAlan Somers	TAP1=`get_tap`
2104b40bdbdSAlan Somers	LAGG=`get_lagg`
2114b40bdbdSAlan Somers
2124b40bdbdSAlan Somers	# Up the lagg's children
2134b40bdbdSAlan Somers	ifconfig $TAP0 inet6 ifdisabled up
2144b40bdbdSAlan Somers	ifconfig $TAP1 inet6 ifdisabled up
2154b40bdbdSAlan Somers
2164b40bdbdSAlan Somers	SRCDIR=$( atf_get_srcdir )
2174b40bdbdSAlan Somers	while true; do
2184b40bdbdSAlan Somers		ifconfig $LAGG inet6 ifdisabled
2194b40bdbdSAlan Somers		# We must open the tap devices to change their link states
2204b40bdbdSAlan Somers		cat /dev/$TAP0 > /dev/null &
2214b40bdbdSAlan Somers		CAT0_PID=$!
2224b40bdbdSAlan Somers		cat /dev/$TAP1 > /dev/null &
2234b40bdbdSAlan Somers		CAT1_PID=$!
2244b40bdbdSAlan Somers		ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
2254b40bdbdSAlan Somers			${ADDR}/${MASK} 2> /dev/null &&
2264b40bdbdSAlan Somers		{ sleep ${MEAN_SLEEP_SECONDS} && \
2274b40bdbdSAlan Somers			kill $CAT0_PID &&
2284b40bdbdSAlan Somers			kill $CAT1_PID &&
2294b40bdbdSAlan Somers			echo -n . >> linkstate_count.txt ; } &
2304b40bdbdSAlan Somers		{ ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
2314b40bdbdSAlan Somers			ifconfig $LAGG destroy &&
2324b40bdbdSAlan Somers			echo -n . >> destroy_count.txt ; } &
2334b40bdbdSAlan Somers		wait
2344b40bdbdSAlan Somers		ifconfig $LAGG create
2354b40bdbdSAlan Somers	done &
2364b40bdbdSAlan Somers	LOOP_PID=$!
2374b40bdbdSAlan Somers
2384b40bdbdSAlan Somers	sleep 60
2394b40bdbdSAlan Somers	kill $LOOP_PID
2404b40bdbdSAlan Somers	echo "Disconnected the children `stat -f %z linkstate_count.txt` times."
2414b40bdbdSAlan Somers	echo "Destroyed the lagg `stat -f %z destroy_count.txt` times."
2424b40bdbdSAlan Somers}
2434b40bdbdSAlan Somerslacp_linkstate_destroy_stress_cleanup()
2444b40bdbdSAlan Somers{
2454b40bdbdSAlan Somers	cleanup_tap_and_lagg
2464b40bdbdSAlan Somers}
2474b40bdbdSAlan Somers
2484b40bdbdSAlan Somersatf_test_case up_destroy_stress cleanup
2494b40bdbdSAlan Somersup_destroy_stress_head()
2504b40bdbdSAlan Somers{
2514b40bdbdSAlan Somers	atf_set "descr" "Simultaneously up and destroy a lagg"
2524b40bdbdSAlan Somers	atf_set "require.user" "root"
2534b40bdbdSAlan Somers}
2544b40bdbdSAlan Somersup_destroy_stress_body()
2554b40bdbdSAlan Somers{
2564b40bdbdSAlan Somers	local TAP0 TAP1 LAGG MAC SRCDIR
2574b40bdbdSAlan Somers
2584b40bdbdSAlan Somers	# Configure the lagg interface to use an RFC5737 nonrouteable addresses
2594b40bdbdSAlan Somers	ADDR="192.0.2.2"
2604b40bdbdSAlan Somers	MASK="24"
2614b40bdbdSAlan Somers	# ifconfig takes about 10ms to run.  To increase race coverage,
2624b40bdbdSAlan Somers	# randomly delay the two commands relative to each other by 5ms either
2634b40bdbdSAlan Somers	# way.
2644b40bdbdSAlan Somers	MEAN_SLEEP_SECONDS=.005
2654b40bdbdSAlan Somers	MAX_SLEEP_USECS=10000
2664b40bdbdSAlan Somers
2674b40bdbdSAlan Somers	TAP0=`get_tap`
2684b40bdbdSAlan Somers	TAP1=`get_tap`
2694b40bdbdSAlan Somers	TAP2=`get_tap`
2704b40bdbdSAlan Somers	TAP3=`get_tap`
2714b40bdbdSAlan Somers	LAGG=`get_lagg`
2724b40bdbdSAlan Somers
2734b40bdbdSAlan Somers	# Up the lagg's children
2744b40bdbdSAlan Somers	ifconfig $TAP0 inet6 ifdisabled up
2754b40bdbdSAlan Somers	ifconfig $TAP1 inet6 ifdisabled up
2764b40bdbdSAlan Somers	ifconfig $TAP2 inet6 ifdisabled up
2774b40bdbdSAlan Somers	ifconfig $TAP3 inet6 ifdisabled up
2784b40bdbdSAlan Somers
2794b40bdbdSAlan Somers	SRCDIR=$( atf_get_srcdir )
2804b40bdbdSAlan Somers	while true; do
2814b40bdbdSAlan Somers		ifconfig $LAGG inet6 ifdisabled
2824b40bdbdSAlan Somers		{ sleep ${MEAN_SLEEP_SECONDS} && \
2834b40bdbdSAlan Somers			ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
2844b40bdbdSAlan Somers				laggport $TAP2 laggport $TAP3 \
2854b40bdbdSAlan Somers				${ADDR}/${MASK} 2> /dev/null &&
2864b40bdbdSAlan Somers			echo -n . >> up_count.txt ; } &
2874b40bdbdSAlan Somers		{ ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
2884b40bdbdSAlan Somers			ifconfig $LAGG destroy &&
2894b40bdbdSAlan Somers			echo -n . >> destroy_count.txt ; } &
2904b40bdbdSAlan Somers		wait
2914b40bdbdSAlan Somers		ifconfig $LAGG create
2924b40bdbdSAlan Somers	done &
2934b40bdbdSAlan Somers	LOOP_PID=$!
2944b40bdbdSAlan Somers
2954b40bdbdSAlan Somers	sleep 60
2964b40bdbdSAlan Somers	kill $LOOP_PID
2974b40bdbdSAlan Somers	echo "Upped the lagg `stat -f %z up_count.txt` times."
2984b40bdbdSAlan Somers	echo "Destroyed it `stat -f %z destroy_count.txt` times."
2994b40bdbdSAlan Somers}
3004b40bdbdSAlan Somersup_destroy_stress_cleanup()
3014b40bdbdSAlan Somers{
3024b40bdbdSAlan Somers	cleanup_tap_and_lagg
3034b40bdbdSAlan Somers}
3044b40bdbdSAlan Somers
3054b40bdbdSAlan Somersatf_test_case set_ether cleanup
3064b40bdbdSAlan Somersset_ether_head()
3074b40bdbdSAlan Somers{
3084b40bdbdSAlan Somers	atf_set "descr" "Set a lagg's ethernet address"
3094b40bdbdSAlan Somers	atf_set "require.user" "root"
3104b40bdbdSAlan Somers}
3114b40bdbdSAlan Somersset_ether_body()
3124b40bdbdSAlan Somers{
3134b40bdbdSAlan Somers	local TAP0 TAP1 LAGG MAC
3144b40bdbdSAlan Somers
3154b40bdbdSAlan Somers	# Configure the lagg interface to use an RFC5737 nonrouteable addresses
3164b40bdbdSAlan Somers	ADDR="192.0.2.2"
3174b40bdbdSAlan Somers	MASK="24"
3184b40bdbdSAlan Somers	MAC="00:11:22:33:44:55"
3194b40bdbdSAlan Somers
3204b40bdbdSAlan Somers	TAP0=`get_tap`
3214b40bdbdSAlan Somers	TAP1=`get_tap`
3224b40bdbdSAlan Somers	LAGG=`get_lagg`
3234b40bdbdSAlan Somers
3244b40bdbdSAlan Somers	# Create the lagg
3254b40bdbdSAlan Somers	ifconfig $TAP0 up
3264b40bdbdSAlan Somers	ifconfig $TAP1 up
3274b40bdbdSAlan Somers	atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
3284b40bdbdSAlan Somers		${ADDR}/${MASK}
3294b40bdbdSAlan Somers
3304b40bdbdSAlan Somers	# Change the lagg's ethernet address
3314b40bdbdSAlan Somers	atf_check ifconfig $LAGG ether ${MAC}
3324b40bdbdSAlan Somers
3334b40bdbdSAlan Somers	# Check that all members have the same MAC
3344b40bdbdSAlan Somers	atf_check -o match:"ether ${MAC}" ifconfig $LAGG
3354b40bdbdSAlan Somers	atf_check -o match:"ether ${MAC}" ifconfig $TAP0
3364b40bdbdSAlan Somers	atf_check -o match:"ether ${MAC}" ifconfig $TAP1
3374b40bdbdSAlan Somers}
3384b40bdbdSAlan Somersset_ether_cleanup()
3394b40bdbdSAlan Somers{
3404b40bdbdSAlan Somers	cleanup_tap_and_lagg
3414b40bdbdSAlan Somers}
3424b40bdbdSAlan Somers
3434b40bdbdSAlan Somersatf_test_case updown cleanup
3444b40bdbdSAlan Somersupdown_head()
3454b40bdbdSAlan Somers{
3464b40bdbdSAlan Somers	atf_set "descr" "upping or downing a lagg ups or downs its children"
3474b40bdbdSAlan Somers	atf_set "require.user" "root"
3484b40bdbdSAlan Somers}
3494b40bdbdSAlan Somersupdown_body()
3504b40bdbdSAlan Somers{
3514b40bdbdSAlan Somers	local TAP0 TAP1 LAGG MAC
3524b40bdbdSAlan Somers
3534b40bdbdSAlan Somers	# Configure the lagg interface to use an RFC5737 nonrouteable addresses
3544b40bdbdSAlan Somers	ADDR="192.0.2.2"
3554b40bdbdSAlan Somers	MASK="24"
3564b40bdbdSAlan Somers	MAC="00:11:22:33:44:55"
3574b40bdbdSAlan Somers
3584b40bdbdSAlan Somers	TAP0=`get_tap`
3594b40bdbdSAlan Somers	TAP1=`get_tap`
3604b40bdbdSAlan Somers	LAGG=`get_lagg`
3614b40bdbdSAlan Somers
3624b40bdbdSAlan Somers	# Create the lagg
3634b40bdbdSAlan Somers	ifconfig $TAP0 up
3644b40bdbdSAlan Somers	ifconfig $TAP1 up
3654b40bdbdSAlan Somers	atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
3664b40bdbdSAlan Somers		${ADDR}/${MASK}
3674b40bdbdSAlan Somers
3684b40bdbdSAlan Somers	# Down the lagg
3694b40bdbdSAlan Somers	ifconfig $LAGG down
3704b40bdbdSAlan Somers	atf_check -o not-match:"flags=.*\<UP\>" ifconfig $LAGG
3714b40bdbdSAlan Somers	atf_check -o not-match:"flags=.*\<UP\>" ifconfig $TAP0
3724b40bdbdSAlan Somers	atf_check -o not-match:"flags=.*\<UP\>" ifconfig $TAP1
3734b40bdbdSAlan Somers	# Up the lagg again
3744b40bdbdSAlan Somers	ifconfig $LAGG up
3754b40bdbdSAlan Somers	atf_check -o match:"flags=.*\<UP\>" ifconfig $LAGG
3764b40bdbdSAlan Somers	atf_check -o match:"flags=.*\<UP\>" ifconfig $TAP0
3774b40bdbdSAlan Somers	atf_check -o match:"flags=.*\<UP\>" ifconfig $TAP1
3784b40bdbdSAlan Somers
3794b40bdbdSAlan Somers	# Check that no members have acquired an IPv6 link-local address by
3804b40bdbdSAlan Somers	# virtue of being upped. IPv6 link-local addresses should never be
3814b40bdbdSAlan Somers	# merged in any way to prevent scope violation.
3824b40bdbdSAlan Somers	atf_check -o not-match:"inet6 fe80:" ifconfig $TAP0
3834b40bdbdSAlan Somers	atf_check -o not-match:"inet6 fe80:" ifconfig $TAP1
3844b40bdbdSAlan Somers}
3854b40bdbdSAlan Somersupdown_cleanup()
3864b40bdbdSAlan Somers{
3874b40bdbdSAlan Somers	cleanup_tap_and_lagg
3884b40bdbdSAlan Somers}
3894b40bdbdSAlan Somers
3904b40bdbdSAlan Somers# Check for lock-order reversals.  For best results, this test should be run
3914b40bdbdSAlan Somers# last.
3924b40bdbdSAlan Somersatf_test_case witness
3934b40bdbdSAlan Somerswitness_head()
3944b40bdbdSAlan Somers{
3954b40bdbdSAlan Somers	atf_set "descr" "Check witness(4) for lock-order reversals in if_lagg"
3964b40bdbdSAlan Somers}
3974b40bdbdSAlan Somerswitness_body()
3984b40bdbdSAlan Somers{
399*aa05775eSAlex Richardson	if [ "$(atf_config_get ci false)" = "true" ]; then
400ee231b27SAlex Richardson		atf_skip "https://bugs.freebsd.org/244163 and https://bugs.freebsd.org/251726"
40107a721acSLi-Wen Hsu	fi
4024b40bdbdSAlan Somers	if [ `sysctl -n debug.witness.watch` -ne 1 ]; then
4034b40bdbdSAlan Somers		atf_skip "witness(4) is not enabled"
4044b40bdbdSAlan Somers	fi
4054b40bdbdSAlan Somers	if `sysctl -n debug.witness.badstacks | grep -q 'at lagg_'`; then
4064b40bdbdSAlan Somers		sysctl debug.witness.badstacks
4074b40bdbdSAlan Somers		atf_fail "Lock-order reversals involving if_lagg.c detected"
4084b40bdbdSAlan Somers	fi
4094b40bdbdSAlan Somers}
4104b40bdbdSAlan Somers
4114b40bdbdSAlan Somersatf_init_test_cases()
4124b40bdbdSAlan Somers{
4134b40bdbdSAlan Somers	atf_add_test_case create
4144b40bdbdSAlan Somers	atf_add_test_case create_destroy_stress
4154b40bdbdSAlan Somers	atf_add_test_case lacp_linkstate_destroy_stress
4164b40bdbdSAlan Somers	atf_add_test_case set_ether
4174b40bdbdSAlan Somers	atf_add_test_case status_stress
4184b40bdbdSAlan Somers	atf_add_test_case up_destroy_stress
4194b40bdbdSAlan Somers	atf_add_test_case updown
4204b40bdbdSAlan Somers	# For best results, keep the witness test last
4214b40bdbdSAlan Somers	atf_add_test_case witness
4224b40bdbdSAlan Somers}
4234b40bdbdSAlan Somers
4244b40bdbdSAlan Somers
4254b40bdbdSAlan Somers# Creates a new tap(4) interface, registers it for cleanup, and echoes it
4264b40bdbdSAlan Somersget_tap()
4274b40bdbdSAlan Somers{
4284b40bdbdSAlan Somers	local TAPN=0
4294b40bdbdSAlan Somers	while ! ifconfig tap${TAPN} create > /dev/null 2>&1; do
4304b40bdbdSAlan Somers		if [ "$TAPN" -ge 8 ]; then
4314b40bdbdSAlan Somers			atf_skip "Could not create a tap(4) interface"
4324b40bdbdSAlan Somers		else
4334b40bdbdSAlan Somers			TAPN=$(($TAPN + 1))
4344b40bdbdSAlan Somers		fi
4354b40bdbdSAlan Somers	done
4364b40bdbdSAlan Somers	local TAPD=tap${TAPN}
4374b40bdbdSAlan Somers	# Record the TAP device so we can clean it up later
4384b40bdbdSAlan Somers	echo ${TAPD} >> "devices_to_cleanup"
4394b40bdbdSAlan Somers	echo ${TAPD}
4404b40bdbdSAlan Somers}
4414b40bdbdSAlan Somers
4424b40bdbdSAlan Somers# Creates a new lagg(4) interface, registers it for cleanup, and echoes it
4434b40bdbdSAlan Somersget_lagg()
4444b40bdbdSAlan Somers{
4454b40bdbdSAlan Somers	local LAGGN=0
4464b40bdbdSAlan Somers	while ! ifconfig lagg${LAGGN} create > /dev/null 2>&1; do
4474b40bdbdSAlan Somers		if [ "$LAGGN" -ge 8 ]; then
4484b40bdbdSAlan Somers			atf_skip "Could not create a lagg(4) interface"
4494b40bdbdSAlan Somers		else
4504b40bdbdSAlan Somers			LAGGN=$(($LAGGN + 1))
4514b40bdbdSAlan Somers		fi
4524b40bdbdSAlan Somers	done
4534b40bdbdSAlan Somers	local LAGGD=lagg${LAGGN}
4544b40bdbdSAlan Somers	# Record the lagg device so we can clean it up later
4554b40bdbdSAlan Somers	echo ${LAGGD} >> "devices_to_cleanup"
4564b40bdbdSAlan Somers	echo ${LAGGD}
4574b40bdbdSAlan Somers}
4584b40bdbdSAlan Somers
4594b40bdbdSAlan Somerscleanup_tap_and_lagg()
4604b40bdbdSAlan Somers{
4614b40bdbdSAlan Somers	local DEV
4624b40bdbdSAlan Somers
4634b40bdbdSAlan Somers	for DEV in `cat "devices_to_cleanup"`; do
4644b40bdbdSAlan Somers		ifconfig ${DEV} destroy
4654b40bdbdSAlan Somers	done
4664b40bdbdSAlan Somers	true
4674b40bdbdSAlan Somers}
468