Skip to content
Merged
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
13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "mptcp-pm"
version = "0.1.3"
authors = ["Gris Ge <[email protected]>"]
license = "MIT"
edition = "2018"
edition = "2021"
description = "Linux kernel MPTCP path manager netlink Library"
keywords = ["network"]
categories = ["network-programming", "os"]
Expand All @@ -21,18 +21,15 @@ tokio_socket = ["netlink-proto/tokio_socket", "tokio"]
smol_socket = ["netlink-proto/smol_socket", "async-std"]

[dependencies]
anyhow = "1.0.44"
async-std = { version = "1.9.0", optional = true }
byteorder = "1.4.3"
futures = "0.3.17"
log = "0.4.14"
thiserror = "1.0.29"
tokio = { version = "1.0.1", features = ["rt"], optional = true }
genetlink = { default-features = false, version = "0.2.5" }
netlink-packet-core = { version = "0.7.0" }
netlink-packet-generic = { version = "0.3.3" }
netlink-packet-utils = { version = "0.5.2" }
netlink-proto = { default-features = false, version = "0.11.2" }
genetlink = { default-features = false, version = "0.2.6" }
netlink-packet-core = { version = "0.8.0" }
netlink-packet-generic = { version = "0.4.0" }
netlink-proto = { default-features = false, version = "0.12.0" }
netlink-sys = { version = "0.8.4" }

[dev-dependencies]
Expand Down
18 changes: 7 additions & 11 deletions src/address/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};

use anyhow::Context;
use byteorder::{ByteOrder, NativeEndian};
use netlink_packet_utils::{
nla::{DefaultNla, Nla, NlaBuffer},
parsers::{parse_i32, parse_ip, parse_u16, parse_u32, parse_u8},
DecodeError, Emitable, Parseable,
use netlink_packet_core::{
emit_i32, emit_u16, emit_u32, parse_i32, parse_ip, parse_u16, parse_u32,
parse_u8, DecodeError, DefaultNla, Emitable, ErrorContext, Nla, NlaBuffer,
Parseable,
};

const MPTCP_PM_ADDR_ATTR_FAMILY: u16 = 1;
Expand Down Expand Up @@ -124,9 +122,7 @@ impl Nla for MptcpPathManagerAddressAttr {

fn emit_value(&self, buffer: &mut [u8]) {
match self {
Self::Family(d) | Self::Port(d) => {
NativeEndian::write_u16(buffer, *d)
}
Self::Family(d) | Self::Port(d) => emit_u16(buffer, *d).unwrap(),
Self::Addr4(i) => buffer.copy_from_slice(&i.octets()),
Self::Addr6(i) => buffer.copy_from_slice(&i.octets()),
Self::Id(d) => buffer[0] = *d,
Expand All @@ -135,9 +131,9 @@ impl Nla for MptcpPathManagerAddressAttr {
for flag in flags {
value += u32::from(flag);
}
NativeEndian::write_u32(buffer, value)
emit_u32(buffer, value).unwrap()
}
Self::IfIndex(d) => NativeEndian::write_i32(buffer, *d),
Self::IfIndex(d) => emit_i32(buffer, *d).unwrap(),
Self::Other(ref attr) => attr.emit(buffer),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use futures::{future::Either, FutureExt, Stream, StreamExt, TryStream};
use genetlink::GenetlinkHandle;
use netlink_packet_core::DecodeError;
use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
use netlink_packet_generic::GenlMessage;
use netlink_packet_utils::DecodeError;

use crate::{
try_mptcp, MptcpPathManagerAddressHandle, MptcpPathManagerCmd,
Expand Down
11 changes: 4 additions & 7 deletions src/limits/attr.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use byteorder::{ByteOrder, NativeEndian};
use netlink_packet_utils::{
nla::{DefaultNla, Nla, NlaBuffer},
parsers::parse_u32,
DecodeError, Emitable, Parseable,
use netlink_packet_core::{
emit_u32, parse_u32, DecodeError, DefaultNla, Emitable, ErrorContext, Nla,
NlaBuffer, Parseable,
};

const MPTCP_PM_ATTR_RCV_ADD_ADDRS: u16 = 2;
Expand Down Expand Up @@ -37,7 +34,7 @@ impl Nla for MptcpPathManagerLimitsAttr {
fn emit_value(&self, buffer: &mut [u8]) {
match self {
Self::RcvAddAddrs(d) | Self::Subflows(d) => {
NativeEndian::write_u32(buffer, *d)
emit_u32(buffer, *d).unwrap()
}
Self::Other(ref attr) => attr.emit(buffer),
}
Expand Down
9 changes: 4 additions & 5 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_generic::{GenlFamily, GenlHeader};
use netlink_packet_utils::{
nla::{DefaultNla, Nla, NlasIterator},
DecodeError, Emitable, Parseable, ParseableParametrized,
use netlink_packet_core::{
DecodeError, DefaultNla, Emitable, ErrorContext, Nla, NlasIterator,
Parseable, ParseableParametrized,
};
use netlink_packet_generic::{GenlFamily, GenlHeader};

use crate::{
address::MptcpPathManagerAddressAttr, limits::MptcpPathManagerLimitsAttr,
Expand Down
8 changes: 4 additions & 4 deletions tests/dump_mptcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ fn test_mptcp_empty_addresses_and_limits() {
.arg("net.mptcp.enabled=1")
.spawn()
.unwrap();
// OK to fail as Github CI has no ip-mptcp
Command::new("ip")
.arg("mptcp")
.arg("endpoint")
.arg("flush")
.spawn()
.ok();
// OK to fail as Github CI has no ip-mptcp
.unwrap();
Command::new("ip")
.arg("mptcp")
.arg("limits")
Expand All @@ -29,7 +27,9 @@ fn test_mptcp_empty_addresses_and_limits() {
.arg("add_addr_accepted")
.arg("0")
.spawn()
.ok();
.unwrap();
// Sleep 1 second for kernel to finish its work
std::thread::sleep(std::time::Duration::from_secs(1));

let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
Expand Down