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

📄 piaclgrp.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This software is copyrighted by and is the sole property of
 * VIA Networking Technologies, Inc. This software may only be used
 * in accordance with the corresponding license agreement. Any unauthorized
 * use, duplication, transmission, distribution, or disclosure of this
 * software is expressly forbidden.
 *
 * This software is provided by VIA Networking Technologies, Inc. "as is"
 * and any express or implied warranties, including, but not limited to, the
 * implied warranties of merchantability and fitness for a particular purpose
 * are disclaimed. In no event shall VIA Networking Technologies, Inc.
 * be liable for any direct, indirect, incidental, special, exemplary, or
 * consequential damages.
 *
 *
 * File:    piaclgrp.c
 *
 * Purpose: ACL group setting UI callback functions
 *
 * Author:  Tim Feng
 *
 * Date:    Dec 06, 2005
 *
 * Functions:
 *
 * Revision History:
 *
 */


#if !defined(__SWCFG_H__)
#include "swcfg.h"
#endif

#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__SWMSG_H__)
#include "swmsg.h"
#endif
#if !defined(__SWSYS_H__)
#include "swsys.h"
#endif
#if !defined(__SWL2PTB_H__)
#include "swl2ptb.h"
#endif
#if !defined(__SWSRAM_H__)
#include "swsram.h"
#endif
#if !defined(__PIACL_H__)
#include "piacl.h"
#endif
#if !defined(_PIEEPTBL_H)
#include "piacleep.h"
#endif
#if !defined(_PIACLGRP_H)
#include "piaclgrp.h"
#endif




/*---------------------  Static Definitions -------------------------*/
// Definitions to reduce statement length
#define pSCurGrp            (&pSPageBuf->SCurGrp)

/*---------------------  Static Classes  ----------------------------*/

/*---------------------  Static Variables  --------------------------*/

/*---------------------  Static Functions  --------------------------*/

static UINT8 s_byACLTransGidToEntryIndex(UINT8 u8GrpId);

static void s_vACLInsEntry (SACLGrpEepCfg* pSACLGrp);
static void s_vACLDelEntry(UINT8 u8GrpId);

static void s_vSetEepDefault (SACLPageCfg *pSPageBuf, BOOL bWriteDefault);

/*---------------------  Static Macros  -----------------------------*/



/*---------------------  Export Variables  --------------------------*/

// Some L4 protocols
UINT8 g_abyL4ProtoVal[] = {
                                0,    //ANY
                                1,    //ICMP
                                2,   //IGMP
                                L4_PROTOCOL_TCP,  //TCP
                                L4_PROTOCOL_UDP //UDP
                                };

//Some TCP based protocols
UINT16 g_awTcpDstPortVal[] = {
                                0,    //ANY
                                21,   //FTP
                                80  //HTTP
                                };


//Some UDP based protocols
UINT16 g_awUdpDstPortVal[] = {
                                0,    //ANY
                                69  //TFTP
                                };


//Some Ether Type Protocols ,exclude IPV4
UINT16 g_awEthProtoVal[] = {
                            0x0,    //ANY
                            0x0806,
                            0x8137   //IPX
                            };

/*---------------------  Export Functions  --------------------------*/


// Get an acl group in Eep struct mode
UINT8 PIACL_byGetGrp (UINT8 u8GrpId, SACLGrpEepCfg *pSACLGrpEepCfg)
{
    UINT8   byTblPtr;


    // If group id not exist, return error code
    byTblPtr = PIACLEEP_wSearchEntry(u8GrpId);
    if (byTblPtr == UINT8_MAX)
        return ACL_OP_GRP_NOT_EXIST;

    // Get entry from EEPROM and transfer into config buffer format
    PIACLEEP_vGetEntry(byTblPtr, pSACLGrpEepCfg);

    return OP_OK;
}

// Get an acl group in Page struct mode
UINT8 PIACL_byGetCurPageGrp(SACLPageCfg  *pSPageBuf)
{
    UINT8 byErrCode;
    SACLGrpEepCfg SACLGrpEepCfgBuf;


    if ((byErrCode=PIACL_byGetGrp(pSCurGrp->u8GrpId,&SACLGrpEepCfgBuf) ) != OP_OK)
        return byErrCode;
    
    //Trans Group Configuration from eeprom to page buffer 
    PIACL_vTransCfgFromEepToPage(pSCurGrp, &SACLGrpEepCfgBuf);

    return OP_OK;
}


