diff --git a/src/client_list.c b/src/client_list.c index ca810610..136b0edd 100644 --- a/src/client_list.c +++ b/src/client_list.c @@ -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; @@ -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; @@ -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); } diff --git a/src/firewall.c b/src/firewall.c index 27b550a7..c9f0ca8a 100644 --- a/src/firewall.c +++ b/src/firewall.c @@ -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"); @@ -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)); diff --git a/src/ws_thread.c b/src/ws_thread.c index 8944a96b..bd1c441c 100644 --- a/src/ws_thread.c +++ b/src/ws_thread.c @@ -81,6 +81,7 @@ 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) { @@ -88,6 +89,7 @@ handle_auth_response(json_object *j_auth) } 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); @@ -95,7 +97,8 @@ handle_auth_response(json_object *j_auth) 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); }