]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
DFS: Don't let cac_time_left_seconds overflow
authorNicolas Escande <nico.escande@gmail.com>
Tue, 8 Mar 2022 10:22:18 +0000 (11:22 +0100)
committerJouni Malinen <j@w1.fi>
Sat, 12 Mar 2022 08:39:43 +0000 (10:39 +0200)
There can be some discrepancy between the theorical dfs cac end (as
computed with the cac duration and cac start) and the actual cac end as
reported by the driver. During that window, the value of remaining time
outputed by the status command on the socket control interface will
display an overflowed, invalid value.
To mitigate this lets compute the remaining time as signed and display
it only when positive, otherwise defaulting it to 0.

Status command shows something like that when polling every seconds:

state=DFS
cac_time_seconds=60
cac_time_left_seconds=1
...
state=DFS
cac_time_seconds=60
cac_time_left_seconds=0
...
state=DFS
cac_time_seconds=60
cac_time_left_seconds=4294967294
...
state=DFS
cac_time_seconds=60
cac_time_left_seconds=4294967293
...
state=DFS
cac_time_seconds=60
cac_time_left_seconds=4294967292
...
state=ENABLED
cac_time_seconds=60
cac_time_left_seconds=N/A

Signed-off-by: Nicolas Escande <nico.escande@gmail.com>
src/ap/ctrl_iface_ap.c

index 1d8fb8246581c25ca32daf394d2a955ff756a01f..9e9eadd2f79ae5253a37ec8c777817c7d2521e6b 100644 (file)
@@ -724,15 +724,15 @@ int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
        } else {
                /* CAC started and CAC time set - calculate remaining time */
                struct os_reltime now;
-               unsigned int left_time;
+               long left_time;
 
                os_reltime_age(&iface->dfs_cac_start, &now);
-               left_time = iface->dfs_cac_ms / 1000 - now.sec;
+               left_time = (long) iface->dfs_cac_ms / 1000 - now.sec;
                ret = os_snprintf(buf + len, buflen - len,
                                  "cac_time_seconds=%u\n"
-                                 "cac_time_left_seconds=%u\n",
+                                 "cac_time_left_seconds=%lu\n",
                                  iface->dfs_cac_ms / 1000,
-                                 left_time);
+                                 left_time > 0 ? left_time : 0);
        }
        if (os_snprintf_error(buflen - len, ret))
                return len;