Optimize uci reinit and config load

This commit is contained in:
Omar Kallel 2023-01-30 14:00:13 +01:00
parent 93920c80e5
commit 79322a0d95
5 changed files with 25 additions and 22 deletions

View file

@ -603,7 +603,6 @@ void cwmp_config_load()
{ {
int ret; int ret;
cwmp_uci_reinit();
ret = global_conf_init(); ret = global_conf_init();
while (ret != CWMP_OK && cwmp_stop != true) { while (ret != CWMP_OK && cwmp_stop != true) {
CWMP_LOG(DEBUG, "Error reading uci ret = %d", ret); CWMP_LOG(DEBUG, "Error reading uci ret = %d", ret);
@ -626,6 +625,7 @@ int cwmp_get_deviceid()
int cwmp_config_reload() int cwmp_config_reload()
{ {
memset(&cwmp_main->env, 0, sizeof(struct env)); memset(&cwmp_main->env, 0, sizeof(struct env));
cwmp_uci_reinit();
int err = global_conf_init(); int err = global_conf_init();
if (err != CWMP_OK) if (err != CWMP_OK)
return err; return err;

View file

@ -196,6 +196,22 @@ end:
return 0; return 0;
} }
static void configure_var_state()
{
char *zone_name = NULL;
if (!file_exists(VARSTATE_CONFIG"/cwmp"))
creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
cwmp_uci_add_section_with_specific_name("cwmp", "acs", "acs", UCI_VARSTATE_CONFIG);
cwmp_uci_add_section_with_specific_name("cwmp", "cpe", "cpe", UCI_VARSTATE_CONFIG);
get_firewall_zone_name_by_wan_iface(cwmp_main->conf.default_wan_iface, &zone_name);
cwmp_uci_set_varstate_value("cwmp", "acs", "zonename", zone_name ? zone_name : "wan");
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
}
static int cwmp_init() static int cwmp_init()
{ {
int error; int error;
@ -234,6 +250,7 @@ static int cwmp_init()
if ((error = create_cwmp_notifications_package())) if ((error = create_cwmp_notifications_package()))
return error; return error;
cwmp_uci_init();
CWMP_LOG(DEBUG, "Loading icwmpd configuration"); CWMP_LOG(DEBUG, "Loading icwmpd configuration");
cwmp_config_load(); cwmp_config_load();
@ -253,6 +270,9 @@ static int cwmp_init()
load_custom_notify_json(); load_custom_notify_json();
set_default_forced_active_parameters_notifications(); set_default_forced_active_parameters_notifications();
init_list_param_notify(); init_list_param_notify();
configure_var_state();
cwmp_uci_exit();
create_cwmp_session_structure(); create_cwmp_session_structure();
get_nonce_key(); get_nonce_key();
memset(&intf_reset_list, 0, sizeof(struct list_head)); memset(&intf_reset_list, 0, sizeof(struct list_head));
@ -338,23 +358,6 @@ void cwmp_exit()
cwmp_free(); cwmp_free();
} }
static void configure_var_state()
{
char *zone_name = NULL;
if (!file_exists(VARSTATE_CONFIG"/cwmp"))
creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
cwmp_uci_reinit();
cwmp_uci_add_section_with_specific_name("cwmp", "acs", "acs", UCI_VARSTATE_CONFIG);
cwmp_uci_add_section_with_specific_name("cwmp", "cpe", "cpe", UCI_VARSTATE_CONFIG);
get_firewall_zone_name_by_wan_iface(cwmp_main->conf.default_wan_iface, &zone_name);
cwmp_uci_set_varstate_value("cwmp", "acs", "zonename", zone_name ? zone_name : "wan");
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int error; int error;
@ -379,7 +382,6 @@ int main(int argc, char **argv)
if ((error = cwmp_root_cause_events())) if ((error = cwmp_root_cause_events()))
return error; return error;
configure_var_state();
icwmp_http_server_init(); icwmp_http_server_init();
uloop_init(); uloop_init();

View file

@ -344,7 +344,6 @@ void create_list_param_obj_notify()
struct uci_element *e = NULL; struct uci_element *e = NULL;
int i; int i;
cwmp_uci_reinit();
for (i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
int option_type; int option_type;
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif); option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif);

View file

@ -63,6 +63,7 @@ int cwmp_session_init()
cwmp_main->cwmp_cr_event = 0; cwmp_main->cwmp_cr_event = 0;
cwmp_uci_init(); cwmp_uci_init();
/* /*
* Set Required methods as initial value of * Set Required methods as initial value of
*/ */
@ -259,7 +260,6 @@ static void set_cwmp_session_status_state(int status)
if (!file_exists(VARSTATE_CONFIG"/cwmp")) if (!file_exists(VARSTATE_CONFIG"/cwmp"))
creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
cwmp_uci_reinit();
cwmp_uci_add_section_with_specific_name("cwmp", "sess_status", "sess_status", UCI_VARSTATE_CONFIG); cwmp_uci_add_section_with_specific_name("cwmp", "sess_status", "sess_status", UCI_VARSTATE_CONFIG);
switch (status) { switch (status) {
@ -329,10 +329,10 @@ void start_cwmp_session()
uloop_timeout_cancel(&check_notify_timer); uloop_timeout_cancel(&check_notify_timer);
if (cwmp_session_init() != CWMP_OK) { if (cwmp_session_init() != CWMP_OK) {
CWMP_LOG(ERROR, "Not able to init a CWMP session"); CWMP_LOG(ERROR, "Not able to init a CWMP session");
cwmp_config_load();
t = cwmp_get_retry_interval(0); t = cwmp_get_retry_interval(0);
CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t); CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t);
set_cwmp_session_status(SESSION_FAILURE, t); set_cwmp_session_status(SESSION_FAILURE, t);
cwmp_config_load();
trigger_periodic_notify_check(); trigger_periodic_notify_check();
return; return;
} }
@ -625,6 +625,7 @@ int run_session_end_func(void)
if (end_session_flag & END_SESSION_INIT_NOTIFY) { if (end_session_flag & END_SESSION_INIT_NOTIFY) {
CWMP_LOG(INFO, "SetParameterAttributes end session: reinit list notify"); CWMP_LOG(INFO, "SetParameterAttributes end session: reinit list notify");
cwmp_uci_reinit();
reinit_list_param_notify(); reinit_list_param_notify();
} }

View file

@ -55,6 +55,7 @@ static int reload_cmd(struct blob_buf *b)
blobmsg_add_u32(b, "status", 0); blobmsg_add_u32(b, "status", 0);
blobmsg_add_string(b, "info", "icwmpd config reloaded"); blobmsg_add_string(b, "info", "icwmpd config reloaded");
} }
cwmp_uci_exit();
} }
return 0; return 0;