From 7c78333321ac2b806e1c5275c6435f12f3922ea0 Mon Sep 17 00:00:00 2001 From: Palaksha Gowda Date: Thu, 9 Jul 2026 13:56:19 +0100 Subject: [PATCH] RDKB-65961 : MACVLAN is used for creating untagged vlan interfaces Signed-off-by: Palaksha Gowda --- config/RdkVlanManager.xml | 8 +- source/TR-181/include/vlan_apis.h | 10 +++ source/TR-181/middle_layer_src/vlan_apis.c | 87 +++++++++++++++++-- source/TR-181/middle_layer_src/vlan_dml.c | 11 +++ .../TR-181/middle_layer_src/vlan_internal.c | 17 ++++ 5 files changed, 123 insertions(+), 10 deletions(-) diff --git a/config/RdkVlanManager.xml b/config/RdkVlanManager.xml index 1cfda42..97f3010 100644 --- a/config/RdkVlanManager.xml +++ b/config/RdkVlanManager.xml @@ -202,7 +202,13 @@ unsignedInt uint32 true - + + + MACVLAN + unsignedInt + uint32 + true + X_RDK_BaseInterface string(64) diff --git a/source/TR-181/include/vlan_apis.h b/source/TR-181/include/vlan_apis.h index 9753c1b..79eac67 100644 --- a/source/TR-181/include/vlan_apis.h +++ b/source/TR-181/include/vlan_apis.h @@ -50,6 +50,7 @@ #define PSM_VLANMANAGER_LOWERLAYERS "dmsb.vlanmanager.%d.lowerlayers" #define PSM_VLANMANAGER_VLANID "dmsb.vlanmanager.%d.vlanid" #define PSM_VLANMANAGER_TPID "dmsb.vlanmanager.%d.tpid" +#define PSM_VLANMANAGER_MACVLAN "dmsb.vlanmanager.%d.macvlan" #define PSM_VLANMANAGER_BASEINTERFACE "dmsb.vlanmanager.%d.baseinterface" #define PSM_VLANMANAGER_PATH "dmsb.vlanmanager.%d.path" @@ -75,6 +76,13 @@ typedef enum { VLAN_IF_ERROR }vlan_link_status_e; +typedef enum macVlan_status +{ + MACVLAN_DISABLED = 0, + MACVLAN_PRIVATE = 1, + MACVLAN_PUBLIC = 2 +}macVlan_status_t; + typedef struct _DML_VLAN { @@ -88,6 +96,7 @@ _DML_VLAN CHAR BaseInterface[64]; INT VLANId; UINT TPId; + macVlan_status_t MacVlanEnable; CHAR Path[1024]; } DML_VLAN, *PDML_VLAN; @@ -96,6 +105,7 @@ static inline void DML_VLAN_INIT(PDML_VLAN pVlan) { pVlan->Enable = FALSE; pVlan->Status = VLAN_IF_DOWN; + pVlan->MacVlanEnable = MACVLAN_DISABLED; } /************************************* diff --git a/source/TR-181/middle_layer_src/vlan_apis.c b/source/TR-181/middle_layer_src/vlan_apis.c index 395de97..a3a9f12 100644 --- a/source/TR-181/middle_layer_src/vlan_apis.c +++ b/source/TR-181/middle_layer_src/vlan_apis.c @@ -361,7 +361,7 @@ void * Vlan_Disable(void *Arg) pthread_mutex_lock(&vlan_access_mutex); //Set EthLink to False. it will take care UnTagged Created Vlan Interface - if (Vlan_SetEthLink(pEntry, FALSE, FALSE) == ANSC_STATUS_FAILURE) + if (pEntry->MacVlanEnable != MACVLAN_DISABLED && Vlan_SetEthLink(pEntry, FALSE, FALSE) == ANSC_STATUS_FAILURE) { CcspTraceError(("%s-%d: Failed to Enable EthLink\n", __FUNCTION__, __LINE__)); } @@ -402,6 +402,22 @@ void * Vlan_Disable(void *Arg) Vlan_DeleteInterface(pEntry); #endif } +#if !defined(VLAN_MANAGER_HAL_ENABLED) + else if(pEntry->VLANId == -1 && pEntry->MacVlanEnable == MACVLAN_DISABLED) + { + /* If the VLANID = -1, delete the OVS bridge and remove the interface */ + if (strcmp(pEntry->BaseInterface, pEntry->Name)) + { + if (pEntry->BaseInterface[0] != '\0') + { + v_secure_system("brctl delif %s %s", pEntry->Name, pEntry->BaseInterface); + } + v_secure_system("ifconfig %s down", pEntry->Name); + v_secure_system("brctl delbr %s", pEntry->Name); + } + + } +#endif pEntry->Status = VLAN_IF_DOWN; EthLink_SendVirtualIfaceVlanStatus(pEntry->Path, "Down"); CcspTraceInfo(("%s - %s:Successfully deleted VLAN interface %s\n", __FUNCTION__, VLAN_MARKER_VLAN_IF_CREATE, pEntry->Name)); @@ -590,6 +606,35 @@ static ANSC_STATUS Vlan_CreateTaggedInterface(PDML_VLAN pEntry) } #endif +#if !defined(VLAN_MANAGER_HAL_ENABLED) +static ANSC_STATUS Vlan_CreateUnTaggedInterface(PDML_VLAN pEntry) +{ + ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; + + if (pEntry == NULL) + { + CcspTraceError(("%s-%d: Failed to Create UnTagged Vlan Interface\n", __FUNCTION__, __LINE__)); + return ANSC_STATUS_FAILURE; + } + + /* If the VLANID = -1, create an OVS bridge and add the interface */ + if(strcmp(pEntry->BaseInterface, pEntry->Name)) + { + v_secure_system("ip link show %s > /dev/null 2>&1 || brctl addbr %s", pEntry->Name, pEntry->Name); + v_secure_system("brctl addif %s %s 2>/dev/null", pEntry->Name, pEntry->BaseInterface); + v_secure_system("ifconfig %s up", pEntry->Name); + + if (Vlan_SetMacAddr(pEntry) == ANSC_STATUS_FAILURE) + { + CcspTraceError(("%s Failed to Set MacAddress \n", __FUNCTION__)); + return ANSC_STATUS_FAILURE; + } + } + return returnStatus; +} +#endif + + void * Vlan_Enable(void *Arg) { ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS; @@ -607,7 +652,7 @@ void * Vlan_Enable(void *Arg) pthread_mutex_lock(&vlan_access_mutex); //Create Vlan Tagged Interface - if(pEntry->VLANId > 0) { + if(pEntry->VLANId > 0 || (pEntry->VLANId == -1 && pEntry->MacVlanEnable == MACVLAN_DISABLED)) { if (Vlan_SetEthLink(pEntry, TRUE, TRUE) == ANSC_STATUS_FAILURE) { CcspTraceError(("%s-%d: Failed to Enable EthLink\n", __FUNCTION__, __LINE__)); @@ -617,25 +662,49 @@ void * Vlan_Enable(void *Arg) { CcspTraceError(("[%s][%d]Failed to get vlan interface status \n", __FUNCTION__, __LINE__)); } -#if defined(VLAN_MANAGER_HAL_ENABLED) if ( ( status != VLAN_IF_NOTPRESENT ) && ( status != VLAN_IF_ERROR ) ) { CcspTraceInfo(("%s %s:VLAN interface(%s) already exists, delete it first\n", __FUNCTION__, VLAN_MARKER_VLAN_IF_CREATE, pEntry->Name)); +#if defined(VLAN_MANAGER_HAL_ENABLED) returnStatus = vlan_eth_hal_deleteInterface(pEntry->Name, pEntry->InstanceNumber); if (ANSC_STATUS_SUCCESS != returnStatus) { CcspTraceError(("%s - Failed to delete the existing VLAN interface %s\n", __FUNCTION__, pEntry->Name)); } - CcspTraceInfo(("%s - %s:Successfully deleted VLAN interface %s\n", __FUNCTION__, VLAN_MARKER_VLAN_IF_DELETE, pEntry->Name)); + else +#else + { + v_secure_system("ip link set %s down", pEntry->Name); + v_secure_system("ip link delete %s",pEntry->Name); + } +#endif + { + CcspTraceInfo(("%s - %s:Successfully deleted VLAN interface %s\n", __FUNCTION__, VLAN_MARKER_VLAN_IF_DELETE, pEntry->Name)); + } } + +#if !defined(VLAN_MANAGER_HAL_ENABLED) + if(pEntry->VLANId > 0) + { #endif - returnStatus = Vlan_CreateTaggedInterface(pEntry); - if (ANSC_STATUS_SUCCESS != returnStatus) + returnStatus = Vlan_CreateTaggedInterface(pEntry); + if (ANSC_STATUS_SUCCESS != returnStatus) + { + pEntry->Status = VLAN_IF_ERROR; + CcspTraceError(("[%s][%d]Failed to create VLAN Tagged interface \n", __FUNCTION__, __LINE__)); + } +#if !defined(VLAN_MANAGER_HAL_ENABLED) + } + else { - pEntry->Status = VLAN_IF_ERROR; - CcspTraceError(("[%s][%d]Failed to create VLAN Tagged interface \n", __FUNCTION__, __LINE__)); + returnStatus = Vlan_CreateUnTaggedInterface(pEntry); + if (ANSC_STATUS_SUCCESS != returnStatus) + { + pEntry->Status = VLAN_IF_ERROR; + CcspTraceError(("[%s][%d]Failed to create VLAN UnTagged interface \n", __FUNCTION__, __LINE__)); + } } - +#endif //Get status of VLAN link while(iIterator < 10) { diff --git a/source/TR-181/middle_layer_src/vlan_dml.c b/source/TR-181/middle_layer_src/vlan_dml.c index 49c422d..9a3ac68 100644 --- a/source/TR-181/middle_layer_src/vlan_dml.c +++ b/source/TR-181/middle_layer_src/vlan_dml.c @@ -360,6 +360,11 @@ Vlan_GetParamUlongValue *puLong = p_Vlan->TPId; return TRUE; } + if (strcmp(ParamName, "MACVLAN") == 0) + { + *puLong = p_Vlan->MacVlanEnable; + return TRUE; + } /* CcspTraceWarning(("Unsupported parameter '%s'\n", ParamName)); */ return FALSE; } @@ -627,6 +632,12 @@ Vlan_SetParamUlongValue p_Vlan->TPId = uValue; return TRUE; } + if (strcmp(ParamName, "MACVLAN") == 0) + { + p_Vlan->MacVlanEnable = uValue; + return TRUE; + } + /* CcspTraceWarning(("Unsupported parameter '%s'\n", ParamName)); */ return FALSE; diff --git a/source/TR-181/middle_layer_src/vlan_internal.c b/source/TR-181/middle_layer_src/vlan_internal.c index 9d9abb9..ca2aec0 100644 --- a/source/TR-181/middle_layer_src/vlan_internal.c +++ b/source/TR-181/middle_layer_src/vlan_internal.c @@ -48,6 +48,7 @@ #define PSM_VLANMANAGER_CFG_REGION "dmsb.vlanmanager.cfg.%d.region" #define PSM_VLANMANAGER_CFG_VLANID "dmsb.vlanmanager.cfg.%d.vlanid" #define PSM_VLANMANAGER_CFG_TPID "dmsb.vlanmanager.cfg.%d.tpid" +#define PSM_VLANMANAGER_CFG_MACVLAN "dmsb.vlanmanager.cfg.%d.macvlan" extern char g_Subsystem[32]; extern ANSC_HANDLE bus_handle; @@ -278,6 +279,15 @@ static ANSC_STATUS VlanTerminationInitialize( ANSC_HANDLE hThisObject) pVlan[nIndex].TPId = atoi(acPSMValue) ; } + /* get macvlan from psm */ + memset(acPSMQuery, 0, sizeof(acPSMQuery)); + memset(acPSMValue, 0, sizeof(acPSMValue)); + snprintf( acPSMQuery, sizeof( acPSMQuery ), PSM_VLANMANAGER_CFG_MACVLAN, (vlanCfgIndexes[nIndex] + 1) ); + if ( CCSP_SUCCESS == DmlVlanGetPSMRecordValue( acPSMQuery, acPSMValue ) ) + { + pVlan[nIndex].MacVlanEnable = (UINT)strtoul(acPSMValue, NULL, 10); + } + /*TODO: *Need to be Removed Path From PSM Once RBUS Support Available in VlanManager and WanManager. */ @@ -377,6 +387,13 @@ static ANSC_STATUS VlanTerminationInitialize( ANSC_HANDLE hThisObject) pVlan[nIndex].TPId = atoi(acPSMValue) ; } + /* get macvlan from psm */ + snprintf( acPSMQuery, sizeof( acPSMQuery ), PSM_VLANMANAGER_MACVLAN, nIndex + 1 ); + if ( CCSP_SUCCESS == DmlVlanGetPSMRecordValue( acPSMQuery, acPSMValue ) ) + { + pVlan[nIndex].MacVlanEnable = (UINT)strtoul(acPSMValue, NULL, 10) ; + } + /* get base interface from psm */ snprintf( acPSMQuery, sizeof( acPSMQuery ), PSM_VLANMANAGER_BASEINTERFACE, nIndex + 1 ); if ( CCSP_SUCCESS == DmlVlanGetPSMRecordValue( acPSMQuery, acPSMValue ) )