Skip to content

Commit a7bfcfd

Browse files
committed
Use latest rust-netlink and drop reexport
Signed-off-by: Gris Ge <[email protected]>
1 parent 6b9490f commit a7bfcfd

File tree

14 files changed

+54
-54
lines changed

14 files changed

+54
-54
lines changed

Diff for: Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ description = "netlink packet types for the netfilter subprotocol"
1414
[dependencies]
1515
anyhow = "1.0.32"
1616
byteorder = "1.3.4"
17-
netlink-packet-core = { version = "0.4.2" }
17+
netlink-packet-core = { version = "0.7.0" }
1818
netlink-packet-utils = { version = "0.5.1" }
19-
bitflags = "1.2.1"
19+
bitflags = "2.3"
2020
libc = "0.2.77"
2121
derive_more = "0.99.16"
2222

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Rust netlink packet types for the netfilter subprotocol

Diff for: examples/nflog.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
// To run this example:
44
// 1) create a iptables/nft rules that send packet with group 1, for example:
5-
// sudo iptables -A INPUT -j NFLOG --nflog-group 1
6-
// 2) build the example:
7-
// cargo build --example nflog
8-
// 3) run it as root:
9-
// sudo ../target/debug/examples/nflog
5+
// sudo iptables -A INPUT -j NFLOG --nflog-group 1
6+
// 2) build the example: cargo build --example nflog
7+
// 3) run it as root: sudo ../target/debug/examples/nflog
108

119
use std::{net::Ipv4Addr, time::Duration};
1210

