1#!/bin/bash 2# Copyright 2014 Cynthia Rempel <cynthia@rtems.org> 3# 4# Brief: Some cursery coverage tests of ifconfig... 5# Note: requires permissions to run modprobe and all ifconfig options 6# Commands used: grep, grep -i, ip link, ip tuntap, wc -l 7# 8# Possible improvements: 9# 1. Verify the dummy interface actually has the modified characteristics 10# instead of relying on ifconfig output 11# 2. Introduce more error cases, to verify ifconfig fails gracefully 12# 3. Do more complex calls to ifconfig, while mixing the order of the 13# arguments 14# 4. Cover more ifconfig options: 15# hw ether|infiniband ADDRESS - set LAN hardware address (AA:BB:CC...) 16# txqueuelen LEN - number of buffered packets before output blocks 17# Obsolete fields included for historical purposes: 18# irq|io_addr|mem_start ADDR - micromanage obsolete hardware 19# outfill|keepalive INTEGER - SLIP analog dialup line quality monitoring 20# metric INTEGER - added to Linux 0.9.10 with comment "never used", still true 21 22[ -f testing.sh ] && . testing.sh 23 24if [ "$(id -u)" -ne 0 ] 25then 26 echo "$SHOWSKIP: ifconfig (not root)" 27 continue 2>/dev/null 28 exit 29fi 30 31#testing "name" "command" "result" "infile" "stdin" 32 33# Add a dummy interface to test with 34modprobe dummy 2>/dev/null 35if ! ifconfig dummy0 up 2>/dev/null 36then 37 echo "$SHOWSKIP: ifconfig dummy0 up failed" 38fi 39 40# Test Description: Disable the dummy0 interface 41# Results Expected: After calling ifconfig, no lines with dummy0 are displayed 42testing "dummy0 down and if config /-only" \ 43"ifconfig dummy0 down && ifconfig | grep dummy | wc -l" \ 44"0\n" "" "" 45 46# Test Description: Enable the dummy0 interface 47# Results Expected: After calling ifconfig, one line with dummy0 is displayed 48testing "dummy0 up" \ 49"ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" \ 50"1\n" "" "" 51 52# Test Description: Set the ip address of the dummy0 interface 53# Results Expected: After calling ifconfig dummy0, one line displays the ip 54# address selected 55testing "dummy0 10.240.240.240" \ 56"ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \ 57"1\n" "" "" 58 59# Test Description: Change the netmask to the interface 60# Results Expected: After calling ifconfig dummy0, one line displays the 61# netmask selected 62testing "dummy0 netmask 255.255.240.0" \ 63"ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \ 64"1\n" "" "" 65 66# Test Description: Change the broadcast address to the interface 67# Results Expected: After calling ifconfig dummy0, one line displays the 68# broadcast address selected 69testing "dummy0 broadcast 10.240.240.255" \ 70"ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \ 71"1\n" "" "" 72 73# Test Description: Revert to the default ip address 74# Results Expected: After calling ifconfig dummy0, there are no lines 75# displaying the ip address previously selected 76testing "dummy0 default" \ 77"ifconfig dummy0 default && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \ 78"0\n" "" "" 79 80# Test Description: Change the Maximum transmission unit (MTU) of the interface 81# Results Expected: After calling ifconfig dummy0, there is one line with the 82# selected MTU 83testing "dummy0 mtu 1269" \ 84"ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep 1269 | wc -l" \ 85"1\n" "" "" 86 87# Test Description: Verify ifconfig add fails with such a small mtu 88# Results Expected: There is one line of error message containing 89# "No buffer space available" 90testing "dummy0 add ::2 -- too small mtu" \ 91"ifconfig dummy0 add ::2 2>&1 | grep No\ buffer\ space\ available | wc -l" \ 92"1\n" "" "" 93 94# Test Description: Change the Maximum transmission unit (MTU) of the interface 95# Results Expected: After calling ifconfig dummy0, there is one line with the 96# selected MTU 97testing "dummy0 mtu 2000" \ 98"ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep 2000 | wc -l" \ 99"1\n" "" "" 100 101# Test Description: Verify ifconfig add succeeds with a larger mtu 102# Results Expected: after calling ifconfig dummy0, there is one line with the 103# selected ip address 104testing "dummy0 add ::2" \ 105"ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2\/126 | wc -l" \ 106"1\n" "" "" 107 108# Test Description: Verify ifconfig del removes the selected ip6 address 109# Results Expected: after calling ifconfig dummy0, there are no lines with the 110# selected ip address 111testing "dummy0 del ::2" \ 112"ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2 | wc -l" \ 113"0\n" "" "" 114 115# Test Description: Remove the noarp flag and bring the interface down in 116# preparation for the next test 117# Results Expected: After calling ifconfig dummy0, there are no lines with the 118# NOARP flag 119testing "dummy0 arp down" \ 120"ifconfig dummy0 arp down && ifconfig dummy0 | grep -i NOARP | wc -l" \ 121"0\n" "" "" 122 123# Test Description: Call the pointopoint option with no argument 124# Results Expected: After calling ifconfig dummy0, there is one line with the 125# NOARP and UP flags 126testing "dummy0 pointopoint" \ 127"ifconfig dummy0 pointopoint && ifconfig dummy0 | grep -i NOARP | grep -i UP | wc -l" \ 128"1\n" "" "" 129 130# Test Description: Test the pointopoint option and set the ipaddress 131# Results Expected: After calling ifconfig dummy0, there is one line with the 132# word inet and the selected ip address 133testing "dummy0 pointopoint 127.0.0.2" \ 134"ifconfig dummy0 pointopoint 127.0.0.2 && ifconfig dummy0 | grep -i inet | grep -i 127\.0\.0\.2 | wc -l" \ 135"1\n" "" "" 136 137####### Flags you can set on an interface (or -remove by prefixing with -): ############### 138 139# Test Description: Enable allmulti mode on the interface 140# Results Expected: After calling ifconfig dummy0, there is one line with the 141# allmulti flag 142testing "dummy0 allmulti" \ 143"ifconfig dummy0 allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "1\n" \ 144"" "" 145 146# Test Description: Disable multicast mode the interface 147# Results Expected: After calling ifconfig dummy0, there are no lines with the 148# allmulti flag 149testing "dummy0 -allmulti" \ 150"ifconfig dummy0 -allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "0\n" \ 151"" "" 152 153# Test Description: Disable NOARP mode on the interface 154# Results Expected: After calling ifconfig dummy0, there are no lines with the 155# NOARP flag 156testing "dummy0 arp" \ 157"ifconfig dummy0 arp && ifconfig dummy0 | grep -i NOARP | wc -l" "0\n" \ 158"" "" 159 160# Test Description: Enable NOARP mode on the interface 161# Results Expected: After calling ifconfig dummy0, there is one line with the 162# NOARP flag 163testing "dummy0 -arp" \ 164"ifconfig dummy0 -arp && ifconfig dummy0 | grep -i NOARP | wc -l" "1\n" \ 165"" "" 166 167# Test Description: Enable multicast mode on the interface 168# Results Expected: After calling ifconfig dummy0, there is one line with the 169# multicast flag 170testing "dummy0 multicast" \ 171"ifconfig dummy0 multicast && ifconfig dummy0 | grep -i multicast | wc -l" \ 172"1\n" "" "" 173 174# Test Description: Disable multicast mode the interface 175# Results Expected: After calling ifconfig dummy0, there are no lines with the 176# multicast flag 177testing "dummy0 -multicast" \ 178"ifconfig dummy0 -multicast && ifconfig dummy0 | grep -i multicast | wc -l" \ 179"0\n" "" "" 180 181# Test Description: Enable promiscuous mode the interface 182# Results Expected: After calling ifconfig dummy0, there is one line with the 183# promisc flag 184testing "dummy0 promisc" \ 185"ifconfig dummy0 promisc && ifconfig dummy0 | grep -i promisc | wc -l" "1\n" \ 186"" "" 187 188# Disable promiscuous mode the interface 189# Results Expected: After calling ifconfig dummy0, there are no lines with the 190# promisc flag 191testing "dummy0 -promisc" \ 192"ifconfig dummy0 -promisc && ifconfig dummy0 | grep -i promisc | wc -l" "0\n" \ 193"" "" 194 195# Disable the dummy interface 196ifconfig dummy0 down 197