From 2437ebee20ed9ce1e789c866728a73f244f80318 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 12 Nov 2024 02:03:44 +0900 Subject: network/ndisc: introduce route_is_bound_to_link() helper function and use it where applicable No functional change, and preparation for later commits. --- src/network/networkd-ndisc.c | 8 ++++---- src/network/networkd-route.c | 12 ++++++++++++ src/network/networkd-route.h | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src/network') diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index c1d2373f65..3b130ee4cc 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -2062,7 +2062,7 @@ static int ndisc_drop_outdated(Link *link, const struct in6_addr *router, usec_t if (route->source != NETWORK_CONFIG_SOURCE_NDISC) continue; - if (route->nexthop.ifindex != link->ifindex) + if (!route_is_bound_to_link(route, link)) continue; if (route->protocol == RTPROT_REDIRECT) @@ -2198,7 +2198,7 @@ static int ndisc_setup_expire(Link *link) { if (route->source != NETWORK_CONFIG_SOURCE_NDISC) continue; - if (route->nexthop.ifindex != link->ifindex) + if (!route_is_bound_to_link(route, link)) continue; if (!route_exists(route)) @@ -2436,7 +2436,7 @@ static int ndisc_neighbor_handle_router_message(Link *link, sd_ndisc_neighbor *n if (route->source != NETWORK_CONFIG_SOURCE_NDISC) continue; - if (route->nexthop.ifindex != link->ifindex) + if (!route_is_bound_to_link(route, link)) continue; if (!in6_addr_equal(&route->provider.in6, &original_address)) @@ -2729,7 +2729,7 @@ int link_drop_ndisc_config(Link *link, Network *network) { if (route->source != NETWORK_CONFIG_SOURCE_NDISC) continue; - if (route->nexthop.ifindex != link->ifindex) + if (!route_is_bound_to_link(route, link)) continue; if (route->protocol == RTPROT_REDIRECT) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 5104223396..b85d2a037a 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -352,6 +352,18 @@ static int route_get_link(Manager *manager, const Route *route, Link **ret) { return route_nexthop_get_link(manager, &route->nexthop, ret); } +bool route_is_bound_to_link(const Route *route, Link *link) { + assert(route); + assert(link); + assert(link->manager); + + Link *route_link; + if (route_get_link(link->manager, route, &route_link) < 0) + return false; + + return route_link->ifindex == link->ifindex; +} + int route_get_request(Manager *manager, const Route *route, Request **ret) { Request *req; diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index f391d95714..b9d2dbf9a6 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -100,6 +100,7 @@ int route_remove(Route *route, Manager *manager); int route_remove_and_cancel(Route *route, Manager *manager); int route_get(Manager *manager, const Route *route, Route **ret); +bool route_is_bound_to_link(const Route *route, Link *link); int route_get_request(Manager *manager, const Route *route, Request **ret); bool route_can_update(const Route *existing, const Route *requesting); -- cgit v1.2.3