Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

RuleMatcher.h File Reference

#include <limits.h>
#include "BroString.h"
#include "List.h"
#include "RE.h"
#include "Net.h"
#include "Sessions.h"
#include "IntSet.h"
#include "util.h"
#include "Rule.h"
#include "RuleAction.h"
#include "RuleCondition.h"

Include dependency graph for RuleMatcher.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Classes

struct  MaskedValue
struct  Range
class  RuleEndpointState
struct  RuleEndpointState::Matcher
class  RuleHdrTest
struct  RuleHdrTest::PatternSet
class  RuleMatcher
struct  RuleMatcher::Stats

Functions

void rules_error (const char *msg)
void rules_error (const char *msg, const char *addl)
void rules_error (Rule *id, const char *msg)
int rules_lex (void)
int rules_parse (void)
int rules_wrap (void)
 declare (PList, MaskedValue)
typedef PList (MaskedValue) maskedvalue_list
typedef PList (char) string_list
 declare (PList, BroString)
typedef PList (BroString) bstr_list
void id_to_maskedvallist (const char *id, maskedvalue_list *append_to)
char * id_to_str (const char *id)
uint32 id_to_uint (const char *id)
 declare (PList, RuleHdrTest)
typedef PList (RuleHdrTest) rule_hdr_test_list

Variables

int rule_bench
FILE * rules_in
int rules_line_number
const char * current_rule_file
RuleMatcherrule_matcher


Function Documentation

declare PList  ,
RuleHdrTest 
 

declare PList  ,
BroString 
 

declare PList  ,
MaskedValue 
 

void id_to_maskedvallist const char *  id,
maskedvalue_list *  append_to
 

Definition at line 1069 of file RuleMatcher.cc.

References get_bro_val(), id, loop_over_list, BroType::Tag(), Val::Type(), TYPE_TABLE, and val_to_maskedval().

Referenced by rules_parse().

01070         {
01071         Val* v = get_bro_val(id);
01072         if ( ! v )
01073                 return;
01074 
01075         if ( v->Type()->Tag() == TYPE_TABLE )
01076                 {
01077                 val_list* vals = v->AsTableVal()->ConvertToPureList()->Vals();
01078                 loop_over_list(*vals, i )
01079                         if ( ! val_to_maskedval((*vals)[i], append_to) )
01080                                 return;
01081                 }
01082 
01083         else
01084                 val_to_maskedval(v, append_to);
01085         }

char* id_to_str const char *  id  ) 
 

Definition at line 1087 of file RuleMatcher.cc.

References BroString::Bytes(), copy_string(), error(), get_bro_val(), id, BroString::Len(), rules_error(), BroType::Tag(), Val::Type(), and TYPE_STRING.

Referenced by rules_parse().

01088         {
01089         const BroString* src;
01090         char* dst;
01091 
01092         Val* v = get_bro_val(id);
01093         if ( ! v )
01094                 goto error;
01095 
01096         if ( v->Type()->Tag() != TYPE_STRING )
01097                 {
01098                 rules_error("Identifier must refer to string");
01099                 goto error;
01100                 }
01101 
01102         src = v->AsString();
01103         dst = new char[src->Len()+1];
01104         memcpy(dst, src->Bytes(), src->Len());
01105         *(dst+src->Len()) = '\0';
01106         return dst;
01107 
01108 error:
01109         char* dummy = copy_string("<error>");
01110         return dummy;
01111         }

uint32 id_to_uint const char *  id  ) 
 

Definition at line 1113 of file RuleMatcher.cc.

References Val::CoerceToUnsigned(), get_bro_val(), id, rules_error(), BroType::Tag(), Val::Type(), TYPE_BOOL, TYPE_COUNT, TYPE_ENUM, TYPE_INT, TYPE_PORT, TypeTag, and uint32.

Referenced by rules_parse().

01114         {
01115         Val* v = get_bro_val(id);
01116         if ( ! v )
01117                 return 0;
01118 
01119         TypeTag t = v->Type()->Tag();
01120 
01121         if ( t == TYPE_BOOL || t == TYPE_COUNT || t == TYPE_ENUM ||
01122              t == TYPE_INT || t == TYPE_PORT )
01123                 return v->CoerceToUnsigned();
01124 
01125         rules_error("Identifier must refer to integer");
01126         return 0;
01127         }

typedef PList RuleHdrTest   ) 
 

typedef PList BroString   ) 
 

typedef PList char   ) 
 

typedef PList MaskedValue   ) 
 

void rules_error Rule id,
const char *  msg
 

Definition at line 1672 of file rule-parse.cc.

References Location::filename, Location::first_line, Rule::GetLocation(), Rule::ID(), rule_matcher, and RuleMatcher::SetParseError().

