mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
datastorage: improve linked list
- Simplify linked list search - code was unnecessarily complex for no benefit - Adjust some MAC address handling to simplify code [cleanup commit message] Signed-off-by: Nick Hainke <vincent@systemli.org>
This commit is contained in:
parent
160ccf8917
commit
6e03e37ce8
6 changed files with 53 additions and 131 deletions
|
|
@ -6,6 +6,9 @@
|
|||
#include "utils.h"
|
||||
#include "mac_utils.h"
|
||||
|
||||
// Used as a filler where a value is required but not used functionally
|
||||
const struct dawn_mac dawn_mac_null = { .u8 = {0,0,0,0,0,0} };
|
||||
|
||||
// source: https://elixir.bootlin.com/linux/v4.9/source/lib/hexdump.c#L28
|
||||
// based on: hostapd src/utils/common.c
|
||||
int hwaddr_aton(const char* txt, uint8_t* addr) {
|
||||
|
|
@ -46,6 +49,22 @@ int hwaddr_aton(const char* txt, uint8_t* addr) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct dawn_mac str2mac(char* s)
|
||||
{
|
||||
// Return something testable if sscanf() fails
|
||||
struct dawn_mac tmp_mac = { .u8 = {0,0,0,0,0,0} };
|
||||
|
||||
// Need to scanf to an array of ints as there is no byte format specifier
|
||||
int tmp_int_mac[ETH_ALEN];
|
||||
if (sscanf(s, MACSTR, STR2MAC(tmp_int_mac)) == 6)
|
||||
{
|
||||
for (int i = 0; i < ETH_ALEN; ++i)
|
||||
tmp_mac.u8[i] = (uint8_t)tmp_int_mac[i];
|
||||
}
|
||||
|
||||
return tmp_mac;
|
||||
}
|
||||
|
||||
void write_mac_to_file(char* path, struct dawn_mac addr) {
|
||||
FILE* f = fopen(path, "a");
|
||||
if (f == NULL)
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ bool discard_entry = true;
|
|||
if (dawn_metric.eval_auth_req <= 0) {
|
||||
dawnlog_trace("Allow authentication due to not evaluating requests");
|
||||
}
|
||||
else if (mac_in_maclist(auth_req->client_addr)) {
|
||||
else if (mac_find_entry(auth_req->client_addr)) {
|
||||
dawnlog_trace("Allow authentication due to mac_in_maclist()");
|
||||
}
|
||||
else {
|
||||
|
|
@ -389,12 +389,6 @@ bool discard_entry = true;
|
|||
dawnlog_trace("Deny authentication due to no probe entry");
|
||||
deny_request = 1;
|
||||
}
|
||||
#if 0
|
||||
// Already know this is false from outer test above
|
||||
else if (mac_in_maclist(probe_req_updated->client_addr)) {
|
||||
dawnlog_trace("Short cut due to mac_in_maclist()");
|
||||
}
|
||||
#endif
|
||||
else if (tmp->counter < dawn_metric.min_probe_count) {
|
||||
dawnlog_trace("Deny authentication due to low probe count");
|
||||
deny_request = 1;
|
||||
|
|
@ -447,7 +441,7 @@ int discard_entry = true;
|
|||
if (dawn_metric.eval_assoc_req <= 0) {
|
||||
dawnlog_trace("Allow association due to not evaluating requests");
|
||||
}
|
||||
else if (mac_in_maclist(assoc_req->client_addr)) {
|
||||
else if (mac_find_entry(assoc_req->client_addr)) {
|
||||
dawnlog_trace("Allow association due to mac_in_maclist()");
|
||||
} else {
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
|
|
@ -467,12 +461,6 @@ int discard_entry = true;
|
|||
dawnlog_trace("Deny association due to no probe entry found");
|
||||
deny_request = 1;
|
||||
}
|
||||
#if 0
|
||||
// Already know this is false from outer test above
|
||||
else if (mac_in_maclist(tmp->client_addr)) {
|
||||
dawnlog_trace("Allow due to mac_in_maclist()");
|
||||
}
|
||||
#endif
|
||||
else if (tmp->counter < dawn_metric.min_probe_count) {
|
||||
dawnlog_trace("Deny association due to low probe count");
|
||||
deny_request = 1;
|
||||
|
|
@ -539,7 +527,7 @@ static int handle_probe_req(struct blob_attr* msg) {
|
|||
if (dawn_metric.eval_probe_req <= 0) {
|
||||
dawnlog_trace("Allow probe due to not evaluating requests");
|
||||
}
|
||||
else if (mac_in_maclist(probe_req_updated->client_addr)) {
|
||||
else if (mac_find_entry(probe_req_updated->client_addr)) {
|
||||
dawnlog_trace("Allow probe due to mac_in_maclist()");
|
||||
}
|
||||
else if (probe_req_updated->counter < dawn_metric.min_probe_count) {
|
||||
|
|
@ -1295,7 +1283,8 @@ int parse_add_mac_to_file(struct blob_attr *msg) {
|
|||
struct dawn_mac addr;
|
||||
hwaddr_aton(blobmsg_data(attr), addr.u8);
|
||||
|
||||
if (insert_to_maclist(addr) == 0) {
|
||||
// Returns item if it was new and added
|
||||
if (insert_to_maclist(addr)) {
|
||||
// TODO: File can grow arbitarily large. Resource consumption risk.
|
||||
// TODO: Consolidate use of file across source: shared resource for name, single point of access?
|
||||
write_mac_to_file("/tmp/dawn_mac_list", addr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue