diff mbox series

Don't let cac_time_left_seconds overflow

Message ID 20220308102218.765098-1-nico.escande@gmail.com
State Accepted
Headers show
Series Don't let cac_time_left_seconds overflow | expand

Commit Message

Nicolas Escande March 8, 2022, 10:22 a.m. UTC
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 | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Jouni Malinen March 12, 2022, 5:05 p.m. UTC | #1
On Tue, Mar 08, 2022 at 11:22:18AM +0100, Nicolas Escande wrote:
> 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.

Thanks, applied.
diff mbox series

Patch

diff --git a/src/ap/ctrl_iface_ap.c b/src/ap/ctrl_iface_ap.c
index 1d8fb8246..9e9eadd2f 100644
--- a/src/ap/ctrl_iface_ap.c
+++ b/src/ap/ctrl_iface_ap.c
@@ -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;