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
|
//! lowk why its free but its indirection and its ass
|
||||||
|
|
||||||
pub mod json;
|
pub mod json;
|
||||||
|
pub mod nl;
|
||||||
|
|
||||||
use crate::utils::serialize::mac::option_mac;
|
use crate::utils::serialize::mac::option_mac;
|
||||||
use macaddr::MacAddr;
|
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};
|
use super::{NUDState, NeighborItem};
|
||||||
|
|
||||||
// dont you love https://github.com/rust-netlink/rtnetlink/blob/main/examples/get_neighbours.rs
|
// 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(
|
pub async fn get(
|
||||||
ip: Option<IpAddr>,
|
ip: Option<IpAddr>,
|
||||||
dev: Option<&str>,
|
dev: Option<&str>,
|
||||||
@@ -27,6 +28,8 @@ pub async fn get(
|
|||||||
tokio::spawn(conn); // every time?
|
tokio::spawn(conn); // every time?
|
||||||
let mut neighbor_data = handle.neighbours().get().execute();
|
let mut neighbor_data = handle.neighbours().get().execute();
|
||||||
let nudset: HashSet<&NUDState> = HashSet::from_iter(gnud);
|
let nudset: HashSet<&NUDState> = HashSet::from_iter(gnud);
|
||||||
|
|
||||||
|
// map ifindex to name
|
||||||
let mut ball: HashMap<u32, String> = HashMap::new();
|
let mut ball: HashMap<u32, String> = HashMap::new();
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
'big: while let Some(neighbour_message_item) = neighbor_data.try_next().await? {
|
'big: while let Some(neighbour_message_item) = neighbor_data.try_next().await? {
|
||||||
|
|||||||
@@ -66,9 +66,9 @@ impl From<NeighborItem> for IpNeighLine {
|
|||||||
dev,
|
dev,
|
||||||
mac,
|
mac,
|
||||||
state: state
|
state: state
|
||||||
.first()
|
.into_iter()
|
||||||
.copied()
|
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
|
.max()
|
||||||
.unwrap_or(NUDState::None),
|
.unwrap_or(NUDState::None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -183,7 +183,7 @@ impl IpNeighLine {
|
|||||||
Self { state, ..self }
|
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();
|
let dev = dev.into();
|
||||||
move |self_| Self {
|
move |self_| Self {
|
||||||
dev: Some(dev.clone()),
|
dev: Some(dev.clone()),
|
||||||
|
|||||||
+18
-35
@@ -1,3 +1,4 @@
|
|||||||
|
use lda_ipjs::subcommands::neighbor;
|
||||||
use macaddr::MacAddr;
|
use macaddr::MacAddr;
|
||||||
|
|
||||||
use crate::arpparse::{self, IpNeighLine, NUDState};
|
use crate::arpparse::{self, IpNeighLine, NUDState};
|
||||||
@@ -76,7 +77,7 @@ 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() {
|
||||||
let devset: HashSet<_> = devs.iter().map(AsRef::as_ref).collect();
|
let devset: HashSet<_> = devs.iter().map(AsRef::as_ref).collect();
|
||||||
let macset: HashSet<_> = macs.iter().collect();
|
let macset: HashSet<_> = macs.iter().collect();
|
||||||
|
|
||||||
@@ -95,6 +96,7 @@ pub async fn get_macs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// /// the atomic get_macs. handle ONE thing only.
|
// /// the atomic get_macs. handle ONE thing only.
|
||||||
|
// // this one sucks shit
|
||||||
// pub async fn get_mac(
|
// pub async fn get_mac(
|
||||||
// ip: Option<IpAddr>,
|
// ip: Option<IpAddr>,
|
||||||
// dev: Option<&str>,
|
// dev: Option<&str>,
|
||||||
@@ -113,7 +115,8 @@ pub async fn get_macs(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
/// the atomic get_macs. handle ONE thing only.
|
/// 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>,
|
ip: Option<IpAddr>,
|
||||||
dev: Option<&str>,
|
dev: Option<&str>,
|
||||||
state: &[NUDState],
|
state: &[NUDState],
|
||||||
@@ -143,45 +146,25 @@ pub async fn get_mac(
|
|||||||
let lines = String::from_utf8_lossy(&out.stdout);
|
let lines = String::from_utf8_lossy(&out.stdout);
|
||||||
let parsed = lines.lines().flat_map(arpparse::parse_ip_neigh_line);
|
let parsed = lines.lines().flat_map(arpparse::parse_ip_neigh_line);
|
||||||
let rows: Vec<IpNeighLine> = if let Some(d) = dev {
|
let rows: Vec<IpNeighLine> = if let Some(d) = dev {
|
||||||
parsed.map(IpNeighLine::with_dev(d)).collect()
|
parsed.map(IpNeighLine::_with_dev(d)).collect()
|
||||||
} else {
|
} else {
|
||||||
parsed.collect()
|
parsed.collect()
|
||||||
};
|
};
|
||||||
Ok(rows)
|
Ok(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// 15 - 20 ms full
|
||||||
/// get macs where you just run ip neigh then rust handles the filtering (faster than get mac)
|
pub async fn get_mac(
|
||||||
pub async fn get_macs_rust(
|
ip: Option<IpAddr>,
|
||||||
machine_names: Option<&str>,
|
dev: Option<&str>,
|
||||||
ips: Option<&[IpAddr]>,
|
state: &[NUDState],
|
||||||
devs: Option<&[&str]>,
|
|
||||||
states: Option<&[NUDState]>,
|
|
||||||
) -> Result<Vec<IpNeighLine>> {
|
) -> Result<Vec<IpNeighLine>> {
|
||||||
let mut ip_map: HashSet<IpAddr> = HashSet::new();
|
let state2: Vec<neighbor::NUDState> = state.iter().copied().map(Into::into).collect();
|
||||||
let mut machine_map = HashSet::new();
|
Ok(neighbor::nl::get(ip, dev, &state2)
|
||||||
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)
|
|
||||||
.await
|
.await
|
||||||
|
.context("rtnetlink failed")?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|f| f.into_iter().flatten())
|
.map(Into::into)
|
||||||
.collect()
|
.collect())
|
||||||
} */
|
// how did i just do that
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user