// Insert an ACL group
UINT8 PIACL_byInsGrp (SACLPageCfg *pSPageBuf)
{
    UINT8 byErrCode;
    UINT8   byTblPtr;
    SACLGrpEepCfg SACLEepGrp;


    // If group id exist, return error code
    byTblPtr = PIACLEEP_wSearchEntry(pSCurGrp->u8GrpId);
    if (byTblPtr != UINT8_MAX)
        return ACL_OP_GRP_EXIST;
        
    if (pSPageBuf->wValidEntryNum == SWITCH_ACL_GRP_NUM )
        return ACL_OP_NO_EMPTY_GRP;    // If no empty group, return error code
     
    byErrCode = PIACL_byTransCfgFromPageToEepHw(&SACLEepGrp, pSCurGrp);
    if (byErrCode != OP_OK)
        return byErrCode;
 
    // Set new content into HW table
    s_vACLInsEntry (&SACLEepGrp);

    // Update group content in EEPROM and return
    byErrCode=PIACLEEP_byInsEntry(&SACLEepGrp);   

    return byErrCode;
}


// Edit an ACL group
UINT8 PIACL_byEditGrp (SACLPageCfg *pSPageBuf)
{
    UINT8   byTblPtr;
    UINT8 byErrCode;
    SACLGrpEepCfg SACLEepGrp;

    // If group id not exist, return error code
    byTblPtr = PIACLEEP_wSearchEntry(pSCurGrp->u8GrpId);
    if (byTblPtr == UINT8_MAX)
        return ACL_OP_GRP_NOT_EXIST;   
   
    byErrCode = PIACL_byTransCfgFromPageToEepHw(&SACLEepGrp, pSCurGrp);
    if (byErrCode != OP_OK)
    return byErrCode;

    // Insert new group into HW table
    s_vACLInsEntry (&SACLEepGrp);    

    PIACLEEP_vEditEntry(byTblPtr, &SACLEepGrp);
  
    return OP_OK;
}


// Delete an ACL group
UINT8 PIACL_byDelGrp (SACLPageCfg *pSPageBuf)
{
    UINT8  byTblPtr;

    // If group id not exist, return error code
    byTblPtr = PIACLEEP_wSearchEntry(pSCurGrp->u8GrpId);
    if (byTblPtr == UINT8_MAX)
        return ACL_OP_GRP_NOT_EXIST;
    
    // Delete group from hardware
    s_vACLDelEntry(pSCurGrp->u8GrpId);

    // Delete group from EEPROM and return
    PIACLEEP_vDelEntry(byTblPtr);
    return OP_OK;
}


// Read Group from EEPROM and set into page buf
//param1     the buffer for data from eeprom
//param2     weather read all ACL rule
//param3     if param2 is FALSE, only read ipv4 group or non-ipv4 group
void PIACL_vInitPage (SACLPageCfg *pSPageBuf,BOOL bIsAllType,BOOL bIsIpv4)
{

    PIACLEEP_vStatisTblInfo(pSPageBuf, bIsAllType, bIsIpv4);

    // Get max acl group id
    pSPageBuf->u8MaxValidGrpId = ACL_MAX_VALID_GRP_ID ;
}

// Set ACL Default Configuration into EEPROM
void PIACL_vSetEepDefault (SACLPageCfg *pSPageBuf, BOOL bWriteDefault)
{
    if (bWriteDefault)
        s_vSetEepDefault(pSPageBuf, TRUE);
}

//Get all groups from eeprom and Set hardware table  when switch booting
void PIACL_vSetHwFromEep(SACLPageCfg *pSPageBuf)
{
    UINT8 si;
    SACLGrpEepCfg SACLEepGrp;

    // Initialize page and set vlan mode into hardware
    PIACL_vInitPage(pSPageBuf, TRUE, FALSE);//Get all valid entry number from eeprom
    
    for (si=0; si<pSPageBuf->wValidEntryNum; si++){
        pSCurGrp->u8GrpId = pSPageBuf->abyValidGrpIdList[si];
         
        //Get group from eeprom
        PIACL_byGetGrp(pSCurGrp->u8GrpId, &SACLEepGrp);   
         
        //Save Configuration to HW
        s_vACLInsEntry(&SACLEepGrp);
    }
}


//Transfer Group configuration from Eeprom  to Page buffer  
void PIACL_vTransCfgFromEepToPage(SACLGrpPageCfg *pSGrpPageBuf, SACLGrpEepCfg* pSGrpEepBuf)
{
    UINT8 u8Index;	
    UINT8 u8MaxIndex;


    //Init Page buffer of current group
    STR_pvMemset(pSGrpPageBuf, 0, sizeof(SACLGrpPageCfg));	


    //Get Group Id
    pSGrpPageBuf->u8GrpId = pSGrpEepBuf->u8GrpId;


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

    //Get Vid if Vid not Zero
    if (pSGrpEepBuf->u16Vid) {
        //Get Vid
        pSGrpPageBuf->bVidEn = TRUE;
        pSGrpPageBuf->u16Vid = pSGrpEepBuf->u16Vid;
    }


    pSGrpPageBuf->bIsIpv4 = pSGrpEepBuf->bIsIpv4;
    //If Ipv4-based Group,get Src IP,Src IP Mask,Dst IP, Dst IP Mask ,L4 Protocol and Dst Port(only valid in TCP,UDP)    
    if (pSGrpEepBuf->bIsIpv4) {
        struct SACLIpv4GrpPageCfg *pSIpv4GrpPgBuf = (struct SACLIpv4GrpPageCfg *)&pSGrpPageBuf->UACLPageCfgBuf;
        struct SACLIPv4GrpEepCfg   *pSIpv4GrpEepBuf = (struct SACLIPv4GrpEepCfg *)&pSGrpEepBuf->UACLGrpEepCfg;

    
        if (pSIpv4GrpEepBuf->u32SIp) {     
            pSIpv4GrpPgBuf->bSIpEn = TRUE;
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szSIp, pSIpv4GrpEepBuf->u32SIp);
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szSIpMsk, pSIpv4GrpEepBuf->u32SIpMsk);  
        }
        else {
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szSIp, 0);
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szSIpMsk, 0xffffffff);             
        }

        
        if (pSIpv4GrpEepBuf->u32DIp) {    
            pSIpv4GrpPgBuf->bDIpEn=TRUE;
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szDIp, pSIpv4GrpEepBuf->u32DIp);
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szDIpMsk, pSIpv4GrpEepBuf->u32DIpMsk);  
        }
        else {
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szDIp, 0);
            STR_vCvtIpValtoStr(pSIpv4GrpPgBuf->szDIpMsk, 0xffffffff);             
        }  


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


        //Trans L4 protocol configuration 

        //L4 protocol
        pSIpv4GrpPgBuf->u16L4Proto = (UINT16)pSIpv4GrpEepBuf->u8L4Proto;  
        u8MaxIndex = sizeof(g_abyL4ProtoVal) / sizeof(UINT8);        
        for (u8Index = 0; u8Index < u8MaxIndex; u8Index ++) {
            if (g_abyL4ProtoVal[u8Index] == pSIpv4GrpEepBuf->u8L4Proto) {
                pSIpv4GrpPgBuf->byL4ProtoIndex = u8Index;  //got the Index of L4 protocol,break
                pSIpv4GrpPgBuf->u16L4Proto = 0;	
                break; 
            }	
        }	
        
         //TCP
        if (pSIpv4GrpEepBuf->u8L4Proto == L4_PROTOCOL_TCP) {    //If Configuration of L4 Protocol is TCP              
            pSIpv4GrpPgBuf->u32TcpPort = (UINT32)pSIpv4GrpEepBuf->u16DstPort;   
            u8MaxIndex = sizeof(g_awTcpDstPortVal) / sizeof(UINT16);
            for (u8Index = 0; u8Index < u8MaxIndex; u8Index++){
                if (g_awTcpDstPortVal[u8Index] == pSIpv4GrpEepBuf->u16DstPort) {
                    pSIpv4GrpPgBuf->byTcpPortIndex = u8Index;  //got the Index of TCP port,break
                    pSIpv4GrpPgBuf->u32TcpPort = 0;	
                    break; 
                }	
            }		
        }

        //UDP
        else if (pSIpv4GrpEepBuf->u8L4Proto == L4_PROTOCOL_UDP){   //If Configuration of L4 Protocol is UDP   
            pSIpv4GrpPgBuf->u32UdpPort = (UINT32)pSIpv4GrpEepBuf->u16DstPort;       
            u8MaxIndex = sizeof(g_awTcpDstPortVal) / sizeof(UINT16);
            for (u8Index = 0; u8Index<u8MaxIndex; u8Index ++) {

⌨️ 快捷键说明

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