Robust interface detection — retry fallback chain for headless boot (#206)

Fixes interface auto-detection failures on Pi Zero 2W where wlan0 doesn't exist
at boot. Implementation:

- Added detect_interface_with_retry() function with 3x retry fallback chain
- Config-supplied interface preferred, then /proc/net/route, then UP interface
- Exponential backoff: 5s, 10s, 20s delays between retries
- Filters excluded prefixes: lo, tailscale*, wg*, tun*, docker*, veth*, br-*
- Used in Engine.__init__(), PacketCapture.start(), MacManager.start()
- Full test coverage: 10 tests for detection, backoff, filtering

Addresses issue where network stack initializes after boot and interfaces
become available after 5-10 second delay.
This commit is contained in:
Cobra
2026-04-08 20:58:43 -04:00
parent 6f421511de
commit 245731e73b
6 changed files with 235 additions and 8 deletions
+7 -2
View File
@@ -23,7 +23,7 @@ from pathlib import Path
from typing import Optional
from modules.base import BaseModule
from utils.networking import get_primary_interface
from utils.networking import detect_interface_with_retry
logger = logging.getLogger("sensor.passive.packet_capture")
@@ -64,7 +64,12 @@ class PacketCapture(BaseModule):
if self._running:
return
iface = self.config.get("interface") or get_primary_interface() or self.DEFAULT_INTERFACE
iface = self.config.get("interface") or detect_interface_with_retry(
max_retries=3,
retry_delay=5,
exponential=True,
config_interface=self.DEFAULT_INTERFACE
)
snap_len = self.config.get("snap_length", self.DEFAULT_SNAP_LEN)
rotation = self.config.get("rotation_minutes", 60) * 60
if rotation <= 0: