xref: /illumos-gate/usr/src/test/net-tests/tests/ipv6/scope-test-v4.ksh (revision 80b758da23abee3ef0e550f533aada9ce3b1b01f)
1#!/usr/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# Copyright 2024 Bill Sommerfeld
14#
15
16# This tests behavior around IP_BOUND_IF for ipv4 sockets as a check that
17# other v6-focused work hasn't cause a regression.
18
19# It does this with multiple vnics on multiple simnets created for this
20# test.   No special system configuration is required.
21
22typeset -a simnets=()
23typeset -a vnics=()
24
25typeset -i failures=0
26
27scriptdir=$(dirname -- "$0")
28
29function fatal {
30	print "$*" >&2
31	exit 1
32}
33
34function test_fail {
35	print "$*" >&2
36	(( failures++ ))
37}
38
39function cleanup {
40	{
41		for vnic in ${vnics[@]}; do
42			ipadm delete-if ${vnic}
43			dladm delete-vnic "$vnic"
44		done
45
46		for simnet in ${simnets[@]}; do
47			dladm delete-simnet "$simnet"
48		done
49	} > /dev/null 2>&1
50}
51
52trap cleanup EXIT
53
54function create_simnet {
55
56	SIMNET="$1"
57	simnets+=($SIMNET)
58	dladm create-simnet -t "$SIMNET"
59	shift
60	while (( $# > 0 )); do
61		IF="$1"
62		vnics+=($IF)
63		dladm create-vnic -t -l "$SIMNET" "$IF"
64		shift
65        done
66	echo $simnets
67	echo $vnics
68}
69
70function init_if {
71	VNIC="$1"
72	V4ADDR="$2"
73
74	ipadm create-if -t $VNIC
75
76	ipadm create-addr -T static -a local=$V4ADDR $VNIC/llt4
77}
78
79create_simnet llt_simnet0 llt_vnic0 llt_vnic1
80create_simnet llt_simnet1 llt_vnic2 llt_vnic3
81
82# RFC2544 assigns 198.18.0.0/15 for "benchmarking"; use in a unit test
83# would be consistent with that assignment.
84
85init_if llt_vnic0 198.18.1.1/25
86init_if llt_vnic1 198.18.1.2/25
87init_if llt_vnic2 198.18.2.1/25
88init_if llt_vnic3 198.18.2.2/25
89
90ipadm show-addr
91
92c0=198.18.1.1
93c1=198.18.1.2
94c2=198.18.2.1
95c3=198.18.2.2
96
97# regression testing for IP_BOUND_IF
98
99for proto in udp tcp; do
100	c="--port 12345  --proto ${proto} --family 4 "
101
102	${scriptdir}/dup_bind ${c} --addr ${c1} --addr ${c3} ${c1} ||
103		test_fail "FAIL: v4 tcp connect 1 failed"
104	${scriptdir}/dup_bind ${c} --addr ${c1} --addr ${c3} ${c3} ||
105		test_fail "FAIL: v4 tcp connect 2 failed"
106	${scriptdir}/dup_bind ${c} --addr ${c0} --addr ${c2} ${c0} ||
107		test_fail "FAIL: v4 tcp connect 3 failed"
108	${scriptdir}/dup_bind ${c} --addr ${c0} --addr ${c2} ${c2} ||
109		test_fail "FAIL: v4 tcp connect 4 failed"
110
111	a="--addr llt_vnic1,${c1} --addr llt_vnic3,${c3}"
112	b="--addr llt_vnic0,${c0} --addr llt_vnic2,${c2}"
113	${scriptdir}/dup_bind ${c} ${a} ${c1} ||
114		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 1 failed"
115	${scriptdir}/dup_bind ${c} ${a} ${c3} ||
116		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 2 failed"
117	${scriptdir}/dup_bind ${c} ${b} ${c0} ||
118		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 3 failed"
119	${scriptdir}/dup_bind ${c} ${b} ${c2} ||
120		test_fail "FAIL: v4 IP_BOUND_IF tcp connect 4 failed"
121
122	${scriptdir}/dup_bind ${c} ${a} llt_vnic0,${c1} ||
123		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 1 failed"
124	${scriptdir}/dup_bind ${c} ${a} llt_vnic2,${c3} ||
125		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 2 failed"
126	${scriptdir}/dup_bind ${c} ${b} llt_vnic1,${c0} ||
127		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 3 failed"
128	${scriptdir}/dup_bind ${c} ${b} llt_vnic3,${c2} ||
129		test_fail "FAIL: v4 2xIP_BOUND_IF tcp connect 4 failed"
130
131done
132
133if (( failures > 0 )); then
134	echo "${failures} failures detected."
135	exit 1
136fi
137
138
139echo "all tests passed"
140exit 0
141