summaryrefslogtreecommitdiff
path: root/nest/a-path.c
diff options
context:
space:
mode:
Diffstat (limited to 'nest/a-path.c')
-rw-r--r--nest/a-path.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/nest/a-path.c b/nest/a-path.c
index 557f29c2..ca39e296 100644
--- a/nest/a-path.c
+++ b/nest/a-path.c
@@ -9,8 +9,10 @@
#include "nest/bird.h"
#include "nest/route.h"
+#include "nest/attrs.h"
#include "lib/resource.h"
#include "lib/unaligned.h"
+#include "lib/string.h"
struct adata *
as_path_prepend(struct linpool *pool, struct adata *olda, int as)
@@ -36,3 +38,46 @@ as_path_prepend(struct linpool *pool, struct adata *olda, int as)
put_u16(newa->data+2, as);
return newa;
}
+
+void
+as_path_format(struct adata *path, byte *buf, unsigned int size)
+{
+ byte *p = path->data;
+ byte *e = p + path->length - 8;
+ byte *end = buf + size;
+ int sp = 1;
+ int l, type, isset, as;
+
+ while (p < e)
+ {
+ if (buf > end)
+ {
+ strcpy(buf, " ...");
+ return;
+ }
+ isset = (*p++ == AS_PATH_SET);
+ l = *p++;
+ if (isset)
+ {
+ if (!sp)
+ *buf++ = ' ';
+ *buf++ = '{';
+ sp = 0;
+ }
+ while (l-- && buf <= end)
+ {
+ if (!sp)
+ *buf++ = ' ';
+ buf += bsprintf(buf, "%d", get_u16(p));
+ p += 2;
+ sp = 0;
+ }
+ if (isset)
+ {
+ *buf++ = ' ';
+ *buf++ = '}';
+ sp = 0;
+ }
+ }
+ *buf = 0;
+}