summaryrefslogtreecommitdiffstats
path: root/nest
diff options
context:
space:
mode:
Diffstat (limited to 'nest')
-rw-r--r--nest/a-path.c18
-rw-r--r--nest/attrs.h7
2 files changed, 22 insertions, 3 deletions
diff --git a/nest/a-path.c b/nest/a-path.c
index ca39e29..d808bc9 100644
--- a/nest/a-path.c
+++ b/nest/a-path.c
@@ -81,3 +81,21 @@ as_path_format(struct adata *path, byte *buf, unsigned int size)
}
*buf = 0;
}
+
+int
+as_path_getlen(struct adata *path)
+{
+ int res = 0;
+ u8 *p = path->data;
+ u8 *q = p+path->length;
+ int len;
+
+ while (p<q) {
+ switch (*p++) {
+ case 1: len = *p++; res++; p += 2*len; break;
+ case 2: len = *p++; res+=len; p += 2*len; break;
+ default: bug("This should not be in path");
+ }
+ }
+ return res;
+}
diff --git a/nest/attrs.h b/nest/attrs.h
index fc960fb..67ec52d 100644
--- a/nest/attrs.h
+++ b/nest/attrs.h
@@ -11,12 +11,13 @@
/* a-path.c */
-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);
-
#define AS_PATH_SET 1 /* Types of path segments */
#define AS_PATH_SEQUENCE 2
+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);
+
/* a-set.c */
void int_set_format(struct adata *set, byte *buf, unsigned int size);