From: Stephen Hemminger <stephen@networkplumber.org>
To: Rajesh Kumar <rajesh3.kumar@intel.com>
Cc: dev@dpdk.org, bruce.richardson@intel.com, aman.deep.singh@intel.com
Subject: Re: [RFC v1 0/4] introduce PTP protocol library and software relay example
Date: Mon, 27 Apr 2026 16:42:30 -0700 [thread overview]
Message-ID: <20260427164230.6e015396@phoenix.local> (raw)
In-Reply-To: <20260428010117.692626-1-rajesh3.kumar@intel.com>
On Tue, 28 Apr 2026 06:31:02 +0530
Rajesh Kumar <rajesh3.kumar@intel.com> wrote:
> This series introduces a new DPDK library (lib/ptp) for IEEE 1588-2019
> PTP protocol packet processing and a companion example application
> (ptp_tap_relay_sw) that demonstrates its usage.
>
> Motivation
> ----------
> Several DPDK applications need to classify and manipulate PTP packets
> (e.g. ptpclient, ptp_tap_relay, custom Transparent Clocks). Today each
> application re-implements its own PTP header parsing and correctionField
> handling. A shared library avoids duplication and provides a tested,
> standards-compliant foundation.
>
> Library: lib/ptp
> ----------------
> The library provides:
> - PTP header structures (IEEE 1588-2019 common header, timestamp,
> port identity)
> - Packet classification: rte_ptp_classify() detects PTP over L2
> (EtherType 0x88F7), VLAN-tagged L2, and UDP/IPv4 (ports 319/320)
> - Header access: rte_ptp_hdr_get() returns a pointer to the PTP
> header inside an mbuf
> - Inline helpers: correctionField manipulation (48.16 fixed-point),
> message type extraction, two-step flag check, timestamp conversion
> - Debug: rte_ptp_msg_type_str() for human-readable message names
The things I noticed were:
Do not use older PTP terminology master/slave; we fixed this in DPDK.
This would cause a NAK for me, and checkpatch would flag it.
AI had lots more to say...
Subject: Re: [RFC v1 0/4] introduce PTP protocol library and software relay example
Some review comments on this RFC. Overall direction (shared PTP
header+classification library) is good, but there are a couple of
correctness bugs in patch 1/4 that need to be fixed before this can
move out of RFC.
Patch 1/4: ptp: introduce PTP protocol library
==============================================
Error: flag bit positions wrong for the host-order representation
-----------------------------------------------------------------
+#define RTE_PTP_FLAG_TWO_STEP (1 << 1) /**< Two-step flag (bit 1) */
+#define RTE_PTP_FLAG_UNICAST (1 << 2) /**< Unicast flag */
+#define RTE_PTP_FLAG_LI_61 (1 << 0) /**< Leap indicator 61 */
+#define RTE_PTP_FLAG_LI_59 (1 << 1) /**< Leap indicator 59 (byte 1) */
+static inline bool
+rte_ptp_is_two_step(const struct rte_ptp_hdr *hdr)
+{
+ return (rte_be_to_cpu_16(hdr->flags) & RTE_PTP_FLAG_TWO_STEP) != 0;
+}
twoStepFlag and unicastFlag live in byte 0 of the wire flag field
(IEEE 1588-2019 Table 37). leap61/leap59 live in byte 1. After
rte_be_to_cpu_16(), byte 0 of the wire ends up in the upper 8 bits of
the host value, so:
TWO_STEP needs to be (1 << 9), not (1 << 1)
UNICAST needs to be (1 << 10), not (1 << 2)
LI_61 stays at (1 << 0)
LI_59 stays at (1 << 1)
As written, rte_ptp_is_two_step() always returns false for any real
two-step Sync from the wire, which silently breaks any Transparent
Clock or Boundary Clock built on this library. TWO_STEP and LI_59
also collide on (1 << 1), which by itself shows the macro layout
isn't right.
Worth adding a unit test that constructs a packet with twoStepFlag
set and checks that the helper returns true.
Error: QinQ classification path is unreachable for standard QinQ
----------------------------------------------------------------
In ptp_hdr_find(), the VLAN block is only entered when the outer
EtherType is RTE_ETHER_TYPE_VLAN (0x8100):
+ if (ether_type == RTE_ETHER_TYPE_VLAN) {
...
+ /* Double-tagged VLAN (QinQ) */
+ if (ether_type == RTE_ETHER_TYPE_QINQ ||
+ ether_type == RTE_ETHER_TYPE_VLAN) {
Standard 802.1ad QinQ uses outer S-tag 0x88A8 (RTE_ETHER_TYPE_QINQ)
followed by a C-tag 0x8100, then the payload EtherType. Packets with
the typical S-tag outer never enter the VLAN branch at all, so the
"QinQ supported" claim in the cover letter and the prog_guide does
not match what the code does.
Either accept 0x88A8 as an entry point to the VLAN parser, or drop
the QinQ claim from the documentation.
Warning: VLAN-tagged PTP-over-UDP not handled
---------------------------------------------
The classifier handles plain L2, VLAN-L2, IPv4-UDP, and IPv6-UDP, but
there is no path for VLAN -> IPv4/IPv6 -> UDP -> PTP. This is a
common deployment pattern. Not fatal, but please mention it in the
limitations list if it's intentional.
Warning: signed left shift in rte_ptp_add_correction()
------------------------------------------------------
+ int64_t cf = (int64_t)rte_be_to_cpu_64(hdr->correction);
+ cf += (residence_ns << 16);
residence_ns is int64_t. Left-shift of a signed value where the
shifted value is not representable in the result type is undefined
behaviour (C11 6.5.7p4). In the relay example residence_ns is
computed from (uint64_t)tx_ts - (uint64_t)rx_ts cast to int64_t, so
clock noise or a tx_ts < rx_ts edge case turns this negative. GCC
and clang happen to produce arithmetic shift, but please make it
well-defined:
cf += (int64_t)((uint64_t)residence_ns << 16);
or just multiply by (1LL << 16).
Same issue, lower severity, in rte_ptp_correction_ns():
+ return (int64_t)rte_be_to_cpu_64(hdr->correction) >> 16;
Right-shift of a negative signed value is implementation-defined
(not UB), but a divide expresses intent more clearly.
Info: include order
-------------------
+#include "rte_ptp.h"
+
+#include <eal_export.h>
eal_export.h is conventionally included with the other system /
EAL headers, before the local rte_ptp.h.
Info: overlap with examples/ptpclient
-------------------------------------
ptpclient.c defines its own struct ptp_header / ptp_message. Since
this series adds a shared library, it would be worth converting
ptpclient as part of the series (or in a follow-up) to avoid
duplicating the same definitions in-tree.
Patch 2/4: doc: add PTP library programmer's guide
==================================================
Just the QinQ wording carryover - prog_guide claims "Double VLAN
(QinQ) + EtherType 0x88F7" but the code as posted only handles
0x8100/0x8100 nesting. Update either the code or the doc to match.
Patch 3/4: examples/ptp_tap_relay_sw
====================================
Warning: promiscuous enable failure on PHY port is not fatal
------------------------------------------------------------
+ ret = rte_eth_promiscuous_enable(port);
+ if (ret != 0)
+ LOG_ERR("Failed to enable promiscuous on port %u", port);
+
+ return 0;
For the PHY port this is what lets the relay see the PTP multicast
group (01:1B:19:00:00:00 / 01:80:C2:00:00:0E). If it fails, the
relay starts up looking healthy but never receives anything. At
least exit on failure for the PHY port, or enable allmulticast
explicitly so the failure mode is visible.
Info: per-burst single timestamp
--------------------------------
A single rx_ts and tx_ts is taken for the whole burst. At
logSyncInterval=-4 (16 packets/sec) bursts are essentially always 1
packet so this doesn't matter, but at higher rates the early
packets in a burst get under-corrected and the late ones
over-corrected by up to a burst's worth of poll latency. Worth
calling out in the comment block; the test results already imply
single-packet bursts.
Info: missing release notes for new library
-------------------------------------------
Targeted at 26.07 per RTE_EXPORT_EXPERIMENTAL_SYMBOL. A new library
should add an entry under "New Features" in
doc/guides/rel_notes/release_26_07.rst.
next prev parent reply other threads:[~2026-04-27 23:42 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 1:01 [RFC v1 0/4] introduce PTP protocol library and software relay example Rajesh Kumar
2026-04-27 23:42 ` Stephen Hemminger [this message]
2026-04-28 16:52 ` Kumar, Rajesh
2026-04-28 1:01 ` [RFC v1 1/4] ptp: introduce PTP protocol library Rajesh Kumar
2026-04-27 23:01 ` Stephen Hemminger
2026-04-28 16:50 ` Kumar, Rajesh
2026-04-28 1:01 ` [RFC v1 2/4] doc: add PTP library programmer's guide Rajesh Kumar
2026-04-28 1:01 ` [RFC v1 3/4] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-04-28 1:01 ` [RFC v1 4/4] doc: add PTP software relay sample app guide Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 0/6] introduce PTP protocol library and software relay Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-04-28 22:28 ` [RFC v2 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-04-29 15:37 ` [RFC v2 0/6] introduce PTP protocol library and software relay Stephen Hemminger
2026-05-04 3:49 ` Kumar, Rajesh3
2026-05-04 9:17 ` [RFC v3 " Rajesh Kumar
2026-05-04 9:17 ` [RFC v3 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-05-04 9:17 ` [RFC v3 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-05-04 9:17 ` [RFC v3 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-05-04 9:17 ` [RFC v3 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-05-04 9:17 ` [RFC v3 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-05-04 9:17 ` [RFC v3 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-04 17:56 ` [RFC v3 0/6] introduce PTP protocol library and software relay Stephen Hemminger
2026-05-05 16:38 ` [RFC v4 " Rajesh Kumar
2026-05-05 16:38 ` [RFC v4 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-05-05 16:38 ` [RFC v4 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-05-05 16:38 ` [RFC v4 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-05-05 16:38 ` [RFC v4 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-05-05 16:38 ` [RFC v4 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-05-05 16:38 ` [RFC v4 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-06 15:41 ` [RFC v5 0/6] introduce PTP protocol library and software relay Rajesh Kumar
2026-05-06 15:41 ` [RFC v5 1/6] ptp: introduce PTP protocol library Rajesh Kumar
2026-05-06 11:02 ` Morten Brørup
2026-05-07 4:45 ` Kumar, Rajesh
2026-05-06 15:41 ` [RFC v5 2/6] doc: add PTP library programmer's guide Rajesh Kumar
2026-05-06 15:41 ` [RFC v5 3/6] examples/ptp_tap_relay_sw: add software PTP relay example Rajesh Kumar
2026-05-06 15:41 ` [RFC v5 4/6] doc: add PTP software relay sample app guide Rajesh Kumar
2026-05-06 15:41 ` [RFC v5 5/6] app/test: add PTP library unit tests Rajesh Kumar
2026-05-06 15:41 ` [RFC v5 6/6] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-06 15:45 ` [RFC v5 0/6] introduce PTP protocol library and software relay Stephen Hemminger
2026-05-07 10:13 ` [PATCH v6 0/4] PTP protocol support in lib/net Rajesh Kumar
2026-05-07 10:13 ` [PATCH v6 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions Rajesh Kumar
2026-05-07 10:13 ` [PATCH v6 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay Rajesh Kumar
2026-05-07 10:13 ` [PATCH v6 3/4] doc: update release notes for PTP protocol library Rajesh Kumar
2026-05-07 10:13 ` [PATCH v6 4/4] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-07 13:45 ` [PATCH v7 0/4] IEEE 1588 PTP v2 protocol support in lib/net Rajesh Kumar
2026-05-07 13:45 ` [PATCH v7 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions Rajesh Kumar
2026-05-07 15:27 ` Morten Brørup
2026-05-09 17:57 ` Kumar, Rajesh
2026-05-07 13:45 ` [PATCH v7 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay Rajesh Kumar
2026-05-07 13:45 ` [PATCH v7 3/4] doc: update release notes for PTP protocol library Rajesh Kumar
2026-05-07 13:45 ` [PATCH v7 4/4] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
2026-05-09 23:25 ` [PATCH v8 0/4] IEEE 1588 PTP v2 protocol support in lib/net Rajesh Kumar
2026-05-09 23:25 ` [PATCH v8 1/4] lib/net: add IEEE 1588 PTP v2 protocol header definitions Rajesh Kumar
2026-05-09 23:25 ` [PATCH v8 2/4] examples/ptp_tap_relay_sw: add PTP software transparent clock relay Rajesh Kumar
2026-05-09 23:25 ` [PATCH v8 3/4] doc: update release notes for PTP protocol library Rajesh Kumar
2026-05-09 23:25 ` [PATCH v8 4/4] examples/ptpclient: use shared PTP library definitions Rajesh Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260427164230.6e015396@phoenix.local \
--to=stephen@networkplumber.org \
--cc=aman.deep.singh@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=rajesh3.kumar@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.