diff --git a/bin/Makefile.am b/bin/Makefile.am index 7fd93e8..9b72c7a 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -28,6 +28,12 @@ cwmpd_SOURCES = \ ../dm/dmtree/root.c \ ../dm/dmtree/wandevice.c \ ../dm/dmtree/x_inteno_se_power_mgmt.c \ + ../dm/dmtree/x_inteno_se_igmp.c \ + ../dm/dmtree/x_inteno_se_wifi.c \ + ../dm/dmtree/x_inteno_se_ice.c \ + ../dm/dmtree/upnp.c \ + ../dm/dmtree/times.c \ + ../dm/dmtree/x_inteno_se_ipacccfg.c \ ../dm/dmtree/managementserver.c cwmpd_CFLAGS = \ diff --git a/dm/dmcommon.c b/dm/dmcommon.c index e30be28..fa38e90 100644 --- a/dm/dmcommon.c +++ b/dm/dmcommon.c @@ -9,11 +9,12 @@ * Author: Feten Besbes */ +#include #include #include #include #include -#include +#include "dmcwmp.h" char *cut_fx(char *str, char *delimiter, int occurence) { @@ -33,8 +34,7 @@ char *get_pid(char *pname) char str[TAILLE_MAX] = ""; char *v; f = popen(pname, "r"); - if (f != NULL) - { + if (f != NULL) { fgets(str, TAILLE_MAX, f); if (str[0] == '\0') { pclose(f); @@ -47,4 +47,14 @@ char *get_pid(char *pname) } v = dmstrdup(""); return v; +} + +int check_file(char *path) +{ + glob_t globbuf; + if(glob(path, 0, NULL, &globbuf) == 0) { + globfree(&globbuf); + return 1; + } + return 0; } \ No newline at end of file diff --git a/dm/dmcommon.h b/dm/dmcommon.h index 4039efa..b8a471a 100644 --- a/dm/dmcommon.h +++ b/dm/dmcommon.h @@ -21,5 +21,6 @@ do { \ char *cut_fx(char *str, char *delimiter, int occurence); char *get_pid(char *pname); +int check_file(char *path); #endif \ No newline at end of file diff --git a/dm/dmcwmp.c b/dm/dmcwmp.c index 07a9ca6..4655a85 100644 --- a/dm/dmcwmp.c +++ b/dm/dmcwmp.c @@ -11,6 +11,7 @@ #include "dmuci.h" #include "dmcwmp.h" #include "root.h" +#include "times.h" #include "upnp.h" #include "landevice.h" #include "wandevice.h" @@ -20,6 +21,7 @@ #include "x_inteno_se_wifi.h" #include "x_inteno_se_ice.h" #include "x_inteno_se_power_mgmt.h" +#include "x_inteno_se_ipacccfg.h" static char *get_parameter_notification (char *param); static int remove_parameter_notification(char *param); @@ -74,6 +76,8 @@ const struct prefix_method prefix_methods[] = { { DMROOT"X_INTENO_SE_Wifi.", 0, &entry_method_root_SE_Wifi }, { DMROOT"X_INTENO_SE_ICE.", 0, &entry_method_root_X_INTENO_SE_Ice }, { DMROOT"UPnP.", 0, &entry_method_root_upnp }, + { DMROOT"Time.", 0, &entry_method_root_Time }, + { DMROOT"X_INTENO_SE_IpAccCfg.", 0, &entry_method_root_X_INTENO_SE_IpAccCfg }, //{ DMROOT"Layer2Bridging.", &entry_method_root_Layer2Bridging }, }; diff --git a/dm/dmtree/times.c b/dm/dmtree/times.c new file mode 100644 index 0000000..feba068 --- /dev/null +++ b/dm/dmtree/times.c @@ -0,0 +1,161 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Copyright (C) 2015 Inteno Broadband Technology AB + * Author Imen Bhiri + * + */ + +#include +#include +#include "dmuci.h" +#include "dmcwmp.h" +#include "dmubus.h" +#include "times.h" +#include "dmcommon.h" + +int get_time_enable(char *refparam, struct dmctx *ctx, char **value) +{ + char *path = dmstrdup("/etc/rc.d/*sysntpd"); + + if (check_file(path)) + *value = dmstrdup("true"); + else + *value = dmstrdup("false"); + dmfree(path); + return 0; +} + +int set_time_enable(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + int check; + char *pname, *v; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + check = string_to_bool(value, &b); + if (check == -1) + return 0; + if(b) { + //delay_service restart "sysntpd" "1" //TODO + ///etc/init.d/sysntpd enable + } + else { + pname = dmstrdup("pidof ntpd"); + v = get_pid(pname); + if (v[0] != '\0') { + //etc/init.d/sysntpd stop; //TODO + //etc/init.d/sysntpd disable //TODO + } + } + } + return 0; +} + +//WE CAN WORK WITHOUT FOUND VALUE TO UPDATE +int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value) +{ + char *pch; + bool found = 0; + int element = 0; + struct uci_list *v; + struct uci_element *e; + int occurence; + + pch = dmstrdup(strrchr(refparam,'.')); + pch = pch + 10; + occurence = atoi(pch); + dmuci_get_option_value_list("system","ntp","server", &v); + if (v) { + uci_foreach_element(v, e) { + element++; + if (element == occurence) { + *value = dmstrdup(e->name); + found = 1; + break; + } + } + } + if (!found) { + *value = dmstrdup(""); + return 0; + } + if (strcmp(*value, "none") == 0) { + dmfree(*value); + *value = dmstrdup(""); + } + return 0; +} + +int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch, *path; + int check, ntp_num; + struct uci_list *v; + struct uci_element *e; + int count = 1; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + pch = dmstrdup(strrchr(refparam,'.')); + pch = pch + 10; + ntp_num = atoi(pch); + dmuci_get_option_value_list("system", "ntp", "server", &v); + dmuci_del_list_value("system", "ntp", "server", NULL); //TODO CHECK IF WE DON'T HAVE VALUE + if (v) { + uci_foreach_element(v, e) { + if (count == ntp_num) { + dmuci_add_list_value("system", "ntp", "server", value); + } + else { + dmuci_add_list_value("system", "ntp", "server", e->name); + } + count++; + } + } + while (count <= ntp_num) { + if (count == ntp_num) { + dmuci_add_list_value("system", "ntp", "server", value); + } + else { + dmuci_add_list_value("system", "ntp", "server", "none"); + } + count++; + } + path = dmstrdup("/etc/rc.d/*sysntpd"); + if (check_file(path)) { + //delay_service restart "sysntpd" //TODO + dmfree(path); + } + return 0; + } + return 0; +} + +int entry_method_root_Time(struct dmctx *ctx) +{ + IF_MATCH(ctx, DMROOT"Time.") { + DMOBJECT(DMROOT"Time.", ctx, "0", 1, NULL, NULL, NULL); + DMPARAM("Enable", ctx, "1", get_time_enable, set_time_enable, "xsd:boolean", 0, 1, UNDEF, NULL); + DMPARAM("NTPServer1", ctx, "1", get_time_ntpserver, set_time_ntpserver, "", 0, 1, UNDEF, NULL); + DMPARAM("NTPServer2", ctx, "1", get_time_ntpserver, set_time_ntpserver, "", 0, 1, UNDEF, NULL); + DMPARAM("NTPServer3", ctx, "1", get_time_ntpserver, set_time_ntpserver, "", 0, 1, UNDEF, NULL); + DMPARAM("NTPServer4", ctx, "1", get_time_ntpserver, set_time_ntpserver, "", 0, 1, UNDEF, NULL); + DMPARAM("NTPServer5", ctx, "1", get_time_ntpserver, set_time_ntpserver, "", 0, 1, UNDEF, NULL); + return 0; + } + return FAULT_9005; +} \ No newline at end of file diff --git a/dm/dmtree/times.h b/dm/dmtree/times.h new file mode 100644 index 0000000..dcd6a2b --- /dev/null +++ b/dm/dmtree/times.h @@ -0,0 +1,10 @@ +#ifndef __TIMES_H +#define __TIMES_H + +int get_time_enable(char *refparam, struct dmctx *ctx, char **value); +int set_time_enable(char *refparam, struct dmctx *ctx, int action, char *value); +int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value); +int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value); +int entry_method_root_Time(struct dmctx *ctx); + +#endif \ No newline at end of file diff --git a/dm/dmtree/wandevice.c b/dm/dmtree/wandevice.c index c70f904..7926657 100644 --- a/dm/dmtree/wandevice.c +++ b/dm/dmtree/wandevice.c @@ -99,7 +99,7 @@ char *get_wan_device_wan_dsl_traffic() char *dsl = NULL; dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); if (!res) - return ""; + return dmstrdup(""); json_select(res, "dslstats", -1, "traffic", &dsl, NULL); if (dsl) { if (strstr(dsl, "ATM")) { @@ -158,7 +158,6 @@ int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx else *value = dmstrdup("NoSignal"); dsl = get_wan_device_wan_dsl_traffic(); - TRACE("get_wan_device_wan_dsl_interface_config_status dsl %s \n", dsl); if (wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) { dmfree(status); dmfree(dsl); @@ -255,7 +254,7 @@ int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, char **value) *value = dmstrdup("None"); } dsl = get_wan_device_wan_dsl_traffic(); - if (wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) { + if (wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) { dmfree(dsl); goto end; } @@ -269,7 +268,7 @@ int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, char **value) *value = dmstrdup("None"); goto end; } - } + } end: return 0; } @@ -294,11 +293,11 @@ int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, cha TRACE("get_wan_device_dsl_downstreamcurrrate rate down %s", rate_down); dsl = get_wan_device_wan_dsl_traffic(); if (((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) - || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && rate_down) { + || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && rate_down) { if(rate_down[0] != '\0') { dmfree(*value); *value = rate_down; - } + } dmfree(dsl); } else { @@ -329,12 +328,11 @@ int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, char return 0; dsl = get_wan_device_wan_dsl_traffic(); if (((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) - || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && max_down) { + || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && max_down) { if (max_down != '\0') { dmfree(*value); - *value = max_down; + *value = max_down; } - dmfree(dsl); } else { @@ -356,7 +354,7 @@ int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, return 0; else { dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = dmstrdup("")); + DM_ASSERT(res, *value = dmstrdup("0")); json_select(res, "dslstats", -1, "attn_down_x100", &attn_down_x100, NULL); if (attn_down_x100) { dmasprintf(&attn_down_x100, "%d", (atoi(attn_down_x100) % 10)); @@ -365,8 +363,8 @@ int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, if ((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) { dmfree(*value); - *value = attn_down_x100; - dmfree(dsl); + *value = attn_down_x100; + dmfree(dsl); } //dmfree(attn_down_x100); } @@ -384,6 +382,7 @@ int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, return 0; else { dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = dmstrdup("0")); json_select(res, "dslstats", -1, "snr_down_x100", &snr_down_x100, NULL); if (snr_down_x100) { dmasprintf(&snr_down_x100, "%d", (atoi(snr_down_x100) % 10)); @@ -392,13 +391,13 @@ int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, if (((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0))) { dmfree(*value); - *value = snr_down_x100; - dmfree(dsl); + *value = snr_down_x100; + dmfree(dsl); } //dmfree(snr_down_x100); } } - return 0; + return 0; } int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, char **value) @@ -420,11 +419,11 @@ int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, char return 0; dsl = get_wan_device_wan_dsl_traffic(); if (((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) - || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && rate_up) { + || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && rate_up) { if(rate_up[0] != '\0') { dmfree(*value); *value = rate_up; - } + } dmfree(dsl); } else { @@ -448,18 +447,18 @@ int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, char * else { dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = dmstrdup("")); - json_select(res, "dslstats", -1, NULL, NULL, &sub_obj); + json_select(res, "dslstats", -1, NULL, NULL, &sub_obj); if (sub_obj) json_select(sub_obj, "bearers", 0, "max_rate_up", &max_up, NULL); else return 0; dsl = get_wan_device_wan_dsl_traffic(); if (((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) - || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && max_up) { + || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) && max_up) { if (max_up != '\0') { dmfree(*value); *value = max_up; - } + } dmfree(dsl); } else { @@ -468,7 +467,7 @@ int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, char * dmfree(dsl); } } - return 0; + return 0; } int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, char **value) @@ -490,7 +489,7 @@ int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, ch if ((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0)) { dmfree(*value); - *value = attn_up_x100; + *value = attn_up_x100; dmfree(dsl); } //dmfree(attn_up_x100); @@ -510,6 +509,7 @@ int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, ch } else { dmubus_call("router", "dslstats", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = dmstrdup("0")); json_select(res, "dslstats", -1, "snr_up_x100", &snr_up_x100, NULL); if (snr_up_x100) { dmasprintf(&snr_up_x100, "%d", (atoi(snr_up_x100) % 10)); @@ -518,7 +518,7 @@ int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, ch if (((wandargs->instance == WAN_INST_ATM && strcmp(dsl, "adsl") == 0) || (wandargs->instance == WAN_INST_PTM && strcmp(dsl, "vdsl") == 0))) { //dmfree(*value); - *value = snr_up_x100; + *value = snr_up_x100; dmfree(dsl); } //dmfree(snr_up_x100); @@ -527,7 +527,7 @@ int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, ch *value = dmstrdup("0"); } } - return 0; + return 0; } int get_annexm_status(char *refparam, struct dmctx *ctx, char **value) @@ -537,7 +537,7 @@ int get_annexm_status(char *refparam, struct dmctx *ctx, char **value) dmuci_get_option_value_string("layer2_interface", "capabilities", "AnnexM", value); } if (*value) { - TRACE("get_annexm_status in if\n"); + TRACE("get_annexm_status in if\n"); if (strcasecmp(*value, "enabled") == 0) { //dmfree(value); *value = dmstrdup("1"); @@ -635,7 +635,7 @@ int get_wan_eth_intf_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **va json_select(res, "statistics", 0, "tx_bytes", value, NULL); if (*value) { if ((*value)[0] == '\0') - *value = dmstrdup("0"); + *value = dmstrdup("0"); } return 0; } @@ -650,7 +650,7 @@ int get_wan_eth_intf_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **va json_select(res, "statistics", 0, "rx_bytes", value, NULL); if (*value) { if ((*value)[0] == '\0') - *value = dmstrdup("0"); + *value = dmstrdup("0"); } return 0; } @@ -665,7 +665,7 @@ int get_wan_eth_intf_stats_tx_packets(char *refparam, struct dmctx *ctx, char ** json_select(res, "statistics", 0, "tx_packets", value, NULL); if (*value) { if ((*value)[0] == '\0') - *value = dmstrdup("0"); + *value = dmstrdup("0"); } return 0; } @@ -681,7 +681,7 @@ int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, char ** TRACE("get_wan_eth_intf_stats_rx_packets %s", value); if (*value) { if ((*value)[0] == '\0') - *value = dmstrdup("0"); + *value = dmstrdup("0"); } return 0; } @@ -689,7 +689,7 @@ int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, char ** int get_wandevice_wandevice_parameters(struct dmctx *ctx, char *dev, char *fdev) { char *notif_permission; - char *cwritable = dmstrdup("1"); + char *cwritable = dmstrdup("1"); dmuci_get_option_value_string("network", default_wan, "ifname", ¬if_permission); if (strcmp(dev, wan_devices[0].instance) == 0) @@ -787,7 +787,7 @@ int entry_method_root_WANDevice(struct dmctx *ctx) TRACE("entry_method_root_WANDevice call update_instance end\n"); //wanconnectiondevice init_wancdevargs(ctx, fwan); - SUBENTRY(get_wandevice_wanconnectiondevice_parameters, ctx, wan_devices[i].instance, iwan); //"$idev" "$iwan" "$fwan" ONLY fdev will be used as arg for get and set function + SUBENTRY(get_wandevice_wanconnectiondevice_parameters, ctx, wan_devices[i].instance, iwan);//"$idev" "$iwan" "$fwan" ONLY fdev will be used as arg for get and set function //BREAK POINT1 uci_foreach_option_cont("network", "interface", "ifname", fwan, ss) { if (ss != NULL) { @@ -797,7 +797,7 @@ int entry_method_root_WANDevice(struct dmctx *ctx) continue; dmuci_get_value_by_section_string(ss, "proto", &proto); init_wancprotoargs(ctx, ss); - iconp = update_instance(ss, cur_iconp, "conpinstance"); + iconp = update_instance(ss, cur_iconp, "conpinstance"); SUBENTRY(get_wandevice_wanprotoclconnection_parameters, ctx, wan_devices[i].instance, iwan, iconp, proto);// "$idev" "$iwan" "$iconp" "$fconp" "$proto" //ONLY fconp will be usedad parameter of get and set method TRACE("BREAK SUBENTRY \n"); if (cur_iconp != NULL) @@ -806,7 +806,7 @@ int entry_method_root_WANDevice(struct dmctx *ctx) dmfree(iconp); } else - break; + break; } if (cur_iwan) dmfree(cur_iwan); @@ -814,7 +814,7 @@ int entry_method_root_WANDevice(struct dmctx *ctx) dmfree(iwan); } else - break; + break; } if (cur_iwan) dmfree(cur_iwan); @@ -853,8 +853,8 @@ int get_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ct dmfree(vpi); dmfree(vci); break; - } - } + } + } return 0; } @@ -880,10 +880,10 @@ int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, type = dmstrdup("eoa"); } else if (strcmp(type, "PPPoA") == 0) { dmfree(type); - type = dmstrdup("pppoa"); + type = dmstrdup("pppoa"); } else if (strcmp(type, "IPoA") == 0) { dmfree(type); - type = dmstrdup("ipoa"); + type = dmstrdup("ipoa"); } dmastrcat(&encaptype, "encaps", type); dmfree(type); @@ -891,7 +891,7 @@ int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, dmfree(encaptype); if (strcmp(encapsulation, "vcmux") == 0) { dmfree(encapsulation); - *value = dmstrdup("VCMUX"); + *value = dmstrdup("VCMUX"); } else if (strcmp(encapsulation, "llc") == 0) { dmfree(encapsulation); @@ -917,7 +917,7 @@ int get_wandevice_wanconnectiondevice_parameters(struct dmctx *ctx, char *idev, bool ipn_perm = 1; bool pppn_perm = 1; char *proto, *notif_permission; - char *cwritable = dmstrdup("1"); + char *cwritable = dmstrdup("1"); dmuci_get_option_value_string("network", default_wan, "ifname", ¬if_permission); if (strcmp(idev, wan_devices[0].instance) == 0) @@ -928,7 +928,7 @@ int get_wandevice_wanconnectiondevice_parameters(struct dmctx *ctx, char *idev, if (strcmp(proto, "dhcp") == 0 || strcmp(proto, "static") == 0) ipn_perm = 0; if (strcmp(proto, "pppoa") == 0 || strcmp(proto, "pppoe") == 0) - pppn_perm = 0; + pppn_perm = 0; } DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.", ctx, cwritable, string_to_bool(notif_permission, &b_notif), NULL, NULL, NULL, idev, iwan);//noti permission is bool ADD notif_permission, DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.", ctx, "1", ipn_perm, NULL, NULL, NULL, idev, iwan); //ADD notif_permission:ipn_perm, @@ -966,23 +966,23 @@ int get_wandevice_wanprotoclconnection_parameters(struct dmctx *ctx, char *idev, string_to_bool(notif_permission, ¬if_b); if (strcmp(proto, "dhcp") == 0 || strcmp(proto, "static") == 0) { - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.", ctx, "1", notif_b, NULL, NULL, section_name(wandcprotoargs->wancprotosection), idev, iwan, iconp);//TO CHECK "linker_interface:$nlan" //TO CHECK - DMPARAM("Enable", ctx, "1", get_interface_enable_ubus, set_interface_enable_ubus, "xsd:boolean", 0, 0, UNDEF, NULL); + DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.", ctx, "1", notif_b, NULL, NULL, section_name(wandcprotoargs->wancprotosection), idev, iwan, iconp);//TO CHECK "linker_interface:$nlan" + DMPARAM("Enable", ctx, "1", get_interface_enable_ubus, set_interface_enable_ubus, "xsd:boolean", 0, 0, UNDEF, NULL); DMPARAM("ConnectionStatus", ctx, "0", get_wan_device_mng_status, NULL, "", 0, 0, UNDEF, NULL); DMPARAM("ExternalIPAddress", ctx, "0", get_wan_device_mng_interface_ip, NULL, "", notif_b, forced_inform_eip, UNDEF, NULL); //TO ADD "$forced_notify" - DMPARAM("MACAddress", ctx, "0", get_wan_device_mng_interface_mac, NULL, "", 0, 0, UNDEF, NULL); //TOCHECK - DMPARAM("ConnectionType", ctx, "1", get_wan_ip_link_connection_connection_type, set_wan_ip_link_connection_connection_type, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("AddressingType", ctx, "1", get_wan_ip_link_connection_addressing_type, set_wan_ip_link_connection_addressing_type, "", 0, 0, UNDEF, NULL); - DMPARAM("NATEnabled", ctx, "1", get_wan_ip_link_connection_nat_enabled, set_wan_ip_link_connection_nat_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("X_BROADCOM_COM_FirewallEnabled", ctx, "1", get_interface_firewall_enabled, set_interface_firewall_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("X_BROADCOM_COM_IGMPEnabled", ctx, "1", get_wan_ip_link_connection_igmp_enabled, set_wan_ip_link_connection_igmp_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("DNSEnabled", ctx, "1", get_wan_ip_link_connection_dns_enabled, set_wan_ip_link_connection_dns_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); + DMPARAM("MACAddress", ctx, "0", get_wan_device_mng_interface_mac, NULL, "", 0, 0, UNDEF, NULL);//TOCHECK + DMPARAM("ConnectionType", ctx, "1", get_wan_ip_link_connection_connection_type, set_wan_ip_link_connection_connection_type, "xsd:boolean", 0, 0, UNDEF, NULL); + DMPARAM("AddressingType", ctx, "1", get_wan_ip_link_connection_addressing_type, set_wan_ip_link_connection_addressing_type, "", 0, 0, UNDEF, NULL); + DMPARAM("NATEnabled", ctx, "1", get_wan_ip_link_connection_nat_enabled, set_wan_ip_link_connection_nat_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); + DMPARAM("X_BROADCOM_COM_FirewallEnabled", ctx, "1", get_interface_firewall_enabled, set_interface_firewall_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); + DMPARAM("X_BROADCOM_COM_IGMPEnabled", ctx, "1", get_wan_ip_link_connection_igmp_enabled, set_wan_ip_link_connection_igmp_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); + DMPARAM("DNSEnabled", ctx, "1", get_wan_ip_link_connection_dns_enabled, set_wan_ip_link_connection_dns_enabled, "xsd:boolean", 0, 0, UNDEF, NULL); //DMPARAM("DNSOverrideAllowed", ctx, "", , , "xsd:boolean", 0, 0, UNDEF, NULL); } else if (strcmp(proto, "pppoa") == 0 || strcmp(proto, "pppoe") == 0) { DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.%s.", ctx, "1", 1, NULL, NULL, linker, idev, iwan, iconp);//TO CHECK "linker_interface:$nlan" - DMPARAM("Enable", ctx, "1", get_interface_enable_ubus, set_interface_enable_ubus, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("ConnectionStatus", ctx, "0", get_wan_device_ppp_status, NULL, "", 0, 0, UNDEF, NULL); + DMPARAM("Enable", ctx, "1", get_interface_enable_ubus, set_interface_enable_ubus, "xsd:boolean", 0, 0, UNDEF, NULL); + DMPARAM("ConnectionStatus", ctx, "0", get_wan_device_ppp_status, NULL, "", 0, 0, UNDEF, NULL); DMPARAM("ExternalIPAddress", ctx, "0", get_wan_device_ppp_interface_ip, NULL, "", notif_b, forced_inform_eip, UNDEF, NULL); //TO ADD "$forced_notify" DMPARAM("MACAddress", ctx, "0", get_wan_device_mng_interface_mac, NULL, "", 0, 0, UNDEF, NULL); DMPARAM("Username", ctx, "1", get_wan_device_ppp_username, set_wan_device_username, "", 0, 0, UNDEF, NULL); @@ -1000,7 +1000,7 @@ int get_wan_device_mng_status(char *refparam, struct dmctx *ctx, char **value) char *pending = NULL; char *intf; char *status = NULL; - char *uptime = NULL; + char *uptime = NULL; struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); intf = dmstrdup(section_name(wandcprotoargs->wancprotosection)); @@ -1091,7 +1091,7 @@ int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx } } else - return 0; + return 0; } dmuci_set_value_by_section(wandcprotoargs->wancprotosection, "type", type); //delay_service reload "network" "1" @@ -1136,7 +1136,7 @@ int set_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx //delay_service reload "network" "1" return 0; } - return 0; + return 0; } int get_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, char **value) @@ -1156,7 +1156,7 @@ int get_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, ch dmfree(masq); dmfree(network); return 0; - } + } } } dmfree(masq); @@ -1182,7 +1182,7 @@ int set_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, in VALUESET: if(value[0] == '0') value = ""; - else if(value[0] != '1') + else if(value[0] != '1') return 0; uci_foreach_option_cont("firewall", "zone", "network", intf, s) { if (s != NULL) { @@ -1233,11 +1233,11 @@ int get_wan_igmp_rule_idx(char *iface, struct uci_section **rule, struct uci_sec else *enable = dmstrdup("1"); } - break; - } + break; + } } if (*rule != NULL) - break; + break; } } } @@ -1290,7 +1290,7 @@ int set_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, i } dmuci_set_value_by_section(rule, "target", value); dmuci_set_value_by_section(rule, "enabled", "1"); - //delay_service reload "firewall" "1" + //delay_service reload "firewall" "1" } return 0; } @@ -1330,7 +1330,7 @@ int set_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, in return 0; } } - + int get_wan_device_ppp_status(char *refparam, struct dmctx *ctx, char **value) { char *intf; @@ -1395,7 +1395,7 @@ int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, char **v //dmfree(res); TRACE("device %s \n", device); dmubus_call("network.device", "status", UBUS_ARGS{{"name", device}}, 1, &res); - if (res) { + if (res) { json_select(res, "macaddr", 0, NULL, value, NULL); goto end; } diff --git a/dm/dmtree/x_inteno_se_ipacccfg.c b/dm/dmtree/x_inteno_se_ipacccfg.c new file mode 100644 index 0000000..505c1ab --- /dev/null +++ b/dm/dmtree/x_inteno_se_ipacccfg.c @@ -0,0 +1,632 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Copyright (C) 2015 Inteno Broadband Technology AB + * Author Imen Bhiri + * + */ + + +#include +#include +#include "dmcwmp.h" +#include "dmuci.h" +#include "dmubus.h" +#include "dmcommon.h" +#include "x_inteno_se_ipacccfg.h" + +struct ipaccargs cur_ipaccargs = {0}; +struct pforwardrgs cur_pforwardrgs = {0}; + +inline int init_args_ipacc(struct dmctx *ctx, struct uci_section *s) +{ + struct ipaccargs *args = &cur_ipaccargs; + ctx->args = (void *)args; + args->ipaccsection = s; + return 0; +} + +inline int init_args_pforward(struct dmctx *ctx, struct uci_section *s) +{ + struct pforwardrgs *args = &cur_pforwardrgs; + ctx->args = (void *)args; + args->forwardsection = s; + return 0; +} + +/************************************************************************************* +**** function related to get_object_ip_acc_list_cfgobj **** +**************************************************************************************/ + +int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, char **value) +{ + struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + + dmuci_get_value_by_section_string(accargs->ipaccsection, "enabled", value); + if ((*value)[0] == '\0') { + dmfree(*value); + *value = dmstrdup("1"); + } + return 0; +} + +int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + int check; + struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + check = string_to_bool(value, &b); + if (check == -1) + return 0; + if(b) { + value = dmstrdup(""); + } + else { + value = dmstrdup("0"); + } + dmuci_set_value_by_section(accargs->ipaccsection, "enabled", value); + //delay_service restart "firewall" "0" //TODO + dmfree(value); + return 0; + } + return 0; +} + +int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, char **value) +{ + struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_list *list = NULL; + + dmuci_get_value_by_section_string(accargs->ipaccsection, "src_ip", value); + if ((*value)[0] == '\0') { + *value = dmstrdup("0.0.0.0/0"); + return 0; + } + return 0; +} + +int set_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_delete_by_section(accargs->ipaccsection, "src_ip", NULL); //TO CHECK + pch = strtok (value, ","); + while (pch != NULL) { + dmuci_add_list_value_by_section(accargs->ipaccsection, "src_ip", pch); + pch = strtok(NULL, ","); + } + //delay_service restart "firewall" "0"//TODO + return 0; + } + return 0; +} + +int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, char **value) +{ + struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + + dmuci_get_value_by_section_string(accargs->ipaccsection, "dest_port", value); + return 0; +} + +int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_set_value_by_section(accargs->ipaccsection, "dest_port", value); + //delay_service restart "firewall" "0" //TODO + return 0; + } + return 0; +} + +inline int get_object_ip_acc_list_cfgobj(struct dmctx *ctx, char *irule) +{ + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.%s.", ctx, "0", 1, NULL, NULL, NULL, irule); + DMPARAM("Enable", ctx, "1", get_x_bcm_com_ip_acc_list_cfgobj_enable, set_x_bcm_com_ip_acc_list_cfgobj_enable, "xsd:boolean", 0, 1, UNDEF, NULL); + DMPARAM("AccAddressAndNetMask", ctx, "1", get_x_inteno_cfgobj_address_netmask, set_x_inteno_cfgobj_address_netmask, "", 0, 1, UNDEF, NULL); + DMPARAM("AccPort", ctx, "1", get_x_bcm_com_ip_acc_list_cfgobj_acc_port, set_x_bcm_com_ip_acc_list_cfgobj_acc_port, "", 0, 1, UNDEF, NULL); + return 0; +} + + +/************************************************************************************* +**** function related to get_cache_object_port_forwarding **** +**************************************************************************************/ + +int get_port_forwarding_name(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "name", value); + return 0; +} + +int set_port_forwarding_name(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_set_value_by_section(forwardargs->forwardsection, "name", value); + //delay_service restart "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "enabled", value); + if((*value)[0] == '\0') { + dmfree(*value); + *value = dmstrdup("1"); + } + return 0; +} + +int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + int check; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + if (check == -1) + return 0; + if(b) + dmuci_set_value_by_section(forwardargs->forwardsection, "enabled", ""); + else + dmuci_set_value_by_section(forwardargs->forwardsection, "enabled", "0"); + //delay_service reload "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "reflection", value); + if((*value)[0] == '\0') { + dmfree(*value); + *value = dmstrdup("1"); + } + return 0; +} + +int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + int check; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + if (check == -1) + return 0; + if(b) + dmuci_set_value_by_section(forwardargs->forwardsection, "reflection", ""); + else + dmuci_set_value_by_section(forwardargs->forwardsection, "reflection", "0"); + //delay_service reload "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "proto", value); + return 0; +} + +int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_set_value_by_section(forwardargs->forwardsection, "proto", value); + //delay_service restart "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "src", value); + return 0; +} + +int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_set_value_by_section(forwardargs->forwardsection, "src", value); + //delay_service restart "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "src", value); + return 0; +} + +int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_set_value_by_section(forwardargs->forwardsection, "src", value); + //delay_service restart "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_dport", value); + return 0; +} + +int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_set_value_by_section(forwardargs->forwardsection, "src_dport", value); + //delay_service restart "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "dest_port", value); + if ((*value)[0] == '\0') { + dmfree(*value); + *value = dmstrdup("any"); + } + return 0; +} + +int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + if (strcasecmp(value, "any") == 0) { + value = dmstrdup(""); + } + dmuci_set_value_by_section(forwardargs->forwardsection, "dest_port", value); + //delay_service restart "firewall" "1" //TODO + dmfree(value); + return 0; + } + return 0; +} + +int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_port", value); + if ((*value)[0] == '\0') { + dmfree(*value); + *value = dmstrdup("any"); + } + return 0; +} + +int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + if (strcasecmp(value, "any") == 0) { + value = dmstrdup(""); + } + dmuci_set_value_by_section(forwardargs->forwardsection, "src_port", value); + //delay_service restart "firewall" "1" //TODO + dmfree(value); + return 0; + } + return 0; +} + +int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_ip", value); + return 0; +} + +int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_set_value_by_section(forwardargs->forwardsection, "src_ip", value); + //delay_service restart "firewall" "1" //TODO + return 0; + } + return 0; +} + +int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_dip", value); + if ((*value)[0] == '\0') { + dmfree(*value); + *value = dmstrdup("any"); + } + return 0; +} + +int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + if (strcasecmp(value, "any") == 0) { + value = dmstrdup(""); + } + dmuci_set_value_by_section(forwardargs->forwardsection, "src_dip", value); + //delay_service restart "firewall" "1" //TODO + dmfree(value); + return 0; + } + return 0; +} + +int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, char **value) +{ + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_ip", value); + if ((*value)[0] == '\0') { + dmfree(*value); + *value = dmstrdup("any"); + } + return 0; +} + +int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + if (strcasecmp(value, "any") == 0) { + value = dmstrdup(""); + } + dmuci_set_value_by_section(forwardargs->forwardsection, "src_ip", value); + //delay_service restart "firewall" "1" //TODO + dmfree(value); + return 0; + } + return 0; +} + +int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, char **value) +{ + struct uci_list *list = NULL; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + dmuci_get_value_by_section_list(forwardargs->forwardsection, "src_mac", &list); + *value = dmuci_list_to_string(list, " "); + return 0; +} + +int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, int action, char *value) +{ + bool b; + char *pch; + struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + + switch (action) { + VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + VALUESET: + dmuci_del_list_value_by_section(forwardargs->forwardsection, "src_mac", NULL); + pch = strtok (value, " "); + while (pch != NULL) { + dmuci_add_list_value_by_section(forwardargs->forwardsection, "src_mac", pch); + pch = strtok(NULL, " "); + } + //delay_service reload "firewall" "1" //TODO + return 0; + } + return 0; +} + +inline int get_object_port_forwarding(struct dmctx *ctx, char *iforward) +{ + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", ctx, "0", 1, NULL, NULL, NULL, iforward); + DMPARAM("Name", ctx, "1", get_port_forwarding_name, set_port_forwarding_name, "", 0, 1, UNDEF, NULL); + DMPARAM("Enable", ctx, "1", get_port_forwarding_enable, set_port_forwarding_enable, "xsd:boolean", 0, 1, UNDEF, NULL); + DMPARAM("EnalbeNatLoopback", ctx, "1", get_port_forwarding_loopback, set_port_forwarding_loopback, "xsd:boolean", 0, 1, UNDEF, NULL); + DMPARAM("Protocol", ctx, "1", get_port_forwarding_protocol, set_port_forwarding_protocol, "", 0, 1, UNDEF, NULL); + DMPARAM("ExternalZone", ctx, "1", get_port_forwarding_external_zone, set_port_forwarding_external_zone, "", 0, 1, UNDEF, NULL); + DMPARAM("InternalZone", ctx, "1", get_port_forwarding_internal_zone, set_port_forwarding_internal_zone, "", 0, 1, UNDEF, NULL); + DMPARAM("ExternalPort", ctx, "1", get_port_forwarding_external_port, set_port_forwarding_external_port, "", 0, 1, UNDEF, NULL); + DMPARAM("InternalPort", ctx, "1", get_port_forwarding_internal_port, set_port_forwarding_internal_port, "", 0, 1, UNDEF, NULL); + DMPARAM("SourcePort", ctx, "1", get_port_forwarding_source_port, set_port_forwarding_source_port, "", 0, 1, UNDEF, NULL); + DMPARAM("InternalIpAddress", ctx, "1", get_port_forwarding_internal_ipaddress, set_port_forwarding_internal_ipaddress, "", 0, 1, UNDEF, NULL); + DMPARAM("ExternalIpAddress", ctx, "1", get_port_forwarding_external_ipaddress, set_port_forwarding_external_ipaddress, "", 0, 1, UNDEF, NULL); + DMPARAM("SourceIpAddress", ctx, "1", get_port_forwarding_source_ipaddress, set_port_forwarding_source_ipaddress, "", 0, 1, UNDEF, NULL); + DMPARAM("SourceMacAddress", ctx, "1", get_port_forwarding_src_mac, set_port_forwarding_src_mac, "", 0, 1, UNDEF, NULL); + return 0; +} + +int entry_method_root_X_INTENO_SE_IpAccCfg(struct dmctx *ctx) +{ + char *irule = NULL; + char *cur_irule = NULL; + char *iforward = NULL; + char *cur_iforward = NULL; + struct uci_section *s = NULL; + IF_MATCH(ctx, DMROOT"X_INTENO_SE_IpAccCfg.") { + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.", ctx, "0", 1, NULL, NULL, NULL); + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.", ctx, "0", 1, NULL, NULL, NULL); + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.", ctx, "1", 1, NULL, NULL, NULL); + uci_foreach_sections("firewall", "rule", s) { + if (s != NULL ) { + init_args_ipacc(ctx, s); + irule = update_instance(s, cur_irule, "fruleinstance"); + SUBENTRY(get_object_ip_acc_list_cfgobj, ctx, irule); + if (cur_irule) + dmfree(cur_irule); + cur_irule = dmstrdup(irule); + dmfree(irule); + } + else + break; + } + uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { + if (s != NULL ) { + init_args_pforward(ctx, s); + iforward = update_instance(s, cur_iforward, "forwardinstance"); + SUBENTRY(get_object_port_forwarding, ctx, iforward); + if (cur_iforward) + dmfree(cur_iforward); + cur_iforward = dmstrdup(iforward); + dmfree(iforward); + } + else + break; + } + return 0; + } + return FAULT_9005; +} \ No newline at end of file diff --git a/dm/dmtree/x_inteno_se_ipacccfg.h b/dm/dmtree/x_inteno_se_ipacccfg.h new file mode 100644 index 0000000..32acd39 --- /dev/null +++ b/dm/dmtree/x_inteno_se_ipacccfg.h @@ -0,0 +1,51 @@ +#ifndef __SE_IPACCCFG_H +#define __SE_IPACCCFG_H + +struct ipaccargs +{ + struct uci_section *ipaccsection; +}; + +struct pforwardrgs +{ + struct uci_section *forwardsection; +}; + +inline int init_args_ipacc(struct dmctx *ctx, struct uci_section *s); +inline int init_args_pforward(struct dmctx *ctx, struct uci_section *s); +int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, char **value); +int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, int action, char *value); +int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, char **value); +int set_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, int action, char *value); +int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, char **value); +int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, int action, char *value); +inline int get_object_ip_acc_list_cfgobj(struct dmctx *ctx, char *irule); +int get_port_forwarding_name(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_name(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value); +int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, char **value); +int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, int action, char *value); +inline int get_object_port_forwarding(struct dmctx *ctx, char *iforward); +int entry_method_root_X_INTENO_SE_IpAccCfg(struct dmctx *ctx); +#endif \ No newline at end of file