diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2022-03-14 20:36:20 +0100 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2022-06-27 21:13:32 +0200 |
commit | cb339a30677901f2c248de08ff535cf0a9efab3d (patch) | |
tree | 2811d66304b044bf3c597c1463c2dff76df18df1 /nest/a-path.c | |
parent | 1ac8e11bba15551ad6473a57a585649757fefa6b (diff) |
Filter: Implement for loops
For loops allow to iterate over elements in compound data like BGP paths
or community lists. The syntax is:
for [ <type> ] <variable> in <expr> do <command-body>
Diffstat (limited to 'nest/a-path.c')
-rw-r--r-- | nest/a-path.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/nest/a-path.c b/nest/a-path.c index d5b01635..6bb18285 100644 --- a/nest/a-path.c +++ b/nest/a-path.c @@ -669,6 +669,35 @@ as_path_filter(struct linpool *pool, const struct adata *path, const struct f_va 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 { |