CMakeLists: don't enable libubox md5 implementation by default
[project/odhcp6c.git] / src / dhcpv6.c
index 63890526e9045fb2a5604698c2ac4de07b491a59..b7322579cdca59822d5a543d02ba482c39de04e9 100644 (file)
@@ -1,5 +1,6 @@
 /**
  * Copyright (C) 2012-2014 Steven Barth <steven@midlink.org>
+ * Copyright (C) 2017 Hans Dedecker <dedeckeh@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License v2 as published by
@@ -15,6 +16,7 @@
 #include <time.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <limits.h>
@@ -34,7 +36,7 @@
 #include <net/ethernet.h>
 
 #include "odhcp6c.h"
-#ifdef LIBUBOX
+#ifdef USE_LIBUBOX
 #include <libubox/md5.h>
 #else
 #include "md5.h"
@@ -561,8 +563,8 @@ int dhcpv6_request(enum dhcpv6_msg type)
        if (timeout == 0)
                return -1;
 
-       syslog(LOG_NOTICE, "Starting %s transaction (timeout %llus, max rc %d)",
-                       retx->name, (unsigned long long)timeout, retx->max_rc);
+       syslog(LOG_NOTICE, "Starting %s transaction (timeout %"PRIu64"s, max rc %d)",
+                       retx->name, timeout, retx->max_rc);
 
        uint64_t start = odhcp6c_get_milli_time(), round_start = start, elapsed;
 
@@ -603,8 +605,8 @@ int dhcpv6_request(enum dhcpv6_msg type)
                case DHCPV6_MSG_UNKNOWN:
                        break;
                default:
-                       syslog(LOG_NOTICE, "Send %s message (elapsed %llums, rc %d)",
-                                       retx->name, (unsigned long long)elapsed, rc);
+                       syslog(LOG_NOTICE, "Send %s message (elapsed %"PRIu64"ms, rc %d)",
+                                       retx->name, elapsed, rc);
                        // Fall through
                case DHCPV6_MSG_SOLICIT:
                case DHCPV6_MSG_INFO_REQ:
@@ -668,8 +670,8 @@ int dhcpv6_request(enum dhcpv6_msg type)
 
                        round_start = odhcp6c_get_milli_time();
                        elapsed = round_start - start;
-                       syslog(LOG_NOTICE, "Got a valid reply after "
-                                       "%llums", (unsigned long long)elapsed);
+                       syslog(LOG_NOTICE, "Got a valid reply after %"PRIu64"ms",
+                                       elapsed);
 
                        if (retx->handler_reply)
                                len = retx->handler_reply(type, rc, opt, opt_end, &addr);
@@ -681,7 +683,7 @@ int dhcpv6_request(enum dhcpv6_msg type)
                // Allow
                if (retx->handler_finish)
                        len = retx->handler_finish();
-       } while (len < 0 && ((timeout == UINT32_MAX) || (elapsed / 1000 < timeout)) && 
+       } while (len < 0 && ((timeout == UINT32_MAX) || (elapsed / 1000 < timeout)) &&
                        (!retx->max_rc || rc < retx->max_rc));
        return len;
 }
@@ -1142,7 +1144,7 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc,
 
        if (orig != DHCPV6_MSG_INFO_REQ) {
                // Update refresh timers if no fatal status code was received
-               if ((ret > 0) && dhcpv6_calc_refresh_timers()) {
+               if ((ret > 0) && (ret = dhcpv6_calc_refresh_timers())) {
                        switch (orig) {
                        case DHCPV6_MSG_RENEW:
                                // Send further renews if T1 is not set
@@ -1331,8 +1333,6 @@ static int dhcpv6_calc_refresh_timers(void)
                t1 = l_t1;
                t2 = l_t2;
                t3 = l_t3;
-       } else {
-               t1 = 600;
        }
 
        return (int)(ia_pd_entries + ia_na_entries);