mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
Ticket refs #7512: icwmpd: Connect imediatly on wan up
(cherry picked from commit d5dd79101ab7b680644678a6862d6cbc213330b0) (cherry picked from commit 9815275e6a0537540905862fb9393570c507e8f1)
This commit is contained in:
parent
cc1763399c
commit
8df8a9a6a0
4 changed files with 65 additions and 15 deletions
74
config.c
74
config.c
|
|
@ -15,6 +15,7 @@
|
|||
#include "log.h"
|
||||
#include "reboot.h"
|
||||
#include "datamodel_interface.h"
|
||||
#include "ubus.h"
|
||||
|
||||
pthread_mutex_t mutex_config_load = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
|
|
@ -269,18 +270,6 @@ int get_global_config(struct config *conf)
|
|||
return error;
|
||||
}
|
||||
|
||||
if ((error = uci_get_value(UCI_CPE_INTERFACE_PATH, &value)) == CWMP_OK) {
|
||||
if (value != NULL) {
|
||||
FREE(conf->interface);
|
||||
conf->interface = strdup(value);
|
||||
FREE(value);
|
||||
}
|
||||
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe interface: %s", conf->interface ? conf->interface : "");
|
||||
} else {
|
||||
return error;
|
||||
}
|
||||
|
||||
if ((error = uci_get_value(UCI_CPE_USERID_PATH, &value)) == CWMP_OK) {
|
||||
FREE(conf->cpe_userid);
|
||||
if (value != NULL) {
|
||||
|
|
@ -603,6 +592,59 @@ int get_global_config(struct config *conf)
|
|||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void ubus_network_interface_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg)
|
||||
{
|
||||
const struct blobmsg_policy p[1] = { { "device", BLOBMSG_TYPE_STRING } };
|
||||
struct blob_attr *tb[1] = { NULL };
|
||||
blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg));
|
||||
if (!tb[0]) {
|
||||
cwmp_main.conf.interface = NULL;
|
||||
CWMP_LOG(DEBUG, "CWMP IFACE - interface: NOT FOUND");
|
||||
return;
|
||||
}
|
||||
|
||||
FREE(cwmp_main.conf.interface);
|
||||
cwmp_main.conf.interface = strdup(blobmsg_get_string(tb[0]));
|
||||
CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s", cwmp_main.conf.interface);
|
||||
}
|
||||
|
||||
int get_connection_interface()
|
||||
{
|
||||
int e = cwmp_ubus_call("network.interface", "status", CWMP_UBUS_ARGS{ { "interface", { .str_val = cwmp_main.conf.default_wan_iface }, UBUS_String } }, 1, ubus_network_interface_callback, NULL);
|
||||
if (e != 0) {
|
||||
CWMP_LOG(INFO, "Get network interface from network.interface ubus method failed. Ubus err code: %d", e);
|
||||
return -1;
|
||||
}
|
||||
if (cwmp_main.conf.interface == NULL) {
|
||||
CWMP_LOG(INFO, "Not able to get the network interface from network.interface ubus method.");
|
||||
return -1;
|
||||
}
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int reload_networking_config()
|
||||
{
|
||||
int error;
|
||||
char *value = NULL;
|
||||
if ((error = uci_get_value(UCI_CPE_DEFAULT_WAN_IFACE, &value)) == CWMP_OK) {
|
||||
FREE(cwmp_main.conf.default_wan_iface);
|
||||
if (value != NULL) {
|
||||
cwmp_main.conf.default_wan_iface = strdup(value);
|
||||
FREE(value);
|
||||
} else {
|
||||
cwmp_main.conf.default_wan_iface = strdup("wan");
|
||||
}
|
||||
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - default wan interface: %s", cwmp_main.conf.default_wan_iface ? cwmp_main.conf.default_wan_iface : "");
|
||||
} else {
|
||||
return error;
|
||||
}
|
||||
|
||||
if ((error = get_connection_interface()))
|
||||
return -1;
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int global_conf_init(struct cwmp *cwmp)
|
||||
{
|
||||
int error = CWMP_OK;
|
||||
|
|
@ -615,6 +657,9 @@ int global_conf_init(struct cwmp *cwmp)
|
|||
if ((error = check_global_config(&(cwmp->conf))))
|
||||
goto end;
|
||||
|
||||
if ((error = get_connection_interface()))
|
||||
return -1;
|
||||
|
||||
/* Launch reboot methods if needed */
|
||||
launch_reboot_methods(cwmp);
|
||||
|
||||
|
|
@ -637,6 +682,9 @@ int cwmp_get_deviceid(struct cwmp *cwmp)
|
|||
int cwmp_config_reload(struct cwmp *cwmp)
|
||||
{
|
||||
memset(&cwmp->env, 0, sizeof(struct env));
|
||||
int err = global_conf_init(cwmp);
|
||||
if (err != CWMP_OK)
|
||||
return err;
|
||||
|
||||
return global_conf_init(cwmp);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
|
|
|||
3
cwmp.c
3
cwmp.c
|
|
@ -364,6 +364,8 @@ static void cwmp_schedule_session(struct cwmp *cwmp)
|
|||
ilist = (&(cwmp->head_session_queue))->next;
|
||||
retry = false;
|
||||
}
|
||||
if (cwmp->session_status.last_status == SESSION_FAILURE)
|
||||
reload_networking_config();
|
||||
cwmp_uci_init();
|
||||
session = list_entry(ilist, struct session, list);
|
||||
if (file_exists(DM_ENABLED_NOTIFY)) {
|
||||
|
|
@ -417,6 +419,7 @@ static void cwmp_schedule_session(struct cwmp *cwmp)
|
|||
cwmp->session_status.last_status = SESSION_FAILURE;
|
||||
cwmp->session_status.next_retry = time(NULL) + cwmp_get_retry_interval(cwmp);
|
||||
cwmp->session_status.failure_session++;
|
||||
reload_networking_config();
|
||||
pthread_mutex_unlock(&(cwmp->mutex_session_send));
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,5 @@ int global_conf_init(struct cwmp *cwmp);
|
|||
int get_global_config(struct config *conf);
|
||||
int cwmp_get_deviceid(struct cwmp *cwmp);
|
||||
int cwmp_config_reload(struct cwmp *cwmp);
|
||||
|
||||
int reload_networking_config();
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
#define UCI_LOG_SEVERITY_PATH "cwmp.cpe.log_severity"
|
||||
#define UCI_CPE_USERID_PATH "cwmp.cpe.userid"
|
||||
#define UCI_CPE_PASSWD_PATH "cwmp.cpe.passwd"
|
||||
#define UCI_CPE_INTERFACE_PATH "cwmp.cpe.interface"
|
||||
#define UCI_CPE_UBUS_SOCKET_PATH "cwmp.cpe.ubus_socket"
|
||||
#define UCI_CPE_PORT_PATH "cwmp.cpe.port"
|
||||
#define UCI_CPE_DEFAULT_WAN_IFACE "cwmp.cpe.default_wan_interface"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue