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