Skip to content

Add comprehensive SCTP protocol support#2031

Open
jordanvrtanoski wants to merge 1 commit into
seladb:devfrom
jordanvrtanoski:sctp
Open

Add comprehensive SCTP protocol support#2031
jordanvrtanoski wants to merge 1 commit into
seladb:devfrom
jordanvrtanoski:sctp

Conversation

@jordanvrtanoski

Copy link
Copy Markdown

Implement full SCTP (Stream Control Transmission Protocol) layer with support for:

Core Protocol (RFC 9260):

  • All standard chunk types (DATA, INIT, INIT-ACK, SACK, HEARTBEAT, ABORT, SHUTDOWN, ERROR, COOKIE-ECHO, COOKIE-ACK, ECNE, CWR, SHUTDOWN-COMPLETE)
  • CRC32c checksum calculation and validation
  • Chunk and parameter action bits helpers
  • Bundling validation per RFC 9260
  • Host Name Address deprecation detection

Extensions:

  • AUTH chunk with HMAC-SHA1/SHA256 computation and verification (RFC 4895)
  • ASCONF/ASCONF-ACK for dynamic address reconfiguration (RFC 5061)
  • RE-CONFIG for stream reconfiguration (RFC 6525)
  • FORWARD-TSN for partial reliability (RFC 3758)
  • I-DATA and I-FORWARD-TSN for message interleaving (RFC 8260)
  • PAD chunk (RFC 4820)
  • NR-SACK experimental support (IANA registered, draft-based)
  • Zero Checksum Acceptable parameter (RFC 9653)

Additional features:

  • Parameter iterators for INIT, RE-CONFIG, and ASCONF chunks
  • Error cause iterator for ABORT/ERROR chunks
  • Extended PPID enum with 70+ protocol identifiers from IANA registry
  • Chunk creation APIs for building SCTP packets

Includes 72 test cases covering parsing, creation, and validation.

@Dimi1010 Dimi1010 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the submission. :)

Comment thread Packet++/src/SctpLayer.cpp
/// @class SctpChunk
/// A wrapper class for SCTP chunks. This class does not create or modify chunk records,
/// but rather serves as a wrapper and provides useful methods for retrieving data from them
class SctpChunk

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is essentially a view class right?

Somewhat thinking out loud but can we split this class into several view subclasses for each chunk type?
Currently the class seems a bit unwieldy with all the different chunk type methods?

Can we instead have:

  • SctpChunk - Common Methods (getChunkType(), etc)
    • SctpDataChunk - A data chunk.
    • SctpInitChunk - Init/InitAck chunk.
    • ScptSackChunk - Sack chunk.
    • ...

Since the chunk objects only hold a pointer, they can be treated as value objects, similar to std::string_view.

class SctpChunk
{
  /* Generic chunk methods */
  SctpChunkType getChunkType() const;
}

class SctpDataChunk : public SctpChunk {
  SctpDataChunk(SctpChunk chunk) { /* validate correct chunk type */ }

  /* Data specific chunk accessors */
}

// Other chunk types.

The inheritance in the above example is mostly for code reuse of the common methods, not for polymorphism, therefor the lack of any virtual methods.

Do you think that would work or is there something I am missing?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That's good observation, let me see what it takes to refactor it to be more aligned to OO principles.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The reason the SctpChunk is designed as a monolith class in the first pace is to avoid the heap overhead that inheritance would create, as well as it's impact on the cache as the objects in the hierarchy have bad locality.

Having the chunks as views classes on the SctpChunk will address my original performance concerns, so I will refactor the code based on the suggestion.

@jordanvrtanoski jordanvrtanoski marked this pull request as draft December 1, 2025 03:08
@jordanvrtanoski

Copy link
Copy Markdown
Author

Converted the PR to draft to address the proposed refactoring.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you please add the original pcap file used for these .dat files?

@codecov

codecov Bot commented Dec 1, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.41284% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.99%. Comparing base (6ba29cf) to head (9912323).

Files with missing lines Patch % Lines
Packet++/src/IPv4Layer.cpp 50.00% 3 Missing ⚠️
Packet++/src/IPv6Layer.cpp 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2031      +/-   ##
==========================================
+ Coverage   82.72%   82.99%   +0.26%     
==========================================
  Files         332      335       +3     
  Lines       59807    64735    +4928     
  Branches    12591    13560     +969     
