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

Commit

Permalink
Merge pull request #195 from stbuehler/refactor-base-types
Browse files Browse the repository at this point in the history
  • Loading branch information
little-dude authored Nov 17, 2021
2 parents e6ce46d + 6e41186 commit f7aeae7
Show file tree
Hide file tree
Showing 61 changed files with 912 additions and 643 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ jobs:
run: |
cd netlink-proto
cargo test
cargo test --features workaround-audit-bug
- name: test (rtnetlink)
env:
Expand Down
10 changes: 5 additions & 5 deletions audit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "audit"
version = "0.4.0"
version = "0.5.0" # TODO: drop this comment - already bumped version for trait changes
authors = ["Corentin Henry <corentinhenry@gmail.com>"]
edition = "2018"

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

[features]
default = ["tokio_socket"]
tokio_socket = ["netlink-proto/tokio_socket", "netlink-proto/workaround-audit-bug"]
smol_socket = ["netlink-proto/smol_socket", "netlink-proto/workaround-audit-bug"]
tokio_socket = ["netlink-proto/tokio_socket"]
smol_socket = ["netlink-proto/smol_socket"]

[dev-dependencies]
tokio = { version = "1.0.1", default-features = false, features = ["macros", "rt-multi-thread"] }
Expand Down
21 changes: 19 additions & 2 deletions audit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,31 @@ use std::io;
use futures::channel::mpsc::UnboundedReceiver;

#[allow(clippy::type_complexity)]
#[cfg(feature = "tokio_socket")]
pub fn new_connection() -> io::Result<(
proto::Connection<packet::AuditMessage>,
proto::Connection<packet::AuditMessage, sys::TokioSocket, packet::NetlinkAuditCodec>,
Handle,
UnboundedReceiver<(
packet::NetlinkMessage<packet::AuditMessage>,
sys::SocketAddr,
)>,
)> {
let (conn, handle, messages) = netlink_proto::new_connection(sys::protocols::NETLINK_AUDIT)?;
new_connection_with_socket()
}

#[allow(clippy::type_complexity)]
pub fn new_connection_with_socket<S>() -> io::Result<(
proto::Connection<packet::AuditMessage, S, packet::NetlinkAuditCodec>,
Handle,
UnboundedReceiver<(
packet::NetlinkMessage<packet::AuditMessage>,
sys::SocketAddr,
)>,
)>
where
S: sys::AsyncSocket,
{
let (conn, handle, messages) =
netlink_proto::new_connection_with_codec(sys::protocols::NETLINK_AUDIT)?;
Ok((conn, Handle::new(handle), messages))
}
12 changes: 6 additions & 6 deletions ethtool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethtool"
version = "0.1.0"
version = "0.2.0" # TODO: drop this comment - already bumped version for trait changes
authors = ["Gris Ge <fge@redhat.com>"]
license = "MIT"
edition = "2018"
Expand All @@ -24,13 +24,13 @@ anyhow = "1.0.44"
async-std = { version = "1.9.0", optional = true}
byteorder = "1.4.3"
futures = "0.3.17"
genetlink = { default-features = false, version = "0.1.0"}
genetlink = { default-features = false, version = "0.2.0"}
log = "0.4.14"
netlink-packet-core = "0.2.4"
netlink-packet-generic = "0.1.0"
netlink-packet-core = "0.3.0"
netlink-packet-generic = "0.2.0"
netlink-packet-utils = "0.4.1"
netlink-proto = { default-features = false, version = "0.7.0" }
netlink-sys = "0.7.0"
netlink-proto = { default-features = false, version = "0.8.0" }
netlink-sys = "0.8.0"
thiserror = "1.0.29"
tokio = { version = "1.0.1", features = ["rt"], optional = true}

Expand Down
17 changes: 15 additions & 2 deletions ethtool/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@ use futures::channel::mpsc::UnboundedReceiver;
use genetlink::message::RawGenlMessage;
use netlink_packet_core::NetlinkMessage;
use netlink_proto::Connection;
use netlink_sys::SocketAddr;
use netlink_sys::{AsyncSocket, SocketAddr};

use crate::EthtoolHandle;

#[cfg(feature = "tokio_socket")]
#[allow(clippy::type_complexity)]
pub fn new_connection() -> io::Result<(
Connection<RawGenlMessage>,
EthtoolHandle,
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
)> {
let (conn, handle, messages) = genetlink::new_connection()?;
new_connection_with_socket()
}

#[allow(clippy::type_complexity)]
pub fn new_connection_with_socket<S>() -> io::Result<(
Connection<RawGenlMessage, S>,
EthtoolHandle,
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
)>
where
S: AsyncSocket,
{
let (conn, handle, messages) = genetlink::new_connection_with_socket()?;
Ok((conn, EthtoolHandle::new(handle), messages))
}
2 changes: 2 additions & 0 deletions ethtool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ mod pause;
mod ring;