1311
use byteorder::{ByteOrder, NetworkEndian};
12+
use netlink_packet_core::{NetlinkMessage, NetlinkPayload};
1413
use netlink_packet_netfilter::{
1514
constants::*,
1615
nflog::{
@@ -21,7 +20,6 @@ use netlink_packet_netfilter::{
2120
},
2221
NfLogMessage,
2322
},
24-
nl::{NetlinkMessage, NetlinkPayload},
2523
NetfilterMessage, NetfilterMessageInner,
2624
};
2725
use netlink_sys::{constants::NETLINK_NETFILTER, Socket};
@@ -58,7 +56,10 @@ fn main() {
5856
let rx_packet =
5957
<NetlinkMessage<NetfilterMessage>>::deserialize(bytes).unwrap();
6058
println!("<<< {:?}", rx_packet);
61-
assert!(matches!(rx_packet.payload, NetlinkPayload::Ack(_)));
59+
assert!(matches!(rx_packet.payload, NetlinkPayload::Error(_)));
60+
if let NetlinkPayload::Error(e) = rx_packet.payload {
61+
assert_eq!(e.code, None);
62+
}
6263

6364
// After that we issue a Bind command, to start receiving packets. We can
6465
// also set various parameters at the same time
@@ -83,7 +84,10 @@ fn main() {
8384
let rx_packet =
8485
<NetlinkMessage<NetfilterMessage>>::deserialize(bytes).unwrap();
8586
println!("<<< {:?}", rx_packet);
86-
assert!(matches!(rx_packet.payload, NetlinkPayload::Ack(_)));
87+
assert!(matches!(rx_packet.payload, NetlinkPayload::Error(_)));
88+
if let NetlinkPayload::Error(e) = rx_packet.payload {
89+
assert_eq!(e.code, None);
90+
}
8791

8892
// And now we can receive the packets
8993
loop {

Diff for: src/buffer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use crate::{
66
NETFILTER_HEADER_LEN,
77
},
88
nflog::NfLogMessage,
9-
traits::{Parseable, ParseableParametrized},
10-
DecodeError,
119
};
1210
use anyhow::Context;
1311
use netlink_packet_utils::{
1412
buffer,
1513
nla::{DefaultNla, NlaBuffer, NlasIterator},
14+
DecodeError, Parseable, ParseableParametrized,
1615
};
1716

1817
buffer!(NetfilterBuffer(NETFILTER_HEADER_LEN) {

Diff for: src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
// SPDX-License-Identifier: MIT
22

3-
pub extern crate netlink_packet_core as nl;
4-
pub(crate) extern crate netlink_packet_utils as utils;
5-
6-
pub use self::utils::{nla, traits, DecodeError};
7-
83
pub(crate) mod buffer;
94
pub mod constants;
105
mod message;

Diff for: src/message.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: MIT
22

33
use netlink_packet_core::{
4-
DecodeError, NetlinkDeserializable, NetlinkHeader, NetlinkPayload,
5-
NetlinkSerializable,
4+
NetlinkDeserializable, NetlinkHeader, NetlinkPayload, NetlinkSerializable,
65
};
76
use netlink_packet_utils::{
8-
buffer, nla::DefaultNla, Emitable, Parseable, ParseableParametrized,
7+
buffer, nla::DefaultNla, DecodeError, Emitable, Parseable,
8+
ParseableParametrized,
99
};
1010

1111
use crate::{buffer::NetfilterBuffer, nflog::NfLogMessage};

Diff for: src/nflog/message.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// SPDX-License-Identifier: MIT
22

3+
use netlink_packet_utils::{
4+
nla::DefaultNla, DecodeError, Emitable, Parseable, ParseableParametrized,
5+
};
6+
37
use crate::{
48
buffer::NetfilterBuffer,
59
constants::{NFNL_SUBSYS_ULOG, NFULNL_MSG_CONFIG, NFULNL_MSG_PACKET},
610
nflog::nlas::{config::ConfigNla, packet::PacketNla},
7-
nla::DefaultNla,
8-
traits::{Emitable, Parseable, ParseableParametrized},
9-
DecodeError,
1011
};
1112

1213
#[derive(Debug, PartialEq, Eq, Clone)]

Diff for: src/nflog/mod.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@ mod message;
44
pub use message::NfLogMessage;
55
pub mod nlas;
66

7+
use netlink_packet_core::{
8+
NetlinkHeader, NetlinkMessage, NetlinkPayload, NLM_F_ACK, NLM_F_REQUEST,
9+
};
10+
711
use crate::{
8-
constants::NFNETLINK_V0,
9-
nflog::nlas::config::ConfigNla,
10-
nl::{
11-
NetlinkHeader, NetlinkMessage, NetlinkPayload, NLM_F_ACK, NLM_F_REQUEST,
12-
},
13-
NetfilterHeader, NetfilterMessage,
12+
constants::NFNETLINK_V0, nflog::nlas::config::ConfigNla, NetfilterHeader,
13+
NetfilterMessage,
1414
};
1515

1616
pub fn config_request(
1717
family: u8,
1818
group_num: u16,
1919
nlas: Vec<ConfigNla>,
2020
) -> NetlinkMessage<NetfilterMessage> {
21-
let mut message = NetlinkMessage {
22-
header: NetlinkHeader {
23-
flags: NLM_F_REQUEST | NLM_F_ACK,
24-
..Default::default()
25-
},
26-
payload: NetlinkPayload::from(NetfilterMessage::new(
21+
let mut hdr = NetlinkHeader::default();
22+
hdr.flags = NLM_F_REQUEST | NLM_F_ACK;
23+
let mut message = NetlinkMessage::new(
24+
hdr,
25+
NetlinkPayload::from(NetfilterMessage::new(
2726
NetfilterHeader::new(family, NFNETLINK_V0, group_num),
2827
NfLogMessage::Config(nlas),
2928
)),
30-
};
29+
);
3130
message.finalize();
3231
message
3332
}

Diff for: src/nflog/nlas/config/config_flags.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use netlink_packet_utils::nla::Nla;
99
const NFULA_CFG_FLAGS: u16 = libc::NFULA_CFG_FLAGS as u16;
1010

1111
bitflags! {
12+
#[derive(Clone, Debug, Copy, PartialEq, Eq)]
1213
pub struct ConfigFlags: u16 {
1314
const SEQ = libc:: NFULNL_CFG_F_SEQ as u16;
1415
const SEQ_GLOBAL = libc:: NFULNL_CFG_F_SEQ_GLOBAL as u16;
@@ -19,7 +20,7 @@ bitflags! {
1920
// see https://github.com/bitflags/bitflags/issues/263
2021
impl ConfigFlags {
2122
pub fn from_bits_preserve(bits: u16) -> Self {
22-
ConfigFlags { bits }
23+
ConfigFlags::from_bits_truncate(bits)
2324
}
2425
}
2526

@@ -33,6 +34,6 @@ impl Nla for ConfigFlags {
3334
}
3435

3536
fn emit_value(&self, buffer: &mut [u8]) {
36-
BigEndian::write_u16(buffer, self.bits);
37+
BigEndian::write_u16(buffer, self.bits());
3738
}
3839
}

Diff for: src/nflog/nlas/config/nla.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
use anyhow::Context;
44
use byteorder::{BigEndian, ByteOrder};
55
use derive_more::{From, IsVariant};
6+
use netlink_packet_utils::{
7+
nla::{DefaultNla, Nla, NlaBuffer},
8+
parsers::{parse_u16_be, parse_u32_be, parse_u8},
9+
DecodeError, Parseable,
10+
};
611

712
use crate::{
813
constants::{
@@ -13,10 +18,6 @@ use crate::{
1318
config_mode::ConfigModeBuffer, ConfigCmd, ConfigFlags, ConfigMode,
1419
Timeout,
1520
},
16-
nl::DecodeError,
17-
nla::{DefaultNla, Nla, NlaBuffer},
18-
traits::Parseable,
19-
utils::parsers::{parse_u16_be, parse_u32_be, parse_u8},
2021
};
2122

2223
#[derive(Clone, Debug, PartialEq, Eq, From, IsVariant)]

Diff for: src/nflog/nlas/packet/hw_addr.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// SPDX-License-Identifier: MIT
22

3-
use crate::{
4-
constants::NFULA_HWADDR, nla::Nla, traits::Parseable, utils::buffer,
5-
DecodeError,
6-
};
3+
use netlink_packet_utils::{buffer, nla::Nla, DecodeError, Parseable};
4+
5+
use crate::constants::NFULA_HWADDR;
76

87
const HW_ADDR_LEN: usize = 12;
98

Diff for: src/nflog/nlas/packet/nla.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ use anyhow::Context;
66
use byteorder::{BigEndian, ByteOrder};
77
use derive_more::{From, IsVariant};
88

9+
use netlink_packet_utils::{
10+
nla::{DefaultNla, Nla, NlaBuffer},
11+
parsers::{parse_u16_be, parse_u32_be},
12+
DecodeError, Parseable,
13+
};
14+
915
use crate::{
1016
constants::{
1117
NFULA_GID, NFULA_HWADDR, NFULA_HWHEADER, NFULA_HWLEN, NFULA_HWTYPE,
@@ -18,10 +24,6 @@ use crate::{
1824
packet_hdr::{PacketHdr, PacketHdrBuffer},
1925
timestamp::{TimeStamp, TimeStampBuffer},
2026
},
21-
nla::{DefaultNla, Nla, NlaBuffer},
22-
traits::Parseable,
23-
utils::parsers::{parse_u16_be, parse_u32_be},
24-
DecodeError,
2527
};
2628

2729
#[derive(Clone, Debug, PartialEq, Eq, From, IsVariant)]

Diff for: src/nflog/nlas/packet/packet_hdr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
use netlink_packet_core::DecodeError;
4-
use netlink_packet_utils::{buffer, nla::Nla, Parseable};
3+
use netlink_packet_utils::{buffer, nla::Nla, DecodeError, Parseable};
54

65
const PACKET_HDR_LEN: usize = 4;
76
pub const NFULA_PACKET_HDR: u16 = libc::NFULA_PACKET_HDR as u16;

Diff for: src/nflog/nlas/packet/timestamp.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3-
use netlink_packet_core::DecodeError;
4-
use netlink_packet_utils::{buffer, nla::Nla, Parseable};
3+
use netlink_packet_utils::{buffer, nla::Nla, DecodeError, Parseable};
54

65
use crate::constants::NFULA_TIMESTAMP;
76

0 commit comments

Comments
 (0)