🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24508

[PATCH net-next v13 4/8] hsr: Drop received PTP packets

#24508
From: Sebastian Andrzej Siewior
Date: Mon, 30 Nov 2026 08:52
102 lines
13496 bytes
Receiving PTP packets via the HSR interface does not make sense. The HSR
stack will forward one copy to the user and ignore the duplicate from
the other port. The PTP stack is however interested in both copies since
they will have different content (due to different processing times
within the HSR ring) and different timestamp information which is not
forwarded at all.

Forwarding a PTP packet by the HSR stack is undesired because the
forwarding takes time, it is not accounted in the packet and this makes
the outgoing PTP packet inaccurate and therefore useless.

Drop all received PTP packets. For the PRP configuration it is the
ether type, for HSR configuration it is the encapsulated protocol, that
is checked. A PTP stack that is doing PTP over a HSR network needs to
retrieve the PTP packet on the original slave interface where it was
received. The PTP packet is dropped with RX_HANDLER_CONSUMED meaning it
won't be visible by packet sockets bounded to protocol ETH_P_1588. It
works for sockets bound to ETH_P_ALL which is what linuxptp is doing.

L3 packets (PTP over UDP) is not considered because it is not part of
the HSR specification.

Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 net/hsr/hsr_slave.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
index 5274ba6dd36e6..a5b47f016abd7 100644
--- a/net/hsr/hsr_slave.c
+++ b/net/hsr/hsr_slave.c
@@ -23,6 +23,7 @@ bool hsr_invalid_dan_ingress_frame(__be16 protocol)
 
 static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
 {
+	struct hsr_ethhdr *hsr_ethhdr;
 	struct sk_buff *skb = *pskb;
 	struct hsr_port *port;
 	struct hsr_priv *hsr;
@@ -44,8 +45,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
 
 	if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) {
 		/* Directly kill frames sent by ourselves */
-		kfree_skb(skb);
-		goto finish_consume;
+		goto finish_free_consume;
 	}
 
 	/* For HSR, only tagged frames are expected (unless the device offloads
@@ -64,15 +64,28 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
 	skb_reset_mac_header(skb);
 	if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) ||
 	    protocol == htons(ETH_P_HSR)) {
-		if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN)) {
-			kfree_skb(skb);
-			goto finish_consume;
-		}
+		if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN))
+			goto finish_free_consume;
 
 		skb_set_network_header(skb, ETH_HLEN + HSR_HLEN);
 	}
 	skb_reset_mac_len(skb);
 
+	/* PTP packets are not supposed to be forwarded via HSR as-is. The
+	 * latency introduced by forwarding renders the time information
+	 * useless. Userland needs to capture the packet on the original
+	 * interface instead of hsr.
+	 */
+	if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) ||
+	    protocol == htons(ETH_P_HSR)) {
+		hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
+		if (hsr_ethhdr->hsr_tag.encap_proto == htons(ETH_P_1588))
+			goto finish_free_consume;
+	} else {
+		if (protocol == htons(ETH_P_1588))
+			goto finish_free_consume;
+	}
+
 	/* Only the frames received over the interlink port will assign a
 	 * sequence number and require synchronisation vs other sender.
 	 */
@@ -84,7 +97,10 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
 		hsr_forward_skb(skb, port, HSR_PT_NONE, false);
 	}
 
-finish_consume:
+	return RX_HANDLER_CONSUMED;
+
+finish_free_consume:
+	kfree_skb(skb);
 	return RX_HANDLER_CONSUMED;
 
 finish_pass:

