Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 ALL_TESTS="standalone two_bridges one_bridge_two_pvids"
0005 NUM_NETIFS=4
0006 
0007 source lib.sh
0008 
0009 h1=${NETIFS[p1]}
0010 h2=${NETIFS[p3]}
0011 swp1=${NETIFS[p2]}
0012 swp2=${NETIFS[p4]}
0013 
0014 H1_IPV4="192.0.2.1"
0015 H2_IPV4="192.0.2.2"
0016 H1_IPV6="2001:db8:1::1"
0017 H2_IPV6="2001:db8:1::2"
0018 
0019 IPV4_ALLNODES="224.0.0.1"
0020 IPV6_ALLNODES="ff02::1"
0021 MACV4_ALLNODES="01:00:5e:00:00:01"
0022 MACV6_ALLNODES="33:33:00:00:00:01"
0023 NON_IP_MC="01:02:03:04:05:06"
0024 NON_IP_PKT="00:04 48:45:4c:4f"
0025 BC="ff:ff:ff:ff:ff:ff"
0026 
0027 # The full 4K VLAN space is too much to check, so strategically pick some
0028 # values which should provide reasonable coverage
0029 vids=(0 1 2 5 10 20 50 100 200 500 1000 1000 2000 4000 4094)
0030 
0031 send_non_ip()
0032 {
0033         local if_name=$1
0034         local smac=$2
0035         local dmac=$3
0036 
0037         $MZ -q $if_name "$dmac $smac $NON_IP_PKT"
0038 }
0039 
0040 send_uc_ipv4()
0041 {
0042         local if_name=$1
0043         local dmac=$2
0044 
0045         ip neigh add $H2_IPV4 lladdr $dmac dev $if_name
0046         ping_do $if_name $H2_IPV4
0047         ip neigh del $H2_IPV4 dev $if_name
0048 }
0049 
0050 send_mc_ipv4()
0051 {
0052         local if_name=$1
0053 
0054         ping_do $if_name $IPV4_ALLNODES "-I $if_name"
0055 }
0056 
0057 send_uc_ipv6()
0058 {
0059         local if_name=$1
0060         local dmac=$2
0061 
0062         ip -6 neigh add $H2_IPV6 lladdr $dmac dev $if_name
0063         ping6_do $if_name $H2_IPV6
0064         ip -6 neigh del $H2_IPV6 dev $if_name
0065 }
0066 
0067 send_mc_ipv6()
0068 {
0069         local if_name=$1
0070 
0071         ping6_do $if_name $IPV6_ALLNODES%$if_name
0072 }
0073 
0074 check_rcv()
0075 {
0076         local if_name=$1
0077         local type=$2
0078         local pattern=$3
0079         local should_fail=1
0080 
0081         RET=0
0082 
0083         tcpdump_show $if_name | grep -q "$pattern"
0084 
0085         check_err_fail "$should_fail" "$?" "reception"
0086 
0087         log_test "$type"
0088 }
0089 
0090 run_test()
0091 {
0092         local test_name="$1"
0093         local smac=$(mac_get $h1)
0094         local dmac=$(mac_get $h2)
0095         local h1_ipv6_lladdr=$(ipv6_lladdr_get $h1)
0096         local vid=
0097 
0098         echo "$test_name: Sending packets"
0099 
0100         tcpdump_start $h2
0101 
0102         send_non_ip $h1 $smac $dmac
0103         send_non_ip $h1 $smac $NON_IP_MC
0104         send_non_ip $h1 $smac $BC
0105         send_uc_ipv4 $h1 $dmac
0106         send_mc_ipv4 $h1
0107         send_uc_ipv6 $h1 $dmac
0108         send_mc_ipv6 $h1
0109 
0110         for vid in "${vids[@]}"; do
0111                 vlan_create $h1 $vid
0112                 simple_if_init $h1.$vid $H1_IPV4/24 $H1_IPV6/64
0113 
0114                 send_non_ip $h1.$vid $smac $dmac
0115                 send_non_ip $h1.$vid $smac $NON_IP_MC
0116                 send_non_ip $h1.$vid $smac $BC
0117                 send_uc_ipv4 $h1.$vid $dmac
0118                 send_mc_ipv4 $h1.$vid
0119                 send_uc_ipv6 $h1.$vid $dmac
0120                 send_mc_ipv6 $h1.$vid
0121 
0122                 simple_if_fini $h1.$vid $H1_IPV4/24 $H1_IPV6/64
0123                 vlan_destroy $h1 $vid
0124         done
0125 
0126         sleep 1
0127 
0128         echo "$test_name: Checking which packets were received"
0129 
0130         tcpdump_stop $h2
0131 
0132         check_rcv $h2 "$test_name: Unicast non-IP untagged" \
0133                 "$smac > $dmac, 802.3, length 4:"
0134 
0135         check_rcv $h2 "$test_name: Multicast non-IP untagged" \
0136                 "$smac > $NON_IP_MC, 802.3, length 4:"
0137 
0138         check_rcv $h2 "$test_name: Broadcast non-IP untagged" \
0139                 "$smac > $BC, 802.3, length 4:"
0140 
0141         check_rcv $h2 "$test_name: Unicast IPv4 untagged" \
0142                 "$smac > $dmac, ethertype IPv4 (0x0800)"
0143 
0144         check_rcv $h2 "$test_name: Multicast IPv4 untagged" \
0145                 "$smac > $MACV4_ALLNODES, ethertype IPv4 (0x0800).*: $H1_IPV4 > $IPV4_ALLNODES"
0146 
0147         check_rcv $h2 "$test_name: Unicast IPv6 untagged" \
0148                 "$smac > $dmac, ethertype IPv6 (0x86dd).*8: $H1_IPV6 > $H2_IPV6"
0149 
0150         check_rcv $h2 "$test_name: Multicast IPv6 untagged" \
0151                 "$smac > $MACV6_ALLNODES, ethertype IPv6 (0x86dd).*: $h1_ipv6_lladdr > $IPV6_ALLNODES"
0152 
0153         for vid in "${vids[@]}"; do
0154                 check_rcv $h2 "$test_name: Unicast non-IP VID $vid" \
0155                         "$smac > $dmac, ethertype 802.1Q (0x8100).*vlan $vid,.*length 4"
0156 
0157                 check_rcv $h2 "$test_name: Multicast non-IP VID $vid" \
0158                         "$smac > $NON_IP_MC, ethertype 802.1Q (0x8100).*vlan $vid,.*length 4"
0159 
0160                 check_rcv $h2 "$test_name: Broadcast non-IP VID $vid" \
0161                         "$smac > $BC, ethertype 802.1Q (0x8100).*vlan $vid,.*length 4"
0162 
0163                 check_rcv $h2 "$test_name: Unicast IPv4 VID $vid" \
0164                         "$smac > $dmac, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv4 (0x0800), $H1_IPV4 > $H2_IPV4"
0165 
0166                 check_rcv $h2 "$test_name: Multicast IPv4 VID $vid" \
0167                         "$smac > $MACV4_ALLNODES, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv4 (0x0800), $H1_IPV4 > $IPV4_ALLNODES"
0168 
0169                 check_rcv $h2 "$test_name: Unicast IPv6 VID $vid" \
0170                         "$smac > $dmac, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv6 (0x86dd), $H1_IPV6 > $H2_IPV6"
0171 
0172                 check_rcv $h2 "$test_name: Multicast IPv6 VID $vid" \
0173                         "$smac > $MACV6_ALLNODES, ethertype 802.1Q (0x8100).*vlan $vid,.*ethertype IPv6 (0x86dd), $h1_ipv6_lladdr > $IPV6_ALLNODES"
0174         done
0175 
0176         tcpdump_cleanup $h2
0177 }
0178 
0179 standalone()
0180 {
0181         run_test "Standalone switch ports"
0182 }
0183 
0184 two_bridges()
0185 {
0186         ip link add br0 type bridge && ip link set br0 up
0187         ip link add br1 type bridge && ip link set br1 up
0188         ip link set $swp1 master br0
0189         ip link set $swp2 master br1
0190 
0191         run_test "Switch ports in different bridges"
0192 
0193         ip link del br1
0194         ip link del br0
0195 }
0196 
0197 one_bridge_two_pvids()
0198 {
0199         ip link add br0 type bridge vlan_filtering 1 vlan_default_pvid 0
0200         ip link set br0 up
0201         ip link set $swp1 master br0
0202         ip link set $swp2 master br0
0203 
0204         bridge vlan add dev $swp1 vid 1 pvid untagged
0205         bridge vlan add dev $swp1 vid 2 pvid untagged
0206 
0207         run_test "Switch ports in VLAN-aware bridge with different PVIDs"
0208 
0209         ip link del br0
0210 }
0211 
0212 h1_create()
0213 {
0214         simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64
0215 }
0216 
0217 h1_destroy()
0218 {
0219         simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64
0220 }
0221 
0222 h2_create()
0223 {
0224         simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64
0225 }
0226 
0227 h2_destroy()
0228 {
0229         simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64
0230 }
0231 
0232 cleanup()
0233 {
0234         pre_cleanup
0235 
0236         h2_destroy
0237         h1_destroy
0238 
0239         vrf_cleanup
0240 }
0241 
0242 setup_prepare()
0243 {
0244         vrf_prepare
0245 
0246         h1_create
0247         h2_create
0248         # we call simple_if_init from the test itself, but setup_wait expects
0249         # that we call it from here, and waits until the interfaces are up
0250         ip link set dev $swp1 up
0251         ip link set dev $swp2 up
0252 }
0253 
0254 trap cleanup EXIT
0255 
0256 setup_prepare
0257 setup_wait
0258 
0259 tests_run
0260 
0261 exit $EXIT_STATUS