Skip to content

Filter default gateway routes by address family in dual-stack config#191

Open
maxpain wants to merge 1 commit intocloudbase:masterfrom
maxpain:fix/dual-stack-gateway-selection
Open

Filter default gateway routes by address family in dual-stack config#191
maxpain wants to merge 1 commit intocloudbase:masterfrom
maxpain:fix/dual-stack-gateway-selection

Conversation

@maxpain
Copy link
Copy Markdown

@maxpain maxpain commented Apr 6, 2026

Summary

When a network adapter has both IPv4 and IPv6 addresses with separate default gateways in network-config v2, _process_networks picks the first route with prefixlen == 0 regardless of address family. This causes IPv6 addresses to receive the IPv4 gateway.

For example, with this config:

version: 2
ethernets:
  eth0:
    addresses:
      - 10.0.0.1/32
      - 2001:db8::1/96
    routes:
      - to: 0.0.0.0/0
        via: 169.254.0.1
      - to: ::/0
        via: fe80::1

Before: both addresses get gateway 169.254.0.1 — IPv6 default route is never configured.

After: IPv4 address gets 169.254.0.1, IPv6 address gets fe80::1.

Fix

Filter default gateway route candidates by matching the route's address family (0.0.0.0/0 for IPv4, ::/0 for IPv6) against the network address being configured.

Testing

  • Added test_execute_network_details_v2_dual_stack_gateways covering dual-stack gateway selection
  • Updated existing _test_execute_network_details_v2 to account for correct address family filtering
  • All 22 tests pass
  • Verified on Windows Server 2025 with dual-stack (IPv4 + IPv6) network configuration

When a network adapter has both IPv4 and IPv6 addresses with separate
default gateways, _process_networks picks the first route with
prefixlen == 0 regardless of address family. This causes IPv6
addresses to receive the IPv4 gateway (e.g., 169.254.0.1 instead of
fe80::1), and the IPv6 default route is never configured.

Filter the default gateway route candidates by matching the route's
address family (0.0.0.0/0 vs ::/0) against the network address being
configured.

Signed-off-by: Max Makarov <maxpain@linux.com>
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.

1 participant