From: Maria Matejka Date: Fri, 25 Mar 2022 18:15:11 +0000 (+0100) Subject: Filter operations: bitwise AND and OR X-Git-Tag: v3.0-alpha1~171^2~67^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4bcef0e0bfee911d403c0cf830de3e3007eeb38;p=thirdparty%2Fbird.git Filter operations: bitwise AND and OR --- diff --git a/conf/cf-lex.l b/conf/cf-lex.l index c9d2f5a5a..b9457a83d 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -347,7 +347,7 @@ else: { return DDOT; } -[={}:;,.()+*/%<>~\[\]?!\|-] { +[={}:;,.()+*/%<>~\[\]?!\|&-] { return yytext[0]; } diff --git a/conf/confbase.Y b/conf/confbase.Y index 6985783b4..753df3252 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -120,6 +120,7 @@ CF_DECLS %nonassoc PREFIX_DUMMY %left AND OR %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC +%left '|' '&' %left '+' '-' %left '*' '/' '%' %left '!' diff --git a/filter/config.Y b/filter/config.Y index 46ba7769d..dabe47816 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -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); } diff --git a/filter/f-inst.c b/filter/f-inst.c index 8e20dc745..0050c2379 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -240,6 +240,16 @@ 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); diff --git a/filter/test.conf b/filter/test.conf index 2a5a2d987..1058d34ed 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -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");