]> git.decadent.org.uk Git - odhcp6c.git/blobdiff - src/odhcp6c.c
Work around false-positive DAD-hits
[odhcp6c.git] / src / odhcp6c.c
index 6ce9adf33ce344548b72ed700d40f9c3934066b0..4fefcd70b2c6521005e29316b3c1048bc2e0996a 100644 (file)
@@ -40,8 +40,9 @@ static uint8_t *state_data[_STATE_MAX] = {NULL};
 static size_t state_len[_STATE_MAX] = {0};
 
 static volatile int do_signal = 0;
-static int urandom_fd = -1, allow_slaac_only = 15;
+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[])
@@ -76,6 +77,9 @@ int main(_unused int argc, char* const argv[])
                        break;
 
                case 'P':
+                       if (allow_slaac_only >= 0 && allow_slaac_only < 10)
+                               allow_slaac_only = 10;
+
                        request_pd = strtoul(optarg, NULL, 10);
                        if (request_pd == 0)
                                request_pd = -1;
@@ -306,7 +310,7 @@ static int usage(void)
        const char buf[] =
        "Usage: odhcp6c [options] <interface>\n"
        "\nFeature options:\n"
-       "       -S <time>       Wait at least <time> sec for a DHCP-server (15)\n"
+       "       -S <time>       Wait at least <time> sec for a DHCP-server (0)\n"
        "       -N <mode>       Mode for requesting addresses [try|force|none]\n"
        "       -P <length>     Request IPv6-Prefix (0 = auto)\n"
        "       -c <clientid>   Override client-ID (base-16 encoded)\n"
@@ -354,9 +358,10 @@ bool odhcp6c_signal_process(void)
 {
        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);
@@ -464,10 +469,8 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed)
 
 void odhcp6c_expire(void)
 {
-       static time_t last_update = 0;
        time_t now = odhcp6c_get_milli_time() / 1000;
-
-       uint32_t elapsed = now - last_update;
+       uint32_t elapsed = (last_update > 0) ? now - last_update : 0;
        last_update = now;
 
        odhcp6c_expire_list(STATE_RA_PREFIX, elapsed);
@@ -478,6 +481,12 @@ void odhcp6c_expire(void)
 }
 
 
+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);