net/nat: Let ICMP echo id zero be a valid NAT id.#18812
net/nat: Let ICMP echo id zero be a valid NAT id.#18812acassis merged 1 commit intoapache:masterfrom
Conversation
Make nat_port_select() return an error code and report the selected external port through an output parameter. This separates selection failure from the valid ICMP echo identifier value zero, so outbound NAT entry creation no longer rejects ICMP echo requests that use id zero. Signed-off-by: Shunchao Hu <ankohuu@gmail.com>
acassis
left a comment
There was a problem hiding this comment.
@ankohuu Nice finding!!!
Could you please update the Documentation https://nuttx.apache.org/docs/latest/components/net/nat.html to include your test?
It seems they have a similar test there, but yours looks a little different, and there are only vague examples without further explanation about the tests.
It should be nice to give more details for beginners to understand the whole process.
|
Hi @acassis ,
I also think the current documentation already has a fair amount of tech detail, but it may be made clearer. Can I handle this rst update in a separate patch? |
Normally we suggest to include the Documentation in the same PR, history shows that mostly the time people forget about it after the main PR is merged, just an example here: #17033 (comment) But I will trust that you will do it and I will remove the Change Request. |
|
Big thank you for your help and for all your contributions to NuttX. In fact, I was only trying to express two points:
That is why I planned to proceed in these two steps. From my perspective, the above is not a request that should delay the document changes that are already needed for this PR. P.S. I do have some practical difficulty in updating the documentation immediately. I need a bit of time to read the current documents carefully and understand the existing style and conventions I should follow. :) |
Hi @ankohuu perfect! If you think your example is already covered there, then I think we just need to make the document more clearer and explain to the details to let new users to get a better understanding. Having the commands there is already a good thing, for some commands and features we don't have anything. I think Documentation is a big gap of the NuttX project |
Summary
ICMP echo identifiers are 16-bit values defined by
RFC 792, and zero isa valid identifier value. NAT currently uses nat_port_select() return
value zero to mean port selection failure, which makes ICMP echo id zero
ambiguous with failure.
https://datatracker.ietf.org/doc/html/rfc792
Change nat_port_select() to return a status code and pass the selected
external port or ICMP identifier through an output parameter. This lets
NAT preserve and create entries for ICMP echo id zero while keeping real
selection failures separate.
Impact
bugfix
Testing
The issue was identified while I try to set up a NAT environment using the NuttX simulator. The test setup consists of a sim instance with two network interfaces, both backed by TAP devices.
Nuttx SIMulator:
Linux:
With the current port selection algorithm, a local ID of 0 is the most likely to result in an external ID of 0.
Testing logs before change:
Testing logs after change: