Home | History | Annotate | Line # | Download | only in ifconfig
      1 # $NetBSD: t_repeated_link_addr.sh,v 1.4 2020/07/27 16:57:44 gson Exp $
      2 #
      3 # Copyright (c) 2020 The NetBSD Foundation, Inc.
      4 # All rights reserved.
      5 #
      6 # This code is derived from software contributed to The NetBSD Foundation
      7 # by Jukka Ruohonen.
      8 #
      9 # Redistribution and use in source and binary forms, with or without
     10 # modification, are permitted provided that the following conditions
     11 # are met:
     12 # 1. Redistributions of source code must retain the above copyright
     13 #    notice, this list of conditions and the following disclaimer.
     14 # 2. Redistributions in binary form must reproduce the above copyright
     15 #    notice, this list of conditions and the following disclaimer in the
     16 #    documentation and/or other materials provided with the distribution.
     17 #
     18 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28 # POSSIBILITY OF SUCH DAMAGE.
     29 #
     30 atf_test_case repeated_link_addr
     31 repeated_link_addr_head() {
     32 	atf_set "require.user" "root"
     33 	atf_set "descr" "Check with ifconfig(8) that " \
     34 		"setting link addresses for active interfaces " \
     35 		"does not cause a panic (PR kern/41912)"
     36 }
     37 
     38 repeated_link_addr_body() {
     39 
     40 	if ! [ $(atf_config_get "run_unsafe" "no") = "yes" ]
     41 	then
     42 		atf_skip "can disrupt networking; also PR port-evbarm/55521"
     43 	fi
     44 
     45 	fail=0
     46 	addrs="00:11:00:00:00:00 \
     47 	       00:11:11:00:00:00 \
     48 	       00:11:11:11:00:00 \
     49 	       00:11:11:11:11:00 \
     50 	       00:00:11:00:00:00 \
     51 	       00:00:11:11:00:00 \
     52 	       00:00:11:11:11:00 \
     53 	       00:00:00:11:00:00 \
     54 	       00:00:00:11:11:00"
     55 
     56 	pkill -9 hostapd
     57 	pkill -9 wpa_supplicant
     58 
     59 	for i in $(ifconfig -l); do
     60 
     61 		state="up"
     62 		addr=$(ifconfig $i | grep "address")
     63 		addr=$(echo $addr | sed "s/address: //" | sed 's/ //')
     64 
     65 		if [ -z "$addr" ]; then
     66 			echo "Skipping $i"
     67 			continue
     68 		fi
     69 
     70 		ifconfig -s $i
     71 
     72 		if [ $? -eq 1 ]; then
     73 			state="down"
     74 			ifconfig $i up
     75 			sleep 1
     76 		fi
     77 
     78 		for j in $addrs; do
     79 
     80 			echo "Request: ifconfig $i link $j active"
     81 			ifconfig $i link $j active
     82 
     83 			if [ ! $? -eq 0 ]; then
     84 				fail=1
     85 			fi
     86 
     87 			if [ -z "$(ifconfig $i | grep $j)" ]; then
     88 				fail=1
     89 			fi
     90 
     91 			sleep 0.5
     92 		done
     93 
     94 		# From the ifconfig(8) manual page:
     95 		#
     96 		# "You may not delete the active address from an interface.
     97 		#  You must activate some other address, first."
     98 		#
     99 		ifconfig $i link $addr active
    100 		echo "Restored the link address of $i to $addr"
    101 		sleep 0.5
    102 
    103 		for j in $addrs; do
    104 			echo "Request: ifconfig $i link $j delete"
    105 			ifconfig $i link $j delete
    106 			sleep 0.5
    107 		done
    108 
    109 		ifconfig $i $state
    110 		echo "Restored state of $i to $state"
    111 	done
    112 
    113 	/bin/sh /etc/rc.d/hostapd restart >/dev/null 2>&1
    114 	/bin/sh /etc/rc.d/wpa_supplicant restart >/dev/null 2>&1
    115 
    116 	if [ $fail -eq 1 ]; then
    117 		atf_fail "Failed to set link addresses"
    118 	fi
    119 
    120 	atf_pass
    121 }
    122 
    123 atf_init_test_cases() {
    124 	atf_add_test_case repeated_link_addr
    125 }
    126