1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-27 07:22:31 +03:00

network: introduce manager_address_is_reachable()

The function will be used in later commits.
This commit is contained in:
Yu Watanabe 2021-05-07 04:37:58 +09:00
parent 884a63d76e
commit d94e8ba021
2 changed files with 41 additions and 0 deletions

View File

@ -665,6 +665,46 @@ int link_has_route(Link *link, const Route *route) {
return true; return true;
} }
static bool route_address_is_reachable(const Route *route, int family, const union in_addr_union *address) {
assert(route);
assert(IN_SET(family, AF_INET, AF_INET6));
assert(address);
if (route->family != family)
return false;
if (!in_addr_is_set(route->family, &route->dst))
return false;
return in_addr_prefix_intersect(
route->family,
&route->dst,
route->dst_prefixlen,
address,
FAMILY_ADDRESS_SIZE(family) * 8) > 0;
}
bool manager_address_is_reachable(Manager *manager, int family, const union in_addr_union *address) {
Link *link;
assert(manager);
assert(IN_SET(family, AF_INET, AF_INET6));
assert(address);
HASHMAP_FOREACH(link, manager->links) {
Route *route;
SET_FOREACH(route, link->routes)
if (route_address_is_reachable(route, family, address))
return true;
SET_FOREACH(route, link->routes_foreign)
if (route_address_is_reachable(route, family, address))
return true;
}
return false;
}
static void log_route_debug(const Route *route, const char *str, const Link *link, const Manager *m) { static void log_route_debug(const Route *route, const char *str, const Link *link, const Manager *m) {
_cleanup_free_ char *dst = NULL, *src = NULL, *gw = NULL, *prefsrc = NULL, _cleanup_free_ char *dst = NULL, *src = NULL, *gw = NULL, *prefsrc = NULL,
*table = NULL, *scope = NULL, *proto = NULL; *table = NULL, *scope = NULL, *proto = NULL;

View File

@ -76,6 +76,7 @@ int route_configure(const Route *route, Link *link, link_netlink_message_handler
int route_remove(const Route *route, Manager *manager, Link *link, link_netlink_message_handler_t callback); int route_remove(const Route *route, Manager *manager, Link *link, link_netlink_message_handler_t callback);
int link_has_route(Link *link, const Route *route); int link_has_route(Link *link, const Route *route);
bool manager_address_is_reachable(Manager *manager, int family, const union in_addr_union *address);
int link_set_routes(Link *link); int link_set_routes(Link *link);
int link_set_routes_with_gateway(Link *link); int link_set_routes_with_gateway(Link *link);