summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeitor Alves de Siqueira <halves@canonical.com>2020-10-30 07:13:31 -0300
committerGitHub <noreply@github.com>2020-10-30 11:13:31 +0100
commit097d875073eac95acfb7aaf988640d7fb5fac3ae (patch)
tree31ba87f243967e890c8efc3cd0839502ced99e9d /src
parent4efd4e721671d33020af469c4f0785c2fd6ff6ee (diff)
Add per-route MTU option (LP: #1860201) (#160)
This patch introduces a way to set MTU for specific routes, which is tracked by the new 'mtubytes' field in the NetplanIPRoute struct, and makes use of already existing route handling code to add the MTU-related fields for networkd and NM backends. Signed-off-by: Heitor Alves de Siqueira <halves@canonical.com>
Diffstat (limited to 'src')
-rw-r--r--src/networkd.c4
-rw-r--r--src/nm.c7
-rw-r--r--src/parse.c1
-rw-r--r--src/parse.h3
4 files changed, 12 insertions, 3 deletions
diff --git a/src/networkd.c b/src/networkd.c
index 48b0cbd..7c86cd6 100644
--- a/src/networkd.c
+++ b/src/networkd.c
@@ -442,6 +442,8 @@ write_route(NetplanIPRoute* r, GString* s)
g_string_append_printf(s, "Metric=%d\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)
+ g_string_append_printf(s, "MTUBytes=%u\n", r->mtubytes);
}
static void
@@ -568,7 +570,7 @@ write_network_file(const NetplanNetDefinition* def, const char* rootdir, const c
}
if (def->mtubytes) {
- g_string_append_printf(link, "MTUBytes=%d\n", def->mtubytes);
+ g_string_append_printf(link, "MTUBytes=%u\n", def->mtubytes);
}
if (def->emit_lldp) {
diff --git a/src/nm.c b/src/nm.c
index 9a377d0..28bd6bd 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -222,6 +222,7 @@ write_routes(const NetplanNetDefinition* def, GString *s, int family)
g_string_append(s, "\n");
if ( cur_route->onlink
+ || cur_route->mtubytes
|| cur_route->table != NETPLAN_ROUTE_TABLE_UNSPEC
|| cur_route->from) {
g_string_append_printf(s, "route%d_options=", j);
@@ -229,6 +230,8 @@ write_routes(const NetplanNetDefinition* def, GString *s, int family)
/* onlink for IPv6 addresses is only supported since nm-1.18.0. */
g_string_append_printf(s, "onlink=true,");
}
+ if (cur_route->mtubytes != NETPLAN_MTU_UNSPEC)
+ g_string_append_printf(s, "mtu=%u,", cur_route->mtubytes);
if (cur_route->table != NETPLAN_ROUTE_TABLE_UNSPEC)
g_string_append_printf(s, "table=%u,", cur_route->table);
if (cur_route->from)
@@ -615,7 +618,7 @@ write_nm_conf_access_point(NetplanNetDefinition* def, const char* rootdir, const
g_string_append_printf(link_str, "cloned-mac-address=%s\n", def->set_mac);
}
if (def->mtubytes) {
- g_string_append_printf(link_str, "mtu=%d\n", def->mtubytes);
+ g_string_append_printf(link_str, "mtu=%u\n", def->mtubytes);
}
if (def->wowlan && def->wowlan > NETPLAN_WIFI_WOWLAN_DEFAULT)
g_string_append_printf(link_str, "wake-on-wlan=%u\n", def->wowlan);
@@ -642,7 +645,7 @@ write_nm_conf_access_point(NetplanNetDefinition* def, const char* rootdir, const
g_string_append_printf(link_str, "cloned-mac-address=%s\n", def->set_mac);
}
if (def->mtubytes) {
- g_string_append_printf(link_str, "mtu=%d\n", def->mtubytes);
+ g_string_append_printf(link_str, "mtu=%u\n", def->mtubytes);
}
if (link_str->len > 0) {
diff --git a/src/parse.c b/src/parse.c
index ff93b9a..033c657 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -1517,6 +1517,7 @@ static const mapping_entry_handler routes_handlers[] = {
{"type", YAML_SCALAR_NODE, handle_routes_type},
{"via", YAML_SCALAR_NODE, handle_routes_ip, NULL, route_offset(via)},
{"metric", YAML_SCALAR_NODE, handle_routes_guint, NULL, route_offset(metric)},
+ {"mtu", YAML_SCALAR_NODE, handle_routes_guint, NULL, route_offset(mtubytes)},
{NULL}
};
diff --git a/src/parse.h b/src/parse.h
index 9f57bb4..4b8fa30 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -425,6 +425,7 @@ typedef struct {
gboolean has_auth;
} NetplanWifiAccessPoint;
+#define NETPLAN_MTU_UNSPEC 0
#define NETPLAN_METRIC_UNSPEC G_MAXUINT
#define NETPLAN_ROUTE_TABLE_UNSPEC 0
#define NETPLAN_IP_RULE_PRIO_UNSPEC G_MAXUINT
@@ -446,6 +447,8 @@ typedef struct {
/* valid metrics are valid positive integers.
* invalid metrics are represented by METRIC_UNSPEC */
guint metric;
+
+ guint mtubytes;
} NetplanIPRoute;
typedef struct {