summaryrefslogtreecommitdiff
path: root/nest/a-path.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2013-08-15 01:06:47 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2013-08-15 01:06:47 +0200
commitbff9ce5130d16af2fd802d42bdb2bff00980c9ae (patch)
tree823dda756311b34c5f2dad4f537671f8d732c9c7 /nest/a-path.c
parent8a112d8ba2e77d79468146ec8f54b3c90b6e68e4 (diff)
Extends delete/filter operators to work no bgp_paths.
Diffstat (limited to 'nest/a-path.c')
-rw-r--r--nest/a-path.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/nest/a-path.c b/nest/a-path.c
index 712e77a3..b1812981 100644
--- a/nest/a-path.c
+++ b/nest/a-path.c
@@ -287,6 +287,69 @@ as_path_match_set(struct adata *path, struct f_tree *set)
return 0;
}
+struct adata *
+as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos)
+{
+ if (!path)
+ return NULL;
+
+ int len = path->length;
+ u8 *p = path->data;
+ u8 *q = path->data + len;
+ u8 *d, *d2;
+ int i, bt, sn, dn;
+ u8 buf[len];
+
+ d = buf;
+ while (p<q)
+ {
+ /* Read block header (type and length) */
+ bt = p[0];
+ sn = p[1];
+ dn = 0;
+ p += 2;
+ d2 = d + 2;
+
+ for (i = 0; i < sn; i++)
+ {
+ u32 as = get_as(p);
+ int match;
+
+ if (set)
+ match = !!find_tree(set, (struct f_val){T_INT, .val.i = as});
+ else
+ match = (as == key);
+
+ if (match == pos)
+ {
+ put_as(d2, as);
+ d2 += BS;
+ dn++;
+ }
+
+ p += BS;
+ }
+
+ if (dn > 0)
+ {
+ /* Nonempty block, set block header and advance */
+ d[0] = bt;
+ d[1] = dn;
+ d = d2;
+ }
+ }
+
+ int nl = d - buf;
+ if (nl == path->length)
+ return path;
+
+ struct adata *res = lp_alloc(pool, sizeof(struct adata) + nl);
+ res->length = nl;
+ memcpy(res->data, buf, nl);
+
+ return res;
+}
+
struct pm_pos
{