xref: /illumos-gate/usr/src/test/net-tests/tests/ipv6/scope-test-v4.ksh (revision 64130b0be265e6f79e86a9f3c515fb40680f25b1)
1*64130b0bSBill Sommerfeld#!/usr/bin/ksh
2*64130b0bSBill Sommerfeld#
3*64130b0bSBill Sommerfeld# This file and its contents are supplied under the terms of the
4*64130b0bSBill Sommerfeld# Common Development and Distribution License ("CDDL"), version 1.0.
5*64130b0bSBill Sommerfeld# You may only use this file in accordance with the terms of version
6*64130b0bSBill Sommerfeld# 1.0 of the CDDL.
7*64130b0bSBill Sommerfeld#
8*64130b0bSBill Sommerfeld# A full copy of the text of the CDDL should have accompanied this
9*64130b0bSBill Sommerfeld# source.  A copy of the CDDL is also available via the Internet at
10*64130b0bSBill Sommerfeld# http://www.illumos.org/license/CDDL.
11*64130b0bSBill Sommerfeld
12*64130b0bSBill Sommerfeld#
13*64130b0bSBill Sommerfeld# Copyright 2024 Bill Sommerfeld
14*64130b0bSBill Sommerfeld#
15*64130b0bSBill Sommerfeld
16*64130b0bSBill Sommerfeld# This tests behavior around IP_BOUND_IF for ipv4 sockets as a check that
17*64130b0bSBill Sommerfeld# other v6-focused work hasn't cause a regression.
18*64130b0bSBill Sommerfeld
19*64130b0bSBill Sommerfeld# It does this with multiple vnics on multiple simnets created for this
20*64130b0bSBill Sommerfeld# test.   No special system configuration is required.
21*64130b0bSBill Sommerfeld
22*64130b0bSBill Sommerfeldtypeset -a simnets=()
23*64130b0bSBill Sommerfeldtypeset -a vnics=()
24*64130b0bSBill Sommerfeld
25*64130b0bSBill Sommerfeldtypeset -i failures=0
26*64130b0bSBill Sommerfeld
27*64130b0bSBill Sommerfeldscriptdir=$(dirname -- "$0")
28*64130b0bSBill Sommerfeld
29*64130b0bSBill Sommerfeldfunction fatal {
30*64130b0bSBill Sommerfeld	print "$*" >&2
31*64130b0bSBill Sommerfeld	exit 1
32*64130b0bSBill Sommerfeld}
33*64130b0bSBill Sommerfeld
34*64130b0bSBill Sommerfeldfunction test_fail {
35*64130b0bSBill Sommerfeld	print "$*" >&2
36*64130b0bSBill Sommerfeld	(( failures++ ))
37*64130b0bSBill Sommerfeld}
38*64130b0bSBill Sommerfeld
39*64130b0bSBill Sommerfeldfunction cleanup {
40*64130b0bSBill Sommerfeld	{
41*64130b0bSBill Sommerfeld		for vnic in ${vnics[@]}; do
42*64130b0bSBill Sommerfeld			ipadm delete-if ${vnic}
43*64130b0bSBill Sommerfeld			dladm delete-vnic "$vnic"
44*64130b0bSBill Sommerfeld		done
45*64130b0bSBill Sommerfeld
46*64130b0bSBill Sommerfeld		for simnet in ${simnets[@]}; do
47*64130b0bSBill Sommerfeld			dladm delete-simnet "$simnet"
48*64130b0bSBill Sommerfeld		done
49*64130b0bSBill Sommerfeld	} > /dev/null 2>&1
50*64130b0bSBill Sommerfeld}
51*64130b0bSBill Sommerfeld
52*64130b0bSBill Sommerfeldtrap cleanup EXIT
53*64130b0bSBill Sommerfeld
54*64130b0bSBill Sommerfeldfunction create_simnet {
55*64130b0bSBill Sommerfeld
56*64130b0bSBill Sommerfeld	SIMNET="$1"
57*64130b0bSBill Sommerfeld	simnets+=($SIMNET)
58*64130b0bSBill Sommerfeld	dladm create-simnet -t "$SIMNET"
59*64130b0bSBill Sommerfeld	shift
60*64130b0bSBill Sommerfeld	while (( $# > 0 )); do
61*64130b0bSBill Sommerfeld		IF="$1"
62*64130b0bSBill Sommerfeld		vnics+=($IF)
63*64130b0bSBill Sommerfeld		dladm create-vnic -t -l "$SIMNET" "$IF"
64*64130b0bSBill Sommerfeld		shift
65*64130b0bSBill Sommerfeld        done
66*64130b0bSBill Sommerfeld	echo $simnets
67*64130b0bSBill Sommerfeld	echo $vnics
68*64130b0bSBill Sommerfeld}
69*64130b0bSBill Sommerfeld
70*64130b0bSBill Sommerfeldfunction init_if {
71*64130b0bSBill Sommerfeld	VNIC="$1"
72*64130b0bSBill Sommerfeld	V4ADDR="$2"
73*64130b0bSBill Sommerfeld
74*64130b0bSBill Sommerfeld	ipadm create-if -t $VNIC
75*64130b0bSBill Sommerfeld
76*64130b0bSBill Sommerfeld	ipadm create-addr -T static -a local=$V4ADDR $VNIC/llt4
77*64130b0bSBill Sommerfeld}
78*64130b0bSBill Sommerfeld
79*64130b0bSBill Sommerfeldcreate_simnet llt_simnet0 llt_vnic0 llt_vnic1
80*64130b0bSBill Sommerfeldcreate_simnet llt_simnet1 llt_vnic2 llt_vnic3
81*64130b0bSBill Sommerfeld
82*64130b0bSBill Sommerfeld# RFC2544 assigns 198.18.0.0/15 for "benchmarking"; use in a unit test
83*64130b0bSBill Sommerfeld# would be consistent with that assignment.
84*64130b0bSBill Sommerfeld
85*64130b0bSBill Sommerfeldinit_if llt_vnic0 198.18.1.1/25
86*64130b0bSBill Sommerfeldinit_if llt_vnic1 198.18.1.2/25
87*64130b0bSBill Sommerfeldinit_if llt_vnic2 198.18.2.1/25
88*64130b0bSBill Sommerfeldinit_if llt_vnic3 198.18.2.2/25
89*64130b0bSBill Sommerfeld
90*64130b0bSBill Sommerfeldipadm show-addr
91*64130b0bSBill Sommerfeld
92*64130b0bSBill Sommerfeldc0=198.18.1.1
93*64130b0bSBill Sommerfeldc1=198.18.1.2
94*64130b0bSBill Sommerfeldc2=198.18.2.1
95*64130b0bSBill Sommerfeldc3=198.18.2.2
96*64130b0bSBill Sommerfeld
97*64130b0bSBill Sommerfeld# regression testing for IP_BOUND_IF
98*64130b0bSBill Sommerfeld
99*64130b0bSBill Sommerfeldfor proto in udp tcp; do
100*64130b0bSBill Sommerfeld	c="--port 12345  --proto ${proto} --family 4 "
101*64130b0bSBill Sommerfeld
102*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} --addr ${c1} --addr ${c3} ${c1} ||
103*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 tcp connect 1 failed"
104*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} --addr ${c1} --addr ${c3} ${c3} ||
105*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 tcp connect 2 failed"
106*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} --addr ${c0} --addr ${c2} ${c0} ||
107*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 tcp connect 3 failed"
108*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} --addr ${c0} --addr ${c2} ${c2} ||
109*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 tcp connect 4 failed"
110*64130b0bSBill Sommerfeld
111*64130b0bSBill Sommerfeld	a="--addr llt_vnic1,${c1} --addr llt_vnic3,${c3}"
112*64130b0bSBill Sommerfeld	b="--addr llt_vnic0,${c0} --addr llt_vnic2,${c2}"
113*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${a} ${c1} ||
114*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 1 failed"
115*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${a} ${c3} ||
116*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 2 failed"
117*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${b} ${c0} ||
118*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 3 failed"
119*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${b} ${c2} ||
120*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 4 failed"
121*64130b0bSBill Sommerfeld
122*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${a} llt_vnic0,${c1} ||
123*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 1 failed"
124*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${a} llt_vnic2,${c3} ||
125*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 2 failed"
126*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${b} llt_vnic1,${c0} ||
127*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 3 failed"
128*64130b0bSBill Sommerfeld	${scriptdir}/dup_bind ${c} ${b} llt_vnic3,${c2} ||
129*64130b0bSBill Sommerfeld		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 4 failed"
130*64130b0bSBill Sommerfeld
131*64130b0bSBill Sommerfelddone
132*64130b0bSBill Sommerfeld
133*64130b0bSBill Sommerfeldif (( failures > 0 )); then
134*64130b0bSBill Sommerfeld	echo "${failures} failures detected."
135*64130b0bSBill Sommerfeld	exit 1
136*64130b0bSBill Sommerfeldfi
137*64130b0bSBill Sommerfeld
138*64130b0bSBill Sommerfeld
139*64130b0bSBill Sommerfeldecho "all tests passed"
140*64130b0bSBill Sommerfeldexit 0
141