diff options
author | Brian May <brian@linuxpenguins.xyz> | 2022-07-24 09:31:19 +1000 |
---|---|---|
committer | Brian May <brian@linuxpenguins.xyz> | 2022-07-26 07:39:00 +1000 |
commit | c45cd74f42d896bf5f7ae37736e6e44ab5dd3ce9 (patch) | |
tree | 8a29e2b6d1507c3978fe48ff173332dccf3ee9f7 /src/sys/socket | |
parent | 7cc33c15fe547dacebe7da154ffc9c1c5b595d6e (diff) | |
download | nix-c45cd74f42d896bf5f7ae37736e6e44ab5dd3ce9.zip |
Add support for RecvOrigDstAddr on Linux
Fixes #1767
Diffstat (limited to 'src/sys/socket')
-rw-r--r-- | src/sys/socket/mod.rs | 20 | ||||
-rw-r--r-- | src/sys/socket/sockopt.rs | 14 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index e789c116..88378b17 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -757,6 +757,14 @@ pub enum ControlMessageOwned { #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv4RecvDstAddr(libc::in_addr), + #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] + #[cfg(feature = "net")] + #[cfg_attr(docsrs, doc(cfg(feature = "net")))] + Ipv4OrigDstAddr(libc::sockaddr_in), + #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] + #[cfg(feature = "net")] + #[cfg_attr(docsrs, doc(cfg(feature = "net")))] + Ipv6OrigDstAddr(libc::sockaddr_in6), /// UDP Generic Receive Offload (GRO) allows receiving multiple UDP /// packets from a single sender. @@ -916,6 +924,12 @@ impl ControlMessageOwned { let dl = ptr::read_unaligned(p as *const libc::in_addr); ControlMessageOwned::Ipv4RecvDstAddr(dl) }, + #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] + #[cfg(feature = "net")] + (libc::IPPROTO_IP, libc::IP_ORIGDSTADDR) => { + let dl = ptr::read_unaligned(p as *const libc::sockaddr_in); + ControlMessageOwned::Ipv4OrigDstAddr(dl) + }, #[cfg(target_os = "linux")] #[cfg(feature = "net")] (libc::SOL_UDP, libc::UDP_GRO) => { @@ -939,6 +953,12 @@ impl ControlMessageOwned { let (err, addr) = Self::recv_err_helper::<sockaddr_in6>(p, len); ControlMessageOwned::Ipv6RecvErr(err, addr) }, + #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] + #[cfg(feature = "net")] + (libc::IPPROTO_IPV6, libc::IPV6_ORIGDSTADDR) => { + let dl = ptr::read_unaligned(p as *const libc::sockaddr_in6); + ControlMessageOwned::Ipv6OrigDstAddr(dl) + }, (_, _) => { let sl = slice::from_raw_parts(p, len); let ucmsg = UnknownCmsg(*header, Vec::<u8>::from(sl)); diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 8f85748f..fff496db 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -574,6 +574,13 @@ sockopt_impl!( /// The `recvmsg(2)` call will return the destination IP address for a UDP /// datagram. Ipv4RecvDstAddr, Both, libc::IPPROTO_IP, libc::IP_RECVDSTADDR, bool); +#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] +#[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. + Ipv4OrigDstAddr, Both, libc::IPPROTO_IP, libc::IP_ORIGDSTADDR, bool); #[cfg(target_os = "linux")] #[cfg(feature = "net")] sockopt_impl!( @@ -621,6 +628,13 @@ sockopt_impl!( sockopt_impl!( /// Set the unicast hop limit for the socket. Ipv6Ttl, Both, libc::IPPROTO_IPV6, libc::IPV6_UNICAST_HOPS, libc::c_int); +#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))] +#[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. + Ipv6OrigDstAddr, Both, libc::IPPROTO_IPV6, libc::IPV6_ORIGDSTADDR, bool); #[cfg(any(target_os = "ios", target_os = "macos"))] sockopt_impl!( /// Set "don't fragment packet" flag on the IP packet. |