Skip to content

Commit

Permalink
Use latest rust-netlink crates
Browse files Browse the repository at this point in the history
Signed-off-by: Gris Ge <fge@redhat.com>
  • Loading branch information
cathay4t committed Jan 29, 2023
1 parent 2858402 commit 77c37a8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions examples/dump_family_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ async fn main() -> Result<(), Error> {
eprintln!("Usage: dump_family_policy <family name>");
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);

Expand Down
13 changes: 6 additions & 7 deletions examples/list_genetlink_family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
22 changes: 19 additions & 3 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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))
}

0 comments on commit 77c37a8

Please sign in to comment.