diff --git a/Cargo.toml b/Cargo.toml index 660f513..843481e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "mptcp-pm" version = "0.1.3" authors = ["Gris Ge "] license = "MIT" -edition = "2018" +edition = "2021" description = "Linux kernel MPTCP path manager netlink Library" keywords = ["network"] categories = ["network-programming", "os"] @@ -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] diff --git a/src/address/attr.rs b/src/address/attr.rs index 3d59fa1..b291af8 100644 --- a/src/address/attr.rs +++ b/src/address/attr.rs @@ -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; @@ -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, @@ -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), } } diff --git a/src/handle.rs b/src/handle.rs index 28c29f5..d523244 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -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, diff --git a/src/limits/attr.rs b/src/limits/attr.rs index e1e7f7c..720b488 100644 --- a/src/limits/attr.rs +++ b/src/limits/attr.rs @@ -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; @@ -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), } diff --git a/src/message.rs b/src/message.rs index 48fa79a..0651fb9 100644 --- a/src/message.rs +++ b/src/message.rs @@ -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, diff --git a/tests/dump_mptcp.rs b/tests/dump_mptcp.rs index fdec7b3..1c0a2d7 100644 --- a/tests/dump_mptcp.rs +++ b/tests/dump_mptcp.rs @@ -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") @@ -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()