From 4c436818cddec880c26c4e79aca7106ba88827ff Mon Sep 17 00:00:00 2001 From: Martin Andre Date: Thu, 8 Sep 2022 10:34:51 +0200 Subject: [PATCH] support IPPROTO_MPTCP Simply add the support for MPTCP protocol by adding and exposing the MPTCP const Protocol. MPTCP allow end user to open multiple path (TCP) to the destination server using multiple interface. For example, one can use the LTE connection of his phone as well as a Wifi connection. Or Ethernet and Wifi. Setting this Protocol will fail if the host does not support MPTCP, thus the fallback is to open as TCP like one would normally do. For reference: `sysctl net.mptcp.enabled=1` Signed-off-by: Martin Andre --- src/lib.rs | 4 ++++ src/sys/unix.rs | 4 ++++ tests/socket.rs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4d588974..1994a540 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -302,6 +302,10 @@ impl Protocol { /// Protocol corresponding to `UDP`. pub const UDP: Protocol = Protocol(sys::IPPROTO_UDP); + + #[cfg(target_os = "linux")] + /// Protocol corresponding to `MPTCP`. + pub const MPTCP: Protocol = Protocol(sys::IPPROTO_MPTCP); } impl From for Protocol { diff --git a/src/sys/unix.rs b/src/sys/unix.rs index b54c2f63..fbe5a171 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -63,6 +63,8 @@ pub(crate) use libc::SOCK_RAW; pub(crate) use libc::SOCK_SEQPACKET; pub(crate) use libc::{SOCK_DGRAM, SOCK_STREAM}; // Used in `Protocol`. +#[cfg(target_os = "linux")] +pub(crate) use libc::IPPROTO_MPTCP; pub(crate) use libc::{IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_TCP, IPPROTO_UDP}; // Used in `SockAddr`. pub(crate) use libc::{ @@ -386,6 +388,8 @@ impl_debug!( libc::IPPROTO_ICMPV6, libc::IPPROTO_TCP, libc::IPPROTO_UDP, + #[cfg(target_os = "linux")] + libc::IPPROTO_MPTCP, ); /// Unix-only API. diff --git a/tests/socket.rs b/tests/socket.rs index f06febbc..e0161bda 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -106,6 +106,8 @@ fn protocol_fmt_debug() { (Protocol::ICMPV6, "IPPROTO_ICMPV6"), (Protocol::TCP, "IPPROTO_TCP"), (Protocol::UDP, "IPPROTO_UDP"), + #[cfg(target_os = "linux")] + (Protocol::MPTCP, "IPPROTO_MPTCP"), (500.into(), "500"), ];