Skip to content

Commit e4193d3

Browse files
committed
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 58e6f35 commit e4193d3

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};
@@ -51,9 +52,18 @@ impl RouteGetRequest {
5152
message,
5253
} = self;
5354

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

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

0 commit comments

Comments
 (0)