mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
Align with configd changes
This commit is contained in:
parent
b4db243c1d
commit
c4b0fa4272
6 changed files with 157 additions and 67 deletions
156
src/common.c
156
src/common.c
|
|
@ -354,6 +354,46 @@ void cwmp_free_all_list_param_fault(struct list_head *list_param_fault)
|
|||
}
|
||||
}
|
||||
|
||||
void cwmp_add_modified_uci_list(const char *config_file)
|
||||
{
|
||||
path_list_t *node = NULL;
|
||||
bool exists = false;
|
||||
|
||||
if (modified_uci_list == NULL || CWMP_STRLEN(config_file) == 0)
|
||||
return;
|
||||
|
||||
list_for_each_entry(node, modified_uci_list, list) {
|
||||
if (CWMP_STRCMP(node->path, config_file) == 0) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (exists)
|
||||
return;
|
||||
|
||||
node = (path_list_t *)calloc(1, sizeof(path_list_t));
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
list_add_tail(&node->list, modified_uci_list);
|
||||
|
||||
snprintf(node->path, sizeof(node->path), "%s", config_file);
|
||||
}
|
||||
|
||||
void cwmp_free_modified_uci_list(void)
|
||||
{
|
||||
path_list_t *node = NULL, *tmp = NULL;
|
||||
|
||||
list_for_each_entry_safe(node, tmp, modified_uci_list, list) {
|
||||
list_del(&node->list);
|
||||
free(node);
|
||||
}
|
||||
|
||||
FREE(modified_uci_list);
|
||||
}
|
||||
|
||||
|
||||
int icwmp_asprintf(char **s, const char *format, ...)
|
||||
{
|
||||
int size;
|
||||
|
|
@ -634,6 +674,49 @@ void icwmp_cleanmem()
|
|||
/*
|
||||
* Services Management
|
||||
*/
|
||||
void icwmp_init_critical_services()
|
||||
{
|
||||
struct blob_buf critical_bb;
|
||||
|
||||
memset(&critical_bb, 0, sizeof(struct blob_buf));
|
||||
blob_buf_init(&critical_bb, 0);
|
||||
blobmsg_add_json_from_file(&critical_bb, CRITICAL_DEF_JSON);
|
||||
|
||||
struct blob_attr *service = NULL, *cur = NULL;
|
||||
int rem1 = 0, rem2 = 0;
|
||||
|
||||
blobmsg_for_each_attr(cur, critical_bb.head, rem1) {
|
||||
const char *name = blobmsg_name(cur);
|
||||
|
||||
if ((CWMP_STRCMP(name, "cwmp") == 0) && (blobmsg_type(cur) == BLOBMSG_TYPE_ARRAY)) {
|
||||
blobmsg_for_each_attr(service, cur, rem2) {
|
||||
bool ret = false;
|
||||
char *config_name = blobmsg_get_string(service);
|
||||
|
||||
struct cwmp_services *serv = NULL;
|
||||
list_for_each_entry(serv, &critical_service_list, list) {
|
||||
if (CWMP_STRCMP(config_name, serv->service) == 0) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == true)
|
||||
continue;
|
||||
|
||||
serv = (struct cwmp_services *)malloc(sizeof(struct cwmp_services));
|
||||
if (serv) {
|
||||
list_add_tail(&serv->list, &critical_service_list);
|
||||
serv->service = CWMP_STRDUP(config_name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
blob_buf_free(&critical_bb);
|
||||
}
|
||||
|
||||
void icwmp_free_critical_services()
|
||||
{
|
||||
struct cwmp_services *serv = NULL, *node = NULL;
|
||||
|
|
@ -710,12 +793,16 @@ static void __apply_services(struct bbf_config *args, struct list_head *service_
|
|||
|
||||
CWMP_LOG(DEBUG, "Detected service: %s will be restarted", config_name);
|
||||
|
||||
if (CWMP_STRCMP(config_name, "cwmp") == 0) {
|
||||
if (CWMP_STRCMP(config_name, "/etc/config/cwmp") == 0) {
|
||||
apply_cwmp_changes(args->is_commit);
|
||||
list_del(&iter->list);
|
||||
FREE(iter);
|
||||
continue;
|
||||
}
|
||||
|
||||
blobmsg_add_string(&bb, NULL, config_name);
|
||||
list_del(&iter->list);
|
||||
FREE(iter);
|
||||
}
|
||||
|
||||
blobmsg_close_array(&bb, array);
|
||||
|
|
@ -731,80 +818,15 @@ static void __apply_services(struct bbf_config *args, struct list_head *service_
|
|||
}
|
||||
}
|
||||
|
||||
static void _updated_services_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *cur, *tb[2] = {0};
|
||||
const struct blobmsg_policy p[2] = {
|
||||
{ "configs", BLOBMSG_TYPE_ARRAY },
|
||||
{ "critical_services", BLOBMSG_TYPE_ARRAY }
|
||||
};
|
||||
int rem = 0;
|
||||
|
||||
if (msg == NULL || req == NULL)
|
||||
return;
|
||||
|
||||
struct list_head *service_list = (struct list_head *)req->priv;
|
||||
|
||||
blobmsg_parse(p, 2, tb, blobmsg_data(msg), blobmsg_len(msg));
|
||||
|
||||
if (!tb[0])
|
||||
return;
|
||||
|
||||
blobmsg_for_each_attr(cur, tb[0], rem) {
|
||||
|
||||
if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
|
||||
continue;
|
||||
|
||||
char *config_name = blobmsg_get_string(cur);
|
||||
if (CWMP_STRLEN(config_name)) {
|
||||
add_path_list(service_list, config_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (list_empty(&critical_service_list) && tb[1]) {
|
||||
blobmsg_for_each_attr(cur, tb[1], rem) {
|
||||
if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
|
||||
continue;
|
||||
|
||||
char *serv_name = blobmsg_get_string(cur);
|
||||
if (CWMP_STRLEN(serv_name) == 0)
|
||||
continue;
|
||||
|
||||
struct cwmp_services *serv = (struct cwmp_services *)malloc(sizeof(struct cwmp_services));
|
||||
if (serv == NULL) {
|
||||
CWMP_LOG(ERROR, "Failed to alloc memory for service list");
|
||||
break;
|
||||
}
|
||||
|
||||
CWMP_MEMSET(serv, 0, sizeof(struct cwmp_services));
|
||||
serv->service = CWMP_STRDUP(serv_name);
|
||||
INIT_LIST_HEAD(&serv->list);
|
||||
list_add(&serv->list, &critical_service_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void icwmp_restart_services(int type, bool is_commit, bool monitor)
|
||||
{
|
||||
struct blob_buf bb = {0};
|
||||
struct bbf_config args = {
|
||||
.is_commit = is_commit,
|
||||
.monitor = monitor,
|
||||
.type = type
|
||||
};
|
||||
LIST_HEAD(service_list);
|
||||
|
||||
memset(&bb, 0, sizeof(struct blob_buf));
|
||||
|
||||
blob_buf_init(&bb, 0);
|
||||
|
||||
blobmsg_add_string(&bb, "proto", "cwmp");
|
||||
|
||||
icwmp_ubus_invoke("bbf.config", "changes", bb.head, _updated_services_cb, &service_list);
|
||||
__apply_services(&args, &service_list);
|
||||
free_path_list(&service_list);
|
||||
|
||||
blob_buf_free(&bb);
|
||||
__apply_services(&args, modified_uci_list);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@
|
|||
#define DM_PPP_INTERFACE_PATH "Device\\.PPP\\.Interface\\."
|
||||
#define DM_IP_INTERFACE_PATH "Device\\.IP\\.Interface\\."
|
||||
#define DEFAULT_CR_TIMEOUT 5 /* In Seconds */
|
||||
#define CRITICAL_DEF_JSON "/etc/bbfdm/critical_services.json"
|
||||
|
||||
#define foreach_elt_in_strlist(elt, str, delim) \
|
||||
char *tmpchr; \
|
||||
|
|
@ -94,6 +95,7 @@ extern struct uloop_timeout periodic_session_timer;
|
|||
extern struct uloop_timeout retry_session_timer;
|
||||
extern struct list_head intf_reset_list;
|
||||
extern struct list_head force_inform_list;
|
||||
extern struct list_head *modified_uci_list;
|
||||
|
||||
enum service_apply_type {
|
||||
RELOAD_END_SESSION,
|
||||
|
|
@ -697,6 +699,7 @@ void *cwmp_memset(void *src, int val, size_t size, const char *origin, int pos);
|
|||
void *cwmp_memcpy(void *dst, const void *src, size_t size, const char *origin, int pos);
|
||||
int regex_replace(char **str, const char *pattern, const char *replace, int *match_count);
|
||||
void stop_service(void);
|
||||
void icwmp_init_critical_services(void);
|
||||
void icwmp_free_critical_services(void);
|
||||
bool end_session_reload_service(const char *service);
|
||||
bool end_session_reload_pending(void);
|
||||
|
|
@ -704,4 +707,6 @@ void add_path_list(struct list_head *list, char *str);
|
|||
void free_path_list(struct list_head *list);
|
||||
void apply_allowed_cr_ip_port(void);
|
||||
int get_random_cpe_port(void);
|
||||
void cwmp_add_modified_uci_list(const char *config_file);
|
||||
void cwmp_free_modified_uci_list(void);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -347,6 +347,8 @@ int main(int argc, char **argv)
|
|||
return error;
|
||||
}
|
||||
|
||||
icwmp_init_critical_services();
|
||||
|
||||
trigger_cwmp_session_timer();
|
||||
|
||||
intiate_heartbeat_procedures();
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
return "9003";
|
||||
|
||||
LIST_HEAD(faults_list);
|
||||
modified_uci_list = (struct list_head *)malloc(sizeof(struct list_head));
|
||||
INIT_LIST_HEAD(modified_uci_list);
|
||||
|
||||
int fault_idx = cwmp_set_parameter_value(in.first_input, in.second_input, NULL, &faults_list);
|
||||
if (fault_idx != FAULT_CPE_NO_FAULT) {
|
||||
|
|
@ -96,6 +98,7 @@ char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
icwmp_asprintf(&fault, "%d", res->obj_res.fault_code);
|
||||
|
||||
icwmp_restart_services(RELOAD_END_SESSION, false, false);
|
||||
cwmp_free_modified_uci_list();
|
||||
|
||||
return fault;
|
||||
}
|
||||
|
|
@ -103,6 +106,7 @@ char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
set_rpc_parameter_key(in.third_input);
|
||||
|
||||
icwmp_restart_services(RELOAD_END_SESSION, true, false);
|
||||
cwmp_free_modified_uci_list();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -126,6 +130,9 @@ char *cmd_add_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
if (in.first_input == NULL)
|
||||
return "9003";
|
||||
|
||||
modified_uci_list = (struct list_head *)malloc(sizeof(struct list_head));
|
||||
INIT_LIST_HEAD(modified_uci_list);
|
||||
|
||||
bool status = cwmp_add_object(in.first_input, &res->obj_res);
|
||||
if (!status) {
|
||||
char *fault = NULL;
|
||||
|
|
@ -133,6 +140,7 @@ char *cmd_add_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
icwmp_asprintf(&fault, "%d", res->obj_res.fault_code);
|
||||
|
||||
icwmp_restart_services(RELOAD_END_SESSION, false, false);
|
||||
cwmp_free_modified_uci_list();
|
||||
|
||||
return fault;
|
||||
}
|
||||
|
|
@ -140,6 +148,7 @@ char *cmd_add_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
set_rpc_parameter_key(in.second_input);
|
||||
|
||||
icwmp_restart_services(RELOAD_END_SESSION, true, false);
|
||||
cwmp_free_modified_uci_list();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -176,6 +185,9 @@ char *cmd_del_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
if (in.first_input == NULL)
|
||||
return "9003";
|
||||
|
||||
modified_uci_list = (struct list_head *)malloc(sizeof(struct list_head));
|
||||
INIT_LIST_HEAD(modified_uci_list);
|
||||
|
||||
bool status = cwmp_delete_object(in.first_input, &res->obj_res);
|
||||
if (!status) {
|
||||
char *fault = NULL;
|
||||
|
|
@ -183,6 +195,7 @@ char *cmd_del_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
icwmp_asprintf(&fault, "%d", res->obj_res.fault_code);
|
||||
|
||||
icwmp_restart_services(RELOAD_END_SESSION, false, false);
|
||||
cwmp_free_modified_uci_list();
|
||||
|
||||
return fault;
|
||||
}
|
||||
|
|
@ -190,6 +203,7 @@ char *cmd_del_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
set_rpc_parameter_key(in.second_input);
|
||||
|
||||
icwmp_restart_services(RELOAD_END_SESSION, true, false);
|
||||
cwmp_free_modified_uci_list();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,21 @@ static struct blob_attr *get_results_array(struct blob_attr *msg)
|
|||
return tb[0];
|
||||
}
|
||||
|
||||
static struct blob_attr *get_modified_uci_array(struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *tb[1] = {0};
|
||||
const struct blobmsg_policy p[1] = {
|
||||
{ "modified_uci", BLOBMSG_TYPE_ARRAY }
|
||||
};
|
||||
|
||||
if (msg == NULL)
|
||||
return NULL;
|
||||
|
||||
blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg));
|
||||
|
||||
return tb[0];
|
||||
}
|
||||
|
||||
static void prepare_optional_table(struct blob_buf *b)
|
||||
{
|
||||
void *table = blobmsg_open_table(b, "optional");
|
||||
|
|
@ -680,6 +695,15 @@ static void ubus_set_value_callback(struct ubus_request *req, int type __attribu
|
|||
return;
|
||||
|
||||
struct setm_values_res *result = (struct setm_values_res *)req->priv;
|
||||
|
||||
struct blob_attr *modified_uci = get_modified_uci_array(msg);
|
||||
if (modified_uci) {
|
||||
blobmsg_for_each_attr(cur, modified_uci, rem) {
|
||||
char *config_name = blobmsg_get_string(cur);
|
||||
cwmp_add_modified_uci_list(config_name);
|
||||
}
|
||||
}
|
||||
|
||||
struct blob_attr *parameters = get_results_array(msg);
|
||||
|
||||
if (parameters == NULL) {
|
||||
|
|
@ -687,6 +711,8 @@ static void ubus_set_value_callback(struct ubus_request *req, int type __attribu
|
|||
return;
|
||||
}
|
||||
|
||||
cur = NULL;
|
||||
rem = 0;
|
||||
blobmsg_for_each_attr(cur, parameters, rem) {
|
||||
struct blob_attr *tb[4] = {0};
|
||||
|
||||
|
|
@ -801,6 +827,15 @@ static void ubus_objects_callback(struct ubus_request *req, int type __attribute
|
|||
return;
|
||||
|
||||
struct object_result *result = (struct object_result *)req->priv;
|
||||
|
||||
struct blob_attr *modified_uci = get_modified_uci_array(msg);
|
||||
if (modified_uci) {
|
||||
blobmsg_for_each_attr(cur, modified_uci, rem) {
|
||||
char *config_name = blobmsg_get_string(cur);
|
||||
cwmp_add_modified_uci_list(config_name);
|
||||
}
|
||||
}
|
||||
|
||||
struct blob_attr *objects = get_results_array(msg);
|
||||
|
||||
if (objects == NULL) {
|
||||
|
|
@ -808,6 +843,8 @@ static void ubus_objects_callback(struct ubus_request *req, int type __attribute
|
|||
return;
|
||||
}
|
||||
|
||||
cur = NULL;
|
||||
rem = 0;
|
||||
blobmsg_for_each_attr(cur, objects, rem) {
|
||||
struct blob_attr *tb[4] = {0};
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ struct uloop_timeout retry_session_timer = { .cb = cwmp_schedule_session };
|
|||
struct uloop_timeout throttle_session_timer = { .cb = cwmp_schedule_throttle_session };
|
||||
|
||||
unsigned int end_session_flag = 0;
|
||||
struct list_head *modified_uci_list = NULL;
|
||||
|
||||
int create_cwmp_session_structure()
|
||||
{
|
||||
|
|
@ -82,6 +83,12 @@ int cwmp_session_init()
|
|||
if (rpc_acs == NULL)
|
||||
return CWMP_GEN_ERR;
|
||||
|
||||
modified_uci_list = (struct list_head *)malloc(sizeof(struct list_head));
|
||||
if (modified_uci_list == NULL)
|
||||
return CWMP_GEN_ERR;
|
||||
|
||||
INIT_LIST_HEAD(modified_uci_list);
|
||||
|
||||
cwmp_ctx.session->rpc_cpe = NULL;
|
||||
|
||||
set_cwmp_session_status(SESSION_RUNNING, 0);
|
||||
|
|
@ -709,6 +716,8 @@ int run_session_end_func(void)
|
|||
|
||||
reinit_cwmp_periodic_session_feature();
|
||||
reinit_heartbeat_procedures();
|
||||
// clear modified uci list
|
||||
cwmp_free_modified_uci_list();
|
||||
|
||||
if (end_session_flag & END_SESSION_NSLOOKUP_DIAGNOSTIC) {
|
||||
CWMP_LOG(INFO, "Executing nslookupdiagnostic: end session request");
|
||||
|
|
@ -826,6 +835,7 @@ int run_session_end_func(void)
|
|||
}
|
||||
|
||||
INIT_LIST_HEAD(&intf_reset_list);
|
||||
|
||||
memset(cwmp_ctx.session->fault_msg, 0, sizeof(cwmp_ctx.session->fault_msg));
|
||||
end_session_flag = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue