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