X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fdhcpv6-ia.c;h=09022a43a252cfa461c2de4e1b0f6fe2a49b3b22;hp=84f368ee17e0bffd0bf7ae6b63f5ccb9f17b8be9;hb=3d9f4067d56660a2c75ab2ce9b801ae1a4ff4cde;hpb=3317c861984ec22155c04dd77e77abb2ed8bb252 diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 84f368e..09022a4 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -88,8 +88,7 @@ int setup_dhcpv6_ia_interface(struct interface *iface, bool enable) return -1; } - if (lease->dhcpv4_leasetime > 0) - a->leasetime = lease->dhcpv4_leasetime; + a->leasetime = lease->dhcpv4_leasetime; a->clid_len = duid_len; a->length = 128; @@ -243,8 +242,12 @@ void dhcpv6_write_statefile(void) int fd = open(config.dhcp_statefile, O_CREAT | O_WRONLY | O_CLOEXEC, 0644); if (fd < 0) return; - - lockf(fd, F_LOCK, 0); + int ret; + ret = lockf(fd, F_LOCK, 0); + if (ret < 0) { + close(fd); + return; + } if (ftruncate(fd, 0) < 0) {} FILE *fp = fdopen(fd, "w"); @@ -294,12 +297,12 @@ void dhcpv6_write_statefile(void) continue; addr.s6_addr32[3] = htonl(c->assigned); - } - else { + } else { if (!valid_prefix_length(c, addrs[i].prefix)) continue; addr.s6_addr32[1] |= htonl(c->assigned); + addr.s6_addr32[2] = addr.s6_addr32[3] = 0; } inet_ntop(AF_INET6, &addr, ipbuf, sizeof(ipbuf) - 1); @@ -396,6 +399,7 @@ static void apply_lease(struct interface *iface, struct dhcpv6_assignment *a, bo for (size_t i = 0; i < addrlen; ++i) { struct in6_addr prefix = addrs[i].addr; prefix.s6_addr32[1] |= htonl(a->assigned); + prefix.s6_addr32[2] = prefix.s6_addr32[3] = 0; odhcpd_setup_route(&prefix, (a->managed_size) ? addrs[i].prefix : a->length, iface, &a->peer.sin6_addr, 1024, add); } @@ -719,16 +723,11 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status, } else { if (a) { uint32_t leasetime; - if (a->leasetime > 0) + if (a->leasetime) leasetime = a->leasetime; else leasetime = iface->dhcpv4_leasetime; - if (leasetime == 0) - leasetime = 3600; - else if (leasetime < 60) - leasetime = 60; - uint32_t pref = leasetime; uint32_t valid = leasetime; @@ -759,6 +758,7 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status, .addr = addrs[i].addr }; p.addr.s6_addr32[1] |= htonl(a->assigned); + p.addr.s6_addr32[2] = p.addr.s6_addr32[3] = 0; size_t entrlen = sizeof(p) - 4; @@ -835,6 +835,7 @@ static size_t append_reply(uint8_t *buf, size_t buflen, uint16_t status, struct in6_addr addr = addrs[i].addr; if (ia->type == htons(DHCPV6_OPT_IA_PD)) { addr.s6_addr32[1] |= htonl(a->assigned); + addr.s6_addr32[2] = addr.s6_addr32[3] = 0; if (!memcmp(&p->addr, &addr, sizeof(addr)) && p->prefix == ((a->managed) ? addrs[i].prefix : a->length)) @@ -967,6 +968,7 @@ static void dhcpv6_log(uint8_t msgtype, struct interface *iface, time_t now, continue; addr.s6_addr32[1] |= htonl(a->assigned); + addr.s6_addr32[2] = addr.s6_addr32[3] = 0; } inet_ntop(AF_INET6, &addr, addrbuf, sizeof(addrbuf));