clean up the source code

- remove unused variables
- fix coding style of most function (Indentation, Tabulation, ..)
- check the source code using cppcheck tool
- change sprintf by snprintf
This commit is contained in:
Amin Ben Ramdhane 2020-02-12 19:08:49 +01:00
parent c76b2f3354
commit ff14c27fc3
122 changed files with 2838 additions and 4272 deletions

View file

@ -79,7 +79,7 @@ libbbfdm_la_SOURCES += \
../dmtree/tr181/users.c \
../dmtree/tr181/dhcpv6.c \
../dmtree/tr181/dsl.c \
../dmtree/tr181/interfacestack.c \
../dmtree/tr181/interfacestack.c \
../dmtree/tr181/qos.c \
../dmtree/tr181/usb.c \
../dmtree/tr181/datamodelversion.c \

View file

@ -9,10 +9,6 @@
*
*/
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include <libbbf_api/dmcommon.h>
int bbfdmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value);

View file

@ -9,21 +9,7 @@
*
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#include <libtrace.h>
#include <libpacketdump.h>
#include <inttypes.h>
#include <assert.h>
#include <getopt.h>
#include <libbbf_api/dmcommon.h>
#include "dmdiagnostics.h"
int read_next;
@ -162,10 +148,7 @@ static void http_download_per_packet(libtrace_packet_t *packet)
struct tm lt;
struct timeval ts;
libtrace_tcp_t *tcp;
uint32_t seq = 0;
char tcp_flag[16] = "";
char *nexthdr;
char s_now[default_date_size];
char *nexthdr, tcp_flag[16] = "", s_now[default_date_size];
uint8_t proto;
uint32_t remaining;
@ -185,8 +168,7 @@ static void http_download_per_packet(libtrace_packet_t *packet)
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)
{
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);
@ -194,8 +176,8 @@ static void http_download_per_packet(libtrace_packet_t *packet)
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)
{
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);
@ -203,8 +185,8 @@ static void http_download_per_packet(libtrace_packet_t *packet)
download_stats.random_seq = ntohl(tcp->seq);
return;
}
if (strcmp(tcp_flag, "PSH ACK ") == 0 && strncmp(nexthdr, "GET", 3) == 0)
{
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);
@ -212,18 +194,17 @@ static void http_download_per_packet(libtrace_packet_t *packet)
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)
{
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 )
{
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)
{
if (download_stats.first_data == 0) {
sprintf((download_stats.bomtime),"%s.%06ld", s_now, (long) ts.tv_usec);
char *val = strstr(nexthdr,"Content-Length");
char *pch, *pchr;
@ -234,13 +215,12 @@ static void http_download_per_packet(libtrace_packet_t *packet)
}
return;
}
if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && ntohl(tcp->ack_seq) == download_stats.ack_seq)
{
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)
{
if (download_stats.first_data == 0) {
sprintf((download_stats.bomtime),"%s.%06ld", s_now, (long) ts.tv_usec);
char *val = strstr(nexthdr,"Content-Length");
char *pch, *pchr;
@ -554,22 +534,16 @@ int extract_stats(char *dump_file, int proto, int diagnostic_type, char *protoco
return 0;
}
int get_default_gateway_device( char **gw )
int get_default_gateway_device(char **gw)
{
FILE *f;
char line[100], *p, *c, *saveptr;
f = fopen("/proc/net/route" , "r");
if (f != NULL)
{
while(fgets(line , 100 , f))
{
FILE *f = fopen("/proc/net/route" , "r");
if (f != NULL) {
char line[100], *p, *c, *saveptr;
while(fgets(line , 100 , f)) {
p = strtok_r(line, " \t", &saveptr);
c = strtok_r(NULL, " \t", &saveptr);
if(p!=NULL && c!=NULL)
{
if(strcmp(c, "00000000") == 0)
{
if(p!=NULL && c!=NULL) {
if(strcmp(c, "00000000") == 0) {
dmasprintf(gw, "%s", p);
fclose(f);
return 0;
@ -583,30 +557,25 @@ int get_default_gateway_device( char **gw )
int start_upload_download_diagnostic(int diagnostic_type)
{
char *url = NULL;
char *interface = NULL;
char *size = NULL;
char *url, *interface, *size, *status;
int error;
char *status;
if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "url", &url);
dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "device", &interface);
}
else {
} else {
dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "url", &url);
dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "TestFileLength", &size);
dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "device", &interface);
}
if ( interface == NULL || interface[0] == '\0' )
{
if (interface[0] == '\0') {
error = get_default_gateway_device(&interface);
if (error == -1)
return -1;
}
if (diagnostic_type == DOWNLOAD_DIAGNOSTIC)
{
if (diagnostic_type == DOWNLOAD_DIAGNOSTIC) {
//Free uci_varstate_ctx
end_uci_varstate_ctx();
@ -617,19 +586,15 @@ int start_upload_download_diagnostic(int diagnostic_type)
dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "url", &url);
dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "DiagnosticState", &status);
if (status && strcmp(status, "Completed") == 0)
{
if (status && strcmp(status, "Completed") == 0) {
init_download_stats();
if(strncmp(url,DOWNLOAD_UPLOAD_PROTOCOL_HTTP,strlen(DOWNLOAD_UPLOAD_PROTOCOL_HTTP)) == 0)
if(strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_HTTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_HTTP)) == 0)
extract_stats(DOWNLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_HTTP, DOWNLOAD_DIAGNOSTIC, "usp");
if(strncmp(url,DOWNLOAD_UPLOAD_PROTOCOL_FTP,strlen(DOWNLOAD_UPLOAD_PROTOCOL_FTP)) == 0)
if(strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_FTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_FTP)) == 0)
extract_stats(DOWNLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_FTP, DOWNLOAD_DIAGNOSTIC, "usp");
}
else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
} else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
return -1;
}
else
{
} else {
//Free uci_varstate_ctx
end_uci_varstate_ctx();
@ -640,15 +605,13 @@ int start_upload_download_diagnostic(int diagnostic_type)
dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "url", &url);
dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "DiagnosticState", &status);
if (status && strcmp(status, "Completed") == 0)
{
if (status && strcmp(status, "Completed") == 0) {
init_upload_stats();
if(strncmp(url,DOWNLOAD_UPLOAD_PROTOCOL_HTTP,strlen(DOWNLOAD_UPLOAD_PROTOCOL_HTTP)) == 0)
if(strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_HTTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_HTTP)) == 0)
extract_stats(UPLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_HTTP, UPLOAD_DIAGNOSTIC, "usp");
if(strncmp(url,DOWNLOAD_UPLOAD_PROTOCOL_FTP,strlen(DOWNLOAD_UPLOAD_PROTOCOL_FTP)) == 0)
if(strncmp(url, DOWNLOAD_UPLOAD_PROTOCOL_FTP, strlen(DOWNLOAD_UPLOAD_PROTOCOL_FTP)) == 0)
extract_stats(UPLOAD_DUMP_FILE, DOWNLOAD_DIAGNOSTIC_FTP, UPLOAD_DIAGNOSTIC, "usp");
}
else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
} else if (status && strncmp(status, "Error_", strlen("Error_")) == 0)
return -1;
}
return 0;

View file

@ -12,6 +12,8 @@
#ifndef __DMDIAGNOSTICS_H__
#define __DMDIAGNOSTICS_H__
#include <libbbf_api/dmcommon.h>
#define DOWNLOAD_UPLOAD_PROTOCOL_HTTP "http://"
#define DOWNLOAD_UPLOAD_PROTOCOL_FTP "ftp://"
#define default_date_format "AAAA-MM-JJTHH:MM:SS.000000Z"

180
dmentry.c
View file

@ -12,13 +12,6 @@
*
*/
#include <unistd.h>
#include <ctype.h>
#include <sys/wait.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
#include "dmentryjson.h"
#include "dmentrylibrary.h"
@ -29,6 +22,7 @@
#ifdef BBF_TR064
#include "upnp_device.h"
#endif
LIST_HEAD(head_package_change);
unsigned char dmcli_timetrack = 0;
unsigned char dmcli_evaluatetest = 0;
@ -162,9 +156,12 @@ int dm_ctx_clean_sub(struct dmctx *ctx)
int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, char *arg2)
{
int fault = 0;
bool setnotif = true, alarm = false, event = false;
int err, err2;
int err = 0, fault = 0;
bool setnotif = true;
#ifdef BBF_TR064
bool alarm = false, event = false;
int err2 = 0;
#endif
if (check_stats_json_folder(JSON_FOLDER_PATH)) {
free_json_dynamic_arrays(tEntry181Obj);
@ -190,11 +187,10 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
case CMD_GET_NAME:
if (ctx->dm_type == DM_CWMP && ctx->in_param[0] == dm_delim && strlen(ctx->in_param) == 1)
fault = FAULT_9005;
else if (arg1 && string_to_bool(arg1, &ctx->nextlevel) == 0){
else if (arg1 && string_to_bool(arg1, &ctx->nextlevel) == 0)
fault = dm_entry_get_name(ctx);
} else {
else
fault = FAULT_9003;
}
break;
case CMD_GET_NOTIFICATION:
if (ctx->dm_type == DM_CWMP && ctx->in_param[0] == dm_delim && strlen(ctx->in_param) == 1)
@ -556,9 +552,9 @@ int dm_entry_upnp_update_version_configuration(struct dmctx *dmctx)
if (!tmp || tmp[0] == '\0') {
dmuci_add_section(UPNP_CFG, "dm", &s, &tmp);
}
sprintf(buf, "%d", version);
snprintf(buf, sizeof(buf), "%d", version);
dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_version", buf);
sprintf(buf, "%ld", time(NULL));
snprintf(buf, sizeof(buf), "%ld", time(NULL));
dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_epochtime", buf);
return version;
@ -569,8 +565,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;
int version, fault;
int ischange;
int version, fault, ischange = 0;
char *all_instances;
list_for_each_entry(p, &list_upnp_enabled_version, list) {
@ -603,7 +598,7 @@ int dm_entry_upnp_check_versiononchange_param(struct dmctx *pctx)
char *tmp;
struct uci_section *s = NULL;
version = dm_entry_upnp_update_version_configuration(&dmctx);
sprintf(buf, "%d", version);
snprintf(buf, sizeof(buf), "%d", version);
if (p->key) {
dmuci_set_value(UPNP_CFG, p->key, "version", buf);
}
@ -640,29 +635,29 @@ int upnp_state_variables_init(struct dmctx *dmctx)
dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "supported_datamodel_version", &v);
n = atoi(v);
if (n != UPNP_SUPPORTED_DATAMODEL_VERSION) {
sprintf(buf, "%d", UPNP_SUPPORTED_DATAMODEL_VERSION);
snprintf(buf, sizeof(buf), "%d", UPNP_SUPPORTED_DATAMODEL_VERSION);
dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_datamodel_version", buf);
sprintf(buf, "%ld", time(NULL));
snprintf(buf, sizeof(buf), "%ld", time(NULL));
dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_datamodel_epochtime", buf);
}
dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "supported_parameters_version", &v);
n = atoi(v);
if (n != UPNP_SUPPORTED_PARAMETERS_VERSION) {
sprintf(buf, "%d", UPNP_SUPPORTED_PARAMETERS_VERSION);
snprintf(buf, sizeof(buf), "%d", UPNP_SUPPORTED_PARAMETERS_VERSION);
dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_parameters_version", buf);
sprintf(buf, "%ld", time(NULL));
snprintf(buf, sizeof(buf), "%ld", time(NULL));
dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_parameters_epochtime", buf);
}
dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "current_configuration_version", &v);
if (*v == '\0') {
dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_version", "0");
sprintf(buf, "%ld", time(NULL));
snprintf(buf, sizeof(buf), "%ld", time(NULL));
dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_epochtime", buf);
}
dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "attribute_values_version", &v);
if (*v == '\0') {
dmuci_set_value(UPNP_CFG, "@dm[0]", "attribute_values_version", "0");
sprintf(buf, "%ld", time(NULL));
snprintf(buf, sizeof(buf), "%ld", time(NULL));
dmuci_set_value(UPNP_CFG, "@dm[0]", "attribute_values_epochtime", buf);
}
@ -687,7 +682,7 @@ int dm_entry_upnp_get_supported_parameters_update(struct dmctx *dmctx, char **va
time_value = atoi(v);
char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value));
sprintf(csv, "%d,%s", UPNP_SUPPORTED_PARAMETERS_VERSION, s_now);
snprintf(csv, sizeof(csv), "%d,%s", UPNP_SUPPORTED_PARAMETERS_VERSION, s_now);
}
return 0;
@ -710,7 +705,7 @@ int dm_entry_upnp_get_supported_datamodel_update(struct dmctx *dmctx, char **val
time_value = atoi(v);
char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value));
sprintf(csv, "%d,%s", UPNP_SUPPORTED_DATAMODEL_VERSION, s_now);
snprintf(csv, sizeof(csv), "%d,%s", UPNP_SUPPORTED_DATAMODEL_VERSION, s_now);
}
return 0;
@ -734,7 +729,7 @@ int dm_entry_upnp_get_attribute_values_update(struct dmctx *dmctx, char **value)
time_value = atoi(v);
char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value));
sprintf(csv, "%s,%s", s, s_now);
snprintf(csv, sizeof(csv), "%s,%s", s, s_now);
}
return 0;
@ -758,7 +753,7 @@ int dm_entry_upnp_get_configuration_update(struct dmctx *dmctx, char **value)
time_value = atoi(v);
char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value));
sprintf(csv, "%s,%s", s, s_now);
snprintf(csv, sizeof(csv), "%s,%s", s, s_now);
}
return 0;
@ -917,11 +912,11 @@ int cli_output_dm_result(struct dmctx *dmctx, int fault, int cmd, int out)
list_for_each_entry(n, &dmctx->list_parameter, list) {
char alrm[32] = "", evnt[32] = "", btype[16], bversion[32] = "", *stype = NULL;
if (n->flags & DM_PARAM_ALARAM_ON_CHANGE)
strcpy(alrm, ", \"alarmOnChange\": \"1\"");
strncpy(alrm, ", \"alarmOnChange\": \"1\"", sizeof(alrm)-1);
if (n->flags & DM_PARAM_EVENT_ON_CHANGE)
strcpy(evnt, ", \"eventOnChange\": \"1\"");
if (n->version)
sprintf(bversion, ", \"version\": \"%s\"", n->version);
snprintf(bversion, sizeof(bversion), ", \"version\": \"%s\"", n->version);
switch (n->flags & NODE_DATA_ATTRIBUTE_TYPEMASK) {
case NODE_DATA_ATTRIBUTE_TYPEINT:
stype = "int";
@ -946,7 +941,7 @@ int cli_output_dm_result(struct dmctx *dmctx, int fault, int cmd, int out)
break;
}
if (stype)
sprintf(btype, ", \"type\": \"%s\"", stype);
snprintf(btype, sizeof(btype), ", \"type\": \"%s\"", stype);
fprintf (stdout, "{ \"parameter\": \"%s\", \"access\": \"%s\"%s%s%s%s}\n", n->name, n->data, btype, evnt, alrm, bversion);
}
break;
@ -996,7 +991,7 @@ int cli_output_dm_result(struct dmctx *dmctx, int fault, int cmd, int out)
if (*bwrite)
bwrite[strlen(bwrite) - 1] = '\0';
if (n->flags & DM_FACTORIZED)
sprintf(bfac, ", \"factorized\": \"1\"");
snprintf(bfac, sizeof(bfac), ", \"factorized\": \"1\"");
fprintf (stdout, "{ \"ACLDataPath\": \"%s\", \"List\": \"%s\", \"Read\": \"%s\", \"Write\": \"%s\"%s }\n", n->name, blist, bread, bwrite, bfac);
}
break;
@ -1064,41 +1059,33 @@ static char *parse_arg_r(char *pch, char **last)
return NULL;
}
for(; *pch != '\0'; pch++)
{
for(; *pch != '\0'; pch++) {
if(*pch == ' ' || *pch == '\t')
continue;
if (*pch == '"')
{
if (*pch == '"') {
char *s = strchr(++pch, '"');
if(s) {
*s = '\0';
*last = s + 1;
return pch;
}
else {
} else {
*last = NULL;
return NULL;
}
}
else
{
} else {
char *s = strchr(pch, ' ');
if(s) {
*s = '\0';
*last = s + 1;
}
else {
} else {
s = strchr(pch, '\t');
if(s) {
*s = '\0';
*last = s + 1;
}
else {
} else {
*last = NULL;
}
}
return pch;
}
}
@ -1130,14 +1117,16 @@ static int dmentry_external_cmd(char **argv)
void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode)
{
struct dmctx cli_dmctx = {0};
int output = 1, dmrpc;
int fault = 0, output = 1;
char *param, *next_level, *parameter_key, *value, *cmd;
int fault = 0, status = -1;
bool set_fault = false;
long ms; // Milliseconds
time_t s; // Seconds
struct timespec tstart, tend;
unsigned char apply_services = 0;
#ifdef BBF_TR064
int dmrpc = 0;
#endif
if (dmcli_timetrack)
clock_gettime(CLOCK_REALTIME, &tstart);
@ -1153,7 +1142,6 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
/* GET NAME */
if (strcmp(cmd, "get_name") == 0) {
if (argc < 6) goto invalid_arguments;
dmrpc = CMD_GET_NAME;
param = argv[4];
next_level =argv[5];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NAME, param, next_level, NULL);
@ -1162,7 +1150,6 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
/* GET VALUE */
else if (strcmp(cmd, "get_value") == 0) {
if (argc < 5) goto invalid_arguments;
dmrpc = CMD_GET_VALUE;
param = argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_VALUE, param, NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_GET_VALUE, output);
@ -1170,7 +1157,6 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
/* GET NOTIFICATION */
else if (strcmp(cmd, "get_notification") == 0) {
if (argc < 5) goto invalid_arguments;
dmrpc = CMD_GET_NOTIFICATION;
param = argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NOTIFICATION, param, NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NOTIFICATION, output);
@ -1178,7 +1164,6 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
/* SET VALUE */
else if (strcmp(cmd, "set_value") == 0) {
if (argc < 7 || (argc % 2) == 0) goto invalid_arguments;
dmrpc = CMD_SET_VALUE;
int i;
for (i = 5; i < argc; i+=2) {
param = argv[i];
@ -1196,7 +1181,6 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
/* SET NOTIFICATION */
else if (strcmp(cmd, "set_notification") == 0) {
if (argc < 6 || (argc % 2) != 0) goto invalid_arguments;
dmrpc = CMD_SET_NOTIFICATION;
int i;
for (i = 4; i < argc; i+=2) {
param = argv[i];
@ -1212,8 +1196,7 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
/* ADD OBJECT */
else if (strcmp(cmd, "add_object") == 0) {
if (argc < 6) goto invalid_arguments;
dmrpc = CMD_ADD_OBJECT;
param =argv[5];
param = argv[5];
parameter_key =argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_ADD_OBJECT, param, parameter_key, NULL);
if (!fault)
@ -1222,9 +1205,8 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
}
/* DEL OBJECT */
else if (strcmp(cmd, "delete_object") == 0) {
dmrpc = CMD_DEL_OBJECT;
if (argc < 6) goto invalid_arguments;
param =argv[5];
param = argv[5];
parameter_key =argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_DEL_OBJECT, param, parameter_key, NULL);
if (!fault)
@ -1233,7 +1215,6 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
}
/* INFORM */
else if (strcmp(cmd, "inform") == 0) {
dmrpc = CMD_INFORM;
fault = dm_entry_param_method(&cli_dmctx, CMD_INFORM, "", NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_INFORM, output);
}
@ -1311,7 +1292,7 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
if (argc >= 6) {
dm_ctx_init_sub(&set_dmctx, dmtype, amd_version, instance_mode);
for (i = 5; i < argc; i+=2) {
sprintf(buf, "%s%s%c%s", param, cli_dmctx.addobj_instance, dm_delim, argv[i]); // concatenate obj path + instance + sub param
snprintf(buf, sizeof(buf), "%s%s%c%s", param, cli_dmctx.addobj_instance, dm_delim, argv[i]); // concatenate obj path + instance + sub param
value = argv[i+1];
dm_entry_param_method(&set_dmctx, CMD_UPNP_SET_VALUES, buf, value, NULL);
}
@ -1389,39 +1370,32 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE, var);
}
else if (strcmp(cmd, "upnp_load_enabled_parametrs_track") == 0) {
char *var;
dmrpc = CMD_UPNP_LOAD_ENABLED_PARAMETRS_TRACK;
dm_entry_upnp_load_tracked_parameters(&cli_dmctx);
}
else if (strcmp(cmd, "upnp_get_enabled_parametrs_alarm") == 0) {
char *var;
dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM;
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM, output);
}
else if (strcmp(cmd, "upnp_get_enabled_parametrs_event") == 0) {
char *var;
dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT;
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT, output);
}
else if (strcmp(cmd, "upnp_get_enabled_parametrs_version") == 0) {
char *var;
dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION;
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION, output);
}
else if (strcmp(cmd, "upnp_check_changed_parametrs_alarm") == 0) {
char *var;
dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM;
dm_entry_upnp_check_alarmonchange_param(&cli_dmctx);
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM, output);
}
else if (strcmp(cmd, "upnp_check_changed_parametrs_event") == 0) {
char *var;
dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT;
dm_entry_upnp_check_eventonchange_param(&cli_dmctx);
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT, output);
}
else if (strcmp(cmd, "upnp_check_changed_parametrs_version") == 0) {
char *var;
dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION;
dm_entry_upnp_check_versiononchange_param(&cli_dmctx);
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION, output);
@ -1437,13 +1411,12 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
}
if (!fault) {
int ualarm, uversion, uevent;
#ifdef BBF_TR064
switch (dmrpc) {
case CMD_UPNP_SET_VALUES:
case CMD_UPNP_DEL_INSTANCE:
case CMD_UPNP_ADD_INSTANCE:
DM_ENTRY_UPNP_CHECK_CHANGES(ualarm, uevent, uversion);
DM_ENTRY_UPNP_CHECK_CHANGES();
break;
case CMD_UPNP_SET_ATTRIBUTES:
DM_ENTRY_UPNP_LOAD_TRACKED_PARAMETERS();
@ -1469,19 +1442,18 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
invalid_arguments:
dm_ctx_clean(&cli_dmctx);
fprintf(stdout, "Invalid arguments!\n");;
fprintf(stdout, "Invalid arguments!\n");
}
int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode)
{
struct dmctx cli_dmctx = {0};
int fault = 0, set_fault = 0;
int i, dmrpc;
char *param;
char *value;
char *parameter_key;
char *notifset;
int fault = 0, set_fault = 0, i;
char *param, *value, *parameter_key, *notifset;
unsigned char apply_services = 0;
#ifdef BBF_TR064
int dmrpc = 0;
#endif
if (argc < 3) {
fprintf(stderr, "Wrong arguments!\n");
@ -1492,7 +1464,6 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
dm_ctx_init(&cli_dmctx, dmtype, amd_version, instance_mode);
if (strcmp(argv[2], "get_value") == 0) {
char *param = "";
dmrpc = CMD_GET_VALUE;
if (argc >= 4)
param = argv[3];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_VALUE, param, NULL, NULL);
@ -1501,13 +1472,11 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
else if (strcmp(argv[2], "get_name") == 0) {
if (argc < 5)
goto invalid_arguments;
dmrpc = CMD_GET_NAME;
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NAME, argv[3], argv[4], NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NAME, 1);
}
else if (strcmp(argv[2], "get_notification") == 0) {
char *param = "";
dmrpc = CMD_GET_NOTIFICATION;
if (argc >= 4)
param = argv[3];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NOTIFICATION, param, NULL, NULL);
@ -1516,9 +1485,7 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
else if (strcmp(argv[2], "set_value") == 0) {
if (argc < 6 || (argc % 2) != 0)
goto invalid_arguments;
dmrpc = CMD_SET_VALUE;
for (i = 4; i < argc; i+=2) {
for (i = 4; i < argc; i += 2) {
param = argv[i];
value = argv[i+1];
fault = dm_entry_param_method(&cli_dmctx, CMD_SET_VALUE, param, value, NULL);
@ -1534,8 +1501,7 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
else if (strcmp(argv[2], "set_notification") == 0) {
if (argc < 6 || (argc % 3) != 0)
goto invalid_arguments;
dmrpc = CMD_SET_NOTIFICATION;
for (i=3; i<argc; i+=3) {
for (i = 3; i < argc; i += 3) {
param = argv[i];
value = argv[i+1];
notifset = argv[i+2];
@ -1548,14 +1514,12 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
cli_output_dm_result(&cli_dmctx, fault, CMD_SET_NOTIFICATION, 1);
}
else if (strcmp(argv[2], "inform") == 0 || strcmp(argv[2], "inform_parameter") == 0) {
dmrpc = CMD_INFORM;
fault = dm_entry_param_method(&cli_dmctx, CMD_INFORM, "", NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_INFORM, 1);
}
else if (strcmp(argv[2], "add_obj") == 0) {
if (argc < 5)
goto invalid_arguments;
dmrpc = CMD_ADD_OBJECT;
param = argv[3];
parameter_key = argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_ADD_OBJECT, param, parameter_key, NULL);
@ -1566,7 +1530,6 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
else if (strcmp(argv[2], "del_obj") == 0) {
if (argc < 5)
goto invalid_arguments;
dmrpc = CMD_DEL_OBJECT;
param =argv[3];
parameter_key =argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_DEL_OBJECT, param, parameter_key, NULL);
@ -1577,7 +1540,6 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
else if (strcmp(argv[2], "external_command") == 0) {
if (argc < 4)
goto invalid_arguments;
dmrpc = CMD_EXTERNAL_COMMAND;
argv[argc] = NULL;
dmentry_external_cmd(&argv[3]);
}
@ -1620,7 +1582,7 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
goto invalid_arguments;
dmrpc = CMD_UPNP_SET_VALUES;
for (i = 3; i < argc; i+=2) {
for (i = 3; i < argc; i += 2) {
param = argv[i];
value = argv[i+1];
fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_SET_VALUES, param, value, NULL);
@ -1628,7 +1590,7 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
}
if (!fault) {
apply_services = 1;
fault = dm_entry_apply(&cli_dmctx, CMD_UPNP_SET_VALUES, parameter_key, NULL);
fault = dm_entry_apply(&cli_dmctx, CMD_UPNP_SET_VALUES, NULL, NULL);
}
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_SET_VALUES, 1);
}
@ -1669,7 +1631,7 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
if (argc >= 5) {
dm_ctx_init_sub(&set_dmctx, dmtype, amd_version, instance_mode);
for (i = 4; i < argc; i+=2) {
sprintf(buf, "%s%s%c%s", param, cli_dmctx.addobj_instance, dm_delim, argv[i]); // concatenate obj path + instance + sub param
snprintf(buf, sizeof(buf), "%s%s%c%s", param, cli_dmctx.addobj_instance, dm_delim, argv[i]); // concatenate obj path + instance + sub param
value = argv[i+1];
dm_entry_param_method(&set_dmctx, CMD_UPNP_SET_VALUES, buf, value, NULL);
}
@ -1731,39 +1693,32 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE, var);
}
else if (strcmp(argv[2], "upnp_load_enabled_parametrs_track") == 0) {
char *var;
dmrpc = CMD_UPNP_LOAD_ENABLED_PARAMETRS_TRACK;
dm_entry_upnp_load_tracked_parameters(&cli_dmctx);
}
else if (strcmp(argv[2], "upnp_get_enabled_parametrs_alarm") == 0) {
char *var;
dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM;
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM, 1);
}
else if (strcmp(argv[2], "upnp_get_enabled_parametrs_event") == 0) {
char *var;
dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT;
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT, 1);
}
else if (strcmp(argv[2], "upnp_get_enabled_parametrs_version") == 0) {
char *var;
dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION;
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION, 1);
}
else if (strcmp(argv[2], "upnp_check_changed_parametrs_alarm") == 0) {
char *var;
dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM;
dm_entry_upnp_check_alarmonchange_param(&cli_dmctx);
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM, 1);
}
else if (strcmp(argv[2], "upnp_check_changed_parametrs_event") == 0) {
char *var;
dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT;
dm_entry_upnp_check_eventonchange_param(&cli_dmctx);
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT, 1);
}
else if (strcmp(argv[2], "upnp_check_changed_parametrs_version") == 0) {
char *var;
dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION;
dm_entry_upnp_check_versiononchange_param(&cli_dmctx);
cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION, 1);
@ -1779,13 +1734,12 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
}
if (!fault) {
int ualarm, uversion, uevent;
#ifdef BBF_TR064
switch (dmrpc) {
case CMD_UPNP_SET_VALUES:
case CMD_UPNP_DEL_INSTANCE:
case CMD_UPNP_ADD_INSTANCE:
DM_ENTRY_UPNP_CHECK_CHANGES(ualarm, uevent, uversion);
DM_ENTRY_UPNP_CHECK_CHANGES();
break;
case CMD_UPNP_SET_ATTRIBUTES:
DM_ENTRY_UPNP_LOAD_TRACKED_PARAMETERS();
@ -1805,9 +1759,7 @@ invalid_arguments:
void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode)
{
FILE *fp;
char *argv[64];
char buf[2048], dbuf[2048];
char *pch, *pchr;
char *argv[64], buf[2048], dbuf[2048], *pch, *pchr;
int argc, len, i=0;
long ms; // Milliseconds
time_t s; // Seconds
@ -1820,8 +1772,7 @@ void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_ve
fflush(stderr);
return;
}
}
else {
} else {
fp = stdin;
}
@ -1853,7 +1804,6 @@ void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_ve
printf(DM_PROMPT" "); fflush(stdout);
continue;
}
i++;
strcpy(dbuf, buf);
@ -1863,7 +1813,7 @@ void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_ve
if (*pch == '"')
pch++;
len = strlen(pch);
if (len>0 && pch[len-1] == '"')
if (len > 0 && pch[len-1] == '"')
pch[len-1] = '\0';
argv[argc++] = pch;
}
@ -1871,16 +1821,15 @@ void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_ve
if (!pch || pch[0] != '#') {
fprintf(stdout, "%s\n", dbuf);
fflush(stdout);
}
else {
} else {
fprintf(stdout, "\n");
fflush(stdout);
}
}
if (argc>2) {
if (argc > 2) {
char testref[32] = "";
if (dmcli_evaluatetest)
sprintf(testref, "Ref: %s - ", argv[1]);
snprintf(testref, sizeof(testref), "Ref: %s - ", argv[1]);
if (dmcli_timetrack || dmcli_evaluatetest) {
fprintf(stdout, "-----------------------------\n");
fprintf(stdout, "[%s%04d] %s\n", testref, i, dbuf);
@ -1902,8 +1851,7 @@ void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_ve
fprintf(stdout, "-----------------------------\n");
fflush(stdout);
}
}
else {
} else {
fprintf(stdout, "Type help for help\n");
fflush(stdout);
}
@ -1943,19 +1891,17 @@ void wepkey_cli(int argc, char** argv)
char strk64[4][11];
wepkey64(passphrase, strk64);
cli_output_wepkey64(strk64);
}
else if (strcmp(strength, "128") == 0) {
} else if (strcmp(strength, "128") == 0) {
char strk128[27];
wepkey128(passphrase, strk128);
cli_output_wepkey128(strk128);
}
else {
} else {
goto invalid_arguments;
}
return;
invalid_arguments:
fprintf(stdout, "Invalid arguments!\n");;
fprintf(stdout, "Invalid arguments!\n");
}
int free_dynamic_arrays(void)

View file

@ -15,7 +15,8 @@
#ifndef __DMENTRY_H__
#define __DMENTRY_H__
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
extern struct list_head head_package_change;
extern unsigned char dmcli_timetrack;
extern unsigned char dmcli_evaluatetest;
@ -56,19 +57,19 @@ void wepkey_cli(int argc, char** argv);
int free_dynamic_arrays(void);
#ifdef BBF_TR064
#define DM_ENTRY_UPNP_CHECK_CHANGES(ALARM, EVENT, VERSION) \
#define DM_ENTRY_UPNP_CHECK_CHANGES() \
do { \
struct dmctx dmctx_chg = {0}; \
dm_ctx_init(&dmctx_chg, DM_UPNP, AMD_2, INSTANCE_MODE_NUMBER); \
ALARM = dm_entry_upnp_check_alarmonchange_param(&dmctx_chg); \
dm_entry_upnp_check_alarmonchange_param(&dmctx_chg); \
dm_ctx_clean(&dmctx_chg); \
memset(&dmctx_chg, 0, sizeof(struct dmctx)); \
dm_ctx_init(&dmctx_chg, DM_UPNP, AMD_2, INSTANCE_MODE_NUMBER); \
EVENT = dm_entry_upnp_check_eventonchange_param(&dmctx_chg); \
dm_entry_upnp_check_eventonchange_param(&dmctx_chg); \
dm_ctx_clean(&dmctx_chg); \
memset(&dmctx_chg, 0, sizeof(struct dmctx)); \
dm_ctx_init(&dmctx_chg, DM_UPNP, AMD_2, INSTANCE_MODE_NUMBER); \
VERSION = dm_entry_upnp_check_versiononchange_param(&dmctx_chg); \
dm_entry_upnp_check_versiononchange_param(&dmctx_chg); \
dm_ctx_clean(&dmctx_chg); \
} while(0)

View file

@ -9,15 +9,6 @@
*
*/
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <sys/stat.h>
#include <dirent.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include "dmentryjson.h"
#include "dmmemjson.h"
@ -38,7 +29,7 @@ static int get_stats_json_folder(char *folder_path, int *file_count, unsigned lo
while ((entry = readdir(dirp)) != NULL) {
if ((entry->d_type == DT_REG) && (strstr(entry->d_name, ".json"))) {
filecount++;
sprintf(buf, "%s/%s", folder_path, entry->d_name);
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;
@ -139,7 +130,7 @@ int check_stats_json_folder(char *json_folder_path)
if (!get_stats_json_folder(json_folder_path, &file_count, &size, &date))
return 0;
sprintf(str, "count:%d,sizes:%lu,date:%lu", file_count, size, date);
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;
@ -274,8 +265,8 @@ int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *
char *obj = generate_obj_without_instance(parent_node->current_object, true);
generate_prefixobj_and_obj_full_obj(parent_node->current_object, &prefix_obj, &object);
sprintf(buf_instance, "%s_instance", object);
sprintf(buf_alias, "%s_alias", object);
snprintf(buf_instance, sizeof(buf_instance), "%s_instance", object);
snprintf(buf_alias, sizeof(buf_alias), "%s_alias", object);
for (int i = 0; buf_instance[i]; i++) {
buf_instance[i] = tolower(buf_instance[i]);
}
@ -332,7 +323,7 @@ static int add_obj(char *refparam, struct dmctx *ctx, void *data, char **instanc
if (arg1 && strcmp(arg1, "uci") == 0) {
generate_prefixobj_and_obj_full_obj(refparam, &prefix_obj, &object);
sprintf(buf_instance, "%s_instance", object);
snprintf(buf_instance, sizeof(buf_instance), "%s_instance", object);
for (int i = 0; buf_instance[i]; i++) {
buf_instance[i] = tolower(buf_instance[i]);
}
@ -439,7 +430,7 @@ static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i
} else if (arg1 && strcmp(arg1, "ubus") == 0) {
//UBUS: arg1=type :: arg2=ubus_object :: arg3=ubus_method :: arg4=ubus_args1 :: arg5=ubus_args2 :: arg6=ubus_key
json_object *res;
json_object *res = NULL;
if (arg2 && arg3 && arg4 && arg5) {
if (data && (strcmp(arg5, "@Name") == 0))
dmubus_call(arg2, arg3, UBUS_ARGS{{arg4, section_name((struct uci_section *)data), String}}, 1, &res);
@ -593,7 +584,9 @@ static void parse_param(char *object, char *param, json_object *jobj, DMLEAF *pl
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type(8)*/
struct json_object *type, *protocols, *proto, *write, *mapping;
char full_param[256] = "";
size_t n_proto, n_mapping;
size_t n_proto;
if (!pleaf) return;
//PARAM
pleaf[i].parameter = dmstrdupjson(param);
@ -606,8 +599,10 @@ static void parse_param(char *object, char *param, json_object *jobj, DMLEAF *pl
json_object_object_get_ex(jobj, "type", &type);
if (strcmp(json_object_get_string(type), "boolean") == 0)
pleaf[i].type = DMT_BOOL;
else if ((strcmp(json_object_get_string(type), "unsignedInt") == 0) || (strcmp(json_object_get_string(type), "unsignedLong") == 0))
else if (strcmp(json_object_get_string(type), "unsignedInt") == 0)
pleaf[i].type = DMT_UNINT;
else if (strcmp(json_object_get_string(type), "unsignedLong") == 0)
pleaf[i].type = DMT_UNLONG;
else if (strcmp(json_object_get_string(type), "hexBinary") == 0)
pleaf[i].type = DMT_HEXBIN;
else if (strcmp(json_object_get_string(type), "int") == 0)
@ -647,7 +642,7 @@ static void parse_param(char *object, char *param, json_object *jobj, DMLEAF *pl
} else
pleaf[i].bbfdm_type = BBFDM_BOTH;
sprintf(full_param, "%s%s", object, param);
snprintf(full_param, sizeof(full_param), "%s%s", object, param);
json_object_object_get_ex(jobj, "mapping", &mapping);
parse_mapping_param(full_param, mapping, list);
}
@ -676,13 +671,14 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, s
char *full_obj = NULL, *prfix_obj = NULL, *obj_str = NULL;
int obj_number = 0, param_number = 0, i = 0, j = 0;
DMOBJ *next_obj;
DMLEAF *next_leaf;
DMOBJ *next_obj = NULL;
DMLEAF *next_leaf = NULL;
count_obj_param_under_jsonobj(jobj, &obj_number, &param_number);
full_obj = replace_string(object, ".{i}.", ".");
generate_prefixobj_and_obj_full_obj(full_obj, &prfix_obj, &obj_str);
if (!pobj) return;
//OBJ
pobj[index].obj = obj_str;
@ -767,8 +763,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)
{
int instance = 0, indx = 0;
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)) {
@ -813,8 +807,7 @@ int load_json_dynamic_arrays(struct dmctx *ctx)
DMOBJ *dm_entryobj = NULL;
json_object *json;
char buf[32] = "";
int instance = 0, indx = 0;
sprintf(buf, "%s/%s", JSON_FOLDER_PATH, ent->d_name);
snprintf(buf, sizeof(buf), "%s/%s", JSON_FOLDER_PATH, ent->d_name);
json = json_object_from_file(buf);
if (!json) continue;

View file

@ -12,6 +12,8 @@
#ifndef __DMENTRYJSON_H__
#define __DMENTRYJSON_H__
#include <libbbf_api/dmcommon.h>
#define JSON_FOLDER_PATH "/etc/bbfdm/json"
int check_stats_json_folder(char *json_folder_path);

View file

@ -9,13 +9,6 @@
*
*/
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <sys/stat.h>
#include <dirent.h>
#include <dlfcn.h>
#include <libbbf_api/dmcommon.h>
#include "dmentrylibrary.h"
#include "dmoperate.h"
@ -35,7 +28,7 @@ static int get_stats_library_folder(char *folder_path, int *file_count, unsigned
while ((entry = readdir(dirp)) != NULL) {
if ((entry->d_type == DT_REG) && (strstr(entry->d_name, ".so"))) {
filecount++;
sprintf(buf, "%s/%s", folder_path, entry->d_name);
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;
@ -61,7 +54,7 @@ int check_stats_library_folder(char *library_folder_path)
if (!get_stats_library_folder(library_folder_path, &file_count, &size, &date))
return 0;
sprintf(str, "count:%d,sizes:%lu,date:%lu", file_count, size, date);
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;
@ -135,7 +128,7 @@ int load_library_dynamic_arrays(struct dmctx *ctx)
char buf[32] = "";
int i;
sprintf(buf, "%s/%s", LIBRARY_FOLDER_PATH, ent->d_name);
snprintf(buf, sizeof(buf), "%s/%s", LIBRARY_FOLDER_PATH, ent->d_name);
handle = dlopen(buf, RTLD_LAZY);
if (!handle) continue;

View file

@ -12,6 +12,8 @@
#ifndef __DMENTRYLIBRARY_H__
#define __DMENTRYLIBRARY_H__
#include <libbbf_api/dmcommon.h>
#define LIBRARY_FOLDER_PATH "/usr/lib/bbfdm"
int check_stats_library_folder(char *library_folder_path);

View file

@ -36,8 +36,12 @@ inline void *__dmreallocjson(void *old, size_t size)
m = container_of(old, struct dmmemjson, mem);
list_del(&m->list);
}
m = realloc(m, sizeof(struct dmmemjson) + size);
if (m == NULL) return NULL;
struct dmmemjson *new_m = realloc(m, sizeof(struct dmmemjson) + size);
if (new_m == NULL) {
dmfreejson(m);
return NULL;
} else
m = new_m;
list_add(&m->list, &memheadjson);
return (void *)m->mem;
}
@ -69,14 +73,12 @@ char *__dmstrdupjson(const char *s)
return (char *) memcpy(new, s, len);
}
int __dmasprintfjson(char **s, const char *format, ...)
{
char buf[512];
va_list arg;
int ret;
va_start(arg,format);
ret = vsprintf(buf, format, arg);
vsprintf(buf, format, arg);
va_end(arg);
*s = __dmstrdupjson(buf);
if (*s == NULL) return -1;

View file

@ -9,16 +9,13 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <libubox/list.h>
#ifndef __DMMEMJSON_H
#define __DMMEMJSON_H
struct dmmemjson {
#include <libbbf_api/dmcommon.h>
struct dmmemjson
{
struct list_head list;
char mem[0];
};

View file

@ -20,16 +20,6 @@
static uint8_t wifi_neighbor_count = 0;
struct op_cmd *dynamic_operate = NULL;
bool match(const char *string, const char *pattern)
{
regex_t re;
if (regcomp(&re, pattern, REG_EXTENDED) != 0) return 0;
int status = regexec(&re, string, 0, NULL, 0);
regfree(&re);
if (status != 0) return false;
return true;
}
bool is_str_eq(const char *s1, const char *s2)
{
if(0==strcmp(s1, s2))
@ -347,6 +337,7 @@ static opr_ret_t fetch_neighboring_wifi_diagnostic(struct dmctx *dmctx, char *pa
dmubus_call(ROUTER_WIRELESS_UBUS_PATH, "radios", UBUS_ARGS{}, 0, &res);
json_object_object_foreach(res, key, val) {
UNUSED(val);
fill_wireless_scan_results(dmctx, key);
}
wifi_neighbor_count = 0;
@ -814,7 +805,11 @@ int add_dynamic_operate(char *path, operation operate)
dynamic_operate[0].opt = operate;
} else {
int idx = get_index_of_available_dynamic_operate(dynamic_operate);
dynamic_operate = realloc(dynamic_operate, (idx + 2) * sizeof(struct op_cmd));
struct op_cmd *new_dynamic_operate = realloc(dynamic_operate, (idx + 2) * sizeof(struct op_cmd));
if (new_dynamic_operate == NULL)
FREE(dynamic_operate);
else
dynamic_operate = new_dynamic_operate;
memset(dynamic_operate + (idx + 1), 0, sizeof(struct op_cmd));
dynamic_operate[idx].name = path;
dynamic_operate[idx].opt = operate;

View file

@ -16,16 +16,6 @@
#ifndef __DMOPERATE_H__
#define __DMOPERATE_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <regex.h>
#include <sys/param.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmjson.h>
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
#include "dmdiagnostics.h"

View file

@ -10,18 +10,9 @@
*/
#include "upnp_common.h"
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include <libbbf_api/dmcommon.h>
#include <json-c/json.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int upnp_get_NetworkInterfaceNumberOfEntries(){
int upnp_get_NetworkInterfaceNumberOfEntries()
{
int n = 0;
struct uci_section *s = NULL;
uci_foreach_sections("network", "interface", s) {
@ -30,7 +21,8 @@ int upnp_get_NetworkInterfaceNumberOfEntries(){
return n;
}
int upnp_get_IPInterfaceNumberOfEntries(){
int upnp_get_IPInterfaceNumberOfEntries()
{
char *value1 = NULL, *value2 = NULL;
int n = 0;
struct uci_section *s = NULL;
@ -61,7 +53,8 @@ char *upnp_get_softwareversion()
return val;
}
void upnp_getMacAddress(char *interfaceName, char **macAddress){
void upnp_getMacAddress(char *interfaceName, char **macAddress)
{
json_object *res = NULL, *res1 =NULL;
int length;
@ -99,9 +92,10 @@ void upnp_getInterfaceStatus(char *interfaceName, char **status){
return;
}
int upnp_getInterfaceTotalPacketSent(char *interfaceName, char **totalPktSent){
json_object *res= NULL, *res1= NULL, *res2= NULL;
char *device = NULL, *tx_packets = NULL;
int upnp_getInterfaceTotalPacketSent(char *interfaceName, char **totalPktSent)
{
json_object *res = NULL, *res1 = NULL;
char *device = NULL;
int length;
char **devices = NULL;
@ -111,7 +105,7 @@ int upnp_getInterfaceTotalPacketSent(char *interfaceName, char **totalPktSent){
goto end_bloc;
}
device = dmjson_get_value(res, 1, "device");
if(device == NULL || strlen(device)<=0){
if (device == NULL || strlen(device)<=0) {
*totalPktSent = NULL;
goto end_bloc;
}
@ -129,7 +123,8 @@ int upnp_getInterfaceTotalPacketSent(char *interfaceName, char **totalPktSent){
return 0;
}
int upnp_getInterfaceTotalPacketReceived(char *interfaceName, char **totalPktReceived){
int upnp_getInterfaceTotalPacketReceived(char *interfaceName, char **totalPktReceived)
{
json_object *res= NULL, *res1= NULL, *res2= NULL;
char *device = NULL, *rx_packets = NULL;
int length;

View file

@ -12,6 +12,8 @@
#ifndef UPNP_COMMON_H
#define UPNP_COMMON_H
#include <libbbf_api/dmcommon.h>
char *upnp_get_softwareversion();
int upnp_get_NetworkInterfaceNumberOfEntries();
int upnp_get_IPInterfaceNumberOfEntries();

View file

@ -9,16 +9,8 @@
*
*/
#include <libbbf_api/dmbbf.h>
#include "upnp_configuration.h"
#include "upnp_common.h"
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <stdio.h>
#include <stdlib.h>
#define DELIMITOR ","
/**************************************************************************
*
* /UPnP/DM/Configuration/ datamodel tree
@ -71,18 +63,20 @@ DMLEAF upnpConfigurationNetworkIPInterfaceIpv4Params[]= {
* /UPnP/DM/Configuration/* parameters functions
*
***************************************************************************/
int upnp_configuration_get_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) {
int upnp_configuration_get_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
int upnp_configuration_get_IPInterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_configuration_get_IPInterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int n = upnp_get_IPInterfaceNumberOfEntries();
dmasprintf(value, "%d", n);
return 0;
}
int upnp_configuration_get_SystemName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_configuration_get_SystemName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
if(upnp_configargs->systemName !=NULL && strlen(upnp_configargs->systemName)>0) dmasprintf(value, "%s", upnp_configargs->systemName);
return 0;
@ -96,7 +90,8 @@ int upnp_configuration_get_ipv4_IPAddress(char *refparam, struct dmctx *ctx, voi
return 0;
}
int upnp_configuration_get_ipv4_addressingtype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_configuration_get_ipv4_addressingtype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *proto=NULL;
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
dmuci_get_value_by_section_string(upnp_configargs->upnpConfiguration_sec, "proto", &proto);
@ -106,7 +101,8 @@ int upnp_configuration_get_ipv4_addressingtype(char *refparam, struct dmctx *ctx
return 0;
}
int upnp_configuration_get_ipv4_dnssevers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_configuration_get_ipv4_dnssevers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res= NULL;
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
char *iface_name = section_name(upnp_configargs->upnpConfiguration_sec);
@ -136,7 +132,8 @@ int upnp_configuration_get_ipv4_dnssevers(char *refparam, struct dmctx *ctx, voi
return 0;
}
int upnp_configuration_get_ipv4_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_configuration_get_ipv4_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
char *netmask = NULL;
@ -147,7 +144,8 @@ int upnp_configuration_get_ipv4_subnetmask(char *refparam, struct dmctx *ctx, vo
return 0;
}
int upnp_configuration_get_ipv4_defaultgateway(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_configuration_get_ipv4_defaultgateway(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
FILE* fp = NULL;
struct proc_routing proute = {0};
@ -172,13 +170,15 @@ int upnp_configuration_get_ipv4_defaultgateway(char *refparam, struct dmctx *ctx
return 0;
}
int upnp_configuration_set_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int upnp_configuration_set_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
return 0;
}
int upnp_configuration_set_ipv4_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int upnp_configuration_set_ipv4_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
char *proto= NULL;
char *proto = NULL;
switch (action) {
case VALUECHECK:
return 0;
@ -192,9 +192,10 @@ int upnp_configuration_set_ipv4_IPAddress(char *refparam, struct dmctx *ctx, voi
return 0;
}
int upnp_configuration_set_ipv4_addressingtype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int upnp_configuration_set_ipv4_addressingtype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
char *proto= NULL;
switch (action) {
case VALUECHECK:
return 0;
@ -212,9 +213,10 @@ int upnp_configuration_set_ipv4_addressingtype(char *refparam, struct dmctx *ctx
return 0;
}
int upnp_configuration_set_ipv4_dnssevers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int upnp_configuration_set_ipv4_dnssevers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
char *dup= NULL, *p= NULL;
char *dup = NULL, *p = NULL;
switch (action) {
case VALUECHECK:
@ -235,9 +237,11 @@ int upnp_configuration_set_ipv4_dnssevers(char *refparam, struct dmctx *ctx, voi
return 0;
}
int upnp_configuration_set_ipv4_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int upnp_configuration_set_ipv4_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
char *proto = NULL;
switch (action) {
case VALUECHECK:
return 0;
@ -251,7 +255,8 @@ int upnp_configuration_set_ipv4_subnetmask(char *refparam, struct dmctx *ctx, vo
return 0;
}
int upnp_configuration_set_ipv4_defaultgateway(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int upnp_configuration_set_ipv4_defaultgateway(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct upnp_configuration_args *upnp_configargs = (struct upnp_configuration_args *)data;
switch (action) {
@ -264,7 +269,6 @@ int upnp_configuration_set_ipv4_defaultgateway(char *refparam, struct dmctx *ctx
return 0;
}
int upnp_configuration_ipinterface_createinstance(char *refparam, struct dmctx *ctx, void *data, char **instance){
char *value=NULL;
char *iface_instance=NULL, ib[8], ip_name[32];
@ -295,14 +299,11 @@ int upnp_configuration_ipinterface_deleteinstance(char *refparam, struct dmctx *
return 0;
}
int upnp_browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance){
char *value1, *value2;
int upnp_browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *net_sec = NULL;
char *iface_int = NULL, *iface_int_last = NULL;
char *iface_int = NULL, *iface_int_last = NULL, *netmask = NULL;
struct upnp_configuration_args currUpnpConfigurationArgs = {0};
char *type=NULL, *ipv4addr = "", *ipv6addr = "", *proto, *inst;
char *value= NULL, *netmask = NULL;
json_object *res = NULL, *res1 = NULL;
uci_foreach_sections("network", "interface", net_sec) {
currUpnpConfigurationArgs.upnpConfiguration_sec = net_sec;

View file

@ -11,9 +11,11 @@
#ifndef UPNP_CONFIGURATION_H
#define UPNP_CONFIGURATION_H
#include <libbbf_api/dmbbf.h>
struct upnp_configuration_args{
#include <libbbf_api/dmcommon.h>
struct upnp_configuration_args
{
struct uci_section *upnpConfiguration_sec;
char *systemName;
char *ipv4address;

View file

@ -9,16 +9,11 @@
*
*/
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmbbf.h>
#include "upnp_device.h"
#include "deviceinfo.h"
#include "managementserver.h"
#include "times.h"
#include "upnp.h"
#if BBF_TR104
#include "voice_services.h"
#endif
#include "x_iopsys_eu_ice.h"
#include "x_iopsys_eu_igmp.h"
#include "x_iopsys_eu_ipacccfg.h"
@ -51,6 +46,10 @@
#include "interfacestack.h"
#include "qos.h"
#if BBF_TR104
#include "voice_services.h"
#endif
#ifdef BBF_TR064
#include "upnp_deviceinfo.h"
#include "upnp_configuration.h"
@ -122,7 +121,6 @@ DMOBJ tRoot181ObjUPNPBBF[] = {
{0}
};
UPNP_SUPPORTED_DM tUPNPSupportedDM[];
UPNP_SUPPORTED_DM tUPNPSupportedDM_181[] = {
{"/UPnP/DM/DeviceInfo/", "urn:UPnP:Parent Device:1:ConfigurationManagement:2", DMROOT_URL_181, "UPnP DeviceInfo from "DMROOT_DESC_181, ""},
{"/UPnP/DM/Configuration/", "urn:UPnP:Parent Device:1:ConfigurationManagement:2", DMROOT_URL_181, "Configuration from "DMROOT_DESC_181, ""},

View file

@ -12,6 +12,8 @@
#ifndef __UPNPDEVICE_H
#define __UPNPDEVICE_H
#include <libbbf_api/dmcommon.h>
#ifdef BBF_TR064
extern DMOBJ tEntry181ObjUPNP[];
extern DMOBJ tRoot181ObjUPNP[];

View file

@ -9,16 +9,10 @@
*
*/
#include <stdio.h>
#include <libbbf_api/dmbbf.h>
#include "upnp_deviceinfo.h"
#include <sys/utsname.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmmem.h>
#include <libbbf_api/dmcommon.h>
#include <uci.h>
#include "upnp_common.h"
#include<stdbool.h>
int upnp_browseNetworkInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
@ -93,14 +87,15 @@ DMLEAF upnpDeviceIdParams[] = {
* /UPnP/DM/DeviceInfo/* parameters functions
*
***************************************************************************/
int upnp_deviceinfo_get_provisionning_code(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_provisionning_code(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_option_value_string("cwmp", "cpe", "provisioning_code", value);
return 0;
}
int upnp_deviceinfo_get_software_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
char *v = NULL, *tmp = NULL, *val = NULL;
int upnp_deviceinfo_get_software_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v = NULL, *tmp = NULL;
db_get_value_string("hw", "board", "iopVersion", &v);
if(v == NULL || strlen(v)<=0) {
@ -112,7 +107,8 @@ int upnp_deviceinfo_get_software_version(char *refparam, struct dmctx *ctx, void
return 0;
}
int upnp_deviceinfo_get_software_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_software_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct utsname unameData;
uname(&unameData);
@ -120,7 +116,8 @@ int upnp_deviceinfo_get_software_description(char *refparam, struct dmctx *ctx,
return 0;
}
int upnp_deviceinfo_get_up_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_up_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE* fp = NULL;
char *pch = NULL, *spch = NULL;
char buf[64];
@ -137,7 +134,8 @@ int upnp_deviceinfo_get_up_time(char *refparam, struct dmctx *ctx, void *data, c
return 0;
}
int upnp_deviceinfo_get_hardware_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_hardware_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
db_get_value_string("hw", "board", "hardwareVersion", value);
return 0;
}
@ -148,7 +146,8 @@ int upnp_deviceinfo_get_network_interface_number_entries(char *refparam, struct
return 0;
}
int upnp_deviceinfo_get_manufacturer_oui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_manufacturer_oui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_option_value_string("cwmp", "cpe", "override_oui", value);
if(*value == NULL || strlen(value)<=0) {
*value = NULL;
@ -160,7 +159,8 @@ int upnp_deviceinfo_get_manufacturer_oui(char *refparam, struct dmctx *ctx, void
}
int upnp_deviceinfo_get_product_class(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_product_class(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v = NULL, *tmp = NULL, *val = NULL;
db_get_value_string("hw", "board", "iopVerBoard", &v);
@ -173,32 +173,39 @@ int upnp_deviceinfo_get_product_class(char *refparam, struct dmctx *ctx, void *d
return 0;
}
int upnp_deviceinfo_get_serial_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_serial_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
db_get_value_string("hw", "board", "serialNumber", value);
return 0;
}
int upnp_deviceinfo_get_system_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_system_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
int upnp_deviceinfo_get_mac_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_mac_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
int upnp_deviceinfo_get_interface_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_interface_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
int upnp_deviceinfo_get_will_reboot(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_will_reboot(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
int upnp_deviceinfo_get_will_base_line_reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_will_base_line_reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
int upnp_deviceinfo_get_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_deviceinfo_get_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
@ -221,7 +228,6 @@ int upnp_deviceinfo_set_provisionning_code(char *refparam, struct dmctx *ctx, vo
* MultiInstance objects browsing functions
*
*************************************************/
int upnp_deviceinfo_networkinterface_createinstance(char *refparam, struct dmctx *ctx, void *data, char **instance){
char *value = NULL;
char *iface_instance = NULL, ib[8], ip_name[32];
@ -241,7 +247,8 @@ int upnp_deviceinfo_networkinterface_createinstance(char *refparam, struct dmctx
return 0;
}
int upnp_deviceinfo_networkinterface_deleteinstance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action){
int upnp_deviceinfo_networkinterface_deleteinstance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
switch (del_action) {
case DEL_INST:
dmuci_set_value_by_section(((struct upnp_dvinf_args *)data)->upnp_deviceinfo_sec, "proto", "");
@ -260,7 +267,8 @@ int upnp_deviceinfo_networkinterface_deleteinstance(char *refparam, struct dmctx
return 0;
}
int upnp_browseNetworkInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance){
int upnp_browseNetworkInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *net_sec = NULL;
char *iface_int = NULL, *iface_int_last = NULL, *interfaceType = NULL, *macAddress = NULL;
struct upnp_dvinf_args curr_upnp_deviceinfo_args = {0};
@ -274,4 +282,5 @@ int upnp_browseNetworkInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, vo
iface_int = handle_update_instance(1, dmctx, &iface_int_last, update_instance_alias, 3, net_sec, "upnp_iface_int_instance", "upnp_iface_int_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_upnp_deviceinfo_args, iface_int) == DM_STOP) break;
}
return 0;
}

View file

@ -11,7 +11,8 @@
#ifndef UPNP_DEVICEINFO_H
#define UPNP_DEVICEINFO_H
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
struct upnp_dvinf_args
{

View file

@ -9,13 +9,8 @@
*
*/
#include <libbbf_api/dmbbf.h>
#include "upnp_monitoring.h"
#include "upnp_common.h"
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include <time.h>
/**************************************************************************
*
@ -66,14 +61,16 @@ DMLEAF upnpMonitoringIPUsageParams[] = {
* /UPnP/DM/Monitoring/* parameters functions
*
***************************************************************************/
int upnp_monitoring_get_IPUsageNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_IPUsageNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int n = upnp_get_IPInterfaceNumberOfEntries();
dmasprintf(value, "%d", n);
return 0;
}
int upnp_monitoring_get_CurrentTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_CurrentTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
time_t rawtime;
struct tm * timeinfo = NULL;
@ -83,11 +80,13 @@ int upnp_monitoring_get_CurrentTime(char *refparam, struct dmctx *ctx, void *dat
return 0;
}
int upnp_monitoring_get_CPUUsage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_CPUUsage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return 0;
}
int upnp_monitoring_get_MemoryUsage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_MemoryUsage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL;
char *totalmemory = NULL, *freememory = NULL;
int total, free;
@ -107,35 +106,40 @@ int upnp_monitoring_get_MemoryUsage(char *refparam, struct dmctx *ctx, void *dat
return 0;
}
int upnp_monitoring_get_SystemName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_SystemName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_ip_usage_args *ipusage_args = (struct upnp_ip_usage_args *)data;
if(ipusage_args->systemName != NULL && strlen(ipusage_args->systemName)>0)
dmasprintf(value, "%s", ipusage_args->systemName);
return 0;
}
int upnp_monitoring_get_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_ip_usage_args *ipusage_args = (struct upnp_ip_usage_args *)data;
if(ipusage_args->status != NULL && strlen(ipusage_args->status)>0)
dmasprintf(value, "%s", ipusage_args->status);
return 0;
}
int upnp_monitoring_get_TotalPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_TotalPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_ip_usage_args *ipusage_args = (struct upnp_ip_usage_args *)data;
if(ipusage_args->totalpacketsent != NULL && strlen(ipusage_args->totalpacketsent)>0)
dmasprintf(value, "%s", ipusage_args->totalpacketsent);
return 0;
}
int upnp_monitoring_get_TotalPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int upnp_monitoring_get_TotalPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_ip_usage_args *ipusage_args = (struct upnp_ip_usage_args *)data;
if(ipusage_args->totalpacketreceived != NULL && strlen(ipusage_args->totalpacketreceived)>0)
dmasprintf(value, "%s", ipusage_args->totalpacketreceived);
return 0;
}
int upnp_BrowseIPUsage(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance){
int upnp_BrowseIPUsage(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *net_sec = NULL;
struct upnp_ip_usage_args curr_ip_usage_args = {0};
char *iface_int = NULL, *iface_int_last = NULL, *totalPktSnt = NULL, *totalPktRcvd= NULL, *status = NULL;

View file

@ -11,8 +11,11 @@
#ifndef UPNP_MONITORING_H
#define UPNP_MONITORING_H
#include <libbbf_api/dmbbf.h>
struct upnp_ip_usage_args{
#include <libbbf_api/dmcommon.h>
struct upnp_ip_usage_args
{
char *systemName;
char *status;
char *totalpacketsent;

View file

@ -10,14 +10,6 @@
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <ctype.h>
#include <uci.h>
#include <unistd.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "voice_services.h"
/* *** Device.Services. *** */
@ -367,15 +359,16 @@ static inline int init_allowed_sip_codecs()
dmubus_call("voice.asterisk", "codecs", UBUS_ARGS{}, 0, &res);
if(res) {
json_object_object_foreach(res, key, val) {
UNUSED(val);
for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) {
if(strcmp(capabilities_sip_codecs[i].c1, key) == 0) {
allowed_sip_codecs[available_sip_codecs].enumid = capabilities_sip_codecs[i].enumid;
break;
}
}
sprintf(id, "%d", available_sip_codecs + 1);
sprintf(priority, "priority_%s", key);
sprintf(ptime, "ptime_%s", key);
snprintf(id, sizeof(id), "%d", available_sip_codecs + 1);
snprintf(priority, sizeof(priority), "priority_%s", key);
snprintf(ptime, sizeof(ptime), "ptime_%s", key);
allowed_sip_codecs[available_sip_codecs].id = dmstrdup(id);
allowed_sip_codecs[available_sip_codecs].allowed_cdc = key;
allowed_sip_codecs[available_sip_codecs].priority_cdc = dmstrdup(priority);
@ -447,17 +440,13 @@ int get_cfg_sipidx(void)
int add_profile_object(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char sname[8];
char account[16];
char bufinst[4];
int sipidx;
char *add_value, *instance, *max_instance, *v;
struct uci_section *voice_profile_section= NULL, *dmmap_voice_section= NULL;
struct uci_section *dmmap_voice_section = NULL;
char sname[8], account[16], *instance, *v;
check_create_dmmap_package("dmmap_voice_client");
sipidx = get_cfg_sipidx();
sprintf(sname, "sip%d", sipidx);
sprintf(account, "Account %d", sipidx);
int sipidx = get_cfg_sipidx();
snprintf(sname, sizeof(sname), "sip%d", sipidx);
snprintf(account, sizeof(account), "Account %d", sipidx);
dmuci_set_value("voice_client", sname, NULL, "sip_service_provider");
dmuci_set_value("voice_client", sname, "name", account);
dmuci_set_value("voice_client", sname, "enabled", "0");
@ -577,9 +566,10 @@ int get_line_max_instance(struct uci_section **tel_section)
char *update_vp_line_instance(struct uci_section *tel_s, char *sipx)
{
struct uci_section *s = NULL, *dmmap_section= NULL, *dmmap_dup= NULL;
struct uci_section *s = NULL, *dmmap_section = NULL, *dmmap_dup = NULL;
int last_instance = 0, i_instance;
char *instance, buf[8];
get_dmmap_section_of_config_section("dmmap_voice_client", "tel_line", section_name(tel_s), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "lineinstance", &instance);
if(instance[0] != '\0'){
@ -594,7 +584,7 @@ char *update_vp_line_instance(struct uci_section *tel_s, char *sipx)
last_instance = i_instance;
}
}
sprintf(buf, "%d", last_instance + 1);
snprintf(buf, sizeof(buf), "%d", last_instance + 1);
instance = dmuci_set_value_by_section(dmmap_section, "lineinstance", buf);
return instance;
}
@ -618,17 +608,17 @@ char *update_vp_line_instance_alias(int action, char **last_inst, void *argv[])
last_instance = i_instance;
}
}
sprintf(buf, "%d", last_instance + 1);
snprintf(buf, sizeof(buf), "%d", last_instance + 1);
instance = dmuci_set_value_by_section(tel_s, "lineinstance", buf);
}
*last_inst = instance;
if (action == INSTANCE_MODE_ALIAS) {
dmuci_get_value_by_section_string(tel_s, "linealias", &alias);
if (alias[0] == '\0') {
sprintf(buf, "cpe-%s", instance);
snprintf(buf, sizeof(buf), "cpe-%s", instance);
alias = dmuci_set_value_by_section(tel_s, "linealias", buf);
}
sprintf(buf, "[%s]", alias);
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
return instance;
@ -643,17 +633,13 @@ int add_line(struct uci_section *s, char *s_name)
int add_line_object(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
int i;
char *value, *v, *voice_profile_key;
char instance[4];
char call_lines[16] = {0};
char *value, *v, *voice_profile_key, call_lines[16] = {0};
struct uci_section *s = NULL;
struct sip_args *sipargs = (struct sip_args *)data;
struct uci_section *dmmap_voice_line_section, *dmmap_section;
int last_instance;
check_create_dmmap_package("dmmap_voice_client");
i = get_line_max_instance(&s);
int i = get_line_max_instance(&s);
if (i == 0)
return FAULT_9004;
add_line(s, section_name(sipargs->sip_section));
@ -662,13 +648,13 @@ int add_line_object(char *refparam, struct dmctx *ctx, void *data, char **instan
get_dmmap_section_of_config_section("dmmap_voice_client", "sip_service_provider", section_name(sipargs->sip_section), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "profileinstance", &voice_profile_key);
dmuci_set_value_by_section(dmmap_voice_line_section, "voice_profile_key", voice_profile_key);
*instancepara = update_vp_line_instance(s, section_name(sipargs->sip_section)); //TODO: To Check
*instancepara = update_vp_line_instance(s, section_name(sipargs->sip_section));
dmuci_get_value_by_section_string(sipargs->sip_section, "call_lines", &value);
if (value[0] == '\0') {
sprintf(call_lines, "%d", i - 1);
snprintf(call_lines, sizeof(call_lines), "%d", i - 1);
}
else {
sprintf(call_lines, "%s %d", value, i - 1);
snprintf(call_lines, sizeof(call_lines), "%s %d", value, i - 1);
}
dmuci_set_value_by_section(sipargs->sip_section, "call_lines", call_lines);
return 0;
@ -676,12 +662,11 @@ int add_line_object(char *refparam, struct dmctx *ctx, void *data, char **instan
int delete_line(struct uci_section *line_section, struct uci_section *sip_section)
{
int len, found =0;
char *section_name, *line_id, *value = NULL;
char *line_section_name, *line_id, *value = NULL;
char *pch, *spch, *call_lines, *p, new_call_lines[34] = {0};
section_name = section_name(line_section);
line_id = section_name + strlen(section_name) - 1;
line_section_name = section_name(line_section);
line_id = line_section_name + strlen(line_section_name) - 1;
dmuci_set_value_by_section(line_section, "sip_account", "-");
dmuci_set_value_by_section(line_section, "lineinstance", "");
dmuci_set_value_by_section(line_section, "linealias", "");
@ -708,7 +693,6 @@ int delete_line(struct uci_section *line_section, struct uci_section *sip_sectio
int delete_line_object(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
char *s_name;
struct uci_section *s;
struct sip_args *sipargs;
@ -834,9 +818,8 @@ int get_capabilities_sip_codec(char *refparam, struct dmctx *ctx, void *data, ch
{
int i;
struct codec_args *cdcargs = (struct codec_args *)data;
bool sep = false;
for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) {
if(capabilities_sip_codecs[i].enumid == cdcargs->enumid) {
if (capabilities_sip_codecs[i].enumid == cdcargs->enumid) {
*value = capabilities_sip_codecs[i].c2;
break;
}
@ -849,7 +832,7 @@ int get_capabilities_sip_bitrate(char *refparam, struct dmctx *ctx, void *data,
int i;
struct codec_args *cdcargs = (struct codec_args *)data;
for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) {
if(capabilities_sip_codecs[i].enumid == cdcargs->enumid) {
if (capabilities_sip_codecs[i].enumid == cdcargs->enumid) {
*value = capabilities_sip_codecs[i].c3;
break;
}
@ -862,7 +845,7 @@ int get_capabilities_sip_pperiod(char *refparam, struct dmctx *ctx, void *data,
int i;
struct codec_args *cdcargs = (struct codec_args *)data;
for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) {
if(capabilities_sip_codecs[i].enumid == cdcargs->enumid) {
if (capabilities_sip_codecs[i].enumid == cdcargs->enumid) {
*value = capabilities_sip_codecs[i].c4;
break;
}
@ -980,8 +963,7 @@ int get_voice_profile_number_of_lines(char *refparam, struct dmctx *ctx, void *d
*value = "0";
dmubus_call("voice.asterisk", "status", UBUS_ARGS{}, 0, &res);
if (!res)
return 0;
DM_ASSERT(res, *value = "0");
uci_foreach_option_eq("voice_client", "tel_line", "sip_account", section_name(sipargs->sip_section), b_section) {
jobj = dmjson_get_obj(res, 2, "tel", section_name(b_section));
if (jobj)
@ -1257,7 +1239,6 @@ int get_sip_re_invite_expires(char *refparam, struct dmctx *ctx, void *data, cha
int set_sip_re_invite_expires(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
switch (action) {
case VALUECHECK:
return 0;
@ -1427,8 +1408,6 @@ int get_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, void *da
int set_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
switch (action) {
case VALUECHECK:
return 0;
@ -1624,35 +1603,33 @@ int set_line_directory_number(char *refparam, struct dmctx *ctx, void *data, cha
int get_voice_profile_line_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *status, *sip_name, *q;
json_object *res;
char buf[64];
struct tel_args *telargs = (struct tel_args *)data;
*value = "Disabled";
sip_name = section_name(telargs->sip_section);
q = buf;
dmstrappendstr(q, "asterisk");
dmstrappendchr(q, '.');
dmstrappendstr(q, "sip");
dmstrappendchr(q, '.');
dmstrappendstr(q, section_name(telargs->sip_section) + 3);
dmstrappendend(q);
dmubus_call(buf, "status", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "Disabled");
if(res) {
status = dmjson_get_value(res, 1, "registered");
if (strcasecmp(status, "true") == 0) {
*value = "Up";
}
else {
status = dmjson_get_value(res, 1, "registry_request_sent");
if(strcasecmp(status, "true") == 0)
*value = "Registering";
else
*value = "Disabled";
}
char *status, *q;
json_object *res;
char buf[64];
struct tel_args *telargs = (struct tel_args *)data;
*value = "Disabled";
q = buf;
dmstrappendstr(q, "asterisk");
dmstrappendchr(q, '.');
dmstrappendstr(q, "sip");
dmstrappendchr(q, '.');
dmstrappendstr(q, section_name(telargs->sip_section) + 3);
dmstrappendend(q);
dmubus_call(buf, "status", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "Disabled");
if(res) {
status = dmjson_get_value(res, 1, "registered");
if (strcasecmp(status, "true") == 0) {
*value = "Up";
} else {
status = dmjson_get_value(res, 1, "registry_request_sent");
if(strcasecmp(status, "true") == 0)
*value = "Registering";
else
*value = "Disabled";
}
return 0;
}
return 0;
}
int get_voice_profile_line_callstate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
@ -1713,7 +1690,7 @@ int set_line_line_profile(char *refparam, struct dmctx *ctx, void *data, char *i
}
else {
str = (section_name(telargs->tel_section) + strlen(section_name(telargs->tel_section)) - 1);
sprintf(call_lines, "%s %s", value, str);
snprintf(call_lines, sizeof(call_lines), "%s %s", value, str);
dmuci_set_value_by_section(sip_s, "call_lines", call_lines);
}
return 0;
@ -1744,7 +1721,7 @@ int set_line_tel_line(char *refparam, struct dmctx *ctx, void *data, char *insta
case VALUESET:
memset(line_name, '\0', sizeof(line_name));
strncpy(line_name, section_name(telargs->tel_section), strlen(section_name(telargs->tel_section)) - 1);
sprintf(bname, "%s%s", line_name, value);
snprintf(bname, sizeof(bname), "%s%s", line_name, value);
error = dmuci_get_section_type("voice_client", bname, &stype);
if(error)
return 0;
@ -1957,7 +1934,6 @@ int set_line_sip_uri(char *refparam, struct dmctx *ctx, void *data, char *instan
}
/******************Line codec ***************************************/
int codec_compare(const void *s1, const void *s2)
{
struct codec *sc1 = (struct codec *)s1;
@ -1969,8 +1945,8 @@ int codec_compare(const void *s1, const void *s2)
void codec_priority_sort(struct uci_section *sip_section, char *new_codec)
{
int j, k = 0, h = 0, size = ARRAY_SIZE(codec_option_array);
char *ucodec, *coption, *poption;
int j, k = 0, size = ARRAY_SIZE(codec_option_array);
char *ucodec;
bool found;
struct codec sipcodec[ARRAY_SIZE(codec_option_array)+1] = {0};
struct uci_section *dmmap_section;
@ -2041,7 +2017,7 @@ void codec_priority_update(struct uci_section *sip_section)
}
}
if (found)
sprintf(pid, "%d", j+1);
snprintf(pid, sizeof(pid), "%d", j+1);
dmuci_set_value_by_section(dmmap_section, allowed_sip_codecs[i].priority_cdc, pid);
}
codec_priority_sort(sip_section, NULL);
@ -2390,11 +2366,11 @@ int browseCodecsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
/*#Device.Services.VoiceService.{i}.VoiceProfile.{i}.!UCI:voice_client/sip_service_provider/dmmap_voice_client*/
int browseProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *sip_section;
char *profile_num = NULL, *profile_num_last = NULL;
struct sip_args curr_sip_args = {0};
struct dmmap_dup *p;
LIST_HEAD(dup_list);
wait_voice_service_up();
synchronize_specific_config_sections_with_dmmap("voice_client", "sip_service_provider", "dmmap_voice_client", &dup_list);
list_for_each_entry(p, &dup_list, list) {
@ -2412,8 +2388,6 @@ int browseLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, ch
{
int maxLine, line_id = 0;
char *line_num = NULL, *last_inst = NULL;
struct uci_section *b_section = NULL;
json_object *res, *jobj;
struct sip_args *sipargs = (struct sip_args *)prev_data;
struct tel_args curr_tel_args = {0};
struct dmmap_dup *p;

View file

@ -14,6 +14,8 @@
#ifndef __VOICE_H
#define __VOICE_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tServicesObj[];
extern DMOBJ tServicesVoiceServiceObj[];
extern DMLEAF tServicesVoiceServiceParams[];

View file

@ -9,14 +9,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "diagnostics.h"
@ -931,6 +923,7 @@ int set_IPDiagnosticsDownloadDiagnostics_Interface(char *refparam, struct dmctx
adm_entry_get_linker_value(ctx, value, &linker);
if (linker) {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", linker, String}}, 1, &res);
if (!res) return 0;
device = dmjson_get_value(res, 1, "device");
if (device) {
DOWNLOAD_DIAGNOSTIC_STOP
@ -1320,6 +1313,7 @@ int set_IPDiagnosticsUploadDiagnostics_Interface(char *refparam, struct dmctx *c
adm_entry_get_linker_value(ctx, value, &linker);
if (linker) {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", linker, String}}, 1, &res);
if (!res) return 0;
device = dmjson_get_value(res, 1, "device");
if (device) {
UPLOAD_DIAGNOSTIC_STOP

View file

@ -12,6 +12,8 @@
#ifndef __DIAGNOSTICS_H
#define __DIAGNOSTICS_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tIPDiagnosticsObj[];
extern DMLEAF tIPDiagnosticsParams[];
extern DMLEAF tIPDiagnosticsIPPingParams[];

View file

@ -8,12 +8,6 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
//#include "dmentry.h"
#include "bulkdata.h"
/* *** Device.BulkData. *** */
@ -130,8 +124,8 @@ DMLEAF tBulkDataProfileHTTPRequestURIParameterParams[] = {
};
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
/*#Device.BulkData.Profile.{i}.!UCI:cwmp_bulkdata/profile/dmmap_cwmp_profile*/
int browseBulkDataProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
@ -183,8 +177,8 @@ int browseBulkDataProfileHTTPRequestURIParameterInst(struct dmctx *dmctx, DMNODE
}
/*************************************************************
* ADD & DEL OBJ
/*************************************************************/
* ADD & DEL OBJ
*************************************************************/
int addObjBulkDataProfile(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *profile;
@ -287,7 +281,7 @@ int addObjBulkDataProfileParameter(char *refparam, struct dmctx *ctx, void *data
int delObjBulkDataProfileParameter(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *s, *ss = NULL, *profile_section = (struct uci_section *)data;;
struct uci_section *s, *ss = NULL, *profile_section = (struct uci_section *)data;
char *prev_profile_id;
switch (del_action) {
@ -326,7 +320,7 @@ int addObjBulkDataProfileHTTPRequestURIParameter(char *refparam, struct dmctx *c
int delObjBulkDataProfileHTTPRequestURIParameter(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *s, *ss = NULL, *profile_section = (struct uci_section *)data;;
struct uci_section *s, *ss = NULL, *profile_section = (struct uci_section *)data;
char *prev_profile_id;
switch (del_action) {
@ -349,8 +343,8 @@ int delObjBulkDataProfileHTTPRequestURIParameter(char *refparam, struct dmctx *c
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
*************************************************************/
/*#Device.BulkData.Enable!UCI:cwmp_bulkdata/bulkdata,bulkdata/enable*/
int get_BulkData_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
@ -608,7 +602,7 @@ int set_BulkDataProfile_TimeReference(char *refparam, struct dmctx *ctx, void *d
case VALUESET:
if (!(strptime(value, "%Y-%m-%dT%H:%M:%S", &tm)))
break;
sprintf(buf, "%ld", mktime(&tm));
snprintf(buf, sizeof(buf), "%ld", mktime(&tm));
dmuci_set_value_by_section((struct uci_section *)data, "time_reference", buf);
break;
}

View file

@ -11,6 +11,8 @@
#ifndef __BULKDATA_H
#define __BULKDATA_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tBulkDataObj[];
extern DMLEAF tBulkDataParams[];
extern DMOBJ tBulkDataProfileObj[];

View file

@ -8,11 +8,6 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "softwaremodules.h"
@ -138,8 +133,8 @@ int get_du_linker(char *refparam, struct dmctx *dmctx, void *data, char *instanc
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
int browseSoftwareModulesExecEnvInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
@ -199,8 +194,8 @@ int browseSoftwareModulesExecutionUnitInst(struct dmctx *dmctx, DMNODE *parent_n
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
*************************************************************/
int get_SoftwareModules_ExecEnvNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *environment = NULL;
@ -479,7 +474,7 @@ int get_SoftwareModulesExecEnv_AvailableMemory(char *refparam, struct dmctx *ctx
int get_SoftwareModulesExecEnv_ActiveExecutionUnits(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
int id = 0, j = 0, env = 0;
int j = 0, env = 0;
char *environment, *eu_list = NULL, *eu_list_tmp = NULL;
char *curr_env = dmjson_get_value((json_object *)data, 1, "name");
@ -968,11 +963,11 @@ char *get_deployment_unit_reference(struct dmctx *ctx, char *package_name, char
void get_deployment_unit_name_version(char *uuid, char **name, char **version, char **env)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
int id = 0, j = 0, i, incr;
int j = 0, i, incr;
char *cur_uuid, buf[5];
for (i = 0;; i += 100) {
sprintf(buf, "%d", i);
snprintf(buf, sizeof(buf), "%d", i);
dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res);
if (res) {
incr = 0;
@ -995,11 +990,11 @@ void get_deployment_unit_name_version(char *uuid, char **name, char **version, c
char *get_softwaremodules_uuid(char *url)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
int id = 0, j = 0, i, incr;
int j = 0, i, incr;
char *cur_url, *uuid = "", buf[5];
for (i = 0;; i += 100) {
sprintf(buf, "%d", i);
snprintf(buf, sizeof(buf), "%d", i);
dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res);
if (res) {
incr = 0;
@ -1021,11 +1016,11 @@ char *get_softwaremodules_uuid(char *url)
char *get_softwaremodules_url(char *uuid)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
int id = 0, j = 0, i, incr;
int j = 0, i, incr;
char *cur_uuid, *url = "", buf[5];
for (i = 0;; i += 100) {
sprintf(buf, "%d", i);
snprintf(buf, sizeof(buf), "%d", i);
dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res);
if (res) {
incr = 0;

View file

@ -11,6 +11,8 @@
#ifndef __SOFTWAREMODULES_H
#define __SOFTWAREMODULES_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tSoftwareModulesObj[];
extern DMLEAF tSoftwareModulesParams[];
extern DMLEAF tSoftwareModulesExecEnvParams[];

View file

@ -9,13 +9,6 @@
*
*/
#include <ctype.h>
#include <uci.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "atm.h"
@ -95,7 +88,6 @@ int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, c
int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *vpi = NULL, *vci = NULL, *spch, *val;
struct uci_section *s;
switch (action) {
case VALUECHECK:
@ -136,8 +128,7 @@ int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *i
dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "encapsulation", &encapsulation);
if (strcasecmp(encapsulation, "vcmux") == 0) {
*value = "VCMUX";
}
else if (strcasecmp(encapsulation, "llc") == 0) {
} else if (strcasecmp(encapsulation, "llc") == 0) {
*value = "LLC";
} else {
*value = "";
@ -189,15 +180,16 @@ int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *insta
int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char linker[16];
sprintf(linker, "channel_%d", atoi(instance)-1);
snprintf(linker, sizeof(linker), "channel_%d", atoi(instance)-1);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cChannel%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
return 0;
}
static inline int ubus_atm_stats(json_object *res, char **value, char *stat_mod, void *data)
static inline int ubus_atm_stats(char **value, char *stat_mod, void *data)
{
json_object *res = NULL;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct atm_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", stat_mod);
@ -207,32 +199,28 @@ static inline int ubus_atm_stats(json_object *res, char **value, char *stat_mod,
/*#Device.ATM.Link.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/
int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_atm_stats(res, value, "rx_bytes", data);
ubus_atm_stats(value, "rx_bytes", data);
return 0;
}
/*#Device.ATM.Link.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_atm_stats(res, value, "tx_bytes", data);
ubus_atm_stats(value, "tx_bytes", data);
return 0;
}
/*#Device.ATM.Link.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/
int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_atm_stats(res, value, "rx_packets", data);
ubus_atm_stats(value, "rx_packets", data);
return 0;
}
/*#Device.ATM.Link.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/
int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_atm_stats(res, value, "tx_packets", data);
ubus_atm_stats(value, "tx_packets", data);
return 0;
}
@ -243,8 +231,8 @@ int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance
}
/*************************************************************
* ADD OBJ
/*************************************************************/
* ADD OBJ
*************************************************************/
int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *instance = NULL, *atm_device = NULL, *v = NULL, *instance_update = NULL;
@ -325,14 +313,14 @@ int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instanc
}
/*************************************************************
* SET AND GET ALIAS
/*************************************************************/
* SET AND GET ALIAS
*************************************************************/
int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "atmlinkalias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "atmlinkalias", value);
return 0;
}
@ -345,15 +333,15 @@ int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance,
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "atmlinkalias", value);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "atmlinkalias", value);
return 0;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
/*#Device.ATM.Link.{i}.!UCI:dsl/atm-device/dmmap_dsl*/
int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{

View file

@ -12,6 +12,8 @@
#ifndef __ATM_H
#define __ATM_H
#include <libbbf_api/dmcommon.h>
struct atm_args
{
struct uci_section *atm_sec;

View file

@ -10,13 +10,6 @@
*
*/
#include <ctype.h>
#include <uci.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "bridging.h"
@ -134,7 +127,8 @@ DMLEAF tBridgingBridgeVLANPortParams[] = {
/**************************************************************************
* LINKER
***************************************************************************/
int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) {
int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{
if(data && ((struct bridging_port_args *)data)->bridge_port_sec) {
dmasprintf(linker,"%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname);
return 0;
@ -143,7 +137,8 @@ int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *in
return 0;
}
int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) {
int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{
if(data && ((struct bridging_vlan_args *)data)->vlan_port) {
dmasprintf(linker,"vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst);
return 0;
@ -208,6 +203,7 @@ int check_ifname_exist_in_br_ifname_list(char *ifname)
{
char *br_ifname_list, *br_ifname_dup, *pch, *spch;
struct uci_section *s;
uci_foreach_option_eq("network", "interface", "type", "bridge", s) {
dmuci_get_value_by_section_string(s, "ifname", &br_ifname_list);
if(br_ifname_list[0] == '\0')
@ -224,16 +220,15 @@ int check_ifname_exist_in_br_ifname_list(char *ifname)
int get_br_port_last_inst(char *br_key)
{
char *tmp;
int max=1;
int instance, max = 1;
struct uci_section *s;
int instance;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_key, s) {
dmuci_get_value_by_section_string(s, "bridge_port_instance", &tmp);
if (tmp[0] == '\0')
continue;
instance = atoi(tmp);
if(instance>max) max=instance;
if (instance > max) max = instance;
}
return max;
}
@ -242,20 +237,19 @@ int reset_br_port(char *br_key)
{
struct uci_section *s, *prev_s = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_key, s){
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", br_key, s) {
if (prev_s)
dmuci_delete_by_section(prev_s, NULL, NULL);
prev_s = s;
}
if (prev_s)
dmuci_delete_by_section(prev_s, NULL, NULL);
if (prev_s) dmuci_delete_by_section(prev_s, NULL, NULL);
return 0;
}
int check_ifname_is_not_lan_port(char *ifname)
{
struct uci_section *s;
if (!strstr(ifname, wan_baseifname)) {
uci_foreach_option_eq("ports", "ethport", "ifname", ifname, s) {
return 0;
@ -267,6 +261,7 @@ int check_ifname_is_not_lan_port(char *ifname)
int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *mg_port)
{
struct uci_section *s, *dmmap_section;
if (check_ifname_is_vlan(linker)) {
uci_foreach_option_eq("network", "device", "ifname", linker, s) {
get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(s), &dmmap_section);
@ -349,11 +344,11 @@ static int update_br_port_ifname(struct bridging_port_args *curr_arg, int status
if (ifname_dup[0] != '\0') dmstrappendchr(ptr, ' ');
dmstrappendstr(ptr, baseifname);
dmstrappendend(ptr);
}else{
if (is_strword_in_optionvalue(ifname_dup, baseifname)){
} else {
if (is_strword_in_optionvalue(ifname_dup, baseifname)) {
start = strstr(ifname_dup, baseifname);
end = start + strlen(baseifname);
if(start != ifname_dup){
if (start != ifname_dup) {
start--;
pos=1;
}
@ -481,8 +476,7 @@ int get_br_port_number_of_entries(char *refparam, struct dmctx *ctx, void *data,
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", instance, s)
{
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "bridge_key", instance, s) {
cnt++;
}
dmasprintf(value, "%d", cnt);
@ -494,8 +488,7 @@ int get_br_vlan_number_of_entries(char *refparam, struct dmctx *ctx, void *data,
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s)
{
uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s) {
cnt++;
}
dmasprintf(value, "%d", cnt);
@ -507,8 +500,7 @@ int get_br_vlan_port_number_of_entries(char *refparam, struct dmctx *ctx, void *
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s)
{
uci_path_foreach_option_eq(bbfdm, "dmmap_network", "device", "bridge_key", instance, s) {
cnt++;
}
dmasprintf(value, "%d", cnt);
@ -608,11 +600,10 @@ int get_br_port_last_change(char *refparam, struct dmctx *ctx, void *data, char
int get_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section= NULL;
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section);
if(dmmap_section==NULL || dmmap_section==0)
dmmap_section= ((struct bridging_port_args *)data)->bridge_port_sec;
if (!dmmap_section) dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec;
dmuci_get_value_by_section_string(dmmap_section, "mg_port", value);
return 0;
}
@ -644,7 +635,7 @@ int get_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instan
{
char *name;
dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name);
if(check_if_ifname_is_tagged(name) != NULL)
if (check_if_ifname_is_tagged(name) != NULL)
*value = "CustomerVLANPort";
else
*value = "";
@ -665,14 +656,14 @@ int set_br_port_type(char *refparam, struct dmctx *ctx, void *data, char *instan
int get_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *name, *type, *priority;
char *name, *type;
*value = "";
dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name);
s = check_if_ifname_is_tagged(name);
if(s != NULL) {
if (s != NULL) {
dmuci_get_value_by_section_string(s, "type", &type);
if(strcmp(type, "untagged") != 0)
if (strcmp(type, "untagged") != 0)
dmuci_get_value_by_section_string(s, "priority", value);
}
return 0;
@ -681,7 +672,7 @@ int get_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *d
int set_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s = NULL;
char *name, *type, *priority;
char *name, *type;
switch (action) {
case VALUECHECK:
@ -689,9 +680,9 @@ int set_br_port_default_user_priority(char *refparam, struct dmctx *ctx, void *d
case VALUESET:
dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name);
s = check_if_ifname_is_tagged(name);
if(s != NULL) {
if (s != NULL) {
dmuci_get_value_by_section_string(s, "type", &type);
if(strcmp(type, "untagged") != 0)
if (strcmp(type, "untagged") != 0)
dmuci_set_value_by_section(s, "priority", value);
}
return 0;
@ -720,7 +711,7 @@ int get_br_port_port_state(char *refparam, struct dmctx *ctx, void *data, char *
{
char *name;
dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name);
if(check_if_ifname_is_tagged(name) != NULL)
if (check_if_ifname_is_tagged(name) != NULL)
*value = "Forwarding";
else
*value = "Disabled";
@ -730,14 +721,14 @@ int get_br_port_port_state(char *refparam, struct dmctx *ctx, void *data, char *
int get_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *name, *type, *priority;
char *name, *type;
*value = "1";
dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name);
s = check_if_ifname_is_tagged(name);
if(s != NULL) {
if (s != NULL) {
dmuci_get_value_by_section_string(s, "type", &type);
if(strcmp(type, "untagged") != 0)
if (strcmp(type, "untagged") != 0)
dmuci_get_value_by_section_string(s, "vid", value);
}
return 0;
@ -746,7 +737,7 @@ int get_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instan
int set_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s = NULL;
char *name, *type, *priority, *ifname, *new_name;
char *name, *type, *ifname, *new_name;
int is_enabled;
switch (action) {
@ -755,17 +746,17 @@ int set_br_port_pvid(char *refparam, struct dmctx *ctx, void *data, char *instan
case VALUESET:
dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", &name);
s = check_if_ifname_is_tagged(name);
if(s != NULL) {
if (s != NULL) {
dmuci_get_value_by_section_string(s, "type", &type);
if(strcmp(type, "untagged") != 0) {
if (strcmp(type, "untagged") != 0) {
dmuci_set_value_by_section(s, "vid", value);
dmuci_get_value_by_section_string(s, "ifname", &ifname);
dmasprintf(&new_name, "%s.%s", ifname, value);
is_enabled = is_br_port_enabled((struct bridging_port_args *)data);
if(is_enabled)
if (is_enabled)
update_br_port_ifname((struct bridging_port_args *)data, 0);
dmuci_set_value_by_section(s, "name", new_name);
if(is_enabled)
if (is_enabled)
update_br_port_ifname((struct bridging_port_args *)data, 1);
dmfree(new_name);
}
@ -942,12 +933,12 @@ int get_br_port_stats_rx_unknown_proto_packets(char *refparam, struct dmctx *ctx
static int is_bridge_vlan_enabled(struct bridging_vlan_args *curr_arg)
{
struct uci_section *vlan_sec = curr_arg->bridge_vlan_sec, *br_sec = curr_arg->bridge_sec;
char *ifname, *br_ifname, *ifname_dup, *pch, *spch;
char *ifname, *br_ifname, *ifname_dup;
dmuci_get_value_by_section_string(br_sec, "ifname", &br_ifname);
dmuci_get_value_by_section_string(vlan_sec, "name", &ifname);
ifname_dup = dmstrdup(br_ifname);
if(ifname!=NULL && ifname[0]!='\0'){
if (ifname != NULL && ifname[0] != '\0') {
if (is_strword_in_optionvalue(ifname_dup, ifname))
return 1;
}
@ -964,16 +955,16 @@ static int update_br_vlan_ifname(struct bridging_vlan_args *curr_arg, int status
ptr = ifname_dup;
dmstrappendstr(ptr, ifname);
dmstrappendend(ptr);
if(status){
if (status) {
if (is_strword_in_optionvalue(ifname_dup, baseifname)) return 0;
if (ifname_dup[0] != '\0') dmstrappendchr(ptr, ' ');
dmstrappendstr(ptr, baseifname);
dmstrappendend(ptr);
}else{
if (is_strword_in_optionvalue(ifname_dup, baseifname)){
} else {
if (is_strword_in_optionvalue(ifname_dup, baseifname)) {
start = strstr(ifname_dup, baseifname);
end = start + strlen(baseifname);
if(start != ifname_dup){
if (start != ifname_dup) {
start--;
pos=1;
}
@ -997,10 +988,8 @@ int get_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *inst
int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
char *vlan_ifname, *br_ifname, *vid, *p;
char new_ifname[256];
char pr_linker[32];
int is_enabled;
switch (action) {
case VALUECHECK:
if (string_to_bool(value, &b))
@ -1012,7 +1001,7 @@ int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *inst
if (b && !is_enabled) {
update_br_vlan_ifname((struct bridging_vlan_args *)data, 1);
}
if (!b && is_enabled){
if (!b && is_enabled) {
update_br_vlan_ifname((struct bridging_vlan_args *)data, 0);
}
return 0;
@ -1022,7 +1011,6 @@ int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *inst
int get_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "";
*value = dmstrdup(section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec));
return 0;
}
@ -1041,14 +1029,13 @@ int set_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instan
int get_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "0";
dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vid", value);
return 0;
}
int set_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *name, *br_ifname, *ifname;
char *name, *ifname;
int is_enabled;
switch (action) {
@ -1072,7 +1059,6 @@ int set_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instanc
int get_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "0";
dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "priority", value);
return 0;
}
@ -1089,14 +1075,14 @@ int set_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *in
return 0;
}
/*************************************************************
* GET SET ALIAS
/*************************************************************/
* GET SET ALIAS
**************************************************************/
int get_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "bridge_alias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "bridge_alias", value);
return 0;
}
@ -1109,7 +1095,7 @@ int set_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance,
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct bridging_args *)data)->bridge_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "bridge_alias", value);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "bridge_alias", value);
return 0;
}
return 0;
@ -1117,28 +1103,24 @@ int set_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance,
int get_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section= NULL;
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section);
if(dmmap_section==NULL || dmmap_section==0)
dmmap_section= ((struct bridging_port_args *)data)->bridge_port_sec;
if (!dmmap_section) dmmap_section= ((struct bridging_port_args *)data)->bridge_port_sec;
dmuci_get_value_by_section_string(dmmap_section, "bridge_port_alias", value);
return 0;
}
int set_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section= NULL;
get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section);
if(dmmap_section==NULL || dmmap_section==0)
dmmap_section= ((struct bridging_port_args *)data)->bridge_port_sec;
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section);
if(!dmmap_section) dmmap_section= ((struct bridging_port_args *)data)->bridge_port_sec;
dmuci_set_value_by_section(dmmap_section, "bridge_port_alias", value);
return 0;
}
@ -1150,7 +1132,7 @@ int get_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *insta
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "bridge_vlan_alias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "bridge_vlan_alias", value);
return 0;
}
@ -1163,15 +1145,15 @@ int set_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *insta
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_network", "device", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "bridge_vlan_alias", value);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "bridge_vlan_alias", value);
return 0;
}
return 0;
}
/*************************************************************
* ADD DELETE OBJECT
/*************************************************************/
* ADD DELETE OBJECT
**************************************************************/
int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *last_inst, *v;
@ -1180,7 +1162,7 @@ int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance)
struct uci_section* dmmap_bridge= NULL;
last_inst = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "bridge_instance", "type", "bridge");
sprintf(ib, "%d", last_inst ? atoi(last_inst)+1 : 1);
snprintf(ib, sizeof(ib), "%d", last_inst ? atoi(last_inst)+1 : 1);
dmstrappendstr(p, "bridge_0_");
dmstrappendstr(p, ib);
dmstrappendend(p);
@ -1198,8 +1180,7 @@ int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance)
int delete_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *prev_s = NULL;
struct uci_section *bridge_s, *vlan_s, *dmmap_section= NULL;
struct uci_section *s = NULL, *prev_s = NULL, *bridge_s, *dmmap_section = NULL;
char *bridgekey = NULL;
switch (del_action) {
@ -1335,13 +1316,12 @@ int delete_br_port(char *refparam, struct dmctx *ctx, void *data, char *instance
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_bridge_port", "bridge_port", section_name(((struct bridging_port_args *)data)->bridge_port_sec), &dmmap_section);
if(dmmap_section==NULL || dmmap_section==0){
dmmap_section= ((struct bridging_port_args *)data)->bridge_port_sec;
if (!dmmap_section) {
dmmap_section = ((struct bridging_port_args *)data)->bridge_port_sec;
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
}
else{
} else {
dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname);
if(ifname[0] != '\0'){
if (ifname[0] != '\0') {
remove_interface_from_ifname(((struct bridging_port_args *)data)->ifname, ifname, new_ifname);
dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_sec, "ifname", new_ifname);
}
@ -1364,8 +1344,8 @@ int delete_br_port(char *refparam, struct dmctx *ctx, void *data, char *instance
}
/*************************************************************
* LOWER LAYER
/*************************************************************/
* LOWER LAYER
**************************************************************/
int check_port_with_ifname (char *ifname, struct uci_section **ss)
{
struct uci_section *sss, *s;
@ -1379,13 +1359,12 @@ int check_port_with_ifname (char *ifname, struct uci_section **ss)
*ss = s;
break;
}
}
else if (strncmp(ifname, "ptm", 3) == 0) {
if(access( file_config_name, F_OK ) != -1){
} else if (strncmp(ifname, "ptm", 3) == 0) {
if (access( file_config_name, F_OK ) != -1) {
uci_foreach_sections("dsl", "ptm-device", sss) {
dmuci_get_value_by_section_string(sss, "device", &ptm_device);
dmasprintf(&ptm_device, "%s.1", ptm_device);
if(strcmp(ifname, ptm_device)==0) {
if (strcmp(ifname, ptm_device) == 0) {
uci_foreach_option_eq("network", "device", "name", ifname, s) {
*ss = s;
break;
@ -1393,13 +1372,12 @@ int check_port_with_ifname (char *ifname, struct uci_section **ss)
}
}
}
}
else if (strncmp(ifname, "atm", 3) == 0) {
if(access( file_config_name, F_OK ) != -1){
} else if (strncmp(ifname, "atm", 3) == 0) {
if (access( file_config_name, F_OK ) != -1) {
uci_foreach_sections("dsl", "atm-device", sss) {
dmuci_get_value_by_section_string(sss, "device", &atm_device);
dmasprintf(&atm_device, "%s.1", atm_device);
if(strcmp(ifname, atm_device)==0) {
if (strcmp(ifname, atm_device) == 0) {
uci_foreach_option_eq("network", "device", "name", ifname, s) {
*ss = s;
break;
@ -1407,20 +1385,17 @@ int check_port_with_ifname (char *ifname, struct uci_section **ss)
}
}
}
}
else if(strncmp(ifname, wan_baseifname, strlen(wan_baseifname))==0) {
} else if (strncmp(ifname, wan_baseifname, strlen(wan_baseifname)) == 0) {
uci_foreach_option_eq("network", "device", "name", ifname, s) {
*ss = s;
break;
}
}
else if(strncmp(ifname, "wl", 2) == 0 || strncmp(ifname, "ra", 2) == 0 || strncmp(ifname, "apclii", 6) == 0) {
} else if (strncmp(ifname, "wl", 2) == 0 || strncmp(ifname, "ra", 2) == 0 || strncmp(ifname, "apclii", 6) == 0) {
uci_foreach_option_eq("wireless", "wifi-iface", "ifname", ifname, s) {
*ss = s;
break;
}
}
else {
} else {
uci_foreach_option_eq("ports", "ethport", "ifname", ifname, s) {
*ss = s;
break;
@ -1444,7 +1419,7 @@ int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *in
check_port_with_ifname(pch, &s);
if(s == NULL)
continue;
sprintf(plinker, "%s+%s", section_name(s), pch);
snprintf(plinker, sizeof(plinker), "%s+%s", section_name(s), pch);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), plinker, value);
if (*value == NULL)
*value = "";
@ -1482,7 +1457,7 @@ int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *in
int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker, *iface, *ifname, *p, *br_key, *br_pt_inst = "", *mg_port = "false", *br_port_ifname, *vid = NULL;
char *linker, *ifname, *p, *br_key, *br_pt_inst = "", *mg_port = "false", *vid = NULL;
char *newvalue= NULL;
char new_ifname[256];
char tmp[16];
@ -1519,7 +1494,7 @@ int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *in
delete_br_port(NULL, ctx, data, instance, DEL_INST);
}
// check if the current port is already linked with VLAN
sprintf(pr_linker,"%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname);
snprintf(pr_linker, sizeof(pr_linker), "%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname);
uci_foreach_option_eq("network", "device", "br_port_linker", pr_linker, s) {
dmuci_get_value_by_section_string(s, "vlan8021q", &vid);
break;
@ -1538,7 +1513,7 @@ int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *in
dmstrappendstr(p, tmp);
dmstrappendend(p);
uci_foreach_option_eq("network", "device", "br_port_linker", pr_linker, s) {
sprintf(pr_linker,"%s+%s", section_name(s), linker);
snprintf(pr_linker, sizeof(pr_linker), "%s+%s", section_name(s), linker);
dmuci_set_value_by_section(s, "br_port_linker", pr_linker);
dmuci_set_value_by_section(s, "ifname", linker);
dmuci_set_value_by_section(s, "penable", "1");
@ -1563,7 +1538,7 @@ int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *in
int get_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char linker[8];
sprintf(linker,"vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst);
snprintf(linker, sizeof(linker),"vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
@ -1585,7 +1560,7 @@ int get_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *
{
char linker[16], *name;
dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "name", &name);
sprintf(linker,"%s+%s", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), name);
snprintf(linker, sizeof(linker),"%s+%s", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), name);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
@ -1672,8 +1647,8 @@ int set_br_vlan_untagged(char *refparam, struct dmctx *ctx, void *data, char *in
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
/*#Device.Bridging.Bridge.{i}.!UCI:network/interface/dmmap_network*/
int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
@ -1731,13 +1706,13 @@ int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
for (pch = strtok_r(ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) {
found = false;
if(!found)
if (!found)
found= synchronize_multi_config_sections_with_dmmap_eq("ports", "ethport", "dmmap_bridge_port", "bridge_port", "ifname", pch, pch, &dup_list);
if(!found)
if (!found)
found= synchronize_multi_config_sections_with_dmmap_eq("wireless", "wifi-iface", "dmmap_bridge_port", "bridge_port", "ifname", pch, pch, &dup_list);
if(access( file_config_name, F_OK ) != -1) {
if (access( file_config_name, F_OK ) != -1) {
uci_foreach_sections("dsl", "atm-device", ss_atm) {
dmuci_get_value_by_section_string(ss_atm, "device", &deviceatm);
dmasprintf(&atm_device, "%s.1", deviceatm);
@ -1759,13 +1734,13 @@ int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
}
}
if(!found){
if (!found) {
if(strncmp(pch, wan_baseifname, strlen(wan_baseifname))==0) {
found= synchronize_multi_config_sections_with_dmmap_eq("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, pch, &dup_list);
}
}
if(!found){
if (!found) {
if(strncmp(pch, wan_baseifname, 4) == 0 || strncmp(pch, "ptm", 3) == 0 || strncmp(pch, "atm", 3) == 0){
found= synchronize_multi_config_sections_with_dmmap_eq_diff("network", "device", "dmmap_bridge_port", "bridge_port", "name", pch, "type", "untagged", pch, &dup_list);
}
@ -1795,7 +1770,7 @@ int browseBridgeVlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
LIST_HEAD(dup_list);
dmuci_get_value_by_section_string(br_args->bridge_sec, "is_lan", &is_lan);
if(is_lan == NULL || strcmp(is_lan, "1") != 0) {
if (is_lan == NULL || strcmp(is_lan, "1") != 0) {
synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if(!p->config_section)
@ -1826,7 +1801,7 @@ int browseBridgeVlanPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
LIST_HEAD(dup_list);
dmuci_get_value_by_section_string(br_args->bridge_sec, "is_lan", &is_lan);
if(is_lan==NULL || strcmp(is_lan, "1") != 0){
if (is_lan == NULL || strcmp(is_lan, "1") != 0) {
synchronize_specific_config_sections_with_dmmap("network", "device", "dmmap_network", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if(!p->config_section)

View file

@ -13,6 +13,8 @@
#ifndef __BRIDGING_H
#define __BRIDGING_H
#include <libbbf_api/dmcommon.h>
struct bridging_args
{
struct uci_section *bridge_sec;

View file

@ -11,7 +11,6 @@
#ifndef __DATAMODELVERSION_H
#define __DATAMODELVERSION_H
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
int get_Device_RootDataModelVersion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -10,8 +10,6 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmbbf.h>
#include "device.h"
#include "deviceinfo.h"
#include "managementserver.h"

View file

@ -13,6 +13,8 @@
#ifndef __DEVICE_H
#define __DEVICE_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tEntry181Obj[];
extern DMOBJ tRoot_181_Obj[];
extern DMLEAF tRoot_181_Params[];

View file

@ -9,19 +9,7 @@
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#include <ctype.h>
#include <uci.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/klog.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmcommon.h>
#include "deviceinfo.h"
#include <libbbf_api/dmjson.h>
#include <libbbf_api/dmubus.h>
/* *** Device.DeviceInfo. *** */
DMOBJ tDeviceInfoObj[] = {
@ -121,8 +109,8 @@ DMLEAF tDeviceInfoVendorLogFileParams[] = {
};
/*************************************************************
* INIT
/*************************************************************/
* INIT
**************************************************************/
inline int init_process_args(struct process_args *args, char *pid, char *command, char* size, char* priority, char *cputime, char *state)
{
args->pid = pid;
@ -146,48 +134,39 @@ char *get_deviceid_manufacturer()
char *get_deviceid_manufactureroui()
{
char *v;
char str[16];
char *mac = NULL;
char *v, *mac = NULL, str[16], macreadfile[18] = {0};
json_object *res;
FILE *nvrammac=NULL;
char macreadfile[18]={0};
FILE *nvrammac = NULL;
dmuci_get_option_value_string("cwmp", "cpe", "override_oui", &v);
if (v[0] == '\0')
{
dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res);
if(!(res)){
if (v[0] == '\0') {
dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res);
if (!(res)) {
db_get_value_string("hw", "board", "basemac", &mac);
if(!mac || strlen(mac)==0 ){
if ((nvrammac = fopen("/proc/nvram/BaseMacAddr", "r")) == NULL)
{
if (!mac || strlen(mac) == 0) {
if ((nvrammac = fopen("/proc/nvram/BaseMacAddr", "r")) == NULL) {
mac = NULL;
}
else{
fscanf(nvrammac,"%[^\n]", macreadfile);
macreadfile[17]='\0';
} else {
fscanf(nvrammac,"%17[^\n]", macreadfile);
macreadfile[17] = '\0';
sscanf(macreadfile,"%2c %2c %2c", str, str+2, str+4);
str[6]='\0';
str[6] = '\0';
v = dmstrdup(str); // MEM WILL BE FREED IN DMMEMCLEAN
fclose(nvrammac);
return v;
}
}
}
else
} else
mac = dm_ubus_get_value(res, 2, "system", "basemac");
if(mac)
{
if(mac) {
size_t ln = strlen(mac);
if (ln<17) goto not_found;
if (ln < 17) goto not_found;
sscanf (mac,"%2c:%2c:%2c",str,str+2,str+4);
str[6] = '\0';
v = dmstrdup(str); // MEM WILL BE FREED IN DMMEMCLEAN
return v;
}
else
} else
goto not_found;
}
return v;
@ -198,22 +177,15 @@ not_found:
char *get_deviceid_productclass()
{
char *v, *tmp, *val;
char *v;
dmuci_get_option_value_string("cwmp", "cpe", "override_productclass", &v);
if (v[0] == '\0')
{
if (v[0] == '\0') {
db_get_value_string("hw", "board", "iopVerBoard", &v);
tmp = dmstrdup(v);// MEM WILL BE FREED IN DMMEMCLEAN
val = tmp;
return val;
return v;
}
tmp = dmstrdup(v);// MEM WILL BE FREED IN DMMEMCLEAN
val = tmp;
return val;
return v;
}
char *get_deviceid_serialnumber()
{
char *v;
@ -223,12 +195,9 @@ char *get_deviceid_serialnumber()
char *get_softwareversion()
{
char *v, *tmp, *val;
char *v;
db_get_value_string("hw", "board", "iopVersion", &v);
tmp = dmstrdup(v);// MEM WILL BE FREED IN DMMEMCLEAN
val = tmp;
return val;
return v;
}
/*#Device.DeviceInfo.Manufacturer!UCI:cwmp/cwmp,cpe/manufacturer*/
@ -278,9 +247,8 @@ int get_device_routermodel(char *refparam, struct dmctx *ctx, void *data, char *
int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE* fp = NULL;
char *pch, *spch;
char buf[64];
FILE *fp = NULL;
char *pch, *spch, buf[64];
*value = "0";
fp = fopen(UPTIME, "r");
@ -342,7 +310,6 @@ int get_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, c
int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
switch (action) {
case VALUECHECK:
return 0;
@ -356,7 +323,6 @@ int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, c
int get_base_mac_addr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res);
DM_ASSERT(res, *value = "");
*value = dm_ubus_get_value(res, 2, "system", "basemac");
@ -366,7 +332,6 @@ int get_base_mac_addr(char *refparam, struct dmctx *ctx, void *data, char *insta
int get_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("router.system", "memory_bank", UBUS_ARGS{{}}, 0, &res);
DM_ASSERT(res, *value = "");
*value = dm_ubus_get_value(res, 1, "code");
@ -389,9 +354,8 @@ int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instan
{
char *catv;
dmuci_get_option_value_string("catv", "catv", "enable", &catv);
if (strcmp(catv, "on") == 0) {
if (strcmp(catv, "on") == 0)
*value = "1";
}
else
*value = "0";
return 0;
@ -421,11 +385,8 @@ int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *
int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
char *str;
*value = "";
dmubus_call("catv", "vpd", UBUS_ARGS{}, 0, &res);
if (!res)
return 0;
DM_ASSERT(res, *value = "");
*value = dm_ubus_get_value(res, 1, "VPD");
return 0;
}
@ -433,11 +394,8 @@ int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, void *data,
int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
char *str;
*value = "";
dmubus_call("catv", "rf", UBUS_ARGS{}, 0, &res);
if (!res)
return 0;
DM_ASSERT(res, *value = "");
*value = dm_ubus_get_value(res, 1, "RF");
return 0;
}
@ -445,11 +403,8 @@ int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, void *data, char
int get_catv_temperature(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
char *str;
*value = "";
dmubus_call("catv", "temp", UBUS_ARGS{}, 0, &res);
if (!res)
return 0;
DM_ASSERT(res, *value = "");
*value = dm_ubus_get_value(res, 1, "Temperature");
return 0;
}
@ -457,26 +412,21 @@ int get_catv_temperature(char *refparam, struct dmctx *ctx, void *data, char *in
int get_catv_voltage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
char *str;
*value = "";
dmubus_call("catv", "vcc", UBUS_ARGS{}, 0, &res);
if (!res)
return 0;
DM_ASSERT(res, *value = "");
*value = dm_ubus_get_value(res, 1, "VCC");
return 0;
}
int get_vcf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *vcf_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(vcf_sec, "name", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
return 0;
}
int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *vcf_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(vcf_sec, "version", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "version", value);
return 0;
}
@ -487,52 +437,48 @@ int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *instance,
struct stat attr;
char path[128];
char date[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
struct uci_section *vcf_sec = (struct uci_section *)data;
*value = "";
dmuci_get_value_by_section_string(vcf_sec, "name", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
if(strcmp(*value, d_file->d_name) == 0) {
sprintf(path, DEFAULT_CONFIG_DIR"%s", d_file->d_name);
snprintf(path, sizeof(path), DEFAULT_CONFIG_DIR"%s", d_file->d_name);
stat(path, &attr);
strftime(date, sizeof date, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&attr.st_mtime));
strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%S.000Z", localtime(&attr.st_mtime));
*value = dmstrdup(date);
}
}
closedir (dir);
closedir (dir);
}
return 0;
}
int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *vcf_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(vcf_sec, "backup_restore", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "backup_restore", value);
return 0;
}
int get_vcf_desc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *vcf_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(vcf_sec, "description", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "description", value);
return 0;
}
int get_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *vcf_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(vcf_sec, "vcf_alias", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "vcf_alias", value);
return 0;
}
int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *vcf_sec = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(vcf_sec, "vcf_alias", value);
dmuci_set_value_by_section((struct uci_section *)data, "vcf_alias", value);
return 0;
}
return 0;
@ -553,31 +499,29 @@ int check_file_dir(char *name)
struct dirent *d_file;
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
if(strcmp(name, d_file->d_name) == 0) {
if (strcmp(name, d_file->d_name) == 0) {
closedir(dir);
return 1;
}
}
closedir(dir);
closedir(dir);
}
return 0;
}
int get_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *sys_log_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(sys_log_sec, "vlf_alias", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "vlf_alias", value);
return 0;
}
int set_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *sys_log_sec = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(sys_log_sec, "vlf_alias", value);
dmuci_set_value_by_section((struct uci_section *)data, "vlf_alias", value);
return 0;
}
return 0;
@ -585,15 +529,13 @@ int set_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance,
int get_vlf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *sys_log_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(sys_log_sec, "log_file", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "log_file", value);
return 0;
}
int get_vlf_max_size (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *sys_log_sec = (struct uci_section *)data;
dmuci_get_value_by_section_string(sys_log_sec, "log_size", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "log_size", value);
*value = (**value) ? *value : "0";
return 0;
}
@ -608,8 +550,8 @@ int get_vlf_persistent(char *refparam, struct dmctx *ctx, void *data, char *inst
int get_memory_status_total(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res);
DM_ASSERT(res, *value = "0");
*value = dm_ubus_get_value(res, 2, "memoryKB", "total");
return 0;
}
@ -618,8 +560,8 @@ int get_memory_status_total(char* refparam, struct dmctx *ctx, void *data, char
int get_memory_status_free(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res);
DM_ASSERT(res, *value = "0");
*value = dm_ubus_get_value(res, 2, "memoryKB", "free");
return 0;
}
@ -628,8 +570,8 @@ int get_memory_status_free(char* refparam, struct dmctx *ctx, void *data, char *
int get_process_cpu_usage(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res);
DM_ASSERT(res, *value = "0");
*value = dm_ubus_get_value(res, 2, "system", "cpu_per");
return 0;
}
@ -640,65 +582,60 @@ int get_process_number_of_entries(char* refparam, struct dmctx *ctx, void *data,
int nbre_process = 0;
dmubus_call("router.system", "processes", UBUS_ARGS{{}}, 0, &res);
DM_ASSERT(res, *value = "0");
json_object_object_get_ex(res, "processes", &processes);
nbre_process= json_object_array_length(processes);
dmasprintf(value,"%d",nbre_process);
nbre_process = json_object_array_length(processes);
dmasprintf(value, "%d", nbre_process);
return 0;
}
int get_process_pid(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct process_args *proc_args= (struct process_args*) data;
*value= proc_args->pid;
*value = ((struct process_args *)data)->pid;
return 0;
}
int get_process_command(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct process_args *proc_args= (struct process_args*) data;
*value= proc_args->command;
*value = ((struct process_args *)data)->command;
return 0;
}
int get_process_size(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct process_args *proc_args= (struct process_args*) data;
if(proc_args->size!=NULL) *value= proc_args->size;
else *value= "0";
if (((struct process_args *)data)->size != NULL)
*value = ((struct process_args *)data)->size;
else
*value = "0";
return 0;
}
int get_process_priority(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct process_args *proc_args= (struct process_args*) data;
long val;
if(proc_args->priority!=NULL) {
val = atol(proc_args->priority);
if(val<0) val=0;
if (((struct process_args *)data)->priority != NULL) {
long val = atol(((struct process_args *)data)->priority);
if (val < 0) val = 0;
dmasprintf(value, "%ld", val);
}
else *value= "0";
} else
*value= "0";
return 0;
}
int get_process_cpu_time(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct process_args *proc_args= (struct process_args*) data;
if(proc_args->cputime!=NULL) *value= proc_args->cputime;
if (((struct process_args *)data)->cputime != NULL)
*value = ((struct process_args *)data)->cputime;
return 0;
}
int get_process_state(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct process_args *proc_args= (struct process_args*) data;
if(strchr(proc_args->state, 'S')!=NULL) *value="Sleeping";
else if(strchr(proc_args->state, 'R')!=NULL) *value= "Running";
else if(strchr(proc_args->state, 'T')!=NULL) *value= "Stopped";
else if(strchr(proc_args->state, 'D')!=NULL) *value= "Uninterruptible";
else if(strchr(proc_args->state, 'Z')!=NULL) *value= "Zombie";
else *value= proc_args->state;
if(strchr(((struct process_args *)data)->state, 'S') != NULL) *value = "Sleeping";
else if (strchr(((struct process_args *)data)->state, 'R') != NULL) *value = "Running";
else if (strchr(((struct process_args *)data)->state, 'T') != NULL) *value = "Stopped";
else if (strchr(((struct process_args *)data)->state, 'D') != NULL) *value = "Uninterruptible";
else if (strchr(((struct process_args *)data)->state, 'Z') != NULL) *value = "Zombie";
else *value = ((struct process_args *)data)->state;
return 0;
}
@ -706,10 +643,11 @@ int browsePocessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev
{
json_object *res, *processes, *fields, *process;
char *pid_field, *command_field, *state_field, *mem_size_field, *cpu_time_field, *priority_field, *pid, *command, *mem_size, *state, *cpu_time, *priority, *idx, *idx_last= NULL;
int i, id=0;
struct process_args proc_args={};
int i, id = 0;
struct process_args proc_args = {0};
dmubus_call("router.system", "processes", UBUS_ARGS{{}}, 0, &res);
if (!res) return 0;
json_object_object_get_ex(res, "fields", &fields);
json_object_object_get_ex(res, "processes", &processes);
size_t nbre_process = json_object_array_length(processes);
@ -720,18 +658,16 @@ int browsePocessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev
priority_field = (char *)dmjson_get_value_in_array_idx(fields, 8, 0, NULL);
cpu_time_field = (char *)dmjson_get_value_in_array_idx(fields, 9, 0, NULL);
if(nbre_process>0){
for(i=0; i<nbre_process; i++){
if (nbre_process > 0) {
for (i = 0; i < nbre_process; i++) {
process= json_object_array_get_idx(processes, i);
pid = dmjson_get_value(process, 1, pid_field);
command = dmjson_get_value(process, 1, command_field);
state = dmjson_get_value(process, 1, state_field);
mem_size= dmjson_get_value(process, 1, mem_size_field);
cpu_time= dmjson_get_value(process, 1, cpu_time_field);
priority= dmjson_get_value(process, 1, priority_field);
mem_size = dmjson_get_value(process, 1, mem_size_field);
cpu_time = dmjson_get_value(process, 1, cpu_time_field);
priority = dmjson_get_value(process, 1, priority_field);
init_process_args(&proc_args, pid, command, mem_size, priority, cpu_time, state);
idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&proc_args, idx) == DM_STOP)
break;
@ -777,22 +713,22 @@ int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, cha
//Browse VendorLogFile instances
int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *sys_log_sec, *s, *dm_sec, *del_sec=NULL;
char *instance, *last_instance, *log_file,*log_size, *add_value, *lfile;
int i=1, n=0;
struct uci_section *sys_log_sec, *dm_sec;
char *instance, *last_instance, *log_file,*log_size;
int i = 1;
uci_foreach_sections("system", "system", sys_log_sec) {
if(!sys_log_sec)
if (!sys_log_sec)
break;
dmuci_get_value_by_section_string(sys_log_sec, "log_file", &log_file);
dmuci_get_value_by_section_string(sys_log_sec, "log_size", &log_size);
uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) {
if(dm_sec)
if (dm_sec)
break;
}
if(!dm_sec){
if (!dm_sec) {
update_section_list(DMMAP,"vlf", NULL, i++, NULL, "log_file", log_file, "log_size", log_size);
}
else{
} else {
DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm_sec, "log_file", log_file);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, dm_sec, "log_size", log_size);
}

View file

@ -12,7 +12,8 @@
#ifndef __DEVICE_INFO_H
#define __DEVICE_INFO_H
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#define UPTIME "/proc/uptime"
#define DEFAULT_CONFIG_DIR "/etc/config/"
@ -26,7 +27,8 @@ extern DMLEAF tDeviceInfoProcessStatusParams[];
extern DMOBJ tDeviceInfoObj[];
extern DMLEAF tDeviceInfoProcessStatusProcessParams[];
struct process_args{
struct process_args
{
char *pid;
char *command;
char* size;

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,7 @@
#ifndef __DHCP_H
#define __DHCP_H
#include <json-c/json.h>
#include <libbbf_api/dmcommon.h>
struct dhcp_args
{
@ -31,7 +31,8 @@ struct client_args
char *key;
};
struct dhcp_client_ipv4address_args {
struct dhcp_client_ipv4address_args
{
char *mac;
char *ip;
unsigned int leasetime;
@ -47,7 +48,8 @@ struct dhcp_client_args {
char *mask;
};
struct dhcp_client_option_args {
struct dhcp_client_option_args
{
struct uci_section *opt_sect;
struct uci_section *client_sect;
char *option_tag;

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,8 @@
#ifndef __DHCPV6_H
#define __DHCPV6_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tDHCPv6Obj[];
extern DMLEAF tDHCPv6Params[];
extern DMOBJ tDHCPv6ClientObj[];
@ -29,7 +31,8 @@ extern DMLEAF tDHCPv6ServerPoolClientIPv6PrefixParams[];
extern DMLEAF tDHCPv6ServerPoolClientOptionParams[];
extern DMLEAF tDHCPv6ServerPoolOptionParams[];
struct dhcpv6_client_args {
struct dhcpv6_client_args
{
struct uci_section *dhcp_client_conf;
struct uci_section *dhcp_client_dm;
char *ip;

View file

@ -8,11 +8,6 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "dns.h"
@ -193,6 +188,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa
if (found)
break;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(ss), String}}, 1, &jobj);
if (!jobj) break;
dmjson_foreach_value_in_array(jobj, arrobj, ipdns, j, 1, "dns-server") {
if (strcmp(ipdns, vip) == 0) {
found = 1;
@ -222,6 +218,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa
if (str[0] == '0')
continue;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &jobj);
if (!jobj) break;
dmjson_foreach_value_in_array(jobj, arrobj, ipdns, j, 1, "dns-server") {
if (ipdns[0] == '\0' || is_dns_server_in_dmmap(ipdns, section_name(s)))
continue;

View file

@ -11,6 +11,8 @@
#ifndef _DNS_H
#define _DNS_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tDNSObj[];
extern DMLEAF tDNSParams[];
extern DMLEAF tDNSClientParams[];

View file

@ -8,19 +8,9 @@
* Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "dsl.h"
#define DELIMITOR ","
/* *** Device.DSL. *** */
DMOBJ tDSLObj[] = {
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
@ -345,8 +335,8 @@ static struct uci_section *update_create_dmmap_dsl_channel(char *curr_id)
return s;
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
int browseDSLLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *line_obj = NULL;
@ -413,8 +403,9 @@ static char *get_dsl_value_without_argument(char *command1, char *id, char *comm
json_object *res;
char command[16], *value = "0";
sprintf(command, "%s.%s", command1, id);
snprintf(command, sizeof(command), "%s.%s", command1, id);
dmubus_call(command, command2, UBUS_ARGS{}, 0, &res);
if (!res) return "";
value = dmjson_get_value(res, 1, key);
return value;
}
@ -424,8 +415,9 @@ static char *get_dsl_value_without_argument_and_with_two_key(char *command1, cha
json_object *res;
char command[16], *value = "0";
sprintf(command, "%s.%s", command1, id);
snprintf(command, sizeof(command), "%s.%s", command1, id);
dmubus_call(command, command2, UBUS_ARGS{}, 0, &res);
if (!res) return "";
value = dmjson_get_value(res, 2, key1, key2);
return value;
}
@ -435,8 +427,9 @@ static char *get_dsl_value_with_argument(char *command1, char *id, char *command
json_object *res;
char command[16], *value = "0";
sprintf(command, "%s.%s", command1, id);
snprintf(command, sizeof(command), "%s.%s", command1, id);
dmubus_call(command, command2, UBUS_ARGS{{"interval", argument, String}}, 1, &res);
if (!res) return "";
value = dmjson_get_value(res, 1, key);
return value;
}
@ -446,8 +439,9 @@ static char *get_dsl_value_array_without_argument(char *command1, char *id, char
json_object *res;
char command[16], *value= "0";
sprintf(command, "%s.%s", command1, id);
snprintf(command, sizeof(command), "%s.%s", command1, id);
dmubus_call(command, command2, UBUS_ARGS{}, 0, &res);
if (!res) return "";
value = dmjson_get_value_array_all(res, DELIMITOR, 1, key);
return value;
}
@ -476,7 +470,7 @@ int get_DSL_ChannelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data
cnt++;
}
dmasprintf(value, "%d", cnt);
return 0;;
return 0;
}
/*#Device.DSL.Line.{i}.Enable!UBUS:dsl.line.0/status//status*/
@ -1154,7 +1148,7 @@ int get_DSLChannel_Name(char *refparam, struct dmctx *ctx, void *data, char *ins
int get_DSLChannel_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char linker[8];
sprintf(linker, "line_%s", ((struct dsl_line_args *)data)->id);
snprintf(linker, sizeof(linker), "line_%s", ((struct dsl_line_args *)data)->id);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cLine%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
@ -1163,7 +1157,7 @@ int get_DSLChannel_LowerLayers(char *refparam, struct dmctx *ctx, void *data, ch
static char *get_dsl_link_encapsulation_standard(char *str)
{
char *dsl_link_encapsulation_standard;
char *dsl_link_encapsulation_standard = "";
if(strcmp(str, "adsl2_atm") == 0)
dsl_link_encapsulation_standard = "G.992.3_Annex_K_ATM";

View file

@ -11,6 +11,8 @@
#ifndef __DSL_H
#define __DSL_H
#include <libbbf_api/dmcommon.h>
struct dsl_line_args
{
struct uci_section *line_sec;

View file

@ -8,12 +8,6 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <stdbool.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "dynamicdns.h"
@ -98,8 +92,8 @@ int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, void *data
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
/*#Device.DynamicDNS.Client.{i}.!UCI:ddns/service/dmmap_ddns*/
int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
@ -213,8 +207,8 @@ int browseDynamicDNSClientHostnameInst(struct dmctx *dmctx, DMNODE *parent_node,
}
/*************************************************************
* ADD & DEL OBJ
/*************************************************************/
* ADD & DEL OBJ
*************************************************************/
int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char inst[8], *last_inst, *value, *v, *s_name;
@ -222,7 +216,7 @@ int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char *
check_create_dmmap_package("dmmap_ddns");
last_inst = get_last_instance_bbfdm("dmmap_ddns", "service", "clientinstance");
sprintf(inst, "%s", last_inst ? last_inst : "1");
snprintf(inst, sizeof(inst), "%s", last_inst ? last_inst : "1");
dmasprintf(&s_name, "Ddns_%d", atoi(inst)+1);
dmuci_add_section("ddns", "service", &s, &value);
@ -285,7 +279,7 @@ int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char *
check_create_dmmap_package("dmmap_ddns");
last_inst = get_last_instance_bbfdm("dmmap_ddns", "ddns_server", "serverinstance");
sprintf(inst, "%s", last_inst ? last_inst : "1");
snprintf(inst, sizeof(inst), "%s", last_inst ? last_inst : "1");
dmasprintf(&s_name, "server_%d", atoi(inst)+1);
dmuci_add_section("ddns", "service", &s, &value);
dmuci_rename_section_by_section(s, s_name);
@ -344,8 +338,8 @@ int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char *
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
*************************************************************/
int get_DynamicDNS_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
@ -387,10 +381,10 @@ int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *da
remove_substring(pch, "\"");
remove_substring(pch, " ");
if (strcmp(buf, "") == 0) {
sprintf(buf, "%s", pch);
snprintf(buf, sizeof(buf), "%s", pch);
} else {
strcpy(buf_tmp, buf);
sprintf(buf, "%s,%s", buf_tmp, pch);
snprintf(buf, sizeof(buf), "%s,%s", buf_tmp, pch);
}
}
fclose(fp);
@ -437,7 +431,7 @@ int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *data, c
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
if (*logdir == '\0')
logdir = "/var/log/ddns";
sprintf(path, "%s/%s.log", logdir, section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name((struct uci_section *)data));
fp = fopen(path, "r");
if (fp != NULL) {
strcpy(status, "Connecting");
@ -463,8 +457,7 @@ int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, ch
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section)
dmuci_get_value_by_section_string(dmmap_section, "clientalias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "clientalias", value);
return 0;
}
@ -477,8 +470,7 @@ int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, ch
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section)
dmuci_set_value_by_section(dmmap_section, "clientalias", value);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "clientalias", value);
break;
}
return 0;
@ -496,7 +488,7 @@ int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, void *data
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
if (*logdir == '\0')
logdir = "/var/log/ddns";
sprintf(path, "%s/%s.log", logdir, section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name((struct uci_section *)data));
fp = fopen(path, "r");
if (fp != NULL) {
strcpy(status, "NO_ERROR");
@ -660,7 +652,7 @@ int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx, void
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
if (*logdir == '\0')
logdir = "/var/log/ddns";
sprintf(path, "%s/%s.log", logdir, section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name((struct uci_section *)data));
fp = fopen(path, "r");
if (fp != NULL) {
strcpy(status, "Registered");
@ -712,7 +704,7 @@ int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx *ctx, v
dmuci_get_option_value_string("ddns", "global", "ddns_rundir", &rundir);
if (*rundir == '\0')
rundir = "/var/run/ddns";
sprintf(path, "%s/%s.update", rundir, section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.update", rundir, section_name((struct uci_section *)data));
fp = fopen(path, "r");
if (fp != NULL) {
@ -801,8 +793,6 @@ int get_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, ch
int set_DynamicDNSServer_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section;
switch (action) {
case VALUECHECK:
break;
@ -871,7 +861,7 @@ int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *
} else {
char *addr = strchr(dns_server, ':');
if (addr)
sprintf(new, "%s%s", value, addr);
snprintf(new, sizeof(new), "%s%s", value, addr);
else
strcpy(new, value);
dmuci_set_value_by_section((struct uci_section *)data, "dns_server", new);
@ -884,7 +874,7 @@ int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *
} else {
char *addr = strchr(dns_server, ':');
if (addr)
sprintf(new, "%s%s", value, addr);
snprintf(new, sizeof(new), "%s%s", value, addr);
else
strcpy(new, value);
dmuci_set_value_by_section(s, "dns_server", new);
@ -931,9 +921,9 @@ int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *dat
char *addr = strchr(dns_server, ':');
if (addr) {
*addr = '\0';
sprintf(new, "%s%s", dns_server, value);
snprintf(new, sizeof(new), "%s%s", dns_server, value);
} else {
sprintf(new, "%s:%s", dns_server, value);
snprintf(new, sizeof(new), "%s:%s", dns_server, value);
}
dmuci_set_value_by_section((struct uci_section *)data, "dns_server", new);
}
@ -946,9 +936,9 @@ int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *dat
char *addr = strchr(dns_server, ':');
if (addr) {
*addr = '\0';
sprintf(new, "%s%s", dns_server, value);
snprintf(new, sizeof(new), "%s%s", dns_server, value);
} else {
sprintf(new, "%s:%s", dns_server, value);
snprintf(new, sizeof(new), "%s:%s", dns_server, value);
}
dmuci_set_value_by_section(s, "dns_server", new);
}
@ -1026,7 +1016,7 @@ int set_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, void *
check_interval = atoi(value) * 60;
else
check_interval = atoi(value);
sprintf(buf, "%d", check_interval);
snprintf(buf, sizeof(buf), sizeof(buf), "%d", check_interval);
dmuci_set_value_by_section((struct uci_section *)data, "check_interval", buf);
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
@ -1064,7 +1054,7 @@ int set_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, void *
retry_interval = atoi(value) * 60;
else
retry_interval = atoi(value);
sprintf(buf, "%d", retry_interval);
snprintf(buf, sizeof(buf), "%d", retry_interval);
dmuci_set_value_by_section((struct uci_section *)data, "retry_interval", buf);
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) {

View file

@ -11,6 +11,8 @@
#ifndef __DYNAMICDNS_H
#define __DYNAMICDNS_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tDynamicDNSObj[];
extern DMLEAF tDynamicDNSParams[];
extern DMOBJ tDynamicDNSClientObj[];

View file

@ -10,14 +10,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "ethernet.h"
@ -167,8 +159,8 @@ DMLEAF tEthernetVLANTerminationStatsParams[] = {
};
/*************************************************************
* INIT
/*************************************************************/
* INIT
**************************************************************/
inline int init_eth_port(struct eth_port_args *args, struct uci_section *s, char *ifname)
{
args->eth_port_sec = s;
@ -177,8 +169,8 @@ inline int init_eth_port(struct eth_port_args *args, struct uci_section *s, char
}
/*************************************************************
* COMMON Functions
/*************************************************************/
* COMMON Functions
**************************************************************/
static int is_mac_exist(char *macaddr)
{
struct uci_section *s = NULL;
@ -235,8 +227,8 @@ static int dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_nod
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
/*#Device.Ethernet.Interface.{i}.!UCI:ports/ethport/dmmap_ports*/
int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
@ -338,8 +330,8 @@ int get_linker_vlan_term(char *refparam, struct dmctx *dmctx, void *data, char *
}
/*************************************************************
* ADD & DEL OBJ
/*************************************************************/
* ADD & DEL OBJ
**************************************************************/
int addObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *inst, *v;
@ -456,8 +448,8 @@ int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data,
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
**************************************************************/
/*#Device.Ethernet.InterfaceNumberOfEntries!UCI:ports/ethport/*/
int get_Ethernet_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
@ -777,8 +769,9 @@ int get_EthernetInterface_EEECapability(char *refparam, struct dmctx *ctx, void
return 0;
}
static inline int get_ubus_ethernet_interface_stats(json_object *res, char **value, char *stat_mod, void *data)
static inline int get_ubus_ethernet_interface_stats(char **value, char *stat_mod, void *data)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", stat_mod);
@ -788,63 +781,42 @@ static inline int get_ubus_ethernet_interface_stats(json_object *res, char **val
/*#Device.Ethernet.Interface.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
int get_EthernetInterfaceStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_interface_stats(res, value, "tx_bytes", data);
get_ubus_ethernet_interface_stats(value, "tx_bytes", data);
return 0;
}
/*#Device.Ethernet.Interface.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/
int get_EthernetInterfaceStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "rx_bytes");
get_ubus_ethernet_interface_stats(value, "rx_bytes", data);
return 0;
}
/*#Device.Ethernet.Interface.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/
int get_EthernetInterfaceStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "tx_packets");
get_ubus_ethernet_interface_stats(value, "tx_packets", data);
return 0;
}
/*#Device.Ethernet.Interface.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/
int get_EthernetInterfaceStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "rx_packets");
get_ubus_ethernet_interface_stats(value, "rx_packets", data);
return 0;
}
/*#Device.Ethernet.Interface.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/
int get_EthernetInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "tx_errors");
get_ubus_ethernet_interface_stats(value, "tx_errors", data);
return 0;
}
/*#Device.Ethernet.Interface.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/
int get_EthernetInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "rx_errors");
get_ubus_ethernet_interface_stats(value, "rx_errors", data);
return 0;
}
@ -863,22 +835,14 @@ int get_EthernetInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmc
/*#Device.Ethernet.Interface.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/
int get_EthernetInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "tx_dropped");
get_ubus_ethernet_interface_stats(value, "tx_dropped", data);
return 0;
}
/*#Device.Ethernet.Interface.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/
int get_EthernetInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "rx_dropped");
get_ubus_ethernet_interface_stats(value, "rx_dropped", data);
return 0;
}
@ -909,11 +873,7 @@ int get_EthernetInterfaceStats_BroadcastPacketsReceived(char *refparam, struct d
/*#Device.Ethernet.Interface.{i}.Stats.UnknownProtoPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_over_errors*/
int get_EthernetInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", "rx_over_errors");
get_ubus_ethernet_interface_stats(value, "rx_over_errors", data);
return 0;
}
@ -1005,7 +965,7 @@ int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void *data,
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)
sprintf(linker, "%s+", section_name(port));
snprintf(linker, sizeof(linker), "%s+", section_name(port));
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 = "";
@ -1044,9 +1004,11 @@ int get_EthernetLink_MACAddress(char *refparam, struct dmctx *ctx, void *data, c
return 0;
}
static inline int get_ubus_ethernet_link_stats(json_object *res, char **value, char *stat_mod, void *data)
static inline int get_ubus_ethernet_link_stats(char **value, char *stat_mod, void *data)
{
char *device;
json_object *res;
dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "device", &device);
dmubus_call("network.device", "status", UBUS_ARGS{{"name", device, String}}, 1, &res);
DM_ASSERT(res, *value = "0");
@ -1056,43 +1018,37 @@ static inline int get_ubus_ethernet_link_stats(json_object *res, char **value, c
int get_EthernetLinkStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "tx_bytes", data);
get_ubus_ethernet_link_stats(value, "tx_bytes", data);
return 0;
}
int get_EthernetLinkStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "rx_bytes", data);
get_ubus_ethernet_link_stats(value, "rx_bytes", data);
return 0;
}
int get_EthernetLinkStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "tx_packets", data);
get_ubus_ethernet_link_stats(value, "tx_packets", data);
return 0;
}
int get_EthernetLinkStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "rx_packets", data);
get_ubus_ethernet_link_stats(value, "rx_packets", data);
return 0;
}
int get_EthernetLinkStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "tx_errors", data);
get_ubus_ethernet_link_stats(value, "tx_errors", data);
return 0;
}
int get_EthernetLinkStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "rx_errors", data);
get_ubus_ethernet_link_stats(value, "rx_errors", data);
return 0;
}
@ -1114,15 +1070,13 @@ int get_EthernetLinkStats_UnicastPacketsReceived(char *refparam, struct dmctx *c
int get_EthernetLinkStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "tx_dropped", data);
get_ubus_ethernet_link_stats(value, "tx_dropped", data);
return 0;
}
int get_EthernetLinkStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "rx_dropped", data);
get_ubus_ethernet_link_stats(value, "rx_dropped", data);
return 0;
}
@ -1160,8 +1114,7 @@ int get_EthernetLinkStats_BroadcastPacketsReceived(char *refparam, struct dmctx
int get_EthernetLinkStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_link_stats(res, value, "rx_over_errors", data);
get_ubus_ethernet_link_stats(value, "rx_over_errors", data);
return 0;
}
@ -1369,9 +1322,11 @@ int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *da
return 0;
}
static inline int get_ubus_ethernet_vlan_termination_stats(json_object *res, char **value, char *stat_mod, void *data)
static inline int get_ubus_ethernet_vlan_termination_stats(char **value, char *stat_mod, void *data)
{
json_object *res;
char *ifname;
dmuci_get_value_by_section_string(((struct dm_args *)data)->section, "ifname", &ifname);
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "0");
@ -1382,48 +1337,42 @@ static inline int get_ubus_ethernet_vlan_termination_stats(json_object *res, cha
/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
int get_EthernetVLANTerminationStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "tx_bytes", data);
get_ubus_ethernet_vlan_termination_stats(value, "tx_bytes", data);
return 0;
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/
int get_EthernetVLANTerminationStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "rx_bytes", data);
get_ubus_ethernet_vlan_termination_stats(value, "rx_bytes", data);
return 0;
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/
int get_EthernetVLANTerminationStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "tx_packets", data);
get_ubus_ethernet_vlan_termination_stats(value, "tx_packets", data);
return 0;
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/
int get_EthernetVLANTerminationStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "rx_packets", data);
get_ubus_ethernet_vlan_termination_stats(value, "rx_packets", data);
return 0;
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/
int get_EthernetVLANTerminationStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "tx_errors", data);
get_ubus_ethernet_vlan_termination_stats(value, "tx_errors", data);
return 0;
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/
int get_EthernetVLANTerminationStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "rx_errors", data);
get_ubus_ethernet_vlan_termination_stats(value, "rx_errors", data);
return 0;
}
@ -1450,16 +1399,14 @@ int get_EthernetVLANTerminationStats_UnicastPacketsReceived(char *refparam, stru
/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/
int get_EthernetVLANTerminationStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "tx_dropped", data);
get_ubus_ethernet_vlan_termination_stats(value, "tx_dropped", data);
return 0;
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/
int get_EthernetVLANTerminationStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "rx_dropped", data);
get_ubus_ethernet_vlan_termination_stats(value, "rx_dropped", data);
return 0;
}
@ -1507,7 +1454,6 @@ int get_EthernetVLANTerminationStats_BroadcastPacketsReceived(char *refparam, st
/*#Device.Ethernet.VLANTermination.{i}.Stats.UnknownProtoPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_over_errors*/
int get_EthernetVLANTerminationStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
get_ubus_ethernet_vlan_termination_stats(res, value, "rx_over_errors", data);
get_ubus_ethernet_vlan_termination_stats(value, "rx_over_errors", data);
return 0;
}

View file

@ -13,6 +13,8 @@
#ifndef __ETHERNET_H
#define __ETHERNET_H
#include <libbbf_api/dmcommon.h>
struct eth_port_args
{
struct uci_section *eth_port_sec;

View file

@ -8,8 +8,6 @@
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
#include "firewall.h"
@ -103,14 +101,12 @@ DMLEAF tTimeSpanParams[] = {
int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s;
char *v, *instance, *instnbr = NULL;
char *v, *instnbr = NULL;
check_create_dmmap_package("dmmap_firewall");
s = is_dmmap_section_exist("dmmap_firewall", "level");
if(!s)
dmuci_add_section_bbfdm("dmmap_firewall", "level", &s, &v);
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_level_instance", "firewall_level_alias");
if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "level", &s, &v);
handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_level_instance", "firewall_level_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, s, "1");
return 0;
}
@ -118,14 +114,12 @@ int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, c
int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s;
char *v, *instance, *instnbr = NULL;
char *v, *instnbr = NULL;
check_create_dmmap_package("dmmap_firewall");
s = is_dmmap_section_exist("dmmap_firewall", "chain");
if(!s)
dmuci_add_section_bbfdm("dmmap_firewall", "chain", &s, &v);
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_chain_instance", "firewall_chain_alias");
if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "chain", &s, &v);
handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "firewall_chain_instance", "firewall_chain_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, s, "1");
return 0;
}
@ -141,21 +135,23 @@ int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, ch
list_for_each_entry(p, &dup_list, list) {
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dmmap_section, "firewall_chain_rule_instance", "firewall_chain_rule_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, instance) == DM_STOP)
return 0;
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char **instance){
int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s, *dmmap_firewall_rule;
char *last_inst= NULL, *sect_name= NULL, *rule_name, *v;
char *last_inst = NULL, *sect_name = NULL, *rule_name, *v;
char ib[8];
last_inst= get_last_instance_bbfdm("dmmap_firewall", "rule", "firewall_chain_rule_instance");
last_inst = get_last_instance_bbfdm("dmmap_firewall", "rule", "firewall_chain_rule_instance");
if (last_inst)
sprintf(ib, "%s", last_inst);
snprintf(ib, sizeof(ib), "%s", last_inst);
else
sprintf(ib, "%s", "1");
snprintf(ib, sizeof(ib), "%s", "1");
dmasprintf(&rule_name, "Firewall rule %d", atoi(ib)+1);
dmuci_add_section("firewall", "rule", &s, &sect_name);
@ -170,40 +166,37 @@ int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char **inst
return 0;
}
int delete_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action){
struct uci_section *s = NULL;
struct uci_section *ss = NULL;
struct uci_section *dmmap_section;
int delete_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
switch (del_action) {
case DEL_INST:
if(is_section_unnamed(section_name((struct uci_section *)data))){
if (is_section_unnamed(section_name((struct uci_section *)data))) {
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_firewall", "rule", "firewall_chain_rule_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "firewall_chain_rule_instance", "dmmap_firewall", "rule");
dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
if (dmmap_section) 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("firewall", "rule", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
}
@ -235,27 +228,25 @@ int get_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, c
int get_firewall_level_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value="1";
*value = "1";
return 0;
}
int get_firewall_chain_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value="1";
*value = "1";
return 0;
}
int get_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section* levels=(struct uci_section *)data;
dmuci_get_value_by_section_string(levels, "name", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
return 0;
}
int get_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section* levels=(struct uci_section *)data;
dmuci_get_value_by_section_string(levels, "description", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "description", value);
return 0;
}
@ -270,8 +261,7 @@ int get_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data
struct uci_section *s = NULL;
char *v;
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "masq", &v);
if (*v == '1') {
*value = "1";
@ -287,8 +277,7 @@ int get_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data,
struct uci_section *s = NULL;
char *v;
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "log", &v);
if (*v == '1') {
*value = "1";
@ -307,8 +296,7 @@ int get_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instan
int get_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section* chains=(struct uci_section *)data;
dmuci_get_value_by_section_string(chains, "name", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
return 0;
}
@ -324,8 +312,7 @@ int get_chain_rule_number_of_entries(char *refparam, struct dmctx *ctx, void *da
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("firewall", "rule", s)
{
uci_foreach_sections("firewall", "rule", s) {
cnt++;
}
dmasprintf(value, "%d", cnt);
@ -354,7 +341,7 @@ int get_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance
{
struct uci_section *dms;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms);
dmuci_get_value_by_section_string(dms, "firewall_chain_rule_instance", value);
if (dms) dmuci_get_value_by_section_string(dms, "firewall_chain_rule_instance", value);
return 0;
}
@ -362,7 +349,7 @@ int get_rule_description(char *refparam, struct dmctx *ctx, void *data, char *in
{
struct uci_section *dms;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms);
dmuci_get_value_by_section_string(dms, "description", value);
if (dms) dmuci_get_value_by_section_string(dms, "description", value);
return 0;
}
@ -374,17 +361,13 @@ int get_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instanc
dmuci_get_value_by_section_string((struct uci_section *)data, "target", &v);
if (strcasecmp(v, "Accept") == 0) {
*value = "Accept";
}
else if (strcasecmp(v, "Reject") == 0) {
} else if (strcasecmp(v, "Reject") == 0) {
*value = "Reject";
}
else if (strcasecmp(v, "Drop") == 0){
} else if (strcasecmp(v, "Drop") == 0) {
*value = "Drop";
}
else if (strcasecmp(v, "MARK") == 0){
} else if (strcasecmp(v, "MARK") == 0) {
*value = "Return";
}
else {
} else {
*value = v;
}
return 0;
@ -398,27 +381,24 @@ int get_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *i
int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *v = NULL, *v1= NULL;
struct uci_list *v = NULL, *v1 = NULL;
struct uci_element *e;
char *zone, *ifaceobj, buf[256] = "", *val;
char *vallink, *zone, buf[256] = "", *val;
struct uci_section *s = NULL;
char linker[64] = "", *vallink;
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &zone);
if(zone == NULL || strlen(zone)==0)
if (zone == NULL || strlen(zone) == 0)
return 0;
if (strcmp(zone, "*") == 0) {
v = dmcalloc(1, sizeof(struct uci_list));
uci_list_init(v);
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_list(s, "network", &v1);
uci_add_list_to_list(v1, v);
}
} else {
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "name", &val);
if (strcmp(val, zone) == 0) {
dmuci_get_value_by_section_list(s, "network", &v);
@ -436,8 +416,7 @@ int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, cha
strcat(buf, ",");
strcat(buf, vallink);
}
}
else {
} else {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), zone, &vallink);
strcpy(buf, vallink);
}
@ -454,8 +433,7 @@ int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char
struct uci_section *s = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest", &zone);
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "name", &val);
if (strcmp(val, zone) == 0) {
dmuci_get_value_by_section_list(s, "network", &v);
@ -481,14 +459,13 @@ int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char
int get_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ipversion;
dmuci_get_value_by_section_string((struct uci_section *)data, "family", &ipversion);
if (strcasecmp(ipversion, "ipv4") == 0) {
*value = "4";
}
else if (strcasecmp(ipversion, "ipv6") == 0) {
} else if (strcasecmp(ipversion, "ipv6") == 0) {
*value = "6";
}
else {
} else {
*value = "-1";
}
return 0;
@ -497,14 +474,12 @@ int get_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *in
/*#Device.Firewall.Chain.{i}.Rule.{i}.DestIp!UCI:firewall/rule,@i-1/dest_ip*/
int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char buf[64];
char *pch;
char *destip;
char buf[64], *pch, *destip;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
strcpy(buf, destip);
pch = strchr(buf, '/');
if (pch)
*pch = '\0';
if (pch) *pch = '\0';
*value = dmstrdup(buf);
return 0;
}
@ -512,10 +487,9 @@ int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instan
/*#Device.Firewall.Chain.{i}.Rule.{i}.DestMask!UCI:firewall/rule,@i-1/dest_ip*/
int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *pch;
char *pch, *destip;
*value = "";
char *destip;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
if (*destip == '\0')
return 0;
@ -523,8 +497,7 @@ int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *inst
pch = strchr(destip, '/');
if (pch) {
*value = pch+1;
}
else {
} else {
*value = "";
}
return 0;
@ -533,14 +506,12 @@ int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *inst
/*#Device.Firewall.Chain.{i}.Rule.{i}.SourceIp!UCI:firewall/rule,@i-1/src_ip*/
int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char buf[64];
char *pch;
char *srcip;
char buf[64], *pch, *srcip;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
strcpy(buf, srcip);
pch = strchr(buf, '/');
if (pch)
*pch = '\0';
if (pch) *pch = '\0';
*value = dmstrdup(buf);
return 0;
}
@ -548,10 +519,9 @@ int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *inst
/*#Device.Firewall.Chain.{i}.Rule.{i}.SourceMask!UCI:firewall/rule,@i-1/src_ip*/
int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *pch;
char *pch, *srcip;
*value = "";
char *srcip;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
if (*srcip == '\0')
return 0;
@ -559,8 +529,7 @@ int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *in
pch = strchr(srcip, '/');
if (pch) {
*value = pch+1;
}
else {
} else {
*value = "";
}
return 0;
@ -570,11 +539,7 @@ int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *in
int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE *fp;
char buf[256];
char protocol[32];
char protocol_nbr[16];
struct uci_section *ss = (struct uci_section *)data;
char *v;
char *v, buf[256], protocol[32], protocol_nbr[16];
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &v);
*value = "-1";
@ -589,7 +554,7 @@ int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *insta
if (fp == NULL)
return 0;
while (fgets (buf , 256 , fp) != NULL) {
sscanf(buf, "%s %s", protocol, protocol_nbr);
sscanf(buf, "%31s %15s", protocol, protocol_nbr);
if (strcmp(protocol, v) == 0) {
*value =dmstrdup(protocol_nbr);
fclose(fp);
@ -603,8 +568,8 @@ int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char *insta
/*#Device.Firewall.Chain.{i}.Rule.{i}.DestPort!UCI:firewall/rule,@i-1/dest_port*/
int get_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *tmp;
char *v;
char *tmp,*v;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v);
v = dmstrdup(v);
tmp = strchr(v, ':');
@ -623,8 +588,8 @@ int get_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *inst
/*#Device.Firewall.Chain.{i}.Rule.{i}.DestPortRangeMax!UCI:firewall/rule,@i-1/dest_port*/
int get_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *rpch, *tmp;
char *v;
char *tmp, *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v);
tmp = strchr(v, ':');
if (tmp == NULL)
@ -636,8 +601,8 @@ int get_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data,
/*#Device.Firewall.Chain.{i}.Rule.{i}.SourcePort!UCI:firewall/rule,@i-1/src_port*/
int get_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *tmp;
char *v;
char *tmp, *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v);
v = dmstrdup(v);
tmp = strchr(v, ':');
@ -656,8 +621,8 @@ int get_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *in
/*#Device.Firewall.Chain.{i}.Rule.{i}.SourcePortRangeMax!UCI:firewall/rule,@i-1/src_port*/
int get_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *rpch, *tmp;
char *v;
char *tmp, *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v);
tmp = strchr(v, ':');
if (tmp == NULL)
@ -679,7 +644,7 @@ int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *inst
ptr = dmstrdup(*value);
dmfree(*value);
if(strlen(ptr)==0)
if (strlen(ptr) == 0)
dmasprintf(value, "%s", e->name);
else {
dmasprintf(value, "%s %s", ptr, e->name);
@ -700,7 +665,7 @@ int get_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *ins
int get_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value= "mon tue wed thu fri sat sun";
*value = "mon tue wed thu fri sat sun";
return 0;
}
@ -775,12 +740,11 @@ int set_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *data, c
int set_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section* level=(struct uci_section *)data;
switch (action) {
case VALUECHECK:
break;
case VALUESET:
DMUCI_SET_VALUE_BY_SECTION(bbfdm, level, "name", value);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "name", value);
break;
}
return 0;
@ -788,12 +752,11 @@ int set_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance
int set_level_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section* level=(struct uci_section *)data;
switch (action) {
case VALUECHECK:
break;
case VALUESET:
DMUCI_SET_VALUE_BY_SECTION(bbfdm, level, "description", value);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "description", value);
break;
}
return 0;
@ -813,8 +776,7 @@ int set_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data
case VALUESET:
string_to_bool(value, &b);
if (b) {
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "src", &v);
dmuci_get_value_by_section_string(s, "name", &v2);
if (strcasestr(v, "wan") || strcasestr(v2, "wan")) {
@ -822,10 +784,8 @@ int set_level_port_mapping_enabled(char *refparam, struct dmctx *ctx, void *data
return 0;
}
}
}
else {
uci_foreach_sections("firewall", "zone", s)
{
} else {
uci_foreach_sections("firewall", "zone", s) {
dmuci_set_value_by_section(s, "masq", "");
}
}
@ -847,20 +807,17 @@ int set_level_default_log_policy(char *refparam, struct dmctx *ctx, void *data,
case VALUESET:
string_to_bool(value, &b);
if (b) {
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_set_value_by_section(s, "log", "1");
}
}
else {
uci_foreach_sections("firewall", "zone", s)
{
} else {
uci_foreach_sections("firewall", "zone", s) {
dmuci_set_value_by_section(s, "log", "");
}
}
break;
}
return 0;
return 0;
}
int set_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -874,18 +831,16 @@ int set_chain_enable(char *refparam, struct dmctx *ctx, void *data, char *instan
case VALUESET:
break;
}
return 0;
return 0;
}
int set_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section* chains=(struct uci_section *)data;
switch (action) {
case VALUECHECK:
break;
case VALUESET:
DMUCI_SET_VALUE_BY_SECTION(bbfdm, chains, "name", value);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, (struct uci_section *)data, "name", value);
break;
}
return 0;
@ -922,12 +877,13 @@ int set_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance
int set_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dms;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms);
switch (action) {
case VALUECHECK:
break;
case VALUESET:
DMUCI_SET_VALUE_BY_SECTION(bbfdm, dms, "description", value);
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms);
if (dms) DMUCI_SET_VALUE_BY_SECTION(bbfdm, dms, "description", value);
break;
}
return 0;
@ -941,14 +897,11 @@ int set_rule_target(char *refparam, struct dmctx *ctx, void *data, char *instanc
case VALUESET:
if (strcasecmp(value, "Accept") == 0) {
dmuci_set_value_by_section((struct uci_section *)data, "target", "ACCEPT");
}
else if (strcasecmp(value, "Reject") == 0) {
} else if (strcasecmp(value, "Reject") == 0) {
dmuci_set_value_by_section((struct uci_section *)data, "target", "REJECT");
}
else if (strcasecmp(value, "Drop") == 0) {
} else if (strcasecmp(value, "Drop") == 0) {
dmuci_set_value_by_section((struct uci_section *)data, "target", "DROP");
}
else if (strcasecmp(value, "Return") == 0) {
} else if (strcasecmp(value, "Return") == 0) {
dmuci_set_value_by_section((struct uci_section *)data, "target", "MARK");
}
break;
@ -969,7 +922,7 @@ int set_rule_target_chain(char *refparam, struct dmctx *ctx, void *data, char *i
int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *iface, *zone, *v = "", *val, *net;
char *iface, *zone, *net;
struct uci_section *s = NULL;
switch (action) {
@ -981,8 +934,7 @@ int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, cha
case VALUESET:
adm_entry_get_linker_value(ctx, value, &iface);
if (iface && iface[0] != '\0') {
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "network", &net);
if (dm_strword(net, iface)) {
dmuci_get_value_by_section_string(s, "name", &zone);
@ -998,7 +950,7 @@ int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, cha
int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *iface, *zone, *v = "", *net;
char *iface, *zone, *net;
struct uci_section *s = NULL;
switch (action) {
@ -1007,8 +959,7 @@ int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char
case VALUESET:
adm_entry_get_linker_value(ctx, value, &iface);
if (iface != NULL && iface[0] != '\0') {
uci_foreach_sections("firewall", "zone", s)
{
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "name", &net);
if (dm_strword(net, iface)) {
dmuci_get_value_by_section_string(s, "name", &zone);
@ -1030,15 +981,12 @@ int set_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, char *in
case VALUESET:
if (strcmp(value, "4") == 0) {
dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv4");
}
else if (strcmp(value, "6") == 0) {
} else if (strcmp(value, "6") == 0) {
dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv6");
}
else if (strcmp(value, "-1") == 0) {
} else if (strcmp(value, "-1") == 0) {
dmuci_set_value_by_section((struct uci_section *)data, "family", "");
}
break;
break;
}
return 0;
}
@ -1056,9 +1004,8 @@ int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char *instan
strcpy(buf, destip);
pch = strchr(buf, '/');
if (pch) {
sprintf(new, "%s%s", value, pch);
}
else {
snprintf(new, sizeof(new), "%s%s", value, pch);
} else {
strcpy(new, value);
}
dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new);
@ -1082,7 +1029,7 @@ int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *inst
if (pch) {
*pch = '\0';
}
sprintf(new, "%s/%s", buf, value);
snprintf(new, sizeof(new), "%s/%s", buf, value);
dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new);
break;
}
@ -1102,9 +1049,8 @@ int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, char *inst
strcpy(buf, srcip);
pch = strchr(buf, '/');
if (pch) {
sprintf(new, "%s%s", value, pch);
}
else {
snprintf(new, sizeof(new), "%s%s", value, pch);
} else {
strcpy(new, value);
}
dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new);
@ -1128,7 +1074,7 @@ int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *in
if (pch) {
*pch = '\0';
}
sprintf(new, "%s/%s", buf, value);
snprintf(new, sizeof(new), "%s/%s", buf, value);
dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new);
break;
}
@ -1165,10 +1111,9 @@ int set_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, char *inst
tmp = strchr(v, '-');
if (tmp == NULL) {
sprintf(buffer, "%s", value);
}
else {
sprintf(buffer, "%s%s", value, tmp);
snprintf(buffer, sizeof(buffer), "%s", value);
} else {
snprintf(buffer, sizeof(buffer), "%s%s", value, tmp);
}
dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer);
break;
@ -1192,16 +1137,15 @@ int set_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void *data,
if (tmp)
*tmp = '\0';
if (*value == '-') {
sprintf(buffer, "%s", v);
}
else {
sprintf(buffer, "%s:%s", v, value);
snprintf(buffer, sizeof(buffer), "%s", v);
} else {
snprintf(buffer, sizeof(buffer), "%s:%s", v, value);
}
dmfree(buf);
dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer);
break;
}
return 0;
return 0;
}
int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -1218,10 +1162,9 @@ int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, char *in
if (tmp == NULL)
tmp = strchr(v, '-');
if (tmp == NULL) {
sprintf(buffer, "%s", value);
}
else {
sprintf(buffer, "%s%s", value, tmp);
snprintf(buffer, sizeof(buffer), "%s", value);
} else {
snprintf(buffer, sizeof(buffer), "%s%s", value, tmp);
}
dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer);
break;
@ -1245,10 +1188,9 @@ int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data
if (tmp)
*tmp = '\0';
if (*value == '-') {
sprintf(buffer, "%s", v);
}
else {
sprintf(buffer, "%s:%s", v, value);
snprintf(buffer, sizeof(buffer), "%s", v);
} else {
snprintf(buffer, sizeof(buffer), "%s:%s", v, value);
}
dmfree(buf);
dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer);
@ -1257,23 +1199,27 @@ int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, void *data
return 0;
}
int set_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int length, i;
char **devices= NULL;
int set_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
int i;
size_t length;
char **devices = NULL;
switch (action) {
case VALUECHECK:
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "icmp_type", "");
devices = strsplit(value, " ", &length);
for(i=0; i<length; i++)
for (i = 0; i < length; i++)
dmuci_add_list_value_by_section((struct uci_section *)data, "icmp_type", devices[i]);
break;
}
return 0;
}
int set_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int set_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
break;
@ -1284,7 +1230,8 @@ int set_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *ins
return 0;
}
int set_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int set_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
break;
@ -1294,7 +1241,8 @@ int set_time_span_supported_days(char *refparam, struct dmctx *ctx, void *data,
return 0;
}
int set_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int set_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
break;
@ -1305,7 +1253,8 @@ int set_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *inst
return 0;
}
int set_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int set_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
break;
@ -1316,7 +1265,8 @@ int set_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char
return 0;
}
int set_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action){
int set_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
break;

View file

@ -11,6 +11,8 @@
#ifndef _FIREWALL_H
#define _FIREWALL_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tFirewallObj[];
extern DMLEAF tFirewallParams[];
extern DMLEAF tFirewallLevelParams[];

View file

@ -8,13 +8,6 @@
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <ctype.h>
#include <uci.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include "gre.h"
/* *** Device.GRE. *** */
@ -123,8 +116,8 @@ DMLEAF tGREFilterParams[] = {
};
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *gretun_inst= NULL, *gretun_inst_last= NULL;
@ -179,8 +172,8 @@ int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
}
/*************************************************************
* ADD & DEL OBJ
/*************************************************************/
* ADD & DEL OBJ
*************************************************************/
int addObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *value, *v;
@ -242,7 +235,7 @@ int delObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char *instanc
int addObjGREFilter(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct dmmap_dup *dm = (struct dmmap_dup *)data;
//TODO
return 0;
}
@ -285,12 +278,10 @@ int addObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char
int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *s1= NULL;
struct uci_section *ss = NULL;
struct uci_section *dmmap_section;
struct uci_section *s = NULL, *ss = NULL, *s1 = NULL, *dmmap_section;
int found = 0;
struct dmmap_dup *p= (struct dmmap_dup *)data;
char *iface= NULL, *atiface= NULL;
struct dmmap_dup *p = (struct dmmap_dup *)data;
char *iface = NULL, *atiface = NULL;
switch (del_action) {
case DEL_INST:
@ -337,14 +328,15 @@ int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
*************************************************************/
static char *get_gre_tunnel_interface_statistics(char *interface, char *key)
{
json_object *res, *diag;
char *device, *value = "0";
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res);
if (!res) return value;
device = dmjson_get_value(res, 1, "device");
if(device[0] != '\0') {
dmubus_call("network.device", "status", UBUS_ARGS{{"name", device, String}}, 1, &diag);

View file

@ -11,6 +11,8 @@
#ifndef __GRE_H
#define __GRE_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tGREObj[];
extern DMLEAF tGREParams[];
extern DMOBJ tGRETunnelObj[];

View file

@ -9,14 +9,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "hosts.h"
@ -53,8 +45,8 @@ DMLEAF tHostsHostParams[] = {
/*************************************************************
* INIT
/*************************************************************/
* INIT
**************************************************************/
inline int init_host_args(struct host_args *args, json_object *clients, char *key)
{
args->client = clients;
@ -62,13 +54,13 @@ inline int init_host_args(struct host_args *args, json_object *clients, char *ke
return 0;
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
**************************************************************/
int get_host_associateddevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
char *macaddr_linker = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr");
char *accesspointInstance = NULL, *wifiAssociativeDeviecPath;
char *macaddr_linker = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr");
uci_path_foreach_sections(bbfdm, "dmmap_wireless", "wifi-iface", ss) {
dmuci_get_value_by_section_string(ss, "accesspointinstance", &accesspointInstance);
@ -101,10 +93,10 @@ int get_host_interface_type(char *refparam, struct dmctx *ctx, void *data, char
struct uci_section *ss = NULL;
uci_foreach_sections("network", "interface", ss) {
if(!strcmp(ifname, section_name(ss))){
if (!strcmp(ifname, section_name(ss))) {
dmuci_get_value_by_section_string(ss, "type", &type);
if(type!=NULL){
if(!strcmp(type, "bridge")) *value="Bridge";else *value= "Normal";
if (type!=NULL) {
if (!strcmp(type, "bridge")) *value="Bridge";else *value= "Normal";
break;
}
}
@ -118,15 +110,12 @@ int get_host_interfacename(char *refparam, struct dmctx *ctx, void *data, char *
frequency = dmjson_get_value(((struct host_args *)data)->client, 1, "frequency");
wireless = dmjson_get_value(((struct host_args *)data)->client, 1, "wireless");
if( (*frequency != '\0') && (strcmp(wireless, "true")==0) )
{
if ((*frequency != '\0') && (strcmp(wireless, "true")==0)) {
if(strcmp(frequency,"5GHz")==0)
*value = "WiFi@5GHz";
else
*value = "WiFi@2.4GHz";
}
else
{
} else {
*value = dmjson_get_value(((struct host_args *)data)->client, 1, "ethport");
if (*value == NULL)
*value = "";
@ -172,10 +161,9 @@ int get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char
int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char buf[80], *dhcp;
char *dhcp;
FILE *fp;
char line[MAX_DHCP_LEASES];
struct tm ts;
char *leasetime, *mac_f, *mac, *line1;
char delimiter[] = " \t";
@ -229,8 +217,7 @@ static char *get_interface_type(char *mac, char *ndev)
json_object *res;
int wlctl_num;
struct uci_section *s, *d;
char *network, *device, *value, *wunit;
char buf[8], *p;
char buf[8], *p, *network, *value, *wunit;
uci_foreach_sections("wireless", "wifi-device", d) {
wlctl_num = 0;
@ -239,15 +226,15 @@ static char *get_interface_type(char *mac, char *ndev)
dmuci_get_value_by_section_string(s, "network", &network);
if (strcmp(network, ndev) == 0) {
if (wlctl_num != 0) {
sprintf(buf, "%s.%d", wunit, wlctl_num);
snprintf(buf, sizeof(buf), "%s.%d", wunit, wlctl_num);
p = buf;
}
else {
} else {
p = wunit;
}
dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", p, String}}, 1, &res);
if(res) {
json_object_object_foreach(res, key, val) {
UNUSED(key);
value = dmjson_get_value(val, 1, "macaddr");
if (strcasecmp(value, mac) == 0)
return "802.11";
@ -278,6 +265,8 @@ int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *in
dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "0");
json_object_object_foreach(res, key, client_obj) {
UNUSED(key);
UNUSED(client_obj);
entries++;
}
dmasprintf(value, "%d", entries); // MEM WILL BE FREED IN DMMEMCLEAN
@ -285,11 +274,11 @@ int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *in
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res, *client_obj;
json_object *res;
char *idx, *idx_last = NULL, *connected;
int id = 0;
struct host_args curr_host_args = {0};

View file

@ -12,6 +12,8 @@
#ifndef __HOSTS_H
#define __HOSTS_H
#include <libbbf_api/dmcommon.h>
struct host_args
{
json_object *client;

View file

@ -8,10 +8,6 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "interfacestack.h"
@ -27,22 +23,21 @@ DMLEAF tInterfaceStackParams[] = {
};
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
static char *get_instance_by_section(struct dmctx *dmctx, int mode, char *dmmap_config, char *section, struct uci_section *s, char *instance_option, char *alias_option)
{
struct uci_section *dmmap_section;
char *instance;
get_dmmap_section_of_config_section(dmmap_config, section, section_name(s), &dmmap_section);
if(dmmap_section == NULL) {
if (dmmap_section == NULL) {
return "";
}
if (mode == INSTANCE_MODE_NUMBER) {
dmuci_get_value_by_section_string(dmmap_section, instance_option, &instance);
}
else {
} else {
dmuci_get_value_by_section_string(dmmap_section, alias_option, &instance);
}
return instance;
@ -54,7 +49,7 @@ static char *get_alias_by_section(char *dmmap_config, char *section, struct uci_
char *alias;
get_dmmap_section_of_config_section(dmmap_config, section, section_name(s), &dmmap_section);
if(dmmap_section == NULL) {
if (dmmap_section == NULL) {
return "";
}
dmuci_get_value_by_section_string(dmmap_section, alias_option, &alias);
@ -81,7 +76,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
{
struct interfacestack_data ifdata = {0};
struct uci_section *s = NULL, *sd = NULL, *port, *port_s, *ss, *dmmap_s = NULL;
char *proto, *type, *pch, *spch, *layer_inst, *v, *vb, *higheralias, *loweralias, *ifname, *br_inst, *mg, *value, *p, *device, *name;
char *proto, *type, *pch, *spch, *layer_inst, *v, *vb, *higheralias, *loweralias, *ifname, *br_inst, *mg, *value, *device, *name;
char *interface_stack_int = NULL, *interface_stack_int_last = NULL, *wanifname, *wanlinker, *mac, *vlan_method, *sectionname, *package, *section;
char buf_lowerlayer[128] = "";
char buf_higherlayer[128] = "";
@ -91,7 +86,6 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
char linker[64] = "";
char buf_tmp[64] = "";
int instance = 0, found = 0;
json_object *jobj;
/* Higher layers are Device.IP.Interface.{i}. */
uci_foreach_sections("network", "interface", s) {
@ -101,17 +95,17 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
layer_inst = get_instance_by_section(dmctx, dmctx->instance_mode, "dmmap_network", "interface", s, "ip_int_instance", "ip_int_alias");
if (*layer_inst == '\0')
continue;
sprintf(buf_higherlayer, "Device.IP.Interface.%s.", layer_inst);
snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.IP.Interface.%s.", layer_inst);
higheralias = get_alias_by_section("dmmap_network", "interface", s, "ip_int_alias");
sprintf(buf_higheralias, "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
dmuci_get_value_by_section_string(s, "proto", &proto);
if (strstr(proto, "ppp")) {
layer_inst = get_instance_by_section(dmctx, dmctx->instance_mode, "dmmap_network", "interface", s, "ppp_int_instance", "ppp_int_alias");
if (*layer_inst == '\0')
continue;
sprintf(buf_lowerlayer, "Device.PPP.Interface.%s.", layer_inst);
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "Device.PPP.Interface.%s.", layer_inst);
loweralias = get_alias_by_section("dmmap_network", "interface", s, "ppp_int_alias");
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
}
else {
device = get_device(section_name(s));
@ -132,14 +126,14 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (v == NULL)
v = "";
}
sprintf(buf_lowerlayer, "%s", v);
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", v);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
}
ifdata.higherlayer = buf_higherlayer;
ifdata.lowerlayer = buf_lowerlayer;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
@ -154,9 +148,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
layer_inst = get_instance_by_section(dmctx, dmctx->instance_mode, "dmmap_network", "interface", s, "ppp_int_instance", "ppp_int_alias");
if (*layer_inst == '\0')
continue;
sprintf(buf_higherlayer, "Device.PPP.Interface.%s.", layer_inst);
snprintf(buf_higherlayer, sizeof(buf_higheralias), "Device.PPP.Interface.%s.", layer_inst);
higheralias = get_alias_by_section("dmmap_network", "interface", s, "ppp_int_alias");
sprintf(buf_higheralias, "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
found = 0;
device = get_device(section_name(s));
if (device[0] != '\0') {
@ -176,13 +170,13 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (v == NULL)
v = "";
}
sprintf(buf_lowerlayer, "%s", v);
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", v);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
ifdata.higherlayer = buf_higherlayer;
ifdata.lowerlayer = buf_lowerlayer;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
@ -201,12 +195,12 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
layer_inst = get_instance_by_section(dmctx, dmctx->instance_mode, "dmmap_network", "device", s, "only_tagged_vlan_term_instance", "vlan_term_alias");
if (*layer_inst == '\0')
continue;
sprintf(buf_higherlayer, "Device.Ethernet.VLANTermination.%s.", layer_inst);
snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.VLANTermination.%s.", layer_inst);
if(strcmp(vlan_method, "2") == 0)
higheralias = get_alias_by_section("dmmap_network", "device", s, "all_vlan_term_alias");
else
higheralias = get_alias_by_section("dmmap_network", "device", s, "vlan_term_alias");
sprintf(buf_higheralias, "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
dmuci_get_value_by_section_string(s, "name", &value);
uci_foreach_sections("network", "interface", ss) {
@ -224,13 +218,13 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
}
}
sprintf(buf_lowerlayer, "%s", v);
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", v);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
ifdata.higherlayer = buf_higherlayer;
ifdata.lowerlayer = buf_lowerlayer;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
@ -248,15 +242,15 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
layer_inst = get_instance_by_section(dmctx, dmctx->instance_mode, "dmmap", "link", s, "link_instance", "link_alias");
if (*layer_inst == '\0')
continue;
sprintf(buf_higherlayer, "Device.Ethernet.Link.%s.", layer_inst);
snprintf(buf_higherlayer, sizeof(buf_higherlayer), "Device.Ethernet.Link.%s.", layer_inst);
higheralias = get_alias_by_section("dmmap", "link", s, "link_alias");
sprintf(buf_higheralias, "%s", higheralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", higheralias);
if (strcmp(type, "bridge") == 0) {
br_inst = get_alias_by_section("dmmap_network", "interface", s, "bridge_instance");
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) {
sprintf(linker, "%s+", section_name(port));
snprintf(linker, sizeof(linker), "%s+", section_name(port));
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, &v);
dmuci_get_value_by_section_string(port, "bridge_port_alias", &loweralias);
break;
@ -276,12 +270,12 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
if (v == NULL)
v = "";
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
ifdata.higherlayer = buf_higherlayer;
ifdata.lowerlayer = v;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
@ -299,10 +293,10 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
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) {
sprintf(linker, "%s+", section_name(port));
snprintf(linker, sizeof(linker), "%s+", section_name(port));
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, &pch);
dmuci_get_value_by_section_string(port, "bridge_port_alias", &higheralias);
sprintf(buf_tmp, "%s", higheralias);
snprintf(buf_tmp, sizeof(buf_tmp), "%s", higheralias);
if (pch == NULL)
pch = "";
break;
@ -326,26 +320,26 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
}
if(strcmp(package, "network") == 0 && strcmp(section, "device") == 0)
sprintf(linker, "%s+%s", sectionname, name);
snprintf(linker, sizeof(linker), "%s+%s", sectionname, name);
else
sprintf(linker, "%s+%s", sectionname, ifname);
snprintf(linker, sizeof(linker), "%s+%s", sectionname, ifname);
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cBridging%cBridge%c", dmroot, dm_delim, dm_delim, dm_delim), linker, &vb);
if (vb == NULL)
vb = "";
dmuci_get_value_by_section_string(sd, "bridge_port_alias", &loweralias);
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
ifdata.higherlayer = pch;
ifdata.lowerlayer = vb;
ifdata.higheralias = buf_tmp;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
goto end;
sprintf(buf_higheralias, "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
if(strcmp(package, "ports") == 0) {
adm_entry_get_linker_param(dmctx, dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), ifname, &v);
loweralias = get_alias_by_section("dmmap_ports", "ethport", port_s, "eth_port_alias");
@ -370,26 +364,26 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
}
} else {
sprintf(linker, "%s.1", ifname);
snprintf(linker, sizeof(linker), "%s.1", ifname);
adm_entry_get_linker_param(dmctx,dm_print_path("%s%cEthernet%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, &v);
loweralias = get_alias_by_section("dmmap_ports", "ethport", port_s, "eth_port_alias");
}
}
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
if (v == NULL)
v = "";
ifdata.higherlayer = vb;
ifdata.lowerlayer = v;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
goto end;
if(strcmp(package, "wireless") == 0) {
sprintf(buf_higheralias, "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
uci_foreach_option_eq("wireless", "wifi-iface", "ifname", ifname, ss) {
dmuci_get_value_by_section_string(ss, "device", &device);
}
@ -404,12 +398,12 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
if (vb == NULL)
vb = "";
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
ifdata.higherlayer = v;
ifdata.lowerlayer = vb;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
@ -418,7 +412,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if(strcmp(package, "network") == 0) {
if(strstr(ifname, "atm") || strstr(ifname, "ptm")) {
sprintf(buf_higheralias, "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
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);
if (vb == NULL)
@ -426,18 +420,18 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
uci_path_foreach_sections(bbfdm, "dmmap", "dsl_channel", ss) {
dmuci_get_value_by_section_string(ss, "dsl_channel_alias", &loweralias);
}
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
ifdata.higherlayer = v;
ifdata.lowerlayer = vb;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
goto end;
sprintf(buf_higheralias, "%s", loweralias);
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s", loweralias);
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);
if (value == NULL)
@ -445,12 +439,12 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
uci_path_foreach_sections(bbfdm, "dmmap", "dsl_line", ss) {
dmuci_get_value_by_section_string(ss, "dsl_line_alias", &loweralias);
}
sprintf(buf_loweralias, "%s", loweralias);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s", loweralias);
ifdata.higherlayer = vb;
ifdata.lowerlayer = value;
ifdata.higheralias = buf_higheralias;
ifdata.loweralias = buf_loweralias;
sprintf(buf_instance, "%d", ++instance);
snprintf(buf_instance, sizeof(buf_instance), "%d", ++instance);
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
interface_stack_int = handle_update_instance(1, dmctx, &interface_stack_int_last, update_instance_alias, 3, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&ifdata, interface_stack_int) == DM_STOP)
@ -465,8 +459,8 @@ end:
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
**************************************************************/
int get_Device_InterfaceStackNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;

View file

@ -11,6 +11,8 @@
#ifndef __INTERFACESTACK_H
#define __INTERFACESTACK_H
#include <libbbf_api/dmcommon.h>
extern DMLEAF tInterfaceStackParams[];
struct interfacestack_data {

View file

@ -10,14 +10,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "ip.h"
#include "dmentry.h"
#ifdef BBF_TR143
@ -173,8 +165,8 @@ unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data,
}
/*************************************************************
* INIT
/*************************************************************/
* INIT
**************************************************************/
inline int init_ip_args(struct ip_args *args, struct uci_section *s, char *ip_4address)
{
args->ip_sec = s;
@ -203,16 +195,15 @@ inline int init_ipv6prefix_args(struct ipv6prefix_args *args, struct uci_section
}
/*************************************************************
* COMMON Functions
/*************************************************************/
* COMMON Functions
**************************************************************/
static char *ubus_call_get_value_with_two_objects(char *interface, char *obj1, char *obj2, char *key)
{
json_object *res, *jobj1, *jobj2;
json_object *res, *jobj1 = NULL, *jobj2 = NULL;
char *value = "";
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res);
if (res)
{
if (res) {
jobj1 = dmjson_select_obj_in_array_idx(res, 0, 1, obj1);
if(jobj1)
jobj2 = dmjson_get_obj(jobj1, 1, obj2);
@ -228,8 +219,7 @@ static char *ubus_call_get_value(char *interface, char *obj, char *key)
char *value = "";
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res);
if (res)
{
if (res) {
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, obj);
value = dmjson_get_value(jobj, 1, key);
}
@ -261,8 +251,8 @@ static char *get_child_prefix_linker(char *interface)
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
**************************************************************/
/*
* *** Device.IP. ***
*/
@ -388,8 +378,9 @@ int set_IPInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *
int get_IPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
char *lan_name = section_name(((struct ip_args *)data)->ip_sec), *val= NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name, String}}, 1, &res);
char *val = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "Down");
val = dmjson_get_value(res, 1, "up");
*value = !strcmp(val, "true") ? "Up" : "Down";
return 0;
@ -479,6 +470,8 @@ int get_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *i
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:
if (string_to_bool(value, &b))
@ -486,9 +479,11 @@ int set_IPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *i
break;
case VALUESET:
string_to_bool(value, &b);
if(b) {
set_interface_enable_ubus(section_name(((struct ip_args *)data)->ip_sec), refparam, ctx, action, "0");
set_interface_enable_ubus(section_name(((struct ip_args *)data)->ip_sec), refparam, ctx, action, "1");
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);
}
break;
}
@ -611,15 +606,62 @@ int get_IPInterface_TWAMPReflectorNumberOfEntries(char *refparam, struct dmctx *
/*
* *** Device.IP.Interface.{i}.IPv4Address.{i}. ***
*/
static struct uci_section *create_firewall_zone_config(char *iface)
{
struct uci_section *s;
char *value, *name;
dmuci_add_section_and_rename("firewall", "zone", &s, &value);
dmasprintf(&name, "fwl_%s", iface);
dmuci_set_value_by_section(s, "name", name);
dmuci_set_value_by_section(s, "input", "DROP");
dmuci_set_value_by_section(s, "forward", "DROP");
dmuci_set_value_by_section(s, "output", "ACCEPT");
dmuci_set_value_by_section(s, "network", iface);
dmfree(name);
return s;
}
int get_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
get_interface_firewall_enabled(section_name(((struct ip_args *)data)->ip_sec), refparam, ctx, value);
char *input = "", *forward = "";
struct uci_section *s = NULL;
uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) {
dmuci_get_value_by_section_string(s, "input", &input);
dmuci_get_value_by_section_string(s, "forward", &forward);
if (strcmp(input, "ACCEPT") !=0 && strcmp(forward, "ACCEPT") !=0) {
*value = "1";
return 0;
}
}
*value = "0";
return 0;
}
int set_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
set_interface_firewall_enabled(section_name(((struct ip_args *)data)->ip_sec), refparam, ctx, action, value);
bool b;
int cnt = 0;
struct uci_section *s = NULL;
switch (action) {
case VALUECHECK:
if (string_to_bool(value, &b))
return FAULT_9007;
return 0;
case VALUESET:
string_to_bool(value, &b);
value = b ? "DROP" : "ACCEPT";
uci_foreach_option_cont("firewall", "zone", "network", section_name(((struct ip_args *)data)->ip_sec), s) {
dmuci_set_value_by_section(s, "input", value);
dmuci_set_value_by_section(s, "forward", value);
cnt++;
}
if (cnt == 0 && b)
create_firewall_zone_config(section_name(((struct ip_args *)data)->ip_sec));
return 0;
}
return 0;
}
@ -696,16 +738,15 @@ int get_ipv4_addressing_type (char *refparam, struct dmctx *ctx, void *data, cha
int set_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *proto;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
if(strcasecmp(value, "static") == 0) {
if (strcasecmp(value, "static") == 0) {
dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static");
dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", "0.0.0.0");
}
if(strcasecmp(value, "dhcp") == 0) {
if (strcasecmp(value, "dhcp") == 0) {
dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "dhcp");
dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", "");
}
@ -716,12 +757,11 @@ int set_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char
int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
char linker[64] = "", *proto, *device, *mac;
dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto);
if (strstr(proto, "ppp")) {
sprintf(linker, "%s", section_name(((struct ip_args *)data)->ip_sec));
snprintf(linker, sizeof(linker), "%s", section_name(((struct ip_args *)data)->ip_sec));
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value);
goto end;
}
@ -748,7 +788,6 @@ end :
int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL, *newvalue = NULL;
struct uci_section *s;
switch (action) {
case VALUECHECK:
@ -1120,6 +1159,7 @@ static char *get_ip_interface_statistics(char *interface, char *key)
char *device, *value = "0";
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res);
if (!res) return value;
device = dmjson_get_value(res, 1, "device");
if(device[0] != '\0') {
dmubus_call("network.device", "status", UBUS_ARGS{{"name", device, String}}, 1, &diag);
@ -1249,7 +1289,7 @@ int set_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void
{
bool b;
struct uci_section *s;
char *type, *interface, *device, *id, *ipv4addr = "";
char *interface, *device, *id, *ipv4addr = "";
json_object *res, *jobj;
switch (action) {
@ -1272,8 +1312,7 @@ int set_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void
}
if (ipv4addr[0] == '\0') {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res);
if (res)
{
if (res) {
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address");
ipv4addr = dmjson_get_value(jobj, 1, "address");
if (ipv4addr[0] == '\0')
@ -1281,12 +1320,10 @@ int set_IPInterfaceTWAMPReflector_Enable(char *refparam, struct dmctx *ctx, void
else
dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "4");
}
}
else
} else
dmuci_set_value_by_section((struct uci_section *)data, "ip_version", "4");
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res);
if (res)
{
if (res) {
device = dmjson_get_value(res, 1, "device");
dmuci_set_value_by_section((struct uci_section *)data, "device", device);
}
@ -1302,7 +1339,7 @@ int get_IPInterfaceTWAMPReflector_Status(char *refparam, struct dmctx *ctx, void
{
char *enable;
dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &enable);
if(strcmp(enable, "1")==0)
if (strcmp(enable, "1") == 0)
*value = "Active";
else
*value = "Disabled";
@ -1400,8 +1437,8 @@ int set_IPInterfaceTWAMPReflector_PortAllowedList(char *refparam, struct dmctx *
}
/*************************************************************
* GET & SET ALIAS
/*************************************************************/
* GET & SET ALIAS
**************************************************************/
int get_IPInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
@ -1519,13 +1556,13 @@ int set_IPInterfaceIPv6Prefix_Alias(char *refparam, struct dmctx *ctx, void *dat
}
/*************************************************************
* ADD & DEL OBJ
/*************************************************************/
* ADD & DEL OBJ
**************************************************************/
char *get_last_instance_cond(char* dmmap_package, char *package, char *section, char *opt_inst, char *opt_cond, char *cond_val, char *opt_filter, char *filter_val, char *refused_interface)
{
struct uci_section *s, *dmmap_section;
char *inst = NULL, *val, *val_f;
char *type, *ipv4addr = "", *ipv6addr = "", *proto;
char *ipv4addr = "", *ipv6addr = "", *proto;
json_object *res, *jobj;
uci_foreach_sections(package, section, s) {
@ -1539,8 +1576,7 @@ char *get_last_instance_cond(char* dmmap_package, char *package, char *section,
dmuci_get_value_by_section_string(s, "ipaddr", &ipv4addr);
if (ipv4addr[0] == '\0') {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res);
if (res)
{
if (res) {
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address");
ipv4addr = dmjson_get_value(jobj, 1, "address");
}
@ -1548,8 +1584,7 @@ char *get_last_instance_cond(char* dmmap_package, char *package, char *section,
dmuci_get_value_by_section_string(s, "ip6addr", &ipv6addr);
if (ipv6addr[0] == '\0') {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res);
if (res)
{
if (res) {
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address");
ipv6addr = dmjson_get_value(jobj, 1, "address");
}
@ -1569,10 +1604,10 @@ int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **insta
char *last_inst, *v;
char ip_name[32], ib[8];
char *p = ip_name;
struct uci_section *dmmap_ip_interface, *dmmap_section;
struct uci_section *dmmap_ip_interface;
last_inst = get_last_instance_cond("dmmap_network", "network", "interface", "ip_int_instance", "type", "alias", "proto", "", "loopback");
sprintf(ib, "%d", last_inst ? atoi(last_inst)+1 : 1);
snprintf(ib, sizeof(ib), "%d", last_inst ? atoi(last_inst)+1 : 1);
dmstrappendstr(p, "ip_interface_");
dmstrappendstr(p, ib);
dmstrappendend(p);
@ -1593,8 +1628,7 @@ int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *ins
case DEL_INST:
dmuci_delete_by_section(((struct ip_args *)data)->ip_sec, NULL, NULL);
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct ip_args *)data)->ip_sec), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if(dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
break;
case DEL_ALL:
return FAULT_9005;
@ -1816,8 +1850,8 @@ int get_linker_ipv6_prefix(char *refparam, struct dmctx *dmctx, void *data, char
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
/*#Device.IP.Interface.{i}.!UCI:network/interface/dmmap_network*/
int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
@ -1913,7 +1947,7 @@ int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_dat
if (ipv6_valid[0] == '\0')
ipv6_valid = dmjson_get_value(jobj, 1, "valid");
entries++;
sprintf(buf, "%d", entries);
snprintf(buf, sizeof(buf), "%d", entries);
s = update_dmmap_network_ipv6(buf, section_name(((struct ip_args *)prev_data)->ip_sec));
init_ipv6_args(&curr_ipv6_args, ((struct ip_args *)prev_data)->ip_sec, ipv6addr, ipv6mask, ipv6_preferred, ipv6_valid);
ipv6_int = handle_update_instance(1, dmctx, &ipv6_int_last, update_instance_alias, 3, s, "ipv6_instance", "ipv6_alias");
@ -1981,7 +2015,7 @@ int browseIfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *pr
ipv6prefix_preferred = dmjson_get_value(jobj, 1, "preferred");
ipv6prefix_valid = dmjson_get_value(jobj, 1, "valid");
entries++;
sprintf(buf, "%d", entries);
snprintf(buf, sizeof(buf), "%d", entries);
s = update_dmmap_network_ipv6prefix(buf, section_name(((struct ip_args *)prev_data)->ip_sec));
init_ipv6prefix_args(&curr_ipv6prefix_args, ((struct ip_args *)prev_data)->ip_sec, ipv6prefixaddr, ipv6prefixmask, ipv6prefix_preferred, ipv6prefix_valid);
ipv6prefix_int = handle_update_instance(1, dmctx, &ipv6prefix_int_last, update_instance_alias, 3, s, "ipv6prefix_instance", "ipv6prefix_alias");
@ -2007,8 +2041,7 @@ int browseIPInterfaceTWAMPReflectorInst(struct dmctx *dmctx, DMNODE *parent_node
struct uci_section *s = NULL;
char *twamp_inst = NULL, *twamp_inst_last = NULL;
uci_foreach_option_eq("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)prev_data)->ip_sec), s)
{
uci_foreach_option_eq("cwmp_twamp", "twamp_reflector", "interface", section_name(((struct ip_args *)prev_data)->ip_sec), s) {
twamp_inst = handle_update_instance(2, dmctx, &twamp_inst_last, update_instance_alias, 3, (void *)s, "twamp_inst", "twamp_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, twamp_inst) == DM_STOP)
break;

View file

@ -13,6 +13,8 @@
#ifndef __IP_H
#define __IP_H
#include <libbbf_api/dmcommon.h>
struct ip_args
{
struct uci_section *ip_sec;

View file

@ -10,20 +10,8 @@
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include <ctype.h>
#include <uci.h>
#include <stdio.h>
#include <time.h>
#include <libbbf_api/dmmem.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "managementserver.h"
#define DEFAULT_ACSURL "http://192.168.1.1:8080/openacs/acs"
/*** ManagementServer. ***/
DMLEAF tManagementServerParams[] = {
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
@ -66,37 +54,31 @@ DMLEAF tManagementServerParams[] = {
/*#Device.ManagementServer.URL!UCI:cwmp/cwmp,acs/url*/
int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int i = 1;
char *dhcp = NULL, *pch = NULL, *spch = NULL;
char *url = NULL;
char *provisioning_value = NULL;
char package[64] = "", section[64] = "", option[64] = "";
char *dhcp = NULL, *url = NULL, *provisioning_value = NULL;
dmuci_get_option_value_string("cwmp", "acs", "dhcp_discovery", &dhcp);
dmuci_get_option_value_string("cwmp", "acs", "url", &url);
dmuci_get_varstate_string("cwmp", "acs", "dhcp_url", &provisioning_value);
if ( ((dhcp && strcmp(dhcp, "enable") == 0 ) || ((url == NULL) || (url[0] == '\0'))) && ((provisioning_value != NULL) && (provisioning_value[0] != '\0')) )
{
*value = provisioning_value;
}
else if ((url != NULL) && (url[0] != '\0'))
*value = url;
*value = url;
else
*value = dmstrdup(DEFAULT_ACSURL);
*value = dmstrdup("http://192.168.1.1:8080/openacs/acs");
return 0;
}
int set_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
return 0;
case VALUECHECK:
break;
case VALUESET:
dmuci_set_value("cwmp", "acs", "dhcp_discovery", "disable");
dmuci_set_value("cwmp", "acs", "url", value);
cwmp_set_end_session(END_SESSION_RELOAD);
return 0;
break;
}
return 0;
}
@ -201,8 +183,7 @@ int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx
char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value));
*value = dmstrdup(s_now); // MEM WILL BE FREED IN DMMEMCLEAN
}
else {
} else {
*value = "0001-01-01T00:00:00Z";
}
return 0;
@ -211,7 +192,8 @@ int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx
int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct tm tm;
char *p, buf[16];
char buf[16];
switch (action) {
case VALUECHECK:
return 0;
@ -219,7 +201,7 @@ int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx
if (!(strptime(value, "%Y-%m-%dT%H:%M:%S", &tm))) {
return 0;
}
sprintf(buf, "%ld", mktime(&tm));
snprintf(buf, sizeof(buf), "%ld", mktime(&tm));
dmuci_set_value("cwmp", "acs", "periodic_inform_time", buf);
cwmp_set_end_session(END_SESSION_RELOAD);
return 0;
@ -238,7 +220,7 @@ int get_management_server_connection_request_url(char *refparam, struct dmctx *c
dmuci_get_option_value_string("cwmp", "cpe", "port", &port);
if (ip[0] != '\0' && port[0] != '\0') {
char buf[64];
sprintf(buf,"http://%s:%s/", ip, port);
snprintf(buf, sizeof(buf), "http://%s:%s/", ip, port);
*value = dmstrdup(buf); // MEM WILL BE FREED IN DMMEMCLEAN
}
return 0;

View file

@ -11,7 +11,9 @@
#ifndef __MANAGEMENT_SERVER_H
#define __MANAGEMENT_SERVER_H
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
extern DMLEAF tManagementServerParams[];
int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -10,13 +10,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
#include "nat.h"
@ -65,8 +58,8 @@ DMLEAF tNATPortMappingParams[] = {
};
/*************************************************************
* ADD DEL OBJ
/*************************************************************/
* ADD DEL OBJ
**************************************************************/
int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *value, *v, *inst, name[16];
@ -74,7 +67,7 @@ int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char
check_create_dmmap_package("dmmap_firewall");
inst = get_last_instance_bbfdm("dmmap_firewall", "zone", "interface_setting_instance");
sprintf(name, "iface_set_%d", inst ? (atoi(inst)+1) : 1);
snprintf(name, sizeof(name), "iface_set_%d", inst ? (atoi(inst)+1) : 1);
dmuci_add_section_and_rename("firewall", "zone", &s, &value);
dmuci_set_value_by_section(s, "input", "REJECT");
dmuci_set_value_by_section(s, "output", "ACCEPT");
@ -91,31 +84,27 @@ int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char
int delete_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
char *lan_name;
struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall= NULL;
struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_firewall);
if(dmmap_firewall != NULL)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
if (dmmap_firewall) dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("firewall", "zone", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall);
if(dmmap_firewall != NULL)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
if (dmmap_firewall) dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall);
if(dmmap_firewall != NULL)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
if(dmmap_firewall) dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;
@ -130,7 +119,7 @@ int add_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char **in
check_create_dmmap_package("dmmap_firewall");
inst = get_last_instance_bbfdm("dmmap_firewall", "redirect", "port_mapping_instance");
sprintf(name, "port_map_%d", inst ? (atoi(inst)+1) : 1);
snprintf(name, sizeof(name), "port_map_%d", inst ? (atoi(inst)+1) : 1);
dmuci_add_section_and_rename("firewall", "redirect", &s, &value);
dmuci_set_value_by_section(s, "name", name);
dmuci_set_value_by_section(s, "src", "wan");
@ -147,31 +136,27 @@ int add_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char **in
int delete_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
char *lan_name;
struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall= NULL;
struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_firewall);
if(dmmap_firewall != NULL)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
if (dmmap_firewall) dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("firewall", "redirect", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall);
if(dmmap_firewall != NULL)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
if (dmmap_firewall) dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall);
if(dmmap_firewall != NULL)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
if (dmmap_firewall) dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;
@ -249,7 +234,7 @@ int get_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *dat
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "interface_setting_alias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "interface_setting_alias", value);
return 0;
}
@ -257,12 +242,12 @@ int set_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *dat
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section);
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(dmmap_section, "interface_setting_alias", value);
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "interface_setting_alias", value);
return 0;
}
return 0;
@ -512,9 +497,9 @@ int set_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &dport);
dport = strchr(dport, ':');
if (dport == NULL)
sprintf(buffer, "%s", value);
snprintf(buffer, sizeof(buffer), "%s", value);
else
sprintf(buffer, "%s%s", value, dport);
snprintf(buffer, sizeof(buffer), "%s%s", value, dport);
dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer);
return 0;
}
@ -543,9 +528,9 @@ int set_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *c
if (tmp)
*tmp = '\0';
if (*value == '0')
sprintf(buffer, "%s", dport);
snprintf(buffer, sizeof(buffer), "%s", dport);
else
sprintf(buffer, "%s:%s", dport, value);
snprintf(buffer, sizeof(buffer), "%s:%s", dport, value);
dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer);
return 0;
}
@ -646,8 +631,8 @@ int set_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *da
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
/*#Device.NAT.InterfaceSetting.{i}.!UCI:firewall/zone/dmmap_firewall*/
int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{

View file

@ -13,6 +13,8 @@
#ifndef __NAT_H
#define __NAT_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tNATObj[];
extern DMLEAF tNATParams[];
extern DMLEAF tNATInterfaceSettingParams[];

View file

@ -9,14 +9,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmjson.h>
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
#include "ppp.h"
@ -87,14 +79,14 @@ DMLEAF tPPPInterfaceStatsParams[] = {
};
/*************************************************************
* GET SET ALIAS
/*************************************************************/
* GET SET ALIAS
**************************************************************/
int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "ppp_int_alias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "ppp_int_alias", value);
return 0;
}
@ -102,12 +94,12 @@ int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance,
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section);
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(dmmap_section, "ppp_int_alias", value);
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "ppp_int_alias", value);
return 0;
}
return 0;
@ -119,20 +111,43 @@ int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance,
/*#Device.PPP.Interface.{i}.Enable!UBUS:network.interface/status/interface,@Name/up*/
int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_interface_enable_ubus(section_name(((struct uci_section *)data)), refparam, ctx, value);
json_object *res;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res);
DM_ASSERT(res, *value = "false");
*value = dmjson_get_value(res, 1, "up");
return 0;
}
int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
return set_interface_enable_ubus(section_name(((struct uci_section *)data)), refparam, ctx, action, value);
bool b;
char *ubus_object;
switch (action) {
case VALUECHECK:
if (string_to_bool(value, &b))
return FAULT_9007;
break;
case VALUESET:
string_to_bool(value, &b);
dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data)));
dmubus_call_set(ubus_object, b ? "up" : "down", UBUS_ARGS{}, 0);
dmfree(ubus_object);
break;
}
return 0;
}
/*#Device.PPP.Interface.{i}.Status!UBUS:network.interface/status/interface,@Name/up*/
int get_PPPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
char *status;
get_interface_enable_ubus(section_name(((struct uci_section *)data)), refparam, ctx, &status);
if(strcmp(status, "true") == 0)
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res);
DM_ASSERT(res, *value = "false");
status = dmjson_get_value(res, 1, "up");
if (strcmp(status, "true") == 0)
*value= "Up";
else
*value= "Down";
@ -158,6 +173,8 @@ int get_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *
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:
if (string_to_bool(value, &b))
@ -165,9 +182,11 @@ int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data, char *
break;
case VALUESET:
string_to_bool(value, &b);
if(b) {
set_interface_enable_ubus(section_name((struct uci_section *)data), refparam, ctx, action, "0");
set_interface_enable_ubus(section_name((struct uci_section *)data), refparam, ctx, action, "1");
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);
}
break;
}
@ -183,17 +202,14 @@ int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance,
/*#Device.PPP.Interface.{i}.ConnectionStatus!UBUS:network.interface/status/interface,@Name/up*/
int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *status = NULL;
char *uptime = NULL;
char *pending = NULL;
char *status = NULL, *uptime = NULL, *pending = NULL;
json_object *res = NULL, *jobj = NULL;
bool bstatus = false, bpend = false;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res);
DM_ASSERT(res, *value = "");
jobj = dmjson_get_obj(res, 1, "up");
if(jobj)
{
if(jobj) {
status = dmjson_get_value(res, 1, "up");
string_to_bool(status, &bstatus);
if (bstatus) {
@ -243,9 +259,11 @@ int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instan
return 0;
}
static inline int ubus_get_wan_stats(void *data, char *instance, json_object *res, char **value, char *stat_mod)
static inline int ubus_get_wan_stats(void *data, char *instance, char **value, char *stat_mod)
{
char *ifname, *proto;
json_object *res;
dmuci_get_value_by_section_string(((struct uci_section *)data), "ifname", &ifname);
dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto);
if (strcmp(proto, "pppoe") == 0) {
@ -259,48 +277,42 @@ static inline int ubus_get_wan_stats(void *data, char *instance, json_object *re
/*#Device.PPP.Interface.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/
int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "rx_bytes");
ubus_get_wan_stats(data, instance, value, "rx_bytes");
return 0;
}
/*#Device.PPP.Interface.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "tx_bytes");
ubus_get_wan_stats(data, instance, value, "tx_bytes");
return 0;
}
/*#Device.PPP.Interface.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/
int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "rx_packets");
ubus_get_wan_stats(data, instance, value, "rx_packets");
return 0;
}
/*#Device.PPP.Interface.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/
int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "tx_packets");
ubus_get_wan_stats(data, instance, value, "tx_packets");
return 0;
}
/*#Device.PPP.Interface.{i}.Stats.ErrorsSent!UBUS:network.device/status/name,@Name/statistics.tx_errors*/
int get_PPPInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "tx_errors");
ubus_get_wan_stats(data, instance, value, "tx_errors");
return 0;
}
/*#Device.PPP.Interface.{i}.Stats.ErrorsReceived!UBUS:network.device/status/name,@Name/statistics.rx_errors*/
int get_PPPInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "rx_errors");
ubus_get_wan_stats(data, instance, value, "rx_errors");
return 0;
}
@ -325,16 +337,14 @@ int get_PPPInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *c
/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_dropped*/
int get_PPPInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "tx_dropped");
ubus_get_wan_stats(data, instance, value, "tx_dropped");
return 0;
}
/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_dropped*/
int get_PPPInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "rx_dropped");
ubus_get_wan_stats(data, instance, value, "rx_dropped");
return 0;
}
@ -377,8 +387,7 @@ int get_PPPInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx
/*#Device.PPP.Interface.{i}.Stats.UnknownProtoPacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_over_errors*/
int get_PPPInterfaceStats_UnknownProtoPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_get_wan_stats(data, instance, res, value, "rx_over_errors");
ubus_get_wan_stats(data, instance, value, "rx_over_errors");
return 0;
}
@ -517,18 +526,17 @@ int get_linker_ppp_interface(char *refparam, struct dmctx *dmctx, void *data, ch
}
/*************************************************************
* ADD DEL OBJ
/*************************************************************/
* ADD DEL OBJ
**************************************************************/
int add_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char name[16] = {0};
char *inst, *v;
struct uci_section *s = NULL;
struct uci_section *dmmap_ppp = NULL;
check_create_dmmap_package("dmmap_network");
inst = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "ppp_int_instance", "proto", "ppp");
sprintf(name, "ppp_%d", inst ? (atoi(inst)+1) : 1);
snprintf(name, sizeof(name), "ppp_%d", inst ? (atoi(inst)+1) : 1);
dmuci_set_value("network", name, "", "interface");
dmuci_set_value("network", name, "proto", "ppp");
dmuci_set_value("network", name, "username", name);
@ -542,22 +550,19 @@ int add_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char **inst
int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *ppp_s = NULL;
struct uci_section *ss = NULL, *dmmap_section = NULL;
struct uci_section *ppp_s = NULL, *ss = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct uci_section *)data)), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (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("network", "interface", "proto", "ppp", ppp_s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = ppp_s;
@ -565,24 +570,21 @@ int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char *in
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;
break;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
/*#Device.PPP.Interface.{i}.!UCI:network/interface/dmmap_network*/
int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *net_sec = NULL;
char *ppp_int = NULL, *ppp_int_last = NULL;
char *proto;
char *ppp_int = NULL, *ppp_int_last = NULL, *proto;
struct dmmap_dup *p;
LIST_HEAD(dup_list);

View file

@ -12,6 +12,8 @@
#ifndef __PPP_H
#define __PPP_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tPPPObj[];
extern DMLEAF tPPPParams[];
extern DMOBJ tPPPInterfaceObj[];

View file

@ -9,13 +9,6 @@
*
*/
#include <ctype.h>
#include <uci.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "ptm.h"
@ -56,7 +49,8 @@ DMLEAF tPTMLinkStatsParams[] = {
/**************************************************************************
* LINKER
***************************************************************************/
int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) {
int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{
if (data && ((struct ptm_args *)data)->ifname){
*linker = ((struct ptm_args *)data)->ifname;
return 0;
@ -88,16 +82,16 @@ int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *insta
int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char linker[16];
sprintf(linker, "channel_%d", atoi(instance)-1);
snprintf(linker, sizeof(linker), "channel_%d", atoi(instance)-1);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cChannel%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
return 0;
}
static inline int ubus_ptm_stats(json_object *res, char **value, char *stat_mod, void *data)
static inline int ubus_ptm_stats(char **value, char *stat_mod, void *data)
{
json_object *res = NULL;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct ptm_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "statistics", stat_mod);
@ -107,32 +101,28 @@ static inline int ubus_ptm_stats(json_object *res, char **value, char *stat_mod,
/*#Device.PTM.Link.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/
int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_ptm_stats(res, value, "rx_bytes", data);
ubus_ptm_stats(value, "rx_bytes", data);
return 0;
}
/*#Device.PTM.Link.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_ptm_stats(res, value, "tx_bytes", data);
ubus_ptm_stats(value, "tx_bytes", data);
return 0;
}
/*#Device.PTM.Link.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/
int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_ptm_stats(res, value, "rx_packets", data);
ubus_ptm_stats(value, "rx_packets", data);
return 0;
}
/*#Device.PTM.Link.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/
int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
ubus_ptm_stats(res, value, "tx_packets", data);
ubus_ptm_stats(value, "tx_packets", data);
return 0;
}
@ -143,8 +133,8 @@ int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance
}
/*************************************************************
* ADD OBJ
/*************************************************************/
* ADD OBJ
*************************************************************/
int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *instance = NULL, *ptm_device = NULL, *v = NULL, *instance_update = NULL;
@ -222,14 +212,14 @@ int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instanc
}
/*************************************************************
* SET AND GET ALIAS
/*************************************************************/
* SET AND GET ALIAS
*************************************************************/
int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "ptmlinkalias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "ptmlinkalias", value);
return 0;
}
@ -242,15 +232,15 @@ int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance,
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "ptmlinkalias", value);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "ptmlinkalias", value);
return 0;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
/*#Device.PTM.Link.{i}.!UCI:dsl/ptm-device/dmmap_dsl*/
int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{

View file

@ -12,6 +12,8 @@
#ifndef __PTM_H
#define __PTM_H
#include <libbbf_api/dmcommon.h>
struct ptm_args
{
struct uci_section *ptm_sec;

View file

@ -8,10 +8,6 @@
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <regex.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include "dmentry.h"
#include "qos.h"
@ -341,24 +337,24 @@ struct uci_section *get_dup_qos_stats_section_in_dmmap(char *dmmap_package, char
int browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *dmmap_sect;
char *questatsout[256], *wnum= NULL, *instance= NULL, *inst_last= NULL, *v, *lastinstancestore= NULL, *instancestore= NULL, dev[50]= "", user[50]= "";
char *questatsout[256], *instance = NULL, *inst_last = NULL, *v, *lastinstancestore = NULL, dev[50] = "", user[50] = "";
int length, i, ret;
struct queuestats queuests= {0}, emptyquestats= {0};
struct queuestats queuests = {0}, emptyquestats = {0};
regex_t regex1, regex2;
regcomp(&regex1, queuessts1, 0);
regcomp(&regex2, queuessts2, 0);
check_create_dmmap_package("dmmap_qos");
command_exec_output_to_array("tc -s qdisc", questatsout, &length);
for(i=0; i<length; i++){
switch(i%3) {
case 0: ret= regexec(&regex1, questatsout[i], 0, NULL, 0);
for (i = 0; i < length; i++){
switch (i%3) {
case 0: ret = regexec(&regex1, questatsout[i], 0, NULL, 0);
if (ret == 0)
sscanf(questatsout[i], "qdisc noqueue %d: dev %s %s refcnt %d\n", &queuests.noqueue, dev, user, &queuests.refcnt);
sscanf(questatsout[i], "qdisc noqueue %d: dev %49s %49s refcnt %d\n", &queuests.noqueue, dev, user, &queuests.refcnt);
else {
ret= regexec(&regex2, questatsout[i], 0, NULL, 0);
if (ret == 0)
sscanf(questatsout[i], "qdisc pfifo_fast %d: dev %s %s refcnt %d\n", &queuests.pfifo_fast, dev, user, &queuests.refcnt);
sscanf(questatsout[i], "qdisc pfifo_fast %d: dev %49s %49s refcnt %d\n", &queuests.pfifo_fast, dev, user, &queuests.refcnt);
}
strcpy(queuests.dev, dev);
break;
@ -373,13 +369,11 @@ int browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev
if(lastinstancestore != NULL && inst_last !=NULL)
inst_last= dmstrdup(lastinstancestore);
instance = handle_update_instance(1, dmctx, &inst_last, update_instance_alias, 3, dmmap_sect, "queuestatsinstance", "queuestatsalias");
instance = handle_update_instance(1, dmctx, &inst_last, update_instance_alias, 3, dmmap_sect, "queuestatsinstance", "queuestatsalias");
lastinstancestore= dmstrdup(inst_last);
instancestore= dmstrdup(instance);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&queuests, instance) == DM_STOP)
goto end;
queuests= emptyquestats;
dmfree(instance);
queuests = emptyquestats;
break;
}
}
@ -390,17 +384,16 @@ int browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev
int browseQoSShaperInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *wnum = NULL, *wnum_last = NULL;
char buf[12];
struct uci_section *s = NULL;
struct dmmap_dup *p;
char *limitrate= NULL;
char *limitrate = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("qos", "class", "dmmap_qos", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "limitrate", &limitrate);
if(limitrate == NULL || strlen(limitrate) == 0)
if (limitrate == NULL || strlen(limitrate) == 0)
continue;
wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "shaperinstance", "shaperalias");
wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, p->dmmap_section, "shaperinstance", "shaperalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, wnum) == DM_STOP)
break;
}
@ -412,13 +405,13 @@ int browseQoSShaperInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_dat
int addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s, *dmmap_qos_classify;
char *last_inst= NULL, *sect_name= NULL, *qos_comment, *v;
char *last_inst = NULL, *sect_name = NULL, *qos_comment, *v;
char ib[8];
last_inst= get_last_instance_bbfdm("dmmap_qos", "classify", "classifinstance");
last_inst = get_last_instance_bbfdm("dmmap_qos", "classify", "classifinstance");
if (last_inst)
sprintf(ib, "%s", last_inst);
snprintf(ib, sizeof(ib), "%s", last_inst);
else
sprintf(ib, "%s", "1");
snprintf(ib, sizeof(ib), "%s", "1");
dmasprintf(&qos_comment, "QoS classify %d", atoi(ib)+1);
dmuci_add_section("qos", "classify", &s, &sect_name);
@ -432,10 +425,8 @@ int addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char
int 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;
struct uci_section *ss = NULL;
struct uci_section *dmmap_section;
struct dmmap_dup *p = (struct dmmap_dup*)data;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
switch (del_action) {
@ -462,7 +453,7 @@ int delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char
ss = s;
found++;
}
if (ss != NULL){
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);
@ -533,13 +524,14 @@ int delObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char *instan
int addObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s, *dmmap_qos_class;
char *last_inst= NULL, *sect_name= NULL, *qos_comment, *v;
char *last_inst = NULL, *sect_name = NULL, *v;
char ib[8];
last_inst= get_last_instance_bbfdm("dmmap_qos", "class", "queueinstance");
last_inst = get_last_instance_bbfdm("dmmap_qos", "class", "queueinstance");
if (last_inst)
sprintf(ib, "%s", last_inst);
snprintf(ib, sizeof(ib), "%s", last_inst);
else
sprintf(ib, "%s", "1");
snprintf(ib, sizeof(ib), "%s", "1");
dmuci_add_section("qos", "class", &s, &sect_name);
dmuci_set_value_by_section(s, "packetsize", "1000");
@ -553,14 +545,12 @@ int addObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char **instanc
int delObjQoSQueue(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;
struct uci_section *ss = NULL;
struct uci_section *dmmap_section;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
switch (del_action) {
case DEL_INST:
if(is_section_unnamed(section_name(p->config_section))){
if (is_section_unnamed(section_name(p->config_section))) {
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_qos", "class", "queueinstance", section_name(p->config_section), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "queueinstance", "dmmap_qos", "class");
@ -573,18 +563,18 @@ int delObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char *instance
break;
case DEL_ALL:
uci_foreach_sections("qos", "class", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
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){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_qos", "class", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
@ -615,13 +605,14 @@ int delObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char *ins
int addObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s, *dmmap_qos_class;
char *last_inst= NULL, *sect_name= NULL, *qos_comment, *v;
char *last_inst = NULL, *sect_name = NULL, *v;
char ib[8];
last_inst= get_last_instance_bbfdm_without_update("dmmap_qos", "class", "shaperinstance");
if (last_inst)
sprintf(ib, "%s", last_inst);
snprintf(ib, sizeof(ib), "%s", last_inst);
else
sprintf(ib, "%s", "1");
snprintf(ib, sizeof(ib), "%s", "1");
dmuci_add_section("qos", "class", &s, &sect_name);
dmuci_set_value_by_section(s, "limitrate", "1000");
@ -996,24 +987,23 @@ int get_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *dat
{
struct dmmap_dup *p= (struct dmmap_dup *) data;
struct uci_section *s;
char *classes= NULL, **classesarr, *classgroup= NULL, *ifaceclassgrp, *targetclass;
int nbre= 0;
char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp, *targetclass;
size_t length;
dmuci_get_value_by_section_string(p->config_section, "target", &targetclass);
uci_foreach_sections("qos", "classgroup", s) {
dmuci_get_value_by_section_string(s, "classes", &classes);
classesarr= strsplit(classes, " ", &length);
if(classes!=NULL && is_array_elt_exist(classesarr, targetclass, length)){
classesarr = strsplit(classes, " ", &length);
if (classes != NULL && is_array_elt_exist(classesarr, targetclass, length)) {
dmasprintf(&classgroup, "%s", section_name(s));
break;
}
}
if(classgroup == NULL)
if (classgroup == NULL)
return 0;
uci_foreach_sections("qos", "interface", s) {
dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp);
if(ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0){
if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value);
@ -3200,16 +3190,15 @@ int set_QoSQueue_TrafficClasses(char *refparam, struct dmctx *ctx, void *data, c
int get_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct dmmap_dup *p= (struct dmmap_dup *) data;
struct dmmap_dup *p = (struct dmmap_dup *)data;
struct uci_section *s;
char *classes= NULL, **classesarr, *classgroup= NULL, *ifaceclassgrp, *targetclass;
int nbre= 0;
char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp;
size_t length;
uci_foreach_sections("qos", "classgroup", s) {
dmuci_get_value_by_section_string(s, "classes", &classes);
classesarr= strsplit(classes, " ", &length);
if(classes!=NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){
classesarr = strsplit(classes, " ", &length);
if (classes != NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){
dmasprintf(&classgroup, "%s", section_name(s));
break;
}
@ -3218,7 +3207,7 @@ int get_QoSQueue_Interface(char *refparam, struct dmctx *ctx, void *data, char *
return 0;
uci_foreach_sections("qos", "interface", s) {
dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp);
if(ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0){
if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value);
@ -3610,16 +3599,15 @@ int set_QoSShaper_Alias(char *refparam, struct dmctx *ctx, void *data, char *ins
int get_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct dmmap_dup *p= (struct dmmap_dup *) data;
struct dmmap_dup *p = (struct dmmap_dup *)data;
struct uci_section *s;
char *classes= NULL, **classesarr, *classgroup= NULL, *ifaceclassgrp, *targetclass;
int nbre= 0;
char *classes = NULL, **classesarr, *classgroup = NULL, *ifaceclassgrp;
size_t length;
uci_foreach_sections("qos", "classgroup", s) {
dmuci_get_value_by_section_string(s, "classes", &classes);
classesarr= strsplit(classes, " ", &length);
if(classes!=NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){
if (classes != NULL && is_array_elt_exist(classesarr, section_name(p->config_section), length)){
dmasprintf(&classgroup, "%s", section_name(s));
break;
}
@ -3628,7 +3616,7 @@ int get_QoSShaper_Interface(char *refparam, struct dmctx *ctx, void *data, char
return 0;
uci_foreach_sections("qos", "interface", s) {
dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp);
if(ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0){
if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value);
if (*value == NULL)
adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), section_name(s), value);

View file

@ -11,6 +11,8 @@
#ifndef __QOS_H
#define __QOS_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tQoSObj[];
extern DMLEAF tQoSParams[];
extern DMLEAF tQoSClassificationParams[];
@ -23,10 +25,9 @@ extern DMLEAF tQoSShaperParams[];
#define queuessts1 "^qdisc noqueue [0-9]*: dev [[:alnum:]]* [[:alnum:]]* refcnt [0-9]*"
#define queuessts2 "^qdisc pfifo_fast [0-9]*: dev [[:alnum:]]* [[:alnum:]]* refcnt [0-9]*"
//#define queuessts3 "^[ ]*Sent [0-9]* bytes [0-9]* pkt (dropped [0-9]*, overlimits [0-9]* requeues [0-9]*)"
//#define queuessts4 "^[ ]*backlog [0-9]*b [0-9]*p requeues [0-9]*"
struct queuestats {
struct queuestats
{
struct uci_section *dmsect;
char dev[50];
char user[50];

View file

@ -10,23 +10,8 @@
*
*/
#include <uci.h>
#include <ctype.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "routing.h"
#include "dmentry.h"
enum enum_route_type {
ROUTE_STATIC,
ROUTE_DYNAMIC,
ROUTE_DISABLED
};
#include "routing.h"
/* *** Device.Routing. *** */
DMOBJ tRoutingObj[] = {
@ -178,6 +163,7 @@ static unsigned char is_proc_route6_in_config(char *ciface, char *cip, char *cgw
gw = (*gw) ? gw : "::";
dmuci_get_value_by_section_string(s, "interface", &v);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", v, String}}, 1, &jobj);
if (!jobj) return 0;
v = dmjson_get_value(jobj, 1, "device");
if (((*v != '\0' && strcmp(ciface, v) == 0) || ((*gw != ':' || *(gw+1) != ':') && strcmp(cgw, gw) == 0)) && strcmp(cip, ip) == 0) {
return 1;
@ -205,11 +191,9 @@ static bool is_cfg_route_active(struct uci_section *s)
dmuci_get_value_by_section_string(s, "netmask", &mask);
fp = fopen(ROUTING_FILE, "r");
if ( fp != NULL)
{
if (fp != NULL) {
fgets(line, MAX_PROC_ROUTING, fp);
while (fgets(line, MAX_PROC_ROUTING, fp) != NULL )
{
while (fgets(line, MAX_PROC_ROUTING, fp) != NULL) {
if (line[0] == '\n')
continue;
parse_proc_route_line(line, &proute);
@ -269,14 +253,12 @@ static char *forwarding_update_instance_alias_bbfdm(int action, char **last_inst
if (instance[0] == '\0') {
if (*find_max) {
int m = get_forwarding_last_inst();
sprintf(buf, "%d", m+1);
snprintf(buf, sizeof(buf), "%d", m+1);
*find_max = false;
}
else if (last_inst == NULL) {
sprintf(buf, "%d", 1);
}
else {
sprintf(buf, "%d", atoi(*last_inst)+1);
} else if (last_inst == NULL) {
snprintf(buf, sizeof(buf), "%d", 1);
} else {
snprintf(buf, sizeof(buf), "%d", atoi(*last_inst)+1);
}
instance = DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, inst_opt, buf);
}
@ -284,10 +266,10 @@ static char *forwarding_update_instance_alias_bbfdm(int action, char **last_inst
if (action == INSTANCE_MODE_ALIAS) {
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias[0] == '\0') {
sprintf(buf, "cpe-%s", instance);
snprintf(buf, sizeof(buf), "cpe-%s", instance);
alias = DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, alias_opt, buf);
}
sprintf(buf, "[%s]", alias);
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
return instance;
@ -331,14 +313,12 @@ static char *forwarding6_update_instance_alias_bbfdm(int action, char **last_ins
if (instance[0] == '\0') {
if (*find_max) {
int m = get_forwarding6_last_inst();
sprintf(buf, "%d", m+1);
snprintf(buf, sizeof(buf), "%d", m+1);
*find_max = false;
}
else if (last_inst == NULL) {
sprintf(buf, "%d", 1);
}
else {
sprintf(buf, "%d", atoi(*last_inst)+1);
} else if (last_inst == NULL) {
snprintf(buf, sizeof(buf), "%d", 1);
} else {
snprintf(buf, sizeof(buf), "%d", atoi(*last_inst)+1);
}
instance = DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, inst_opt, buf);
}
@ -346,10 +326,10 @@ static char *forwarding6_update_instance_alias_bbfdm(int action, char **last_ins
if (action == INSTANCE_MODE_ALIAS) {
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias[0] == '\0') {
sprintf(buf, "cpe-%s", instance);
snprintf(buf, sizeof(buf), "cpe-%s", instance);
alias = DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, alias_opt, buf);
}
sprintf(buf, "[%s]", alias);
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
return instance;
@ -370,11 +350,9 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN
dmuci_get_value_by_section_string(s, "device", &iface);
found = 0;
fp = fopen(ROUTING_FILE, "r");
if ( fp != NULL)
{
if ( fp != NULL) {
fgets(line, MAX_PROC_ROUTING, fp);
while (fgets(line, MAX_PROC_ROUTING, fp) != NULL )
{
while (fgets(line, MAX_PROC_ROUTING, fp) != NULL) {
if (line[0] == '\n')
continue;
parse_proc_route_line(line, &proute);
@ -392,8 +370,7 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN
fp = fopen(ROUTING_FILE, "r");
if ( fp != NULL) {
fgets(line, MAX_PROC_ROUTING, fp);
while (fgets(line, MAX_PROC_ROUTING, fp) != NULL )
{
while (fgets(line, MAX_PROC_ROUTING, fp) != NULL) {
if (line[0] == '\n')
continue;
parse_proc_route_line(line, &proute);
@ -402,6 +379,10 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN
iface = "";
uci_foreach_sections("network", "interface", s) {
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");
if (strcmp(str, proute.iface) == 0) {
iface = section_name(s);
@ -448,7 +429,7 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
while (fgets(buf, 512, fp) != NULL) {
if (*buf == '\n' || *buf == '\0')
continue;
sscanf(buf, "%8x%8x%8x%8x %x %*s %*s %8x%8x%8x%8x %x %x %x %x %s", &ip[0], &ip[1], &ip[2], &ip[3],
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;
@ -457,12 +438,11 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
ip[2] = htonl(ip[2]);
ip[3] = htonl(ip[3]);
inet_ntop(AF_INET6, ip, buf, INET6_ADDRSTRLEN);
sprintf(ipstr, "%s/%u", buf, prefix);
snprintf(ipstr, sizeof(ipstr), "%s/%u", buf, prefix);
if (strcmp(iface, dev) == 0 && strcmp(ipstr, target) == 0) {
found = 1;
break;
}
}
if (!found)
dmuci_delete_by_section(s, NULL, NULL);
@ -476,7 +456,7 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
while (fgets(buf , 512 , fp) != NULL) {
if (*buf == '\n' || *buf == '\0')
continue;
sscanf(buf, "%8x%8x%8x%8x %x %*s %*s %8x%8x%8x%8x %x %x %x %x %s", &ip[0], &ip[1], &ip[2], &ip[3],
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;
@ -489,13 +469,17 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
gw[2] = htonl(gw[2]);
gw[3] = htonl(gw[3]);
inet_ntop(AF_INET6, ip, buf, INET6_ADDRSTRLEN);
sprintf(ipstr, "%s/%u", buf, prefix);
snprintf(ipstr, sizeof(ipstr), "%s/%u", buf, 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) {
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");
if (strcmp(str, dev) == 0) {
iface = section_name(s);
@ -509,7 +493,7 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "gateway", gwstr);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "interface", iface);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "device", dev);
sprintf(buf, "%u", metric);
snprintf(buf, sizeof(buf), "%u", metric);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "metric", buf);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "route6instance", instance);
dmfree(instance);
@ -519,8 +503,8 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
**************************************************************/
int get_router_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "1";
@ -589,9 +573,7 @@ int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struct dmctx
int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if(routeargs->type == ROUTE_DISABLED)
if(((struct routingfwdargs *)data)->type == ROUTE_DISABLED)
*value = "0";
else
*value = "1";
@ -600,7 +582,6 @@ int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *da
int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
bool b;
switch (action) {
@ -611,14 +592,14 @@ int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *da
case VALUESET:
string_to_bool(value, &b);
if (b) {
if (routeargs->type == ROUTE_STATIC)
if (((struct routingfwdargs *)data)->type == ROUTE_STATIC)
return 0;
dmuci_set_value_by_section(routeargs->routefwdsection, NULL, "route");
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, NULL, "route");
}
else {
if (routeargs->type == ROUTE_DISABLED)
if (((struct routingfwdargs *)data)->type == ROUTE_DISABLED)
return 0;
dmuci_set_value_by_section(routeargs->routefwdsection, NULL, "route_disabled");
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, NULL, "route_disabled");
}
return 0;
}
@ -627,12 +608,10 @@ int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *da
int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if(routeargs->type == ROUTE_DISABLED) {
if(((struct routingfwdargs *)data)->type == ROUTE_DISABLED) {
*value = "Disabled";
} else {
if (is_cfg_route_active(routeargs->routefwdsection))
if (is_cfg_route_active(((struct routingfwdargs *)data)->routefwdsection))
*value = "Enabled";
else
*value = "Error";
@ -643,10 +622,8 @@ int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *da
/*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestIPAddress!UCI:network/route,@i-1/target*/
int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "target", value);
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "target", value);
if ((*value)[0] == '\0')
*value = "0.0.0.0";
return 0;
@ -654,13 +631,11 @@ int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *da
int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(routeargs->routefwdsection, "target", value);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "target", value);
return 0;
}
return 0;
@ -669,10 +644,8 @@ int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *da
/*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestSubnetMask!UCI:network/route,@i-1/netmask*/
int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "netmask", value);
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "netmask", value);
if ((*value)[0] == '\0')
*value = "255.255.255.255";
return 0;
@ -680,13 +653,11 @@ int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *
int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(routeargs->routefwdsection, "netmask", value);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "netmask", value);
return 0;
}
return 0;
@ -694,9 +665,7 @@ int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *
int get_router_ipv4forwarding_static_route(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->type != ROUTE_DYNAMIC)
if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC)
*value = "1";
else
*value = "0";
@ -712,9 +681,7 @@ int get_router_ipv4forwarding_forwarding_policy(char *refparam, struct dmctx *ct
int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->type != ROUTE_DYNAMIC)
if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC)
*value = "Static";
return 0;
}
@ -722,10 +689,8 @@ int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, void *da
/*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.GatewayIPAddress!UCI:network/route,@i-1/gateway*/
int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "gateway", value);
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "gateway", value);
if ((*value)[0] == '\0')
*value = "0.0.0.0";
return 0;
@ -733,13 +698,11 @@ int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void
int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(routeargs->routefwdsection, "gateway", value);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "gateway", value);
return 0;
}
return 0;
@ -747,11 +710,10 @@ int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void
int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
char *linker;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "interface", &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)
@ -763,7 +725,6 @@ int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct
int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker;
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
@ -771,7 +732,7 @@ int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker) {
dmuci_set_value_by_section(routeargs->routefwdsection, "interface", linker);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", linker);
dmfree(linker);
}
return 0;
@ -782,10 +743,8 @@ int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct
/*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.ForwardingMetric!UCI:network/route,@i-1/metric*/
int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "metric", value);
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "metric", value);
if ((*value)[0] == '\0')
*value = "0";
return 0;
@ -793,13 +752,11 @@ int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *da
int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(routeargs->routefwdsection, "metric", value);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "metric", value);
return 0;
}
return 0;
@ -831,10 +788,8 @@ int get_RoutingRouterIPv6Forwarding_Status(char *refparam, struct dmctx *ctx, vo
/*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.DestIPPrefix!UCI:network/route,@i-1/target*/
int get_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "target", value);
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "target", value);
if ((*value)[0] == '\0')
*value = "::";
return 0;
@ -842,13 +797,11 @@ int get_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *c
int set_RoutingRouterIPv6Forwarding_DestIPPrefix(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(routeargs->routefwdsection, "target", value);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "target", value);
return 0;
}
return 0;
@ -874,10 +827,8 @@ int set_RoutingRouterIPv6Forwarding_ForwardingPolicy(char *refparam, struct dmct
/*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.NextHop!UCI:network/route,@i-1/gateway*/
int get_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "gateway", value);
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "gateway", value);
if ((*value)[0] == '\0')
*value = "::";
return 0;
@ -885,13 +836,11 @@ int get_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, v
int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(routeargs->routefwdsection, "gateway", value);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "gateway", value);
return 0;
}
return 0;
@ -899,11 +848,10 @@ int set_RoutingRouterIPv6Forwarding_NextHop(char *refparam, struct dmctx *ctx, v
int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
char *linker;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "interface", &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)
@ -915,7 +863,6 @@ int get_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx,
int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker;
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
@ -923,7 +870,7 @@ int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx,
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker) {
dmuci_set_value_by_section(routeargs->routefwdsection, "interface", linker);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "interface", linker);
dmfree(linker);
}
return 0;
@ -933,9 +880,7 @@ int set_RoutingRouterIPv6Forwarding_Interface(char *refparam, struct dmctx *ctx,
int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->type != ROUTE_DYNAMIC)
if (((struct routingfwdargs *)data)->type != ROUTE_DYNAMIC)
*value = "Static";
return 0;
}
@ -943,10 +888,8 @@ int get_RoutingRouterIPv6Forwarding_Origin(char *refparam, struct dmctx *ctx, vo
/*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.ForwardingMetric!UCI:network/route,@i-1/metric*/
int get_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
if (routeargs->routefwdsection != NULL)
dmuci_get_value_by_section_string(routeargs->routefwdsection, "metric", value);
if (((struct routingfwdargs *)data)->routefwdsection != NULL)
dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "metric", value);
if ((*value)[0] == '\0')
*value = "0";
return 0;
@ -954,13 +897,11 @@ int get_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmct
int set_RoutingRouterIPv6Forwarding_ForwardingMetric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(routeargs->routefwdsection, "metric", value);
dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "metric", value);
return 0;
}
return 0;
@ -992,7 +933,7 @@ int set_RoutingRouteInformation_Enable(char *refparam, struct dmctx *ctx, void *
int get_RoutingRouteInformation_InterfaceSettingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
json_object *res, *jobj, *route_obj;
json_object *res, *route_obj;
char *proto, *ip6addr;
int entries = 0;
@ -1023,7 +964,7 @@ int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, struct dm
*value = "NoForwardingEntry";
target = dmjson_get_value((struct json_object *)data, 1, "target");
mask = dmjson_get_value((struct json_object *)data, 1, "mask");
sprintf(buf, "%s/%s", target, mask);
snprintf(buf, sizeof(buf), "%s/%s", target, mask);
nexthop = dmjson_get_value((struct json_object *)data, 1, "nexthop");
uci_foreach_sections("network", "route6", s) {
dmuci_get_value_by_section_string(s, "target", &ip_target);
@ -1041,7 +982,7 @@ int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct
struct uci_section *s = NULL;
char buf[512], dev[32], ipstr[INET6_ADDRSTRLEN + 8], gwstr[INET6_ADDRSTRLEN + 8];
unsigned int ip[4], gw[4], flags, refcnt, use, metric, prefix;
char *linker, *source, *nexthop, *str, *iface = "";
char *source, *nexthop, *str, *iface = "";
json_object *jobj;
FILE* fp = NULL;
@ -1054,7 +995,7 @@ int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct
while (fgets(buf , 512 , fp) != NULL) {
if (*buf == '\n' || *buf == '\0')
continue;
sscanf(buf, "%8x%8x%8x%8x %x %*s %*s %8x%8x%8x%8x %x %x %x %x %s", &ip[0], &ip[1], &ip[2], &ip[3],
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;
@ -1067,7 +1008,7 @@ int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct
gw[2] = htonl(gw[2]);
gw[3] = htonl(gw[3]);
inet_ntop(AF_INET6, ip, buf, INET6_ADDRSTRLEN);
sprintf(ipstr, "%s/%u", buf, prefix);
snprintf(ipstr, sizeof(ipstr), "%s/%u", buf, prefix);
inet_ntop(AF_INET6, gw, gwstr, INET6_ADDRSTRLEN);
if((strcmp(source, ipstr) == 0) && (strcmp(nexthop, gwstr) == 0))
break;
@ -1075,6 +1016,7 @@ int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, struct
fclose(fp);
uci_foreach_sections("network", "interface", s) {
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");
if (strcmp(str, dev) == 0) {
iface = section_name(s);
@ -1107,8 +1049,8 @@ int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refparam, st
}
/*************************************************************
* SET AND GET ALIAS FOR ROUTER OBJ
/*************************************************************/
* SET AND GET ALIAS FOR ROUTER OBJ
**************************************************************/
int get_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "router_alias", value);
@ -1130,7 +1072,6 @@ int set_RoutingRouter_Alias(char *refparam, struct dmctx *ctx, void *data, char
int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
*value = "";
if(((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC)
dmmap_section= ((struct routingfwdargs *)data)->routefwdsection;
@ -1138,7 +1079,6 @@ int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *dat
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
else
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route_disabled", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "routealias", value);
return 0;
}
@ -1147,17 +1087,16 @@ int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *dat
{
struct uci_section *dmmap_section;
if(((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC)
dmmap_section= ((struct routingfwdargs *)data)->routefwdsection;
else if (((struct routingfwdargs *)data)->type == ROUTE_STATIC)
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
else
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route_disabled", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
if(((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC)
dmmap_section= ((struct routingfwdargs *)data)->routefwdsection;
else if (((struct routingfwdargs *)data)->type == ROUTE_STATIC)
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
else
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route_disabled", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "routealias", value);
return 0;
}
@ -1167,12 +1106,11 @@ int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *dat
int get_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
*value = "";
if(((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC)
dmmap_section= ((struct routingfwdargs *)data)->routefwdsection;
dmmap_section = ((struct routingfwdargs *)data)->routefwdsection;
else
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "route6alias", value);
return 0;
}
@ -1181,15 +1119,14 @@ int set_RoutingRouterIPv6Forwarding_Alias(char *refparam, struct dmctx *ctx, voi
{
struct uci_section *dmmap_section;
if(((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC)
dmmap_section= ((struct routingfwdargs *)data)->routefwdsection;
else
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
if(((struct routingfwdargs *)data)->type == ROUTE_DYNAMIC)
dmmap_section = ((struct routingfwdargs *)data)->routefwdsection;
else
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "route6alias", value);
return 0;
}
@ -1204,8 +1141,8 @@ char *get_routing_perm(char *refparam, struct dmctx *dmctx, void *data, char *in
struct dm_permession_s DMRouting = {"0", &get_routing_perm};
/*************************************************************
* ADD DEL OBJ
/*************************************************************/
* ADD DEL OBJ
**************************************************************/
int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *value, *v, instance[8];
@ -1215,7 +1152,7 @@ int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **ins
check_create_dmmap_package("dmmap_route_forwarding");
last_inst = get_forwarding_last_inst();
sprintf(instance, "%d", last_inst);
snprintf(instance, sizeof(instance), "%d", last_inst);
dmuci_add_section_and_rename("network", "route", &s, &value);
dmuci_set_value_by_section(s, "metric", "0");
dmuci_set_value_by_section(s, "interface", "lan");
@ -1228,22 +1165,17 @@ int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **ins
int delete_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
struct uci_section *dmmap_section= NULL;
struct uci_section *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route", section_name(routeargs->routefwdsection), &dmmap_section);
if(dmmap_section != NULL) {
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(routeargs->routefwdsection, NULL, NULL);
break;
}
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route_disabled", section_name(routeargs->routefwdsection), &dmmap_section);
if(dmmap_section != NULL) {
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(routeargs->routefwdsection, NULL, NULL);
}
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct routingfwdargs *)data)->routefwdsection, NULL, NULL);
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route_disabled", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct routingfwdargs *)data)->routefwdsection, NULL, NULL);
break;
case DEL_ALL:
return FAULT_9005;
@ -1260,7 +1192,7 @@ int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **ins
check_create_dmmap_package("dmmap_route_forwarding");
last_inst = get_forwarding6_last_inst();
sprintf(instance, "%d", last_inst);
snprintf(instance, sizeof(instance), "%d", last_inst);
dmuci_add_section_and_rename("network", "route6", &s, &value);
dmuci_set_value_by_section(s, "metric", "0");
dmuci_set_value_by_section(s, "interface", "lan");
@ -1273,16 +1205,13 @@ int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **ins
int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct routingfwdargs *routeargs = (struct routingfwdargs *)data;
struct uci_section *dmmap_section= NULL;
struct uci_section *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route6", section_name(routeargs->routefwdsection), &dmmap_section);
if(dmmap_section != NULL) {
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(routeargs->routefwdsection, NULL, NULL);
}
get_dmmap_section_of_config_section("dmmap_route_forwarding", "route6", section_name(((struct routingfwdargs *)data)->routefwdsection), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct routingfwdargs *)data)->routefwdsection, NULL, NULL);
break;
case DEL_ALL:
return FAULT_9005;
@ -1291,8 +1220,8 @@ int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char *i
}
/*************************************************************
* SUB ENTRIES
/*************************************************************/
* SUB ENTRIES
**************************************************************/
int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
@ -1311,7 +1240,7 @@ int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *iroute = NULL, *iroute_last = NULL;
struct uci_section *s = NULL, *ss = NULL;
struct uci_section *ss = NULL;
bool find_max = true;
struct routingfwdargs curr_routefwdargs = {0};
struct dmmap_dup *p;
@ -1348,7 +1277,7 @@ end:
int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *iroute = NULL, *iroute_last = NULL;
struct uci_section *s = NULL, *ss = NULL;
struct uci_section *ss = NULL;
bool find_max = true;
struct routingfwdargs curr_route6fwdargs = {0};
struct dmmap_dup *p;
@ -1376,7 +1305,7 @@ end:
int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
json_object *res, *jobj, *route_obj;
json_object *res, *route_obj;
char *proto, *ip6addr, *idx, *idx_last = NULL;
int id = 0, entries = 0;

View file

@ -13,9 +13,17 @@
#ifndef __ROUTING_H
#define __ROUTING_H
#include <libbbf_api/dmcommon.h>
#define PROC_ROUTE6 "/proc/net/ipv6_route"
extern struct dm_permession_s DMRouting;
enum enum_route_type {
ROUTE_STATIC,
ROUTE_DYNAMIC,
ROUTE_DISABLED
};
extern DMOBJ tRoutingObj[];
extern DMLEAF tRoutingParams[];
extern DMOBJ tRoutingRouterObj[];

View file

@ -9,12 +9,6 @@
*
*/
#include <uci.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
#include "times.h"
@ -49,7 +43,6 @@ int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instanc
int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
int check;
pid_t pid;
switch (action) {
@ -60,17 +53,16 @@ int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instanc
case VALUESET:
string_to_bool(value, &b);
if(b) {
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "enable"); //TODO wait ubus command
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "enable");
pid = get_pid("ntpd");
if (pid < 0) {
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "start"); //TODO wait ubus command
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "start");
}
}
else {
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "disable"); //TODO wait ubus command
} else {
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "disable");
pid = get_pid("ntpd");
if (pid > 0) {
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "stop"); //TODO may be should be updated with ubus call uci
DMCMD("/etc/rc.common", 2, "/etc/init.d/ntpd", "stop");
}
}
return 0;
@ -78,7 +70,8 @@ int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instanc
return 0;
}
int get_time_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int get_time_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *path = "/etc/rc.d/*ntpd";
if (check_file(path))
@ -90,7 +83,7 @@ int get_time_status(char *refparam, struct dmctx *ctx, void *data, char *instanc
int get_time_CurrentLocalTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char time_buf[26] = {0};
char time_buf[27] = {0};
struct tm *t_tm;
*value = "0001-01-01T00:00:00Z";
@ -131,13 +124,14 @@ int set_time_LocalTimeZone(char *refparam, struct dmctx *ctx, void *data, char *
return 0;
}
int get_local_time_zone_olson(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
int get_local_time_zone_olson(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_option_value_string("system", "@system[0]", "zonename", value);
return 0;
}
int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int index)
{
char *pch;
bool found = 0;
int element = 0;
struct uci_list *v;
@ -148,7 +142,7 @@ int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int inde
uci_foreach_element(v, e) {
element++;
if (element == index) {
*value = dmstrdup(e->name); // MEM WILL BE FREED IN DMMEMCLEAN
*value = dmstrdup(e->name);
found = 1;
break;
}
@ -164,16 +158,17 @@ int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int inde
return 0;
}
int get_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value){
char *iface= NULL, *interface= NULL;
*value= "";
int get_time_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *iface = NULL, *interface = NULL;
*value = "";
dmuci_get_option_value_string("system", "ntp", "interface", &iface);
if (*iface == '\0' || strlen(iface)== 0)
if (*iface == '\0' || strlen(iface) == 0)
return 0;
adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", dmroot, dm_delim, dm_delim, dm_delim), iface, &interface);
if (*interface == '\0')
return 0;
*value= dmstrdup(interface);
*value = dmstrdup(interface);
return 0;
}
@ -208,7 +203,7 @@ int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, cha
switch (action) {
case VALUECHECK:
adm_entry_get_linker_value(ctx, value, &iface);
if(iface == NULL || iface[0] == '\0')
if (iface == NULL || iface[0] == '\0')
return FAULT_9007;
break;
case VALUESET:
@ -221,12 +216,9 @@ int set_time_source_interface(char *refparam, struct dmctx *ctx, void *data, cha
int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value, int index)
{
char *pch, *path;
int check;
struct uci_list *v;
struct uci_element *e;
int count = 0;
int i = 0;
int count = 0, i = 0;
char *ntp[5] = {0};
switch (action) {
@ -236,21 +228,19 @@ int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *valu
dmuci_get_option_value_list("system", "ntp", "server", &v);
if (v) {
uci_foreach_element(v, e) {
if ((count+1) == index) {
if ((count + 1) == index)
ntp[count] = dmstrdup(value);
}
else {
ntp[count] = dmstrdup(e->name);
}
else
ntp[count] = dmstrdup(e->name);
count++;
if (count > 4)
break;
}
}
if (index > count) {
ntp[index-1] = dmstrdup(value);
ntp[index - 1] = dmstrdup(value);
count = index;
}
}
for (i = 0; i < 5; i++) {
if (ntp[i] && (*ntp[i]) != '\0')
count = i+1;

View file

@ -11,7 +11,8 @@
#ifndef __TIMES_H
#define __TIMES_H
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
extern DMLEAF tTimeParams[];

View file

@ -1,26 +1,20 @@
/*
* Copyright (C) 2019 iopsys Software Solutions AB
* Copyright (C) 2020 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 Imen Bhiri <imen.bhiri@pivasoftware.com>
* Omar Kallel <omar.kallel@pivasoftware.com>
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
*/
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "upnp.h"
/* *** Device.UPnP. *** */
DMOBJ tUPnPObj[] = {
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
{"Device", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUPnPDeviceObj, tUPnPDeviceParams, NULL, BBFDM_BOTH},
{"Discovery", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUPnPDiscoveryObj, tUPnPDiscoveryParams, NULL, BBFDM_BOTH},
{"Description", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUPnPDescriptionObj, tUPnPDescriptionParams, NULL, BBFDM_BOTH},
@ -29,7 +23,7 @@ DMOBJ tUPnPObj[] = {
/* *** Device.UPnP.Device. *** */
DMOBJ tUPnPDeviceObj[] = {
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
{"Capabilities", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUPnPDeviceCapabilitiesParams, NULL, BBFDM_BOTH},
{0}
};
@ -70,7 +64,7 @@ DMLEAF tUPnPDeviceCapabilitiesParams[] = {
/* *** Device.UPnP.Discovery. *** */
DMOBJ tUPnPDiscoveryObj[] = {
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
{"RootDevice", &DMREAD, NULL, NULL, NULL, browseUPnPDiscoveryRootDeviceInst, NULL, NULL, NULL, NULL, tUPnPDiscoveryRootDeviceParams, get_root_device_linker, BBFDM_BOTH},
{"Device", &DMREAD, NULL, NULL, NULL, browseUPnPDiscoveryDeviceInst, NULL, NULL, NULL, NULL, tUPnPDiscoveryDeviceParams, get_device_linker, BBFDM_BOTH},
{"Service", &DMREAD, NULL, NULL, NULL, browseUPnPDiscoveryServiceInst, NULL, NULL, NULL, NULL, tUPnPDiscoveryServiceParams, get_service_linker, BBFDM_BOTH},
@ -129,7 +123,7 @@ DMLEAF tUPnPDiscoveryServiceParams[] = {
/* *** Device.UPnP.Description. *** */
DMOBJ tUPnPDescriptionObj[] = {
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
{"DeviceDescription", &DMREAD, NULL, NULL, NULL, browseUPnPDescriptionDeviceDescriptionInst, NULL, NULL, NULL, NULL, tUPnPDescriptionDeviceDescriptionParams, NULL, BBFDM_BOTH},
{"DeviceInstance", &DMREAD, NULL, NULL, NULL, browseUPnPDescriptionDeviceInstanceInst, NULL, NULL, NULL, NULL, tUPnPDescriptionDeviceInstanceParams, get_device_instance_linker, BBFDM_BOTH},
{"ServiceInstance", &DMREAD, NULL, NULL, NULL, browseUPnPDescriptionServiceInstanceInst, NULL, NULL, NULL, NULL, tUPnPDescriptionServiceInstanceParams, NULL, BBFDM_BOTH},
@ -232,8 +226,8 @@ int get_service_linker(char *refparam, struct dmctx *dmctx, void *data, char *in
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
int browseUPnPDiscoveryRootDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *devices = NULL, *device = NULL;
@ -500,8 +494,8 @@ int browseUPnPDescriptionServiceInstanceInst(struct dmctx *dmctx, DMNODE *parent
return 0;
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
**************************************************************/
/*#Device.UPnP.Device.Enable!UCI:upnpd/upnpd,config/enabled*/
int get_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
@ -515,7 +509,6 @@ int get_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *i
int set_UPnPDevice_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
int check;
switch (action) {
case VALUECHECK:
if (string_to_bool(value, &b))
@ -805,7 +798,7 @@ int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dmctx *ct
{
int nbre = 0, i;
char *is_root_device = NULL;
json_object *res = NULL, *devices = NULL, *device = NULL;
json_object *res = NULL, *devices = NULL, *device = NULL;
dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res);
if (res == NULL) {
@ -818,10 +811,10 @@ int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dmctx *ct
return 0;
}
size_t nbre_devices = json_object_array_length(devices);
if(nbre_devices>0){
for(i=0; i<nbre_devices; i++){
device= json_object_array_get_idx(devices, i);
is_root_device= dmjson_get_value(device, 1, "is_root_device");
if (nbre_devices > 0){
for (i = 0; i < nbre_devices; i++){
device = json_object_array_get_idx(devices, i);
is_root_device = dmjson_get_value(device, 1, "is_root_device");
if(strcmp(is_root_device, "0") == 0)
continue;
nbre ++;
@ -852,7 +845,7 @@ int get_UPnPDiscovery_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, v
int get_UPnPDiscovery_ServiceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res, *services;
json_object *res, *services;
dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res);
if (res == NULL) {
@ -1054,7 +1047,7 @@ int get_UPnPDescription_DeviceDescriptionNumberOfEntries(char *refparam, struct
int get_UPnPDescription_DeviceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res, *devicesinstances;
json_object *res, *devicesinstances;
dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res);
if (res == NULL) {
@ -1073,7 +1066,7 @@ int get_UPnPDescription_DeviceInstanceNumberOfEntries(char *refparam, struct dmc
int get_UPnPDescription_ServiceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res, *servicesinstances;
json_object *res, *servicesinstances;
dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res);
if (res == NULL) {
@ -1132,11 +1125,10 @@ int get_UPnPDescriptionDeviceInstance_ParentDevice(char *refparam, struct dmctx
int get_UPnPDescriptionDeviceInstance_DiscoveryDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
char **udnarray = NULL;
char *rootdevlink = NULL, *devlink = NULL;
int length;
char *rootdevlink = NULL, *devlink = NULL, **udnarray = NULL;
size_t length;
if(upnpdevinst->udn && upnpdevinst->udn[0]){
if (upnpdevinst->udn && upnpdevinst->udn[0]) {
udnarray = strsplit(upnpdevinst->udn, ":", &length);
adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cRootDevice%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), udnarray[1], &rootdevlink);
if(rootdevlink != NULL){
@ -1175,7 +1167,7 @@ int get_UPnPDescriptionDeviceInstance_DeviceCategory(char *refparam, struct dmct
int get_UPnPDescriptionDeviceInstance_Manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst= (struct upnp_device_inst *)data;
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
*value = upnpdevinst->manufacturer;
return 0;
}
@ -1188,21 +1180,21 @@ int get_UPnPDescriptionDeviceInstance_ManufacturerOUI(char *refparam, struct dmc
int get_UPnPDescriptionDeviceInstance_ManufacturerURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst= (struct upnp_device_inst *)data;
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
*value = upnpdevinst->manufacturer_url;
return 0;
}
int get_UPnPDescriptionDeviceInstance_ModelDescription(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst= (struct upnp_device_inst *)data;
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
*value = upnpdevinst->model_description;
return 0;
}
int get_UPnPDescriptionDeviceInstance_ModelName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst= (struct upnp_device_inst *)data;
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
*value = upnpdevinst->model_name;
return 0;
}
@ -1216,21 +1208,21 @@ int get_UPnPDescriptionDeviceInstance_ModelNumber(char *refparam, struct dmctx *
int get_UPnPDescriptionDeviceInstance_ModelURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst= (struct upnp_device_inst *)data;
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
*value = upnpdevinst->model_url;
return 0;
}
int get_UPnPDescriptionDeviceInstance_SerialNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst= (struct upnp_device_inst *)data;
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
*value = upnpdevinst->serial_number;
return 0;
}
int get_UPnPDescriptionDeviceInstance_UPC(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_device_inst *upnpdevinst= (struct upnp_device_inst *)data;
struct upnp_device_inst *upnpdevinst = (struct upnp_device_inst *)data;
*value = upnpdevinst->upc;
return 0;
}
@ -1244,7 +1236,7 @@ int get_UPnPDescriptionDeviceInstance_PresentationURL(char *refparam, struct dmc
int get_UPnPDescriptionServiceInstance_ParentDevice(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_service_inst *upnpserviceinst= (struct upnp_service_inst *)data;
struct upnp_service_inst *upnpserviceinst = (struct upnp_service_inst *)data;
char *devinstlink = NULL;
adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDescription%cDeviceInstance%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), upnpserviceinst->parentudn, &devinstlink);
if(devinstlink != NULL){
@ -1256,20 +1248,20 @@ int get_UPnPDescriptionServiceInstance_ParentDevice(char *refparam, struct dmctx
int get_UPnPDescriptionServiceInstance_ServiceId(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_service_inst *upnpserviceinst= (struct upnp_service_inst *)data;
struct upnp_service_inst *upnpserviceinst = (struct upnp_service_inst *)data;
*value = upnpserviceinst->serviceid;
return 0;
}
int get_UPnPDescriptionServiceInstance_ServiceDiscovery(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_service_inst *upnpserviceinst= (struct upnp_service_inst *)data;
struct upnp_service_inst *upnpserviceinst = (struct upnp_service_inst *)data;
char *usn = NULL, *devlink = NULL;
dmasprintf(&usn, "%s::%s", upnpserviceinst->parentudn, upnpserviceinst->servicetype);
if(usn && usn[0]){
if (usn && usn[0]) {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cUPnP%cDiscovery%cService%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim), usn, &devlink);
if(devlink != NULL){
*value =devlink;
if (devlink != NULL) {
*value = devlink;
return 0;
}
}
@ -1279,28 +1271,28 @@ int get_UPnPDescriptionServiceInstance_ServiceDiscovery(char *refparam, struct d
int get_UPnPDescriptionServiceInstance_ServiceType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_service_inst *upnpserviceinst= (struct upnp_service_inst *)data;
struct upnp_service_inst *upnpserviceinst = (struct upnp_service_inst *)data;
*value = upnpserviceinst->servicetype;
return 0;
}
int get_UPnPDescriptionServiceInstance_SCPDURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_service_inst *upnpserviceinst= (struct upnp_service_inst *)data;
struct upnp_service_inst *upnpserviceinst = (struct upnp_service_inst *)data;
*value = upnpserviceinst->scpdurl;
return 0;
}
int get_UPnPDescriptionServiceInstance_ControlURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_service_inst *upnpserviceinst= (struct upnp_service_inst *)data;
struct upnp_service_inst *upnpserviceinst = (struct upnp_service_inst *)data;
*value = upnpserviceinst->controlurl;
return 0;
}
int get_UPnPDescriptionServiceInstance_EventSubURL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct upnp_service_inst *upnpserviceinst= (struct upnp_service_inst *)data;
struct upnp_service_inst *upnpserviceinst = (struct upnp_service_inst *)data;
*value = upnpserviceinst->eventsuburl;
return 0;
}

View file

@ -1,18 +1,19 @@
/*
* Copyright (C) 2019 iopsys Software Solutions AB
* Copyright (C) 2020 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 Imen Bhiri <imen.bhiri@pivasoftware.com>
* Omar Kallel <omar.kallel@pivasoftware.com>
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
*/
#ifndef __UPNP_H
#define __UPNP_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tUPnPObj[];
extern DMOBJ tUPnPDeviceObj[];
extern DMLEAF tUPnPDeviceParams[];
@ -28,8 +29,6 @@ extern DMLEAF tUPnPDescriptionDeviceDescriptionParams[];
extern DMLEAF tUPnPDescriptionDeviceInstanceParams[];
extern DMLEAF tUPnPDescriptionServiceInstanceParams[];
extern struct list_head file_info_list;
struct upnpdiscovery {
char *st;
char *usn;

View file

@ -8,10 +8,6 @@
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <dirent.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmuci.h>
#include "dmentry.h"
#include "usb.h"
@ -176,39 +172,40 @@ DMLEAF tUSBUSBHostsHostDeviceConfigurationInterfaceParams[] = {
};
/*************************************************************
* INIT
/*************************************************************/
void init_usb_port(struct uci_section *dm, char *folder_name, char *folder_path, struct usb_port *port){
port->dm_usb_port= dm;
port->folder_name= dmstrdup(folder_name);
port->folder_path= dmstrdup(folder_path);
* INIT
*************************************************************/
void init_usb_port(struct uci_section *dm, char *folder_name, char *folder_path, struct usb_port *port)
{
port->dm_usb_port = dm;
port->folder_name = dmstrdup(folder_name);
port->folder_path = dmstrdup(folder_path);
}
void init_usb_interface(struct uci_section *dm, char *iface_name, char *iface_path, char *statistics_path, char *portlink, struct usb_interface *iface){
iface->dm_usb_iface= dm;
iface->iface_name= dmstrdup(iface_name);
iface->iface_path= dmstrdup(iface_path);
iface->portlink= dmstrdup(portlink);
iface->statistics_path= dmstrdup(statistics_path);
void init_usb_interface(struct uci_section *dm, char *iface_name, char *iface_path, char *statistics_path, char *portlink, struct usb_interface *iface)
{
iface->dm_usb_iface = dm;
iface->iface_name = dmstrdup(iface_name);
iface->iface_path = dmstrdup(iface_path);
iface->portlink = dmstrdup(portlink);
iface->statistics_path = dmstrdup(statistics_path);
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
*************************************************************/
int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
DIR *dir;
struct dirent *ent;
char *netfolderpath, *iface_name, *iface_path, *statistics_path, *port_link, *v, *instnbr = NULL, *instance = NULL;
size_t length;
char **foldersplit;
struct uci_section *s;
struct usb_interface iface= {};
LIST_HEAD(dup_list);
struct sysfs_dmsection *p;
char *netfolderpath, *iface_name, *iface_path, *statistics_path, *port_link, *instnbr = NULL, *instance = NULL;
size_t length;
char **foldersplit;
struct usb_interface iface = {};
LIST_HEAD(dup_list);
struct sysfs_dmsection *p;
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "port_link", "usb_iface_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "port_link", "usb_iface_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmasprintf(&netfolderpath, "%s/%s/net", SYSFS_USB_DEVICES_PATH, p->sysfs_folder_name);
if(!isfolderexist(netfolderpath)){
//dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL);
@ -231,7 +228,7 @@ int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_
init_usb_interface(p->dm, iface_name, iface_path, statistics_path, port_link, &iface);
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, p->dm, "usb_iface_instance", "usb_iface_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &iface, instance) == DM_STOP)
return 0;
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
@ -239,15 +236,13 @@ int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_
int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
int ret1, ret2;
char *folderpath, *instnbr = NULL, *instance = NULL, *v;
struct uci_section *s;
struct usb_port port= {};
LIST_HEAD(dup_list);
char *instnbr = NULL, *instance = NULL;
struct usb_port port = {0};
struct sysfs_dmsection *p;
LIST_HEAD(dup_list);
ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
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);
check_create_dmmap_package("dmmap_usb");
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) {
@ -256,10 +251,9 @@ int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
continue;
}
init_usb_port(p->dm, p->sysfs_folder_name, p->sysfs_folder_path, &port);
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_port_instance", "usb_port_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
return 0;
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
@ -267,12 +261,10 @@ int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
DIR *dir;
struct dirent *ent;
LIST_HEAD(dup_list);
struct sysfs_dmsection *p;
char *instance = NULL, *instnbr = NULL;
struct usb_port port= {};
LIST_HEAD(dup_list);
check_create_dmmap_package("dmmap_usb");
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list);
@ -299,11 +291,10 @@ int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmm
struct dirent *ent;
char *v, *dmmap_file_path, *sysfs_rep_path, *instance= NULL;
struct sysfs_dmsection *p;
int ret1, ret2;
char *deviceClassFile= NULL, *deviceClass= NULL, *hubpath;
char *deviceClassFile = NULL, *deviceClass = NULL, *hubpath;
ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
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);
LIST_HEAD(dup_list_no_inst);
@ -318,7 +309,7 @@ int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmm
sysfs_foreach_file(sysfsrep, dir, ent) {
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){
if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0) {
dmasprintf(&deviceClassFile, "%s/%s/bDeviceClass", sysfsrep, ent->d_name);
deviceClass= readFileContent(deviceClassFile);
if(strncmp(deviceClass, "09", 2) == 0){
@ -366,13 +357,12 @@ int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmm
int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
DIR *dir;
struct dirent *ent;
LIST_HEAD(dup_list);
struct sysfs_dmsection *p;
char *instance = NULL, *instnbr = NULL;
struct usb_port port= {};
struct usb_port *prev_port= (struct usb_port *)prev_data;
LIST_HEAD(dup_list);
check_create_dmmap_package("dmmap_usb");
synchronize_usb_devices_with_dmmap_opt_recursively(prev_port->folder_path, "dmmap_usb", "dmmap_host_device", "port_link", "usb_host_device_instance", 1, &dup_list);
list_for_each_entry(p, &dup_list, list) {
@ -380,30 +370,29 @@ int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, vo
port.dmsect= prev_port->dmsect;
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias_bbfdm, 3, p->dm, "usb_host_device_instance", "usb_host_device_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
return 0;
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct usb_port *usb_dev= (struct usb_port*)prev_data;
struct usb_port port= {};
struct usb_port *usb_dev = (struct usb_port*)prev_data;
struct usb_port port = {0};
struct uci_section *s;
char *v, *instance, *instnbr = NULL, *nbre;
char *filepath= NULL;
char *v, *instnbr = NULL, *nbre, *filepath = NULL;
dmasprintf(&filepath, "%s/bNumConfigurations", usb_dev->folder_path);
nbre= readFileContent(filepath);
if(nbre[0] == '0')
nbre = readFileContent(filepath);
if (nbre[0] == '0')
return 0;
check_create_dmmap_package("dmmap_usb");
s=is_dmmap_section_exist("dmmap_usb", "usb_device_conf");
if(!s)
dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf", &s, &v);
s = is_dmmap_section_exist("dmmap_usb", "usb_device_conf");
if (!s) dmuci_add_section_bbfdm("dmmap_usb", "usb_device_conf", &s, &v);
init_usb_port(s, usb_dev->folder_name, usb_dev->folder_path, &port);
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "usb_device_conf_instance", "usb_device_conf_alias");
handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "usb_device_conf_instance", "usb_device_conf_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, &port, "1");
return 0;
}
@ -413,13 +402,12 @@ int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, D
DIR *dir;
struct dirent *ent;
struct usb_port *usb_dev = (struct usb_port*)prev_data;
struct usb_port port = {};
int ret1, ret2;
struct usb_port port = {0};
char *sysfs_rep_path, *v, *instance = NULL, *instnbr = NULL;
struct uci_section *dmmap_sect;
ret1 = regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0);
ret2 = regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0);
regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0);
regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]:[0-9][0-9]*\\.[0-9]*[0-9]$", 0);
check_create_dmmap_package("dmmap_usb");
sysfs_foreach_file(usb_dev->folder_path, dir, ent) {
if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0)
@ -442,8 +430,8 @@ int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, D
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
* GET & SET PARAM
**************************************************************/
int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir;
@ -457,7 +445,7 @@ int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *da
return 0;
while ((ent = readdir (dir)) != NULL) {
buffer= (char*)dmmalloc(100*sizeof(char));
sprintf(filename, "/sys/class/net/%s", ent->d_name);
snprintf(filename, sizeof(filename), "/sys/class/net/%s", ent->d_name);
readlink (filename, buffer, size);
if(strstr(buffer, "/usb") == NULL)
continue;
@ -471,11 +459,10 @@ int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, c
{
DIR *dir;
struct dirent *ent;
int ret1, ret2, nbre = 0;
ret1 = regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
ret2 = regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
int nbre = 0;
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);
sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0 || strstr(ent->d_name, "usb") == ent->d_name)
@ -985,17 +972,16 @@ int get_number_devices(char *folderpath, int *nbre)
{
DIR *dir;
struct dirent *ent;
int ret1, ret2;
char *deviceClassFile= NULL, *deviceClass= NULL, *hubpath;
char *deviceClassFile = NULL, *deviceClass = NULL, *hubpath;
ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
ret2= regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
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);
sysfs_foreach_file(folderpath, dir, ent) {
if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0){
if (regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) == 0) {
dmasprintf(&deviceClassFile, "%s/%s/bDeviceClass", folderpath, ent->d_name);
deviceClass= readFileContent(deviceClassFile);
if(strncmp(deviceClass, "09", 2) == 0){
deviceClass = readFileContent(deviceClassFile);
if (strncmp(deviceClass, "09", 2) == 0) {
dmasprintf(&hubpath, "%s/%s", folderpath, ent->d_name);
get_number_devices(hubpath, nbre);
}
@ -1138,11 +1124,11 @@ int get_USBUSBHostsHostDevice_SerialNumber(char *refparam, struct dmctx *ctx, vo
int get_USBUSBHostsHostDevice_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct usb_port *port= (struct usb_port *)data;
int ret1, ret2, length;
size_t length;
char **busname, **portname;
ret1 = regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
ret2 = regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
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);
if(regexec(&regex1, port->folder_name, 0, NULL, 0) == 0 || regexec(&regex2, port->folder_name, 0, NULL, 0) ==0){
busname = strsplit(port->folder_name, "-", &length);
portname = strsplit(busname[1], ".", &length);
@ -1162,28 +1148,27 @@ int get_USBUSBHostsHostDevice_USBPort(char *refparam, struct dmctx *ctx, void *d
int get_USBUSBHostsHostDevice_Rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct usb_port *port= (struct usb_port *)data;
char *filepath= NULL, *speed;
struct usb_port *port = (struct usb_port *)data;
char *filepath = NULL, *speed;
dmasprintf(&filepath, "%s/speed", port->folder_path);
speed= readFileContent(filepath);
if(strcmp(speed, "1.5") == 0)
*value= "Low";
else if(strcmp(speed, "12") == 0)
*value= "Full";
else if(strcmp(speed, "480") == 0)
*value= "High";
speed = readFileContent(filepath);
if (strcmp(speed, "1.5") == 0)
*value = "Low";
else if (strcmp(speed, "12") == 0)
*value = "Full";
else if (strcmp(speed, "480") == 0)
*value = "High";
else
*value= "Super";
*value = "Super";
return 0;
}
int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct usb_port *port= (struct usb_port*)data;
int ret1;
char *v;
ret1= regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
if(regexec(&regex1, port->folder_name, 0, NULL, 0) != 0 || port->dmsect == NULL){
*value= "";
return 0;
@ -1196,9 +1181,9 @@ int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, void *da
int get_USBUSBHostsHostDevice_MaxChildren(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct usb_port *port= (struct usb_port *)data;
char *filepath= NULL, *maxchild;
char *filepath= NULL;
dmasprintf(&filepath, "%s/maxchild", port->folder_path);
maxchild= readFileContent(filepath);
*value = readFileContent(filepath);
return 0;
}
@ -1207,11 +1192,11 @@ int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *ctx, voi
struct usb_port *port= (struct usb_port *)data;
char *filepath= NULL, *status;
dmasprintf(&filepath, "%s/power/runtime_status", port->folder_path);
status= readFileContent(filepath);
if(strncmp(status, "suspended", 9) == 0)
*value= "1";
status = readFileContent(filepath);
if (strncmp(status, "suspended", 9) == 0)
*value = "1";
else
*value= "0";
*value = "0";
return 0;
}

View file

@ -11,7 +11,7 @@
#ifndef __USB_H
#define __USB_H
#include <regex.h>
#include <libbbf_api/dmcommon.h>
extern DMOBJ tUSBObj[];
extern DMLEAF tUSBParams[];
@ -33,14 +33,16 @@ extern DMLEAF tUSBUSBHostsHostDeviceConfigurationInterfaceParams[];
regex_t regex1, regex2;
struct usb_port {
struct usb_port
{
struct uci_section *dm_usb_port;
char *folder_name;
char *folder_path;
struct uci_section *dmsect;
};
struct usb_interface {
struct usb_interface
{
struct uci_section *dm_usb_iface;
char *iface_name;
char *iface_path;

View file

@ -10,14 +10,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmjson.h>
#include <libbbf_api/dmcommon.h>
#include "userinterface.h"
/* *** Device.UserInterface. *** */
@ -60,17 +52,14 @@ int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *da
struct uci_section *ss;
char *rule_name, *rule_enabled;
uci_foreach_sections("firewall", "rule", ss)
{
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(strcmp(rule_name, "juci-remote-access") == 0)
{
if (strcmp(rule_name, "juci-remote-access") == 0) {
dmuci_get_value_by_section_string(ss, "enabled", &rule_enabled);
*value= (strcmp(rule_enabled, "0") == 0) ? "0": "1";
return 0;
}
}
*value = "0";
return 0;
}
@ -88,16 +77,13 @@ int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *da
return 0;
case VALUESET:
string_to_bool(value, &b);
uci_foreach_sections("firewall", "rule", ss)
{
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(strcmp(rule_name, "juci-remote-access") == 0)
{
if (strcmp(rule_name, "juci-remote-access") == 0) {
dmuci_set_value_by_section(ss, "enabled", b ? "" : "0");
return 0;
}
}
add_default_rule("80", value, "wan");
return 0;
}
@ -111,34 +97,29 @@ int get_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(strcmp(rule_name, "juci-remote-access") == 0){
if (strcmp(rule_name, "juci-remote-access") == 0) {
dmuci_get_value_by_section_string(ss, "dest_port", &dest_port);
*value= dest_port;
return 0;
}
}
*value = "80";
return 0;
}
int set_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ss;
char *rule_name, *owsd;
char *ret;
switch (action)
{
case VALUECHECK:
return 0;
case VALUESET:
uci_foreach_sections("firewall", "rule", ss)
{
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(strcmp(rule_name, "juci-remote-access") == 0)
{
if (strcmp(rule_name, "juci-remote-access") == 0) {
dmuci_set_value_by_section(ss, "dest_port", value);
dmuci_get_value_by_section_string(ss, "owsd", &owsd);
dmuci_set_value("owsd", owsd, "port", value);
@ -168,15 +149,11 @@ static int get_supportedprotocols(void)
int get_userint_remoteaccesss_supportedprotocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int found;
found = get_supportedprotocols();
if (found)
{
int found = get_supportedprotocols();
if (found) {
*value = "HTTP, HTTPS";
return 0;
}
*value = "HTTP";
return 0;
}
@ -186,11 +163,9 @@ int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *
struct uci_section *ss;
char *rule_name, *rule_owsd;
uci_foreach_sections("firewall", "rule", ss)
{
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(strcmp(rule_name, "juci-remote-access") == 0)
{
if (strcmp(rule_name, "juci-remote-access") == 0) {
dmuci_get_value_by_section_string(ss, "owsd", &rule_owsd);
if (strcmp(rule_owsd, "wan") == 0)
*value = "HTTP";
@ -199,7 +174,6 @@ int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *
return 0;
}
}
*value = "HTTP";
return 0;
}
@ -214,24 +188,19 @@ int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *
{
case VALUECHECK:
found = get_supportedprotocols();
if (found)
{
if (found) {
if ((strcmp(value, "HTTP") != 0) && (strcmp(value, "HTTPS") != 0))
return FAULT_9007;
}
else
{
} else {
if (strcmp(value, "HTTP") != 0)
return FAULT_9007;
}
return 0;
case VALUESET:
uci_foreach_sections("firewall", "rule", ss)
{
uci_foreach_sections("firewall", "rule", ss) {
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if(strcmp(rule_name, "juci-remote-access") == 0)
{
if(strcmp(value, "HTTPS") == 0)
if (strcmp(rule_name, "juci-remote-access") == 0) {
if (strcmp(value, "HTTPS") == 0)
dmuci_set_value_by_section(ss, "owsd", "wan_https");
else
dmuci_set_value_by_section(ss, "owsd", "wan");
@ -239,7 +208,7 @@ int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *
}
}
if(strcmp(value, "HTTPS") == 0)
if (strcmp(value, "HTTPS") == 0)
name_http = "wan_https";
else
name_http = "wan";

View file

@ -13,6 +13,8 @@
#ifndef __USER_INTERFACE_H
#define __USER_INTERFACE_H
#include <libbbf_api/dmcommon.h>
extern DMLEAF tUserInterfaceRemoteAccessParams[];
extern DMOBJ tUserInterfaceObj[];

View file

@ -9,8 +9,6 @@
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include "users.h"
/* *** Device.Users. *** */
@ -56,18 +54,14 @@ int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, ch
return 0;
}
int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instance){
int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s, *dmmap_user;
char *last_inst= NULL, *sect_name= NULL, *username, *v;
char ib[8];
last_inst= get_last_instance_bbfdm("dmmap_users", "user", "user_instance");
if (last_inst)
sprintf(ib, "%s", last_inst);
else
sprintf(ib, "%s", "1");
char ib[8], *last_inst = NULL, *sect_name = NULL, *username, *v;
last_inst = get_last_instance_bbfdm("dmmap_users", "user", "user_instance");
snprintf(ib, sizeof(ib), "%s", last_inst ? last_inst : "1");
dmasprintf(&username, "user_%d", atoi(ib)+1);
dmuci_add_section("users", "user", &s, &sect_name);
dmuci_rename_section_by_section(s, username);
dmuci_set_value_by_section(s, "enabled", "1");
@ -81,14 +75,12 @@ int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instanc
int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL;
struct uci_section *ss = NULL;
struct uci_section *dmmap_section;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
switch (del_action) {
case DEL_INST:
if(is_section_unnamed(section_name((struct uci_section *)data))){
if (is_section_unnamed(section_name((struct uci_section *)data))) {
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_users", "user", "user_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "user_instance", "dmmap_users", "user");
@ -101,19 +93,17 @@ int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *insta
break;
case DEL_ALL:
uci_foreach_sections("users", "user", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_users", "user", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_users", "user", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
@ -140,7 +130,7 @@ int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_users", "user", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "user_alias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "user_alias", value);
return 0;
}
@ -153,7 +143,7 @@ int get_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instanc
int get_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value= dmstrdup(section_name((struct uci_section *)data));
*value = dmstrdup(section_name((struct uci_section *)data));
return 0;
}
@ -187,7 +177,7 @@ int set_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_users", "user", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "user_alias", value);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "user_alias", value);
return 0;
}
return 0;

View file

@ -11,7 +11,7 @@
#ifndef _USERS_H
#define _USERS_H
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
extern DMOBJ tUsersObj[];
extern DMLEAF tUsersParams[];

View file

@ -10,20 +10,10 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include <libbbf_api/dmjson.h>
#include "dmentry.h"
#include "wepkey.h"
#include "wifi.h"
#define DELIMITOR ","
/* *** Device.WiFi. *** */
DMOBJ tWiFiObj[] = {
/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type*/
@ -474,8 +464,8 @@ int get_WiFi_AccessPointNumberOfEntries(char *refparam, struct dmctx *ctx, void
int get_WiFi_EndPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
int nbre= 0;
char *mode= NULL;
int nbre = 0;
char *mode = NULL;
uci_foreach_sections("wireless", "wifi-iface", s) {
dmuci_get_value_by_section_string(s, "mode", &mode);
@ -557,13 +547,13 @@ int get_wifi_status (char *refparam, struct dmctx *ctx, void *data, char *instan
}
/*#Device.WiFi.SSID.{i}.SSID!UCI:wireless/wifi-iface,@i-1/ssid*/
static int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssid", value);
return 0;
}
static int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
@ -576,7 +566,7 @@ static int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *in
}
/*#Device.WiFi.SSID.{i}.BSSID!UBUS:router.wireless/status/vif,@Name/bssid*/
static int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
@ -670,7 +660,7 @@ int get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char
*value = "";
wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec);
dmubus_call("router.wireless", "radios", UBUS_ARGS{}, 0, &res);
if(res) {
if (res) {
rate = dmjson_get_value(res, 2, wlan_name, "rate");
*value = strtok(rate, " Mbps");
}
@ -686,7 +676,7 @@ int get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *ins
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res);
DM_ASSERT(res, *value = "");
freq = dmjson_get_value(res, 1, "frequency");
if(strcmp(freq, "2") == 0 ) {
if (strcmp(freq, "2") == 0 ) {
dmastrcat(value, freq, ".4GHz"); // MEM WILL BE FREED IN DMMEMCLEAN
return 0;
}
@ -701,8 +691,7 @@ int get_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, voi
json_object *res;
char *wlan_name;
dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", value);
if ((*value)[0] == '\0')
{
if ((*value)[0] == '\0') {
wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec);
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res);
DM_ASSERT(res, *value = "");
@ -786,13 +775,11 @@ int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *ins
/*#Device.WiFi.Radio.{i}.SupportedStandards!UBUS:router.wireless/radios//hwmodes*/
int get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *freq, *wlan_name;
json_object *res;
wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec);
dmubus_call("router.wireless", "radios", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "");
json_object_object_foreach(res, key, radio_obj) {
if(strcmp(wlan_name, key) == 0) {
if (strcmp(section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), key) == 0) {
*value = dmjson_get_value_array_all(radio_obj, DELIMITOR, 1, "hwmodes");
}
}
@ -806,7 +793,7 @@ int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data,
dmubus_call("router.wireless", "radios", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "");
json_object_object_foreach(res, key, radio_obj) {
if(strcmp(section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), key) == 0) {
if (strcmp(section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), key) == 0) {
*value = dmjson_get_value(radio_obj, 1, "opmode");
break;
}
@ -816,14 +803,15 @@ int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data,
int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *freq, *wlan_name;
char *freq;
json_object *res;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec);
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res);
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
if (!res) return 0;
freq = dmjson_get_value(res, 1, "frequency");
if (strcmp(freq, "5") == 0) {
if (strcmp(value, "n") == 0)
@ -972,12 +960,11 @@ int set_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *data, char
/*#Device.WiFi.Radio.{i}.SupportedOperatingChannelBandwidths!UBUS:router.wireless/radios//@Name.bandwidth*/
int get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res, *jobj;
json_object *res;
dmubus_call("router.wireless", "radios", UBUS_ARGS{{}}, 0, &res);
if(res)
*value = dmjson_get_value_array_all(res, DELIMITOR, 2, section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), "bwcaps");
DM_ASSERT(res, *value = "");
*value = dmjson_get_value_array_all(res, DELIMITOR, 2, section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), "bwcaps");
return 0;
}
@ -1012,8 +999,7 @@ int get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dmctx
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
if(res)
*value = dmjson_get_value(res, 1, "bandwidth");
*value = dmjson_get_value(res, 1, "bandwidth");
return 0;
}
@ -1098,11 +1084,11 @@ int set_WiFiRadio_TransmitPower(char *refparam, struct dmctx *ctx, void *data, c
int get_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *country, **arr;
int length;
size_t length;
dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", &country);
arr= strsplit(country, "/", &length);
if(strlen(arr[0]) > 0)
arr = strsplit(country, "/", &length);
if (strlen(arr[0]) > 0)
dmasprintf(value, "%s", arr[0]);
else
*value= "";
@ -1113,15 +1099,15 @@ int get_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data
int set_WiFiRadio_RegulatoryDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *country, **arr;
int length;
size_t length;
switch (action) {
case VALUECHECK:
break;
case VALUESET:
dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "country", &country);
if(strlen(country)>0){
arr= strsplit(country, "/", &length);
if (strlen(country) > 0) {
arr = strsplit(country, "/", &length);
dmasprintf(&country, "%s/%s", value, arr[1]);
} else
dmasprintf(&country, "%s/1", value);
@ -1186,10 +1172,8 @@ int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data,
else {
wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec);
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res);
if(res == NULL)
return 0;
else
value = dmjson_get_value(res, 1, "channel");
if (res) return 0;
value = dmjson_get_value(res, 1, "channel");
}
dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value);
return 0;
@ -1198,14 +1182,14 @@ int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data,
}
/*************************************************************
* GET STAT
/*************************************************************/
* GET STAT
**************************************************************/
/*#Device.WiFi.Radio.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
int get_radio_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_bytes");
return 0;
}
@ -1215,7 +1199,7 @@ int get_radio_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data,
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_bytes");
return 0;
}
@ -1225,7 +1209,7 @@ int get_radio_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *dat
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_packets");
return 0;
}
@ -1235,7 +1219,7 @@ int get_radio_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *dat
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_packets");
return 0;
}
@ -1245,7 +1229,7 @@ int get_radio_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_errors");
return 0;
}
@ -1255,7 +1239,7 @@ int get_radio_statistics_rx_errors(char *refparam, struct dmctx *ctx, void *data
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_errors");
return 0;
}
@ -1265,7 +1249,7 @@ int get_radio_statistics_tx_discardpackets(char *refparam, struct dmctx *ctx, vo
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_dropped");
return 0;
}
@ -1275,7 +1259,7 @@ int get_radio_statistics_rx_discardpackets(char *refparam, struct dmctx *ctx, vo
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_dropped");
return 0;
}
@ -1283,9 +1267,8 @@ int get_radio_statistics_rx_discardpackets(char *refparam, struct dmctx *ctx, vo
int get_WiFiRadioStats_Noise(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
if(res)
*value = dmjson_get_value(res, 1, "noise");
return 0;
@ -1296,7 +1279,7 @@ int get_ssid_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data,
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_bytes");
return 0;
}
@ -1306,7 +1289,7 @@ int get_ssid_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data,
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_bytes");
return 0;
}
@ -1316,7 +1299,7 @@ int get_ssid_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_packets");
return 0;
}
@ -1326,7 +1309,7 @@ int get_ssid_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_packets");
return 0;
}
@ -1336,7 +1319,7 @@ int get_WiFiSSIDStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data,
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_errors");
return 0;
}
@ -1346,7 +1329,7 @@ int get_WiFiSSIDStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *da
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_errors");
return 0;
}
@ -1356,7 +1339,7 @@ int get_WiFiSSIDStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "tx_dropped");
return 0;
}
@ -1366,7 +1349,7 @@ int get_WiFiSSIDStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx,
{
json_object *res;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "");
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", "rx_dropped");
return 0;
}
@ -1430,8 +1413,7 @@ static char *get_associative_device_statistics(struct wifi_associative_device_ar
return stats;
}
entries++;
}
else
} else
break;
}
return stats;
@ -1522,7 +1504,7 @@ int get_access_point_associative_device_statistics_multiple_retry_count(char *re
* SET & GET VALUE
***************************************************************************/
/*#Device.WiFi.SSID.{i}.SSIDAdvertisementEnabled!UCI:wireless/wifi-iface,@i-1/hidden*/
static int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *hidden;
dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", &hidden);
@ -1533,7 +1515,7 @@ static int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx,
return 0;
}
static int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
switch (action) {
@ -1554,7 +1536,7 @@ static int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx,
}
/*#Device.WiFi.AccessPoint.{i}.WMMEnable!UCI:wireless/wifi-device,@i-1/wmm*/
static int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
bool b;
dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", value);
@ -1568,7 +1550,7 @@ static int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *
return 0;
}
static int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
char *device;
@ -1599,8 +1581,9 @@ int get_access_point_total_associations(char *refparam, struct dmctx *ctx, void
{
json_object *res, *jobj;
int entries = 0;
dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
dmubus_call("wifix", "stations", UBUS_ARGS{{"vif", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "0");
while (1) {
jobj = dmjson_select_obj_in_array_idx(res, entries, 1, "stations");
if (jobj == NULL)
@ -1712,14 +1695,15 @@ int get_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, voi
int set_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
int length, i;
size_t length;
int i;
char **arr;
switch (action) {
case VALUECHECK:
break;
case VALUESET:
arr= strsplit(value, " ", &length);
for (i=0; i<length; i++){
for (i = 0; i < length; i++){
dmuci_add_list_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "maclist", arr[i]);
}
break;
@ -1729,7 +1713,7 @@ int set_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, voi
int get_WiFiAccessPoint_UAPSDCapability(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value= "true";
*value = "true";
return 0;
}
@ -1777,6 +1761,7 @@ int set_WiFiAccessPoint_UAPSDEnable(char *refparam, struct dmctx *ctx, void *dat
}
return 0;
}
int get_access_point_security_supported_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "None, WEP-64, WEP-128, WPA-Personal, WPA2-Personal, WPA-WPA2-Personal, WPA-Enterprise, WPA2-Enterprise, WPA-WPA2-Enterprise";
@ -1918,7 +1903,7 @@ int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, void *da
dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption);
if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 ) {
dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "key_index", &key_index);
sprintf(buf,"key%s", key_index);
snprintf(buf, sizeof(buf), "key%s", key_index);
dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, buf, value);
}
return 0;
@ -1993,8 +1978,8 @@ int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx,
int set_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *key_index, *encryption;
char buf[8];
char *encryption;
switch (action) {
case VALUECHECK:
return 0;
@ -2019,8 +2004,8 @@ int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ct
int set_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *key_index, *encryption;
char buf[8];
char *encryption;
switch (action) {
case VALUECHECK:
return 0;
@ -2042,8 +2027,8 @@ int get_access_point_security_radius_server_port(char *refparam, struct dmctx *c
int set_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *key_index, *encryption;
char buf[8];
char *encryption;
switch (action) {
case VALUECHECK:
return 0;
@ -2058,8 +2043,8 @@ int set_access_point_security_radius_server_port(char *refparam, struct dmctx *c
int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *key_index, *encryption;
char buf[8];
char *encryption;
switch (action) {
case VALUECHECK:
return 0;
@ -2103,7 +2088,6 @@ int get_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data,
int set_WiFiAccessPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
char *boolS;
switch (action) {
case VALUECHECK:
@ -2127,33 +2111,33 @@ int get_WiFiAccessPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *
int get_WiFiAccessPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *pushbut= NULL, *label= NULL, *pin= NULL, *methodenabled= NULL, *tmp, *str1, *str2, *str3;
bool a, b, c;
char *pushbut = NULL, *label = NULL, *pin = NULL, *str1, *str2, *str3;
dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pushbutton", &pushbut);
dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_label", &label);
dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", &pin);
if(pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0)
str1= dmstrdup("");
if (pushbut == NULL || pushbut[0] == '\0' || strcmp(pushbut, "1") != 0)
str1 = dmstrdup("");
else
str1= dmstrdup("PushButton");
str1 = dmstrdup("PushButton");
if(label == NULL || label[0]=='\0' || strcmp(label, "1")!=0)
str2= dmstrdup("");
if (label == NULL || label[0] == '\0' || strcmp(label, "1") != 0)
str2 = dmstrdup("");
else {
if(pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0)
str2= dmstrdup("Label");
if(pushbut == NULL || pushbut[0] == '\0' || strcmp(pushbut, "1") != 0)
str2 = dmstrdup("Label");
else
str2= dmstrdup(",Label");
str2 = dmstrdup(",Label");
}
if(pin == NULL || pin[0]=='\0')
str3= dmstrdup("");
if( pin == NULL || pin[0] == '\0')
str3 = dmstrdup("");
else {
if((pushbut != NULL && pushbut[0]!='\0' && strcmp(pushbut, "1")==0) || (label != NULL && label[0]!='\0' && strcmp(label, "1")==0))
str3= dmstrdup(",PIN");
if((pushbut != NULL && pushbut[0] != '\0' && strcmp(pushbut, "1") == 0) || (label != NULL && label[0] != '\0' && strcmp(label, "1") == 0))
str3 = dmstrdup(",PIN");
else
str3= dmstrdup("PIN");
str3 = dmstrdup("PIN");
}
dmasprintf(value,"%s%s%s", str1, str2, str3);
@ -2538,7 +2522,7 @@ int get_WiFiEndPoint_SSIDReference(char *refparam, struct dmctx *ctx, void *data
int get_WiFiEndPointProfile_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value="1";
*value = "1";
return 0;
}
@ -2563,7 +2547,7 @@ int get_WiFiEndPointProfile_Status(char *refparam, struct dmctx *ctx, void *data
int get_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section, *dm;
char *epinst= NULL;
char *epinst = NULL;
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name((struct uci_section*)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &epinst);
@ -2575,7 +2559,7 @@ int get_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data,
int set_WiFiEndPointProfile_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section, *dm;
char *epinst= NULL;
char *epinst = NULL;
switch (action) {
case VALUECHECK:
@ -2862,7 +2846,6 @@ int get_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, ch
int set_WiFiEndPointWPS_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
char *boolS;
switch (action) {
case VALUECHECK:
@ -2886,33 +2869,33 @@ int get_WiFiEndPointWPS_ConfigMethodsSupported(char *refparam, struct dmctx *ctx
int get_WiFiEndPointWPS_ConfigMethodsEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *pushbut= NULL, *label= NULL, *pin= NULL, *methodenabled= NULL, *tmp, *str1, *str2, *str3;
bool a, b, c;
char *pushbut = NULL, *label = NULL, *pin = NULL, *str1, *str2, *str3;
dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pushbutton", &pushbut);
dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_label", &label);
dmuci_get_value_by_section_string(((struct wifi_enp_args *)data)->wifi_enp_sec, "wps_pin", &pin);
if(pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0)
str1= dmstrdup("");
if (pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0)
str1 = dmstrdup("");
else
str1= dmstrdup("PushButton");
str1 = dmstrdup("PushButton");
if(label == NULL || label[0]=='\0' || strcmp(label, "1")!=0)
str2= dmstrdup("");
if (label == NULL || label[0]=='\0' || strcmp(label, "1")!=0)
str2 = dmstrdup("");
else {
if(pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0)
str2= dmstrdup("Label");
if (pushbut == NULL || pushbut[0]=='\0' || strcmp(pushbut, "1")!=0)
str2 = dmstrdup("Label");
else
str2= dmstrdup(",Label");
str2 = dmstrdup(",Label");
}
if(pin == NULL || pin[0]=='\0')
str3= dmstrdup("");
if (pin == NULL || pin[0]=='\0')
str3 = dmstrdup("");
else {
if((pushbut != NULL && pushbut[0]!='\0' && strcmp(pushbut, "1")==0) || (label != NULL && label[0]!='\0' && strcmp(label, "1")==0))
str3= dmstrdup(",PIN");
if ((pushbut != NULL && pushbut[0] != '\0' && strcmp(pushbut, "1") == 0) || (label != NULL && label[0] != '\0' && strcmp(label, "1") == 0))
str3 = dmstrdup(",PIN");
else
str3= dmstrdup("PIN");
str3 = dmstrdup("PIN");
}
dmasprintf(value,"%s%s%s", str1, str2, str3);
@ -2975,6 +2958,7 @@ int get_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dm
uci_foreach_sections("wireless", "wifi-device", ss) {
dmubus_call("router.wireless", "scanresults", UBUS_ARGS{{"radio", section_name(ss), String}}, 1, &res);
DM_ASSERT(res, *value = "None");
neighboring_wifi_obj = dmjson_select_obj_in_array_idx(res, 0, 1, "access_points");
if(neighboring_wifi_obj) {
*value = "Complete";
@ -3073,7 +3057,7 @@ int get_neighboring_wifi_diagnostics_result_noise(char *refparam, struct dmctx *
/**************************************************************************
* SET AND GET ALIAS
***************************************************************************/
static int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
@ -3082,7 +3066,7 @@ static int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *
return 0;
}
static int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section;
@ -3126,7 +3110,7 @@ int get_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_acp_args *)data)->wifi_acp_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "accesspointalias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "accesspointalias", value);
return 0;
}
@ -3139,17 +3123,17 @@ int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(((struct wifi_acp_args *)data)->wifi_acp_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "accesspointalias", value);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "accesspointalias", value);
return 0;
}
return 0;
}
/*************************************************************
* GET & SET LOWER LAYER
/*************************************************************/
* GET & SET LOWER LAYER
**************************************************************/
int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
if (((struct wifi_ssid_args *)data)->linker[0] != '\0') {
if (data && ((struct wifi_ssid_args *)data)->linker[0] != '\0') {
adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", dmroot, dm_delim, dm_delim, dm_delim), ((struct wifi_ssid_args *)data)->linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
@ -3164,7 +3148,7 @@ int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *in
case VALUECHECK:
return 0;
case VALUESET:
if (value[strlen(value)-1]!='.') {
if (value[strlen(value)-1] != '.') {
dmasprintf(&newvalue, "%s.", value);
adm_entry_get_linker_value(ctx, newvalue, &linker);
} else
@ -3189,19 +3173,16 @@ int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instanc
}
/*************************************************************
* ADD DEL OBJ
/*************************************************************/
* ADD DEL OBJ
**************************************************************/
int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *value, *v;
char ssid[16] = {0};
char *inst;
struct uci_section *s = NULL;
struct uci_section *dmmap_wifi=NULL;
char *value, *v, *inst, ssid[16] = {0};
struct uci_section *s = NULL, *dmmap_wifi = NULL;
check_create_dmmap_package("dmmap_wireless");
inst = get_last_instance_bbfdm("dmmap_wireless", "wifi-iface", "ssidinstance");
sprintf(ssid, "Iopsys_%d", inst ? (atoi(inst)+1) : 1);
snprintf(ssid, sizeof(ssid), "iopsys_%d", inst ? (atoi(inst)+1) : 1);
dmuci_add_section("wireless", "wifi-iface", &s, &value);
dmuci_set_value_by_section(s, "device", "wl0");
dmuci_set_value_by_section(s, "encryption", "none");
@ -3218,23 +3199,19 @@ int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instance
int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
char *lan_name;
struct uci_section *s = NULL;
struct uci_section *ss = NULL, *dmmap_section= NULL;
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);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (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);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
@ -3242,8 +3219,7 @@ int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instan
}
if (ss != NULL){
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;
@ -3253,10 +3229,8 @@ int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instan
int addObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *value, *v, *ssid;
char *instancepara, *instancepara1, *instancepara2;
char *value, *v, *instancepara, *instancepara1, *instancepara2;
struct uci_section *endpoint_sec = NULL, *dmmap_sec= NULL;
int inst;
check_create_dmmap_package("dmmap_wireless");
instancepara1 = get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "wet")?get_last_instance_lev2_bbfdm("wireless", "wifi-iface", "dmmap_wireless", "endpointinstance", "mode", "wet"):"0";
@ -3275,41 +3249,34 @@ int addObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char **ins
int delObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL;
struct uci_section *ss = NULL;
struct uci_section *dmmap_section;
struct uci_section *s = NULL, *dmmap_section;
char *mode;
int found = 0;
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);
if(dmmap_section != NULL)
dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", "");
if (dmmap_section) dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", "");
dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "mode", "");
break;
case DEL_ALL:
uci_foreach_sections("wireless", "wifi-iface", s) {
dmuci_get_value_by_section_string(s, "mode", &mode);
if(strcmp(mode, "sta")!=0 && strcmp(mode, "wet")!=0)
if (strcmp(mode, "sta") != 0 && strcmp(mode, "wet") != 0)
continue;
dmuci_set_value_by_section(s, "mode", "");
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(s), &dmmap_section);
if(dmmap_section != NULL)
dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", "");
if (dmmap_section) dmuci_set_value_by_section(((struct wifi_enp_args *)data)->wifi_enp_sec, "endpointinstance", "");
}
}
return 0;
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
* ENTRY METHOD
**************************************************************/
/*#Device.WiFi.Radio.{i}.!UCI:wireless/wifi-device/dmmap_wireless*/
int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *wnum = NULL, *wnum_last = NULL;
char buf[12];
struct uci_section *s = NULL;
struct wifi_radio_args curr_wifi_radio_args = {0};
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -3328,9 +3295,7 @@ int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_dat
/*#Device.WiFi.SSID.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/
int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *wnum = NULL, *ssid_last = NULL, *ifname, *acpt_last = NULL, *linker;
struct uci_section *ss = NULL;
json_object *res;
char *wnum = NULL, *ssid_last = NULL, *ifname, *linker;
struct wifi_ssid_args curr_wifi_ssid_args = {0};
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -3351,9 +3316,7 @@ int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data
/*#Device.WiFi.AccessPoint.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/
int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *wnum = NULL, *ssid_last = NULL, *ifname, *acpt_last = NULL, *mode= NULL;
struct uci_section *ss = NULL;
json_object *res;
char *wnum = NULL, *ifname, *acpt_last = NULL, *mode = NULL;
struct wifi_acp_args curr_wifi_acp_args = {0};
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -3376,9 +3339,7 @@ int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *pr
/*#Device.WiFi.EndPoint.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/
int browseWiFiEndPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *wnum = NULL, *ssid_last = NULL, *ifname, *acpt_last = NULL, *mode= NULL;
struct uci_section *ss = NULL;
json_object *res;
char *wnum = NULL, *ifname, *acpt_last = NULL, *mode= NULL;
struct wifi_enp_args curr_wifi_enp_args = {0};
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -3404,7 +3365,7 @@ int browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, void
struct uci_section *ss = NULL;
char *value, *ap_ifname, *idx, *idx_last = NULL;
int id = 0, entries = 0;
char *macaddr= NULL, *active= NULL, *lastdatadownloadlinkrate= NULL, *lastdatauplinkrate= NULL, *signalstrength= NULL, *noise= NULL, *retrans= NULL, *assoctimestr= NULL;
char *macaddr = NULL, *lastdatadownloadlinkrate = NULL, *lastdatauplinkrate = NULL, *signalstrength = NULL, *noise = NULL, *retrans = NULL, *assoctimestr = NULL;
struct wifi_associative_device_args cur_wifi_associative_device_args = {0};
struct uci_section *dmmap_section;
@ -3519,7 +3480,7 @@ int browseWifiNeighboringWiFiDiagnosticResultInst(struct dmctx *dmctx, DMNODE *p
int browseWiFiEndPointProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s= NULL;
char *v, *instance, *instnbr = NULL, *ep_instance;
char *v, *instnbr = NULL, *ep_instance;
struct wifi_enp_args *ep_args = (struct wifi_enp_args *)prev_data;
struct uci_section *dmmap_section= NULL;
@ -3531,7 +3492,7 @@ int browseWiFiEndPointProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void
if(!s)
dmuci_add_section_bbfdm("dmmap_wireless", "ep_profile", &s, &v);
DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "ep_key", ep_instance);
instance = handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "ep_profile_instance", "ep_profile_alias");
handle_update_instance(1, dmctx, &instnbr, update_instance_alias, 3, s, "ep_profile_instance", "ep_profile_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, ep_args->wifi_enp_sec, "1");
return 0;

View file

@ -13,6 +13,8 @@
#ifndef __WIFI_H
#define __WIFI_H
#include <libbbf_api/dmcommon.h>
struct wifi_radio_args
{
struct uci_section *wifi_radio_sec;
@ -48,7 +50,6 @@ struct wifi_associative_device_args
int noise;
int retransmissions;
int assoctime;
};
struct wifi_neighboring_diagnostic_args
@ -110,7 +111,7 @@ int get_WiFi_EndPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *da
int get_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
static int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_radio_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_WiFiRadio_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
@ -138,9 +139,9 @@ int get_radio_statistics_rx_discardpackets(char *refparam, struct dmctx *ctx, vo
int get_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_wifi_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
static int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
static int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ssid_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ssid_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ssid_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
@ -149,8 +150,8 @@ int get_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *
int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_wifi_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
static int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
static int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
@ -262,7 +263,7 @@ int get_WiFiEndPointProfile_Priority(char *refparam, struct dmctx *ctx, void *da
int get_WiFiEndPointProfileSecurity_ModeEnabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int get_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
static int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
@ -273,11 +274,11 @@ int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data,
int set_WiFiRadio_AutoChannelRefreshPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
static int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
static int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
@ -291,7 +292,7 @@ int set_access_point_security_radius_server_port(char *refparam, struct dmctx *c
int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_access_point_ieee80211r_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
static int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_WiFiRadio_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_WiFiRadio_FragmentationThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_WiFiRadio_RTSThreshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
@ -334,4 +335,5 @@ int set_WiFiEndPointProfileSecurity_WEPKey(char *refparam, struct dmctx *ctx, vo
int set_WiFiEndPointProfileSecurity_PreSharedKey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_WiFiEndPointProfileSecurity_KeyPassphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
int set_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);
#endif

View file

@ -10,12 +10,6 @@
*
*/
#include <uci.h>
#include <ctype.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include "x_iopsys_eu_buttons.h"
/*** DMROOT.X_IOPSYS_EU_Buttons.{i}. ****/
@ -34,7 +28,6 @@ DMLEAF X_IOPSYS_EU_ButtonParams[] = {
int browseXIopsysEuButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *ibutton = NULL, *ibutton_last = NULL;
struct uci_section *s = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -144,13 +137,12 @@ int set_x_iopsys_eu_button_enable(char *refparam, struct dmctx *ctx, void *data,
return 0;
}
////////////////////////SET AND GET ALIAS/////////////////////////////////
int get_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_buttons", "button", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "buttonalias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "buttonalias", value);
return 0;
}
@ -158,12 +150,12 @@ int set_x_iopsys_eu_button_alias(char *refparam, struct dmctx *ctx, void *data,
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_buttons", "button", section_name((struct uci_section *)data), &dmmap_section);
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(dmmap_section, "buttonalias", value);
get_dmmap_section_of_config_section("dmmap_buttons", "button", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "buttonalias", value);
return 0;
}
return 0;

View file

@ -13,6 +13,8 @@
#ifndef __SE_BUTTONS_H
#define __SE_BUTTONS_H
#include <libbbf_api/dmcommon.h>
extern DMLEAF X_IOPSYS_EU_ButtonParams[];
int browseXIopsysEuButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int get_x_iopsys_eu_button_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -9,12 +9,6 @@
*
*/
#include <uci.h>
#include <ctype.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include "x_iopsys_eu_dropbear.h"
/*** DMROOT.X_IOPSYS_EU_Dropbear.{i}. ****/
@ -39,7 +33,6 @@ DMLEAF X_IOPSYS_EU_DropbearParams[] = {
int browseXIopsysEuDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *idropbear = NULL, *idropbear_last = NULL;
struct uci_section *s = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -60,8 +53,7 @@ int get_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, vo
dmuci_get_value_by_section_string((struct uci_section *)data, "PasswordAuth", value);
if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1') {
*value = "1";
}
else
} else
*value = "0";
return 0;
}
@ -91,8 +83,7 @@ int get_x_iopsys_eu_dropbear_root_password_auth(char *refparam, struct dmctx *ct
dmuci_get_value_by_section_string((struct uci_section *)data, "RootPasswordAuth", value);
if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1') {
*value = "1";
}
else
} else
*value = "0";
return 0;
}
@ -209,8 +200,7 @@ int get_x_iopsys_eu_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, vo
dmuci_get_value_by_section_string((struct uci_section *)data, "GatewayPorts", value);
if ((*value)[0] == '\0' || (*value)[0] == '0' ) {
*value = "0";
}
else
} else
*value = "1";
return 0;
}
@ -368,7 +358,7 @@ int get_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "dropbearalias", value);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "dropbearalias", value);
return 0;
}
@ -376,12 +366,12 @@ int set_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data
{
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name((struct uci_section *)data), &dmmap_section);
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(dmmap_section, "dropbearalias", value);
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "dropbearalias", value);
return 0;
}
return 0;
@ -390,8 +380,7 @@ int set_x_iopsys_eu_dropbear_alias(char *refparam, struct dmctx *ctx, void *data
/***** ADD DEL OBJ *******/
int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *value, *v;
char *instance;
char *value, *v, *instance;
struct uci_section *dropbear_sec = NULL, *dmmap_sec= NULL;
check_create_dmmap_package("dmmap_dropbear");
@ -413,9 +402,7 @@ int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **
int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL;
struct uci_section *ss = NULL;
struct uci_section *dmmap_section;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
switch (del_action) {
@ -433,19 +420,17 @@ int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char
break;
case DEL_ALL:
uci_foreach_sections("dropbear", "dropbear", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;

View file

@ -12,6 +12,8 @@
#ifndef __SE_DROPBEAR_H
#define __SE_DROPBEAR_H
#include <libbbf_api/dmcommon.h>
extern DMLEAF X_IOPSYS_EU_DropbearParams[];
int browseXIopsysEuDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int get_x_iopsys_eu_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -8,14 +8,7 @@
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include "x_iopsys_eu_ice.h"
/*** DMROOT.X_IOPSYS_EU_ICE. ***/
@ -56,6 +49,7 @@ int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *in
dmuci_set_value("ice", "cloud", "enabled", "0");
return 0;
}
return 0;
}
int get_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)

View file

@ -12,6 +12,8 @@
#ifndef __SE_ICE_H
#define __SE_ICE_H
#include <libbbf_api/dmcommon.h>
extern DMLEAF tSe_IceParam[];
int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -9,13 +9,6 @@
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmcommon.h>
#include "x_iopsys_eu_igmp.h"
DMLEAF tSe_IgmpParam[] = {
@ -71,7 +64,6 @@ int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char
int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
int i;
char *p;
switch (action) {
@ -387,7 +379,6 @@ int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, c
int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
int i;
char *p;
switch (action) {

View file

@ -12,6 +12,8 @@
#ifndef __SE_IGMP_H
#define __SE_IGMP_H
#include <libbbf_api/dmcommon.h>
extern DMLEAF tSe_IgmpParam[];
int get_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);

View file

@ -10,12 +10,6 @@
*
*/
#include <uci.h>
#include <ctype.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include "x_iopsys_eu_ipacccfg.h"
/*** DMROOT.X_IOPSYS_EU_IpAccCfg. ***/
@ -63,9 +57,7 @@ DMLEAF tSe_IpAccCfgParam[] = {
**************************************************************************************/
int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(ipaccsection, "enabled", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value);
if ((*value)[0] == '\0') {
*value = "1";
}
@ -75,8 +67,6 @@ int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, v
int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
int check;
struct uci_section *ipaccsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
@ -91,7 +81,7 @@ int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, v
else {
value = "0";
}
dmuci_set_value_by_section(ipaccsection, "enabled", value);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", value);
return 0;
}
return 0;
@ -99,21 +89,17 @@ int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, v
int get_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(ipaccsection, "family", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "family", value);
return 0;
}
int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(ipaccsection, "family", value);
dmuci_set_value_by_section((struct uci_section *)data, "family", value);
return 0;
}
return 0;
@ -121,21 +107,17 @@ int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx
int get_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(ipaccsection, "proto", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", value);
return 0;
}
int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(ipaccsection, "proto", value);
dmuci_set_value_by_section((struct uci_section *)data, "proto", value);
return 0;
}
return 0;
@ -143,21 +125,17 @@ int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx,
int get_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(ipaccsection, "name", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
return 0;
}
int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(ipaccsection, "name", value);
dmuci_set_value_by_section((struct uci_section *)data, "name", value);
return 0;
}
return 0;
@ -166,15 +144,11 @@ int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, voi
int get_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *val;
struct uci_element *e = NULL;
struct uci_section *ipaccsection = (struct uci_section *)data;
struct uci_list *list = NULL;
dmuci_get_value_by_section_list(ipaccsection, "src_ip", &val);
dmuci_get_value_by_section_list((struct uci_section *)data, "src_ip", &val);
if (val) {
*value = dmuci_list_to_string(val, ",");
}
else
} else
*value = "";
if ((*value)[0] == '\0') {
*value = "0.0.0.0/0";
@ -186,17 +160,16 @@ int get_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, vo
int set_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch, *spch, *val;
struct uci_section *ipaccsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_delete_by_section(ipaccsection, "src_ip", "");
dmuci_delete_by_section((struct uci_section *)data, "src_ip", "");
val = dmstrdup(value);
pch = strtok_r(val, " ,", &spch);
while (pch != NULL) {
dmuci_add_list_value_by_section(ipaccsection, "src_ip", pch);
dmuci_add_list_value_by_section((struct uci_section *)data, "src_ip", pch);
pch = strtok_r(NULL, " ,", &spch);
}
dmfree(val);
@ -207,21 +180,17 @@ int set_x_iopsys_eu_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, vo
int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(ipaccsection, "dest_port", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value);
return 0;
}
int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(ipaccsection, "dest_port", value);
dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value);
return 0;
}
return 0;
@ -229,21 +198,17 @@ int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx,
int get_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(ipaccsection, "target", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "target", value);
return 0;
}
int set_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ipaccsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(ipaccsection, "target", value);
dmuci_set_value_by_section((struct uci_section *)data, "target", value);
return 0;
}
return 0;
@ -254,21 +219,17 @@ int set_x_bcm_com_ip_acc_list_cfgobj_target(char *refparam, struct dmctx *ctx, v
**************************************************************************************/
int get_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "name", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
return 0;
}
int set_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(forwardsection, "name", value);
dmuci_set_value_by_section((struct uci_section *)data, "name", value);
return 0;
}
return 0;
@ -276,17 +237,13 @@ int set_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char
int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "enabled", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", value);
return 0;
}
int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
int check;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
@ -296,9 +253,9 @@ int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, ch
case VALUESET:
string_to_bool(value, &b);
if(b)
dmuci_set_value_by_section(forwardsection, "enabled", "1");
dmuci_set_value_by_section((struct uci_section *)data, "enabled", "1");
else
dmuci_set_value_by_section(forwardsection, "enabled", "0");
dmuci_set_value_by_section((struct uci_section *)data, "enabled", "0");
return 0;
}
return 0;
@ -306,9 +263,7 @@ int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, ch
int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "reflection", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "reflection", value);
if((*value)[0] == '\0') {
*value = "1";
}
@ -318,7 +273,6 @@ int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data,
int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
@ -328,9 +282,9 @@ int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data,
case VALUESET:
string_to_bool(value, &b);
if(b)
dmuci_set_value_by_section(forwardsection, "reflection", "1");
dmuci_set_value_by_section((struct uci_section *)data, "reflection", "1");
else
dmuci_set_value_by_section(forwardsection, "reflection", "0");
dmuci_set_value_by_section((struct uci_section *)data, "reflection", "0");
return 0;
}
return 0;
@ -338,22 +292,17 @@ int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data,
int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "proto", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", value);
return 0;
}
int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(forwardsection, "proto", value);
dmuci_set_value_by_section((struct uci_section *)data, "proto", value);
return 0;
}
return 0;
@ -361,22 +310,17 @@ int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data,
int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "src", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "src", value);
return 0;
}
int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(forwardsection, "src", value);
dmuci_set_value_by_section((struct uci_section *)data, "src", value);
return 0;
}
return 0;
@ -384,22 +328,17 @@ int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *d
int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "dest", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "dest", value);
return 0;
}
int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(forwardsection, "dest", value);
dmuci_set_value_by_section((struct uci_section *)data, "dest", value);
return 0;
}
return 0;
@ -407,22 +346,17 @@ int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *d
int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "src_dport", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", value);
return 0;
}
int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(forwardsection, "src_dport", value);
dmuci_set_value_by_section((struct uci_section *)data, "src_dport", value);
return 0;
}
return 0;
@ -430,9 +364,7 @@ int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *d
int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "dest_port", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", value);
if ((*value)[0] == '\0') {
*value = "any";
}
@ -441,9 +373,6 @@ int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *d
int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
@ -451,7 +380,7 @@ int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *d
if (strcasecmp(value, "any") == 0) {
value = "";
}
dmuci_set_value_by_section(forwardsection, "dest_port", value);
dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value);
return 0;
}
return 0;
@ -459,9 +388,7 @@ int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *d
int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "src_port", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", value);
if ((*value)[0] == '\0') {
*value = "any";
}
@ -470,9 +397,6 @@ int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *dat
int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
@ -480,7 +404,7 @@ int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *dat
if (strcasecmp(value, "any") == 0) {
value = "";
}
dmuci_set_value_by_section(forwardsection, "src_port", value);
dmuci_set_value_by_section((struct uci_section *)data, "src_port", value);
return 0;
}
return 0;
@ -488,22 +412,17 @@ int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *dat
int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "dest_ip", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", value);
return 0;
}
int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(forwardsection, "dest_ip", value);
dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", value);
return 0;
}
return 0;
@ -511,9 +430,7 @@ int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, vo
int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_string(forwardsection, "src_dip", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", value);
if ((*value)[0] == '\0') {
*value = "any";
}
@ -522,9 +439,6 @@ int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, vo
int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
@ -532,7 +446,7 @@ int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, vo
if (strcasecmp(value, "any") == 0) {
value = "";
}
dmuci_set_value_by_section(forwardsection, "src_dip", value);
dmuci_set_value_by_section((struct uci_section *)data, "src_dip", value);
return 0;
}
return 0;
@ -541,14 +455,11 @@ int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, vo
int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *val;
struct uci_element *e = NULL;
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_list(forwardsection, "src_ip", &val);
dmuci_get_value_by_section_list((struct uci_section *)data, "src_ip", &val);
if (val) {
*value = dmuci_list_to_string(val, ",");
}
else {
} else {
*value = "";
}
if ((*value)[0] == '\0') {
@ -560,21 +471,19 @@ int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void
int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch, *val, *spch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
if (strcasecmp(value, "any") == 0) {
dmuci_delete_by_section(forwardsection, "src_ip", "");
}
else {
dmuci_delete_by_section(forwardsection, "src_ip", "");
dmuci_delete_by_section((struct uci_section *)data, "src_ip", "");
} else {
dmuci_delete_by_section((struct uci_section *)data, "src_ip", "");
val = dmstrdup(value);
pch = strtok_r(val, " ,", &spch);
while (pch != NULL) {
dmuci_add_list_value_by_section(forwardsection, "src_ip", pch);
dmuci_add_list_value_by_section((struct uci_section *)data, "src_ip", pch);
pch = strtok_r(NULL, " ,", &spch);
}
dmfree(val);
@ -587,9 +496,8 @@ int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void
int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *list = NULL;
struct uci_section *forwardsection = (struct uci_section *)data;
dmuci_get_value_by_section_list(forwardsection, "src_mac", &list);
dmuci_get_value_by_section_list((struct uci_section *)data, "src_mac", &list);
*value = dmuci_list_to_string(list, " ");
return 0;
}
@ -597,17 +505,16 @@ int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, c
int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch, *spch;
struct uci_section *forwardsection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_delete_by_section(forwardsection, "src_mac", NULL);
dmuci_delete_by_section((struct uci_section *)data, "src_mac", NULL);
value = dmstrdup(value);
pch = strtok_r(value, " ", &spch);
while (pch != NULL) {
dmuci_add_list_value_by_section(forwardsection, "src_mac", pch);
dmuci_add_list_value_by_section((struct uci_section *)data, "src_mac", pch);
pch = strtok_r(NULL, " ", &spch);
}
dmfree(value);
@ -619,9 +526,8 @@ int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, c
/***** ADD DEL OBJ *******/
int add_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *value, *v;
char *instance;
struct uci_section *rule = NULL, *dmmap_rule= NULL;
char *value, *v, *instance;
struct uci_section *rule = NULL, *dmmap_rule = NULL;
check_create_dmmap_package("dmmap_firewall");
instance = get_last_instance_bbfdm("dmmap_firewall", "rule", "fruleinstance");
@ -638,39 +544,33 @@ int add_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char **inst
dmuci_add_section_bbfdm("dmmap_firewall", "rule", &dmmap_rule, &v);
dmuci_set_value_by_section(dmmap_rule, "section_name", section_name(rule));
*instancepara = update_instance_bbfdm(dmmap_rule, instance, "fruleinstance");
return 0;
}
int delete_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL;
struct uci_section *ss = NULL;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
struct uci_section *ipaccsection = (struct uci_section *)data;
struct uci_section *dmmap_section;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ipaccsection), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ipaccsection, NULL, NULL);
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
if (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_sections("firewall", "rule", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(s), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
@ -681,9 +581,8 @@ int delete_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char *in
int add_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *value, *v;
char *instance;
struct uci_section *redirect = NULL, *dmmap_redirect= NULL;
char *value, *v, *instance;
struct uci_section *redirect = NULL, *dmmap_redirect = NULL;
check_create_dmmap_package("dmmap_firewall");
instance = get_last_instance_bbfdm("dmmap_firewall", "redirect", "forwardinstance");
@ -702,33 +601,27 @@ int add_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data,
int delete_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct pforwardrgs *forwardargs;
struct uci_section *s = NULL;
struct uci_section *ss = NULL;
struct uci_section *forwardsection = (struct uci_section *)data;
struct uci_section *dmmap_section;
struct uci_section *forwardsection = (struct uci_section *)data, *s = NULL, *ss = NULL, *dmmap_section;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(forwardsection), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(forwardsection, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(s), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
@ -792,7 +685,6 @@ int set_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, cha
int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *irule = NULL, *irule_last = NULL;
struct uci_section *s = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -800,7 +692,7 @@ int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
list_for_each_entry(p, &dup_list, list) {
irule = handle_update_instance(1, dmctx, &irule_last, update_instance_alias_bbfdm, 3, p->dmmap_section, "fruleinstance", "frulealias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, irule) == DM_STOP)
return 0;
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
@ -809,7 +701,6 @@ int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
int browseport_forwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *iforward = NULL, *iforward_last = NULL;
struct uci_section *s = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);

View file

@ -13,6 +13,8 @@
#ifndef __SE_IPACCCFG_H
#define __SE_IPACCCFG_H
#include <libbbf_api/dmcommon.h>
extern DMOBJ tSe_IpAccObj[];
extern DMLEAF tSe_IpAccCfgParam[];
extern DMLEAF tSe_PortForwardingParam[];

View file

@ -9,11 +9,6 @@
*
*/
#include <uci.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include "x_iopsys_eu_logincfg.h"
/*** DMROOT.X_IOPSYS_EU_LoginCfg. ***/

View file

@ -12,6 +12,8 @@
#ifndef __SE_LOGINCFG_H
#define __SE_LOGINCFG_H
#include <libbbf_api/dmcommon.h>
extern DMLEAF tSe_LoginCfgParam[];
int set_x_bcm_admin_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action);

View file

@ -10,12 +10,6 @@
*
*/
#include <uci.h>
#include <ctype.h>
#include <libbbf_api/dmbbf.h>
#include <libbbf_api/dmuci.h>
#include <libbbf_api/dmubus.h>
#include <libbbf_api/dmcommon.h>
#include "dmentry.h"
#include "x_iopsys_eu_owsd.h"
@ -61,7 +55,6 @@ DMLEAF X_IOPSYS_EU_ListenObjParams[] = {
int browseXIopsysEuOwsdListenObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *iowsd_listen = NULL, *iowsd_listen_last = NULL;
struct uci_section *s = NULL;
struct dmmap_dup *p;
LIST_HEAD(dup_list);
@ -119,8 +112,7 @@ int set_x_iopsys_eu_owsd_global_redirect(char *refparam, struct dmctx *ctx, void
**************************************************************************************/
int get_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
dmuci_get_value_by_section_string(owsd_listensection, "port", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "port", value);
if ((*value)[0] == '\0') {
*value = "";
}
@ -129,13 +121,11 @@ int get_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void
int set_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(owsd_listensection, "port", value);
dmuci_set_value_by_section((struct uci_section *)data, "port", value);
return 0;
}
return 0;
@ -144,9 +134,8 @@ int set_x_iopsys_eu_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void
int get_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *iface;
struct uci_section *owsd_listensection = (struct uci_section *)data;
dmuci_get_value_by_section_string(owsd_listensection, "interface", &iface);
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &iface);
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); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
@ -158,7 +147,6 @@ int get_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx,
int set_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker;
struct uci_section *owsd_listensection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
@ -166,7 +154,7 @@ int set_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx,
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker) {
dmuci_set_value_by_section(owsd_listensection, "interface", linker);
dmuci_set_value_by_section((struct uci_section *)data, "interface", linker);
dmfree(linker);
}
return 0;
@ -176,9 +164,7 @@ int set_x_iopsys_eu_owsd_listenobj_interface(char *refparam, struct dmctx *ctx,
int get_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
dmuci_get_value_by_section_string(owsd_listensection, "ipv6", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "ipv6", value);
if ((*value)[0] != '\0' && (*value)[0] == 'o' && (*value)[1] == 'n' ) {
*value = "1";
}
@ -190,7 +176,6 @@ int get_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx
int set_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
struct uci_section *owsd_listensection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
@ -200,9 +185,9 @@ int set_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx
case VALUESET:
string_to_bool(value, &b);
if(b)
dmuci_set_value_by_section(owsd_listensection, "ipv6", "on");
dmuci_set_value_by_section((struct uci_section *)data, "ipv6", "on");
else
dmuci_set_value_by_section(owsd_listensection, "ipv6", "off");
dmuci_set_value_by_section((struct uci_section *)data, "ipv6", "off");
return 0;
}
return 0;
@ -210,8 +195,7 @@ int set_x_iopsys_eu_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx
int get_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
dmuci_get_value_by_section_string(owsd_listensection, "whitelist_interface_as_origin", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "whitelist_interface_as_origin", value);
if ((*value)[0] == '\0' ) {
*value = "0";
}
@ -221,7 +205,6 @@ int get_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dm
int set_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
struct uci_section *owsd_listensection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
@ -231,9 +214,9 @@ int set_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dm
case VALUESET:
string_to_bool(value, &b);
if(b)
dmuci_set_value_by_section(owsd_listensection, "whitelist_interface_as_origin", "1");
dmuci_set_value_by_section((struct uci_section *)data, "whitelist_interface_as_origin", "1");
else
dmuci_set_value_by_section(owsd_listensection, "whitelist_interface_as_origin", "0");
dmuci_set_value_by_section((struct uci_section *)data, "whitelist_interface_as_origin", "0");
return 0;
}
return 0;
@ -241,8 +224,7 @@ int set_x_iopsys_eu_owsd_listenobj_whitelist_interface(char *refparam, struct dm
int get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
dmuci_get_value_by_section_string(owsd_listensection, "whitelist_dhcp_domains", value);
dmuci_get_value_by_section_string((struct uci_section *)data, "whitelist_dhcp_domains", value);
if ((*value)[0] == '\0') {
*value = "0";
}
@ -252,7 +234,6 @@ int get_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *
int set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
struct uci_section *owsd_listensection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
@ -262,9 +243,9 @@ int set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *
case VALUESET:
string_to_bool(value, &b);
if(b)
dmuci_set_value_by_section(owsd_listensection, "whitelist_dhcp_domains", "1");
dmuci_set_value_by_section((struct uci_section *)data, "whitelist_dhcp_domains", "1");
else
dmuci_set_value_by_section(owsd_listensection, "whitelist_dhcp_domains", "0");
dmuci_set_value_by_section((struct uci_section *)data, "whitelist_dhcp_domains", "0");
return 0;
}
return 0;
@ -273,9 +254,8 @@ int set_x_iopsys_eu_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *
int get_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *val;
struct uci_section *owsd_listensection = (struct uci_section *)data;
dmuci_get_value_by_section_list(owsd_listensection, "origin", &val);
dmuci_get_value_by_section_list((struct uci_section *)data, "origin", &val);
if (val)
*value = dmuci_list_to_string(val, " ");
else
@ -286,16 +266,16 @@ int get_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, voi
int set_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch, *spch;
struct uci_section *owsd_listensection = (struct uci_section *)data;
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_delete_by_section(owsd_listensection, "origin", NULL);
dmuci_delete_by_section((struct uci_section *)data, "origin", NULL);
value = dmstrdup(value);
pch = strtok_r(value, " ", &spch);
while (pch != NULL) {
dmuci_add_list_value_by_section(owsd_listensection, "origin", pch);
dmuci_add_list_value_by_section((struct uci_section *)data, "origin", pch);
pch = strtok_r(NULL, " ", &spch);
}
dmfree(value);
@ -307,25 +287,23 @@ int set_x_iopsys_eu_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, voi
////////////////////////SET AND GET ALIAS/////////////////////////////////
int get_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_owsd", "owsd-listen", section_name(owsd_listensection), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "olistenalias", value);
get_dmmap_section_of_config_section("dmmap_owsd", "owsd-listen", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section) dmuci_get_value_by_section_string(dmmap_section, "olistenalias", value);
return 0;
}
int set_x_iopsys_eu_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
struct uci_section *dmmap_section;
get_dmmap_section_of_config_section("dmmap_owsd", "owsd-listen", section_name(owsd_listensection), &dmmap_section);
switch (action) {
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section(dmmap_section, "olistenalias", value);
get_dmmap_section_of_config_section("dmmap_owsd", "owsd-listen", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section) dmuci_set_value_by_section(dmmap_section, "olistenalias", value);
return 0;
}
return 0;
@ -405,19 +383,17 @@ int set_x_iopsys_eu_owsd_ubus_proxy_ca(char *refparam, struct dmctx *ctx, void *
int get_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
char *net_cur_mode = NULL;
dmuci_get_option_value_string("netmode", "setup", "curmode", &net_cur_mode);
if(strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
dmuci_get_value_by_section_string(owsd_listensection, "cert", value);
if (strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
dmuci_get_value_by_section_string((struct uci_section *)data, "cert", value);
}
return 0;
}
int set_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
char *net_cur_mode = NULL;
switch (action) {
@ -425,9 +401,9 @@ int set_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data
return 0;
case VALUESET:
dmuci_get_option_value_string("netmode", "setup", "curmode", &net_cur_mode);
if(strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")){
if(strcmp(section_name(owsd_listensection), "wan_https")== 0)
dmuci_set_value_by_section(owsd_listensection, "cert", value);
if (strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
if (strcmp(section_name((struct uci_section *)data), "wan_https")== 0)
dmuci_set_value_by_section((struct uci_section *)data, "cert", value);
}
return 0;
}
@ -436,19 +412,17 @@ int set_x_iopsys_eu_owsd_ubus_cert(char *refparam, struct dmctx *ctx, void *data
int get_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
char *net_cur_mode= NULL;
dmuci_get_option_value_string("netmode", "setup", "curmode", &net_cur_mode);
if(strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
dmuci_get_value_by_section_string(owsd_listensection, "key", value);
if (strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
dmuci_get_value_by_section_string((struct uci_section *)data, "key", value);
}
return 0;
}
int set_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
char *net_cur_mode = NULL;
switch (action) {
@ -456,9 +430,9 @@ int set_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data,
return 0;
case VALUESET:
dmuci_get_option_value_string("netmode", "setup", "curmode", &net_cur_mode);
if(strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
if(strcmp(section_name(owsd_listensection), "wan_https")== 0)
dmuci_set_value_by_section(owsd_listensection, "key", value);
if (strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
if(strcmp(section_name((struct uci_section *)data), "wan_https") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "key", value);
}
return 0;
}
@ -467,19 +441,17 @@ int set_x_iopsys_eu_owsd_ubus_key(char *refparam, struct dmctx *ctx, void *data,
int get_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
char *net_cur_mode = NULL;
dmuci_get_option_value_string("netmode", "setup", "curmode", &net_cur_mode);
if(strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")){
dmuci_get_value_by_section_string(owsd_listensection, "ca", value);
if (strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
dmuci_get_value_by_section_string((struct uci_section *)data, "ca", value);
}
return 0;
}
int set_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *owsd_listensection = (struct uci_section *)data;
char *net_cur_mode = NULL;
switch (action) {
@ -487,9 +459,9 @@ int set_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data,
return 0;
case VALUESET:
dmuci_get_option_value_string("netmode", "setup", "curmode", &net_cur_mode);
if(strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
if(strcmp(section_name(owsd_listensection), "wan_https")== 0)
dmuci_set_value_by_section(owsd_listensection, "ca", value);
if (strstr(net_cur_mode, "repeater") || strstr(net_cur_mode, "extender")) {
if (strcmp(section_name((struct uci_section *)data), "wan_https") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "ca", value);
}
return 0;
}
@ -499,9 +471,8 @@ int set_x_iopsys_eu_owsd_ubus_ca(char *refparam, struct dmctx *ctx, void *data,
/***** ADD DEL OBJ *******/
int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
char *value, *v;
char *instance;
struct uci_section *listen_sec = NULL, *dmmap_sec= NULL;
char *value, *v, *instance;
struct uci_section *listen_sec = NULL, *dmmap_sec = NULL;
check_create_dmmap_package("dmmap_owsd");
instance = get_last_instance_bbfdm("dmmap_owsd", "owsd-listen", "olisteninstance");
@ -520,40 +491,35 @@ int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instan
int delete_owsd_listen_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL;
struct uci_section *ss = NULL;
struct uci_section *owsd_listensection = (struct uci_section *)data;
struct uci_section *dmmap_section;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
switch (del_action) {
case DEL_INST:
if(is_section_unnamed(section_name(owsd_listensection))){
if (is_section_unnamed(section_name((struct uci_section *)data))) {
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_owsd", "owsd-listen", "olisteninstance", section_name(owsd_listensection), atoi(instance), &dup_list);
delete_sections_save_next_sections("dmmap_owsd", "owsd-listen", "olisteninstance", section_name((struct uci_section *)data), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "olisteninstance", "dmmap_owsd", "owsd-listen");
dmuci_delete_by_section_unnamed(owsd_listensection, NULL, NULL);
dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_owsd", "owsd-listen", section_name(owsd_listensection), &dmmap_section);
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section(owsd_listensection, NULL, NULL);
get_dmmap_section_of_config_section("dmmap_owsd", "owsd-listen", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section) 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("owsd", "owsd-listen", s) {
if (found != 0){
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_owsd", "listen", section_name(s), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_owsd", "listen", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;

Some files were not shown because too many files have changed in this diff Show more