From 5d0cfb6f7fa84743c4763801d7bfc0f0d29cdb1c Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 30 Jan 2016 14:46:55 +0000 Subject: [PATCH] captivectrl: Support unlimited leases When the expiry time equals zero, the lease will have no time constraints. The IP address will also be removed as it might probably change. Signed-off-by: Michael Tremer --- src/misc-progs/captivectrl.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/misc-progs/captivectrl.c b/src/misc-progs/captivectrl.c index 97d5c19d63..57871ffe4d 100644 --- a/src/misc-progs/captivectrl.c +++ b/src/misc-progs/captivectrl.c @@ -143,24 +143,29 @@ static int add_client_rules(const client_t* clients) { char match[STRING_SIZE]; while (clients) { - time_t expires = clients->time_start + clients->expires; - - char* time_start = format_time(&clients->time_start); - char* time_end = format_time(&expires); - size_t len = 0; - if (*clients->ipaddr) { + if (*clients->ipaddr && clients->expires > 0) { len += snprintf(match + len, sizeof(match) - len, "-s %s", clients->ipaddr); } len += snprintf(match + len, sizeof(match) - len, - " -m mac --mac-source %s -m time --datestart %s --datestop %s", - clients->etheraddr, time_start, time_end); + " -m mac --mac-source %s", clients->etheraddr); + + if (clients->expires > 0) { + time_t expires = clients->time_start + clients->expires; + + char* time_start = format_time(&clients->time_start); + char* time_end = format_time(&expires); - free(time_start); - free(time_end); + len += snprintf(match + len, sizeof(match) - len, + "-m time --datestart %s --datestop %s", + time_start, time_end); + + free(time_start); + free(time_end); + } // filter snprintf(command, sizeof(command), IPTABLES " -A CAPTIVE_PORTAL_CLIENTS" -- 2.39.5