t_repeated_link_addr.sh revision 1.2
1# $NetBSD: t_repeated_link_addr.sh,v 1.2 2020/07/03 02:51:13 jruoho 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# 30atf_test_case repeated_link_addr 31repeated_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 38repeated_link_addr_body() { 39 40 case $(uname -m) in 41 evbarm) 42 atf_expect_timeout "reason for timeout unknown" 43 ;; 44 esac 45 46 fail=0 47 addrs="00:11:00:00:00:00 \ 48 00:11:11:00:00:00 \ 49 00:11:11:11:00:00 \ 50 00:11:11:11:11:00 \ 51 00:00:11:00:00:00 \ 52 00:00:11:11:00:00 \ 53 00:00:11:11:11:00 \ 54 00:00:00:11:00:00 \ 55 00:00:00:11:11:00" 56 57 pkill -9 hostapd 58 pkill -9 wpa_supplicant 59 60 for i in $(ifconfig -l); do 61 62 state="up" 63 addr=$(ifconfig $i | grep "address") 64 addr=$(echo $addr | sed "s/address: //" | sed 's/ //') 65 66 if [ -z "$addr" ]; then 67 echo "Skipping $i" 68 continue 69 fi 70 71 ifconfig -s $i 72 73 if [ $? -eq 1 ]; then 74 state="down" 75 ifconfig $i up 76 sleep 1 77 fi 78 79 for j in $addrs; do 80 81 echo "Request: ifconfig $i link $j active" 82 ifconfig $i link $j active 83 84 if [ ! $? -eq 0 ]; then 85 fail=1 86 fi 87 88 if [ -z "$(ifconfig $i | grep $j)" ]; then 89 fail=1 90 fi 91 92 sleep 0.5 93 done 94 95 # From the ifconfig(8) manual page: 96 # 97 # "You may not delete the active address from an interface. 98 # You must activate some other address, first." 99 # 100 ifconfig $i link $addr active 101 echo "Restored the link address of $i to $addr" 102 sleep 0.5 103 104 for j in $addrs; do 105 echo "Request: ifconfig $i link $j delete" 106 ifconfig $i link $j delete 107 sleep 0.5 108 done 109 110 ifconfig $i $state 111 echo "Restored state of $i to $state" 112 done 113 114 /bin/sh /etc/rc.d/hostapd restart >/dev/null 2>&1 115 /bin/sh /etc/rc.d/wpa_supplicant restart >/dev/null 2>&1 116 117 if [ $fail -eq 1 ]; then 118 atf_fail "Failed to set link addresses" 119 fi 120 121 atf_pass 122} 123 124atf_init_test_cases() { 125 atf_add_test_case repeated_link_addr 126} 127