• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
27. test_net.sh
28
29rm_dummy=
30
31init()
32{
33	tst_resm TINFO "inititalizing tests"
34	tst_require_root
35	tst_tmpdir
36	tst_check_cmds cat awk ip diff
37
38	iface=ltp_dummy
39	lsmod | grep -q dummy || rm_dummy=1
40
41	ROD ip li add $iface type dummy
42
43	ip4_addr=${IPV4_NET16_UNUSED}.6.6
44	ROD ip a add ${ip4_addr}/24 dev $iface
45
46	cat > tst_ip02.exp <<-EOF
47	1:
48	link/loopback
49	2:
50	link/ether
51	3:
52	link/ether
53	EOF
54
55	if [ $? -ne 0 ]; then
56		tst_brkm TBROK "can't create expected output for test02"
57	fi
58}
59
60cleanup()
61{
62	tst_rmdir
63
64	[ -n "$iface" -a -d /sys/class/net/$iface ] && ip li del $iface
65
66	[ "$rm_dummy" ] && modprobe -r dummy
67
68	# test #5
69	ip route show | grep $ip4_addr && ip route del $ip4_addr
70}
71
72test01()
73{
74	tst_resm TINFO "test 'ip link set' command"
75	tst_resm TINFO "changing mtu size of $iface device"
76
77	MTUSZ_BAK=$(cat /sys/class/net/${iface}/mtu)
78	ip link set ${iface} mtu 1281
79	if [ $? -ne 0 ]; then
80		tst_resm TFAIL "ip command failed"
81		return
82	fi
83
84	MTUSZ=$(cat /sys/class/net/${iface}/mtu)
85	if [ $MTUSZ -eq 1281 ]; then
86		tst_resm TPASS "successfully changed mtu size"
87		ip link set $iface mtu $MTUSZ_BAK
88	else
89		tst_resm TFAIL "MTU value set to $MTUSZ, but expected 1281"
90	fi
91}
92
93test02()
94{
95	tst_resm TINFO "test 'ip link show' command (list device attributes)"
96
97	ip link show $iface | grep $iface > /dev/null
98	if [ $? -ne 0 ]; then
99		tst_resm TFAIL "'ip link show $iface' command failed"
100		return
101	fi
102
103	tst_resm TPASS "$iface correctly listed"
104}
105
106test03()
107{
108	tst_resm TINFO "test 'ip addr' command with loopback dev"
109	tst_resm TINFO "add a new protocol address to the device"
110
111	ip addr add 127.6.6.6/24 dev lo
112	if [ $? -ne 0 ]; then
113		tst_resm TFAIL "'ip addr add' command failed"
114		return
115	fi
116
117	tst_resm TINFO "show protocol address"
118	ip addr show dev lo | grep 127.6.6.6 > /dev/null
119	if [ $? -ne 0 ]; then
120		tst_resm TFAIL "'ip addr show' command failed"
121		return
122	fi
123
124	tst_resm TINFO "delete protocol address"
125	ip addr del 127.6.6.6/24 dev lo
126	if [ $? -ne 0 ]; then
127		tst_resm TFAIL "'ip addr del' command failed"
128		return
129	fi
130
131	ip addr show dev lo | grep 127.6.6.6 > /dev/null
132	if [ $? -eq 0 ]; then
133		tst_resm TFAIL "ip addr del command failed"
134		return
135	fi
136
137	tst_resm TPASS "'ip addr' command successfully tested"
138}
139
140test04()
141{
142	tst_resm TINFO "test 'ip neigh' command"
143	tst_resm TINFO "add a new neighbor (or replace existed)"
144	ip neigh replace 127.6.6.6 lladdr 00:00:00:00:00:00 dev lo nud reachable
145	if [ $? -ne 0 ]; then
146		tst_resm TFAIL "'ip neigh replace' command failed"
147		return
148	fi
149
150	tst_resm TINFO "show all neighbor entries in arp tables"
151	cat > tst_ip.exp <<-EOF
152127.6.6.6 dev lo lladdr 00:00:00:00:00:00 REACHABLE
153	EOF
154
155	ip neigh show 127.6.6.6 | head -n1 > tst_ip.out 2>&1
156	if [ $? -ne 0 ]; then
157		tst_resm TFAIL "'ip neigh show' command failed"
158		return
159	fi
160
161	diff -iwB tst_ip.out tst_ip.exp
162	if [ $? -ne 0 ]; then
163		tst_resm TFAIL "expected output differs from actual output"
164		return
165	fi
166
167	tst_resm TINFO "delete neighbor from the arp table"
168
169	ip neigh del 127.6.6.6 dev lo
170	if [ $? -ne 0 ]; then
171		tst_resm TFAIL "'ip neigh del' command failed"
172		return
173	fi
174
175	ip neigh show | grep 127.6.6.6 | grep -v ' FAILED$' > /dev/null
176	if [ $? -eq 0 ]; then
177		tst_resm TFAIL "127.6.6.6 still listed in arp"
178		return
179	fi
180
181	tst_resm TPASS "'ip neigh' command successfully tested"
182}
183
184test05()
185{
186	tst_resm TINFO "test 'ip route add/del' commands"
187
188	ROD ip route add $ip4_addr via 127.0.0.1
189
190	tst_resm TINFO "show all route entries in route table"
191
192	# create expected output file.
193	cat > tst_ip.exp <<-EOF
194$ip4_addr via 127.0.0.1 dev lo
195	EOF
196
197	ip route show | grep "$ip4_addr via 127.0.0.1 dev lo" > tst_ip.out 2>&1
198	if [ $? -ne 0 ]; then
199		tst_resm TFAIL "'ip route show' command failed"
200		return
201	fi
202
203	diff -iwB tst_ip.out tst_ip.exp
204	if [ $? -ne 0 ]; then
205		tst_resm TFAIL "'ip route show' did not list new route"
206		return
207	fi
208
209	tst_resm TINFO "delete route from the route table"
210
211	ROD ip route del $ip4_addr via 127.0.0.1
212
213	ip route show | grep 127.0.0.1 > /dev/null
214	if [ $? -eq 0 ]; then
215		tst_resm TFAIL "route not deleted"
216		return
217	fi
218
219	tst_resm TPASS "'ip route' command successfully tested"
220}
221
222test06()
223{
224	tst_resm TINFO "test 'ip maddr add/del' commands"
225	tst_resm TINFO "adding a new multicast addr"
226
227	ip maddr add 66:66:00:00:00:66 dev $iface
228	if [ $? -ne 0 ]; then
229		tst_resm TFAIL "ip maddr add command failed"
230		return
231	fi
232
233	tst_resm TINFO "show all multicast addr entries"
234
235	cat > tst_ip.exp <<-EOF
236        link  66:66:00:00:00:66 static
237	EOF
238
239	ip maddr show | grep "66:66:00:00:00:66" > tst_ip.out 2>&1
240	if [ $? -ne 0 ]; then
241		tst_resm TFAIL "'ip maddr show' command failed"
242		return
243	fi
244
245	diff -iwB tst_ip.out tst_ip.exp
246	if [ $? -ne 0 ]; then
247		tst_resm TFAIL "multicast addr not added to $iface"
248		return
249	fi
250
251	tst_resm TINFO "delete multicast address"
252
253	ip maddr del 66:66:00:00:00:66 dev $iface
254	if [ $? -ne 0 ]; then
255		tst_resm TFAIL "'ip maddr del' command failed"
256		return
257	fi
258
259	ip maddr show | grep "66:66:00:00:00:66" > /dev/null
260	if [ $? -eq 0 ]; then
261		tst_resm TFAIL "66:66:00:00:00:66 is not deleted"
262		return
263	fi
264
265	tst_resm TPASS "'ip maddr' command successfully tested"
266}
267
268init
269
270test01
271test02
272test03
273test04
274test05
275test06
276
277tst_exit
278