Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Commit ee9bad4

Browse files
authored
Merge pull request #195 from stbuehler/refactor-base-types
2 parents 8288e17 + aa89fe6 commit ee9bad4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+912
-643
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ jobs:
6161
run: |
6262
cd netlink-proto
6363
cargo test
64-
cargo test --features workaround-audit-bug
6564
6665
- name: test (rtnetlink)
6766
env:

audit/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "audit"
3-
version = "0.4.0"
3+
version = "0.5.0" # TODO: drop this comment - already bumped version for trait changes
44
authors = ["Corentin Henry <[email protected]>"]
55
edition = "2018"
66

@@ -14,13 +14,13 @@ description = "linux audit via netlink"
1414
[dependencies]
1515
futures = "0.3.11"
1616
thiserror = "1"
17-
netlink-packet-audit = "0.2"
18-
netlink-proto = { default-features = false, version = "0.7" }
17+
netlink-packet-audit = "0.3"
18+
netlink-proto = { default-features = false, version = "0.8" }
1919

2020
[features]
2121
default = ["tokio_socket"]
22-
tokio_socket = ["netlink-proto/tokio_socket", "netlink-proto/workaround-audit-bug"]
23-
smol_socket = ["netlink-proto/smol_socket", "netlink-proto/workaround-audit-bug"]
22+
tokio_socket = ["netlink-proto/tokio_socket"]
23+
smol_socket = ["netlink-proto/smol_socket"]
2424

2525
[dev-dependencies]
2626
tokio = { version = "1.0.1", default-features = false, features = ["macros", "rt-multi-thread"] }

audit/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,31 @@ use std::io;
1515
use futures::channel::mpsc::UnboundedReceiver;
1616

1717
#[allow(clippy::type_complexity)]
18+
#[cfg(feature = "tokio_socket")]
1819
pub fn new_connection() -> io::Result<(
19-
proto::Connection<packet::AuditMessage>,
20+
proto::Connection<packet::AuditMessage, sys::TokioSocket, packet::NetlinkAuditCodec>,
2021
Handle,
2122
UnboundedReceiver<(
2223
packet::NetlinkMessage<packet::AuditMessage>,
2324
sys::SocketAddr,
2425
)>,
2526
)> {
26-
let (conn, handle, messages) = netlink_proto::new_connection(sys::protocols::NETLINK_AUDIT)?;
27+
new_connection_with_socket()
28+
}
29+
30+
#[allow(clippy::type_complexity)]
31+
pub fn new_connection_with_socket<S>() -> io::Result<(
32+
proto::Connection<packet::AuditMessage, S, packet::NetlinkAuditCodec>,
33+
Handle,
34+
UnboundedReceiver<(
35+
packet::NetlinkMessage<packet::AuditMessage>,
36+
sys::SocketAddr,
37+
)>,
38+
)>
39+
where
40+
S: sys::AsyncSocket,
41+
{
42+
let (conn, handle, messages) =
43+
netlink_proto::new_connection_with_codec(sys::protocols::NETLINK_AUDIT)?;
2744
Ok((conn, Handle::new(handle), messages))
2845
}

ethtool/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ethtool"
3-
version = "0.1.0"
3+
version = "0.2.0" # TODO: drop this comment - already bumped version for trait changes
44
authors = ["Gris Ge <[email protected]>"]
55
license = "MIT"
66
edition = "2018"
@@ -24,13 +24,13 @@ anyhow = "1.0.44"
2424
async-std = { version = "1.9.0", optional = true}
2525
byteorder = "1.4.3"
2626
futures = "0.3.17"
27-
genetlink = { default-features = false, version = "0.1.0"}
27+
genetlink = { default-features = false, version = "0.2.0"}
2828
log = "0.4.14"
29-
netlink-packet-core = "0.2.4"
30-
netlink-packet-generic = "0.1.0"
29+
netlink-packet-core = "0.3.0"
30+
netlink-packet-generic = "0.2.0"
3131
netlink-packet-utils = "0.4.1"
32-
netlink-proto = { default-features = false, version = "0.7.0" }
33-
netlink-sys = "0.7.0"
32+
netlink-proto = { default-features = false, version = "0.8.0" }
33+
netlink-sys = "0.8.0"
3434
thiserror = "1.0.29"
3535
tokio = { version = "1.0.1", features = ["rt"], optional = true}
3636

