mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-02-14 17:51:51 +00:00
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 <cotequeiroz@gmail.com>
This commit is contained in:
parent
a7a830950a
commit
1e34357bdc
3 changed files with 15 additions and 0 deletions
|
@ -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?
|
||||
|
|
|
@ -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]));
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue