xref: /illumos-gate/usr/src/test/util-tests/tests/dladm/allowed-ips.ksh (revision 52244c0958bdf281ca42932b449f644b4decfdc2)
1#!/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2014, Joyent, Inc.
15#
16
17ai_arg0="$(basename $0)"
18ai_stub="teststub$$"
19ai_vnic="testvnic$$"
20
21function fatal
22{
23	typeset msg="$*"
24	[[ -z "$msg" ]] && msg="failed"
25	echo "TEST_FAIL: $vt_arg0: $msg" >&2
26	exit 1
27}
28
29function setup
30{
31	dladm create-etherstub $ai_stub || fatal "failed to create etherstub"
32	dladm create-vnic -l $ai_stub $ai_vnic || fatal "failed to create vnic"
33}
34
35function cleanup
36{
37	dladm delete-vnic $ai_vnic || fatal "failed to remove vnic"
38	dladm delete-etherstub $ai_stub || fatal "failed to remove etherstub"
39}
40
41function runtest
42{
43	dladm set-linkprop -p allowed-ips="$@" $ai_vnic 2>/dev/null
44}
45
46function epass
47{
48	runtest $* || fatal "allowed-ips=$* failed, expected success\n"
49}
50
51function efail
52{
53	runtest $* && fatal "allowed-ips=$* succeeded, expected failure\n"
54}
55
56#
57# Run through all IPv6 prefixes for validity with a token prefix
58#
59function allv6
60{
61	typeset i;
62	for ((i = 1; i <= 128; i++)); do
63		epass "8000::/$i"
64	done
65}
66
67#
68# Run through all of the v6 prefixes except /128 and ensure that they fail for
69# a given IPv6 address because the other bits are set.
70#
71function v6specific
72{
73	typeset i;
74	for ((i = 0; i < 128; i++)); do
75		efail 2600:3c00::f03c:91ff:fe96:a267/$i
76	done
77}
78
79setup
80
81# Basic IPv4 single and multiple IPs
82efail 0.0.0.0
83epass 127.0.0.1
84epass 127.0.0.1,127.0.0.2
85efail 127.0.0.1,127.0.0.1
86epass 10.167.169.23
87epass 11.167.169.23
88epass 12.167.169.23
89epass 10.167.169.23,11.167.169.23,12.167.169.23
90efail 256.1.1.1
91efail 1.256.1.1
92efail 1.1.256.1
93efail 1.1.1.256
94efail 300.300.300.300
95efail 300.300.300.300,1.1.1.1
96efail 1.1.1.1,300.300.300.300
97efail 3.-3.3.-3
98
99# Basic IPv4 prefixes
100efail 0.0.0.0/0
101epass 127.0.0.0/8
102efail 127.0.0.1/8
103epass 128.0.0.0/1
104epass 128.0.0.0/2
105epass 128.0.0.0/3
106epass 128.0.0.0/4
107epass 128.0.0.0/5
108epass 128.0.0.0/6
109epass 128.0.0.0/7
110epass 128.0.0.0/8
111epass 128.0.0.0/9
112epass 128.0.0.0/10
113epass 128.0.0.0/11
114epass 128.0.0.0/12
115epass 128.0.0.0/13
116epass 128.0.0.0/14
117epass 128.0.0.0/15
118epass 128.0.0.0/16
119epass 128.0.0.0/17
120epass 128.0.0.0/18
121epass 128.0.0.0/19
122epass 128.0.0.0/20
123epass 128.0.0.0/21
124epass 128.0.0.0/22
125epass 128.0.0.0/23
126epass 128.0.0.0/24
127epass 128.0.0.0/25
128epass 128.0.0.0/26
129epass 128.0.0.0/27
130epass 128.0.0.0/28
131epass 128.0.0.0/29
132epass 128.0.0.0/30
133epass 128.0.0.0/21
134epass 128.0.0.0/32
135
136efail 128.0.0.1/2
137efail 128.0.0.1/4
138efail 128.0.0.1/8
139efail 128.0.0.1/10
140efail 128.0.0.1/12
141efail 128.0.0.1/14
142efail 128.0.0.1/16
143efail 128.0.0.1/18
144efail 128.0.0.1/20
145efail 128.0.0.1/22
146efail 128.0.0.1/24
147efail 128.0.0.1/28
148efail 128.0.0.1/30
149epass 128.0.0.1/32
150
151epass 10.0.0.0/30
152epass 10.0.0.4/30
153epass 10.0.0.8/30
154epass 10.0.0.12/30
155epass 10.0.0.16/30
156epass 10.0.0.20/30
157
158efail 10.0.0.1/30
159efail 10.0.0.5/30
160efail 10.0.0.9/30
161efail 10.0.0.13/30
162efail 10.0.0.17/30
163efail 10.0.0.21/30
164
165epass 10.99.99.0/24,10.88.88.0/24,10.77.7.0/24
166epass 10.99.99.7/32,10.168.0.0/16
167
168efail 10.99.99.7/33
169efail 10.99.99.7/-1
170efail 10.99.99.7/
171efail 10.99.99.7/0
172
173# Basic IPv6 Addresss
174efail ::
175efail 1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1
176efail dead:beef::gg
177epass ::1
178epass ::127.0.0.1
179epass ::10.0.0.0
180efail ::0.0.0.0
181efail ::ffff:0.0.0.0
182epass ::ffff:10.123.167.169
183epass 2600:3c00::f03c:91ff:fe96:a264
184
185# IPv6 Prefixes
186
187efail ::/128
188efail 2600:3c00::f03c:91ff:fe96:a264/129
189efail 2600:3c00::f03c:91ff:fe96:a264/-1
190efail 2600:3c00::f03c:91ff:fe96:a264/-
191efail 2600:3c00::f03c:91ff:fe96:a264/
192efail ::1/1
193efail ::1/20
194
195allv6
196v6specific
197
198epass 2600:3c00::f03c:91ff:fe96:a264/128
199epass 2600:3c00::/64
200
201efail fe80::8:20ff:fead:3361/10
202efail fe80::1/10
203epass fe80::/15
204epass fe82::/15
205
206cleanup
207printf "TEST PASS: $ai_arg0"
208