]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: link - deserialize routes
authorTom Gundersen <teg@jklm.no>
Sun, 25 Oct 2015 13:45:53 +0000 (14:45 +0100)
committerTom Gundersen <teg@jklm.no>
Fri, 30 Oct 2015 11:32:49 +0000 (12:32 +0100)
src/network/networkd-link.c

index 5dcd862c21b09498fb441f9c0636cba8525bdb1d..9beaa7822b9823faba60769babc575282f571c76 100644 (file)
@@ -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) {