Thread (3 messages) 3 messages, 1 author, 2d ago

[RFC net-next 1/2] hsr: Set equal MAC addresses on port A and B for HSR

From: Felix Maurer <hidden>
Date: 2026-07-14 10:53:24
Subsystem: hsr network protocol, kernel selftest framework, networking [general], the rest · Maintainers: Shuah Khan, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

All hsr interfaces are created with their MAC address set to the MAC
address of port A. Since commit b65999e7238e ("net: hsr: sync hw addr of
slave2 according to slave1 hw addr on PRP"), we are copying the MAC address
of port A to port B as well for PRP interfaces because for correct
operation, a node in a PRP network must use the same MAC address on both
ports. IOW, the frames sent over port A and port B must only differ in the
LAN ID in their PRP redundancy control trailer, i.e., must not differ in
their source MAC address.

The same applies to HSR: for correct operation of the ring, the frames sent
from port A and port B must not differ in their source MAC address.
Therefore, extend the address copying behavior from PRP to HSR interfaces.

In the selftests, we now set only the addresses of port A which is how HSR
is intended to be used. The address is copied over to port B anyways. With
only a single address per node, there is also no reason anymore to wait for
nodes in the table to get merged. While touching the MAC addresses in the
hsr_redbox test, I noticed that the bridge in ns3 and its ports have the
same addresses; fixing that as well.

Signed-off-by: Felix Maurer <redacted>
---
 net/hsr/hsr_device.c                          |  6 ++--
 net/hsr/hsr_main.c                            | 12 +++----
 tools/testing/selftests/net/hsr/hsr_ping.sh   | 33 +++----------------
 tools/testing/selftests/net/hsr/hsr_redbox.sh | 13 +++-----
 .../testing/selftests/net/hsr/link_faults.sh  | 26 ---------------
 5 files changed, 16 insertions(+), 74 deletions(-)
diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index 5555b71ab19b..a52079eb2adb 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -795,10 +795,8 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
 	if (res)
 		goto err_unregister;
 
-	if (protocol_version == PRP_V1) {
-		eth_hw_addr_set(slave[1], slave[0]->dev_addr);
-		call_netdevice_notifiers(NETDEV_CHANGEADDR, slave[1]);
-	}
+	eth_hw_addr_set(slave[1], slave[0]->dev_addr);
+	call_netdevice_notifiers(NETDEV_CHANGEADDR, slave[1]);
 
 	if (interlink) {
 		res = hsr_add_port(hsr, interlink, HSR_PT_INTERLINK, extack);
diff --git a/net/hsr/hsr_main.c b/net/hsr/hsr_main.c
index 33951d9bd3c5..202cf2a3625f 100644
--- a/net/hsr/hsr_main.c
+++ b/net/hsr/hsr_main.c
@@ -79,13 +79,11 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
 			call_netdevice_notifiers(NETDEV_CHANGEADDR,
 						 master->dev);
 
-			if (hsr->prot_version == PRP_V1) {
-				port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
-				if (port) {
-					eth_hw_addr_set(port->dev, dev->dev_addr);
-					call_netdevice_notifiers(NETDEV_CHANGEADDR,
-								 port->dev);
-				}
+			port = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);
+			if (port) {
+				eth_hw_addr_set(port->dev, dev->dev_addr);
+				call_netdevice_notifiers(NETDEV_CHANGEADDR,
+							 port->dev);
 			}
 		}
 
diff --git a/tools/testing/selftests/net/hsr/hsr_ping.sh b/tools/testing/selftests/net/hsr/hsr_ping.sh
index f4d685df4345..454c6fdfd834 100755
--- a/tools/testing/selftests/net/hsr/hsr_ping.sh
+++ b/tools/testing/selftests/net/hsr/hsr_ping.sh
@@ -51,25 +51,6 @@ do_ping_tests()
 	do_ping "$ns3" "dead:beef:$netid::2"
 	stop_if_error "Initial validation failed on IPv6."
 
-# Wait until supervisor all supervision frames have been processed and the node
-# entries have been merged. Otherwise duplicate frames will be observed which is
-# valid at this stage.
-	echo "INFO: Wait for node table entries to be merged."
-	WAIT=5
-	while [ ${WAIT} -gt 0 ]
-	do
-		grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table
-		if [ $? -ne 0 ]
-		then
-			break
-		fi
-		sleep 1
-		let "WAIT = WAIT - 1"
-	done
-
-# Just a safety delay in case the above check didn't handle it.
-	sleep 1
-
 	echo "INFO: Longer ping test."
 	do_ping_long "$ns1" "100.64.$netid.2"
 	do_ping_long "$ns1" "dead:beef:$netid::2"
@@ -110,6 +91,11 @@ setup_hsr_interfaces()
 	ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
 	ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
 
+	# MAC addresses will be copied from LAN A interfaces
+	ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
+	ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
+	ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
+
 	# HSRv0/1
 	ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 \
 		slave2 ns1eth2 supervision 45 version "$HSRv" proto 0
@@ -126,15 +112,6 @@ setup_hsr_interfaces()
 	ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
 	ip -net "$ns3" addr add dead:beef:0::3/64 dev hsr3 nodad
 
-	ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
-	ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
-
-	ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
-	ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
-
-	ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
-	ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2
-
 	# All Links up
 	ip -net "$ns1" link set ns1eth1 up
 	ip -net "$ns1" link set ns1eth2 up
diff --git a/tools/testing/selftests/net/hsr/hsr_redbox.sh b/tools/testing/selftests/net/hsr/hsr_redbox.sh
index 998103502d5d..f945d7d82fa1 100755
--- a/tools/testing/selftests/net/hsr/hsr_redbox.sh
+++ b/tools/testing/selftests/net/hsr/hsr_redbox.sh
@@ -23,10 +23,6 @@ do_complete_ping_test()
 	do_ping "${ns5}" 100.64.0.1
 	stop_if_error "Initial validation failed."
 
-	# Wait for MGNT HSR frames being received and nodes being
-	# merged.
-	sleep 5
-
 	echo "INFO: Longer ping test (HSR-SAN/RedBox)."
 	# Ping from SAN to hsr1 (via hsr2)
 	do_ping_long "${ns3}" 100.64.0.1
@@ -96,16 +92,15 @@ setup_hsr_interfaces()
 	ip -n "${ns4}" link set ns4eth1 up
 	ip -n "${ns5}" link set ns5eth1 up
 
+	# Setting MAC addresses to help with debugging
 	ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
-	ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
 
 	ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
-	ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
 	ip -net "$ns2" link set address 00:11:22:00:02:03 dev ns2eth3
 
-	ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth1
-	ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth2
-	ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth3
+	ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
+	ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2
+	ip -net "$ns3" link set address 00:11:22:00:03:03 dev ns3eth3
 	ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3br1
 
 	ip -net "$ns4" link set address 00:11:22:00:04:01 dev ns4eth1
diff --git a/tools/testing/selftests/net/hsr/link_faults.sh b/tools/testing/selftests/net/hsr/link_faults.sh
index be526281571c..c002390acc07 100755
--- a/tools/testing/selftests/net/hsr/link_faults.sh
+++ b/tools/testing/selftests/net/hsr/link_faults.sh
@@ -59,13 +59,8 @@ setup_hsr_topo()
 
 	# MAC addresses (not needed for HSR operation, but helps with debugging)
 	ip -net "$node1" link set address 00:11:22:00:01:01 dev vethA
-	ip -net "$node1" link set address 00:11:22:00:01:02 dev vethB
-
 	ip -net "$node2" link set address 00:11:22:00:02:01 dev vethA
-	ip -net "$node2" link set address 00:11:22:00:02:02 dev vethB
-
 	ip -net "$node3" link set address 00:11:22:00:03:01 dev vethA
-	ip -net "$node3" link set address 00:11:22:00:03:02 dev vethB
 
 	# HSR interfaces
 	ip -net "$node1" link add name hsr1 type hsr proto 0 version "$ver" \
@@ -134,35 +129,14 @@ setup_prp_topo()
 	ip -net "$node2" link set prp2 up
 }
 
-wait_for_hsr_node_table()
-{
-	log_info "Wait for node table entries to be merged."
-	WAIT=5
-	while [ "${WAIT}" -gt 0 ]; do
-		nts=$(cat /sys/kernel/debug/hsr/hsr*/node_table)
-
-		# We need entries in the node tables, and they need to be merged
-		if (echo "$nts" | grep -qE "^([0-9a-f]{2}:){5}") && \
-		    ! (echo "$nts" | grep -q "00:00:00:00:00:00"); then
-			return
-		fi
-
-		sleep 1
-		((WAIT--))
-	done
-	check_err 1 "Failed to wait for merged node table entries"
-}
-
 setup_topo()
 {
 	local proto="$1"
 
 	if [ "$proto" = "HSRv0" ]; then
 		setup_hsr_topo 0
-		wait_for_hsr_node_table
 	elif [ "$proto" = "HSRv1" ]; then
 		setup_hsr_topo 1
-		wait_for_hsr_node_table
 	elif [ "$proto" = "PRP" ]; then
 		setup_prp_topo
 	else
-- 
2.55.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help