xref: /illumos-gate/usr/src/test/net-tests/tests/ipv6/scope-test-v6.ksh (revision ff56787d6488797571f1eaba7dcf3ff9903154ba)
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 link local scopes, ensuring that traffic to
17# link-local addresses is properly separated by scope id.
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	IFID="$2"
73
74	ipadm create-if -t $VNIC
75
76	ipadm create-addr -T addrconf -i $IFID $VNIC/llt
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 ::2112:1/64
86init_if llt_vnic1 ::2112:2/64
87init_if llt_vnic2 ::2112:1/64
88init_if llt_vnic3 ::2112:2/64
89
90# wait for DAD to complete
91sleep 1
92ipadm show-addr
93
94a0=fe80::2112:1%llt_vnic0
95a1=fe80::2112:1%llt_vnic1
96a2=fe80::2112:1%llt_vnic2
97a3=fe80::2112:1%llt_vnic3
98
99b0=fe80::2112:2%llt_vnic0
100b1=fe80::2112:2%llt_vnic1
101b2=fe80::2112:2%llt_vnic2
102b3=fe80::2112:2%llt_vnic3
103
104# try with ifindex passed via IPV6_BOUND_IF instead of via sin6_scope_id
105c0=llt_vnic0,fe80::2112:1
106c1=llt_vnic1,fe80::2112:1
107c2=llt_vnic2,fe80::2112:1
108c3=llt_vnic3,fe80::2112:1
109
110
111ping -i llt_vnic0 -s ${b0} 56 1 ||
112	test_fail "FAIL: fe80::2112:2 unreachable through llt_vnic0"
113ping -i llt_vnic1 -s ${a1} 56 1 ||
114	test_fail "FAIL: fe80::2112:1 unreachable through llt_vnic1"
115ping -i llt_vnic2 -s ${b2} 56 1 ||
116	test_fail "FAIL: fe80::2112:2 unreachable through llt_vnic2"
117ping -i llt_vnic3 -s ${a3} 56 1 ||
118	test_fail "FAIL: fe80::2112:1 unreachable through llt_vnic3"
119
120for proto in udp tcp; do
121	c="--port 12345  --proto ${proto} --family 6"
122
123	${scriptdir}/dup_bind ${c} --addr ${a0} --addr ${a2} ${a1} ||
124		test_fail "FAIL: ${proto} connect 1 failed"
125	${scriptdir}/dup_bind ${c} --addr ${a0} --addr ${a2} ${a3} ||
126		test_fail "FAIL: ${proto} connect 2 failed"
127	${scriptdir}/dup_bind ${c} --addr ${b1} --addr ${b3} ${b0} ||
128		test_fail "FAIL: ${proto} connect 3 failed"
129	${scriptdir}/dup_bind ${c} --addr ${b1} --addr ${b3} ${b2} ||
130		test_fail "FAIL: ${proto} connect 4 failed"
131
132	${scriptdir}/dup_bind ${c} --addr ${c0} --addr ${c2} ${a1} ||
133		test_fail "FAIL: ${proto} connect 5 failed"
134	${scriptdir}/dup_bind ${c} --addr ${c0} --addr ${c2} ${a3} ||
135		test_fail "FAIL: ${proto} connect 6 failed"
136
137	${scriptdir}/dup_bind ${c} --addr ${a2} ${a1} &&
138		test_fail "FAIL: ${proto} neg 1 failed"
139	${scriptdir}/dup_bind ${c} --addr ${a0} ${a3} &&
140		test_fail "FAIL: ${proto} neg 2 failed"
141
142done
143
144if (( failures > 0 )); then
145	echo "${failures} failures detected."
146	exit 1
147fi
148
149echo "all tests passed"
150exit 0
151