www.pudn.com > Firewall_PNE_3_3.zip > fwMacFilter.h, change:2009-03-16,size:5162b


/* fwMacFilter.h - MAC Filtering routines */

/* Copyright 2004 Wind River Systems, Inc. */

/*
modification history
--------------------
01d,13jul04,myz  port to dual stack
01c,20feb04,myz  added binding semaphore
01b,30jan04,myz  public typedef changes and removed all MAC API prototypes 
01a,15dec03,myz  written
*/

#ifndef __INCfwMacFilterh
#define __INCfwMacFilterh

#ifdef __cplusplus
extern "C" {
#endif

#include "fw.h"

/* local constants */

#define FW_MAC_SRC_NOT_USED   0
#define FW_MAC_SRC_USED       1 
#define FW_MAC_SRC_OP_MASK    0xff
#define FW_MAC_DST_OP_MASK    0xff00  
#define FW_MAC_DST_NOT_USED   0
#define FW_MAC_DST_USED       0x100

/* this should be defined in netBufLib.h */

#ifndef M_L2HDR
#define M_L2HDR 0x80
#endif

#define CACHE_ASSOCIATIVE_POWER   2  /* 0,1,2 ... */
#define CACHE_ASSOCIATIVE_SIZE    (1 << CACHE_ASSOCIATIVE_POWER)
#define CACHE_A_MASK              (CACHE_ASSOCIATIVE_SIZE - 1)
#define CACHE_SET_SIZE            16  /* must be power of 2 */
#define ADDR_LOOKUP_CACHE_SIZE  (CACHE_SET_SIZE * CACHE_ASSOCIATIVE_SIZE)
#define ADDR_CACHE_SIZE_MASK    (ADDR_LOOKUP_CACHE_SIZE - 1)
#define ADDR_BACKUP_TABLE_SIZE    64

#define DEFAULT_INTERFACE_NUM     10
#define DEFAULT_RULE_ENTRY_NUM    20

#define ETHER_ADDRS_LEN 12

#define PACKET_FROM_END_DRIVER    0x00000
#define PACKET_FROM_NPT_DRIVER    0x10000

#define MAC_ADDR_CONVERT(pAddr,f4,l2) \
    if (ALIGNED((pAddr),4)) \
        { \
        (f4) = *(UINT32 *)(pAddr); \
        (l2)  = *(UINT16 *)((UINT32 *)(pAddr) + 1); \
        } \
    else if (ALIGNED((pAddr),2)) \
        { \
        *(UINT16 *)(&f4) = *(UINT16 *)(pAddr); \
        *((UINT16 *)(&f4) + 1) = *((UINT16 *)(pAddr) + 1); \
        (l2)  = *((UINT16 *)(pAddr) + 2); \
        } \
    else \
        { \
        *(UINT8 *)(&f4) = (pAddr)[0]; \
        *((UINT8 *)(&f4) + 1) = (pAddr)[1]; \
        *((UINT8 *)(&f4) + 2) = (pAddr)[2]; \
        *((UINT8 *)(&f4) + 3) = (pAddr)[3]; \
        *(UINT8 *)(&l2)  = (pAddr)[4]; \
        *((UINT8 *)(&l2) + 1) = (pAddr)[5]; \
        }

#define MAC_DST_ADDR_MATCH(pRule,f4,l2) \
        ( (((f4) & (pRule)->uDstMaskAddrF4) == \
	   ((pRule)->uDstMaskAddrF4 & (pRule)->uDstAddrF4)) && \
          (((l2) & (pRule)->uDstMaskAddrL2) == \
	   ((pRule)->uDstMaskAddrL2 & (pRule)->uDstAddrL2)) )

#define MAC_SRC_ADDR_MATCH(pRule,f4,l2) \
        ( (((f4) & (pRule)->uSrcMaskAddrF4) == \
	   ((pRule)->uSrcMaskAddrF4 & (pRule)->uSrcAddrF4)) && \
          (((l2) & (pRule)->uSrcMaskAddrL2) == \
	   ((pRule)->uSrcMaskAddrL2 & (pRule)->uSrcAddrL2)) )


/* typedefs */

typedef struct {
    FW_MAC_ADDR_TYPE mac;
    UINT8   inUse:  4,       /* entry use flag, TRUE or FALSE */
	    action: 4;       /* deny or permit */
    UINT8   setInx;          /* the last refrenced index within a cache
			      * associative set */
    } MAC_ADDR_ENTRY;    
 
typedef struct  
    {
    FW_MAC_USER_RULE usrSpec; /* user rule specification */    
    FW_MAC_EXT_FUNCPTR pPostFunc;  /* the post processing function */
    void * funcArg;
    UINT32  entryId;
    UINT16 addrOp;           /* the src/dst addresses operation type */
    } FILTER_RULE_ENTRY;


#define macf4            mac.addrInternal.first4
#define macl2            mac.addrInternal.last2
#define srcAddrF4        src.addrInternal.first4
#define srcAddrL2        src.addrInternal.last2
#define srcMaskAddrF4    srcMask.addrInternal.first4
#define srcMaskAddrL2    srcMask.addrInternal.last2
#define dstAddrF4        dst.addrInternal.first4
#define dstAddrL2        dst.addrInternal.last2
#define dstMaskAddrF4    dstMask.addrInternal.first4
#define dstMaskAddrL2    dstMask.addrInternal.last2
#define srcAddr          src.addr
#define dstAddr          dst.addr
#define sMask            srcMask.addr
#define dMask            dstMask.addr
#define uSrcAddrF4       usrSpec.srcAddrF4
#define uSrcAddrL2       usrSpec.srcAddrL2
#define uSrcMaskAddrF4   usrSpec.srcMaskAddrF4
#define uSrcMaskAddrL2   usrSpec.srcMaskAddrL2
#define uDstAddrF4       usrSpec.dstAddrF4
#define uDstAddrL2       usrSpec.dstAddrL2
#define uDstMaskAddrF4   usrSpec.dstMaskAddrF4
#define uDstMaskAddrL2   usrSpec.dstMaskAddrL2
#define uSrcAddr         usrSpec.srcAddr
#define uDstAddr         usrSpec.dstAddr
#define uSMask           usrSpec.sMask
#define uDMask           usrSpec.dMask

typedef struct {
    UINT32 type;    /* receiving or transmitting filter type */
    struct filterBindStruct * pBind;
    int bindCnt;
    MAC_ADDR_ENTRY  * pCacheTbl;
    MAC_ADDR_ENTRY  * pBackupList;
    int backupMax;
    int backupCnt;
    FILTER_RULE_ENTRY * pRuleList;
    int ruleListCnt;
    int ruleListMax;
    UINT32 dftActions;
    FW_MAC_EXT_FUNCPTR pDftPostFunc;
    void * funcArg;
    RULE_FILTER_STAT_DESC * pFwStats; 
    SEM_ID bindSem;
    } FW_MAC_FILTER_DESC;

typedef struct filterBindStruct {
    BOOL used;
    char ifName[END_NAME_MAX];    /* interface name */
    int  ifUnit;                  /* interface unit number */
    void *cookie;                 /* muxBind return cookie */
    FW_MAC_FILTER_DESC * pDesc;   /* RX or TX filter descriptor */
    } FILTER_BIND;


#ifdef __cplusplus
}
#endif

#endif