summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-25 14:45:53 +0100
committerTom Gundersen <teg@jklm.no>2015-10-30 12:32:49 +0100
commitf703cc2c5756088605a37d7d9a9b84e719b667f5 (patch)
tree65550d4a4bfa11ae0445f5a692dd64bba50bcd83 /src/network
parent0bc70f1d9c5453ba614ec0ed041dc30b9cd52071 (diff)
networkd: link - deserialize routes
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-link.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 5dcd862c21..9beaa7822b 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2135,9 +2135,11 @@ int link_initialized(Link *link, struct udev_device *device) {
static int link_load(Link *link) {
_cleanup_free_ char *network_file = NULL,
*addresses = NULL,
+ *routes = NULL,
*dhcp4_address = NULL,
*ipv4ll_address = NULL;
union in_addr_union address;
+ union in_addr_union route_dst;
int r;
assert(link);
@@ -2145,6 +2147,7 @@ static int link_load(Link *link) {
r = parse_env_file(link->state_file, NEWLINE,
"NETWORK_FILE", &network_file,
"ADDRESSES", &addresses,
+ "ROUTES", &routes,
"DHCP4_ADDRESS", &dhcp4_address,
"IPV4LL_ADDRESS", &ipv4ll_address,
NULL);
@@ -2215,6 +2218,46 @@ network_file_fail:
}
}
+ if (routes) {
+ _cleanup_strv_free_ char **routes_strv = NULL;
+ char **route_str;
+
+ routes_strv = strv_split(routes, " ");
+ if (!routes_strv)
+ return log_oom();
+
+ STRV_FOREACH(route_str, routes_strv) {
+ char *prefixlen_str;
+ int family;
+ unsigned char prefixlen, tos, table;
+ uint32_t priority;
+
+ prefixlen_str = strchr(*route_str, '/');
+ if (!prefixlen_str) {
+ log_link_debug(link, "Failed to parse route %s", *route_str);
+ continue;
+ }
+
+ *prefixlen_str ++ = '\0';
+
+ r = sscanf(prefixlen_str, "%hhu/%hhu/%"SCNu32"/%hhu", &prefixlen, &tos, &priority, &table);
+ if (r != 4) {
+ log_link_debug(link, "Failed to parse destination prefix length, tos, priority or table %s", prefixlen_str);
+ continue;
+ }
+
+ r = in_addr_from_string_auto(*route_str, &family, &route_dst);
+ if (r < 0) {
+ log_link_debug_errno(link, r, "Failed to parse route destination %s: %m", *route_str);
+ continue;
+ }
+
+ r = route_add(link, family, &route_dst, prefixlen, tos, priority, table, NULL);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to add route: %m");
+ }
+ }
+
if (dhcp4_address) {
r = in_addr_from_string(AF_INET, dhcp4_address, &address);
if (r < 0) {