Skip to content

Commit

Permalink
fix: no auth clients reports
Browse files Browse the repository at this point in the history
Signed-off-by: Dengfeng Liu <[email protected]>
  • Loading branch information
liudf0716 committed Sep 2, 2024
1 parent 39008dd commit c492466
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/client_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ client_list_insert_client(t_client * client)
{
t_client *prev_head;

pthread_mutex_lock(&client_id_mutex);
client->id = client_id++;
pthread_mutex_unlock(&client_id_mutex);

prev_head = firstclient;
client->next = prev_head;
firstclient = client;
Expand Down Expand Up @@ -268,6 +265,7 @@ client_dup(const t_client * src)
new->first_login = src->first_login;
new->is_online = src->is_online;
new->wired = src->wired;
new->gw_setting = src->gw_setting;
new->next = NULL;

return new;
Expand Down Expand Up @@ -451,6 +449,8 @@ client_free_node(t_client * client)
if(client->ip) free(client->ip);
if(client->token) free(client->token);
if (client->name) free(client->name);
client->gw_setting = NULL;
client->next = NULL;
free(client);
}

Expand Down
8 changes: 6 additions & 2 deletions src/firewall.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ get_gw_clients_counter(t_gateway_setting *gw_setting, t_client *worklist)
while (gw_setting) {
json_object *gw_obj = json_object_new_object();
json_object_object_add(gw_obj, "gw_id", json_object_new_string(gw_setting->gw_id));
json_object_object_add(gw_obj, "gw_channel", json_object_new_string(gw_setting->gw_channel));
json_object *client_array = json_object_new_array();
if (!client_array) {
debug(LOG_ERR, "Could not create json array");
Expand All @@ -539,8 +540,11 @@ get_gw_clients_counter(t_gateway_setting *gw_setting, t_client *worklist)
t_client *p1 = NULL, *p2 = NULL;
for (p1 = p2 = worklist; NULL != p1; p1 = p2) {
p2 = p1->next;
if (p1->gw_setting != gw_setting)
continue;
if (p1->gw_setting && p1->gw_setting != gw_setting) {
debug(LOG_INFO, "client %s client gw_setting %lu not in gateway %s",
p1->ip, p1->gw_setting, gw_setting->gw_id);
continue;
}

json_object *clt = json_object_new_object();
json_object_object_add(clt, "id", json_object_new_int(p1->id));
Expand Down
5 changes: 4 additions & 1 deletion src/ws_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,24 @@ handle_auth_response(json_object *j_auth)
debug(LOG_ERR, "auth: gateway %s not found\n", gw_id_str);
return;
}
LOCK_CLIENT_LIST();
t_client *client = client_list_add(client_ip_str, client_mac_str, token_str, gw_setting);
fw_allow(client, FW_MARK_KNOWN);
if (client_name != NULL) {
client->name = strdup(json_object_get_string(client_name));
}
client->first_login = time(NULL);
client->is_online = 1;
UNLOCK_CLIENT_LIST();
{
LOCK_OFFLINE_CLIENT_LIST();
t_offline_client *o_client = offline_client_list_find_by_mac(client->mac);
if(o_client)
offline_client_list_delete(o_client);
UNLOCK_OFFLINE_CLIENT_LIST();
}
debug(LOG_DEBUG, "fw_allow client: token %s, client_ip %s, client_mac %s\n", token_str, client_ip_str, client_mac_str);
debug(LOG_DEBUG, "fw_allow client: token %s, client_ip %s, client_mac %s gw_setting is %lu\n",
token_str, client_ip_str, client_mac_str, client->gw_setting);
} else {
debug(LOG_DEBUG, "client already exists: token %s, client_ip %s, client_mac %s\n", token_str, client_ip_str, client_mac_str);
}
Expand Down

0 comments on commit c492466

Please sign in to comment.