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