Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/backend/libc/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,42 @@ pub(crate) fn ipv6_freebind(fd: BorrowedFd<'_>) -> io::Result<bool> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_FREEBIND).map(to_bool)
}

#[cfg(any(linux_like, target_os = "cygwin", target_os = "fuchsia",))]
#[inline]
pub(crate) fn set_ip_checksum(fd: BorrowedFd<'_>, value: u32) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IP, c::IP_CHECKSUM, value)
}

#[cfg(any(linux_like, target_os = "cygwin", target_os = "fuchsia",))]
#[inline]
pub(crate) fn ip_checksum(fd: BorrowedFd<'_>) -> io::Result<u32> {
getsockopt(fd, c::IPPROTO_IP, c::IP_CHECKSUM)
}

#[cfg(any(
apple,
linux_like,
target_os = "cygwin",
target_os = "freebsd",
target_os = "fuchsia",
))]
#[inline]
pub(crate) fn set_ipv6_checksum(fd: BorrowedFd<'_>, value: u32) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_CHECKSUM, value)
}

#[cfg(any(
apple,
linux_like,
target_os = "cygwin",
target_os = "freebsd",
target_os = "fuchsia",
))]
#[inline]
pub(crate) fn ipv6_checksum(fd: BorrowedFd<'_>) -> io::Result<u32> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_CHECKSUM)
}

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[inline]
pub(crate) fn ip_original_dst(fd: BorrowedFd<'_>) -> io::Result<SocketAddrV4> {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/linux_raw/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ pub(crate) use linux_raw_sys::{
AF_LLC, AF_NETBEUI, AF_NETLINK, AF_NETROM, AF_PACKET, AF_PHONET, AF_PPPOX, AF_RDS, AF_ROSE,
AF_RXRPC, AF_SECURITY, AF_SNA, AF_TIPC, AF_UNIX, AF_UNSPEC, AF_VSOCK, AF_WANPIPE, AF_X25,
AF_XDP, IP6T_SO_ORIGINAL_DST, IPPROTO_FRAGMENT, IPPROTO_ICMPV6, IPPROTO_MH,
IPPROTO_ROUTING, IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_FREEBIND,
IPPROTO_ROUTING, IPV6_ADD_MEMBERSHIP, IPV6_CHECKSUM, IPV6_DROP_MEMBERSHIP, IPV6_FREEBIND,
IPV6_MULTICAST_HOPS, IPV6_MULTICAST_LOOP, IPV6_PMTUDISC_DO, IPV6_PMTUDISC_DONT,
IPV6_PMTUDISC_INTERFACE, IPV6_PMTUDISC_OMIT, IPV6_PMTUDISC_PROBE, IPV6_PMTUDISC_WANT,
IPV6_RECVTCLASS, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP,
IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP, IP_FREEBIND,
IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_PMTUDISC_DO, IP_PMTUDISC_DONT,
IP_ADD_SOURCE_MEMBERSHIP, IP_CHECKSUM, IP_DROP_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
IP_FREEBIND, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_PMTUDISC_DO, IP_PMTUDISC_DONT,
IP_PMTUDISC_INTERFACE, IP_PMTUDISC_OMIT, IP_PMTUDISC_PROBE, IP_PMTUDISC_WANT, IP_RECVTOS,
IP_TOS, IP_TTL, MSG_CMSG_CLOEXEC, MSG_CONFIRM, MSG_CTRUNC, MSG_DONTROUTE, MSG_DONTWAIT,
MSG_EOR, MSG_ERRQUEUE, MSG_MORE, MSG_NOSIGNAL, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL,
Expand Down
20 changes: 20 additions & 0 deletions src/backend/linux_raw/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,26 @@ pub(crate) fn ipv6_freebind(fd: BorrowedFd<'_>) -> io::Result<bool> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_FREEBIND).map(to_bool)
}

#[inline]
pub(crate) fn set_ip_checksum(fd: BorrowedFd<'_>, value: u32) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IP, c::IP_CHECKSUM, value)
}

#[inline]
pub(crate) fn ip_checksum(fd: BorrowedFd<'_>) -> io::Result<u32> {
getsockopt(fd, c::IPPROTO_IP, c::IP_CHECKSUM)
}

#[inline]
pub(crate) fn set_ipv6_checksum(fd: BorrowedFd<'_>, value: u32) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_CHECKSUM, value)
}

#[inline]
pub(crate) fn ipv6_checksum(fd: BorrowedFd<'_>) -> io::Result<u32> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_CHECKSUM)
}

#[inline]
pub(crate) fn ip_original_dst(fd: BorrowedFd<'_>) -> io::Result<SocketAddrV4> {
let level = c::IPPROTO_IP;
Expand Down
60 changes: 60 additions & 0 deletions src/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,66 @@ pub fn ipv6_freebind<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::sockopt::ipv6_freebind(fd.as_fd())
}

/// `setsockopt(fd, IPPROTO_IP, IP_CHECKSUM, value)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(any(linux_like, target_os = "cygwin", target_os = "fuchsia",))]
#[inline]
#[doc(alias = "IP_CHECKSUM")]
pub fn set_ip_checksum<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_ip_checksum(fd.as_fd(), value)
}

/// `getsockopt(fd, IPPROTO_IP, IP_CHECKSUM)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(any(linux_like, target_os = "cygwin", target_os = "fuchsia",))]
#[inline]
#[doc(alias = "IP_CHECKSUM")]
pub fn ip_checksum<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ip_checksum(fd.as_fd())
}

/// `setsockopt(fd, IPPROTO_IPV6, IPV6_CHECKSUM, value)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(any(
apple,
linux_like,
target_os = "cygwin",
target_os = "freebsd",
target_os = "fuchsia",
))]
#[inline]
#[doc(alias = "IPV6_CHECKSUM")]
pub fn set_ipv6_checksum<Fd: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
backend::net::sockopt::set_ipv6_checksum(fd.as_fd(), value)
}

/// `getsockopt(fd, IPPROTO_IPV6, IPV6_CHECKSUM)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(any(
apple,
linux_like,
target_os = "cygwin",
target_os = "freebsd",
target_os = "fuchsia",
))]
#[inline]
#[doc(alias = "IPV6_CHECKSUM")]
pub fn ipv6_checksum<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
backend::net::sockopt::ipv6_checksum(fd.as_fd())
}

/// `getsockopt(fd, IPPROTO_IP, SO_ORIGINAL_DST)`
///
/// Even though this corresponds to a `SO_*` constant, it is an `IPPROTO_IP`
Expand Down
Loading