summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Machek <pavel@ucw.cz>2000-04-12 12:10:37 +0000
committerPavel Machek <pavel@ucw.cz>2000-04-12 12:10:37 +0000
commit77de68825caae7a9cb1275b0020e49fa9cb27e29 (patch)
tree09da4aad6cd49926b4c9b17ddc25bb9fc5bee450
parent78c6217c1e9f8a46026cecf6a6369b72d5d883b0 (diff)
BGP_PATH masks now actually work as data type.
-rw-r--r--filter/config.Y19
-rw-r--r--filter/filter.c2
-rw-r--r--filter/filter.h6
-rw-r--r--filter/test.conf10
4 files changed, 34 insertions, 3 deletions
diff --git a/filter/config.Y b/filter/config.Y
index e17245df..b0562974 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -24,7 +24,7 @@ mnozina cisel ASu. Na cestach nadefinuji nasledujici operace:
Filtry by mely podporovat:
- - operator pridani AS k ceste [bgp_path_prepend]
+ - operator pridani AS k ceste [bgppath_prepend]
- matchovani na pritomnost podposloupnosti v ceste (pricemz vyskytne-li
se tam mnozina, tak si ji lze predstavit prerovnanou v libovolnem
poradi)
@@ -65,7 +65,7 @@ CF_DECLS
CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
ACCEPT, REJECT, ERROR, QUITBIRD,
- INT, BOOL, IP, PREFIX, PAIR, SET, STRING,
+ INT, BOOL, IP, PREFIX, PAIR, SET, STRING, BGP_PATH,
IF, THEN, ELSE, CASE,
TRUE, FALSE,
FROM, GW, NET, MASK, SOURCE,
@@ -84,6 +84,8 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
%type <e> set_item set_items switch_body
%type <v> set_atom prefix prefix_s ipa
%type <s> decls declsn one_decl function_params
+%type <h> bgp_path
+%type <i> bgp_one
CF_GRAMMAR
@@ -104,6 +106,7 @@ type:
| PREFIX { $$ = T_PREFIX; }
| PAIR { $$ = T_PAIR; }
| STRING { $$ = T_STRING; }
+ | BGP_PATH { $$ = T_PATH; }
| type SET {
switch ($1) {
default:
@@ -305,6 +308,15 @@ switch_body: /* EMPTY */ { $$ = NULL; }
/* CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $3; } */
+bgp_one:
+ NUM { $$ = $1; }
+ ;
+
+bgp_path:
+ bgp_one { $$ = cfg_alloc(sizeof(struct f_path)); $$->next = NULL; $$->val = $1; }
+ | bgp_one bgp_path { $$ = cfg_alloc(sizeof(struct f_path)); $$->next = $2; $$->val = $1; }
+ ;
+
constant:
NUM { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $1; }
| TRUE { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 1; }
@@ -315,6 +327,7 @@ constant:
| prefix_s {NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
| '[' set_items ']' { DBG( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_SET; $$->a2.p = build_tree($2); DBG( "ook\n" ); }
| ENUM { $$ = f_new_inst(); $$->code = 'c'; $$->aux = $1 >> 16; $$->a2.i = $1 & 0xffff; }
+ | '/' bgp_path '/' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_PATH; $$->a2.p = $2; }
;
/*
@@ -371,6 +384,7 @@ term:
case SYM_VARIABLE | T_PAIR:
case SYM_VARIABLE | T_PREFIX:
case SYM_VARIABLE | T_IP:
+ case SYM_VARIABLE | T_PATH:
$$->code = 'C';
$$->a1.p = $1->aux2;
break;
@@ -401,7 +415,6 @@ term:
/* Paths */
| term '.' APPEND '(' term ')' { }
/* | term '.' LEN { } Hmm, this would colide with ip.len. What to do with that? */
- | term '.' MATCH '(' term ')' { }
/* function_call is inlined here */
| SYM '(' var_list ')' {
diff --git a/filter/filter.c b/filter/filter.c
index f3f8c237..9788edb6 100644
--- a/filter/filter.c
+++ b/filter/filter.c
@@ -133,6 +133,7 @@ val_print(struct f_val v)
case T_PAIR: PRINTF( "(%d,%d)", v.val.i >> 16, v.val.i & 0xffff ); break;
case T_SET: tree_print( v.val.t ); PRINTF( "\n" ); break;
case T_ENUM: PRINTF( "(enum %x)%d", v.type, v.val.i ); break;
+ case T_PATH: debug( "(path " ); { struct f_path *p = v.val.s; while (p) { debug("%d ", p->val); p=p->next; } debug(")" ); } break;
default: PRINTF( "[unknown type %x]", v.type );
#undef PRINTF
}
@@ -248,6 +249,7 @@ interpret(struct f_inst *what)
case T_IP:
case T_PREFIX:
case T_PAIR:
+ case T_PATH:
if (sym->class != (SYM_VARIABLE | v2.type))
runtime( "Variable of bad type" );
* (struct f_val *) sym->aux2 = v2;
diff --git a/filter/filter.h b/filter/filter.h
index a6868f97..ecfd88d7 100644
--- a/filter/filter.h
+++ b/filter/filter.h
@@ -50,6 +50,11 @@ struct f_val {
} val;
};
+struct f_path {
+ struct f_path *next;
+ int val;
+};
+
struct filter {
char *name;
struct f_inst *root;
@@ -110,6 +115,7 @@ void val_print(struct f_val v);
#define T_IP 0x20
#define T_PREFIX 0x21
#define T_STRING 0x22
+#define T_PATH 0x23 /* BGP path */
#define T_RETURN 0x40
#define T_SET 0x80
diff --git a/filter/test.conf b/filter/test.conf
index 1677cd2f..cc62cd17 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -29,6 +29,14 @@ function fifteen()
return 15;
}
+function paths()
+bgp_path p;
+{
+ print "Testing paths";
+ p = / 1 2 3 4 /;
+ print p;
+}
+
function startup()
int i;
prefix px;
@@ -73,6 +81,8 @@ ip p;
i = fifteen();
print "Testing function calls: 15 = ", i;
+ paths();
+
print "done";
quitbird;
# print "*** FAIL: this is unreachable";