From f25ebe658f178d7d32fd837e40669c4b6a613ea8 Mon Sep 17 00:00:00 2001 From: Eneas U de Queiroz Date: Thu, 5 Aug 2021 10:55:51 -0300 Subject: [PATCH] Verify compatibility before parsing config message This adds a verion field to the ubus configuration message, to avoid acting upon a message from an incompatible version of dawn. Signed-off-by: Eneas U de Queiroz --- src/include/datastorage.h | 5 +++++ src/utils/msghandler.c | 9 +++++++++ src/utils/ubus.c | 1 + 3 files changed, 15 insertions(+) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 2553359..96f073c 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -52,6 +52,11 @@ void mac_array_delete(struct mac_entry_s* entry); // ---------------- Global variables ---------------- /*** Metrics and configuration data ***/ +// TODO: Define a proper version string +#ifndef DAWN_CONFIG_VERSION +#define DAWN_CONFIG_VERSION "1" +#endif + // ---------------- Structs ---------------- struct probe_metric_s { int ap_weight; // TODO: Never evaluated? diff --git a/src/utils/msghandler.c b/src/utils/msghandler.c index e27230b..c033ab7 100644 --- a/src/utils/msghandler.c +++ b/src/utils/msghandler.c @@ -553,6 +553,7 @@ int parse_to_clients(struct blob_attr* msg, int do_kick, uint32_t id) { } enum { + UCI_CONFIG_VERSION, UCI_TABLE_METRIC, UCI_TABLE_TIMES, __UCI_TABLE_MAX @@ -605,6 +606,7 @@ enum { }; static const struct blobmsg_policy uci_table_policy[__UCI_TABLE_MAX] = { + [UCI_CONFIG_VERSION ] = {.name = "version", .type = BLOBMSG_TYPE_STRING}, [UCI_TABLE_METRIC] = {.name = "metric", .type = BLOBMSG_TYPE_TABLE}, [UCI_TABLE_TIMES] = {.name = "times", .type = BLOBMSG_TYPE_TABLE} }; @@ -658,6 +660,13 @@ static int handle_uci_config(struct blob_attr* msg) { 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", + version_string ? : ""); + return -1; + } + struct blob_attr* tb_metric[__UCI_METIC_MAX]; blobmsg_parse(uci_metric_policy, __UCI_METIC_MAX, tb_metric, blobmsg_data(tb[UCI_TABLE_METRIC]), blobmsg_len(tb[UCI_TABLE_METRIC])); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 6af745d..eccae24 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -1366,6 +1366,7 @@ int uci_send_via_network() void *metric, *times; blob_buf_init(&b, 0); + blobmsg_add_string(&b, "version", DAWN_CONFIG_VERSION); metric = blobmsg_open_table(&b, "metric"); blobmsg_add_u32(&b, "ht_support", dawn_metric.ht_support); blobmsg_add_u32(&b, "vht_support", dawn_metric.vht_support);