xref: /linux/tools/testing/selftests/net/hsr/hsr_prp_redbox.sh (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Test a PRP RedBox (PRP-SAN): a SAN that sits behind the interlink port must
5# reach, and be reached by, a peer DANP on the PRP network with its own MAC
6# preserved on the wire, and the RedBox must announce the SAN with a RedBox-MAC
7# TLV (terminated by an EOT marker) in its PRP supervision frames.
8#
9#   RB    PRP RedBox: prp0 over rb_a/rb_b (LAN A/B) + interlink rb_il
10#   PEER  peer DANP : prp0 over pe_a/pe_b, 100.64.0.2
11#   SAN   SAN       : san_il, own MAC, 100.64.0.51 (behind the interlink)
12
13ipv6=false
14
15source ./hsr_common.sh
16
17check_prerequisites
18
19if ! command -v tcpdump >/dev/null 2>&1; then
20	echo "SKIP: This test requires tcpdump"
21	exit $ksft_skip
22fi
23
24if ! ip link help hsr 2>&1 | grep -q interlink; then
25	echo "SKIP: iproute2 too old (no hsr interlink support)"
26	exit $ksft_skip
27fi
28
29setup_ns RB PEER SAN
30trap 'cleanup_ns "$RB" "$PEER" "$SAN"' EXIT
31
32ip link add rb_a netns "$RB" type veth peer name pe_a netns "$PEER"
33ip link add rb_b netns "$RB" type veth peer name pe_b netns "$PEER"
34ip link add rb_il netns "$RB" type veth peer name san_il netns "$SAN"
35
36ip -n "$RB"   link set rb_a up
37ip -n "$RB"   link set rb_b up
38ip -n "$RB"   link set rb_il up
39ip -n "$PEER" link set pe_a up
40ip -n "$PEER" link set pe_b up
41ip -n "$SAN"  link set san_il up
42ip -n "$SAN"  addr add 100.64.0.51/24 dev san_il
43
44# Feature gate: PRP interlink (RedBox) creation. A kernel without PRP RedBox
45# support rejects this with -EINVAL, so SKIP rather than FAIL.
46if ! ip -n "$RB" link add name prp0 type hsr slave1 rb_a slave2 rb_b \
47     interlink rb_il proto 1 2>/dev/null; then
48	echo "SKIP: kernel without PRP RedBox (interlink) support"
49	exit $ksft_skip
50fi
51ip -n "$RB"   link set prp0 up
52ip -n "$PEER" link add name prp0 type hsr slave1 pe_a slave2 pe_b proto 1
53ip -n "$PEER" link set prp0 up
54ip -n "$PEER" addr add 100.64.0.2/24 dev prp0
55sleep 1
56
57san_mac=$(ip -n "$SAN" -br link show san_il | awk '{print $3}')
58rb_mac=$(ip -n "$RB" -br link show rb_il | awk '{print $3}')
59
60# Bidirectional unicast across the interlink.
61do_ping "$PEER" 100.64.0.51
62do_ping "$SAN"  100.64.0.2
63stop_if_error "PRP RedBox bidirectional unicast failed"
64
65# The SAN source MAC must be preserved on the PRP network, not laundered to the
66# RedBox MAC: the peer resolves the SAN IP to the SAN's own MAC.
67neigh=$(ip -n "$PEER" neigh show 100.64.0.51 | awk '{print $5}')
68if [ "$neigh" != "$san_mac" ]; then
69	echo "SAN MAC preservation [ FAIL ]: peer resolved 100.64.0.51 to" \
70	     "'$neigh', expected $san_mac" 1>&2
71	ret=1
72fi
73stop_if_error "SAN MAC not preserved on the PRP network"
74
75# The proxy-announce supervision frame must carry, in order, the life-check TLV
76# (type 0x14, len 6) + MacAddressA == SAN MAC + the RedBox-MAC TLV (type 0x1e,
77# len 6) + MacAddressRedBox == RedBox MAC + the EOT marker (0x0000).
78ip netns exec "$SAN" ping -i 0.2 -q 100.64.0.2 >/dev/null 2>&1 &
79ping_pid=$!
80cap=$(ip netns exec "$PEER" timeout 5 tcpdump -i pe_a -nn -x \
81	"ether proto 0x88fb and ether src $rb_mac" 2>/dev/null || true)
82kill "$ping_pid" 2>/dev/null || true
83wait "$ping_pid" 2>/dev/null || true
84
85san_hex=$(echo "$san_mac" | tr -d ':')
86rb_hex=$(echo "$rb_mac" | tr -d ':')
87# Reassemble contiguous frame hex: drop the "0x0010:" offset labels and spaces.
88frame_hex=$(echo "$cap" | awk '/^[[:space:]]*0x[0-9a-f]+:/ {
89	sub(/^[[:space:]]*0x[0-9a-f]+:[[:space:]]*/, "");
90	gsub(/ /, ""); printf "%s", $0 }')
91if ! echo "$frame_hex" | grep -q "1406${san_hex}1e06${rb_hex}0000"; then
92	echo "supervision RedBox-MAC TLV [ FAIL ]: missing SAN MAC, Type-30" \
93	     "payload, or EOT" 1>&2
94	ret=1
95fi
96stop_if_error "PRP RedBox supervision RedBox-MAC TLV/EOT check failed"
97
98echo "INFO: PRP RedBox (PRP-SAN) conformance checks passed"
99exit $ret
100