route->dst_prefixlen = 64;
route->protocol = RTPROT_DHCP;
route->priority = link->network->dhcp6_pd_route_metric;
- route->lifetime = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
+ route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
if (route_get(NULL, link, route, &existing) < 0)
link->dhcp6_pd_configured = false;
route->type = RTN_UNREACHABLE;
route->protocol = RTPROT_DHCP;
route->priority = DHCP_ROUTE_METRIC;
- route->lifetime = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
+ route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
if (route_get(link->manager, NULL, route, &existing) < 0)
link->dhcp6_configured = false;
static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
_cleanup_(route_freep) Route *route = NULL;
+ usec_t lifetime_usec, timestamp_usec;
struct in6_addr gateway;
- uint32_t mtu = 0;
+ uint16_t lifetime_sec;
unsigned preference;
- uint16_t lifetime;
- usec_t time_now;
+ uint32_t mtu = 0;
int r;
assert(link);
assert(rt);
- r = sd_ndisc_router_get_lifetime(rt, &lifetime);
+ r = sd_ndisc_router_get_lifetime(rt, &lifetime_sec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get gateway lifetime from RA: %m");
- if (lifetime == 0) /* not a default router */
+ if (lifetime_sec == 0) /* not a default router */
return 0;
+ r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
+
+ lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
+
r = sd_ndisc_router_get_address(rt, &gateway);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m");
if (r < 0)
return log_link_error_errno(link, r, "Failed to get default router preference from RA: %m");
- r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &time_now);
- if (r < 0)
- return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
-
if (link->network->ipv6_accept_ra_use_mtu) {
r = sd_ndisc_router_get_mtu(rt, &mtu);
if (r < 0 && r != -ENODATA)
route->pref = preference;
route->gw_family = AF_INET6;
route->gw.in6 = gateway;
- route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
+ route->lifetime_usec = lifetime_usec;
route->mtu = mtu;
r = ndisc_request_route(TAKE_PTR(route), link, rt);
route->gw.in6 = gateway;
if (!route->pref_set)
route->pref = preference;
- route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
+ route->lifetime_usec = lifetime_usec;
if (route->mtu == 0)
route->mtu = mtu;
static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
_cleanup_(route_freep) Route *route = NULL;
- usec_t time_now;
- uint32_t lifetime;
+ usec_t timestamp_usec;
+ uint32_t lifetime_sec;
unsigned prefixlen;
int r;
assert(link);
assert(rt);
- r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &time_now);
+ r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
- r = sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime);
+ r = sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime_sec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix lifetime: %m");
route->family = AF_INET6;
route->flags = RTM_F_PREFIX;
route->dst_prefixlen = prefixlen;
- route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
+ route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
r = sd_ndisc_router_prefix_get_address(rt, &route->dst.in6);
if (r < 0)
static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
_cleanup_(route_freep) Route *route = NULL;
- struct in6_addr gateway, dst;
- uint32_t lifetime;
unsigned preference, prefixlen;
- usec_t time_now;
+ struct in6_addr gateway, dst;
+ uint32_t lifetime_sec;
+ usec_t timestamp_usec;
int r;
assert(link);
- r = sd_ndisc_router_route_get_lifetime(rt, &lifetime);
+ r = sd_ndisc_router_route_get_lifetime(rt, &lifetime_sec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get route lifetime from RA: %m");
- if (lifetime == 0)
+ if (lifetime_sec == 0)
return 0;
r = sd_ndisc_router_route_get_address(rt, &dst);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get default router preference from RA: %m");
- r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &time_now);
+ r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
route->gw_family = AF_INET6;
route->dst.in6 = dst;
route->dst_prefixlen = prefixlen;
- route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
+ route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
r = ndisc_request_route(TAKE_PTR(route), link, rt);
if (r < 0)
.protocol = RTPROT_UNSPEC,
.type = RTN_UNICAST,
.table = RT_TABLE_MAIN,
- .lifetime = USEC_INFINITY,
+ .lifetime_usec = USEC_INFINITY,
.quickack = -1,
.fast_open_no_cookie = -1,
.gateway_onlink = -1,
manager = route->manager ?: route->link->manager;
- if (route->lifetime == USEC_INFINITY)
+ if (route->lifetime_usec == USEC_INFINITY)
return 0;
if (cacheinfo && cacheinfo->rta_expires != 0)
return 0;
r = event_reset_time(manager->event, &route->expire, clock_boottime_or_monotonic(),
- route->lifetime, 0, route_expire_handler, route, 0, "route-expiration", true);
+ route->lifetime_usec, 0, route_expire_handler, route, 0, "route-expiration", true);
if (r < 0)
return r;
if (r < 0)
return r;
- if (route->lifetime != USEC_INFINITY) {
+ if (route->lifetime_usec != USEC_INFINITY) {
r = sd_netlink_message_append_u32(req, RTA_EXPIRES,
- MIN(DIV_ROUND_UP(usec_sub_unsigned(route->lifetime, now(clock_boottime_or_monotonic())), USEC_PER_SEC), UINT32_MAX));
+ MIN(DIV_ROUND_UP(usec_sub_unsigned(route->lifetime_usec, now(clock_boottime_or_monotonic())), USEC_PER_SEC), UINT32_MAX));
if (r < 0)
return log_link_error_errno(link, r, "Could not append RTA_EXPIRES attribute: %m");
}
return -EINVAL;
/* Currently, we do not support static route with finite lifetime. */
- assert(route->lifetime == USEC_INFINITY);
+ assert(route->lifetime_usec == USEC_INFINITY);
if (route->gateway_from_dhcp_or_ra) {
if (route->gw_family == AF_UNSPEC) {