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