about as good as i want idfk yet

This commit is contained in:
lda committed 2026-04-06 02:39:10 +07:00
1 parent 7eee1e0bab
commit 310b0b462d
7 files changed
+375 -26

No files matched your search

+12 -1
View File
@@ -7,6 +7,7 @@ use std::{
use futures::TryStreamExt;
use macaddr::MacAddr;
use rtnetlink::Handle;
use rtnetlink::packet_route::{
AddressFamily,
neighbour::{NeighbourAddress, NeighbourAttribute, NeighbourState},
@@ -27,6 +28,16 @@ pub async fn get(
let (conn, handle, _) = rtnetlink::new_connection()?;
tokio::spawn(conn);
get_with_handle(&handle, ips, devs, nuds, macs).await
}
pub async fn get_with_handle(
handle: &Handle,
ips: &[IpAddr],
devs: &[impl AsRef<str>],
nuds: &[NUDState],
macs: &[MacAddr],
) -> anyhow::Result<Vec<NeighborItem>> {
let mut neighbor_data = handle.neighbours().get().execute();
// Build filter sets (empty = match all)
@@ -36,7 +47,7 @@ pub async fn get(
let mac_set: HashSet<MacAddr> = macs.iter().copied().collect();
// Prefetch all links once; link lookups were the ugliest and most expensive part.
let ifname_cache: HashMap<u32, String> = link::nl::get(None)
let ifname_cache: HashMap<u32, String> = link::nl::get_with_handle(handle, None)
.await?
.into_iter()
.map(|link| (link.ifindex, link.ifname))