Path matching now actually works, including / * 1 2 3 * /.

This commit is contained in:
Pavel Machek 2000-04-17 10:50:03 +00:00
parent e399b6f6ad
commit 4b641bab52
4 changed files with 7 additions and 21 deletions

View file

@ -313,6 +313,7 @@ switch_body: /* EMPTY */ { $$ = NULL; }
bgp_one: bgp_one:
NUM { $$ = $1; } NUM { $$ = $1; }
| '*' { $$ = PM_ANY; }
; ;
bgp_path: bgp_path:

View file

@ -592,7 +592,6 @@ filters_postconfig(void)
die( "Startup function resulted in error." ); die( "Startup function resulted in error." );
debug( "done\n" ); debug( "done\n" );
} }
self_test();
} }
int int
@ -674,11 +673,8 @@ path_format(u8 *p, int len)
#undef PRINTF #undef PRINTF
#undef COMMA #undef COMMA
#define PM_END -1
#define PM_ASTERIX -2
#define MASK_PLUS do { mask = mask->next; if (!mask) return next == q; \ #define MASK_PLUS do { mask = mask->next; if (!mask) return next == q; \
asterix = (mask->val == PM_ASTERIX); \ asterix = (mask->val == PM_ANY); \
if (asterix) { mask = mask->next; if (!mask) { return 1; } } \ if (asterix) { mask = mask->next; if (!mask) { return 1; } } \
} while(0) } while(0)
@ -690,6 +686,9 @@ path_match(u8 *p, int len, struct f_path_mask *mask)
u8 *q = p+len; u8 *q = p+len;
u8 *next; u8 *next;
asterix = (mask->val == PM_ANY);
if (asterix) { mask = mask->next; if (!mask) { return 1; } }
while (p<q) { while (p<q) {
switch (*p++) { switch (*p++) {
case 1: /* This is a set */ case 1: /* This is a set */
@ -789,19 +788,3 @@ adata_empty(struct linpool *pool)
res->length = 0; res->length = 0;
return res; return res;
} }
void
self_test(void)
{
char path1[] = { 2, 5, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1 };
char path2[] = { 2, 5, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1, 1, 5, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1 };
s32 match[] = { 5, PM_ASTERIX, 2, PM_ASTERIX, 1, 3, PM_END };
DBG( "Filters self-testing:\n" );
DBG( "%s\n", path_format(path1, sizeof(path1)) );
DBG( "%s\n", path_format(path2, sizeof(path2)) );
DBG( "5, 6 = %d, %d\n", path_getlen(path1, sizeof(path1)), path_getlen(path2, sizeof(path2)) );
// DBG( "%d\n", path_match(path1, sizeof(path1), match));
// DBG( "%d\n", path_match(path2, sizeof(path2), match));
// die( "okay" );
}

View file

@ -43,6 +43,7 @@ struct f_path_mask {
struct f_path_mask *next; struct f_path_mask *next;
int val; int val;
}; };
#define PM_ANY -1
struct f_val { struct f_val {
int type; int type;

View file

@ -43,6 +43,7 @@ bgppath p2;
print "Should be true: ", p2 ~ p; print "Should be true: ", p2 ~ p;
p2 = prepend( p2, 5 ); p2 = prepend( p2, 5 );
print "Should be false: ", p2 ~ p; print "Should be false: ", p2 ~ p;
print "Should be true: ", p2 ~ / * 4 3 2 1 /, p2, / * 4 3 2 1 /;
} }
function startup() function startup()