use hotplug hooks, cant wait to use ts.

This commit is contained in:
lda
2026-04-26 22:17:28 +07:00 Verified
parent dc35e6e5d1
commit 35bed390f7
9 changed files with 258 additions and 1 deletions
+55
View File
@@ -33,6 +33,8 @@ pub enum Command {
Wake(WakeArgs),
/// Show condensed network interface summaries.
Devs(DevsArgs),
/// Record local hotplug observations.
Observe(ObserveArgs),
}
#[derive(Args)]
@@ -116,6 +118,42 @@ pub struct DevsArgs {
pub json: bool,
}
#[derive(Args)]
pub struct ObserveArgs {
#[command(subcommand)]
pub command: ObserveCommand,
}
#[derive(Subcommand)]
pub enum ObserveCommand {
/// Observe a dnsmasq DHCP lease event.
Dhcp(ObserveDhcpArgs),
/// Observe a neighbor-table event.
Neigh(ObserveNeighArgs),
}
#[derive(Args)]
pub struct ObserveDhcpArgs {
#[arg(long)]
pub action: String,
#[arg(long)]
pub mac: macaddr::MacAddr,
#[arg(long)]
pub ip: Option<IpAddr>,
#[arg(long)]
pub hostname: Option<String>,
}
#[derive(Args)]
pub struct ObserveNeighArgs {
#[arg(long)]
pub action: String,
#[arg(long)]
pub mac: Option<macaddr::MacAddr>,
#[arg(long)]
pub ip: Option<IpAddr>,
}
pub fn init_tracing(verbose: u8) {
let filter = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new(default_filter_for_verbosity(verbose)))
@@ -206,6 +244,23 @@ pub async fn run(cli: Cli) -> Result<()> {
println!("{}", table::render_devs_table(&devs));
}
}
Command::Observe(args) => match args.command {
ObserveCommand::Dhcp(args) => {
let changed = wakey::observe_dhcp_event(
&args.action,
args.mac,
args.ip,
args.hostname.as_deref(),
)
.await?;
println!("observed=dhcp changed={changed}");
}
ObserveCommand::Neigh(args) => {
let changed =
wakey::observe_neighbor_event(&args.action, args.mac, args.ip).await?;
println!("observed=neigh changed={changed}");
}
},
}
Ok(())
+1
View File
@@ -9,6 +9,7 @@ pub use service::{
inventory, leases_without_state, merge_devices, resolve_devices, resolve_query,
resolve_selector, resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
};
pub use wakey_linux::dhcp::{observe_dhcp_event, observe_neighbor_event};
#[cfg(test)]
mod tests {