Skip to content

Commit

Permalink
RouteGetRequest: specify NLM_F_DUMP only when no destination address …
Browse files Browse the repository at this point in the history
…specified

We can have the behaviour of `ip route get` now.

Co-Developed-By: Nevo Hed <[email protected]>
  • Loading branch information
hack3ric committed Jan 16, 2025
1 parent 58e6f35 commit e4193d3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/route/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use futures::{

use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
use netlink_packet_route::{
route::RouteMessage, AddressFamily, RouteNetlinkMessage,
route::{RouteAttribute, RouteMessage},
AddressFamily, RouteNetlinkMessage,
};

use crate::{try_rtnl, Error, Handle};
Expand Down Expand Up @@ -51,9 +52,18 @@ impl RouteGetRequest {
message,
} = self;

let has_dest = message
.attributes
.iter()
.any(|attr| matches!(attr, RouteAttribute::Destination(_)));

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

if !has_dest {
req.header.flags |= NLM_F_DUMP;
}

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

0 comments on commit e4193d3

Please sign in to comment.