From 7953a350b431e0ace0babe8d0856759d9e12d94b Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Wed, 2 Dec 2020 13:31:08 +0100 Subject: [PATCH] Device.NAT.PortMapping.{i}.Protocol: fix get/set according to TR-181 standard --- dmtree/tr181/nat.c | 18 ++++-------------- libbbf_api/dmcommon.c | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/dmtree/tr181/nat.c b/dmtree/tr181/nat.c index 2d135827..03aaf7b5 100644 --- a/dmtree/tr181/nat.c +++ b/dmtree/tr181/nat.c @@ -505,14 +505,9 @@ static int set_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, /*#Device.NAT.PortMapping.{i}.Protocol!UCI:firewall/redirect,@i-1/proto*/ static int get_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *proto; + char *proto = NULL; dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); - if (strcmp(proto, "tcp") == 0) - *value = "TCP"; - else if (strcmp(proto, "udp") == 0) - *value = "UDP"; - else - *value = "TCP,UDP"; + *value = (proto && strcmp(proto, "udp") == 0) ? "UDP" : "TCP"; return 0; } @@ -520,16 +515,11 @@ static int set_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void { switch (action) { case VALUECHECK: - if (dm_validate_string(value, -1, -1, NATProtocol, 3, NULL, 0)) + if (dm_validate_string(value, -1, -1, NATProtocol, 2, NULL, 0)) return FAULT_9007; return 0; case VALUESET: - if (strcasecmp("TCP", value) == 0) - dmuci_set_value_by_section((struct uci_section *)data, "proto", "tcp"); - else if (strcasecmp("UDP", value) == 0) - dmuci_set_value_by_section((struct uci_section *)data, "proto", "udp"); - else - dmuci_set_value_by_section((struct uci_section *)data, "proto", "tcpudp"); + dmuci_set_value_by_section((struct uci_section *)data, "proto", (strcmp("UDP", value) == 0) ? "udp" : "tcp"); return 0; } return 0; diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index 2e8fa6eb..77f1652c 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -31,7 +31,7 @@ char *VendorClassIDMode[] = {"Exact", "Prefix", "Suffix", "Substring"}; char *DiagnosticsState[] = {"None", "Requested", "Canceled", "Complete", "Error"}; char *SupportedProtocols[] = {"HTTP", "HTTPS"}; char *InstanceMode[] = {"InstanceNumber", "InstanceAlias"}; -char *NATProtocol[] = {"TCP", "UDP", "TCP/UDP"}; +char *NATProtocol[] = {"TCP", "UDP"}; char *Config[] = {"High", "Low", "Off", "Advanced"}; char *Target[] = {"Drop", "Accept", "Reject", "Return", "TargetChain"}; char *ServerConnectAlgorithm[] = {"DNS-SRV", "DNS", "ServerTable", "WebSocket"};