Remove bgp_as4_support variable.

This commit is contained in:
Ondrej Zajicek 2009-12-14 23:31:25 +01:00
parent 13a7395704
commit 43c1ceccb9
5 changed files with 29 additions and 74 deletions

View file

@ -16,53 +16,36 @@
#include "filter/filter.h" #include "filter/filter.h"
/* Global AS4 support, shared by all BGP instances. // static inline void put_as(byte *data, u32 as) { put_u32(data, as); }
* This specifies whether BA_AS_PATH attributes contain 2 or 4 B per ASN // static inline u32 get_as(byte *data) { return get_u32(data); }
*/
int bgp_as4_support = 1; #define put_as put_u32
#define get_as get_u32
static void #define BS 4
put_as(byte *data, u32 as)
{
if (bgp_as4_support)
put_u32(data, as);
else if (as <= 0xFFFF)
put_u16(data, as);
else
bug("put_as: Try to put 32bit AS to 16bit AS Path");
}
static inline u32
get_as(byte *data)
{
return bgp_as4_support ? get_u32(data) : get_u16(data);
}
struct adata * struct adata *
as_path_prepend(struct linpool *pool, struct adata *olda, u32 as) as_path_prepend(struct linpool *pool, struct adata *olda, u32 as)
{ {
int bs = bgp_as4_support ? 4 : 2;
struct adata *newa; struct adata *newa;
if (olda->length && olda->data[0] == AS_PATH_SEQUENCE && olda->data[1] < 255) if (olda->length && olda->data[0] == AS_PATH_SEQUENCE && olda->data[1] < 255)
/* Starting with sequence => just prepend the AS number */ /* Starting with sequence => just prepend the AS number */
{ {
int nl = olda->length + bs; int nl = olda->length + BS;
newa = lp_alloc(pool, sizeof(struct adata) + nl); newa = lp_alloc(pool, sizeof(struct adata) + nl);
newa->length = nl; newa->length = nl;
newa->data[0] = AS_PATH_SEQUENCE; newa->data[0] = AS_PATH_SEQUENCE;
newa->data[1] = olda->data[1] + 1; newa->data[1] = olda->data[1] + 1;
memcpy(newa->data + bs + 2, olda->data + 2, olda->length - 2); memcpy(newa->data + BS + 2, olda->data + 2, olda->length - 2);
} }
else /* Create new path segment */ else /* Create new path segment */
{ {
int nl = olda->length + bs + 2; int nl = olda->length + BS + 2;
newa = lp_alloc(pool, sizeof(struct adata) + nl); newa = lp_alloc(pool, sizeof(struct adata) + nl);
newa->length = nl; newa->length = nl;
newa->data[0] = AS_PATH_SEQUENCE; newa->data[0] = AS_PATH_SEQUENCE;
newa->data[1] = 1; newa->data[1] = 1;
memcpy(newa->data + bs + 2, olda->data, olda->length); memcpy(newa->data + BS + 2, olda->data, olda->length);
} }
put_as(newa->data + 2, as); put_as(newa->data + 2, as);
return newa; return newa;
@ -144,7 +127,6 @@ as_path_convert_to_new(struct adata *path, byte *dst, int req_as)
void void
as_path_format(struct adata *path, byte *buf, unsigned int size) as_path_format(struct adata *path, byte *buf, unsigned int size)
{ {
int bs = bgp_as4_support ? 4 : 2;
byte *p = path->data; byte *p = path->data;
byte *e = p + path->length; byte *e = p + path->length;
byte *end = buf + size - 16; byte *end = buf + size - 16;
@ -172,7 +154,7 @@ as_path_format(struct adata *path, byte *buf, unsigned int size)
if (!sp) if (!sp)
*buf++ = ' '; *buf++ = ' ';
buf += bsprintf(buf, "%u", get_as(p)); buf += bsprintf(buf, "%u", get_as(p));
p += bs; p += BS;
sp = 0; sp = 0;
} }
if (isset) if (isset)
@ -188,8 +170,7 @@ as_path_format(struct adata *path, byte *buf, unsigned int size)
int int
as_path_getlen(struct adata *path) as_path_getlen(struct adata *path)
{ {
int bs = bgp_as4_support ? 4 : 2; return as_path_getlen_int(path, BS);
return as_path_getlen_int(path, bs);
} }
int int
@ -215,7 +196,6 @@ as_path_getlen_int(struct adata *path, int bs)
int int
as_path_get_last(struct adata *path, u32 *orig_as) as_path_get_last(struct adata *path, u32 *orig_as)
{ {
int bs = bgp_as4_support ? 4 : 2;
int found = 0; int found = 0;
u32 res = 0; u32 res = 0;
u8 *p = path->data; u8 *p = path->data;
@ -230,15 +210,15 @@ as_path_get_last(struct adata *path, u32 *orig_as)
if (len = *p++) if (len = *p++)
{ {
found = 0; found = 0;
p += bs * len; p += BS * len;
} }
break; break;
case AS_PATH_SEQUENCE: case AS_PATH_SEQUENCE:
if (len = *p++) if (len = *p++)
{ {
found = 1; found = 1;
res = get_as(p + bs * (len - 1)); res = get_as(p + BS * (len - 1));
p += bs * len; p += BS * len;
} }
break; break;
default: bug("as_path_get_first: Invalid path segment"); default: bug("as_path_get_first: Invalid path segment");
@ -267,7 +247,6 @@ as_path_get_first(struct adata *path, u32 *last_as)
int int
as_path_is_member(struct adata *path, u32 as) as_path_is_member(struct adata *path, u32 as)
{ {
int bs = bgp_as4_support ? 4 : 2;
u8 *p = path->data; u8 *p = path->data;
u8 *q = p+path->length; u8 *q = p+path->length;
int i, n; int i, n;
@ -280,7 +259,7 @@ as_path_is_member(struct adata *path, u32 as)
{ {
if (get_as(p) == as) if (get_as(p) == as)
return 1; return 1;
p += bs; p += BS;
} }
} }
return 0; return 0;
@ -301,7 +280,6 @@ struct pm_pos
static int static int
parse_path(struct adata *path, struct pm_pos *pos) parse_path(struct adata *path, struct pm_pos *pos)
{ {
int bs = bgp_as4_support ? 4 : 2;
u8 *p = path->data; u8 *p = path->data;
u8 *q = p + path->length; u8 *q = p + path->length;
struct pm_pos *opos = pos; struct pm_pos *opos = pos;
@ -316,7 +294,7 @@ parse_path(struct adata *path, struct pm_pos *pos)
pos->mark = 0; pos->mark = 0;
pos->val.sp = p; pos->val.sp = p;
len = *p; len = *p;
p += 1 + bs * len; p += 1 + BS * len;
pos++; pos++;
break; break;
@ -327,7 +305,7 @@ parse_path(struct adata *path, struct pm_pos *pos)
pos->set = 0; pos->set = 0;
pos->mark = 0; pos->mark = 0;
pos->val.asn = get_as(p); pos->val.asn = get_as(p);
p += bs; p += BS;
pos++; pos++;
} }
break; break;
@ -346,13 +324,12 @@ pm_match(struct pm_pos *pos, u32 asn)
if (! pos->set) if (! pos->set)
return pos->val.asn == asn; return pos->val.asn == asn;
int bs = bgp_as4_support ? 4 : 2;
u8 *p = pos->val.sp; u8 *p = pos->val.sp;
int len = *p++; int len = *p++;
int i; int i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
if (get_as(p + i * bs) == asn) if (get_as(p + i * BS) == asn)
return 1; return 1;
return 0; return 0;

View file

@ -196,16 +196,8 @@ bgp_format_aggregator(eattr *a, byte *buf, int buflen UNUSED)
byte *data = ad->data; byte *data = ad->data;
u32 as; u32 as;
if (bgp_as4_support)
{
as = get_u32(data); as = get_u32(data);
data += 4; data += 4;
}
else
{
as = get_u16(data);
data += 2;
}
bsprintf(buf, "%d.%d.%d.%d AS%d", data[0], data[1], data[2], data[3], as); bsprintf(buf, "%d.%d.%d.%d AS%d", data[0], data[1], data[2], data[3], as);
} }
@ -279,9 +271,8 @@ static struct attr_desc bgp_attr_table[] = {
NULL, NULL } NULL, NULL }
}; };
/* BA_AS4_PATH is type EAF_TYPE_OPAQUE and not type EAF_TYPE_AS_PATH because /* BA_AS4_PATH is type EAF_TYPE_OPAQUE and not type EAF_TYPE_AS_PATH.
* EAF_TYPE_AS_PATH is supposed to have different format (2 or 4 B for each ASN) * It does not matter as this attribute does not appear on routes in the routing table.
* depending on bgp_as4_support variable.
*/ */
#define ATTR_KNOWN(code) ((code) < ARRAY_SIZE(bgp_attr_table) && bgp_attr_table[code].name) #define ATTR_KNOWN(code) ((code) < ARRAY_SIZE(bgp_attr_table) && bgp_attr_table[code].name)
@ -449,7 +440,7 @@ bgp_encode_attrs(struct bgp_proto *p, byte *w, ea_list *attrs, int remains)
* we have to convert our 4B AS_PATH to 2B AS_PATH and send our AS_PATH * we have to convert our 4B AS_PATH to 2B AS_PATH and send our AS_PATH
* as optional AS4_PATH attribute. * as optional AS4_PATH attribute.
*/ */
if ((code == BA_AS_PATH) && bgp_as4_support && (! p->as4_session)) if ((code == BA_AS_PATH) && (! p->as4_session))
{ {
len = a->u.ptr->length; len = a->u.ptr->length;
@ -491,7 +482,7 @@ bgp_encode_attrs(struct bgp_proto *p, byte *w, ea_list *attrs, int remains)
} }
/* The same issue with AGGREGATOR attribute */ /* The same issue with AGGREGATOR attribute */
if ((code == BA_AGGREGATOR) && bgp_as4_support && (! p->as4_session)) if ((code == BA_AGGREGATOR) && (! p->as4_session))
{ {
int new_used; int new_used;
@ -864,14 +855,10 @@ bgp_create_attrs(struct bgp_proto *p, rte *e, ea_list **attrs, struct linpool *p
bgp_set_attr_wa(ea->attrs+1, pool, BA_AS_PATH, 0); bgp_set_attr_wa(ea->attrs+1, pool, BA_AS_PATH, 0);
else else
{ {
z = bgp_set_attr_wa(ea->attrs+1, pool, BA_AS_PATH, bgp_as4_support ? 6 : 4); z = bgp_set_attr_wa(ea->attrs+1, pool, BA_AS_PATH, 6);
z[0] = AS_PATH_SEQUENCE; z[0] = AS_PATH_SEQUENCE;
z[1] = 1; /* 1 AS */ z[1] = 1; /* 1 AS */
if (bgp_as4_support)
put_u32(z+2, p->local_as); put_u32(z+2, p->local_as);
else
put_u16(z+2, p->local_as);
} }
z = bgp_set_attr_wa(ea->attrs+2, pool, BA_NEXT_HOP, NEXT_HOP_LENGTH); z = bgp_set_attr_wa(ea->attrs+2, pool, BA_NEXT_HOP, NEXT_HOP_LENGTH);
@ -1416,10 +1403,9 @@ bgp_decode_attrs(struct bgp_conn *conn, byte *attr, unsigned int len, struct lin
/* When receiving attributes from non-AS4-aware BGP speaker, /* When receiving attributes from non-AS4-aware BGP speaker,
* we have to reconstruct 4B AS_PATH and AGGREGATOR attributes * we have to reconstruct 4B AS_PATH and AGGREGATOR attributes
*/ */
if (bgp_as4_support && (! bgp->as4_session)) if (! bgp->as4_session)
bgp_reconstruct_4b_atts(bgp, a, pool); bgp_reconstruct_4b_atts(bgp, a, pool);
if (bgp_as4_support)
bgp_remove_as4_attrs(bgp, a); bgp_remove_as4_attrs(bgp, a);
/* If the AS path attribute contains our AS, reject the routes */ /* If the AS path attribute contains our AS, reject the routes */

View file

@ -884,12 +884,6 @@ bgp_check(struct bgp_config *c)
if (!c->remote_as) if (!c->remote_as)
cf_error("Neighbor must be configured"); cf_error("Neighbor must be configured");
if (!bgp_as4_support && c->enable_as4)
cf_error("AS4 support disabled globally");
if (!bgp_as4_support && (c->local_as > 0xFFFF))
cf_error("Local AS number out of range");
if (!(c->capabilities && c->enable_as4) && (c->remote_as > 0xFFFF)) if (!(c->capabilities && c->enable_as4) && (c->remote_as > 0xFFFF))
cf_error("Neighbor AS number out of range (AS4 not available)"); cf_error("Neighbor AS number out of range (AS4 not available)");

View file

@ -132,8 +132,6 @@ struct bgp_bucket {
extern struct linpool *bgp_linpool; extern struct linpool *bgp_linpool;
extern int bgp_as4_support;
void bgp_start_timer(struct timer *t, int value); void bgp_start_timer(struct timer *t, int value);
void bgp_check(struct bgp_config *c); void bgp_check(struct bgp_config *c);

View file

@ -41,7 +41,7 @@ bgp_proto_start: proto_start BGP {
BGP_CFG->error_delay_time_min = 60; BGP_CFG->error_delay_time_min = 60;
BGP_CFG->error_delay_time_max = 300; BGP_CFG->error_delay_time_max = 300;
BGP_CFG->enable_refresh = 1; BGP_CFG->enable_refresh = 1;
BGP_CFG->enable_as4 = bgp_as4_support; BGP_CFG->enable_as4 = 1;
BGP_CFG->capabilities = 2; BGP_CFG->capabilities = 2;
BGP_CFG->advertise_ipv4 = 1; BGP_CFG->advertise_ipv4 = 1;
} }