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