static volatile int do_signal = 0;
static int urandom_fd = -1, allow_slaac_only = 0;
static bool bound = false, release = true;
+static time_t last_update = 0;
int main(_unused int argc, char* const argv[])
{
if (do_signal == SIGIO) {
do_signal = 0;
+ bool ra_rtnled = ra_rtnl_process();
bool ra_updated = ra_process();
- if (ra_rtnl_process() || (ra_updated && (bound || allow_slaac_only == 0)))
+ if (ra_rtnled || (ra_updated && (bound || allow_slaac_only == 0)))
script_call("ra-updated"); // Immediate process urgent events
else if (ra_updated && !bound && allow_slaac_only > 0)
script_delay_call("ra-updated", allow_slaac_only);
void odhcp6c_expire(void)
{
- static time_t last_update = 0;
time_t now = odhcp6c_get_milli_time() / 1000;
-
uint32_t elapsed = (last_update > 0) ? now - last_update : 0;
last_update = now;
}
+uint32_t odhcp6c_elapsed(void)
+{
+ return odhcp6c_get_milli_time() / 1000 - last_update;
+}
+
+
void odhcp6c_random(void *buf, size_t len)
{
read(urandom_fd, buf, len);
void odhcp6c_update_entry_safe(enum odhcp6c_state state, struct odhcp6c_entry *new, uint32_t safe);
void odhcp6c_expire(void);
+uint32_t odhcp6c_elapsed(void);
bool ra_rtnl_process(void)
{
bool found = false;
+ uint32_t elapsed = odhcp6c_elapsed();
uint8_t buf[8192];
while (true) {
ssize_t len = recv(rtnl_sock, buf, sizeof(buf), MSG_DONTWAIT);
if (len < 0)
break;
+ if (elapsed > 10)
+ continue;
+
for (struct nlmsghdr *nh = (struct nlmsghdr*)buf; NLMSG_OK(nh, (size_t)len);
nh = NLMSG_NEXT(nh, len)) {
struct ifaddrmsg *ifa = NLMSG_DATA(nh);
struct nd_router_advert *adv = (struct nd_router_advert*)buf;
struct odhcp6c_entry entry = {IN6ADDR_ANY_INIT, 0, 0, IN6ADDR_ANY_INIT, 0, 0};
const struct in6_addr any = IN6ADDR_ANY_INIT;
- odhcp6c_expire();
while (true) {
struct sockaddr_in6 from;
rs_attempt = 0;
}
- found = true;
+ if (!found) {
+ odhcp6c_expire();
+ found = true;
+ }
uint32_t router_valid = ntohs(adv->nd_ra_router_lifetime);
// Parse default route
entry[i].valid = router_valid;
}
- odhcp6c_expire();
+ if (found)
+ odhcp6c_expire();
+
return found;
}