==========================================
+ Hits        49475    53724    +4249     
- Misses       8947    10138    +1191     
+ Partials     1385      873     -512     
Flag Coverage Δ
23.11.6 6.79% <0.00%> (-0.49%) ⬇️
24.11.5 6.79% <0.00%> (-0.52%) ⬇️
25.11.1 6.74% <0.00%> (-0.58%) ⬇️
alpine320 76.52% <63.63%> (-0.34%) ⬇️
fedora42 76.15% <63.63%> (-0.29%) ⬇️
macos-14 82.12% <96.22%> (-0.15%) ⬇️
macos-15 82.11% <96.22%> (-0.15%) ⬇️
mingw32 70.07% <57.14%> (-1.04%) ⬇️
mingw64 70.09% <57.14%> (-0.93%) ⬇️
npcap ?
rhel94 75.99% <63.63%> (-0.27%) ⬇️
ubuntu2204 76.01% <63.63%> (-0.26%) ⬇️
ubuntu2204-icpx 59.22% <50.00%> (-0.18%) ⬇️
ubuntu2404 76.27% <63.63%> (-0.30%) ⬇️
ubuntu2404-arm64 76.23% <63.63%> (-0.34%) ⬇️
ubuntu2604 76.17% <63.63%> (-0.34%) ⬇️
unittest 82.99% <95.41%> (+0.26%) ⬆️
windows-2022 84.97% <50.00%> (-0.73%) ⬇️
windows-2025 85.00% <50.00%> (-0.71%) ⬇️
winpcap 85.00% <50.00%> (-0.91%) ⬇️
xdp 54.43% <28.57%> (+1.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@jordanvrtanoski jordanvrtanoski force-pushed the sctp branch 5 times, most recently from 15ee3a5 to 5a4d9c5 Compare December 8, 2025 02:00
@seladb

seladb commented May 16, 2026

Copy link
Copy Markdown
Owner

@jordanvrtanoski this PR is opened for a long time, are you planning to continue working on it? Otherwise we can close it for now

@jordanvrtanoski

Copy link
Copy Markdown
Author

I will rebase it and prepare for merge, as I see all concerns ware addressed.

@seladb

seladb commented May 27, 2026

Copy link
Copy Markdown
Owner

I will rebase it and prepare for merge, as I see all concerns ware addressed.

Thanks @jordanvrtanoski ! Can you please make sure CI passed as well?

@jordanvrtanoski

Copy link
Copy Markdown
Author

Sure

@jordanvrtanoski jordanvrtanoski marked this pull request as ready for review May 27, 2026 14:49
@jordanvrtanoski jordanvrtanoski force-pushed the sctp branch 3 times, most recently from d0884b1 to 4415715 Compare May 28, 2026 20:17
@jordanvrtanoski

jordanvrtanoski commented May 28, 2026

Copy link
Copy Markdown
Author

@seladb, I have problems in my github runner with actions/setup-java@v5 test. I am getting "Error: Java setup process failed due to: error code: 520". The project is build fine but the test is failing as the JDK can not be set up properly. Have you faced this issue? This is blocking Android tests, all other tests are green. Any tips how to proceed?

@jordanvrtanoski

Copy link
Copy Markdown
Author

After multiple retries, one of the Android test passed, but the other 3 are still failing with the same issue, I assume the repository had reached some type of limitation.

@jordanvrtanoski

Copy link
Copy Markdown
Author

After a few more tries, all the checks on my repo passed!

Implement full SCTP (Stream Control Transmission Protocol) layer with support for:

Core Protocol (RFC 9260):
- All standard chunk types (DATA, INIT, INIT-ACK, SACK, HEARTBEAT, ABORT,
  SHUTDOWN, ERROR, COOKIE-ECHO, COOKIE-ACK, ECNE, CWR, SHUTDOWN-COMPLETE)
- CRC32c checksum calculation and validation
- Chunk and parameter action bits helpers
- Bundling validation per RFC 9260
- Host Name Address deprecation detection

Extensions:
- AUTH chunk with HMAC-SHA1/SHA256 computation and verification (RFC 4895)
- ASCONF/ASCONF-ACK for dynamic address reconfiguration (RFC 5061)
- RE-CONFIG for stream reconfiguration (RFC 6525)
- FORWARD-TSN for partial reliability (RFC 3758)
- I-DATA and I-FORWARD-TSN for message interleaving (RFC 8260)
- PAD chunk (RFC 4820)
- NR-SACK experimental support (IANA registered, draft-based)
- Zero Checksum Acceptable parameter (RFC 9653)

Additional features:
- Type-safe chunk views: Zero-overhead wrapper classes for all 24 chunk types, enabling type-safe field access without
  runtime overhead
- Parameter iterators for INIT, RE-CONFIG, and ASCONF chunks
- Error cause iterator for ABORT/ERROR chunks
- Extended PPID enum with 70+ protocol identifiers from IANA registry
- Chunk creation APIs for building SCTP packets

Includes 91 test cases covering parsing, creation, and validation.
@jordanvrtanoski

Copy link
Copy Markdown
Author

@seladb ready to merge

@Dimi1010 Dimi1010 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well. There are some long files here. I did a first pass review. I will probably do another pass later, tho. I am really liking how the view classes turned out. I have one comment about the return type of pointers from them tho. The other things I looked at LGTM.


PS: @jordanvrtanoski if you make further edits to this, can you please not force push. It makes it really hard to find the edits since it deletes the old commits. It will all get squashed on merge, so it doesn't matter for the main branch, but it makes it easier to track changes during the review process.

Comment on lines +2358 to +2363
// Cannot add INIT, INIT-ACK, or SHUTDOWN-COMPLETE to a packet with existing chunks
if (chunkType == SctpChunkType::INIT || chunkType == SctpChunkType::INIT_ACK ||
chunkType == SctpChunkType::SHUTDOWN_COMPLETE)
{
return false;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Perhaps move this condition above the O(N) while loop?

size_t getTotalSize() const;

/// @return Pointer to chunk value/payload (after the 4-byte header)
uint8_t* getValue() const;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it be better to return uint8_t const*?
Currently the returned buffer can be mutated, but I am not sure if that is intended behaviour.

PS: The question also applies for all other view types that return pointer to internals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants