diff --git a/dm/dmtree/x_inteno_se_ipacccfg.c b/dm/dmtree/x_inteno_se_ipacccfg.c index b00b184..eaca208 100644 --- a/dm/dmtree/x_inteno_se_ipacccfg.c +++ b/dm/dmtree/x_inteno_se_ipacccfg.c @@ -21,6 +21,8 @@ struct ipaccargs cur_ipaccargs = {0}; struct pforwardrgs cur_pforwardrgs = {0}; +inline int entry_xinteno_ipacccfg_listcfgobj(struct dmctx *ctx); +inline int entry_xinteno_ipacccfg_portforwarding(struct dmctx *ctx); inline int init_args_ipacc(struct dmctx *ctx, struct uci_section *s) { struct ipaccargs *args = &cur_ipaccargs; @@ -54,7 +56,7 @@ int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, c int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, int action, char *value) { - static bool b; + bool b; int check; struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; @@ -64,6 +66,7 @@ int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, i return FAULT_9007; return 0; case VALUESET: + string_to_bool(value, &b); if(b) { value = ""; } @@ -78,10 +81,17 @@ int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, i int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, char **value) { + struct uci_list *val; + struct uci_element *e = NULL; struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; struct uci_list *list = NULL; - dmuci_get_value_by_section_string(accargs->ipaccsection, "src_ip", value); + dmuci_get_value_by_section_list(accargs->ipaccsection, "src_ip", &val); + if (val) { + *value = dmuci_list_to_string(val, ","); + } + else + *value = ""; if ((*value)[0] == '\0') { *value = "0.0.0.0/0"; return 0; @@ -91,21 +101,21 @@ int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, char int set_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, int action, char *value) { - char *pch, *spch; + char *pch, *spch, *val; struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_delete_by_section(accargs->ipaccsection, "src_ip", NULL); //TODO CHECK - value = dmstrdup(value); - pch = strtok_r (value, ",", &pch); + dmuci_delete_by_section(accargs->ipaccsection, "src_ip", ""); + val = dmstrdup(value); + pch = strtok_r(val, " ", &spch); while (pch != NULL) { dmuci_add_list_value_by_section(accargs->ipaccsection, "src_ip", pch); - pch = strtok_r(NULL, ",", &pch); + pch = strtok_r(NULL, " ", &spch); } - dmfree(value); + dmfree(val); return 0; } return 0; @@ -133,14 +143,6 @@ int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, 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, NULL, 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, NULL, 0, 1, UNDEF, NULL); - return 0; -} /************************************************************************************* @@ -182,7 +184,7 @@ 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) { - static bool b; + bool b; int check; struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; @@ -192,6 +194,7 @@ int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, int action, ch return FAULT_9007; return 0; case VALUESET: + string_to_bool(value, &b); if(b) dmuci_set_value_by_section(forwardargs->forwardsection, "enabled", ""); else @@ -214,7 +217,7 @@ 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) { - static bool b; + bool b; struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; switch (action) { @@ -223,8 +226,9 @@ int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, int action, return FAULT_9007; return 0; case VALUESET: + string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(forwardargs->forwardsection, "reflection", ""); + dmuci_set_value_by_section(forwardargs->forwardsection, "reflection", "1"); else dmuci_set_value_by_section(forwardargs->forwardsection, "reflection", "0"); return 0; @@ -436,9 +440,17 @@ int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, in int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, char **value) { + struct uci_list *val; + struct uci_element *e = NULL; struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_ip", value); + dmuci_get_value_by_section_list(forwardargs->forwardsection, "src_ip", &val); + if (val) { + *value = dmuci_list_to_string(val, ","); + } + else { + *value = ""; + } if ((*value)[0] == '\0') { *value = "any"; } @@ -475,21 +487,21 @@ 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) { - char *pch, *spch; + char *pch, *spch, *val; struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_del_list_value_by_section(forwardargs->forwardsection, "src_mac", NULL); - value = dmstrdup(value); + dmuci_delete_by_section(forwardargs->forwardsection, "src_mac", ""); + val = dmstrdup(value); pch = strtok_r(value, " ", &spch); while (pch != NULL) { dmuci_add_list_value_by_section(forwardargs->forwardsection, "src_mac", pch); pch = strtok_r(NULL, " ", &spch); } - dmfree(value); + dmfree(val); return 0; } return 0; @@ -541,61 +553,75 @@ int delete_ipacccfg_port_forwarding_instance(struct dmctx *ctx) } /**********************/ -inline int get_object_port_forwarding(struct dmctx *ctx, char *iforward) +/////////////SUB ENTRIES/////////////// +inline int entry_xinteno_ipacccfg_listcfgobj(struct dmctx *ctx) { - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", ctx, "0", 1, NULL, delete_ipacccfg_port_forwarding_instance, NULL, iforward); - DMPARAM("Name", ctx, "1", get_port_forwarding_name, set_port_forwarding_name, NULL, 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, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalZone", ctx, "1", get_port_forwarding_external_zone, set_port_forwarding_external_zone, NULL, 0, 1, UNDEF, NULL); - DMPARAM("InternalZone", ctx, "1", get_port_forwarding_internal_zone, set_port_forwarding_internal_zone, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalPort", ctx, "1", get_port_forwarding_external_port, set_port_forwarding_external_port, NULL, 0, 1, UNDEF, NULL); - DMPARAM("InternalPort", ctx, "1", get_port_forwarding_internal_port, set_port_forwarding_internal_port, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourcePort", ctx, "1", get_port_forwarding_source_port, set_port_forwarding_source_port, NULL, 0, 1, UNDEF, NULL); - DMPARAM("InternalIpAddress", ctx, "1", get_port_forwarding_internal_ipaddress, set_port_forwarding_internal_ipaddress, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalIpAddress", ctx, "1", get_port_forwarding_external_ipaddress, set_port_forwarding_external_ipaddress, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceIpAddress", ctx, "1", get_port_forwarding_source_ipaddress, set_port_forwarding_source_ipaddress, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceMacAddress", ctx, "1", get_port_forwarding_src_mac, set_port_forwarding_src_mac, NULL, 0, 1, UNDEF, NULL); + char *irule = NULL; + struct uci_section *s = NULL; + + uci_foreach_sections("firewall", "rule", s) { + init_args_ipacc(ctx, s); + irule = update_instance(s, irule, "fruleinstance"); + SUBENTRY(entry_xinteno_ipacccfg_listcfgobj_instance, ctx, irule); + } return 0; } +inline int entry_xinteno_ipacccfg_portforwarding(struct dmctx *ctx) +{ + char *iforward = NULL; + struct uci_section *s = NULL; + uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { + init_args_pforward(ctx, s); + iforward = update_instance(s, iforward, "forwardinstance"); + SUBENTRY(entry_xinteno_ipacccfg_portforwarding_instance, ctx, iforward); + } + 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, add_ipacccfg_port_forwarding, delete_ipacccfg_port_forwarding_all, 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); - dmfree(cur_irule); - cur_irule = dmstrdup(irule); - } - else - break; - } - dmfree(cur_irule); - 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); - } - else - break; - } - dmfree(cur_iforward); + SUBENTRY(entry_xinteno_ipacccfg_listcfgobj, ctx); + SUBENTRY(entry_xinteno_ipacccfg_portforwarding, ctx); + return 0; + } + return FAULT_9005; +} + +inline int entry_xinteno_ipacccfg_listcfgobj_instance(struct dmctx *ctx, char *irule) +{ + IF_MATCH(ctx, DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.%s.", 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, NULL, 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, NULL, 0, 1, UNDEF, NULL); + return 0; + } + return FAULT_9005; +} + +inline int entry_xinteno_ipacccfg_portforwarding_instance(struct dmctx *ctx, char *iforward) +{ + IF_MATCH(ctx, DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", iforward) { + DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", ctx, "0", 1, NULL, delete_ipacccfg_port_forwarding_instance, NULL, iforward); + DMPARAM("Name", ctx, "1", get_port_forwarding_name, set_port_forwarding_name, NULL, 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, NULL, 0, 1, UNDEF, NULL); + DMPARAM("ExternalZone", ctx, "1", get_port_forwarding_external_zone, set_port_forwarding_external_zone, NULL, 0, 1, UNDEF, NULL); + DMPARAM("InternalZone", ctx, "1", get_port_forwarding_internal_zone, set_port_forwarding_internal_zone, NULL, 0, 1, UNDEF, NULL); + DMPARAM("ExternalPort", ctx, "1", get_port_forwarding_external_port, set_port_forwarding_external_port, NULL, 0, 1, UNDEF, NULL); + DMPARAM("InternalPort", ctx, "1", get_port_forwarding_internal_port, set_port_forwarding_internal_port, NULL, 0, 1, UNDEF, NULL); + DMPARAM("SourcePort", ctx, "1", get_port_forwarding_source_port, set_port_forwarding_source_port, NULL, 0, 1, UNDEF, NULL); + DMPARAM("InternalIpAddress", ctx, "1", get_port_forwarding_internal_ipaddress, set_port_forwarding_internal_ipaddress, NULL, 0, 1, UNDEF, NULL); + DMPARAM("ExternalIpAddress", ctx, "1", get_port_forwarding_external_ipaddress, set_port_forwarding_external_ipaddress, NULL, 0, 1, UNDEF, NULL); + DMPARAM("SourceIpAddress", ctx, "1", get_port_forwarding_source_ipaddress, set_port_forwarding_source_ipaddress, NULL, 0, 1, UNDEF, NULL); + DMPARAM("SourceMacAddress", ctx, "1", get_port_forwarding_src_mac, set_port_forwarding_src_mac, NULL, 0, 1, UNDEF, NULL); return 0; } return FAULT_9005; diff --git a/dm/dmtree/x_inteno_se_ipacccfg.h b/dm/dmtree/x_inteno_se_ipacccfg.h index bad0e45..f7edfc3 100644 --- a/dm/dmtree/x_inteno_se_ipacccfg.h +++ b/dm/dmtree/x_inteno_se_ipacccfg.h @@ -11,43 +11,5 @@ 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 add_ipacccfg_port_forwarding(struct dmctx *ctx, char **instancepara); -int delete_ipacccfg_port_forwarding_all(struct dmctx *ctx); int entry_method_root_X_INTENO_SE_IpAccCfg(struct dmctx *ctx); #endif \ No newline at end of file