pub use coalesce::{EthtoolCoalesceAttr, EthtoolCoalesceGetRequest, EthtoolCoalesceHandle};
#[cfg(feature = "tokio_socket")]
pub use connection::new_connection;
pub use connection::new_connection_with_socket;
pub use error::EthtoolError;
pub use feature::{
EthtoolFeatureAttr,
Expand Down
12 changes: 6 additions & 6 deletions genetlink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "genetlink"
version = "0.1.0"
version = "0.2.0" # TODO: drop this comment - already bumped version for trait changes
authors = ["Leo <leo881003@gmail.com>"]
edition = "2018"
homepage = "https://github.com/little-dude/netlink"
Expand All @@ -12,17 +12,17 @@ description = "communicate with generic netlink"

[features]
default = ["tokio_socket"]
tokio_socket = ["netlink-proto/tokio_socket","netlink-proto/workaround-audit-bug", "tokio"]
smol_socket = ["netlink-proto/smol_socket","netlink-proto/workaround-audit-bug","async-std"]
tokio_socket = ["netlink-proto/tokio_socket", "tokio"]
smol_socket = ["netlink-proto/smol_socket","async-std"]

[dependencies]
futures = "0.3.16"
netlink-packet-generic = "0.1.0"
netlink-proto = { default-features = false, version = "0.7.0" }
netlink-packet-generic = "0.2.0"
netlink-proto = { default-features = false, version = "0.8.0" }
tokio = { version = "1.9.0", features = ["rt"], optional = true }
async-std = { version = "1.9.0", optional = true }
netlink-packet-utils = "0.4.1"
netlink-packet-core = "0.2.4"
netlink-packet-core = "0.3.0"
thiserror = "1.0.26"

[dev-dependencies]
Expand Down
18 changes: 16 additions & 2 deletions genetlink/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use futures::channel::mpsc::UnboundedReceiver;
use netlink_packet_core::NetlinkMessage;
use netlink_proto::{
self,
sys::{protocols::NETLINK_GENERIC, SocketAddr},
sys::{protocols::NETLINK_GENERIC, AsyncSocket, SocketAddr},
Connection,
};
use std::io;
Expand All @@ -21,12 +21,26 @@ use std::io;
///
/// The [`GenetlinkHandle`] can send and receive any type of generic netlink message.
/// And it can automatic resolve the generic family id before sending.
#[cfg(feature = "tokio_socket")]
#[allow(clippy::type_complexity)]
pub fn new_connection() -> io::Result<(
Connection<RawGenlMessage>,
GenetlinkHandle,
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
)> {
let (conn, handle, messages) = netlink_proto::new_connection(NETLINK_GENERIC)?;
new_connection_with_socket()
}

/// Variant of [`new_connection`] that allows specifying a socket type to use for async handling
#[allow(clippy::type_complexity)]
pub fn new_connection_with_socket<S>() -> io::Result<(
Connection<RawGenlMessage, S>,
GenetlinkHandle,
UnboundedReceiver<(NetlinkMessage<RawGenlMessage>, SocketAddr)>,
)>
where
S: AsyncSocket,
{
let (conn, handle, messages) = netlink_proto::new_connection_with_socket(NETLINK_GENERIC)?;
Ok((conn, GenetlinkHandle::new(handle), messages))
}
34 changes: 5 additions & 29 deletions genetlink/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ impl GenetlinkHandle {
GenetlinkError,
>
where
F: GenlFamily
+ Emitable
+ ParseableParametrized<[u8], GenlHeader>
+ Clone
+ Debug
+ PartialEq
+ Eq,
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
{
self.resolve_message_family_id(&mut message).await?;
self.send_request(message)
Expand All @@ -102,13 +96,7 @@ impl GenetlinkHandle {
GenetlinkError,
>
where
F: GenlFamily
+ Emitable
+ ParseableParametrized<[u8], GenlHeader>
+ Clone
+ Debug
+ PartialEq
+ Eq,
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
{
let raw_msg = map_to_rawgenlmsg(message);

Expand All @@ -122,13 +110,7 @@ impl GenetlinkHandle {
mut message: NetlinkMessage<GenlMessage<F>>,
) -> Result<(), GenetlinkError>
where
F: GenlFamily
+ Emitable
+ ParseableParametrized<[u8], GenlHeader>
+ Clone
+ Debug
+ PartialEq
+ Eq,
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
{
self.resolve_message_family_id(&mut message).await?;
self.send_notify(message)
Expand All @@ -140,13 +122,7 @@ impl GenetlinkHandle {
message: NetlinkMessage<GenlMessage<F>>,
) -> Result<(), GenetlinkError>
where
F: GenlFamily
+ Emitable
+ ParseableParametrized<[u8], GenlHeader>
+ Clone
+ Debug
+ PartialEq
+ Eq,
F: GenlFamily + Emitable + ParseableParametrized<[u8], GenlHeader> + Debug,
{
let raw_msg = map_to_rawgenlmsg(message);

Expand All @@ -159,7 +135,7 @@ impl GenetlinkHandle {
message: &mut NetlinkMessage<GenlMessage<F>>,
) -> Result<(), GenetlinkError>
where
F: GenlFamily + Clone + Debug + PartialEq + Eq,
F: GenlFamily + Debug,
{
if let NetlinkPayload::InnerMessage(genlmsg) = &mut message.payload {
if genlmsg.family_id() == 0 {
Expand Down
2 changes: 2 additions & 0 deletions genetlink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mod handle;
pub mod message;
mod resolver;

#[cfg(feature = "tokio_socket")]
pub use connection::new_connection;
pub use connection::new_connection_with_socket;
pub use error::GenetlinkError;
pub use handle::GenetlinkHandle;
12 changes: 6 additions & 6 deletions genetlink/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl RawGenlMessage {
/// Serialize the generic netlink payload into raw bytes
pub fn from_genlmsg<F>(genlmsg: GenlMessage<F>) -> Self
where
F: GenlFamily + Emitable + Clone + Debug + PartialEq + Eq,
F: GenlFamily + Emitable + Debug,
{
let mut payload_buf = vec![0u8; genlmsg.payload.buffer_len()];
genlmsg.payload.emit(&mut payload_buf);
Expand All @@ -72,7 +72,7 @@ impl RawGenlMessage {
/// Try to deserialize the generic netlink payload from raw bytes
pub fn parse_into_genlmsg<F>(&self) -> Result<GenlMessage<F>, DecodeError>
where
F: GenlFamily + ParseableParametrized<[u8], GenlHeader> + Clone + Debug + PartialEq + Eq,
F: GenlFamily + ParseableParametrized<[u8], GenlHeader> + Debug,
{
let inner = F::parse_with_param(&self.payload, self.header)?;
Ok(GenlMessage::new(self.header, inner, self.family_id))
Expand Down Expand Up @@ -107,7 +107,7 @@ where
}
}

impl NetlinkSerializable<RawGenlMessage> for RawGenlMessage {
impl NetlinkSerializable for RawGenlMessage {
fn message_type(&self) -> u16 {
self.family_id
}
Expand All @@ -121,7 +121,7 @@ impl NetlinkSerializable<RawGenlMessage> for RawGenlMessage {
}
}

impl NetlinkDeserializable<RawGenlMessage> for RawGenlMessage {
impl NetlinkDeserializable for RawGenlMessage {
type Error = DecodeError;
fn deserialize(header: &NetlinkHeader, payload: &[u8]) -> Result<Self, Self::Error> {
let buffer = GenlBuffer::new_checked(payload)?;
Expand All @@ -141,7 +141,7 @@ pub fn map_to_rawgenlmsg<F>(
message: NetlinkMessage<GenlMessage<F>>,
) -> NetlinkMessage<RawGenlMessage>
where
F: GenlFamily + Emitable + Clone + Debug + PartialEq + Eq,
F: GenlFamily + Emitable + Debug,
{
let raw_payload = match message.payload {
NetlinkPayload::InnerMessage(genlmsg) => {
Expand All @@ -162,7 +162,7 @@ pub fn map_from_rawgenlmsg<F>(
raw_msg: NetlinkMessage<RawGenlMessage>,
) -> Result<NetlinkMessage<GenlMessage<F>>, DecodeError>
where
F: GenlFamily + ParseableParametrized<[u8], GenlHeader> + Clone + Debug + PartialEq + Eq,
F: GenlFamily + ParseableParametrized<[u8], GenlHeader> + Debug,
{
let payload = match raw_msg.payload {
NetlinkPayload::InnerMessage(raw_genlmsg) => {
Expand Down
7 changes: 5 additions & 2 deletions netlink-packet-audit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Corentin Henry <corentinhenry@gmail.com>"]
name = "netlink-packet-audit"
version = "0.2.2"
version = "0.3.0" # TODO: drop this comment - already bumped version for trait changes
edition = "2018"

homepage = "https://github.com/little-dude/netlink"
Expand All @@ -13,9 +13,12 @@ description = "netlink packet types"

[dependencies]
anyhow = "1.0.31"
bytes = "1.0"
byteorder = "1.3.2"
netlink-packet-core = "0.2"
log = "0.4.8"
netlink-packet-core = "0.3"
netlink-packet-utils = ">= 0.3, <0.5"
netlink-proto = { default-features = false, version = "0.8" }

[dev-dependencies]
lazy_static = "1.4.0"
4 changes: 2 additions & 2 deletions netlink-packet-audit/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ edition = "2018"
cargo-fuzz = true

[dependencies]
netlink-packet-audit = "0.2"
netlink-packet-core = "0.2"
netlink-packet-audit = "0.3"
netlink-packet-core = "0.3"
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }

[[bin]]
Expand Down
Loading

0 comments on commit f7aeae7

Please sign in to comment.