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