diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2016-02-16 17:33:58 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2016-02-16 17:33:58 +0100 |
commit | 9c9cc35c0273f8bcae10fb8b546d199514b2bbc5 (patch) | |
tree | 060b7ebe4012294ee4468a47cb4e73e3f6b1f0c1 /nest | |
parent | c2106b674ca632f7c0bffd7cab4b1940f74d353c (diff) |
Filter: Implement last_nonaggregated operator on bgp_path
Diffstat (limited to 'nest')
-rw-r--r-- | nest/a-path.c | 31 | ||||
-rw-r--r-- | nest/attrs.h | 1 |
2 files changed, 31 insertions, 1 deletions
diff --git a/nest/a-path.c b/nest/a-path.c index c9c5aefb..32e2d27e 100644 --- a/nest/a-path.c +++ b/nest/a-path.c @@ -220,7 +220,7 @@ as_path_get_last(struct adata *path, u32 *orig_as) p += BS * len; } break; - default: bug("as_path_get_first: Invalid path segment"); + default: bug("Invalid path segment"); } } @@ -229,6 +229,35 @@ as_path_get_last(struct adata *path, u32 *orig_as) return found; } +u32 +as_path_get_last_nonaggregated(struct adata *path) +{ + u8 *p = path->data; + u8 *q = p+path->length; + u32 res = 0; + int len; + + while (p<q) + { + switch (*p++) + { + case AS_PATH_SET: + return res; + + case AS_PATH_SEQUENCE: + if (len = *p++) + res = get_as(p + BS * (len - 1)); + p += BS * len; + break; + + default: bug("Invalid path segment"); + } + } + + return res; +} + + int as_path_get_first(struct adata *path, u32 *last_as) { diff --git a/nest/attrs.h b/nest/attrs.h index 1d005a6a..0171c6a8 100644 --- a/nest/attrs.h +++ b/nest/attrs.h @@ -35,6 +35,7 @@ int as_path_getlen(struct adata *path); int as_path_getlen_int(struct adata *path, int bs); int as_path_get_first(struct adata *path, u32 *orig_as); int as_path_get_last(struct adata *path, u32 *last_as); +u32 as_path_get_last_nonaggregated(struct adata *path); int as_path_contains(struct adata *path, u32 as, int min); int as_path_match_set(struct adata *path, struct f_tree *set); struct adata *as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos); |