From: Yu Watanabe Date: Mon, 11 Nov 2024 19:31:55 +0000 (+0900) Subject: network/ndisc: introduce ndisc_route_prepare() and ndisc_router_route_prepare() X-Git-Tag: v257-rc2~25^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=74e0b590dd4defad123a7876784009d86c1b1e32;p=thirdparty%2Fsystemd.git network/ndisc: introduce ndisc_route_prepare() and ndisc_router_route_prepare() These applies common parameters to the route to be requested or removed. No functional change, just refactoring and preparation for later commits. --- diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 698fdbdb032..0833cd37734 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -196,11 +196,6 @@ static int ndisc_request_route(Route *route, Link *link) { assert(link->manager); assert(link->network); - route->source = NETWORK_CONFIG_SOURCE_NDISC; - - if (!route->table_set) - route->table = link_get_ndisc_route_table(link); - r = route_metric_set(&route->metric, RTAX_QUICKACK, link->network->ndisc_quickack); if (r < 0) return r; @@ -274,6 +269,29 @@ static int ndisc_request_route(Route *route, Link *link) { return 0; } +static void ndisc_route_prepare(Route *route, Link *link) { + assert(route); + assert(link); + + route->source = NETWORK_CONFIG_SOURCE_NDISC; + + if (!route->table_set) + route->table = link_get_ndisc_route_table(link); +} + +static int ndisc_router_route_prepare(Route *route, Link *link, sd_ndisc_router *rt) { + assert(route); + assert(link); + assert(rt); + + ndisc_route_prepare(route, link); + + if (!route->protocol_set) + route->protocol = RTPROT_RA; + + return sd_ndisc_router_get_sender_address(rt, &route->provider.in6); +} + static int ndisc_request_router_route(Route *route, Link *link, sd_ndisc_router *rt) { int r; @@ -281,13 +299,10 @@ static int ndisc_request_router_route(Route *route, Link *link, sd_ndisc_router assert(link); assert(rt); - r = sd_ndisc_router_get_sender_address(rt, &route->provider.in6); + r = ndisc_router_route_prepare(route, link, rt); if (r < 0) return r; - if (!route->protocol_set) - route->protocol = RTPROT_RA; - return ndisc_request_route(route, link); } @@ -298,9 +313,6 @@ static int ndisc_remove_route(Route *route, Link *link) { assert(link); assert(link->manager); - if (!route->table_set) - route->table = link_get_ndisc_route_table(link); - r = route_adjust_nexthops(route, link); if (r < 0) return r; @@ -344,6 +356,20 @@ static int ndisc_remove_route(Route *route, Link *link) { return ret; } +static int ndisc_remove_router_route(Route *route, Link *link, sd_ndisc_router *rt) { + int r; + + assert(route); + assert(link); + assert(rt); + + r = ndisc_router_route_prepare(route, link, rt); + if (r < 0) + return r; + + return ndisc_remove_route(route, link); +} + static int ndisc_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, Address *address) { int r; @@ -474,6 +500,8 @@ static int ndisc_remove_redirect_route(Link *link, sd_ndisc_redirect *rd) { if (r < 0) return r; + ndisc_route_prepare(route, link); + return ndisc_remove_route(route, link); } @@ -674,6 +702,8 @@ static int ndisc_redirect_handler(Link *link, sd_ndisc_redirect *rd) { if (r < 0) return r; + ndisc_route_prepare(route, link); + return ndisc_request_route(route, link); } @@ -749,7 +779,7 @@ static int ndisc_router_drop_default(Link *link, sd_ndisc_router *rt) { route->nexthop.family = AF_INET6; route->nexthop.gw.in6 = gateway; - r = ndisc_remove_route(route, link); + r = ndisc_remove_router_route(route, link, rt); if (r < 0) return log_link_warning_errno(link, r, "Failed to remove the default gateway configured by RA: %m"); @@ -769,7 +799,7 @@ static int ndisc_router_drop_default(Link *link, sd_ndisc_router *rt) { tmp->nexthop.gw.in6 = gateway; - r = ndisc_remove_route(tmp, link); + r = ndisc_remove_router_route(tmp, link, rt); if (r < 0) return log_link_warning_errno(link, r, "Could not remove semi-static gateway: %m"); } @@ -1274,7 +1304,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) { * received advertisement, reset its invalidation timer to the Valid Lifetime value in the Prefix * Information option. If the new Lifetime value is zero, timeout the prefix immediately. */ if (lifetime_usec == 0) { - r = ndisc_remove_route(route, link); + r = ndisc_remove_router_route(route, link, rt); if (r < 0) return log_link_warning_errno(link, r, "Failed to remove prefix route: %m"); } else { @@ -1412,7 +1442,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) { if (r < 0) return log_link_warning_errno(link, r, "Could not request additional route: %m"); } else { - r = ndisc_remove_route(route, link); + r = ndisc_remove_router_route(route, link, rt); if (r < 0) return log_link_warning_errno(link, r, "Could not remove additional route with zero lifetime: %m"); }