⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 piaclgrp.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 C
📖 第 1 页 / 共 2 页
字号:
                if (g_awUdpDstPortVal[u8Index] == pSIpv4GrpEepBuf->u16DstPort) {
                    pSIpv4GrpPgBuf->byUdpPortIndex = u8Index;   //got the Index of UDP port,break
                    pSIpv4GrpPgBuf->u32UdpPort = 0;	
                    break; 
                }	
            }	
        } 
	 
    }

     
    //Non-Ipv4 based group
    else {        
        struct SACLNonIpv4GrpPageCfg  *pSNonIpv4GrpPgBuf = (struct SACLNonIpv4GrpPageCfg *)&pSGrpPageBuf->UACLPageCfgBuf;
        struct SACLNonIPv4GrpEepCfg  *pSNonIpv4GrpEepBuf = (struct SACLNonIPv4GrpEepCfg *)&pSGrpEepBuf->UACLGrpEepCfg;

   
        pSNonIpv4GrpPgBuf->wEthType = pSNonIpv4GrpEepBuf->wEthType;        
        u8MaxIndex = sizeof(g_awEthProtoVal) / sizeof(UINT16);     
        for (u8Index = 0; u8Index<u8MaxIndex; u8Index ++) {
            if (g_awEthProtoVal[u8Index] == pSNonIpv4GrpEepBuf->wEthType) {
                pSNonIpv4GrpPgBuf->byEthProtoIndex = u8Index;
                pSNonIpv4GrpPgBuf->wEthType = 0;	
                break; //got the Index
            }	
        }     
    }
}


