X-Git-Url: https://git.decadent.org.uk/gitweb/?p=odhcp6c.git;a=blobdiff_plain;f=src%2Fdhcpv6.c;h=215f68c86e3c92677959e5120b46777908d4c95c;hp=f18a3e946f6d8cbe3b73cb2cba0bac841f8cad01;hb=58f5bf8da1f5dca44abc31f454ce651a6927cc85;hpb=db2915f095db17cb10bf67d5b3bf67f891d45625 diff --git a/src/dhcpv6.c b/src/dhcpv6.c index f18a3e9..215f68c 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -429,19 +429,19 @@ static void dhcpv6_send(enum dhcpv6_msg type, uint8_t trid[3], uint32_t ecs) // Disable IAs if not used if (type != DHCPV6_MSG_SOLICIT) { - iov[7].iov_len = 0; + iov[9].iov_len = 0; if (ia_na_len == 0) - iov[9].iov_len = 0; + iov[11].iov_len = 0; } if (na_mode == IA_MODE_NONE) - iov[9].iov_len = 0; + iov[11].iov_len = 0; if (!(client_options & DHCPV6_ACCEPT_RECONFIGURE)) - iov[7].iov_len = 0; + iov[9].iov_len = 0; if (!(client_options & DHCPV6_CLIENT_FQDN)) - iov[8].iov_len = 0; + iov[10].iov_len = 0; struct sockaddr_in6 srv = {AF_INET6, htons(DHCPV6_SERVER_PORT), 0, ALL_DHCPV6_RELAYS, ifindex}; @@ -474,9 +474,9 @@ int dhcpv6_request(enum dhcpv6_msg type) if (type == DHCPV6_MSG_UNKNOWN) timeout = t1; else if (type == DHCPV6_MSG_RENEW) - timeout = (t2 > t1) ? t2 - t1 : 0; + timeout = (t2 > t1) ? t2 - t1 : ((t1 == UINT32_MAX) ? UINT32_MAX : 0); else if (type == DHCPV6_MSG_REBIND) - timeout = (t3 > t2) ? t3 - t2 : 0; + timeout = (t3 > t2) ? t3 - t2 : ((t2 == UINT32_MAX) ? UINT32_MAX : 0); if (timeout == 0) return -1; @@ -514,8 +514,8 @@ int dhcpv6_request(enum dhcpv6_msg type) uint64_t round_end = round_start + rto; elapsed = round_start - start; - // Don't wait too long - if (round_end - start > timeout * 1000) + // Don't wait too long if timeout differs from infinite + if ((timeout != UINT32_MAX) && (round_end - start > timeout * 1000)) round_end = timeout * 1000 + start; // Built and send package @@ -542,9 +542,9 @@ int dhcpv6_request(enum dhcpv6_msg type) // Set timeout for receiving uint64_t t = round_end - round_start; - struct timeval timeout = {t / 1000, (t % 1000) * 1000}; + struct timeval tv = {t / 1000, (t % 1000) * 1000}; setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, - &timeout, sizeof(timeout)); + &tv, sizeof(tv)); // Receive cycle len = recvmsg(sock, &msg, 0); @@ -589,8 +589,8 @@ int dhcpv6_request(enum dhcpv6_msg type) // Allow if (retx->handler_finish) len = retx->handler_finish(); - } while (len < 0 && ((elapsed / 1000 < timeout) && (!retx->max_rc || rc < retx->max_rc))); - + } while (len < 0 && ((timeout == UINT32_MAX) || (elapsed / 1000 < timeout)) && + (!retx->max_rc || rc < retx->max_rc)); return len; } @@ -861,9 +861,14 @@ static int dhcpv6_handle_reply(enum dhcpv6_msg orig, _unused const int rc, uint32_t elapsed = (last_update > 0) ? now - last_update : 0; last_update = now; - t1 -= elapsed; - t2 -= elapsed; - t3 -= elapsed; + if (t1 != UINT32_MAX) + t1 -= elapsed; + + if (t2 != UINT32_MAX) + t2 -= elapsed; + + if (t3 != UINT32_MAX) + t3 -= elapsed; if (t1 < 0) t1 = 0;