Skip to content
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

Add support for RecvOrigDstAddr on Linux #1772

Merged
merged 1 commit into from Jul 26, 2022

Conversation

brianmay
Copy link
Contributor

Fixes #1767

@brianmay
Copy link
Contributor Author

Still trying to work out why this doesn't work. But is a start.

Also not sure if I should use RecvOrigDstAddr or OrigDstAddr.

@brianmay brianmay changed the title Add support for RecvOrigDstAddr on Linux WIP: Add support for RecvOrigDstAddr on Linux Jul 23, 2022
@brianmay brianmay force-pushed the add_linux_RECVORIGDSTADDR branch 5 times, most recently from 9471997 to c00d930 Compare July 24, 2022 00:00
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

These new symbols are also defined for Android and FreeBSD. You should enable them there.

@brianmay
Copy link
Contributor Author

@asomers Will do so, thanks.

I am not actually sure what these functions are suppose to be returning for non-TPROXY connections. Seem to be getting random addresses, which is causing the tests to fail. Not sure if that is normal or not.

Setting up TPROXY firewall rules probably an overkill for these tests.

@brianmay
Copy link
Contributor Author

Also for some reason this works:

let mut space = cmsg_space!(libc::in_addr, [u8; 0]);

But this fails with MSG_CTRUNC:

let mut space = cmsg_space!(libc::in_addr);

I have no idea what is going on here.

@brianmay
Copy link
Contributor Author

I am also a bit puzzled in that some Linux platforms don't appear to be running the test_recvif_ipv6 test, and some don't appear to be running the test_recvif_ipv4 test either.

@asomers
Copy link
Member

asomers commented Jul 24, 2022

Also for some reason this works:

let mut space = cmsg_space!(libc::in_addr, [u8; 0]);

But this fails with MSG_CTRUNC:

let mut space = cmsg_space!(libc::in_addr);

I have no idea what is going on here.

That's because in_addr is the wrong datatype. According to the FreeBSD man page at least, IP_ORIGDSTADDR sends its message as a struct sockaddr_in.

@brianmay
Copy link
Contributor Author

OK, fixed that, was confused reading an existing test.

Trying to run a local test with TPROXY, but first need to debug why my TPROXY UDP firewall rules don't appear to be working...

src/sys/socket/mod.rs Outdated Show resolved Hide resolved
src/sys/socket/mod.rs Outdated Show resolved Hide resolved
@brianmay
Copy link
Contributor Author

All tests pass now when run locally....

@brianmay brianmay changed the title WIP: Add support for RecvOrigDstAddr on Linux Add support for RecvOrigDstAddr on Linux Jul 24, 2022
@brianmay
Copy link
Contributor Author

Some of the Linux targets are failing tests. Wonder if this is a Linux compile time option.

@brianmay
Copy link
Contributor Author

Confirmed it works with a really hackish TPROXY UDP client now.

Looks like values need network byte ordering conversion, was expecting that.

@asomers
Copy link
Member

asomers commented Jul 24, 2022

The ENOPROTOOPT errors are probably due to lack of support in QEMU user mode emulation. There are a bunch of tests that have to be disabled due to that. You can add #[cfg_attr(qemu, ignore)] to those tests.

@brianmay
Copy link
Contributor Author

Done.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

Mostly looks good, but for the naming. And don't forget to add a CHANGELOG entry.

src/sys/socket/mod.rs Outdated Show resolved Hide resolved
@brianmay
Copy link
Contributor Author

Added changelog entry.

CHANGELOG.md Show resolved Hide resolved
Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

bors r+

@bors bors bot merged commit 854a546 into nix-rust:master Jul 26, 2022
@asomers
Copy link
Member

asomers commented Jul 29, 2022

BTW, I just added IPV6_ORIGDSTADDR to the ip6(4) man page on FreeBSD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ipv4RecvDstAddr recvmsg stuff disabled on Linux
2 participants