//Transfer Group Configuration from  Page buffer struct to Eeprom struct 
UINT8 PIACL_byTransCfgFromPageToEepHw(SACLGrpEepCfg* pSGrpEepBuf, SACLGrpPageCfg *pSGrpPageBuf)
{
   STR_pvMemset(pSGrpEepBuf, 0, sizeof(SACLGrpEepCfg));


    //Check and Set Group Id
//    if (pSGrpPageBuf->u8GrpId < ACL_MIN_VALID_GRP_ID || pSGrpPageBuf->u8GrpId > ACL_MAX_VALID_GRP_ID)
//  pSGrpPageBuf->u8GrpId > ACL_MAX_VALID_GRP_ID always false
    if (pSGrpPageBuf->u8GrpId < ACL_MIN_VALID_GRP_ID)
        return ACL_OP_GID_INVALID;  
    pSGrpEepBuf->u8GrpId = pSGrpPageBuf->u8GrpId;


    //Set action
    pSGrpEepBuf->bFilter = pSGrpPageBuf->bFilter;


    //Set Vid
    if (pSGrpPageBuf->bVidEn) {
        if ((pSGrpPageBuf->u16Vid < VLAN_MIN_VALID_VID) || (pSGrpPageBuf->u16Vid > VLAN_MAX_VALID_VID_3268) )
            return ACL_OP_VID_INVALID;

        pSGrpEepBuf->u16Vid = pSGrpPageBuf->u16Vid;
    }

    
    pSGrpEepBuf->bIsIpv4 = pSGrpPageBuf->bIsIpv4;
    //Group is Ipv4 group
    if (pSGrpPageBuf->bIsIpv4) {    
        struct SACLIPv4GrpEepCfg *pSIpv4GrpEepBuf = (struct SACLIPv4GrpEepCfg  *)&pSGrpEepBuf->UACLGrpEepCfg;
        struct SACLIpv4GrpPageCfg  *pSIpv4GrpPgBuf = (struct SACLIpv4GrpPageCfg  *)&pSGrpPageBuf->UACLPageCfgBuf;        


        //Check Source IP and Source IP mask
        if (!pSIpv4GrpPgBuf->bSIpEn) {                          // Soruce Ip is any
            pSIpv4GrpEepBuf->u32SIp = 0;                        //0.0.0.0
            pSIpv4GrpEepBuf->u32SIpMsk = 0xffffffff;            //255.255.255.255         
        }
        else {
            if (0 == (pSIpv4GrpEepBuf->u32SIp = STR_dwCvtIpStrtoVal(pSIpv4GrpPgBuf->szSIp)))//SIp is invalid
                return ACL_OP_SIP_INVALID;
           
            if (0 == (pSIpv4GrpEepBuf->u32SIpMsk = STR_dwCvtIpStrtoVal(pSIpv4GrpPgBuf->szSIpMsk)))
                return ACL_OP_SIPMSK_INVALID; 
        }

        
        //Check Dest IP and Dest IP mask
        if (!pSIpv4GrpPgBuf->bDIpEn) { // Soruce Ip is any
            pSIpv4GrpEepBuf->u32DIp = 0;                         //0.0.0.0
            pSIpv4GrpEepBuf->u32DIpMsk = 0xffffffff;   //255.255.255.255         
        }
        else {
            if (0==(pSIpv4GrpEepBuf->u32DIp = STR_dwCvtIpStrtoVal(pSIpv4GrpPgBuf->szDIp)))//DIp is invalid
                return ACL_OP_DIP_INVALID;
           
            if (0==(pSIpv4GrpEepBuf->u32DIpMsk = STR_dwCvtIpStrtoVal(pSIpv4GrpPgBuf->szDIpMsk)))
                return ACL_OP_DIPMSK_INVALID; 
        }


        //IP Fragment check
        pSIpv4GrpEepBuf->bFragCheck = pSIpv4GrpPgBuf->bFragCheck;


        //Trans L4 protocol configuration. 
        
        //L4 protocol
        if (pSIpv4GrpPgBuf->u16L4Proto && pSIpv4GrpPgBuf->byL4ProtoIndex) {     //check whether set two l4 protocol
            if (pSIpv4GrpPgBuf->u16L4Proto != g_abyL4ProtoVal[pSIpv4GrpPgBuf->byL4ProtoIndex])
                return ACL_OP_TWO_TYPES_OF_L4PROTO_EXIST;
        }    
        
        if (pSIpv4GrpPgBuf->u16L4Proto) {
            if (pSIpv4GrpPgBuf->u16L4Proto > UINT8_MAX)
                return ACL_OP_L4PROTO_VAL_INVALID;                        
            pSIpv4GrpEepBuf->u8L4Proto = (UINT8)pSIpv4GrpPgBuf->u16L4Proto;        
        }
        else  
            pSIpv4GrpEepBuf->u8L4Proto = g_abyL4ProtoVal[pSIpv4GrpPgBuf->byL4ProtoIndex];
            
        //TCP
        if (pSIpv4GrpEepBuf->u8L4Proto == L4_PROTOCOL_TCP) {    //If Configuration of L4 Protocol is TCP
            if (pSIpv4GrpPgBuf->u32TcpPort && pSIpv4GrpPgBuf->byTcpPortIndex) { //check whether set two TCP port
                if (pSIpv4GrpPgBuf->u32TcpPort != g_awTcpDstPortVal[pSIpv4GrpPgBuf->byTcpPortIndex])
                    return ACL_OP_TWO_TYPES_OF_TCP_PORT_EXIST;
            }
            
            if (pSIpv4GrpPgBuf->u32TcpPort) {
                if (pSIpv4GrpPgBuf->u32TcpPort > UINT16_MAX)
                    return ACL_OP_TCP_PORT_VAL_INVALID;              
                pSIpv4GrpEepBuf->u16DstPort = (UINT16)pSIpv4GrpPgBuf->u32TcpPort;
            }
            else
                pSIpv4GrpEepBuf->u16DstPort = g_awTcpDstPortVal[pSIpv4GrpPgBuf->byTcpPortIndex];
        }

        //UDP
        else if (pSIpv4GrpEepBuf->u8L4Proto == L4_PROTOCOL_UDP) {    //If Configuration of L4 Protocol is UDP
            if (pSIpv4GrpPgBuf->u32UdpPort && pSIpv4GrpPgBuf->byUdpPortIndex) //check whether set two UDP port
                if (pSIpv4GrpPgBuf->u32UdpPort != g_awUdpDstPortVal[pSIpv4GrpPgBuf->byUdpPortIndex])
                    return ACL_OP_TWO_TYPES_OF_UDP_PORT_EXIST;
                
            if (pSIpv4GrpPgBuf->u32UdpPort) {
                if (pSIpv4GrpPgBuf->u32UdpPort > UINT16_MAX)
                    return ACL_OP_UDP_PORT_VAL_INVALID;                
                pSIpv4GrpEepBuf->u16DstPort = (UINT16)pSIpv4GrpPgBuf->u32UdpPort ;
            }    
            else 
                pSIpv4GrpEepBuf->u16DstPort = g_awUdpDstPortVal[pSIpv4GrpPgBuf->byUdpPortIndex];      
        }    
        
        //L4 protocol port can't exist with Ip fragment
        if ((pSIpv4GrpEepBuf->bFragCheck ) && (pSIpv4GrpEepBuf->u16DstPort) )
            return ACL_OP_L4PROTO_PORT_WITH_IPFRAG;
                 
    }	

    //Group is Non-Ipv4 
    else{       
        struct SACLNonIPv4GrpEepCfg *pSNonIpv4GrpEepBuf = (struct SACLNonIPv4GrpEepCfg *)&pSGrpEepBuf->UACLGrpEepCfg;
        struct SACLNonIpv4GrpPageCfg *pSNonIpv4GrpPgBuf = (struct SACLNonIpv4GrpPageCfg *)&pSGrpPageBuf->UACLPageCfgBuf;

        if (pSNonIpv4GrpPgBuf->byEthProtoIndex && pSNonIpv4GrpPgBuf->wEthType) //check whether set two UDP port
            if (pSNonIpv4GrpPgBuf->wEthType != g_awEthProtoVal[pSNonIpv4GrpPgBuf->byEthProtoIndex])
                return ACL_OP_TWO_TYPES_OF_ETHER_TYPE_EXIST;

        if (pSNonIpv4GrpPgBuf->wEthType) {
            //Patch to check whether configurate Ether type as IPV4    
            if (pSNonIpv4GrpPgBuf->wEthType == ETH_PROTOCOL_IPV4)
                return ACL_OP_ETHER_TYPE_AS_IPV4;

            pSNonIpv4GrpEepBuf->wEthType = (UINT16)pSNonIpv4GrpPgBuf->wEthType;
        }    
        else    
            pSNonIpv4GrpEepBuf->wEthType = g_awEthProtoVal[pSNonIpv4GrpPgBuf->byEthProtoIndex];
    }


    return OP_OK;
}



