mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-09 23:34:41 +01:00
Select random cpe port if not configured
This commit is contained in:
parent
3b6737be25
commit
b4db243c1d
3 changed files with 40 additions and 11 deletions
17
src/common.c
17
src/common.c
|
|
@ -24,6 +24,7 @@
|
|||
#include "common.h"
|
||||
#include "cwmp_cli.h"
|
||||
#include "uci_utils.h"
|
||||
#include "ssl_utils.h"
|
||||
#include "ubus_utils.h"
|
||||
#include "log.h"
|
||||
|
||||
|
|
@ -1376,3 +1377,19 @@ void apply_allowed_cr_ip_port(void)
|
|||
pclose(pp);
|
||||
}
|
||||
}
|
||||
|
||||
int get_random_cpe_port(void)
|
||||
{
|
||||
unsigned int min = 30000;
|
||||
unsigned int max = 45000;
|
||||
unsigned int rand_port = 0;
|
||||
|
||||
char *rand = generate_random_string(4);
|
||||
if (rand) {
|
||||
unsigned int tmp_rand = (unsigned int)strtoul(rand, NULL, 16);
|
||||
rand_port = min + (tmp_rand % (max - min + 1));
|
||||
free(rand);
|
||||
}
|
||||
|
||||
return rand_port ? rand_port : DEFAULT_CONNECTION_REQUEST_PORT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -703,4 +703,5 @@ bool end_session_reload_pending(void);
|
|||
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);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -336,13 +336,20 @@ static void config_get_cpe_elements(struct uci_section *s)
|
|||
}
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request timeout: %d", cwmp_ctx.conf.cr_timeout);
|
||||
|
||||
cwmp_ctx.conf.connection_request_port = DEFAULT_CONNECTION_REQUEST_PORT;
|
||||
int a = 0;
|
||||
bool cpe_port_configured = true;
|
||||
char *port = get_value_from_uci_option(cpe_tb[UCI_CPE_PORT]);
|
||||
if (strlen(port) != 0) {
|
||||
int a = (int)strtol(port, NULL, 10);
|
||||
cwmp_ctx.conf.connection_request_port = (a > 0) ? a : DEFAULT_CONNECTION_REQUEST_PORT;
|
||||
a = (int)strtol(port, NULL, 10);
|
||||
}
|
||||
|
||||
if (a > 0) {
|
||||
cwmp_ctx.conf.connection_request_port = a;
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request port: %d", cwmp_ctx.conf.connection_request_port);
|
||||
} else {
|
||||
cpe_port_configured = false;
|
||||
cwmp_ctx.conf.connection_request_port = get_random_cpe_port();
|
||||
}
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request port: %d", cwmp_ctx.conf.connection_request_port);
|
||||
|
||||
char *crpath = get_value_from_uci_option(cpe_tb[UCI_CPE_CRPATH]);
|
||||
if (CWMP_STRLEN(crpath) == 0) {
|
||||
|
|
@ -471,14 +478,18 @@ static void config_get_cpe_elements(struct uci_section *s)
|
|||
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe allowed_cr_ip: %s", cwmp_ctx.conf.valid_cr_ip);
|
||||
|
||||
cwmp_ctx.conf.cpe_bind_retries = 0;
|
||||
char *bind_count = get_value_from_uci_option(cpe_tb[UCI_CPE_BIND_RETRIES]);
|
||||
if (strlen(bind_count) != 0) {
|
||||
int a = (int)strtol(bind_count, NULL, 10);
|
||||
cwmp_ctx.conf.cpe_bind_retries = (a > 0) ? a : 0;
|
||||
if (cpe_port_configured == true) {
|
||||
cwmp_ctx.conf.cpe_bind_retries = 0;
|
||||
char *bind_count = get_value_from_uci_option(cpe_tb[UCI_CPE_BIND_RETRIES]);
|
||||
if (strlen(bind_count) != 0) {
|
||||
int a = (int)strtol(bind_count, NULL, 10);
|
||||
cwmp_ctx.conf.cpe_bind_retries = (a > 0) ? a : 0;
|
||||
}
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe bind retries: %d", cwmp_ctx.conf.cpe_bind_retries);
|
||||
} else {
|
||||
cwmp_ctx.conf.cpe_bind_retries = 1;
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe bind retries set to 1 since random cpe port selected");
|
||||
}
|
||||
|
||||
CWMP_LOG(DEBUG, "CWMP CONFIG - cpe bind retries: %d", cwmp_ctx.conf.cpe_bind_retries);
|
||||
}
|
||||
|
||||
static void config_get_lwn_elements(struct uci_section *s)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue