X Tutup
Skip to content

Commit 91fc513

Browse files
committed
network: route: rename lifetime -> lifetime_usec
1 parent 0b5fe54 commit 91fc513

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

src/network/networkd-dhcp6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static int dhcp6_pd_request_route(Link *link, const struct in6_addr *prefix, use
310310
route->dst_prefixlen = 64;
311311
route->protocol = RTPROT_DHCP;
312312
route->priority = link->network->dhcp6_pd_route_metric;
313-
route->lifetime = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
313+
route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
314314

315315
if (route_get(NULL, link, route, &existing) < 0)
316316
link->dhcp6_pd_configured = false;
@@ -778,7 +778,7 @@ static int dhcp6_request_unreachable_route(Link *link, const struct in6_addr *ad
778778
route->type = RTN_UNREACHABLE;
779779
route->protocol = RTPROT_DHCP;
780780
route->priority = DHCP_ROUTE_METRIC;
781-
route->lifetime = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
781+
route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
782782

783783
if (route_get(link->manager, NULL, route, &existing) < 0)
784784
link->dhcp6_configured = false;

src/network/networkd-ndisc.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,29 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) {
291291

292292
static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
293293
_cleanup_(route_freep) Route *route = NULL;
294+
usec_t lifetime_usec, timestamp_usec;
294295
struct in6_addr gateway;
295-
uint32_t mtu = 0;
296+
uint16_t lifetime_sec;
296297
unsigned preference;
297-
uint16_t lifetime;
298-
usec_t time_now;
298+
uint32_t mtu = 0;
299299
int r;
300300

301301
assert(link);
302302
assert(rt);
303303

304-
r = sd_ndisc_router_get_lifetime(rt, &lifetime);
304+
r = sd_ndisc_router_get_lifetime(rt, &lifetime_sec);
305305
if (r < 0)
306306
return log_link_error_errno(link, r, "Failed to get gateway lifetime from RA: %m");
307307

308-
if (lifetime == 0) /* not a default router */
308+
if (lifetime_sec == 0) /* not a default router */
309309
return 0;
310310

311+
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &timestamp_usec);
312+
if (r < 0)
313+
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
314+
315+
lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
316+
311317
r = sd_ndisc_router_get_address(rt, &gateway);
312318
if (r < 0)
313319
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) {
327333
if (r < 0)
328334
return log_link_error_errno(link, r, "Failed to get default router preference from RA: %m");
329335

330-
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &time_now);
331-
if (r < 0)
332-
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
333-
334336
if (link->network->ipv6_accept_ra_use_mtu) {
335337
r = sd_ndisc_router_get_mtu(rt, &mtu);
336338
if (r < 0 && r != -ENODATA)
@@ -345,7 +347,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
345347
route->pref = preference;
346348
route->gw_family = AF_INET6;
347349
route->gw.in6 = gateway;
348-
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
350+
route->lifetime_usec = lifetime_usec;
349351
route->mtu = mtu;
350352

351353
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) {
367369
route->gw.in6 = gateway;
368370
if (!route->pref_set)
369371
route->pref = preference;
370-
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
372+
route->lifetime_usec = lifetime_usec;
371373
if (route->mtu == 0)
372374
route->mtu = mtu;
373375

@@ -472,23 +474,23 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
472474

473475
static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
474476
_cleanup_(route_freep) Route *route = NULL;
475-
usec_t time_now;
476-
uint32_t lifetime;
477+
usec_t timestamp_usec;
478+
uint32_t lifetime_sec;
477479
unsigned prefixlen;
478480
int r;
479481

480482
assert(link);
481483
assert(rt);
482484

483-
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &time_now);
485+
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &timestamp_usec);
484486
if (r < 0)
485487
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
486488

487489
r = sd_ndisc_router_prefix_get_prefixlen(rt, &prefixlen);
488490
if (r < 0)
489491
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
490492

491-
r = sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime);
493+
r = sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime_sec);
492494
if (r < 0)
493495
return log_link_error_errno(link, r, "Failed to get prefix lifetime: %m");
494496

@@ -499,7 +501,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
499501
route->family = AF_INET6;
500502
route->flags = RTM_F_PREFIX;
501503
route->dst_prefixlen = prefixlen;
502-
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
504+
route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
503505

504506
r = sd_ndisc_router_prefix_get_address(rt, &route->dst.in6);
505507
if (r < 0)
@@ -514,19 +516,19 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
514516

