Skip to content

Commit 8b5faa0

Browse files
hack3riccathay4t
authored andcommitted
RouteGetRequest: specify NLM_F_DUMP only when no destination address specified
We can have the behaviour of `ip route get` now. Co-Developed-By: Nevo Hed <[email protected]>
1 parent ed5a194 commit 8b5faa0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/route/get.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use futures::{
88

99
use netlink_packet_core::{NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST};
1010
use netlink_packet_route::{
11-
route::RouteMessage, AddressFamily, RouteNetlinkMessage,
11+
route::{RouteAttribute, RouteMessage},
12+
AddressFamily, RouteNetlinkMessage,
1213
};
1314

1415
use crate::{try_rtnl, Error, Handle};
@@ -52,9 +53,18 @@ impl RouteGetRequest {
5253
message,
5354
} = self;
5455

56+
let has_dest = message
57+
.attributes
58+
.iter()
59+
.any(|attr| matches!(attr, RouteAttribute::Destination(_)));
60+
5561
let mut req =
5662
NetlinkMessage::from(RouteNetlinkMessage::GetRoute(message));
57-
req.header.flags = NLM_F_REQUEST | NLM_F_DUMP;
63+
req.header.flags = NLM_F_REQUEST;
64+
65+
if !has_dest {
66+
req.header.flags |= NLM_F_DUMP;
67+
}
5868

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

0 commit comments

Comments
 (0)