Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

pcrm.h

Go to the documentation of this file.
00001 /*
00002 ** $Id$
00003 **
00004 ** pcrm.h
00005 **
00006 ** Copyright (C) 2002 Sourcefire,Inc
00007 ** Marc Norton <mnorton@sourcefire.com>
00008 ** Dan Roelker <droelker@sourcefire.com>
00009 **
00010 ** 
00011 **
00012 ** This program is free software; you can redistribute it and/or modify
00013 ** it under the terms of the GNU General Public License as published by
00014 ** the Free Software Foundation; either version 2 of the License, or
00015 ** (at your option) any later version.
00016 **
00017 ** This program is distributed in the hope that it will be useful,
00018 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 ** GNU General Public License for more details.
00021 **
00022 ** You should have received a copy of the GNU General Public License
00023 ** along with this program; if not, write to the Free Software
00024 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00025 **
00026 ** Packet Classification-Rule Manager
00027 **
00028 */
00029 #ifndef _PCRM_H
00030 #define _PCRM_H
00031 
00032 #include "bitop.h"
00033 
00034 typedef void * RULE_PTR;
00035 
00036 #define MAX_PORTS 64*1024
00037 #define ANYPORT   -1
00038 
00039 
00040 /*
00041 ** Macros to walk a RULE_NODE list, and get the
00042 ** RULE_PTR from a RULE_NODE, these eliminate 
00043 ** subroutine calls, in high performance needs.
00044 */
00045 #define PRM_GET_FIRST_GROUP_NODE(pg) (pg->pgHead)
00046 #define PRM_GET_NEXT_GROUP_NODE(rn)  (rn->rnNext)
00047 
00048 #define PRM_GETRULE_FROM_NODE(rn)     (rn->rnRuleData)
00049 
00050 #define PRM_GET_FIRST_GROUP_NODE_NC(pg) (pg->pgHeadNC)
00051 #define PRM_GET_NEXT_GROUP_NODE_NC(rn)  (rn->rnNext)
00052 
00053 typedef struct _not_rule_node_ {
00054 
00055   struct _not_rule_node_ * next;
00056   
00057   int iPos; /* RULE_NODE->iRuleNodeID */
00058   
00059   
00060 } NOT_RULE_NODE;
00061 
00062 
00063 typedef struct _rule_node_ {
00064 
00065   struct  _rule_node_ * rnNext;
00066  
00067   RULE_PTR rnRuleData; 
00068 
00069   int iRuleNodeID;
00070  
00071 }RULE_NODE;
00072 
00073 
00074 typedef struct {
00075   
00076   /* Content List */
00077   RULE_NODE *pgHead, *pgTail, *pgCur;
00078   int   pgContentCount;
00079  
00080   /* No-Content List */
00081   RULE_NODE *pgHeadNC, *pgTailNC, *pgCurNC;
00082   int   pgNoContentCount;
00083 
00084   /*  Uri-Content List */
00085   RULE_NODE *pgUriHead, *pgUriTail, *pgUriCur;
00086   int   pgUriContentCount;
00087  
00088   /* Setwise Pattern Matching data structures */
00089   void * pgPatData;
00090   void * pgPatDataUri;
00091   
00092   int avgLen;  
00093   int minLen;
00094   int maxLen;
00095   int c1,c2,c3,c4,c5;
00096 
00097   /*
00098   **  Bit operation for validating matches
00099   */
00100   BITOP boRuleNodeID;
00101   
00102   /*
00103   *   Not rule list for this group
00104   */
00105   NOT_RULE_NODE *pgNotRuleList;
00106 
00107   /*
00108   **  Count of rule_node's in this group/list 
00109   */
00110   int pgCount;
00111 
00112   int pgNQEvents;
00113   int pgQEvents;
00114  
00115 }PORT_GROUP;
00116 
00117 
00118 
00119 typedef struct {
00120 
00121   int        prmNumDstRules;
00122   int        prmNumSrcRules;
00123   int        prmNumGenericRules;
00124   
00125   int        prmNumDstGroups;
00126   int        prmNumSrcGroups;
00127 
00128   PORT_GROUP *prmSrcPort[MAX_PORTS];
00129   PORT_GROUP *prmDstPort[MAX_PORTS];
00130   /* char       prmConflicts[MAX_PORTS]; */
00131   PORT_GROUP *prmGeneric;
00132 
00133 } PORT_RULE_MAP ;
00134 
00135 
00136 typedef struct {
00137 
00138   int        prmNumRules;
00139   int        prmNumGenericRules;
00140   
00141   int        prmNumGroups;
00142 
00143   PORT_GROUP prmByteGroup[256];
00144   PORT_GROUP prmGeneric;
00145 
00146 } BYTE_RULE_MAP ;
00147 
00148 
00149 PORT_RULE_MAP * prmNewMap( );
00150 BYTE_RULE_MAP * prmNewByteMap( );
00151 
00152 void prmFreeMap( PORT_RULE_MAP * p );
00153 void prmFreeByteMap( BYTE_RULE_MAP * p );
00154 
00155 int prmAddRule( PORT_RULE_MAP * p, int dport, int sport, RULE_PTR rd );
00156 int prmAddByteRule( BYTE_RULE_MAP * p, int dport, RULE_PTR rd );
00157 
00158 int prmAddRuleUri( PORT_RULE_MAP * p, int dport, int sport, RULE_PTR rd );
00159 int prmAddRuleNC( PORT_RULE_MAP * p, int dport, int sport, RULE_PTR rd );
00160 int prmAddByteRuleNC( BYTE_RULE_MAP * p, int dport, RULE_PTR rd );
00161 
00162 void prmAddNotNode( PORT_GROUP * pg, int id );
00163 
00164 int prmCompileGroups( PORT_RULE_MAP * p );
00165 int prmCompileByteGroups( BYTE_RULE_MAP * p );
00166 
00167 int prmShowStats( PORT_RULE_MAP * p );
00168 int prmShowByteStats( BYTE_RULE_MAP * p );
00169 
00170 int prmShowEventStats( PORT_RULE_MAP * p );
00171 int prmShowEventByteStats( BYTE_RULE_MAP * p );
00172 
00173 RULE_PTR prmGetFirstRule( PORT_GROUP * pg );
00174 RULE_PTR prmGetNextRule( PORT_GROUP * pg );
00175 
00176 RULE_PTR prmGetFirstRuleUri( PORT_GROUP * pg );
00177 RULE_PTR prmGetNextRuleUri( PORT_GROUP * pg );
00178 
00179 RULE_PTR prmGetFirstRuleNC( PORT_GROUP * pg );
00180 RULE_PTR prmGetNextRuleNC( PORT_GROUP * pg );
00181 
00182 
00183 int prmFindRuleGroup( PORT_RULE_MAP * p, int dport, int sport, PORT_GROUP ** src, PORT_GROUP **dst , PORT_GROUP ** gen);
00184 int prmFindByteRuleGroup( BYTE_RULE_MAP * p, int dport, PORT_GROUP **dst , PORT_GROUP ** gen);
00185 
00186 PORT_GROUP * prmFindDstRuleGroup( PORT_RULE_MAP * p, int port );
00187 PORT_GROUP * prmFindSrcRuleGroup( PORT_RULE_MAP * p, int port );
00188 
00189 PORT_GROUP * prmFindByteRuleGroupUnique( BYTE_RULE_MAP * p, int port );
00190 
00191 int      prmSetGroupPatData( PORT_GROUP * pg, void * data );
00192 void *   prmGetGroupPatData( PORT_GROUP * pg );
00193 
00194 
00195 #endif

Generated on Sun May 14 14:51:14 2006 by  doxygen 1.4.2