Skip to content

Commit b6c3ce2

Browse files
committed
Use latest rust-netlink
Signed-off-by: Gris Ge <[email protected]>
1 parent a344a11 commit b6c3ce2

File tree

6 files changed

+25
-36
lines changed

6 files changed

+25
-36
lines changed

Cargo.toml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "mptcp-pm"
33
version = "0.1.3"
44
authors = ["Gris Ge <[email protected]>"]
55
license = "MIT"
6-
edition = "2018"
6+
edition = "2021"
77
description = "Linux kernel MPTCP path manager netlink Library"
88
keywords = ["network"]
99
categories = ["network-programming", "os"]
@@ -21,18 +21,15 @@ tokio_socket = ["netlink-proto/tokio_socket", "tokio"]
2121
smol_socket = ["netlink-proto/smol_socket", "async-std"]
2222

2323
[dependencies]
24-
anyhow = "1.0.44"
2524
async-std = { version = "1.9.0", optional = true }
26-
byteorder = "1.4.3"
2725
futures = "0.3.17"
2826
log = "0.4.14"
2927
thiserror = "1.0.29"
3028
tokio = { version = "1.0.1", features = ["rt"], optional = true }
31-
genetlink = { default-features = false, version = "0.2.5" }
32-
netlink-packet-core = { version = "0.7.0" }
33-
netlink-packet-generic = { version = "0.3.3" }
34-
netlink-packet-utils = { version = "0.5.2" }
35-
netlink-proto = { default-features = false, version = "0.11.2" }
29+
genetlink = { default-features = false, version = "0.2.6" }
30+
netlink-packet-core = { version = "0.8.0" }
31+
netlink-packet-generic = { version = "0.4.0" }
32+
netlink-proto = { default-features = false, version = "0.12.0" }
3633
netlink-sys = { version = "0.8.4" }
3734

3835
[dev-dependencies]

src/address/attr.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

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

5-
use anyhow::Context;
6-
use byteorder::{ByteOrder, NativeEndian};
7-
use netlink_packet_utils::{
8-
nla::{DefaultNla, Nla, NlaBuffer},
9-
parsers::{parse_i32, parse_ip, parse_u16, parse_u32, parse_u8},
10-
DecodeError, Emitable, Parseable,
5+
use netlink_packet_core::{
6+
emit_i32, emit_u16, emit_u32, parse_i32, parse_ip, parse_u16, parse_u32,
7+
parse_u8, DecodeError, DefaultNla, Emitable, ErrorContext, Nla, NlaBuffer,
8+
Parseable,
119
};
1210

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

125123
fn emit_value(&self, buffer: &mut [u8]) {
126124
match self {
127-
Self::Family(d) | Self::Port(d) => {
128-
NativeEndian::write_u16(buffer, *d)
129-
}
125+
Self::Family(d) | Self::Port(d) => emit_u16(buffer, *d).unwrap(),
130126
Self::Addr4(i) => buffer.copy_from_slice(&i.octets()),
131127
Self::Addr6(i) => buffer.copy_from_slice(&i.octets()),
132128
Self::Id(d) => buffer[0] = *d,
@@ -135,9 +131,9 @@ impl Nla for MptcpPathManagerAddressAttr {
135131
for flag in flags {
136132
value += u32::from(flag);
137133
}
138-
NativeEndian::write_u32(buffer, value)
134+
emit_u32(buffer, value).unwrap()
139135
}
140-
Self::IfIndex(d) => NativeEndian::write_i32(buffer, *d),
136+
Self::IfIndex(d) => emit_i32(buffer, *d).unwrap(),
141137
Self::Other(ref attr) => attr.emit(buffer),
142138
}
143139
}

src/handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
use futures::{future::Either, FutureExt, Stream, StreamExt, TryStream};
44
use genetlink::GenetlinkHandle;
5+
use netlink_packet_core::DecodeError;
56
use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
67
use netlink_packet_generic::GenlMessage;
7-
use netlink_packet_utils::DecodeError;
88

99
use crate::{
1010
try_mptcp, MptcpPathManagerAddressHandle, MptcpPathManagerCmd,

src/limits/attr.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// SPDX-License-Identifier: MIT
22

3-
use anyhow::Context;
4-
use byteorder::{ByteOrder, NativeEndian};
5-
use netlink_packet_utils::{
6-
nla::{DefaultNla, Nla, NlaBuffer},
7-
parsers::parse_u32,
8-
DecodeError, Emitable, Parseable,
3+
use netlink_packet_core::{
4+
emit_u32, parse_u32, DecodeError, DefaultNla, Emitable, ErrorContext, Nla,
5+
NlaBuffer, Parseable,
96
};
107

118
const MPTCP_PM_ATTR_RCV_ADD_ADDRS: u16 = 2;
@@ -37,7 +34,7 @@ impl Nla for MptcpPathManagerLimitsAttr {
3734
fn emit_value(&self, buffer: &mut [u8]) {
3835
match self {
3936
Self::RcvAddAddrs(d) | Self::Subflows(d) => {
40-
NativeEndian::write_u32(buffer, *d)
37+
emit_u32(buffer, *d).unwrap()
4138
}
4239
Self::Other(ref attr) => attr.emit(buffer),
4340
}

src/message.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// SPDX-License-Identifier: MIT
22

3-
use anyhow::Context;
4-
use netlink_packet_generic::{GenlFamily, GenlHeader};
5-
use netlink_packet_utils::{
6-
nla::{DefaultNla, Nla, NlasIterator},
7-
DecodeError, Emitable, Parseable, ParseableParametrized,
3+
use netlink_packet_core::{
4+
DecodeError, DefaultNla, Emitable, ErrorContext, Nla, NlasIterator,
5+
Parseable, ParseableParametrized,
86
};
7+
use netlink_packet_generic::{GenlFamily, GenlHeader};
98

109
use crate::{
1110
address::MptcpPathManagerAddressAttr, limits::MptcpPathManagerLimitsAttr,

tests/dump_mptcp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ fn test_mptcp_empty_addresses_and_limits() {
1212
.arg("net.mptcp.enabled=1")
1313
.spawn()
1414
.unwrap();
15-
// OK to fail as Github CI has no ip-mptcp
1615
Command::new("ip")
1716
.arg("mptcp")
1817
.arg("endpoint")
1918
.arg("flush")
2019
.spawn()
21-
.ok();
22-
// OK to fail as Github CI has no ip-mptcp
20+
.unwrap();
2321
Command::new("ip")
2422
.arg("mptcp")
2523
.arg("limits")
@@ -29,7 +27,9 @@ fn test_mptcp_empty_addresses_and_limits() {
2927
.arg("add_addr_accepted")
3028
.arg("0")
3129
.spawn()
32-
.ok();
30+
.unwrap();
31+
// Sleep 1 second for kernel to finish its work
32+
std::thread::sleep(std::time::Duration::from_secs(1));
3333

3434
let rt = tokio::runtime::Builder::new_current_thread()
3535
.enable_io()

0 commit comments

Comments
 (0)