mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-01-28 01:27:16 +01:00
optimize dual stack implementation
This commit is contained in:
parent
6a64707419
commit
2048786b91
16 changed files with 149 additions and 241 deletions
|
|
@ -228,9 +228,16 @@
|
|||
<td class="td_row_odd"><div class="td_row_odd">default_lan_interface</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">string</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">no</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd"></div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">lan</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">Configure the default lan interface of the device.</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td_row_odd"><div class="td_row_odd">default_wan_interface</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">string</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">yes</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">wan</div></td>
|
||||
<td class="td_row_odd"><div class="td_row_odd">Configure the default wan interface that will be used for IPv4/IPv6 connection.</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td_row_even"><div class="td_row_even">log_to_console</div></td>
|
||||
<td class="td_row_even"><div class="td_row_even">string</div></td>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,4 @@ While the CPE must prioritize the IPv6, so it starts by checking if IPv6 is work
|
|||
|
||||
### Dual Stack configuration
|
||||
|
||||
Two uci options are present to configure dual stack:
|
||||
|
||||
- cwmp.cpe.default_wan_interface: that is the network interface that is used to check the connection with IPv4.
|
||||
- cwmp.cpe.default_wan6_interface: that is the network interface that is used to check the connection with IPv6.
|
||||
- cwmp.cpe.default_wan_interface: this is the interface name that is used to check the connection with IPv4/IPv6.
|
||||
|
|
@ -183,16 +183,9 @@
|
|||
{
|
||||
"name": "default_wan_interface",
|
||||
"type": "string",
|
||||
"required": "no",
|
||||
"required": "yes",
|
||||
"default": "wan",
|
||||
"description": "Configure the default wan interface that will be used for IPv4 connection."
|
||||
},
|
||||
{
|
||||
"name": "default_wan6_interface",
|
||||
"type": "string",
|
||||
"required": "no",
|
||||
"default": "wan6",
|
||||
"description": "Configure the default wan interface that will be used for IPv6 connection."
|
||||
"description": "Configure the default wan interface that will be used for IPv4/IPv6 connection."
|
||||
},
|
||||
{
|
||||
"name": "log_to_console",
|
||||
|
|
|
|||
196
src/common.c
196
src/common.c
|
|
@ -16,6 +16,8 @@
|
|||
#include <getopt.h>
|
||||
#include <stdarg.h>
|
||||
#include <regex.h>
|
||||
#include <sys/types.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <mxml.h>
|
||||
|
||||
#include "common.h"
|
||||
|
|
@ -743,130 +745,110 @@ int copy_file(char *source_file, char *target_file)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void ubus_network_interface_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg)
|
||||
static 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] = { { "l3_device", BLOBMSG_TYPE_STRING } };
|
||||
struct blob_attr *tb[1] = { NULL };
|
||||
char *l3_device = NULL;
|
||||
blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg));
|
||||
if (tb[0] != NULL) {
|
||||
l3_device = blobmsg_get_string(tb[0]);
|
||||
}
|
||||
struct blob_attr *tb[1] = {0};
|
||||
struct blobmsg_policy p[1] = {
|
||||
{ "l3_device", BLOBMSG_TYPE_STRING }
|
||||
};
|
||||
|
||||
// Only update the interface if its not empty
|
||||
if (CWMP_STRLEN(l3_device)) {
|
||||
cwmp_main->net.interface = strdup(l3_device);
|
||||
}
|
||||
|
||||
CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s", cwmp_main->net.interface);
|
||||
}
|
||||
|
||||
void set_uci_connection_interface(char* interface)
|
||||
{
|
||||
if (interface == NULL) {
|
||||
CWMP_LOG(WARNING, "%s interface is NULL", __FUNCTION__);
|
||||
if (msg == NULL)
|
||||
return;
|
||||
}
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "interface", interface);
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
}
|
||||
|
||||
int get_connection_interface()
|
||||
{
|
||||
struct blob_buf b = { 0 };
|
||||
memset(&b, 0, sizeof(struct blob_buf));
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
char ubus_obj[100] = {0};
|
||||
if (cwmp_main->net.ipv6_status)
|
||||
snprintf(ubus_obj, sizeof(ubus_obj), "network.interface.%s", cwmp_main->conf.default_wan6_iface);
|
||||
else
|
||||
snprintf(ubus_obj, sizeof(ubus_obj), "network.interface.%s", cwmp_main->conf.default_wan_iface);
|
||||
|
||||
FREE(cwmp_main->net.interface);
|
||||
|
||||
int e = icwmp_ubus_invoke(ubus_obj, "status", b.head, ubus_network_interface_callback, NULL);
|
||||
blob_buf_free(&b);
|
||||
|
||||
if (e != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (cwmp_main->net.interface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
set_uci_connection_interface(cwmp_main->net.interface);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
int get_connection_parameters()
|
||||
{
|
||||
int error = get_connection_interface();
|
||||
if (error != CWMP_OK) {
|
||||
CWMP_LOG(DEBUG, "Failed to get interface [%s] details", cwmp_main->net.connection_wan_iface);
|
||||
return error;
|
||||
}
|
||||
|
||||
error = icwmp_check_http_connection();
|
||||
if (error != CWMP_OK || !cwmp_main->net.connection_wan_iface) {
|
||||
CWMP_LOG(DEBUG, "Failed to check http connection");
|
||||
return error;
|
||||
}
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void ubus_network_interface_status_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg)
|
||||
{
|
||||
bool *up = (bool *)req->priv;
|
||||
|
||||
const struct blobmsg_policy p[1] = { { "up", BLOBMSG_TYPE_BOOL } };
|
||||
struct blob_attr *tb[1] = { NULL };
|
||||
blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg));
|
||||
if (tb[0] != NULL)
|
||||
*up = blobmsg_get_bool(tb[0]);
|
||||
|
||||
if (!tb[0])
|
||||
return;
|
||||
|
||||
char *l3_device = blobmsg_get_string(tb[0]);
|
||||
if (!CWMP_STRLEN(l3_device))
|
||||
return;
|
||||
|
||||
cwmp_main->net.interface = strdup(l3_device);
|
||||
|
||||
CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s && device: %s", cwmp_main->conf.default_wan_iface, cwmp_main->net.interface);
|
||||
}
|
||||
|
||||
bool check_ipv6_enabled()
|
||||
static bool is_ipv6_addr_available(const char *device)
|
||||
{
|
||||
bool up=false;
|
||||
struct blob_buf b = { 0 };
|
||||
memset(&b, 0, sizeof(struct blob_buf));
|
||||
blob_buf_init(&b, 0);
|
||||
struct ifaddrs *ifaddr = NULL,*ifa = NULL;
|
||||
void *in_addr = NULL;
|
||||
bool ipv6_addr_available = false;
|
||||
int family, err = 0;
|
||||
|
||||
char ubus_network_interface[512];
|
||||
snprintf(ubus_network_interface, sizeof(ubus_network_interface), "network.interface.%s", cwmp_main->conf.default_wan6_iface);
|
||||
icwmp_ubus_invoke(ubus_network_interface, "status", b.head, ubus_network_interface_status_callback, &up);
|
||||
if (CWMP_STRLEN(device) == 0)
|
||||
return false;
|
||||
|
||||
blob_buf_free(&b);
|
||||
err = getifaddrs(&ifaddr);
|
||||
if (err != 0)
|
||||
return false;
|
||||
|
||||
return up;
|
||||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
|
||||
if (ifa->ifa_addr == NULL || ifa->ifa_name == NULL || strcmp(ifa->ifa_name, device) != 0)
|
||||
continue;
|
||||
|
||||
family = ifa->ifa_addr->sa_family;
|
||||
|
||||
// Skip this result, if it is not an IPv6 node
|
||||
if (family != AF_INET6)
|
||||
continue;
|
||||
|
||||
#define NOT_GLOBAL_UNICAST(addr) \
|
||||
( (IN6_IS_ADDR_UNSPECIFIED(addr)) || (IN6_IS_ADDR_LOOPBACK(addr)) || \
|
||||
(IN6_IS_ADDR_MULTICAST(addr)) || (IN6_IS_ADDR_LINKLOCAL(addr)) || \
|
||||
(IN6_IS_ADDR_SITELOCAL(addr)) )
|
||||
|
||||
if (family == AF_INET6) {
|
||||
|
||||
in_addr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
|
||||
|
||||
// Skip this result, if it is an IPv6 address, but not globally routable
|
||||
if (NOT_GLOBAL_UNICAST((struct in6_addr *)in_addr))
|
||||
continue;
|
||||
|
||||
ipv6_addr_available = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(ifaddr);
|
||||
|
||||
return ipv6_addr_available;
|
||||
}
|
||||
|
||||
bool check_connection_attributes_change()
|
||||
bool is_ipv6_enabled(void)
|
||||
{
|
||||
cwmp_uci_reinit();
|
||||
if (cwmp_main->net.interface == NULL) {
|
||||
struct blob_buf b = {0};
|
||||
char network_interface[64];
|
||||
|
||||
char *actual_wan_interface = NULL, *actual_wan6_interface = NULL;
|
||||
uci_get_value("cwmp.cpe.default_wan_interface", &actual_wan_interface);
|
||||
uci_get_value("cwmp.cpe.default_wan6_interface", &actual_wan6_interface);
|
||||
bool wan_interface_changed = CWMP_STRCMP(actual_wan_interface, cwmp_main->conf.default_wan_iface);
|
||||
bool wan6_interface_changed = CWMP_STRCMP(actual_wan6_interface, cwmp_main->conf.default_wan_iface);
|
||||
memset(&b, 0, sizeof(struct blob_buf));
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
if (wan_interface_changed)
|
||||
{
|
||||
FREE(cwmp_main->conf.default_wan_iface);
|
||||
cwmp_main->conf.default_wan_iface = strdup(actual_wan_interface);
|
||||
snprintf(network_interface, sizeof(network_interface), "network.interface.%s", cwmp_main->conf.default_wan_iface);
|
||||
|
||||
int e = icwmp_ubus_invoke(network_interface, "status", b.head, ubus_network_interface_callback, NULL);
|
||||
|
||||
blob_buf_free(&b);
|
||||
|
||||
if (e != 0 || cwmp_main->net.interface == NULL)
|
||||
return false;
|
||||
}
|
||||
if (wan6_interface_changed)
|
||||
{
|
||||
FREE(cwmp_main->conf.default_wan6_iface);
|
||||
cwmp_main->conf.default_wan6_iface = strdup(actual_wan6_interface);
|
||||
}
|
||||
FREE(actual_wan_interface);
|
||||
FREE(actual_wan6_interface);
|
||||
bool actual_ipv6_status = check_ipv6_enabled();
|
||||
bool ipv6_status_changed = (actual_ipv6_status != cwmp_main->net.ipv6_status);
|
||||
cwmp_main->net.ipv6_status = actual_ipv6_status;
|
||||
return ipv6_status_changed || wan_interface_changed || wan6_interface_changed;
|
||||
|
||||
if (!is_ipv6_addr_available(cwmp_main->net.interface))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_ipv6_status_changed(void)
|
||||
{
|
||||
bool curr_ipv6_status = is_ipv6_enabled();
|
||||
bool ipv6_status_changed = (curr_ipv6_status != cwmp_main->net.ipv6_status);
|
||||
cwmp_main->net.ipv6_status = curr_ipv6_status;
|
||||
|
||||
return ipv6_status_changed;
|
||||
}
|
||||
|
||||
char *get_time(time_t t_time)
|
||||
|
|
|
|||
14
src/common.h
14
src/common.h
|
|
@ -90,9 +90,8 @@ typedef struct env {
|
|||
} env;
|
||||
|
||||
struct connection {
|
||||
char *connection_wan_iface;
|
||||
char *interface;
|
||||
int ip_resolve;
|
||||
long ip_resolve;
|
||||
bool ipv6_status;
|
||||
};
|
||||
|
||||
|
|
@ -104,8 +103,6 @@ typedef struct config {
|
|||
char *cpe_userid;
|
||||
char *cpe_passwd;
|
||||
char *custom_notify_json;
|
||||
char *ip;
|
||||
char *ipv6;
|
||||
char *ubus_socket;
|
||||
char *connection_request_path;
|
||||
char *auto_tc_transfer_type;
|
||||
|
|
@ -115,7 +112,6 @@ typedef struct config {
|
|||
char *auto_cdu_result_type;
|
||||
char *auto_cdu_fault_code;
|
||||
char *default_wan_iface;
|
||||
char *default_wan6_iface;
|
||||
int connection_request_port;
|
||||
int period;
|
||||
int periodic_notify_interval;
|
||||
|
|
@ -613,11 +609,9 @@ bool icwmp_validate_unsignedint(char *arg);
|
|||
bool icwmp_validate_int_in_range(char *arg, int min, int max);
|
||||
char *string_to_hex(const unsigned char *str, size_t size);
|
||||
int copy_file(char *source_file, char *target_file);
|
||||
int get_connection_interface();
|
||||
int get_connection_parameters();
|
||||
int icwmp_check_http_connection();
|
||||
bool check_ipv6_enabled();
|
||||
bool check_connection_attributes_change();
|
||||
int icwmp_check_http_connection(void);
|
||||
bool is_ipv6_enabled(void);
|
||||
bool is_ipv6_status_changed(void);
|
||||
char *get_time(time_t t_time);
|
||||
bool is_obj_excluded(const char *object_name);
|
||||
bool is_reload_parameter(const char *object_name);
|
||||
|
|
|
|||
10
src/config.c
10
src/config.c
|
|
@ -48,7 +48,6 @@ static void config_get_cpe_elements(struct uci_section *s)
|
|||
UCI_CPE_ENABLE_SYSLOG,
|
||||
UCI_CPE_AMD_VERSION,
|
||||
UCI_CPE_DEFAULT_WAN_IFACE,
|
||||
UCI_CPE_DEFAULT_WAN6_IFACE,
|
||||
__MAX_NUM_UCI_CPE_ATTRS,
|
||||
};
|
||||
|
||||
|
|
@ -61,8 +60,7 @@ static void config_get_cpe_elements(struct uci_section *s)
|
|||
{ .name = "log_severity", .type = UCI_TYPE_STRING },
|
||||
{ .name = "log_to_syslog", .type = UCI_TYPE_STRING },
|
||||
{ .name = "amd_version", .type = UCI_TYPE_STRING },
|
||||
{ .name = "default_wan_interface", .type = UCI_TYPE_STRING },
|
||||
{ .name = "default_wan6_interface", .type = UCI_TYPE_STRING },
|
||||
{ .name = "default_wan_interface", .type = UCI_TYPE_STRING }
|
||||
};
|
||||
|
||||
struct uci_option *cpe_tb[__MAX_NUM_UCI_CPE_ATTRS] = {0};
|
||||
|
|
@ -99,12 +97,6 @@ static void config_get_cpe_elements(struct uci_section *s)
|
|||
else
|
||||
cwmp_main->conf.default_wan_iface = strdup("wan");
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - default wan interface: %s", cwmp_main->conf.default_wan_iface);
|
||||
|
||||
if (cpe_tb[UCI_CPE_DEFAULT_WAN6_IFACE])
|
||||
cwmp_main->conf.default_wan6_iface = strdup(get_value_from_uci_option(cpe_tb[UCI_CPE_DEFAULT_WAN6_IFACE]));
|
||||
else
|
||||
cwmp_main->conf.default_wan6_iface = strdup("wan6");
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - default wan ipv6 interface: %s", cwmp_main->conf.default_wan6_iface);
|
||||
}
|
||||
|
||||
static void config_get_acs_elements(struct uci_section *s)
|
||||
|
|
|
|||
18
src/cwmp.c
18
src/cwmp.c
|
|
@ -283,15 +283,15 @@ static int cwmp_init(void)
|
|||
INIT_LIST_HEAD(&du_uuid_list);
|
||||
cwmp_main->start_time = time(NULL);
|
||||
|
||||
cwmp_uci_exit();
|
||||
sleep(15);
|
||||
|
||||
cwmp_main->net.ipv6_status = check_ipv6_enabled();
|
||||
error = get_connection_parameters();
|
||||
cwmp_main->net.ipv6_status = is_ipv6_enabled();
|
||||
error = icwmp_check_http_connection();
|
||||
if (error != CWMP_OK) {
|
||||
CWMP_LOG(DEBUG, "Failed to get connection parameters");
|
||||
CWMP_LOG(DEBUG, "Init: failed to check http connection");
|
||||
return error;
|
||||
}
|
||||
|
||||
cwmp_uci_exit();
|
||||
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
|
|
@ -304,17 +304,13 @@ static void cwmp_free()
|
|||
FREE(cwmp_main->deviceid.oui);
|
||||
FREE(cwmp_main->deviceid.softwareversion);
|
||||
FREE(cwmp_main->conf.lw_notification_hostname);
|
||||
FREE(cwmp_main->conf.ip);
|
||||
FREE(cwmp_main->conf.ipv6);
|
||||
FREE(cwmp_main->conf.acsurl);
|
||||
FREE(cwmp_main->conf.acs_userid);
|
||||
FREE(cwmp_main->conf.acs_passwd);
|
||||
FREE(cwmp_main->net.interface);
|
||||
FREE(cwmp_main->conf.cpe_userid);
|
||||
FREE(cwmp_main->conf.cpe_passwd);
|
||||
FREE(cwmp_main->conf.ubus_socket);
|
||||
FREE(cwmp_main->conf.connection_request_path);
|
||||
FREE(cwmp_main->net.connection_wan_iface);
|
||||
FREE(cwmp_main->conf.custom_notify_json);
|
||||
FREE(cwmp_main->conf.auto_cdu_fault_code);
|
||||
FREE(cwmp_main->conf.auto_cdu_oprt_type);
|
||||
|
|
@ -323,7 +319,7 @@ static void cwmp_free()
|
|||
FREE(cwmp_main->conf.auto_tc_result_type);
|
||||
FREE(cwmp_main->conf.auto_tc_transfer_type);
|
||||
FREE(cwmp_main->conf.default_wan_iface);
|
||||
FREE(cwmp_main->conf.default_wan6_iface);
|
||||
FREE(cwmp_main->net.interface);
|
||||
FREE(nonce_key);
|
||||
clean_list_param_notify();
|
||||
bkp_tree_clean();
|
||||
|
|
|
|||
|
|
@ -431,56 +431,40 @@ static int set_management_server_periodic_inform_time(char *refparam, struct dmc
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int network_get_ipaddr(char *iface, int ipver, char **value)
|
||||
{
|
||||
json_object *res = NULL, *jobj = NULL;
|
||||
|
||||
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", iface, String}}, 1, &res);
|
||||
DM_ASSERT(res, *value = "");
|
||||
|
||||
|
||||
if (ipver == 6)
|
||||
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address");
|
||||
else
|
||||
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address");
|
||||
|
||||
*value = dmjson_get_value(jobj, 1, "address");
|
||||
|
||||
if ((*value)[0] == '\0')
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void get_management_ip_port(char **listen_addr)
|
||||
{
|
||||
char *ip = NULL, *port = NULL, *interface = NULL, *if_name = NULL, *version = NULL;
|
||||
char *ip = NULL, *port = NULL, *interface = NULL, *ip_version = NULL;
|
||||
|
||||
dmuci_get_option_value_string_varstate("cwmp", "cpe", "interface", &if_name);
|
||||
dmuci_get_option_value_string_varstate("cwmp", "acs", "ip_version", &version);
|
||||
dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &interface);
|
||||
dmuci_get_option_value_string("cwmp", "cpe", "port", &port);
|
||||
dmuci_get_option_value_string("cwmp", "cpe", *version == '6' ? "default_wan6_interface" : "default_wan_interface", &interface);
|
||||
dmuci_get_option_value_string_varstate("cwmp", "acs", "ip_version", &ip_version);
|
||||
|
||||
if (network_get_ipaddr(interface, *version == '6' ? 6 : 4, &ip) == -1) {
|
||||
if (if_name[0] == '\0')
|
||||
return;
|
||||
if (!DM_STRLEN(interface))
|
||||
return;
|
||||
|
||||
ip = (*version == '6') ? get_ipv6(if_name) : ioctl_get_ipv4(if_name);
|
||||
}
|
||||
char *l3_device = get_l3_device(interface);
|
||||
if (!DM_STRLEN(l3_device))
|
||||
return;
|
||||
|
||||
if (ip[0] != '\0' && port[0] != '\0') {
|
||||
dmasprintf(listen_addr, (*version == '6') ? "[%s]:%s" : "%s:%s", ip, port);
|
||||
}
|
||||
if (DM_STRCMP(ip_version, "6") == 0)
|
||||
ip = ifaddrs_get_global_ipv6(l3_device);
|
||||
else
|
||||
ip = ioctl_get_ipv4(l3_device);
|
||||
|
||||
if (DM_STRLEN(ip) && DM_STRLEN(port))
|
||||
dmasprintf(listen_addr, !DM_STRCMP(ip_version, "6") ? "[%s]:%s" : "%s:%s", ip, port);
|
||||
}
|
||||
|
||||
/*#Device.ManagementServer.ConnectionRequestURL!UCI:cwmp/cpe,cpe/port*/
|
||||
static int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *mgmt_addr = NULL;
|
||||
|
||||
get_management_ip_port(&mgmt_addr);
|
||||
|
||||
if (mgmt_addr != NULL) {
|
||||
char *path;
|
||||
if (DM_STRLEN(mgmt_addr)) {
|
||||
char *path = NULL;
|
||||
|
||||
dmuci_get_option_value_string("cwmp", "cpe", "path", &path);
|
||||
dmasprintf(value, "http://%s/%s", mgmt_addr, path ? path : "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,21 +51,21 @@ void http_server_stop(void)
|
|||
pthread_join(http_cr_server_thread, NULL);
|
||||
}
|
||||
|
||||
void set_http_ip_resolve(int resolve)
|
||||
static void set_http_ip_resolve(long ip_resolve)
|
||||
{
|
||||
cwmp_uci_set_varstate_value("cwmp", "acs", "ip_version", (resolve == CURL_IPRESOLVE_V6) ? "6" : "4");
|
||||
cwmp_main->net.ip_resolve = ip_resolve;
|
||||
|
||||
cwmp_uci_set_varstate_value("cwmp", "acs", "ip_version", (ip_resolve == CURL_IPRESOLVE_V6) ? "6" : "4");
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
FREE(cwmp_main->net.connection_wan_iface);
|
||||
cwmp_main->net.connection_wan_iface = strdup((resolve == CURL_IPRESOLVE_V6) ? cwmp_main->conf.default_wan6_iface : cwmp_main->conf.default_wan_iface);
|
||||
cwmp_main->net.ip_resolve = resolve;
|
||||
}
|
||||
|
||||
int icwmp_check_http_connection()
|
||||
int icwmp_check_http_connection(void)
|
||||
{
|
||||
if (!cwmp_main->net.ipv6_status) {
|
||||
set_http_ip_resolve(CURL_IPRESOLVE_V4);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
long resolve = CURL_IPRESOLVE_V6;
|
||||
while(1) {
|
||||
CURL *c = curl_easy_init();
|
||||
|
|
@ -75,7 +75,10 @@ int icwmp_check_http_connection()
|
|||
curl_easy_setopt(c, CURLOPT_URL, cwmp_main->conf.acsurl);
|
||||
curl_easy_setopt(c, CURLOPT_CONNECT_ONLY, 1L);
|
||||
curl_easy_setopt(c, CURLOPT_IPRESOLVE, resolve);
|
||||
curl_easy_setopt(c, CURLOPT_INTERFACE, cwmp_main->net.interface);
|
||||
|
||||
if (CWMP_STRLEN(cwmp_main->net.interface))
|
||||
curl_easy_setopt(c, CURLOPT_INTERFACE, cwmp_main->net.interface);
|
||||
|
||||
ret = curl_easy_perform(c);
|
||||
if(ret == CURLE_OK) {
|
||||
int tmp = 1;
|
||||
|
|
@ -90,6 +93,7 @@ int icwmp_check_http_connection()
|
|||
set_http_ip_resolve(CURL_IPRESOLVE_V4);
|
||||
else
|
||||
set_http_ip_resolve(CURL_IPRESOLVE_V6);
|
||||
|
||||
curl_easy_cleanup(c);
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
|
@ -102,5 +106,6 @@ int icwmp_check_http_connection()
|
|||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
32
src/event.c
32
src/event.c
|
|
@ -320,38 +320,6 @@ int cwmp_root_cause_event_periodic()
|
|||
return CWMP_OK;
|
||||
}
|
||||
|
||||
void connection_request_ip_value_change(int version)
|
||||
{
|
||||
char *bip = NULL;
|
||||
char *ip_version = (version == IPv6) ? "ipv6" : "ip";
|
||||
char *ip_value = (version == IPv6) ? cwmp_main->conf.ipv6 : cwmp_main->conf.ip;
|
||||
|
||||
if (version == IPv6)
|
||||
cwmp_load_saved_session(&bip, CR_IPv6);
|
||||
else
|
||||
cwmp_load_saved_session(&bip, CR_IP);
|
||||
|
||||
if (bip == NULL) {
|
||||
CWMP_LOG(ERROR, "event %s: bip is null", __FUNCTION__);
|
||||
bkp_session_simple_insert_in_parent("connection_request", ip_version, ip_value);
|
||||
bkp_session_save();
|
||||
return;
|
||||
}
|
||||
if (ip_value && strcmp(bip, ip_value) != 0) {
|
||||
struct event_container *event_container;
|
||||
event_container = cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, "");
|
||||
if (event_container == NULL) {
|
||||
CWMP_LOG(ERROR, "event %s: event_container is null", __FUNCTION__);
|
||||
FREE(bip);
|
||||
return;
|
||||
}
|
||||
cwmp_save_event_container(event_container);
|
||||
bkp_session_simple_insert_in_parent("connection_request", ip_version, ip_value);
|
||||
bkp_session_save();
|
||||
}
|
||||
FREE(bip);
|
||||
}
|
||||
|
||||
void connection_request_port_value_change(int port)
|
||||
{
|
||||
char *bport = NULL;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ extern const struct EVENT_CONST_STRUCT EVENT_CONST[__EVENT_IDX_MAX];
|
|||
|
||||
int event_remove_noretry_event_container();
|
||||
void cwmp_save_event_container(struct event_container *event_container);
|
||||
void connection_request_ip_value_change( int version);
|
||||
void connection_request_port_value_change(int port);
|
||||
int cwmp_get_int_event_code(const char *code);
|
||||
bool event_exist_in_list(int event);
|
||||
|
|
|
|||
|
|
@ -123,14 +123,12 @@ static void http_set_connection_options()
|
|||
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, cwmp_main->net.ip_resolve);
|
||||
#ifdef DEVEL
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
#endif
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, fc_cookies);
|
||||
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, fc_cookies);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp_main->net.interface);
|
||||
if (CWMP_STRLEN(cwmp_main->net.interface))
|
||||
curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp_main->net.interface);
|
||||
}
|
||||
|
||||
static void http_set_header_list_options()
|
||||
|
|
@ -213,7 +211,7 @@ int icwmp_http_send_message(char *msg_out, int msg_out_len, char **msg_in)
|
|||
FREE(*msg_in);
|
||||
|
||||
curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
|
||||
if (ip && ip[0] != '\0') {
|
||||
if (CWMP_STRLEN(ip)) {
|
||||
if (ip_acs[0] == '\0' || strcmp(ip_acs, ip) != 0) {
|
||||
CWMP_STRNCPY(ip_acs, ip, sizeof(ip_acs));
|
||||
tmp = inet_pton(AF_INET, ip, buf);
|
||||
|
|
|
|||
|
|
@ -337,9 +337,9 @@ void start_cwmp_session()
|
|||
if (cwmp_main->session->session_status.last_status == SESSION_FAILURE)
|
||||
cwmp_config_load();
|
||||
|
||||
if (check_connection_attributes_change()) {
|
||||
if (get_connection_parameters() != CWMP_OK || cwmp_stop) {
|
||||
CWMP_LOG(INFO, "cwmp fails to get connection parameters");
|
||||
if (is_ipv6_status_changed()) {
|
||||
if (icwmp_check_http_connection() != CWMP_OK || cwmp_stop) {
|
||||
CWMP_LOG(INFO, "Failed to check http connection");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,8 +45,6 @@ static int dm_iface_unit_tests_clean(void **state)
|
|||
FREE(cwmp_main->deviceid.oui);
|
||||
FREE(cwmp_main->deviceid.softwareversion);
|
||||
FREE(cwmp_main->conf.lw_notification_hostname);
|
||||
FREE(cwmp_main->conf.ip);
|
||||
FREE(cwmp_main->conf.ipv6);
|
||||
FREE(cwmp_main->conf.acsurl);
|
||||
FREE(cwmp_main->conf.acs_userid);
|
||||
FREE(cwmp_main->conf.acs_passwd);
|
||||
|
|
@ -55,7 +53,6 @@ static int dm_iface_unit_tests_clean(void **state)
|
|||
FREE(cwmp_main->conf.ubus_socket);
|
||||
FREE(cwmp_main->conf.connection_request_path);
|
||||
FREE(cwmp_main->conf.default_wan_iface);
|
||||
FREE(cwmp_main->conf.default_wan6_iface);
|
||||
FREE(cwmp_main->conf.custom_notify_json);
|
||||
cwmp_free_all_list_param_fault(&faults_array);
|
||||
cwmp_free_all_dm_parameter_list(&list_set_param_value);
|
||||
|
|
|
|||
|
|
@ -45,8 +45,6 @@ static void clean_config()
|
|||
FREE(cwmp_main->deviceid.oui);
|
||||
FREE(cwmp_main->deviceid.softwareversion);
|
||||
FREE(cwmp_main->conf.lw_notification_hostname);
|
||||
FREE(cwmp_main->conf.ip);
|
||||
FREE(cwmp_main->conf.ipv6);
|
||||
FREE(cwmp_main->conf.acsurl);
|
||||
FREE(cwmp_main->conf.acs_userid);
|
||||
FREE(cwmp_main->conf.acs_passwd);
|
||||
|
|
@ -55,7 +53,6 @@ static void clean_config()
|
|||
FREE(cwmp_main->conf.ubus_socket);
|
||||
FREE(cwmp_main->conf.connection_request_path);
|
||||
FREE(cwmp_main->conf.default_wan_iface);
|
||||
FREE(cwmp_main->conf.default_wan6_iface);
|
||||
}
|
||||
|
||||
static void clean_name_space()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ config cpe 'cpe'
|
|||
option enable '1'
|
||||
option interface 'eth0'
|
||||
option default_wan_interface 'wan'
|
||||
option default_wan6_interface 'wan6'
|
||||
option log_to_console 'disable'
|
||||
option log_to_syslog 'disable'
|
||||
option log_to_file 'enable'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue