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

📄 piacleep.c

📁 vt6528芯片交换机API函数和文档运行程序
💻 C
字号:
/*
 * 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:    piacleep.c
 *
 * Purpose: ACL related EEPROM accessing functions
 *
 * Author:  Tim Feng
 *
 * Date:    Dec 01, 2005
 *
 * Functions:
 *
 * Revision History:
 *
 */
#if !defined(_PIEEPROM_H)
#include "pieeprom.h"
#endif
#if !defined(__SWMSG_H__)
#include "swmsg.h"
#endif
#if !defined(__PIACL_H__)
#include "piacl.h"
#endif
#if !defined(_PIACLEEP_H)
#include "piacleep.h"
#endif
/*---------------------  Static Definitions -------------------------*/

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

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

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

/*---------------------  Static Macros  -----------------------------*/
#define s_vGetEntryId(wTblPtr, pbyId) PIEEP_vGetCfgFromEep(PIACLEEP_dwEntryEepAddr(wTblPtr), SIZE_OF_ACL_GID, (PUINT8)pbyId)
/*---------------------  Export Variables  --------------------------*/

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

// Search entry in EEPROM
// If search successed, return EEPROM table entry id; else return UINT8_MAX
UINT16 PIACLEEP_wSearchEntry (UINT8 byGrpId)
{
    UINT8  byId, si;

    // Find where in EEPROM the current entry is
    for (si = 0; si < SWITCH_ACL_GRP_NUM; si++) {
        // Get current entry id and compare with the target one
        s_vGetEntryId(si, &byId);

        // If HIT => return current location
        if ((byId != 0) && (byId == byGrpId) )
            return si;
    }

    // If entry not exist, return UINT8_MAX
    return UINT8_MAX;
}


UINT8 PIACLEEP_byInsEntry (SACLGrpEepCfg *pSEntry)
{
    UINT8  byTblPtr, byId;

    // Check if entry already exist
    if (PIACLEEP_wSearchEntry(pSEntry->u8GrpId) != UINT8_MAX)
        return ACL_OP_GRP_EXIST;
    
    // Search where in eeprom to insert the entry
    for (byTblPtr = 0; byTblPtr < SWITCH_ACL_GRP_NUM; byTblPtr++) {
        s_vGetEntryId(byTblPtr, &byId);
        if (byId == 0)          //entry is empty
            break;
    }

    // Check if table full
    if (byTblPtr == SWITCH_ACL_GRP_NUM)
        return ACL_OP_NO_EMPTY_GRP;

    // Insert the target entry into EEPROM and update checksum
    PIEEP_vSetCfgIntoEep( (PUINT8)pSEntry, PIACLEEP_dwEntryEepAddr(byTblPtr), EEP_SIZE_ACL_TBL_ENTRY );
    NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
    
    return OP_OK;
}


void PIACLEEP_vDelEntry (UINT8 byTblPtr)
{
    UINT8  byBuf = 0;       //set the entry empty

    PIEEP_vSetCfgIntoEep( (PUINT8)&byBuf, PIACLEEP_dwEntryEepAddr(byTblPtr), SIZE_OF_ACL_GID);
    NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
}


void PIACLEEP_vEditEntry (UINT8 byTblPtr, SACLGrpEepCfg *pSEntry)
{       
    PIEEP_vSetCfgIntoEep( (PUINT8)pSEntry, PIACLEEP_dwEntryEepAddr(byTblPtr), EEP_SIZE_ACL_TBL_ENTRY );
    NVRAM_vUpdateChecksum(EEP_SIZE_DATA_AREA);
}


//Get ACL information
//param1     buffer for information from eeprom
//param2     weather read all ACL rule
//param3     if param2 is FALSE, only read ipv4 rule or non-ipv4 rule 
void PIACLEEP_vStatisTblInfo (SACLPageCfg *pSPageBuf,BOOL bIsAllType,BOOL bIsIpv4)
{
    UINT8  u8TblPtr, u8Gid, si;
    SACLGrpEepCfg SACLGrpEntry;
    // Prepare for table info statistics
    pSPageBuf->wValidEntryNum = 0;

    // Add group id into valid group list one by one
    for (u8TblPtr = 0; u8TblPtr < SWITCH_ACL_GRP_NUM; u8TblPtr++) {
        s_vGetEntryId(u8TblPtr, &u8Gid);
        
        if (u8Gid != 0) {
            PIACLEEP_vGetEntry(u8TblPtr,(PINT8)&SACLGrpEntry);    
            
            if (bIsAllType) 	   //read all ACL rules
                goto InsGrpId2List;

            else  if ((bIsIpv4&&SACLGrpEntry.bIsIpv4) || (!bIsIpv4 && !SACLGrpEntry.bIsIpv4))            // only read ipv4 group or only read non-ipv4 group
                goto InsGrpId2List;
            else            //next entry
                continue; 

         
InsGrpId2List :

            pSPageBuf->wValidEntryNum++;
  
            for (si = pSPageBuf->wValidEntryNum-1; si > 0; si--) {
                if (u8Gid < pSPageBuf->abyValidGrpIdList[si-1])
                    pSPageBuf->abyValidGrpIdList[si] = pSPageBuf->abyValidGrpIdList[si-1];
                else
                    break;
            }

            pSPageBuf->abyValidGrpIdList[si] = u8Gid;         
        }
        
    }
}

⌨️ 快捷键说明

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