treewide: improve logging

Provide multi-priority syslog() based logging to improve user and
developer experience. Add dawnlog_* functions and macros to convert
printf() family and perror() logging to syslog() family. Removed
unnecessary sprintf() for building log strings (embed format directly).
Add local config settings for log level. Add command line parameters for
log level and destination. Set default log level to suppress a lot of
previously noisy messages. Restore some previously removed noisy
messages as DEBUG level in case they help in future. Eliminate DAWN_NO_OUTPUT static code checks which are no longer used.

Signed-off-by: Ian Clowes <clowes_ian@hotmail.com>
This commit is contained in:
Ian Clowes 2022-01-06 09:08:17 +01:00 committed by Nick Hainke
parent ddc007e32c
commit 4df0c986f1
18 changed files with 922 additions and 396 deletions

View file

@ -133,6 +133,8 @@ static int handle_uci_config(struct blob_attr* msg);
int parse_to_hostapd_notify(struct blob_attr* msg, hostapd_notify_entry* notify_req) {
struct blob_attr* tb[__HOSTAPD_NOTIFY_MAX];
dawnlog_debug_func("Entering...");
blobmsg_parse(hostapd_notify_policy, __HOSTAPD_NOTIFY_MAX, tb, blob_data(msg), blob_len(msg));
if (hwaddr_aton(blobmsg_data(tb[HOSTAPD_NOTIFY_BSSID_ADDR]), notify_req->bssid_addr.u8))
@ -147,10 +149,12 @@ int parse_to_hostapd_notify(struct blob_attr* msg, hostapd_notify_entry* notify_
probe_entry *parse_to_probe_req(struct blob_attr* msg) {
struct blob_attr* tb[__PROB_MAX];
dawnlog_debug_func("Entering...");
probe_entry* prob_req = dawn_malloc(sizeof(probe_entry));
if (prob_req == NULL)
{
fprintf(stderr, "dawn_malloc of probe_entry failed!\n");
dawnlog_error("dawn_malloc of probe_entry failed!\n");
return NULL;
}
@ -220,6 +224,8 @@ int handle_deauth_req(struct blob_attr* msg) {
hostapd_notify_entry notify_req;
parse_to_hostapd_notify(msg, &notify_req);
dawnlog_debug_func("Entering...");
pthread_mutex_lock(&client_array_mutex);
client* client_entry = client_array_get_client(notify_req.client_addr);
@ -228,11 +234,15 @@ int handle_deauth_req(struct blob_attr* msg) {
pthread_mutex_unlock(&client_array_mutex);
dawnlog_debug("[WC] Deauth: %s\n", "deauth");
return 0;
}
static int handle_set_probe(struct blob_attr* msg) {
dawnlog_debug_func("Entering...");
hostapd_notify_entry notify_req;
parse_to_hostapd_notify(msg, &notify_req);
@ -246,6 +256,8 @@ int handle_network_msg(char* msg) {
char* method;
char* data;
dawnlog_debug_func("Entering...");
blob_buf_init(&network_buf, 0);
blobmsg_add_json_from_string(&network_buf, msg);
@ -258,18 +270,18 @@ int handle_network_msg(char* msg) {
method = blobmsg_data(tb[NETWORK_METHOD]);
data = blobmsg_data(tb[NETWORK_DATA]);
#ifndef DAWN_NO_OUTPUT
printf("Network Method new: %s : %s\n", method, msg);
#endif
dawnlog_debug("Network Method new: %s : %s\n", method, msg);
blob_buf_init(&data_buf, 0);
blobmsg_add_json_from_string(&data_buf, data);
if (!data_buf.head) {
dawnlog_warning("Data header not formed!");
return -1;
}
if (blob_len(data_buf.head) <= 0) {
dawnlog_warning("Data header invalid length!");
return -1;
}
@ -294,15 +306,11 @@ int handle_network_msg(char* msg) {
parse_to_clients(data_buf.head, 0, 0);
}
else if (strncmp(method, "deauth", 5) == 0) {
#ifndef DAWN_NO_OUTPUT
printf("METHOD DEAUTH\n");
#endif
dawnlog_debug("METHOD DEAUTH\n");
handle_deauth_req(data_buf.head);
}
else if (strncmp(method, "setprobe", 5) == 0) {
#ifndef DAWN_NO_OUTPUT
printf("HANDLING SET PROBE!\n");
#endif
dawnlog_debug("HANDLING SET PROBE!\n");
handle_set_probe(data_buf.head);
}
else if (strncmp(method, "addmac", 5) == 0) {
@ -312,25 +320,21 @@ int handle_network_msg(char* msg) {
parse_add_mac_to_file(data_buf.head);
}
else if (strncmp(method, "uci", 2) == 0) {
#ifndef DAWN_NO_OUTPUT
printf("HANDLING UCI!\n");
#endif
dawnlog_debug("HANDLING UCI!\n");
handle_uci_config(data_buf.head);
}
else if (strncmp(method, "beacon-report", 12) == 0) {
// TODO: Check beacon report stuff
//printf("HANDLING BEACON REPORT NETWORK!\n");
//printf("The Method for beacon-report is: %s\n", method);
dawnlog_debug("HANDLING BEACON REPORT NETWORK!\n");
dawnlog_debug("The Method for beacon-report is: %s\n", method);
// ignore beacon reports send via network!, use probe functions for it
//probe_entry entry; // for now just stay at probe entry stuff...
//parse_to_beacon_rep(data_buf.head, &entry, true);
}
else
{
#ifndef DAWN_NO_OUTPUT
printf("No method fonud for: %s\n", method);
#endif
dawnlog_warning("No method found for: %s\n", method);
}
return 0;
@ -339,8 +343,10 @@ int handle_network_msg(char* msg) {
static uint8_t
dump_rrm_data(struct blob_attr* head)
{
dawnlog_debug_func("Entering...");
if (blob_id(head) != BLOBMSG_TYPE_INT32) {
fprintf(stderr, "wrong type of rrm array.\n");
dawnlog_error("wrong type of rrm array.\n");
return 0;
}
return (uint8_t)blobmsg_get_u32(head);
@ -350,6 +356,8 @@ dump_rrm_data(struct blob_attr* head)
static void
dump_client(struct blob_attr** tb, struct dawn_mac client_addr, const char* bssid_addr, uint32_t freq, uint8_t ht_supported,
uint8_t vht_supported) {
dawnlog_debug_func("Entering...");
client *client_entry = dawn_malloc(sizeof(struct client_s));
if (client_entry == NULL)
{
@ -430,6 +438,8 @@ dump_client_table(struct blob_attr* head, int len, const char* bssid_addr, uint3
struct blobmsg_hdr* hdr;
int station_count = 0;
dawnlog_debug_func("Entering...");
__blob_for_each_attr(attr, head, len)
{
hdr = blob_data(attr);
@ -453,6 +463,8 @@ dump_client_table(struct blob_attr* head, int len, const char* bssid_addr, uint3
int parse_to_clients(struct blob_attr* msg, int do_kick, uint32_t id) {
struct blob_attr* tb[__CLIENT_TABLE_MAX];
dawnlog_debug_func("Entering...");
if (!msg) {
return -1;
}
@ -682,12 +694,14 @@ static const struct blobmsg_policy uci_times_policy[__UCI_TIMES_MAX] = {
static int handle_uci_config(struct blob_attr* msg) {
dawnlog_debug_func("Entering...");
struct blob_attr* tb[__UCI_TABLE_MAX];
blobmsg_parse(uci_table_policy, __UCI_TABLE_MAX, tb, blob_data(msg), blob_len(msg));
const char *version_string = blobmsg_get_string(tb[UCI_CONFIG_VERSION]);
if (version_string == NULL || strcmp(version_string, DAWN_CONFIG_VERSION)) {
fprintf(stderr, "Ignoring network config message with incompatible version string '%s'.\n",
dawnlog_warning("Ignoring network config message with incompatible version string '%s'.\n",
version_string ? : "");
return -1;
}
@ -768,7 +782,7 @@ static int handle_uci_config(struct blob_attr* msg) {
break;
}
if (band == __DAWN_BAND_MAX) {
fprintf(stderr, "handle_uci_config: Warning: unknown band '%s'.\n", band_name);
dawnlog_warning("handle_uci_config: unknown band '%s'.\n", band_name);
continue; // Should we write the metrics of an unknown band to the config file?
}