Re: [LEDE-DEV] [PATCH odhcpd 3/5] ubus: Fix displayed valid paramater for both DHCPv4 and DHCPv6 lease

2016-11-17 Thread Hans Dedecker
On Thu, Nov 17, 2016 at 11:15 PM, Karl Palsson  wrote:
>
> Hans Dedecker  wrote:
>> Fix ubus valid parameter being displayed as a negative number;
>> also display infinite lifetime as INT32_MAX
>
> Really? Why not 0 or -1? You dont' specify an infinite lease as
> INT32_MAX, why would I want to receive an infinite lease as some
> magic number that only programmer nerds would even recognize?
Fine most important for me was that the displayed value was not
decreasing; I prefer to display -1 then as 0 indicates a lease is
expired
>
> Sincerely,
> Karl Palsson

___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


Re: [LEDE-DEV] [PATCH odhcpd 3/5] ubus: Fix displayed valid paramater for both DHCPv4 and DHCPv6 lease

2016-11-17 Thread Karl Palsson

Hans Dedecker  wrote:
> Fix ubus valid parameter being displayed as a negative number;
> also display infinite lifetime as INT32_MAX

Really? Why not 0 or -1? You dont' specify an infinite lease as
INT32_MAX, why would I want to receive an infinite lease as some
magic number that only programmer nerds would even recognize?

Sincerely,
Karl Palsson

signature.asc
Description: OpenPGP Digital Signature
___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH odhcpd 3/5] ubus: Fix displayed valid paramater for both DHCPv4 and DHCPv6 lease

2016-11-17 Thread Hans Dedecker
Fix ubus valid parameter being displayed as a negative number;
also display infinite lifetime as INT32_MAX

Signed-off-by: Hans Dedecker 
---
 src/ubus.c | 10 ++
 1 file 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, >dhcpv4_assignments, head) {
-   if (lease->valid_until < now)
+   if (!INFINITE_VALID(lease->valid_until) && 
lease->valid_until < now)
continue;
 
void *l = blobmsg_open_table(, NULL);
@@ -50,7 +50,8 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, 
_unused struct ubus_ob
inet_ntop(AF_INET, , buf, INET_ADDRSTRLEN);
blobmsg_add_string_buffer();
 
-   blobmsg_add_u32(, "valid", now - lease->valid_until);
+   blobmsg_add_u32(, "valid", 
INFINITE_VALID(lease->valid_until) ?
+   INT32_MAX : 
(uint32_t)(lease->valid_until - now));
 
blobmsg_close_table(, 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, >ia_assignments, head) {
-   if (lease->valid_until < now)
+   if (!INFINITE_VALID(lease->valid_until) && 
lease->valid_until < now)
continue;
 
void *l = blobmsg_open_table(, NULL);
@@ -115,7 +116,8 @@ static int handle_dhcpv6_leases(_unused struct ubus_context 
*ctx, _unused struct
}
blobmsg_close_table(, m);
 
-   blobmsg_add_u32(, "valid", now - lease->valid_until);
+   blobmsg_add_u32(, "valid", 
INFINITE_VALID(lease->valid_until) ?
+   INT32_MAX : 
(uint32_t)(lease->valid_until - now));
 
blobmsg_close_table(, l);
}
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev