🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26532

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

#26532
From: Sebastian Andrzej Siewior
Date: Thu, 03 Dec 2026 17:44
102 lines
13613 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: <20261203-hsr_ptp-v14-4-1511ffd4c362@linutronix.de>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376794-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-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376794-linux-kernel-netdev=dewy.ru
From: bigeasy@linutronix.de (Sebastian Andrzej Siewior)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v14 4/8] hsr: Drop received PTP packets
Date: Thu,  3 Dec 2026 18:44:45 +0100
Organization: Usenet Network
Message-ID: <20261203-hsr_ptp-v14-4-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="2557303"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:mmFb/D74oEqEl4f1SsndMvoiP9E= sha256:qEOTbJkWdgaBVeIgPWKpkXbuKKRu4IyVfTBirFjUoZo=
	sha1:zRNqf7ahjskZnjxf/IBpRi4sFBE= sha256:bt7rk7LWsURdMRct5qNy0zs62vDztv76ckWFcICv+g0=
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 CF84F1179EF; 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.399
X-Spam-Status: No, score=-3.399 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.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=hIDUnAhf; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=J3knQ5hn
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 PRImbldlIkQr;
	Thu,  3 Dec 2026 20:45:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376794-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 7D5141179F4; Thu,  3 Dec 2026 20:45:13 +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 879B725F2E; Thu,  3 Dec 2026 17:45:03 +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=1796319898;
	b=5WEpokYLi5e/aiFPb1uFv/1/965lBc+ZEpxWNrFtAo/Xmy6d+UotQayt7JCtYcHoJORl
	 /1y8CiESyMy3XvOOs+8GGbtkbXmddFhbpvliYrOjHkmY00T4iCB8Ql7SUf7LELm0xByWQ
	 G767CEaYAwhNBQJMw5jfQbGMW1Q4tmgLAag8jwuKTobgk6dkSCsBPR5FJ+/Ru7P13MJD7
	 gow2oP/iT19v0kD+EbauPwFA9PgYmXjsZmi1ZBlDESOPIDeCO0vj2hc39Nq8RNpbd6Sbq
	 MpxC55fkVdg20bn8ifJbvIaZxu+I9cuEUXIWZd2ltKhrmG6iHksgTS0XHplrKfA2hUA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319898;
	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=u3zv5/i9uBmOXwfJkESO6mg5T5GORssGbo2HyRL6nlb8LdHutCkxlix0oiujPl53R8ys
	 lN8/rDqGa6CfIVNyg2RPK42exCUuhQ7j0EdcIlUGJiy5GxcFsCN4MgaUz+zNdZPMmySsx
	 2LZHpDUHmPLXAz15QJ05XOAneBJ1OnHFMJtP2SpjNzE1vuiBNpaDbwxo4tYAH4W9zmyfA
	 bAAxmFyZSdRe/bo3G98zTZgDR9CBTHyQ8n7PQ6H5TJhE5SiPR7rHXCFxoD90+uRTT8S+E
	 yOg16YQ5R+tKSbnarHse1fqjt5P0ypn9pXXjMQ5Vvoli4KU0DvSS/6Bu92leAJpuYsA==
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=hIDUnAhf;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=J3knQ5hn;
	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 AB1A7606A696;
	Thu,  3 Dec 2026 17:44:58 +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=hIDUnAhf;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=J3knQ5hn
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=1796319897;
	b=t1eNqbcGUSfVuAYdzmfbcvN2t4l/o0TKZIUgLYBUAkZMqR9MMipDXRyYV+ezVGFl+Lzx
	 +XWsnPQ2mKuiXLBz8yawaztbgniRGxGG+dvxexw56BEHnu8zEHP8nD3zdVloxLzYPByV+
	 bvqFA5d4Mi/lxsNvfoOcu6gT3ZiSOg8a/w3gF88uCA9TGJ1zUA/5IRmcPnb2L5keokqxq
	 wOjLsvMTNfmOJiQIw67dZSYUX9oCILFniu0CDskXHqMPfw5GJB37upoyHAdfd1PFZfApk
	 GgxC3zXJ/X3uIb/Rzbo1W4hJdEOBnFRsw2maT1nepX8ZrrJrIrd9f2wb9/Yvt2p/rzg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319897;
	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=zO9T0929w91KVf+httQ+X0RyujaMjXmbBIW81FSkN28xjjuc2NiGkKL2ea4RmT5zEeMy
	 rFaVRRlYc44jNkOowx/XKKJekgtmiaKaNWE2KKjtmT0IQXVK09eMi8nchB1QYlgUrgse/
	 3Brq2rCnbH3tW10T+rBO+QFVNtVLeFn+oFfodpf5Q7KKNTDg/7FlJzyRXrpEBQ0zUtYk+
	 M6PGtxKCctuORDXRz8ls3M2Rx3cSR/MCozX1D9IART8L9JMwW5MQvkKddAB+8WDYJlNbg
	 nn6YNDXO+DhgKO2csVmpDy+OqXj7XTIMSaEyP+G/24Ds2awAKiUHthVtTS4lZ/X6enw==
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=hIDUnAhf;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=J3knQ5hn;
	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 5AF27606A322
	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 5AF27606A322
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=1796319895;
	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=hIDUnAhfPtwISJaxmY0+WdZ9ILZLqvMtgg1z37OcVqSmTsddGChmVs9+QFCzQ+VT6uPkMJ
	wA2zk/WB1Y2uxVWy2YyWr63NSt0HTAlWZcbcz7Pj1IVIuSpkIW9Nj8voY1TEVYisCLdMeq
	zwCufSN+eqi2NTJjFDXuKII/12t8gXrPMM/MwZ0/w527ygMQZnERk9giCAGTemfaJWZFh4
	MQHd5dD7vDYKXqtIrOmGfV4tYDkRs+7Yod3Y2tzheFsYHTYI4hraI4Iz6UBbGssftsEHNf
	+/HyDqSCTJAAX4mtiwb7SgHwbW/Zn9epg22fLgJYm9u5P8WlKho8L1uFEX2l2Q==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1796319895;
	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=J3knQ5hnAy3d7Fm5ntavuJmlllO+IQ2D0Mazq11WxxuA0M2alluftGU+w7neSCkTKl4trJ
	4WrJV3zhguKEglBw==
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