Ticket refs #3730: bbf: fix Static Code Analysis

This commit is contained in:
Amin Ben Ramdhane 2020-12-11 21:00:30 +01:00
parent 3d4ac802c2
commit 3906faa12d
45 changed files with 1648 additions and 3352 deletions

View file

@ -40,8 +40,7 @@ libbbfdm_la_SOURCES = \
../dmmemjson.c \
../dmoperate.c \
../dmdiagnostics.c \
../dmbbfcommon.c \
../wepkey.c
../dmbbfcommon.c
if BBF_TR181
libbbfdm_la_SOURCES += \

View file

@ -86,17 +86,6 @@ void dmjson_get_string(char *jkey, char **jval)
bbf_api_dmjson_get_string(jkey, jval);
}
void dmbbf_update_enabled_notify_file(unsigned int dm_type, unsigned int amd_version, int instance_mode)
{
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx, dm_type, amd_version, instance_mode);
dmctx.in_param = "";
dm_entry_enabled_notify(&dmctx);
dm_ctx_clean(&dmctx);
}
int get_dm_type(char *dm_str)
{
if (dm_str == NULL)

View file

@ -15,8 +15,6 @@
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
extern struct list_head list_execute_end_session;
void bbf_uci_commit_bbfdm(void);
void bbf_uci_revert_bbfdm(void);
int set_bbfdatamodel_type(int bbf_type);
@ -30,11 +28,8 @@ int copy_temporary_file_to_original_file(char *f1, char *f2);
void dmjson_get_var(char *jkey, char **jval);
void dmjson_get_string(char *jkey, char **jval);
void apply_end_session(void);
int dm_add_end_session(struct dmctx *ctx, void(*function)(struct execute_end_session *), int action, void *data);
void bbf_set_end_session_flag (struct dmctx *ctx, unsigned int flag);
int bbfdmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value);
void dmbbf_update_enabled_notify_file(unsigned int dm_type, unsigned int amd_version, int instance_mode);
int get_dm_type(char *dm_str);
#endif //__DMBBFCOMMON_H__

View file

@ -13,9 +13,8 @@
#include "dmentry.h"
#include "dmdiagnostics.h"
int read_next;
struct download_diag download_stats = {0};
struct upload_diagnostic_stats upload_stats = {0};
static int read_next;
static struct diagnostic_stats diag_stats = {0};
char *get_diagnostics_option(char *sec_name, char *option)
{
@ -72,201 +71,6 @@ void set_diagnostics_interface_option(struct dmctx *ctx, char *sec_name, char *v
}
}
static void init_download_stats(void)
{
memset(&download_stats, 0, sizeof(download_stats));
}
static void init_upload_stats(void)
{
memset(&upload_stats, 0, sizeof(upload_stats));
}
static void ftp_download_per_packet(libtrace_packet_t *packet)
{
struct tm lt;
struct timeval ts;
libtrace_tcp_t *tcp;
char tcp_flag[16] = "";
char *nexthdr;
char s_now[20];
uint8_t proto;
uint32_t remaining;
tcp = trace_get_transport(packet, &proto, &remaining);
if (tcp == NULL)
return;
else
nexthdr = trace_get_payload_from_tcp(tcp, &remaining);
if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS ");
if (tcp->cwr) strcat(tcp_flag, "CWR ");
if (tcp->ece) strcat(tcp_flag, "ECE ");
if (tcp->fin) strcat(tcp_flag, "FIN ");
if (tcp->syn) strcat(tcp_flag, "SYN ");
if (tcp->rst) strcat(tcp_flag, "RST ");
if (tcp->psh) strcat(tcp_flag, "PSH ");
if (tcp->ack) strcat(tcp_flag, "ACK ");
if (tcp->urg) strcat(tcp_flag, "URG ");
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_SIZE_RESPONSE) && strncmp(nexthdr, FTP_SIZE_RESPONSE, strlen(FTP_SIZE_RESPONSE)) == 0)
{
char *val = strstr(nexthdr,"213");
char *pch, *pchr;
val += strlen("213 ");
pch=strtok_r(val, " \r\n\t", &pchr);
download_stats.test_bytes_received = atoi(pch);
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0)
{
download_stats.ftp_syn = 1;
return;
}
if (download_stats.random_seq == 0 && strcmp(tcp_flag, "SYN ") == 0 && download_stats.ftp_syn == 1)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
download_stats.random_seq = ntohl(tcp->seq);
snprintf(download_stats.tcpopenrequesttime, sizeof(download_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && download_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == download_stats.random_seq)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(download_stats.tcpopenresponsetime, sizeof(download_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
download_stats.random_seq = ntohl(tcp->ack_seq);
snprintf(download_stats.tcpopenresponsetime, sizeof(download_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_RETR_REQUEST) && strncmp(nexthdr, FTP_RETR_REQUEST, strlen(FTP_RETR_REQUEST)) == 0)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(download_stats.romtime, sizeof(download_stats.romtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == download_stats.random_seq && download_stats.ack_seq == 0)
{
download_stats.ack_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == download_stats.ack_seq )
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (download_stats.first_data == 0)
{
snprintf(download_stats.bomtime, sizeof(download_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
}
download_stats.first_data = 1;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == download_stats.ack_seq)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (download_stats.first_data == 0)
{
snprintf(download_stats.bomtime, sizeof(download_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
download_stats.first_data = 1;
}
snprintf(download_stats.eomtime, sizeof(download_stats.eomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
}
}
static void http_download_per_packet(libtrace_packet_t *packet)
{
struct tm lt;
struct timeval ts;
libtrace_tcp_t *tcp;
char *nexthdr, tcp_flag[16] = "", s_now[20];
uint8_t proto;
uint32_t remaining;
tcp = trace_get_transport(packet, &proto, &remaining);
if (tcp == NULL)
return;
else
nexthdr = trace_get_payload_from_tcp(tcp, &remaining);
if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS ");
if (tcp->cwr) strcat(tcp_flag, "CWR ");
if (tcp->ece) strcat(tcp_flag, "ECE ");
if (tcp->fin) strcat(tcp_flag, "FIN ");
if (tcp->syn) strcat(tcp_flag, "SYN ");
if (tcp->rst) strcat(tcp_flag, "RST ");
if (tcp->psh) strcat(tcp_flag, "PSH ");
if (tcp->ack) strcat(tcp_flag, "ACK ");
if (tcp->urg) strcat(tcp_flag, "URG ");
if (strcmp(tcp_flag, "SYN ") == 0 && download_stats.random_seq == 0) {
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(download_stats.tcpopenrequesttime, sizeof(download_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
download_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && download_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == download_stats.random_seq) {
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(download_stats.tcpopenresponsetime, sizeof(download_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
download_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "GET", 3) == 0) {
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(download_stats.romtime, sizeof(download_stats.romtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
download_stats.get_ack = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == download_stats.get_ack && download_stats.ack_seq == 0) {
download_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == download_stats.ack_seq ) {
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (download_stats.first_data == 0) {
snprintf(download_stats.bomtime, sizeof(download_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
char *val = strstr(nexthdr,"Content-Length");
char *pch, *pchr;
val += strlen("Content-Length: ");
pch=strtok_r(val, " \r\n\t", &pchr);
download_stats.test_bytes_received = atoi(pch);
download_stats.first_data = 1;
}
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == download_stats.ack_seq) {
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (download_stats.first_data == 0) {
snprintf(download_stats.bomtime, sizeof(download_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
char *val = strstr(nexthdr,"Content-Length");
char *pch, *pchr;
val += strlen("Content-Length: ");
pch=strtok_r(val, " \r\n\t", &pchr);
download_stats.test_bytes_received = atoi(pch);
download_stats.first_data = 1;
}
snprintf(download_stats.eomtime, sizeof(download_stats.eomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
return;
}
}
static void libtrace_cleanup(libtrace_t *trace, libtrace_packet_t *packet)
{
if (trace)
@ -276,281 +80,355 @@ static void libtrace_cleanup(libtrace_t *trace, libtrace_packet_t *packet)
trace_destroy_packet(packet);
}
static void set_download_stats(char *protocol)
static void set_stats_value(char *diag_type)
{
char buf[16] = {0};
set_diagnostics_option("download", "ROMtime", ((download_stats.romtime)[0] != 0) ? download_stats.romtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("download", "BOMtime", ((download_stats.bomtime)[0] != 0) ? download_stats.bomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("download", "EOMtime", ((download_stats.eomtime)[0] != 0) ? download_stats.eomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("download", "TCPOpenRequestTime", ((download_stats.tcpopenrequesttime)[0] != 0) ? download_stats.tcpopenrequesttime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("download", "TCPOpenResponseTime",((download_stats.tcpopenresponsetime)[0] != 0) ? download_stats.tcpopenresponsetime : "0001-01-01T00:00:00.000000Z");
snprintf(buf, sizeof(buf), "%d", download_stats.test_bytes_received);
set_diagnostics_option("download", "TestBytesReceived", buf);
set_diagnostics_option(diag_type, "ROMtime", ((diag_stats.romtime)[0] != 0) ? diag_stats.romtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "BOMtime", ((diag_stats.bomtime)[0] != 0) ? diag_stats.bomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "EOMtime", ((diag_stats.eomtime)[0] != 0) ? diag_stats.eomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "TCPOpenRequestTime", ((diag_stats.tcpopenrequesttime)[0] != 0) ? diag_stats.tcpopenrequesttime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option(diag_type, "TCPOpenResponseTime",((diag_stats.tcpopenresponsetime)[0] != 0) ? diag_stats.tcpopenresponsetime : "0001-01-01T00:00:00.000000Z");
snprintf(buf, sizeof(buf), "%d", diag_stats.test_bytes_received);
set_diagnostics_option(diag_type, "TestBytesReceived", buf);
}
static void set_upload_stats(char *protocol)
static int get_tcp_flag_from_packet(libtrace_packet_t *packet, libtrace_tcp_t **tcp, char *tcp_flag, char **nexthdr)
{
set_diagnostics_option("upload", "ROMtime", ((upload_stats.romtime)[0] != 0) ? upload_stats.romtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("upload", "BOMtime", ((upload_stats.bomtime)[0] != 0) ? upload_stats.bomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("upload", "EOMtime", ((upload_stats.eomtime)[0] != 0) ? upload_stats.eomtime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("upload", "TCPOpenRequestTime", ((upload_stats.tcpopenrequesttime)[0] != 0) ? upload_stats.tcpopenrequesttime : "0001-01-01T00:00:00.000000Z");
set_diagnostics_option("upload", "TCPOpenResponseTime", ((upload_stats.tcpopenresponsetime)[0] != 0) ? upload_stats.tcpopenresponsetime : "0001-01-01T00:00:00.000000Z");
uint8_t proto;
uint32_t remaining;
*tcp = trace_get_transport(packet, &proto, &remaining);
if (*tcp == NULL)
return -1;
*nexthdr = trace_get_payload_from_tcp(*tcp, &remaining);
if ((*tcp)->ecn_ns) strcat(tcp_flag, "ECN_NS ");
if ((*tcp)->cwr) strcat(tcp_flag, "CWR ");
if ((*tcp)->ece) strcat(tcp_flag, "ECE ");
if ((*tcp)->fin) strcat(tcp_flag, "FIN ");
if ((*tcp)->syn) strcat(tcp_flag, "SYN ");
if ((*tcp)->rst) strcat(tcp_flag, "RST ");
if ((*tcp)->psh) strcat(tcp_flag, "PSH ");
if ((*tcp)->ack) strcat(tcp_flag, "ACK ");
if ((*tcp)->urg) strcat(tcp_flag, "URG ");
return 0;
}
static void http_download_per_packet(libtrace_packet_t *packet)
{
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm http_download_lt;
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
struct timeval http_download_ts = trace_get_timeval(packet);
localtime_r(&(http_download_ts.tv_sec), &http_download_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &http_download_lt);
if (strcmp(tcp_flag, "SYN ") == 0 && diag_stats.random_seq == 0) {
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "GET", 3) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
diag_stats.get_ack = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == diag_stats.get_ack && diag_stats.ack_seq == 0) {
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
char *val = strstr(nexthdr,"Content-Length");
char *pch, *pchr;
val += strlen("Content-Length: ");
pch = strtok_r(val, " \r\n\t", &pchr);
diag_stats.test_bytes_received = atoi(pch);
diag_stats.first_data = 1;
return;
}
if ((strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq) {
if (diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
char *val = strstr(nexthdr,"Content-Length");
char *pch, *pchr;
val += strlen("Content-Length: ");
pch = strtok_r(val, " \r\n\t", &pchr);
diag_stats.test_bytes_received = atoi(pch);
diag_stats.first_data = 1;
}
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) http_download_ts.tv_usec);
read_next = 0;
return;
}
}
static void ftp_download_per_packet(libtrace_packet_t *packet)
{
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm ftp_download_lt;
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
struct timeval ftp_download_ts = trace_get_timeval(packet);
localtime_r(&(ftp_download_ts.tv_sec), &ftp_download_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &ftp_download_lt);
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_SIZE_RESPONSE) && strncmp(nexthdr, FTP_SIZE_RESPONSE, strlen(FTP_SIZE_RESPONSE)) == 0) {
char *val = strstr(nexthdr,"213");
char *pch, *pchr;
val += strlen("213 ");
pch =strtok_r(val, " \r\n\t", &pchr);
diag_stats.test_bytes_received = atoi(pch);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) {
diag_stats.ftp_syn = 1;
return;
}
if (diag_stats.random_seq == 0 && strcmp(tcp_flag, "SYN ") == 0 && diag_stats.ftp_syn == 1) {
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_RETR_REQUEST) && strncmp(nexthdr, FTP_RETR_REQUEST, strlen(FTP_RETR_REQUEST)) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == diag_stats.random_seq && diag_stats.ack_seq == 0) {
diag_stats.ack_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.first_data = 1;
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq) {
if (diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
diag_stats.first_data = 1;
}
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec);
read_next = 0;
return;
}
}
static void http_upload_per_packet(libtrace_packet_t *packet)
{
struct tm lt;
struct timeval ts;
libtrace_tcp_t *tcp;
char tcp_flag[16] = "";
char *nexthdr;
char s_now[20];
uint8_t proto;
uint32_t remaining;
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm http_upload_lt;
tcp = trace_get_transport(packet, &proto, &remaining);
if (tcp == NULL)
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
else
nexthdr = trace_get_payload_from_tcp(tcp, &remaining);
if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS ");
if (tcp->cwr) strcat(tcp_flag, "CWR ");
if (tcp->ece) strcat(tcp_flag, "ECE ");
if (tcp->fin) strcat(tcp_flag, "FIN ");
if (tcp->syn) strcat(tcp_flag, "SYN ");
if (tcp->rst) strcat(tcp_flag, "RST ");
if (tcp->psh) strcat(tcp_flag, "PSH ");
if (tcp->ack) strcat(tcp_flag, "ACK ");
if (tcp->urg) strcat(tcp_flag, "URG ");
struct timeval http_upload_ts = trace_get_timeval(packet);
localtime_r(&(http_upload_ts.tv_sec), &http_upload_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &http_upload_lt);
if (strcmp(tcp_flag, "SYN ") == 0 && download_stats.random_seq == 0)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(upload_stats.tcpopenrequesttime, sizeof(upload_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
upload_stats.random_seq = ntohl(tcp->seq);
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && upload_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == upload_stats.random_seq)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(upload_stats.tcpopenresponsetime, sizeof(upload_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
upload_stats.random_seq = ntohl(tcp->seq);
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "PUT", 3) == 0)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(upload_stats.romtime, sizeof(upload_stats.romtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
if (strstr(nexthdr, "Expect: 100-continue"))
{
upload_stats.tmp=1;
upload_stats.ack_seq = ntohl(tcp->ack_seq);
}
else
upload_stats.ack_seq = ntohl(tcp->ack_seq);
if (strcmp(tcp_flag, "SYN ") == 0 && diag_stats.random_seq == 0) {
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && upload_stats.tmp == 1 && strstr(nexthdr, "100 Continue"))
{
upload_stats.tmp = 2;
upload_stats.ack_seq = ntohl(tcp->ack_seq);
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && upload_stats.tmp == 2 && ntohl(tcp->seq) == upload_stats.ack_seq)
{
upload_stats.tmp = 0;
upload_stats.ack_seq = ntohl(tcp->ack_seq);
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "PUT", 3) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
if (strstr(nexthdr, "Expect: 100-continue")) {
diag_stats.tmp = 1;
diag_stats.ack_seq = ntohl(tcp->ack_seq);
} else
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == upload_stats.ack_seq && upload_stats.tmp == 0)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (upload_stats.first_data == 0)
{
snprintf(upload_stats.bomtime, sizeof(upload_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
upload_stats.first_data = 1;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && diag_stats.tmp == 1 && strstr(nexthdr, "100 Continue")) {
diag_stats.tmp = 2;
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == upload_stats.ack_seq && upload_stats.tmp == 0)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (upload_stats.first_data == 0)
{
snprintf(upload_stats.bomtime, sizeof(upload_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
upload_stats.first_data = 1;
}
if (strcmp(tcp_flag, "ACK ") == 0 && diag_stats.tmp == 2 && ntohl(tcp->seq) == diag_stats.ack_seq) {
diag_stats.tmp = 0;
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->seq) == upload_stats.ack_seq && upload_stats.tmp == 0)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(upload_stats.eomtime, sizeof(upload_stats.eomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.tmp == 0 && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.first_data = 1;
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.tmp == 0) {
if (diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
diag_stats.first_data = 1;
}
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->seq) == diag_stats.ack_seq && diag_stats.tmp == 0) {
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) http_upload_ts.tv_usec);
read_next = 0;
return;
}
}
static void ftp_upload_per_packet(libtrace_packet_t *packet)
{
struct tm lt;
struct timeval ts;
libtrace_tcp_t *tcp;
uint8_t proto;
uint32_t remaining;
char tcp_flag[16] = "";
char *nexthdr;
char s_now[20];
libtrace_tcp_t *tcp = NULL;
char *nexthdr, tcp_flag[16] = {0}, s_now[20] = {0};
struct tm ftp_upload_lt;
tcp = trace_get_transport(packet, &proto, &remaining);
if (tcp == NULL)
if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr))
return;
else
nexthdr = trace_get_payload_from_tcp(tcp, &remaining);
if (tcp->ecn_ns) strcat(tcp_flag, "ECN_NS ");
if (tcp->cwr) strcat(tcp_flag, "CWR ");
if (tcp->ece) strcat(tcp_flag, "ECE ");
if (tcp->fin) strcat(tcp_flag, "FIN ");
if (tcp->syn) strcat(tcp_flag, "SYN ");
if (tcp->rst) strcat(tcp_flag, "RST ");
if (tcp->psh) strcat(tcp_flag, "PSH ");
if (tcp->ack) strcat(tcp_flag, "ACK ");
if (tcp->urg) strcat(tcp_flag, "URG ");
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0)
{
upload_stats.ftp_syn = 1;
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) {
diag_stats.ftp_syn = 1;
return;
}
if (strcmp(tcp_flag, "SYN ") == 0 && upload_stats.ftp_syn == 1)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
upload_stats.random_seq = ntohl(tcp->seq);
snprintf(upload_stats.tcpopenrequesttime, sizeof(upload_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
struct timeval ftp_upload_ts = trace_get_timeval(packet);
localtime_r(&(ftp_upload_ts.tv_sec), &ftp_upload_lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &ftp_upload_lt);
if (strcmp(tcp_flag, "SYN ") == 0 && diag_stats.ftp_syn == 1) {
diag_stats.random_seq = ntohl(tcp->seq);
snprintf(diag_stats.tcpopenrequesttime, sizeof(diag_stats.tcpopenrequesttime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
return;
}
if (strcmp(tcp_flag, "SYN ACK ") == 0 && upload_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == upload_stats.random_seq)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(upload_stats.tcpopenresponsetime, sizeof(upload_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
upload_stats.random_seq = ntohl(tcp->ack_seq);
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_STOR_REQUEST) && strncmp(nexthdr, FTP_STOR_REQUEST, strlen(FTP_STOR_REQUEST)) == 0)
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(upload_stats.romtime, sizeof(upload_stats.romtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == upload_stats.random_seq && upload_stats.ack_seq == 0)
{
upload_stats.ack_seq = ntohl(tcp->ack_seq);
if (strcmp(tcp_flag, "SYN ACK ") == 0 && diag_stats.random_seq != 0 && (ntohl(tcp->ack_seq) - 1 ) == diag_stats.random_seq) {
snprintf(diag_stats.tcpopenresponsetime, sizeof(diag_stats.tcpopenresponsetime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
diag_stats.random_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == upload_stats.ack_seq )
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (upload_stats.first_data == 0)
{
snprintf(upload_stats.bomtime, sizeof(upload_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
upload_stats.first_data = 1;
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_STOR_REQUEST) && strncmp(nexthdr, FTP_STOR_REQUEST, strlen(FTP_STOR_REQUEST)) == 0) {
snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->seq) == diag_stats.random_seq && diag_stats.ack_seq == 0) {
diag_stats.ack_seq = ntohl(tcp->ack_seq);
return;
}
if (strcmp(tcp_flag, "ACK ") == 0 && ntohl(tcp->ack_seq) == diag_stats.ack_seq && diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
diag_stats.first_data = 1;
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == diag_stats.ack_seq) {
if (diag_stats.first_data == 0) {
snprintf(diag_stats.bomtime, sizeof(diag_stats.bomtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
diag_stats.first_data = 1;
}
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == upload_stats.ack_seq) //&& strlen(nexthdr) > 16 && strncmp(nexthdr, "HTTP/1.1 200 OK", 16) == 0
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
if (upload_stats.first_data == 0)
{
snprintf(upload_stats.bomtime, sizeof(upload_stats.bomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
upload_stats.first_data = 1;
}
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && strlen(nexthdr) > strlen(FTP_TRANSFERT_COMPLETE) && strncmp(nexthdr, FTP_TRANSFERT_COMPLETE, strlen(FTP_TRANSFERT_COMPLETE)) == 0) //&& strlen(nexthdr) > 16 && strncmp(nexthdr, "HTTP/1.1 200 OK", 16) == 0
{
ts = trace_get_timeval(packet);
(void) localtime_r(&(ts.tv_sec), &lt);
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &lt);
snprintf(upload_stats.eomtime, sizeof(upload_stats.eomtime), "%s.%06ldZ", s_now, (long) ts.tv_usec);
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && strlen(nexthdr) > strlen(FTP_TRANSFERT_COMPLETE) && strncmp(nexthdr, FTP_TRANSFERT_COMPLETE, strlen(FTP_TRANSFERT_COMPLETE)) == 0) {
snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec);
read_next = 0;
return;
}
}
static int extract_stats(char *dump_file, int proto, int diagnostic_type, char *protocol)
static int extract_stats(char *dump_file, int proto, int diagnostic_type)
{
libtrace_t *trace = NULL;
libtrace_packet_t *packet = NULL;
read_next = 1;
packet = trace_create_packet();
if (packet == NULL) {
perror("Creating libtrace packet");
libtrace_cleanup(trace, packet);
return 1;
}
trace = trace_create(dump_file);
if (!trace) {
return -1;
}
trace = trace_create(dump_file);
if (!trace)
return -1;
if (trace_is_err(trace)) {
trace_perror(trace,"Opening trace file");
libtrace_cleanup(trace, packet);
return -1;
}
if (trace_start(trace) == -1) {
libtrace_cleanup(trace, packet);
return 1;
}
if (trace_start(trace) == -1) {
trace_perror(trace,"Starting trace");
libtrace_cleanup(trace, packet);
return 1;
}
if (proto == DOWNLOAD_DIAGNOSTIC_HTTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC)
{
while (trace_read_packet(trace,packet)>0 && read_next == 1) {
if (proto == DIAGNOSTIC_HTTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
http_download_per_packet(packet);
continue;
}
set_download_stats(protocol);
}
else if (proto == DOWNLOAD_DIAGNOSTIC_FTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC)
{
while (trace_read_packet(trace,packet)>0 && read_next == 1) {
set_stats_value("download");
} else if (proto == DIAGNOSTIC_FTP && diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
ftp_download_per_packet(packet);
continue;
}
set_download_stats(protocol);
}
else if (proto == DOWNLOAD_DIAGNOSTIC_HTTP && diagnostic_type == UPLOAD_DIAGNOSTIC)
{
while (trace_read_packet(trace,packet)>0 && read_next == 1) {
set_stats_value("download");
} else if (proto == DIAGNOSTIC_HTTP && diagnostic_type == UPLOAD_DIAGNOSTIC) {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
http_upload_per_packet(packet);
continue;
}
set_upload_stats(protocol);
}
else
{
while (trace_read_packet(trace,packet)>0 && read_next == 1) {
set_stats_value("upload");
} else {
while (trace_read_packet(trace,packet) > 0 && read_next == 1) {
ftp_upload_per_packet(packet);
continue;
}
set_upload_stats(protocol);
set_stats_value("upload");
}
libtrace_cleanup(trace, packet);
return 0;
}
@ -611,11 +489,11 @@ int start_upload_download_diagnostic(int diagnostic_type, char *proto)
url = get_diagnostics_option("download", "url");
status = get_diagnostics_option("download", "DiagnosticState");
if (status && strcmp(status, "Complete") == 0) {
init_download_stats();
memset(&diag_stats, 0, sizeof(diag_stats));
if (strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_HTTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_HTTP)) == 0)
extract_stats(DOWNLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_HTTP, DOWNLOAD_DIAGNOSTIC, proto);
extract_stats(DOWNLOAD_DUMP_FILE, DIAGNOSTIC_HTTP, DOWNLOAD_DIAGNOSTIC);
if (strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_FTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_FTP)) == 0)
extract_stats(DOWNLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_FTP, DOWNLOAD_DIAGNOSTIC, proto);
extract_stats(DOWNLOAD_DUMP_FILE, DIAGNOSTIC_FTP, DOWNLOAD_DIAGNOSTIC);
} else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
return -1;
} else {
@ -630,11 +508,11 @@ int start_upload_download_diagnostic(int diagnostic_type, char *proto)
url = get_diagnostics_option("upload", "url");
status = get_diagnostics_option("upload", "DiagnosticState");
if (status && strcmp(status, "Complete") == 0) {
init_upload_stats();
memset(&diag_stats, 0, sizeof(diag_stats));
if (strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_HTTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_HTTP)) == 0)
extract_stats(UPLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_HTTP, UPLOAD_DIAGNOSTIC, proto);
extract_stats(UPLOAD_DUMP_FILE, DIAGNOSTIC_HTTP, UPLOAD_DIAGNOSTIC);
if (strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_FTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_FTP)) == 0)
extract_stats(UPLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_FTP, UPLOAD_DIAGNOSTIC, proto);
extract_stats(UPLOAD_DUMP_FILE, DIAGNOSTIC_FTP, UPLOAD_DIAGNOSTIC);
} else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
return -1;
}

View file

@ -25,15 +25,14 @@
#define FTP_STOR_REQUEST "STOR"
#define DMMAP_DIAGNOSTIGS "dmmap_diagnostics"
struct download_diag
struct diagnostic_stats
{
char romtime[default_date_size];
char bomtime[default_date_size];
char eomtime[default_date_size];
char tcpopenrequesttime[default_date_size];
char tcpopenresponsetime[default_date_size];
int test_bytes_received;
unsigned long total_bytes_received;
char tcpopenrequesttime[default_date_size];
char tcpopenresponsetime[default_date_size];
int tmp;
int first_data;
uint16_t ip_len;
@ -43,27 +42,9 @@ struct download_diag
uint32_t ftp_syn;
};
struct upload_diagnostic_stats
{
char romtime[default_date_size];
char bomtime[default_date_size];
char eomtime[default_date_size];
unsigned long total_bytes_sent;
char tcpopenrequesttime[default_date_size];
char tcpopenresponsetime[default_date_size];
int tmp;
int first_data;
uint16_t ip_len;
uint32_t ack_seq;
uint32_t random_seq;
uint32_t get_ack;
uint32_t ftp_syn;
};
enum download_diagnostic_protocol {
DOWNLOAD_DIAGNOSTIC_HTTP = 1,
DOWNLOAD_DIAGNOSTIC_FTP
DIAGNOSTIC_HTTP = 1,
DIAGNOSTIC_FTP
};
enum diagnostic_type {

113
dmentry.c
View file

@ -17,7 +17,6 @@
#include "dmentrylibrary.h"
#include "dmoperate.h"
#include "device.h"
#include "wepkey.h"
#include "dmbbfcommon.h"
#ifdef BBF_TR064
@ -27,6 +26,9 @@
LIST_HEAD(head_package_change);
LIST_HEAD(list_enabled_lw_notify);
static char json_hash[64] = {0};
static char library_hash[64] = {0};
int usp_fault_map(int fault)
{
int out_fault;
@ -223,15 +225,8 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
int err2 = 0;
#endif
if (check_stats_json_folder(JSON_FOLDER_PATH)) {
free_json_dynamic_arrays(tEntry181Obj);
load_json_dynamic_arrays(ctx);
}
if (check_stats_library_folder(LIBRARY_FOLDER_PATH)) {
free_library_dynamic_arrays(tEntry181Obj);
load_library_dynamic_arrays(ctx);
}
// Load dynamic objects and parameters
load_dynamic_arrays(ctx);
if (!inparam) inparam = "";
ctx->in_param = inparam;
@ -331,7 +326,7 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
break;
case CMD_UPNP_GET_INSTANCES:
ctx->depth = atoi(arg1);
fault = dm_entry_upnp_get_instances(ctx);
fault = dm_entry_upnp_get_instances(ctx, false);
break;
case CMD_UPNP_SET_VALUES:
ctx->in_value = arg1 ? arg1 : "";
@ -347,13 +342,13 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
ctx->dmparam_flags |= (event) ? DM_PARAM_EVENT_ON_CHANGE : 0;
ctx->dmparam_flags |= (alarm) ? DM_PARAM_ALARAM_ON_CHANGE : 0;
ctx->setaction = VALUECHECK;
fault = dm_entry_upnp_set_attributes(ctx);
fault = dm_entry_upnp_get_set_attributes(ctx, false);
} else {
fault = FAULT_9003;
}
break;
case CMD_UPNP_GET_ATTRIBUTES:
fault = dm_entry_upnp_get_attributes(ctx);
fault = dm_entry_upnp_get_set_attributes(ctx, true);
break;
case CMD_UPNP_DEL_INSTANCE:
fault = dm_entry_upnp_delete_instance(ctx);
@ -440,7 +435,7 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2)
ctx->in_param = n->name;
ctx->dmparam_flags = n->flags;
ctx->stop = false;
fault = dm_entry_upnp_set_attributes(ctx);
fault = dm_entry_upnp_get_set_attributes(ctx, false);
if (fault) break;
}
if (fault) {
@ -554,8 +549,7 @@ int dm_entry_upnp_check_onchange_param(struct dmctx *pctx, struct list_head *ena
add_list_upnp_param_track(&dmctx, changed_head, p->name, "1", all_instances, 1);
ischange = 1;
}
}
else {
} else {
fault = dm_entry_param_method(&dmctx, CMD_UPNP_GET_VALUES, p->name, NULL, NULL);
if (!fault && dmctx.list_parameter.next != &dmctx.list_parameter) {
dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
@ -617,7 +611,7 @@ int dm_entry_upnp_check_versiononchange_param(struct dmctx *pctx)
{
struct dmctx dmctx = {0};
struct dm_upnp_enabled_track *p;
struct dm_parameter *dm_parameter;
struct dm_parameter *parameter;
int version, fault, ischange = 0;
char *all_instances;
@ -632,21 +626,19 @@ int dm_entry_upnp_check_versiononchange_param(struct dmctx *pctx)
add_list_upnp_param_track(&dmctx, &list_upnp_changed_version, p->name, "1", all_instances, 1);
ischange = 1;
}
}
else {
} else {
fault = dm_entry_param_method(&dmctx, CMD_UPNP_GET_VALUES, p->name, NULL, NULL);
if (!fault && dmctx.list_parameter.next != &dmctx.list_parameter) {
dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
if (strcmp(dm_parameter->data, p->value) != 0) {
dm_upnp_update_enabled_track_value(p, dm_parameter->data);
add_list_upnp_param_track(&dmctx, &list_upnp_changed_version, p->name, p->key, dm_parameter->data, 0);
parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
if (strcmp(parameter->data, p->value) != 0) {
dm_upnp_update_enabled_track_value(p, parameter->data);
add_list_upnp_param_track(&dmctx, &list_upnp_changed_version, p->name, p->key, parameter->data, 0);
ischange = 1;
}
}
free_all_list_parameter(&dmctx);
}
if (ischange)
{
if (ischange) {
char buf[32];
char *tmp;
struct uci_section *s = NULL;
@ -654,8 +646,7 @@ int dm_entry_upnp_check_versiononchange_param(struct dmctx *pctx)
snprintf(buf, sizeof(buf), "%d", version);
if (p->key) {
dmuci_set_value(UPNP_CFG, p->key, "version", buf);
}
else {
} else {
dmuci_add_section(UPNP_CFG, "parameter_version", &s);
if (s != NULL) {
dmuci_set_value_by_section(s, "version", buf);
@ -894,12 +885,80 @@ int cli_output_dm_upnp_variable_state(struct dmctx *dmctx, int cmd, char *variab
}
#endif
static int get_stats_folder(const char *path, bool is_json, int *file_count, unsigned long *size, unsigned long *date)
{
struct stat stats;
struct dirent *entry;
DIR *dirp = NULL;
char buf[264] = {0};
int filecount = 0;
unsigned long filesize = 0, filedate = 0;
if (folder_exists(path)) {
dirp = opendir(path);
while ((entry = readdir(dirp)) != NULL) {
if ((entry->d_type == DT_REG) && (strstr(entry->d_name, is_json ? ".json" : ".so"))) {
filecount++;
snprintf(buf, sizeof(buf), "%s/%s", path, entry->d_name);
if (!stat(buf, &stats)) {
filesize = (filesize + stats.st_size) / 2;
filedate = (filedate + stats.st_mtime) / 2;
}
}
}
if (dirp) closedir(dirp);
*file_count = filecount;
*size = filesize;
*date = filedate;
return 1;
}
return 0;
}
static int check_stats_folder(const char *path, bool is_json)
{
int file_count = 0;
unsigned long size = 0, date = 0;
char buf[128] = {0};
if (!get_stats_folder(path, is_json, &file_count, &size, &date))
return 0;
snprintf(buf, sizeof(buf), "count:%d,sizes:%lu,date:%lu", file_count, size, date);
if (strcmp(buf, is_json ? json_hash : library_hash)) {
strcpy(is_json ? json_hash : library_hash, buf);
return 1;
}
return 0;
}
int load_dynamic_arrays(struct dmctx *ctx)
{
// Load dynamic objects and parameters exposed via a JSON file
if (check_stats_folder(JSON_FOLDER_PATH, true)) {
free_json_dynamic_arrays(tEntry181Obj);
load_json_dynamic_arrays(ctx);
}
// Load dynamic objects and parameters exposed via a library
if (check_stats_folder(LIBRARY_FOLDER_PATH, false)) {
free_library_dynamic_arrays(tEntry181Obj);
load_library_dynamic_arrays(ctx);
}
return 0;
}
int free_dynamic_arrays(void)
{
DMOBJ *root = tEntry181Obj;
DMNODE node = {.current_object = ""};
free_dm_browse_node_dynamic_object_tree(&node, root);
free_json_dynamic_arrays(tEntry181Obj);
free_library_dynamic_arrays(tEntry181Obj);
return 0;
}

View file

@ -49,6 +49,7 @@ int dm_entry_upnp_get_current_configuration_version(struct dmctx *dmctx, char **
int dm_ctx_clean(struct dmctx *ctx);
int dm_ctx_clean_sub(struct dmctx *ctx);
int load_dynamic_arrays(struct dmctx *ctx);
int free_dynamic_arrays(void);
int dmentry_get_parameter_leaf_value(struct dmctx *ctx, char *inparam);
void dm_ctx_init_list_parameter(struct dmctx *ctx);

View file

@ -14,38 +14,6 @@
#include "dmentry.h"
LIST_HEAD(json_list);
static char json_hash[64] = "";
static int get_stats_json_folder(char *folder_path, int *file_count, unsigned long *size, unsigned long *date)
{
struct stat stats;
struct dirent *entry;
DIR *dirp = NULL;
char buf[264] = {0};
int filecount = 0;
unsigned long filesize = 0, filedate = 0;
if (folder_exists(folder_path)) {
dirp = opendir(folder_path);
while ((entry = readdir(dirp)) != NULL) {
if ((entry->d_type == DT_REG) && (strstr(entry->d_name, ".json"))) {
filecount++;
snprintf(buf, sizeof(buf), "%s/%s", folder_path, entry->d_name);
if (!stat(buf, &stats)) {
filesize = (filesize + stats.st_size) / 2;
filedate = (filedate + stats.st_mtime) / 2;
}
}
}
if (dirp) closedir(dirp);
*file_count = filecount;
*size = filesize;
*date = filedate;
return 1;
}
return 0;
}
static void add_json_data_to_list(struct list_head *dup_list, char *name, char *arg1, const char *arg2, const char *arg3, const char *arg4,
const char *arg5, const char *arg6, const char *arg7, const char *arg8)
@ -127,23 +95,6 @@ int free_json_dynamic_arrays(DMOBJ *dm_entryobj)
return 0;
}
int check_stats_json_folder(char *json_folder_path)
{
int file_count = 0;
unsigned long size = 0, date = 0;
char str[128] = "";
if (!get_stats_json_folder(json_folder_path, &file_count, &size, &date))
return 0;
snprintf(str, sizeof(str), "count:%d,sizes:%lu,date:%lu", file_count, size, date);
if (strcmp(str, json_hash)) {
strcpy(json_hash, str);
return 1;
}
return 0;
}
static void generate_prefixobj_and_obj_full_obj(char *full_obj, char **prefix_obj, char **obj)
{
char *pch = NULL, *pchr = NULL, *tmp_obj = NULL, *str = NULL;
@ -828,41 +779,6 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, s
}
}
static void parse_next_obj(struct dmctx *ctx, json_object *jobj)
{
json_object_object_foreach(jobj, key, json_obj) {
DMOBJ *dm_entryobj = NULL;
if (json_object_get_type(json_obj) == json_type_object && is_obj(key, json_obj)) {
int check_obj = check_json_root_obj(ctx, key, &dm_entryobj);
if (check_obj == 0) continue;
if (check_obj == 1) {
parse_next_obj(ctx, json_obj);
} else {
if (!dm_entryobj) continue;
if (dm_entryobj->nextdynamicobj == NULL) {
dm_entryobj->nextdynamicobj = calloc(__INDX_DYNAMIC_MAX, sizeof(struct dm_dynamic_obj));
dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].isstatic = 0;
}
if (dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj == NULL) {
dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj = calloc(2, sizeof(struct dm_obj_s *));
}
if (dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0] == NULL) {
dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0] = dmcallocjson(2, sizeof(struct dm_obj_s));
parse_obj(key, jobj, dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0], 0, &json_list);
} else {
int idx = get_index_of_available_entry(dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0]);
dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0] = dmreallocjson(dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0], (idx + 2) * sizeof(struct dm_obj_s));
memset(dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0] + (idx + 1), 0, sizeof(struct dm_obj_s));
parse_obj(key, jobj, dm_entryobj->nextdynamicobj[INDX_JSON_OBJ_MOUNT].nextobj[0], idx, &json_list);
}
}
}
}
}
int load_json_dynamic_arrays(struct dmctx *ctx)
{
struct dirent *ent;
@ -881,12 +797,11 @@ int load_json_dynamic_arrays(struct dmctx *ctx)
json_object_object_foreach(json, key, jobj) {
if (!key) break;
int check_obj = check_json_root_obj(ctx, key, &dm_entryobj);
if (check_obj == 0) continue;
if (check_obj == 1) {
parse_next_obj(ctx, jobj);
if (check_obj == 0)
continue;
if (!dm_entryobj)
continue;
}
if (!dm_entryobj) continue;
if (dm_entryobj->nextdynamicobj == NULL) {
dm_entryobj->nextdynamicobj = calloc(__INDX_DYNAMIC_MAX, sizeof(struct dm_dynamic_obj));

View file

@ -16,7 +16,6 @@
#define JSON_FOLDER_PATH "/etc/bbfdm/json"
int check_stats_json_folder(char *json_folder_path);
int load_json_dynamic_arrays(struct dmctx *ctx);
int free_json_dynamic_arrays(DMOBJ *dm_entryobj);

View file

@ -12,56 +12,6 @@
#include "dmentrylibrary.h"
#include "dmoperate.h"
static char library_hash[64] = "";
static int get_stats_library_folder(char *folder_path, int *file_count, unsigned long *size, unsigned long *date)
{
struct stat stats;
struct dirent *entry;
DIR *dirp = NULL;
char buf[264] = {0};
int filecount = 0;
unsigned long filesize = 0, filedate = 0;
if (folder_exists(folder_path)) {
dirp = opendir(folder_path);
while ((entry = readdir(dirp)) != NULL) {
if ((entry->d_type == DT_REG) && (strstr(entry->d_name, ".so"))) {
filecount++;
snprintf(buf, sizeof(buf), "%s/%s", folder_path, entry->d_name);
if (!stat(buf, &stats)) {
filesize = (filesize + stats.st_size) / 2;
filedate = (filedate + stats.st_mtime) / 2;
}
}
}
if (dirp) closedir(dirp);
*file_count = filecount;
*size = filesize;
*date = filedate;
return 1;
}
return 0;
}
int check_stats_library_folder(char *library_folder_path)
{
int file_count = 0;
unsigned long size = 0, date = 0;
char str[128] = "";
if (!get_stats_library_folder(library_folder_path, &file_count, &size, &date))
return 0;
snprintf(str, sizeof(str), "count:%d,sizes:%lu,date:%lu", file_count, size, date);
if (strcmp(str, library_hash)) {
strcpy(library_hash, str);
return 1;
}
return 0;
}
static int dm_browse_node_dynamic_object_tree(DMNODE *parent_node, DMOBJ *entryobj)
{
if (!entryobj)

View file

@ -16,7 +16,6 @@
#define LIBRARY_FOLDER_PATH "/usr/lib/bbfdm"
int check_stats_library_folder(char *library_folder_path);
int load_library_dynamic_arrays(struct dmctx *ctx);
int free_library_dynamic_arrays(DMOBJ *dm_entryobj);

View file

@ -180,13 +180,13 @@ int upnp_configuration_set_ipv4_IPAddress(char *refparam, struct dmctx *ctx, voi
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
char *proto = NULL;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_get_value_by_section_string(upnp_configargs->upnpConfiguration_sec, "proto", &proto);
if(proto == NULL || strlen(proto)<=0) return 0;
if(strcmp(proto, "static") == 0)
if (proto && strcmp(proto, "static") == 0)
dmuci_set_value_by_section(upnp_configargs->upnpConfiguration_sec, "ipaddr", value);
return 0;
}

View file

@ -11,6 +11,62 @@
#include "common.h"
#include "servicesvoiceservice.h"
/*************************************************************
* COMMON FUNCTIONS
**************************************************************/
int browseVoiceServiceSIPProviderInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "clientinstance", "clientalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
int delObjVoiceServiceSIPProvider(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("asterisk", "sip_service_provider", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
@ -40,21 +96,7 @@ static int browseServicesVoiceServiceCallLogInst(struct dmctx *dmctx, DMNODE *pa
/*#Device.Services.VoiceService.{i}.VoIPProfile.{i}.!UCI:asterisk/sip_service_provider/dmmap_asterisk*/
static int browseServicesVoiceServiceVoIPProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "clientinstance", "clientalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browseVoiceServiceSIPProviderInst(dmctx, parent_node, prev_data, prev_instance);
}
/*#Device.Services.VoiceService.{i}.CodecProfile.{i}.!UCI:asterisk/codec_profile/dmmap_asterisk*/
@ -133,36 +175,7 @@ static int addObjServicesVoiceServiceVoIPProfile(char *refparam, struct dmctx *c
static int delObjServicesVoiceServiceVoIPProfile(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("asterisk", "sip_service_provider", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
return delObjVoiceServiceSIPProvider(refparam, ctx, data, instance, del_action);
}
static int addObjServicesVoiceServiceCodecProfile(char *refparam, struct dmctx *ctx, void *data, char **instance)

View file

@ -28,5 +28,8 @@ extern DMOBJ tServicesVoiceServiceVoIPProfileObj[];
extern DMLEAF tServicesVoiceServiceVoIPProfileParams[];
extern DMLEAF tServicesVoiceServiceCodecProfileParams[];
int browseVoiceServiceSIPProviderInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int delObjVoiceServiceSIPProvider(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action);
#endif //__SERVICESVOICESERVICE_H

View file

@ -8,6 +8,7 @@
* Author: Yalu Zhang, yalu.zhang@iopsys.eu
*/
#include "servicesvoiceservice.h"
#include "servicesvoiceservicecallcontrol.h"
#include "common.h"
#include "dmentry.h"
@ -47,41 +48,13 @@ static int browseServicesVoiceServiceCallControlLineInst(struct dmctx *dmctx, DM
/*#Device.Services.VoiceService.{i}.CallControl.IncomingMap.{i}.!UCI:asterisk/sip_service_provider/dmmap_asterisk*/
static int browseServicesVoiceServiceCallControlIncomingMapInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "clientinstance", "clientalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browseVoiceServiceSIPProviderInst(dmctx, parent_node, prev_data, prev_instance);
}
/*#Device.Services.VoiceService.{i}.CallControl.OutgoingMap.{i}.!UCI:asterisk/sip_service_provider/dmmap_asterisk*/
static int browseServicesVoiceServiceCallControlOutgoingMapInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "clientinstance", "clientalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browseVoiceServiceSIPProviderInst(dmctx, parent_node, prev_data, prev_instance);
}
/*#Device.Services.VoiceService.{i}.CallControl.NumberingPlan.{i}.!UCI:asterisk/tel_advanced/dmmap_asterisk*/

View file

@ -8,6 +8,7 @@
* Author: Yalu Zhang, yalu.zhang@iopsys.eu
*/
#include "servicesvoiceservice.h"
#include "servicesvoiceservicesip.h"
#include "common.h"
#include "dmentry.h"
@ -27,21 +28,7 @@ static int get_voice_service_sip_client_linker(char *refparam, struct dmctx *dmc
/*#Device.Services.VoiceService.{i}.SIP.Client.{i}.!UCI:asterisk/sip_service_provider/dmmap_asterisk*/
static int browseServicesVoiceServiceSIPClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "clientinstance", "clientalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browseVoiceServiceSIPProviderInst(dmctx, parent_node, prev_data, prev_instance);
}
/*#Device.Services.VoiceService.{i}.SIP.Client.{i}.Contact.{i}.*/
@ -126,36 +113,7 @@ static int addObjServicesVoiceServiceSIPClient(char *refparam, struct dmctx *ctx
static int delObjServicesVoiceServiceSIPClient(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("asterisk", "sip_service_provider", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
return delObjVoiceServiceSIPProvider(refparam, ctx, data, instance, del_action);
}
static int addObjServicesVoiceServiceSIPNetwork(char *refparam, struct dmctx *ctx, void *data, char **instance)

View file

@ -91,6 +91,32 @@ static int browseSoftwareModulesExecutionUnitInst(struct dmctx *dmctx, DMNODE *p
return 0;
}
/*************************************************************
* COMMON FUNCTIONS
**************************************************************/
static int get_SoftwareModules_VendorConfigList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
*value = "";
char *config = dmjson_get_value((json_object *)data, 1, "config");
if (config == NULL || *config == '\0')
return 0;
uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) {
char *name = NULL;
dmuci_get_value_by_section_string(s, "name", &name);
if (name && strcmp(name, config) == 0) {
char *vcf_instance;
dmuci_get_value_by_section_string(s, "vcf_instance", &vcf_instance);
*value = strdup(dm_print_path("%s%cDeviceInfo%cVendorConfigFile%c%s%c", dmroot, dm_delim, dm_delim, dm_delim, vcf_instance, dm_delim));
break;
}
}
return 0;
}
/*************************************************************
* GET & SET PARAM
*************************************************************/
@ -470,23 +496,7 @@ static int get_SoftwareModulesDeploymentUnit_VendorLogList(char *refparam, struc
/*#Device.SoftwareModules.DeploymentUnit.{i}.VendorConfigList!UBUS:swmodules/du_list//deployment_unit[i-1].config*/
static int get_SoftwareModulesDeploymentUnit_VendorConfigList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *name, *vcf_instance, *config;
*value = "";
config = dmjson_get_value((json_object *)data, 1, "config");
if (!strlen(config))
return 0;
uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) {
dmuci_get_value_by_section_string(s, "name", &name);
if (strcmp(name, config) == 0) {
dmuci_get_value_by_section_string(s, "vcf_instance", &vcf_instance);
*value = strdup(dm_print_path("%s%cDeviceInfo%cVendorConfigFile%c%s%c", dmroot, dm_delim, dm_delim, dm_delim, vcf_instance, dm_delim));
break;
}
}
return 0;
return get_SoftwareModules_VendorConfigList(refparam, ctx, data, instance, value);
}
static int get_SoftwareModulesDeploymentUnit_ExecutionUnitList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
@ -694,23 +704,7 @@ static int get_SoftwareModulesExecutionUnit_VendorLogList(char *refparam, struct
/*#Device.SoftwareModules.ExecutionUnit.{i}.VendorConfigList!UBUS:swmodules/eu_list//execution_unit[i-1].config*/
static int get_SoftwareModulesExecutionUnit_VendorConfigList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *name, *vcf_instance, *config;
*value = "";
config = dmjson_get_value((json_object *)data, 1, "config");
if (!strlen(config))
return 0;
uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) {
dmuci_get_value_by_section_string(s, "name", &name);
if (strcmp(name, config) == 0) {
dmuci_get_value_by_section_string(s, "vcf_instance", &vcf_instance);
*value = strdup(dm_print_path("%s%cDeviceInfo%cVendorConfigFile%c%s%c", dmroot, dm_delim, dm_delim, dm_delim, vcf_instance, dm_delim));
break;
}
}
return 0;
return get_SoftwareModules_VendorConfigList(refparam, ctx, data, instance, value);
}
/*#Device.SoftwareModules.ExecutionUnit.{i}.ExecutionEnvRef!UBUS:swmodules/eu_list//execution_unit[i-1].environment*/

View file

@ -257,54 +257,40 @@ static int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **in
static int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *ns = NULL, *nss = NULL, *dmmap_section= NULL;
char *ifname;
struct uci_section *s = NULL, *ss = NULL, *ns = NULL, *nss = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct atm_args *)data)->atm_sec, NULL, NULL);
uci_foreach_option_cont("network", "interface", "ifname", ((struct atm_args *)data)->ifname, s) {
if (ss && ifname!=NULL)
if (ss != NULL && ((struct atm_args *)data)->ifname != NULL)
wan_remove_dev_interface(ss, ((struct atm_args *)data)->ifname);
ss = s;
}
if (ss != NULL && ifname!=NULL)
if (ss != NULL && ((struct atm_args *)data)->ifname != NULL)
wan_remove_dev_interface(ss, ((struct atm_args *)data)->ifname);
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct atm_args *)data)->atm_sec, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("dsl", "atm-device", s) {
if (ss){
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_get_value_by_section_string(ss, "device", &ifname);
dmuci_delete_by_section(ss, NULL, NULL);
uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) {
if (nss && ifname!=NULL)
wan_remove_dev_interface(nss, ifname);
nss = ns;
}
if (nss != NULL && ifname!=NULL)
wan_remove_dev_interface(nss, ifname);
}
ss = s;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_get_value_by_section_string(ss, "device", &ifname);
dmuci_delete_by_section(ss, NULL, NULL);
uci_foreach_sections_safe("dsl", "atm-device", ss, s) {
char *ifname = NULL;
dmuci_get_value_by_section_string(s, "device", &ifname);
uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) {
if (nss && ifname!=NULL)
if (nss != NULL && ifname != NULL)
wan_remove_dev_interface(nss, ifname);
nss = ns;
}
if (nss != NULL && ifname!=NULL)
if (nss != NULL && ifname != NULL)
wan_remove_dev_interface(nss, ifname);
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}

View file

@ -699,13 +699,13 @@ static void update_device_management_port(char *old_name, char *new_name, char *
static void update_vlanport_and_device_section(void *data, char *linker, char **new_linker)
{
struct uci_section *ss = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_vlanport", "bridge_vlanport", "br_inst", ((struct bridge_port_args *)data)->br_inst, ss) {
struct uci_section *br_vlan_port_s = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_vlanport", "bridge_vlanport", "br_inst", ((struct bridge_port_args *)data)->br_inst, br_vlan_port_s) {
char *port_name;
dmuci_get_value_by_section_string(ss, "port_name", &port_name);
dmuci_get_value_by_section_string(br_vlan_port_s, "port_name", &port_name);
if (strcmp(section_name(((struct bridge_port_args *)data)->bridge_port_dmmap_sec), port_name) == 0) {
char *device_name;
dmuci_get_value_by_section_string(ss, "device_name", &device_name);
dmuci_get_value_by_section_string(br_vlan_port_s, "device_name", &device_name);
// Update device section
struct uci_section *s = NULL;
@ -729,7 +729,7 @@ static void update_vlanport_and_device_section(void *data, char *linker, char **
}
// Update vlan port section in dmmap
dmuci_set_value_by_section(ss, "name", *new_linker);
dmuci_set_value_by_section(br_vlan_port_s, "name", *new_linker);
break;
}
}

View file

@ -7,6 +7,7 @@
*
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*
*/
@ -101,11 +102,11 @@ static inline void init_client_options_args(struct client_options_args *args, ch
}
/*************************************************************
* COMMON Functions
* COMMON FUNCTIONS
**************************************************************/
static struct uci_section *exist_other_section_same_order(struct uci_section *dmmap_sect, char * package, char* sect_type, char *order)
static struct uci_section *exist_other_section_same_order(struct uci_section *dmmap_sect, char *package, char *sect_type, char *order)
{
struct uci_section *s;
struct uci_section *s = NULL;
uci_path_foreach_option_eq(bbfdm, package, sect_type, "order", order, s) {
if (strcmp(section_name(s), section_name(dmmap_sect)) != 0) {
return s;
@ -127,7 +128,7 @@ int set_section_order(char *package, char *dmpackage, char *sect_type, struct uc
dmuci_get_value_by_section_string(dmmap_sect, "section_name", &sect_name);
get_config_section_of_dmmap_section(package, sect_type, sect_name, &s);
} else
s= conf;
s = conf;
if (strcmp(order, "1") != 0 && s != NULL) {
dmuci_set_value_by_section(s, "force", "");
@ -149,6 +150,65 @@ int set_section_order(char *package, char *dmpackage, char *sect_type, struct uc
return 0;
}
int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, char **value)
{
char *option_value = NULL, **macarray, buf[32];
unsigned pos = 0;
size_t length;
dmuci_get_value_by_section_string(s, option_name, &option_value);
if (option_value == NULL || *option_value == '\0')
return -1;
buf[0] = 0;
macarray = strsplit(option_value, ":", &length);
for (int i = 0; i < 6; i++)
pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s:", (macarray[i] && strcmp(macarray[i], "*") == 0) ? "00" : type ? "FF" : macarray[i]);
if (pos)
buf[pos - 1] = 0;
*value = dmstrdup(buf);
return 0;
}
int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *s_data, char *dmmap_name, char *proto, int action)
{
struct uci_section *s = NULL;
char *linker = NULL, *v;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || linker[0] == '\0')
return FAULT_9007;
uci_path_foreach_sections(bbfdm, dmmap_name, "interface", s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if(strcmp(v, linker) == 0)
return FAULT_9007;
}
uci_foreach_sections("network", "interface", s) {
if(strcmp(section_name(s), linker) == 0){
dmuci_get_value_by_section_string(s, "proto", &v);
if(strcmp(v, proto) != 0)
return FAULT_9007;
}
}
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
dmuci_set_value_by_section_bbfdm(s_data, "section_name", linker);
break;
}
return 0;
}
static char *get_last_host_instance(char *package, char *section, char *dmmap_package, char *opt_inst, char *opt_check, char *value_check)
{
struct uci_section *s = NULL, *dmmap_section = NULL;
@ -294,25 +354,39 @@ static bool check_dhcp_host_option_exists(char *dhcp_interface, char *option, ch
return false;
}
static int get_dhcp_iface_range(struct uci_section *dhcp_sec, char *interface, unsigned *iface_addr, unsigned *iface_bits, unsigned *iface_net_start, unsigned *iface_net_end, int *start, int *limit)
{
char *dhcp_start = NULL, *dhcp_limit = NULL;
unsigned iface_cidr;
dmuci_get_value_by_section_string(dhcp_sec, "start", &dhcp_start);
dmuci_get_value_by_section_string(dhcp_sec, "limit", &dhcp_limit);
if (!dhcp_start || *dhcp_start == '\0' || !dhcp_limit || *dhcp_limit == '\0')
return -1;
if (interface_get_ipv4(interface, iface_addr, &iface_cidr))
return -1;
*iface_bits = ~((1 << (32 - iface_cidr)) - 1);
*iface_net_start = (ntohl(*iface_addr) & *iface_bits) + atoi(dhcp_start);
*iface_net_end = (ntohl(*iface_addr) & *iface_bits) + atoi(dhcp_start) + atoi(dhcp_limit) - 1;
*start = atoi(dhcp_start);
*limit = atoi(dhcp_limit);
return 0;
}
static int check_ipv4_in_dhcp_pool(struct uci_section *dhcp_sec, char *interface, char *ip)
{
unsigned iface_addr, iface_cidr, addr;
char *start = NULL, *limit = NULL;
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end;
int start = 0, limit = 0;
dmuci_get_value_by_section_string(dhcp_sec, "start", &start);
dmuci_get_value_by_section_string(dhcp_sec, "limit", &limit);
if (!start || *start == '\0' || !limit || *limit == '\0')
if (get_dhcp_iface_range(dhcp_sec, interface, &iface_addr, &iface_bits, &iface_net_start, &iface_net_end, &start, &limit))
return -1;
if (interface_get_ipv4(interface, &iface_addr, &iface_cidr))
return -1;
unsigned iface_bits = ~((1 << (32 - iface_cidr)) - 1);
unsigned iface_net_start = (ntohl(iface_addr) & iface_bits) + atoi(start);
unsigned iface_net_end = (ntohl(iface_addr) & iface_bits) + atoi(start) + atoi(limit) - 1;
unsigned addr, net;
inet_pton(AF_INET, ip, &addr);
unsigned net = ntohl(addr);
net = ntohl(addr);
if (net > iface_net_end || net < iface_net_start)
return -1;
@ -892,18 +966,14 @@ static int set_DHCPv4ServerPool_Interface(char *refparam, struct dmctx *ctx, voi
/*#Device.DHCPv4.Server.Pool.{i}.MinAddress!UCI:dhcp/interface,@i-1/start*/
static int get_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
unsigned iface_addr, iface_cidr;
char *start = NULL, addr_min[32] = {0};
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end;
int start = 0, limit = 0;
char addr_min[32] = {0};
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "start", &start);
if (!start || *start == '\0')
if (get_dhcp_iface_range(((struct dhcp_args *)data)->dhcp_sec, ((struct dhcp_args *)data)->interface, &iface_addr, &iface_bits, &iface_net_start, &iface_net_end, &start, &limit))
return -1;
if (interface_get_ipv4(((struct dhcp_args *)data)->interface, &iface_addr, &iface_cidr))
return -1;
unsigned iface_bits = ~((1 << (32 - iface_cidr)) - 1);
unsigned iface_start_addr = htonl((ntohl(iface_addr) & iface_bits) + atoi(start));
unsigned iface_start_addr = htonl((ntohl(iface_addr) & iface_bits) + start);
inet_ntop(AF_INET, &iface_start_addr, addr_min, INET_ADDRSTRLEN);
*value = dmstrdup(addr_min);
@ -912,8 +982,9 @@ static int get_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, vo
static int set_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *start = NULL, *limit = NULL, buf[32] = {0};
unsigned iface_addr, iface_cidr, value_addr;
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end, value_addr;
int start = 0, limit = 0;
char buf[32] = {0};
switch (action) {
case VALUECHECK:
@ -921,15 +992,9 @@ static int set_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, vo
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "start", &start);
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "limit", &limit);
if (!start || *start == '\0' || !limit || *limit == '\0')
if (get_dhcp_iface_range(((struct dhcp_args *)data)->dhcp_sec, ((struct dhcp_args *)data)->interface, &iface_addr, &iface_bits, &iface_net_start, &iface_net_end, &start, &limit))
return -1;
if (interface_get_ipv4(((struct dhcp_args *)data)->interface, &iface_addr, &iface_cidr))
return -1;
unsigned iface_bits = ~((1 << (32 - iface_cidr)) - 1);
unsigned iface_net = ntohl(iface_addr) & iface_bits;
inet_pton(AF_INET, value, &value_addr);
@ -938,7 +1003,7 @@ static int set_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, vo
if (value_net == iface_net) {
unsigned dhcp_start = ntohl(value_addr) - iface_net;
unsigned dhcp_limit = atoi(start) + atoi(limit) - dhcp_start;
unsigned dhcp_limit = start + limit - dhcp_start;
// check if MinAddress > MaxAddress
if ((int)dhcp_limit < 0)
@ -960,19 +1025,14 @@ static int set_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, vo
/*#Device.DHCPv4.Server.Pool.{i}.MaxAddress!UCI:dhcp/interface,@i-1/limit*/
static int get_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
unsigned iface_addr, iface_cidr;
char *start = NULL, *limit = NULL, addr_max[32] = {0};
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end;
int start = 0, limit = 0;
char addr_max[32] = {0};
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "start", &start);
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "limit", &limit);
if (!start || *start == '\0' || !limit || *limit == '\0')
if (get_dhcp_iface_range(((struct dhcp_args *)data)->dhcp_sec, ((struct dhcp_args *)data)->interface, &iface_addr, &iface_bits, &iface_net_start, &iface_net_end, &start, &limit))
return -1;
if (interface_get_ipv4(((struct dhcp_args *)data)->interface, &iface_addr, &iface_cidr))
return -1;
unsigned iface_bits = ~((1 << (32 - iface_cidr)) - 1);
unsigned iface_end_addr = htonl((ntohl(iface_addr) & iface_bits) + atoi(start) + atoi(limit) - 1);
unsigned iface_end_addr = htonl((ntohl(iface_addr) & iface_bits) + start + limit - 1);
inet_ntop(AF_INET, &iface_end_addr, addr_max, INET_ADDRSTRLEN);
*value = dmstrdup(addr_max);
@ -981,8 +1041,9 @@ static int get_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, vo
static int set_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *start = NULL, buf[32] = {0};
unsigned iface_addr, iface_cidr, value_addr;
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end, value_addr;
int start = 0, limit = 0;
char buf[32] = {0};
switch (action) {
case VALUECHECK:
@ -990,14 +1051,9 @@ static int set_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, vo
return FAULT_9007;
return 0;
case VALUESET:
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "start", &start);
if (!start || *start == '\0')
if (get_dhcp_iface_range(((struct dhcp_args *)data)->dhcp_sec, ((struct dhcp_args *)data)->interface, &iface_addr, &iface_bits, &iface_net_start, &iface_net_end, &start, &limit))
return -1;
if (interface_get_ipv4(((struct dhcp_args *)data)->interface, &iface_addr, &iface_cidr))
return -1;
unsigned iface_bits = ~((1 << (32 - iface_cidr)) - 1);
unsigned iface_net = ntohl(iface_addr) & iface_bits;
inet_pton(AF_INET, value, &value_addr);
@ -1005,7 +1061,7 @@ static int set_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, vo
if (value_net == iface_net) {
unsigned dhcp_limit = ntohl(value_addr) - iface_net - atoi(start) + 1;
unsigned dhcp_limit = ntohl(value_addr) - iface_net - start + 1;
// check if MaxAddress < MinAddress
if ((int)dhcp_limit < 0)
@ -1023,22 +1079,14 @@ static int set_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, vo
static int get_DHCPv4ServerPool_ReservedAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
unsigned iface_addr, iface_cidr, addr, pos = 0;
char *start = NULL, *limit = NULL, list_val[512];
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end, addr, pos = 0;
int start = 0, limit = 0;
char list_val[512];
struct uci_section *s = NULL;
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "start", &start);
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "limit", &limit);
if (!start || *start == '\0' || !limit || *limit == '\0')
if (get_dhcp_iface_range(((struct dhcp_args *)data)->dhcp_sec, ((struct dhcp_args *)data)->interface, &iface_addr, &iface_bits, &iface_net_start, &iface_net_end, &start, &limit))
return -1;
if (interface_get_ipv4(((struct dhcp_args *)data)->interface, &iface_addr, &iface_cidr))
return -1;
unsigned iface_bits = ~((1 << (32 - iface_cidr)) - 1);
unsigned iface_net_start = (ntohl(iface_addr) & iface_bits) + atoi(start);
unsigned iface_net_end = (ntohl(iface_addr) & iface_bits) + atoi(start) + atoi(limit) - 1;
list_val[0] = 0;
uci_foreach_option_eq("dhcp", "host", "dhcp", ((struct dhcp_args *)data)->interface, s) {
@ -1727,38 +1775,7 @@ static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d
static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s = NULL;
char *linker = NULL, *v;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || linker[0] == '\0')
return FAULT_9007;
uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if(strcmp(v, linker) == 0)
return FAULT_9007;
}
uci_foreach_sections("network", "interface", s) {
if(strcmp(section_name(s), linker) == 0){
dmuci_get_value_by_section_string(s, "proto", &v);
if(strcmp(v, "dhcp") != 0)
return FAULT_9007;
}
}
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
dmuci_set_value_by_section_bbfdm(((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker);
break;
}
return 0;
return set_DHCP_Interface(ctx, value, ((struct dhcp_client_args *)data)->dhcp_client_dm, "dmmap_dhcp_client", "dhcp", action);
}
/*#Device.DHCPv4.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/
@ -2406,38 +2423,7 @@ static int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx
static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s = NULL;
char *linker = NULL, *v;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || linker[0] == '\0')
return FAULT_9007;
uci_path_foreach_sections(bbfdm, "dmmap_dhcp_relay", "interface", s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if (strcmp(v, linker) == 0)
return FAULT_9007;
}
uci_foreach_sections("network", "interface", s) {
if (strcmp(section_name(s), linker) == 0) {
dmuci_get_value_by_section_string(s, "proto", &v);
if(strcmp(v, "relay") != 0)
return FAULT_9007;
}
}
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
dmuci_set_value_by_section_bbfdm(((struct dhcp_client_args *)data)->dhcp_client_dm, "section_name", linker);
break;
}
return 0;
return set_DHCP_Interface(ctx, value, ((struct dhcp_client_args *)data)->dhcp_client_dm, "dmmap_dhcp_relay", "relay", action);
}
/*#Device.DHCPv4.Relay.Forwarding.{i}.VendorClassID!UCI:network/interface,@i-1/vendorclass*/
@ -2466,33 +2452,12 @@ static int set_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx
/*#Device.DHCPv4.Relay.Forwarding.{i}.Chaddr!UCI:network/interface,@i-1/mac*/
static int get_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *mac, **macarray, *res = NULL, *tmp = "";
size_t length;
int i;
if (((struct dhcp_client_args *)data)->macclassifier == NULL) {
*value = "";
return 0;
}
dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->macclassifier, "mac", &mac);
macarray = strsplit(mac, ":", &length);
res = (char*)dmcalloc(18, sizeof(char));
tmp = res;
for (i = 0; i < 6; i++) {
if (strcmp(macarray[i], "*") == 0) {
sprintf(tmp, "%s", "00");
} else {
sprintf(tmp, "%s", macarray[i]);
}
tmp += 2;
if (i < 5) {
sprintf(tmp, "%s", ":");
tmp++;
}
}
dmasprintf(value, "%s", res);
return 0;
return get_value_in_mac_format(((struct dhcp_client_args *)data)->macclassifier, "mac", false, value);
}
static int set_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -2511,33 +2476,12 @@ static int set_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, v
/*#Device.DHCPv4.Relay.Forwarding.{i}.ChaddrMask!UCI:network/interface,@i-1/mac*/
static int get_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *mac, **macarray, *res = NULL, *tmp = "";
size_t length;
int i;
if (((struct dhcp_client_args *)data)->macclassifier == NULL) {
*value= "";
return 0;
}
dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->macclassifier, "mac", &mac);
macarray = strsplit(mac, ":", &length);
res = (char*)dmcalloc(18, sizeof(char));
tmp = res;
for (i = 0; i < 6; i++) {
if (strcmp(macarray[i], "*") == 0) {
sprintf(tmp, "%s", "00");
} else {
sprintf(tmp, "%s", "FF");
}
tmp += 2;
if (i < 5) {
sprintf(tmp, "%s", ":");
tmp++;
}
}
dmasprintf(value, "%s", res);
return 0;
return get_value_in_mac_format(((struct dhcp_client_args *)data)->macclassifier, "mac", true, value);
}
static int set_DHCPv4RelayForwarding_ChaddrMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -2997,7 +2941,7 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
struct dhcp_args *curr_dhcp_args = (struct dhcp_args*)prev_data;
struct uci_section *dmmap_sect;
struct browse_args browse_args = {0};
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue = NULL, *tmp, *tag, *value;
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue = NULL, *tmp, *dhcpv4_tag, *dhcpv4_value;
size_t length;
int j;
struct dhcp_client_option_args dhcp_client_opt_args = {0};
@ -3027,12 +2971,13 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
}
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &value);
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &dhcpv4_tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &dhcpv4_value);
dhcp_client_opt_args.client_sect = curr_dhcp_args->dhcp_sec;
dhcp_client_opt_args.option_tag = dmstrdup(tag);
dhcp_client_opt_args.value = dmstrdup(value);
dhcp_client_opt_args.opt_sect = dmmap_sect;
dhcp_client_opt_args.option_tag = dmstrdup(dhcpv4_tag);
dhcp_client_opt_args.value = dmstrdup(dhcpv4_value);
browse_args.option = "section_name";
browse_args.value = section_name(curr_dhcp_args->dhcp_sec);
@ -3050,9 +2995,9 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
/*#Device.DHCPv4.Relay.Forwarding.{i}.!UCI:network/interface/dmmap_dhcp_relay*/
static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst, *max_inst = NULL, *v, *dhcp_network = NULL;
char *relay_type = NULL, *relay_ipv4addr = NULL, *relay_ipv6addr = NULL, *relay_mask4 = NULL;
char *inst, *max_inst = NULL, *relay_network = NULL, *dhcp_network = NULL;
struct dmmap_dup *p;
char *type, *ipv4addr = "", *ipv6addr = "", *proto, *ip_inst, *mask4 = NULL;
json_object *res, *jobj;
struct dhcp_client_args dhcp_relay_arg = {0};
LIST_HEAD(dup_list);
@ -3060,65 +3005,48 @@ static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_n
synchronize_specific_config_sections_with_dmmap_eq_no_delete("network", "interface", "dmmap_dhcp_relay", "proto", "relay", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (p->config_section != NULL) {
dmuci_get_value_by_section_string(p->config_section, "type", &type);
if (strcmp(type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback") == 0)
dmuci_get_value_by_section_string(p->config_section, "type", &relay_type);
if (strcmp(relay_type, "alias") == 0 || strcmp(section_name(p->config_section), "loopback") == 0)
continue;
dmuci_get_value_by_section_string(p->config_section, "ipaddr", &ipv4addr);
dmuci_get_value_by_section_string(p->config_section, "netmask", &mask4);
if (ipv4addr[0] == '\0') {
dmuci_get_value_by_section_string(p->config_section, "ipaddr", &relay_ipv4addr);
dmuci_get_value_by_section_string(p->config_section, "netmask", &relay_mask4);
if (relay_ipv4addr && *relay_ipv4addr) {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res);
if (res) {
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address");
ipv4addr = dmjson_get_value(jobj, 1, "address");
mask4= dmjson_get_value(jobj, 1, "mask");
}
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address");
relay_ipv4addr = dmjson_get_value(jobj, 1, "address");
relay_mask4 = dmjson_get_value(jobj, 1, "mask");
}
dmuci_get_value_by_section_string(p->config_section, "ip6addr", &ipv6addr);
if (ipv6addr[0] == '\0') {
dmuci_get_value_by_section_string(p->config_section, "ip6addr", &relay_ipv6addr);
if (relay_ipv6addr[0] == '\0') {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(p->config_section), String}}, 1, &res);
if (res) {
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address");
ipv6addr = dmjson_get_value(jobj, 1, "address");
relay_ipv6addr = dmjson_get_value(jobj, 1, "address");
}
}
dmuci_get_value_by_section_string(p->config_section, "proto", &proto);
dmuci_get_value_by_section_string(p->config_section, "ip_int_instance", &ip_inst);
if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(ip_inst, "") == 0 && strcmp(type, "bridge") != 0 && strcmp(proto, "relay") != 0) {
if (relay_ipv4addr[0] == '\0' &&
relay_ipv6addr[0] == '\0' &&
strcmp(relay_type, "bridge") != 0) {
p->config_section = NULL;
dmuci_set_value_by_section_bbfdm(p->dmmap_section, "section_name", "");
}
}
if (ipv4addr == NULL || strlen(ipv4addr) == 0)
dhcp_relay_arg.ip = dmstrdup("");
else
dhcp_relay_arg.ip = dmstrdup(ipv4addr);
if (mask4 == NULL || strlen(mask4) == 0)
dhcp_relay_arg.mask = dmstrdup("");
else
dhcp_relay_arg.mask = dmstrdup(mask4);
if (p->config_section != NULL)
dmuci_get_value_by_section_string(p->config_section, "network", &v);
else
v = dmstrdup("");
dhcp_relay_arg.ip = relay_ipv4addr ? dmstrdup(relay_ipv4addr) : dmstrdup("");
dhcp_relay_arg.mask = relay_mask4 ? dmstrdup(relay_mask4) : dmstrdup("");
dhcp_network = get_dhcp_network_from_relay_list(v);
if (dhcp_network && strlen(dhcp_network) > 0) {
dhcp_relay_arg.macclassifier = get_dhcp_classifier("mac", dhcp_network);
dhcp_relay_arg.vendorclassidclassifier = get_dhcp_classifier("vendorclass", dhcp_network);
dhcp_relay_arg.userclassclassifier = get_dhcp_classifier("userclass", dhcp_network);
} else {
dhcp_relay_arg.macclassifier = NULL;
dhcp_relay_arg.vendorclassidclassifier = NULL;
dhcp_relay_arg.userclassclassifier = NULL;
}
dmuci_get_value_by_section_string(p->config_section, "network", &relay_network);
dhcp_network = get_dhcp_network_from_relay_list(relay_network);
dhcp_relay_arg.macclassifier = (dhcp_network && *dhcp_network) ? get_dhcp_classifier("mac", dhcp_network) : NULL;
dhcp_relay_arg.vendorclassidclassifier = (dhcp_network && *dhcp_network) ? get_dhcp_classifier("vendorclass", dhcp_network) : NULL;
dhcp_relay_arg.userclassclassifier = (dhcp_network && *dhcp_network) ? get_dhcp_classifier("userclass", dhcp_network) : NULL;
dhcp_relay_arg.dhcp_client_conf = p->config_section;
dhcp_relay_arg.dhcp_client_dm= p->dmmap_section;
dhcp_relay_arg.dhcp_client_dm = p->dmmap_section;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "bbf_dhcpv4relay_instance", "bbf_dhcpv4relay_alias");

View file

@ -38,5 +38,7 @@ extern DMLEAF tDHCPv4RelayParams[];
extern DMLEAF tDHCPv4RelayForwardingParams[];
int set_section_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order);
int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, char **value);
int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *s_data, char *dmmap_name, char *proto, int action);
#endif

View file

@ -6,6 +6,7 @@
* as published by the Free Software Foundation
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include "dmentry.h"
@ -40,7 +41,7 @@ struct dhcpv6_client_option_args {
char *value;
};
struct uci_section* get_dhcpv6_classifier(char *classifier_name, char *network)
static struct uci_section *get_dhcpv6_classifier(char *classifier_name, const char *network)
{
struct uci_section *s = NULL;
char *v;
@ -53,6 +54,19 @@ struct uci_section* get_dhcpv6_classifier(char *classifier_name, char *network)
return NULL;
}
static int get_value_in_date_time_format(json_object *json_obj, char *option_name, char **value)
{
const char *option_value = dmjson_get_value(json_obj, 1, option_name);
if (option_value && *option_value != '\0' && atoi(option_value) > 0) {
time_t time_value = atoi(option_value);
char s_now[sizeof "AAAA-MM-JJTHH:MM:SSZ"];
if (strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%SZ", localtime(&time_value)) == 0)
return -1;
*value = dmstrdup(s_now); // MEM WILL BE FREED IN DMMEMCLEAN
}
return 0;
}
static inline int init_dhcpv6_client_args(struct clientv6_args *args, json_object *client, json_object *client_param, int i)
{
args->client = client;
@ -61,52 +75,6 @@ static inline int init_dhcpv6_client_args(struct clientv6_args *args, json_objec
return 0;
}
struct uci_section* exist_other_section_dhcp6_same_order(struct uci_section *dmmap_sect, char * package, char* sect_type, char *order)
{
struct uci_section *s;
uci_path_foreach_option_eq(bbfdm, package, sect_type, "order", order, s) {
if (strcmp(section_name(s), section_name(dmmap_sect)) != 0) {
return s;
}
}
return NULL;
}
static int set_section_dhcp6_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order)
{
char *v = NULL, *sect_name, *incrorder;
struct uci_section *s, *dm;
dmuci_get_value_by_section_string(dmmap_sect, "order", &v);
if(strlen(v) > 0 && strcmp(v, order) == 0)
return 0;
dmuci_set_value_by_section_bbfdm(dmmap_sect, "order", order);
if (conf == NULL) {
dmuci_get_value_by_section_string(dmmap_sect, "section_name", &sect_name);
get_config_section_of_dmmap_section(package, sect_type, sect_name, &s);
} else
s= conf;
if (strcmp(order, "1") != 0 && s != NULL) {
dmuci_set_value_by_section(s, "force", "");
}
if (set_force==1 && strcmp(order, "1") == 0 && s != NULL) {
dmuci_set_value_by_section(s, "force", "1");
}
if ((dm = exist_other_section_dhcp6_same_order(dmmap_sect, dmpackage, sect_type, order)) != NULL) {
dmuci_get_value_by_section_string(dm, "section_name", &sect_name);
get_config_section_of_dmmap_section(package, sect_type, sect_name, &s);
dmasprintf(&incrorder, "%d", atoi(order)+1);
if (s != NULL && strcmp(order, "1") == 0) {
dmuci_set_value_by_section(s, "force", "");
}
set_section_dhcp6_order(package, dmpackage, sect_type, dm, s, set_force, incrorder);
}
return 0;
}
static inline int init_dhcpv6_args(struct dhcpv6_args *args, struct uci_section *s, char *interface)
{
args->interface = interface;
@ -162,7 +130,7 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node,
dmuci_get_value_by_section_string(p->dmmap_section, "order", &v);
if (v == NULL || strlen(v) == 0)
set_section_dhcp6_order("dhcp", "dmmap_dhcpv6", "dhcp", p->dmmap_section, p->config_section, 0, inst);
set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", p->dmmap_section, p->config_section, 0, inst);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp6_args, inst) == DM_STOP)
break;
@ -209,7 +177,7 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
struct dhcpv6_args *curr_dhcp_args = (struct dhcpv6_args*)prev_data;
struct uci_section *dmmap_sect;
struct browse_args browse_args = {0};
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue= NULL, *tmp, *tag, *value;
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue= NULL, *tmp, *dhcpv6_tag, *dhcpv6_value;
size_t length;
int j;
struct dhcpv6_client_option_args dhcp_client_opt_args = {0};
@ -217,7 +185,7 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list);
if (dhcp_options_list != NULL) {
uci_foreach_element(dhcp_options_list, e) {
tagvalue= strsplit(e->name, ",", &length);
tagvalue = strsplit(e->name, ",", &length);
if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcpv6", "servpool_option", section_name(curr_dhcp_args->dhcp_sec), "option_tag", tagvalue[0])) == NULL) {
dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", tagvalue[0]);
@ -239,12 +207,13 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
}
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &value);
dhcp_client_opt_args.client_sect= curr_dhcp_args->dhcp_sec;
dhcp_client_opt_args.option_tag = dmstrdup(tag);
dhcp_client_opt_args.value = dmstrdup(value);
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &dhcpv6_tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &dhcpv6_value);
dhcp_client_opt_args.client_sect = curr_dhcp_args->dhcp_sec;
dhcp_client_opt_args.opt_sect = dmmap_sect;
dhcp_client_opt_args.option_tag = dmstrdup(dhcpv6_tag);
dhcp_client_opt_args.value = dmstrdup(dhcpv6_value);
browse_args.option = "section_name";
browse_args.value = section_name(curr_dhcp_args->dhcp_sec);
@ -558,38 +527,7 @@ static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d
static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s = NULL;
char *linker = NULL, *v;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || linker[0] == '\0')
return FAULT_9007;
uci_path_foreach_sections(bbfdm, "dmmap_dhcpv6", "interface", s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if (strcmp(v, linker) == 0)
return FAULT_9007;
}
uci_foreach_sections("network", "interface", s) {
if (strcmp(section_name(s), linker) == 0) {
dmuci_get_value_by_section_string(s, "proto", &v);
if (strcmp(v, "dhcpv6") != 0)
return FAULT_9007;
}
}
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
dmuci_set_value_by_section_bbfdm(((struct dhcpv6_client_args *)data)->dhcp_client_dm, "section_name", linker);
break;
}
return 0;
return set_DHCP_Interface(ctx, value, ((struct dhcpv6_client_args *)data)->dhcp_client_dm, "dmmap_dhcpv6", "dhcpv6", action);
}
/*#Device.DHCPv6.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/
@ -1004,35 +942,13 @@ static int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, v
static int get_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *macaddrclassifier;
char *mac, **macarray, *res = NULL, *tmp = "";
int i;
size_t length;
macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface);
if (macaddrclassifier == NULL) {
struct uci_section *classifier_s = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface);
if (classifier_s == NULL) {
*value = "";
return 0;
}
dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac);
macarray = strsplit(mac, ":", &length);
res = (char*)dmcalloc(18, sizeof(char));
tmp = res;
for (i = 0; i < 6; i++) {
if(strcmp(macarray[i], "*") == 0) {
sprintf(tmp, "%s", "00");
} else {
sprintf(tmp, "%s", macarray[i]);
}
tmp += 2;
if (i < 5) {
sprintf(tmp, "%s", ":");
tmp++;
}
}
dmasprintf(value, "%s", res);
return 0;
return get_value_in_mac_format(classifier_s, "mac", false, value);
}
static int set_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -1050,34 +966,13 @@ static int set_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx,
static int get_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) //TODO: return wrong value
{
struct uci_section *macaddrclassifier;
char *mac, **macarray, *res = NULL, *tmp = "";
int i;
size_t length;
macaddrclassifier = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface);
if (macaddrclassifier == NULL) {
struct uci_section *classifier_s = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface);
if (classifier_s == NULL) {
*value = "";
return 0;
}
dmuci_get_value_by_section_string(macaddrclassifier, "mac", &mac);
macarray = strsplit(mac, ":", &length);
res = (char *)dmcalloc(18, sizeof(char));
tmp = res;
for (i = 0; i < 6; i++) {
if (strcmp(macarray[i], "*") == 0) {
sprintf(tmp, "%s", "00");
} else {
sprintf(tmp, "%s", "FF");
}
tmp += 2;
if (i < 5) {
sprintf(tmp, "%s", ":");
tmp++;
}
}
dmasprintf(value, "%s", res);
return 0;
return get_value_in_mac_format(classifier_s, "mac", true, value);
}
static int set_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -1213,36 +1108,12 @@ static int get_DHCPv6ServerPoolClientIPv6Address_IPAddress(char *refparam, struc
static int get_DHCPv6ServerPoolClientIPv6Address_PreferredLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "0001-01-01T00:00:00Z";
char *preferred = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "preferred-lifetime");
if (preferred && *preferred != '\0' && atoi(preferred) > 0) {
time_t time_value = atoi(preferred);
char s_now[sizeof "AAAA-MM-JJTHH:MM:SSZ"];
if (strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%SZ", localtime(&time_value)) == 0)
return -1;
*value = dmstrdup(s_now); // MEM WILL BE FREED IN DMMEMCLEAN
}
return 0;
return get_value_in_date_time_format(((struct clientv6_args *)data)->clientparam, "preferred-lifetime", value);
}
static int get_DHCPv6ServerPoolClientIPv6Address_ValidLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "0001-01-01T00:00:00Z";
char *valid = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "valid-lifetime");
if (valid && *valid != '\0' && atoi(valid) > 0) {
time_t time_value = atoi(valid);
char s_now[sizeof "AAAA-MM-JJTHH:MM:SSZ"];
if (strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%SZ", localtime(&time_value)) == 0)
return -1;
*value = dmstrdup(s_now);
}
return 0;
return get_value_in_date_time_format(((struct clientv6_args *)data)->clientparam, "valid-lifetime", value);
}
static int get_DHCPv6ServerPoolClientIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)

View file

@ -101,24 +101,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa
}
/******************************** Browse Functions ****************************************/
static int browseServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
dmmap_synchronizeDNSClientRelayServer(dmctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_dns", "dns_server", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "dns_server_instance", "dns_server_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
}
return 0;
}
static int browseRelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
static int browseDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
@ -152,7 +135,7 @@ static int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev
}
/*********************************** Add/Delet Object functions *************************/
static int add_client_server(char *refparam, struct dmctx *ctx, void *data, char **instance)
static int add_dns_server(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL;
@ -168,60 +151,7 @@ static int add_client_server(char *refparam, struct dmctx *ctx, void *data, char
return 0;
}
static int add_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL;
char *inst = get_last_instance_bbfdm("dmmap_dns", "dns_server", "dns_server_instance");
dmuci_add_list_value("network", "lan", "dns", "0.0.0.0");
dmuci_add_section_bbfdm("dmmap_dns", "dns_server", &s);
dmuci_set_value_by_section(s, "ip", "0.0.0.0");
dmuci_set_value_by_section(s, "interface", "lan");
dmuci_set_value_by_section(s, "enable", "1");
*instance = update_instance(inst, 2, s, "dns_server_instance");
return 0;
}
static int delete_client_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *stmp = NULL;
char *interface, *ip, *str;
struct uci_list *v;
struct uci_element *e, *tmp;
switch (del_action) {
case DEL_INST:
dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str);
if (str[0] == '1')
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface);
dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &ip);
dmuci_del_list_value("network", interface, "dns", ip);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("network", "interface", s) {
dmuci_get_value_by_section_string(s, "peerdns", &str);
if (str[0] == '1')
continue;
dmuci_get_value_by_section_list(s, "dns", &v);
if (v != NULL) {
uci_foreach_element_safe(v, e, tmp) {
uci_path_foreach_option_eq_safe(bbfdm, "dmmap_dns", "dns_server", "ip", tmp->name, stmp, ss) {
dmuci_delete_by_section(ss, NULL, NULL);
}
dmuci_del_list_value_by_section(s, "dns", tmp->name);
}
}
}
break;
}
return 0;
}
static int delete_relay_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
static int delete_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *stmp = NULL;
char *interface, *ip, *str;
@ -319,7 +249,7 @@ static int get_server_dns_server(char *refparam, struct dmctx *ctx, void *data,
return 0;
}
static int get_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int get_dns_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *linker;
@ -330,7 +260,7 @@ static int get_server_interface(char *refparam, struct dmctx *ctx, void *data, c
return 0;
}
static int get_server_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int get_dns_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
*value = "Static";
@ -403,32 +333,6 @@ static int get_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *da
return 0;
}
static int get_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *linker;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &linker);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value);
if (*value == NULL)
*value = "";
return 0;
}
static int get_forwarding_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
*value = "Static";
dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &v);
if (*v == '1') {
dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &v);
if (strchr(v, ':') == NULL)
*value = "DHCPv4";
else
*value = "DHCPv6";
}
return 0;
}
static int get_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = get_diagnostics_option_fallback_def("nslookup", "DiagnosticState", "None");
@ -535,7 +439,7 @@ static int set_client_enable(char *refparam, struct dmctx *ctx, void *data, char
return 0;
}
static int set_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
static int set_dns_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *str, *ip, *interface;
bool b, ob;
@ -580,7 +484,7 @@ static int set_server_alias(char *refparam, struct dmctx *ctx, void *data, char
return 0;
}
static int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
static int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *str, *oip, *interface;
struct uci_list *v;
@ -625,9 +529,9 @@ static int set_server_dns_server(char *refparam, struct dmctx *ctx, void *data,
return 0;
}
static int set_server_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
static int set_dns_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *str, *ointerface, *ip, *interface = NULL;
char *str, *interface, *ip, *linker = NULL;
switch (action) {
case VALUECHECK:
@ -635,21 +539,21 @@ static int set_server_interface(char *refparam, struct dmctx *ctx, void *data, c
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &interface);
if (interface == NULL && interface[0] == '\0')
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || linker[0] == '\0')
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &ointerface);
if (strcmp(ointerface, interface) == 0)
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface);
if (strcmp(interface, linker) == 0)
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str);
if (str[0] == '1')
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &ip);
dmuci_del_list_value("network", ointerface, "dns", ip);
dmuci_del_list_value("network", interface, "dns", ip);
dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &str);
if (str[0] == '1')
dmuci_add_list_value("network", interface, "dns", ip);
dmuci_add_list_value("network", linker, "dns", ip);
dmuci_set_value_by_section((struct uci_section *)data, "interface", interface);
break;
}
@ -673,37 +577,6 @@ static int set_relay_enable(char *refparam, struct dmctx *ctx, void *data, char
return 0;
}
static int set_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *str, *ip, *interface;
bool b, ob;
switch (action) {
case VALUECHECK:
if (dm_validate_boolean(value))
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &str);
string_to_bool(value, &b);
string_to_bool(str, &ob);
if (ob == b)
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str);
if (str[0] == '1')
return 0;
dmuci_set_value_by_section((struct uci_section *)data, "enable", b ? "1" : "0");
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface);
dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &ip);
if (b == 1)
dmuci_add_list_value("network", interface, "dns", ip);
else
dmuci_del_list_value("network", interface, "dns", ip);
break;
}
return 0;
}
static int set_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
@ -718,82 +591,6 @@ static int set_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, c
return 0;
}
static int set_forwarding_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *str, *oip, *interface;
struct uci_list *v;
struct uci_element *e;
int count = 0, i = 0;
char *dns[32] = {0};
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 45, NULL, 0, IPAddress, 2))
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &oip);
if (strcmp(oip, value) == 0)
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str);
if (str[0] == '1')
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface);
dmuci_get_option_value_list("network", interface, "dns", &v);
if (v) {
uci_foreach_element(v, e) {
if (strcmp(e->name, oip)==0)
dns[count] = dmstrdup(value);
else
dns[count] = dmstrdup(e->name);
count++;
}
}
dmuci_delete("network", interface, "dns", NULL);
dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &str);
if (str[0] == '1') {
for (i = 0; i < count; i++) {
dmuci_add_list_value("network", interface, "dns", dns[i] ? dns[i] : "");
dmfree(dns[i]);
}
}
dmuci_set_value_by_section((struct uci_section *)data, "ip", value);
break;
}
return 0;
}
static int set_forwarding_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *str, *ointerface, *ip, *interface = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &interface);
if (interface == NULL || interface[0] == '\0')
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &ointerface);
if (strcmp(ointerface, interface) == 0)
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &str);
if (str[0] == '1')
return 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &ip);
dmuci_del_list_value("network", ointerface, "dns", ip);
dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &str);
if (str[0] == '1')
dmuci_add_list_value("network", interface, "dns", ip);
dmuci_set_value_by_section((struct uci_section *)data, "interface", interface);
break;
}
return 0;
}
static int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
@ -905,7 +702,7 @@ DMLEAF tDNSParams[] = {
/* *** Device.DNS.Client. *** */
DMOBJ tDNSClientObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
{"Server", &DMWRITE, add_client_server, delete_client_server, NULL, browseServerInst, NULL, NULL, tDNSClientServerParams, NULL, BBFDM_BOTH, LIST_KEY{"DNSServer", "Alias", NULL}},
{"Server", &DMWRITE, add_dns_server, delete_dns_server, NULL, browseDNSServerInst, NULL, NULL, tDNSClientServerParams, NULL, BBFDM_BOTH, LIST_KEY{"DNSServer", "Alias", NULL}},
{0}
};
@ -920,19 +717,19 @@ DMLEAF tDNSClientParams[] = {
/* *** Device.DNS.Client.Server.{i}. *** */
DMLEAF tDNSClientServerParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/
{"Enable", &DMWRITE, DMT_BOOL, get_server_enable, set_server_enable, BBFDM_BOTH},
{"Enable", &DMWRITE, DMT_BOOL, get_server_enable, set_dns_enable, BBFDM_BOTH},
{"Status", &DMREAD, DMT_STRING, get_server_status, NULL, BBFDM_BOTH},
{"Alias", &DMWRITE, DMT_STRING, get_server_alias, set_server_alias, BBFDM_BOTH},
{"DNSServer", &DMWRITE, DMT_STRING, get_server_dns_server, set_server_dns_server, BBFDM_BOTH},
{"Interface", &DMWRITE, DMT_STRING, get_server_interface, set_server_interface, BBFDM_BOTH},
{"Type", &DMREAD, DMT_STRING, get_server_type, NULL, BBFDM_BOTH},
{"DNSServer", &DMWRITE, DMT_STRING, get_server_dns_server, set_dns_server, BBFDM_BOTH},
{"Interface", &DMWRITE, DMT_STRING, get_dns_interface, set_dns_interface, BBFDM_BOTH},
{"Type", &DMREAD, DMT_STRING, get_dns_type, NULL, BBFDM_BOTH},
{0}
};
/* *** Device.DNS.Relay. *** */
DMOBJ tDNSRelayObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
{"Forwarding", &DMWRITE, add_relay_forwarding, delete_relay_forwarding, NULL, browseRelayForwardingInst, NULL, NULL, tDNSRelayForwardingParams, NULL, BBFDM_BOTH, LIST_KEY{"DNSServer", "Alias", NULL}},
{"Forwarding", &DMWRITE, add_dns_server, delete_dns_server, NULL, browseDNSServerInst, NULL, NULL, tDNSRelayForwardingParams, NULL, BBFDM_BOTH, LIST_KEY{"DNSServer", "Alias", NULL}},
{0}
};
@ -947,12 +744,12 @@ DMLEAF tDNSRelayParams[] = {
/* *** Device.DNS.Relay.Forwarding.{i}. *** */
DMLEAF tDNSRelayForwardingParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/
{"Enable", &DMWRITE, DMT_BOOL, get_forwarding_enable, set_forwarding_enable, BBFDM_BOTH},
{"Enable", &DMWRITE, DMT_BOOL, get_forwarding_enable, set_dns_enable, BBFDM_BOTH},
{"Status", &DMREAD, DMT_STRING, get_forwarding_status, NULL, BBFDM_BOTH},
{"Alias", &DMWRITE, DMT_STRING, get_forwarding_alias, set_forwarding_alias, BBFDM_BOTH},
{"DNSServer", &DMWRITE, DMT_STRING, get_forwarding_dns_server, set_forwarding_dns_server, BBFDM_BOTH},
{"Interface", &DMWRITE, DMT_STRING, get_forwarding_interface, set_forwarding_interface, BBFDM_BOTH},
{"Type", &DMREAD, DMT_STRING, get_forwarding_type, NULL, BBFDM_BOTH},
{"DNSServer", &DMWRITE, DMT_STRING, get_forwarding_dns_server, set_dns_server, BBFDM_BOTH},
{"Interface", &DMWRITE, DMT_STRING, get_dns_interface, set_dns_interface, BBFDM_BOTH},
{"Type", &DMREAD, DMT_STRING, get_dns_type, NULL, BBFDM_BOTH},
{0}
};

View file

@ -422,19 +422,21 @@ static int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *d
static int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE* fp = NULL;
char buf[512] = "", path[64] = "", status[32] = "", *enable, *logdir = NULL;
char status[64] = {0}, *enable = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enable);
if (*enable == '\0' || strcmp(enable, "0") == 0) {
if (enable && (*enable == '\0' || strcmp(enable, "0") == 0)) {
strcpy(status, "NO_ERROR");
} else {
char path[128] = {0}, *logdir = NULL;
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
if (*logdir == '\0')
logdir = "/var/log/ddns";
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name((struct uci_section *)data));
fp = fopen(path, "r");
snprintf(path, sizeof(path), "%s/%s.log", (logdir && *logdir) ? logdir : "/var/log/ddns", section_name((struct uci_section *)data));
FILE *fp = fopen(path, "r");
if (fp != NULL) {
char buf[512] = {0};
strcpy(status, "NO_ERROR");
while (fgets(buf, 512, fp) != NULL) {
if (strstr(buf, "ERROR") && strstr(buf, "Please check your configuration"))
@ -593,19 +595,20 @@ static int set_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx
/*#Device.DynamicDNS.Client.{i}.Hostname.{i}.Status!UCI:ddns/service,@i-1/enabled*/
static int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE* fp = NULL;
char buf[512] = "", path[64] = "", status[32] = "", *enable, *logdir = NULL;
char status[32] = {0}, *enable = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enable);
if (*enable == '\0' || strcmp(enable, "0") == 0) {
if (enable && (*enable == '\0' || strcmp(enable, "0") == 0)) {
strcpy(status, "Disabled");
} else {
char path[128] = {0}, *logdir = NULL;
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
if (*logdir == '\0')
logdir = "/var/log/ddns";
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name((struct uci_section *)data));
fp = fopen(path, "r");
snprintf(path, sizeof(path), "%s/%s.log", (logdir && *logdir) ? logdir : "/var/log/ddns", section_name((struct uci_section *)data));
FILE *fp = fopen(path, "r");
if (fp != NULL) {
char buf[512] = {0};
strcpy(status, "Registered");
while (fgets(buf, 512, fp) != NULL) {
if (strstr(buf, "Registered IP") || strstr(buf, "Update successful"))

View file

@ -43,8 +43,57 @@ static inline int init_eth_rmon(struct eth_rmon_args *args, struct uci_section *
}
/*************************************************************
* COMMON Functions
* COMMON FUNCTIONS
**************************************************************/
int is_vlan_termination_section(const char *name)
{
struct uci_section *s;
uci_foreach_sections("network", "interface", s) {
// check ifname is not empty
char *ifname;
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (*ifname == '\0')
continue;
// check if ifname list contains the device name
if (strstr(ifname, name)) {
char *type;
// check type is not bridge
dmuci_get_value_by_section_string(s, "type", &type);
if (strcmp(type, "bridge") == 0)
return 0;
break;
}
}
return 1;
}
void get_bridge_port_linker(struct dmctx *ctx, char *intf_name, char **value)
{
struct uci_section *dmmap_section = NULL, *bridge_port = NULL;
*value = NULL;
get_dmmap_section_of_config_section("dmmap_network", "interface", intf_name, &dmmap_section);
if (dmmap_section != NULL) {
char *br_inst, *mg;
dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", br_inst, bridge_port) {
dmuci_get_value_by_section_string(bridge_port, "management", &mg);
if (strcmp(mg, "1") == 0) {
char *device, linker[512] = "";
dmuci_get_value_by_section_string(bridge_port, "device", &device);
snprintf(linker, sizeof(linker), "br_%s:%s+%s", br_inst, section_name(bridge_port), device);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value);
break;
}
}
}
}
static int eth_iface_sysfs(const struct uci_section *data, const char *name, char **value)
{
char *device;
@ -946,39 +995,23 @@ static int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void
if (bridge) {
char *int_name;
dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &int_name);
struct uci_section *dmmap_section, *port;
get_dmmap_section_of_config_section("dmmap_network", "interface", int_name, &dmmap_section);
if (dmmap_section != NULL) {
char *br_inst, *mg;
dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", br_inst, port) {
dmuci_get_value_by_section_string(port, "management", &mg);
if (strcmp(mg, "1") == 0) {
char *device, linker[512] = "";
dmuci_get_value_by_section_string(port, "device", &device);
snprintf(linker, sizeof(linker), "br_%s:%s+%s", br_inst, section_name(port), device);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value);
if (*value == NULL)
*value = "";
break;
}
}
}
get_bridge_port_linker(ctx, int_name, value);
} else {
char *vid = strchr(linker, '.');
if (vid) *vid = '\0';
char *macvlan = strchr(linker, '_');
if (macvlan) *macvlan = '\0';
adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value);
if (*value == NULL)
*value = "";
}
if (*value == NULL)
*value = "";
return 0;
}
static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
char *link_linker = NULL;
switch (action) {
case VALUECHECK:
@ -986,27 +1019,27 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || *linker == '\0')
adm_entry_get_linker_value(ctx, value, &link_linker);
if (link_linker == NULL || *link_linker == '\0')
return -1;
if (strncmp(value, "Device.Ethernet.Interface.", 26) == 0) {
struct uci_section *s = NULL;
char *int_name = NULL;
dmuci_set_value_by_section((struct uci_section *)data, "device", linker);
dmuci_set_value_by_section((struct uci_section *)data, "device", link_linker);
dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &int_name);
uci_foreach_sections("network", "interface", s) {
if (strcmp(section_name(s), int_name) == 0) {
dmuci_set_value_by_section(s, "ifname", linker);
dmuci_set_value_by_section(s, "ifname", link_linker);
break;
}
}
} else if (strncmp(value, "Device.Bridging.Bridge.", 23) == 0) {
char br_linker[250] = {0};
strncpy(br_linker, linker, sizeof(br_linker) - 1);
strncpy(br_linker, link_linker, sizeof(br_linker) - 1);
char *bridge = strchr(br_linker, ':');
if (bridge) {
@ -1207,7 +1240,7 @@ static int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
char *vlan_linker = NULL;
switch (action) {
case VALUECHECK:
@ -1215,8 +1248,8 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || *linker == '\0')
adm_entry_get_linker_value(ctx, value, &vlan_linker);
if (vlan_linker == NULL || *vlan_linker == '\0')
return -1;
if (strncmp(value, "Device.Ethernet.Link.", 21) == 0) {
@ -1232,12 +1265,12 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
char link_inst[8] = {0}, sec_name[32] = {0};
snprintf(link_inst, sizeof(link_inst), "%c", value[21]);
snprintf(new_name, sizeof(new_name), "%s_%s", linker, link_inst);
snprintf(new_name, sizeof(new_name), "%s_%s", vlan_linker, link_inst);
if (is_name_exist_in_devices(new_name))
return -1;
uci_foreach_option_eq("network", "interface", "ifname", linker, s) {
uci_foreach_option_eq("network", "interface", "ifname", vlan_linker, s) {
dmuci_set_value_by_section(s, "ifname", new_name);
strncpy(sec_name, section_name(s), sizeof(sec_name) - 1);
break;
@ -1255,9 +1288,9 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &old_name);
dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &vid);
if (*vid != '\0')
snprintf(new_name, sizeof(new_name), "%s.%s", linker, vid);
snprintf(new_name, sizeof(new_name), "%s.%s", vlan_linker, vid);
else
snprintf(new_name, sizeof(new_name), "%s", linker);
snprintf(new_name, sizeof(new_name), "%s", vlan_linker);
if (is_name_exist_in_devices(new_name))
return -1;
@ -1271,7 +1304,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
}
// Set ifname and name options of device section
dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker);
dmuci_set_value_by_section((struct uci_section *)data, "ifname", vlan_linker);
dmuci_set_value_by_section((struct uci_section *)data, "name", new_name);
} else if (strncmp(value, "Device.Ethernet.VLANTermination.", 32) == 0) {
@ -1280,7 +1313,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &vid);
uci_foreach_option_eq("network", "device", "name", linker, ss) {
uci_foreach_option_eq("network", "device", "name", vlan_linker, ss) {
dmuci_get_value_by_section_string(ss, "vid", &inner_vid);
dmuci_get_value_by_section_string(ss, "ifname", &dev_name);
break;

View file

@ -28,4 +28,7 @@ extern DMLEAF tEthernetVLANTerminationParams[];
extern DMLEAF tEthernetVLANTerminationStatsParams[];
extern DMLEAF tEthernetRMONStatsParams[];
void get_bridge_port_linker(struct dmctx *ctx, char *intf_name, char **value);
int is_vlan_termination_section(const char *name);
#endif //__ETHERNET_H

View file

@ -9,6 +9,7 @@
*/
#include "dmentry.h"
#include "ethernet.h"
#include "interfacestack.h"
struct interfacestack_data {
@ -23,7 +24,7 @@ struct interfacestack_data {
**************************************************************/
static char *get_instance_by_section(int mode, char *dmmap_config, char *section, char *option, char *value, char *instance_option, char *alias_option)
{
struct uci_section *dmmap_section;
struct uci_section *dmmap_section = NULL;
char *instance = "";
get_dmmap_section_of_config_section_eq(dmmap_config, section, option, value, &dmmap_section);
@ -38,7 +39,7 @@ static char *get_instance_by_section(int mode, char *dmmap_config, char *section
static char *get_instance_by_section_option_condition(int mode, char *dmmap_config, char *section, struct uci_section *s, char *option, char *value, char *instance_option, char *alias_option)
{
struct uci_section *dmmap_section;
struct uci_section *dmmap_section = NULL;
char *instance = "";
get_dmmap_section_of_config_section_cont(dmmap_config, section, option, value, &dmmap_section);
@ -53,7 +54,7 @@ static char *get_instance_by_section_option_condition(int mode, char *dmmap_conf
static char *get_alias_by_section(char *dmmap_config, char *section, struct uci_section *s, char *alias_option)
{
struct uci_section *dmmap_section;
struct uci_section *dmmap_section = NULL;
char *alias = "";
get_dmmap_section_of_config_section(dmmap_config, section, section_name(s), &dmmap_section);
@ -63,7 +64,7 @@ static char *get_alias_by_section(char *dmmap_config, char *section, struct uci_
static char *get_alias_by_section_option_condition(char *dmmap_config, char *section, char *option, char *value, char *alias_option)
{
struct uci_section *dmmap_section;
struct uci_section *dmmap_section = NULL;
char *alias = "";
get_dmmap_section_of_config_section_cont(dmmap_config, section, option, value, &dmmap_section);
@ -87,17 +88,41 @@ static struct uci_section *create_dmmap_interface_stack_section(char *curr_inst)
return s;
}
int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
static int create_and_link_interface_stack_instance(struct dmctx *dmctx, DMNODE *parent_node, char *higherlayer, char *lowerlayer, char *higheralias, char *loweralias, char *max_inst, int *instance)
{
struct interfacestack_data intf_stack_data = {0};
struct uci_section *s = NULL, *dmmap_s = NULL;
struct uci_section *dmmap_s = NULL;
char *inst = NULL, buf_instance[16] = {0};
// fill interface stack data
intf_stack_data.higherlayer = higherlayer;
intf_stack_data.lowerlayer = lowerlayer;
intf_stack_data.higheralias = higheralias;
intf_stack_data.loweralias = loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++(*instance));
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
return -1;
return 0;
}
int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *layer_inst = "", *loweralias = "", *higheralias = "";
char *inst = NULL, *max_inst = NULL;
char *max_inst = NULL;
char buf_lowerlayer[128] = {0};
char buf_higherlayer[128] = {0};
char buf_higheralias[64] = {0};
char buf_loweralias[64] = {0};
char buf_instance[16] = {0};
int instance = 0;
/* Higher layers are Device.IP.Interface.{i}. */
@ -119,13 +144,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.IP.Interface.%s", layer_inst);
higheralias = get_alias_by_section("dmmap_network", "interface", s, "ip_int_alias");
if (*higheralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", layer_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *higheralias ? higheralias : *layer_inst ? "cpe-" : "", (*higheralias == '\0' && *layer_inst) ? layer_inst : "");
if (strstr(proto, "ppp")) {
// The lower layer is Device.PPP.Interface.{i}.
@ -134,10 +153,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
continue;
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "Device.PPP.Interface.%s", layer_inst);
loweralias = get_alias_by_section("dmmap_network", "interface", s, "ppp_int_alias");
if (*loweralias == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", layer_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : "cpe-", (*loweralias == '\0') ? layer_inst : "");
} else {
// The lower layer is Device.Ethernet.VLANTermination.{i}.
char *value = NULL;
@ -167,31 +183,11 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (value == NULL)
value = "";
}
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value?value:"");
if (*loweralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", layer_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value ? value : "");
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
}
// fill interface stack data
intf_stack_data.higherlayer = buf_higherlayer;
intf_stack_data.lowerlayer = buf_lowerlayer;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
}
@ -209,22 +205,16 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.PPP.Interface.%s", layer_inst);
higheralias = get_alias_by_section("dmmap_network", "interface", s, "ppp_int_alias");
if (*higheralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", layer_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *higheralias ? higheralias : *layer_inst ? "cpe-" : "", (*higheralias == '\0' && *layer_inst) ? layer_inst : "");
char *value = NULL;
int found = 0;
// The lower layer is Device.Ethernet.VLANTermination.{i}.
char *device = get_device(section_name(s));
if (device[0] != '\0') {
char *ppp_device = get_device(section_name(s));
if (ppp_device[0] != '\0') {
struct uci_section *vlan_sect = NULL;
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cEthernet%cVLANTermination%c", dmroot, dm_delim, dm_delim, dm_delim), device, &value);
uci_foreach_option_eq("network", "device", "name", device, vlan_sect) {
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cEthernet%cVLANTermination%c", dmroot, dm_delim, dm_delim, dm_delim), ppp_device, &value);
uci_foreach_option_eq("network", "device", "name", ppp_device, vlan_sect) {
loweralias = get_alias_by_section("dmmap_network", "device", vlan_sect, "vlan_term_alias");
layer_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_network", "device", "section_name", section_name(vlan_sect), "vlan_term_instance", "vlan_term_alias");
break;
@ -236,7 +226,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (found == 0) {
// The lower layer is Device.Ethernet.Link.{i}.
char linker[32] = {0};
strncpy(linker, device, sizeof(linker) - 1);
strncpy(linker, ppp_device, sizeof(linker) - 1);
char *vid = strchr(linker, '.');
if (vid) *vid = '\0';
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cEthernet%cLink%c", dmroot, dm_delim, dm_delim, dm_delim), linker, &value);
@ -247,29 +237,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value);
if (*loweralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", layer_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
// fill interface stack data
intf_stack_data.higherlayer = buf_higherlayer;
intf_stack_data.lowerlayer = buf_lowerlayer;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
}
@ -289,13 +259,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.VLANTermination.%s", layer_inst);
higheralias = get_alias_by_section("dmmap_network", "device", s, "vlan_term_alias");
if (*higheralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", layer_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *higheralias ? higheralias : *layer_inst ? "cpe-" : "", (*higheralias == '\0' && *layer_inst) ? layer_inst : "");
// The lower layer is Device.Ethernet.Link.{i}.
char *vid = strchr(name, '.');
@ -310,29 +274,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
dmuci_get_value_by_section_string(link_s, "link_alias", &loweralias);
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value);
if (*loweralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", layer_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
// fill interface stack data
intf_stack_data.higherlayer = buf_higherlayer;
intf_stack_data.lowerlayer = buf_lowerlayer;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
}
@ -347,14 +291,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.Link.%s", layer_inst);
dmuci_get_value_by_section_string(s, "link_alias", &higheralias);
if (*higheralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", layer_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *higheralias ? higheralias : *layer_inst ? "cpe-" : "", (*higheralias == '\0' && *layer_inst) ? layer_inst : "");
char *linker, *value = NULL;
dmuci_get_value_by_section_string(s, "device", &linker);
@ -406,29 +343,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
value = "";
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value);
if (*loweralias == '\0')
if (*layer_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", layer_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
// fill interface stack data
intf_stack_data.higherlayer = buf_higherlayer;
intf_stack_data.lowerlayer = buf_lowerlayer;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
}
@ -457,13 +374,8 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, &mg_value);
dmuci_get_value_by_section_string(port, "bridge_port_alias", &higheralias);
dmuci_get_value_by_section_string(port, "bridge_port_instance", &bridge_port_inst);
if (*higheralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_mngr, sizeof(buf_mngr), "%s", "");
else
snprintf(buf_mngr, sizeof(buf_mngr), "cpe-%s", bridge_port_inst);
else
snprintf(buf_mngr, sizeof(buf_mngr), "%s", higheralias);
snprintf(buf_mngr, sizeof(buf_mngr), "%s%s", *higheralias ? higheralias : *bridge_port_inst ? "cpe-" : "", (*higheralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
if (mg_value == NULL)
mg_value = "";
@ -490,38 +402,13 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
dmuci_get_value_by_section_string(sd, "bridge_port_alias", &loweralias);
dmuci_get_value_by_section_string(sd, "bridge_port_instance", &bridge_port_inst);
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
// fill interface stack data
intf_stack_data.higherlayer = mg_value;
intf_stack_data.lowerlayer = vb;
intf_stack_data.higheralias = buf_mngr;
intf_stack_data.loweralias = buf_loweralias;
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, mg_value, vb, buf_mngr, buf_loweralias, max_inst, &instance))
goto end;
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
char package[32] = {0};
int found = 0;
@ -606,41 +493,19 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
}
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
if (value == NULL)
value = "";
// fill interface stack data
intf_stack_data.higherlayer = vb;
intf_stack_data.lowerlayer = value;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, vb, value, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
// The lower layer is Device.WiFi.Radio.{i}.
if(strcmp(package, "wireless") == 0) {
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
struct uci_section *wl_s = NULL;
char *wl_device;
uci_foreach_option_eq("wireless", "wifi-iface", "ifname", device, wl_s) {
@ -663,41 +528,16 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (vb == NULL)
vb = "";
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
// fill interface stack data
intf_stack_data.higherlayer = value;
intf_stack_data.lowerlayer = vb;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, value, vb, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
}
// The lower layer is Device.DSL.Channel.{i}.
if(strcmp(package, "dsl:atm") == 0) {
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
char *link_channel = "channel_0";
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cDSL%cChannel%c", dmroot, dm_delim, dm_delim, dm_delim), link_channel, &vb);
@ -710,41 +550,16 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap", "dsl_channel", "section_name", section_name(dsl_s), "dsl_channel_instance", "dsl_channel_alias");
}
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
// fill interface stack data
intf_stack_data.higherlayer = value;
intf_stack_data.lowerlayer = vb;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, value, vb, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
}
// The lower layer is Device.DSL.Line.{i}.
if(strcmp(package, "dsl:ptm") == 0) {
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", "");
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
char *link_line = "line_0";
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cDSL%cLine%c", dmroot, dm_delim, dm_delim, dm_delim), link_line, &value);
@ -757,29 +572,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
bridge_port_inst = get_instance_by_section(dmctx->instance_mode, "dmmap", "dsl_line", "id", "0", "dsl_line_instance", "dsl_line_alias");
}
if (*loweralias == '\0')
if (*bridge_port_inst == '\0')
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", "");
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "cpe-%s", bridge_port_inst);
else
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
// fill interface stack data
intf_stack_data.higherlayer = vb;
intf_stack_data.lowerlayer = value;
intf_stack_data.higheralias = buf_higheralias;
intf_stack_data.loweralias = buf_loweralias;
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
if (create_and_link_interface_stack_instance(dmctx, parent_node, vb, value, buf_higheralias, buf_loweralias, max_inst, &instance))
goto end;
}
}

View file

@ -411,6 +411,56 @@ static void set_ip_interface_ifname_option(struct uci_section *section, char *li
dmuci_set_value_by_section(section, "ifname", ifname);
}
static int delObjIPInterfaceIPv6(void *data, unsigned char del_action, char *dmmap_file_name, char *section_type, char *option_name)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_s = NULL;
char *proto, *ifname, buf[32] = {0};
switch (del_action) {
case DEL_INST:
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec))))
return FAULT_9001;
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ifname", &ifname);
if (strchr(ifname, '@')) {
dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL);
} else {
dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, option_name, "");
}
dmuci_delete_by_section(((struct intf_ip_args *)data)->dmmap_sec, NULL, NULL);
break;
case DEL_ALL:
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data))))
return FAULT_9001;
snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data));
uci_foreach_sections_safe("network", "interface", stmp, s) {
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (strcmp(section_name(s), section_name((struct uci_section *)data)) == 0) {
dmuci_set_value_by_section(s, option_name, "");
get_dmmap_section_of_config_section(dmmap_file_name, section_type, section_name(s), &dmmap_s);
dmuci_delete_by_section(dmmap_s, NULL, NULL);
} else if (strcmp(ifname, buf) == 0) {
get_dmmap_section_of_config_section(dmmap_file_name, section_type, section_name(s), &dmmap_s);
dmuci_delete_by_section(dmmap_s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
} else {
continue;
}
}
break;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
@ -871,52 +921,7 @@ static int addObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void
static int delObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_s = NULL;
char *proto, *ifname, buf[32] = {0};
switch (del_action) {
case DEL_INST:
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec))))
return FAULT_9001;
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ifname", &ifname);
if (strchr(ifname, '@')) {
dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL);
} else {
dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6addr", "");
}
dmuci_delete_by_section(((struct intf_ip_args *)data)->dmmap_sec, NULL, NULL);
break;
case DEL_ALL:
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data))))
return FAULT_9001;
snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data));
uci_foreach_sections_safe("network", "interface", stmp, s) {
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (strcmp(section_name(s), section_name((struct uci_section *)data)) == 0) {
dmuci_set_value_by_section(s, "ip6addr", "");
get_dmmap_section_of_config_section("dmmap_network_ipv6", "intf_ipv6", section_name(s), &dmmap_s);
dmuci_delete_by_section(dmmap_s, NULL, NULL);
} else if (strcmp(ifname, buf) == 0) {
get_dmmap_section_of_config_section("dmmap_network_ipv6", "intf_ipv6", section_name(s), &dmmap_s);
dmuci_delete_by_section(dmmap_s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
} else {
continue;
}
}
break;
}
return 0;
return delObjIPInterfaceIPv6(data, del_action, "dmmap_network_ipv6", "intf_ipv6", "ip6addr");
}
static int addObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *data, char **instance)
@ -957,51 +962,7 @@ static int addObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *
static int delObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_s = NULL;
char *proto, *ifname, buf[32] = {0};
switch (del_action) {
case DEL_INST:
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec))))
return FAULT_9001;
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ifname", &ifname);
if (strchr(ifname, '@')) {
dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL);
} else {
dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6prefix", "");
}
dmuci_delete_by_section(((struct intf_ip_args *)data)->dmmap_sec, NULL, NULL);
break;
case DEL_ALL:
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data))))
return FAULT_9001;
snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data));
uci_foreach_sections_safe("network", "interface", stmp, s) {
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (strcmp(section_name(s), section_name((struct uci_section *)data)) == 0) {
dmuci_set_value_by_section(s, "ip6prefix", "");
get_dmmap_section_of_config_section("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", section_name(s), &dmmap_s);
dmuci_delete_by_section(dmmap_s, NULL, NULL);
} else if (strcmp(ifname, buf) == 0) {
get_dmmap_section_of_config_section("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", section_name(s), &dmmap_s);
dmuci_delete_by_section(dmmap_s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
} else {
continue;
}
}
break;
}
return 0;
return delObjIPInterfaceIPv6(data, del_action, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "ip6prefix");
}
/*************************************************************
@ -1346,7 +1307,7 @@ static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
char *ip_linker = NULL;
switch (action) {
case VALUECHECK:
@ -1354,8 +1315,8 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker == NULL || *linker == '\0')
adm_entry_get_linker_value(ctx, value, &ip_linker);
if (ip_linker == NULL || *ip_linker == '\0')
return -1;
if (strncmp(value, "Device.Ethernet.VLANTermination.", 32) == 0) {
@ -1370,21 +1331,21 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
break;
}
char *mac_vlan = strchr(linker, '_');
char *mac_vlan = strchr(ip_linker, '_');
if (mac_vlan) {
// Check if there is an interface that has the same ifname ==> if yes, remove it
uci_foreach_option_eq_safe("network", "interface", "ifname", linker, stmp, s) {
uci_foreach_option_eq_safe("network", "interface", "ifname", ip_linker, stmp, s) {
dmuci_delete_by_section(s, NULL, NULL);
}
// Check if there is an dmmap link section that has the same device ==> if yes, update section name
get_dmmap_section_of_config_section_eq("dmmap", "link", "device", linker, &s);
get_dmmap_section_of_config_section_eq("dmmap", "link", "device", ip_linker, &s);
dmuci_set_value_by_section_bbfdm(s, "section_name", section_name((struct uci_section *)data));
} else {
// Check if there is an interface that has the same name of device ==> if yes, remove it
char device[32] = {0};
strncpy(device, linker, sizeof(device) - 1);
strncpy(device, ip_linker, sizeof(device) - 1);
char *vid = strchr(device, '.');
if (vid) {
*vid = '\0';
@ -1395,14 +1356,14 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
}
// Update ifname list
dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker);
dmuci_set_value_by_section((struct uci_section *)data, "ifname", ip_linker);
} else if (strncmp(value, "Device.Ethernet.Link.", 21) == 0) {
// Get interface name from Ethernet.Link. object
struct uci_section *s = NULL;
char *interface_list;
get_dmmap_section_of_config_section_eq("dmmap", "link", "device", linker, &s);
get_dmmap_section_of_config_section_eq("dmmap", "link", "device", ip_linker, &s);
dmuci_get_value_by_section_string(s, "section_name", &interface_list);
char *interface = strchr(interface_list, ',');
@ -1417,7 +1378,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
if (*proto == '\0') {
dmuci_set_value_by_section(s, "proto", "dhcp");
if (strcmp(type, "bridge") != 0)
set_ip_interface_ifname_option(s, linker, instance);
set_ip_interface_ifname_option(s, ip_linker, instance);
} else {
ip_interface_s = true;
}
@ -1445,10 +1406,10 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
// remove the current interface section
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
} else {
set_ip_interface_ifname_option((struct uci_section *)data, linker, instance);
set_ip_interface_ifname_option((struct uci_section *)data, ip_linker, instance);
}
} else {
set_ip_interface_ifname_option((struct uci_section *)data, linker, instance);
set_ip_interface_ifname_option((struct uci_section *)data, ip_linker, instance);
}
}
break;
@ -1484,7 +1445,6 @@ static int get_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data,
static int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
char *ubus_object;
switch (action) {
case VALUECHECK:
@ -1494,10 +1454,10 @@ static int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data,
case VALUESET:
string_to_bool(value, &b);
if (b) {
dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data)));
dmubus_call_set(ubus_object, "down", UBUS_ARGS{}, 0);
dmubus_call_set(ubus_object, "up", UBUS_ARGS{}, 0);
dmfree(ubus_object);
char interface_obj[64] = {0};
snprintf(interface_obj, sizeof(interface_obj), "network.interface.%s", section_name(((struct uci_section *)data)));
dmubus_call_set(interface_obj, "down", UBUS_ARGS{}, 0);
dmubus_call_set(interface_obj, "up", UBUS_ARGS{}, 0);
}
break;
}
@ -1673,7 +1633,7 @@ static int get_IPInterfaceIPv4Address_IPAddress(char *refparam, struct dmctx *ct
static int set_IPInterfaceIPv4Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *proto = NULL;
char *proto_intf = NULL;
switch (action) {
case VALUECHECK:
@ -1681,8 +1641,8 @@ static int set_IPInterfaceIPv4Address_IPAddress(char *refparam, struct dmctx *ct
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto);
if (proto && strcmp(proto, "static") == 0) {
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto_intf);
if (proto_intf && strcmp(proto_intf, "static") == 0) {
dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipaddr", value);
dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "address", value);
}
@ -1962,9 +1922,9 @@ static int get_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign);
if (assign && strcmp(assign, "1") == 0)
preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "preferred");
preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "valid");
else
preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred");
preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "valid");
if (preferred && *preferred && get_shift_time_time(atoi(preferred), local_time, sizeof(local_time)) == -1)
return 0;

View file

@ -110,7 +110,6 @@ static int get_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data,
static int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
char *ubus_object;
switch (action) {
case VALUECHECK:
@ -120,10 +119,10 @@ static int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data,
case VALUESET:
string_to_bool(value, &b);
if (b) {
dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data)));
dmubus_call_set(ubus_object, "down", UBUS_ARGS{}, 0);
dmubus_call_set(ubus_object, "up", UBUS_ARGS{}, 0);
dmfree(ubus_object);
char intf_obj[64] = {0};
snprintf(intf_obj, sizeof(intf_obj), "network.interface.%s", section_name(((struct uci_section *)data)));
dmubus_call_set(intf_obj, "down", UBUS_ARGS{}, 0);
dmubus_call_set(intf_obj, "up", UBUS_ARGS{}, 0);
}
break;
}
@ -285,7 +284,7 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
char *ppp_linker = NULL;
switch (action) {
case VALUECHECK:
@ -293,10 +292,10 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
return FAULT_9007;
return 0;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section(((struct uci_section *)data), "ifname", linker);
dmfree(linker);
adm_entry_get_linker_value(ctx, value, &ppp_linker);
if (ppp_linker && *ppp_linker) {
dmuci_set_value_by_section(((struct uci_section *)data), "ifname", ppp_linker);
dmfree(ppp_linker);
}
return 0;
}
@ -333,15 +332,15 @@ static int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void
static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *proto;
char *proto_intf;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto);
if (strcmp(proto, "pppoe") != 0)
dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto_intf);
if (strcmp(proto_intf, "pppoe") != 0)
return FAULT_9001;
break;
case VALUESET:

View file

@ -20,6 +20,7 @@ int os_get_linker_qos_queue(char *refparam, struct dmctx *dmctx, void *data, cha
*linker = "";
return 0;
}
int os_browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *value = NULL;
@ -181,8 +182,8 @@ int os_addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, ch
int os_delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section= NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
if (is_section_unnamed(section_name((struct uci_section *)data))){
@ -192,90 +193,22 @@ int os_delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, ch
dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
}
break;
case DEL_ALL:
uci_foreach_sections("qos", "classify", s) {
if (found != 0){
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
uci_foreach_sections_safe("qos", "classify", stmp, s) {
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
#if 0
int addObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
//TODO
return 0;
}
int delObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
switch (del_action) {
case DEL_INST:
//TODO
break;
case DEL_ALL:
//TODO
break;
}
return 0;
}
int addObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
//TODO
return 0;
}
int delObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
switch (del_action) {
case DEL_INST:
//TODO
break;
case DEL_ALL:
//TODO
break;
}
return 0;
}
int addObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
//TODO
return 0;
}
int delObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
switch (del_action) {
case DEL_INST:
//TODO
break;
case DEL_ALL:
//TODO
break;
}
return 0;
}
#endif
int os_addObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
@ -497,6 +430,47 @@ int os_delObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char *inst
return 0;
}
/*************************************************************
* COMMON Functions
**************************************************************/
static int os_get_QoS_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ifname = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
*value = "";
return 0;
}
static int os_set_QoS_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker);
dmfree(linker);
}
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
*************************************************************/
@ -1010,40 +984,12 @@ int os_set_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data
int os_get_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ifname;
dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
*value = "";
return 0;
return os_get_QoS_Interface(refparam, ctx, data, instance, value);
}
int os_set_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker);
dmfree(linker);
}
break;
}
return 0;
return os_set_QoS_Interface(refparam, ctx, data, instance, value, action);
}
int os_get_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
@ -3290,40 +3236,12 @@ int os_set_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data
int os_get_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ifname;
dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
*value = "";
return 0;
return os_get_QoS_Interface(refparam, ctx, data, instance, value);
}
int os_set_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker);
dmfree(linker);
}
break;
}
return 0;
return os_set_QoS_Interface(refparam, ctx, data, instance, value, action);
}
#if 0
@ -3704,39 +3622,12 @@ int os_set_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *
int os_get_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ifname = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, value);
if (*value == NULL)
*value = "";
return 0;
return os_get_QoS_Interface(refparam, ctx, data, instance, value);
}
int os_set_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
break;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "ifname", linker);
dmfree(linker);
}
break;
}
return 0;
return os_set_QoS_Interface(refparam, ctx, data, instance, value, action);
}
int os_get_QoSShaper_ShapingRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)

View file

@ -197,8 +197,7 @@ int os_addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, ch
int os_delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct dmmap_dup *p = (struct dmmap_dup*)data;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
@ -209,73 +208,23 @@ int os_delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, ch
dmuci_delete_by_section_unnamed(p->config_section, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(p->config_section), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section(p->config_section, NULL, NULL);
}
break;
case DEL_ALL:
uci_foreach_sections("qos", "classify", s) {
if (found != 0){
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
uci_foreach_sections_safe("qos", "classify", stmp, s) {
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
#if 0
int addObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
//TODO
return 0;
}
int delObjQoSApp(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
switch (del_action) {
case DEL_INST:
//TODO
break;
case DEL_ALL:
//TODO
break;
}
return 0;
}
int addObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
//TODO
return 0;
}
int delObjQoSFlow(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
switch (del_action) {
case DEL_INST:
//TODO
break;
case DEL_ALL:
//TODO
break;
}
return 0;
}
#endif
int os_addObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
//TODO

View file

@ -129,30 +129,33 @@ static bool is_cfg_route_active(struct uci_section *s)
return false;
}
static int get_forwarding_last_inst()
static int get_forwarding_last_inst(void)
{
char *rinst = NULL, *drinst = NULL, *dsinst = NULL, *tmp;
int r = 0, dr = 0, ds = 0, max;
struct uci_section *s;
char *rinst = NULL, *drinst = NULL, *dsinst = NULL, *tmp = NULL;
int r = 0, dr = 0, ds = 0, max = 0;
struct uci_section *s = NULL;
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route", s) {
dmuci_get_value_by_section_string(s, "routeinstance", &tmp);
if (tmp[0] == '\0')
if (tmp && tmp[0] == '\0')
break;
rinst = tmp;
}
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route_disabled", s) {
dmuci_get_value_by_section_string(s, "routeinstance", &tmp);
if (tmp[0] == '\0')
if (tmp && tmp[0] == '\0')
break;
dsinst = tmp;
}
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route_dynamic", s) {
dmuci_get_value_by_section_string(s, "routeinstance", &tmp);
if (tmp[0] == '\0')
if (tmp && tmp[0] == '\0')
break;
drinst = tmp;
}
if (rinst) r = atoi(rinst);
if (dsinst) ds = atoi(dsinst);
if (drinst) dr = atoi(drinst);
@ -160,6 +163,32 @@ static int get_forwarding_last_inst()
return max;
}
static int get_forwarding6_last_inst(void)
{
char *rinst = NULL, *drinst = NULL, *tmp = NULL;
int r = 0, dr = 0, max = 0;
struct uci_section *s = NULL;
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6", s) {
dmuci_get_value_by_section_string(s, "route6instance", &tmp);
if (tmp && tmp[0] == '\0')
break;
rinst = tmp;
}
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6_dynamic", s) {
dmuci_get_value_by_section_string(s, "route6instance", &tmp);
if (tmp && tmp[0] == '\0')
break;
drinst = tmp;
}
if (rinst) r = atoi(rinst);
if (drinst) dr = atoi(drinst);
max = r>dr?r:dr;
return max;
}
static char *forwarding_update_instance_alias_bbfdm(int action, char **last_inst, char **max_inst, void *argv[])
{
char *instance, *alias;
@ -168,73 +197,13 @@ static char *forwarding_update_instance_alias_bbfdm(int action, char **last_inst
struct uci_section *s = (struct uci_section *) argv[0];
char *inst_opt = (char *) argv[1];
char *alias_opt = (char *) argv[2];
bool *find_max = (bool *) argv[3];
bool *ipv4_forwarding = (bool *) argv[3];
bool *find_max = (bool *) argv[4];
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
if (*find_max) {
int m = get_forwarding_last_inst();
snprintf(buf, sizeof(buf), "%d", m+1);
*find_max = false;
} else if (max_inst == NULL) {
snprintf(buf, sizeof(buf), "%d", 1);
} else {
snprintf(buf, sizeof(buf), "%d", atoi(*max_inst)+1);
}
instance = dmuci_set_value_by_section_bbfdm(s, inst_opt, buf);
}
*max_inst = instance;
*last_inst = instance;
if (action == INSTANCE_MODE_ALIAS) {
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias[0] == '\0') {
snprintf(buf, sizeof(buf), "cpe-%s", instance);
alias = dmuci_set_value_by_section_bbfdm(s, alias_opt, buf);
}
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
return instance;
}
static int get_forwarding6_last_inst()
{
char *rinst = NULL, *drinst = NULL, *tmp;
int r = 0, dr = 0, max;
struct uci_section *s;
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6", s) {
dmuci_get_value_by_section_string(s, "route6instance", &tmp);
if (tmp[0] == '\0')
break;
rinst = tmp;
}
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6_dynamic", s) {
dmuci_get_value_by_section_string(s, "route6instance", &tmp);
if (tmp[0] == '\0')
break;
drinst = tmp;
}
if (rinst) r = atoi(rinst);
if (drinst) dr = atoi(drinst);
max = r>dr?r:dr;
return max;
}
static char *forwarding6_update_instance_alias_bbfdm(int action, char **last_inst, char **max_inst, void *argv[])
{
char *instance, *alias;
char buf[64] = {0};
struct uci_section *s = (struct uci_section *) argv[0];
char *inst_opt = (char *) argv[1];
char *alias_opt = (char *) argv[2];
bool *find_max = (bool *) argv[3];
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
if (*find_max) {
int m = get_forwarding6_last_inst();
int m = (*ipv4_forwarding) ? get_forwarding_last_inst() : get_forwarding6_last_inst();
snprintf(buf, sizeof(buf), "%d", m+1);
*find_max = false;
} else if (max_inst == NULL) {
@ -332,47 +301,70 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN
return 0;
}
static int parse_proc_route6_line(const char *line, char *ipstr, char *gwstr, char *dev, unsigned int *metric)
{
unsigned int ip[4], gw[4], flags, refcnt, use, prefix;
char ipbuf[INET6_ADDRSTRLEN];
if (*line == '\n' || *line == '\0')
return -1;
sscanf(line, "%8x%8x%8x%8x %x %*s %*s %8x%8x%8x%8x %x %x %x %x %31s",
&ip[0], &ip[1], &ip[2], &ip[3], &prefix,
&gw[0], &gw[1], &gw[2], &gw[3], metric,
&refcnt, &use, &flags, dev);
if (strcmp(dev, "lo") == 0)
return -1;
ip[0] = htonl(ip[0]);
ip[1] = htonl(ip[1]);
ip[2] = htonl(ip[2]);
ip[3] = htonl(ip[3]);
gw[0] = htonl(gw[0]);
gw[1] = htonl(gw[1]);
gw[2] = htonl(gw[2]);
gw[3] = htonl(gw[3]);
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
sprintf(ipstr, "%s/%u", ipbuf, prefix);
inet_ntop(AF_INET6, gw, gwstr, INET6_ADDRSTRLEN);
return 0;
}
static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL, *stmp;
char buf[512], dev[32], ipstr[INET6_ADDRSTRLEN + 8], gwstr[INET6_ADDRSTRLEN + 8];
char ipbuf[INET6_ADDRSTRLEN];
unsigned int ip[4], gw[4];
unsigned int flags, refcnt, use, metric, prefix;
char *iface, *str, *target;
json_object *jobj;
FILE* fp = NULL;
int found;
struct uci_section *s = NULL, *stmp = NULL;
char buf[512] = {0}, dev[32] = {0}, ipstr[INET6_ADDRSTRLEN + 8] = {0}, gwstr[INET6_ADDRSTRLEN + 8] = {0};
char *iface, *target;
unsigned int metric;
FILE *fp = NULL;
int found = 0;
uci_path_foreach_sections_safe(bbfdm, "dmmap_route_forwarding", "route6_dynamic", stmp, s) {
dmuci_get_value_by_section_string(s, "target", &target);
dmuci_get_value_by_section_string(s, "device", &iface);
fp = fopen(PROC_ROUTE6, "r");
if (fp == NULL)
return 0;
found = 0;
while (fgets(buf, 512, fp) != NULL) {
if (*buf == '\n' || *buf == '\0')
if (parse_proc_route6_line(buf, ipstr, gwstr, dev, &metric))
continue;
sscanf(buf, "%8x%8x%8x%8x %x %*s %*s %8x%8x%8x%8x %x %x %x %x %31s", &ip[0], &ip[1], &ip[2], &ip[3],
&prefix, &gw[0], &gw[1], &gw[2], &gw[3], &metric, &refcnt, &use, &flags, dev);
if (strcmp(dev, "lo") == 0)
continue;
ip[0] = htonl(ip[0]);
ip[1] = htonl(ip[1]);
ip[2] = htonl(ip[2]);
ip[3] = htonl(ip[3]);
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
snprintf(ipstr, sizeof(ipstr), "%s/%u", ipbuf, prefix);
if (strcmp(iface, dev) == 0 && strcmp(ipstr, target) == 0) {
found = 1;
break;
}
}
fclose(fp);
if (!found)
dmuci_delete_by_section(s, NULL, NULL);
fclose(fp);
}
fp = fopen(PROC_ROUTE6, "r");
@ -380,33 +372,22 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
return 0;
while (fgets(buf , 512 , fp) != NULL) {
if (*buf == '\n' || *buf == '\0')
if (parse_proc_route6_line(buf, ipstr, gwstr, dev, &metric))
continue;
sscanf(buf, "%8x%8x%8x%8x %x %*s %*s %8x%8x%8x%8x %x %x %x %x %31s", &ip[0], &ip[1], &ip[2], &ip[3],
&prefix, &gw[0], &gw[1], &gw[2], &gw[3], &metric, &refcnt, &use, &flags, dev);
if (strcmp(dev, "lo") == 0)
continue;
ip[0] = htonl(ip[0]);
ip[1] = htonl(ip[1]);
ip[2] = htonl(ip[2]);
ip[3] = htonl(ip[3]);
gw[0] = htonl(gw[0]);
gw[1] = htonl(gw[1]);
gw[2] = htonl(gw[2]);
gw[3] = htonl(gw[3]);
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
snprintf(ipstr, sizeof(ipstr), "%s/%u", ipbuf, prefix);
inet_ntop(AF_INET6, gw, gwstr, INET6_ADDRSTRLEN);
if (is_proc_route6_in_config(dev, ipstr, gwstr))
continue;
iface = "";
uci_foreach_sections("network", "interface", s) {
json_object *jobj = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &jobj);
if (!jobj) {
fclose(fp);
return 0;
}
str = dmjson_get_value(jobj, 1, "device");
char *str = dmjson_get_value(jobj, 1, "device");
if (strcmp(str, dev) == 0) {
iface = section_name(s);
break;
@ -635,7 +616,7 @@ static int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx
return 0;
}
static int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int get_RoutingRouterForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *linker;
@ -649,7 +630,7 @@ static int get_router_ipv4forwarding_interface_linker_parameter(char *refparam,
return 0;
}
static int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
static int set_RoutingRouterForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
@ -776,40 +757,6 @@ static int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx
return 0;
}
static int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *linker;
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "interface", &linker);
if (linker[0] != '\0') {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
}
return 0;
}
static int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
return FAULT_9007;
return 0;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", linker);
dmfree(linker);
}
return 0;
}
return 0;
}
static int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC)
@ -866,26 +813,23 @@ static int set_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx,
static int get_RoutingRouteInformation_InterfaceSettingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
json_object *res, *route_obj;
char *proto, *ip6addr;
int entries = 0;
size_t nbre_routes = 0;
uci_foreach_sections("network", "interface", s) {
char *proto = NULL, *ip6addr = NULL;
dmuci_get_value_by_section_string(s, "proto", &proto);
dmuci_get_value_by_section_string(s, "ip6addr", &ip6addr);
if(strcmp(proto, "dhcpv6")==0 || ip6addr[0] != '\0') {
if ((proto && strcmp(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) {
json_object *res = NULL, *routes = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res);
while (res) {
route_obj = dmjson_select_obj_in_array_idx(res, entries, 1, "route");
if(route_obj) {
entries++;
}
else
break;
}
DM_ASSERT(res, *value = "0");
json_object_object_get_ex(res, "route", &routes);
nbre_routes = (routes) ? json_object_array_length(routes) : 0;
}
}
dmasprintf(value, "%d", entries);
dmasprintf(value, "%d", nbre_routes);
return 0;
}
@ -913,50 +857,39 @@ static int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, st
static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char buf[512], dev[32], ipstr[INET6_ADDRSTRLEN + 8], gwstr[INET6_ADDRSTRLEN + 8];
char ipbuf[INET6_ADDRSTRLEN];
unsigned int ip[4], gw[4], flags, refcnt, use, metric, prefix;
char *source, *nexthop, *str, *iface = "";
json_object *jobj;
FILE* fp = NULL;
char buf[512] = {0}, dev[32] = {0}, ipstr[INET6_ADDRSTRLEN + 8] = {0}, gwstr[INET6_ADDRSTRLEN + 8] = {0};
unsigned int metric;
char *iface = "";
source = dmjson_get_value((struct json_object *)data, 1, "source");
nexthop = dmjson_get_value((struct json_object *)data, 1, "nexthop");
fp = fopen(PROC_ROUTE6, "r");
char *source = dmjson_get_value((struct json_object *)data, 1, "source");
char *nexthop = dmjson_get_value((struct json_object *)data, 1, "nexthop");
FILE *fp = fopen(PROC_ROUTE6, "r");
if (fp == NULL)
return 0;
while (fgets(buf , 512 , fp) != NULL) {
if (*buf == '\n' || *buf == '\0')
if (parse_proc_route6_line(buf, ipstr, gwstr, dev, &metric))
continue;
sscanf(buf, "%8x%8x%8x%8x %x %*s %*s %8x%8x%8x%8x %x %x %x %x %31s", &ip[0], &ip[1], &ip[2], &ip[3],
&prefix, &gw[0], &gw[1], &gw[2], &gw[3], &metric, &refcnt, &use, &flags, dev);
if (strcmp(dev, "lo") == 0)
continue;
ip[0] = htonl(ip[0]);
ip[1] = htonl(ip[1]);
ip[2] = htonl(ip[2]);
ip[3] = htonl(ip[3]);
gw[0] = htonl(gw[0]);
gw[1] = htonl(gw[1]);
gw[2] = htonl(gw[2]);
gw[3] = htonl(gw[3]);
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
snprintf(ipstr, sizeof(ipstr), "%s/%u", ipbuf, prefix);
inet_ntop(AF_INET6, gw, gwstr, INET6_ADDRSTRLEN);
if((strcmp(source, ipstr) == 0) && (strcmp(nexthop, gwstr) == 0))
break;
}
fclose(fp);
uci_foreach_sections("network", "interface", s) {
json_object *jobj = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &jobj);
if (!jobj) return 0;
str = dmjson_get_value(jobj, 1, "device");
char *str = dmjson_get_value(jobj, 1, "device");
if (strcmp(str, dev) == 0) {
iface = section_name(s);
break;
}
}
if (iface[0] != '\0') {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), iface, value);
if (*value == NULL)
@ -1192,7 +1125,7 @@ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
{
char *inst = NULL, *max_inst = NULL;
struct uci_section *ss = NULL;
bool find_max = true;
bool find_max = true, ipv4_forwarding = true;
struct routingfwdargs curr_routefwdargs = {0};
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -1201,8 +1134,8 @@ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
list_for_each_entry(p, &dup_list, list) {
init_args_ipv4forward(&curr_routefwdargs, p->config_section, "1", ROUTE_STATIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 4,
p->dmmap_section, "routeinstance", "routealias", &find_max);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
p->dmmap_section, "routeinstance", "routealias", ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
@ -1212,8 +1145,8 @@ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
list_for_each_entry(p, &dup_list, list) {
init_args_ipv4forward(&curr_routefwdargs, p->config_section, "1", ROUTE_DISABLED);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 4,
p->dmmap_section, "routeinstance", "routealias", &find_max);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
p->dmmap_section, "routeinstance", "routealias", ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
@ -1224,8 +1157,8 @@ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route_dynamic", ss) {
init_args_ipv4forward(&curr_routefwdargs, ss, "0", ROUTE_DYNAMIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 4,
ss, "routeinstance", "routealias", &find_max);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
ss, "routeinstance", "routealias", ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
@ -1239,7 +1172,7 @@ static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
{
char *inst = NULL, *max_inst = NULL;
struct uci_section *ss = NULL;
bool find_max = true;
bool find_max = true, ipv4_forwarding = false;
struct routingfwdargs curr_route6fwdargs = {0};
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -1248,8 +1181,8 @@ static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
list_for_each_entry(p, &dup_list, list) {
init_args_ipv6forward(&curr_route6fwdargs, p->config_section, "1", ROUTE_STATIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding6_update_instance_alias_bbfdm, 4,
p->dmmap_section, "route6instance", "route6alias", &find_max);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
p->dmmap_section, "route6instance", "route6alias", ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
@ -1259,8 +1192,8 @@ static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6_dynamic", ss) {
init_args_ipv6forward(&curr_route6fwdargs, ss, "0", ROUTE_DYNAMIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding6_update_instance_alias_bbfdm, 4,
ss, "route6instance", "route6alias", &find_max);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
ss, "route6instance", "route6alias", ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
@ -1272,24 +1205,21 @@ end:
static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
json_object *res, *route_obj;
char *proto, *ip6addr, *inst, *max_inst = NULL;
int id = 0, entries = 0;
char *inst, *max_inst = NULL;
int id = 0, i = 0;
uci_foreach_sections("network", "interface", s) {
char *proto = NULL, *ip6addr = NULL;
dmuci_get_value_by_section_string(s, "proto", &proto);
dmuci_get_value_by_section_string(s, "ip6addr", &ip6addr);
if(strcmp(proto, "dhcpv6")==0 || ip6addr[0] != '\0') {
if ((proto && strcmp(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) {
json_object *res = NULL, *route_obj = NULL, *arrobj = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res);
while (res) {
route_obj = dmjson_select_obj_in_array_idx(res, entries, 1, "route");
if(route_obj) {
entries++;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)route_obj, inst) == DM_STOP)
break;
}
else
dmjson_foreach_obj_in_array(res, arrobj, route_obj, i, 1, "route") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)route_obj, inst) == DM_STOP)
break;
}
}
@ -1340,7 +1270,7 @@ DMLEAF tRoutingRouterIPv4ForwardingParams[] = {
{"DestSubnetMask", &DMRouting, DMT_STRING, get_router_ipv4forwarding_destmask, set_router_ipv4forwarding_destmask, BBFDM_BOTH},
{"ForwardingPolicy", &DMREAD, DMT_INT, get_router_ipv4forwarding_forwarding_policy, NULL, BBFDM_BOTH},
{"GatewayIPAddress", &DMRouting, DMT_STRING, get_router_ipv4forwarding_gatewayip, set_router_ipv4forwarding_gatewayip, BBFDM_BOTH},
{"Interface", &DMRouting, DMT_STRING, get_router_ipv4forwarding_interface_linker_parameter, set_router_ipv4forwarding_interface_linker_parameter, BBFDM_BOTH},
{"Interface", &DMRouting, DMT_STRING, get_RoutingRouterForwarding_Interface, set_RoutingRouterForwarding_Interface, BBFDM_BOTH},
{"Origin", &DMREAD, DMT_STRING, get_router_ipv4forwarding_origin, NULL, BBFDM_BOTH},
{"ForwardingMetric", &DMRouting, DMT_INT, get_router_ipv4forwarding_metric, set_router_ipv4forwarding_metric, BBFDM_BOTH},
{0}
@ -1355,7 +1285,7 @@ DMLEAF tRoutingRouterIPv6ForwardingParams[] = {
{"DestIPPrefix", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_DestIPPrefix, set_RoutingRouterIPv6Forwarding_DestIPPrefix, BBFDM_BOTH},
{"ForwardingPolicy", &DMRouting, DMT_INT, get_RoutingRouterIPv6Forwarding_ForwardingPolicy, set_RoutingRouterIPv6Forwarding_ForwardingPolicy, BBFDM_BOTH},
{"NextHop", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_NextHop, set_RoutingRouterIPv6Forwarding_NextHop, BBFDM_BOTH},
{"Interface", &DMRouting, DMT_STRING, get_RoutingRouterIPv6Forwarding_Interface, set_RoutingRouterIPv6Forwarding_Interface, BBFDM_BOTH},
{"Interface", &DMRouting, DMT_STRING, get_RoutingRouterForwarding_Interface, set_RoutingRouterForwarding_Interface, BBFDM_BOTH},
{"Origin", &DMREAD, DMT_STRING, get_RoutingRouterIPv6Forwarding_Origin, NULL, BBFDM_BOTH},
{"ForwardingMetric", &DMRouting, DMT_INT, get_RoutingRouterIPv6Forwarding_ForwardingMetric, set_RoutingRouterIPv6Forwarding_ForwardingMetric, BBFDM_BOTH},
{"ExpirationTime", &DMREAD, DMT_TIME, get_RoutingRouterIPv6Forwarding_ExpirationTime, NULL, BBFDM_BOTH},

View file

@ -150,7 +150,7 @@ static int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_nod
{
json_object *res = NULL, *devices = NULL, *device = NULL;
struct upnpdiscovery upnp_dev = {};
char *descurl = NULL, *st = NULL, *usn = NULL, *inst = NULL, *max_inst = NULL;
char *dev_descurl = NULL, *dev_st = NULL, *dev_usn = NULL, *inst = NULL, *max_inst = NULL;
char **stparams = NULL, **uuid, **urn;
size_t lengthuuid, lengthurn;
struct uci_section* dmmap_sect = NULL;
@ -163,18 +163,18 @@ static int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_nod
size_t nbre_devices = (devices) ? json_object_array_length(devices) : 0;
for (i = 0; i < nbre_devices; i++) {
device= json_object_array_get_idx(devices, i);
descurl = dmjson_get_value(device, 1, "descurl");
st = dmjson_get_value(device, 1, "st");
usn = dmjson_get_value(device, 1, "usn");
stparams = strsplit_by_str(usn, "::");
device = json_object_array_get_idx(devices, i);
dev_descurl = dmjson_get_value(device, 1, "descurl");
dev_st = dmjson_get_value(device, 1, "st");
dev_usn = dmjson_get_value(device, 1, "usn");
stparams = strsplit_by_str(dev_usn, "::");
uuid = strsplit(stparams[0], ":", &lengthuuid);
urn = strsplit(stparams[1], ":", &lengthurn);
dmasprintf(&upnp_dev.descurl, "%s", descurl?descurl:"");
dmasprintf(&upnp_dev.st, "%s", st?st:"");
dmasprintf(&upnp_dev.usn, "%s", usn?usn:"");
dmasprintf(&upnp_dev.uuid, "%s", lengthuuid>0?uuid[1]:"");
dmasprintf(&upnp_dev.urn, "%s", lengthurn>0?urn[1]:"");
dmasprintf(&upnp_dev.descurl, "%s", dev_descurl ? dev_descurl : "");
dmasprintf(&upnp_dev.st, "%s", dev_st ? dev_st : "");
dmasprintf(&upnp_dev.usn, "%s", dev_usn ? dev_usn : "");
dmasprintf(&upnp_dev.uuid, "%s", (lengthuuid > 0) ? uuid[1] : "");
dmasprintf(&upnp_dev.urn, "%s", (lengthurn > 0) ? urn[1] : "");
if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_device", "uuid", uuid[1])) == NULL) {
dmuci_add_section_bbfdm("dmmap_upnp", "upnp_device", &dmmap_sect);
@ -196,7 +196,7 @@ static int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_no
{
json_object *res = NULL, *services = NULL, *service = NULL;
struct upnpdiscovery upnp_dev = {};
char *descurl = NULL, *st = NULL, *usn = NULL, *inst = NULL, *max_inst = NULL;
char *srv_descurl = NULL, *srv_st = NULL, *srv_usn = NULL, *inst = NULL, *max_inst = NULL;
char **stparams = NULL, **uuid, **urn;
size_t lengthuuid, lengthurn;
struct uci_section* dmmap_sect = NULL;
@ -210,21 +210,21 @@ static int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_no
for (i = 0; i < nbre_services; i++){
service = json_object_array_get_idx(services, i);
descurl = dmjson_get_value(service, 1, "descurl");
st = dmjson_get_value(service, 1, "st");
usn = dmjson_get_value(service, 1, "usn");
stparams = strsplit_by_str(usn, "::");
srv_descurl = dmjson_get_value(service, 1, "descurl");
srv_st = dmjson_get_value(service, 1, "st");
srv_usn = dmjson_get_value(service, 1, "usn");
stparams = strsplit_by_str(srv_usn, "::");
uuid = strsplit(stparams[0], ":", &lengthuuid);
urn = strsplit(stparams[1], ":", &lengthurn);
dmasprintf(&upnp_dev.descurl, "%s", descurl?descurl:"");
dmasprintf(&upnp_dev.st, "%s", st?st:"");
dmasprintf(&upnp_dev.usn, "%s", usn?usn:"");
dmasprintf(&upnp_dev.uuid, "%s", lengthuuid>0?uuid[1]:"");
dmasprintf(&upnp_dev.urn, "%s", lengthurn>0?urn[1]:"");
dmasprintf(&upnp_dev.descurl, "%s", srv_descurl ? srv_descurl : "");
dmasprintf(&upnp_dev.st, "%s", srv_st ? srv_st : "");
dmasprintf(&upnp_dev.usn, "%s", srv_usn ? srv_usn : "");
dmasprintf(&upnp_dev.uuid, "%s", (lengthuuid > 0) ? uuid[1] : "");
dmasprintf(&upnp_dev.urn, "%s", (lengthurn > 0) ? urn[1] : "");
if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_service", "usn", usn)) == NULL) {
if ((dmmap_sect = get_dup_section_in_dmmap_opt("dmmap_upnp", "upnp_service", "usn", srv_usn)) == NULL) {
dmuci_add_section_bbfdm("dmmap_upnp", "upnp_service", &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "usn", usn);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "usn", srv_usn);
}
upnp_dev.dmmap_sect = dmmap_sect;

View file

@ -140,7 +140,7 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
//dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL);
continue;
}
if(p->dm){
if(p->dmmap_section){
foldersplit= strsplit(p->sysfs_folder_name, ":", &length);
snprintf(port_link, sizeof(port_link), "%s", foldersplit[0]);
}
@ -155,14 +155,14 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
closedir(dir);
dmasprintf(&iface_path, "%s/%s", netfolderpath, iface_name);
if (p->dm)
dmuci_set_value_by_section_bbfdm(p->dm, "usb_iface_path", iface_path);
if (p->dmmap_section)
dmuci_set_value_by_section_bbfdm(p->dmmap_section, "usb_iface_path", iface_path);
dmasprintf(&statistics_path, "%s/statistics", iface_path);
init_usb_interface(p->dm, iface_name, iface_path, statistics_path, port_link, &iface);
init_usb_interface(p->dmmap_section, iface_name, iface_path, statistics_path, port_link, &iface);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dm, "usb_iface_instance", "usb_iface_alias");
p->dmmap_section, "usb_iface_instance", "usb_iface_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &iface, inst) == DM_STOP)
break;
@ -183,22 +183,21 @@ static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH,
"dmmap_usb", "dmmap_port", "port_link", "usb_port_instance", &dup_list);
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_port", "port_link", "usb_port_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (regexec(&regex1, p->sysfs_folder_name, 0, NULL, 0) != 0 &&
regexec(&regex2, p->sysfs_folder_name, 0, NULL, 0) !=0 &&
strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name) {
dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL);
dmuci_delete_by_section_unnamed_bbfdm(p->dmmap_section, NULL, NULL);
continue;
}
init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port);
init_usb_port(p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path, &port);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dm, "usb_port_instance", "usb_port_alias");
p->dmmap_section, "usb_port_instance", "usb_port_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, inst) == DM_STOP)
break;
@ -213,21 +212,20 @@ static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, v
{
struct sysfs_dmsection *p;
char *inst = NULL, *max_inst = NULL;
struct usb_port port= {};
struct usb_port port = {0};
LIST_HEAD(dup_list);
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH,
"dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list);
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if(!strstr(p->sysfs_folder_name, "usb"))
continue;
init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port);
port.dmsect= p->dm;
init_usb_port(p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path, &port);
port.dmsect= p->dmmap_section;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dm, "usb_host_instance", "usb_host_alias");
p->dmmap_section, "usb_host_instance", "usb_host_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, inst) == DM_STOP)
break;
@ -241,7 +239,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
struct uci_section *s, *stmp, *dmmap_sect;
DIR *dir;
struct dirent *ent;
char *v, *sysfs_rep_path, *instance = NULL;
char *v, *sysfs_repo_path, *instance = NULL;
struct sysfs_dmsection *p;
regex_t regex1 = {}, regex2 = {};
@ -251,7 +249,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
LIST_HEAD(dup_list_no_inst);
sysfs_foreach_file(sysfsrep, dir, ent) {
if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0)
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
if (regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0) {
@ -261,7 +259,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", sysfsrep, ent->d_name);
dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass));
if(strncmp(deviceClass, "09", 2) == 0){
if (strncmp(deviceClass, "09", 2) == 0) {
char hubpath[270];
snprintf(hubpath, sizeof(hubpath), "%s/%s", sysfsrep, ent->d_name);
@ -270,19 +268,19 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
/*
* create/update corresponding dmmap section that have same config_section link and using param_value_array
*/
dmasprintf(&sysfs_rep_path, "%s/%s", sysfsrep, ent->d_name);
if ((dmmap_sect = get_dup_section_in_dmmap_opt(dmmap_package, dmmap_section, opt_name, sysfs_rep_path)) == NULL) {
dmasprintf(&sysfs_repo_path, "%s/%s", sysfsrep, ent->d_name);
if ((dmmap_sect = get_dup_section_in_dmmap_opt(dmmap_package, dmmap_section, opt_name, sysfs_repo_path)) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, dmmap_section, &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, opt_name, sysfs_rep_path);
dmuci_set_value_by_section_bbfdm(dmmap_sect, opt_name, sysfs_repo_path);
}
dmuci_get_value_by_section_string(dmmap_sect, inst_opt, &instance);
/*
* Add system and dmmap sections to the list
*/
if (instance == NULL || strlen(instance) <= 0)
add_sysfs_sectons_list_paramameter(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path);
add_sysfs_section_list(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_repo_path);
else
add_sysfs_sectons_list_paramameter(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path);
add_sysfs_section_list(dup_list, dmmap_sect, ent->d_name, sysfs_repo_path);
}
}
if (dir)
@ -293,12 +291,12 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
* fusion two lists
*/
list_for_each_entry(p, &dup_list_no_inst, list) {
add_sysfs_sectons_list_paramameter(dup_list, p->dm, p->sysfs_folder_name, p->sysfs_folder_path);
add_sysfs_section_list(dup_list, p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path);
}
/*
* Delete unused dmmap sections
*/
if(is_root){
if (is_root) {
uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_section, stmp, s) {
dmuci_get_value_by_section_string(s, opt_name, &v);
if (!folder_exists(v)) {
@ -323,17 +321,17 @@ static int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_n
list_for_each_entry(p, &dup_list, list) {
init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port);
init_usb_port(p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path, &port);
if (p->dm && prev_port->dmsect ) {
if (p->dmmap_section && prev_port->dmsect ) {
dmuci_get_value_by_section_string(prev_port->dmsect, "usb_host_instance", &parent_host_instance);
dmuci_set_value_by_section_bbfdm(p->dm, "usb_host_device_parent_host_instance", parent_host_instance);
dmuci_set_value_by_section_bbfdm(p->dmmap_section, "usb_host_device_parent_host_instance", parent_host_instance);
}
port.dmsect = prev_port->dmsect;
instance = handle_update_instance(2, dmctx, &instnbr, update_instance_alias, 3,
p->dm, "usb_host_device_instance", "usb_host_device_alias");
p->dmmap_section, "usb_host_device_instance", "usb_host_device_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
break;

View file

@ -709,9 +709,7 @@ char * os__get_default_wpa_key()
/**************************************************************************
* *** Device.WiFi.DataElements. *** *
***************************************************************************/
/*#Device.WiFi.DataElements.Network.ID!UBUS:wifi.dataelements.collector/dump//data[0].wfa-dataelements:Network.ID*/
int os__get_WiFiDataElementsNetwork_ID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int os__get_WiFiDataElementsNetwork_option(const char *option, char **value)
{
int i;
json_object *res, *data_arr = NULL, *data_obj = NULL, *net_obj = NULL;
@ -720,11 +718,17 @@ int os__get_WiFiDataElementsNetwork_ID(char *refparam, struct dmctx *ctx, void *
DM_ASSERT(res, *value = "");
dmjson_foreach_obj_in_array(res, data_arr, data_obj, i, 1, "data") {
json_object_object_get_ex(data_obj, "wfa-dataelements:Network", &net_obj);
*value = dmjson_get_value(net_obj, 1, "ID");
*value = dmjson_get_value(net_obj, 1, option);
}
return 0;
}
/*#Device.WiFi.DataElements.Network.ID!UBUS:wifi.dataelements.collector/dump//data[0].wfa-dataelements:Network.ID*/
int os__get_WiFiDataElementsNetwork_ID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return os__get_WiFiDataElementsNetwork_option("ID", value);
}
int os__set_WiFiDataElementsNetwork_ID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
@ -739,34 +743,16 @@ int os__set_WiFiDataElementsNetwork_ID(char *refparam, struct dmctx *ctx, void *
return 0;
}
/*#Device.WiFi.DataElements.Network.TimeStamp!UBUS:wifi.dataelements.collector/dump//description*/
/*#Device.WiFi.DataElements.Network.TimeStamp!UBUS:wifi.dataelements.collector/dump//data[0].wfa-dataelements:Network.TimeStamp*/
int os__get_WiFiDataElementsNetwork_TimeStamp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int i;
json_object *res, *data_arr = NULL, *data_obj = NULL, *net_obj = NULL;
dmubus_call("wifi.dataelements.collector", "dump", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "");
dmjson_foreach_obj_in_array(res, data_arr, data_obj, i, 1, "data") {
json_object_object_get_ex(data_obj, "wfa-dataelements:Network", &net_obj);
*value = dmjson_get_value(net_obj, 1, "TimeStamp");
}
return 0;
return os__get_WiFiDataElementsNetwork_option("TimeStamp", value);
}
/*#Device.WiFi.DataElements.Network.ControllerID!UBUS:wifi.dataelements.collector/dump//data[0].wfa-dataelements:Network.ControllerID*/
int os__get_WiFiDataElementsNetwork_ControllerID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int i;
json_object *res, *data_arr = NULL, *data_obj = NULL, *net_obj = NULL;
dmubus_call("wifi.dataelements.collector", "dump", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "");
dmjson_foreach_obj_in_array(res, data_arr, data_obj, i, 1, "data") {
json_object_object_get_ex(data_obj, "wfa-dataelements:Network", &net_obj);
*value = dmjson_get_value(net_obj, 1, "ControllerID");
}
return 0;
return os__get_WiFiDataElementsNetwork_option("ControllerID", value);
}
int os__set_WiFiDataElementsNetwork_ControllerID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)

View file

@ -13,7 +13,6 @@
*/
#include "dmentry.h"
#include "wepkey.h"
#include "wifi.h"
#include "os.h"
@ -851,6 +850,28 @@ static void reset_wlan(struct uci_section *s)
dmuci_delete_by_section(s, "auth_secret", NULL);
}
static void generate_wep_key(char *passphrase, char strk64[4][11])
{
unsigned char k64[4][5];
unsigned char pseed[4] = {0};
unsigned int randNumber, tmp;
int i, j;
for (i = 0; i < strlen(passphrase); i++)
pseed[i%4] ^= (unsigned char) passphrase[i];
randNumber = pseed[0] | (pseed[1] << 8) | (pseed[2] << 16) | (pseed[3] << 24);
for (i = 0; i < 4; i++) {
for (j = 0; j < 5; j++) {
randNumber = (randNumber * 0x343fd + 0x269ec3) & 0xffffffff;
tmp = (randNumber >> 16) & 0xff;
k64[i][j] = (unsigned char) tmp;
}
snprintf(strk64[i], sizeof(strk64[i]), "%02X%02X%02X%02X%02X", k64[i][0], k64[i][1], k64[i][2], k64[i][3], k64[i][4]);
}
}
static void set_security_mode(struct uci_section *section, char *value)
{
char *encryption, *mode;
@ -867,7 +888,7 @@ static void set_security_mode(struct uci_section *section, char *value)
reset_wlan(section);
dmuci_set_value_by_section(section, "encryption", "wep-open");
char *option, strk64[4][11];
wepkey64("iopsys", strk64);
generate_wep_key("iopsys", strk64);
int i;
for (i = 0; i < 4; i++) {
dmasprintf(&option, "key%d", i + 1);
@ -1793,7 +1814,7 @@ static int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, c
static int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL;
char *ssid_linker = NULL;
switch (action) {
case VALUECHECK:
@ -1801,10 +1822,10 @@ static int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, c
return FAULT_9007;
return 0;
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", linker);
dmfree(linker);
adm_entry_get_linker_value(ctx, value, &ssid_linker);
if (ssid_linker && *ssid_linker) {
dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", ssid_linker);
dmfree(ssid_linker);
}
return 0;
}
@ -1822,12 +1843,12 @@ static int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *
/*************************************************************
* ADD DEL OBJ
**************************************************************/
static int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instance)
static int add_wifi_iface(char *inst_name, char **instance)
{
struct uci_section *s = NULL, *dmmap_wifi = NULL;
char ssid[32] = {0};
char *inst = get_last_instance_bbfdm("dmmap_wireless", "wifi-iface", "ssidinstance");
char *inst = get_last_instance_bbfdm("dmmap_wireless", "wifi-iface", inst_name);
snprintf(ssid, sizeof(ssid), "iopsys_%d", inst ? (atoi(inst)+1) : 1);
dmuci_add_section("wireless", "wifi-iface", &s);
@ -1838,62 +1859,21 @@ static int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **i
dmuci_add_section_bbfdm("dmmap_wireless", "wifi-iface", &dmmap_wifi);
dmuci_set_value_by_section(dmmap_wifi, "section_name", section_name(s));
*instance = update_instance(inst, 2, dmmap_wifi, "ssidinstance");
*instance = update_instance(inst, 2, dmmap_wifi, inst_name);
return 0;
}
static int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
static int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
int found = 0;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_ssid_args *)data)->wifi_ssid_sec), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("wireless", "wifi-iface", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;
}
return 0;
return add_wifi_iface("ssidinstance", instance);
}
static int add_wifi_accesspoint(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_wifi = NULL;
char ssid[32] = {0};
char *inst = get_last_instance_bbfdm("dmmap_wireless", "wifi-iface", "ap_instance");
snprintf(ssid, sizeof(ssid), "iopsys_%d", inst ? (atoi(inst)+1) : 1);
dmuci_add_section("wireless", "wifi-iface", &s);
dmuci_set_value_by_section(s, "ssid", ssid);
dmuci_set_value_by_section(s, "network", "lan");
dmuci_set_value_by_section(s, "mode", "ap");
dmuci_set_value_by_section(s, "disabled", "0");
dmuci_add_section_bbfdm("dmmap_wireless", "wifi-iface", &dmmap_wifi);
dmuci_set_value_by_section(dmmap_wifi, "section_name", section_name(s));
*instance = update_instance(inst, 2, dmmap_wifi, "ap_instance");
return 0;
return add_wifi_iface("ap_instance", instance);
}
static int delete_wifi_accesspoint(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
static int delete_wifi_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
@ -2122,8 +2102,8 @@ DMOBJ tWiFiObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
{"DataElements", &DMREAD, NULL, NULL, NULL, NULL, NULL, tWiFiDataElementsObj, NULL, NULL, BBFDM_BOTH},
{"Radio", &DMREAD, NULL, NULL, NULL, browseWifiRadioInst, NULL, tWiFiRadioObj, tWiFiRadioParams, get_linker_Wifi_Radio, BBFDM_BOTH, LIST_KEY{"Name", "Alias", NULL}},
{"SSID", &DMWRITE, add_wifi_ssid, delete_wifi_ssid, NULL, browseWifiSsidInst, NULL, tWiFiSSIDObj, tWiFiSSIDParams, get_linker_Wifi_Ssid, BBFDM_BOTH, LIST_KEY{"Name", "Alias", "BSSID", NULL}},
{"AccessPoint", &DMWRITE, add_wifi_accesspoint, delete_wifi_accesspoint, NULL, browseWifiAccessPointInst, NULL, tWiFiAccessPointObj, tWiFiAccessPointParams, NULL, BBFDM_BOTH, LIST_KEY{"SSIDReference", "Alias", NULL}},
{"SSID", &DMWRITE, add_wifi_ssid, delete_wifi_iface, NULL, browseWifiSsidInst, NULL, tWiFiSSIDObj, tWiFiSSIDParams, get_linker_Wifi_Ssid, BBFDM_BOTH, LIST_KEY{"Name", "Alias", "BSSID", NULL}},
{"AccessPoint", &DMWRITE, add_wifi_accesspoint, delete_wifi_iface, NULL, browseWifiAccessPointInst, NULL, tWiFiAccessPointObj, tWiFiAccessPointParams, NULL, BBFDM_BOTH, LIST_KEY{"SSIDReference", "Alias", NULL}},
{"NeighboringWiFiDiagnostic", &DMREAD, NULL, NULL, NULL, NULL, NULL, tWiFiNeighboringWiFiDiagnosticObj, tWiFiNeighboringWiFiDiagnosticParams, NULL, BBFDM_BOTH},
{"EndPoint", &DMWRITE, addObjWiFiEndPoint, delObjWiFiEndPoint, NULL, browseWiFiEndPointInst, NULL, tWiFiEndPointObj, tWiFiEndPointParams, NULL, BBFDM_BOTH, LIST_KEY{"SSIDReference", "Alias", NULL}},
{0}

View file

@ -10,6 +10,7 @@
*/
#include "dmentry.h"
#include "ethernet.h"
#include "x_iopsys_eu_igmp.h"
static void get_mcast_iface_key(char *p_ifname, char *key, size_t key_size)
@ -63,7 +64,7 @@ static void sync_mcast_dmmap_iface_sec(struct uci_list *proxy_iface, char *s_mod
uci_path_foreach_option_eq(bbfdm, dmmap_package, dmmap_sec, "ifname", key, d_sec) {
dmuci_get_value_by_section_string(d_sec, "section_name", &s_name);
if (strcmp(s_name, section_name(s)) == 0) {
add_sectons_list_paramameter(dup_list, s, d_sec, NULL);
add_dmmap_config_dup_list(dup_list, s, d_sec, NULL);
found = 1;
break;
}
@ -76,7 +77,7 @@ static void sync_mcast_dmmap_iface_sec(struct uci_list *proxy_iface, char *s_mod
dmuci_set_value_by_section_bbfdm(d_sec, "ifname", key);
dmuci_set_value_by_section_bbfdm(d_sec, "upstream", up_iface);
dmuci_set_value_by_section_bbfdm(d_sec, "snooping_mode", s_mode);
add_sectons_list_paramameter(dup_list, s, d_sec, NULL);
add_dmmap_config_dup_list(dup_list, s, d_sec, NULL);
}
}
}
@ -91,7 +92,7 @@ static void add_empty_mcast_iface_to_list(char *dmmap_package, char *dmmap_sec,
dmuci_get_value_by_section_string(dmmap_sect, "ifname", &f_ifname);
if (strcmp(f_ifname, "") == 0)
add_sectons_list_paramameter(dup_list, s, dmmap_sect, NULL);
add_dmmap_config_dup_list(dup_list, s, dmmap_sect, NULL);
}
}
@ -162,7 +163,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package,
uci_path_foreach_option_eq(bbfdm, dmmap_package, dmmap_sec, "ipaddr", ip_addr, d_sec) {
dmuci_get_value_by_section_string(d_sec, "section_name", &s_name);
if (strcmp(s_name, section_name(s)) == 0) {
add_sectons_list_paramameter(dup_list, s, d_sec, NULL);
add_dmmap_config_dup_list(dup_list, s, d_sec, NULL);
found = 1;
break;
}
@ -174,7 +175,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package,
dmuci_set_value_by_section_bbfdm(d_sec, "section_name", section_name(s));
dmuci_set_value_by_section_bbfdm(d_sec, "ipaddr", ip_addr);
dmuci_set_value_by_section_bbfdm(d_sec, "enable", "1");
add_sectons_list_paramameter(dup_list, s, d_sec, NULL);
add_dmmap_config_dup_list(dup_list, s, d_sec, NULL);
}
}
}
@ -187,7 +188,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package,
dmuci_get_value_by_section_string(dmmap_sect, "enable", &f_enable);
if ((f_ip[0] == '\0') || (strcmp(f_enable, "0") == 0))
add_sectons_list_paramameter(dup_list, s, dmmap_sect, NULL);
add_dmmap_config_dup_list(dup_list, s, dmmap_sect, NULL);
}
}
@ -262,6 +263,48 @@ int get_mcast_snooping_interface_val(char *value, char *ifname, size_t s_ifname)
return 0;
}
int del_proxy_obj(void *data, char *proto, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
switch (del_action) {
case DEL_INST:
// first delete all filter child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_filter", "section_name", section_name((struct uci_section *)data));
// Now delete all interface child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data));
// Now delete the proxy node
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name((struct uci_section *)data), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq("mcast", "proxy", "proto", proto, s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(s), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
}
static int add_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap = NULL, *s = NULL;
@ -292,47 +335,7 @@ static int add_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, cha
static int del_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
switch (del_action) {
case DEL_INST:
// first delete all filter child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_filter",
"section_name", section_name((struct uci_section *)data));
// Now delete all interface child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data));
// Now delete the proxy node
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq("mcast", "proxy", "proto", "igmp", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(s), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
return del_proxy_obj(data, "igmp", del_action);
}
static int browse_igmp_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
@ -388,7 +391,7 @@ static int add_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data,
return 0;
}
static int del_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
int del_snooping_obj(void *data, char *proto, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
@ -396,20 +399,18 @@ static int del_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data,
switch (del_action) {
case DEL_INST:
// first delete all filter child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter",
"section_name", section_name((struct uci_section *)data));
// Now delete all interface child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_interface",
"section_name", section_name((struct uci_section *)data));
get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name((struct uci_section *)data), &dmmap_section);
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data));
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
// Now delete all interface child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_interface", "section_name", section_name((struct uci_section *)data));
get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name((struct uci_section *)data), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq("mcast", "snooping", "proto", "igmp", s) {
uci_foreach_option_eq("mcast", "snooping", "proto", proto, s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name(s), &dmmap_section);
if (dmmap_section != NULL)
@ -431,6 +432,11 @@ static int del_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data,
return 0;
}
static int del_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
return del_snooping_obj(data, "igmp", del_action);
}
static int browse_igmp_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
@ -550,28 +556,25 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i
"section_name", section_name((struct uci_section *)data), d_sec) {
dmuci_get_value_by_section_string(d_sec, "ipaddr", &ip_addr);
if (ip_addr[0] != '\0') {
dmuci_del_list_value_by_section((struct uci_section *)data,
"filter", ip_addr);
dmuci_del_list_value_by_section((struct uci_section *)data, "filter", ip_addr);
}
}
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter",
"section_name", section_name((struct uci_section *)data));
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data));
break;
}
return 0;
}
static int browse_igmps_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
int browse_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *section_type, char *option_name, char *option_value)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_filter("mcast", "snooping", prev_data,
"dmmap_mcast", "snooping_filter", "igmp", &dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_filter("mcast", section_type, prev_data, "dmmap_mcast", option_name, option_value, &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (!p->config_section)
break;
@ -591,6 +594,11 @@ static int browse_igmps_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, vo
return 0;
}
static int browse_igmps_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
return browse_filter_inst(dmctx, parent_node, prev_data, "snooping", "snooping_filter", "igmp");
}
int get_mcasts_filter_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
@ -754,7 +762,7 @@ int set_mcast_snooping_enable(char *refparam, struct dmctx *ctx, void *data, cha
return 0;
}
static int get_igmp_snooping_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int get_igmp_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val);
@ -762,7 +770,7 @@ static int get_igmp_snooping_version(char *refparam, struct dmctx *ctx, void *da
return 0;
}
static int set_igmp_snooping_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
static int set_igmp_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
@ -877,39 +885,19 @@ int get_mcast_snooping_interface(char *refparam, struct dmctx *ctx, void *data,
strncpy(val, val1, sizeof(val) - 1);
tok = strtok_r(val, "-", &end);
if ((tok == NULL) || (end == NULL)) {
if ((tok == NULL) || (end == NULL))
return 0;
}
if (strcmp(tok, "br") != 0) {
if (strcmp(tok, "br") != 0)
return 0;
}
strncpy(sec_name, end, sizeof(sec_name) - 1);
// In the dmmap_network file, the details related to the instance id etc. associated with this bridge
// is stored, we now switch our focus to it to extract the necessary information.
struct uci_section *dmmap_section, *port;
get_dmmap_section_of_config_section("dmmap_network", "interface", sec_name, &dmmap_section);
if (dmmap_section != NULL) {
char *br_inst, *mg;
dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", br_inst, port) {
dmuci_get_value_by_section_string(port, "management", &mg);
if (strcmp(mg, "1") == 0) {
char *device, linker[512] = "";
dmuci_get_value_by_section_string(port, "device", &device);
snprintf(linker, sizeof(linker), "br_%s:%s+%s", br_inst, section_name(port), device);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot,
dm_delim, dm_delim, dm_delim), linker, value);
break;
}
}
}
get_bridge_port_linker(ctx, sec_name, value);
if (*value == NULL)
*value = "";
return 0;
}
@ -984,20 +972,20 @@ static void del_igmpp_iface_val(char *upstream, void *data, char *pch)
static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *d_sec = NULL;
char *f_inst, *if_name, *upstream;
int found = 0;
struct uci_section *igmpp_s = NULL;
switch (del_action) {
case DEL_INST:
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data), d_sec) {
dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), igmpp_s) {
char *f_inst = NULL, *if_name = NULL, *upstream = NULL;
int found = 0;
dmuci_get_value_by_section_string(igmpp_s, "iface_instance", &f_inst);
if (strcmp(instance, f_inst) == 0) {
dmuci_get_value_by_section_string(d_sec, "ifname", &if_name);
dmuci_get_value_by_section_string(d_sec, "upstream", &upstream);
dmuci_delete_by_section(d_sec, NULL, NULL);
dmuci_get_value_by_section_string(igmpp_s, "ifname", &if_name);
dmuci_get_value_by_section_string(igmpp_s, "upstream", &upstream);
dmuci_delete_by_section(igmpp_s, NULL, NULL);
found = 1;
} else {
continue;
@ -1007,23 +995,24 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data
char key[1024];
get_igmpp_iface_del_key_val(key, sizeof(key), if_name);
char *pch, *spch;
char *pch = NULL, *spch = NULL;
pch = strtok_r(key, " ", &spch);
while (pch != NULL) {
del_igmpp_iface_val(upstream, data, pch);
pch = strtok_r(NULL, " ", &spch);
}
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface",
"ifname", if_name);
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "ifname", if_name);
break;
}
}
break;
case DEL_ALL:
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data), d_sec) {
dmuci_get_value_by_section_string(d_sec, "ifname", &if_name);
dmuci_get_value_by_section_string(d_sec, "upstream", &upstream);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), igmpp_s) {
char *if_name = NULL, *upstream = NULL;
dmuci_get_value_by_section_string(igmpp_s, "ifname", &if_name);
dmuci_get_value_by_section_string(igmpp_s, "upstream", &upstream);
if (if_name[0] != '\0') {
char key[1024];
get_igmpp_iface_del_key_val(key, sizeof(key), if_name);
@ -1037,23 +1026,21 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data
}
}
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data));
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data));
break;
}
return 0;
}
static int browse_igmpp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
int browse_proxy_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *proto)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_iface("mcast", "proxy", prev_data,
"dmmap_mcast", "proxy_interface", "igmp", &dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_iface("mcast", "proxy", prev_data, "dmmap_mcast", "proxy_interface", proto, &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (!p->config_section)
break;
@ -1067,13 +1054,17 @@ static int browse_igmpp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node,
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
static int browse_igmpp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
return browse_proxy_interface_inst(dmctx, parent_node, prev_data, "igmp");
}
static int add_igmpp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_igmpp_filter = NULL;
@ -1141,30 +1132,7 @@ int del_mcastp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i
static int browse_igmpp_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_filter("mcast", "proxy", prev_data,
"dmmap_mcast", "proxy_filter", "igmp", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (!p->config_section)
break;
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)prev_data);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "filter_instance", "filter_alias",
check_browse_section, (void *)&browse_args);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browse_filter_inst(dmctx, parent_node, prev_data, "proxy", "proxy_filter", "igmp");
}
int get_mcastp_interface_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
@ -1251,7 +1219,7 @@ int get_mcastp_filter_address(char *refparam, struct dmctx *ctx, void *data, cha
static int set_igmpp_filter_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s = NULL;
struct uci_section *igmp_s = NULL;
char *s_inst, *up;
bool b;
@ -1259,18 +1227,15 @@ static int set_igmpp_filter_address(char *refparam, struct dmctx *ctx, void *dat
case VALUECHECK:
if (dm_validate_string(value, -1, 15, NULL, 0, IPv4Address, 1))
return FAULT_9007;
break;
case VALUESET:
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter",
"section_name", section_name((struct uci_section *)data), s) {
dmuci_get_value_by_section_string(s, "filter_instance", &s_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", "section_name", section_name((struct uci_section *)data), igmp_s) {
dmuci_get_value_by_section_string(igmp_s, "filter_instance", &s_inst);
if (strcmp(s_inst, instance) == 0) {
dmuci_set_value_by_section(s, "ipaddr", value);
dmuci_get_value_by_section_string(s, "enable", &up);
dmuci_set_value_by_section(igmp_s, "ipaddr", value);
dmuci_get_value_by_section_string(igmp_s, "enable", &up);
string_to_bool(up, &b);
sync_dmmap_bool_to_uci_list((struct uci_section *)data,
"filter", value, b);
sync_dmmap_bool_to_uci_list((struct uci_section *)data, "filter", value, b);
break;
}
}
@ -1451,29 +1416,6 @@ int set_mcast_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *
return 0;
}
static int get_igmp_proxy_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val);
*value = (strcmp(val, "2") == 0) ? "V2" : "V3";
return 0;
}
static int set_igmp_proxy_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if ((strcmp("V2", value) != 0) && (strcmp("V3", value) != 0))
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "version", (strcmp(value, "V2") == 0) ? "2" : "3");
break;
}
return 0;
}
int get_mcast_proxy_robustness(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "robustness", "0");
@ -1785,82 +1727,61 @@ static int set_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da
static int get_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *d_sec, *s;
char *ifname, *f_inst;
struct uci_section *igmpp_s = NULL;
char *igmpp_ifname, *f_inst;
char sec_name[16] = {0};
int found = 0;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data), d_sec) {
dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), igmpp_s) {
dmuci_get_value_by_section_string(igmpp_s, "iface_instance", &f_inst);
if (strcmp(instance, f_inst) == 0) {
dmuci_get_value_by_section_string(d_sec, "ifname", &ifname);
dmuci_get_value_by_section_string(igmpp_s, "ifname", &igmpp_ifname);
found = 1;
break;
}
}
if ((found == 0) || (ifname[0] == '\0')) {
if ((found == 0) || (igmpp_ifname[0] == '\0')) {
*value = "";
return 0;
}
// Check if this is bridge type interface
if (strstr(ifname, "br-")) {
if (strstr(igmpp_ifname, "br-")) {
// Interface is bridge type, convert to network uci file section name
char val[16] = {0};
strncpy(val, ifname, sizeof(val) - 1);
char *tok, *end;
tok = strtok_r(val, "-", &end);
if (strcmp(tok, "br") == 0) {
strncpy(val, igmpp_ifname, sizeof(val) - 1);
char *token, *end;
token = strtok_r(val, "-", &end);
if (strcmp(token, "br") == 0) {
strncpy(sec_name, end, sizeof(sec_name) - 1);
} else {
goto end;
}
char *proto;
uci_foreach_sections("network", "interface", s) {
if(strcmp(section_name(s), sec_name) != 0)
struct uci_section *interface_s = NULL;
uci_foreach_sections("network", "interface", interface_s) {
if(strcmp(section_name(interface_s), sec_name) != 0)
continue;
dmuci_get_value_by_section_string(s, "proto", &proto);
if (proto[0] != '\0') {
char *proto = NULL;
dmuci_get_value_by_section_string(interface_s, "proto", &proto);
if (proto && proto[0] != '\0') {
// It is a L3 bridge, get the linker accordingly
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c",
dmroot, dm_delim, dm_delim, dm_delim), sec_name, value);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), sec_name, value);
} else {
// It is a L2 bridge, get the linker accordingly
struct uci_section *dmmap_section, *port;
char *br_inst, *mg, linker[64] = "";
get_dmmap_section_of_config_section("dmmap_network", "interface", sec_name,
&dmmap_section);
if (dmmap_section != NULL) {
dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port",
"bridge_port", "bridge_key", br_inst, port) {
dmuci_get_value_by_section_string(port, "mg_port", &mg);
if (strcmp(mg, "true") == 0)
snprintf(linker, sizeof(linker), "%s+", section_name(port));
else
continue;
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot,
dm_delim, dm_delim, dm_delim), linker, value);
break;
}
}
get_bridge_port_linker(ctx, sec_name, value);
}
break;
}
} else {
// in case its a L3 interface, the ifname would be section name of network file in the dmmap file,
// which infact is the linker, just use that directly.
if (ifname == NULL)
if (igmpp_ifname == NULL)
goto end;
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim,
dm_delim, dm_delim), ifname, value);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), igmpp_ifname, value);
}
end:
@ -2064,7 +1985,7 @@ DMLEAF IGMPSnoopingClientGroupStatsParams[] = {
DMLEAF X_IOPSYS_EU_IGMPSnoopingParams[] = {
{"Enable", &DMWRITE, DMT_BOOL, get_mcast_snooping_enable, set_mcast_snooping_enable, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_igmp_snooping_version, set_igmp_snooping_version, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_igmp_version, set_igmp_version, BBFDM_BOTH},
{"Robustness", &DMWRITE, DMT_UNINT, get_mcast_snooping_robustness, set_mcast_snooping_robustness, BBFDM_BOTH},
{"Aggregation", &DMWRITE, DMT_BOOL, get_mcast_snooping_aggregation, set_mcast_snooping_aggregation, BBFDM_BOTH},
{"Interface", &DMWRITE, DMT_STRING, get_mcast_snooping_interface, set_mcast_snooping_interface, BBFDM_BOTH},
@ -2125,7 +2046,7 @@ DMLEAF IGMPProxyInterfaceParams[] = {
DMLEAF X_IOPSYS_EU_IGMPProxyParams[] = {
{"Enable", &DMWRITE, DMT_BOOL, get_mcast_proxy_enable, set_mcast_proxy_enable, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_igmp_proxy_version, set_igmp_proxy_version, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_igmp_version, set_igmp_version, BBFDM_BOTH},
{"QueryInterval", &DMWRITE, DMT_UNINT, get_mcastp_query_interval, set_mcastp_query_interval, BBFDM_BOTH},
{"QueryResponseInterval", &DMWRITE, DMT_UNINT, get_mcastp_q_response_interval, set_mcastp_q_response_interval, BBFDM_BOTH},
{"LastMemberQueryInterval", &DMWRITE, DMT_UNINT, get_mcastp_last_mq_interval, set_mcastp_last_mq_interval, BBFDM_BOTH},

View file

@ -78,6 +78,11 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i
void update_snooping_mode(struct uci_section *s);
int get_mcast_snooping_interface_val(char *value, char *ifname, size_t s_ifname);
int del_proxy_obj(void *data, char *proto, unsigned char del_action);
int del_snooping_obj(void *data, char *proto, unsigned char del_action);
int browse_proxy_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *proto);
int browse_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *section_type,
char *option_name, char *option_value);
void synchronize_specific_config_sections_with_dmmap_mcast_iface(char *package, char *section_type,
void *data, char *dmmap_package, char *dmmap_sec, char *proto,
struct list_head *dup_list);

View file

@ -10,6 +10,7 @@
*/
#include "dmentry.h"
#include "ethernet.h"
#include "x_iopsys_eu_mld.h"
#include "x_iopsys_eu_igmp.h"
@ -42,47 +43,7 @@ static int add_mld_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char
static int del_mld_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
switch (del_action) {
case DEL_INST:
// first delete all filter child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_filter",
"section_name", section_name((struct uci_section *)data));
// Now delete all interface child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data));
// Now delete the proxy node
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq("mcast", "proxy", "proto", "mld", s) {
if (found != 0){
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(s), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
return del_proxy_obj(data, "mld", del_action);
}
static int browse_mld_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
@ -139,45 +100,7 @@ static int add_mld_snooping_obj(char *refparam, struct dmctx *ctx, void *data, c
static int del_mld_snooping_obj(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
switch (del_action) {
case DEL_INST:
// first delete all filter child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter",
"section_name", section_name((struct uci_section *)data));
// Now delete all interface child nodes related to this object
del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_interface",
"section_name", section_name((struct uci_section *)data));
get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq("mcast", "snooping", "proto", "mld", s) {
if (found != 0){
get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name(s), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
return del_snooping_obj(data, "mld", del_action);
}
static int browse_mld_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
@ -266,33 +189,10 @@ static int add_mlds_filter_obj(char *refparam, struct dmctx *ctx, void *data, ch
static int browse_mlds_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_filter("mcast", "snooping", prev_data,
"dmmap_mcast", "snooping_filter", "mld", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (!p->config_section)
break;
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)prev_data);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "filter_instance", "filter_alias",
check_browse_section, (void *)&browse_args);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browse_filter_inst(dmctx, parent_node, prev_data, "snooping", "snooping_filter", "mld");
}
static int get_mld_snooping_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
static int get_mld_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val);
@ -300,7 +200,7 @@ static int get_mld_snooping_version(char *refparam, struct dmctx *ctx, void *dat
return 0;
}
static int set_mld_snooping_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
static int set_mld_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
@ -338,50 +238,49 @@ static int add_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data,
static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *d_sec = NULL;
char *f_inst, *if_name, *upstream;
int found = 0;
struct uci_section *mldp_s = NULL;
switch (del_action) {
case DEL_INST:
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data), d_sec) {
dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), mldp_s) {
char *f_inst = NULL, *if_name = NULL, *upstream = NULL;
int found = 0;
if (strcmp(instance, f_inst) == 0) {
dmuci_get_value_by_section_string(d_sec, "ifname", &if_name);
dmuci_get_value_by_section_string(d_sec, "upstream", &upstream);
dmuci_delete_by_section(d_sec, NULL, NULL);
dmuci_get_value_by_section_string(mldp_s, "iface_instance", &f_inst);
if (f_inst && strcmp(instance, f_inst) == 0) {
dmuci_get_value_by_section_string(mldp_s, "ifname", &if_name);
dmuci_get_value_by_section_string(mldp_s, "upstream", &upstream);
dmuci_delete_by_section(mldp_s, NULL, NULL);
found = 1;
}
if (found) {
if (strcmp(upstream, "1") == 0) {
if (upstream && strcmp(upstream, "1") == 0)
dmuci_del_list_value_by_section((struct uci_section *)data, "upstream_interface", if_name);
} else {
else
dmuci_del_list_value_by_section((struct uci_section *)data, "downstream_interface", if_name);
}
break;
}
}
break;
case DEL_ALL:
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data), d_sec) {
dmuci_get_value_by_section_string(d_sec, "ifname", &if_name);
dmuci_get_value_by_section_string(d_sec, "upstream", &upstream);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), mldp_s) {
char *if_name = NULL, *upstream = NULL;
dmuci_get_value_by_section_string(mldp_s, "ifname", &if_name);
dmuci_get_value_by_section_string(mldp_s, "upstream", &upstream);
if (if_name[0] != '\0') {
if (strcmp(upstream, "1") == 0) {
if (strcmp(upstream, "1") == 0)
dmuci_del_list_value_by_section((struct uci_section *)data, "upstream_interface", if_name);
} else {
else
dmuci_del_list_value_by_section((struct uci_section *)data, "downstream_interface", if_name);
}
}
}
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data));
del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data));
break;
}
@ -390,30 +289,7 @@ static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data,
static int browse_mldp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_iface("mcast", "proxy", prev_data,
"dmmap_mcast", "proxy_interface", "mld", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (!p->config_section)
break;
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)prev_data);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "iface_instance", "iface_alias",
check_browse_section, (void *)&browse_args);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browse_proxy_interface_inst(dmctx, parent_node, prev_data, "mld");
}
static int add_mldp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
@ -421,8 +297,7 @@ static int add_mldp_filter_obj(char *refparam, struct dmctx *ctx, void *data, ch
struct uci_section *dmmap_mldp_filter = NULL;
struct browse_args browse_args = {0};
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy_filter", "filter_instance",
"section_name", section_name((struct uci_section *)data));
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy_filter", "filter_instance", "section_name", section_name((struct uci_section *)data));
dmuci_add_section_bbfdm("dmmap_mcast", "proxy_filter", &dmmap_mldp_filter);
dmuci_set_value_by_section(dmmap_mldp_filter, "section_name", section_name((struct uci_section *)data));
@ -438,30 +313,7 @@ static int add_mldp_filter_obj(char *refparam, struct dmctx *ctx, void *data, ch
static int browse_mldp_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_filter("mcast", "proxy", prev_data,
"dmmap_mcast", "proxy_filter", "mld", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (!p->config_section)
break;
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)prev_data);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "filter_instance", "filter_alias",
check_browse_section, (void *)&browse_args);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
return browse_filter_inst(dmctx, parent_node, prev_data, "proxy", "proxy_filter", "mld");
}
static int set_mldp_filter_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -626,29 +478,6 @@ static int get_mldp_cgrp_stats_lrcvd(char *refparam, struct dmctx *ctx, void *da
}
#endif
static int get_mld_proxy_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val);
*value = (strcmp(val, "2") == 0) ? "V2" : "V1";
return 0;
}
static int set_mld_proxy_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if ((strcmp("V2", value) != 0) && (strcmp("V1", value) != 0))
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "version", (strcmp(value, "V2") == 0) ? "2" : "1");
break;
}
return 0;
}
static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL, *interface_linker = NULL;
@ -706,31 +535,30 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat
static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *d_sec, *s;
char *ifname, *f_inst;
struct uci_section *mldp_s = NULL;
char *mldp_ifname, *f_inst;
char sec_name[16] = {0};
int found = 0;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
"section_name", section_name((struct uci_section *)data), d_sec) {
dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), mldp_s) {
dmuci_get_value_by_section_string(mldp_s, "iface_instance", &f_inst);
if (strcmp(instance, f_inst) == 0) {
dmuci_get_value_by_section_string(d_sec, "ifname", &ifname);
dmuci_get_value_by_section_string(mldp_s, "ifname", &mldp_ifname);
found = 1;
break;
}
}
if ((found == 0) || (ifname[0] == '\0')) {
if ((found == 0) || (mldp_ifname[0] == '\0')) {
*value = "";
return 0;
}
// Check if this is bridge type interface
if (strstr(ifname, "br-")) {
if (strstr(mldp_ifname, "br-")) {
// Interface is bridge type, convert to network uci file section name
char val[16] = {0};
strncpy(val, ifname, sizeof(val) - 1);
strncpy(val, mldp_ifname, sizeof(val) - 1);
char *tok, *end;
tok = strtok_r(val, "-", &end);
if (strcmp(tok, "br") == 0) {
@ -739,48 +567,30 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat
goto end;
}
char *proto;
uci_foreach_sections("network", "interface", s) {
if(strcmp(section_name(s), sec_name) != 0)
struct uci_section *intf_s = NULL;
uci_foreach_sections("network", "interface", intf_s) {
if(strcmp(section_name(intf_s), sec_name) != 0)
continue;
dmuci_get_value_by_section_string(s, "proto", &proto);
if (proto[0] != '\0') {
char *proto = NULL;
dmuci_get_value_by_section_string(intf_s, "proto", &proto);
if (proto && proto[0] != '\0') {
// It is a L3 bridge, get the linker accordingly
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c",
dmroot, dm_delim, dm_delim, dm_delim), sec_name, value);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), sec_name, value);
} else {
// It is a L2 bridge, get the linker accordingly
struct uci_section *dmmap_section, *port;
char *br_inst, *mg, linker[64] = "";
get_dmmap_section_of_config_section("dmmap_network", "interface", sec_name,
&dmmap_section);
if (dmmap_section != NULL) {
dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port",
"bridge_port", "bridge_key", br_inst, port) {
dmuci_get_value_by_section_string(port, "mg_port", &mg);
if (strcmp(mg, "true") == 0)
snprintf(linker, sizeof(linker), "%s+", section_name(port));
else
continue;
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot,
dm_delim, dm_delim, dm_delim), linker, value);
break;
}
}
get_bridge_port_linker(ctx, sec_name, value);
}
break;
}
} else {
char *device_name, *tmp_linker = NULL;
// it is a L3 interface, get the section name from device name to construct the linker
uci_foreach_sections("network", "interface", s) {
dmuci_get_value_by_section_string(s, "ifname", &device_name);
if (strcmp(device_name, ifname) == 0) {
tmp_linker = dmstrdup(section_name(s));
struct uci_section *intf_s = NULL;
uci_foreach_sections("network", "interface", intf_s) {
dmuci_get_value_by_section_string(intf_s, "ifname", &device_name);
if (strcmp(device_name, mldp_ifname) == 0) {
tmp_linker = dmstrdup(section_name(intf_s));
break;
}
}
@ -788,8 +598,7 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat
if (tmp_linker == NULL)
goto end;
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim,
dm_delim, dm_delim), tmp_linker, value);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), tmp_linker, value);
}
end:
@ -887,7 +696,7 @@ DMLEAF MLDSnoopingClientGroupStatsParams[] = {
DMLEAF X_IOPSYS_EU_MLDSnoopingParams[] = {
{"Enable", &DMWRITE, DMT_BOOL, get_mcast_snooping_enable, set_mcast_snooping_enable, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_mld_snooping_version, set_mld_snooping_version, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_mld_version, set_mld_version, BBFDM_BOTH},
{"Robustness", &DMWRITE, DMT_UNINT, get_mcast_snooping_robustness, set_mcast_snooping_robustness, BBFDM_BOTH},
{"Aggregation", &DMWRITE, DMT_BOOL, get_mcast_snooping_aggregation, set_mcast_snooping_aggregation, BBFDM_BOTH},
{"Interface", &DMWRITE, DMT_STRING, get_mcast_snooping_interface, set_mcast_snooping_interface, BBFDM_BOTH},
@ -947,7 +756,7 @@ DMLEAF MLDProxyInterfaceParams[] = {
DMLEAF X_IOPSYS_EU_MLDProxyParams[] = {
{"Enable", &DMWRITE, DMT_BOOL, get_mcast_proxy_enable, set_mcast_proxy_enable, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_mld_proxy_version, set_mld_proxy_version, BBFDM_BOTH},
{"Version", &DMWRITE, DMT_STRING, get_mld_version, set_mld_version, BBFDM_BOTH},
{"QueryInterval", &DMWRITE, DMT_UNINT, get_mcastp_query_interval, set_mcastp_query_interval, BBFDM_BOTH},
{"QueryResponseInterval", &DMWRITE, DMT_UNINT, get_mcastp_q_response_interval, set_mcastp_q_response_interval, BBFDM_BOTH},
{"LastMemberQueryInterval", &DMWRITE, DMT_UNINT, get_mcastp_last_mq_interval, set_mcastp_last_mq_interval, BBFDM_BOTH},

View file

@ -49,7 +49,6 @@ static int mparam_set_notification_in_obj(DMPARAM_ARGS);
static int mobj_set_notification_in_param(DMOBJECT_ARGS);
static int mparam_set_notification_in_param(DMPARAM_ARGS);
static int mobj_set_notification_in_obj(DMOBJECT_ARGS);
static int dm_browse_schema(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance);
#ifdef BBF_TR064
static int mparam_upnp_get_instances(DMPARAM_ARGS);
static int mobj_upnp_get_instances(DMOBJECT_ARGS);
@ -110,11 +109,11 @@ struct notification notifications[] = {
};
struct dm_parameter forced_notifications_parameters[] = {
{.name = "Device.DeviceInfo.SoftwareVersion", .notification = "2"},
{.name = "Device.DeviceInfo.ProvisioningCode", .notification = "2"},
{.name = "Device.ManagementServer.ConnectionRequestURL", .notification = "2"},
{.name = "Device.ManagementServer.ConnReqJabberID", .notification = "2"},
{.name = "Device.SoftwareModules.ExecutionUnit.*.Status", .notification = "2"}
{.name = "Device.DeviceInfo.SoftwareVersion", .notification = "2"},
{.name = "Device.DeviceInfo.ProvisioningCode", .notification = "2"},
{.name = "Device.ManagementServer.ConnectionRequestURL", .notification = "2"},
{.name = "Device.ManagementServer.ConnReqJabberID", .notification = "2"},
{.name = "Device.SoftwareModules.ExecutionUnit.*.Status", .notification = "2"}
};
struct dm_acl dm_acl[] = {
@ -130,15 +129,25 @@ struct dm_acl dm_acl[] = {
};
char *DMT_TYPE[] = {
[DMT_STRING] = "xsd:string",
[DMT_UNINT] = "xsd:unsignedInt",
[DMT_INT] = "xsd:int",
[DMT_UNLONG] = "xsd:unsignedLong",
[DMT_LONG] = "xsd:long",
[DMT_BOOL] = "xsd:boolean",
[DMT_TIME] = "xsd:dateTime",
[DMT_HEXBIN] = "xsd:hexBinary",
[DMT_BASE64] = "xsd:base64",
[DMT_STRING] = "xsd:string",
[DMT_UNINT] = "xsd:unsignedInt",
[DMT_INT] = "xsd:int",
[DMT_UNLONG] = "xsd:unsignedLong",
[DMT_LONG] = "xsd:long",
[DMT_BOOL] = "xsd:boolean",
[DMT_TIME] = "xsd:dateTime",
[DMT_HEXBIN] = "xsd:hexBinary",
[DMT_BASE64] = "xsd:base64",
};
char *array_notifcation_char[__MAX_notification] = {
[notification_none] = "0",
[notification_passive] = "1",
[notification_active] = "2",
[notification_passive_lw] = "3",
[notification_ppassive_passive_lw] = "4",
[notification_aactive_lw] = "5",
[notification_passive_active_lw] = "6",
};
#ifdef BBF_TR064
@ -223,6 +232,23 @@ static int plugin_leaf_nextlevel_match(DMOBJECT_ARGS)
return FAULT_9005;
}
static int plugin_dynamic_obj_match(struct dmctx *dmctx, struct dmnode *node, char *entry_obj, char *full_obj)
{
if (node->matched)
return 0;
if (!dmctx->inparam_isparam && strstr(node->current_object, full_obj) == node->current_object) {
node->matched++;
dmctx->findparam = 1;
return 0;
}
if (strstr(full_obj, node->current_object) == full_obj)
return 0;
return FAULT_9005;
}
static int bbfdatamodel_matches(const enum bbfdm_type_enum type)
{
return bbfdatamodel_type == BBFDM_BOTH || type == BBFDM_BOTH || bbfdatamodel_type == type;
@ -282,7 +308,6 @@ static void dm_browse_entry(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *ent
node.parent = parent_node;
node.instance_level = parent_node->instance_level;
node.matched = parent_node->matched;
dmasprintf(&(node.current_object), "%s%s%c", parent_obj, entryobj->obj, dm_delim);
if (!bbfdatamodel_matches(entryobj->bbfdm_type))
return;
@ -290,22 +315,28 @@ static void dm_browse_entry(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *ent
if (entryobj->checkdep && (check_dependency(entryobj->checkdep) == false))
return;
if (entryobj->browseinstobj && dmctx->isgetschema)
dmasprintf(&(node.current_object), "%s%s%c{i}%c", parent_obj, entryobj->obj, dm_delim, dm_delim);
else
dmasprintf(&(node.current_object), "%s%s%c", parent_obj, entryobj->obj, dm_delim);
if (dmctx->checkobj) {
*err = dmctx->checkobj(dmctx, &node, entryobj->permission, entryobj->addobj, entryobj->delobj, entryobj->get_linker, data, instance);
if (*err)
return;
}
*err = dmctx->method_obj(dmctx, &node, entryobj->permission, entryobj->addobj, entryobj->delobj, entryobj->get_linker, data, instance);
if (dmctx->stop)
return;
if ((entryobj->browseinstobj && dmctx->isgetschema) || !dmctx->isgetschema) {
*err = dmctx->method_obj(dmctx, &node, entryobj->permission, entryobj->addobj, entryobj->delobj, entryobj->get_linker, data, instance);
if (dmctx->stop)
return;
}
if (entryobj->browseinstobj) {
if (entryobj->browseinstobj && !dmctx->isgetschema) {
if (dmctx->instance_wildchar) {
dm_link_inst_obj(dmctx, &node, data, dmctx->instance_wildchar);
return;
}
else {
} else {
entryobj->browseinstobj(dmctx, &node, data, instance);
*err = dmctx->faultcode;
return;
@ -327,12 +358,11 @@ static void dm_browse_entry(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *ent
}
}
if (entryobj->nextobj || entryobj->nextdynamicobj) {
if (entryobj->nextobj || entryobj->nextdynamicobj)
*err = dm_browse(dmctx, &node, entryobj->nextobj, data, instance);
}
}
int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance)
static int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance)
{
DMOBJ *jentryobj;
struct dm_dynamic_obj *next_dyn_array;
@ -369,76 +399,6 @@ int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *d
return err;
}
static void dm_browse_schema_entry(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance, char *parent_obj, int *err)
{
DMNODE node = {0};
node.obj = entryobj;
node.parent = parent_node;
node.instance_level = parent_node->instance_level;
node.matched = parent_node->matched;
if (!bbfdatamodel_matches(entryobj->bbfdm_type))
return;
if (entryobj->checkdep && (check_dependency(entryobj->checkdep) == false))
return;
if (entryobj->browseinstobj) {
dmasprintf(&(node.current_object), "%s%s%c{i}%c", parent_obj, entryobj->obj, dm_delim, dm_delim);
if (dmctx->method_obj) {
*err = dmctx->method_obj(dmctx, &node, entryobj->permission,
entryobj->addobj, entryobj->delobj,
entryobj->get_linker,
data, instance);
}
} else {
dmasprintf(&(node.current_object), "%s%s%c", parent_obj, entryobj->obj, dm_delim);
}
if (entryobj->leaf)
*err = dm_browse_leaf(dmctx, &node, entryobj->leaf, data, instance);
if (entryobj->nextobj || entryobj->nextdynamicobj)
*err = dm_browse_schema(dmctx, &node, entryobj->nextobj, data, instance);
}
static int dm_browse_schema(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance)
{
DMOBJ *jentryobj;
struct dm_dynamic_obj *next_dyn_array;
int i, j, err = 0;
char *parent_obj = parent_node->current_object;
if (entryobj) {
for (; entryobj->obj; entryobj++) {
dm_browse_schema_entry(dmctx, parent_node, entryobj, data, instance, parent_obj, &err);
if (dmctx->stop)
return err;
}
}
if (parent_node->obj) {
if (parent_node->obj->nextdynamicobj) {
for (i = 0; i < __INDX_DYNAMIC_MAX; i++) {
next_dyn_array = parent_node->obj->nextdynamicobj + i;
if (next_dyn_array->nextobj) {
for (j = 0; next_dyn_array->nextobj[j]; j++) {
jentryobj = next_dyn_array->nextobj[j];
for (; (jentryobj && jentryobj->obj); jentryobj++) {
dm_browse_schema_entry(dmctx, parent_node, jentryobj, data, instance, parent_obj, &err);
if (dmctx->stop)
return err;
}
}
}
}
}
}
return 0;
}
int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance)
{
int err = 0;
@ -488,23 +448,6 @@ int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char
return err;
}
static int plugin_dynamic_obj_match(struct dmctx *dmctx, struct dmnode *node, char *entry_obj, char *full_obj)
{
if (node->matched)
return 0;
if (!dmctx->inparam_isparam && strstr(node->current_object, full_obj) == node->current_object) {
node->matched++;
dmctx->findparam = 1;
return 0;
}
if (strstr(full_obj, node->current_object) == full_obj)
return 0;
return FAULT_9005;
}
void dm_check_dynamic_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, char *full_obj, char *obj, DMOBJ **root_entry, int *obj_found)
{
int err = 0;
@ -846,7 +789,7 @@ void free_all_list_parameter(struct dmctx *ctx)
}
}
void add_set_list_tmp(struct dmctx *ctx, char *param, char *value, unsigned int flags)
static void add_set_list_tmp(struct dmctx *ctx, char *param, char *value, unsigned int flags)
{
struct set_tmp *set_tmp;
set_tmp = dmcalloc(1, sizeof(struct set_tmp));
@ -856,7 +799,7 @@ void add_set_list_tmp(struct dmctx *ctx, char *param, char *value, unsigned int
set_tmp->flags = flags;
}
void del_set_list_tmp(struct set_tmp *set_tmp)
static void del_set_list_tmp(struct set_tmp *set_tmp)
{
list_del(&set_tmp->list);
dmfree(set_tmp->name);
@ -900,7 +843,34 @@ void free_all_list_fault_param(struct dmctx *ctx)
}
}
int bbf_api_dm_update_file_enabled_notify(char *param, char *new_value)
static int check_instance_wildcard_parameter_by_regex(const char *parameter, const char *regex)
{
size_t l1, l2;
char **parameter_split = strsplit(parameter, ".", &l1);
char **regex_split = strsplit(regex, ".", &l2);
if (l1 != l2)
return -1;
for (int i = 0; i < l1; i++) {
if (strcmp(parameter_split[i], regex_split[i]) != 0 && (strcmp(regex_split[i], "*") != 0 || atoi(parameter_split[i]) <= 0))
return -1;
}
return 0;
}
static int check_notification_value(const char *value)
{
int i;
for (i = 0; i< __MAX_notification; i++) {
if (strcmp(value, array_notifcation_char[i]) == 0)
return 0;
}
return -1;
}
static int bbf_api_dm_update_file_enabled_notify(char *param, char *new_value)
{
FILE *fp, *ftmp;
char buf[512];
@ -943,7 +913,7 @@ int bbf_api_dm_update_file_enabled_notify(char *param, char *new_value)
return 0;
}
void dm_update_enabled_notify_byname(char *name, char *new_value)
static void dm_update_enabled_notify_byname(char *name, char *new_value)
{
int iscopy;
bbf_api_dm_update_file_enabled_notify(name, new_value);
@ -1486,13 +1456,14 @@ int dm_entry_get_schema(struct dmctx *ctx)
int err;
ctx->inparam_isparam = 0;
ctx->isgetschema = 1;
ctx->findparam = 0;
ctx->stop = 0;
ctx->checkobj = NULL;
ctx->checkleaf = NULL;
ctx->method_obj = mobj_get_schema_name;
ctx->method_param = mparam_get_schema_name;
err = dm_browse_schema(ctx, &node, root, NULL, NULL);
err = dm_browse(ctx, &node, root, NULL, NULL);
return err;
}
@ -1848,8 +1819,9 @@ int dm_entry_set_notification(struct dmctx *dmctx)
DMNODE node = { .current_object = "" };
int err;
if (dmcommon_check_notification_value(dmctx->in_notification) < 0)
if (check_notification_value(dmctx->in_notification) < 0)
return FAULT_9003;
if (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, root->obj) == 0) {
return FAULT_9009;
} else if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) == dm_delim) {
@ -1876,8 +1848,6 @@ int dm_entry_set_notification(struct dmctx *dmctx)
return FAULT_9005;
}
/* SET Notification*/
static int mparam_set_notification_in_obj(DMPARAM_ARGS)
{
return FAULT_9005;
@ -1956,14 +1926,16 @@ int dm_entry_enabled_notify(struct dmctx *dmctx)
return err;
}
char* check_parameter_forced_notification(char *parameter)
char *check_parameter_forced_notification(const char *parameter)
{
int i;
for (i=0; i<ARRAY_SIZE(forced_notifications_parameters); i++) {
if (strcmp(forced_notifications_parameters[i].name, parameter) == 0 || check_instance_wildcard_parameter_by_regex(parameter, forced_notifications_parameters[i].name) == 0)
for (i = 0; i < ARRAY_SIZE(forced_notifications_parameters); i++) {
if (strcmp(forced_notifications_parameters[i].name, parameter) == 0 ||
check_instance_wildcard_parameter_by_regex(parameter, forced_notifications_parameters[i].name) == 0)
return forced_notifications_parameters[i].notification;
}
return NULL;
}
@ -2374,8 +2346,7 @@ int dm_entry_upnp_update_attribute_values_update(struct dmctx *dmctx)
/* ******************
* UPNP get instances
* ******************/
int dm_entry_upnp_get_instances(struct dmctx *dmctx)
int dm_entry_upnp_get_instances(struct dmctx *dmctx, bool all_instances)
{
DMOBJ *root = dmctx->dm_entryobj;
DMNODE node = {.current_object = ""};
@ -2394,8 +2365,8 @@ int dm_entry_upnp_get_instances(struct dmctx *dmctx)
dmctx->stop = 0;
dmctx->checkobj = plugin_upnp_obj_depth_match;
dmctx->checkleaf = plugin_upnp_skip_leafs;
dmctx->method_obj = mobj_upnp_get_instances;
dmctx->method_param = mparam_upnp_get_instances;
dmctx->method_obj = all_instances ? mobj_upnp_get_instance_numbers : mobj_upnp_get_instances;
dmctx->method_param = all_instances ? mparam_upnp_get_instance_numbers : mparam_upnp_get_instances;
err = dm_browse(dmctx, &node, root, NULL, NULL);
if (dmctx->findparam)
return 0;
@ -2423,6 +2394,24 @@ static int mobj_upnp_get_instances(DMOBJECT_ARGS)
return 0;
}
static int mparam_upnp_get_instance_numbers(DMPARAM_ARGS)
{
return 0;
}
static int mobj_upnp_get_instance_numbers(DMOBJECT_ARGS)
{
char *refparam;
refparam = node->current_object;
if (!node->is_instanceobj || !node->matched)
return FAULT_UPNP_703;
if (*(dmctx->all_instances)) {
strcat(dmctx->all_instances, ",");
}
strcat(dmctx->all_instances, instance);
return 0;
}
/* *****************************
* UPNP get supported parameters
* *****************************/
@ -2857,9 +2846,9 @@ static int mobj_upnp_add_instance(DMOBJECT_ARGS)
}
/* ********************
* UPNP get attributes
* UPNP get/set attributes
* ********************/
int dm_entry_upnp_get_attributes(struct dmctx *dmctx)
int dm_entry_upnp_get_set_attributes(struct dmctx *dmctx, bool is_get)
{
DMOBJ *root = dmctx->dm_entryobj;
DMNODE node = { .current_object = "" };
@ -2879,8 +2868,8 @@ int dm_entry_upnp_get_attributes(struct dmctx *dmctx)
dmctx->stop = 0;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_match;
dmctx->method_obj = mobj_upnp_get_attributes;
dmctx->method_param = mparam_upnp_get_attributes;
dmctx->method_obj = is_get ? mobj_upnp_get_attributes : mobj_upnp_set_attributes;
dmctx->method_param = is_get ? mparam_upnp_get_attributes : mparam_upnp_set_attributes;
err = dm_browse(dmctx, &node, root, NULL, NULL);
if (dmctx->findparam)
return 0;
@ -2966,38 +2955,6 @@ static int mobj_upnp_get_attributes(DMOBJECT_ARGS)
return 0;
}
/* ********************
* UPNP set attributes
* ********************/
int dm_entry_upnp_set_attributes(struct dmctx *dmctx)
{
DMOBJ *root = dmctx->dm_entryobj;
DMNODE node = { .current_object = "" };
int err;
char buf[4] = {0};
buf[0] = dm_delim;
if (*(dmctx->in_param) == '\0')
dmctx->in_param = buf;
if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim)
dmctx->inparam_isparam = 1;
else
dmctx->inparam_isparam = 0;
dmctx->findparam = 0;
dmctx->stop = 0;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_match;
dmctx->method_obj = mobj_upnp_set_attributes;
dmctx->method_param = mparam_upnp_set_attributes;
err = dm_browse(dmctx, &node, root, NULL, NULL);
if (dmctx->findparam)
return 0;
else
return (upnp_map_bbf_fault(err));
}
static int mparam_upnp_set_attributes(DMPARAM_ARGS)
{
char *refparam;
@ -3137,7 +3094,6 @@ static int mobj_upnp_get_acldata(DMOBJECT_ARGS)
/* **************************
* UPNP get instance numbers
* *************************/
char *dm_entry_get_all_instance_numbers(struct dmctx *pctx, char *param)
{
static char instbuf[256];
@ -3146,58 +3102,12 @@ char *dm_entry_get_all_instance_numbers(struct dmctx *pctx, char *param)
dm_ctx_init_sub(&dmctx, pctx->dm_type, pctx->amd_version, pctx->instance_mode);
dmctx.in_param = param;
dmctx.depth = 1;
dm_entry_upnp_get_instance_numbers(&dmctx);
dm_entry_upnp_get_instances(&dmctx, true);
strcpy(instbuf, dmctx.all_instances);
dm_ctx_clean_sub(&dmctx);
return instbuf;
}
int dm_entry_upnp_get_instance_numbers(struct dmctx *dmctx)
{
DMOBJ *root = dmctx->dm_entryobj;
DMNODE node = {.current_object = ""};
int err;
char buf[4] = {0};
buf[0] = dm_delim;
if (*(dmctx->in_param) == '\0')
dmctx->in_param = buf;
if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim)
return FAULT_UPNP_701;
dmctx->inparam_isparam = 0;
dmctx->findparam = 0;
dmctx->stop = 0;
dmctx->checkobj = plugin_upnp_obj_depth_match;
dmctx->checkleaf = plugin_upnp_skip_leafs;
dmctx->method_obj = mobj_upnp_get_instance_numbers;
dmctx->method_param = mparam_upnp_get_instance_numbers;
err = dm_browse(dmctx, &node, root, NULL, NULL);
if (dmctx->findparam)
return 0;
else
return (upnp_map_bbf_fault(err));
}
static int mparam_upnp_get_instance_numbers(DMPARAM_ARGS)
{
return 0;
}
static int mobj_upnp_get_instance_numbers(DMOBJECT_ARGS)
{
char *refparam;
refparam = node->current_object;
if (!node->is_instanceobj || !node->matched)
return FAULT_UPNP_703;
if (*(dmctx->all_instances)) {
strcat(dmctx->all_instances, ",");
}
strcat(dmctx->all_instances, instance);
return 0;
}
/************************************
* upnp load tracked parameter values
***********************************/

