wifi-2069: Fix opensync vifS synchronization

- Make sure that uci_context used while loading a UCI is exclusive at
   any given time.
 - Some other improvements in the same area.

Signed-off-by: Yashvardhan <yashvardhan@netexperience.com>
This commit is contained in:
Yashvardhan
2021-05-07 00:36:39 -07:00
committed by Rick Sommerville
parent 49383f1c01
commit 63f602a136
7 changed files with 98 additions and 70 deletions

View File

@@ -215,6 +215,7 @@ pid_t cmd_handler_tcpdump_wifi(struct task *task)
char *argv[] = { "/usr/sbin/tcpdump", "-c", "1000", "-G", duration, "-W", "1", "-w", pcap, "-i", phy, NULL };
char iw[128];
pid_t pid;
int ret = 0;
task->arg = SCHEMA_KEY_VAL(task->conf.payload, "wifi");
if (!task->arg) {
@@ -225,15 +226,23 @@ pid_t cmd_handler_tcpdump_wifi(struct task *task)
blob_buf_init(&b, 0);
uci = uci_alloc_context();
uci_load(uci, "wireless", &p);
ret = uci_load(uci, "wireless", &p);
if (ret) {
LOGE("%s: uci_load() failed with rc %d", __func__, ret);
uci_free_context(uci);
return -1;
}
s = uci_lookup_section(uci, p, task->arg);
if (!s) {
task_status(task, TASK_FAILED, "unknown wifi");
uci_unload(uci, p);
uci_free_context(uci);
return -1;
}
uci_to_blob(&b, s, &phy_param);
uci_unload(uci, p);
uci_free_context(uci);
blobmsg_parse(phy_policy, __PHY_ATTR_MAX, tb, blob_data(b.head), blob_len(b.head));

View File

@@ -88,9 +88,14 @@ static void syslog_state(int config)
struct uci_element *e = NULL;
struct uci_section *s = NULL;
char val[128];
int ret = 0;
blob_buf_init(&b, 0);
uci_load(uci, "system", &system);
ret = uci_load(uci, "system", &system);
if (ret) {
LOGE("%s: uci_load() failed with rc %d", __func__, ret);
return;
}
uci_foreach_element(&system->sections, e) {
s = uci_to_section(e);
if (!strcmp(s->type, "system"))
@@ -179,14 +184,20 @@ static void ntp_state(int config)
struct uci_section *s;
struct blob_attr *cur = NULL;
char val[128] = {};
int first = 1, rem = 0;
int first = 1, rem = 0, ret = 0;
blob_buf_init(&b, 0);
uci_load(uci, "system", &p);
ret = uci_load(uci, "system", &p);
if (ret) {
LOGE("%s: uci_load() failed with rc %d", __func__, ret);
return;
}
s = uci_lookup_section(uci, p, "ntp");
if (!s)
if (!s) {
uci_unload(uci, p);
return;
}
uci_to_blob(&b, s, &ntp_param);
blobmsg_parse(ntp_policy, __NTP_ATTR_MAX, tb, blob_data(b.head), blob_len(b.head));

View File

@@ -501,25 +501,30 @@ void opennds_parameters(char *ifname)
void opennds_section_del(char *section_name)
{
struct uci_package *opennds;
struct uci_context *nds_ctx;
struct uci_element *e = NULL, *tmp = NULL;
int ret=0;
int ret = 0;
ret= uci_load(uci, "opennds", &opennds);
nds_ctx = uci_alloc_context();
ret = uci_load(nds_ctx, "opennds", &opennds);
if (ret) {
LOGD("%s: uci_load() failed with rc %d", section_name, ret);
LOGE("%s: %s uci_load() failed with rc %d", section_name, __func__, ret);
uci_free_context(nds_ctx);
return;
}
uci_foreach_element_safe(&opennds->sections, tmp, e) {
struct uci_section *s = uci_to_section(e);
if (!strcmp(s->e.name, section_name)) {
uci_section_del(uci, "vif", "opennds", (char *)s->e.name, section_name);
uci_section_del(nds_ctx, "vif", "opennds", (char *)s->e.name, section_name);
}
else {
continue;
}
}
uci_commit(uci, &opennds, false);
uci_unload(uci, opennds);
uci_commit(nds_ctx, &opennds, false);
uci_unload(nds_ctx, opennds);
uci_free_context(nds_ctx);
reload_config = 1;
}

View File

@@ -34,7 +34,7 @@ ovsdb_table_t table_Hotspot20_Icon_Config;
ovsdb_table_t table_APC_Config;
ovsdb_table_t table_APC_State;
unsigned int radproxy_apc;
unsigned int radproxy_apc = 0;
static struct uci_package *wireless;
struct uci_context *uci;
@@ -445,6 +445,7 @@ static void periodic_task(void *arg)
{
static int counter = 0;
struct uci_element *e = NULL, *tmp = NULL;
int ret = 0;
if ((counter % 15) && !reload_config)
goto done;
@@ -468,9 +469,12 @@ static void periodic_task(void *arg)
system("reload_config");
}
LOGT("periodic: start state update ");
uci_load(uci, "wireless", &wireless);
LOGD("periodic: start state update ");
ret = uci_load(uci, "wireless", &wireless);
if (ret) {
LOGE("%s: uci_load() failed with rc %d", __func__, ret);
return;
}
uci_foreach_element_safe(&wireless->sections, tmp, e) {
struct uci_section *s = uci_to_section(e);
@@ -485,7 +489,7 @@ static void periodic_task(void *arg)
vif_state_update(s, NULL);
}
uci_unload(uci, wireless);
LOGT("periodic: stop state update ");
LOGD("periodic: stop state update ");
done:
counter++;
@@ -691,36 +695,26 @@ const struct uci_blob_param_list apc_param = {
void APC_config_update(struct schema_APC_Config *conf)
{
struct uci_package *apc;
struct blob_buf apcb = { };
int rc = 0;
struct uci_context *apc_uci;
LOGD("APC: APC_config_update");
rc = uci_load(uci, "apc", &apc);
if (rc)
{
LOGD("%s: uci_load failed with rc %d", __func__, rc);
}
apc_uci = uci_alloc_context();
blob_buf_init(&apcb, 0);
if (conf->enabled_changed) {
if (conf->enabled == true) {
blobmsg_add_bool(&apcb, "enabled", 1);
system("/etc/init.d/apc start");
}
else {
} else {
blobmsg_add_bool(&apcb, "enabled", 0);
system("/etc/init.d/apc stop");
}
}
blob_to_uci_section(uci, "apc", "apc", "apc",
blob_to_uci_section(apc_uci, "apc", "apc", "apc",
apcb.head, &apc_param, NULL);
uci_commit(uci, &apc, false);
uci_unload(uci, apc);
uci_commit_all(apc_uci);
uci_free_context(apc_uci);
}
static void callback_APC_Config(ovsdb_update_monitor_t *mon,

View File

@@ -362,22 +362,27 @@ static bool radius_proxy_config_set(struct schema_Radius_Proxy_Config *conf )
static bool radius_proxy_config_delete()
{
struct uci_package *radsecproxy;
struct uci_context *rad_uci;
struct uci_element *e = NULL, *tmp = NULL;
int ret=0;
int ret = 0;
ret= uci_load(uci, "radsecproxy", &radsecproxy);
rad_uci = uci_alloc_context();
ret = uci_load(rad_uci, "radsecproxy", &radsecproxy);
if (ret) {
LOGD("%s: uci_load() failed with rc %d", __func__, ret);
LOGE("%s: uci_load() failed with rc %d", __func__, ret);
uci_free_context(rad_uci);
return false;
}
uci_foreach_element_safe(&radsecproxy->sections, tmp, e) {
struct uci_section *s = uci_to_section(e);
if ((s == NULL) || (s->type == NULL)) continue;
uci_section_del(uci, "radsecproxy", "radsecproxy",
uci_section_del(rad_uci, "radsecproxy", "radsecproxy",
(char *)s->e.name, s->type);
}
uci_commit(uci, &radsecproxy, false);
uci_unload(uci, radsecproxy);
uci_commit(rad_uci, &radsecproxy, false);
uci_unload(rad_uci, radsecproxy);
uci_free_context(rad_uci);
reload_config = 1;
return true;
}

View File

@@ -210,8 +210,10 @@ int uci_section_to_blob(struct uci_context *uci, char *package, char *section,
if (uci_load(uci, package, &p))
p = uci_lookup_package(uci, package);
if (!p)
if (!p) {
uci_unload(uci, p);
return -1;
}
s = uci_lookup_section(uci, p, section);
if (!s)
goto out;

View File

@@ -1020,30 +1020,31 @@ size_t write_file(void *ptr, size_t size, size_t nmemb, FILE *stream) {
void vif_section_del(char *section_name)
{
struct uci_package *wireless;
struct uci_context *sec_ctx;
struct uci_element *e = NULL, *tmp = NULL;
int ret=0;
ret= uci_load(uci, "wireless", &wireless);
sec_ctx = uci_alloc_context();
ret= uci_load(sec_ctx, "wireless", &wireless);
if (ret) {
LOGD("%s: uci_load() failed with rc %d", section_name, ret);
LOGE("%s: %s uci_load() failed with rc %d", section_name, __func__, ret);
uci_free_context(sec_ctx);
return;
}
uci_foreach_element_safe(&wireless->sections, tmp, e) {
struct uci_section *s = uci_to_section(e);
if ((s == NULL) || (s->type == NULL)) continue;
if (!strcmp(s->type, section_name)) {
uci_section_del(uci, "vif", "wireless", (char *)s->e.name, section_name);
uci_section_del(sec_ctx, "vif", "wireless", (char *)s->e.name, section_name);
}
else {
continue;
}
}
uci_commit(uci, &wireless, false);
uci_unload(uci, wireless);
uci_commit(sec_ctx, &wireless, false);
uci_unload(sec_ctx, wireless);
uci_free_context(sec_ctx);
reload_config = 1;
}
static void vif_check_radius_proxy()
@@ -1063,12 +1064,10 @@ static void vif_check_radius_proxy()
}
uci_ctx = uci_alloc_context();
rc = uci_load(uci_ctx, "wireless", &wireless);
if (rc)
{
LOGD("%s: uci_load() failed with rc %d", __func__, rc);
if (rc) {
LOGE("%s: uci_load() failed with rc %d", __func__, rc);
goto free;
}
@@ -1334,14 +1333,17 @@ static void hs20_vif_config(struct blob_buf *b,
bool target_vif_config_del(const struct schema_Wifi_VIF_Config *vconf)
{
struct uci_package *wireless;
struct uci_context *vif_ctx;
struct uci_element *e = NULL, *tmp = NULL;
const char *ifname;
int ret=0;
int ret = 0;
vlan_del((char *)vconf->if_name);
ret= uci_load(uci, "wireless", &wireless);
vif_ctx = uci_alloc_context();
ret= uci_load(vif_ctx, "wireless", &wireless);
if (ret) {
LOGD("%s: uci_load() failed with rc %d", vconf->if_name, ret);
LOGE("%s: %s uci_load() failed with rc %d", vconf->if_name, __func__, ret);
uci_free_context(vif_ctx);
return false;
}
uci_foreach_element_safe(&wireless->sections, tmp, e) {
@@ -1349,14 +1351,15 @@ bool target_vif_config_del(const struct schema_Wifi_VIF_Config *vconf)
if ((s == NULL) || (s->type == NULL)) continue;
if (strcmp(s->type, "wifi-iface")) continue;
ifname = uci_lookup_option_string( uci, s, "ifname" );
ifname = uci_lookup_option_string( vif_ctx, s, "ifname" );
if (!strcmp(ifname,vconf->if_name)) {
uci_section_del(uci, "vif", "wireless", (char *)s->e.name, "wifi-iface");
uci_section_del(vif_ctx, "vif", "wireless", (char *)s->e.name, "wifi-iface");
break;
}
}
uci_commit(uci, &wireless, false);
uci_unload(uci, wireless);
uci_commit(vif_ctx, &wireless, false);
uci_unload(vif_ctx, wireless);
uci_free_context(vif_ctx);
reload_config = 1;
return true;
}
@@ -1549,7 +1552,6 @@ static int ap_vif_config_set(const struct schema_Wifi_Radio_Config *rconf,
blob_buf_init(&b, 0);
blob_buf_init(&del,0);
blobmsg_add_string(&b, "ifname", vconf->if_name);
blobmsg_add_string(&b, "device", rconf->if_name);
blobmsg_add_string(&b, "mode", "ap");