-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix buffer size issue for AF_NETLINK #8
base: main
Are you sure you want to change the base?
Conversation
2dff22d
to
f6806aa
Compare
I've updated the code a bit with the following things:
|
43dd434
to
23cad4a
Compare
Wow, this is huge 🙂 I’m thinking, if we’re going this big, wouldn’t it better to rewrite it in Rust? Doing what you’re trying to do in this PR would be much easier. I tried prototyping something last weekend, and I’ve got some things working, but I’m super early in it, I only wrap the four functions and add debug prints. How’s your Rust? Would you be able to contribute to a Rust codebase? |
How's my Rust? Well, I know how to spell the word "Rust" and I know that it's a programming language, that's about it ^^ Not sure how easy it would be to get into Rust to a level to be able to make helpful PRs. Although, if you have something working in Rust, couldn't hurt to have both a C and a Rust variant of the library. I do know that any other programming language other than C is probably way easier to write safe code that handles all corner cases. I was planning, once this PR is merged, to continue with #6 (different prefix sizes), and once that's done, try adding support to autodiscover the NAT64 prefix (RFC7050). And then, if possible, UDP support, and then the library should be fairly feature-complete. |
So, any status update regarding this? From my side, this PR should be done unless you have further comments regarding something I should change. Would you be willing to merge this so I can continue working on the other stuff I've planned to implement (prefix autodiscover, UDP, ...); or do you plan to no longer maintain this version in favour of a Rust rewrite? If so, is that already available somewhere for me to take a look at? |
Hi, |
Thanks for the response. No problem, I just wasn't sure if you were waiting for another response from me, that's why I asked. |
476960c
to
a86373a
Compare
I've added two more changes:
I hope all that new malloc/realloc code is correct ... |
669dad5
to
6aa3140
Compare
@andrewshadura Any update yet? |
Is there any update yet @andrewshadura ? Do you plan to review and merge this eventually, or would I be better off maintaining my own fork of tnat64? |
I’m really sorry for delaying it for this long. Adding this to my calendar to look at tomorrow. |
Co-authored-by: Andrej Shadura <[email protected]>
7a8ae29
to
f4f9e06
Compare
Looks like one of your tests is already failing in this branch. Question is, is my code broken or is your test broken? :) |
Looks like the test is broken. With my changes it just no longer hits that code path. What was that test ( |
Well, yeah, it was not supposed to hit this bug, you need to add a new test failing on the current main but passing in this branch 🙂
…--
Cheers,
Andrej
|
Ah, so basically just revert the existing test? Fail if it finds that string, success otherwise? |
Wait, what bugs are we talking about? This test was just for the garbage in the logs, but not for the netlink issue.
|
When executing this test, the current
(and the original test on main passes). But the version inside this PR (#8) prints this:
(so the test fails) Because "dig" is opening a UDP socket for DNS queries, and tnat64 is (currently) incapable of nat64'ing UDP connections, the calls skip most of the code and don't even run into the code path that had the issue with the corrupted logging which is tested by that test. So the test with dig is essentially useless. For a real test you'd need to use TCP, but I don't think an IP of 0.0.0.0 / :: will work there either. EDIT: I do know that I should still add a whole new test for the NETLINK issue in particular, but that's a different topic. This change / question was about the existing test (for bug #1) failing on this branch because the code that's being tested here is no longer even being executed. |
Ah, okay, I see. |
I just added a third test that verifies that netlink sockets can call getsockname without errors. This test fails on I hope a dependency on python for that test isn't an issue; I made sure to test it with python2 and python3; but that was the easiest way I could figure out to test a netlink socket. |
IPV6_V6ONLY is only supposed to have the values 0 or 1. However, the man page says to assume 0=false and everything else = true.
Any update yet? Is there something I still need to do, or do you just need to review this? Or do you want to switch to the new meson build system? I'm hoping to be able to add a couple more features as well (UDP, auto-discovering the NAT64 prefix, ...) but I'd rather not have too many open PRs with different features because I don't want to run into more merge conflicts. |
This should hopefully fix #5 in all cases, by almost completely rewriting getsockname and getpeername It does fix the issue with AF_NETLINK I had with my application in particular.
It also fixes another issue with the buffer size. Previously, if the
__addr
buffer ingetsockname
orgetpeername
was too small for the struct, your code just aborted and returned -1.According to the documentation though, the returned data is supposed to be truncated to fit into the buffer, and the real needed buffer size is supposed to be returned through
__len
so the calling application can either decide to retry with a larger buffer, or be satisfied with the partial response.Also,
getsockname
is the IP address the local side of the socket is working on/with (your IP). So if you open a socket and connect to a remote server, getsockname is supposed to return your own IP. What happens currently is that in this case the library just "throws" the IPv6 address back to the application, which is probably not going to end well when an IPv4-only application actually tries to use this. I've modded it to return the IPv4 address 0.0.0.0 instead for the local socket.