/////////////////////////////////////////////////////////////////////////////////////

//Trans Group id to Entry Index of the l2+ rule table.
UINT8 s_byACLTransGidToEntryIndex(UINT8 u8GrpId)
{
    return u8GrpId - 1;
}


// Insert ACL entry into HW table
void s_vACLInsEntry (SACLGrpEepCfg* pSACLGrp)
{
    STcamEntry    STcamEntryBuf;
    SL2pACEntry   SL2ACEntryBuf;
    UINT8         u8EntryIndex ;	
    UINT16        u16ByteMsk, u16MskType;

        
    u8EntryIndex = s_byACLTransGidToEntryIndex(pSACLGrp->u8GrpId);//Get the real entry index of the entry which will be insert.

    u16ByteMsk = 0;
    u16MskType = 0;

    //Set entry into TCAM  table
    STR_pvMemset(&STcamEntryBuf, 0 , sizeof(STcamEntry));


    // Incoming packet is VLAN-tagged packet
    if (pSACLGrp->u16Vid) {    
        STcamEntryBuf.bVlanTag = TRUE;
        STcamEntryBuf.u16Vid = pSACLGrp->u16Vid;
        u16MskType |= MSK_VLAN_TYPE;
        u16MskType |= MSK_VID;
    }

    
    //no matter Ipv4 or Non_ipv4 group,check this bit
    u16MskType |= MSK_IPV4;

    
    STcamEntryBuf.bIpv4 = pSACLGrp->bIsIpv4;
    if (pSACLGrp->bIsIpv4) {    //ipv4
        struct SACLIPv4GrpEepCfg* pSACLIPv4Grp = (struct SACLIPv4GrpEepCfg*)&pSACLGrp->UACLGrpEepCfg;
        struct tagSIpv4Fld*  ptagSIpv4Fld = (struct tagSIpv4Fld*)&STcamEntryBuf.UCfg13B;	


        //Ip fragment check
        if (pSACLIPv4Grp->bFragCheck) {
        STcamEntryBuf.bIpFrag = pSACLIPv4Grp->bFragCheck;
            u16MskType |= MSK_IP_FRG;
        } 
       
        //SIp
        if (pSACLIPv4Grp->u32SIp) {    
            ptagSIpv4Fld->u32SrcIp = pSACLIPv4Grp->u32SIp;
            u16MskType |= MSK_SRC_IP;
        }
       
        //DIp
        if (pSACLIPv4Grp->u32DIp) {
            ptagSIpv4Fld->u32DstIp = pSACLIPv4Grp->u32DIp;
            u16MskType |= MSK_DST_IP;
        }
       
        if (pSACLIPv4Grp->u8L4Proto) {        
            ptagSIpv4Fld->u8IpProto = pSACLIPv4Grp->u8L4Proto;            //Trans L4 protocol configuration
            u16MskType |= MSK_IP_PROTO;
           
            //Dst Port
            if (pSACLIPv4Grp->u16DstPort) { 
                STcamEntryBuf.bIpHd20Oct = TRUE;               //make sure IP header is 20 octs
                ptagSIpv4Fld->u32IpOption = (UINT32)pSACLIPv4Grp->u16DstPort;
                u16ByteMsk |= MSK_L4;
            }
           
        } //End if (pSACLIPv4Grp->u8L4Proto) 
       
    }	

    //Non-ipv4 based group
    else {       
        struct SACLNonIPv4GrpEepCfg* pSACLNonIPv4Grp = (struct SACLNonIPv4GrpEepCfg*)&pSACLGrp->UACLGrpEepCfg;
        UINT8       byTmpType[2];

    
        if (pSACLNonIPv4Grp->wEthType) {        
            *((PUINT16)byTmpType) = pSACLNonIPv4Grp->wEthType;
           
#if defined(__LITTLE_ENDIAN)
            // convert u16Type to byte array
            SWSRAM_vEndianConvert(byTmpType, 2);
#endif       
            STcamEntryBuf.UCfg13B.au8AftSV[0] = byTmpType[0];
            STcamEntryBuf.UCfg13B.au8AftSV[1] = byTmpType[1];
            u16ByteMsk |= 0x0003;    //unmaked 1st,2nd octet after SMAC or VLAN-tag (0000 0000 0000 0011 b)
            
#if defined(__LITTLE_ENDIAN)
            // convert byte array 
            SWSRAM_vEndianConvert(&STcamEntryBuf.UCfg13B.au8AftSV[1],4);
            SWSRAM_vEndianConvert(&STcamEntryBuf.UCfg13B.au8AftSV[5],4);
            SWSRAM_vEndianConvert(&STcamEntryBuf.UCfg13B.au8AftSV[9],4);
#endif   
        }//End Non-Ipv4 based group

    }

    // Insert entry into HW TCAM table
    SWTCAM_bInsEntry(u8EntryIndex, &STcamEntryBuf,FALSE);


    // Set entry into HW TCAM MASK table
    STR_pvMemset(&STcamEntryBuf, 0 , sizeof(STcamEntry));
    
    //UNMASK rules
    SWTCAM_vUnMskEntry(&STcamEntryBuf, pSACLGrp->bIsIpv4, u16MskType, u16ByteMsk);
    
    //make mask of IP option , SIp and DIp a little change
    if (pSACLGrp->bIsIpv4) {
        struct SACLIPv4GrpEepCfg* pSACLIPv4Grp = (struct SACLIPv4GrpEepCfg*)&pSACLGrp->UACLGrpEepCfg;
        struct tagSIpv4Fld*  ptagSIpv4Fld = (struct tagSIpv4Fld*)&STcamEntryBuf.UCfg13B;


        //SIp
        if (pSACLIPv4Grp->u32SIp) {    
            ptagSIpv4Fld->u32SrcIp = pSACLIPv4Grp->u32SIpMsk;
        }
       
        //DIp
        if (pSACLIPv4Grp->u32DIp) {
            ptagSIpv4Fld->u32DstIp = pSACLIPv4Grp->u32DIpMsk;
        }        
       
        if (pSACLIPv4Grp->u8L4Proto && pSACLIPv4Grp->u16DstPort) {    //ip options
            STcamEntryBuf.bIpHd20Oct = TRUE;                        //IP header is 20 OCTS
            ptagSIpv4Fld->u32IpOption = 0x0000ffff;                 //only mask the Dst port
        }    
       
    }
    
    else {     //Non-Ipv4
#if defined(__LITTLE_ENDIAN)
        // convert byte array 
        SWSRAM_vEndianConvert(&STcamEntryBuf.UCfg13B.au8AftSV[1],4);
        SWSRAM_vEndianConvert(&STcamEntryBuf.UCfg13B.au8AftSV[5],4);
        SWSRAM_vEndianConvert(&STcamEntryBuf.UCfg13B.au8AftSV[9],4);
#endif  
    }
    
    // Insert entry into HW TCAM MASK table
    SWTCAM_bInsEntry(u8EntryIndex, &STcamEntryBuf,TRUE);

    // Set entry into ACTION CODE table
    STR_pvMemset(&SL2ACEntryBuf, 0 , sizeof(SL2pACEntry));    
    SL2ACEntryBuf.bFilter = pSACLGrp->bFilter;
    
     // Insert entry into HW ACTION CODE table
    SWL2PAC_bInsEntry(u8EntryIndex, &SL2ACEntryBuf);
}

void s_vACLDelEntry(UINT8 u8GrpId)
{
    UINT8 u8GrpIndex ;	

    
    u8GrpIndex = s_byACLTransGidToEntryIndex(u8GrpId);//Get the real entry index of the entry which will be insert.

    SWTCAM_bDelEntry(u8GrpIndex);
}

// Set EEPROM default value of each ACL entry
static void s_vSetEepDefault (SACLPageCfg *pSPageBuf, BOOL bWriteDefault)
{
    // Clear all entry buffer
    STR_pvMemset(g_pu8NVRSwCache + (EEP_ADDR_ACL_GROUP - NVR_ADDR_DATA_AREA_START), 0, EEP_SIZE_ACL_TBL_ENTRY * SWITCH_ACL_GRP_NUM);

    if (!bWriteDefault) {
        // Not write default operation
        // Write cache data into flash
        NVRAM_bWriteBlock(EEP_ADDR_ACL_CFG, g_pu8NVRSwCache + (EEP_ADDR_ACL_CFG - NVR_ADDR_DATA_AREA_START), EEP_SIZE_ACL_CFG, FALSE);

        // Update checksum and return
        NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -