X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkd-route.c;h=f451b975a701bb9b7ed1ecb337a8c55939f078b5;hb=16aa63a00b5b1db23a9c0b8de350ebf482d90cd0;hp=8b020adba469a29739357262e8e362a8bae6b659;hpb=c6f7c917a1b494d4455800823472227463f87438;p=elogind.git diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 8b020adba..f451b975a 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -32,9 +32,8 @@ int route_new_static(Network *network, unsigned section, Route **ret) { _cleanup_route_free_ Route *route = NULL; if (section) { - uint64_t key = section; - - route = hashmap_get(network->routes_by_section, &key); + route = hashmap_get(network->routes_by_section, + UINT_TO_PTR(section)); if (route) { *ret = route; route = NULL; @@ -49,14 +48,16 @@ int route_new_static(Network *network, unsigned section, Route **ret) { route->family = AF_UNSPEC; route->scope = RT_SCOPE_UNIVERSE; + route->protocol = RTPROT_STATIC; route->network = network; - LIST_PREPEND(static_routes, network->static_routes, route); + LIST_PREPEND(routes, network->static_routes, route); if (section) { route->section = section; - hashmap_put(network->routes_by_section, &route->section, route); + hashmap_put(network->routes_by_section, + UINT_TO_PTR(route->section), route); } *ret = route; @@ -65,7 +66,7 @@ int route_new_static(Network *network, unsigned section, Route **ret) { return 0; } -int route_new_dynamic(Route **ret) { +int route_new_dynamic(Route **ret, unsigned char rtm_protocol) { _cleanup_route_free_ Route *route = NULL; route = new0(Route, 1); @@ -74,6 +75,7 @@ int route_new_dynamic(Route **ret) { route->family = AF_UNSPEC; route->scope = RT_SCOPE_UNIVERSE; + route->protocol = rtm_protocol; *ret = route; route = NULL; @@ -86,11 +88,11 @@ void route_free(Route *route) { return; if (route->network) { - LIST_REMOVE(static_routes, route->network->static_routes, route); + LIST_REMOVE(routes, route->network->static_routes, route); if (route->section) hashmap_remove(route->network->routes_by_section, - &route->section); + UINT_TO_PTR(route->section)); } free(route); @@ -108,7 +110,8 @@ int route_drop(Route *route, Link *link, assert(route->family == AF_INET || route->family == AF_INET6); r = sd_rtnl_message_new_route(link->manager->rtnl, &req, - RTM_DELROUTE, route->family); + RTM_DELROUTE, route->family, + route->protocol); if (r < 0) { log_error("Could not create RTM_DELROUTE message: %s", strerror(-r)); return r; @@ -164,6 +167,8 @@ int route_drop(Route *route, Link *link, return r; } + link_ref(link); + return 0; } @@ -179,7 +184,8 @@ int route_configure(Route *route, Link *link, assert(route->family == AF_INET || route->family == AF_INET6); r = sd_rtnl_message_new_route(link->manager->rtnl, &req, - RTM_NEWROUTE, route->family); + RTM_NEWROUTE, route->family, + route->protocol); if (r < 0) { log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r)); return r; @@ -235,6 +241,8 @@ int route_configure(Route *route, Link *link, return r; } + link_ref(link); + return 0; } @@ -356,3 +364,38 @@ int config_parse_destination(const char *unit, return 0; } + +int config_parse_route_priority(const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + Network *network = userdata; + _cleanup_route_free_ Route *n = NULL; + int r; + + assert(filename); + assert(section); + assert(lvalue); + assert(rvalue); + assert(data); + + r = route_new_static(network, section_line, &n); + if (r < 0) + return r; + + r = config_parse_unsigned(unit, filename, line, section, + section_line, lvalue, ltype, + rvalue, &n->metrics, userdata); + if (r < 0) + return r; + + n = NULL; + + return 0; +}