odhcpd: Display infinite valid lifetime as -1
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 21 Nov 2016 13:42:16 +0000 (14:42 +0100)
committerFelix Fietkau <nbd@nbd.name>
Thu, 1 Dec 2016 10:27:15 +0000 (11:27 +0100)
Display infinite valid lifetime as -1 both in ubus
and statefile

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/dhcpv6-ia.c
src/ubus.c

index 852af97914a4067fe792948a7c6f2b838fc23364..8db53b98b21b729381805e4a392d2455b420dd27 100644 (file)
@@ -243,12 +243,12 @@ void dhcpv6_write_statefile(void)
                                        odhcpd_hexlify(duidbuf, c->clid_data, c->clid_len);
 
                                        // iface DUID iaid hostname lifetime assigned length [addrs...]
-                                       int l = snprintf(leasebuf, sizeof(leasebuf), "# %s %s %x %s %u %x %u ",
+                                       int l = snprintf(leasebuf, sizeof(leasebuf), "# %s %s %x %s %ld %x %u ",
                                                        iface->ifname, duidbuf, ntohl(c->iaid),
                                                        (c->hostname ? c->hostname : "-"),
-                                                       (unsigned)(c->valid_until > now ?
-                                                                       (c->valid_until - now + wall_time) :
-                                                                       (INFINITE_VALID(c->valid_until) ? INT32_MAX: 0)),
+                                                       (c->valid_until > now ?
+                                                               (c->valid_until - now + wall_time) :
+                                                               (INFINITE_VALID(c->valid_until) ? -1 : 0)),
                                                        c->assigned, (unsigned)c->length);
 
                                        struct in6_addr addr;
@@ -306,12 +306,12 @@ void dhcpv6_write_statefile(void)
                                        odhcpd_hexlify(duidbuf, c->hwaddr, sizeof(c->hwaddr));
 
                                        // iface DUID iaid hostname lifetime assigned length [addrs...]
-                                       int l = snprintf(leasebuf, sizeof(leasebuf), "# %s %s ipv4 %s %u %x 32 ",
+                                       int l = snprintf(leasebuf, sizeof(leasebuf), "# %s %s ipv4 %s %ld %x 32 ",
                                                        iface->ifname, duidbuf,
                                                        (c->hostname ? c->hostname : "-"),
-                                                       (unsigned)(c->valid_until > now ?
-                                                                       (c->valid_until - now + wall_time) :
-                                                                       (INFINITE_VALID(c->valid_until) ? INT32_MAX: 0)),
+                                                       (c->valid_until > now ?
+                                                               (c->valid_until - now + wall_time) :
+                                                               (INFINITE_VALID(c->valid_until) ? -1 : 0)),
                                                        c->addr);
 
                                        struct in_addr addr = {htonl(c->addr)};
index 425abe4e377ce16ebf18d044d1abfd7b2629f423..e9e2de386e53e170c076b4b413a34c03b2c7ef62 100644 (file)
@@ -51,7 +51,7 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _unused struct ubus_ob
                        blobmsg_add_string_buffer(&b);
 
                        blobmsg_add_u32(&b, "valid", INFINITE_VALID(lease->valid_until) ?
-                                               INT32_MAX : (uint32_t)(lease->valid_until - now));
+                                               (uint32_t)-1 : (uint32_t)(lease->valid_until - now));
 
                        blobmsg_close_table(&b, l);
                }
@@ -117,7 +117,7 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct
                        blobmsg_close_table(&b, m);
 
                        blobmsg_add_u32(&b, "valid", INFINITE_VALID(lease->valid_until) ?
-                                               INT32_MAX : (uint32_t)(lease->valid_until - now));
+                                               (uint32_t)-1 : (uint32_t)(lease->valid_until - now));
 
                        blobmsg_close_table(&b, l);
                }