summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-route-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkd-route-util.c')
-rw-r--r--src/network/networkd-route-util.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/network/networkd-route-util.c b/src/network/networkd-route-util.c
index d49a0b9..b7e07f4 100644
--- a/src/network/networkd-route-util.c
+++ b/src/network/networkd-route-util.c
@@ -39,6 +39,12 @@ unsigned routes_max(void) {
return cached;
}
+bool route_type_is_reject(const Route *route) {
+ assert(route);
+
+ return IN_SET(route->type, RTN_UNREACHABLE, RTN_PROHIBIT, RTN_BLACKHOLE, RTN_THROW);
+}
+
static bool route_lifetime_is_valid(const Route *route) {
assert(route);
@@ -52,8 +58,11 @@ bool link_find_default_gateway(Link *link, int family, Route **gw) {
Route *route;
assert(link);
+ assert(link->manager);
- SET_FOREACH(route, link->routes) {
+ SET_FOREACH(route, link->manager->routes) {
+ if (route->nexthop.ifindex != link->ifindex)
+ continue;
if (!route_exists(route))
continue;
if (family != AF_UNSPEC && route->family != family)
@@ -68,7 +77,7 @@ bool link_find_default_gateway(Link *link, int family, Route **gw) {
continue;
if (route->scope != RT_SCOPE_UNIVERSE)
continue;
- if (!in_addr_is_set(route->gw_family, &route->gw))
+ if (!in_addr_is_set(route->nexthop.family, &route->nexthop.gw))
continue;
/* Found a default gateway. */
@@ -77,7 +86,7 @@ bool link_find_default_gateway(Link *link, int family, Route **gw) {
/* If we have already found another gw, then let's compare their weight and priority. */
if (*gw) {
- if (route->gw_weight > (*gw)->gw_weight)
+ if (route->nexthop.weight > (*gw)->nexthop.weight)
continue;
if (route->priority >= (*gw)->priority)
continue;
@@ -113,12 +122,7 @@ int manager_find_uplink(Manager *m, int family, Link *exclude, Link **ret) {
if (!gw)
return -ENOENT;
- if (ret) {
- assert(gw->link);
- *ret = gw->link;
- }
-
- return 0;
+ return link_get_by_index(m, gw->nexthop.ifindex, ret);
}
bool gateway_is_ready(Link *link, bool onlink, int family, const union in_addr_union *gw) {
@@ -137,7 +141,9 @@ bool gateway_is_ready(Link *link, bool onlink, int family, const union in_addr_u
if (family == AF_INET6 && in6_addr_is_link_local(&gw->in6))
return true;
- SET_FOREACH(route, link->routes) {
+ SET_FOREACH(route, link->manager->routes) {
+ if (route->nexthop.ifindex != link->ifindex)
+ continue;
if (!route_exists(route))
continue;
if (!route_lifetime_is_valid(route))
@@ -181,10 +187,14 @@ static int link_address_is_reachable_internal(
Route *route, *found = NULL;
assert(link);
+ assert(link->manager);
assert(IN_SET(family, AF_INET, AF_INET6));
assert(address);
- SET_FOREACH(route, link->routes) {
+ SET_FOREACH(route, link->manager->routes) {
+ if (route->nexthop.ifindex != link->ifindex)
+ continue;
+
if (!route_exists(route))
continue;
@@ -298,7 +308,11 @@ int manager_address_is_reachable(
return 0;
}
- r = link_get_address(found->link, found->family, &found->prefsrc, 0, &a);
+ r = link_get_by_index(manager, found->nexthop.ifindex, &link);
+ if (r < 0)
+ return r;
+
+ r = link_get_address(link, found->family, &found->prefsrc, 0, &a);
if (r < 0)
return r;