Skip to content

Feature/add-ptp-protocol#4640

Merged
polybassa merged 2 commits intosecdev:masterfrom
satveerbrar:feature/add-ptp-protocol
Mar 17, 2026
Merged

Feature/add-ptp-protocol#4640
polybassa merged 2 commits intosecdev:masterfrom
satveerbrar:feature/add-ptp-protocol

Conversation

@satveerbrar
Copy link
Contributor

@satveerbrar satveerbrar commented Jan 12, 2025

@polybassa @gpotter2
Here is the draft PR to add PTP protocol.

Currently this includes basic PTP header and Sync message type.

Planned additions in future commits:

  1. post_build function to calculate and insert message length field.
  2. Classes for the remaining PTP message types.
  3. Unit tests

Let me know if I have followed the correct approach.

fixes #4637

@satveerbrar satveerbrar marked this pull request as draft January 12, 2025 08:12
Copy link
Member

@gpotter2 gpotter2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
A few comments. It's a good start !

@codecov
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.28%. Comparing base (2cb8101) to head (3764966).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
scapy/contrib/ptp_v2.py 83.33% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4640   +/-   ##
=======================================
  Coverage   80.27%   80.28%           
=======================================
  Files         375      376    +1     
  Lines       92480    92498   +18     
=======================================
+ Hits        74242    74258   +16     
- Misses      18238    18240    +2     
Files with missing lines Coverage Δ
scapy/contrib/ptp_v2.py 83.33% <83.33%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@satveerbrar satveerbrar marked this pull request as ready for review January 18, 2025 01:07
@satveerbrar satveerbrar force-pushed the feature/add-ptp-protocol branch from 4eb7a14 to 3c72f1a Compare January 18, 2025 01:23
@satveerbrar satveerbrar requested a review from gpotter2 January 18, 2025 01:26
@gpotter2 gpotter2 marked this pull request as draft February 22, 2025 14:46
@eyalitki
Copy link
Contributor

Hi, found this when going over the issues in the repository. I suggest you use the following logic I implemented way back during my thesis on IEEE 1588 security - eyalitki/ptpd@4e46fe9#diff-bf2c30fee47c7daecd502ee34e25bc6324ff333f293f9d539d3ec4277764acaf.

You can ignore the "encryption" fields as they were part of my thesis and weren't adopted by the IEEE 1588 security committee. Still, the layer implements all non-control messages + Announce, so it should become handy. It served me well in my python scripts for sending/receiving packets, so it is well tested (even if old).

I hereby grant full access rights for this code and its derivatives to be used as part of the Scapy repository in any way the maintainers of the repository deem to be fit. Enjoy.

polybassa
polybassa previously approved these changes Aug 25, 2025
@polybassa
Copy link
Contributor

@gpotter2 What do you think?

@gpotter2
Copy link
Member

Looks promising although it should be in contrib/ (I think). Unsure why it's marked as draft though

@satveerbrar satveerbrar marked this pull request as ready for review November 10, 2025 03:16
@satveerbrar
Copy link
Contributor Author

@gpotter2
Sorry, I was away from last couple months. I’ve just switched it from draft to ready for review.

@polybassa
Copy link
Contributor

@satveerbrar Could you please move the layer into contrib/

@polybassa polybassa self-assigned this Mar 4, 2026
@satveerbrar
Copy link
Contributor Author

@polybassa Moved it to contrib/

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an initial Scapy contrib implementation for Precision Time Protocol v2 (PTPv2) to address #4637, along with regression tests to validate basic parsing/field behavior.

Changes:

  • Introduces a new scapy.contrib.ptp_v2 layer with PTPv2 header fields, message-type-specific conditional fields, UDP bindings, and a post_build length fixup.
  • Adds a new UTS regression test suite covering haslayer/getlayer and dissection of several PTP message types from raw bytes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
scapy/contrib/ptp_v2.py New PTPv2 packet layer definition, conditional body fields, post_build message length handling, and UDP port bindings.
test/contrib/ptp_v2.uts New regression tests for PTP layer presence and dissection across multiple message types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@polybassa polybassa merged commit e986fbc into secdev:master Mar 17, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request for Support for Precision Time Protocol (PTPv2)

5 participants