network: add timeout for client connections

Somtimes client connetions will not close therfore add a timeout. Add a
new timer that checks every 5s if we did not receive anything from a
client for (default) 60s. Can be configured via client_timeout.

Code is based on the work of ptpt52.

Signed-off-by: Nick Hainke <vincent@systemli.org>
This commit is contained in:
Nick Hainke 2022-07-20 13:30:00 +02:00 committed by Chen Minqiang
parent e596ff1317
commit 4fa5bc2e37
8 changed files with 50 additions and 0 deletions

View file

@ -79,6 +79,7 @@ struct time_config_s uci_get_time_config() {
.update_tcp_con = 10,
.update_chan_util = 5,
.update_beacon_reports = 20,
.client_timeout = 60,
};
dawnlog_debug_func("Entering...");
@ -105,6 +106,8 @@ struct time_config_s uci_get_time_config() {
DAWN_SET_CONFIG_TIME(ret, s, update_chan_util);
//CONFIG-T: update_beacon_reports|Timer to ask all connected clients for a new BEACON REPORT|[20]
DAWN_SET_CONFIG_TIME(ret, s, update_beacon_reports);
//CONFIG-T: client_timeout|Timespan to check if a client timed out|[60]
DAWN_SET_CONFIG_TIME(ret, s, client_timeout);
return ret;
}
}

View file

@ -656,6 +656,7 @@ enum {
UCI_UPDATE_TCP_CON,
UCI_UPDATE_CHAN_UTIL,
UCI_UPDATE_BEACON_REPORTS,
UCI_CLIENT_TIMEOUT,
__UCI_TIMES_MAX,
};
@ -713,6 +714,7 @@ static const struct blobmsg_policy uci_times_policy[__UCI_TIMES_MAX] = {
[UCI_UPDATE_TCP_CON] = {.name = "update_tcp_con", .type = BLOBMSG_TYPE_INT32},
[UCI_UPDATE_CHAN_UTIL] = {.name = "update_chan_util", .type = BLOBMSG_TYPE_INT32},
[UCI_UPDATE_BEACON_REPORTS] = {.name = "update_beacon_reports", .type = BLOBMSG_TYPE_INT32},
[UCI_CLIENT_TIMEOUT] = {.name = "client_timeout", .type = BLOBMSG_TYPE_INT32},
};
static void set_uci_item(char* m, struct blob_attr* a)
@ -895,6 +897,8 @@ static int handle_uci_config(struct blob_attr* msg) {
set_uci_item("dawn.@times[0].update_beacon_reports=%d", tb_times[UCI_UPDATE_BEACON_REPORTS]);
set_uci_item("dawn.@times[0].client_timeout=%d", tb_times[UCI_CLIENT_TIMEOUT]);
uci_reset();
dawn_metric = uci_get_dawn_metric();
timeout_config = uci_get_time_config();

View file

@ -23,6 +23,8 @@ void update_clients(struct uloop_timeout *t);
void update_tcp_connections(struct uloop_timeout *t);
void check_client_timeouts(struct uloop_timeout *t);
void update_channel_utilization(struct uloop_timeout *t);
void run_server_update(struct uloop_timeout *t);
@ -38,6 +40,9 @@ struct uloop_timeout hostapd_timer = {
struct uloop_timeout tcp_con_timer = {
.cb = update_tcp_connections
};
struct uloop_timeout client_timeout_timer = {
.cb = check_client_timeouts
};
struct uloop_timeout channel_utilization_timer = {
.cb = update_channel_utilization
};
@ -1148,11 +1153,20 @@ void update_tcp_connections(struct uloop_timeout *t) {
uloop_timeout_set(&tcp_con_timer, timeout_config.update_tcp_con * 1000);
}
void check_client_timeouts(struct uloop_timeout *t) {
dawnlog_debug_func("Entering...");
check_client_timeout(timeout_config.client_timeout);
uloop_timeout_set(&client_timeout_timer, CHECK_CLIENT_TIMEOUT * 1000);
}
void start_tcp_con_update() {
dawnlog_debug_func("Entering...");
// update connections
uloop_timeout_add(&tcp_con_timer); // callback = update_tcp_connections
uloop_timeout_add(&client_timeout_timer); // callback = client_timeout
}
void update_hostapd_sockets(struct uloop_timeout *t) {
@ -1888,6 +1902,7 @@ int uci_send_via_network()
blobmsg_add_u32(&b, "update_tcp_con", timeout_config.update_tcp_con);
blobmsg_add_u32(&b, "update_chan_util", timeout_config.update_chan_util);
blobmsg_add_u32(&b, "update_beacon_reports", timeout_config.update_beacon_reports);
blobmsg_add_u32(&b, "client_timeout", timeout_config.client_timeout);
blobmsg_close_table(&b, times);
send_blob_attr_via_network(b.head, "uci");