Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netplan ignores NetworkManager ipv4.route-metric (LP: #2076172) #495

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nm.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ write_nm_conf_access_point(const NetplanNetDefinition* def, const char* rootdir,
g_key_file_set_boolean(kf, "ipv4", "never-default", TRUE);
}

if (def->dhcp4 && def->dhcp4_overrides.metric != NETPLAN_METRIC_UNSPEC)
if ((def->dhcp4 || def->ip4_addresses || def->gateway4 || def->routes) && def->dhcp4_overrides.metric != NETPLAN_METRIC_UNSPEC)
g_key_file_set_uint64(kf, "ipv4", "route-metric", def->dhcp4_overrides.metric);

if (def->dhcp6 || def->ip6_addresses || def->gateway6 || def->ip6_nameservers || def->ip6_addr_gen_mode) {
Expand Down
82 changes: 82 additions & 0 deletions tests/parser/test_keyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2428,3 +2428,85 @@ def test_nameserver_with_DoT_lp2055148(self):
ipv6.ip6-privacy: "-1"
proxy._: ""
'''.format(UUID, UUID)})

def test_ipv4_route_metric_is_overriden_when_dhcp4_is_disabled(self):
self.generate_from_keyfile('''[connection]
id=dummy-123
type=dummy
uuid={}
interface-name=dummy123

[ipv4]
method=manual
address1=100.85.0.1/24,100.85.0.1
route-metric=95

[ipv6]
method=ignore
addr-gen-mode=default

[dummy]

[proxy]\n'''.format(UUID))
self.assert_netplan({UUID: '''network:
version: 2
dummy-devices:
NM-{}:
renderer: NetworkManager
addresses:
- "100.85.0.1/24"
dhcp4-overrides:
route-metric: 95
networkmanager:
uuid: "{}"
name: "dummy-123"
passthrough:
connection.interface-name: "dummy123"
ipv4.method: "manual"
ipv4.address1: "100.85.0.1/24,100.85.0.1"
ipv6.addr-gen-mode: "default"
dummy._: ""
proxy._: ""
'''.format(UUID, UUID)})

def test_ipv6_route_metric_is_overriden_when_dhcp6_is_disabled(self):
self.generate_from_keyfile('''[connection]
id=dummy-123
type=dummy
uuid={}
interface-name=dummy123

[ipv4]
method=disabled

[ipv6]
method=manual
address1=fdeb:446c:912d:8da::/64,fdeb:446c:912d:8da::1
route-metric=95
addr-gen-mode=default

[dummy]

[proxy]\n'''.format(UUID))
self.assert_netplan({UUID: '''network:
version: 2
dummy-devices:
NM-{}:
renderer: NetworkManager
addresses:
- "fdeb:446c:912d:8da::/64"
dhcp6-overrides:
route-metric: 95
networkmanager:
uuid: "{}"
name: "dummy-123"
passthrough:
connection.interface-name: "dummy123"
ipv4.method: "disabled"
ipv6.method: "manual"
ipv6.address1: "fdeb:446c:912d:8da::/64,fdeb:446c:912d:8da::1"
ipv6.addr-gen-mode: "default"
ipv6.ip6-privacy: "-1"
dummy._: ""
proxy._: ""
'''.format(UUID, UUID)})
Loading