Skip to content

Commit 5d19355

Browse files
committed
Be conservative about outputting interface names when there's ambiguity
1 parent 4990cc9 commit 5d19355

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/netlink/route.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{drive_req, nl_hdr_flags};
22
use anyhow::{Context, Result};
3+
use itertools::Itertools as _;
34
use netlink_packet_core::{
45
NetlinkHeader, NetlinkMessage, NetlinkPayload, NLM_F_DUMP, NLM_F_REQUEST,
56
};
@@ -146,12 +147,14 @@ impl Rtbl {
146147
Self(routes)
147148
}
148149
pub fn route(&self, addr: IpAddr) -> Option<u32> {
149-
for route in &self.0 {
150-
if route.pfx.matches(addr) {
151-
return Some(route.iface);
152-
}
153-
}
154-
None
150+
Some(
151+
self.0
152+
.iter()
153+
.filter(|route| route.pfx.matches(addr))
154+
.exactly_one()
155+
.ok()?
156+
.iface,
157+
)
155158
}
156159
pub fn for_iface(&self, iface: u32) -> impl Iterator<Item = Prefix> + '_ {
157160
self.0

0 commit comments

Comments
 (0)