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

Ipv4RecvDstAddr recvmsg stuff disabled on Linux #1767

Closed
brianmay opened this issue Jul 23, 2022 · 3 comments · Fixed by #1772
Closed

Ipv4RecvDstAddr recvmsg stuff disabled on Linux #1767

brianmay opened this issue Jul 23, 2022 · 3 comments · Fixed by #1772

Comments

@brianmay
Copy link
Contributor

brianmay commented Jul 23, 2022

It looks like definitions needed to find the real IP destination of a TPROXY redirected stream are disabled on Linux. Such as:

nix::sys::socket::sockopt::Ipv4RecvDstAddr
ControlMessageOwned::Ipv4RecvDstAddr

And the equivalent IPv6 versions.

https://powerdns.org/tproxydoc/tproxy.md.html

These are valid on Linux and should be enabled.

e.g. the code has:

#[cfg(any(
    target_os = "freebsd",
    target_os = "ios",
    target_os = "macos",
    target_os = "netbsd",
    target_os = "openbsd",
))]
#[cfg(feature = "net")]
sockopt_impl!(
    #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
    /// The `recvmsg(2)` call will return the destination IP address for a UDP
    /// datagram.
    Ipv4RecvDstAddr, Both, libc::IPPROTO_IP, libc::IP_RECVDSTADDR, bool);

I believe this explains why I cannot use the on Linux.

@asomers
Copy link
Member

asomers commented Jul 23, 2022

How have you determined that "These are valid on Linux"? They aren't defined by the libc crate. If they really are defined on Linux, you should submit a PR to https://github.com/rust-lang/libc to add them there. Then you can submit a PR to Nix to enable them.

@brianmay
Copy link
Contributor Author

I use these functions in code I am porting from Python. Like I said, these are required to get TPROXY support working, which I believe is a Linux only thing.

Not sure I understand what needs to change in libc, it already has constants such as IP_RECVDSTADDR defined for all platforms.

@brianmay
Copy link
Contributor Author

Yuck, I find this so confusing. Linux might have a slightly different API that looks very similar:

   Compiling nix v0.24.1 (/home/brian/tree/3rdparty/nix)
error[E0425]: cannot find value `IP_RECVDSTADDR` in crate `libc`
   --> src/sys/socket/sockopt.rs:577:52
    |
577 |     Ipv4RecvDstAddr, Both, libc::IPPROTO_IP, libc::IP_RECVDSTADDR, bool);
    |                                                    ^^^^^^^^^^^^^^ help: a constant with a similar name exists: `IP_ORIGDSTADDR`
    |
   ::: /home/brian/.cargo/git/checkouts/libc-d1297d136f47e864/8dbd2c9/src/unix/linux_like/mod.rs:804:1
    |
804 | pub const IP_ORIGDSTADDR: ::c_int = 20;
    | --------------------------------------- similarly named constant `IP_ORIGDSTADDR` defined here

For more information about this error, try `rustc --explain E0425`.
error: could not compile `nix` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `nix` due to previous error

So, yes, I think this is defined already in libc... But I might have got the name wrong.

In the python code I use IP_RECVORIGDSTADDR, libc6 defines an alias for that:

pub const IP_ORIGDSTADDR: ::c_int = 20;
pub const IP_RECVORIGDSTADDR: ::c_int = IP_ORIGDSTADDR;

brianmay added a commit to brianmay/nix that referenced this issue Jul 23, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 23, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 23, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 23, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 23, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 24, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 24, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 24, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 24, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 24, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 24, 2022
brianmay added a commit to brianmay/nix that referenced this issue Jul 24, 2022
bors bot added a commit that referenced this issue Jul 26, 2022
1772: Add support for RecvOrigDstAddr on Linux r=asomers a=brianmay

Fixes #1767

Co-authored-by: Brian May <brian@linuxpenguins.xyz>
@bors bors bot closed this as completed in c45cd74 Jul 26, 2022
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 a pull request may close this issue.

2 participants