Add passive mDNS/Bonjour discovery scanner

Introduce a second discovery module that passively listens for mDNS
multicast announcements (224.0.0.251:5353) and feeds discovered devices
into the existing devices/events/notifications pipeline, running in its
own task alongside the ARP scanner.

Since mDNS carries an IP and hostname but no MAC (the device key), the
module resolves IP->MAC via the OS ARP cache with a targeted ARP-probe
fallback. The advertised hostname is stored in a new optional `name`
column on devices (blank for ARP-only devices); the single `update`
writes `name` only when set so ARP rescans never clobber it. Device
names are included in event/notification messages.

Adds a GET /api/mdns_scanner/status endpoint (is_listening, devices_seen,
last_device_seen_seconds_ago) wired into OpenAPI, an optional
[mdns_scanner] config section, and the corresponding Nix module option.
Also aligns the Nix module's stale `timings` section with the current
`arp_scanner` schema.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-29 09:37:33 -04:00
co-authored by Claude Opus 4.7
parent 2fe850c070
commit ca83009944
26 changed files with 778 additions and 157 deletions
+13 -8
View File
@@ -6,6 +6,8 @@ use crate::model::notifications::{Notification, NotificationType};
use crate::settings::get_settings;
use crate::web_server::arp_scanner::ArpScannerStatusResponse;
use crate::web_server::devices::RegisterDevicePayload;
use crate::web_server::mdns_scanner::MdnsScannerStatusResponse;
use axum::Json;
use axum::extract::Request;
use axum::http::StatusCode;
use axum::middleware::Next;
@@ -16,15 +18,15 @@ use log::{debug, error, info};
use tower::ServiceBuilder;
use tower_http::cors::{Any, CorsLayer};
use tower_http::services::ServeDir;
use axum::Json;
use utoipa::Modify;
use utoipa::OpenApi;
use utoipa::openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme};
use utoipa::Modify;
use utoipa_swagger_ui::SwaggerUi;
pub mod arp_scanner;
pub mod device_events;
pub mod devices;
pub mod mdns_scanner;
pub mod notifications;
pub mod utils;
@@ -49,6 +51,7 @@ pub mod utils;
notifications::mark_all_as_old,
device_events::list,
arp_scanner::status,
mdns_scanner::status,
),
components(schemas(
Device,
@@ -59,6 +62,7 @@ pub mod utils;
DeviceEvent,
DeviceEventType,
ArpScannerStatusResponse,
MdnsScannerStatusResponse,
)),
modifiers(&SecurityAddon),
tags(
@@ -66,6 +70,7 @@ pub mod utils;
(name = "notifications", description = "Notification management"),
(name = "device_events", description = "Device event history"),
(name = "arp_scanner", description = "ARP scanner process status"),
(name = "mdns_scanner", description = "mDNS/Bonjour scanner process status"),
)
)]
struct ApiDoc;
@@ -77,11 +82,7 @@ impl Modify for SecurityAddon {
let components = openapi.components.get_or_insert_with(Default::default);
components.add_security_scheme(
"bearer_auth",
SecurityScheme::Http(
HttpBuilder::new()
.scheme(HttpAuthScheme::Bearer)
.build(),
),
SecurityScheme::Http(HttpBuilder::new().scheme(HttpAuthScheme::Bearer).build()),
);
}
}
@@ -108,8 +109,12 @@ pub async fn serve() -> Result<(), Box<dyn Error>> {
.route("/api/devices/summary", get(devices::summary))
.route("/api/devices/{mac_address}", delete(devices::unregister))
.route("/api/devices/{mac_address}", get(devices::read))
.route("/api/devices/{mac_address}/events", get(device_events::list))
.route(
"/api/devices/{mac_address}/events",
get(device_events::list),
)
.route("/api/arp_scanner/status", get(arp_scanner::status))
.route("/api/mdns_scanner/status", get(mdns_scanner::status))
.route("/api/notifications", get(notifications::list))
.route(
"/api/notifications/mark_all_as_old",