Skip to content

controller: prevent duplicate tunnel pairs in rendered configs#3058

Merged
elitegreg merged 2 commits intomainfrom
gm/controller-prevent-dup-tunnel-pairs
Feb 20, 2026
Merged

controller: prevent duplicate tunnel pairs in rendered configs#3058
elitegreg merged 2 commits intomainfrom
gm/controller-prevent-dup-tunnel-pairs

Conversation

@elitegreg
Copy link
Contributor

User tunnels are GRE tunnels identified by (UnderlaySrcIP, UnderlayDstIP) pairs. In normal operation, the activator ensures each device gets unique tunnel pairs, but corrupted onchain state or bugs could create duplicates. If duplicate pairs exist when the controller renders device configs, the resulting configuration will contain conflicting GRE tunnel interface definitions, causing device configuration errors or undefined behavior.

Summary of Changes

  • Add a defensive deduplication layer in GetConfig() that filters the tunnel list before rendering. When duplicates are detected:
    • Log an error with full context (device pubkey/code, tunnel IDs, user pubkeys, underlay IPs, VRF ID)
    • Increment controller_duplicate_tunnel_pairs_total Prometheus metric
    • Keep the first occurrence and remove subsequent duplicates
    • Continue rendering the rest of the config normally

This fail-safe prevents bad configs from reaching devices even if upstream validation fails. The deduplication happens per-device at render time using a shallow device copy, so the cache remains faithful to onchain state while devices receive only valid configurations.

Testing Verification

  • Added 5 unit tests covering duplicate removal, first-occurrence selection, unallocated tunnel handling, empty lists, and end-to-end integration with GetConfig().
  • All existing tests pass.

…onfigs

User tunnels are GRE tunnels identified by (UnderlaySrcIP, UnderlayDstIP)
pairs. In normal operation, the activator ensures each device gets unique
tunnel pairs, but corrupted onchain state or bugs could create duplicates.
If duplicate pairs exist when the controller renders device configs, the
resulting configuration will contain conflicting GRE tunnel interface
definitions, causing device configuration errors or undefined behavior.

Add a defensive deduplication layer in GetConfig() that filters the tunnel
list before rendering. When duplicates are detected:
- Log an error with full context (device pubkey/code, tunnel IDs, user
  pubkeys, underlay IPs, VRF ID)
- Increment controller_duplicate_tunnel_pairs_total Prometheus metric
- Keep the first occurrence and remove subsequent duplicates
- Continue rendering the rest of the config normally

This fail-safe prevents bad configs from reaching devices even if upstream
validation fails. The deduplication happens per-device at render time using
a shallow device copy, so the cache remains faithful to onchain state while
devices receive only valid configurations.

Testing: Added 5 unit tests covering duplicate removal, first-occurrence
selection, unallocated tunnel handling, empty lists, and end-to-end
integration with GetConfig(). All existing tests pass.
@elitegreg elitegreg merged commit b1a68c1 into main Feb 20, 2026
36 of 37 checks passed
@elitegreg elitegreg deleted the gm/controller-prevent-dup-tunnel-pairs branch February 20, 2026 17:54
nikw9944 pushed a commit that referenced this pull request Feb 20, 2026
User tunnels are GRE tunnels identified by (UnderlaySrcIP,
UnderlayDstIP) pairs. In normal operation, the activator ensures each
device gets unique tunnel pairs, but corrupted onchain state or bugs
could create duplicates. If duplicate pairs exist when the controller
renders device configs, the resulting configuration will contain
conflicting GRE tunnel interface definitions, causing device
configuration errors or undefined behavior.

## Summary of Changes
* Add a defensive deduplication layer in GetConfig() that filters the
tunnel list before rendering. When duplicates are detected:
* Log an error with full context (device pubkey/code, tunnel IDs, user
pubkeys, underlay IPs, VRF ID)
  * Increment controller_duplicate_tunnel_pairs_total Prometheus metric
  * Keep the first occurrence and remove subsequent duplicates
  * Continue rendering the rest of the config normally

This fail-safe prevents bad configs from reaching devices even if
upstream validation fails. The deduplication happens per-device at
render time using a shallow device copy, so the cache remains faithful
to onchain state while devices receive only valid configurations.

## Testing Verification
* Added 5 unit tests covering duplicate removal, first-occurrence
selection, unallocated tunnel handling, empty lists, and end-to-end
integration with GetConfig().
* All existing tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants