mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
memory: Tighten up some memory handling to help spot errors
Set pointers to NULL after free() to help force out memory handling errors. Add some extra memory / resource tracking to try and chase out latent bugs / leaks Fixed a couple of memory traces that were misreporting. Signed-off-by: Ian Clowes <clowes_ian@hotmail.com>
This commit is contained in:
parent
4df0c986f1
commit
6bf9b6df9a
10 changed files with 202 additions and 75 deletions
|
@ -98,16 +98,19 @@ char *gcrypt_decrypt_msg(char *msg, size_t msg_length) {
|
||||||
gcry_strsource(gcry_error_handle),
|
gcry_strsource(gcry_error_handle),
|
||||||
gcry_strerror(gcry_error_handle));
|
gcry_strerror(gcry_error_handle));
|
||||||
dawn_free(out_buffer);
|
dawn_free(out_buffer);
|
||||||
|
out_buffer = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *out = dawn_malloc(strlen(out_buffer) + 1);
|
char *out = dawn_malloc(strlen(out_buffer) + 1);
|
||||||
if (!out){
|
if (!out){
|
||||||
dawn_free(out_buffer);
|
dawn_free(out_buffer);
|
||||||
|
out_buffer = NULL;
|
||||||
dawnlog_error("gcry_cipher_decrypt error: not enough memory\n");
|
dawnlog_error("gcry_cipher_decrypt error: not enough memory\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcpy(out, out_buffer);
|
strcpy(out, out_buffer);
|
||||||
dawn_free(out_buffer);
|
dawn_free(out_buffer);
|
||||||
|
out_buffer = NULL;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ int parse_to_hostapd_notify(struct blob_attr* msg, hostapd_notify_entry* notify_
|
||||||
*/
|
*/
|
||||||
int handle_network_msg(char* msg);
|
int handle_network_msg(char* msg);
|
||||||
|
|
||||||
|
|
||||||
int handle_deauth_req(struct blob_attr* msg);
|
int handle_deauth_req(struct blob_attr* msg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -112,14 +112,17 @@ void *receive_msg_enc(void *args) {
|
||||||
char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length);
|
char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length);
|
||||||
if (!dec){
|
if (!dec){
|
||||||
dawn_free(base64_dec_str);
|
dawn_free(base64_dec_str);
|
||||||
|
base64_dec_str = NULL;
|
||||||
dawnlog_error("Received network error: not enough memory\n");
|
dawnlog_error("Received network error: not enough memory\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dawnlog_debug("Received network message: %s\n", dec);
|
dawnlog_debug("Received network message: %s\n", dec);
|
||||||
dawn_free(base64_dec_str);
|
dawn_free(base64_dec_str);
|
||||||
|
base64_dec_str = NULL;
|
||||||
handle_network_msg(dec);
|
handle_network_msg(dec);
|
||||||
dawn_free(dec);
|
dawn_free(dec);
|
||||||
|
dec = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +160,7 @@ int send_string_enc(char *msg) {
|
||||||
char *base64_enc_str = dawn_malloc(B64_ENCODE_LEN(length_enc));
|
char *base64_enc_str = dawn_malloc(B64_ENCODE_LEN(length_enc));
|
||||||
if (!base64_enc_str){
|
if (!base64_enc_str){
|
||||||
dawn_free(enc);
|
dawn_free(enc);
|
||||||
|
enc = NULL;
|
||||||
dawnlog_error("sendto() error: not enough memory\n");
|
dawnlog_error("sendto() error: not enough memory\n");
|
||||||
pthread_mutex_unlock(&send_mutex);
|
pthread_mutex_unlock(&send_mutex);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -174,7 +178,9 @@ int send_string_enc(char *msg) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
dawn_free(base64_enc_str);
|
dawn_free(base64_enc_str);
|
||||||
|
base64_enc_str = NULL;
|
||||||
dawn_free(enc);
|
dawn_free(enc);
|
||||||
|
enc = NULL;
|
||||||
pthread_mutex_unlock(&send_mutex);
|
pthread_mutex_unlock(&send_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,10 @@ static void client_close(struct ustream *s) {
|
||||||
|
|
||||||
dawnlog_warning("Connection closed\n");
|
dawnlog_warning("Connection closed\n");
|
||||||
ustream_free(s);
|
ustream_free(s);
|
||||||
|
dawn_unregmem(s);
|
||||||
close(cl->s.fd.fd);
|
close(cl->s.fd.fd);
|
||||||
dawn_free(cl);
|
dawn_free(cl);
|
||||||
|
cl = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void client_notify_write(struct ustream *s, int bytes) {
|
static void client_notify_write(struct ustream *s, int bytes) {
|
||||||
|
@ -76,9 +78,12 @@ static void client_to_server_close(struct ustream *s) {
|
||||||
|
|
||||||
dawnlog_warning("Connection to server closed\n");
|
dawnlog_warning("Connection to server closed\n");
|
||||||
ustream_free(s);
|
ustream_free(s);
|
||||||
|
dawn_unregmem(s);
|
||||||
|
|
||||||
close(con->fd.fd);
|
close(con->fd.fd);
|
||||||
list_del(&con->list);
|
list_del(&con->list);
|
||||||
dawn_free(con);
|
dawn_free(con);
|
||||||
|
con = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void client_to_server_state(struct ustream *s) {
|
static void client_to_server_state(struct ustream *s) {
|
||||||
|
@ -184,6 +189,7 @@ static void client_read_cb(struct ustream *s, int bytes) {
|
||||||
}
|
}
|
||||||
handle_network_msg(dec);
|
handle_network_msg(dec);
|
||||||
dawn_free(dec);
|
dawn_free(dec);
|
||||||
|
dec = NULL;
|
||||||
} else {
|
} else {
|
||||||
handle_network_msg(cl->str + HEADER_SIZE);//len of str is final_len
|
handle_network_msg(cl->str + HEADER_SIZE);//len of str is final_len
|
||||||
}
|
}
|
||||||
|
@ -223,6 +229,7 @@ static void server_cb(struct uloop_fd *fd, unsigned int events) {
|
||||||
cl->s.stream.notify_state = client_notify_state;
|
cl->s.stream.notify_state = client_notify_state;
|
||||||
cl->s.stream.notify_write = client_notify_write;
|
cl->s.stream.notify_write = client_notify_write;
|
||||||
ustream_fd_init(&cl->s, sfd);
|
ustream_fd_init(&cl->s, sfd);
|
||||||
|
dawn_regmem(&cl->s);
|
||||||
next_client = NULL; // TODO: Why is this here? To avoid resetting if above return happens?
|
next_client = NULL; // TODO: Why is this here? To avoid resetting if above return happens?
|
||||||
dawnlog_info("New connection\n");
|
dawnlog_info("New connection\n");
|
||||||
}
|
}
|
||||||
|
@ -266,6 +273,7 @@ static void connect_cb(struct uloop_fd *f, unsigned int events) {
|
||||||
close(entry->fd.fd);
|
close(entry->fd.fd);
|
||||||
list_del(&entry->list);
|
list_del(&entry->list);
|
||||||
dawn_free(entry);
|
dawn_free(entry);
|
||||||
|
entry = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,6 +284,8 @@ static void connect_cb(struct uloop_fd *f, unsigned int events) {
|
||||||
entry->stream.stream.notify_state = client_to_server_state;
|
entry->stream.stream.notify_state = client_to_server_state;
|
||||||
|
|
||||||
ustream_fd_init(&entry->stream, entry->fd.fd);
|
ustream_fd_init(&entry->stream, entry->fd.fd);
|
||||||
|
dawn_regmem(&entry->stream);
|
||||||
|
|
||||||
entry->connected = 1;
|
entry->connected = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +311,8 @@ int add_tcp_conncection(char *ipv4, int port) {
|
||||||
// Delete already existing entry
|
// Delete already existing entry
|
||||||
close(tmp->fd.fd);
|
close(tmp->fd.fd);
|
||||||
list_del(&tmp->list);
|
list_del(&tmp->list);
|
||||||
// TODO: Removed free(tmp) here - was it needed?
|
dawn_free(tmp);
|
||||||
|
tmp = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,6 +322,7 @@ int add_tcp_conncection(char *ipv4, int port) {
|
||||||
|
|
||||||
if (tcp_entry->fd.fd < 0) {
|
if (tcp_entry->fd.fd < 0) {
|
||||||
dawn_free(tcp_entry);
|
dawn_free(tcp_entry);
|
||||||
|
tcp_entry = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tcp_entry->fd.cb = connect_cb;
|
tcp_entry->fd.cb = connect_cb;
|
||||||
|
@ -342,6 +354,7 @@ void send_tcp(char *msg) {
|
||||||
char *final_str = dawn_malloc(final_len);
|
char *final_str = dawn_malloc(final_len);
|
||||||
if (!final_str){
|
if (!final_str){
|
||||||
dawn_free(enc);
|
dawn_free(enc);
|
||||||
|
enc = NULL;
|
||||||
dawnlog_error("Ustream error: not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
dawnlog_error("Ustream error: not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -358,9 +371,11 @@ void send_tcp(char *msg) {
|
||||||
//ERROR HANDLING!
|
//ERROR HANDLING!
|
||||||
if (con->stream.stream.write_error) {
|
if (con->stream.stream.write_error) {
|
||||||
ustream_free(&con->stream.stream);
|
ustream_free(&con->stream.stream);
|
||||||
|
dawn_unregmem(&con->stream.stream);
|
||||||
close(con->fd.fd);
|
close(con->fd.fd);
|
||||||
list_del(&con->list);
|
list_del(&con->list);
|
||||||
dawn_free(con);
|
dawn_free(con);
|
||||||
|
con = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,7 +383,9 @@ void send_tcp(char *msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dawn_free(final_str);
|
dawn_free(final_str);
|
||||||
|
final_str = NULL;
|
||||||
dawn_free(enc);
|
dawn_free(enc);
|
||||||
|
enc = NULL;
|
||||||
} else {
|
} else {
|
||||||
size_t msglen = strlen(msg) + 1;
|
size_t msglen = strlen(msg) + 1;
|
||||||
uint32_t final_len = msglen + sizeof(final_len);
|
uint32_t final_len = msglen + sizeof(final_len);
|
||||||
|
@ -391,14 +408,17 @@ void send_tcp(char *msg) {
|
||||||
dawnlog_error("Ustream error(" STR_QUOTE(__LINE__) ")!\n");
|
dawnlog_error("Ustream error(" STR_QUOTE(__LINE__) ")!\n");
|
||||||
if (con->stream.stream.write_error) {
|
if (con->stream.stream.write_error) {
|
||||||
ustream_free(&con->stream.stream);
|
ustream_free(&con->stream.stream);
|
||||||
|
dawn_unregmem(&con->stream.stream);
|
||||||
close(con->fd.fd);
|
close(con->fd.fd);
|
||||||
list_del(&con->list);
|
list_del(&con->list);
|
||||||
dawn_free(con);
|
dawn_free(con);
|
||||||
|
con = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dawn_free(final_str);
|
dawn_free(final_str);
|
||||||
|
final_str = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1049,6 +1049,7 @@ probe_entry* victim = *i;
|
||||||
|
|
||||||
*i = victim->next_probe;
|
*i = victim->next_probe;
|
||||||
dawn_free(victim);
|
dawn_free(victim);
|
||||||
|
victim = NULL;
|
||||||
|
|
||||||
probe_entry_last--;
|
probe_entry_last--;
|
||||||
}
|
}
|
||||||
|
@ -1327,6 +1328,7 @@ static __inline__ void ap_array_unlink_next(ap** i)
|
||||||
ap* entry = *i;
|
ap* entry = *i;
|
||||||
*i = entry->next_ap;
|
*i = entry->next_ap;
|
||||||
dawn_free(entry);
|
dawn_free(entry);
|
||||||
|
entry = NULL;
|
||||||
ap_entry_last--;
|
ap_entry_last--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1445,9 +1447,6 @@ client * ret = NULL;
|
||||||
void insert_macs_from_file() {
|
void insert_macs_from_file() {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
#ifdef DAWN_MEMORY_AUDITING
|
|
||||||
char *old_line = NULL;
|
|
||||||
#endif
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t read;
|
ssize_t read;
|
||||||
|
|
||||||
|
@ -1462,17 +1461,17 @@ void insert_macs_from_file() {
|
||||||
|
|
||||||
dawn_regmem(fp);
|
dawn_regmem(fp);
|
||||||
|
|
||||||
while ((read = getline(&line, &len, fp)) != -1) {
|
read = getline(&line, &len, fp);
|
||||||
#ifdef DAWN_MEMORY_AUDITING
|
#ifdef DAWN_MEMORY_AUDITING
|
||||||
if (old_line != line)
|
if (line)
|
||||||
{
|
dawn_regmem(line);
|
||||||
if (old_line != NULL)
|
|
||||||
dawn_unregmem(old_line);
|
|
||||||
old_line = line;
|
|
||||||
dawn_regmem(old_line);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
while (read != -1) {
|
||||||
|
|
||||||
|
dawnlog_debug("Retrieved line of length %zu :\n", read);
|
||||||
|
dawnlog_debug("%s", line);
|
||||||
|
|
||||||
// Need to scanf to an array of ints as there is no byte format specifier
|
// Need to scanf to an array of ints as there is no byte format specifier
|
||||||
int tmp_int_mac[ETH_ALEN];
|
int tmp_int_mac[ETH_ALEN];
|
||||||
sscanf(line, MACSTR, STR2MAC(tmp_int_mac));
|
sscanf(line, MACSTR, STR2MAC(tmp_int_mac));
|
||||||
|
@ -1491,8 +1490,19 @@ void insert_macs_from_file() {
|
||||||
|
|
||||||
insert_to_mac_array(new_mac, NULL);
|
insert_to_mac_array(new_mac, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
#ifdef DAWN_MEMORY_AUDITING
|
||||||
|
char* old_line = line;
|
||||||
|
#endif
|
||||||
|
read = getline(&line, &len, fp);
|
||||||
|
#ifdef DAWN_MEMORY_AUDITING
|
||||||
|
if (old_line != line)
|
||||||
|
{
|
||||||
|
dawn_unregmem(old_line);
|
||||||
|
dawn_regmem(line);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (dawnlog_showing(DAWNLOG_DEBUG))
|
if (dawnlog_showing(DAWNLOG_DEBUG))
|
||||||
{
|
{
|
||||||
|
@ -1505,7 +1515,11 @@ void insert_macs_from_file() {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
dawn_unregmem(fp);
|
dawn_unregmem(fp);
|
||||||
if (line)
|
if (line)
|
||||||
dawn_free(line);
|
{
|
||||||
|
free(line);
|
||||||
|
dawn_unregmem(line);
|
||||||
|
}
|
||||||
|
|
||||||
//exit(EXIT_SUCCESS);
|
//exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1604,6 +1618,7 @@ void denied_req_array_delete(auth_entry* entry) {
|
||||||
*i = entry->next_auth;
|
*i = entry->next_auth;
|
||||||
denied_req_last--;
|
denied_req_last--;
|
||||||
dawn_free(entry);
|
dawn_free(entry);
|
||||||
|
entry = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1639,6 +1654,7 @@ void mac_array_delete(struct mac_entry_s* entry) {
|
||||||
*i = entry->next_mac;
|
*i = entry->next_mac;
|
||||||
mac_set_last--;
|
mac_set_last--;
|
||||||
dawn_free(entry);
|
dawn_free(entry);
|
||||||
|
entry = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,6 @@ int get_bandwidth(const char *ifname, struct dawn_mac client_addr, float *rx_rat
|
||||||
int compare_essid_iwinfo(struct dawn_mac bssid_addr, struct dawn_mac bssid_addr_to_compare) {
|
int compare_essid_iwinfo(struct dawn_mac bssid_addr, struct dawn_mac bssid_addr_to_compare) {
|
||||||
const struct iwinfo_ops *iw;
|
const struct iwinfo_ops *iw;
|
||||||
|
|
||||||
char mac_buf[20];
|
|
||||||
char mac_buf_to_compare[20];
|
|
||||||
sprintf(mac_buf, MACSTR, MAC2STR(bssid_addr.u8));
|
|
||||||
sprintf(mac_buf_to_compare, MACSTR, MAC2STR(bssid_addr_to_compare.u8));
|
|
||||||
|
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||||
|
@ -50,11 +45,15 @@ int compare_essid_iwinfo(struct dawn_mac bssid_addr, struct dawn_mac bssid_addr_
|
||||||
|
|
||||||
iw = iwinfo_backend(entry->d_name);
|
iw = iwinfo_backend(entry->d_name);
|
||||||
|
|
||||||
|
// FIXME: Try to reduce string conversion and comparison here by using byte array compares
|
||||||
// TODO: Magic number
|
// TODO: Magic number
|
||||||
static char buf_bssid[18] = {0};
|
static char buf_bssid[18] = {0};
|
||||||
if (iw->bssid(entry->d_name, buf_bssid))
|
if (iw->bssid(entry->d_name, buf_bssid))
|
||||||
snprintf(buf_bssid, sizeof(buf_bssid), "00:00:00:00:00:00");
|
snprintf(buf_bssid, sizeof(buf_bssid), "00:00:00:00:00:00");
|
||||||
|
|
||||||
|
char mac_buf[20];
|
||||||
|
sprintf(mac_buf, MACSTR, MAC2STR(bssid_addr.u8));
|
||||||
|
|
||||||
if (strcmp(mac_buf, buf_bssid) == 0) {
|
if (strcmp(mac_buf, buf_bssid) == 0) {
|
||||||
|
|
||||||
if (iw->ssid(entry->d_name, buf_essid))
|
if (iw->ssid(entry->d_name, buf_essid))
|
||||||
|
@ -62,6 +61,9 @@ int compare_essid_iwinfo(struct dawn_mac bssid_addr, struct dawn_mac bssid_addr_
|
||||||
essid = buf_essid;
|
essid = buf_essid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char mac_buf_to_compare[20];
|
||||||
|
sprintf(mac_buf_to_compare, MACSTR, MAC2STR(bssid_addr_to_compare.u8));
|
||||||
|
|
||||||
if (strcmp(mac_buf_to_compare, buf_bssid) == 0) {
|
if (strcmp(mac_buf_to_compare, buf_bssid) == 0) {
|
||||||
if (iw->ssid(entry->d_name, buf_essid_to_compare))
|
if (iw->ssid(entry->d_name, buf_essid_to_compare))
|
||||||
memset(buf_essid_to_compare, 0, sizeof(buf_essid_to_compare));
|
memset(buf_essid_to_compare, 0, sizeof(buf_essid_to_compare));
|
||||||
|
|
|
@ -186,9 +186,9 @@ static int parse_rrm_mode(int *rrm_mode_order, const char *mode_string) {
|
||||||
static struct mac_entry_s *insert_neighbor_mac(struct mac_entry_s *head, const char* mac) {
|
static struct mac_entry_s *insert_neighbor_mac(struct mac_entry_s *head, const char* mac) {
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
struct mac_entry_s *new;
|
struct mac_entry_s *new = dawn_malloc(sizeof(struct mac_entry_s));
|
||||||
|
|
||||||
if (!(new = dawn_malloc(sizeof (struct mac_entry_s)))) {
|
if (new == NULL) {
|
||||||
dawnlog_error("Failed to allocate neighbor entry for '%s'\n", mac);
|
dawnlog_error("Failed to allocate neighbor entry for '%s'\n", mac);
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
@ -196,6 +196,7 @@ static struct mac_entry_s *insert_neighbor_mac(struct mac_entry_s *head, const c
|
||||||
if (hwaddr_aton(mac, new->mac.u8) != 0) {
|
if (hwaddr_aton(mac, new->mac.u8) != 0) {
|
||||||
dawnlog_error("Failed to parse MAC from '%s'\n", mac);
|
dawnlog_error("Failed to parse MAC from '%s'\n", mac);
|
||||||
dawn_free(new);
|
dawn_free(new);
|
||||||
|
new = NULL;
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
new->next_mac = head;
|
new->next_mac = head;
|
||||||
|
@ -210,13 +211,14 @@ static void free_neighbor_mac_list(struct mac_entry_s *list) {
|
||||||
ptr = list;
|
ptr = list;
|
||||||
list = list->next_mac;
|
list = list->next_mac;
|
||||||
dawn_free(ptr);
|
dawn_free(ptr);
|
||||||
|
ptr = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct mac_entry_s* uci_lookup_mac_list(struct uci_option *o) {
|
static struct mac_entry_s* uci_lookup_mac_list(struct uci_option *o) {
|
||||||
struct uci_element *e;
|
struct uci_element *e = NULL;
|
||||||
struct mac_entry_s *head = NULL;
|
struct mac_entry_s *head = NULL;
|
||||||
char *str;
|
char* str = NULL;
|
||||||
|
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
|
@ -337,6 +339,7 @@ struct probe_metric_s uci_get_dawn_metric() {
|
||||||
uci_lookup_option_string(uci_ctx, global_s, "rrm_mode"));
|
uci_lookup_option_string(uci_ctx, global_s, "rrm_mode"));
|
||||||
global_neighbors = uci_lookup_option(uci_ctx, global_s, "neighbors");
|
global_neighbors = uci_lookup_option(uci_ctx, global_s, "neighbors");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int band = 0; band < __DAWN_BAND_MAX; band++) {
|
for (int band = 0; band < __DAWN_BAND_MAX; band++) {
|
||||||
band_s[band] = uci_find_metric_section(band_config_name[band]);
|
band_s[band] = uci_find_metric_section(band_config_name[band]);
|
||||||
neighbors = band_s[band] ? uci_lookup_option(uci_ctx, band_s[band], "neighbors") : NULL;
|
neighbors = band_s[band] ? uci_lookup_option(uci_ctx, band_s[band], "neighbors") : NULL;
|
||||||
|
|
|
@ -55,10 +55,6 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
||||||
struct mem_list* this_log = NULL;
|
struct mem_list* this_log = NULL;
|
||||||
char type_c = '?';
|
char type_c = '?';
|
||||||
|
|
||||||
// Ignore over enthusiastic effort to register a failed allocation
|
|
||||||
if (ptr == NULL)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case DAWN_MALLOC:
|
case DAWN_MALLOC:
|
||||||
|
@ -78,6 +74,15 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note effort to register a failed allocation (other code probably wrong as well)
|
||||||
|
if (ptr == NULL)
|
||||||
|
{
|
||||||
|
char* xfile = strrchr(file, '/');
|
||||||
|
|
||||||
|
dawnlog_warning("mem-audit: attempting to register failed allocation (%c@%s:%d)...\n", type_c, xfile ? xfile + 1 : file, line);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Insert to linked list with ascending memory reference
|
// Insert to linked list with ascending memory reference
|
||||||
struct mem_list** ipos = &mem_base;
|
struct mem_list** ipos = &mem_base;
|
||||||
while (*ipos != NULL && (*ipos)->ptr < ptr)
|
while (*ipos != NULL && (*ipos)->ptr < ptr)
|
||||||
|
@ -85,7 +90,9 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
||||||
|
|
||||||
if (*ipos != NULL && (*ipos)->ptr == ptr)
|
if (*ipos != NULL && (*ipos)->ptr == ptr)
|
||||||
{
|
{
|
||||||
dawnlog_warning("mem-audit: attempting to register memory already registered (%c@%s:%d)...\n", type_c, file, line);
|
char* xfile = strrchr(file, '/');
|
||||||
|
|
||||||
|
dawnlog_warning("mem-audit: attempted to register memory already registered (%c@%s:%d)...\n", type_c, xfile ? xfile + 1 : file, line);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -93,18 +100,19 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
||||||
|
|
||||||
if (this_log == NULL)
|
if (this_log == NULL)
|
||||||
{
|
{
|
||||||
dawnlog_warning("mem-audit: Oh the irony! malloc() failed in dawn_memory_register()!\n");
|
dawnlog_error("mem-audit: Oh the irony! malloc() failed in dawn_memory_register()!\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Just use filename - no path
|
||||||
|
char *xfile = strrchr(file, '/');
|
||||||
|
|
||||||
|
dawnlog_debug("mem-audit: registering memory (%c@%s:%d)...\n", type_c, xfile ? xfile + 1 : file, line);
|
||||||
this_log->next_mem = *ipos;
|
this_log->next_mem = *ipos;
|
||||||
*ipos = this_log;
|
*ipos = this_log;
|
||||||
|
|
||||||
// Just use filename - no path
|
if (xfile != NULL)
|
||||||
file = strrchr(file, '/');
|
strncpy(this_log->file, xfile + 1, DAWN_MEM_FILENAME_LEN);
|
||||||
|
|
||||||
if (file != NULL)
|
|
||||||
strncpy(this_log->file, file + 1, DAWN_MEM_FILENAME_LEN);
|
|
||||||
else
|
else
|
||||||
strncpy(this_log->file, "?? UNKNOWN ??", DAWN_MEM_FILENAME_LEN);
|
strncpy(this_log->file, "?? UNKNOWN ??", DAWN_MEM_FILENAME_LEN);
|
||||||
|
|
||||||
|
@ -122,38 +130,26 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
||||||
void dawn_memory_unregister(enum dawn_memop type, char* file, int line, void* ptr)
|
void dawn_memory_unregister(enum dawn_memop type, char* file, int line, void* ptr)
|
||||||
{
|
{
|
||||||
struct mem_list** mem = &mem_base;
|
struct mem_list** mem = &mem_base;
|
||||||
char type_c = '?';
|
|
||||||
|
|
||||||
while (*mem != NULL && (*mem)->ptr < ptr)
|
while (*mem != NULL && (*mem)->ptr < ptr)
|
||||||
{
|
{
|
||||||
mem = &((*mem)->next_mem);
|
mem = &((*mem)->next_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type)
|
char* xfile = strrchr(file, '/');
|
||||||
{
|
|
||||||
case DAWN_FREE:
|
|
||||||
type_c = 'F';
|
|
||||||
break;
|
|
||||||
case DAWN_MEMUNREG:
|
|
||||||
type_c = 'U';
|
|
||||||
break;
|
|
||||||
case DAWN_REALLOC:
|
|
||||||
type_c = 'R';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dawnlog_warning("mem-audit: Unexpected memory op tag!\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*mem != NULL && (*mem)->ptr == ptr)
|
if (*mem != NULL && (*mem)->ptr == ptr)
|
||||||
{
|
{
|
||||||
|
// Just use filename - no path
|
||||||
|
dawnlog_debug("mem-audit: unregistering memory (%s:%d -> %c@%s:%d)...\n", xfile ? xfile + 1 : file, line, (*mem)->type, (*mem)->file, (*mem)->line);
|
||||||
|
|
||||||
struct mem_list* tmp = *mem;
|
struct mem_list* tmp = *mem;
|
||||||
*mem = tmp->next_mem;
|
*mem = tmp->next_mem;
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dawnlog_warning("mem-audit: Releasing (%c) memory we hadn't registered (%s:%d)...\n", type_c, file, line);
|
dawnlog_warning("mem-audit: Releasing memory we hadn't registered (%s:%d)...\n", xfile ? xfile + 1 : file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -173,18 +169,18 @@ void dawn_memory_audit()
|
||||||
size_t total = 0;
|
size_t total = 0;
|
||||||
|
|
||||||
dawnlog_always("mem-audit: Currently recorded allocations...\n");
|
dawnlog_always("mem-audit: Currently recorded allocations...\n");
|
||||||
for (struct mem_list* mem = mem_base; mem != NULL; mem = mem->next_mem)
|
for (struct mem_list* mem = mem_base; mem != NULL; mem = mem->next_mem)
|
||||||
{
|
{
|
||||||
dawnlog_always("mem-audit: %8" PRIu64 "=%c - %s@%d: %zu\n", mem->ref, mem->type, mem->file, mem->line, mem->size);
|
dawnlog_always("mem-audit: %8" PRIu64 "=%c - %s@%d: %zu\n", mem->ref, mem->type, mem->file, mem->line, mem->size);
|
||||||
total += mem->size;
|
total += mem->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *suffix = "bytes";
|
char *suffix = "bytes";
|
||||||
if (total > 128 * 1024)
|
if (total > 128 * 1024)
|
||||||
{
|
{
|
||||||
total /= 1024;
|
total /= 1024;
|
||||||
suffix = "kbytes";
|
suffix = "kbytes";
|
||||||
}
|
}
|
||||||
|
|
||||||
dawnlog_always("mem-audit: [End of list: %zu %s]\n", total, suffix);
|
dawnlog_always("mem-audit: [End of list: %zu %s]\n", total, suffix);
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,18 +163,21 @@ probe_entry *parse_to_probe_req(struct blob_attr* msg) {
|
||||||
if (hwaddr_aton(blobmsg_data(tb[PROB_BSSID_ADDR]), prob_req->bssid_addr.u8))
|
if (hwaddr_aton(blobmsg_data(tb[PROB_BSSID_ADDR]), prob_req->bssid_addr.u8))
|
||||||
{
|
{
|
||||||
dawn_free(prob_req);
|
dawn_free(prob_req);
|
||||||
|
prob_req = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hwaddr_aton(blobmsg_data(tb[PROB_CLIENT_ADDR]), prob_req->client_addr.u8))
|
if (hwaddr_aton(blobmsg_data(tb[PROB_CLIENT_ADDR]), prob_req->client_addr.u8))
|
||||||
{
|
{
|
||||||
dawn_free(prob_req);
|
dawn_free(prob_req);
|
||||||
|
prob_req = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hwaddr_aton(blobmsg_data(tb[PROB_TARGET_ADDR]), prob_req->target_addr.u8))
|
if (hwaddr_aton(blobmsg_data(tb[PROB_TARGET_ADDR]), prob_req->target_addr.u8))
|
||||||
{
|
{
|
||||||
dawn_free(prob_req);
|
dawn_free(prob_req);
|
||||||
|
prob_req = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,6 +262,7 @@ int handle_network_msg(char* msg) {
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&network_buf, 0);
|
blob_buf_init(&network_buf, 0);
|
||||||
|
// dawn_regmem(&network_buf);
|
||||||
blobmsg_add_json_from_string(&network_buf, msg);
|
blobmsg_add_json_from_string(&network_buf, msg);
|
||||||
|
|
||||||
blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(network_buf.head), blob_len(network_buf.head));
|
blobmsg_parse(network_policy, __NETWORK_MAX, tb, blob_data(network_buf.head), blob_len(network_buf.head));
|
||||||
|
@ -273,6 +277,7 @@ int handle_network_msg(char* msg) {
|
||||||
dawnlog_debug("Network Method new: %s : %s\n", method, msg);
|
dawnlog_debug("Network Method new: %s : %s\n", method, msg);
|
||||||
|
|
||||||
blob_buf_init(&data_buf, 0);
|
blob_buf_init(&data_buf, 0);
|
||||||
|
// dawn_regmem(&data_buf);
|
||||||
blobmsg_add_json_from_string(&data_buf, data);
|
blobmsg_add_json_from_string(&data_buf, data);
|
||||||
|
|
||||||
if (!data_buf.head) {
|
if (!data_buf.head) {
|
||||||
|
@ -299,6 +304,7 @@ int handle_network_msg(char* msg) {
|
||||||
{
|
{
|
||||||
// insert found an existing entry, rather than linking in our new one
|
// insert found an existing entry, rather than linking in our new one
|
||||||
dawn_free(entry);
|
dawn_free(entry);
|
||||||
|
entry = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,6 +343,12 @@ int handle_network_msg(char* msg) {
|
||||||
dawnlog_warning("No method found for: %s\n", method);
|
dawnlog_warning("No method found for: %s\n", method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blob_buf_free(&data_buf);
|
||||||
|
// dawn_unregmem(&data_buf);
|
||||||
|
|
||||||
|
blob_buf_free(&network_buf);
|
||||||
|
// dawn_unregmem(&network_buf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +439,11 @@ dump_client(struct blob_attr** tb, struct dawn_mac client_addr, const char* bssi
|
||||||
pthread_mutex_lock(&client_array_mutex);
|
pthread_mutex_lock(&client_array_mutex);
|
||||||
// If entry was akraedy in list it won't be added, so free memorY
|
// If entry was akraedy in list it won't be added, so free memorY
|
||||||
if (client_entry != insert_client_to_array(client_entry, time(0)))
|
if (client_entry != insert_client_to_array(client_entry, time(0)))
|
||||||
|
{
|
||||||
dawn_free(client_entry);
|
dawn_free(client_entry);
|
||||||
|
client_entry = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&client_array_mutex);
|
pthread_mutex_unlock(&client_array_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -383,6 +383,7 @@ int parse_to_beacon_rep(struct blob_attr *msg) {
|
||||||
// insert found an existing entry, rather than linking in our new one
|
// insert found an existing entry, rather than linking in our new one
|
||||||
ubus_send_probe_via_network(beacon_rep_updated);
|
ubus_send_probe_via_network(beacon_rep_updated);
|
||||||
dawn_free(beacon_rep);
|
dawn_free(beacon_rep);
|
||||||
|
beacon_rep = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ubus_send_probe_via_network(beacon_rep_updated);
|
ubus_send_probe_via_network(beacon_rep_updated);
|
||||||
|
@ -426,7 +427,10 @@ bool discard_entry = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (discard_entry)
|
if (discard_entry)
|
||||||
|
{
|
||||||
dawn_free(auth_req);
|
dawn_free(auth_req);
|
||||||
|
auth_req = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -463,7 +467,10 @@ int discard_entry = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (discard_entry)
|
if (discard_entry)
|
||||||
|
{
|
||||||
dawn_free(auth_req);
|
dawn_free(auth_req);
|
||||||
|
auth_req = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -480,7 +487,10 @@ static int handle_probe_req(struct blob_attr *msg) {
|
||||||
// send new probe req because we want to stay synced.
|
// send new probe req because we want to stay synced.
|
||||||
// If not, probe_req and probe_req_updated should be equivalent
|
// If not, probe_req and probe_req_updated should be equivalent
|
||||||
if (probe_req != probe_req_updated)
|
if (probe_req != probe_req_updated)
|
||||||
|
{
|
||||||
dawn_free(probe_req);
|
dawn_free(probe_req);
|
||||||
|
probe_req = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ubus_send_probe_via_network(probe_req_updated);
|
ubus_send_probe_via_network(probe_req_updated);
|
||||||
|
|
||||||
|
@ -519,7 +529,10 @@ int send_blob_attr_via_network(struct blob_attr* msg, char* method) {
|
||||||
|
|
||||||
data_str = blobmsg_format_json(msg, true);
|
data_str = blobmsg_format_json(msg, true);
|
||||||
dawn_regmem(data_str);
|
dawn_regmem(data_str);
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
|
|
||||||
blobmsg_add_string(&b, "method", method);
|
blobmsg_add_string(&b, "method", method);
|
||||||
blobmsg_add_string(&b, "data", data_str);
|
blobmsg_add_string(&b, "data", data_str);
|
||||||
|
|
||||||
|
@ -537,9 +550,14 @@ int send_blob_attr_via_network(struct blob_attr* msg, char* method) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dawn_free(data_str);
|
|
||||||
dawn_free(str);
|
dawn_free(str);
|
||||||
|
str = NULL;
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
|
dawn_free(data_str);
|
||||||
|
data_str = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -550,12 +568,15 @@ static int hostapd_notify(struct ubus_context* ctx_local, struct ubus_object* ob
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct blob_buf b = {0};
|
struct blob_buf b = {0};
|
||||||
|
|
||||||
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
if (dawnlog_showing(DAWNLOG_DEBUG))
|
if (dawnlog_showing(DAWNLOG_DEBUG))
|
||||||
{
|
{
|
||||||
char* str = blobmsg_format_json(msg, true);
|
char* str = blobmsg_format_json(msg, true);
|
||||||
dawn_regmem(str);
|
dawn_regmem(str);
|
||||||
dawnlog_debug("Method new: %s : %s\n", method, str);
|
dawnlog_debug("Method new: %s : %s\n", method, str);
|
||||||
dawn_free(str);
|
dawn_free(str);
|
||||||
|
str = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hostapd_sock_entry *entry;
|
struct hostapd_sock_entry *entry;
|
||||||
|
@ -566,6 +587,7 @@ static int hostapd_notify(struct ubus_context* ctx_local, struct ubus_object* ob
|
||||||
|
|
||||||
struct blob_attr *cur; int rem;
|
struct blob_attr *cur; int rem;
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_for_each_attr(cur, msg, rem){
|
blobmsg_for_each_attr(cur, msg, rem){
|
||||||
blobmsg_add_blob(&b, cur);
|
blobmsg_add_blob(&b, cur);
|
||||||
}
|
}
|
||||||
|
@ -587,6 +609,7 @@ static int hostapd_notify(struct ubus_context* ctx_local, struct ubus_object* ob
|
||||||
}
|
}
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -643,6 +666,7 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
||||||
|
|
||||||
ubus_free(ctx);
|
ubus_free(ctx);
|
||||||
dawn_unregmem(ctx);
|
dawn_unregmem(ctx);
|
||||||
|
ctx = NULL;
|
||||||
uloop_done();
|
uloop_done();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -659,19 +683,14 @@ static int get_band_from_bssid(struct dawn_mac bssid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_attr *msg) {
|
static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_attr *msg) {
|
||||||
struct hostapd_sock_entry *sub, *entry = NULL;
|
dawnlog_debug_func("Entering...");
|
||||||
struct blob_buf b = {0};
|
|
||||||
|
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char *data_str = blobmsg_format_json(msg, 1);
|
struct hostapd_sock_entry* entry = NULL;
|
||||||
dawn_regmem(data_str);
|
|
||||||
blob_buf_init(&b, 0);
|
|
||||||
blobmsg_add_json_from_string(&b, data_str);
|
|
||||||
blobmsg_add_u32(&b, "collision_domain", network_config.collision_domain);
|
|
||||||
blobmsg_add_u32(&b, "bandwidth", network_config.bandwidth);
|
|
||||||
|
|
||||||
|
struct hostapd_sock_entry* sub = NULL;
|
||||||
list_for_each_entry(sub, &hostapd_sock_list, list)
|
list_for_each_entry(sub, &hostapd_sock_list, list)
|
||||||
{
|
{
|
||||||
if (sub->id == req->peer) {
|
if (sub->id == req->peer) {
|
||||||
|
@ -679,20 +698,29 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub = NULL;
|
||||||
|
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
dawnlog_error("Failed to find interface!\n");
|
dawnlog_error("Failed to find interface!\n");
|
||||||
dawn_free(data_str);
|
|
||||||
blob_buf_free(&b);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entry->subscribed) {
|
if (!entry->subscribed) {
|
||||||
dawnlog_error("Interface %s is not subscribed!\n", entry->iface_name);
|
dawnlog_error("Interface %s is not subscribed!\n", entry->iface_name);
|
||||||
dawn_free(data_str);
|
|
||||||
blob_buf_free(&b);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *data_str = blobmsg_format_json(msg, 1);
|
||||||
|
dawn_regmem(data_str);
|
||||||
|
|
||||||
|
struct blob_buf b = {0};
|
||||||
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
|
|
||||||
|
blobmsg_add_json_from_string(&b, data_str);
|
||||||
|
blobmsg_add_u32(&b, "collision_domain", network_config.collision_domain);
|
||||||
|
blobmsg_add_u32(&b, "bandwidth", network_config.bandwidth);
|
||||||
|
|
||||||
blobmsg_add_macaddr(&b, "bssid", entry->bssid_addr);
|
blobmsg_add_macaddr(&b, "bssid", entry->bssid_addr);
|
||||||
blobmsg_add_string(&b, "ssid", entry->ssid);
|
blobmsg_add_string(&b, "ssid", entry->ssid);
|
||||||
blobmsg_add_u8(&b, "ht_supported", entry->ht_support);
|
blobmsg_add_u8(&b, "ht_supported", entry->ht_support);
|
||||||
|
@ -719,20 +747,26 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
|
||||||
print_ap_array();
|
print_ap_array();
|
||||||
|
|
||||||
dawn_free(data_str);
|
dawn_free(data_str);
|
||||||
|
data_str = NULL;
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ubus_get_clients() {
|
static int ubus_get_clients() {
|
||||||
int timeout = 1;
|
int timeout = 1;
|
||||||
struct hostapd_sock_entry *sub;
|
struct hostapd_sock_entry *sub;
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
list_for_each_entry(sub, &hostapd_sock_list, list)
|
list_for_each_entry(sub, &hostapd_sock_list, list)
|
||||||
{
|
{
|
||||||
if (sub->subscribed) {
|
if (sub->subscribed) {
|
||||||
struct blob_buf b = {0};
|
struct blob_buf b = {0};
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
ubus_invoke(ctx, sub->id, "get_clients", b.head, ubus_get_clients_cb, NULL, timeout * 1000);
|
ubus_invoke(ctx, sub->id, "get_clients", b.head, ubus_get_clients_cb, NULL, timeout * 1000);
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -787,8 +821,10 @@ static int ubus_get_rrm() {
|
||||||
if (sub->subscribed) {
|
if (sub->subscribed) {
|
||||||
struct blob_buf b = {0};
|
struct blob_buf b = {0};
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
ubus_invoke(ctx, sub->id, "rrm_nr_get_own", b.head, ubus_get_rrm_cb, NULL, timeout * 1000);
|
ubus_invoke(ctx, sub->id, "rrm_nr_get_own", b.head, ubus_get_rrm_cb, NULL, timeout * 1000);
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -859,6 +895,7 @@ void ubus_send_beacon_report(client *c, ap *a, int id)
|
||||||
int timeout = 1;
|
int timeout = 1;
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_macaddr(&b, "addr", c->client_addr);
|
blobmsg_add_macaddr(&b, "addr", c->client_addr);
|
||||||
blobmsg_add_u32(&b, "op_class", a->op_class);
|
blobmsg_add_u32(&b, "op_class", a->op_class);
|
||||||
blobmsg_add_u32(&b, "channel", a->channel);
|
blobmsg_add_u32(&b, "channel", a->channel);
|
||||||
|
@ -869,6 +906,7 @@ void ubus_send_beacon_report(client *c, ap *a, int id)
|
||||||
dawnlog_debug("Invoking beacon report!\n");
|
dawnlog_debug("Invoking beacon report!\n");
|
||||||
ubus_invoke(ctx, id, "rrm_beacon_req", b.head, NULL, NULL, timeout * 1000);
|
ubus_invoke(ctx, id, "rrm_beacon_req", b.head, NULL, NULL, timeout * 1000);
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_beacon_reports(struct uloop_timeout *t) {
|
void update_beacon_reports(struct uloop_timeout *t) {
|
||||||
|
@ -932,9 +970,11 @@ void ubus_set_nr(){
|
||||||
if (sub->subscribed) {
|
if (sub->subscribed) {
|
||||||
struct blob_buf b = {0};
|
struct blob_buf b = {0};
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
ap_get_nr(&b, sub->bssid_addr, sub->ssid);
|
ap_get_nr(&b, sub->bssid_addr, sub->ssid);
|
||||||
ubus_invoke(ctx, sub->id, "rrm_nr_set", b.head, NULL, NULL, timeout * 1000);
|
ubus_invoke(ctx, sub->id, "rrm_nr_set", b.head, NULL, NULL, timeout * 1000);
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -946,6 +986,7 @@ void del_client_all_interfaces(const struct dawn_mac client_addr, uint32_t reaso
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_macaddr(&b, "addr", client_addr);
|
blobmsg_add_macaddr(&b, "addr", client_addr);
|
||||||
blobmsg_add_u32(&b, "reason", reason);
|
blobmsg_add_u32(&b, "reason", reason);
|
||||||
blobmsg_add_u8(&b, "deauth", deauth);
|
blobmsg_add_u8(&b, "deauth", deauth);
|
||||||
|
@ -959,6 +1000,7 @@ void del_client_all_interfaces(const struct dawn_mac client_addr, uint32_t reaso
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void del_client_interface(uint32_t id, const struct dawn_mac client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) {
|
void del_client_interface(uint32_t id, const struct dawn_mac client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) {
|
||||||
|
@ -966,6 +1008,7 @@ void del_client_interface(uint32_t id, const struct dawn_mac client_addr, uint32
|
||||||
struct blob_buf b = {0};
|
struct blob_buf b = {0};
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_macaddr(&b, "addr", client_addr);
|
blobmsg_add_macaddr(&b, "addr", client_addr);
|
||||||
blobmsg_add_u32(&b, "reason", reason);
|
blobmsg_add_u32(&b, "reason", reason);
|
||||||
blobmsg_add_u8(&b, "deauth", deauth);
|
blobmsg_add_u8(&b, "deauth", deauth);
|
||||||
|
@ -980,6 +1023,7 @@ void del_client_interface(uint32_t id, const struct dawn_mac client_addr, uint32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wnm_disassoc_imminent(uint32_t id, const struct dawn_mac client_addr, struct kicking_nr* neighbor_list, uint32_t duration) {
|
int wnm_disassoc_imminent(uint32_t id, const struct dawn_mac client_addr, struct kicking_nr* neighbor_list, uint32_t duration) {
|
||||||
|
@ -989,6 +1033,7 @@ int wnm_disassoc_imminent(uint32_t id, const struct dawn_mac client_addr, struct
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_macaddr(&b, "addr", client_addr);
|
blobmsg_add_macaddr(&b, "addr", client_addr);
|
||||||
blobmsg_add_u32(&b, "duration", duration);
|
blobmsg_add_u32(&b, "duration", duration);
|
||||||
blobmsg_add_u8(&b, "abridged", 1); // prefer aps in neighborlist
|
blobmsg_add_u8(&b, "abridged", 1); // prefer aps in neighborlist
|
||||||
|
@ -1010,6 +1055,7 @@ int wnm_disassoc_imminent(uint32_t id, const struct dawn_mac client_addr, struct
|
||||||
}
|
}
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1064,9 +1110,11 @@ int ubus_call_umdns() {
|
||||||
|
|
||||||
int timeout = 1;
|
int timeout = 1;
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
ubus_invoke(ctx, id, "update", b.head, NULL, NULL, timeout * 1000);
|
ubus_invoke(ctx, id, "update", b.head, NULL, NULL, timeout * 1000);
|
||||||
ubus_invoke(ctx, id, "browse", b.head, ubus_umdns_cb, NULL, timeout * 1000);
|
ubus_invoke(ctx, id, "browse", b.head, ubus_umdns_cb, NULL, timeout * 1000);
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1078,6 +1126,7 @@ int ubus_send_probe_via_network(struct probe_entry_s *probe_entry) { // TODO: p
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_macaddr(&b, "bssid", probe_entry->bssid_addr);
|
blobmsg_add_macaddr(&b, "bssid", probe_entry->bssid_addr);
|
||||||
blobmsg_add_macaddr(&b, "address", probe_entry->client_addr);
|
blobmsg_add_macaddr(&b, "address", probe_entry->client_addr);
|
||||||
blobmsg_add_macaddr(&b, "target", probe_entry->target_addr);
|
blobmsg_add_macaddr(&b, "target", probe_entry->target_addr);
|
||||||
|
@ -1104,6 +1153,7 @@ int ubus_send_probe_via_network(struct probe_entry_s *probe_entry) { // TODO: p
|
||||||
send_blob_attr_via_network(b.head, "probe");
|
send_blob_attr_via_network(b.head, "probe");
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1114,12 +1164,14 @@ int send_set_probe(struct dawn_mac client_addr) {
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_macaddr(&b, "bssid", client_addr);
|
blobmsg_add_macaddr(&b, "bssid", client_addr);
|
||||||
blobmsg_add_macaddr(&b, "address", client_addr);
|
blobmsg_add_macaddr(&b, "address", client_addr);
|
||||||
|
|
||||||
send_blob_attr_via_network(b.head, "setprobe");
|
send_blob_attr_via_network(b.head, "setprobe");
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1208,6 +1260,7 @@ static int reload_config(struct ubus_context *ctx_local, struct ubus_object *obj
|
||||||
dawnlog_trace("UBUS invoking reload_config()");
|
dawnlog_trace("UBUS invoking reload_config()");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
uci_reset();
|
uci_reset();
|
||||||
dawn_metric = uci_get_dawn_metric();
|
dawn_metric = uci_get_dawn_metric();
|
||||||
timeout_config = uci_get_time_config();
|
timeout_config = uci_get_time_config();
|
||||||
|
@ -1223,6 +1276,7 @@ static int reload_config(struct ubus_context *ctx_local, struct ubus_object *obj
|
||||||
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1238,11 +1292,13 @@ static int get_hearing_map(struct ubus_context *ctx_local, struct ubus_object *o
|
||||||
dawnlog_trace("UBUS invoking get_hearing_map()");
|
dawnlog_trace("UBUS invoking get_hearing_map()");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
build_hearing_map_sort_client(&b);
|
build_hearing_map_sort_client(&b);
|
||||||
ret = ubus_send_reply(ctx_local, req, b.head);
|
ret = ubus_send_reply(ctx_local, req, b.head);
|
||||||
if (ret)
|
if (ret)
|
||||||
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1259,11 +1315,13 @@ static int get_network(struct ubus_context *ctx_local, struct ubus_object *obj,
|
||||||
dawnlog_trace("UBUS invoking get_network()");
|
dawnlog_trace("UBUS invoking get_network()");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
build_network_overview(&b);
|
build_network_overview(&b);
|
||||||
ret = ubus_send_reply(ctx_local, req, b.head);
|
ret = ubus_send_reply(ctx_local, req, b.head);
|
||||||
if (ret)
|
if (ret)
|
||||||
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1289,6 +1347,7 @@ static void respond_to_notify(uint32_t id) {
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_u32(&b, "notify_response", 1);
|
blobmsg_add_u32(&b, "notify_response", 1);
|
||||||
|
|
||||||
ret = ubus_invoke(ctx, id, "notify_response", b.head, NULL, NULL, timeout * 1000);
|
ret = ubus_invoke(ctx, id, "notify_response", b.head, NULL, NULL, timeout * 1000);
|
||||||
|
@ -1296,6 +1355,7 @@ static void respond_to_notify(uint32_t id) {
|
||||||
dawnlog_error("Failed to invoke: %s\n", ubus_strerror(ret));
|
dawnlog_error("Failed to invoke: %s\n", ubus_strerror(ret));
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enable_rrm(uint32_t id) {
|
static void enable_rrm(uint32_t id) {
|
||||||
|
@ -1303,6 +1363,7 @@ static void enable_rrm(uint32_t id) {
|
||||||
struct blob_buf b = {0};
|
struct blob_buf b = {0};
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_u8(&b, "neighbor_report", 1);
|
blobmsg_add_u8(&b, "neighbor_report", 1);
|
||||||
blobmsg_add_u8(&b, "beacon_report", 1);
|
blobmsg_add_u8(&b, "beacon_report", 1);
|
||||||
blobmsg_add_u8(&b, "bss_transition", 1);
|
blobmsg_add_u8(&b, "bss_transition", 1);
|
||||||
|
@ -1313,6 +1374,7 @@ static void enable_rrm(uint32_t id) {
|
||||||
dawnlog_error("Failed to invoke: %s\n", ubus_strerror(ret));
|
dawnlog_error("Failed to invoke: %s\n", ubus_strerror(ret));
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hostapd_handle_remove(struct ubus_context *ctx_local,
|
static void hostapd_handle_remove(struct ubus_context *ctx_local,
|
||||||
|
@ -1506,6 +1568,7 @@ int uci_send_via_network()
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_string(&b, "version", DAWN_CONFIG_VERSION);
|
blobmsg_add_string(&b, "version", DAWN_CONFIG_VERSION);
|
||||||
metric = blobmsg_open_table(&b, "metric");
|
metric = blobmsg_open_table(&b, "metric");
|
||||||
|
|
||||||
|
@ -1567,6 +1630,7 @@ int uci_send_via_network()
|
||||||
send_blob_attr_via_network(b.head, "uci");
|
send_blob_attr_via_network(b.head, "uci");
|
||||||
|
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1884,9 +1948,11 @@ int send_add_mac(struct dawn_mac client_addr) {
|
||||||
dawnlog_debug_func("Entering...");
|
dawnlog_debug_func("Entering...");
|
||||||
|
|
||||||
blob_buf_init(&b, 0);
|
blob_buf_init(&b, 0);
|
||||||
|
dawn_regmem(&b);
|
||||||
blobmsg_add_macaddr(&b, "addr", client_addr);
|
blobmsg_add_macaddr(&b, "addr", client_addr);
|
||||||
send_blob_attr_via_network(b.head, "addmac");
|
send_blob_attr_via_network(b.head, "addmac");
|
||||||
blob_buf_free(&b);
|
blob_buf_free(&b);
|
||||||
|
dawn_unregmem(&b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue