Skip to content
Snippets Groups Projects
Commit 25356bbf authored by Jakob Olsson's avatar Jakob Olsson
Browse files

dyn-cntlr-sync: persist enabled variable between writes

parent 25d90046
No related branches found
No related tags found
1 merge request!136Dyn cntlr sync enabled
......@@ -4653,6 +4653,7 @@ int handle_hld_message(void *agent, struct cmdu_buff *rx_cmdu)
cmdu_free(cmdu);
} else if (proto == 0xac && cntlr_sync) {
struct sync_config out = {0};
char enabled[2] = {0};
dbg("*** Process dyn-controller-config-sync response ***\n");
/*
......@@ -4677,9 +4678,14 @@ int handle_hld_message(void *agent, struct cmdu_buff *rx_cmdu)
return ret;
}
agent_get_controller_enabled(a, enabled);
ret = writeto_configfile("/etc/config/mapcontroller", out.data, out.len);
if (ret)
fprintf(stderr, "failed to write file\n");
set_value_by_string("mapcontroller", "controller", "enabled",
enabled, UCI_TYPE_STRING);
}
#endif /* AGENT_SYNC_DYNAMIC_CNTLR_CONFIG */
......
......@@ -249,6 +249,39 @@ out_pkg:
}
#endif
/* expects buf to len 2 */
char *agent_get_controller_enabled(struct agent *a, char *buf)
{
struct uci_context *ctx;
struct uci_ptr ptr = {0};
int ret = -1;
ctx = uci_alloc_context();
if (!ctx)
return -1;
ptr.package = "mapcontroller";
ptr.section = "controller";
ptr.option = "enabled";
ptr.target = UCI_TYPE_OPTION;
ret = uci_lookup_ptr(ctx, &ptr, NULL, false);
if (ret != UCI_OK ||!(ptr.flags & UCI_LOOKUP_DONE)) {
goto error;
}
if (ptr.flags & UCI_LOOKUP_COMPLETE) {
/* option found */
strncpy(buf, ptr.o->v.string, 1);
}
uci_unload(ctx, ptr.p);
error:
uci_free_context(ctx);
return ret;
}
int wifi_get_iface_bssid(char *ifname, uint8_t *bssid)
{
struct uci_context *ctx = NULL;
......
......@@ -222,6 +222,7 @@ int set_value(struct uci_context *ctx, struct uci_package *pkg,
const char *value, enum uci_option_type type);
int set_value_by_string(const char *package, const char *section,
const char *key, const char *value, enum uci_option_type type);
char *agent_get_controller_enabled(struct agent *a, char *buf);
struct uci_section *config_get_iface_section(struct uci_context *ctx,
struct uci_package *pkg, const char *type, const char *ifname);
bool uci_reload_services(char *services);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment