like idk this compiles or not
This commit is contained in:
Generated
+114
-4
@@ -195,6 +195,12 @@ version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||
|
||||
[[package]]
|
||||
name = "cfg_aliases"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.41"
|
||||
@@ -621,12 +627,13 @@ name = "lda-ipjs"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"futures",
|
||||
"macaddr",
|
||||
"rtnetlink",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"strum",
|
||||
"thiserror",
|
||||
"thiserror 2.0.16",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -689,6 +696,66 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-packet-core"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3463cbb78394cb0141e2c926b93fc2197e473394b761986eca3b9da2c63ae0f4"
|
||||
dependencies = [
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-packet-route"
|
||||
version = "0.25.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ec2f5b6839be2a19d7fa5aab5bc444380f6311c2b693551cb80f45caaa7b5ef"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
"log",
|
||||
"netlink-packet-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-proto"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b65d130ee111430e47eed7896ea43ca693c387f097dd97376bffafbf25812128"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures",
|
||||
"log",
|
||||
"netlink-packet-core",
|
||||
"netlink-sys",
|
||||
"thiserror 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "netlink-sys"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16c903aa70590cb93691bf97a767c8d1d6122d2cc9070433deb3bbf36ce8bd23"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures",
|
||||
"libc",
|
||||
"log",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
@@ -725,6 +792,12 @@ version = "4.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
@@ -787,6 +860,23 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rtnetlink"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08fd15aa4c64c34d0b3178e45ec6dad313a9f02b193376d501668a7950264bb7"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"log",
|
||||
"netlink-packet-core",
|
||||
"netlink-packet-route",
|
||||
"netlink-proto",
|
||||
"netlink-sys",
|
||||
"nix",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.26"
|
||||
@@ -1019,13 +1109,33 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
dependencies = [
|
||||
"thiserror-impl 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
"thiserror-impl 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1211,7 +1321,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"strum",
|
||||
"thiserror",
|
||||
"thiserror 2.0.16",
|
||||
"tokio",
|
||||
"urlencoding",
|
||||
]
|
||||
|
||||
+2
-1
@@ -8,9 +8,10 @@ edition = "2024"
|
||||
macaddr = { version = "1.0.1", features = ["serde", "serde_std"] }
|
||||
strum = { version = "0.27.2", features = ["derive", "strum_macros"] }
|
||||
serde_json = "1.0.143"
|
||||
serde_with = { version = "3.14.0", features = ["json"] }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
thiserror = "2.0.16"
|
||||
anyhow = "1.0.100"
|
||||
tokio = { version = "1.47.1", features = ["fs", "process", "rt-multi-thread", "io-util"] }
|
||||
rtnetlink = "0.18.1"
|
||||
futures = "0.3.31"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//!
|
||||
//! lowk why its free but its indirection and its ass
|
||||
|
||||
use macaddr::{MacAddr, MacAddr6};
|
||||
use macaddr::MacAddr6;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// i dont include what i dont know about (almost all ts)
|
||||
|
||||
@@ -1,25 +1,41 @@
|
||||
//! idk what to put here
|
||||
|
||||
use std::{iter, net::IpAddr};
|
||||
use std::net::IpAddr;
|
||||
|
||||
use anyhow::bail;
|
||||
|
||||
use super::{NUDState, NeighborItem};
|
||||
|
||||
// loose translation of [wakey::utils::query::macs::get_mac]
|
||||
// i think ill write tokio::process every time tho (for this if let thing) because iterate through all ts youll have to as str and all the hooplas.
|
||||
// it all turns to live osstr tho so ts just for my own sanity
|
||||
// thiserror? anyhow
|
||||
pub async fn get(
|
||||
ip: Option<IpAddr>,
|
||||
dev: Option<&str>,
|
||||
nud: &[NUDState],
|
||||
) -> anyhow::Result<Vec<NeighborItem>> {
|
||||
let output = tokio::process::Command::new("ip")
|
||||
.args(
|
||||
(["-j", "neigh", "show"].iter().map(ToString::to_string))
|
||||
.chain(ip.map(|ip| ip.to_canonical().to_string()))
|
||||
.chain(dev.map(ToString::to_string))
|
||||
.chain(nud.iter().map(|f| f.to_string())),
|
||||
)
|
||||
.output()
|
||||
.await?;
|
||||
let mut cmd = tokio::process::Command::new("ip");
|
||||
cmd.args(["-j", "neigh", "show"]);
|
||||
|
||||
bail!("no")
|
||||
if let Some(ip) = ip {
|
||||
cmd.arg(ip.to_canonical().to_string());
|
||||
};
|
||||
|
||||
if let Some(dev) = dev {
|
||||
cmd.arg("dev");
|
||||
cmd.arg(dev);
|
||||
}
|
||||
for nud in nud {
|
||||
cmd.arg("nud");
|
||||
cmd.arg(nud.to_string());
|
||||
}
|
||||
|
||||
let output = cmd.output().await?;
|
||||
|
||||
if !output.status.success() {
|
||||
bail!(String::from_utf8_lossy(&output.stderr).into_owned())
|
||||
} else {
|
||||
Ok(serde_json::from_slice(&output.stdout)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
//! yes. this is a real call.
|
||||
|
||||
pub mod json;
|
||||
pub mod nl;
|
||||
|
||||
use crate::utils::serialize::mac::{des_opm, ser_opm};
|
||||
use std::net::IpAddr;
|
||||
@@ -25,7 +26,9 @@ pub struct NeighborInput {
|
||||
|
||||
// as input this must be lowercase. as output it is uppercase
|
||||
/// docs for items come from a random ahh man website idk
|
||||
#[derive(Debug, PartialEq, Eq, EnumString, Display, Clone, Copy, Hash, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Debug, PartialEq, Eq, EnumString, Display, Clone, Copy, Hash, Serialize, Deserialize, Default,
|
||||
)]
|
||||
#[strum(serialize_all = "lowercase", ascii_case_insensitive)]
|
||||
#[serde(rename_all = "UPPERCASE")]
|
||||
pub enum NUDState {
|
||||
@@ -47,6 +50,7 @@ pub enum NUDState {
|
||||
/// this is a pseudo state used when initially
|
||||
/// creating a neighbour entry or after trying to
|
||||
/// remove it before it becomes free to do so.
|
||||
#[default]
|
||||
None,
|
||||
/// the neighbour entry has not (yet) been
|
||||
/// validated/resolved.
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// hallo
|
||||
use std::net::IpAddr;
|
||||
|
||||
use futures::TryStreamExt;
|
||||
use macaddr::MacAddr;
|
||||
use rtnetlink::packet_route::{
|
||||
link::LinkAttribute,
|
||||
neighbour::{NeighbourAddress, NeighbourAttribute, NeighbourState},
|
||||
};
|
||||
|
||||
use super::{NUDState, NeighborItem};
|
||||
|
||||
// dont you love https://github.com/rust-netlink/rtnetlink/blob/main/examples/get_neighbours.rs
|
||||
pub async fn get(
|
||||
ip: Option<IpAddr>,
|
||||
dev: Option<&str>,
|
||||
nud: &[NUDState],
|
||||
) -> anyhow::Result<Vec<NeighborItem>> {
|
||||
let (conn, handle, _) = rtnetlink::new_connection()?;
|
||||
tokio::spawn(conn); // every time?
|
||||
let mut neighbor_data = handle.neighbours().get().execute(); // can i change header with message_mut? what even is header.
|
||||
let mut result = vec![];
|
||||
'big: while let Some(neighbour_message_item) = neighbor_data.try_next().await? {
|
||||
let state = vec![
|
||||
neighbour_message_item
|
||||
.header
|
||||
.state
|
||||
.try_into()
|
||||
.unwrap_or_default(),
|
||||
];
|
||||
let mut dst = None;
|
||||
let mut lladdr = None;
|
||||
|
||||
// a hassle and a half to get the name
|
||||
let dev = handle
|
||||
.link()
|
||||
.get()
|
||||
.match_index(neighbour_message_item.header.ifindex)
|
||||
.execute()
|
||||
.try_next()
|
||||
.await?
|
||||
.and_then(|a| {
|
||||
for link_attr in a.attributes {
|
||||
match link_attr {
|
||||
LinkAttribute::IfName(name) => return Some(name),
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
None
|
||||
});
|
||||
for neigh_attr in neighbour_message_item.attributes {
|
||||
match neigh_attr {
|
||||
NeighbourAttribute::Destination(neighbour_address) => match neighbour_address {
|
||||
NeighbourAddress::Inet(ipv4_addr) => dst = Some(ipv4_addr.into()),
|
||||
NeighbourAddress::Inet6(ipv6_addr) => dst = Some(ipv6_addr.into()),
|
||||
_ => continue 'big,
|
||||
},
|
||||
NeighbourAttribute::LinkLocalAddress(items) => {
|
||||
lladdr = match items.len() {
|
||||
6 => items.first_chunk::<6>().map(|&e| MacAddr::from(e)),
|
||||
8 => items.first_chunk::<8>().map(|&e| MacAddr::from(e)),
|
||||
_ => continue 'big,
|
||||
}
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
let Some((dst, dev)) = dst.zip(dev) else {
|
||||
continue;
|
||||
};
|
||||
result.push(NeighborItem {
|
||||
dst,
|
||||
dev,
|
||||
lladdr,
|
||||
state,
|
||||
});
|
||||
}
|
||||
Ok(result) // now i need another pass to filter out the uh.
|
||||
}
|
||||
|
||||
impl TryFrom<NeighbourState> for NUDState {
|
||||
fn try_from(value: NeighbourState) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
NeighbourState::Incomplete => Ok(Self::Incomplete),
|
||||
NeighbourState::Reachable => Ok(Self::Reachable),
|
||||
NeighbourState::Stale => Ok(Self::Stale),
|
||||
NeighbourState::Delay => Ok(Self::Delay),
|
||||
NeighbourState::Probe => Ok(Self::Probe),
|
||||
NeighbourState::Failed => Ok(Self::Failed),
|
||||
NeighbourState::Noarp => Ok(Self::Noarp),
|
||||
NeighbourState::Permanent => Ok(Self::Permanent),
|
||||
NeighbourState::None => Ok(Self::None),
|
||||
NeighbourState::Other(e) => Err(e),
|
||||
_ => Err(u16::MAX), // idk
|
||||
}
|
||||
}
|
||||
|
||||
type Error = u16;
|
||||
}
|
||||
+1
-3
@@ -8,14 +8,11 @@
|
||||
//! 2. incorporate ip -j;
|
||||
//! 3. small 1-5 second caching;
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
use tokio::net::TcpListener;
|
||||
mod arpparse;
|
||||
pub mod assets;
|
||||
mod dhcpparse;
|
||||
mod route;
|
||||
mod utils;
|
||||
use std::io;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[tokio::main]
|
||||
@@ -36,6 +33,7 @@ async fn entry() -> io::Result<()> {
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn main() -> color_eyre::Result<()> {
|
||||
use std::net::ToSocketAddrs;
|
||||
color_eyre::install()?;
|
||||
// use crate::arpparse::NUDState;
|
||||
// println!("{}", NUDState::Reachable.to_string().to_lowercase());
|
||||
|
||||
Reference in New Issue
Block a user