Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route lifetime from Router Advertisement #429

Merged
merged 18 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move route lifetime calc to common func
If not set to infinite, lifetime is shortened
by time elapsed since acquired
  • Loading branch information
ColinMcInnes committed Jan 10, 2025
commit 2d2e7bef015db8be339e3d12eeb75f18ebbc6930
14 changes: 14 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
@@ -214,3 +214,17 @@ is_root_local(void)
return -1;
#endif
}

uint32_t
lifetime_left(uint32_t lifetime, const struct timespec *aquired, const struct timespec *now)
{
uint32_t elpased;

if (lifetime == INFINITE_LIFETIME)
return lifetime;

elapsed = (uint32_t)eloop_timespec_diff(now, &acquired, NULL);
if (elapsed > lifetime)
return 0;
return lifetime - elapsed;
}
3 changes: 3 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -141,11 +141,14 @@
# endif
#endif

#define INFINITE_LIFETIME (~0U)

const char *hwaddr_ntoa(const void *, size_t, char *, size_t);
size_t hwaddr_aton(uint8_t *, const char *);
ssize_t readfile(const char *, void *, size_t);
ssize_t writefile(const char *, mode_t, const void *, size_t);
int filemtime(const char *, time_t *);
char *get_line(char ** __restrict, ssize_t * __restrict);
int is_root_local(void);
uint32_t lifetime_left(uint32_t, const struct timespec *, const struct timespec *);
#endif
11 changes: 3 additions & 8 deletions src/ipv6.c
Original file line number Diff line number Diff line change
@@ -2306,8 +2306,6 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
return 0;

struct timespec now;
uint32_t elapsed;

clock_gettime(CLOCK_MONOTONIC, &now);

TAILQ_FOREACH(rap, ctx->ra_routers, next) {
@@ -2330,8 +2328,7 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
#ifdef HAVE_ROUTE_PREF
rt->rt_pref = ipv6nd_rtpref(rinfo->flags);
#endif
elapsed = (uint32_t)eloop_timespec_diff(&now, &rinfo->acquired, NULL);
rt->rt_expires = rap->lifetime - elapsed;
rt->rt_expires = lifetime_left(rap->lifetime, &rinfo->aquired, &now);

rt_proto_add(routes, rt);
}
@@ -2346,8 +2343,7 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
#ifdef HAVE_ROUTE_PREF
rt->rt_pref = ipv6nd_rtpref(rap->flags);
#endif
elapsed = (uint32_t)eloop_timespec_diff(&now, &addr->acquired, NULL);
rt->rt_expires = rap->lifetime - elapsed;
rt->rt_expires = lifetime_left(rap->lifetime, &addr->aquired, &now);

rt_proto_add(routes, rt);
}
@@ -2380,8 +2376,7 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
#ifdef HAVE_ROUTE_PREF
rt->rt_pref = ipv6nd_rtpref(rap->flags);
#endif
elapsed = (uint32_t)eloop_timespec_diff(&now, &rap->acquired, NULL);
rt->rt_expires = rap->lifetime - elapsed;
rt->rt_expires = lifetime_left(rap->lifetime, &rap->aquired, &now);

rt_proto_add(routes, rt);
}
Loading
Oops, something went wrong.