Skip to content

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 !

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.

Project coverage is 81.62%. Comparing base (92925da) to head (7bf9906).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
scapy/layers/ptp_v2.py 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4640      +/-   ##
==========================================
+ Coverage   80.71%   81.62%   +0.90%     
==========================================
  Files         359      360       +1     
  Lines       86052    86253     +201     
==========================================
+ Hits        69461    70404     +943     
+ Misses      16591    15849     -742     
Files with missing lines Coverage Δ
scapy/layers/ptp_v2.py 0.00% <0.00%> (ø)

... and 25 files with indirect coverage changes

@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.

ShortField("sequenceId", 0),
ByteEnumField("controlField", 0, _control_field),
ByteField("logMessageInterval", 0),
ConditionalField(BitField("originTimestamp_seconds", 0, 48),
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also use BitScalingField here. This would allow you to add a unit to the value for the representation to the user. If you think that's useful. But since the field names already contain the unit, it's not really necessary.

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)
4 participants