mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-02-12 16:51:53 +00:00
treewide: improve maintaince
General revisions to maintain code (no functional changes intended). Removed unnecessary linked-list length checks. Fixed some typos on function names / comments. Changed how test_storage forces SEGV due to new compiler warnings. Signed-off-by: Ian Clowes <clowes_ian@hotmail.com>
This commit is contained in:
parent
6bf9b6df9a
commit
9187665f8e
8 changed files with 50 additions and 69 deletions
|
@ -9,16 +9,9 @@
|
|||
#include "mac_utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
// Core data storage array sizes
|
||||
#define ARRAY_AP_LEN 100
|
||||
#define ARRAY_CLIENT_LEN 300
|
||||
#define PROBE_ARRAY_LEN 1000
|
||||
#define DENY_REQ_ARRAY_LEN 100
|
||||
|
||||
/* Mac */
|
||||
|
||||
// ---------------- Defines -------------------
|
||||
#define MAC_LIST_LENGTH 100
|
||||
#define DEFAULT_RRM_MODE_ORDER "pat"
|
||||
#define RRM_MODE_COUNT 3
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ struct network_con_s {
|
|||
* @param port
|
||||
* @return
|
||||
*/
|
||||
int add_tcp_conncection(char *ipv4, int port);
|
||||
int add_tcp_connection(char *ipv4, int port);
|
||||
|
||||
/**
|
||||
* Opens a tcp server and adds it to the uloop.
|
||||
|
|
|
@ -56,10 +56,12 @@ static void client_notify_write(struct ustream *s, int bytes) {
|
|||
return;
|
||||
}
|
||||
|
||||
static void client_notify_state(struct ustream *s) {
|
||||
struct client *cl = container_of(s,
|
||||
struct client, s.stream);
|
||||
|
||||
// FIXME: This void function tries to return a value sometimes...
|
||||
static void client_notify_state(struct ustream *s) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
if (!s->eof)
|
||||
return;
|
||||
|
||||
|
@ -71,8 +73,7 @@ static void client_notify_state(struct ustream *s) {
|
|||
}
|
||||
|
||||
static void client_to_server_close(struct ustream *s) {
|
||||
struct network_con_s *con = container_of(s,
|
||||
struct network_con_s, stream.stream);
|
||||
struct network_con_s *con = container_of(s, struct network_con_s, stream.stream);
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
|
@ -87,8 +88,7 @@ static void client_to_server_close(struct ustream *s) {
|
|||
}
|
||||
|
||||
static void client_to_server_state(struct ustream *s) {
|
||||
struct client *cl = container_of(s,
|
||||
struct client, s.stream);
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
|
@ -289,7 +289,7 @@ static void connect_cb(struct uloop_fd *f, unsigned int events) {
|
|||
entry->connected = 1;
|
||||
}
|
||||
|
||||
int add_tcp_conncection(char *ipv4, int port) {
|
||||
int add_tcp_connection(char *ipv4, int port) {
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
|
|
@ -90,7 +90,7 @@ static const struct dawn_mac dawn_mac_null = { .u8 = {0,0,0,0,0,0} };
|
|||
** then the target element does not exist, but can be inserted by using the returned reference.
|
||||
*/
|
||||
|
||||
static struct probe_entry_s** probe_skip_array_find_first_entry(struct dawn_mac client_mac, struct dawn_mac bssid_mac, int do_bssid)
|
||||
static struct probe_entry_s** probe_skip_array_find_first_entry(struct dawn_mac client_mac, struct dawn_mac bssid_mac, bool do_bssid)
|
||||
{
|
||||
int lo = 0;
|
||||
struct probe_entry_s** lo_ptr = &probe_skip_set;
|
||||
|
@ -906,10 +906,6 @@ void client_array_insert(client *entry, client** insert_pos) {
|
|||
|
||||
client_entry_last++;
|
||||
|
||||
if (client_entry_last == ARRAY_CLIENT_LEN) {
|
||||
dawnlog_warning("client_array overflowing (now contains %d entries)!\n", client_entry_last);
|
||||
}
|
||||
|
||||
// Try to keep skip list density stable
|
||||
if ((client_entry_last / DAWN_CLIENT_SKIP_RATIO) > client_skip_entry_last)
|
||||
{
|
||||
|
@ -1220,10 +1216,6 @@ probe_entry* insert_to_array(probe_entry* entry, int inc_counter, int save_80211
|
|||
*existing_entry = entry;
|
||||
probe_entry_last++;
|
||||
|
||||
if (probe_entry_last == PROBE_ARRAY_LEN) {
|
||||
dawnlog_warning("probe_array overflowing (now contains %d entries)!\n", probe_entry_last);
|
||||
}
|
||||
|
||||
// Try to keep skip list density stable
|
||||
if ((probe_entry_last / DAWN_PROBE_SKIP_RATIO) > probe_skip_entry_last)
|
||||
{
|
||||
|
@ -1299,10 +1291,6 @@ void ap_array_insert(ap* entry) {
|
|||
entry->next_ap = *i;
|
||||
*i = entry;
|
||||
ap_entry_last++;
|
||||
|
||||
if (ap_entry_last == ARRAY_AP_LEN) {
|
||||
dawnlog_warning("ap_array overflowing (contains %d entries)!\n", ap_entry_last);
|
||||
}
|
||||
}
|
||||
|
||||
ap* ap_array_get_ap(struct dawn_mac bssid_mac, const uint8_t* ssid) {
|
||||
|
@ -1451,7 +1439,7 @@ void insert_macs_from_file() {
|
|||
ssize_t read;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
// TODO: Loading to array is not constrained by array checks. Buffer overrun can occur.
|
||||
|
||||
fp = fopen("/tmp/dawn_mac_list", "r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
|
@ -1596,10 +1584,6 @@ auth_entry* insert_to_denied_req_array(auth_entry* entry, int inc_counter, time_
|
|||
entry->next_auth = *i;
|
||||
*i = entry;
|
||||
denied_req_last++;
|
||||
|
||||
if (denied_req_last == DENY_REQ_ARRAY_LEN) {
|
||||
dawnlog_warning("denied_req_array overflowing (now contains %d entries)!\n", denied_req_last);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&denied_array_mutex);
|
||||
|
@ -1636,10 +1620,6 @@ struct mac_entry_s* insert_to_mac_array(struct mac_entry_s* entry, struct mac_en
|
|||
*insert_pos = entry;
|
||||
mac_set_last++;
|
||||
|
||||
if (mac_set_last == DENY_REQ_ARRAY_LEN) {
|
||||
dawnlog_warning("denied_req_array overflowing (now contains %d entries)!\n", mac_set_last);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
|
|
@ -429,7 +429,17 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
|
|||
args_required = 1;
|
||||
|
||||
char* leaky = dawn_malloc(10);
|
||||
strcpy(leaky, "LEAKED"); // Force use of memory to avoid unused error
|
||||
strcpy(leaky, "TRACKED"); // Force use of memory to avoid unused error
|
||||
|
||||
leaky = malloc(10);
|
||||
strcpy(leaky, "UNTRACKED"); // Force use of memory to avoid unused error
|
||||
}
|
||||
else if (strcmp(*argv, "segv") == 0)
|
||||
{
|
||||
args_required = 1;
|
||||
|
||||
char *badpointer = 0;
|
||||
*badpointer = 0;
|
||||
}
|
||||
else if (strcmp(*argv, "memaudit") == 0)
|
||||
{
|
||||
|
|
|
@ -308,15 +308,18 @@ struct probe_metric_s uci_get_dawn_metric() {
|
|||
struct uci_section *global_s, *band_s[__DAWN_BAND_MAX];
|
||||
struct uci_option *global_neighbors = NULL, *neighbors;
|
||||
|
||||
if (!(global_s = uci_find_metric_section("global"))) {
|
||||
if (!(global_s = uci_find_metric_section(NULL))) {
|
||||
dawnlog_warning("config metric global section not found! Using defaults.\n");
|
||||
} else {
|
||||
dawnlog_warning("config metric global section not found. "
|
||||
"Using first unnamed config metric.\n"
|
||||
"Consider naming a 'global' metric section to avoid ambiguity.\n");
|
||||
}
|
||||
}
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
global_s = uci_find_metric_section("global");
|
||||
|
||||
if (!global_s && (global_s = uci_find_metric_section(NULL)))
|
||||
dawnlog_warning("config metric global section not found. "
|
||||
"Using first unnamed config metric.\n"
|
||||
"Consider naming a 'global' metric section to avoid ambiguity.\n");
|
||||
|
||||
if (!global_s)
|
||||
dawnlog_warning("config metric global section not found! Using defaults.\n");
|
||||
|
||||
if (global_s) {
|
||||
// True global configuration
|
||||
DAWN_SET_CONFIG_INT(ret, global_s, kicking);
|
||||
|
|
|
@ -48,17 +48,10 @@ int hwaddr_aton(const char* txt, uint8_t* addr) {
|
|||
|
||||
void write_mac_to_file(char* path, struct dawn_mac addr) {
|
||||
FILE* f = fopen(path, "a");
|
||||
if (f == NULL) {
|
||||
if (f == NULL)
|
||||
dawnlog_error("Error opening mac file!\n");
|
||||
|
||||
// TODO: Should this be an exit()?
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char mac_buf[20];
|
||||
sprintf(mac_buf, MACSTR, MAC2STR(addr.u8));
|
||||
|
||||
fprintf(f, "%s\n", mac_buf);
|
||||
else
|
||||
fprintf(f, MACSTR "\n", MAC2STR(addr.u8));
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
|
|
@ -441,25 +441,25 @@ int discard_entry = true;
|
|||
|
||||
dawnlog_debug_func("Entering...");
|
||||
print_probe_array();
|
||||
auth_entry* auth_req = dawn_malloc(sizeof(struct auth_entry_s));
|
||||
if (auth_req == NULL)
|
||||
auth_entry* assoc_req = dawn_malloc(sizeof(struct auth_entry_s));
|
||||
if (assoc_req == NULL)
|
||||
return -1;
|
||||
|
||||
parse_to_assoc_req(msg, auth_req);
|
||||
parse_to_assoc_req(msg, assoc_req);
|
||||
dawnlog_debug("Association entry: ");
|
||||
print_auth_entry(DAWNLOG_DEBUG, auth_req);
|
||||
print_auth_entry(DAWNLOG_DEBUG, assoc_req);
|
||||
|
||||
if (!mac_in_maclist(auth_req->client_addr)) {
|
||||
if (!mac_in_maclist(assoc_req->client_addr)) {
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
|
||||
probe_entry *tmp = probe_array_get_entry(auth_req->bssid_addr, auth_req->client_addr);
|
||||
probe_entry *tmp = probe_array_get_entry(assoc_req->bssid_addr, assoc_req->client_addr);
|
||||
|
||||
pthread_mutex_unlock(&probe_array_mutex);
|
||||
|
||||
// block if entry was not already found in probe database
|
||||
if (tmp == NULL || !decide_function(tmp, REQ_TYPE_ASSOC)) {
|
||||
if (dawn_metric.use_driver_recog) {
|
||||
if (auth_req == insert_to_denied_req_array(auth_req, 1, time(0)))
|
||||
if (assoc_req == insert_to_denied_req_array(assoc_req, 1, time(0)))
|
||||
discard_entry = false;
|
||||
}
|
||||
return dawn_metric.deny_assoc_reason;
|
||||
|
@ -468,8 +468,8 @@ int discard_entry = true;
|
|||
|
||||
if (discard_entry)
|
||||
{
|
||||
dawn_free(auth_req);
|
||||
auth_req = NULL;
|
||||
dawn_free(assoc_req);
|
||||
assoc_req = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -503,8 +503,10 @@ static int handle_probe_req(struct blob_attr *msg) {
|
|||
return WLAN_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// FIXME: Seems to do nothing...
|
||||
static int handle_beacon_rep(struct blob_attr *msg) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (parse_to_beacon_rep(msg) == 0) {
|
||||
// dawnlog_debug("Inserting beacon Report!\n");
|
||||
// insert_to_array(beacon_rep, 1);
|
||||
|
@ -936,7 +938,7 @@ void update_tcp_connections(struct uloop_timeout *t) {
|
|||
if (strcmp(network_config.server_ip, ""))
|
||||
{
|
||||
// nothing happens if tcp connection is already established
|
||||
add_tcp_conncection(network_config.server_ip, network_config.tcp_port);
|
||||
add_tcp_connection(network_config.server_ip, network_config.tcp_port);
|
||||
}
|
||||
if (network_config.network_option == 2) // mdns enabled?
|
||||
{
|
||||
|
@ -1093,7 +1095,7 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr *
|
|||
} else {
|
||||
return;
|
||||
}
|
||||
add_tcp_conncection(blobmsg_get_string(tb_dawn[DAWN_UMDNS_IPV4]), blobmsg_get_u32(tb_dawn[DAWN_UMDNS_PORT]));
|
||||
add_tcp_connection(blobmsg_get_string(tb_dawn[DAWN_UMDNS_IPV4]), blobmsg_get_u32(tb_dawn[DAWN_UMDNS_PORT]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue