summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2000-05-19 13:01:06 +0200
committerMartin Mares <mj@ucw.cz>2000-05-19 13:01:06 +0200
commitf49528a3dfa034415527824cbbd0762f3829f0cd (patch)
treeb0d2cf55d47ad66e569bb86e4aef87f06ed4f497
parentf7ad556f2017075abaef659bf018a0ce215b13b3 (diff)
downloadbird-f49528a3dfa034415527824cbbd0762f3829f0cd.tar
bird-f49528a3dfa034415527824cbbd0762f3829f0cd.zip
Added as_path_get_first().
-rw-r--r--nest/a-path.c28
-rw-r--r--nest/attrs.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/nest/a-path.c b/nest/a-path.c
index 0ea3e7b..0c46755 100644
--- a/nest/a-path.c
+++ b/nest/a-path.c
@@ -103,6 +103,34 @@ as_path_getlen(struct adata *path)
return res;
}
+int
+as_path_get_first(struct adata *path)
+{
+ int res = -1;
+ u8 *p = path->data;
+ u8 *q = p+path->length;
+ int len;
+
+ while (p<q)
+ {
+ switch (*p++)
+ {
+ case AS_PATH_SET:
+ if (len = *p++)
+ res = get_u16(p);
+ p += 2*len;
+ break;
+ case AS_PATH_SEQUENCE:
+ if (len = *p++)
+ res = get_u16(p+2*(len-1));
+ p += 2*len;
+ break;
+ default: bug("as_path_get_first: Invalid path segment");
+ }
+ }
+ return res;
+}
+
#define MASK_PLUS do { mask = mask->next; if (!mask) return next == q; \
asterisk = (mask->val == PM_ANY); \
if (asterisk) { mask = mask->next; if (!mask) { return 1; } } \
diff --git a/nest/attrs.h b/nest/attrs.h
index 2618fa3..abd6b9e 100644
--- a/nest/attrs.h
+++ b/nest/attrs.h
@@ -17,6 +17,7 @@
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);
+int as_path_get_first(struct adata *path);
struct f_path_mask {
struct f_path_mask *next;