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:
@@ -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:
|
||||
|
||||
@@ -20,7 +20,7 @@ from typing import Optional
|
||||
from modules.base import BaseModule
|
||||
from utils.networking import (
|
||||
get_mac,
|
||||
get_primary_interface,
|
||||
detect_interface_with_retry,
|
||||
get_wifi_interfaces,
|
||||
set_mac,
|
||||
)
|
||||
@@ -74,7 +74,12 @@ class MacManager(BaseModule):
|
||||
"primary_interface", "auto"
|
||||
)
|
||||
if self._eth_iface == "auto":
|
||||
self._eth_iface = get_primary_interface()
|
||||
self._eth_iface = detect_interface_with_retry(
|
||||
max_retries=3,
|
||||
retry_delay=5,
|
||||
exponential=True,
|
||||
config_interface=None
|
||||
)
|
||||
|
||||
wifi_ifaces = get_wifi_interfaces()
|
||||
wifi_cfg = self.config.get("network", {}).get("wifi", {}).get("interface", "wlan0")
|
||||
|
||||
Reference in New Issue
Block a user