Skip to content

Commit c7b3e43

Browse files
committed
kernel/rtnl: use matches!
1 parent d7e2b50 commit c7b3e43

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/kernel/rtnl.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rtnetlink::packet_route::address::{AddressAttribute, AddressMessage};
1010
use rtnetlink::packet_route::route::{RouteAddress, RouteAttribute, RouteMessage, RouteVia};
1111
use rtnetlink::packet_route::rule::{RuleAction, RuleAttribute, RuleMessage};
1212
use rtnetlink::packet_route::{AddressFamily, RouteNetlinkMessage};
13-
use rtnetlink::packet_utils::nla::Nla;
1413
use rtnetlink::{Handle, RouteMessageBuilder};
1514
use serde::{Deserialize, Serialize};
1615
use std::collections::{BTreeMap, BTreeSet};
@@ -20,12 +19,6 @@ use std::time::Duration;
2019
use tokio::select;
2120
use tokio::time::{interval, Interval};
2221

23-
// Route attribute kinds. Some const declarations are missing in libc crate with
24-
// musl targets, so define here.
25-
const RTA_OIF: u16 = 4;
26-
const RTA_GATEWAY: u16 = 5;
27-
const RTA_VIA: u16 = 18;
28-
2922
// TODO: maintain device info similar to BIRD's "device" protocol, and use it to
3023
// ensure only direct traffic to neighbours
3124
// For now, we allow any address by `ip route get`.
@@ -271,12 +264,11 @@ impl<K: Kernel> RtNetlink<K> {
271264
};
272265
let mut has_gateway = false;
273266
let attrs = rt.attributes.into_iter().filter(|x| {
274-
let kind = x.kind();
275-
if kind == RTA_GATEWAY || kind == RTA_VIA {
267+
if matches!(x, RouteAttribute::Gateway(_) | RouteAttribute::Via(_)) {
276268
has_gateway = true;
277269
true
278270
} else {
279-
kind == RTA_OIF
271+
matches!(x, RouteAttribute::Oif(_))
280272
}
281273
});
282274
let mut attrs: Vec<_> = attrs.collect();

0 commit comments

Comments
 (0)