summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2016-11-17 16:11:58 +0100
committerJohn Crispin <john@phrozen.org>2016-11-21 11:36:07 +0100
commit4fc68bde9fd7b630a2b51fe189e10e26714abc4d (patch)
tree8ba568d91898b54e1b4af11040c419c4a11bd7fe /src
parent44ca70ae6f0fb649cef47d9160ec1ee13e7844f1 (diff)
ubus: Fix displayed valid paramater for both DHCPv4 and DHCPv6 lease
Fix ubus valid parameter being displayed as a negative number; also display infinite lifetime as INT32_MAX Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/ubus.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/ubus.c b/src/ubus.c
index 14d0a5f..425abe4 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -34,7 +34,7 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _unused struct ubus_ob
struct dhcpv4_assignment *lease;
list_for_each_entry(lease, &iface->dhcpv4_assignments, head) {
- if (lease->valid_until < now)
+ if (!INFINITE_VALID(lease->valid_until) && lease->valid_until < now)
continue;
void *l = blobmsg_open_table(&b, NULL);
@@ -50,7 +50,8 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _unused struct ubus_ob
inet_ntop(AF_INET, &addr, buf, INET_ADDRSTRLEN);
blobmsg_add_string_buffer(&b);
- blobmsg_add_u32(&b, "valid", now - lease->valid_until);
+ blobmsg_add_u32(&b, "valid", INFINITE_VALID(lease->valid_until) ?
+ INT32_MAX : (uint32_t)(lease->valid_until - now));
blobmsg_close_table(&b, l);
}
@@ -83,7 +84,7 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct
struct dhcpv6_assignment *lease;
list_for_each_entry(lease, &iface->ia_assignments, head) {
- if (lease->valid_until < now)
+ if (!INFINITE_VALID(lease->valid_until) && lease->valid_until < now)
continue;
void *l = blobmsg_open_table(&b, NULL);
@@ -115,7 +116,8 @@ static int handle_dhcpv6_leases(_unused struct ubus_context *ctx, _unused struct
}
blobmsg_close_table(&b, m);
- blobmsg_add_u32(&b, "valid", now - lease->valid_until);
+ blobmsg_add_u32(&b, "valid", INFINITE_VALID(lease->valid_until) ?
+ INT32_MAX : (uint32_t)(lease->valid_until - now));
blobmsg_close_table(&b, l);
}