Skip to content

Improvements in connection logic#90

Open
ttherbrink wants to merge 4 commits into
release/1.6.0from
fix/multiple-interfaces
Open

Improvements in connection logic#90
ttherbrink wants to merge 4 commits into
release/1.6.0from
fix/multiple-interfaces

Conversation

@ttherbrink

@ttherbrink ttherbrink commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What & why

KNX devices could get stuck reporting "Selected IP Interface Not available."
after a host reboot — most visibly on Homey Self-Hosted Server (KNX running in a
container on a NAS with several network interfaces). The gateway was rediscovered
fine, but the tunnel bound to the wrong local interface, so the handshake never
completed and every device flapped into an endless disconnect loop.

This branch fixes that and hardens interface discovery/connection overall.

Changes

Multiple local interfaces

  • Discovery now scans every non-internal local IPv4 interface in parallel
    (ethernet + wifi + VLANs), merging results by MAC so a gateway reachable over
    more than one interface still shows as one entry.
  • Each search socket is bound to a specific interface with an ephemeral port and
    setMulticastInterface, so searches can run concurrently without port clashes.

Correct tunnel binding (the SHS fix)

  • The tunnel now binds to the local interface on the gateway's subnet via the knx
    lib's options.interface, re-resolved on every (re)connect so a reboot that
    reorders interfaces self-corrects. Falls back to the lib default when no subnet
    matches.

Probe no longer exhausts gateway tunnel slots

  • checkKNXInterface now sends a DISCONNECT_REQUEST to release the tunnel channel
    it opens while probing, and defers the socket close until that datagram is
    flushed. Released on all exit paths (success/timeout/error).

Reconnect-storm resilience

  • Concurrent probes for the same gateway IP collapse into a single in-flight
    request; the probe lock is decoupled from the multicast-search lock.

Robustness

  • parseKNXResponse guards against truncated/malformed frames instead of throwing
    inside socket handlers.
  • All UDP sockets are tracked and closed on destroy().

Notes

  • Multi-IP-per-NIC is handled correctly: probe sockets bind the matching alias
    directly, while the knx options.interface name uses the lib's own
    "last IPv4 per name" resolution to avoid a subnet mismatch.
  • Version/changelog intentionally left to the separate bump-version flow.

Testing

  • homey app validate -l publish passes.
  • Multi-alias source-IP/interface selection verified against a mocked
    os.networkInterfaces().
  • Recommended on-device check (SHS): reboot the host and confirm the new
    Binding tunnel to local interface <name> log line appears followed by
    KNX Connected.

@ttherbrink
ttherbrink requested a review from wouter-athom July 22, 2026 11:43
@ttherbrink ttherbrink self-assigned this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant