1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
|
#
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2020 The FreeBSD Foundation
#
# This software was developed by Kristof Provost under sponsorship
# from the FreeBSD Foundation.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
. $(atf_get_srcdir)/../common/vnet.subr
atf_test_case "bridge_transmit_ipv4_unicast" "cleanup"
bridge_transmit_ipv4_unicast_head()
{
atf_set descr 'bridge_transmit_ipv4_unicast bridging test'
atf_set require.user root
}
bridge_transmit_ipv4_unicast_body()
{
vnet_init
vnet_init_bridge
epair_alcatraz=$(vnet_mkepair)
epair_singsing=$(vnet_mkepair)
vnet_mkjail alcatraz ${epair_alcatraz}b
vnet_mkjail singsing ${epair_singsing}b
jexec alcatraz ifconfig ${epair_alcatraz}b 192.0.2.1/24 up
jexec singsing ifconfig ${epair_singsing}b 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
ifconfig ${bridge} up
ifconfig ${epair_alcatraz}a up
ifconfig ${epair_singsing}a up
ifconfig ${bridge} addm ${epair_alcatraz}a
ifconfig ${bridge} addm ${epair_singsing}a
atf_check -s exit:0 -o ignore jexec alcatraz ping -c 3 -t 1 192.0.2.2
atf_check -s exit:0 -o ignore jexec singsing ping -c 3 -t 1 192.0.2.1
}
bridge_transmit_ipv4_unicast_cleanup()
{
vnet_cleanup
}
atf_test_case "stp" "cleanup"
stp_head()
{
atf_set descr 'Spanning tree test'
atf_set require.user root
}
stp_body()
{
vnet_init
vnet_init_bridge
epair_one=$(vnet_mkepair)
epair_two=$(vnet_mkepair)
bridge_a=$(vnet_mkbridge)
bridge_b=$(vnet_mkbridge)
vnet_mkjail a ${bridge_a} ${epair_one}a ${epair_two}a
vnet_mkjail b ${bridge_b} ${epair_one}b ${epair_two}b
jexec a ifconfig ${epair_one}a up
jexec a ifconfig ${epair_two}a up
jexec a ifconfig ${bridge_a} addm ${epair_one}a
jexec a ifconfig ${bridge_a} addm ${epair_two}a
jexec b ifconfig ${epair_one}b up
jexec b ifconfig ${epair_two}b up
jexec b ifconfig ${bridge_b} addm ${epair_one}b
jexec b ifconfig ${bridge_b} addm ${epair_two}b
jexec a ifconfig ${bridge_a} 192.0.2.1/24
# Enable spanning tree
jexec a ifconfig ${bridge_a} stp ${epair_one}a
jexec a ifconfig ${bridge_a} stp ${epair_two}a
jexec b ifconfig ${bridge_b} stp ${epair_one}b
jexec b ifconfig ${bridge_b} stp ${epair_two}b
jexec b ifconfig ${bridge_b} up
jexec a ifconfig ${bridge_a} up
# Give STP time to do its thing
sleep 5
a_discard=$(jexec a ifconfig ${bridge_a} | grep discarding)
b_discard=$(jexec b ifconfig ${bridge_b} | grep discarding)
if [ -z "${a_discard}" ] && [ -z "${b_discard}" ]
then
atf_fail "STP failed to detect bridging loop"
fi
# We must also have at least some forwarding interfaces
a_forwarding=$(jexec a ifconfig ${bridge_a} | grep forwarding)
b_forwarding=$(jexec b ifconfig ${bridge_b} | grep forwarding)
if [ -z "${a_forwarding}" ] && [ -z "${b_forwarding}" ]
then
atf_fail "STP failed to detect bridging loop"
fi
}
stp_cleanup()
{
vnet_cleanup
}
atf_test_case "stp_vlan" "cleanup"
stp_vlan_head()
{
atf_set descr 'Spanning tree on VLAN test'
atf_set require.user root
}
stp_vlan_body()
{
vnet_init
vnet_init_bridge
epair_one=$(vnet_mkepair)
epair_two=$(vnet_mkepair)
bridge_a=$(vnet_mkbridge)
bridge_b=$(vnet_mkbridge)
vnet_mkjail a ${bridge_a} ${epair_one}a ${epair_two}a
vnet_mkjail b ${bridge_b} ${epair_one}b ${epair_two}b
jexec a ifconfig ${epair_one}a up
jexec a ifconfig ${epair_two}a up
vlan_a_one=$(jexec a ifconfig vlan create vlandev ${epair_one}a vlan 42)
vlan_a_two=$(jexec a ifconfig vlan create vlandev ${epair_two}a vlan 42)
jexec a ifconfig ${vlan_a_one} up
jexec a ifconfig ${vlan_a_two} up
jexec a ifconfig ${bridge_a} addm ${vlan_a_one}
jexec a ifconfig ${bridge_a} addm ${vlan_a_two}
jexec b ifconfig ${epair_one}b up
jexec b ifconfig ${epair_two}b up
vlan_b_one=$(jexec b ifconfig vlan create vlandev ${epair_one}b vlan 42)
vlan_b_two=$(jexec b ifconfig vlan create vlandev ${epair_two}b vlan 42)
jexec b ifconfig ${vlan_b_one} up
jexec b ifconfig ${vlan_b_two} up
jexec b ifconfig ${bridge_b} addm ${vlan_b_one}
jexec b ifconfig ${bridge_b} addm ${vlan_b_two}
jexec a ifconfig ${bridge_a} 192.0.2.1/24
# Enable spanning tree
jexec a ifconfig ${bridge_a} stp ${vlan_a_one}
jexec a ifconfig ${bridge_a} stp ${vlan_a_two}
jexec b ifconfig ${bridge_b} stp ${vlan_b_one}
jexec b ifconfig ${bridge_b} stp ${vlan_b_two}
jexec b ifconfig ${bridge_b} up
jexec a ifconfig ${bridge_a} up
# Give STP time to do its thing
sleep 5
a_discard=$(jexec a ifconfig ${bridge_a} | grep discarding)
b_discard=$(jexec b ifconfig ${bridge_b} | grep discarding)
if [ -z "${a_discard}" ] && [ -z "${b_discard}" ]
then
atf_fail "STP failed to detect bridging loop"
fi
# We must also have at least some forwarding interfaces
a_forwarding=$(jexec a ifconfig ${bridge_a} | grep forwarding)
b_forwarding=$(jexec b ifconfig ${bridge_b} | grep forwarding)
if [ -z "${a_forwarding}" ] && [ -z "${b_forwarding}" ]
then
atf_fail "STP failed to detect bridging loop"
fi
}
stp_vlan_cleanup()
{
vnet_cleanup
}
atf_test_case "static" "cleanup"
static_head()
{
atf_set descr 'Bridge static address test'
atf_set require.user root
}
static_body()
{
vnet_init
vnet_init_bridge
epair=$(vnet_mkepair)
bridge=$(vnet_mkbridge)
vnet_mkjail one ${bridge} ${epair}a
ifconfig ${epair}b up
jexec one ifconfig ${bridge} up
jexec one ifconfig ${epair}a up
jexec one ifconfig ${bridge} addm ${epair}a
# Wrong interface
atf_check -s exit:1 -o ignore -e ignore \
jexec one ifconfig ${bridge} static ${epair}b 00:01:02:03:04:05
# Bad address format
atf_check -s exit:1 -o ignore -e ignore \
jexec one ifconfig ${bridge} static ${epair}a 00:01:02:03:04
# Correct add
atf_check -s exit:0 -o ignore \
jexec one ifconfig ${bridge} static ${epair}a 00:01:02:03:04:05
# List addresses
atf_check -s exit:0 \
-o match:"00:01:02:03:04:05 Vlan0 ${epair}a 0 flags=1<STATIC>" \
jexec one ifconfig ${bridge} addr
# Delete with bad address format
atf_check -s exit:1 -o ignore -e ignore \
jexec one ifconfig ${bridge} deladdr 00:01:02:03:04
# Delete with unlisted address
atf_check -s exit:1 -o ignore -e ignore \
jexec one ifconfig ${bridge} deladdr 00:01:02:03:04:06
# Correct delete
atf_check -s exit:0 -o ignore \
jexec one ifconfig ${bridge} deladdr 00:01:02:03:04:05
}
static_cleanup()
{
vnet_cleanup
}
atf_test_case "vstatic" "cleanup"
vstatic_head()
{
atf_set descr 'Bridge VLAN static address test'
atf_set require.user root
}
vstatic_body()
{
vnet_init
vnet_init_bridge
epair=$(vnet_mkepair)
bridge=$(vnet_mkbridge)
vnet_mkjail one ${bridge} ${epair}a
ifconfig ${epair}b up
jexec one ifconfig ${bridge} up
jexec one ifconfig ${epair}a up
jexec one ifconfig ${bridge} addm ${epair}a
# Wrong interface
atf_check -s exit:1 -o ignore -e ignore jexec one \
ifconfig ${bridge} static ${epair}b 00:01:02:03:04:05 vlan 10
# Bad address format
atf_check -s exit:1 -o ignore -e ignore jexec one \
ifconfig ${bridge} static ${epair}a 00:01:02:03:04 vlan 10
# Invalid VLAN ID
atf_check -s exit:1 -o ignore -e ignore jexec one \
ifconfig ${bridge} static ${epair}a 00:01:02:03:04:05 vlan 5000
# Correct add
atf_check -s exit:0 -o ignore jexec one \
ifconfig ${bridge} static ${epair}a 00:01:02:03:04:05 vlan 10
# List addresses
atf_check -s exit:0 \
-o match:"00:01:02:03:04:05 Vlan10 ${epair}a 0 flags=1<STATIC>" \
jexec one ifconfig ${bridge} addr
# Delete with bad address format
atf_check -s exit:1 -o ignore -e ignore jexec one \
ifconfig ${bridge} deladdr 00:01:02:03:04 vlan 10
# Delete with unlisted address
atf_check -s exit:1 -o ignore -e ignore jexec one \
ifconfig ${bridge} deladdr 00:01:02:03:04:06 vlan 10
# Delete with wrong vlan id
atf_check -s exit:1 -o ignore -e ignore jexec one \
ifconfig ${bridge} deladdr 00:01:02:03:04:05 vlan 20
# Correct delete
atf_check -s exit:0 -o ignore jexec one \
ifconfig ${bridge} deladdr 00:01:02:03:04:05 vlan 10
}
vstatic_cleanup()
{
vnet_cleanup
}
atf_test_case "span" "cleanup"
span_head()
{
atf_set descr 'Bridge span test'
atf_set require.user root
atf_set require.progs python3 scapy
}
span_body()
{
vnet_init
vnet_init_bridge
epair=$(vnet_mkepair)
epair_span=$(vnet_mkepair)
bridge=$(vnet_mkbridge)
vnet_mkjail one ${bridge} ${epair}a ${epair_span}a
ifconfig ${epair}b up
ifconfig ${epair_span}b up
jexec one ifconfig ${bridge} up
jexec one ifconfig ${epair}a up
jexec one ifconfig ${epair_span}a up
jexec one ifconfig ${bridge} addm ${epair}a
jexec one ifconfig ${bridge} span ${epair_span}a
jexec one ifconfig ${bridge} 192.0.2.1/24
# Send some traffic through the span
jexec one ping -c 1 -t 1 192.0.2.2
# Check that we see the traffic on the span interface
atf_check -s exit:0 \
$(atf_get_srcdir)/../netpfil/common/pft_ping.py \
--sendif ${epair}b \
--to 192.0.2.2 \
--recvif ${epair_span}b
jexec one ifconfig ${bridge} -span ${epair_span}a
# And no more traffic after we remove the span
atf_check -s exit:1 \
$(atf_get_srcdir)/../netpfil/common/pft_ping.py \
--sendif ${epair}b \
--to 192.0.2.2 \
--recvif ${epair_span}b
}
span_cleanup()
{
vnet_cleanup
}
atf_test_case "delete_with_members" "cleanup"
delete_with_members_head()
{
atf_set descr 'Delete a bridge which still has member interfaces'
atf_set require.user root
}
delete_with_members_body()
{
vnet_init
vnet_init_bridge
bridge=$(vnet_mkbridge)
epair=$(vnet_mkepair)
ifconfig ${bridge} 192.0.2.1/24 up
ifconfig ${epair}a up
ifconfig ${bridge} addm ${epair}a
ifconfig ${bridge} destroy
}
delete_with_members_cleanup()
{
vnet_cleanup
}
atf_test_case "mac_conflict" "cleanup"
mac_conflict_head()
{
atf_set descr 'Ensure that bridges in different jails get different mac addresses'
atf_set require.user root
}
mac_conflict_body()
{
vnet_init
vnet_init_bridge
epair=$(vnet_mkepair)
# Ensure the bridge module is loaded so jails can use it.
tmpbridge=$(vnet_mkbridge)
vnet_mkjail bridge_mac_conflict_one ${epair}a
vnet_mkjail bridge_mac_conflict_two ${epair}b
jexec bridge_mac_conflict_one ifconfig bridge create
jexec bridge_mac_conflict_one ifconfig bridge0 192.0.2.1/24 up \
addm ${epair}a
jexec bridge_mac_conflict_one ifconfig ${epair}a up
jexec bridge_mac_conflict_two ifconfig bridge create
jexec bridge_mac_conflict_two ifconfig bridge0 192.0.2.2/24 up \
addm ${epair}b
jexec bridge_mac_conflict_two ifconfig ${epair}b up
atf_check -s exit:0 -o ignore \
jexec bridge_mac_conflict_one ping -c 3 192.0.2.2
}
mac_conflict_cleanup()
{
vnet_cleanup
}
atf_test_case "inherit_mac" "cleanup"
inherit_mac_head()
{
atf_set descr 'Bridge inherit_mac test, #216510'
atf_set require.user root
}
inherit_mac_body()
{
vnet_init
vnet_init_bridge
bridge=$(vnet_mkbridge)
epair=$(vnet_mkepair)
vnet_mkjail one ${bridge} ${epair}a
jexec one sysctl net.link.bridge.inherit_mac=1
# Attempt to provoke the panic described in #216510
jexec one ifconfig ${bridge} 192.0.0.1/24 up
jexec one ifconfig ${bridge} addm ${epair}a
}
inherit_mac_cleanup()
{
vnet_cleanup
}
atf_test_case "stp_validation" "cleanup"
stp_validation_head()
{
atf_set descr 'Check STP validation'
atf_set require.user root
atf_set require.progs python3 scapy
}
stp_validation_body()
{
vnet_init
vnet_init_bridge
epair_one=$(vnet_mkepair)
epair_two=$(vnet_mkepair)
bridge=$(vnet_mkbridge)
ifconfig ${bridge} up
ifconfig ${bridge} addm ${epair_one}a addm ${epair_two}a
ifconfig ${bridge} stp ${epair_one}a stp ${epair_two}a
ifconfig ${epair_one}a up
ifconfig ${epair_one}b up
ifconfig ${epair_two}a up
ifconfig ${epair_two}b up
# Wait until the interfaces are no longer discarding
while ifconfig ${bridge} | grep 'state discarding' >/dev/null
do
sleep 1
done
# Now inject invalid STP BPDUs on epair_one and see if they're repeated
# on epair_two
atf_check -s exit:0 \
$(atf_get_srcdir)/stp.py \
--sendif ${epair_one}b \
--recvif ${epair_two}b
}
stp_validation_cleanup()
{
vnet_cleanup
}
atf_test_case "gif" "cleanup"
gif_head()
{
atf_set descr 'gif as a bridge member'
atf_set require.user root
}
gif_body()
{
vnet_init
vnet_init_bridge
epair=$(vnet_mkepair)
vnet_mkjail one ${epair}a
vnet_mkjail two ${epair}b
jexec one sysctl net.link.gif.max_nesting=2
jexec two sysctl net.link.gif.max_nesting=2
jexec one ifconfig ${epair}a 192.0.2.1/24 up
jexec two ifconfig ${epair}b 192.0.2.2/24 up
# Tunnel
gif_one=$(jexec one ifconfig gif create)
gif_two=$(jexec two ifconfig gif create)
jexec one ifconfig ${gif_one} tunnel 192.0.2.1 192.0.2.2
jexec one ifconfig ${gif_one} up
jexec two ifconfig ${gif_two} tunnel 192.0.2.2 192.0.2.1
jexec two ifconfig ${gif_two} up
bridge_one=$(jexec one ifconfig bridge create)
bridge_two=$(jexec two ifconfig bridge create)
jexec one ifconfig ${bridge_one} 198.51.100.1/24 up
jexec one ifconfig ${bridge_one} addm ${gif_one}
jexec two ifconfig ${bridge_two} 198.51.100.2/24 up
jexec two ifconfig ${bridge_two} addm ${gif_two}
# Sanity check
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 192.0.2.2
# Test tunnel
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 198.51.100.2
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 -s 1200 198.51.100.2
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 -s 2000 198.51.100.2
# Higher MTU on the tunnel than on the underlying interface
jexec one ifconfig ${epair}a mtu 1000
jexec two ifconfig ${epair}b mtu 1000
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 -s 1200 198.51.100.2
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 -s 2000 198.51.100.2
}
gif_cleanup()
{
vnet_cleanup
}
atf_test_case "mtu" "cleanup"
mtu_head()
{
atf_set descr 'Bridge MTU changes'
atf_set require.user root
}
get_mtu()
{
intf=$1
ifconfig ${intf} | awk '$5 == "mtu" { print $6 }'
}
check_mtu()
{
intf=$1
expected=$2
mtu=$(get_mtu $intf)
if [ "$mtu" -ne "$expected" ];
then
atf_fail "Expected MTU of $expected on $intf but found $mtu"
fi
}
mtu_body()
{
vnet_init
vnet_init_bridge
epair=$(vnet_mkepair)
gif=$(ifconfig gif create)
echo ${gif} >> created_interfaces.lst
bridge=$(vnet_mkbridge)
atf_check -s exit:0 \
ifconfig ${bridge} addm ${epair}a
ifconfig ${gif} mtu 1500
atf_check -s exit:0 \
ifconfig ${bridge} addm ${gif}
# Changing MTU changes it for all member interfaces
atf_check -s exit:0 \
ifconfig ${bridge} mtu 2000
check_mtu ${bridge} 2000
check_mtu ${gif} 2000
check_mtu ${epair}a 2000
# Rejected MTUs mean none of the MTUs change
atf_check -s exit:1 -e ignore \
ifconfig ${bridge} mtu 9000
check_mtu ${bridge} 2000
check_mtu ${gif} 2000
check_mtu ${epair}a 2000
# We're not allowed to change the MTU of a member interface
atf_check -s exit:1 -e ignore \
ifconfig ${epair}a mtu 1900
check_mtu ${epair}a 2000
# Test adding an interface with a different MTU
new_epair=$(vnet_mkepair)
check_mtu ${new_epair}a 1500
atf_check -s exit:0 -e ignore \
ifconfig ${bridge} addm ${new_epair}a
check_mtu ${bridge} 2000
check_mtu ${gif} 2000
check_mtu ${epair}a 2000
check_mtu ${new_epair}a 2000
}
mtu_cleanup()
{
vnet_cleanup
}
atf_test_case "vlan" "cleanup"
vlan_head()
{
atf_set descr 'Ensure the bridge takes vlan ID into account, PR#270559'
atf_set require.user root
}
vlan_body()
{
vnet_init
vnet_init_bridge
vid=1
epaira=$(vnet_mkepair)
epairb=$(vnet_mkepair)
br=$(vnet_mkbridge)
vnet_mkjail one ${epaira}b
vnet_mkjail two ${epairb}b
ifconfig ${br} up
ifconfig ${epaira}a up
ifconfig ${epairb}a up
ifconfig ${br} addm ${epaira}a addm ${epairb}a
jexec one ifconfig ${epaira}b up
jexec one ifconfig ${epaira}b.${vid} create
jexec two ifconfig ${epairb}b up
jexec two ifconfig ${epairb}b.${vid} create
# Create a MAC address conflict between an untagged and tagged interface
jexec two ifconfig ${epairb}b.${vid} ether 02:05:6e:06:28:1a
jexec one ifconfig ${epaira}b ether 02:05:6e:06:28:1a
jexec one ifconfig ${epaira}b.${vid} ether 02:05:6e:06:28:1b
# Add ip address, will also populate $br's fowarding table, by ARP announcement
jexec one ifconfig ${epaira}b.${vid} 192.0.2.1/24 up
jexec two ifconfig ${epairb}b.${vid} 192.0.2.2/24 up
sleep 0.5
ifconfig ${br}
jexec one ifconfig
jexec two ifconfig
ifconfig ${br} addr
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 -t 1 192.0.2.2
# This will trigger a mac flap (by ARP announcement)
jexec one ifconfig ${epaira}b 192.0.2.1/24 up
sleep 0.5
ifconfig ${br} addr
atf_check -s exit:0 -o ignore \
jexec one ping -c 1 -t 1 192.0.2.2
}
vlan_cleanup()
{
vnet_cleanup
}
atf_test_case "many_bridge_members" "cleanup"
many_bridge_members_head()
{
atf_set descr 'many_bridge_members ifconfig test'
atf_set require.user root
}
many_bridge_members_body()
{
vnet_init
vnet_init_bridge
bridge=$(vnet_mkbridge)
ifcount=256
for _ in $(seq 1 $ifcount); do
epair=$(vnet_mkepair)
ifconfig "${bridge}" addm "${epair}"a
done
atf_check -s exit:0 -o inline:"$ifcount\n" \
sh -c "ifconfig ${bridge} | grep member: | wc -l | xargs"
}
many_bridge_members_cleanup()
{
vnet_cleanup
}
atf_test_case "member_ifaddrs_enabled" "cleanup"
member_ifaddrs_enabled_head()
{
atf_set descr 'bridge with member_ifaddrs=1'
atf_set require.user root
}
member_ifaddrs_enabled_body()
{
vnet_init
vnet_init_bridge
ep=$(vnet_mkepair)
ifconfig ${ep}a inet 192.0.2.1/24 up
vnet_mkjail one ${ep}b
jexec one sysctl net.link.bridge.member_ifaddrs=1
jexec one ifconfig ${ep}b inet 192.0.2.2/24 up
jexec one ifconfig bridge0 create addm ${ep}b
atf_check -s exit:0 -o ignore ping -c3 -t1 192.0.2.2
}
member_ifaddrs_enabled_cleanup()
{
vnet_cleanup
}
atf_test_case "member_ifaddrs_disabled" "cleanup"
member_ifaddrs_disabled_head()
{
atf_set descr 'bridge with member_ifaddrs=0'
atf_set require.user root
}
member_ifaddrs_disabled_body()
{
vnet_init
vnet_init_bridge
vnet_mkjail one
jexec one sysctl net.link.bridge.member_ifaddrs=0
bridge=$(jexec one ifconfig bridge create)
# adding an interface with an IPv4 address
ep=$(jexec one ifconfig epair create)
jexec one ifconfig ${ep} 192.0.2.1/32
atf_check -s exit:1 -e ignore jexec one ifconfig ${bridge} addm ${ep}
# adding an interface with an IPv6 address
ep=$(jexec one ifconfig epair create)
jexec one ifconfig ${ep} inet6 2001:db8::1/128
atf_check -s exit:1 -e ignore jexec one ifconfig ${bridge} addm ${ep}
# adding an interface with an IPv6 link-local address
ep=$(jexec one ifconfig epair create)
jexec one ifconfig ${ep} inet6 -ifdisabled auto_linklocal up
atf_check -s exit:1 -e ignore jexec one ifconfig ${bridge} addm ${ep}
# adding an IPv4 address to a member
ep=$(jexec one ifconfig epair create)
jexec one ifconfig ${bridge} addm ${ep}
atf_check -s exit:1 -e ignore jexec one ifconfig ${ep} inet 192.0.2.2/32
# adding an IPv6 address to a member
ep=$(jexec one ifconfig epair create)
jexec one ifconfig ${bridge} addm ${ep}
atf_check -s exit:1 -e ignore jexec one ifconfig ${ep} inet6 2001:db8::1/128
}
member_ifaddrs_disabled_cleanup()
{
vnet_cleanup
}
#
# Test kern/287150: when member_ifaddrs=0, and a physical interface which is in
# a bridge also has a vlan(4) on it, tagged packets are not correctly passed to
# vlan(4).
atf_test_case "member_ifaddrs_vlan" "cleanup"
member_ifaddrs_vlan_head()
{
atf_set descr 'kern/287150: vlan and bridge on the same interface'
atf_set require.user root
}
member_ifaddrs_vlan_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
# The first jail has an epair with an IP address on vlan 20.
vnet_mkjail one ${epone}a
atf_check -s exit:0 jexec one ifconfig ${epone}a up
atf_check -s exit:0 jexec one \
ifconfig ${epone}a.20 create inet 192.0.2.1/24 up
# The second jail has an epair with an IP address on vlan 20,
# which is also in a bridge.
vnet_mkjail two ${epone}b
jexec two ifconfig
atf_check -s exit:0 -o save:bridge jexec two ifconfig bridge create
bridge=$(cat bridge)
atf_check -s exit:0 jexec two ifconfig ${bridge} addm ${epone}b up
atf_check -s exit:0 -o ignore jexec two \
sysctl net.link.bridge.member_ifaddrs=0
atf_check -s exit:0 jexec two ifconfig ${epone}b up
atf_check -s exit:0 jexec two \
ifconfig ${epone}b.20 create inet 192.0.2.2/24 up
# Make sure the two jails can communicate over the vlan.
atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
member_ifaddrs_vlan_cleanup()
{
vnet_cleanup
}
atf_test_case "vlan_pvid" "cleanup"
vlan_pvid_head()
{
atf_set descr 'bridge with two ports with pvid and vlanfilter set'
atf_set require.user root
}
vlan_pvid_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
vnet_mkjail one ${epone}b
vnet_mkjail two ${eptwo}b
jexec one ifconfig ${epone}b 192.0.2.1/24 up
jexec two ifconfig ${eptwo}b 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
ifconfig ${bridge} vlanfilter up
ifconfig ${epone}a up
ifconfig ${eptwo}a up
ifconfig ${bridge} addm ${epone}a untagged 20
ifconfig ${bridge} addm ${eptwo}a untagged 20
# With VLAN filtering enabled, traffic should be passed.
atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
# Removed the untagged VLAN on one port; traffic should not be passed.
ifconfig ${bridge} -ifuntagged ${epone}a
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
vlan_pvid_cleanup()
{
vnet_cleanup
}
atf_test_case "vlan_pvid_filtered" "cleanup"
vlan_pvid_filtered_head()
{
atf_set descr 'bridge with two ports with different pvids'
atf_set require.user root
}
vlan_pvid_filtered_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
vnet_mkjail one ${epone}b
vnet_mkjail two ${eptwo}b
atf_check -s exit:0 jexec one ifconfig ${epone}b 192.0.2.1/24 up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge} vlanfilter up
atf_check -s exit:0 ifconfig ${epone}a up
atf_check -s exit:0 ifconfig ${eptwo}a up
atf_check -s exit:0 ifconfig ${bridge} addm ${epone}a untagged 20
atf_check -s exit:0 ifconfig ${bridge} addm ${eptwo}a untagged 30
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
vlan_pvid_filtered_cleanup()
{
vnet_cleanup
}
atf_test_case "vlan_pvid_tagged" "cleanup"
vlan_pvid_tagged_head()
{
atf_set descr 'bridge pvid with tagged frames for pvid'
atf_set require.user root
}
vlan_pvid_tagged_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
vnet_mkjail one ${epone}b
vnet_mkjail two ${eptwo}b
# Create two tagged interfaces on the appropriate VLANs
atf_check -s exit:0 jexec one ifconfig ${epone}b up
atf_check -s exit:0 jexec one ifconfig ${epone}b.20 \
create 192.0.2.1/24 up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b.20 \
create 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge} vlanfilter up
atf_check -s exit:0 ifconfig ${epone}a up
atf_check -s exit:0 ifconfig ${eptwo}a up
atf_check -s exit:0 ifconfig ${bridge} addm ${epone}a untagged 20
atf_check -s exit:0 ifconfig ${bridge} addm ${eptwo}a untagged 20
# Tagged frames should not be passed.
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
vlan_pvid_tagged_cleanup()
{
vnet_cleanup
}
atf_test_case "vlan_pvid_1q" "cleanup"
vlan_pvid_1q_head()
{
atf_set descr '802.1q tag addition and removal'
atf_set require.user root
}
vlan_pvid_1q_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
vnet_mkjail one ${epone}b
vnet_mkjail two ${eptwo}b
# Set up one jail with an access port, and the other with a trunk port.
# This forces the bridge to add and remove .1q tags to bridge the
# traffic.
atf_check -s exit:0 jexec one ifconfig ${epone}b 192.0.2.1/24 up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b.20 create 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge} vlanfilter up
atf_check -s exit:0 ifconfig ${bridge} addm ${epone}a untagged 20
atf_check -s exit:0 ifconfig ${bridge} addm ${eptwo}a tagged 20
atf_check -s exit:0 ifconfig ${epone}a up
atf_check -s exit:0 ifconfig ${eptwo}a up
atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
vlan_pvid_1q_cleanup()
{
vnet_cleanup
}
#
# Test vlan filtering.
#
atf_test_case "vlan_filtering" "cleanup"
vlan_filtering_head()
{
atf_set descr 'tagged traffic with filtering'
atf_set require.user root
}
vlan_filtering_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
vnet_mkjail one ${epone}b
vnet_mkjail two ${eptwo}b
atf_check -s exit:0 jexec one ifconfig ${epone}b up
atf_check -s exit:0 jexec one ifconfig ${epone}b.20 \
create 192.0.2.1/24 up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b.20 \
create 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge} vlanfilter up
atf_check -s exit:0 ifconfig ${epone}a up
atf_check -s exit:0 ifconfig ${eptwo}a up
atf_check -s exit:0 ifconfig ${bridge} addm ${epone}a
atf_check -s exit:0 ifconfig ${bridge} addm ${eptwo}a
# Right now there are no VLANs on the access list, so everything
# should be blocked.
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
# Set the untagged vlan on both ports to 20 and make sure traffic is
# still blocked. We intentionally do not pass tagged traffic for the
# untagged vlan.
atf_check -s exit:0 ifconfig ${bridge} ifuntagged ${epone}a 20
atf_check -s exit:0 ifconfig ${bridge} ifuntagged ${eptwo}a 20
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
atf_check -s exit:0 ifconfig ${bridge} -ifuntagged ${epone}a
atf_check -s exit:0 ifconfig ${bridge} -ifuntagged ${eptwo}a
# Add VLANs 10-30 to the access list; now access should be allowed.
atf_check -s exit:0 ifconfig ${bridge} +iftagged ${epone}a 10-30
atf_check -s exit:0 ifconfig ${bridge} +iftagged ${eptwo}a 10-30
atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
# Remove vlan 20 from the access list, now access should be blocked
# again.
atf_check -s exit:0 ifconfig ${bridge} -iftagged ${epone}a 20
atf_check -s exit:0 ifconfig ${bridge} -iftagged ${eptwo}a 20
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
vlan_filtering_cleanup()
{
vnet_cleanup
}
#
# Test the ifconfig 'iftagged' option.
#
atf_test_case "vlan_ifconfig_iftagged" "cleanup"
vlan_ifconfig_iftagged_head()
{
atf_set descr 'test the ifconfig iftagged option'
atf_set require.user root
}
vlan_ifconfig_iftagged_body()
{
vnet_init
vnet_init_bridge
ep=$(vnet_mkepair)
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge} vlanfilter up
atf_check -s exit:0 ifconfig ${bridge} addm ${ep}a
atf_check -s exit:0 ifconfig ${ep}a up
# To start with, no vlans should be configured.
atf_check -s exit:0 -o not-match:"tagged" ifconfig ${bridge}
# Add vlans 100-149.
atf_check -s exit:0 ifconfig ${bridge} iftagged ${ep}a 100-149
atf_check -s exit:0 -o match:"tagged 100-149" ifconfig ${bridge}
# Replace the vlan list with 139-199.
atf_check -s exit:0 ifconfig ${bridge} iftagged ${ep}a 139-199
atf_check -s exit:0 -o match:"tagged 139-199" ifconfig ${bridge}
# Add vlans 100-170.
atf_check -s exit:0 ifconfig ${bridge} +iftagged ${ep}a 100-170
atf_check -s exit:0 -o match:"tagged 100-199" ifconfig ${bridge}
# Remove vlans 104, 105, and 150-159
atf_check -s exit:0 ifconfig ${bridge} -iftagged ${ep}a 104,105,150-159
atf_check -s exit:0 -o match:"tagged 100-103,106-149,160-199" \
ifconfig ${bridge}
# Remove the entire vlan list.
atf_check -s exit:0 ifconfig ${bridge} iftagged ${ep}a none
atf_check -s exit:0 -o not-match:"tagged" ifconfig ${bridge}
# Test some invalid vlans sets.
for bad_vlan in -1 0 4096 4097 foo 0-10 4000-5000 foo-40 40-foo; do
atf_check -s exit:1 -e ignore \
ifconfig ${bridge} iftagged "$bad_vlan"
done
}
vlan_ifconfig_iftagged_cleanup()
{
vnet_cleanup
}
#
# Test a vlan(4) "SVI" interface on top of a bridge.
#
atf_test_case "vlan_svi" "cleanup"
vlan_svi_head()
{
atf_set descr 'vlan bridge with an SVI'
atf_set require.user root
}
vlan_svi_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
vnet_mkjail one ${epone}b
atf_check -s exit:0 jexec one ifconfig ${epone}b up
atf_check -s exit:0 jexec one ifconfig ${epone}b.20 \
create 192.0.2.1/24 up
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge} vlanfilter up
atf_check -s exit:0 ifconfig ${epone}a up
atf_check -s exit:0 ifconfig ${bridge} addm ${epone}a tagged 20
svi=$(vnet_mkvlan)
atf_check -s exit:0 ifconfig ${svi} vlan 20 vlandev ${bridge}
atf_check -s exit:0 ifconfig ${svi} inet 192.0.2.2/24 up
atf_check -s exit:0 -o ignore ping -c 3 -t 1 192.0.2.1
}
vlan_svi_cleanup()
{
vnet_cleanup
}
#
# Test QinQ (802.1ad).
#
atf_test_case "vlan_qinq" "cleanup"
vlan_qinq_head()
{
atf_set descr 'vlan filtering with QinQ traffic'
atf_set require.user root
}
vlan_qinq_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
vnet_mkjail one ${epone}b
vnet_mkjail two ${eptwo}b
# Create a QinQ trunk between the two jails. The outer (provider) tag
# is 5, and the inner tag is 10.
atf_check -s exit:0 jexec one ifconfig ${epone}b up
atf_check -s exit:0 jexec one \
ifconfig ${epone}b.5 create vlanproto 802.1ad up
atf_check -s exit:0 jexec one \
ifconfig ${epone}b.5.10 create inet 192.0.2.1/24 up
atf_check -s exit:0 jexec two ifconfig ${eptwo}b up
atf_check -s exit:0 jexec two ifconfig \
${eptwo}b.5 create vlanproto 802.1ad up
atf_check -s exit:0 jexec two ifconfig \
${eptwo}b.5.10 create inet 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge} vlanfilter defqinq up
atf_check -s exit:0 ifconfig ${epone}a up
atf_check -s exit:0 ifconfig ${eptwo}a up
atf_check -s exit:0 ifconfig ${bridge} addm ${epone}a
atf_check -s exit:0 ifconfig ${bridge} addm ${eptwo}a
# Right now there are no VLANs on the access list, so everything
# should be blocked.
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
# Add the provider tag to the access list; now traffic should be passed.
atf_check -s exit:0 ifconfig ${bridge} +iftagged ${epone}a 5
atf_check -s exit:0 ifconfig ${bridge} +iftagged ${eptwo}a 5
atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
# Remove the qinq flag from one of the interfaces; traffic should
# be blocked again.
atf_check -s exit:0 ifconfig ${bridge} -qinq ${epone}a
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
vlan_qinq_cleanup()
{
vnet_cleanup
}
# Adding a bridge SVI to a bridge should not be allowed.
atf_test_case "bridge_svi_in_bridge" "cleanup"
bridge_svi_in_bridge_head()
{
atf_set descr 'adding a bridge SVI to a bridge is not allowed (1)'
atf_set require.user root
}
bridge_svi_in_bridge_body()
{
vnet_init
vnet_init_bridge
bridge=$(vnet_mkbridge)
atf_check -s exit:0 ifconfig ${bridge}.1 create
atf_check -s exit:1 -e ignore ifconfig ${bridge} addm ${bridge}.1
}
bridge_svi_in_bridge_cleanup()
{
vnet_cleanup
}
atf_test_case "vlan_untagged" "cleanup"
vlan_untagged_head()
{
atf_set descr 'bridge with two ports with untagged set'
atf_set require.user root
}
vlan_untagged_body()
{
vnet_init
vnet_init_bridge
epone=$(vnet_mkepair)
eptwo=$(vnet_mkepair)
vnet_mkjail one ${epone}b
vnet_mkjail two ${eptwo}b
jexec one ifconfig ${epone}b 192.0.2.1/24 up
jexec two ifconfig ${eptwo}b 192.0.2.2/24 up
bridge=$(vnet_mkbridge)
ifconfig ${bridge} up
ifconfig ${epone}a up
ifconfig ${eptwo}a up
ifconfig ${bridge} addm ${epone}a untagged 20
ifconfig ${bridge} addm ${eptwo}a untagged 30
# With two ports on different VLANs, traffic should not be passed.
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
# Move the second port to VLAN 20; now traffic should be passed.
atf_check -s exit:0 ifconfig ${bridge} ifuntagged ${eptwo}a 20
atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
# Remove the first's port untagged config, now traffic should
# not pass again.
atf_check -s exit:0 ifconfig ${bridge} -ifuntagged ${epone}a
atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
}
vlan_untagged_cleanup()
{
vnet_cleanup
}
atf_test_case "vlan_defuntagged" "cleanup"
vlan_defuntagged_head()
{
atf_set descr 'defuntagged (defpvid) bridge option'
atf_set require.user root
}
vlan_defuntagged_body()
{
vnet_init
vnet_init_bridge
bridge=$(vnet_mkbridge)
# Invalid VLAN IDs
atf_check -s exit:1 -ematch:"invalid vlan id: 0" \
ifconfig ${bridge} defuntagged 0
atf_check -s exit:1 -ematch:"invalid vlan id: 4095" \
ifconfig ${bridge} defuntagged 4095
atf_check -s exit:1 -ematch:"invalid vlan id: 5000" \
ifconfig ${bridge} defuntagged 5000
# Check the bridge option is set and cleared correctly
atf_check -s exit:0 -onot-match:"defuntagged=" \
ifconfig ${bridge}
atf_check -s exit:0 ifconfig ${bridge} defuntagged 10
atf_check -s exit:0 -omatch:"defuntagged=10$" \
ifconfig ${bridge}
atf_check -s exit:0 ifconfig ${bridge} -defuntagged
atf_check -s exit:0 -onot-match:"defuntagged=" \
ifconfig ${bridge}
# Check the untagged option is correctly set on a member
atf_check -s exit:0 ifconfig ${bridge} defuntagged 10
epair=$(vnet_mkepair)
atf_check -s exit:0 ifconfig ${bridge} addm ${epair}a
tag=$(ifconfig ${bridge} | sed -Ene \
"/member: ${epair}a/ { N;s/.*untagged ([0-9]+).*/\\1/p;q; }")
if [ "$tag" != "10" ]; then
atf_fail "wrong untagged vlan: ${tag}"
fi
}
vlan_defuntagged_cleanup()
{
vnet_cleanup
}
atf_init_test_cases()
{
atf_add_test_case "bridge_transmit_ipv4_unicast"
atf_add_test_case "stp"
atf_add_test_case "stp_vlan"
atf_add_test_case "static"
atf_add_test_case "vstatic"
atf_add_test_case "span"
atf_add_test_case "inherit_mac"
atf_add_test_case "delete_with_members"
atf_add_test_case "mac_conflict"
atf_add_test_case "stp_validation"
atf_add_test_case "gif"
atf_add_test_case "mtu"
atf_add_test_case "vlan"
atf_add_test_case "many_bridge_members"
atf_add_test_case "member_ifaddrs_enabled"
atf_add_test_case "member_ifaddrs_disabled"
atf_add_test_case "member_ifaddrs_vlan"
atf_add_test_case "vlan_pvid"
atf_add_test_case "vlan_pvid_1q"
atf_add_test_case "vlan_pvid_filtered"
atf_add_test_case "vlan_pvid_tagged"
atf_add_test_case "vlan_filtering"
atf_add_test_case "vlan_ifconfig_iftagged"
atf_add_test_case "vlan_svi"
atf_add_test_case "vlan_qinq"
atf_add_test_case "vlan_untagged"
atf_add_test_case "vlan_defuntagged"
atf_add_test_case "bridge_svi_in_bridge"
}
|