1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-13 12:58:20 +03:00

network: route: rename lifetime -> lifetime_usec

This commit is contained in:
Yu Watanabe 2021-10-21 00:22:49 +09:00
parent 0b5fe54ff5
commit 91fc5135e6
4 changed files with 37 additions and 32 deletions

View File

@ -310,7 +310,7 @@ static int dhcp6_pd_request_route(Link *link, const struct in6_addr *prefix, use
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;
@ -778,7 +778,7 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad
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;

View File

@ -291,23 +291,29 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) {
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(), &timestamp_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");
@ -327,10 +333,6 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
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)
@ -345,7 +347,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
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);
@ -367,7 +369,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *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;
@ -472,15 +474,15 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
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(), &timestamp_usec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
@ -488,7 +490,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
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");
@ -499,7 +501,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
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)
@ -514,19 +516,19 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
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);
@ -568,7 +570,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
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(), &timestamp_usec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
@ -582,7 +584,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
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)

View File

@ -186,7 +186,7 @@ int route_new(Route **ret) {
.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,
@ -1240,7 +1240,7 @@ static int route_setup_timer(Route *route, const struct rta_cacheinfo *cacheinfo
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)
@ -1248,7 +1248,7 @@ static int route_setup_timer(Route *route, const struct rta_cacheinfo *cacheinfo
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;
@ -1392,9 +1392,9 @@ static int route_configure(
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");
}
@ -3039,7 +3039,7 @@ static int route_section_verify(Route *route, Network *network) {
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) {

View File

@ -61,7 +61,10 @@ typedef struct Route {
union in_addr_union prefsrc;
OrderedSet *multipath_routes;
usec_t lifetime;
/* This is an absolute point in time, and NOT a timespan/duration.
* Must be specified with clock_boottime_or_monotonic(). */
usec_t lifetime_usec;
/* Used when kernel does not support RTA_EXPIRES attribute. */
sd_event_source *expire;
} Route;