Referenced by RuleMatcher::AddRule(), get_bro_val(), id_to_str(), id_to_uint(), RuleMatcher::InsertRuleIntoTree(), RuleConditionEval::RuleConditionEval(), rules_parse(), and val_to_maskedval().

01673         {
01674         const Location& l = r->GetLocation();
01675         fprintf(stderr, "Error in signature %s (%s:%d): %s\n",
01676                         r->ID(), l.filename, l.first_line, msg);
01677         rule_matcher->SetParseError();
01678         }

void rules_error const char *  msg,
const char *  addl
 

Definition at line 1665 of file rule-parse.cc.

References current_rule_file, rule_matcher, rules_line_number, and RuleMatcher::SetParseError().

01666         {
01667         fprintf(stderr, "Error in signature (%s:%d): %s (%s)\n",
01668                         current_rule_file, rules_line_number+1, msg, addl);
01669         rule_matcher->SetParseError();
01670         }

void rules_error const char *  msg  ) 
 

Definition at line 1658 of file rule-parse.cc.

References current_rule_file, rule_matcher, rules_line_number, and RuleMatcher::SetParseError().

01659         {
01660         fprintf(stderr, "Error in signature (%s:%d): %s\n",
01661                         current_rule_file, rules_line_number+1, msg);
01662         rule_matcher->SetParseError();
01663         }

int rules_lex void   ) 
 

int rules_parse void   ) 
 

Definition at line 874 of file rule-parse.cc.

References Rule::AddAction(), Rule::AddCondition(), Rule::AddHdrTest(), Rule::AddPattern(), Rule::AddRequires(), RuleMatcher::AddRule(), current_rule, current_rule_file, YYSTYPE::hdr_test, id_to_maskedvallist(), id_to_str(), id_to_uint(), Range::len, MaskedValue::mask, YYSTYPE::mval, Range::offset, YYSTYPE::range, YYSTYPE::rule, rule_matcher, rules_char, rules_check, rules_defact, rules_defgoto, rules_error(), rules_line_number, rules_lval, rules_nerrs, rules_pact, rules_pgoto, rules_r1, rules_r2, rules_stos, rules_table, rules_tname, rules_type, Rule::SetActiveStatus(), YYSTYPE::str, YYSTYPE::val, MaskedValue::val, val, YYSTYPE::vallist, warn(), YY_REDUCE_PRINT, YY_STACK_PRINT, YYABORT, YYACCEPT, YYDPRINTF, YYDSYMPRINTF, YYEMPTY, YYEOF, YYFINAL, YYINITDEPTH, YYLAST, YYLEX, YYMAXDEPTH, YYNTOKENS, YYPACT_NINF, YYPOPSTACK, YYSIZE_T, YYSTACK_ALLOC, YYSTACK_BYTES, YYSTACK_FREE, YYSTACK_RELOCATE, YYTABLE_NINF, YYTERROR, and YYTRANSLATE.

Referenced by RuleMatcher::ReadFiles().

