1#! /bin/sh 2# Copyright (c) 2014-2016 Oracle and/or its affiliates. All Rights Reserved. 3# Copyright (c) International Business Machines Corp., 2001 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License as 7# published by the Free Software Foundation; either version 2 of 8# the License, or (at your option) any later version. 9# 10# This program is distributed in the hope that it would be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write the Free Software Foundation, 17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18# 19# Description: Test basic functionality of ip command in route2 package 20# 21# Author: Manoj Iyer, manjo@mail.utexas.edu 22 23TST_CLEANUP=cleanup 24TST_TOTAL=6 25TCID="ip_tests" 26 27TST_USE_LEGACY_API=1 28. tst_net.sh 29 30rm_dummy= 31 32init() 33{ 34 tst_resm TINFO "inititalizing tests" 35 tst_require_root 36 tst_tmpdir 37 tst_test_cmds cat awk diff 38 39 iface=ltp_dummy 40 lsmod | grep -q dummy || rm_dummy=1 41 42 ROD ip li add $iface type dummy 43 44 ip4_addr=${IPV4_NET16_UNUSED}.6.6 45 ROD ip a add ${ip4_addr}/24 dev $iface 46 47 cat > tst_ip02.exp <<-EOF 48 1: 49 link/loopback 50 2: 51 link/ether 52 3: 53 link/ether 54 EOF 55 56 if [ $? -ne 0 ]; then 57 tst_brkm TBROK "can't create expected output for test02" 58 fi 59} 60 61cleanup() 62{ 63 tst_rmdir 64 65 [ -n "$iface" -a -d /sys/class/net/$iface ] && ip li del $iface 66 67 [ "$rm_dummy" ] && modprobe -r dummy 68 69 # test #5 70 ip route show | grep $ip4_addr && ip route del $ip4_addr 71} 72 73test01() 74{ 75 tst_resm TINFO "test 'ip link set' command" 76 tst_resm TINFO "changing mtu size of $iface device" 77 78 MTUSZ_BAK=$(cat /sys/class/net/${iface}/mtu) 79 ip link set ${iface} mtu 1281 80 if [ $? -ne 0 ]; then 81 tst_resm TFAIL "ip command failed" 82 return 83 fi 84 85 MTUSZ=$(cat /sys/class/net/${iface}/mtu) 86 if [ $MTUSZ -eq 1281 ]; then 87 tst_resm TPASS "successfully changed mtu size" 88 ip link set $iface mtu $MTUSZ_BAK 89 else 90 tst_resm TFAIL "MTU value set to $MTUSZ, but expected 1281" 91 fi 92} 93 94test02() 95{ 96 tst_resm TINFO "test 'ip link show' command (list device attributes)" 97 98 ip link show $iface | grep $iface > /dev/null 99 if [ $? -ne 0 ]; then 100 tst_resm TFAIL "'ip link show $iface' command failed" 101 return 102 fi 103 104 tst_resm TPASS "$iface correctly listed" 105} 106 107test03() 108{ 109 tst_resm TINFO "test 'ip addr' command with loopback dev" 110 tst_resm TINFO "add a new protocol address to the device" 111 112 ip addr add 127.6.6.6/24 dev lo 113 if [ $? -ne 0 ]; then 114 tst_resm TFAIL "'ip addr add' command failed" 115 return 116 fi 117 118 tst_resm TINFO "show protocol address" 119 ip addr show dev lo | grep 127.6.6.6 > /dev/null 120 if [ $? -ne 0 ]; then 121 tst_resm TFAIL "'ip addr show' command failed" 122 return 123 fi 124 125 tst_resm TINFO "delete protocol address" 126 ip addr del 127.6.6.6/24 dev lo 127 if [ $? -ne 0 ]; then 128 tst_resm TFAIL "'ip addr del' command failed" 129 return 130 fi 131 132 ip addr show dev lo | grep 127.6.6.6 > /dev/null 133 if [ $? -eq 0 ]; then 134 tst_resm TFAIL "ip addr del command failed" 135 return 136 fi 137 138 tst_resm TPASS "'ip addr' command successfully tested" 139} 140 141test04() 142{ 143 local taddr="$(tst_ipaddr_un)" 144 local tdev="$(tst_iface)" 145 tst_resm TINFO "test 'ip neigh' command" 146 tst_resm TINFO "add a new neighbor (or replace existed)" 147 ip neigh replace $taddr lladdr 00:00:00:00:00:00 dev $tdev nud reachable 148 if [ $? -ne 0 ]; then 149 tst_resm TFAIL "'ip neigh replace' command failed" 150 return 151 fi 152 153 tst_resm TINFO "show all neighbor entries in arp tables" 154 echo "$taddr dev $tdev lladdr 00:00:00:00:00:00 REACHABLE" > tst_ip.exp 155 156 ip neigh show $taddr | head -n1 > tst_ip.out 2>&1 157 if [ $? -ne 0 ]; then 158 tst_resm TFAIL "'ip neigh show' command failed" 159 return 160 fi 161 162 diff -iwB tst_ip.out tst_ip.exp 163 if [ $? -ne 0 ]; then 164 tst_resm TFAIL "expected output differs from actual output" 165 return 166 fi 167 168 tst_resm TINFO "delete neighbor from the arp table" 169 170 ip neigh del $taddr dev $tdev 171 if [ $? -ne 0 ]; then 172 tst_resm TFAIL "'ip neigh del' command failed" 173 return 174 fi 175 176 ip neigh show | grep $taddr | grep -v ' FAILED$' > /dev/null 177 if [ $? -eq 0 ]; then 178 tst_resm TFAIL "$taddr still listed in arp" 179 return 180 fi 181 182 tst_resm TPASS "'ip neigh' command successfully tested" 183} 184 185test05() 186{ 187 tst_resm TINFO "test 'ip route add/del' commands" 188 189 ROD ip route add $ip4_addr via 127.0.0.1 190 191 tst_resm TINFO "show all route entries in route table" 192 193 # create expected output file. 194 cat > tst_ip.exp <<-EOF 195$ip4_addr via 127.0.0.1 dev lo 196 EOF 197 198 ip route show | grep "$ip4_addr via 127.0.0.1 dev lo" > tst_ip.out 2>&1 199 if [ $? -ne 0 ]; then 200 tst_resm TFAIL "'ip route show' command failed" 201 return 202 fi 203 204 diff -iwB tst_ip.out tst_ip.exp 205 if [ $? -ne 0 ]; then 206 tst_resm TFAIL "'ip route show' did not list new route" 207 return 208 fi 209 210 tst_resm TINFO "delete route from the route table" 211 212 ROD ip route del $ip4_addr via 127.0.0.1 213 214 ip route show | grep 127.0.0.1 > /dev/null 215 if [ $? -eq 0 ]; then 216 tst_resm TFAIL "route not deleted" 217 return 218 fi 219 220 tst_resm TPASS "'ip route' command successfully tested" 221} 222 223test06() 224{ 225 tst_resm TINFO "test 'ip maddr add/del' commands" 226 tst_resm TINFO "adding a new multicast addr" 227 228 ip maddr add 66:66:00:00:00:66 dev $iface 229 if [ $? -ne 0 ]; then 230 tst_resm TFAIL "ip maddr add command failed" 231 return 232 fi 233 234 tst_resm TINFO "show all multicast addr entries" 235 236 cat > tst_ip.exp <<-EOF 237 link 66:66:00:00:00:66 static 238 EOF 239 240 ip maddr show | grep "66:66:00:00:00:66" > tst_ip.out 2>&1 241 if [ $? -ne 0 ]; then 242 tst_resm TFAIL "'ip maddr show' command failed" 243 return 244 fi 245 246 diff -iwB tst_ip.out tst_ip.exp 247 if [ $? -ne 0 ]; then 248 tst_resm TFAIL "multicast addr not added to $iface" 249 return 250 fi 251 252 tst_resm TINFO "delete multicast address" 253 254 ip maddr del 66:66:00:00:00:66 dev $iface 255 if [ $? -ne 0 ]; then 256 tst_resm TFAIL "'ip maddr del' command failed" 257 return 258 fi 259 260 ip maddr show | grep "66:66:00:00:00:66" > /dev/null 261 if [ $? -eq 0 ]; then 262 tst_resm TFAIL "66:66:00:00:00:66 is not deleted" 263 return 264 fi 265 266 tst_resm TPASS "'ip maddr' command successfully tested" 267} 268 269init 270 271test01 272test02 273test03 274test04 275test05 276test06 277 278tst_exit 279