diff --git a/Cargo.toml b/Cargo.toml index 7c6f467..a370486 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,13 +17,14 @@ smol_socket = ["netlink-proto/smol_socket","async-std"] [dependencies] futures = "0.3.16" -netlink-proto = { default-features = false, version = "0.10" } -netlink-packet-generic = { version = "0.3.1" } -netlink-packet-utils = { version = "0.5.1" } -netlink-packet-core = { version = "0.4.2" } +netlink-proto = { default-features = false, version = "0.11.1" } +netlink-packet-generic = { version = "0.3.2" } +netlink-packet-utils = { version = "0.5.2" } +netlink-packet-core = { version = "0.5.0" } tokio = { version = "1.9.0", features = ["rt"], optional = true } async-std = { version = "1.9.0", optional = true } thiserror = "1.0.26" +log = "0.4" [dev-dependencies] anyhow = "1.0.42" diff --git a/examples/dump_family_policy.rs b/examples/dump_family_policy.rs index 4ac2da7..70640a5 100644 --- a/examples/dump_family_policy.rs +++ b/examples/dump_family_policy.rs @@ -21,18 +21,17 @@ async fn main() -> Result<(), Error> { eprintln!("Usage: dump_family_policy "); bail!("Required arguments not given"); } + let mut nl_hdr = NetlinkHeader::default(); + nl_hdr.flags = NLM_F_REQUEST | NLM_F_DUMP; - let nlmsg = NetlinkMessage { - header: NetlinkHeader { - flags: NLM_F_REQUEST | NLM_F_DUMP, - ..Default::default() - }, - payload: GenlMessage::from_payload(GenlCtrl { + let nlmsg = NetlinkMessage::new( + nl_hdr, + GenlMessage::from_payload(GenlCtrl { cmd: GenlCtrlCmd::GetPolicy, nlas: vec![GenlCtrlAttrs::FamilyName(argv[1].to_owned())], }) .into(), - }; + ); let (conn, mut handle, _) = new_connection()?; tokio::spawn(conn); diff --git a/examples/list_genetlink_family.rs b/examples/list_genetlink_family.rs index 30af9ac..1f32bf7 100644 --- a/examples/list_genetlink_family.rs +++ b/examples/list_genetlink_family.rs @@ -19,17 +19,16 @@ use netlink_packet_generic::{ #[tokio::main] async fn main() -> Result<(), Error> { - let nlmsg = NetlinkMessage { - header: NetlinkHeader { - flags: NLM_F_REQUEST | NLM_F_DUMP, - ..Default::default() - }, - payload: GenlMessage::from_payload(GenlCtrl { + let mut nl_hdr = NetlinkHeader::default(); + nl_hdr.flags = NLM_F_REQUEST | NLM_F_DUMP; + let nlmsg = NetlinkMessage::new( + nl_hdr, + GenlMessage::from_payload(GenlCtrl { cmd: GenlCtrlCmd::GetFamily, nlas: vec![], }) .into(), - }; + ); let (conn, mut handle, _) = new_connection()?; tokio::spawn(conn); diff --git a/src/handle.rs b/src/handle.rs index 30280e7..93efe4d 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -6,9 +6,9 @@ use crate::{ resolver::Resolver, }; use futures::{lock::Mutex, Stream, StreamExt}; -use netlink_packet_core::{DecodeError, NetlinkMessage, NetlinkPayload}; +use netlink_packet_core::{NetlinkMessage, NetlinkPayload}; use netlink_packet_generic::{GenlFamily, GenlHeader, GenlMessage}; -use netlink_packet_utils::{Emitable, ParseableParametrized}; +use netlink_packet_utils::{DecodeError, Emitable, ParseableParametrized}; use netlink_proto::{sys::SocketAddr, ConnectionHandle}; use std::{fmt::Debug, sync::Arc}; diff --git a/src/message.rs b/src/message.rs index c7502f2..e578a1f 100644 --- a/src/message.rs +++ b/src/message.rs @@ -20,11 +20,13 @@ //! (`netlink_proto` would drop messages if they fails to decode.) //! I think this can help developers debug their deserializing implementation. use netlink_packet_core::{ - DecodeError, NetlinkDeserializable, NetlinkHeader, NetlinkMessage, - NetlinkPayload, NetlinkSerializable, + NetlinkDeserializable, NetlinkHeader, NetlinkMessage, NetlinkPayload, + NetlinkSerializable, }; use netlink_packet_generic::{GenlBuffer, GenlFamily, GenlHeader, GenlMessage}; -use netlink_packet_utils::{Emitable, Parseable, ParseableParametrized}; +use netlink_packet_utils::{ + DecodeError, Emitable, Parseable, ParseableParametrized, +}; use std::fmt::Debug; /// Message type to hold serialized generic netlink payload @@ -158,6 +160,13 @@ where NetlinkPayload::Ack(i) => NetlinkPayload::Ack(i), NetlinkPayload::Noop => NetlinkPayload::Noop, NetlinkPayload::Overrun(i) => NetlinkPayload::Overrun(i), + i => { + log::warn!( + "map_from_rawgenlmsg(): Unexpected NetlinkPayload {:?}", + i + ); + NetlinkPayload::Noop + } }; NetlinkMessage::new(message.header, raw_payload) } @@ -179,6 +188,13 @@ where NetlinkPayload::Ack(i) => NetlinkPayload::Ack(i), NetlinkPayload::Noop => NetlinkPayload::Noop, NetlinkPayload::Overrun(i) => NetlinkPayload::Overrun(i), + i => { + log::warn!( + "map_from_rawgenlmsg(): Unexpected NetlinkPayload {:?}", + i + ); + NetlinkPayload::Noop + } }; Ok(NetlinkMessage::new(raw_msg.header, payload)) }