xref: /openbmc/linux/tools/testing/selftests/net/forwarding/local_termination.sh (revision f3c3091b98d5d52df40aaf27f11530701d02ac56)
190b9566aSVladimir Oltean#!/bin/bash
290b9566aSVladimir Oltean# SPDX-License-Identifier: GPL-2.0
390b9566aSVladimir Oltean
490b9566aSVladimir OlteanALL_TESTS="standalone bridge"
590b9566aSVladimir OlteanNUM_NETIFS=2
690b9566aSVladimir OlteanPING_COUNT=1
790b9566aSVladimir OlteanREQUIRE_MTOOLS=yes
890b9566aSVladimir OlteanREQUIRE_MZ=no
990b9566aSVladimir Oltean
1090b9566aSVladimir Olteansource lib.sh
1190b9566aSVladimir Oltean
1290b9566aSVladimir OlteanH1_IPV4="192.0.2.1"
1390b9566aSVladimir OlteanH2_IPV4="192.0.2.2"
1490b9566aSVladimir OlteanH1_IPV6="2001:db8:1::1"
1590b9566aSVladimir OlteanH2_IPV6="2001:db8:1::2"
1690b9566aSVladimir Oltean
1790b9566aSVladimir OlteanBRIDGE_ADDR="00:00:de:ad:be:ee"
1890b9566aSVladimir OlteanMACVLAN_ADDR="00:00:de:ad:be:ef"
1990b9566aSVladimir OlteanUNKNOWN_UC_ADDR1="de:ad:be:ef:ee:03"
2090b9566aSVladimir OlteanUNKNOWN_UC_ADDR2="de:ad:be:ef:ee:04"
2190b9566aSVladimir OlteanUNKNOWN_UC_ADDR3="de:ad:be:ef:ee:05"
2290b9566aSVladimir OlteanJOINED_IPV4_MC_ADDR="225.1.2.3"
2390b9566aSVladimir OlteanUNKNOWN_IPV4_MC_ADDR1="225.1.2.4"
2490b9566aSVladimir OlteanUNKNOWN_IPV4_MC_ADDR2="225.1.2.5"
2590b9566aSVladimir OlteanUNKNOWN_IPV4_MC_ADDR3="225.1.2.6"
2690b9566aSVladimir OlteanJOINED_IPV6_MC_ADDR="ff2e::0102:0304"
2790b9566aSVladimir OlteanUNKNOWN_IPV6_MC_ADDR1="ff2e::0102:0305"
2890b9566aSVladimir OlteanUNKNOWN_IPV6_MC_ADDR2="ff2e::0102:0306"
2990b9566aSVladimir OlteanUNKNOWN_IPV6_MC_ADDR3="ff2e::0102:0307"
3090b9566aSVladimir Oltean
3190b9566aSVladimir OlteanJOINED_MACV4_MC_ADDR="01:00:5e:01:02:03"
3290b9566aSVladimir OlteanUNKNOWN_MACV4_MC_ADDR1="01:00:5e:01:02:04"
3390b9566aSVladimir OlteanUNKNOWN_MACV4_MC_ADDR2="01:00:5e:01:02:05"
3490b9566aSVladimir OlteanUNKNOWN_MACV4_MC_ADDR3="01:00:5e:01:02:06"
3590b9566aSVladimir OlteanJOINED_MACV6_MC_ADDR="33:33:01:02:03:04"
3690b9566aSVladimir OlteanUNKNOWN_MACV6_MC_ADDR1="33:33:01:02:03:05"
3790b9566aSVladimir OlteanUNKNOWN_MACV6_MC_ADDR2="33:33:01:02:03:06"
3890b9566aSVladimir OlteanUNKNOWN_MACV6_MC_ADDR3="33:33:01:02:03:07"
3990b9566aSVladimir Oltean
4090b9566aSVladimir OlteanNON_IP_MC="01:02:03:04:05:06"
4190b9566aSVladimir OlteanNON_IP_PKT="00:04 48:45:4c:4f"
4290b9566aSVladimir OlteanBC="ff:ff:ff:ff:ff:ff"
4390b9566aSVladimir Oltean
4490b9566aSVladimir Oltean# Disable promisc to ensure we don't receive unknown MAC DA packets
4590b9566aSVladimir Olteanexport TCPDUMP_EXTRA_FLAGS="-pl"
4690b9566aSVladimir Oltean
4790b9566aSVladimir Olteanh1=${NETIFS[p1]}
4890b9566aSVladimir Olteanh2=${NETIFS[p2]}
4990b9566aSVladimir Oltean
5090b9566aSVladimir Olteansend_non_ip()
5190b9566aSVladimir Oltean{
5290b9566aSVladimir Oltean	local if_name=$1
5390b9566aSVladimir Oltean	local smac=$2
5490b9566aSVladimir Oltean	local dmac=$3
5590b9566aSVladimir Oltean
5690b9566aSVladimir Oltean	$MZ -q $if_name "$dmac $smac $NON_IP_PKT"
5790b9566aSVladimir Oltean}
5890b9566aSVladimir Oltean
5990b9566aSVladimir Olteansend_uc_ipv4()
6090b9566aSVladimir Oltean{
6190b9566aSVladimir Oltean	local if_name=$1
6290b9566aSVladimir Oltean	local dmac=$2
6390b9566aSVladimir Oltean
6490b9566aSVladimir Oltean	ip neigh add $H2_IPV4 lladdr $dmac dev $if_name
6590b9566aSVladimir Oltean	ping_do $if_name $H2_IPV4
6690b9566aSVladimir Oltean	ip neigh del $H2_IPV4 dev $if_name
6790b9566aSVladimir Oltean}
6890b9566aSVladimir Oltean
6990b9566aSVladimir Olteancheck_rcv()
7090b9566aSVladimir Oltean{
7190b9566aSVladimir Oltean	local if_name=$1
7290b9566aSVladimir Oltean	local type=$2
7390b9566aSVladimir Oltean	local pattern=$3
7490b9566aSVladimir Oltean	local should_receive=$4
7590b9566aSVladimir Oltean	local should_fail=
7690b9566aSVladimir Oltean
7790b9566aSVladimir Oltean	[ $should_receive = true ] && should_fail=0 || should_fail=1
7890b9566aSVladimir Oltean	RET=0
7990b9566aSVladimir Oltean
8090b9566aSVladimir Oltean	tcpdump_show $if_name | grep -q "$pattern"
8190b9566aSVladimir Oltean
8290b9566aSVladimir Oltean	check_err_fail "$should_fail" "$?" "reception"
8390b9566aSVladimir Oltean
8490b9566aSVladimir Oltean	log_test "$if_name: $type"
8590b9566aSVladimir Oltean}
8690b9566aSVladimir Oltean
8790b9566aSVladimir Olteanmc_route_prepare()
8890b9566aSVladimir Oltean{
8990b9566aSVladimir Oltean	local if_name=$1
9090b9566aSVladimir Oltean	local vrf_name=$(master_name_get $if_name)
9190b9566aSVladimir Oltean
9290b9566aSVladimir Oltean	ip route add 225.100.1.0/24 dev $if_name vrf $vrf_name
9390b9566aSVladimir Oltean	ip -6 route add ff2e::/64 dev $if_name vrf $vrf_name
9490b9566aSVladimir Oltean}
9590b9566aSVladimir Oltean
9690b9566aSVladimir Olteanmc_route_destroy()
9790b9566aSVladimir Oltean{
9890b9566aSVladimir Oltean	local if_name=$1
9990b9566aSVladimir Oltean	local vrf_name=$(master_name_get $if_name)
10090b9566aSVladimir Oltean
10190b9566aSVladimir Oltean	ip route del 225.100.1.0/24 dev $if_name vrf $vrf_name
10290b9566aSVladimir Oltean	ip -6 route del ff2e::/64 dev $if_name vrf $vrf_name
10390b9566aSVladimir Oltean}
10490b9566aSVladimir Oltean
10590b9566aSVladimir Olteanrun_test()
10690b9566aSVladimir Oltean{
10790b9566aSVladimir Oltean	local rcv_if_name=$1
10890b9566aSVladimir Oltean	local smac=$(mac_get $h1)
10990b9566aSVladimir Oltean	local rcv_dmac=$(mac_get $rcv_if_name)
11090b9566aSVladimir Oltean
11190b9566aSVladimir Oltean	tcpdump_start $rcv_if_name
11290b9566aSVladimir Oltean
11390b9566aSVladimir Oltean	mc_route_prepare $h1
11490b9566aSVladimir Oltean	mc_route_prepare $rcv_if_name
11590b9566aSVladimir Oltean
11690b9566aSVladimir Oltean	send_uc_ipv4 $h1 $rcv_dmac
11790b9566aSVladimir Oltean	send_uc_ipv4 $h1 $MACVLAN_ADDR
11890b9566aSVladimir Oltean	send_uc_ipv4 $h1 $UNKNOWN_UC_ADDR1
11990b9566aSVladimir Oltean
12090b9566aSVladimir Oltean	ip link set dev $rcv_if_name promisc on
12190b9566aSVladimir Oltean	send_uc_ipv4 $h1 $UNKNOWN_UC_ADDR2
12290b9566aSVladimir Oltean	mc_send $h1 $UNKNOWN_IPV4_MC_ADDR2
12390b9566aSVladimir Oltean	mc_send $h1 $UNKNOWN_IPV6_MC_ADDR2
12490b9566aSVladimir Oltean	ip link set dev $rcv_if_name promisc off
12590b9566aSVladimir Oltean
12690b9566aSVladimir Oltean	mc_join $rcv_if_name $JOINED_IPV4_MC_ADDR
12790b9566aSVladimir Oltean	mc_send $h1 $JOINED_IPV4_MC_ADDR
12890b9566aSVladimir Oltean	mc_leave
12990b9566aSVladimir Oltean
13090b9566aSVladimir Oltean	mc_join $rcv_if_name $JOINED_IPV6_MC_ADDR
13190b9566aSVladimir Oltean	mc_send $h1 $JOINED_IPV6_MC_ADDR
13290b9566aSVladimir Oltean	mc_leave
13390b9566aSVladimir Oltean
13490b9566aSVladimir Oltean	mc_send $h1 $UNKNOWN_IPV4_MC_ADDR1
13590b9566aSVladimir Oltean	mc_send $h1 $UNKNOWN_IPV6_MC_ADDR1
13690b9566aSVladimir Oltean
13790b9566aSVladimir Oltean	ip link set dev $rcv_if_name allmulticast on
13890b9566aSVladimir Oltean	send_uc_ipv4 $h1 $UNKNOWN_UC_ADDR3
13990b9566aSVladimir Oltean	mc_send $h1 $UNKNOWN_IPV4_MC_ADDR3
14090b9566aSVladimir Oltean	mc_send $h1 $UNKNOWN_IPV6_MC_ADDR3
14190b9566aSVladimir Oltean	ip link set dev $rcv_if_name allmulticast off
14290b9566aSVladimir Oltean
14390b9566aSVladimir Oltean	mc_route_destroy $rcv_if_name
14490b9566aSVladimir Oltean	mc_route_destroy $h1
14590b9566aSVladimir Oltean
14690b9566aSVladimir Oltean	sleep 1
14790b9566aSVladimir Oltean
14890b9566aSVladimir Oltean	tcpdump_stop $rcv_if_name
14990b9566aSVladimir Oltean
15090b9566aSVladimir Oltean	check_rcv $rcv_if_name "Unicast IPv4 to primary MAC address" \
15190b9566aSVladimir Oltean		"$smac > $rcv_dmac, ethertype IPv4 (0x0800)" \
15290b9566aSVladimir Oltean		true
15390b9566aSVladimir Oltean
15490b9566aSVladimir Oltean	check_rcv $rcv_if_name "Unicast IPv4 to macvlan MAC address" \
15590b9566aSVladimir Oltean		"$smac > $MACVLAN_ADDR, ethertype IPv4 (0x0800)" \
15690b9566aSVladimir Oltean		true
15790b9566aSVladimir Oltean
15890b9566aSVladimir Oltean	check_rcv $rcv_if_name "Unicast IPv4 to unknown MAC address" \
15990b9566aSVladimir Oltean		"$smac > $UNKNOWN_UC_ADDR1, ethertype IPv4 (0x0800)" \
16090b9566aSVladimir Oltean		false
16190b9566aSVladimir Oltean
16290b9566aSVladimir Oltean	check_rcv $rcv_if_name "Unicast IPv4 to unknown MAC address, promisc" \
16390b9566aSVladimir Oltean		"$smac > $UNKNOWN_UC_ADDR2, ethertype IPv4 (0x0800)" \
16490b9566aSVladimir Oltean		true
16590b9566aSVladimir Oltean
16690b9566aSVladimir Oltean	check_rcv $rcv_if_name "Unicast IPv4 to unknown MAC address, allmulti" \
16790b9566aSVladimir Oltean		"$smac > $UNKNOWN_UC_ADDR3, ethertype IPv4 (0x0800)" \
16890b9566aSVladimir Oltean		false
16990b9566aSVladimir Oltean
17090b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv4 to joined group" \
17190b9566aSVladimir Oltean		"$smac > $JOINED_MACV4_MC_ADDR, ethertype IPv4 (0x0800)" \
17290b9566aSVladimir Oltean		true
17390b9566aSVladimir Oltean
17490b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv4 to unknown group" \
17590b9566aSVladimir Oltean		"$smac > $UNKNOWN_MACV4_MC_ADDR1, ethertype IPv4 (0x0800)" \
17690b9566aSVladimir Oltean		false
17790b9566aSVladimir Oltean
17890b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv4 to unknown group, promisc" \
17990b9566aSVladimir Oltean		"$smac > $UNKNOWN_MACV4_MC_ADDR2, ethertype IPv4 (0x0800)" \
18090b9566aSVladimir Oltean		true
18190b9566aSVladimir Oltean
18290b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv4 to unknown group, allmulti" \
18390b9566aSVladimir Oltean		"$smac > $UNKNOWN_MACV4_MC_ADDR3, ethertype IPv4 (0x0800)" \
18490b9566aSVladimir Oltean		true
18590b9566aSVladimir Oltean
18690b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv6 to joined group" \
18790b9566aSVladimir Oltean		"$smac > $JOINED_MACV6_MC_ADDR, ethertype IPv6 (0x86dd)" \
18890b9566aSVladimir Oltean		true
18990b9566aSVladimir Oltean
19090b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv6 to unknown group" \
19190b9566aSVladimir Oltean		"$smac > $UNKNOWN_MACV6_MC_ADDR1, ethertype IPv6 (0x86dd)" \
19290b9566aSVladimir Oltean		false
19390b9566aSVladimir Oltean
19490b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv6 to unknown group, promisc" \
19590b9566aSVladimir Oltean		"$smac > $UNKNOWN_MACV6_MC_ADDR2, ethertype IPv6 (0x86dd)" \
19690b9566aSVladimir Oltean		true
19790b9566aSVladimir Oltean
19890b9566aSVladimir Oltean	check_rcv $rcv_if_name "Multicast IPv6 to unknown group, allmulti" \
19990b9566aSVladimir Oltean		"$smac > $UNKNOWN_MACV6_MC_ADDR3, ethertype IPv6 (0x86dd)" \
20090b9566aSVladimir Oltean		true
20190b9566aSVladimir Oltean
20290b9566aSVladimir Oltean	tcpdump_cleanup $rcv_if_name
20390b9566aSVladimir Oltean}
20490b9566aSVladimir Oltean
20590b9566aSVladimir Olteanh1_create()
20690b9566aSVladimir Oltean{
20790b9566aSVladimir Oltean	simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64
20890b9566aSVladimir Oltean}
20990b9566aSVladimir Oltean
21090b9566aSVladimir Olteanh1_destroy()
21190b9566aSVladimir Oltean{
21290b9566aSVladimir Oltean	simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64
21390b9566aSVladimir Oltean}
21490b9566aSVladimir Oltean
21590b9566aSVladimir Olteanh2_create()
21690b9566aSVladimir Oltean{
21790b9566aSVladimir Oltean	simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64
21890b9566aSVladimir Oltean}
21990b9566aSVladimir Oltean
22090b9566aSVladimir Olteanh2_destroy()
22190b9566aSVladimir Oltean{
22290b9566aSVladimir Oltean	simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64
22390b9566aSVladimir Oltean}
22490b9566aSVladimir Oltean
22590b9566aSVladimir Olteanbridge_create()
22690b9566aSVladimir Oltean{
22790b9566aSVladimir Oltean	ip link add br0 type bridge
22890b9566aSVladimir Oltean	ip link set br0 address $BRIDGE_ADDR
22990b9566aSVladimir Oltean	ip link set br0 up
23090b9566aSVladimir Oltean
23190b9566aSVladimir Oltean	ip link set $h2 master br0
23290b9566aSVladimir Oltean	ip link set $h2 up
23390b9566aSVladimir Oltean
23490b9566aSVladimir Oltean	simple_if_init br0 $H2_IPV4/24 $H2_IPV6/64
23590b9566aSVladimir Oltean}
23690b9566aSVladimir Oltean
23790b9566aSVladimir Olteanbridge_destroy()
23890b9566aSVladimir Oltean{
23990b9566aSVladimir Oltean	simple_if_fini br0 $H2_IPV4/24 $H2_IPV6/64
24090b9566aSVladimir Oltean
24190b9566aSVladimir Oltean	ip link del br0
24290b9566aSVladimir Oltean}
24390b9566aSVladimir Oltean
24490b9566aSVladimir Olteanstandalone()
24590b9566aSVladimir Oltean{
24690b9566aSVladimir Oltean	h1_create
24790b9566aSVladimir Oltean	h2_create
24890b9566aSVladimir Oltean
24990b9566aSVladimir Oltean	ip link add link $h2 name macvlan0 type macvlan mode private
25090b9566aSVladimir Oltean	ip link set macvlan0 address $MACVLAN_ADDR
25190b9566aSVladimir Oltean	ip link set macvlan0 up
25290b9566aSVladimir Oltean
25390b9566aSVladimir Oltean	run_test $h2
25490b9566aSVladimir Oltean
25590b9566aSVladimir Oltean	ip link del macvlan0
25690b9566aSVladimir Oltean
25790b9566aSVladimir Oltean	h2_destroy
25890b9566aSVladimir Oltean	h1_destroy
25990b9566aSVladimir Oltean}
26090b9566aSVladimir Oltean
26190b9566aSVladimir Olteanbridge()
26290b9566aSVladimir Oltean{
26390b9566aSVladimir Oltean	h1_create
26490b9566aSVladimir Oltean	bridge_create
26590b9566aSVladimir Oltean
26690b9566aSVladimir Oltean	ip link add link br0 name macvlan0 type macvlan mode private
26790b9566aSVladimir Oltean	ip link set macvlan0 address $MACVLAN_ADDR
26890b9566aSVladimir Oltean	ip link set macvlan0 up
26990b9566aSVladimir Oltean
27090b9566aSVladimir Oltean	run_test br0
27190b9566aSVladimir Oltean
27290b9566aSVladimir Oltean	ip link del macvlan0
27390b9566aSVladimir Oltean
27490b9566aSVladimir Oltean	bridge_destroy
27590b9566aSVladimir Oltean	h1_destroy
27690b9566aSVladimir Oltean}
27790b9566aSVladimir Oltean
27890b9566aSVladimir Olteancleanup()
27990b9566aSVladimir Oltean{
28090b9566aSVladimir Oltean	pre_cleanup
281*7aa9f978SPetr Machata
282*7aa9f978SPetr Machata	ip link set $h2 down
283*7aa9f978SPetr Machata	ip link set $h1 down
284*7aa9f978SPetr Machata
28590b9566aSVladimir Oltean	vrf_cleanup
28690b9566aSVladimir Oltean}
28790b9566aSVladimir Oltean
28890b9566aSVladimir Olteansetup_prepare()
28990b9566aSVladimir Oltean{
29090b9566aSVladimir Oltean	vrf_prepare
29190b9566aSVladimir Oltean	# setup_wait() needs this
29290b9566aSVladimir Oltean	ip link set $h1 up
29390b9566aSVladimir Oltean	ip link set $h2 up
29490b9566aSVladimir Oltean}
29590b9566aSVladimir Oltean
29690b9566aSVladimir Olteantrap cleanup EXIT
29790b9566aSVladimir Oltean
29890b9566aSVladimir Olteansetup_prepare
29990b9566aSVladimir Olteansetup_wait
30090b9566aSVladimir Oltean
30190b9566aSVladimir Olteantests_run
30290b9566aSVladimir Oltean
30390b9566aSVladimir Olteanexit $EXIT_STATUS
304