00878 {
00879   
00880   register int rules_state;
00881   register int rules_n;
00882   int rules_result;
00883   /* Number of tokens to shift before error messages enabled.  */
00884   int rules_errstatus;
00885   /* Lookahead token as an internal (translated) token number.  */
00886   int rules_token = 0;
00887 
00888   /* Three stacks and their tools:
00889      `rules_ss': related to states,
00890      `rules_vs': related to semantic values,
00891      `rules_ls': related to locations.
00892 
00893      Refer to the stacks thru separate pointers, to allow rules_overflow
00894      to reallocate them elsewhere.  */
00895 
00896   /* The state stack.  */
00897   short rules_ssa[YYINITDEPTH];
00898   short *rules_ss = rules_ssa;
00899   register short *rules_ssp;
00900 
00901   /* The semantic value stack.  */
00902   YYSTYPE rules_vsa[YYINITDEPTH];
00903   YYSTYPE *rules_vs = rules_vsa;
00904   register YYSTYPE *rules_vsp;
00905 
00906 
00907 
00908 #define YYPOPSTACK   (rules_vsp--, rules_ssp--)
00909 
00910   YYSIZE_T rules_stacksize = YYINITDEPTH;
00911 
00912   /* The variables used to return semantic value and location from the
00913      action routines.  */
00914   YYSTYPE rules_val;
00915 
00916 
00917   /* When reducing, the number of symbols on the RHS of the reduced
00918      rule.  */
00919   int rules_len;
00920 
00921   YYDPRINTF ((stderr, "Starting parse\n"));
00922 
00923   rules_state = 0;
00924   rules_errstatus = 0;
00925   rules_nerrs = 0;
00926   rules_char = YYEMPTY;         /* Cause a token to be read.  */
00927 
00928   /* Initialize stack pointers.
00929      Waste one element of value and location stack
00930      so that they stay on the same level as the state stack.
00931      The wasted elements are never initialized.  */
00932 
00933   rules_ssp = rules_ss;
00934   rules_vsp = rules_vs;
00935 
00936   goto rules_setstate;
00937 
00938 /*------------------------------------------------------------.
00939 | rules_newstate -- Push a new state, which is found in rules_state.  |
00940 `------------------------------------------------------------*/
00941  rules_newstate:
00942   /* In all cases, when you get here, the value and location stacks
00943      have just been pushed. so pushing a state here evens the stacks.
00944      */
00945   rules_ssp++;
00946 
00947  rules_setstate:
00948   *rules_ssp = rules_state;
00949 
00950   if (rules_ss + rules_stacksize - 1 <= rules_ssp)
00951     {
00952       /* Get the current used size of the three stacks, in elements.  */
00953       YYSIZE_T rules_size = rules_ssp - rules_ss + 1;
00954 
00955 #ifdef rules_overflow
00956       {
00957         /* Give user a chance to reallocate the stack. Use copies of
00958            these so that the &'s don't force the real ones into
00959            memory.  */
00960         YYSTYPE *rules_vs1 = rules_vs;
00961         short *rules_ss1 = rules_ss;
00962 
00963 
00964         /* Each stack pointer address is followed by the size of the
00965            data in use in that stack, in bytes.  This used to be a
00966            conditional around just the two extra args, but that might
00967            be undefined if rules_overflow is a macro.  */
00968         rules_overflow ("parser stack overflow",
00969                     &rules_ss1, rules_size * sizeof (*rules_ssp),
00970                     &rules_vs1, rules_size * sizeof (*rules_vsp),
00971 
00972                     &rules_stacksize);
00973 
00974         rules_ss = rules_ss1;
00975         rules_vs = rules_vs1;
00976       }
00977 #else /* no rules_overflow */
00978 # ifndef YYSTACK_RELOCATE
00979       goto rules_overflowlab;
00980 # else
00981       /* Extend the stack our own way.  */
00982       if (YYMAXDEPTH <= rules_stacksize)
00983         goto rules_overflowlab;
00984       rules_stacksize *= 2;
00985       if (YYMAXDEPTH < rules_stacksize)
00986         rules_stacksize = YYMAXDEPTH;
00987 
00988       {
00989         short *rules_ss1 = rules_ss;
00990         union rules_alloc *rules_ptr =
00991           (union rules_alloc *) YYSTACK_ALLOC (YYSTACK_BYTES (rules_stacksize));
00992         if (! rules_ptr)
00993           goto rules_overflowlab;
00994         YYSTACK_RELOCATE (rules_ss);
00995         YYSTACK_RELOCATE (rules_vs);
00996 
00997 #  undef YYSTACK_RELOCATE
00998         if (rules_ss1 != rules_ssa)
00999           YYSTACK_FREE (rules_ss1);
01000       }
01001 # endif
01002 #endif /* no rules_overflow */
01003 
01004       rules_ssp = rules_ss + rules_size - 1;
01005       rules_vsp = rules_vs + rules_size - 1;
01006 
01007 
01008       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
01009                   (unsigned long int) rules_stacksize));
01010 
01011       if (rules_ss + rules_stacksize - 1 <= rules_ssp)
01012         YYABORT;
01013     }
01014 
01015   YYDPRINTF ((stderr, "Entering state %d\n", rules_state));
01016 
01017   goto rules_backup;
01018 
01019 /*-----------.
01020 | rules_backup.  |
01021 `-----------*/
01022 rules_backup:
01023 
01024 /* Do appropriate processing given the current state.  */
01025 /* Read a lookahead token if we need one and don't already have one.  */
01026 /* rules_resume: */
01027 
01028   /* First try to decide what to do without reference to lookahead token.  */
01029 
01030   rules_n = rules_pact[rules_state];
01031   if (rules_n == YYPACT_NINF)
01032     goto rules_default;
01033 
01034   /* Not known => get a lookahead token if don't already have one.  */
01035 
01036   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
01037   if (rules_char == YYEMPTY)
01038     {
01039       YYDPRINTF ((stderr, "Reading a token: "));
01040       rules_char = YYLEX;
01041     }
01042 
01043   if (rules_char <= YYEOF)
01044     {
01045       rules_char = rules_token = YYEOF;
01046       YYDPRINTF ((stderr, "Now at end of input.\n"));
01047     }
01048   else
01049     {
01050       rules_token = YYTRANSLATE (rules_char);
01051       YYDSYMPRINTF ("Next token is", rules_token, &rules_lval, &rules_lloc);
01052     }
01053 
01054   /* If the proper action on seeing token YYTOKEN is to reduce or to
01055      detect an error, take that action.  */
01056   rules_n += rules_token;
01057   if (rules_n < 0 || YYLAST < rules_n || rules_check[rules_n] != rules_token)
01058     goto rules_default;
01059   rules_n = rules_table[rules_n];
01060   if (rules_n <= 0)
01061     {
01062       if (rules_n == 0 || rules_n == YYTABLE_NINF)
01063         goto rules_errlab;
01064       rules_n = -rules_n;
01065       goto rules_reduce;
01066     }
01067 
01068   if (rules_n == YYFINAL)
01069     YYACCEPT;
01070 
01071   /* Shift the lookahead token.  */
01072   YYDPRINTF ((stderr, "Shifting token %s, ", rules_tname[rules_token]));
01073 
01074   /* Discard the token being shifted unless it is eof.  */
01075   if (rules_char != YYEOF)
01076     rules_char = YYEMPTY;
01077 
01078   *++rules_vsp = rules_lval;
01079 
01080 
01081   /* Count tokens shifted since error; after three, turn off error
01082      status.  */
01083   if (rules_errstatus)
01084     rules_errstatus--;
01085 
01086   rules_state = rules_n;
01087   goto rules_newstate;
01088 
01089 
01090 /*-----------------------------------------------------------.
01091 | rules_default -- do the default action for the current state.  |
01092 `-----------------------------------------------------------*/
01093 rules_default:
01094   rules_n = rules_defact[rules_state];
01095   if (rules_n == 0)
01096     goto rules_errlab;
01097   goto rules_reduce;
01098 
01099 
01100 /*-----------------------------.
01101 | rules_reduce -- Do a reduction.  |
01102 `-----------------------------*/
01103 rules_reduce:
01104   /* rules_n is the number of a rule to reduce with.  */
01105   rules_len = rules_r2[rules_n];
01106 
01107   /* If YYLEN is nonzero, implement the default value of the action:
01108      `$$ = $1'.
01109 
01110      Otherwise, the following line sets YYVAL to garbage.
01111      This behavior is undocumented and Bison
01112      users should not rely upon it.  Assigning to YYVAL
01113      unconditionally makes the parser a bit smaller, and it avoids a
01114      GCC warning that YYVAL may be used uninitialized.  */
01115   rules_val = rules_vsp[1-rules_len];
01116 
01117 
01118   YY_REDUCE_PRINT (rules_n);
01119   switch (rules_n)
01120     {
01121         case 2:
01122 #line 69 "rule-parse.y"
01123     { rule_matcher->AddRule(rules_vsp[0].rule); }
01124     break;
01125 
01126   case 4:
01127 #line 75 "rule-parse.y"
01128     {
01129                         Location l(current_rule_file, rules_line_number+1, 0, 0, 0);
01130                         current_rule = new Rule(rules_lval.str, l);
01131                         }
01132     break;
01133 
01134   case 5:
01135 #line 80 "rule-parse.y"
01136     { rules_val.rule = current_rule; }
01137     break;
01138 
01139   case 8:
01140 #line 90 "rule-parse.y"
01141     {
01142                         current_rule->AddHdrTest(new RuleHdrTest(
01143                                 RuleHdrTest::IP, 16, 4,
01144                                 (RuleHdrTest::Comp) rules_vsp[-1].val, rules_vsp[0].vallist));
01145                         }
01146     break;
01147 
01148   case 9:
01149 #line 97 "rule-parse.y"
01150     { // Works for both TCP and UDP
01151                         current_rule->AddHdrTest(new RuleHdrTest(
01152                                 RuleHdrTest::TCP, 2, 2,
01153                                 (RuleHdrTest::Comp) rules_vsp[-1].val, rules_vsp[0].vallist));
01154                         }
01155     break;
01156 
01157   case 10:
01158 #line 104 "rule-parse.y"
01159     {
01160                         current_rule->AddCondition(new RuleConditionEval(rules_vsp[0].str));
01161                         }
01162     break;
01163 
01164   case 11:
01165 #line 109 "rule-parse.y"
01166     { current_rule->AddHdrTest(rules_vsp[0].hdr_test); }
01167     break;
01168 
01169   case 12:
01170 #line 112 "rule-parse.y"
01171     {
01172                         current_rule->AddCondition(
01173                                 new RuleConditionIPOptions(rules_vsp[0].val));
01174                         }
01175     break;
01176 
01177   case 13:
01178 #line 118 "rule-parse.y"
01179     {
01180                         int proto = 0;
01181                         switch ( rules_vsp[0].prot ) {
01182                         case RuleHdrTest::ICMP: proto = 1; break;
01183                         case RuleHdrTest::IP: proto = 0; break;
01184                         case RuleHdrTest::TCP: proto = 6; break;
01185                         case RuleHdrTest::UDP: proto = 17; break;
01186                         default:
01187                                 rules_error("internal_error: unknown protocol");
01188                         }
01189 
01190                         if ( proto )
01191                                 {
01192                                 maskedvalue_list* vallist = new maskedvalue_list;
01193                                 MaskedValue* val = new MaskedValue();
01194 
01195                                 val->val = proto;
01196                                 val->mask = 0xffffffff;
01197                                 vallist->append(val);
01198 
01199                                 current_rule->AddHdrTest(new RuleHdrTest(
01200                                         RuleHdrTest::IP, 9, 1,
01201                                         (RuleHdrTest::Comp) rules_vsp[-1].val, vallist));
01202                                 }
01203                         }
01204     break;
01205 
01206   case 14:
01207 #line 145 "rule-parse.y"
01208     {
01209                         current_rule->AddHdrTest(new RuleHdrTest(
01210                                 RuleHdrTest::IP, 9, 1,
01211                                 (RuleHdrTest::Comp) rules_vsp[-1].val, rules_vsp[0].vallist));
01212                         }
01213     break;
01214 
01215   case 15:
01216 #line 152 "rule-parse.y"
01217     { current_rule->AddAction(new RuleActionEvent( rules_vsp[0].str )); }
01218     break;
01219 
01220   case 16:
01221 #line 155 "rule-parse.y"
01222     { current_rule->AddPattern(rules_vsp[0].str, rules_vsp[-1].ptype); }
01223     break;
01224 
01225   case 17:
01226 #line 158 "rule-parse.y"
01227     {
01228                         if ( rules_vsp[-2].range.offset > 0 )
01229                                 warn("Offsets are currently ignored for patterns");
01230                         current_rule->AddPattern(rules_vsp[0].str, rules_vsp[-4].ptype, 0, rules_vsp[-2].range.len);
01231                         }
01232     break;
01233 
01234   case 18:
01235 #line 165 "rule-parse.y"
01236     {
01237                         current_rule->AddCondition(
01238                                 new RuleConditionPayloadSize(rules_vsp[0].val, (RuleConditionPayloadSize::Comp) (rules_vsp[-1].val)));
01239                         }
01240     break;
01241 
01242   case 19:
01243 #line 171 "rule-parse.y"
01244     { current_rule->AddRequires(rules_vsp[0].str, 0, 0); }
01245     break;
01246 
01247   case 20:
01248 #line 174 "rule-parse.y"
01249     { current_rule->AddRequires(rules_vsp[0].str, 0, 1); }
01250     break;
01251 
01252   case 21:
01253 #line 177 "rule-parse.y"
01254     { current_rule->AddRequires(rules_vsp[0].str, 1, 0); }
01255     break;
01256 
01257   case 22:
01258 #line 180 "rule-parse.y"
01259     { current_rule->AddRequires(rules_vsp[0].str, 1, 1); }
01260     break;
01261 
01262   case 23:
01263 #line 183 "rule-parse.y"
01264     { current_rule->AddCondition(new RuleConditionSameIP()); }
01265     break;
01266 
01267   case 24:
01268 #line 186 "rule-parse.y"
01269     {
01270                         current_rule->AddHdrTest(new RuleHdrTest(
01271                                 RuleHdrTest::IP, 12, 4,
01272                                 (RuleHdrTest::Comp) rules_vsp[-1].val, rules_vsp[0].vallist));
01273                         }
01274     break;
01275 
01276   case 25:
01277 #line 193 "rule-parse.y"
01278     { // Works for both TCP and UDP
01279                         current_rule->AddHdrTest(new RuleHdrTest(
01280                                 RuleHdrTest::TCP, 0, 2,
01281                                 (RuleHdrTest::Comp) rules_vsp[-1].val, rules_vsp[0].vallist));
01282                         }
01283     break;
01284 
01285   case 26:
01286 #line 200 "rule-parse.y"
01287     {
01288                         current_rule->AddCondition(new RuleConditionTCPState(rules_vsp[0].val));
01289                         }
01290     break;
01291 
01292   case 27:
01293 #line 205 "rule-parse.y"
01294     { current_rule->SetActiveStatus(rules_vsp[0].bl); }
01295     break;
01296 
01297   case 28:
01298 #line 210 "rule-parse.y"
01299     {
01300                         maskedvalue_list* vallist = new maskedvalue_list;
01301                         MaskedValue* val = new MaskedValue();
01302 
01303                         val->val = rules_vsp[0].mval.val;
01304                         val->mask = rules_vsp[-2].val;
01305                         vallist->append(val);
01306 
01307                         rules_val.hdr_test = new RuleHdrTest(rules_vsp[-7].prot, rules_vsp[-5].range.offset, rules_vsp[-5].range.len,
01308                                         (RuleHdrTest::Comp) rules_vsp[-1].val, vallist);
01309                         }
01310     break;
01311 
01312   case 29:
01313 #line 223 "rule-parse.y"
01314     {
01315                         rules_val.hdr_test = new RuleHdrTest(rules_vsp[-5].prot, rules_vsp[-3].range.offset, rules_vsp[-3].range.len,
01316                                                 (RuleHdrTest::Comp) rules_vsp[-1].val, rules_vsp[0].vallist);
01317                         }
01318     break;
01319 
01320   case 30:
01321 #line 231 "rule-parse.y"
01322     { rules_vsp[-2].vallist->append(new MaskedValue(rules_vsp[0].mval)); rules_val.vallist = rules_vsp[-2].vallist; }
01323     break;
01324 
01325   case 31:
01326 #line 233 "rule-parse.y"
01327     { id_to_maskedvallist(rules_vsp[0].str, rules_vsp[-2].vallist); rules_val.vallist = rules_vsp[-2].vallist; }
01328     break;
01329 
01330   case 32:
01331 #line 235 "rule-parse.y"
01332     {
01333                         rules_val.vallist = new maskedvalue_list();
01334                         rules_val.vallist->append(new MaskedValue(rules_vsp[0].mval));
01335                         }
01336     break;
01337 
01338   case 33:
01339 #line 240 "rule-parse.y"
01340     {
01341                         rules_val.vallist = new maskedvalue_list();
01342                         id_to_maskedvallist(rules_vsp[0].str, rules_val.vallist);
01343                         }
01344     break;
01345 
01346   case 34:
01347 #line 248 "rule-parse.y"
01348     { rules_val.mval.val = rules_vsp[0].val; rules_val.mval.mask = 0xffffffff; }
01349     break;
01350 
01351   case 36:
01352 #line 254 "rule-parse.y"
01353     { rules_val.range = rules_vsp[0].range; }
01354     break;
01355 
01356   case 37:
01357 #line 256 "rule-parse.y"
01358     { rules_val.range.offset = 0; rules_val.range.len = rules_vsp[0].val; }
01359     break;
01360 
01361   case 38:
01362 #line 258 "rule-parse.y"
01363     { rules_val.range.offset = rules_vsp[-1].val; rules_val.range.len = UINT_MAX; }
01364     break;
01365 
01366   case 39:
01367 #line 263 "rule-parse.y"
01368     { rules_val.range.offset = rules_vsp[0].val; rules_val.range.len = 1; }
01369     break;
01370 
01371   case 40:
01372 #line 265 "rule-parse.y"
01373     { rules_val.range.offset = rules_vsp[-2].val; rules_val.range.len = rules_vsp[0].val; }
01374     break;
01375 
01376   case 41:
01377 #line 270 "rule-parse.y"
01378     { rules_val.val = rules_vsp[-2].val | rules_vsp[0].val; }
01379     break;
01380 
01381   case 42:
01382 #line 272 "rule-parse.y"
01383     { rules_val.val = rules_vsp[0].val; }
01384     break;
01385 
01386   case 43:
01387 #line 277 "rule-parse.y"
01388     { rules_val.val = rules_vsp[-2].val | rules_vsp[0].val; }
01389     break;
01390 
01391   case 44:
01392 #line 279 "rule-parse.y"
01393     { rules_val.val = rules_vsp[0].val; }
01394     break;
01395 
01396   case 45:
01397 #line 284 "rule-parse.y"
01398     { rules_val.val = rules_vsp[0].val; }
01399     break;
01400 
01401   case 46:
01402 #line 286 "rule-parse.y"
01403     { rules_val.val = id_to_uint(rules_vsp[0].str); }
01404     break;
01405 
01406   case 47:
01407 #line 291 "rule-parse.y"
01408     { rules_val.str = rules_vsp[0].str; }
01409     break;
01410 
01411   case 48:
01412 #line 293 "rule-parse.y"
01413     { rules_val.str = id_to_str(rules_vsp[0].str); }
01414     break;
01415 
01416   case 49:
01417 #line 298 "rule-parse.y"
01418     { rules_val.str = rules_vsp[0].str; }
01419     break;
01420 
01421   case 50:
01422 #line 300 "rule-parse.y"
01423     { rules_val.str = id_to_str(rules_vsp[0].str); }
01424     break;
01425 
01426 
01427     }
01428 
01429 /* Line 993 of yacc.c.  */
01430 #line 1431 "y.tab.c"
01431 
01432   rules_vsp -= rules_len;
01433   rules_ssp -= rules_len;
01434 
01435 
01436   YY_STACK_PRINT (rules_ss, rules_ssp);
01437 
01438   *++rules_vsp = rules_val;
01439 
01440 
01441   /* Now `shift' the result of the reduction.  Determine what state
01442      that goes to, based on the state we popped back to and the rule
01443      number reduced by.  */
01444 
01445   rules_n = rules_r1[rules_n];
01446 
01447   rules_state = rules_pgoto[rules_n - YYNTOKENS] + *rules_ssp;
01448   if (0 <= rules_state && rules_state <= YYLAST && rules_check[rules_state] == *rules_ssp)
01449     rules_state = rules_table[rules_state];
01450   else
01451     rules_state = rules_defgoto[rules_n - YYNTOKENS];
01452 
01453   goto rules_newstate;
01454 
01455 
01456 /*------------------------------------.
01457 | rules_errlab -- here on detecting error |
01458 `------------------------------------*/
01459 rules_errlab:
01460   /* If not already recovering from an error, report this error.  */
01461   if (!rules_errstatus)
01462     {
01463       ++rules_nerrs;
01464 #if YYERROR_VERBOSE
01465       rules_n = rules_pact[rules_state];
01466 
01467       if (YYPACT_NINF < rules_n && rules_n < YYLAST)
01468         {
01469           YYSIZE_T rules_size = 0;
01470           int rules_type = YYTRANSLATE (rules_char);
01471           const char* rules_prefix;
01472           char *rules_msg;
01473           int rules_x;
01474 
01475           /* Start YYX at -YYN if negative to avoid negative indexes in
01476              YYCHECK.  */
01477           int rules_xbegin = rules_n < 0 ? -rules_n : 0;
01478 
01479           /* Stay within bounds of both rules_check and rules_tname.  */
01480           int rules_checklim = YYLAST - rules_n;
01481           int rules_xend = rules_checklim < YYNTOKENS ? rules_checklim : YYNTOKENS;
01482           int rules_count = 0;
01483 
01484           rules_prefix = ", expecting ";
01485           for (rules_x = rules_xbegin; rules_x < rules_xend; ++rules_x)
01486             if (rules_check[rules_x + rules_n] == rules_x && rules_x != YYTERROR)
01487               {
01488                 rules_size += rules_strlen (rules_prefix) + rules_strlen (rules_tname [rules_x]);
01489                 rules_count += 1;
01490                 if (rules_count == 5)
01491                   {
01492                     rules_size = 0;
01493                     break;
01494                   }
01495               }
01496           rules_size += (sizeof ("syntax error, unexpected ")
01497                      + rules_strlen (rules_tname[rules_type]));
01498           rules_msg = (char *) YYSTACK_ALLOC (rules_size);
01499           if (rules_msg != 0)
01500             {
01501               char *rules_p = rules_stpcpy (rules_msg, "syntax error, unexpected ");
01502               rules_p = rules_stpcpy (rules_p, rules_tname[rules_type]);
01503 
01504               if (rules_count < 5)
01505                 {
01506                   rules_prefix = ", expecting ";
01507                   for (rules_x = rules_xbegin; rules_x < rules_xend; ++rules_x)
01508                     if (rules_check[rules_x + rules_n] == rules_x && rules_x != YYTERROR)
01509                       {
01510                         rules_p = rules_stpcpy (rules_p, rules_prefix);
01511                         rules_p = rules_stpcpy (rules_p, rules_tname[rules_x]);
01512                         rules_prefix = " or ";
01513                       }
01514                 }
01515               rules_error (rules_msg);
01516               YYSTACK_FREE (rules_msg);
01517             }
01518           else
01519             rules_error ("syntax error; also virtual memory exhausted");
01520         }
01521       else
01522 #endif /* YYERROR_VERBOSE */
01523         rules_error ("syntax error");
01524     }
01525 
01526 
01527 
01528   if (rules_errstatus == 3)
01529     {
01530       /* If just tried and failed to reuse lookahead token after an
01531          error, discard it.  */
01532 
01533       if (rules_char <= YYEOF)
01534         {
01535           /* If at end of input, pop the error token,
01536              then the rest of the stack, then return failure.  */
01537           if (rules_char == YYEOF)
01538              for (;;)
01539                {
01540                  YYPOPSTACK;
01541                  if (rules_ssp == rules_ss)
01542                    YYABORT;
01543                  YYDSYMPRINTF ("Error: popping", rules_stos[*rules_ssp], rules_vsp, rules_lsp);
01544                  rules_destruct (rules_stos[*rules_ssp], rules_vsp);
01545                }
01546         }
01547       else
01548         {
01549           YYDSYMPRINTF ("Error: discarding", rules_token, &rules_lval, &rules_lloc);
01550           rules_destruct (rules_token, &rules_lval);
01551           rules_char = YYEMPTY;
01552 
01553         }
01554     }
01555 
01556   /* Else will try to reuse lookahead token after shifting the error
01557      token.  */
01558   goto rules_errlab1;
01559 
01560 
01561 /*---------------------------------------------------.
01562 | rules_errorlab -- error raised explicitly by YYERROR.  |
01563 `---------------------------------------------------*/
01564 rules_errorlab:
01565 
01566 #ifdef __GNUC__
01567   /* Pacify GCC when the user code never invokes YYERROR and the label
01568      rules_errorlab therefore never appears in user code.  */
01569   if (0)
01570      goto rules_errorlab;
01571 #endif
01572 
01573   rules_vsp -= rules_len;
01574   rules_ssp -= rules_len;
01575   rules_state = *rules_ssp;
01576   goto rules_errlab1;
01577 
01578 
01579 /*-------------------------------------------------------------.
01580 | rules_errlab1 -- common code for both syntax error and YYERROR.  |
01581 `-------------------------------------------------------------*/
01582 rules_errlab1:
01583   rules_errstatus = 3;  /* Each real token shifted decrements this.  */
01584 
01585   for (;;)
01586     {
01587       rules_n = rules_pact[rules_state];
01588       if (rules_n != YYPACT_NINF)
01589         {
01590           rules_n += YYTERROR;
01591           if (0 <= rules_n && rules_n <= YYLAST && rules_check[rules_n] == YYTERROR)
01592             {
01593               rules_n = rules_table[rules_n];
01594               if (0 < rules_n)
01595                 break;
01596             }
01597         }
01598 
01599       /* Pop the current state because it cannot handle the error token.  */
01600       if (rules_ssp == rules_ss)
01601         YYABORT;
01602 
01603       YYDSYMPRINTF ("Error: popping", rules_stos[*rules_ssp], rules_vsp, rules_lsp);
01604       rules_destruct (rules_stos[rules_state], rules_vsp);
01605       YYPOPSTACK;
01606       rules_state = *rules_ssp;
01607       YY_STACK_PRINT (rules_ss, rules_ssp);
01608     }
01609 
01610   if (rules_n == YYFINAL)
01611     YYACCEPT;
01612 
01613   YYDPRINTF ((stderr, "Shifting error token, "));
01614 
01615   *++rules_vsp = rules_lval;
01616 
01617 
01618   rules_state = rules_n;
01619   goto rules_newstate;
01620 
01621 
01622 /*-------------------------------------.
01623 | rules_acceptlab -- YYACCEPT comes here.  |
01624 `-------------------------------------*/
01625 rules_acceptlab:
01626   rules_result = 0;
01627   goto rules_return;
01628 
01629 /*-----------------------------------.
01630 | rules_abortlab -- YYABORT comes here.  |
01631 `-----------------------------------*/
01632 rules_abortlab:
01633   rules_result = 1;
01634   goto rules_return;
01635 
01636 #ifndef rules_overflow
01637 /*----------------------------------------------.
01638 | rules_overflowlab -- parser overflow comes here.  |
01639 `----------------------------------------------*/
01640 rules_overflowlab:
01641   rules_error ("parser stack overflow");
01642   rules_result = 2;
01643   /* Fall through.  */
01644 #endif
01645 
01646 rules_return:
01647 #ifndef rules_overflow
01648   if (rules_ss != rules_ssa)
01649     YYSTACK_FREE (rules_ss);
01650 #endif
01651   return rules_result;
01652 }

