Skip to content

Commit 4c43681

Browse files
MartichouThomasdezeeuw
authored andcommitted
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 <[email protected]>
1 parent 07993fd commit 4c43681

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ impl Protocol {
302302

303303
/// Protocol corresponding to `UDP`.
304304
pub const UDP: Protocol = Protocol(sys::IPPROTO_UDP);
305+
306+
#[cfg(target_os = "linux")]
307+
/// Protocol corresponding to `MPTCP`.
308+
pub const MPTCP: Protocol = Protocol(sys::IPPROTO_MPTCP);
305309
}
306310

307311
impl From<c_int> for Protocol {

src/sys/unix.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub(crate) use libc::SOCK_RAW;
6363
pub(crate) use libc::SOCK_SEQPACKET;
6464
pub(crate) use libc::{SOCK_DGRAM, SOCK_STREAM};
6565
// Used in `Protocol`.
66+
#[cfg(target_os = "linux")]
67+
pub(crate) use libc::IPPROTO_MPTCP;
6668
pub(crate) use libc::{IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_TCP, IPPROTO_UDP};
6769
// Used in `SockAddr`.
6870
pub(crate) use libc::{
@@ -386,6 +388,8 @@ impl_debug!(
386388
libc::IPPROTO_ICMPV6,
387389
libc::IPPROTO_TCP,
388390
libc::IPPROTO_UDP,
391+
#[cfg(target_os = "linux")]
392+
libc::IPPROTO_MPTCP,
389393
);
390394

391395
/// Unix-only API.

tests/socket.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ fn protocol_fmt_debug() {
106106
(Protocol::ICMPV6, "IPPROTO_ICMPV6"),
107107
(Protocol::TCP, "IPPROTO_TCP"),
108108
(Protocol::UDP, "IPPROTO_UDP"),
109+
#[cfg(target_os = "linux")]
110+
(Protocol::MPTCP, "IPPROTO_MPTCP"),
109111
(500.into(), "500"),
110112
];
111113

0 commit comments

Comments
 (0)