ethtool/src/connection.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@ use futures::channel::mpsc::UnboundedReceiver;
44
use genetlink::message::RawGenlMessage;
55
use netlink_packet_core::NetlinkMessage;
66
use netlink_proto::Connection;
7-
use netlink_sys::SocketAddr;
7+
use netlink_sys::{AsyncSocket, SocketAddr};
88

99
use crate::EthtoolHandle;
1010

11+
#[cfg(feature = "tokio_socket")]
1112
#[allow(clippy::type_complexity)]
1213
pub fn new_connection() -> io::Result<(
1314
Connection<RawGenlMessage>,
1415
EthtoolHandle,
1516
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
1617
)> {
17-
let (conn, handle, messages) = genetlink::new_connection()?;
18+
new_connection_with_socket()
19+
}
20+
21+
#[allow(clippy::type_complexity)]
22+
pub fn new_connection_with_socket<S>() -> io::Result<(
23+
Connection<RawGenlMessage, S>,
24+
EthtoolHandle,
25+
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
26+
)>
27+
where
28+
S: AsyncSocket,
29+
{
30+
let (conn, handle, messages) = genetlink::new_connection_with_socket()?;
1831
Ok((conn, EthtoolHandle::new(handle), messages))
1932
}

ethtool/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ mod pause;
1111
mod ring;
1212

