diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-address.c | 31 | ||||
-rw-r--r-- | src/network/networkd-link.c | 8 | ||||
-rw-r--r-- | src/network/networkd-network.c | 8 | ||||
-rw-r--r-- | src/network/networkd-route.c | 31 | ||||
-rw-r--r-- | src/network/networkd.h | 14 |
5 files changed, 62 insertions, 30 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index c0cc1287aa..8a71630051 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -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; diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index cc5441bc3f..ea94966f18 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 80c952a55b..56e5637a66 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -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); diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 3eaefa2cc7..488d3f5013 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -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; diff --git a/src/network/networkd.h b/src/network/networkd.h index bb775081c3..547533fbab 100644 --- a/src/network/networkd.h +++ b/src/network/networkd.h @@ -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); |