From c0668f36967ce651e452a476b786b7604038a556 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 17 Apr 2000 07:53:29 +0000 Subject: Created nest/a-path.c and a-set.c which should contain general operations on AS paths and community sets. Moved as_path_prepend() there. Pavel, please move the other functions as well. --- nest/a-path.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 nest/a-path.c (limited to 'nest/a-path.c') diff --git a/nest/a-path.c b/nest/a-path.c new file mode 100644 index 0000000..557f29c --- /dev/null +++ b/nest/a-path.c @@ -0,0 +1,38 @@ +/* + * BIRD -- Path Operations + * + * (c) 2000 Martin Mares + * (c) 2000 Pavel Machek + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#include "nest/bird.h" +#include "nest/route.h" +#include "lib/resource.h" +#include "lib/unaligned.h" + +struct adata * +as_path_prepend(struct linpool *pool, struct adata *olda, int as) +{ + struct adata *newa; + + if (olda->length && olda->data[0] == 2 && olda->data[1] < 255) /* Starting with sequence => just prepend the AS number */ + { + newa = lp_alloc(pool, sizeof(struct adata) + olda->length + 2); + newa->length = olda->length + 2; + newa->data[0] = 2; + newa->data[1] = olda->data[1] + 1; + memcpy(newa->data+4, olda->data+2, olda->length-2); + } + else /* Create new path segment */ + { + newa = lp_alloc(pool, sizeof(struct adata) + olda->length + 4); + newa->length = olda->length + 4; + newa->data[0] = 2; + newa->data[1] = 1; + memcpy(newa->data+4, olda->data, olda->length); + } + put_u16(newa->data+2, as); + return newa; +} -- cgit v1.2.3