the commit of cherrypicking
release / build (push) Successful in 3m19s

d7c34ee
This commit is contained in:
lda
2025-10-21 01:10:19 +07:00 Unverified
parent 1e7db089d5
commit 1dc598b262
2 changed files with 5 additions and 14 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ pub async fn _ping_ip_2<T: ToSocketAddrs>(_addr: T) -> bool {
} }
pub async fn _ping_ip_3<T: Into<IpAddr>>(addr: T) -> u8 { pub async fn _ping_ip_3<T: Into<IpAddr>>(addr: T) -> u8 {
match get_mac(Some(addr.into()), None, None).await { match get_mac(Some(addr.into()), None, &[] as &[NUDState]).await {
Err(_) => 0, Err(_) => 0,
Ok(l) => l Ok(l) => l
.into_iter() .into_iter()
+4 -13
View File
@@ -72,13 +72,8 @@ pub async fn get_macs(
} else { } else {
devs.iter().next().map(AsRef::as_ref) devs.iter().next().map(AsRef::as_ref)
}; };
let opt_state = if state.len() > 1 {
None
} else {
state.iter().next().copied()
};
let run_one = |to_ip: Option<IpAddr>| get_mac(to_ip, opt_dev, opt_state); let run_one = |to_ip: Option<IpAddr>| get_mac(to_ip, opt_dev, state);
let mut ip_filtered = if let Some(something) = ip_all { let mut ip_filtered = if let Some(something) = ip_all {
if something.len() == 1 { if something.len() == 1 {
@@ -97,7 +92,6 @@ pub async fn get_macs(
// Apply additional filters if any were provided // Apply additional filters if any were provided
if !devs.is_empty() || !macs.is_empty() || !state.is_empty() { if !devs.is_empty() || !macs.is_empty() || !state.is_empty() {
let devset: HashSet<_> = devs.iter().map(AsRef::as_ref).collect(); let devset: HashSet<_> = devs.iter().map(AsRef::as_ref).collect();
let nudset: HashSet<_> = state.iter().collect();
let macset: HashSet<_> = macs.iter().collect(); let macset: HashSet<_> = macs.iter().collect();
ip_filtered.retain(|entry| { ip_filtered.retain(|entry| {
@@ -105,13 +99,10 @@ pub async fn get_macs(
let dev_ok = let dev_ok =
devset.is_empty() || entry.dev.as_deref().is_some_and(|d| devset.contains(d)); devset.is_empty() || entry.dev.as_deref().is_some_and(|d| devset.contains(d));
// NUD filter: always present, simple check
let nud_ok = nudset.is_empty() || nudset.contains(&entry.state);
// MAC filter: if we're filtering by MAC, entry must have a MAC AND it must be in the set // MAC filter: if we're filtering by MAC, entry must have a MAC AND it must be in the set
let mac_ok = macset.is_empty() || entry.mac.is_some_and(|m| macset.contains(&m)); let mac_ok = macset.is_empty() || entry.mac.is_some_and(|m| macset.contains(&m));
dev_ok && nud_ok && mac_ok dev_ok && mac_ok
}) })
}; };
Ok(ip_filtered) Ok(ip_filtered)
@@ -121,7 +112,7 @@ pub async fn get_macs(
pub async fn get_mac( pub async fn get_mac(
ip: Option<IpAddr>, ip: Option<IpAddr>,
dev: Option<&str>, dev: Option<&str>,
state: Option<NUDState>, state: &[NUDState],
) -> Result<Vec<IpNeighLine>> { ) -> Result<Vec<IpNeighLine>> {
let mut args: Vec<String> = vec!["neigh".into(), "show".into()]; let mut args: Vec<String> = vec!["neigh".into(), "show".into()];
if let Some(ip) = ip { if let Some(ip) = ip {
@@ -132,7 +123,7 @@ pub async fn get_mac(
args.push("dev".into()); args.push("dev".into());
args.push(d.to_string()); args.push(d.to_string());
} }
if let Some(nud) = state { for nud in state {
args.push("nud".into()); args.push("nud".into());
args.push(nud.as_ip_neigh_arg().into()); args.push(nud.as_ip_neigh_arg().into());
} }