View file

@ -32,7 +32,6 @@
#define DMDELIM_CWMP '.'
#define DELIMITOR ","
#define DM_PROMPT "icwmp>"
#define DM_ENABLED_NOTIFY "/etc/bbfdm/.dm_enabled_notify"
#define DM_ENABLED_NOTIFY_TEMPORARY "/tmp/.dm_enabled_notify_temporary"
@ -46,10 +45,6 @@
#endif
#define UNDEF -1
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
@ -233,9 +228,9 @@ struct dmctx
char *inst_buf[16];
char *instance_wildchar;
unsigned int end_session_flag;
bool isgetschema;
};
typedef struct dmnode {
DMOBJ *obj;
struct dmnode *parent;
@ -245,13 +240,6 @@ typedef struct dmnode {
unsigned char is_instanceobj;
} DMNODE;
struct prefix_method {
const char *prefix_name;
bool enable;
bool (*set_enable)(void);
int (*method)(struct dmctx *ctx);
};
struct notification {
char *value;
char *type;
@ -262,16 +250,6 @@ struct dm_acl {
char *user_access;
};
typedef struct execute_end_session {
struct list_head list;
int action;
unsigned int dm_type;
unsigned int amd_version;
unsigned int instance_mode;
void *data;
void (*function)(struct execute_end_session *);
} execute_end_session;
typedef struct lib_map_obj {
char *path;
struct dm_obj_s *root_obj;
@ -548,6 +526,17 @@ enum {
__INDX_DYNAMIC_MAX
};
enum notification_enum {
notification_none,
notification_passive,
notification_active,
notification_passive_lw,
notification_ppassive_passive_lw,
notification_aactive_lw,
notification_passive_active_lw,
__MAX_notification
};
extern struct list_head list_enabled_notify;
#ifdef BBF_TR064
@ -571,8 +560,6 @@ int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, cha
void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type, char *param_version, unsigned int flags, char *param_notification);
void api_del_list_parameter(struct dm_parameter *dm_parameter);
void free_all_list_parameter(struct dmctx *ctx);
void add_set_list_tmp(struct dmctx *ctx, char *param, char *value, unsigned int flags);
void del_set_list_tmp(struct set_tmp *set_tmp);
void free_all_set_list_tmp(struct dmctx *ctx);
void add_list_fault_param(struct dmctx *ctx, char *param, int fault);
void bbf_api_del_list_fault_param(struct param_fault *param_fault);
@ -591,21 +578,6 @@ int dm_entry_set_notification(struct dmctx *ctx);
int dm_entry_enabled_notify(struct dmctx *dmctx);
int dm_entry_get_linker(struct dmctx *ctx);
int dm_entry_get_linker_value(struct dmctx *ctx);
#ifdef BBF_TR064
int dm_entry_upnp_get_instances(struct dmctx *ctx);
int dm_entry_upnp_get_selected_values(struct dmctx *dmctx);
int dm_entry_upnp_get_values(struct dmctx *dmctx);
int dm_entry_upnp_set_values(struct dmctx *dmctx);
int dm_entry_upnp_get_attributes(struct dmctx *dmctx);
int upnp_state_variables_init(struct dmctx *dmctx);
int dm_entry_upnp_tracked_parameters(struct dmctx *dmctx);
int dm_entry_upnp_get_instance_numbers(struct dmctx *dmctx);
char *dm_entry_get_all_instance_numbers(struct dmctx *pctx, char *param);
void free_all_list_enabled_notify();
void free_all_list_upnp_param_track(struct list_head *head);
#endif
int bbf_api_dm_update_file_enabled_notify(char *param, char *new_value);
void dm_update_enabled_notify_byname(char *name, char *new_value);
char *get_last_instance(char *package, char *section, char *opt_inst);
char *get_last_instance_bbfdm_without_update(char *package, char *section, char *opt_inst);
char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst);
@ -613,21 +585,29 @@ char *get_last_instance_lev2(char *package, char *section, char *opt_inst, char
char *get_last_instance_lev2_bbfdm_dmmap_opt(char* dmmap_package, char *section, char *opt_inst, char *opt_check, char *value_check);
char *get_last_instance_lev2_bbfdm(char *package, char *section, char* dmmap_package, char *opt_inst, char *opt_check, char *value_check);
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_inst, char * (*up_instance)(int action, char **last_inst, char **max_inst, void *argv[]), int argc, ...);
int dm_add_end_session(struct dmctx *ctx, void(*function)(struct execute_end_session *), int action, void *data);
char *dm_print_path(char *fpath, ...);
int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance);
void dm_check_dynamic_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, char *full_obj, char *obj, DMOBJ **root_entry, int *obj_found);
int free_dm_browse_node_dynamic_object_tree(DMNODE *parent_node, DMOBJ *entryobj);
int dm_entry_get_full_param_value(struct dmctx *dmctx);
char* check_parameter_forced_notification(char *parameter);
char *check_parameter_forced_notification(const char *parameter);
#ifdef BBF_TR064
void add_list_upnp_param_track(struct dmctx *dmctx, struct list_head *pchead, char *param, char *key, char *value, unsigned int isobj);
int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance);
int dm_entry_upnp_get_instances(struct dmctx *ctx, bool all_instances);
int dm_entry_upnp_get_selected_values(struct dmctx *dmctx);
int dm_entry_upnp_get_values(struct dmctx *dmctx);
int dm_entry_upnp_set_values(struct dmctx *dmctx);
int dm_entry_upnp_get_set_attributes(struct dmctx *dmctx);
int dm_entry_upnp_get_supported_parameters(struct dmctx *dmctx);
int dm_entry_upnp_set_attributes(struct dmctx *dmctx);
int dm_entry_upnp_delete_instance(struct dmctx *dmctx);
int dm_entry_upnp_get_acl_data(struct dmctx *dmctx);
int dm_entry_upnp_add_instance(struct dmctx *dmctx);
int upnp_state_variables_init(struct dmctx *dmctx);
int dm_entry_upnp_tracked_parameters(struct dmctx *dmctx);
char *dm_entry_get_all_instance_numbers(struct dmctx *pctx, char *param);
void free_all_list_enabled_notify();
void free_all_list_upnp_param_track(struct list_head *head);
void add_list_upnp_param_track(struct dmctx *dmctx, struct list_head *pchead, char *param, char *key, char *value, unsigned int isobj);
int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance);
#endif
static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance)

