odhcp6c: add -K option to set packet kernel priority
[project/odhcp6c.git] / src / script.c
index 5696b7f9c955308a542e63af50095b50b21e9f19..bb93a53ed519927406f660659bd33c618bd6d0ea 100644 (file)
@@ -179,6 +179,14 @@ static void entry_to_env(const char *name, const void *data, size_t len, enum en
        buf[buf_len++] = '=';
 
        for (size_t i = 0; i < len / sizeof(*e); ++i) {
+               /*
+                * The only invalid entries allowed to be passed to the script are prefix entries.
+                * This will allow immediate removal of the old ipv6-prefix-assignment that might
+                * otherwise be kept for up to 2 hours (see L-13 requirement of RFC 7084).
+                */
+               if (!e[i].valid && type != ENTRY_PREFIX)
+                       continue;
+
                inet_ntop(AF_INET6, &e[i].target, &buf[buf_len], INET6_ADDRSTRLEN);
                buf_len += strlen(&buf[buf_len]);
 
@@ -238,6 +246,8 @@ static void search_to_env(const char *name, const uint8_t *start, size_t len)
                                (uint8_t*)e < &start[len] &&
                                (uint8_t*)odhcp6c_next_entry(e) <= &start[len];
                                e = odhcp6c_next_entry(e)) {
+               if (!e->valid)
+                       continue;
                c = mempcpy(c, e->auxtarget, e->auxlen);
                *c++ = ' ';
        }
@@ -393,8 +403,15 @@ void script_call(const char *status, int delay, bool resume)
        bool running_script = false;
 
        if (running) {
+               time_t diff = now - started;
+
                kill(running, SIGTERM);
-               delay -= now - started;
+
+               if (diff > delay)
+                       delay -= diff;
+               else
+                       delay = 0;
+
                running_script = true;
        }
 
@@ -418,7 +435,7 @@ void script_call(const char *status, int delay, bool resume)
                signal(SIGTERM, SIG_DFL);
                if (delay > 0) {
                        sleep(delay);
-                       odhcp6c_expire();
+                       odhcp6c_expire(false);
                }
 
                struct in6_addr *addr = odhcp6c_get_state(STATE_SERVER_ADDR, &addr_len);
@@ -471,10 +488,10 @@ void script_call(const char *status, int delay, bool resume)
                entry_to_env("RA_DNS", ra_dns, ra_dns_len, ENTRY_HOST);
                search_to_env("RA_DOMAINS", ra_search, ra_search_len);
 
-               int_to_env("RA_HOPLIMIT", ra_conf_hoplimit(0));
-               int_to_env("RA_MTU", ra_conf_mtu(0));
-               int_to_env("RA_REACHABLE", ra_conf_reachable(0));
-               int_to_env("RA_RETRANSMIT", ra_conf_retransmit(0));
+               int_to_env("RA_HOPLIMIT", ra_get_hoplimit());
+               int_to_env("RA_MTU", ra_get_mtu());
+               int_to_env("RA_REACHABLE", ra_get_reachable());
+               int_to_env("RA_RETRANSMIT", ra_get_retransmit());
 
                char *buf = malloc(10 + passthru_len * 2);
                strncpy(buf, "PASSTHRU=", 10);