From b05ef07c87fcaf6618cd2e2eae8ae3d2bcbc2774 Mon Sep 17 00:00:00 2001 From: Rahul Date: Mon, 17 May 2021 11:11:54 +0530 Subject: [PATCH] bbf: config vlan translation add support to configure vlan translation via acs --- dmtree/tr181/bridging.c | 46 ++++++++++++++++++++++++++- dmtree/tr181/bridging.h | 2 ++ dmtree/vendor/iopsys/tr181/bridging.c | 26 +++++++++++++++ dmtree/vendor/iopsys/tr181/bridging.h | 1 + dmtree/vendor/iopsys/tr181/vendor.c | 1 + 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index 9be12b24..8d8094cc 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -9,7 +9,6 @@ * Author: Amin Ben Ramdhane * */ - #include "dmentry.h" #include "bridging.h" @@ -2326,6 +2325,38 @@ void bridging_get_priority_list(char *uci_opt_name, void *data, char **value) dmasprintf(value, "%s", uci_value); } +void bridging_get_vlan_tvid(char *uci_opt_name, void *data, char **value) +{ + dmuci_get_value_by_section_string(((struct bridge_vlan_args *)data)->bridge_vlan_sec, uci_opt_name, value); +} + +void bridging_set_vlan_tvid(char *uci_opt_name, void *data, char *value) +{ + char *ifname, *pch, *spch; + + dmuci_get_value_by_section_string(((struct bridge_vlan_args *)data)->bridge_sec, "ifname", &ifname); + char *br_ifname = dmstrdup(ifname); + for (pch = strtok_r(br_ifname, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + struct uci_section *device_s = NULL; + + /* Update tvid in the device section */ + uci_foreach_option_eq("network", "device", "name", pch, device_s) { + // tvid value 0 means vlan translation disable + if (strcmp(value, "0") == 0) { + dmuci_delete_by_section(device_s, uci_opt_name, NULL); + } else { + dmuci_set_value_by_section(device_s, uci_opt_name, value); + } + } + } + dmfree(br_ifname); + if (strcmp(value, "0") == 0) { + dmuci_delete_by_section(((struct bridge_vlan_args *)data)->bridge_vlan_sec, uci_opt_name, NULL); + } else { + dmuci_set_value_by_section(((struct bridge_vlan_args *)data)->bridge_vlan_sec, uci_opt_name, value); + } +} + void bridging_set_priority_list(char *uci_opt_name, void *data, char *value) { char buf[16]; @@ -2892,6 +2923,19 @@ static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, "vid", new_vid); } dmfree(new_vid); + + /* Update tvid, read from dmmap_bridge_vlan, set in vlanport_sec */ + struct uci_section *vlan_s = NULL; + uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_vlan", "bridge_vlan", "br_inst", ((struct bridge_vlanport_args *)data)->br_inst, vlan_s) { + char *vlan_inst; + dmuci_get_value_by_section_string(vlan_s, "bridge_vlan_instance", &vlan_inst); + if (strcmp(vlan_inst, instance) == 0) { + char *tvid; + dmuci_get_value_by_section_string(vlan_s, "tvid", &tvid); + dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, "tvid", tvid); + break; + } + } } } handle_inner_vid(); diff --git a/dmtree/tr181/bridging.h b/dmtree/tr181/bridging.h index 7c100950..b3bb885a 100644 --- a/dmtree/tr181/bridging.h +++ b/dmtree/tr181/bridging.h @@ -29,4 +29,6 @@ extern DMLEAF tBridgingProviderBridgeParams[]; void bridging_get_priority_list(char *uci_opt_name, void *data, char **value); void bridging_set_priority_list(char *uci_opt_name, void *data, char *value); +void bridging_get_vlan_tvid(char *uci_opt_name, void *data, char **value); +void bridging_set_vlan_tvid(char *uci_opt_name, void *data, char *value); #endif diff --git a/dmtree/vendor/iopsys/tr181/bridging.c b/dmtree/vendor/iopsys/tr181/bridging.c index 2e8d4e61..d1c0ec9a 100644 --- a/dmtree/vendor/iopsys/tr181/bridging.c +++ b/dmtree/vendor/iopsys/tr181/bridging.c @@ -54,6 +54,26 @@ static int set_BridgingBridgePort_DSCP_Eth_Priority_Map(char *refparam, struct d return 0; } +static int get_BridgingBridgeVLAN_TVID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + bridging_get_vlan_tvid("tvid", data, value); + return 0; +} + +static int set_BridgingBridgeVLAN_TVID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + if (dm_validate_int(value, RANGE_ARGS{{"0","4094"}}, 1)) + return FAULT_9007; + return 0; + case VALUESET: + bridging_set_vlan_tvid("tvid", data, value); + return 0; + } + return 0; +} + /********************************************************************************************************************************** * OBJ & PARAM DEFINITION ***********************************************************************************************************************************/ @@ -63,3 +83,9 @@ DMLEAF tIOPSYS_BridgingBridgePortParams[] = { {BBF_VENDOR_PREFIX"DSCPEthernetPriorityMapping", &DMWRITE, DMT_STRING, get_BridgingBridgePort_DSCP_Eth_Priority_Map, set_BridgingBridgePort_DSCP_Eth_Priority_Map, BBFDM_BOTH}, {0} }; + +DMLEAF tIOPSYS_BridgingBridgeVLANParams[] = { +/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/ +{BBF_VENDOR_PREFIX"TVID", &DMWRITE, DMT_INT, get_BridgingBridgeVLAN_TVID, set_BridgingBridgeVLAN_TVID, BBFDM_BOTH}, +{0} +}; diff --git a/dmtree/vendor/iopsys/tr181/bridging.h b/dmtree/vendor/iopsys/tr181/bridging.h index 05807fe7..505aeb54 100644 --- a/dmtree/vendor/iopsys/tr181/bridging.h +++ b/dmtree/vendor/iopsys/tr181/bridging.h @@ -15,5 +15,6 @@ #include extern DMLEAF tIOPSYS_BridgingBridgePortParams[]; +extern DMLEAF tIOPSYS_BridgingBridgeVLANParams[]; #endif //__IOPSYS_BRIDGING_H diff --git a/dmtree/vendor/iopsys/tr181/vendor.c b/dmtree/vendor/iopsys/tr181/vendor.c index 335b3f4c..df5c0215 100644 --- a/dmtree/vendor/iopsys/tr181/vendor.c +++ b/dmtree/vendor/iopsys/tr181/vendor.c @@ -26,5 +26,6 @@ DM_MAP_OBJ tVendorExtensionIOPSYS[] = { {"Device.Time.", NULL, tIOPSYS_TimeParams}, {"Device.IEEE1905.AL.NetworkTopology.", tIOPSYS_IEEE1905ALNetworkTopologyObj, tIOPSYS_IEEE1905ALNetworkTopologyParams}, {"Device.Bridging.Bridge.{i}.Port.{i}.", NULL, tIOPSYS_BridgingBridgePortParams}, +{"Device.Bridging.Bridge.{i}.VLAN.{i}.", NULL, tIOPSYS_BridgingBridgeVLANParams}, {0} };