summaryrefslogtreecommitdiff
path: root/nest/a-path.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-07-11 11:08:10 +0200
committerMaria Matejka <mq@ucw.cz>2022-07-11 11:08:10 +0200
commit2e5bfeb73ac25e236a24b6c1a88d0f2221ca303f (patch)
tree396657a62a5a63b0a304268bd011934f56d414ce /nest/a-path.c
parentd429bc5c841a8e9d4c81786973edfa56d20a407e (diff)
parentcb339a30677901f2c248de08ff535cf0a9efab3d (diff)
Merge remote-tracking branch 'origin/master' into backport
Diffstat (limited to 'nest/a-path.c')
-rw-r--r--nest/a-path.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/nest/a-path.c b/nest/a-path.c
index badbc911..c421b41f 100644
--- a/nest/a-path.c
+++ b/nest/a-path.c
@@ -602,8 +602,10 @@ as_path_match_set(const struct adata *path, const struct f_tree *set)
}
const struct adata *
-as_path_filter(struct linpool *pool, const struct adata *path, const struct f_tree *set, u32 key, int pos)
+as_path_filter(struct linpool *pool, const struct adata *path, const struct f_val *set, int pos)
{
+ ASSERT((set->type == T_SET) || (set->type == T_INT));
+
if (!path)
return NULL;
@@ -629,13 +631,13 @@ as_path_filter(struct linpool *pool, const struct adata *path, const struct f_tr
u32 as = get_as(p);
int match;
- if (set)
+ if (set->type == T_SET)
{
struct f_val v = { .type = T_INT, .val.i = as};
- match = !!find_tree(set, &v);
+ match = !!find_tree(set->val.t, &v);
}
- else
- match = (as == key);
+ else /* T_INT */
+ match = (as == set->val.i);
if (match == pos)
{
@@ -667,6 +669,35 @@ as_path_filter(struct linpool *pool, const struct adata *path, const struct f_tr
return res;
}
+int
+as_path_walk(const struct adata *path, uint *pos, uint *val)
+{
+ if (!path)
+ return 0;
+
+ const u8 *p = path->data;
+ const u8 *q = p + path->length;
+ uint n, x = *pos;
+
+ while (p < q)
+ {
+ n = p[1];
+ p += 2;
+
+ if (x < n)
+ {
+ *val = get_as(p + x * BS);
+ *pos += 1;
+ return 1;
+ }
+
+ p += n * BS;
+ x -= n;
+ }
+
+ return 0;
+}
+
struct pm_pos
{