chiark / gitweb /
networkd: distinguish between static and dynamic addresses/routes
authorTom Gundersen <teg@jklm.no>
Wed, 1 Jan 2014 14:16:10 +0000 (15:16 +0100)
committerTom Gundersen <teg@jklm.no>
Wed, 1 Jan 2014 15:23:00 +0000 (16:23 +0100)
Static addresses/routes are associated with a network. Dynamic
addresses/routes are associtade with links (as the corresponding network
may be shared by several links).

src/network/networkd-address.c
src/network/networkd-link.c
src/network/networkd-network.c
src/network/networkd-route.c
src/network/networkd.h

index c0cc1287aa3a48532a26cc5a2d7ee653bea33347..8a716300513c8ea2ea1bb575b8d290e026dcf6be 100644 (file)
@@ -28,7 +28,7 @@
 #include "conf-parser.h"
 #include "net-util.h"
 
-int address_new(Network *network, unsigned section, Address **ret) {
+int address_new_static(Network *network, unsigned section, Address **ret) {
         _cleanup_address_free_ Address *address = NULL;
 
         if (section) {
@@ -48,7 +48,7 @@ int address_new(Network *network, unsigned section, Address **ret) {
 
         address->network = network;
 
-        LIST_PREPEND(addresses, network->addresses, address);
+        LIST_PREPEND(static_addresses, network->static_addresses, address);
 
         if (section) {
                 address->section = section;
@@ -61,15 +61,30 @@ int address_new(Network *network, unsigned section, Address **ret) {
         return 0;
 }
 
+int address_new_dynamic(Address **ret) {
+        _cleanup_address_free_ Address *address = NULL;
+
+        address = new0(Address, 1);
+        if (!address)
+                return -ENOMEM;
+
+        *ret = address;
+        address = NULL;
+
+        return 0;
+}
+
 void address_free(Address *address) {
         if (!address)
                 return;
 
-        LIST_REMOVE(addresses, address->network->addresses, address);
+        if (address->network) {
+                LIST_REMOVE(static_addresses, address->network->static_addresses, address);
 
-        if (address->section)
-                hashmap_remove(address->network->addresses_by_section,
-                               &address->section);
+                if (address->section)
+                        hashmap_remove(address->network->addresses_by_section,
+                                       &address->section);
+        }
 
         free(address);
 }
@@ -203,7 +218,7 @@ int config_parse_address(const char *unit,
                 section_line = 0;
         }
 
-        r = address_new(network, section_line, &n);
+        r = address_new_static(network, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -266,7 +281,7 @@ int config_parse_label(const char *unit,
         assert(rvalue);
         assert(data);
 
-        r = address_new(network, section_line, &n);
+        r = address_new_static(network, section_line, &n);
         if (r < 0)
                 return r;
 
index cc5441bc3f088e8e3d94908331fe8c78c878df4f..ea94966f18fd77f4389ecbceca1da66d63c54407 100644 (file)
@@ -172,10 +172,10 @@ static int link_enter_set_routes(Link *link) {
 
         link->state = LINK_STATE_SETTING_ROUTES;
 
-        if (!link->network->routes)
+        if (!link->network->static_routes)
                 return link_enter_configured(link);
 
-        LIST_FOREACH(routes, route, link->network->routes) {
+        LIST_FOREACH(static_routes, route, link->network->static_routes) {
                 r = route_configure(route, link, &route_handler);
                 if (r < 0) {
                         log_warning("Could not set routes for link '%s'", link->ifname);
@@ -225,10 +225,10 @@ static int link_enter_set_addresses(Link *link) {
 
         link->state = LINK_STATE_SETTING_ADDRESSES;
 
-        if (!link->network->addresses)
+        if (!link->network->static_addresses)
                 return link_enter_set_routes(link);
 
-        LIST_FOREACH(addresses, address, link->network->addresses) {
+        LIST_FOREACH(static_addresses, address, link->network->static_addresses) {
                 r = address_configure(address, link, &address_handler);
                 if (r < 0) {
                         log_warning("Could not set addresses for link '%s'", link->ifname);
index 80c952a55b74990f5fd372d6b892dd6bdcccc4ab..56e5637a6601cdabcb9c19ae57cef9e3a552199d 100644 (file)
@@ -47,8 +47,8 @@ static int network_load_one(Manager *manager, const char *filename) {
 
         network->manager = manager;
 
-        LIST_HEAD_INIT(network->addresses);
-        LIST_HEAD_INIT(network->routes);
+        LIST_HEAD_INIT(network->static_addresses);
+        LIST_HEAD_INIT(network->static_routes);
 
         network->addresses_by_section = hashmap_new(uint64_hash_func, uint64_compare_func);
         if (!network->addresses_by_section)
@@ -120,10 +120,10 @@ void network_free(Network *network) {
 
         free(network->description);
 
-        while ((route = network->routes))
+        while ((route = network->static_routes))
                 route_free(route);
 
-        while ((address = network->addresses))
+        while ((address = network->static_addresses))
                 address_free(address);
 
         hashmap_free(network->addresses_by_section);
index 3eaefa2cc741ffa42e84da99acdd2065d2be1613..488d3f5013719bac0be8a34fe11a2a73778eb099 100644 (file)
@@ -28,7 +28,7 @@
 #include "conf-parser.h"
 #include "net-util.h"
 
-int route_new(Network *network, unsigned section, Route **ret) {
+int route_new_static(Network *network, unsigned section, Route **ret) {
         _cleanup_route_free_ Route *route = NULL;
 
         if (section) {
@@ -49,7 +49,7 @@ int route_new(Network *network, unsigned section, Route **ret) {
 
         route->network = network;
 
-        LIST_PREPEND(routes, network->routes, route);
+        LIST_PREPEND(static_routes, network->static_routes, route);
 
         if (section) {
                 route->section = section;
@@ -62,15 +62,30 @@ int route_new(Network *network, unsigned section, Route **ret) {
         return 0;
 }
 
+int route_new_dynamic(Route **ret) {
+        _cleanup_route_free_ Route *route = NULL;
+
+        route = new0(Route, 1);
+        if (!route)
+                return -ENOMEM;
+
+        *ret = route;
+        route = NULL;
+
+        return 0;
+}
+
 void route_free(Route *route) {
         if (!route)
                 return;
 
-        LIST_REMOVE(routes, route->network->routes, route);
+        if (route->network) {
+                LIST_REMOVE(static_routes, route->network->static_routes, route);
 
-        if (route->section)
-                hashmap_remove(route->network->routes_by_section,
-                               &route->section);
+                if (route->section)
+                        hashmap_remove(route->network->routes_by_section,
+                                       &route->section);
+        }
 
         free(route);
 }
@@ -160,7 +175,7 @@ int config_parse_gateway(const char *unit,
                 section_line = 0;
         }
 
-        r = route_new(network, section_line, &n);
+        r = route_new_static(network, section_line, &n);
         if (r < 0)
                 return r;
 
@@ -198,7 +213,7 @@ int config_parse_destination(const char *unit,
         assert(rvalue);
         assert(data);
 
-        r = route_new(network, section_line, &n);
+        r = route_new_static(network, section_line, &n);
         if (r < 0)
                 return r;
 
index bb775081c37ae6d5026b0b0667441b99ee98f6a6..547533fbab5e60b09e031989917471b30ef6db83 100644 (file)
@@ -85,8 +85,8 @@ struct Network {
         char *description;
         Bridge *bridge;
 
-        LIST_HEAD(Address, addresses);
-        LIST_HEAD(Route, routes);
+        LIST_HEAD(Address, static_addresses);
+        LIST_HEAD(Route, static_routes);
 
         Hashmap *addresses_by_section;
         Hashmap *routes_by_section;
@@ -109,7 +109,7 @@ struct Address {
                 struct in6_addr in6;
         } in_addr;
 
-        LIST_FIELDS(Address, addresses);
+        LIST_FIELDS(Address, static_addresses);
 };
 
 struct Route {
@@ -129,7 +129,7 @@ struct Route {
                 struct in6_addr in6;
         } dst_addr;
 
-        LIST_FIELDS(Route, routes);
+        LIST_FIELDS(Route, static_routes);
 };
 
 typedef enum LinkState {
@@ -223,7 +223,8 @@ int config_parse_bridge(const char *unit, const char *filename, unsigned line,
 const struct ConfigPerfItem* network_gperf_lookup(const char *key, unsigned length);
 
 /* Route */
-int route_new(Network *network, unsigned section, Route **ret);
+int route_new_static(Network *network, unsigned section, Route **ret);
+int route_new_dynamic(Route **ret);
 void route_free(Route *route);
 int route_configure(Route *route, Link *link, sd_rtnl_message_handler_t callback);
 
@@ -239,7 +240,8 @@ int config_parse_destination(const char *unit, const char *filename, unsigned li
                              int ltype, const char *rvalue, void *data, void *userdata);
 
 /* Address */
-int address_new(Network *network, unsigned section, Address **ret);
+int address_new_static(Network *network, unsigned section, Address **ret);
+int address_new_dynamic(Address **ret);
 void address_free(Address *address);
 int address_configure(Address *address, Link *link, sd_rtnl_message_handler_t callback);
 int address_drop(Address *address, Link *link, sd_rtnl_message_handler_t callback);