Skip to content

Commit

Permalink
support IPPROTO_MPTCP
Browse files Browse the repository at this point in the history
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 <martin.andre@tessares.net>
  • Loading branch information
Martichou authored and Thomasdezeeuw committed Sep 10, 2022
1 parent 07993fd commit 4c43681
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Expand Up @@ -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<c_int> for Protocol {
Expand Down
4 changes: 4 additions & 0 deletions src/sys/unix.rs
Expand Up @@ -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::{
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions tests/socket.rs
Expand Up @@ -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"),
];

Expand Down

0 comments on commit 4c43681

Please sign in to comment.