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
Show file tree
Hide file tree
Changes from 7 commits
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
6 changes: 6 additions & 0 deletions src/if-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, struct nlmsghdr *nlm)
}
break;
}
case RTA_EXPIRES:
rt->rt_expires = *(uint32_t *)RTA_DATA(rta);
break;
}

if (sa != NULL) {
Expand Down Expand Up @@ -1735,6 +1738,9 @@ if_route(unsigned char cmd, const struct rt *rt)
if (!sa_is_loopback(&rt->rt_gateway))
add_attr_32(&nlm.hdr, sizeof(nlm), RTA_OIF, rt->rt_ifp->index);

/* add route lifetime */
add_attr_32(&nlm.hdr, sizeof(nlm), RTA_EXPIRES, rt->rt_expires);
ColinMcInnes marked this conversation as resolved.
Show resolved Hide resolved

if (rt->rt_metric != 0)
add_attr_32(&nlm.hdr, sizeof(nlm), RTA_PRIORITY,
rt->rt_metric);
Expand Down
12 changes: 12 additions & 0 deletions src/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,10 @@ inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
const struct routeinfo *rinfo;
const struct ipv6_addr *addr;
struct in6_addr netmask;
struct timespec now;
uint32_t elapsed;

clock_gettime(CLOCK_MONOTONIC, &now);
ColinMcInnes marked this conversation as resolved.
Show resolved Hide resolved

if (ctx->ra_routers == NULL)
return 0;
Expand All @@ -2325,6 +2329,8 @@ 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, &rap->acquired, NULL);
ColinMcInnes marked this conversation as resolved.
Show resolved Hide resolved
rt->rt_expires = rap->lifetime - elapsed;

rt_proto_add(routes, rt);
}
Expand All @@ -2339,6 +2345,9 @@ 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);
ColinMcInnes marked this conversation as resolved.
Show resolved Hide resolved
rt->rt_expires = rap->lifetime - elapsed;

rt_proto_add(routes, rt);
}
}
Expand Down Expand Up @@ -2370,6 +2379,9 @@ 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_proto_add(routes, rt);
}
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct rt {
#define RTDF_GATELINK 0x40 /* Gateway is on link */
size_t rt_order;
rb_node_t rt_tree;
uint32_t rt_expires; /* current lifetime of route */
};

extern const rb_tree_ops_t rt_compare_list_ops;
Expand Down
Loading