1313
pub use coalesce::{EthtoolCoalesceAttr, EthtoolCoalesceGetRequest, EthtoolCoalesceHandle};
14+
#[cfg(feature = "tokio_socket")]
1415
pub use connection::new_connection;
16+
pub use connection::new_connection_with_socket;
1517
pub use error::EthtoolError;
1618
pub use feature::{
1719
EthtoolFeatureAttr,

genetlink/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "genetlink"
3-
version = "0.1.0"
3+
version = "0.2.0" # TODO: drop this comment - already bumped version for trait changes
44
authors = ["Leo <[email protected]>"]
55
edition = "2018"
66
homepage = "https://github.com/little-dude/netlink"
@@ -12,17 +12,17 @@ description = "communicate with generic netlink"
1212

1313
[features]
1414
default = ["tokio_socket"]
15-
tokio_socket = ["netlink-proto/tokio_socket","netlink-proto/workaround-audit-bug", "tokio"]
16-
smol_socket = ["netlink-proto/smol_socket","netlink-proto/workaround-audit-bug","async-std"]
15+
tokio_socket = ["netlink-proto/tokio_socket", "tokio"]
16+
smol_socket = ["netlink-proto/smol_socket","async-std"]
1717

1818
[dependencies]
1919
futures = "0.3.16"
20-
netlink-packet-generic = "0.1.0"
21-
netlink-proto = { default-features = false, version = "0.7.0" }
20+
netlink-packet-generic = "0.2.0"
21+
netlink-proto = { default-features = false, version = "0.8.0" }
2222
tokio = { version = "1.9.0", features = ["rt"], optional = true }
2323
async-std = { version = "1.9.0", optional = true }
2424
netlink-packet-utils = "0.4.1"
25-
netlink-packet-core = "0.2.4"
25+
netlink-packet-core = "0.3.0"
2626
thiserror = "1.0.26"
2727

2828
[dev-dependencies]

genetlink/src/connection.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use futures::channel::mpsc::UnboundedReceiver;
33
use netlink_packet_core::NetlinkMessage;
44
use netlink_proto::{
55
self,
6-
sys::{protocols::NETLINK_GENERIC, SocketAddr},
6+
sys::{protocols::NETLINK_GENERIC, AsyncSocket, SocketAddr},
77
Connection,
88
};
99
use std::io;
@@ -21,12 +21,26 @@ use std::io;
2121
///
2222
/// The [`GenetlinkHandle`] can send and receive any type of generic netlink message.
2323
/// And it can automatic resolve the generic family id before sending.
24+
#[cfg(feature = "tokio_socket")]
2425
#[allow(clippy::type_complexity)]
2526
pub fn new_connection() -> io::Result<(
2627
Connection<RawGenlMessage>,
2728
GenetlinkHandle,
2829
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
2930
)> {
30-
let (conn, handle, messages) = netlink_proto::new_connection(NETLINK_GENERIC)?;
31+
new_connection_with_socket()
32+
}
33+
34+
/// Variant of [`new_connection`] that allows specifying a socket type to use for async handling
35+
#[allow(clippy::type_complexity)]
36+
pub fn new_connection_with_socket<S>() -> io::Result<(
37+
Connection<RawGenlMessage, S>,
38+
GenetlinkHandle,
39+
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
40+
)>
41+
where
42+
S: AsyncSocket,
43+
{
44+
let (conn, handle, messages) = netlink_proto::new_connection_with_socket(NETLINK_GENERIC)?;
3145
Ok((conn, GenetlinkHandle::new(handle), messages))
3246
}

genetlink/src/handle.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,7 @@ impl GenetlinkHandle {
7878
GenetlinkError,
7979
>
8080
where
81-
F: GenlFamily
82-
+ Emitable
83-
+ ParseableParametrized<[u8], GenlHeader>
84-
+ Clone
85-
+ Debug
86-
+ PartialEq
87-
+ Eq,
81+
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
8882
{
8983
self.resolve_message_family_id(&mut message).await?;
9084
self.send_request(message)
@@ -102,13 +96,7 @@ impl GenetlinkHandle {
10296
GenetlinkError,
10397
>
10498
where
105-
F: GenlFamily
106-
+ Emitable
107-
+ ParseableParametrized<[u8], GenlHeader>
108-
+ Clone
109-
+ Debug
110-
+ PartialEq
111-
+ Eq,
99+
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
112100
{
113101
let raw_msg = map_to_rawgenlmsg(message);
114102

@@ -122,13 +110,7 @@ impl GenetlinkHandle {
122110
mut message: NetlinkMessage<GenlMessage<F>>,
123111
) -> Result<(), GenetlinkError>
124112
where
125-
F: GenlFamily
126-
+ Emitable
127-
+ ParseableParametrized<[u8], GenlHeader>
128-
+ Clone
129-
+ Debug
130-
+ PartialEq
131-
+ Eq,
113+
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
132114
{
133115
self.resolve_message_family_id(&mut message).await?;
134116
self.send_notify(message)
@@ -140,13 +122,7 @@ impl GenetlinkHandle {
140122
message: NetlinkMessage<GenlMessage<F>>,
141123
) -> Result<(), GenetlinkError>
142124
where
143-
F: GenlFamily
144-
+ Emitable
145-
+ ParseableParametrized<[u8], GenlHeader>
146-
+ Clone
147-
+ Debug
148-
+ PartialEq
149-
+ Eq,
125+
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
150126
{
151127
let raw_msg = map_to_rawgenlmsg(message);
152128

@@ -159,7 +135,7 @@ impl GenetlinkHandle {
159135
message: &mut NetlinkMessage<GenlMessage<F>>,
160136
) -> Result<(), GenetlinkError>
161137
where
162-
F: GenlFamily + Clone + Debug + PartialEq + Eq,
138+
F: GenlFamily + Debug,
163139
{
164140
if let NetlinkPayload::InnerMessage(genlmsg) = &mut message.payload {
165141
if genlmsg.family_id() == 0 {

genetlink/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ mod handle;
77
pub mod message;
88
mod resolver;
99

10+
#[cfg(feature = "tokio_socket")]
1011
pub use connection::new_connection;
12+
pub use connection::new_connection_with_socket;
1113
pub use error::GenetlinkError;
1214
pub use handle::GenetlinkHandle;

0 commit comments

Comments
 (0)