]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter operations: bitwise AND and OR
authorMaria Matejka <mq@ucw.cz>
Fri, 25 Mar 2022 18:15:11 +0000 (19:15 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 4 May 2022 13:37:41 +0000 (15:37 +0200)
conf/cf-lex.l
conf/confbase.Y
filter/config.Y
filter/f-inst.c
filter/test.conf

index c9d2f5a5acd5241bce5e0f932ebb1fc644460ea7..b9457a83d1bdd9c4829ade9877161f35b514df27 100644 (file)
@@ -347,7 +347,7 @@ else: {
   return DDOT;
 }
 
-[={}:;,.()+*/%<>~\[\]?!\|-] {
+[={}:;,.()+*/%<>~\[\]?!\|&-] {
   return yytext[0];
 }
 
index 6985783b4531bf5ae23804a70210b80f4efaf176..753df32527376121181e299a695abcf342601c18 100644 (file)
@@ -120,6 +120,7 @@ CF_DECLS
 %nonassoc PREFIX_DUMMY
 %left AND OR
 %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
+%left '|' '&'
 %left '+' '-'
 %left '*' '/' '%'
 %left '!'
index 46ba7769da9b04d667fbf91d437153e500f0aea8..dabe47816f9875adde7532ff9bd6d4d23a20607d 100644 (file)
@@ -780,6 +780,8 @@ term:
  | term '-' term       { $$ = f_new_inst(FI_SUBTRACT, $1, $3); }
  | term '*' term       { $$ = f_new_inst(FI_MULTIPLY, $1, $3); }
  | term '/' term       { $$ = f_new_inst(FI_DIVIDE, $1, $3); }
+ | term '&' term       { $$ = f_new_inst(FI_BITAND, $1, $3); }
+ | term '|' term       { $$ = f_new_inst(FI_BITOR, $1, $3); }
  | term AND term       { $$ = f_new_inst(FI_AND, $1, $3); }
  | term OR  term       { $$ = f_new_inst(FI_OR, $1, $3); }
  | term '=' term       { $$ = f_new_inst(FI_EQ, $1, $3); }
index 8e20dc745103ace43bb94cb48756bca1a500ab22..0050c23791f680f45176deb66ddb29004d28d0b9 100644 (file)
     if (v2.val.i == 0) runtime( "Mother told me not to divide by 0" );
     RESULT(T_INT, i, v1.val.i / v2.val.i);
   }
+  INST(FI_BITOR, 2, 1) {
+    ARG(1,T_INT);
+    ARG(2,T_INT);
+    RESULT(T_INT, i, v1.val.i | v2.val.i);
+  }
+  INST(FI_BITAND, 2, 1) {
+    ARG(1,T_INT);
+    ARG(2,T_INT);
+    RESULT(T_INT, i, v1.val.i & v2.val.i);
+  }
   INST(FI_AND, 1, 1) {
     ARG(1,T_BOOL);
     ARG_TYPE_STATIC(2,T_BOOL);
index 2a5a2d987fa1d40c3ed98eb6ca7a05cdb9109812..1058d34edc3dbae375296d2a6ceba11ad24348cd 100644 (file)
@@ -111,6 +111,14 @@ int i;
        bt_assert(!(i = 4));
        bt_assert(1 <= 1);
        bt_assert(!(1234 < 1234));
+
+       bt_assert(10 - 5 = 5);
+       bt_assert(4294967295 + 1 = 0);
+       bt_assert(6*9=54);
+       bt_assert(984/41 = 24);
+       bt_assert(123/45 = 2);
+       bt_assert(0xfee1a | 0xbeef = 0xffeff);
+       bt_assert(0xfee1a & 0xbeef = 0xae0a);
 }
 
 bt_test_suite(t_int, "Testing integers");