IPV4_ADDRESS_FMT_VAL(route->dst.in), route->dst_prefixlen, IPV4_ADDRESS_FMT_VAL(*gw));
route->scope = RT_SCOPE_HOST;
- route->gw_family = AF_UNSPEC;
- route->gw = IN_ADDR_NULL;
+ route->nexthop.family = AF_UNSPEC;
+ route->nexthop.gw = IN_ADDR_NULL;
route->prefsrc = IN_ADDR_NULL;
} else if (in4_addr_equal(&route->dst.in, &address)) {
IPV4_ADDRESS_FMT_VAL(route->dst.in), route->dst_prefixlen, IPV4_ADDRESS_FMT_VAL(*gw));
route->scope = RT_SCOPE_HOST;
- route->gw_family = AF_UNSPEC;
- route->gw = IN_ADDR_NULL;
+ route->nexthop.family = AF_UNSPEC;
+ route->nexthop.gw = IN_ADDR_NULL;
route->prefsrc.in = address;
} else if (in4_addr_is_null(gw)) {
}
route->scope = RT_SCOPE_LINK;
- route->gw_family = AF_UNSPEC;
- route->gw = IN_ADDR_NULL;
+ route->nexthop.family = AF_UNSPEC;
+ route->nexthop.gw = IN_ADDR_NULL;
route->prefsrc.in = address;
} else {
return r;
route->scope = RT_SCOPE_UNIVERSE;
- route->gw_family = AF_INET;
- route->gw.in = *gw;
+ route->nexthop.family = AF_INET;
+ route->nexthop.gw.in = *gw;
route->prefsrc.in = address;
}
return r;
/* Next, add a default gateway. */
- route->gw_family = AF_INET;
- route->gw.in = router;
+ route->nexthop.family = AF_INET;
+ route->nexthop.gw.in = router;
route->prefsrc.in = address;
return dhcp4_request_route(TAKE_PTR(route), link);
if (!rt->gateway_from_dhcp_or_ra)
continue;
- if (rt->gw_family != AF_INET)
+ if (rt->nexthop.family != AF_INET)
continue;
assert(rt->family == AF_INET);
if (r < 0)
return r;
- route->gw.in = gw;
+ route->nexthop.gw.in = gw;
r = dhcp4_request_route(TAKE_PTR(route), link);
if (r < 0)
void route_nexthops_done(Route *route) {
assert(route);
+ route_nexthop_done(&route->nexthop);
ordered_set_free(route->nexthops);
}
return true;
if (ordered_set_isempty(route->nexthops))
- return gateway_is_ready(link, FLAGS_SET(route->flags, RTNH_F_ONLINK), route->gw_family, &route->gw);
+ return route_nexthop_is_ready_to_configure(&route->nexthop, link, FLAGS_SET(route->flags, RTNH_F_ONLINK));
RouteNextHop *nh;
ORDERED_SET_FOREACH(nh, route->nexthops)
}
if (ordered_set_isempty(route->nexthops)) {
- if (in_addr_is_set(route->gw_family, &route->gw))
- buf = strjoin("gw: ", IN_ADDR_TO_STRING(route->gw_family, &route->gw));
+ if (in_addr_is_set(route->nexthop.family, &route->nexthop.gw))
+ buf = strjoin("gw: ", IN_ADDR_TO_STRING(route->nexthop.family, &route->nexthop.gw));
else if (route->gateway_from_dhcp_or_ra) {
- if (route->gw_family == AF_INET)
+ if (route->nexthop.family == AF_INET)
buf = strdup("gw: _dhcp4");
- else if (route->gw_family == AF_INET6)
+ else if (route->nexthop.family == AF_INET6)
buf = strdup("gw: _ipv6ra");
else
buf = strdup("gw: _dhcp");
if (ordered_set_isempty(route->nexthops)) {
- if (in_addr_is_set(route->gw_family, &route->gw)) {
- if (route->gw_family == route->family)
- r = netlink_message_append_in_addr_union(message, RTA_GATEWAY, route->gw_family, &route->gw);
+ if (in_addr_is_set(route->nexthop.family, &route->nexthop.gw)) {
+ if (route->nexthop.family == route->family)
+ r = netlink_message_append_in_addr_union(message, RTA_GATEWAY, route->nexthop.family, &route->nexthop.gw);
else {
assert(route->family == AF_INET);
r = sd_netlink_message_append_data(message, RTA_VIA,
&(const RouteVia) {
- .family = route->gw_family,
- .address = route->gw,
+ .family = route->nexthop.family,
+ .address = route->nexthop.gw,
}, sizeof(RouteVia));
}
if (r < 0)
return log_warning_errno(r, "rtnl: could not get ifindex from route message, ignoring: %m");
if (ifindex > 0) {
- r = netlink_message_read_in_addr_union(message, RTA_GATEWAY, route->family, &route->gw);
+ r = netlink_message_read_in_addr_union(message, RTA_GATEWAY, route->family, &route->nexthop.gw);
if (r >= 0) {
- route->gw_family = route->family;
+ route->nexthop.family = route->family;
return 0;
}
if (r != -ENODATA)
RouteVia via;
r = sd_netlink_message_read(message, RTA_VIA, sizeof(via), &via);
if (r >= 0) {
- route->gw_family = via.family;
- route->gw = via.address;
+ route->nexthop.family = via.family;
+ route->nexthop.gw = via.address;
return 0;
}
if (r != -ENODATA)
if (route->gateway_from_dhcp_or_ra) {
assert(route->network);
- if (route->gw_family == AF_UNSPEC)
+ if (route->nexthop.family == AF_UNSPEC)
/* When deprecated Gateway=_dhcp is set, then assume gateway family based on other settings. */
switch (route->family) {
case AF_UNSPEC:
"Please use \"_dhcp4\" or \"_ipv6ra\" instead. Assuming \"_dhcp4\".",
route->section->filename, route->section->line);
- route->gw_family = route->family = AF_INET;
+ route->nexthop.family = route->family = AF_INET;
break;
case AF_INET:
case AF_INET6:
"Assuming \"%s\" based on Destination=, Source=, or PreferredSource= setting.",
route->section->filename, route->section->line, route->family == AF_INET ? "_dhcp4" : "_ipv6ra");
- route->gw_family = route->family;
+ route->nexthop.family = route->family;
break;
default:
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
route->section->filename, route->section->line);
}
- if (route->gw_family == AF_INET && !FLAGS_SET(route->network->dhcp, ADDRESS_FAMILY_IPV4))
+ if (route->nexthop.family == AF_INET && !FLAGS_SET(route->network->dhcp, ADDRESS_FAMILY_IPV4))
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: Gateway=\"_dhcp4\" is specified but DHCPv4 client is disabled. "
"Ignoring [Route] section from line %u.",
route->section->filename, route->section->line);
- if (route->gw_family == AF_INET6 && !route->network->ipv6_accept_ra)
+ if (route->nexthop.family == AF_INET6 && !route->network->ipv6_accept_ra)
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: Gateway=\"_ipv6ra\" is specified but IPv6AcceptRA= is disabled. "
"Ignoring [Route] section from line %u.",
/* When only Gateway= is specified, assume the route family based on the Gateway address. */
if (route->family == AF_UNSPEC)
- route->family = route->gw_family;
+ route->family = route->nexthop.family;
if (route->family == AF_UNSPEC) {
assert(route->section);
route->section->filename, route->section->line);
}
- if (route->gateway_onlink < 0 && in_addr_is_set(route->gw_family, &route->gw) &&
+ if (route->gateway_onlink < 0 && in_addr_is_set(route->nexthop.family, &route->nexthop.gw) &&
route->network && ordered_hashmap_isempty(route->network->addresses_by_section)) {
/* If no address is configured, in most cases the gateway cannot be reachable.
* TODO: we may need to improve the condition above. */
SET_FLAG(route->flags, RTNH_F_ONLINK, route->gateway_onlink);
if (route->family == AF_INET6) {
- if (route->gw_family == AF_INET)
+ if (route->nexthop.family == AF_INET)
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: IPv4 gateway is configured for IPv6 route. "
"Ignoring [Route] section from line %u.",
if (route->nexthop_id != 0 &&
(route->gateway_from_dhcp_or_ra ||
- in_addr_is_set(route->gw_family, &route->gw) ||
+ in_addr_is_set(route->nexthop.family, &route->nexthop.gw) ||
!ordered_set_isempty(route->nexthops)))
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: NextHopId= cannot be specified with Gateway= or MultiPathRoute=. "
if (route_type_is_reject(route) &&
(route->gateway_from_dhcp_or_ra ||
- in_addr_is_set(route->gw_family, &route->gw) ||
+ in_addr_is_set(route->nexthop.family, &route->nexthop.gw) ||
!ordered_set_isempty(route->nexthops)))
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: reject type route cannot be specified with Gateway= or MultiPathRoute=. "
route->section->filename, route->section->line);
if ((route->gateway_from_dhcp_or_ra ||
- in_addr_is_set(route->gw_family, &route->gw)) &&
+ in_addr_is_set(route->nexthop.family, &route->nexthop.gw)) &&
!ordered_set_isempty(route->nexthops))
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: Gateway= cannot be specified with MultiPathRoute=. "
if (isempty(rvalue)) {
route->gateway_from_dhcp_or_ra = false;
- route->gw_family = AF_UNSPEC;
- route->gw = IN_ADDR_NULL;
+ route->nexthop.family = AF_UNSPEC;
+ route->nexthop.gw = IN_ADDR_NULL;
TAKE_PTR(route);
return 0;
}
if (streq(rvalue, "_dhcp")) {
route->gateway_from_dhcp_or_ra = true;
- route->gw_family = AF_UNSPEC;
- route->gw = IN_ADDR_NULL;
+ route->nexthop.family = AF_UNSPEC;
+ route->nexthop.gw = IN_ADDR_NULL;
TAKE_PTR(route);
return 0;
}
if (streq(rvalue, "_dhcp4")) {
route->gateway_from_dhcp_or_ra = true;
- route->gw_family = AF_INET;
- route->gw = IN_ADDR_NULL;
+ route->nexthop.family = AF_INET;
+ route->nexthop.gw = IN_ADDR_NULL;
TAKE_PTR(route);
return 0;
}
if (streq(rvalue, "_ipv6ra")) {
route->gateway_from_dhcp_or_ra = true;
- route->gw_family = AF_INET6;
- route->gw = IN_ADDR_NULL;
+ route->nexthop.family = AF_INET6;
+ route->nexthop.gw = IN_ADDR_NULL;
TAKE_PTR(route);
return 0;
}
}
- r = in_addr_from_string_auto(rvalue, &route->gw_family, &route->gw);
+ r = in_addr_from_string_auto(rvalue, &route->nexthop.family, &route->nexthop.gw);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid %s='%s', ignoring assignment: %m", lvalue, rvalue);
siphash24_compress_typesafe(route->src_prefixlen, state);
in_addr_hash_func(&route->src, route->family, state);
- siphash24_compress_typesafe(route->gw_family, state);
- if (IN_SET(route->gw_family, AF_INET, AF_INET6)) {
- in_addr_hash_func(&route->gw, route->gw_family, state);
- siphash24_compress_typesafe(route->gw_weight, state);
+ siphash24_compress_typesafe(route->nexthop.family, state);
+ if (IN_SET(route->nexthop.family, AF_INET, AF_INET6)) {
+ in_addr_hash_func(&route->nexthop.gw, route->nexthop.family, state);
+ siphash24_compress_typesafe(route->nexthop.weight, state);
}
in_addr_hash_func(&route->prefsrc, route->family, state);
if (r != 0)
return r;
- r = CMP(a->gw_family, b->gw_family);
+ r = CMP(a->nexthop.family, b->nexthop.family);
if (r != 0)
return r;
- if (IN_SET(a->gw_family, AF_INET, AF_INET6)) {
- r = memcmp(&a->gw, &b->gw, FAMILY_ADDRESS_SIZE(a->family));
+ if (IN_SET(a->nexthop.family, AF_INET, AF_INET6)) {
+ r = memcmp(&a->nexthop.gw, &b->nexthop.gw, FAMILY_ADDRESS_SIZE(a->family));
if (r != 0)
return r;
- r = CMP(a->gw_weight, b->gw_weight);
+ r = CMP(a->nexthop.weight, b->nexthop.weight);
if (r != 0)
return r;
}
assert(nh);
assert(hashmap_isempty(nh->group));
- route->gw_family = nh->family;
- route->gw = nh->gw;
+ route->nexthop.family = nh->family;
+ route->nexthop.gw = nh->gw;
if (nh_weight != UINT8_MAX)
- route->gw_weight = nh_weight;
+ route->nexthop.weight = nh_weight;
if (nh->blackhole)
route->type = RTN_BLACKHOLE;
assert(route);
assert(nh);
- route->gw_family = nh->family;
- route->gw = nh->gw;
- route->gw_weight = nh->weight;
+ route->nexthop.family = nh->family;
+ route->nexthop.gw = nh->gw;
+ route->nexthop.weight = nh->weight;
}
typedef struct ConvertedRoutes {
route->scope = RT_SCOPE_LINK;
else if (IN_SET(route->type, RTN_UNICAST, RTN_UNSPEC) &&
!route->gateway_from_dhcp_or_ra &&
- !in_addr_is_set(route->gw_family, &route->gw) &&
+ !in_addr_is_set(route->nexthop.family, &route->nexthop.gw) &&
ordered_set_isempty(route->nexthops) &&
route->nexthop_id == 0)
route->scope = RT_SCOPE_LINK;