1 2. $(atf_get_srcdir)/../common/vnet.subr 3 4atf_test_case "basic" "cleanup" 5basic_head() 6{ 7 atf_set descr 'Basic VLAN test' 8 atf_set require.user root 9} 10 11basic_body() 12{ 13 vnet_init 14 15 epair_vlan=$(vnet_mkepair) 16 17 vnet_mkjail alcatraz ${epair_vlan}a 18 vnet_mkjail singsing ${epair_vlan}b 19 20 vlan0=$(jexec alcatraz ifconfig vlan create vlandev ${epair_vlan}a \ 21 vlan 42) 22 jexec alcatraz ifconfig ${epair_vlan}a up 23 jexec alcatraz ifconfig ${vlan0} 10.0.0.1/24 up 24 25 vlan1=$(jexec singsing ifconfig vlan create) 26 27 # Test associating the physical interface 28 atf_check -s exit:0 \ 29 jexec singsing ifconfig ${vlan1} vlandev ${epair_vlan}b vlan 42 30 31 jexec singsing ifconfig ${epair_vlan}b up 32 jexec singsing ifconfig ${vlan1} 10.0.0.2/24 up 33 34 atf_check -s exit:0 -o ignore jexec singsing ping -c 1 10.0.0.1 35 36 # Test changing the vlan ID 37 atf_check -s exit:0 \ 38 jexec singsing ifconfig ${vlan1} vlandev ${epair_vlan}b vlan 43 39 atf_check -s exit:2 -o ignore jexec singsing ping -c 1 10.0.0.1 40 41 # And change back 42 # Test changing the vlan ID 43 atf_check -s exit:0 \ 44 jexec singsing ifconfig ${vlan1} vlan 42 vlandev ${epair_vlan}b 45 atf_check -s exit:0 -o ignore jexec singsing ping -c 1 10.0.0.1 46} 47 48basic_cleanup() 49{ 50 vnet_cleanup 51} 52 53# Simple Q-in-Q (802.1Q over 802.1ad) 54 55atf_test_case "qinq_simple" "cleanup" 56qinq_simple_head() 57{ 58 atf_set descr 'Simple Q-in-Q test (802.1Q over 802.1ad)' 59 atf_set require.user root 60} 61 62qinq_simple_body() 63{ 64 vnet_init 65 66 epair_qinq=$(vnet_mkepair) 67 68 vnet_mkjail jqinq0 ${epair_qinq}a 69 vnet_mkjail jqinq1 ${epair_qinq}b 70 71 vlan5a=$(jexec jqinq0 ifconfig vlan create \ 72 vlandev ${epair_qinq}a vlan 5 vlanproto 802.1ad) 73 vlan42a=$(jexec jqinq0 ifconfig vlan create \ 74 vlandev ${vlan5a} vlan 42 vlanproto 802.1q) 75 jexec jqinq0 ifconfig ${epair_qinq}a up 76 jexec jqinq0 ifconfig ${vlan5a} up 77 jexec jqinq0 ifconfig ${vlan42a} 10.5.42.1/24 up 78 79 vlan5b=$(jexec jqinq1 ifconfig vlan create \ 80 vlandev ${epair_qinq}b vlan 5 vlanproto 802.1ad) 81 vlan42b=$(jexec jqinq1 ifconfig vlan create \ 82 vlandev ${vlan5b} vlan 42 vlanproto 802.1q) 83 jexec jqinq1 ifconfig ${epair_qinq}b up 84 jexec jqinq1 ifconfig ${vlan5b} up 85 jexec jqinq1 ifconfig ${vlan42b} 10.5.42.2/24 up 86 87 atf_check -s exit:0 -o ignore jexec jqinq1 ping -c 1 10.5.42.1 88} 89 90qinq_simple_cleanup() 91{ 92 vnet_cleanup 93} 94 95# Deep Q-in-Q (802.1Q over 802.1ad over 802.1ad) 96 97atf_test_case "qinq_deep" "cleanup" 98qinq_deep_head() 99{ 100 atf_set descr 'Deep Q-in-Q test (802.1Q over 802.1ad over 802.1ad)' 101 atf_set require.user root 102} 103 104qinq_deep_body() 105{ 106 vnet_init 107 108 epair_qinq=$(vnet_mkepair) 109 110 vnet_mkjail jqinq2 ${epair_qinq}a 111 vnet_mkjail jqinq3 ${epair_qinq}b 112 113 vlan5a=$(jexec jqinq2 ifconfig vlan create \ 114 vlandev ${epair_qinq}a vlan 5 vlanproto 802.1ad) 115 vlan6a=$(jexec jqinq2 ifconfig vlan create \ 116 vlandev ${vlan5a} vlan 6 vlanproto 802.1ad) 117 vlan42a=$(jexec jqinq2 ifconfig vlan create \ 118 vlandev ${vlan6a} vlan 42 vlanproto 802.1q) 119 jexec jqinq2 ifconfig ${epair_qinq}a up 120 jexec jqinq2 ifconfig ${vlan5a} up 121 jexec jqinq2 ifconfig ${vlan6a} up 122 jexec jqinq2 ifconfig ${vlan42a} 10.6.42.1/24 up 123 124 vlan5b=$(jexec jqinq3 ifconfig vlan create \ 125 vlandev ${epair_qinq}b vlan 5 vlanproto 802.1ad) 126 vlan6b=$(jexec jqinq3 ifconfig vlan create \ 127 vlandev ${vlan5b} vlan 6 vlanproto 802.1ad) 128 vlan42b=$(jexec jqinq3 ifconfig vlan create \ 129 vlandev ${vlan6b} vlan 42 vlanproto 802.1q) 130 jexec jqinq3 ifconfig ${epair_qinq}b up 131 jexec jqinq3 ifconfig ${vlan5b} up 132 jexec jqinq3 ifconfig ${vlan6b} up 133 jexec jqinq3 ifconfig ${vlan42b} 10.6.42.2/24 up 134 135 atf_check -s exit:0 -o ignore jexec jqinq3 ping -c 1 10.6.42.1 136} 137 138qinq_deep_cleanup() 139{ 140 vnet_cleanup 141} 142 143# Legacy Q-in-Q (802.1Q over 802.1Q) 144 145atf_test_case "qinq_legacy" "cleanup" 146qinq_legacy_head() 147{ 148 atf_set descr 'Legacy Q-in-Q test (802.1Q over 802.1Q)' 149 atf_set require.user root 150} 151 152qinq_legacy_body() 153{ 154 vnet_init 155 156 epair_qinq=$(vnet_mkepair) 157 158 vnet_mkjail jqinq4 ${epair_qinq}a 159 vnet_mkjail jqinq5 ${epair_qinq}b 160 161 vlan5a=$(jexec jqinq4 ifconfig vlan create \ 162 vlandev ${epair_qinq}a vlan 5) 163 vlan42a=$(jexec jqinq4 ifconfig vlan create \ 164 vlandev ${vlan5a} vlan 42) 165 jexec jqinq4 ifconfig ${epair_qinq}a up 166 jexec jqinq4 ifconfig ${vlan5a} up 167 jexec jqinq4 ifconfig ${vlan42a} 10.5.42.1/24 up 168 169 vlan5b=$(jexec jqinq5 ifconfig vlan create \ 170 vlandev ${epair_qinq}b vlan 5) 171 vlan42b=$(jexec jqinq5 ifconfig vlan create \ 172 vlandev ${vlan5b} vlan 42) 173 jexec jqinq5 ifconfig ${epair_qinq}b up 174 jexec jqinq5 ifconfig ${vlan5b} up 175 jexec jqinq5 ifconfig ${vlan42b} 10.5.42.2/24 up 176 177 atf_check -s exit:0 -o ignore jexec jqinq5 ping -c 1 10.5.42.1 178} 179 180qinq_legacy_cleanup() 181{ 182 vnet_cleanup 183} 184 185# Simple Q-in-Q with dot notation 186 187atf_test_case "qinq_dot" "cleanup" 188qinq_dot_head() 189{ 190 atf_set descr 'Simple Q-in-Q test with dot notation' 191 atf_set require.user root 192} 193 194qinq_dot_body() 195{ 196 vnet_init 197 198 epair_qinq=$(vnet_mkepair) 199 200 vnet_mkjail jqinq6 ${epair_qinq}a 201 vnet_mkjail jqinq7 ${epair_qinq}b 202 203 jexec jqinq6 ifconfig vlan5 create \ 204 vlandev ${epair_qinq}a vlan 5 vlanproto 802.1ad 205 jexec jqinq6 ifconfig vlan5.42 create \ 206 vlanproto 802.1q 207 jexec jqinq6 ifconfig ${epair_qinq}a up 208 jexec jqinq6 ifconfig vlan5 up 209 jexec jqinq6 ifconfig vlan5.42 10.5.42.1/24 up 210 211 vlan5b=$(jexec jqinq7 ifconfig vlan create \ 212 vlandev ${epair_qinq}b vlan 5 vlanproto 802.1ad) 213 vlan42b=$(jexec jqinq7 ifconfig vlan create \ 214 vlandev ${vlan5b} vlan 42 vlanproto 802.1q) 215 jexec jqinq7 ifconfig ${epair_qinq}b up 216 jexec jqinq7 ifconfig ${vlan5b} up 217 jexec jqinq7 ifconfig ${vlan42b} 10.5.42.2/24 up 218 219 atf_check -s exit:0 -o ignore jexec jqinq7 ping -c 1 10.5.42.1 220} 221 222qinq_dot_cleanup() 223{ 224 vnet_cleanup 225} 226 227atf_test_case "qinq_setflags" "cleanup" 228qinq_setflags_head() 229{ 230 atf_set descr 'Test setting flags on a QinQ device' 231 atf_set require.user root 232} 233 234qinq_setflags_body() 235{ 236 vnet_init 237 238 epair=$(vnet_mkepair) 239 240 ifconfig ${epair}a up 241 vlan1=$(ifconfig vlan create) 242 ifconfig $vlan1 vlan 1 vlandev ${epair}a 243 vlan2=$(ifconfig vlan create) 244 ifconfig $vlan2 vlan 2 vlandev $vlan1 245 246 # This panics, incorrect locking 247 ifconfig $vlan2 promisc 248} 249 250qinq_setflags_cleanup() 251{ 252 vnet_cleanup 253} 254 255atf_test_case "bpf_pcp" "cleanup" 256bpf_pcp_head() 257{ 258 atf_set descr 'Set VLAN PCP through BPF' 259 atf_set require.user root 260 atf_set require.progs scapy 261} 262 263bpf_pcp_body() 264{ 265 vnet_init 266 267 epair=$(vnet_mkepair) 268 269 ifconfig ${epair}a up 270 271 vnet_mkjail alcatraz ${epair}b 272 vlan=$(jexec alcatraz ifconfig vlan create) 273 jexec alcatraz ifconfig ${vlan} vlan 42 vlandev ${epair}b 274 jexec alcatraz ifconfig ${vlan} up 275 jexec alcatraz ifconfig ${epair}b up 276 277 jexec alcatraz sysctl net.link.vlan.mtag_pcp=1 278 279 jexec alcatraz dhclient ${vlan} & 280 atf_check -s exit:1 -o ignore -e ignore $(atf_get_srcdir)/pcp.py \ 281 --expect-pcp 6 \ 282 --recvif ${epair}a 283 284 jexec alcatraz killall dhclient 285 sleep 1 286 287 jexec alcatraz dhclient -c $(atf_get_srcdir)/dhclient_pcp.conf ${vlan} & 288 atf_check -s exit:0 -o ignore -e ignore $(atf_get_srcdir)/pcp.py \ 289 --expect-pcp 6 \ 290 --recvif ${epair}a 291} 292 293bpf_pcp_cleanup() 294{ 295 sysctl net.link.vlan.mtag_pcp=0 296 jexec alcatraz killall dhclient 297 vnet_cleanup 298} 299 300atf_test_case "conflict_id" "cleanup" 301conflict_id_head() 302{ 303 atf_set descr 'Test conflicting VLAN IDs, PR #279195' 304 atf_set require.user root 305} 306 307conflict_id_body() 308{ 309 vnet_init 310 311 epair=$(vnet_mkepair) 312 313 vnet_mkjail alcatraz ${epair}b 314 vlan_a=$(jexec alcatraz ifconfig vlan create) 315 vlan_b=$(jexec alcatraz ifconfig vlan create) 316 317 jexec alcatraz ifconfig ${vlan_a} vlan 100 vlandev ${epair}b 318 jexec alcatraz ifconfig ${vlan_b} vlan 101 vlandev ${epair}b 319 320 atf_check -s exit:1 -o ignore -e ignore \ 321 jexec alcatraz ifconfig ${vlan_a} vlan 101 322 323 atf_check -s exit:0 -o match:"vlan: 100" \ 324 jexec alcatraz ifconfig ${vlan_a} 325 326 atf_check -s exit:0 -o ignore -e ignore \ 327 jexec alcatraz ifconfig ${vlan_a} vlan 100 328} 329 330conflict_id_cleanup() 331{ 332 vnet_cleanup 333 334} 335 336atf_init_test_cases() 337{ 338 atf_add_test_case "basic" 339 atf_add_test_case "qinq_simple" 340 atf_add_test_case "qinq_deep" 341 atf_add_test_case "qinq_legacy" 342 atf_add_test_case "qinq_dot" 343 atf_add_test_case "qinq_setflags" 344 atf_add_test_case "bpf_pcp" 345 atf_add_test_case "conflict_id" 346} 347