Skip to content

Commit

Permalink
Add dump option to RouteGetRequest
Browse files Browse the repository at this point in the history
With dump set to false, we can mimic the behaviour of `ip route get`.
  • Loading branch information
hack3ric committed Nov 26, 2024
1 parent 58e6f35 commit 7db34e9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/route/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{try_rtnl, Error, Handle};
pub struct RouteGetRequest {
handle: Handle,
message: RouteMessage,
dump: bool,
}

/// Internet Protocol (IP) version.
Expand All @@ -38,7 +39,11 @@ impl IpVersion {

impl RouteGetRequest {
pub(crate) fn new(handle: Handle, message: RouteMessage) -> Self {
RouteGetRequest { handle, message }
RouteGetRequest {
handle,
message,
dump: true,
}
}

pub fn message_mut(&mut self) -> &mut RouteMessage {
Expand All @@ -49,11 +54,15 @@ impl RouteGetRequest {
let RouteGetRequest {
mut handle,
message,
dump,
} = self;

let mut req =
NetlinkMessage::from(RouteNetlinkMessage::GetRoute(message));
req.header.flags = NLM_F_REQUEST | NLM_F_DUMP;
req.header.flags = NLM_F_REQUEST;
if dump {
req.header.flags |= NLM_F_DUMP;
}

match handle.request(req) {
Ok(response) => Either::Left(response.map(move |msg| {
Expand Down

0 comments on commit 7db34e9

Please sign in to comment.