Path matching now actually works, including / * 1 2 3 * /.
This commit is contained in:
parent
e399b6f6ad
commit
4b641bab52
4 changed files with 7 additions and 21 deletions
|
@ -313,6 +313,7 @@ switch_body: /* EMPTY */ { $$ = NULL; }
|
|||
|
||||
bgp_one:
|
||||
NUM { $$ = $1; }
|
||||
| '*' { $$ = PM_ANY; }
|
||||
;
|
||||
|
||||
bgp_path:
|
||||
|
|
|
@ -592,7 +592,6 @@ filters_postconfig(void)
|
|||
die( "Startup function resulted in error." );
|
||||
debug( "done\n" );
|
||||
}
|
||||
self_test();
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -674,11 +673,8 @@ path_format(u8 *p, int len)
|
|||
#undef PRINTF
|
||||
#undef COMMA
|
||||
|
||||
#define PM_END -1
|
||||
#define PM_ASTERIX -2
|
||||
|
||||
#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; } } \
|
||||
} while(0)
|
||||
|
||||
|
@ -690,6 +686,9 @@ path_match(u8 *p, int len, struct f_path_mask *mask)
|
|||
u8 *q = p+len;
|
||||
u8 *next;
|
||||
|
||||
asterix = (mask->val == PM_ANY);
|
||||
if (asterix) { mask = mask->next; if (!mask) { return 1; } }
|
||||
|
||||
while (p<q) {
|
||||
switch (*p++) {
|
||||
case 1: /* This is a set */
|
||||
|
@ -789,19 +788,3 @@ adata_empty(struct linpool *pool)
|
|||
res->length = 0;
|
||||
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" );
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ struct f_path_mask {
|
|||
struct f_path_mask *next;
|
||||
int val;
|
||||
};
|
||||
#define PM_ANY -1
|
||||
|
||||
struct f_val {
|
||||
int type;
|
||||
|
|
|
@ -43,6 +43,7 @@ bgppath p2;
|
|||
print "Should be true: ", p2 ~ p;
|
||||
p2 = prepend( p2, 5 );
|
||||
print "Should be false: ", p2 ~ p;
|
||||
print "Should be true: ", p2 ~ / * 4 3 2 1 /, p2, / * 4 3 2 1 /;
|
||||
}
|
||||
|
||||
function startup()
|
||||
|
|
Loading…
Reference in a new issue