xref: /freebsd/tests/sys/net/if_vlan.sh (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1# $FreeBSD$
2
3. $(atf_get_srcdir)/../common/vnet.subr
4
5atf_test_case "basic" "cleanup"
6basic_head()
7{
8	atf_set descr 'Basic VLAN test'
9	atf_set require.user root
10}
11
12basic_body()
13{
14	vnet_init
15
16	epair_vlan=$(vnet_mkepair)
17
18	vnet_mkjail alcatraz ${epair_vlan}a
19	vnet_mkjail singsing ${epair_vlan}b
20
21	vlan0=$(jexec alcatraz ifconfig vlan create vlandev ${epair_vlan}a \
22		vlan 42)
23	jexec alcatraz ifconfig ${epair_vlan}a up
24	jexec alcatraz ifconfig ${vlan0} 10.0.0.1/24 up
25
26	vlan1=$(jexec singsing ifconfig vlan create vlandev ${epair_vlan}b \
27		vlan 42)
28	jexec singsing ifconfig ${epair_vlan}b up
29	jexec singsing ifconfig ${vlan1} 10.0.0.2/24 up
30
31	atf_check -s exit:0 -o ignore jexec singsing ping -c 1 10.0.0.1
32}
33
34basic_cleanup()
35{
36	vnet_cleanup
37}
38
39# Simple Q-in-Q (802.1Q over 802.1ad)
40
41atf_test_case "qinq_simple" "cleanup"
42qinq_simple_head()
43{
44	atf_set descr 'Simple Q-in-Q test (802.1Q over 802.1ad)'
45	atf_set require.user root
46}
47
48qinq_simple_body()
49{
50	vnet_init
51
52	epair_qinq=$(vnet_mkepair)
53
54	vnet_mkjail jqinq0 ${epair_qinq}a
55	vnet_mkjail jqinq1 ${epair_qinq}b
56
57	vlan5a=$(jexec jqinq0 ifconfig vlan create \
58		vlandev ${epair_qinq}a vlan 5 vlanproto 802.1ad)
59	vlan42a=$(jexec jqinq0 ifconfig vlan create \
60		vlandev ${vlan5a} vlan 42 vlanproto 802.1q)
61	jexec jqinq0 ifconfig ${epair_qinq}a up
62	jexec jqinq0 ifconfig ${vlan5a} up
63	jexec jqinq0 ifconfig ${vlan42a} 10.5.42.1/24 up
64
65	vlan5b=$(jexec jqinq1 ifconfig vlan create \
66		vlandev ${epair_qinq}b vlan 5 vlanproto 802.1ad)
67	vlan42b=$(jexec jqinq1 ifconfig vlan create \
68		vlandev ${vlan5b} vlan 42 vlanproto 802.1q)
69	jexec jqinq1 ifconfig ${epair_qinq}b up
70	jexec jqinq1 ifconfig ${vlan5b} up
71	jexec jqinq1 ifconfig ${vlan42b} 10.5.42.2/24 up
72
73	atf_check -s exit:0 -o ignore jexec jqinq1 ping -c 1 10.5.42.1
74}
75
76qinq_simple_cleanup()
77{
78	vnet_cleanup
79}
80
81# Deep Q-in-Q (802.1Q over 802.1ad over 802.1ad)
82
83atf_test_case "qinq_deep" "cleanup"
84qinq_deep_head()
85{
86	atf_set descr 'Deep Q-in-Q test (802.1Q over 802.1ad over 802.1ad)'
87	atf_set require.user root
88}
89
90qinq_deep_body()
91{
92	vnet_init
93
94	epair_qinq=$(vnet_mkepair)
95
96	vnet_mkjail jqinq2 ${epair_qinq}a
97	vnet_mkjail jqinq3 ${epair_qinq}b
98
99	vlan5a=$(jexec jqinq2 ifconfig vlan create \
100		vlandev ${epair_qinq}a vlan 5 vlanproto 802.1ad)
101	vlan6a=$(jexec jqinq2 ifconfig vlan create \
102		vlandev ${vlan5a} vlan 6 vlanproto 802.1ad)
103	vlan42a=$(jexec jqinq2 ifconfig vlan create \
104		vlandev ${vlan6a} vlan 42 vlanproto 802.1q)
105	jexec jqinq2 ifconfig ${epair_qinq}a up
106	jexec jqinq2 ifconfig ${vlan5a} up
107	jexec jqinq2 ifconfig ${vlan6a} up
108	jexec jqinq2 ifconfig ${vlan42a} 10.6.42.1/24 up
109
110	vlan5b=$(jexec jqinq3 ifconfig vlan create \
111		vlandev ${epair_qinq}b vlan 5 vlanproto 802.1ad)
112	vlan6b=$(jexec jqinq3 ifconfig vlan create \
113		vlandev ${vlan5b} vlan 6 vlanproto 802.1ad)
114	vlan42b=$(jexec jqinq3 ifconfig vlan create \
115		vlandev ${vlan6b} vlan 42 vlanproto 802.1q)
116	jexec jqinq3 ifconfig ${epair_qinq}b up
117	jexec jqinq3 ifconfig ${vlan5b} up
118	jexec jqinq3 ifconfig ${vlan6b} up
119	jexec jqinq3 ifconfig ${vlan42b} 10.6.42.2/24 up
120
121	atf_check -s exit:0 -o ignore jexec jqinq3 ping -c 1 10.6.42.1
122}
123
124qinq_deep_cleanup()
125{
126	vnet_cleanup
127}
128
129# Legacy Q-in-Q (802.1Q over 802.1Q)
130
131atf_test_case "qinq_legacy" "cleanup"
132qinq_legacy_head()
133{
134	atf_set descr 'Legacy Q-in-Q test (802.1Q over 802.1Q)'
135	atf_set require.user root
136}
137
138qinq_legacy_body()
139{
140	vnet_init
141
142	epair_qinq=$(vnet_mkepair)
143
144	vnet_mkjail jqinq4 ${epair_qinq}a
145	vnet_mkjail jqinq5 ${epair_qinq}b
146
147	vlan5a=$(jexec jqinq4 ifconfig vlan create \
148		vlandev ${epair_qinq}a vlan 5)
149	vlan42a=$(jexec jqinq4 ifconfig vlan create \
150		vlandev ${vlan5a} vlan 42)
151	jexec jqinq4 ifconfig ${epair_qinq}a up
152	jexec jqinq4 ifconfig ${vlan5a} up
153	jexec jqinq4 ifconfig ${vlan42a} 10.5.42.1/24 up
154
155	vlan5b=$(jexec jqinq5 ifconfig vlan create \
156		vlandev ${epair_qinq}b vlan 5)
157	vlan42b=$(jexec jqinq5 ifconfig vlan create \
158		vlandev ${vlan5b} vlan 42)
159	jexec jqinq5 ifconfig ${epair_qinq}b up
160	jexec jqinq5 ifconfig ${vlan5b} up
161	jexec jqinq5 ifconfig ${vlan42b} 10.5.42.2/24 up
162
163	atf_check -s exit:0 -o ignore jexec jqinq5 ping -c 1 10.5.42.1
164}
165
166qinq_legacy_cleanup()
167{
168	vnet_cleanup
169}
170
171# Simple Q-in-Q with dot notation
172
173atf_test_case "qinq_dot" "cleanup"
174qinq_dot_head()
175{
176	atf_set descr 'Simple Q-in-Q test with dot notation'
177	atf_set require.user root
178}
179
180qinq_dot_body()
181{
182	vnet_init
183
184	epair_qinq=$(vnet_mkepair)
185
186	vnet_mkjail jqinq6 ${epair_qinq}a
187	vnet_mkjail jqinq7 ${epair_qinq}b
188
189	jexec jqinq6 ifconfig vlan5 create \
190		vlandev ${epair_qinq}a vlan 5 vlanproto 802.1ad
191	jexec jqinq6 ifconfig vlan5.42 create \
192		vlanproto 802.1q
193	jexec jqinq6 ifconfig ${epair_qinq}a up
194	jexec jqinq6 ifconfig vlan5 up
195	jexec jqinq6 ifconfig vlan5.42 10.5.42.1/24 up
196
197	vlan5b=$(jexec jqinq7 ifconfig vlan create \
198		vlandev ${epair_qinq}b vlan 5 vlanproto 802.1ad)
199	vlan42b=$(jexec jqinq7 ifconfig vlan create \
200		vlandev ${vlan5b} vlan 42 vlanproto 802.1q)
201	jexec jqinq7 ifconfig ${epair_qinq}b up
202	jexec jqinq7 ifconfig ${vlan5b} up
203	jexec jqinq7 ifconfig ${vlan42b} 10.5.42.2/24 up
204
205	atf_check -s exit:0 -o ignore jexec jqinq7 ping -c 1 10.5.42.1
206}
207
208qinq_dot_cleanup()
209{
210	vnet_cleanup
211}
212
213atf_test_case "bpf_pcp" "cleanup"
214bpf_pcp_head()
215{
216	atf_set descr 'Set VLAN PCP through BPF'
217	atf_set require.config 'allow_sysctl_side_effects'
218	atf_set require.user root
219	atf_set require.progs scapy
220}
221
222bpf_pcp_body()
223{
224	vnet_init
225
226	epair=$(vnet_mkepair)
227
228	ifconfig ${epair}a up
229
230	vnet_mkjail alcatraz ${epair}b
231	vlan=$(jexec alcatraz ifconfig vlan create)
232	jexec alcatraz ifconfig ${vlan} vlan 42 vlandev ${epair}b
233	jexec alcatraz ifconfig ${vlan} up
234	jexec alcatraz ifconfig ${epair}b up
235
236	sysctl net.link.vlan.mtag_pcp=1
237
238	jexec alcatraz dhclient ${vlan} &
239	atf_check -s exit:1 -o ignore -e ignore $(atf_get_srcdir)/pcp.py \
240		--expect-pcp 6 \
241		--recvif ${epair}a
242
243	jexec alcatraz killall dhclient
244	sleep 1
245
246	jexec alcatraz dhclient -c $(atf_get_srcdir)/dhclient_pcp.conf ${vlan} &
247	atf_check -s exit:0 -o ignore -e ignore $(atf_get_srcdir)/pcp.py \
248		--expect-pcp 6 \
249		--recvif ${epair}a
250}
251
252bpf_pcp_cleanup()
253{
254	sysctl net.link.vlan.mtag_pcp=0
255	jexec alcatraz killall dhclient
256	vnet_cleanup
257}
258
259atf_init_test_cases()
260{
261	atf_add_test_case "basic"
262	atf_add_test_case "qinq_simple"
263	atf_add_test_case "qinq_deep"
264	atf_add_test_case "qinq_legacy"
265	atf_add_test_case "qinq_dot"
266	atf_add_test_case "bpf_pcp"
267}
268