1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# +----------------------------+ 5# | H1 (vrf) | 6# | + $h1.10 | +----------------------+ 7# | | 192.0.2.1/28 | | H2 (vrf) | 8# | | 2001:db8:1::1/64 | | + $h2 | 9# | | | | | 192.0.2.130/28 | 10# | + $h1 | | | 2001:db8:2::2/64 | 11# +---|------------------------+ +--|-------------------+ 12# | | 13# +---|--------------------------------------------------|-------------------+ 14# | | router (main VRF) | | 15# | +-|----------------------------------+ + $swp2 | 16# | | + $swp1 BR1 (802.1q, pvid=10) | 192.0.2.129/28 | 17# | | 192.0.2.2/28 | 2001:db8:2::1/64 | 18# | | 2001:db8:1::2/64 | | 19# | +------------------------------------+ | 20# +--------------------------------------------------------------------------+ 21 22ALL_TESTS=" 23 ping_ipv4 24 ping_ipv6 25 shuffle_pvid 26 ping_ipv4 27 ping_ipv6 28" 29NUM_NETIFS=4 30source lib.sh 31 32h1_create() 33{ 34 simple_if_init $h1 35 vlan_create $h1 10 v$h1 192.0.2.1/28 2001:db8:1::1/64 36 ip -4 route add 192.0.2.128/28 vrf v$h1 nexthop via 192.0.2.2 37 ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2 38} 39 40h1_destroy() 41{ 42 ip -6 route del 2001:db8:2::/64 vrf v$h1 43 ip -4 route del 192.0.2.128/28 vrf v$h1 44 vlan_destroy $h1 10 45 simple_if_fini $h1 46} 47 48h2_create() 49{ 50 simple_if_init $h2 192.0.2.130/28 2001:db8:2::2/64 51 ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.129 52 ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::1 53} 54 55h2_destroy() 56{ 57 ip -6 route del 2001:db8:1::/64 vrf v$h2 58 ip -4 route del 192.0.2.0/28 vrf v$h2 59 simple_if_fini $h2 192.0.2.130/28 2001:db8:2::2/64 60} 61 62router_create() 63{ 64 ip link add name br1 address $(mac_get $swp1) \ 65 type bridge vlan_filtering 1 vlan_default_pvid 0 66 ip link set dev br1 up 67 __addr_add_del br1 add 192.0.2.2/28 2001:db8:1::2/64 68 69 ip link set dev $swp1 master br1 70 ip link set dev $swp1 up 71 72 ip link set dev $swp2 up 73 __addr_add_del $swp2 add 192.0.2.129/28 2001:db8:2::1/64 74 75 bridge vlan add dev br1 vid 10 pvid untagged self 76 bridge vlan add dev $swp1 vid 10 77} 78 79router_destroy() 80{ 81 bridge vlan del dev $swp1 vid 10 82 bridge vlan del dev br1 vid 10 self 83 84 __addr_add_del $swp2 del 192.0.2.129/28 2001:db8:2::1/64 85 ip link set dev $swp2 down 86 87 ip link set dev $swp1 down 88 ip link set dev $swp1 nomaster 89 90 __addr_add_del br1 del 192.0.2.2/28 2001:db8:1::2/64 91 ip link del dev br1 92} 93 94setup_prepare() 95{ 96 h1=${NETIFS[p1]} 97 swp1=${NETIFS[p2]} 98 99 swp2=${NETIFS[p3]} 100 h2=${NETIFS[p4]} 101 102 vrf_prepare 103 104 h1_create 105 h2_create 106 107 router_create 108 109 forwarding_enable 110} 111 112shuffle_pvid() 113{ 114 log_info "Add and remove VLAN upper for PVID VLAN" 115 116 # Adding and removing a VLAN upper for the PVID VLAN shouldn't change 117 # anything. The address is arbitrary, just to make sure it will be an L3 118 # netdevice. 119 vlan_create br1 10 "" 192.0.2.33/28 120 sleep 1 121 vlan_destroy br1 10 122} 123 124cleanup() 125{ 126 pre_cleanup 127 128 forwarding_restore 129 130 router_destroy 131 132 h2_destroy 133 h1_destroy 134 135 vrf_cleanup 136} 137 138ping_ipv4() 139{ 140 ping_test $h1 192.0.2.130 141} 142 143ping_ipv6() 144{ 145 ping6_test $h1 2001:db8:2::2 146} 147 148trap cleanup EXIT 149 150setup_prepare 151setup_wait 152 153tests_run 154 155exit $EXIT_STATUS 156