int rules_wrap void   ) 
 

Definition at line 1680 of file rule-parse.cc.

01681         {
01682         return 1;
01683         }


Variable Documentation

const char* current_rule_file
 

Definition at line 34 of file RuleMatcher.h.

Referenced by RuleMatcher::ReadFiles(), rules_error(), and rules_parse().

int rule_bench
 

Definition at line 22 of file RuleMatcher.h.

Referenced by RuleMatcher::ClearEndpointState(), RuleMatcher::FinishEndpoint(), RuleMatcher::InitEndpoint(), main(), RE_Match_State::Match(), and RuleMatcher::Match().

RuleMatcher* rule_matcher
 

Definition at line 37 of file RuleMatcher.h.

Referenced by TCP_Reassembler::BlockInserted(), Connection::ClearMatchState(), TCP_Endpoint::DataSent(), RuleActionEvent::DoAction(), RuleConditionEval::DoMatch(), Connection::FinishEndpointMatcher(), HTTP_Conn::HTTP_RequestLine(), Connection::InitEndpointMatcher(), ProfileLogger::Log(), main(), Connection::Match(), TCP_Reassembler::MatchUndelivered(), NetSessions::NewConn(), FingerConn::NewLine(), FTP_Conn::NewLine(), ICMP_Connection::NextPacket(), TCP_Connection::NextPacket(), UDP_Connection::NextPacket(), rules_error(), rules_parse(), and termination_signal().

FILE* rules_in
 

Definition at line 32 of file RuleMatcher.h.

Referenced by RuleMatcher::ReadFiles().

int rules_line_number
 

Definition at line 33 of file RuleMatcher.h.

Referenced by RuleMatcher::ReadFiles(), rules_error(), and rules_parse().


Generated on Wed Sep 14 03:04:17 2005 for bro_docs by doxygen 1.3.5