From 7f77e2500218c197ba56a473d587dedda7309029 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 10 Apr 2000 15:07:43 +0000 Subject: Functions for matching paths added, tested lightly. Functions for working with community lists added, they compile. This should not be definitive place for this stuff. --- filter/filter.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) (limited to 'filter/filter.c') diff --git a/filter/filter.c b/filter/filter.c index af7ee53..7549d6b 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -16,6 +16,7 @@ #include "lib/resource.h" #include "lib/socket.h" #include "lib/string.h" +#include "lib/unaligned.h" #include "nest/route.h" #include "nest/protocol.h" #include "nest/iface.h" @@ -133,6 +134,7 @@ val_print(struct f_val v) case T_SET: tree_print( v.val.t ); PRINTF( "\n" ); break; case T_ENUM: PRINTF( "(enum %x)%d", v.type, v.val.i ); break; default: PRINTF( "[unknown type %x]", v.type ); +#undef PRINTF } debug( buf ); } @@ -554,6 +556,7 @@ filters_postconfig(void) die( "Startup function resulted in error." ); debug( "done\n" ); } + self_test(); } int @@ -566,3 +569,203 @@ filter_same(struct filter *new, struct filter *old) return 0; return i_same(new->root, old->root); } + +/* This should end up far away from here! */ + +int +path_getlen(u8 *p, int len) +{ + int res = 0; + u8 *q = p+len; + while (plength + sizeof(struct adata) + 4); + res->length = list->length+4; + * (u32 *) res->data = val; + memcpy((char *) res->data + 4, list->data, list->length); + return res; +} + +struct adata * +comlist_contains(struct adata *list, u32 val) +{ + u32 *l = &(list->data); + int i; + for (i=0; ilength/4; i++) + if (*l++ == val) + return 1; + return 0; +} + +struct adata * +comlist_del(struct linpool *pool, struct adata *list, u32 val) +{ + struct adata *res; + u32 *l, *k; + int i; + + if (!comlist_contains(list, val)) + return list; + + res = lp_alloc(pool, list->length + sizeof(struct adata) - 4); + res->length = list->length-4; + + l = &(list->data); + k = &(res->data); + for (i=0; ilength/4; i++) + if (l[i] != val) + *k++ = l[i]; + + return res; +} + +struct adata * +comlist_empty(struct linpool *pool) +{ + struct adata *res = lp_alloc(pool, sizeof(struct adata)); + 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" ); +} -- cgit v1.2.3