Compare commits
20
Commits
v0.1.6
...
b0d0bbf015
No files matched your search
+7
-2
@@ -1,5 +1,10 @@
|
|||||||
|
[target.armv7-unknown-linux-musleabihf]
|
||||||
|
linker = "rust-lld"
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
target = "armv7-unknown-linux-musleabihf"
|
target = "armv7-unknown-linux-musleabihf"
|
||||||
|
|
||||||
[target.armv7-unknown-linux-musleabihf]
|
[alias]
|
||||||
linker = "rust-lld"
|
ldabr = "b -r --target=target.armv7-unknown-linux-musleabihf"
|
||||||
|
t = "test -- --nocapture --test-threads=1"
|
||||||
|
tdebug = "test -- --nocapture --test-threads=1 --show-output"
|
||||||
File renamed without changes.
@@ -1,8 +1,10 @@
|
|||||||
you should use block code to refence code, like so:
|
you should use block code to refence code, like so:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
hello_world!(println);
|
hello_world!(println);
|
||||||
// indented lines
|
// indented lines
|
||||||
```
|
```
|
||||||
|
|
||||||
in the chat. Else it fucks up formatting.
|
in the chat. Else it fucks up formatting.
|
||||||
|
|
||||||
We work towards clean, maintainable design. im not the best at this thing.
|
We work towards clean, maintainable design. im not the best at this thing.
|
||||||
Generated
+134
-3
@@ -32,6 +32,12 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atomic-waker"
|
name = "atomic-waker"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@@ -189,6 +195,12 @@ version = "1.0.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg_aliases"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.41"
|
version = "0.4.41"
|
||||||
@@ -610,6 +622,22 @@ version = "1.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lda-ipjs"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"futures",
|
||||||
|
"macaddr",
|
||||||
|
"rtnetlink",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_with",
|
||||||
|
"strum",
|
||||||
|
"thiserror 2.0.16",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.175"
|
version = "0.2.175"
|
||||||
@@ -669,6 +697,66 @@ dependencies = [
|
|||||||
"windows-sys",
|
"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]]
|
[[package]]
|
||||||
name = "num-conv"
|
name = "num-conv"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -705,6 +793,12 @@ version = "4.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
|
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
@@ -767,6 +861,23 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.26"
|
version = "0.1.26"
|
||||||
@@ -999,13 +1110,33 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
|
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]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "2.0.16"
|
version = "2.0.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
|
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
|
||||||
dependencies = [
|
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]]
|
[[package]]
|
||||||
@@ -1179,7 +1310,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wakey"
|
name = "wakey"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
@@ -1191,7 +1322,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_with",
|
"serde_with",
|
||||||
"strum",
|
"strum",
|
||||||
"thiserror",
|
"thiserror 2.0.16",
|
||||||
"tokio",
|
"tokio",
|
||||||
"urlencoding",
|
"urlencoding",
|
||||||
]
|
]
|
||||||
|
|||||||
+13
-3
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wakey"
|
name = "wakey"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = ["gitea"]
|
publish = ["gitea"]
|
||||||
|
|
||||||
@@ -16,7 +16,13 @@ serde_json = "1.0.143"
|
|||||||
serde_with = { version = "3.14.0", features = ["json"] }
|
serde_with = { version = "3.14.0", features = ["json"] }
|
||||||
strum = { version = "0.27.2", features = ["derive", "strum_macros"] }
|
strum = { version = "0.27.2", features = ["derive", "strum_macros"] }
|
||||||
thiserror = "2.0.16"
|
thiserror = "2.0.16"
|
||||||
tokio = { version = "1.47.1", features = ["fs", "process", "rt-multi-thread", "io-util"] }
|
tokio = { version = "1.47.1", features = [
|
||||||
|
"fs",
|
||||||
|
"process",
|
||||||
|
"rt-multi-thread",
|
||||||
|
"io-util",
|
||||||
|
"macros",
|
||||||
|
] }
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
@@ -25,4 +31,8 @@ strip = true
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["very-smart-parsing"]
|
default = ["very-smart-parsing"]
|
||||||
very-smart-parsing = [] # this is the a-bit-redundant parse thing that copilot made
|
very-smart-parsing = [
|
||||||
|
] # this is the a-bit-redundant parse thing that copilot made
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = ["ipjs"]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
[package]
|
||||||
|
name = "lda-ipjs"
|
||||||
|
description = "ip -j show schemas"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
macaddr = { version = "1.0.1", features = ["serde", "serde_std"] }
|
||||||
|
strum = { version = "0.27.2", features = ["derive", "strum_macros"] }
|
||||||
|
serde_json = "1.0.143"
|
||||||
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
|
serde_with = { version = "3.14.0", features = ["json"] }
|
||||||
|
thiserror = "2.0.16"
|
||||||
|
anyhow = "1.0.100"
|
||||||
|
tokio = { version = "1.47.1", features = ["fs", "process", "rt-multi-thread", "io-util", "macros"] }
|
||||||
|
rtnetlink = "0.18.1"
|
||||||
|
futures = "0.3.31"
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
trait IpCommand {
|
||||||
|
|
||||||
|
}
|
||||||
Whitespace-only changes.
@@ -0,0 +1,20 @@
|
|||||||
|
//! low
|
||||||
|
//!
|
||||||
|
//! # lda-ipjs
|
||||||
|
//!
|
||||||
|
//! this package will represent all my needs with the all the subcommands of ip -j.
|
||||||
|
//!
|
||||||
|
//! ## what i need
|
||||||
|
//!
|
||||||
|
//! ```console
|
||||||
|
//! ip -j neigh show
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! i also need to see devices and idk MAYBE maybe not MAYBE UHHHHHH maybe broadcast
|
||||||
|
//!
|
||||||
|
//! LOWK if this were to be calls to kernel or some bullshit then PLEASE because doing ts parsing its hell cuh
|
||||||
|
|
||||||
|
pub mod subcommands;
|
||||||
|
pub mod utils;
|
||||||
|
|
||||||
|
// i want a generalized way to build and call
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]
|
||||||
|
// [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]
|
||||||
|
// [ label LABEL ] [up] [ vrf NAME ] ]
|
||||||
|
// fuck is this mean
|
||||||
|
|
||||||
|
// do i need all this? do i need anything but `ip -j a show dev br-lan`?
|
||||||
|
|
||||||
|
// TYPE := { vlan | veth | vcan | vxcan | dummy | ifb | macvlan | macvtap |
|
||||||
|
// bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |
|
||||||
|
// gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan | vti |
|
||||||
|
// nlmon | can | bond_slave | ipvlan | geneve | bridge_slave |
|
||||||
|
// hsr | macsec | netdevsim }
|
||||||
|
// FLAG-LIST := [ FLAG-LIST ] FLAG
|
||||||
|
// FLAG := [ permanent | dynamic | secondary | primary |
|
||||||
|
// [-]tentative | [-]deprecated | [-]dadfailed | temporary |
|
||||||
|
// CONFFLAG-LIST ]
|
||||||
|
// CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG
|
||||||
|
// CONFFLAG := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ]
|
||||||
|
|
||||||
|
// prefix seems to be a cidr. both 6 and 4 works. idfk dog
|
||||||
|
|
||||||
|
use super::AddrInfo;
|
||||||
|
|
||||||
|
pub async fn get(dev: Option<&str>) -> anyhow::Result<Vec<AddrInfo>> {
|
||||||
|
let mut cmd = tokio::process::Command::new("ip");
|
||||||
|
cmd.args(["-j", "address", "show"]);
|
||||||
|
|
||||||
|
if let Some(d) = dev {
|
||||||
|
cmd.args(["dev", d]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = cmd.output().await?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(String::from_utf8_lossy(&output.stderr).into_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(serde_json::from_slice(&output.stdout)?)
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
//! ts
|
||||||
|
//!
|
||||||
|
//! deals with both ip a (addroutput) and ip l (commonoutput)
|
||||||
|
//!
|
||||||
|
//! lowk why its free but its indirection and its ass
|
||||||
|
|
||||||
|
pub mod json;
|
||||||
|
|
||||||
|
use crate::utils::serialize::mac::option_mac;
|
||||||
|
use macaddr::MacAddr;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// i dont include what i dont know about (almost all ts)
|
||||||
|
#[derive(Serialize, Debug, Deserialize)]
|
||||||
|
pub struct AddrOutput {
|
||||||
|
pub ifindex: u32,
|
||||||
|
pub ifname: String,
|
||||||
|
/// i imagine UP or DOWN, unknown
|
||||||
|
pub operstate: String,
|
||||||
|
// 6 has a serde and the enum doesnt? why. (serializing ts is ass although... im not given an array. they string formatted ts)
|
||||||
|
#[serde(with = "option_mac", default)]
|
||||||
|
pub address: Option<MacAddr>,
|
||||||
|
#[serde(default)] // i wish we have intellisense for this... fuck you metaprogramming
|
||||||
|
pub addr_info: Vec<AddrInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// i be copying
|
||||||
|
// Raw JSON shape from ip -j -4 address show
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct AddrInfo {
|
||||||
|
pub family: Option<String>,
|
||||||
|
|
||||||
|
pub local: Option<String>,
|
||||||
|
pub prefixlen: Option<u8>,
|
||||||
|
|
||||||
|
pub broadcast: Option<String>,
|
||||||
|
|
||||||
|
pub scope: Option<String>,
|
||||||
|
pub label: Option<String>,
|
||||||
|
// many more exist; we only take what we need
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod address;
|
||||||
|
pub mod neighbor;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
//! idk what to put here
|
||||||
|
|
||||||
|
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 mut cmd = tokio::process::Command::new("ip");
|
||||||
|
cmd.args(["-j", "neigh", "show"]);
|
||||||
|
|
||||||
|
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)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
//! ```bash
|
||||||
|
//! ip -j n s
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! yes. this is a real call.
|
||||||
|
|
||||||
|
pub mod json;
|
||||||
|
pub mod nl;
|
||||||
|
|
||||||
|
use crate::utils::serialize::mac::option_mac;
|
||||||
|
use std::net::IpAddr;
|
||||||
|
|
||||||
|
use macaddr::MacAddr;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use strum::{Display, EnumString};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
|
||||||
|
pub struct NeighborInput {
|
||||||
|
/// supports only the last item (ignore), `to` keyword is optional
|
||||||
|
pub to: Option<IpAddr>,
|
||||||
|
/// supports only one item (it complains if multiple)
|
||||||
|
pub dev: Option<String>, // im all for simplicity
|
||||||
|
/// takes multiple, has to have `nud` before bro or it will think you `to`
|
||||||
|
pub nud: Vec<NUDState>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, Default,
|
||||||
|
)]
|
||||||
|
#[strum(serialize_all = "lowercase", ascii_case_insensitive)]
|
||||||
|
#[serde(rename_all = "UPPERCASE")]
|
||||||
|
pub enum NUDState {
|
||||||
|
/// the neighbour entry is valid forever and can
|
||||||
|
/// be only be removed administratively.
|
||||||
|
Permanent,
|
||||||
|
/// the neighbour entry is valid. No attempts to
|
||||||
|
/// validate this entry will be made but it can
|
||||||
|
/// be removed when its lifetime expires.
|
||||||
|
Noarp,
|
||||||
|
/// the neighbour entry is valid until the
|
||||||
|
/// reachability timeout expires.
|
||||||
|
Reachable,
|
||||||
|
/// the neighbour entry is valid but suspicious.
|
||||||
|
/// This option to ip neigh does not change the
|
||||||
|
/// neighbour state if it was valid and the
|
||||||
|
/// address is not changed by this command.
|
||||||
|
Stale,
|
||||||
|
/// 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.
|
||||||
|
Incomplete,
|
||||||
|
/// neighbor entry validation is currently
|
||||||
|
/// delayed.
|
||||||
|
Delay,
|
||||||
|
/// neighbor is being probed.
|
||||||
|
Probe,
|
||||||
|
/// max number of probes exceeded without
|
||||||
|
/// success, neighbor validation has ultimately
|
||||||
|
/// failed.
|
||||||
|
Failed,
|
||||||
|
|
||||||
|
Other(u16)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// everything i see
|
||||||
|
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
|
||||||
|
pub struct NeighborItem {
|
||||||
|
#[serde(rename(deserialize = "dst"))]
|
||||||
|
pub ip: IpAddr,
|
||||||
|
pub dev: String,
|
||||||
|
#[serde(with = "option_mac", default, rename(deserialize = "lladdr"))]
|
||||||
|
pub mac: Option<MacAddr>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub state: Vec<NUDState>,
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
// hallo
|
||||||
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
net::IpAddr,
|
||||||
|
};
|
||||||
|
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
use macaddr::MacAddr;
|
||||||
|
use rtnetlink::packet_route::{
|
||||||
|
AddressFamily,
|
||||||
|
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 (gip, gdev, gnud) = (ip, dev, nud);
|
||||||
|
let (conn, handle, _) = rtnetlink::new_connection()?;
|
||||||
|
tokio::spawn(conn); // every time?
|
||||||
|
let mut neighbor_data = handle.neighbours().get().execute();
|
||||||
|
let nudset: HashSet<&NUDState> = HashSet::from_iter(gnud);
|
||||||
|
let mut ball: HashMap<u32, String> = HashMap::new();
|
||||||
|
let mut result = vec![];
|
||||||
|
'big: while let Some(neighbour_message_item) = neighbor_data.try_next().await? {
|
||||||
|
// Filter by address family
|
||||||
|
if !matches!(
|
||||||
|
neighbour_message_item.header.family,
|
||||||
|
AddressFamily::Inet | AddressFamily::Inet6
|
||||||
|
) || matches!(neighbour_message_item.header.state, NeighbourState::Noarp)
|
||||||
|
// copilot says this to match ip -j n s
|
||||||
|
{
|
||||||
|
continue 'big;
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = vec![
|
||||||
|
neighbour_message_item
|
||||||
|
.header
|
||||||
|
.state
|
||||||
|
.try_into()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
]; // ONE ITEM. why tf ts design json.
|
||||||
|
let mut ip = None;
|
||||||
|
let mut mac = None;
|
||||||
|
|
||||||
|
for neigh_attr in neighbour_message_item.attributes {
|
||||||
|
match neigh_attr {
|
||||||
|
NeighbourAttribute::Destination(neighbour_address) => match neighbour_address {
|
||||||
|
NeighbourAddress::Inet(ipv4_addr) => ip = Some(ipv4_addr.into()),
|
||||||
|
NeighbourAddress::Inet6(ipv6_addr) => ip = Some(ipv6_addr.into()),
|
||||||
|
_ => continue 'big,
|
||||||
|
},
|
||||||
|
NeighbourAttribute::LinkLocalAddress(items) => {
|
||||||
|
mac = 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// exquisite
|
||||||
|
let dev = if let Some(cached) = ball.get(&neighbour_message_item.header.ifindex) {
|
||||||
|
Some(cached.clone())
|
||||||
|
} else {
|
||||||
|
// Query and cache
|
||||||
|
let name = handle
|
||||||
|
.link()
|
||||||
|
.get()
|
||||||
|
.match_index(neighbour_message_item.header.ifindex)
|
||||||
|
.execute()
|
||||||
|
.try_next()
|
||||||
|
.await?
|
||||||
|
.and_then(|a| {
|
||||||
|
a.attributes.into_iter().find_map(|attr| match attr {
|
||||||
|
LinkAttribute::IfName(name) => Some(name),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(ref n) = name {
|
||||||
|
ball.insert(neighbour_message_item.header.ifindex, n.clone());
|
||||||
|
}
|
||||||
|
name
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some((ip, dev)) = ip.zip(dev) else {
|
||||||
|
continue 'big;
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
// low block
|
||||||
|
if let Some(fip) = gip
|
||||||
|
&& fip != ip
|
||||||
|
{
|
||||||
|
continue 'big;
|
||||||
|
}
|
||||||
|
if let Some(fdev) = gdev
|
||||||
|
&& dev != fdev
|
||||||
|
{
|
||||||
|
continue 'big;
|
||||||
|
}
|
||||||
|
if !nudset.is_empty() && !nudset.contains(&state[0]) {
|
||||||
|
continue 'big;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push(NeighborItem {
|
||||||
|
ip,
|
||||||
|
dev,
|
||||||
|
mac,
|
||||||
|
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) => Ok(Self::Other(e)),
|
||||||
|
_ => Err(u16::MAX), // idk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Error = u16;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
use std::iter::Fuse;
|
||||||
|
|
||||||
|
/// wrap ts into a [Fuse][std::iter::Fuse] or something
|
||||||
|
pub struct Real<A: Clone, B: Iterator<Item = A>> {
|
||||||
|
prepend: A,
|
||||||
|
iter: B,
|
||||||
|
my_turn: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A: Clone, B: Iterator<Item = A>> Real<A, B> {
|
||||||
|
pub fn new(prepend: A, iter: B) -> Self {
|
||||||
|
Self {
|
||||||
|
prepend,
|
||||||
|
iter,
|
||||||
|
my_turn: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn fuse(prepend: A, iter: B) -> Fuse<Self> {
|
||||||
|
Self::new(prepend, iter).fuse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A: Clone, B: Iterator<Item = A>> Iterator for Real<A, B> {
|
||||||
|
type Item = A;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let a = if self.my_turn {
|
||||||
|
Some(self.prepend.clone())
|
||||||
|
} else {
|
||||||
|
self.iter.next()
|
||||||
|
};
|
||||||
|
self.my_turn = !self.my_turn;
|
||||||
|
a
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod iter;
|
||||||
|
pub mod serialize;
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
use macaddr::MacAddr;
|
||||||
|
use serde::{self, Deserialize, Deserializer, de::Error as DeError};
|
||||||
|
use serde::{Serialize, Serializer, de};
|
||||||
|
|
||||||
|
pub fn serialize_macs<S>(macs: &[MacAddr], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let strings: Vec<String> = macs.iter().map(|m| m.to_string()).collect();
|
||||||
|
serde::Serialize::serialize(&strings, serializer)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Serialize a MacAddr as a string
|
||||||
|
pub fn serialize<S>(mac: &MacAddr, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.serialize_str(&mac.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deserialize a MacAddr from a string
|
||||||
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<MacAddr, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = <String as serde::Deserialize>::deserialize(deserializer)?;
|
||||||
|
s.parse::<MacAddr>().map_err(DeError::custom)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod option_mac {
|
||||||
|
use super::*;
|
||||||
|
/// serialize an [`Option<MacAddr>`]
|
||||||
|
pub fn serialize<S: Serializer>(bro: &Option<MacAddr>, ser: S) -> Result<S::Ok, S::Error> {
|
||||||
|
Option::<String>::serialize(&bro.as_ref().map(ToString::to_string), ser)
|
||||||
|
}
|
||||||
|
/// deserialize an [`Option<MacAddr>`]
|
||||||
|
pub fn deserialize<'de, D>(des: D) -> Result<Option<MacAddr>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
Option::<&str>::deserialize(des)?
|
||||||
|
.map(str::parse)
|
||||||
|
.transpose()
|
||||||
|
.map_err(de::Error::custom)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod mac;
|
||||||
|
pub mod vec;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
use serde::Deserialize;
|
||||||
|
use serde::de;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum OneOrMany<T> {
|
||||||
|
One(T),
|
||||||
|
Many(Vec<T>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vec_from_strs<'de, D, T>(des: D) -> Result<Vec<T>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
T: std::str::FromStr,
|
||||||
|
T::Err: std::fmt::Display,
|
||||||
|
{
|
||||||
|
let raw: OneOrMany<String> = OneOrMany::<String>::deserialize(des)?;
|
||||||
|
let mut out = Vec::new();
|
||||||
|
match raw {
|
||||||
|
OneOrMany::One(s) => {
|
||||||
|
let t = s.trim();
|
||||||
|
if !t.is_empty() {
|
||||||
|
out.push(t.parse().map_err(de::Error::custom)?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OneOrMany::Many(vs) => {
|
||||||
|
for s in vs {
|
||||||
|
let t = s.trim();
|
||||||
|
if t.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out.push(t.parse().map_err(de::Error::custom)?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use lda_ipjs::subcommands::neighbor;
|
||||||
|
|
||||||
|
#[tokio::test] // ← Use tokio::test instead of manual #[tokio::main]
|
||||||
|
async fn ball1() -> anyhow::Result<()> {
|
||||||
|
let result = neighbor::nl::get(None, None, &[]).await?;
|
||||||
|
println!("netlink results: {:?}", result);
|
||||||
|
Ok(()) // ← Don't force error, let it succeed
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn ball2() -> anyhow::Result<()> {
|
||||||
|
let result = neighbor::json::get(None, None, &[]).await?;
|
||||||
|
println!("json results: {:?}", result);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add this to debug the raw JSON
|
||||||
|
#[tokio::test]
|
||||||
|
async fn ball_raw_json() -> anyhow::Result<()> {
|
||||||
|
let output = tokio::process::Command::new("ip")
|
||||||
|
.args(["-j", "neigh", "show"])
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let json = String::from_utf8_lossy(&output.stdout);
|
||||||
|
println!("Raw JSON:\n{}", json);
|
||||||
|
|
||||||
|
// Try to parse it
|
||||||
|
let parsed: Result<Vec<neighbor::NeighborItem>, _> = serde_json::from_slice(&output.stdout);
|
||||||
|
match parsed {
|
||||||
|
Ok(items) => println!("Parsed {} items", items.len()),
|
||||||
|
Err(e) => println!("Parse error: {}", e),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check what fields actually exist in the JSON
|
||||||
|
#[tokio::test]
|
||||||
|
async fn ball_field_analysis() -> anyhow::Result<()> {
|
||||||
|
let output = tokio::process::Command::new("ip")
|
||||||
|
.args(["-j", "neigh", "show"])
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let raw: Vec<serde_json::Value> = serde_json::from_slice(&output.stdout)?;
|
||||||
|
|
||||||
|
println!("Found {} neighbor entries", raw.len());
|
||||||
|
|
||||||
|
// Collect all unique field names across all entries
|
||||||
|
let mut all_fields = std::collections::HashSet::new();
|
||||||
|
for (i, entry) in raw.iter().enumerate() {
|
||||||
|
if let Some(obj) = entry.as_object() {
|
||||||
|
println!("\nEntry {}: {} fields", i, obj.len());
|
||||||
|
for (key, value) in obj {
|
||||||
|
all_fields.insert(key.clone());
|
||||||
|
println!(" {}: {} = {:?}", key, value.type_name(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("\n=== All unique fields seen ===");
|
||||||
|
for field in &all_fields {
|
||||||
|
println!(" - {}", field);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper trait to get type name for JSON values
|
||||||
|
trait TypeName {
|
||||||
|
fn type_name(&self) -> &str;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TypeName for serde_json::Value {
|
||||||
|
fn type_name(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
serde_json::Value::Null => "null",
|
||||||
|
serde_json::Value::Bool(_) => "bool",
|
||||||
|
serde_json::Value::Number(_) => "number",
|
||||||
|
serde_json::Value::String(_) => "string",
|
||||||
|
serde_json::Value::Array(_) => "array",
|
||||||
|
serde_json::Value::Object(_) => "object",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test filtering logic
|
||||||
|
#[tokio::test]
|
||||||
|
async fn ball_compare_backends() -> anyhow::Result<()> {
|
||||||
|
println!("=== JSON Backend ===");
|
||||||
|
let json_result = neighbor::json::get(None, None, &[]).await?;
|
||||||
|
println!("Got {} entries from JSON", json_result.len());
|
||||||
|
|
||||||
|
println!("\n=== Netlink Backend ===");
|
||||||
|
let nl_result = neighbor::nl::get(None, None, &[]).await?;
|
||||||
|
println!("Got {} entries from netlink", nl_result.len());
|
||||||
|
|
||||||
|
// Compare counts
|
||||||
|
if json_result.len() != nl_result.len() {
|
||||||
|
println!(
|
||||||
|
"\n⚠️ Count mismatch! JSON: {}, Netlink: {}",
|
||||||
|
json_result.len(),
|
||||||
|
nl_result.len()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
println!("\n✅ Both backends returned same count");
|
||||||
|
}
|
||||||
|
let a: HashSet<neighbor::NeighborItem> = HashSet::from_iter(json_result);
|
||||||
|
let b: HashSet<neighbor::NeighborItem> = HashSet::from_iter(nl_result);
|
||||||
|
println!(
|
||||||
|
"istg {len1} == {len2} or else",
|
||||||
|
len1 = a.len(),
|
||||||
|
len2 = b.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn cidr_filter() {
|
||||||
|
unimplemented!("never. i aint add what i dont need")
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# taking back my code AHHHH
|
||||||
|
|
||||||
|
this is going to be lengthy. ci is spotless but idk how it works cuz powershell. this is good but i cant afford VPN on the router; we will need to do some bullshit.
|
||||||
|
|
||||||
|
## overview
|
||||||
|
|
||||||
|
we need a:
|
||||||
|
|
||||||
|
- small ahh bin in the router.
|
||||||
|
- forwards a shell and some functions.
|
||||||
|
- may be shell calling fns maybe some unsafe c. i cant unsafe c.
|
||||||
|
- big ahh bin in the vps.
|
||||||
|
- connect to the small ahh bin thru the wide ass internet.
|
||||||
|
- forwards some APIs.
|
||||||
|
- static site
|
||||||
|
- now need no hosts; apis can be called anywhere anyway.
|
||||||
|
- do offer these in the big ahh bins tho lets not miss out some shit.
|
||||||
|
- automation
|
||||||
|
- gitea
|
||||||
|
- on the vps or the uh idk.
|
||||||
|
- ABSOLUTELY can auto build main:latest every day / other day.
|
||||||
|
- and releases.
|
||||||
|
- router
|
||||||
|
- a script to pull the tar. from actions artifacts or from releases. (lua or shell yo)
|
||||||
|
- a script for the bin and the init.d scripts for these two.
|
||||||
|
- vps
|
||||||
|
- a systemd service (ima use ai for ts ngl)
|
||||||
|
- an auto updater. maybe we overkill and dnf. maybe go easy and git clone + cargo install. maybe we pull from release or nightly. idk
|
||||||
|
|
||||||
|
i think idk
|
||||||
|
|
||||||
|
## router
|
||||||
|
|
||||||
|
### current
|
||||||
|
|
||||||
|
everything.
|
||||||
|
|
||||||
|
we have some functions that call ip neigh a bajillion times.
|
||||||
|
we have some other functions that read the same file/folder in /sys or sum shit.
|
||||||
|
we have a function that broadcast to a set ahh address.
|
||||||
|
|
||||||
|
we have some routes; and some data structures acting as schema for them ahh. we dont do posts with json but gets with query strings for some ahh reasons.
|
||||||
|
|
||||||
|
these are carryover from the early days.
|
||||||
|
|
||||||
|
also from the early days are the js.
|
||||||
|
|
||||||
|
static was 100% ai with 0 intervention.
|
||||||
|
|
||||||
|
we have a search bar of sort that hooks through a smart endpoint that searches for everything.
|
||||||
|
|
||||||
|
we have some bullshit. and two buttons to check and wake. that pings `/api/smart/{query}` and `/wake?name=query`. why.
|
||||||
|
we have the result of the wake and or status and the errors in the first text box.
|
||||||
|
|
||||||
|
the list of cliets with names connected to the router the second box.
|
||||||
|
thats cool.
|
||||||
|
|
||||||
|
### changes?
|
||||||
|
|
||||||
|
idk changes.
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
use macaddr::MacAddr6;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::{net::IpAddr, process::Command};
|
||||||
|
|
||||||
|
// Raw JSON shape from ip -j -4 address show
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct IpJAddrInfo {
|
||||||
|
family: Option<String>,
|
||||||
|
local: Option<String>,
|
||||||
|
broadcast: Option<String>,
|
||||||
|
scope: Option<String>,
|
||||||
|
label: Option<String>,
|
||||||
|
prefixlen: Option<u8>,
|
||||||
|
// many more exist; we only take what we need
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct IpJAddrEntry {
|
||||||
|
ifname: String,
|
||||||
|
// interface MAC address (present on non-loopback):
|
||||||
|
address: Option<String>,
|
||||||
|
addr_info: Option<Vec<IpJAddrInfo>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct AddrInfo {
|
||||||
|
pub local: IpAddr,
|
||||||
|
pub broadcast: Option<IpAddr>,
|
||||||
|
pub scope: Option<String>,
|
||||||
|
pub label: Option<String>,
|
||||||
|
pub prefixlen: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct IpAEntry {
|
||||||
|
pub ifname: String,
|
||||||
|
pub mac: Option<MacAddr6>,
|
||||||
|
pub addr_info: Vec<AddrInfo>,
|
||||||
|
// IPv4 only (inet)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run ip -j -4 address show and deserialize
|
||||||
|
fn read_ip_json() -> Result<Vec<IpJAddrEntry>, Box<dyn std::error::Error>> {
|
||||||
|
let out = Command::new("ip")
|
||||||
|
.args(["-j", "-4", "address", "show"])
|
||||||
|
.output()?;
|
||||||
|
if !out.status.success() {
|
||||||
|
return Err(format!("ip exited with {}", out.status).into());
|
||||||
|
}
|
||||||
|
let entries: Vec<IpJAddrEntry> = serde_json::from_slice(&out.stdout)?;
|
||||||
|
Ok(entries)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_ip(s: &str) -> Option<IpAddr> {
|
||||||
|
s.parse::<IpAddr>().ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_mac(s: &str) -> Option<MacAddr6> {
|
||||||
|
// ip outputs lowercase aa:bb:..., which MacAddr6 can parse
|
||||||
|
s.parse::<MacAddr6>().ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public: read and convert to a cleaned model
|
||||||
|
pub fn get_ip_addr_entries() -> Result<Vec<IpAEntry>, Box<dyn std::error::Error>> {
|
||||||
|
let raw = read_ip_json()?;
|
||||||
|
let mut out = Vec::new();
|
||||||
|
for e in raw {
|
||||||
|
let mac = e.address.as_deref().and_then(parse_mac);
|
||||||
|
let mut infos = Vec::new();
|
||||||
|
|
||||||
|
if let Some(list) = e.addr_info {
|
||||||
|
for ai in list {
|
||||||
|
// keep only IPv4
|
||||||
|
if ai.family.as_deref() != Some("inet") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(local) = ai.local.as_deref().and_then(parse_ip) {
|
||||||
|
let broadcast = ai.broadcast.as_deref().and_then(parse_ip);
|
||||||
|
infos.push(AddrInfo {
|
||||||
|
local,
|
||||||
|
broadcast,
|
||||||
|
scope: ai.scope,
|
||||||
|
label: ai.label,
|
||||||
|
prefixlen: ai.prefixlen,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out.push(IpAEntry {
|
||||||
|
ifname: e.ifname,
|
||||||
|
mac,
|
||||||
|
addr_info: infos,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper: first “good” (global) broadcast on an interface
|
||||||
|
pub fn broadcast_for_ifname(ifname: &str) -> Result<Option<IpAddr>, Box<dyn std::error::Error>> {
|
||||||
|
let entries = get_ip_addr_entries()?;
|
||||||
|
let dev = entries.into_iter().find(|e| e.ifname == ifname);
|
||||||
|
if let Some(dev) = dev {
|
||||||
|
// Prefer scope=global with a broadcast; else any broadcast
|
||||||
|
if let Some(b) = dev
|
||||||
|
.addr_info
|
||||||
|
.iter()
|
||||||
|
.filter(|ai| ai.scope.as_deref() == Some("global"))
|
||||||
|
.filter_map(|ai| ai.broadcast)
|
||||||
|
.next()
|
||||||
|
{
|
||||||
|
return Ok(Some(b));
|
||||||
|
}
|
||||||
|
if let Some(b) = dev.addr_info.iter().filter_map(|ai| ai.broadcast).next() {
|
||||||
|
return Ok(Some(b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper: broadcast for a given interface MAC
|
||||||
|
pub fn broadcast_for_mac(
|
||||||
|
mac: MacAddr6,
|
||||||
|
) -> Result<Option<(String, IpAddr)>, Box<dyn std::error::Error>> {
|
||||||
|
let entries = get_ip_addr_entries()?;
|
||||||
|
for e in entries {
|
||||||
|
if let Some(m) = e.mac {
|
||||||
|
if m == mac {
|
||||||
|
// prefer global broadcast
|
||||||
|
if let Some(b) = e
|
||||||
|
.addr_info
|
||||||
|
.iter()
|
||||||
|
.filter(|ai| ai.scope.as_deref() == Some("global"))
|
||||||
|
.filter_map(|ai| ai.broadcast)
|
||||||
|
.next()
|
||||||
|
{
|
||||||
|
return Ok(Some((e.ifname, b)));
|
||||||
|
}
|
||||||
|
if let Some(b) = e.addr_info.iter().filter_map(|ai| ai.broadcast).next() {
|
||||||
|
return Ok(Some((e.ifname, b)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: if nothing else, use limited broadcast (may be filtered on some networks)
|
||||||
|
pub fn fallback_broadcast() -> IpAddr {
|
||||||
|
// 255.255.255.255
|
||||||
|
IpAddr::from([255, 255, 255, 255])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convenience: all broadcasts grouped by interface (IPv4)
|
||||||
|
pub fn all_broadcasts() -> Result<Vec<(String, IpAddr)>, Box<dyn std::error::Error>> {
|
||||||
|
let Some(r) = Some(12) else {
|
||||||
|
e.addr_info
|
||||||
|
.iter()
|
||||||
|
.filter(|ai| ai.scope.as_deref() == Some("global"))
|
||||||
|
.filter_map(|ai| ai.broadcast)
|
||||||
|
};
|
||||||
|
let entries = get_ip_addr_entries()?;
|
||||||
|
let mut out = Vec::new();
|
||||||
|
for e in entries {
|
||||||
|
for ai in e.addr_info {
|
||||||
|
if let Some(b) = ai.broadcast {
|
||||||
|
out.push((e.ifname.clone(), b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
root = Path(__file__).parent.parent
|
root = Path(__file__).parent.parent
|
||||||
static = root / "static" # change "assets" to your folder
|
static = root / "static"
|
||||||
out_rs = root / "src" / "assets.rs"
|
src = root / "src"
|
||||||
|
out_rs = src / "assets.rs"
|
||||||
|
|
||||||
|
assert 'name = "wakey"' in (root / "Cargo.toml").read_text(
|
||||||
|
encoding="utf-8"
|
||||||
|
), "uhh how do i explain this"
|
||||||
|
|
||||||
def sanitize(name: str) -> str:
|
def sanitize(name: str) -> str:
|
||||||
# Valid Rust identifiers: letters, digits, underscores; no starting digit
|
# Valid Rust identifiers: letters, digits, underscores; no starting digit
|
||||||
@@ -35,7 +38,7 @@ class RsAssetFile:
|
|||||||
const_name = sanitize(self.path.name).upper()
|
const_name = sanitize(self.path.name).upper()
|
||||||
return (
|
return (
|
||||||
f"pub const {const_name}: &str = "
|
f"pub const {const_name}: &str = "
|
||||||
f'include_str!("{self.path.relative_to(out_rs.parent, walk_up=True).as_posix()}");'
|
f'include_str!("{self.path.relative_to(src, walk_up=True).as_posix()}");'
|
||||||
)
|
)
|
||||||
# specify walk_up to have .. in yo path
|
# specify walk_up to have .. in yo path
|
||||||
|
|
||||||
@@ -62,4 +65,4 @@ rs_code = "// generated with ./scripts/map_static.py\n" + str(
|
|||||||
RsAssetModule(static, True)
|
RsAssetModule(static, True)
|
||||||
)
|
)
|
||||||
out_rs.write_text(rs_code, encoding="utf-8")
|
out_rs.write_text(rs_code, encoding="utf-8")
|
||||||
print(f"written to {out_rs}")
|
print(f"written to {out_rs.relative_to(Path.cwd(), walk_up=True)}")
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
# Test ipjs on remote ARM device
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$Package = "lda-ipjs",
|
||||||
|
[string]$TestName = "",
|
||||||
|
[ValidateSet("debug", "release")]
|
||||||
|
[string]$BuildProfile = "debug",
|
||||||
|
[string]$password,
|
||||||
|
[switch]$Verbose,
|
||||||
|
[string]$RemoteTestPath = "/root/.bin/test",
|
||||||
|
[string]$RemoteHost = "[email protected]"
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Build tests and capture output
|
||||||
|
Write-Host "Building tests for $Package..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Stream cargo output anc convert to text
|
||||||
|
$cargoOutput = cargo test --no-run -p $Package --target armv7-unknown-linux-musleabihf $(if ($BuildProfile -eq "release") { "-r" }) 2>&1 |
|
||||||
|
ForEach-Object {
|
||||||
|
$line = if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.ToString() } else { $_ }
|
||||||
|
if ($Verbose) {
|
||||||
|
Write-Host $line
|
||||||
|
}
|
||||||
|
$line # Pass through to capture
|
||||||
|
}
|
||||||
|
|
||||||
|
# Parse test binary paths from cargo output
|
||||||
|
$testBinaries = $cargoOutput |
|
||||||
|
Select-String -Pattern "Executable.*\((.+)\)" |
|
||||||
|
ForEach-Object { $_.Matches.Groups[1].Value } |
|
||||||
|
Get-Item
|
||||||
|
|
||||||
|
if ($testBinaries.Count -eq 0) {
|
||||||
|
Write-Error "No test binaries found!"
|
||||||
|
Write-Host "Cargo output:" -ForegroundColor Yellow
|
||||||
|
$cargoOutput | ForEach-Object { Write-Host $_ }
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Found $($testBinaries.Count) test $($testBinaries.Count -eq 1 ? "binary" : "binaries")" -ForegroundColor Green
|
||||||
|
|
||||||
|
# Run each test binary
|
||||||
|
foreach ($testBinary in $testBinaries) {
|
||||||
|
Write-Host "`nTesting: $($testBinary.Name)" -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Copy to target
|
||||||
|
pscp.exe -batch -scp -pw $password $testBinary.FullName ${RemoteHost}:$RemoteTestPath | Out-Null
|
||||||
|
|
||||||
|
# Run on target
|
||||||
|
$testArgs = "$(if ($Verbose) {"--nocapture --show-output"})"
|
||||||
|
if ($TestName) {
|
||||||
|
$testArgs = "$TestName $testArgs"
|
||||||
|
}
|
||||||
|
|
||||||
|
plink -batch -ssh $RemoteHost -pw $password "chmod +x $RemoteTestPath && $RemoteTestPath $testArgs"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`nDone!" -ForegroundColor Green
|
||||||
+9
-5
@@ -41,7 +41,7 @@ pub struct IpNeighLine {
|
|||||||
|
|
||||||
// NUDState custom Deserialize now lives in arpparse/impl.rs; use serde_with OneOrMany for Vec
|
// NUDState custom Deserialize now lives in arpparse/impl.rs; use serde_with OneOrMany for Vec
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, EnumString, Display, Clone, Copy, Hash, serde::Serialize)]
|
#[derive(Debug, PartialEq, Eq, EnumString, Display, Clone, Copy, Hash, serde::Serialize, Default)]
|
||||||
#[strum(serialize_all = "UPPERCASE", ascii_case_insensitive)]
|
#[strum(serialize_all = "UPPERCASE", ascii_case_insensitive)]
|
||||||
#[serde(rename_all = "UPPERCASE")]
|
#[serde(rename_all = "UPPERCASE")]
|
||||||
pub enum NUDState {
|
pub enum NUDState {
|
||||||
@@ -63,10 +63,7 @@ pub enum NUDState {
|
|||||||
/// neighbour state if it was valid and the
|
/// neighbour state if it was valid and the
|
||||||
/// address is not changed by this command.
|
/// address is not changed by this command.
|
||||||
Stale,
|
Stale,
|
||||||
/// 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.
|
|
||||||
None,
|
|
||||||
|
|
||||||
/// the neighbour entry has not (yet) been
|
/// the neighbour entry has not (yet) been
|
||||||
/// validated/resolved.
|
/// validated/resolved.
|
||||||
@@ -80,6 +77,13 @@ pub enum NUDState {
|
|||||||
/// success, neighbor validation has ultimately
|
/// success, neighbor validation has ultimately
|
||||||
/// failed.
|
/// failed.
|
||||||
Failed,
|
Failed,
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
#[serde(other)]
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NUDState {
|
impl NUDState {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ async fn entry() -> io::Result<()> {
|
|||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
fn main() -> color_eyre::Result<()> {
|
fn main() -> color_eyre::Result<()> {
|
||||||
|
use std::net::ToSocketAddrs;
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
// use crate::arpparse::NUDState;
|
// use crate::arpparse::NUDState;
|
||||||
// println!("{}", NUDState::Reachable.to_string().to_lowercase());
|
// println!("{}", NUDState::Reachable.to_string().to_lowercase());
|
||||||
|
|||||||
+3
-10
@@ -49,12 +49,10 @@ pub async fn status_smart_redirect(
|
|||||||
};
|
};
|
||||||
match serde_html_form::to_string(query) {
|
match serde_html_form::to_string(query) {
|
||||||
Ok(e) => Ok(Redirect::to(&format!("/api/status?{e}"))),
|
Ok(e) => Ok(Redirect::to(&format!("/api/status?{e}"))),
|
||||||
Err(e) => Err((
|
Err(e) => Err(ApiError {
|
||||||
StatusCode::BAD_GATEWAY,
|
|
||||||
Json(ApiError {
|
|
||||||
error: e.to_string(),
|
error: e.to_string(),
|
||||||
|
code: StatusCode::BAD_GATEWAY,
|
||||||
}),
|
}),
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,12 +65,7 @@ pub async fn status_redirect(Path(NamePath { name }): Path<NamePath>) -> Redirec
|
|||||||
|
|
||||||
pub async fn ip(Path(name): Path<String>) -> impl IntoResponse {
|
pub async fn ip(Path(name): Path<String>) -> impl IntoResponse {
|
||||||
get_ips(&name).await.map_or_else(
|
get_ips(&name).await.map_or_else(
|
||||||
|e| {
|
|e| ApiError::ise(e.to_string()).into_response(),
|
||||||
ApiError {
|
|
||||||
error: e.to_string(),
|
|
||||||
}
|
|
||||||
.into_response()
|
|
||||||
},
|
|
||||||
|ips| Json(ips.collect::<Vec<_>>()).into_response(),
|
|ips| Json(ips.collect::<Vec<_>>()).into_response(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
+3
-5
@@ -26,12 +26,10 @@ pub async fn get_dhcp_leases(Query(raw): Query<DhcpLeasesQueryRaw>) -> impl Into
|
|||||||
let out = enrich_leases_with_nud_state(leases_with_names).await;
|
let out = enrich_leases_with_nud_state(leases_with_names).await;
|
||||||
(StatusCode::OK, Json(out)).into_response()
|
(StatusCode::OK, Json(out)).into_response()
|
||||||
}
|
}
|
||||||
Err(e) => (
|
Err(e) => ApiError {
|
||||||
StatusCode::BAD_GATEWAY,
|
|
||||||
Json(ApiError {
|
|
||||||
error: e.to_string(),
|
error: e.to_string(),
|
||||||
}),
|
code: StatusCode::BAD_GATEWAY,
|
||||||
)
|
}
|
||||||
.into_response(),
|
.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-1
@@ -7,11 +7,23 @@ use serde::Serialize;
|
|||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct ApiError {
|
pub struct ApiError {
|
||||||
|
#[serde(skip_serializing, skip_deserializing)]
|
||||||
|
pub code: StatusCode,
|
||||||
pub error: String,
|
pub error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ApiError {
|
||||||
|
/// [StatusCode::INTERNAL_SERVER_ERROR]
|
||||||
|
pub const fn ise(error: String) -> Self {
|
||||||
|
Self {
|
||||||
|
code: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntoResponse for ApiError {
|
impl IntoResponse for ApiError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(self)).into_response()
|
(self.code, Json(self)).into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ pub mod status;
|
|||||||
pub mod wake;
|
pub mod wake;
|
||||||
|
|
||||||
use crate::assets;
|
use crate::assets;
|
||||||
|
use crate::dhcpparse::load_mac_name_cache;
|
||||||
use crate::route::api::ip;
|
use crate::route::api::ip;
|
||||||
use crate::route::api::status_redirect;
|
use crate::route::api::status_redirect;
|
||||||
use crate::route::api::status_smart_redirect;
|
use crate::route::api::status_smart_redirect;
|
||||||
@@ -14,6 +15,8 @@ use crate::route::dhcp::get_dhcp_leases;
|
|||||||
use crate::route::status::get_status_json;
|
use crate::route::status::get_status_json;
|
||||||
use crate::route::wake::wake_multi;
|
use crate::route::wake::wake_multi;
|
||||||
|
|
||||||
|
use axum::Json;
|
||||||
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::post;
|
use axum::routing::post;
|
||||||
use axum::{Router, http::header, response::Html, routing::get};
|
use axum::{Router, http::header, response::Html, routing::get};
|
||||||
|
|
||||||
@@ -57,4 +60,13 @@ pub fn api_router() -> Router {
|
|||||||
.route("/devs", get(devs_router))
|
.route("/devs", get(devs_router))
|
||||||
.route("/wake", post(wake_multi))
|
.route("/wake", post(wake_multi))
|
||||||
.route("/ips/{name}", get(ip))
|
.route("/ips/{name}", get(ip))
|
||||||
|
.route(
|
||||||
|
"/mac-cache",
|
||||||
|
get(|| async {
|
||||||
|
match load_mac_name_cache().await {
|
||||||
|
Ok(h) => Json(h).into_response(),
|
||||||
|
Err(e) => e.to_string().into_response(),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
+3
-13
@@ -47,14 +47,6 @@ pub struct Filters {
|
|||||||
pub macs: Vec<MacAddr>,
|
pub macs: Vec<MacAddr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated = "use ApiError"]
|
|
||||||
#[skip_serializing_none]
|
|
||||||
#[derive(Debug, Serialize, Default)]
|
|
||||||
pub struct StatusError {
|
|
||||||
pub name: Option<String>,
|
|
||||||
pub error: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_status_json(
|
pub async fn get_status_json(
|
||||||
Query(DeviceQuery {
|
Query(DeviceQuery {
|
||||||
name,
|
name,
|
||||||
@@ -94,12 +86,10 @@ pub async fn get_status_json(
|
|||||||
)
|
)
|
||||||
.into_response()
|
.into_response()
|
||||||
}
|
}
|
||||||
Err(error) => (
|
Err(error) => ApiError {
|
||||||
StatusCode::BAD_GATEWAY,
|
code: StatusCode::BAD_GATEWAY,
|
||||||
Json(ApiError {
|
|
||||||
error: error.to_string(),
|
error: error.to_string(),
|
||||||
}),
|
}
|
||||||
)
|
|
||||||
.into_response(),
|
.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -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()
|
||||||
|
|||||||
+5
-14
@@ -48,7 +48,7 @@ pub async fn get_macs(
|
|||||||
let ip_m: HashSet<IpAddr> = futures::future::try_join_all(
|
let ip_m: HashSet<IpAddr> = futures::future::try_join_all(
|
||||||
machine_names
|
machine_names
|
||||||
.iter()
|
.iter()
|
||||||
.map(|c| async { get_ips(c.as_ref()).await }),
|
.map(|c| get_ips(c.as_ref())),
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -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());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ impl From<WakeTargetResult> for RouteWakeResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RouteWakeTarget {
|
impl RouteWakeTarget {
|
||||||
pub fn to_incomplete(self) -> RouteWakeResult {
|
pub const fn to_incomplete(self) -> RouteWakeResult {
|
||||||
RouteWakeResult {
|
RouteWakeResult {
|
||||||
target: self,
|
target: self,
|
||||||
status: RouteWakeStatus::Incomplete,
|
status: RouteWakeStatus::Incomplete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn is_incomplete(&self) -> bool {
|
pub const fn is_incomplete(&self) -> bool {
|
||||||
!matches!(
|
!matches!(
|
||||||
self,
|
self,
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -22,21 +22,21 @@ pub enum WakeStatus {
|
|||||||
WrongSize,
|
WrongSize,
|
||||||
}
|
}
|
||||||
impl WakeTarget {
|
impl WakeTarget {
|
||||||
fn _new(ip: IpAddr, mac: MacAddr) -> Self {
|
const fn _new(ip: IpAddr, mac: MacAddr) -> Self {
|
||||||
Self { ip, mac }
|
Self { ip, mac }
|
||||||
}
|
}
|
||||||
fn good(self) -> WakeTargetResult {
|
const fn good(self) -> WakeTargetResult {
|
||||||
WakeTargetResult::new(self, WakeStatus::Success)
|
WakeTargetResult::new(self, WakeStatus::Success)
|
||||||
}
|
}
|
||||||
fn bad(self) -> WakeTargetResult {
|
const fn bad(self) -> WakeTargetResult {
|
||||||
WakeTargetResult::new(self, WakeStatus::WrongSize)
|
WakeTargetResult::new(self, WakeStatus::WrongSize)
|
||||||
}
|
}
|
||||||
fn errored(self) -> WakeTargetResult {
|
const fn errored(self) -> WakeTargetResult {
|
||||||
WakeTargetResult::new(self, WakeStatus::NonexistentAddress)
|
WakeTargetResult::new(self, WakeStatus::NonexistentAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl WakeTargetResult {
|
impl WakeTargetResult {
|
||||||
fn new(target: WakeTarget, status: WakeStatus) -> Self {
|
const fn new(target: WakeTarget, status: WakeStatus) -> Self {
|
||||||
Self { target, status }
|
Self { target, status }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user