update and use ts shit idk anymore
This commit is contained in:
Generated
+237
-229
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
||||
//! lowk why its free but its indirection and its ass
|
||||
|
||||
pub mod json;
|
||||
pub mod nl;
|
||||
|
||||
use crate::utils::serialize::mac::option_mac;
|
||||
use macaddr::MacAddr;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//! i said i aint doing ts no more why am i still here
|
||||
|
||||
use futures::TryStreamExt;
|
||||
|
||||
use crate::subcommands::address::AddrOutput;
|
||||
|
||||
// shit this one is even worse you needa collect info from two places
|
||||
pub async fn get(dev: Option<&str>) -> anyhow::Result<Vec<AddrOutput>> {
|
||||
let (conn, handle, _) = rtnetlink::new_connection()?;
|
||||
tokio::spawn(conn); // every time?
|
||||
let mut address = handle.address().get();
|
||||
let mut link = handle.link().get();
|
||||
if let Some(dev) = dev {
|
||||
link = link.match_name(dev.to_owned());
|
||||
if let Some(ind) = link.execute().try_next().await?.map(|a| a.header.index) {
|
||||
address = address.set_link_index_filter(ind);
|
||||
}
|
||||
};
|
||||
todo!()
|
||||
}
|
||||
@@ -17,6 +17,7 @@ use rtnetlink::packet_route::{
|
||||
use super::{NUDState, NeighborItem};
|
||||
|
||||
// dont you love https://github.com/rust-netlink/rtnetlink/blob/main/examples/get_neighbours.rs
|
||||
// NeighborItem.state guarantees to be a single thing.
|
||||
pub async fn get(
|
||||
ip: Option<IpAddr>,
|
||||
dev: Option<&str>,
|
||||
@@ -27,6 +28,8 @@ pub async fn get(
|
||||
tokio::spawn(conn); // every time?
|
||||
let mut neighbor_data = handle.neighbours().get().execute();
|
||||
let nudset: HashSet<&NUDState> = HashSet::from_iter(gnud);
|
||||
|
||||
// map ifindex to name
|
||||
let mut ball: HashMap<u32, String> = HashMap::new();
|
||||
let mut result = vec![];
|
||||
'big: while let Some(neighbour_message_item) = neighbor_data.try_next().await? {
|
||||
|
||||
@@ -66,9 +66,9 @@ impl From<NeighborItem> for IpNeighLine {
|
||||
dev,
|
||||
mac,
|
||||
state: state
|
||||
.first()
|
||||
.copied()
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.max()
|
||||
.unwrap_or(NUDState::None),
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -183,7 +183,7 @@ impl IpNeighLine {
|
||||
Self { state, ..self }
|
||||
}
|
||||
*/
|
||||
pub fn with_dev(dev: impl Into<String>) -> impl FnMut(Self) -> Self {
|
||||
pub fn _with_dev(dev: impl Into<String>) -> impl FnMut(Self) -> Self {
|
||||
let dev = dev.into();
|
||||
move |self_| Self {
|
||||
dev: Some(dev.clone()),
|
||||
|
||||
+19
-36
@@ -1,3 +1,4 @@
|
||||
use lda_ipjs::subcommands::neighbor;
|
||||
use macaddr::MacAddr;
|
||||
|
||||
use crate::arpparse::{self, IpNeighLine, NUDState};
|
||||
@@ -76,7 +77,7 @@ pub async fn get_macs(
|
||||
};
|
||||
|
||||
// Apply additional filters if any were provided
|
||||
if !devs.is_empty() || !macs.is_empty() || !state.is_empty() {
|
||||
if !devs.is_empty() || !macs.is_empty() {
|
||||
let devset: HashSet<_> = devs.iter().map(AsRef::as_ref).collect();
|
||||
let macset: HashSet<_> = macs.iter().collect();
|
||||
|
||||
@@ -95,12 +96,13 @@ pub async fn get_macs(
|
||||
}
|
||||
|
||||
// /// the atomic get_macs. handle ONE thing only.
|
||||
// // this one sucks shit
|
||||
// pub async fn get_mac(
|
||||
// ip: Option<IpAddr>,
|
||||
// dev: Option<&str>,
|
||||
// state: &[NUDState],
|
||||
// ) -> Result<Vec<IpNeighLine>> {
|
||||
// use lda_ipjs::subcommands::neighbor as ipjs_neigh;
|
||||
// use lda_ipjs::subcommands::neighbor as ipjs_neigh;
|
||||
// let ipjs_states: Vec<ipjs_neigh::NUDState> = state.iter().copied().map(Into::into).collect();
|
||||
|
||||
// let items = ipjs_neigh::json::get(ip, dev, &ipjs_states)
|
||||
@@ -113,7 +115,8 @@ pub async fn get_macs(
|
||||
// }
|
||||
|
||||
/// the atomic get_macs. handle ONE thing only.
|
||||
pub async fn get_mac(
|
||||
// 17 - 25 ms full
|
||||
pub async fn _get_mac(
|
||||
ip: Option<IpAddr>,
|
||||
dev: Option<&str>,
|
||||
state: &[NUDState],
|
||||
@@ -143,45 +146,25 @@ pub async fn get_mac(
|
||||
let lines = String::from_utf8_lossy(&out.stdout);
|
||||
let parsed = lines.lines().flat_map(arpparse::parse_ip_neigh_line);
|
||||
let rows: Vec<IpNeighLine> = if let Some(d) = dev {
|
||||
parsed.map(IpNeighLine::with_dev(d)).collect()
|
||||
parsed.map(IpNeighLine::_with_dev(d)).collect()
|
||||
} else {
|
||||
parsed.collect()
|
||||
};
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
/*
|
||||
/// get macs where you just run ip neigh then rust handles the filtering (faster than get mac)
|
||||
pub async fn get_macs_rust(
|
||||
machine_names: Option<&str>,
|
||||
ips: Option<&[IpAddr]>,
|
||||
devs: Option<&[&str]>,
|
||||
states: Option<&[NUDState]>,
|
||||
// 15 - 20 ms full
|
||||
pub async fn get_mac(
|
||||
ip: Option<IpAddr>,
|
||||
dev: Option<&str>,
|
||||
state: &[NUDState],
|
||||
) -> Result<Vec<IpNeighLine>> {
|
||||
let mut ip_map: HashSet<IpAddr> = HashSet::new();
|
||||
let mut machine_map = HashSet::new();
|
||||
if let Some(ips) = ips {
|
||||
ip_map.extend(ips);
|
||||
}
|
||||
if let Some(m) = machine_names {
|
||||
machine_map.extend(get_ips(m).await.into_iter().flatten());
|
||||
}
|
||||
|
||||
let real = match (ip_map.is_empty(), machine_map.is_empty()) {
|
||||
(true, true) => HashSet::new(),
|
||||
(true, false) => machine_map,
|
||||
(false, true) => ip_map,
|
||||
(false, false) => ip_map.intersection(&machine_map).copied().collect(),
|
||||
};
|
||||
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
pub async fn _get_machines(m: &[&str]) -> Vec<IpAddr> {
|
||||
let futs = m.iter().map(|c| get_ips(c));
|
||||
futures::future::join_all(futs)
|
||||
let state2: Vec<neighbor::NUDState> = state.iter().copied().map(Into::into).collect();
|
||||
Ok(neighbor::nl::get(ip, dev, &state2)
|
||||
.await
|
||||
.context("rtnetlink failed")?
|
||||
.into_iter()
|
||||
.flat_map(|f| f.into_iter().flatten())
|
||||
.collect()
|
||||
} */
|
||||
.map(Into::into)
|
||||
.collect())
|
||||
// how did i just do that
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user