515517
static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
516518
_cleanup_(route_freep) Route *route = NULL;
517-
struct in6_addr gateway, dst;
518-
uint32_t lifetime;
519519
unsigned preference, prefixlen;
520-
usec_t time_now;
520+
struct in6_addr gateway, dst;
521+
uint32_t lifetime_sec;
522+
usec_t timestamp_usec;
521523
int r;
522524

523525
assert(link);
524526

525-
r = sd_ndisc_router_route_get_lifetime(rt, &lifetime);
527+
r = sd_ndisc_router_route_get_lifetime(rt, &lifetime_sec);
526528
if (r < 0)
527529
return log_link_error_errno(link, r, "Failed to get route lifetime from RA: %m");
528530

529-
if (lifetime == 0)
531+
if (lifetime_sec == 0)
530532
return 0;
531533

532534
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) {
568570
if (r < 0)
569571
return log_link_error_errno(link, r, "Failed to get default router preference from RA: %m");
570572

571-
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &time_now);
573+
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &timestamp_usec);
572574
if (r < 0)
573575
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
574576

@@ -582,7 +584,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
582584
route->gw_family = AF_INET6;
583585
route->dst.in6 = dst;
584586
route->dst_prefixlen = prefixlen;
585-
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
587+
route->lifetime_usec = usec_add(timestamp_usec, lifetime_sec * USEC_PER_SEC);
586588

587589
r = ndisc_request_route(TAKE_PTR(route), link, rt);
588590
if (r < 0)

src/network/networkd-route.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ int route_new(Route **ret) {
186186
.protocol = RTPROT_UNSPEC,
187187
.type = RTN_UNICAST,
188188
.table = RT_TABLE_MAIN,
189-
.lifetime = USEC_INFINITY,
189+
.lifetime_usec = USEC_INFINITY,
190190
.quickack = -1,
191191
.fast_open_no_cookie = -1,
192192
.gateway_onlink = -1,
@@ -1240,15 +1240,15 @@ static int route_setup_timer(Route *route, const struct rta_cacheinfo *cacheinfo
12401240

12411241
manager = route->manager ?: route->link->manager;
12421242

1243-
if (route->lifetime == USEC_INFINITY)
1243+
if (route->lifetime_usec == USEC_INFINITY)
12441244
return 0;
12451245

12461246
if (cacheinfo && cacheinfo->rta_expires != 0)
12471247
/* Assume that non-zero rta_expires means kernel will handle the route expiration. */
12481248
return 0;
12491249

12501250
r = event_reset_time(manager->event, &route->expire, clock_boottime_or_monotonic(),
1251-
route->lifetime, 0, route_expire_handler, route, 0, "route-expiration", true);
1251+
route->lifetime_usec, 0, route_expire_handler, route, 0, "route-expiration", true);
12521252
if (r < 0)
12531253
return r;
12541254

@@ -1392,9 +1392,9 @@ static int route_configure(
13921392
if (r < 0)
13931393
return r;
13941394

1395-
if (route->lifetime != USEC_INFINITY) {
1395+
if (route->lifetime_usec != USEC_INFINITY) {
13961396
r = sd_netlink_message_append_u32(req, RTA_EXPIRES,
1397-
MIN(DIV_ROUND_UP(usec_sub_unsigned(route->lifetime, now(clock_boottime_or_monotonic())), USEC_PER_SEC), UINT32_MAX));
1397+
MIN(DIV_ROUND_UP(usec_sub_unsigned(route->lifetime_usec, now(clock_boottime_or_monotonic())), USEC_PER_SEC), UINT32_MAX));
13981398
if (r < 0)
13991399
return log_link_error_errno(link, r, "Could not append RTA_EXPIRES attribute: %m");
14001400
}
@@ -3039,7 +3039,7 @@ static int route_section_verify(Route *route, Network *network) {
30393039
return -EINVAL;
30403040

30413041
/* Currently, we do not support static route with finite lifetime. */
3042-
assert(route->lifetime == USEC_INFINITY);
3042+
assert(route->lifetime_usec == USEC_INFINITY);
30433043

30443044
if (route->gateway_from_dhcp_or_ra) {
30453045
if (route->gw_family == AF_UNSPEC) {

src/network/networkd-route.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ typedef struct Route {
6161
union in_addr_union prefsrc;
6262
OrderedSet *multipath_routes;
6363

64-
usec_t lifetime;
64+
/* This is an absolute point in time, and NOT a timespan/duration.
65+
* Must be specified with clock_boottime_or_monotonic(). */
66+
usec_t lifetime_usec;
67+
/* Used when kernel does not support RTA_EXPIRES attribute. */
6568
sd_event_source *expire;
6669
} Route;
6770

0 commit comments

Comments
 (0)
X Tutup