View file

@ -13,16 +13,6 @@
#include "dmcommon.h"
char *array_notifcation_char[__MAX_notification] = {
[notification_none] = "0",
[notification_passive] = "1",
[notification_active] = "2",
[notification_passive_lw] = "3",
[notification_ppassive_passive_lw] = "4",
[notification_aactive_lw] = "5",
[notification_passive_active_lw] = "6",
};
char *Encapsulation[] = {"LLC", "VCMUX"};
char *LinkType[] = {"EoA", "IPoA", "PPPoA", "CIP", "Unconfigured"};
char *BridgeStandard[] = {"802.1D-2004", "802.1Q-2005", "802.1Q-2011"};
@ -71,18 +61,6 @@ char *IPPrefix[] = {"^/(3[0-2]|[012]?[0-9])$", "^((25[0-5]|2[0-4][0-9]|[01]?[0-9
char *IPv4Prefix[] = {"^/(3[0-2]|[012]?[0-9])$", "^((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])/(3[0-2]|[012]?[0-9])$"};
char *IPv6Prefix[] = {"^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/(12[0-8]|1[0-1][0-9]|[0-9]?[0-9])$"};
char *cut_fx(char *str, char *delimiter, int occurence)
{
int i = 1;
char *pch, *spch;
pch = strtok_r(str, delimiter, &spch);
while (pch != NULL && i < occurence) {
i++;
pch = strtok_r(NULL, delimiter, &spch);
}
return pch;
}
unsigned char dmisnumeric(char *nbr)
{
if (*nbr == '\0')
@ -409,16 +387,6 @@ int wan_remove_dev_interface(struct uci_section *interface_setion, char *dev)
return 0;
}
int dmcommon_check_notification_value(char *value)
{
int i;
for (i = 0; i< __MAX_notification; i++) {
if (strcmp(value, array_notifcation_char[i]) == 0)
return 0;
}
return -1;
}
void parse_proc_route_line(char *line, struct proc_routing *proute)
{
char *pch, *spch;
@ -462,7 +430,7 @@ void ip_to_hex(char *address, char *ret)
/*
* dmmap_config sections list manipulation
*/
void add_sectons_list_paramameter(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section, void* additional_attribute)
void add_dmmap_config_dup_list(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section, void *additional_attribute)
{
struct dmmap_dup *dmmap_config;
@ -554,7 +522,7 @@ void synchronize_specific_config_sections_with_dmmap(char *package, char *sectio
/*
* Add system and dmmap sections to the list
*/
add_sectons_list_paramameter(dup_list, s, dmmap_sect, NULL);
add_dmmap_config_dup_list(dup_list, s, dmmap_sect, NULL);
}
/*
@ -584,7 +552,7 @@ void synchronize_specific_config_sections_with_dmmap_eq(char *package, char *sec
/*
* Add system and dmmap sections to the list
*/
add_sectons_list_paramameter(dup_list, s, dmmap_sect, NULL);
add_dmmap_config_dup_list(dup_list, s, dmmap_sect, NULL);
}
/*
@ -617,49 +585,49 @@ void synchronize_specific_config_sections_with_dmmap_eq_no_delete(char *package,
uci_path_foreach_sections(bbfdm, dmmap_package, section_type, dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "section_name", &v);
get_config_section_of_dmmap_section("network", "interface", v, &s);
add_sectons_list_paramameter(dup_list, s, dmmap_sect, NULL);
add_dmmap_config_dup_list(dup_list, s, dmmap_sect, NULL);
}
}
void synchronize_specific_config_sections_with_dmmap_cont(char *package, char *section_type, char *dmmap_package,char* option_name, char* option_value, struct list_head *dup_list)
{
struct uci_section *s, *stmp, *dmmap_sect;
struct uci_section *uci_s, *stmp, *dmmap_sect;
char *v;
uci_foreach_option_cont(package, section_type, option_name, option_value, s) {
uci_foreach_option_cont(package, section_type, option_name, option_value, uci_s) {
/*
* create/update corresponding dmmap section that have same config_section link and using param_value_array
*/
if ((dmmap_sect = get_dup_section_in_dmmap(dmmap_package, section_type, section_name(s))) == NULL) {
if ((dmmap_sect = get_dup_section_in_dmmap(dmmap_package, section_type, section_name(uci_s))) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, section_type, &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(s));
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(uci_s));
}
/*
* Add system and dmmap sections to the list
*/
add_sectons_list_paramameter(dup_list, s, dmmap_sect, NULL);
add_dmmap_config_dup_list(dup_list, uci_s, dmmap_sect, NULL);
}
/*
* Delete unused dmmap sections
*/
uci_path_foreach_sections_safe(bbfdm, dmmap_package, section_type, stmp, s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
uci_path_foreach_sections_safe(bbfdm, dmmap_package, section_type, stmp, uci_s) {
dmuci_get_value_by_section_string(uci_s, "section_name", &v);
if (get_origin_section_from_config(package, section_type, v) == NULL)
dmuci_delete_by_section(s, NULL, NULL);
dmuci_delete_by_section(uci_s, NULL, NULL);
}
}
void add_sysfs_sectons_list_paramameter(struct list_head *dup_list, struct uci_section *dmmap_section, char *file_name, char* filepath)
void add_sysfs_section_list(struct list_head *dup_list, struct uci_section *dmmap_section, char *file_name, char *file_path)
{
struct sysfs_dmsection *dmmap_sysfs;
dmmap_sysfs = dmcalloc(1, sizeof(struct sysfs_dmsection));
list_add_tail(&dmmap_sysfs->list, dup_list);
dmmap_sysfs->dm = dmmap_section;
dmmap_sysfs->dmmap_section = dmmap_section;
dmmap_sysfs->sysfs_folder_name = dmstrdup(file_name);
dmmap_sysfs->sysfs_folder_path = dmstrdup(filepath);
dmmap_sysfs->sysfs_folder_path = dmstrdup(file_path);
}
int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, struct list_head *dup_list)
@ -667,7 +635,7 @@ int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_packag
struct uci_section *s, *stmp, *dmmap_sect;
DIR *dir;
struct dirent *ent;
char *v, *sysfs_rep_path, *instance= NULL;
char *v, *sysfs_rep_path, *instance = NULL;
struct sysfs_dmsection *p, *tmp;
LIST_HEAD(dup_list_no_inst);
@ -691,9 +659,9 @@ int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_packag
*/
if(instance == NULL || strlen(instance) <= 0)
add_sysfs_sectons_list_paramameter(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path);
add_sysfs_section_list(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path);
else
add_sysfs_sectons_list_paramameter(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path);
add_sysfs_section_list(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path);
}
if (dir)
closedir(dir);
@ -816,15 +784,15 @@ void delete_sections_save_next_sections(char* dmmap_package, char *section_type,
uci_path_foreach_sections(bbfdm, dmmap_package, section_type, s) {
dmuci_get_value_by_section_string(s, instancename, &v);
inst= atoi(v);
if(inst>instance){
inst = atoi(v);
if (inst > instance){
dmuci_get_value_by_section_string(s, "section_name", &tmp);
add_dmmap_list_section(dup_list, lsectname, v);
dmfree(lsectname);
lsectname= NULL;
lsectname = NULL;
dmasprintf(&lsectname, "%s", tmp);
dmfree(tmp);
tmp= NULL;
tmp = NULL;
}
}
@ -832,8 +800,8 @@ void delete_sections_save_next_sections(char* dmmap_package, char *section_type,
uci_path_foreach_sections_safe(bbfdm, dmmap_package, section_type, stmp, s) {
dmuci_get_value_by_section_string(s, instancename, &v);
inst= atoi(v);
if(inst>=instance)
inst = atoi(v);
if (inst >= instance)
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
}
}
@ -1380,7 +1348,7 @@ int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_
/* check size for each range */
for (i = 0; i < r_args_size; i++) {
unsigned long val = 0, minval = 0, maxval = 0;
unsigned long ui_val = 0, minval = 0, maxval = 0;
char *endval = NULL, *endmin = NULL, *endmax = NULL;
if (r_args[i].min) minval = strtoul(r_args[i].min, &endmin, 10);
@ -1389,7 +1357,7 @@ int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_
/* reset errno to 0 before call */
errno = 0;
val = strtoul(value, &endval, 10);
ui_val = strtoul(value, &endval, 10);
if ((*value == '-') || (*endval != 0) || (errno != 0)) return -1;
@ -1405,7 +1373,7 @@ int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_
}
/* check size */
if ((r_args[i].min && val < minval) || (r_args[i].max && val > maxval) || (val < 0) || (val > (unsigned int)UINT_MAX))
if ((r_args[i].min && ui_val < minval) || (r_args[i].max && ui_val > maxval) || (ui_val < 0) || (ui_val > (unsigned int)UINT_MAX))
return -1;
}
@ -1418,7 +1386,7 @@ int dm_validate_int(char *value, struct range_args r_args[], int r_args_size)
/* check size for each range */
for (i = 0; i < r_args_size; i++) {
long val = 0, minval = 0, maxval = 0;
long i_val = 0, minval = 0, maxval = 0;
char *endval = NULL, *endmin = NULL, *endmax = NULL;
if (r_args[i].min) minval = strtol(r_args[i].min, &endmin, 10);
@ -1427,12 +1395,12 @@ int dm_validate_int(char *value, struct range_args r_args[], int r_args_size)
/* reset errno to 0 before call */
errno = 0;
val = strtol(value, &endval, 10);
i_val = strtol(value, &endval, 10);
if ((*endval != 0) || (errno != 0)) return -1;
/* check size */
if ((r_args[i].min && val < minval) || (r_args[i].max && val > maxval) || (val < INT_MIN) || (val > INT_MAX))
if ((r_args[i].min && i_val < minval) || (r_args[i].max && i_val > maxval) || (i_val < INT_MIN) || (i_val > INT_MAX))
return -1;
}
@ -1445,7 +1413,7 @@ int dm_validate_unsignedLong(char *value, struct range_args r_args[], int r_args
/* check size for each range */
for (i = 0; i < r_args_size; i++) {
unsigned long val = 0, minval = 0, maxval = 0;
unsigned long ul_val = 0, minval = 0, maxval = 0;
char *endval = NULL, *endmin = NULL, *endmax = NULL;
if (r_args[i].min) minval = strtoul(r_args[i].min, &endmin, 10);
@ -1454,12 +1422,12 @@ int dm_validate_unsignedLong(char *value, struct range_args r_args[], int r_args
/* reset errno to 0 before call */
errno = 0;
val = strtoul(value, &endval, 10);
ul_val = strtoul(value, &endval, 10);
if ((*value == '-') || (*endval != 0) || (errno != 0)) return -1;
/* check size */
if ((r_args[i].min && val < minval) || (r_args[i].max && val > maxval) || (val < 0) || (val > (unsigned long)ULONG_MAX))
if ((r_args[i].min && ul_val < minval) || (r_args[i].max && ul_val > maxval) || (ul_val < 0) || (ul_val > (unsigned long)ULONG_MAX))
return -1;
}
@ -1472,7 +1440,7 @@ int dm_validate_long(char *value, struct range_args r_args[], int r_args_size)
/* check size for each range */
for (i = 0; i < r_args_size; i++) {
long val = 0, minval = 0, maxval = 0;
long u_val = 0, minval = 0, maxval = 0;
char *endval = NULL, *endmin = NULL, *endmax = NULL;
if (r_args[i].min) minval = strtol(r_args[i].min, &endmin, 10);
@ -1481,12 +1449,12 @@ int dm_validate_long(char *value, struct range_args r_args[], int r_args_size)
/* reset errno to 0 before call */
errno = 0;
val = strtol(value, &endval, 10);
u_val = strtol(value, &endval, 10);
if ((*endval != 0) || (errno != 0)) return -1;
/* check size */
if ((r_args[i].min && val < minval) || (r_args[i].max && val > maxval))
if ((r_args[i].min && u_val < minval) || (r_args[i].max && u_val > maxval))
return -1;
}
@ -1574,7 +1542,7 @@ int dm_validate_string_list(char *value, int min_item, int max_item, int max_siz
int dm_validate_unsignedInt_list(char *value, int min_item, int max_item, int max_size, struct range_args r_args[], int r_args_size)
{
char *pch, *pchr;
char *token, *saveptr;
int nbr_item = 0;
/* check length of list */
@ -1587,8 +1555,8 @@ int dm_validate_unsignedInt_list(char *value, int min_item, int max_item, int ma
buf[strlen(value)] = '\0';
/* for each value, validate string */
for (pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) {
if (dm_validate_unsignedInt(pch, r_args, r_args_size))
for (token = strtok_r(buf, ",", &saveptr); token != NULL; token = strtok_r(NULL, ",", &saveptr)) {
if (dm_validate_unsignedInt(token, r_args, r_args_size))
return -1;
nbr_item ++;
}
@ -1681,33 +1649,6 @@ char *replace_char(char *str, char find, char replace)
return str;
}
int is_vlan_termination_section(char *name)
{
struct uci_section *s;
uci_foreach_sections("network", "interface", s) {
// check ifname is not empty
char *ifname;
dmuci_get_value_by_section_string(s, "ifname", &ifname);
if (*ifname == '\0')
continue;
// check if ifname list contains the device name
if (strstr(ifname, name)) {
char *type;
// check type is not bridge
dmuci_get_value_by_section_string(s, "type", &type);
if (strcmp(type, "bridge") == 0)
return 0;
break;
}
}
return 1;
}
void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, char *value)
{
struct uci_section *d_sec = NULL;
@ -1760,18 +1701,3 @@ int check_browse_section(struct uci_section *s, void *data)
return 0;
return -1;
}
int check_instance_wildcard_parameter_by_regex(char *parameter, char* regex)
{
size_t l1, l2;
char **parameter_split = strsplit(parameter, ".", &l1);
char **regex_split = strsplit(regex, ".", &l2);
if (l1 != l2)
return -1;
int i;
for (i=0; i<l1; i++) {
if (strcmp(parameter_split[i], regex_split[i]) != 0 && (strcmp(regex_split[i], "*") != 0 || atoi(parameter_split[i])<=0))
return -1;
}
return 0;
}

View file

@ -177,17 +177,6 @@ do { \
if ((dir = opendir(path)) == NULL) return 0; \
while ((ent = readdir (dir)) != NULL) \
enum notification_enum {
notification_none,
notification_passive,
notification_active,
notification_passive_lw,
notification_ppassive_passive_lw,
notification_aactive_lw,
notification_passive_active_lw,
__MAX_notification
};
enum strstructered_enum {
STRUCTERED_SAME,
STRUCTERED_PART,
@ -239,7 +228,7 @@ struct sysfs_dmsection {
struct list_head list;
char *sysfs_folder_path;
char *sysfs_folder_name;
struct uci_section *dm;
struct uci_section *dmmap_section;
};
struct browse_args {
@ -247,7 +236,6 @@ struct browse_args {
char *value;
};
char *cut_fx(char *str, char *delimiter, int occurence);
pid_t get_pid(char *pname);
int check_file(char *path);
char *cidr2netmask(int bits);
@ -262,16 +250,15 @@ void update_section_list(char *config, char *section, char *option, int number,
int wan_remove_dev_interface(struct uci_section *interface_setion, char *dev);
void parse_proc_route_line(char *line, struct proc_routing *proute);
int strstructered(char *str1, char *str2);
int dmcommon_check_notification_value(char *value);
void hex_to_ip(char *address, char *ret);
void ip_to_hex(char *address, char *ret);
void add_sectons_list_paramameter(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section, void* additional_attribute);
void add_dmmap_config_dup_list(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section, void* additional_attribute);
void free_dmmap_config_dup_list(struct list_head *dup_list);
void synchronize_specific_config_sections_with_dmmap(char *package, char *section_type, char *dmmap_package, struct list_head *dup_list);
void synchronize_specific_config_sections_with_dmmap_eq(char *package, char *section_type, char *dmmap_package,char* option_name, char* option_value, struct list_head *dup_list);
void synchronize_specific_config_sections_with_dmmap_eq_no_delete(char *package, char *section_type, char *dmmap_package,char* option_name, char* option_value, struct list_head *dup_list);
void synchronize_specific_config_sections_with_dmmap_cont(char *package, char *section_type, char *dmmap_package,char* option_name, char* option_value, struct list_head *dup_list);
void add_sysfs_sectons_list_paramameter(struct list_head *dup_list, struct uci_section *dmmap_section, char *file_name, char* filepath);
void add_sysfs_section_list(struct list_head *dup_list, struct uci_section *dmmap_section, char *file_name, char *file_path);
int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, struct list_head *dup_list);
void get_dmmap_section_of_config_section(char* dmmap_package, char* section_type, char *section_name, struct uci_section **dmmap_section);
void get_dmmap_section_of_config_section_eq(char* dmmap_package, char* section_type, char *opt, char* value, struct uci_section **dmmap_section);
@ -326,9 +313,7 @@ bool file_exists(const char *path);
bool is_regular_file(const char *path);
char *stringToHex(char *text, int length);
char *replace_char(char *str, char find, char replace);
int is_vlan_termination_section(char *name);
void sync_dmmap_bool_to_uci_list(struct uci_section *s, char *section, char *value, bool b);
void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, char *value);
int check_browse_section(struct uci_section *s, void *data);
int check_instance_wildcard_parameter_by_regex(char *parameter, char* regex);
#endif

View file

@ -1,41 +0,0 @@
/*
* Copyright (C) 2019 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author: MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wepkey.h"
void wepkey64(char *passphrase, char strk64[4][11])
{
unsigned char k64[4][5];
unsigned char pseed[4] = {0};
unsigned int randNumber, tmp;
int i, j;
for(i = 0; i < strlen(passphrase); i++)
{
pseed[i%4] ^= (unsigned char) passphrase[i];
}
randNumber = pseed[0] | (pseed[1] << 8) | (pseed[2] << 16) | (pseed[3] << 24);
for (i = 0; i < 4; i++)
{
for (j = 0; j < 5; j++)
{
randNumber = (randNumber * 0x343fd + 0x269ec3) & 0xffffffff;
tmp = (randNumber >> 16) & 0xff;
k64[i][j] = (unsigned char) tmp;
}
snprintf(strk64[i], sizeof(strk64[i]), "%02X%02X%02X%02X%02X", k64[i][0], k64[i][1], k64[i][2], k64[i][3], k64[i][4]);
}
}

View file

@ -1,16 +0,0 @@
/*
* Copyright (C) 2019 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author: MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
*
*/
#ifndef __WEPKEY_H__
#define __WEPKEY_H__
void wepkey64(char *passphrase, char strk64[4][11]);
#endif /*__WEPKEY_H__*/