]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce link_serialize_routes()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Oct 2020 02:56:12 +0000 (11:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 6 Oct 2020 17:44:42 +0000 (02:44 +0900)
src/network/networkd-link.c
src/network/networkd-route.c
src/network/networkd-route.h

index 0217300be6d63e2bab079de8e783f4311541438f..4daefb8dbeff3a21229619e05e5d066a7168b756 100644 (file)
@@ -3975,7 +3975,6 @@ int link_save(Link *link) {
         const char *admin_state, *oper_state, *carrier_state, *address_state;
         _cleanup_free_ char *temp_path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        Route *route;
         Address *a;
         int r;
 
@@ -4210,22 +4209,9 @@ int link_save(Link *link) {
 
                 /************************************************************/
 
-                fputs("ROUTES=", f);
-                space = false;
-                SET_FOREACH(route, link->routes) {
-                        _cleanup_free_ char *route_str = NULL;
-
-                        r = in_addr_to_string(route->family, &route->dst, &route_str);
-                        if (r < 0)
-                                goto fail;
-
-                        fprintf(f, "%s%s/%hhu/%hhu/%"PRIu32"/%"PRIu32"/"USEC_FMT,
-                                space ? " " : "", route_str,
-                                route->dst_prefixlen, route->tos, route->priority, route->table, route->lifetime);
-                        space = true;
-                }
-
-                fputc('\n', f);
+                r = link_serialize_routes(link, f);
+                if (r < 0)
+                        goto fail;
         }
 
         print_link_hashmap(f, "CARRIER_BOUND_TO=", link->bound_to_links);
index 0ac6ccd7946b1924d1c05e27de391c1ba4b15748..ad837099c8e21fedd50f9900ef7fccdbf124bfe8 100644 (file)
@@ -1234,6 +1234,31 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Ma
         return 1;
 }
 
+int link_serialize_routes(Link *link, FILE *f) {
+        bool space = false;
+        Route *route;
+
+        assert(link);
+        assert(link->network);
+        assert(f);
+
+        fputs("ROUTES=", f);
+        SET_FOREACH(route, link->routes) {
+                _cleanup_free_ char *route_str = NULL;
+
+                if (in_addr_to_string(route->family, &route->dst, &route_str) < 0)
+                        continue;
+
+                fprintf(f, "%s%s/%hhu/%hhu/%"PRIu32"/%"PRIu32"/"USEC_FMT,
+                        space ? " " : "", route_str,
+                        route->dst_prefixlen, route->tos, route->priority, route->table, route->lifetime);
+                space = true;
+        }
+        fputc('\n', f);
+
+        return 0;
+}
+
 int link_deserialize_routes(Link *link, const char *routes) {
         int r;
 
index 02b7c1b3ad000504446cd7d57e62c36597d9fb91..3cff8bba4117fd73ded78a2d5c0ca441a84a711e 100644 (file)
@@ -74,6 +74,7 @@ int route_remove(Route *route, Link *link, link_netlink_message_handler_t callba
 int link_set_routes(Link *link);
 int link_drop_routes(Link *link);
 int link_drop_foreign_routes(Link *link);
+int link_serialize_routes(Link *link, FILE *f);
 int link_deserialize_routes(Link *link, const char *routes);
 
 int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);