-- 
2.55.0
Technical Details
Message-ID: <20261130-hsr_ptp-v13-4-598326208fc5@linutronix.de>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374038-linux-kernel-netdev=dewy.ru
References: <20261130-hsr_ptp-v13-0-598326208fc5@linutronix.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374038-linux-kernel-netdev=dewy.ru
From: bigeasy@linutronix.de (Sebastian Andrzej Siewior)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v13 4/8] hsr: Drop received PTP packets
Date: Mon, 30 Nov 2026 09:52:21 +0100
Organization: Usenet Network
Message-ID: <20261130-hsr_ptp-v13-4-598326208fc5@linutronix.de>
References: <20261130-hsr_ptp-v13-0-598326208fc5@linutronix.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1384155"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CkbI3o1RMWgClsQs2L1j/T9dwh8= sha256:Zs1MANRwYZC/z4hjB/s09fuZWFWA7EleV/BgCtcO2GQ=
	sha1:qBOCiNt2hAD5Etp7gQGCCB0et7M= sha256:j0H4SuCpXpHnvIwSIuaVxPKBECv6UKto6qihM010GpY=
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 10DDD125FD0; Mon, 30 Nov 2026 11:53:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.151
X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=3VdJb8eg; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=1kWHM7lB
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 UOi4wxokzYnJ;
	Mon, 30 Nov 2026 11:53:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374038-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 7E1E2125FD2; Mon, 30 Nov 2026 11:52:49 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 76600255C3; Mon, 30 Nov 2026 08:52:43 +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=1796028753;
	b=vj72Ew118xi6o1SRKgt/z5RkAl/ljlKb66q8D39Ekt1Wm0wzRbpzNJj/OLdjFeqYVVqw
	 PbHkIUYAR9WFE/1LhKJWRP8reJzvPuuJqMS9iZI2QP1I4dWE/w0HqA0lBevPJVLP/dYn/
	 V1BERnzOuhI/hz2rB8mIYva8sa8GtUqcTdpAO0YAd5cHOVnpFm6J79bHTrYi/ycx03v3J
	 rjY4uWcGTvSMnfTSwsoGyoll+00x+sNyXQe4q1cwkDMn20WpmeMws0k6LjVfYOZOdvrS9
	 wJWoBU//X2/utJEFs/biMx3TEzu0NUeiOj8teJubbZotsR8MFnvJHICt4ntbuKfi8rg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796028753;
	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=TxSFGvzroXMP1yCKj5gXKh91OPMqff9Hzouu/ZStk84=;
	b=PvihriGhT19JgxEE6d9E6JKvgdnOR1b0w9IpVLILKcas191os4jq06C+DIaESADqLmbG
	 F3FR4UN/p0PYti4Qz533nUNDXQ0wHDw3XUn6/QIknDB7XtYSGKdGYPKjSws4a+IcaQOS9
	 SNNtGL9LVLs3xTGxli1nSgyO4pVyuBf6tihG8JcJ4iRJOcaSclCowlsMK1aU1OCFB81A4
	 s2hAbkvvES9NfjJjpBTKpweQx/ZJaBkGyBFyUSji5nTznh0YYIKJsOHLnumiCC83W2QCV
	 iNYB0MHqssEh4dmYI5+09qzpDuDzU8+n+VBch7Mfkd0ymQV1ePRPgippd8FfXugY/fg==
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=3VdJb8eg;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=1kWHM7lB;
	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 0AA2B606A330;
	Mon, 30 Nov 2026 08:52:33 +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=3VdJb8eg;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=1kWHM7lB
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=1796028752;
	b=SGfLnFMxLM4dU5AbkeiWG91IVMcthE5PUs0QZC6EOe4XgUZydopobEdm/JeXPfH1bpQ6
	 ajgFu/JhULr7yIMD+drjIqA+Io7lUXSUYBPYLBhzofUpRpFTvRnXtYDDZinjhgfiZXwJS
	 MtFX56NoSvHjWbZg4kBu2If2afYZgVqIIlnoJNCzJB0SsV6R/fhAVU8mqqY0zsfrGU0cT
	 vPrzf+woNbnRbnfz+d704iky/rQndxRfNCqKGhATt/sMUCVrzsUHT3IWkDfjtSJeEk5LD
	 RKjUagwz+ikExs5RXJPIkwGa74MAsS84jV1ywsMz5VB/fcm6Co5bboZZH0GkubDcRBQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796028752;
	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=TxSFGvzroXMP1yCKj5gXKh91OPMqff9Hzouu/ZStk84=;
	b=Xk7A56NHKfrV6Ba4NNeKoNeIMuFpZh9nS72NGsMA8tMmtuPWKwvJPUITuoF4MMrPzlav
	 mrYIHWSTmVvZRLbzUt7mFjPPYbgU8lKmaXrJ0ruJ+Zm3ra5MXqfE2YC6214efiRa4mADO
	 aJfAbOuEdbhPBmsYijedb4QRwG91/fdwIsNjb/jRApIB17/dX9QlyAHPwN96azBj1pkGh
	 qF3bigtPT13nRW71nWHxLNIpeJmqKYQcVpLR/IUTAt5xol+zLOxq2s8aBliw695DoPOEU
	 onD83oHqbUjz+6fSwwqZZK/SwkxTm0ZDo7N8o7Eyt40S5kdS+4yiCnTL8CvFA/Ulrjg==
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=3VdJb8eg;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=1kWHM7lB;
	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 B2084606A686
	for <netdev@vger.kernel.org>; Mon, 30 Nov 2026 08:52:31 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B2084606A686
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=1796028750;
	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=TxSFGvzroXMP1yCKj5gXKh91OPMqff9Hzouu/ZStk84=;
	b=3VdJb8egMutWPk277aJPbI41MKSU6h5esVSFnvR+jNJMUrmLX/tEQak6eW3Us/i8nApO6n
	zIpBwMHIT2FQ0botMNO7dfGdoyueof9a8FOWZkV+6I8DQyrxsszOd+XWhOT8mrGVHMWKHc
	l0VaQOekvuCm20e/O0SPEGVZSXr9UfrBxlBjAB6gbUKzBEZN7Y5V0RYaSoO1VrkFproM7A
	nQIZYVK32a5aVNmrD0Mcxr8CbeSmpM04/6VI0Ne+Iuj3hIDkQq/tZS9OHxaVhkEI9ZRWsq
	mWEgeQdUV5GhnCTavpFIVXA1ZUho4mUQiouOv8DK4Ai+ejALppW5+8TP5qnYMw==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1796028750;
	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=TxSFGvzroXMP1yCKj5gXKh91OPMqff9Hzouu/ZStk84=;
	b=1kWHM7lBxeEOKO8zRqUJLsyLpvNqd6S024nODO6PSojMUcRFf79+B3JRYFEsCXoSloJG1g
	zcAN7Yy/1Y7+FNBg==
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: <20261130-hsr_ptp-v13-0-598326208fc5@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