-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
napt: Fixes and improvements (IDFGH-6861) #43
Conversation
Thanks for your contribution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes! LGTM in general
It would be nice to cover this in the test cases. Also, the current NAPT test suite fails (on compilation):
To run the lwip unit tests on host, please follow these steps: Lines 33 to 46 in 76303df
|
thanks for the review, all done. |
@rojer Thanks for the update! Seems like you forgot to revert the changes in
The port directory is present in the contrib repo. I'm sorry, running the CI locally hasn't been very straight-forward. Currently working on improvements for the upcoming branches using GitHub workflows (so contributors can easily check their work). You can temporarily use these workflows to test your changes, though it's very WIP and present only on my personal fork. Tried to pick your changes here, CI fails with the forgotten timeout changes, mentioned above. |
yes, you're right, forgot to commit that change. done.
ok, i cloned it and checked out STABLE-2_1_0_RELEASE but now check.h is missing:
|
ok, updated the branch. in addition to issues with my patch i had to fix two other unrelated C90/C99 issues that prevented code from building, i have no idea how it works on the CI but they are legit in C90 mode. tests are now passing:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for the update! just some minor nitpicks.
src/core/ipv4/ip4_napt.c
Outdated
|
||
#include "assert.h" | ||
#include "stdbool.h" | ||
#include "string.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick (same above)
#include "string.h" | |
#include <string.h> |
|
||
#define NO_IDX ((u16_t)-1) | ||
#define NT(x) ((x) == NO_IDX ? NULL : &ip_napt_table[x]) | ||
|
||
struct napt_table { | ||
#pragma GCC diagnostic push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally prefer using basic integer types to placing #pragma
's into generic lwip code. These directives apparently work in clang
, so okay with me, feel free to ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One correction, this won't compile in clang:
clang -DIP_FORWARD=1 -DIP_FORWARD=1 -DIP_NAPT=1 -DLWIP_ARCH_CC_H -include cc_esp_platform.h -DLWIP_NOASSERT_ON_ERROR -I/usr/include/check -I../../../../src/../test/unit -Wno-gnu-zero-variadic-macro-arguments -g -DLWIP_DEBUG -Wall -pedantic -Werror -Wparentheses -Wsequence-point -Wswitch-default -Wextra -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wc++-compat -Wwrite-strings -Wold-style-definition -Wcast-align -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Wunreachable-code -Wuninitialized -Wmissing-prototypes -Wredundant-decls -Waggregate-return -Wlogical-not-parentheses -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -Wdocumentation -Wno-documentation-deprecated-sync -I. -I../../.. -I../../../../src/include -I../../../ports/unix/port/include -c ../../../../src/core/ipv6/dhcp6.c
../../../../src/core/ipv4/ip4_napt.c:64:32: error: unknown warning group '-Wc90-c99-compat', ignored [-Werror,-Wunknown-warning-option]
#pragma GCC diagnostic ignored "-Wc90-c99-compat" /* To allow u8_t bit fields */
^
1 error generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so when compiling with the extra bitchy flags GCC complains about the bitfield underlying type being uint8 instead of a unsigned (or signed) int, as per standard. fine. but in practice it works and i don't feel comfortable about adding extra 3 bytes to the size of the struct just to maintain purity.
clang doesn't complain about it, so i ifdefed this out for it, now it builds.
Nice, that you succeeded in running the tests eventually! Still some issues in the debug prints though:
Please note, that the test with debug logs are not executed in the CI: Lines 47 to 50 in 76303df
just wanted to see how the NAPT tests would work with the newly introduced eviction mechanism you implemented, seems like the oldest record was removed here: |
Note: I'm passing this PR to an internal review, which usually takes some time until accepted and merged. |
c29735a
to
a46e0b4
Compare
1. Fix enable/disable to properly allocate and deallocate tables. Current algorithm is just broken. 2. Introduce eviction policy when table gets full: oldest connection is evicted, instead of new ones getting silently dropped. this results in much better behavior with small tables than before. When TCP connection is dropped, RSTs are sent both ways to inform parties instead of dropping silently. thiw requires additional 8 bytes per entry but is, again, a big improvement for clients in terms of usability. 3. FIxed handling of timestamp wraparound (every ~50 days of uptime). 3. Added ip_portmap_get() to retrieve current port mapping settings. 4. Added ip_napt_get_stats() for some insight into the state of NAT.
@david-cermak addressed comments, rebased onto most recent 2.1.2-esp |
Current algorithm is just broken.
is evicted, instead of new ones getting silently dropped. this
results in much better behavior with small tables than before.
When TCP connection is dropped, RSTs are sent both ways to inform
parties instead of dropping silently. thiw requires additional 8
bytes per entry but is, again, a big improvement for clients in
terms of usability.