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 return 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" 38 return 2>/dev/null 39 exit 40fi 41 42# Test Description: Disable the dummy0 interface 43# Results Expected: After calling ifconfig, no lines with dummy0 are displayed 44testing "dummy0 down and if config /-only" \ 45"ifconfig dummy0 down && ifconfig | grep dummy | wc -l" \ 46"0\n" "" "" 47 48# Test Description: Enable the dummy0 interface 49# Results Expected: After calling ifconfig, one line with dummy0 is displayed 50testing "dummy0 up" \ 51"ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" \ 52"1\n" "" "" 53 54# Test Description: Set the ip address of the dummy0 interface 55# Results Expected: After calling ifconfig dummy0, one line displays the ip 56# address selected 57testing "dummy0 10.240.240.240" \ 58"ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \ 59"1\n" "" "" 60 61# Test Description: Change the netmask to the interface 62# Results Expected: After calling ifconfig dummy0, one line displays the 63# netmask selected 64testing "dummy0 netmask 255.255.240.0" \ 65"ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \ 66"1\n" "" "" 67 68# Test Description: Change the broadcast address to the interface 69# Results Expected: After calling ifconfig dummy0, one line displays the 70# broadcast address selected 71testing "dummy0 broadcast 10.240.240.255" \ 72"ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \ 73"1\n" "" "" 74 75# Test Description: Revert to the default ip address 76# Results Expected: After calling ifconfig dummy0, there are no lines 77# displaying the ip address previously selected 78testing "dummy0 default" \ 79"ifconfig dummy0 default && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \ 80"0\n" "" "" 81 82# Test Description: Change the Maximum transmission unit (MTU) of the interface 83# Results Expected: After calling ifconfig dummy0, there is one line with the 84# selected MTU 85testing "dummy0 mtu 1269" \ 86"ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep 1269 | wc -l" \ 87"1\n" "" "" 88 89# Test Description: Verify ifconfig add fails with such a small mtu 90# Results Expected: There is one line of error message containing 91# "No buffer space available" 92testing "dummy0 add ::2 -- too small mtu" \ 93"ifconfig dummy0 add ::2 2>&1 | grep No\ buffer\ space\ available | wc -l" \ 94"1\n" "" "" 95 96# Test Description: Change the Maximum transmission unit (MTU) of the interface 97# Results Expected: After calling ifconfig dummy0, there is one line with the 98# selected MTU 99testing "dummy0 mtu 2000" \ 100"ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep 2000 | wc -l" \ 101"1\n" "" "" 102 103# Test Description: Verify ifconfig add succeeds with a larger mtu 104# Results Expected: after calling ifconfig dummy0, there is one line with the 105# selected ip address 106testing "dummy0 add ::2" \ 107"ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2\/126 | wc -l" \ 108"1\n" "" "" 109 110# Test Description: Verify ifconfig del removes the selected ip6 address 111# Results Expected: after calling ifconfig dummy0, there are no lines with the 112# selected ip address 113testing "dummy0 del ::2" \ 114"ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2 | wc -l" \ 115"0\n" "" "" 116 117# Test Description: Remove the noarp flag and bring the interface down in 118# preparation for the next test 119# Results Expected: After calling ifconfig dummy0, there are no lines with the 120# NOARP flag 121testing "dummy0 arp down" \ 122"ifconfig dummy0 arp down && ifconfig dummy0 | grep -i NOARP | wc -l" \ 123"0\n" "" "" 124 125# Test Description: Call the pointopoint option with no argument 126# Results Expected: After calling ifconfig dummy0, there is one line with the 127# NOARP and UP flags 128# TODO: http://lists.landley.net/pipermail/toybox-landley.net/2014-November/003795.html 129#testing "dummy0 pointopoint" \ 130#"ifconfig dummy0 pointopoint && ifconfig dummy0 | grep -i NOARP | grep -i UP | wc -l" \ 131#"1\n" "" "" 132 133# Test Description: Test the pointopoint option and set the ipaddress 134# Results Expected: After calling ifconfig dummy0, there is one line with the 135# word inet and the selected ip address 136# TODO: http://lists.landley.net/pipermail/toybox-landley.net/2014-November/003795.html 137#testing "dummy0 pointopoint 127.0.0.2" \ 138#"ifconfig dummy0 pointopoint 127.0.0.2 && ifconfig dummy0 | grep -i inet | grep -i 127\.0\.0\.2 | wc -l" \ 139#"1\n" "" "" 140 141####### Flags you can set on an interface (or -remove by prefixing with -): ############### 142 143# Test Description: Enable allmulti mode on the interface 144# Results Expected: After calling ifconfig dummy0, there is one line with the 145# allmulti flag 146testing "dummy0 allmulti" \ 147"ifconfig dummy0 allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "1\n" \ 148"" "" 149 150# Test Description: Disable multicast mode the interface 151# Results Expected: After calling ifconfig dummy0, there are no lines with the 152# allmulti flag 153testing "dummy0 -allmulti" \ 154"ifconfig dummy0 -allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "0\n" \ 155"" "" 156 157# Test Description: Disable NOARP mode on the interface 158# Results Expected: After calling ifconfig dummy0, there are no lines with the 159# NOARP flag 160testing "dummy0 arp" \ 161"ifconfig dummy0 arp && ifconfig dummy0 | grep -i NOARP | wc -l" "0\n" \ 162"" "" 163 164# Test Description: Enable NOARP mode on the interface 165# Results Expected: After calling ifconfig dummy0, there is one line with the 166# NOARP flag 167testing "dummy0 -arp" \ 168"ifconfig dummy0 -arp && ifconfig dummy0 | grep -i NOARP | wc -l" "1\n" \ 169"" "" 170 171# Test Description: Enable multicast mode on the interface 172# Results Expected: After calling ifconfig dummy0, there is one line with the 173# multicast flag 174testing "dummy0 multicast" \ 175"ifconfig dummy0 multicast && ifconfig dummy0 | grep -i multicast | wc -l" \ 176"1\n" "" "" 177 178# Test Description: Disable multicast mode the interface 179# Results Expected: After calling ifconfig dummy0, there are no lines with the 180# multicast flag 181testing "dummy0 -multicast" \ 182"ifconfig dummy0 -multicast && ifconfig dummy0 | grep -i multicast | wc -l" \ 183"0\n" "" "" 184 185# Test Description: Enable promiscuous mode the interface 186# Results Expected: After calling ifconfig dummy0, there is one line with the 187# promisc flag 188testing "dummy0 promisc" \ 189"ifconfig dummy0 promisc && ifconfig dummy0 | grep -i promisc | wc -l" "1\n" \ 190"" "" 191 192# Disable promiscuous mode the interface 193# Results Expected: After calling ifconfig dummy0, there are no lines with the 194# promisc flag 195testing "dummy0 -promisc" \ 196"ifconfig dummy0 -promisc && ifconfig dummy0 | grep -i promisc | wc -l" "0\n" \ 197"" "" 198 199# Disable the dummy interface 200ifconfig dummy0 down 201