phy: add RxToken::preprocess hook#1118
Conversation
Add optional preprocess method to RxToken trait for custom packet preprocessing before consumption. Default implementation is no-op. This enables use cases like pre-allocating TCP accept queue sockets in OS implementations. Signed-off-by: Weikang Guo <guoweikang@kylinos.cn>
fad8ccc to
543b652
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1118 +/- ##
=======================================
Coverage 81.27% 81.27%
=======================================
Files 81 81
Lines 24839 24841 +2
=======================================
+ Hits 20188 20190 +2
Misses 4651 4651 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I'm opposed to this implementation. The phy layer should not depend on anything from the upper layers. It's not fully clear to me what the intended final use of the feature is, but this seems like something that should be a part of the |
|
|
|
Adding it to If the problem is we want a TCP accept queue, we should simply add a TCP accept queue. How would it work, not sure. Maybe a new kind of TCP socket that only holds memory for N SYN packets, so the user can poll it for new connections, and to accept them they have to set up a "full" TcpSocket. |
This sounds reasonable to me, and it maps well to the underlying TCP reality. |
|
With SYN cookies, the new kind of socket wouldn't even need a user-provided queue. But that would require being able to deserialize a TCP socket in the |
|
I don't see a way to do this entirely without allocation—you'd need some sort of storage to make sure SYN cookies won't be forged, no? |
|
If that's just a cryptographic hash, the RNG it's seeded from can be stored on the stack if no hardware RNG is present. |
Motivation
When implementing a POSIX-like TCP server with
accept()semantics in an operating system using smoltcp, we need to pre-allocate TCP sockets when receiving SYN packets, before the packet reaches the protocol stack's normal processing flow.Currently, there is no clean way to intercept and analyze incoming packets before they are consumed by the Interface. This leads to either:
Proposed Solution
Add an optional
preprocessmethod to theRxTokentrait that allows users to inspect packet data and access the socket set before packet consumption.API Design
Use Case: TCP Accept Queue