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

routes: fix metric rendering (LP: #2023681) #367

Merged
merged 2 commits into from Jun 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/networkd.c
Expand Up @@ -591,7 +591,7 @@ write_route(NetplanIPRoute* r, GString* s)
if (r->onlink)
g_string_append_printf(s, "GatewayOnLink=true\n");
if (r->metric != NETPLAN_METRIC_UNSPEC)
g_string_append_printf(s, "Metric=%d\n", r->metric);
g_string_append_printf(s, "Metric=%u\n", r->metric);
if (r->table != NETPLAN_ROUTE_TABLE_UNSPEC)
g_string_append_printf(s, "Table=%d\n", r->table);
if (r->mtubytes != NETPLAN_MTU_UNSPEC)
Expand Down
2 changes: 1 addition & 1 deletion src/nm.c
Expand Up @@ -210,7 +210,7 @@ write_routes(const NetplanNetDefinition* def, GKeyFile *kf, int family, GError**
tmp_key = g_strdup_printf("route%d", j);
tmp_val = g_string_new(destination);
if (cur_route->metric != NETPLAN_METRIC_UNSPEC)
g_string_append_printf(tmp_val, ",%s,%d", is_global ? cur_route->via : "",
g_string_append_printf(tmp_val, ",%s,%u", is_global ? cur_route->via : "",
cur_route->metric);
else if (is_global) // no metric, but global gateway
g_string_append_printf(tmp_val, ",%s", cur_route->via);
Expand Down
2 changes: 1 addition & 1 deletion src/validation.c
Expand Up @@ -555,7 +555,7 @@ defroute_err(struct _defroute_entry *entry, const char *new_netdef_id, GError **
if (entry->metric == NETPLAN_METRIC_UNSPEC)
strncpy(metric_name, "metric: default", sizeof(metric_name) - 1);
else
snprintf(metric_name, sizeof(metric_name) - 1, "metric: %d", entry->metric);
snprintf(metric_name, sizeof(metric_name) - 1, "metric: %u", entry->metric);

g_set_error(error, NETPLAN_VALIDATION_ERROR, NETPLAN_ERROR_CONFIG_GENERIC,
"Conflicting default route declarations for %s (%s, %s), first declared in %s but also in %s",
Expand Down
63 changes: 63 additions & 0 deletions tests/generator/test_routing.py
Expand Up @@ -806,6 +806,35 @@ def test_type_local_lp1892272(self):
UseMTU=true
'''})

def test_route_metric_rendering_lp2023681(self):
"""Validate metric rendering is unsigned
(can render up to 4294967294, 4294967295 is used internally to define an unset value)
"""

self.generate('''network:
version: 2
ethernets:
engreen:
addresses: ["192.168.14.2/24"]
routes:
- to: 10.10.10.0/24
via: 192.168.14.20
metric: 4294967294
''')

self.assert_networkd({'engreen.network': '''[Match]
Name=engreen

[Network]
LinkLocalAddressing=ipv6
Address=192.168.14.2/24

[Route]
Destination=10.10.10.0/24
Gateway=192.168.14.20
Metric=4294967294
'''})


class TestNetworkManager(TestBase):

Expand Down Expand Up @@ -1537,4 +1566,38 @@ def test_add_duplicate_routes_from_multiple_files(self):
[RoutingPolicyRule]
From=10.0.0.2
Table=1002
'''})

def test_route_metric_rendering_lp2023681(self):
"""Validate metric rendering is unsigned
(can render up to 4294967294, 4294967295 is used internally to define an unset value)
"""

self.generate('''network:
version: 2
renderer: NetworkManager
ethernets:
engreen:
addresses: ["192.168.14.2/24"]
routes:
- to: 10.10.10.0/24
via: 192.168.14.20
metric: 4294967294
''')

self.assert_nm({'engreen': '''[connection]
id=netplan-engreen
type=ethernet
interface-name=engreen

[ethernet]
wake-on-lan=0

[ipv4]
method=manual
address1=192.168.14.2/24
route1=10.10.10.0/24,192.168.14.20,4294967294

[ipv6]
method=ignore
'''})