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.
This commit is contained in:
Martin Mares 2000-04-17 07:53:29 +00:00
parent ebff007f08
commit c0668f3696
6 changed files with 69 additions and 27 deletions

View file

@ -1,4 +1,5 @@
source=rt-table.c rt-fib.c rt-attr.c proto.c iface.c rt-dev.c password.c cli.c locks.c cmds.c neighbor.c
source=rt-table.c rt-fib.c rt-attr.c proto.c iface.c rt-dev.c password.c cli.c locks.c cmds.c neighbor.c \
a-path.c a-set.c
root-rel=../
dir-name=nest

38
nest/a-path.c Normal file
View file

@ -0,0 +1,38 @@
/*
* BIRD -- Path Operations
*
* (c) 2000 Martin Mares <mj@ucw.cz>
* (c) 2000 Pavel Machek <pavel@ucw.cz>
*
* 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;
}

12
nest/a-set.c Normal file
View file

@ -0,0 +1,12 @@
/*
* BIRD -- Set/Community-list Operations
*
* (c) 2000 Martin Mares <mj@ucw.cz>
* (c) 2000 Pavel Machek <pavel@ucw.cz>
*
* 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"

16
nest/attrs.h Normal file
View file

@ -0,0 +1,16 @@
/*
* BIRD Internet Routing Daemon -- Attribute Operations
*
* (c) 2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_ATTRS_H_
#define _BIRD_ATTRS_H_
/* a-path.c */
struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, int as);
#endif

View file

@ -12,6 +12,7 @@
#include "nest/iface.h"
#include "nest/protocol.h"
#include "nest/route.h"
#include "nest/attrs.h"
#include "conf/conf.h"
#include "lib/resource.h"
#include "lib/string.h"
@ -278,31 +279,6 @@ bgp_create_attrs(struct bgp_proto *p, rte *e, ea_list **attrs, struct linpool *p
return 0; /* Leave decision to the filters */
}
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;
}
static ea_list *
bgp_path_prepend(struct linpool *pool, eattr *a, ea_list *old, int as)
{

View file

@ -96,7 +96,6 @@ int bgp_get_attr(struct eattr *e, byte *buf);
int bgp_rte_better(struct rte *, struct rte *);
void bgp_rt_notify(struct proto *, struct network *, struct rte *, struct rte *, struct ea_list *);
int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *);
struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, int as);
void bgp_attr_init(struct bgp_proto *);
/* packets.c */