chatgpt tech
This commit is contained in:
1 parent
af0682a1f0
commit
940614e14a
4 files changed
+35
-16
No files matched your search
@@ -10,35 +10,33 @@ pub struct DhcpLeaseOut {
|
||||
#[serde(flatten)]
|
||||
pub lease_line: DhcpLeaseLine,
|
||||
pub nud_state: Option<NUDState>,
|
||||
pub rank: Option<u8>,
|
||||
}
|
||||
|
||||
/// Enrich DHCP leases with NUD state and rank using get_macs
|
||||
pub async fn enrich_leases_with_nud_state(leases: Vec<DhcpLeaseLine>) -> Vec<DhcpLeaseOut> {
|
||||
let ips: Vec<IpAddr> = leases.iter().map(|l| l.ip).collect();
|
||||
let mut map: std::collections::HashMap<IpAddr, (NUDState, u8)> =
|
||||
std::collections::HashMap::new();
|
||||
let mut map: std::collections::HashMap<IpAddr, NUDState> = std::collections::HashMap::new();
|
||||
if let Ok(rows) = get_macs(&[] as &[&str], &ips, &[] as &[&str], &[], &[]).await {
|
||||
for row in rows {
|
||||
let state = row.state;
|
||||
let r = state.rank();
|
||||
map.entry(row.ip)
|
||||
.and_modify(|e| {
|
||||
if r > e.1 {
|
||||
*e = (state, r)
|
||||
let er = e.rank();
|
||||
if r > er {
|
||||
*e = state
|
||||
}
|
||||
})
|
||||
.or_insert((state, r));
|
||||
.or_insert(state);
|
||||
}
|
||||
}
|
||||
leases
|
||||
.into_iter()
|
||||
.map(|lease_line| {
|
||||
let (nud_state, rank) = map.get(&lease_line.ip).copied().unzip();
|
||||
let nud_state = map.get(&lease_line.ip).copied();
|
||||
DhcpLeaseOut {
|
||||
lease_line,
|
||||
nud_state,
|
||||
rank,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
||||
Reference in new issue
Block a user