Merge branch 'dhcp_rediscover' into 'devel'

DHCP re-discovery if ACS not reachable

See merge request bbf/icwmp!496
This commit is contained in:
Suvendhu Hansa 2025-11-10 19:12:47 +05:30 committed by IOPSYS Dev
commit 45f72b949f
No known key found for this signature in database
3 changed files with 67 additions and 12 deletions

View file

@ -357,6 +357,7 @@ static int set_management_server_url(char *refparam, struct dmctx *ctx, void *da
break; break;
case VALUESET: case VALUESET:
dmuci_set_value("cwmp", "acs", "dhcp_discovery", "disable"); dmuci_set_value("cwmp", "acs", "dhcp_discovery", "disable");
dmuci_set_value("cwmp", "acs", "dhcp_url", "");
dmuci_set_value("cwmp", "acs", "url", value); dmuci_set_value("cwmp", "acs", "url", value);
break; break;
} }

View file

@ -26,6 +26,22 @@
#include "heartbeat.h" #include "heartbeat.h"
#include "cwmp_http.h" #include "cwmp_http.h"
static bool dhcp_discovered_acs()
{
char dhcp_url[BUF_SIZE_2048] = {0};
get_uci_path_value(NULL, "cwmp.acs.dhcp_url", dhcp_url, BUF_SIZE_2048);
if (CWMP_STRLEN(cwmp_ctx.conf.acs_url) == 0)
return false;
if (CWMP_STRCMP(dhcp_url, cwmp_ctx.conf.acs_url) == 0) {
// CWMP trying to reach with DHCP discovered ACS url
return true;
}
return false;
}
int get_preinit_config() int get_preinit_config()
{ {
char value[BUF_SIZE_256] = {0}; char value[BUF_SIZE_256] = {0};
@ -85,19 +101,69 @@ static void global_conf_init()
void cwmp_config_load() void cwmp_config_load()
{ {
int error; int error;
struct timeval start_time, current_time;
global_conf_init(); global_conf_init();
cwmp_ctx.net.ipv6_status = is_ipv6_enabled(); cwmp_ctx.net.ipv6_status = is_ipv6_enabled();
error = icwmp_check_http_connection(); error = icwmp_check_http_connection();
if (error != CWMP_OK && dhcp_discovered_acs() == true) {
gettimeofday(&start_time, NULL);
}
while (error != CWMP_OK) { while (error != CWMP_OK) {
if (dhcp_discovered_acs() == true) {
gettimeofday(&current_time, NULL);
long long start_microseconds = (long long)start_time.tv_sec * 1000000 + start_time.tv_usec;
long long current_microseconds = (long long)current_time.tv_sec * 1000000 + current_time.tv_usec;
long long elapsed_microseconds = current_microseconds - start_microseconds;
long long elapsed_seconds = elapsed_microseconds / 1000000;
if (elapsed_seconds >= 300) {
// CWMP not able to connect DHCP discovered ACS url for 300 seconds
// let's renew the lease in search of new ACS URL from DHCP server
if (cwmp_ctx.conf.dhcp_discovery == false) {
set_uci_path_value(NULL, "cwmp.acs.dhcp_discovery", "1");
}
// Renew DHCP lease
if (CWMP_STRLEN(cwmp_ctx.conf.default_wan_iface) != 0) {
struct blob_buf b = {0};
CWMP_MEMSET(&b, 0, sizeof(struct blob_buf));
blob_buf_init(&b, 0);
blobmsg_add_string(&b, "interface", cwmp_ctx.conf.default_wan_iface);
icwmp_ubus_invoke("network.interface", "renew", b.head, NULL, NULL);
blob_buf_free(&b);
}
// Reset start time
gettimeofday(&start_time, NULL);
}
}
CWMP_LOG(DEBUG, "Init: failed to check http connection"); CWMP_LOG(DEBUG, "Init: failed to check http connection");
sleep(UCI_OPTION_READ_INTERVAL); sleep(UCI_OPTION_READ_INTERVAL);
global_conf_init(); global_conf_init();
cwmp_ctx.net.ipv6_status = is_ipv6_enabled(); cwmp_ctx.net.ipv6_status = is_ipv6_enabled();
error = icwmp_check_http_connection(); error = icwmp_check_http_connection();
} }
if (dhcp_discovered_acs() == true) {
// CWMP connected to DHCP discovered ACS URL
if (cwmp_ctx.conf.dhcp_discovery == true) {
set_uci_path_value(NULL, "cwmp.acs.dhcp_discovery", "0");
}
char cur_url[BUF_SIZE_2048] = {0};
get_uci_path_value(NULL, "cwmp.acs.url", cur_url, BUF_SIZE_2048);
if (CWMP_STRCMP(cwmp_ctx.conf.acs_url, cur_url) != 0) {
set_uci_path_value(NULL, "cwmp.acs.url", cwmp_ctx.conf.acs_url);
}
}
} }
static void cwmp_get_device_info(const char *param, char *value, size_t size) { static void cwmp_get_device_info(const char *param, char *value, size_t size) {

View file

@ -158,18 +158,6 @@ int cwmp_schedule_rpc()
if (rpc_acs_methods[rpc_acs->type].parse_response) { if (rpc_acs_methods[rpc_acs->type].parse_response) {
if (rpc_acs_methods[rpc_acs->type].parse_response(rpc_acs)) if (rpc_acs_methods[rpc_acs->type].parse_response(rpc_acs))
goto retry; goto retry;
if (rpc_acs->type == RPC_ACS_INFORM) {
/* Inform response received from ACS and parsed successfully
* now disable DHCP discovery and set url */
if (cwmp_ctx.conf.dhcp_discovery == true)
set_uci_path_value(NULL, "cwmp.acs.dhcp_discovery", "0");
char cur_url[BUF_SIZE_2048] = {0};
get_uci_path_value(NULL, "cwmp.acs.url", cur_url, BUF_SIZE_2048);
if (CWMP_STRCMP(cwmp_ctx.conf.acs_url, cur_url) != 0)
set_uci_path_value(NULL, "cwmp.acs.url", cwmp_ctx.conf.acs_url);
}
} }
ilist = ilist->prev; ilist = ilist->prev;