@@ -291,23 +291,29 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) {
291291
292292static 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
473475static 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
515517static 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 )
0 commit comments