]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Split inst->code into inst->code and inst->aux. Both are only 16 bit,
authorPavel Machek <pavel@ucw.cz>
Thu, 18 Nov 1999 14:01:36 +0000 (14:01 +0000)
committerPavel Machek <pavel@ucw.cz>
Thu, 18 Nov 1999 14:01:36 +0000 (14:01 +0000)
so aux is suitable for storing type but not much more.

filter/config.Y
filter/f-util.c
filter/filter.c
filter/filter.h
filter/test.conf

index 540a85d0791988ad04727e7c81d35821478e916b..0a14856008453c02a918318bfe45674e9b460b9b 100644 (file)
@@ -10,6 +10,7 @@
        FIXME: create community lists
        FIXME: write access to dynamic attributes.
        FIXME: '! =' should not be permitted. Ze `!=' by nemelo byt totez jako `! =' Nadefinujes si pres %token novy token a do cf-lex.l pridas nove pravidlo, ktere jej rozpoznava. Napriklad !=      return NEQ;
+       FIXME: write access to static attribute: Z rte ma byt read/write: pref, attrs (neprimo).
 
  */
 
@@ -229,21 +230,21 @@ switch_body: /* EMPTY */ { $$ = NULL; }
  ;
 
 constant:
-   CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT; $$->a2.i = $3; }
- | NUM    { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT;  $$->a2.i = $1; }
- | TRUE   { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_BOOL; $$->a2.i = 1;  }
- | FALSE  { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_BOOL; $$->a2.i = 0;  }
- | TEXT   { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_STRING; $$->a2.p = $1; }
- | pair   { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_PAIR;  $$->a2.i = $1; }
+   CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $3; }
+ | NUM    { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT;  $$->a2.i = $1; }
+ | TRUE   { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 1;  }
+ | FALSE  { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 0;  }
+ | TEXT   { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_STRING; $$->a2.p = $1; }
+ | pair   { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_PAIR;  $$->a2.i = $1; }
  | ipa    { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
  | prefix_s {NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
- | '[' set_items ']' { printf( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_SET; $$->a2.p = build_tree($2); printf( "ook\n" ); }
- | ENUM          { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = $1 >> 16; $$->a2.i = $1 & 0xffff; }
+ | '[' set_items ']' { printf( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_SET; $$->a2.p = build_tree($2); printf( "ook\n" ); }
+ | ENUM          { $$ = f_new_inst(); $$->code = 'c'; $$->aux = $1 >> 16; $$->a2.i = $1 & 0xffff; }
  ;
 
 any_dynamic:
-   RIP_METRIC { $$ = f_new_inst(); $$->a1.i = T_INT; $$->a2.i = EA_RIP_METRIC;}
- | RIP_TAG    { $$ = f_new_inst(); $$->a1.i = T_INT; $$->a2.i = EA_RIP_TAG; }
+   RIP_METRIC { $$ = f_new_inst(); $$->aux = T_INT; $$->a2.i = EA_RIP_METRIC;}
+ | RIP_TAG    { $$ = f_new_inst(); $$->aux = T_INT; $$->a2.i = EA_RIP_TAG; }
  ;
 
 
@@ -283,8 +284,8 @@ term:
 
  | RTA '.' any_dynamic { $$ = $3; $$->code = 'ea'; }
 
- | term '.' IP { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->a2.i = T_IP; }
- | term '.' LEN { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->a2.i = T_INT; }
+ | term '.' IP { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->aux = T_IP; }
+ | term '.' LEN { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->aux = T_INT; }
  | term '.' MASK '(' term ')' { $$ = f_new_inst(); $$->code = 'iM'; $$->a1.p = $1; $$->a2.p = $5; }
  ;
 
@@ -356,6 +357,11 @@ cmd:
      $$->a1.p = $1;
      $$->a2.p = $3;
    }
+ | RTA '.' any_dynamic '=' term ';' {
+     $$ = $3;
+     $$->code  = 'eS';
+
+   }
  | break_command print_list ';' { $$ = f_new_inst(); $$->code = 'p,'; $$->a1.p = $2; $$->a2.i = $1; }
  | SYM '(' var_list ')' ';' {
      struct symbol *sym;
index 40805f8a1447878ed4824373a522e1f44692ed8c..b070d951fce7bcd25b5f45814adb9132409a1194 100644 (file)
@@ -27,7 +27,7 @@ f_new_inst(void)
 {
   struct f_inst * ret;
   ret = cfg_alloc(sizeof(struct f_inst));
-  ret->code = 0;
+  ret->code = ret->aux = 0;
   ret->arg1 = ret->arg2 = ret->next = NULL;
   return ret;
 }
index a26b9e6f68960c9484ba98bc39201afb375027a6..458b8760967f8e7e06fea5b6fd5cdfe9ff5b7b2e 100644 (file)
@@ -250,7 +250,7 @@ interpret(struct f_inst *what)
     break;
 
   case 'c':    /* integer (or simple type) constant */
-    res.type = what->a1.i;
+    res.type = what->aux;
     res.val.i = what->a2.i;
     break;
   case 'C':
@@ -284,7 +284,7 @@ interpret(struct f_inst *what)
     case F_ACCEPT:
       /* Should take care about turning ACCEPT into MODIFY */
     case F_ERROR:
-    case F_REJECT:
+    case F_REJECT:     /* FIXME (noncritical) Should print compele route along with reason to reject route */
       res.type = T_RETURN;
       res.val.i = what->a1.i;
       break;
@@ -298,11 +298,14 @@ interpret(struct f_inst *what)
   case 'a':    /* rta access */
     {
       struct rta *rta = (*f_rte)->attrs;
-      res.type = what->a1.i;
+      res.type = what->aux;
       switch(res.type) {
       case T_IP:
        res.val.px.ip = * (ip_addr *) ((char *) rta + what->a2.i);
        break;
+      case T_ENUM:
+       res.val.i = * ((char *) rta + what->a2.i);
+       break;
       case T_PREFIX:   /* Warning: this works only for prefix of network */
        {
          res.val.px.ip = (*f_rte)->net->n.prefix;
@@ -321,7 +324,7 @@ interpret(struct f_inst *what)
        res.type = T_VOID;
        break;
       }
-      res.type = what->a1.i;
+      res.type = what->aux;
       switch (what->a1.i) {
       case T_INT:
        res.val.i = e->u.data;
@@ -333,7 +336,7 @@ interpret(struct f_inst *what)
     ONEARG;
     if (v1.type != T_PREFIX)
       runtime( "Can not convert non-prefix this way" );
-    res.type = what->a2.i;
+    res.type = what->aux;
     switch(res.type) {
     case T_INT:        res.val.i = v1.val.px.len; break;
     case T_IP: res.val.px.ip = v1.val.px.ip; break;
index 189b226b9ca55e693585ad3688e14ecf90b24e94..a62cb2476238a7db890321d5d310e4b85d8b47af 100644 (file)
@@ -14,7 +14,8 @@
 
 struct f_inst {                /* Instruction */
   struct f_inst *next; /* Structure is 16 bytes, anyway */
-  int code;
+  u16 code;
+  u16 aux;
   union {
     int i;
     void *p;
@@ -85,8 +86,9 @@ void val_print(struct f_val v);
 #define T_MASK 0xff
 
 /* Internal types */
-#define T_VOID 0
-#define T_RETURN 1
+/* Do not use type of zero, that way we'll see errors easier. */
+#define T_VOID 1
+#define T_RETURN 2
 
 /* User visible types, which fit in int */
 #define T_INT 0x10
index 97aaf8f9e0d8098b010a53dee509de686b477c8a..837c423dfae077b2212b3e1902610f18eab96da8 100644 (file)
@@ -66,12 +66,13 @@ ip p;
 filter testf 
 int j; 
 { 
-       print "Heya, filtering route to " rta.net.ip " prefixlen " rta.net.len;
+       print "Heya, filtering route to " rta.net.ip " prefixlen " rta.net.len " source " rta.source;
        print "This route was from " rta.from;
        j = 7;
        j = 17;
-       if rta.rip_metric > 15 then
-               print "RIP Metric is more than infinity";
+       if rta.rip_metric > 15 then {
+               reject "RIP Metric is more than infinity";
+       }
                
-       accept;
+       accept "ok I take that";
 }