🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26531

[PATCH net-next v14 5/8] hsr: Use the port and header information in hsr_forward_skb()

#26531
From: Sebastian Andrzej Siewior
Date: Thu, 03 Dec 2026 17:44
158 lines
15762 bytes
The upper layer can submit a port on which the skb should be sent and
whether or not a HSR header should be added. Use this information while
forwarding the packet:
- If the port set, deliver it only on the requested port.
- If a header is already present then skip parts of the stack:
  - The packet originates from the master port and we don't want to
    assign a sequence number to it, it needs to preserve the original
    one.
  - The existing h_source must be used (and not replaced).
  - The node should already exist in the node_db if "other" packets are
    exchanged. If the node information is not yet existing then
    creating it makes no sense because it is used for deduplication of
    incoming packets and this is not used in the PTP case. If no other
    packets are exchanged then the node_db will age and then removed.

This is only used in the pure software version. Hardware with any kind
of NETIF_F_HW_* offload support need to be addressed separately.

Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 net/hsr/hsr_forward.c  | 47 +++++++++++++++++++++++++++++++++++++++--------
 net/hsr/hsr_framereg.h |  2 ++
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index f49d962337f8b..1d1d75ed8cd06 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c
@@ -426,7 +426,7 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
 static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
 		    struct hsr_frame_info *frame)
 {
-	if (frame->port_rcv->type == HSR_PT_MASTER) {
+	if (frame->port_rcv->type == HSR_PT_MASTER && !frame->has_hsr_header) {
 		hsr_addr_subst_dest(frame->node_src, skb, port);
 
 		/* Address substitution (IEC62439-3 pp 26, 50): replace mac
@@ -552,6 +552,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
 
 	hsr_for_each_port(frame->port_rcv->hsr, port) {
 		struct hsr_priv *hsr = port->hsr;
+
 		/* Don't send frame back the way it came */
 		if (port == frame->port_rcv)
 			continue;
@@ -570,6 +571,20 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
 		if ((port->dev->features & NETIF_F_HW_HSR_DUP) && sent)
 			continue;
 
+		/* If this frame has a specific outgoing port specified (by the
+		 * sender) then send it on this port only.
+		 */
+		if (frame->req_tx_port != HSR_PT_NONE &&
+		    frame->req_tx_port != port->type)
+			continue;
+		/* If this TX frame already has a HSR header then forward the
+		 * frame with it and don't add one.
+		 */
+		if (frame->has_hsr_header && frame->skb_std) {
+			skb = skb_clone(frame->skb_std, GFP_ATOMIC);
+			goto inject_into_stack;
+		}
+
 		/* Don't send frame over port where it has been sent before.
 		 * Also for SAN, this shouldn't be done.
 		 */
@@ -597,6 +612,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
 		else
 			skb = hsr->proto_ops->get_untagged_frame(frame, port);
 
+inject_into_stack:
 		if (!skb) {
 			frame->port_rcv->dev->stats.rx_dropped++;
 			continue;
@@ -661,6 +677,13 @@ int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
 	struct hsr_port *port = frame->port_rcv;
 	struct hsr_priv *hsr = port->hsr;
 
+	if (frame->has_hsr_header) {
+		frame->skb_std = skb;
+
+		WARN_ON_ONCE(port->type != HSR_PT_MASTER);
+		WARN_ON_ONCE(skb->mac_len < sizeof(struct hsr_ethhdr));
+		return 0;
+	}
 	/* HSRv0 supervisory frames double as a tag so treat them as tagged. */
 	if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) ||
 	    proto == htons(ETH_P_HSR)) {
@@ -702,7 +725,8 @@ int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,
 }
 
 static int fill_frame_info(struct hsr_frame_info *frame,
-			   struct sk_buff *skb, struct hsr_port *port)
+			   struct sk_buff *skb, struct hsr_port *port,
+			   enum hsr_port_type req_tx_port, bool has_hsr_header)
 {
 	struct hsr_priv *hsr = port->hsr;
 	struct hsr_vlan_ethhdr *vlan_hdr;
@@ -725,10 +749,16 @@ static int fill_frame_info(struct hsr_frame_info *frame,
 	if (port->type == HSR_PT_INTERLINK)
 		n_db = &hsr->proxy_node_db;
 
-	frame->node_src = hsr_get_node(port, n_db, skb,
-				       frame->is_supervision, port->type);
-	if (!frame->node_src)
-		return -1; /* Unknown node and !is_supervision, or no mem */
+	frame->req_tx_port = req_tx_port;
+	frame->has_hsr_header = has_hsr_header;
+
+	if (!frame->has_hsr_header) {
+		frame->node_src = hsr_get_node(port, n_db, skb,
+					       frame->is_supervision,
+					       port->type);
+		if (!frame->node_src)
+			return -1; /* Unknown node and !is_supervision, or no mem */
+	}
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 	frame->is_vlan = false;
@@ -777,10 +807,11 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,
 	struct hsr_frame_info frame;
 
 	rcu_read_lock();
-	if (fill_frame_info(&frame, skb, port) < 0)
+	if (fill_frame_info(&frame, skb, port, req_tx_port, has_hsr_header) < 0)
 		goto out_drop;
 
-	hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
+	if (!frame.has_hsr_header)
+		hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
 	hsr_forward_do(&frame);
 	rcu_read_unlock();
 	/* Gets called for ingress frames as well as egress from master port.
diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
index 127a3fb64d5f0..dc13819d04098 100644
--- a/net/hsr/hsr_framereg.h
+++ b/net/hsr/hsr_framereg.h
@@ -29,6 +29,8 @@ struct hsr_frame_info {
 	bool is_from_san;
 	bool dst_in_node_db;
 	bool dst_in_proxy_node_db;
+	bool has_hsr_header;
+	enum hsr_port_type req_tx_port;
 };
 
 void hsr_del_self_node(struct hsr_priv *hsr);

-- 
2.55.0
Technical Details
Message-ID: <20261203-hsr_ptp-v14-5-1511ffd4c362@linutronix.de>
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376795-linux-kernel-netdev=dewy.ru
References: <20261203-hsr_ptp-v14-0-1511ffd4c362@linutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376795-linux-kernel-netdev=dewy.ru
From: bigeasy@linutronix.de (Sebastian Andrzej Siewior)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v14 5/8] hsr: Use the port and header information in hsr_forward_skb()
Date: Thu,  3 Dec 2026 18:44:46 +0100
Organization: Usenet Network
Message-ID: <20261203-hsr_ptp-v14-5-1511ffd4c362@linutronix.de>
References: <20261203-hsr_ptp-v14-0-1511ffd4c362@linutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2557254"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:brtrOoS4t/WsQj85z8ckUcrajlU= sha256:RiythtXKXFtR8lZAYwqVHeHl3UszQza7YKO0Nmvv1qU=
	sha1:u6Mqfzfv9ZJ08zIlYR2EqxfsGb4= sha256:6D7g8SzIr45ydJ2mpNDzbL9jhyv7S5bNJcD7iysAfwo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id A84091179F0; Thu,  3 Dec 2026 20:45:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.299
X-Spam-Status: No, score=-3.299 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=linutronix.de header.b=HaZ+G3UQ; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=A06U1Wmj
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id G9IlJ0QtCn57;
	Thu,  3 Dec 2026 20:45:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-376795-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linutronix.de
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id D71B11179BD; Thu,  3 Dec 2026 20:45:10 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id D4CE32216F; Thu,  3 Dec 2026 17:45:04 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796319899;
	b=dFYIVJLwwRLap/Pbi0R/MulWfDjT4XCC1Wd0hF9k2ogehwDKGz2L1wxpeki3elLCTdc0
	 98Gi+Axdl4PtR0IEmHBJBqW2dt9S88TJDSzvmMVkCRtF0w0lS+uh9tVjzuUJGv2Ykh/kD
	 axMznPv7pvNfi4Xp9dO96z16YYa1f5sn/zFDAfoqaSPFfyFpnjOMdU/FwQL1NdOaM0X1a
	 FRT2s8petCTVUZhtpSCfQb4xolATTdXpUE5W7i+95dOiEoccjTKinLLQT7qrdq1OVn8Wx
	 5WH//izHdfBugaFDnr02IveRDo4hJoUKlmjE3aCeet1ow/66JhvhMmytXhUqRTb+IFQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319899;
	h=X-Original-To:Received:DMARC-Filter:From:DKIM-Signature:
	 DKIM-Signature:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=vMhz5wBioPFyCYnw40TBhwFfNGE+6yx/y9Xk7tpAx9A=;
	b=e8emyZGM2xvH9C3JczHkldkM+iRNC2f06GtxdGvajnAnkmmr67s5QnW5MyTUP/tQbYAT
	 U4MW8gbq0gnqu9Os3jm0ofFqsJMqgPhYMkOY21vvfFlPSD4pe976MVzvTYqp0tyh2qdlT
	 3uiLTWt1FG7PC3RO7rBMS5dnIkKxUgXg0N9/XghnWGEqyQQPZk851oK4wmi4eMF9KOgDy
	 VhUtXLpeMdrR0yVguEJogID6cKtiMH5ajLlItjtlGTSdAZqdUmeLiHRNiJ4l0iQyVLhZ1
	 gL4sqZvgiVJl8DwlHjUvsmF2+qLSWoVlx6mLcfQb6Wu/dcqusJVbut8y1bv/MOZuG0g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=HaZ+G3UQ;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=A06U1Wmj;
	dmarc=pass header.from=linutronix.de;
	spf=pass smtp.mailfrom=linutronix.de;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 302FE606A33F;
	Thu,  3 Dec 2026 17:44:59 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=HaZ+G3UQ;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=A06U1Wmj
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796319898;
	b=oQg50d+s6XW/mTCdEDk2ql69K52HrcsNzRGuFB647cGf03ZbHVRVf5Ccat1Q4uvQrZ5l
	 iW277NgPZDi64g0aU/qFEvOQtj3GG/za9oKFjDrlROALQkWCPpSACT5xsKzamof87PKUS
	 J7bHwsJghkKGjWlg17ZfjP//dBXVqqagvbmclZbprLKYOKGxr7AyPoQicvS1lyq9DI0ae
	 5XF6ninj6zcztIV9dWnsUM6L14bxTJh+3GQE1NZOB1qsJi99MrrDBBWctekJxMpsr0Zyd
	 8dZ20+mpUkdy88pGNyoQkpYYPofchiUi6hlkNm/Qga3H4KNN3FTmjpu6znhFXnl+R4w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319898;
	h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:To:Cc:Subject:Date:
	 Message-ID:In-Reply-To:References:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=vMhz5wBioPFyCYnw40TBhwFfNGE+6yx/y9Xk7tpAx9A=;
	b=Wq8Xn1kr1msYc8LYrxIq1AfGCLRol2b5mFPNCoWxZh+p2pOk8mVIrHsyAxp3lQjWjA1n
	 8sg1yDg77gDN1VXi0Ep5DqrInZXX+IAroGMs3jslo7Z1/fCDwTXSDN9x7EcT9vVYA+y+4
	 FR0ZH7A44PEBm/9+sXoqbr45Vfc6GYUSZUKlRXUkSfQEgVuqlOMuF0ZIMdpJTCZG+p2jd
	 e7zwUSinsYKJ1OiXn7+Hfk4GMSK/Znfj6hNdR4ZDA+AuZk8bToi63b70JZ5dyRiGmZNrw
	 2xUx0iYAmt2Gjw2PjnuwaMAxxOI8/goTlWu6EtKd7NoNatGJzjDR3dBVPfpakBBny0w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linutronix.de;
	spf=pass smtp.mailfrom=linutronix.de;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=HaZ+G3UQ;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=A06U1Wmj;
	arc=none smtp.remote-ip=193.142.43.55
X-Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4D98606A32D
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 17:44:57 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4D98606A32D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020; t=1796319896;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=vMhz5wBioPFyCYnw40TBhwFfNGE+6yx/y9Xk7tpAx9A=;
	b=HaZ+G3UQJa5bSwZnkJTbh6OVic/Wxk7C+f/xNuI2oVQuRlzj/+HgdOV0qAB1Rr27Fb+Ibv
	x4t7wwJchzGLu6tSVKFgLBn1tvr5FLEN/YyQHg9HOvsnhUzMhE+RKMAPF5nvQfgM+NMs1s
	hIYQuhkgccDj8NkkHy1GOCPjPLQq4byDZHPPtzz0AvB2Tt99CksgeCiSrDEHi3ETuk381h
	u5hl0mRvVw90xUJzOT4Z2D1i6iX65gQ6GiWecwtqLgkCcDysz+h8e8IJ9wfcwqhhPr5cwE
	A9kpTZAkQP7kFkQzOl/+2ewKc7puBBDzA66X0T7H/3EfiJNHVLS8e6Wd1jqb5g==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1796319896;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=vMhz5wBioPFyCYnw40TBhwFfNGE+6yx/y9Xk7tpAx9A=;
	b=A06U1WmjPpti48WZRl5ey7SF0vHSW/9Zlz3jSmMc/pamKAxj/hugbnYQUuLfwK+QCWDpZk
	RgISO0wH9ReWKMBA==
X-Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"(JC), Jayachandran" <j-rameshbabu@ti.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Danish Anwar <danishanwar@ti.com>,
	Daolin Qiu <d-qiu@ti.com>,
	"David S. Miller" <davem@davemloft.net>,
	Felix Maurer <fmaurer@redhat.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Neelima Muralidharan <neelima@ti.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Praneeth Bajjuri <praneeth@ti.com>,
	Pratheesh Gangadhar TK <pratheesh@ti.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Simon Horman <horms@kernel.org>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Daniel Machon <daniel.machon@microchip.com>,
	Eric Dumazet <edumazet@kernel.org>
X-In-Reply-To: <20261203-hsr_ptp-v14-0-1511ffd4c362@linutronix.de>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list