im not sure what im changing
This commit is contained in:
@@ -9,6 +9,7 @@ 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"] }
|
||||
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
//! low
|
||||
//!
|
||||
//! # lda-ipj
|
||||
//! # lda-ipjs
|
||||
//!
|
||||
//! this package will represent all my needs with the all the subcommands of ip -j.
|
||||
//!
|
||||
//! ## what i need
|
||||
//!
|
||||
//! ```console
|
||||
//! ip -j neigh
|
||||
//! ip -j neigh show
|
||||
//! ```
|
||||
//!
|
||||
//! i also need to see devices and idk MAYBE maybe not MAYBE UHHHHHH maybe broadcast
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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() -> Vec<AddrInfo> {
|
||||
todo!()
|
||||
}
|
||||
@@ -4,39 +4,38 @@
|
||||
//!
|
||||
//! lowk why its free but its indirection and its ass
|
||||
|
||||
use macaddr::MacAddr6;
|
||||
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(Debug, Serialize, Deserialize)]
|
||||
struct CommmonOutput {
|
||||
ifindex: u32,
|
||||
ifname: String,
|
||||
/// i imagine UP or DOWN, unknown
|
||||
operstate: String,
|
||||
// 6 has a serde and the enum doesnt? why.
|
||||
address: Option<MacAddr6>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Deserialize)]
|
||||
struct AddrOutput {
|
||||
#[serde(flatten)]
|
||||
c: CommmonOutput,
|
||||
addr_info: Vec<AddrInfo>,
|
||||
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)]
|
||||
struct AddrInfo {
|
||||
family: Option<String>,
|
||||
pub struct AddrInfo {
|
||||
pub family: Option<String>,
|
||||
|
||||
local: Option<String>,
|
||||
prefixlen: Option<u8>,
|
||||
pub local: Option<String>,
|
||||
pub prefixlen: Option<u8>,
|
||||
|
||||
broadcast: Option<String>,
|
||||
pub broadcast: Option<String>,
|
||||
|
||||
scope: Option<String>,
|
||||
label: Option<String>,
|
||||
pub scope: Option<String>,
|
||||
pub label: Option<String>,
|
||||
// many more exist; we only take what we need
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
pub mod json;
|
||||
pub mod nl;
|
||||
|
||||
use crate::utils::serialize::mac::{des_opm, ser_opm};
|
||||
use crate::utils::serialize::mac::option_mac;
|
||||
use std::net::IpAddr;
|
||||
|
||||
use macaddr::MacAddr;
|
||||
@@ -17,11 +17,11 @@ 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
|
||||
to: Option<IpAddr>,
|
||||
pub to: Option<IpAddr>,
|
||||
/// supports only one item (it complains if multiple)
|
||||
dev: Option<String>, // im all for simplicity
|
||||
pub dev: Option<String>, // im all for simplicity
|
||||
/// takes multiple, has to have `nud` before bro or it will think you `to`
|
||||
nud: Vec<NUDState>,
|
||||
pub nud: Vec<NUDState>,
|
||||
}
|
||||
|
||||
// as input this must be lowercase. as output it is uppercase
|
||||
@@ -64,21 +64,18 @@ pub enum NUDState {
|
||||
/// 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"))]
|
||||
ip: IpAddr,
|
||||
dev: String,
|
||||
#[serde(
|
||||
deserialize_with = "des_opm",
|
||||
serialize_with = "ser_opm",
|
||||
default,
|
||||
rename(deserialize = "lladdr")
|
||||
)]
|
||||
mac: Option<MacAddr>,
|
||||
pub ip: IpAddr,
|
||||
pub dev: String,
|
||||
#[serde(with = "option_mac", default, rename(deserialize = "lladdr"))]
|
||||
pub mac: Option<MacAddr>,
|
||||
#[serde(default)]
|
||||
state: Vec<NUDState>,
|
||||
pub state: Vec<NUDState>,
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ impl TryFrom<NeighbourState> for NUDState {
|
||||
NeighbourState::Noarp => Ok(Self::Noarp),
|
||||
NeighbourState::Permanent => Ok(Self::Permanent),
|
||||
NeighbourState::None => Ok(Self::None),
|
||||
NeighbourState::Other(e) => Err(e),
|
||||
NeighbourState::Other(e) => Ok(Self::Other(e)),
|
||||
_ => Err(u16::MAX), // idk
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ where
|
||||
}
|
||||
|
||||
/// Serialize a MacAddr as a string
|
||||
pub fn serialize_mac<S>(mac: &MacAddr, serializer: S) -> Result<S::Ok, S::Error>
|
||||
pub fn serialize<S>(mac: &MacAddr, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
@@ -19,7 +19,7 @@ where
|
||||
}
|
||||
|
||||
/// Deserialize a MacAddr from a string
|
||||
pub fn deserialize_mac<'de, D>(deserializer: D) -> Result<MacAddr, D::Error>
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<MacAddr, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
@@ -27,18 +27,20 @@ where
|
||||
s.parse::<MacAddr>().map_err(DeError::custom)
|
||||
}
|
||||
|
||||
/// serialize an [`Option<MacAddr>`]
|
||||
pub fn ser_opm<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 des_opm<'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)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user