diff options
author | Pavel Machek <pavel@ucw.cz> | 2000-04-17 13:11:33 +0200 |
---|---|---|
committer | Pavel Machek <pavel@ucw.cz> | 2000-04-17 13:11:33 +0200 |
commit | 2a40efa5e6252eb5a5dbe5e82dcd9c67ad7838a9 (patch) | |
tree | 6d856eaff0bcfc6b77e477c30acc50b66e1d6565 /nest | |
parent | 684c6f5a0e134426159be7dbd514271aea9f4d3d (diff) | |
download | bird-2a40efa5e6252eb5a5dbe5e82dcd9c67ad7838a9.tar bird-2a40efa5e6252eb5a5dbe5e82dcd9c67ad7838a9.zip |
as_path_match moved to a-path.c
Diffstat (limited to 'nest')
-rw-r--r-- | nest/a-path.c | 67 | ||||
-rw-r--r-- | nest/attrs.h | 8 |
2 files changed, 75 insertions, 0 deletions
diff --git a/nest/a-path.c b/nest/a-path.c index d808bc9..3468e4a 100644 --- a/nest/a-path.c +++ b/nest/a-path.c @@ -99,3 +99,70 @@ as_path_getlen(struct adata *path) } return res; } + +#define MASK_PLUS do { mask = mask->next; if (!mask) return next == q; \ + asterix = (mask->val == PM_ANY); \ + if (asterix) { mask = mask->next; if (!mask) { return 1; } } \ + } while(0) + +int +as_path_match(struct adata *path, struct f_path_mask *mask) +{ + int i; + int asterix = 0; + u8 *p = path->data; + u8 *q = p+path->length; + int 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 */ + len = *p++; + { + u8 *p_save = p; + next = p_save + 2*len; + retry: + p = p_save; + for (i=0; i<len; i++) { + if (asterix && (get_u16(p) == mask->val)) { + MASK_PLUS; + goto retry; + } + if (!asterix && (get_u16(p) == mask->val)) { + p = next; + MASK_PLUS; + goto okay; + } + p+=2; + } + if (!asterix) + return 0; + okay: + } + break; + + case 2: /* This is a sequence */ + len = *p++; + for (i=0; i<len; i++) { + next = p+2; + if (asterix && (get_u16(p) == mask->val)) + MASK_PLUS; + else if (!asterix) { + if (get_u16(p) != mask->val) + return 0; + MASK_PLUS; + } + p+=2; + } + break; + + default: + bug("This should not be in path"); + } + } + return 0; +} diff --git a/nest/attrs.h b/nest/attrs.h index 67ec52d..ede152c 100644 --- a/nest/attrs.h +++ b/nest/attrs.h @@ -18,6 +18,14 @@ struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, int as); void as_path_format(struct adata *path, byte *buf, unsigned int size); int as_path_getlen(struct adata *path); +struct f_path_mask { + struct f_path_mask *next; + int val; +}; +#define PM_ANY -1 + +int as_path_match(struct adata *path, struct f_path_mask *mask); + /* a-set.c */ void int_set_format(struct adata *set, byte *buf, unsigned int size); |