0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 17:51:53 +00:00

BGP redesign

Integrated and extensible BGP with generalized AFI handling,
support for IPv4+IPv6 AFI and unicast+multicast SAFI.
This commit is contained in:
Ondrej Zajicek (work) 2016-12-07 14:11:28 +01:00
parent 5df4073c81
commit d15b0b0a1b
25 changed files with 4786 additions and 3545 deletions

View File

@ -170,7 +170,7 @@ fi
AC_SUBST(iproutedir) AC_SUBST(iproutedir)
# all_protocols="$proto_bfd babel bgp ospf pipe radv rip static" # all_protocols="$proto_bfd babel bgp ospf pipe radv rip static"
all_protocols="$proto_bfd ospf pipe radv rip static" all_protocols="$proto_bfd bgp ospf pipe radv rip static"
all_protocols=`echo $all_protocols | sed 's/ /,/g'` all_protocols=`echo $all_protocols | sed 's/ /,/g'`

View File

@ -1065,7 +1065,7 @@ interpret(struct f_inst *what)
l->count = 1; l->count = 1;
l->attrs[0].id = code; l->attrs[0].id = code;
l->attrs[0].flags = 0; l->attrs[0].flags = 0;
l->attrs[0].type = what->aux | EAF_ORIGINATED; l->attrs[0].type = what->aux | EAF_ORIGINATED | EAF_FRESH;
switch (what->aux & EAF_TYPE_MASK) { switch (what->aux & EAF_TYPE_MASK) {
case EAF_TYPE_INT: case EAF_TYPE_INT:

View File

@ -35,6 +35,7 @@
#define DELTA(a,b) (((a)>=(b))?(a)-(b):(b)-(a)) #define DELTA(a,b) (((a)>=(b))?(a)-(b):(b)-(a))
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a))) #define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
#define CALL(fn, args...) ({ if (fn) fn(args); }) #define CALL(fn, args...) ({ if (fn) fn(args); })
#define ADVANCE(w, r, l) ({ r -= l; w += l; })
static inline int uint_cmp(uint i1, uint i2) static inline int uint_cmp(uint i1, uint i2)
{ return (int)(i1 > i2) - (int)(i1 < i2); } { return (int)(i1 > i2) - (int)(i1 < i2); }

View File

@ -91,6 +91,7 @@ typedef ip6_addr ip_addr;
#define ipa_to_u32(x) ip4_to_u32(ipa_to_ip4(x)) #define ipa_to_u32(x) ip4_to_u32(ipa_to_ip4(x))
#define ipa_is_ip4(a) ip6_is_v4mapped(a) #define ipa_is_ip4(a) ip6_is_v4mapped(a)
#define ipa_is_ip6(a) (! ip6_is_v4mapped(a))
#define IPA_NONE4 ipa_from_ip4(IP4_NONE) #define IPA_NONE4 ipa_from_ip4(IP4_NONE)
#define IPA_NONE6 ipa_from_ip6(IP6_NONE) #define IPA_NONE6 ipa_from_ip6(IP6_NONE)

View File

@ -158,3 +158,15 @@ add_tail_list(list *to, list *l)
q->next = &to->tail_node; q->next = &to->tail_node;
to->tail = q; to->tail = q;
} }
LIST_INLINE uint
list_length(list *l)
{
uint len = 0;
node *n;
WALK_LIST(n, *l)
len++;
return len;
}

View File

@ -80,6 +80,7 @@ void rem_node(node *);
void add_tail_list(list *, list *); void add_tail_list(list *, list *);
void init_list(list *); void init_list(list *);
void insert_node(node *, node *); void insert_node(node *, node *);
uint list_length(list *);
#endif #endif
#endif #endif

View File

@ -109,6 +109,24 @@ net_compare(const net_addr *a, const net_addr *b)
return 0; return 0;
} }
#define NET_HASH(a,t) net_hash_##t((const net_addr_##t *) a)
u32
net_hash(const net_addr *n)
{
switch (n->type)
{
case NET_IP4: return NET_HASH(n, ip4);
case NET_IP6: return NET_HASH(n, ip6);
case NET_VPN4: return NET_HASH(n, vpn4);
case NET_VPN6: return NET_HASH(n, vpn6);
case NET_ROA4: return NET_HASH(n, roa4);
case NET_ROA6: return NET_HASH(n, roa6);
default: bug("invalid type");
}
}
int int
net_validate(const net_addr *N) net_validate(const net_addr *N)
{ {

View File

@ -321,6 +321,8 @@ static inline u32 net_hash_roa4(const net_addr_roa4 *n)
static inline u32 net_hash_roa6(const net_addr_roa6 *n) static inline u32 net_hash_roa6(const net_addr_roa6 *n)
{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); } { return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
u32 net_hash(const net_addr *a);
static inline int net_validate_ip4(const net_addr_ip4 *n) static inline int net_validate_ip4(const net_addr_ip4 *n)
{ {

View File

@ -69,4 +69,22 @@ put_u64(void *p, u64 x)
memcpy(p+4, &xl, 4); memcpy(p+4, &xl, 4);
} }
static inline void
get_u32s(const void *p, u32 *x, int n)
{
int i;
memcpy(x, p, 4*n);
for (i = 0; i < n; i++)
x[i] = ntohl(x[i]);
}
static inline void
put_u32s(void *p, const u32 *x, int n)
{
int i;
for (i = 0; i < n; i++)
put_u32((byte *) p + 4*i, x[i]);
}
#endif #endif

View File

@ -22,112 +22,313 @@
#define get_as get_u32 #define get_as get_u32
#define BS 4 /* Default block size of ASN (autonomous system number) */ #define BS 4 /* Default block size of ASN (autonomous system number) */
struct adata * #define BAD(DSC, VAL) ({ err_dsc = DSC; err_val = VAL; goto bad; })
as_path_prepend(struct linpool *pool, struct adata *olda, u32 as)
{
struct adata *newa;
if (olda->length && olda->data[0] == AS_PATH_SEQUENCE && olda->data[1] < 255) int
/* Starting with sequence => just prepend the AS number */ as_path_valid(byte *data, uint len, int bs, char *err, uint elen)
{
byte *pos = data;
char *err_dsc = NULL;
uint err_val = 0;
while (len)
{ {
int nl = olda->length + BS; if (len < 2)
newa = lp_alloc(pool, sizeof(struct adata) + nl); BAD("segment framing error", 0);
newa->length = nl;
newa->data[0] = AS_PATH_SEQUENCE; /* Process one AS path segment */
newa->data[1] = olda->data[1] + 1; uint type = pos[0];
memcpy(newa->data + BS + 2, olda->data + 2, olda->length - 2); uint slen = 2 + bs * pos[1];
if (len < slen)
BAD("segment framing error", len);
/* XXXX handle CONFED segments */
if ((type != AS_PATH_SET) && (type != AS_PATH_SEQUENCE))
BAD("unknown segment", type);
if (pos[1] == 0)
BAD("zero-length segment", type);
pos += slen;
len -= slen;
} }
else /* Create new path segment */
{ return 1;
int nl = olda->length + BS + 2;
newa = lp_alloc(pool, sizeof(struct adata) + nl); bad:
newa->length = nl; if (err)
newa->data[0] = AS_PATH_SEQUENCE; if (bsnprintf(err, elen, "%s (%u) at %d", err_dsc, err_val, (int) (pos - data)) < 0)
newa->data[1] = 1; err[0] = 0;
memcpy(newa->data + BS + 2, olda->data, olda->length);
} return 0;
put_as(newa->data + 2, as);
return newa;
} }
int int
as_path_convert_to_old(struct adata *path, byte *dst, int *new_used) as_path_16to32(byte *dst, byte *src, uint len)
{ {
byte *src = path->data; byte *dst0 = dst;
byte *src_end = src + path->length; byte *end = src + len;
byte *dst_start = dst; uint i, n;
u32 as;
int i, n;
*new_used = 0;
while (src < src_end) while (src < end)
{ {
n = src[1]; n = src[1];
*dst++ = *src++; *dst++ = *src++;
*dst++ = *src++; *dst++ = *src++;
for(i=0; i<n; i++) for (i = 0; i < n; i++)
{ {
as = get_u32(src); put_u32(dst, get_u16(src));
if (as > 0xFFFF)
{
as = AS_TRANS;
*new_used = 1;
}
put_u16(dst, as);
src += 4;
dst += 2;
}
}
return dst - dst_start;
}
int
as_path_convert_to_new(struct adata *path, byte *dst, int req_as)
{
byte *src = path->data;
byte *src_end = src + path->length;
byte *dst_start = dst;
u32 as;
int i, t, n;
while ((src < src_end) && (req_as > 0))
{
t = *src++;
n = *src++;
if (t == AS_PATH_SEQUENCE)
{
if (n > req_as)
n = req_as;
req_as -= n;
}
else // t == AS_PATH_SET
req_as--;
*dst++ = t;
*dst++ = n;
for(i=0; i<n; i++)
{
as = get_u16(src);
put_u32(dst, as);
src += 2; src += 2;
dst += 4; dst += 4;
} }
} }
return dst - dst_start; return dst - dst0;
}
int
as_path_32to16(byte *dst, byte *src, uint len)
{
byte *dst0 = dst;
byte *end = src + len;
uint i, n;
while (src < end)
{
n = src[1];
*dst++ = *src++;
*dst++ = *src++;
for (i = 0; i < n; i++)
{
put_u16(dst, get_u32(src));
src += 4;
dst += 2;
}
}
return dst - dst0;
}
int
as_path_contains_as4(const struct adata *path)
{
const byte *pos = path->data;
const byte *end = pos + path->length;
uint i, n;
while (pos < end)
{
n = pos[1];
pos += 2;
for (i = 0; i < n; i++)
{
if (get_as(pos) > 0xFFFF)
return 1;
pos += BS;
}
}
return 0;
}
int
as_path_contains_confed(const struct adata *path)
{
const byte *pos = path->data;
const byte *end = pos + path->length;
while (pos < end)
{
uint type = pos[0];
uint slen = 2 + BS * pos[1];
if ((type == AS_PATH_CONFED_SEQUENCE) ||
(type == AS_PATH_CONFED_SET))
return 1;
pos += slen;
}
return 0;
}
static void
as_path_strip_confed_(byte *dst, const byte *src, uint len)
{
const byte *end = src + len;
while (src < end)
{
uint type = src[0];
uint slen = 2 + BS * src[1];
/* Copy regular segments */
if ((type == AS_PATH_SET) || (type == AS_PATH_SEQUENCE))
{
memcpy(dst, src, slen);
dst += slen;
}
src += slen;
}
}
struct adata *
as_path_strip_confed(struct linpool *pool, const struct adata *op)
{
struct adata *np = lp_alloc_adata(pool, op->length);
as_path_strip_confed_(np->data, op->data, op->length);
return np;
}
struct adata *
as_path_prepend2(struct linpool *pool, const struct adata *op, int seq, u32 as, int strip)
{
struct adata *np;
const byte *pos = op->data;
uint len = op->length;
if (len && (pos[0] == seq) && (pos[1] < 255))
{
/* Starting with matching segment => just prepend the AS number */
np = lp_alloc_adata(pool, len + BS);
np->data[0] = seq;
np->data[1] = pos[1] + 1;
put_as(np->data + 2, as);
uint dlen = BS * pos[1];
memcpy(np->data + 2 + BS, pos + 2, dlen);
ADVANCE(pos, len, 2 + dlen);
}
else
{
/* Create a new path segment */
np = lp_alloc_adata(pool, len + 2 + BS);
np->data[0] = seq;
np->data[1] = 1;
put_as(np->data + 2, as);
}
if (len)
{
byte *dst = np->data + 2 + BS * np->data[1];
if (strip)
as_path_strip_confed_(dst, pos, len);
else
memcpy(dst, pos, len);
}
return np;
}
struct adata *
as_path_to_old(struct linpool *pool, const struct adata *path)
{
struct adata *res = lp_alloc_adata(pool, path->length);
byte *pos = res->data;
byte *end = pos + res->length;
uint i, n;
u32 as;
/* Copy the whole path */
memcpy(res->data, path->data, path->length);
/* Replace 32-bit AS numbers with AS_TRANS */
while (pos < end)
{
n = pos[1];
pos += 2;
for (i = 0; i < n; i++)
{
as = get_as(pos);
if (as > 0xFFFF)
put_as(pos, AS_TRANS);
pos += BS;
}
}
return res;
}
/*
* Cut the path to the length @num, measured to the usual path metric. Note that
* AS_CONFED_* segments have zero length and must be added if they are on edge.
* In contrast to other as_path_* functions, @path is modified in place.
*/
void
as_path_cut(struct adata *path, uint num)
{
byte *pos = path->data;
byte *end = pos + path->length;
while (pos < end)
{
uint t = pos[0];
uint l = pos[1];
uint n = 0;
switch (t)
{
case AS_PATH_SET: n = 1; break;
case AS_PATH_SEQUENCE: n = l; break;
case AS_PATH_CONFED_SEQUENCE: n = 0; break;
case AS_PATH_CONFED_SET: n = 0; break;
default: bug("as_path_cut: Invalid path segment");
}
/* Cannot add whole segment, so try partial one and finish */
if (num < n)
{
if (num)
{
pos[1] = num;
pos += 2 + BS * num;
}
break;
}
num -= n;
pos += 2 + BS * l;
}
path->length = pos - path->data;
}
/*
* Merge (concatenate) paths @p1 and @p2 and return the result.
* In contrast to other as_path_* functions, @p1 and @p2 may be reused.
*/
struct adata *
as_path_merge(struct linpool *pool, struct adata *p1, struct adata *p2)
{
if (p1->length == 0)
return p2;
if (p2->length == 0)
return p1;
struct adata *res = lp_alloc_adata(pool, p1->length + p2->length);
memcpy(res->data, p1->data, p1->length);
memcpy(res->data + p1->length, p2->data, p2->length);
return res;
} }
void void
as_path_format(struct adata *path, byte *buf, uint size) as_path_format(const struct adata *path, byte *buf, uint size)
{ {
byte *p = path->data; const byte *p = path->data;
byte *e = p + path->length; const byte *e = p + path->length;
byte *end = buf + size - 16; byte *end = buf + size - 16;
int sp = 1; int sp = 1;
int l, isset; int l, isset;
@ -167,38 +368,41 @@ as_path_format(struct adata *path, byte *buf, uint size)
} }
int int
as_path_getlen(struct adata *path) as_path_getlen(const struct adata *path)
{ {
return as_path_getlen_int(path, BS); const byte *pos = path->data;
} const byte *end = pos + path->length;
uint res = 0;
int while (pos < end)
as_path_getlen_int(struct adata *path, int bs) {
{ uint t = pos[0];
int res = 0; uint l = pos[1];
u8 *p = path->data; uint n = 0;
u8 *q = p+path->length;
int len;
while (p<q) switch (t)
{ {
switch (*p++) case AS_PATH_SET: n = 1; break;
{ case AS_PATH_SEQUENCE: n = l; break;
case AS_PATH_SET: len = *p++; res++; p += bs * len; break; case AS_PATH_CONFED_SEQUENCE: n = 0; break;
case AS_PATH_SEQUENCE: len = *p++; res += len; p += bs * len; break; case AS_PATH_CONFED_SET: n = 0; break;
default: bug("as_path_getlen: Invalid path segment"); default: bug("as_path_getlen: Invalid path segment");
} }
res += n;
pos += 2 + BS * l;
} }
return res; return res;
} }
int int
as_path_get_last(struct adata *path, u32 *orig_as) as_path_get_last(const struct adata *path, u32 *orig_as)
{ {
int found = 0; int found = 0;
u32 res = 0; u32 res = 0;
u8 *p = path->data; const u8 *p = path->data;
u8 *q = p+path->length; const u8 *q = p+path->length;
int len; int len;
while (p<q) while (p<q)
@ -230,10 +434,10 @@ as_path_get_last(struct adata *path, u32 *orig_as)
} }
u32 u32
as_path_get_last_nonaggregated(struct adata *path) as_path_get_last_nonaggregated(const struct adata *path)
{ {
u8 *p = path->data; const u8 *p = path->data;
u8 *q = p+path->length; const u8 *q = p+path->length;
u32 res = 0; u32 res = 0;
int len; int len;
@ -257,11 +461,10 @@ as_path_get_last_nonaggregated(struct adata *path)
return res; return res;
} }
int int
as_path_get_first(struct adata *path, u32 *last_as) as_path_get_first(const struct adata *path, u32 *last_as)
{ {
u8 *p = path->data; const u8 *p = path->data;
if ((path->length == 0) || (p[0] != AS_PATH_SEQUENCE) || (p[1] == 0)) if ((path->length == 0) || (p[0] != AS_PATH_SEQUENCE) || (p[1] == 0))
return 0; return 0;
@ -273,10 +476,10 @@ as_path_get_first(struct adata *path, u32 *last_as)
} }
int int
as_path_contains(struct adata *path, u32 as, int min) as_path_contains(const struct adata *path, u32 as, int min)
{ {
u8 *p = path->data; const u8 *p = path->data;
u8 *q = p+path->length; const u8 *q = p+path->length;
int num = 0; int num = 0;
int i, n; int i, n;
@ -296,10 +499,10 @@ as_path_contains(struct adata *path, u32 as, int min)
} }
int int
as_path_match_set(struct adata *path, struct f_tree *set) as_path_match_set(const struct adata *path, struct f_tree *set)
{ {
u8 *p = path->data; const u8 *p = path->data;
u8 *q = p+path->length; const u8 *q = p+path->length;
int i, n; int i, n;
while (p<q) while (p<q)
@ -325,8 +528,8 @@ as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32
return NULL; return NULL;
int len = path->length; int len = path->length;
u8 *p = path->data; const u8 *p = path->data;
u8 *q = path->data + len; const u8 *q = path->data + len;
u8 *d, *d2; u8 *d, *d2;
int i, bt, sn, dn; int i, bt, sn, dn;
u8 buf[len]; u8 buf[len];
@ -388,16 +591,16 @@ struct pm_pos
u8 mark; u8 mark;
union union
{ {
char *sp; const char *sp;
u32 asn; u32 asn;
} val; } val;
}; };
static int static int
parse_path(struct adata *path, struct pm_pos *pos) parse_path(const struct adata *path, struct pm_pos *pos)
{ {
u8 *p = path->data; const u8 *p = path->data;
u8 *q = p + path->length; const u8 *q = p + path->length;
struct pm_pos *opos = pos; struct pm_pos *opos = pos;
int i, len; int i, len;
@ -433,7 +636,6 @@ parse_path(struct adata *path, struct pm_pos *pos)
return pos - opos; return pos - opos;
} }
static int static int
pm_match(struct pm_pos *pos, u32 asn, u32 asn2) pm_match(struct pm_pos *pos, u32 asn, u32 asn2)
{ {
@ -441,7 +643,7 @@ pm_match(struct pm_pos *pos, u32 asn, u32 asn2)
if (! pos->set) if (! pos->set)
return ((pos->val.asn >= asn) && (pos->val.asn <= asn2)); return ((pos->val.asn >= asn) && (pos->val.asn <= asn2));
u8 *p = pos->val.sp; const u8 *p = pos->val.sp;
int len = *p++; int len = *p++;
int i; int i;
@ -500,7 +702,7 @@ pm_mark(struct pm_pos *pos, int i, int plen, int *nl, int *nh)
* is marked. * is marked.
*/ */
int int
as_path_match(struct adata *path, struct f_path_mask *mask) as_path_match(const struct adata *path, struct f_path_mask *mask)
{ {
struct pm_pos pos[2048 + 1]; struct pm_pos pos[2048 + 1];
int plen = parse_path(path, pos); int plen = parse_path(path, pos);

View File

@ -7,6 +7,8 @@
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
#include <stdlib.h>
#include "nest/bird.h" #include "nest/bird.h"
#include "nest/route.h" #include "nest/route.h"
#include "nest/attrs.h" #include "nest/attrs.h"
@ -455,3 +457,85 @@ lc_set_union(struct linpool *pool, struct adata *l1, struct adata *l2)
memcpy(res->data + l1->length, tmp, len); memcpy(res->data + l1->length, tmp, len);
return res; return res;
} }
struct adata *
ec_set_del_nontrans(struct linpool *pool, struct adata *set)
{
adata *res = lp_alloc_adata(pool, set->length);
u32 *src = int_set_get_data(set);
u32 *dst = int_set_get_data(res);
int len = int_set_get_size(set);
int i;
/* Remove non-transitive communities (EC_TBIT set) */
for (i = 0; i < len; i += 2)
{
if (src[i] & EC_TBIT)
continue;
*dst++ = src[i];
*dst++ = src[i+1];
}
res->length = ((byte *) dst) - res->data;
return res;
}
static int
int_set_cmp(const void *X, const void *Y)
{
const u32 *x = X, *y = Y;
return (*x < *y) ? -1 : (*x > *y) ? 1 : 0;
}
struct adata *
int_set_sort(struct linpool *pool, struct adata *src)
{
struct adata *dst = lp_alloc_adata(pool, src->length);
memcpy(dst->data, src->data, src->length);
qsort(dst->data, dst->length / 4, 4, int_set_cmp);
return dst;
}
static int
ec_set_cmp(const void *X, const void *Y)
{
u64 x = ec_get(X, 0);
u64 y = ec_get(Y, 0);
return (x < y) ? -1 : (x > y) ? 1 : 0;
}
struct adata *
ec_set_sort(struct linpool *pool, struct adata *src)
{
struct adata *dst = lp_alloc_adata(pool, src->length);
memcpy(dst->data, src->data, src->length);
qsort(dst->data, dst->length / 8, 8, ec_set_cmp);
return dst;
}
static int
lc_set_cmp(const void *X, const void *Y)
{
const u32 *x = X, *y = Y;
if (x[0] != y[0])
return (x[0] > y[0]) ? 1 : -1;
if (x[1] != y[1])
return (x[1] > y[1]) ? 1 : -1;
if (x[2] != y[2])
return (x[2] > y[2]) ? 1 : -1;
return 0;
}
struct adata *
lc_set_sort(struct linpool *pool, struct adata *src)
{
struct adata *dst = lp_alloc_adata(pool, src->length);
memcpy(dst->data, src->data, src->length);
qsort(dst->data, dst->length / LCOMM_LENGTH, LCOMM_LENGTH, lc_set_cmp);
return dst;
}

View File

@ -10,6 +10,9 @@
#define _BIRD_ATTRS_H_ #define _BIRD_ATTRS_H_
#include <stdint.h> #include <stdint.h>
#include "lib/unaligned.h"
#include "nest/route.h"
/* a-path.c */ /* a-path.c */
@ -27,19 +30,29 @@
struct f_tree; struct f_tree;
struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, u32 as); int as_path_valid(byte *data, uint len, int bs, char *err, uint elen);
int as_path_convert_to_old(struct adata *path, byte *dst, int *new_used); int as_path_16to32(byte *dst, byte *src, uint len);
int as_path_convert_to_new(struct adata *path, byte *dst, int req_as); int as_path_32to16(byte *dst, byte *src, uint len);
void as_path_format(struct adata *path, byte *buf, uint size); int as_path_contains_as4(const struct adata *path);
int as_path_getlen(struct adata *path); int as_path_contains_confed(const struct adata *path);
int as_path_getlen_int(struct adata *path, int bs); struct adata *as_path_strip_confed(struct linpool *pool, const struct adata *op);
int as_path_get_first(struct adata *path, u32 *orig_as); struct adata *as_path_prepend2(struct linpool *pool, const struct adata *op, int seq, u32 as, int strip);
int as_path_get_last(struct adata *path, u32 *last_as); struct adata *as_path_to_old(struct linpool *pool, const struct adata *path);
u32 as_path_get_last_nonaggregated(struct adata *path); void as_path_cut(struct adata *path, uint num);
int as_path_contains(struct adata *path, u32 as, int min); struct adata *as_path_merge(struct linpool *pool, struct adata *p1, struct adata *p2);
int as_path_match_set(struct adata *path, struct f_tree *set); void as_path_format(const struct adata *path, byte *buf, uint size);
int as_path_getlen(const struct adata *path);
int as_path_getlen_int(const struct adata *path, int bs);
int as_path_get_first(const struct adata *path, u32 *orig_as);
int as_path_get_last(const struct adata *path, u32 *last_as);
u32 as_path_get_last_nonaggregated(const struct adata *path);
int as_path_contains(const struct adata *path, u32 as, int min);
int as_path_match_set(const struct adata *path, struct f_tree *set);
struct adata *as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos); struct adata *as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos);
static inline struct adata *as_path_prepend(struct linpool *pool, const struct adata *path, u32 as)
{ return as_path_prepend2(pool, path, AS_PATH_SEQUENCE, as, 0); }
#define PM_ASN 0 #define PM_ASN 0
#define PM_QUESTION 1 #define PM_QUESTION 1
@ -54,7 +67,42 @@ struct f_path_mask {
uintptr_t val2; uintptr_t val2;
}; };
int as_path_match(struct adata *path, struct f_path_mask *mask); int as_path_match(const struct adata *path, struct f_path_mask *mask);
/* Counterparts to appropriate as_path_* functions */
static inline int
aggregator_16to32(byte *dst, byte *src)
{
put_u32(dst, get_u16(src));
memcpy(dst+4, src+2, 4);
return 8;
}
static inline int
aggregator_32to16(byte *dst, byte *src)
{
put_u16(dst, get_u32(src));
memcpy(dst+2, src+4, 4);
return 6;
}
static inline int
aggregator_contains_as4(struct adata *a)
{
return get_u32(a->data) > 0xFFFF;
}
static inline struct adata *
aggregator_to_old(struct linpool *pool, struct adata *a)
{
struct adata *d = lp_alloc_adata(pool, 8);
put_u32(d->data, 0xFFFF);
memcpy(d->data + 4, a->data + 4, 4);
return d;
}
/* a-set.c */ /* a-set.c */
@ -142,5 +190,9 @@ struct adata *int_set_union(struct linpool *pool, struct adata *l1, struct adata
struct adata *ec_set_union(struct linpool *pool, struct adata *l1, struct adata *l2); struct adata *ec_set_union(struct linpool *pool, struct adata *l1, struct adata *l2);
struct adata *lc_set_union(struct linpool *pool, struct adata *l1, struct adata *l2); struct adata *lc_set_union(struct linpool *pool, struct adata *l1, struct adata *l2);
struct adata *ec_set_del_nontrans(struct linpool *pool, struct adata *set);
struct adata *int_set_sort(struct linpool *pool, struct adata *src);
struct adata *ec_set_sort(struct linpool *pool, struct adata *src);
struct adata *lc_set_sort(struct linpool *pool, struct adata *src);
#endif #endif

View File

@ -80,7 +80,6 @@ print_size(char *dsc, size_t val)
extern pool *rt_table_pool; extern pool *rt_table_pool;
extern pool *rta_pool; extern pool *rta_pool;
extern pool *proto_pool;
void void
cmd_show_memory(void) cmd_show_memory(void)

View File

@ -39,7 +39,7 @@ static int graceful_restart_state;
static u32 graceful_restart_locks; static u32 graceful_restart_locks;
static char *p_states[] = { "DOWN", "START", "UP", "STOP" }; static char *p_states[] = { "DOWN", "START", "UP", "STOP" };
static char *c_states[] UNUSED = { "DOWN", "START", "UP", "FLUSHING" }; static char *c_states[] = { "DOWN", "START", "UP", "FLUSHING" };
extern struct protocol proto_unix_iface; extern struct protocol proto_unix_iface;
@ -304,6 +304,8 @@ channel_do_down(struct channel *c)
memset(&c->stats, 0, sizeof(struct proto_stats)); memset(&c->stats, 0, sizeof(struct proto_stats));
CALL(c->channel->cleanup, c);
/* Schedule protocol shutddown */ /* Schedule protocol shutddown */
if (proto_is_done(c->proto)) if (proto_is_done(c->proto))
ev_schedule(c->proto->event); ev_schedule(c->proto->event);
@ -514,7 +516,9 @@ channel_reconfigure(struct channel *c, struct channel_config *cf)
channel_verify_limits(c); channel_verify_limits(c);
CALL(c->channel->reconfigure, c, cf); /* Execute channel-specific reconfigure hook */
if (c->channel->reconfigure && !c->channel->reconfigure(c, cf))
return 0;
/* If the channel is not open, it has no routes and we cannot reload it anyways */ /* If the channel is not open, it has no routes and we cannot reload it anyways */
if (c->channel_state != CS_UP) if (c->channel_state != CS_UP)
@ -797,7 +801,6 @@ proto_reconfigure(struct proto *p, struct proto_config *oc, struct proto_config
if ((nc->protocol != oc->protocol) || if ((nc->protocol != oc->protocol) ||
(nc->net_type != oc->net_type) || (nc->net_type != oc->net_type) ||
(nc->disabled != p->disabled)) (nc->disabled != p->disabled))
return 0; return 0;
p->name = nc->name; p->name = nc->name;
@ -1575,6 +1578,7 @@ void
channel_show_info(struct channel *c) channel_show_info(struct channel *c)
{ {
cli_msg(-1006, " Channel %s", c->name); cli_msg(-1006, " Channel %s", c->name);
cli_msg(-1006, " State: %s", c_states[c->channel_state]);
cli_msg(-1006, " Table: %s", c->table->name); cli_msg(-1006, " Table: %s", c->table->name);
cli_msg(-1006, " Preference: %d", c->preference); cli_msg(-1006, " Preference: %d", c->preference);
cli_msg(-1006, " Input filter: %s", filter_name(c->in_filter)); cli_msg(-1006, " Input filter: %s", filter_name(c->in_filter));

View File

@ -273,6 +273,7 @@ proto_get_router_id(struct proto_config *pc)
/* Moved from route.h to avoid dependency conflicts */ /* Moved from route.h to avoid dependency conflicts */
static inline void rte_update(struct proto *p, net_addr *n, rte *new) { rte_update2(p->main_channel, n, new, p->main_source); } static inline void rte_update(struct proto *p, net_addr *n, rte *new) { rte_update2(p->main_channel, n, new, p->main_source); }
extern pool *proto_pool;
extern list proto_list; extern list proto_list;
/* /*
@ -418,20 +419,22 @@ struct channel_class {
uint channel_size; /* Size of channel data structure */ uint channel_size; /* Size of channel data structure */
uint config_size; /* Size of channel config data structure */ uint config_size; /* Size of channel config data structure */
struct channel * (*init)(struct channel *, struct channel_config *); /* Create new instance */ void (*init)(struct channel *, struct channel_config *); /* Create new instance */
int (*reconfigure)(struct channel *, struct channel_config *); /* Try to reconfigure instance, returns success */ int (*reconfigure)(struct channel *, struct channel_config *); /* Try to reconfigure instance, returns success */
int (*start)(struct channel *); /* Start the instance */ int (*start)(struct channel *); /* Start the instance */
int (*shutdown)(struct channel *); /* Stop the instance */ void (*shutdown)(struct channel *); /* Stop the instance */
void (*cleanup)(struct channel *); /* Channel finished flush */
void (*copy_config)(struct channel_config *, struct channel_config *); /* Copy config from given channel instance */ void (*copy_config)(struct channel_config *, struct channel_config *); /* Copy config from given channel instance */
#if 0 #if 0
XXXX;
void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */ void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
void (*postconfig)(struct proto_config *); /* After configuring each instance */ void (*postconfig)(struct proto_config *); /* After configuring each instance */
void (*dump)(struct proto *); /* Debugging dump */ void (*dump)(struct proto *); /* Debugging dump */
void (*dump_attrs)(struct rte *); /* Dump protocol-dependent attributes */ void (*dump_attrs)(struct rte *); /* Dump protocol-dependent attributes */
void (*cleanup)(struct proto *); /* Called after shutdown when protocol became hungry/down */
void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */ void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
void (*get_route_info)(struct rte *, byte *buf, struct ea_list *attrs); /* Get route information (for `show route' command) */ void (*get_route_info)(struct rte *, byte *buf, struct ea_list *attrs); /* Get route information (for `show route' command) */
int (*get_attr)(struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */ int (*get_attr)(struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */
@ -440,6 +443,8 @@ struct channel_class {
#endif #endif
}; };
extern struct channel_class channel_bgp;
struct channel_config { struct channel_config {
node n; node n;
const char *name; const char *name;
@ -484,6 +489,7 @@ struct channel {
u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */ u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
u8 in_keep_filtered; /* Routes rejected in import filter are kept */ u8 in_keep_filtered; /* Routes rejected in import filter are kept */
u8 disabled; u8 disabled;
u8 stale; /* Used in reconfiguration */
u8 channel_state; u8 channel_state;
u8 export_state; /* Route export state (ES_*, see below) */ u8 export_state; /* Route export state (ES_*, see below) */

View File

@ -457,13 +457,22 @@ typedef struct eattr {
#define EAF_TYPE_UNDEF 0x1f /* `force undefined' entry */ #define EAF_TYPE_UNDEF 0x1f /* `force undefined' entry */
#define EAF_EMBEDDED 0x01 /* Data stored in eattr.u.data (part of type spec) */ #define EAF_EMBEDDED 0x01 /* Data stored in eattr.u.data (part of type spec) */
#define EAF_VAR_LENGTH 0x02 /* Attribute length is variable (part of type spec) */ #define EAF_VAR_LENGTH 0x02 /* Attribute length is variable (part of type spec) */
#define EAF_ORIGINATED 0x40 /* The attribute has originated locally */ #define EAF_ORIGINATED 0x20 /* The attribute has originated locally */
#define EAF_FRESH 0x40 /* An uncached attribute (e.g. modified in export filter) */
#define EAF_TEMP 0x80 /* A temporary attribute (the one stored in the tmp attr list) */ #define EAF_TEMP 0x80 /* A temporary attribute (the one stored in the tmp attr list) */
struct adata { typedef struct adata {
uint length; /* Length of data */ uint length; /* Length of data */
byte data[0]; byte data[0];
}; } adata;
static inline struct adata *
lp_alloc_adata(struct linpool *pool, uint len)
{
struct adata *ad = lp_alloc(pool, sizeof(struct adata) + len);
ad->length = len;
return ad;
}
static inline int adata_same(struct adata *a, struct adata *b) static inline int adata_same(struct adata *a, struct adata *b)
{ return (a->length == b->length && !memcmp(a->data, b->data, a->length)); } { return (a->length == b->length && !memcmp(a->data, b->data, a->length)); }
@ -523,7 +532,7 @@ static inline rta * rta_cow(rta *r, linpool *lp) { return rta_is_cached(r) ? rta
void rta_dump(rta *); void rta_dump(rta *);
void rta_dump_all(void); void rta_dump_all(void);
void rta_show(struct cli *, rta *, ea_list *); void rta_show(struct cli *, rta *, ea_list *);
void rta_set_recursive_next_hop(rtable *dep, rta *a, rtable *tab, ip_addr *gw, ip_addr *ll); void rta_set_recursive_next_hop(rtable *dep, rta *a, rtable *tab, ip_addr gw, ip_addr ll);
/* /*
* rta_set_recursive_next_hop() acquires hostentry from hostcache and fills * rta_set_recursive_next_hop() acquires hostentry from hostcache and fills

View File

@ -528,7 +528,7 @@ ea_do_prune(ea_list *e)
if ((s0->type & EAF_TYPE_MASK) != EAF_TYPE_UNDEF) if ((s0->type & EAF_TYPE_MASK) != EAF_TYPE_UNDEF)
{ {
*d = *s0; *d = *s0;
d->type = (d->type & ~EAF_ORIGINATED) | (s[-1].type & EAF_ORIGINATED); d->type = (d->type & ~(EAF_ORIGINATED|EAF_FRESH)) | (s[-1].type & EAF_ORIGINATED);
d++; d++;
i++; i++;
} }

View File

@ -2426,9 +2426,9 @@ rt_get_hostentry(rtable *tab, ip_addr a, ip_addr ll, rtable *dep)
} }
void void
rta_set_recursive_next_hop(rtable *dep, rta *a, rtable *tab, ip_addr *gw, ip_addr *ll) rta_set_recursive_next_hop(rtable *dep, rta *a, rtable *tab, ip_addr gw, ip_addr ll)
{ {
rta_apply_hostentry(a, rt_get_hostentry(tab, *gw, *ll, dep)); rta_apply_hostentry(a, rt_get_hostentry(tab, gw, ipa_zero(ll) ? gw : ll, dep));
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,8 @@
* BIRD -- The Border Gateway Protocol * BIRD -- The Border Gateway Protocol
* *
* (c) 2000 Martin Mares <mj@ucw.cz> * (c) 2000 Martin Mares <mj@ucw.cz>
* (c) 2008--2016 Ondrej Zajicek <santiago@crfreenet.org>
* (c) 2008--2016 CZ.NIC z.s.p.o.
* *
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
@ -10,26 +12,66 @@
#define _BIRD_BGP_H_ #define _BIRD_BGP_H_
#include <stdint.h> #include <stdint.h>
#include <setjmp.h>
#include "nest/bird.h"
#include "nest/route.h" #include "nest/route.h"
#include "nest/bfd.h" #include "nest/bfd.h"
//#include "lib/lists.h"
#include "lib/hash.h" #include "lib/hash.h"
#include "lib/socket.h"
struct linpool; struct linpool;
struct eattr; struct eattr;
/* Address families */
#define BGP_AFI_IPV4 1
#define BGP_AFI_IPV6 2
#define BGP_SAFI_UNICAST 1
#define BGP_SAFI_MULTICAST 2
/* Internal AF codes */
#define BGP_AF(A, B) (((u32)(A) << 16) | (u32)(B))
#define BGP_AFI(A) ((u32)(A) >> 16)
#define BGP_SAFI(A) ((u32)(A) & 0xFFFF)
#define BGP_AF_IPV4 BGP_AF( BGP_AFI_IPV4, BGP_SAFI_UNICAST )
#define BGP_AF_IPV6 BGP_AF( BGP_AFI_IPV6, BGP_SAFI_UNICAST )
#define BGP_AF_IPV4_MC BGP_AF( BGP_AFI_IPV4, BGP_SAFI_MULTICAST )
#define BGP_AF_IPV6_MC BGP_AF( BGP_AFI_IPV6, BGP_SAFI_MULTICAST )
struct bgp_write_state;
struct bgp_parse_state;
struct bgp_export_state;
struct bgp_bucket;
struct bgp_af_desc {
u32 afi;
u32 net;
const char *name;
uint (*encode_nlri)(struct bgp_write_state *s, struct bgp_bucket *buck, byte *buf, uint size);
void (*decode_nlri)(struct bgp_parse_state *s, byte *pos, uint len, rta *a);
void (*update_next_hop)(struct bgp_export_state *s, eattr *nh, ea_list **to);
uint (*encode_next_hop)(struct bgp_write_state *s, eattr *nh, byte *buf, uint size);
void (*decode_next_hop)(struct bgp_parse_state *s, byte *pos, uint len, rta *a);
};
struct bgp_config { struct bgp_config {
struct proto_config c; struct proto_config c;
u32 local_as, remote_as; u32 local_as, remote_as;
ip_addr local_ip; /* Source address to use */
ip_addr remote_ip; ip_addr remote_ip;
ip_addr source_addr; /* Source address to use */
struct iface *iface; /* Interface for link-local addresses */ struct iface *iface; /* Interface for link-local addresses */
u16 local_port; /* Local listening port */
u16 remote_port; /* Neighbor destination port */ u16 remote_port; /* Neighbor destination port */
int multihop; /* Number of hops if multihop */ int multihop; /* Number of hops if multihop */
int ttl_security; /* Enable TTL security [RFC5082] */ int strict_bind; /* Bind listening socket to local address XXXX */
int next_hop_self; /* Always set next hop to local IP address */ int ttl_security; /* Enable TTL security [RFC 5082] */
int next_hop_keep; /* Do not touch next hop attribute */
int missing_lladdr; /* What we will do when we don' know link-local addr, see MLL_* */
int gw_mode; /* How we compute route gateway from next_hop attr, see GW_* */
int compare_path_lengths; /* Use path lengths when selecting best route */ int compare_path_lengths; /* Use path lengths when selecting best route */
int med_metric; /* Compare MULTI_EXIT_DISC even between routes from differen ASes */ int med_metric; /* Compare MULTI_EXIT_DISC even between routes from differen ASes */
int igp_metric; /* Use IGP metrics when selecting best route */ int igp_metric; /* Use IGP metrics when selecting best route */
@ -37,18 +79,17 @@ struct bgp_config {
int deterministic_med; /* Use more complicated algo to have strict RFC 4271 MED comparison */ int deterministic_med; /* Use more complicated algo to have strict RFC 4271 MED comparison */
u32 default_local_pref; /* Default value for LOCAL_PREF attribute */ u32 default_local_pref; /* Default value for LOCAL_PREF attribute */
u32 default_med; /* Default value for MULTI_EXIT_DISC attribute */ u32 default_med; /* Default value for MULTI_EXIT_DISC attribute */
int capabilities; /* Enable capability handshake [RFC3392] */ int capabilities; /* Enable capability handshake [RFC 3392] */
int enable_refresh; /* Enable local support for route refresh [RFC2918] */ int enable_refresh; /* Enable local support for route refresh [RFC 2918] */
int enable_as4; /* Enable local support for 4B AS numbers [RFC4893] */ int enable_as4; /* Enable local support for 4B AS numbers [RFC 4893] */
int enable_extended_messages; /* Enable local support for extended messages [draft] */ int enable_extended_messages; /* Enable local support for extended messages [draft] */
u32 rr_cluster_id; /* Route reflector cluster ID, if different from local ID */ u32 rr_cluster_id; /* Route reflector cluster ID, if different from local ID */
int rr_client; /* Whether neighbor is RR client of me */ int rr_client; /* Whether neighbor is RR client of me */
int rs_client; /* Whether neighbor is RS client of me */ int rs_client; /* Whether neighbor is RS client of me */
int advertise_ipv4; /* Whether we should add IPv4 capability advertisement to OPEN message */ u32 confederation; /* Confederation ID, or zero if confeds not active */
int confederation_member; /* Whether neighbor AS is member of our confederation */
int passive; /* Do not initiate outgoing connection */ int passive; /* Do not initiate outgoing connection */
int interpret_communities; /* Hardwired handling of well-known communities */ int interpret_communities; /* Hardwired handling of well-known communities */
int secondary; /* Accept also non-best routes (i.e. RA_ACCEPTED) */
int add_path; /* Use ADD-PATH extension [draft] */
int allow_local_as; /* Allow that number of local ASNs in incoming AS_PATHs */ int allow_local_as; /* Allow that number of local ASNs in incoming AS_PATHs */
int gr_mode; /* Graceful restart mode (BGP_GR_*) */ int gr_mode; /* Graceful restart mode (BGP_GR_*) */
int setkey; /* Set MD5 password to system SA/SP database */ int setkey; /* Set MD5 password to system SA/SP database */
@ -63,11 +104,27 @@ struct bgp_config {
unsigned disable_after_error; /* Disable the protocol when error is detected */ unsigned disable_after_error; /* Disable the protocol when error is detected */
char *password; /* Password used for MD5 authentication */ char *password; /* Password used for MD5 authentication */
struct rtable_config *igp_table; /* Table used for recursive next hop lookups */
int check_link; /* Use iface link state for liveness detection */ int check_link; /* Use iface link state for liveness detection */
int bfd; /* Use BFD for liveness detection */ int bfd; /* Use BFD for liveness detection */
}; };
struct bgp_channel_config {
struct channel_config c;
u32 afi;
ip_addr next_hop_addr; /* Local address for NEXT_HOP attribute */
u8 next_hop_self; /* Always set next hop to local IP address */
u8 next_hop_keep; /* Do not touch next hop attribute */
u8 missing_lladdr; /* What we will do when we don' know link-local addr, see MLL_* */
u8 gw_mode; /* How we compute route gateway from next_hop attr, see GW_* */
u8 secondary; /* Accept also non-best routes (i.e. RA_ACCEPTED) */
u8 gr_able; /* Allow full graceful restart for the channel */
u8 add_path; /* Use ADD-PATH extension [RFC 7911] */
struct rtable_config *igp_table; /* Table used for recursive next hop lookups */
};
#define MLL_SELF 1 #define MLL_SELF 1
#define MLL_DROP 2 #define MLL_DROP 2
#define MLL_IGNORE 3 #define MLL_IGNORE 3
@ -75,112 +132,226 @@ struct bgp_config {
#define GW_DIRECT 1 #define GW_DIRECT 1
#define GW_RECURSIVE 2 #define GW_RECURSIVE 2
#define ADD_PATH_RX 1 #define BGP_ADD_PATH_RX 1
#define ADD_PATH_TX 2 #define BGP_ADD_PATH_TX 2
#define ADD_PATH_FULL 3 #define BGP_ADD_PATH_FULL 3
#define BGP_GR_ABLE 1 #define BGP_GR_ABLE 1
#define BGP_GR_AWARE 2 #define BGP_GR_AWARE 2
/* For peer_gr_flags */ /* For GR capability common flags */
#define BGP_GRF_RESTART 0x80 #define BGP_GRF_RESTART 0x80
/* For peer_gr_aflags */ /* For GR capability per-AF flags */
#define BGP_GRF_FORWARDING 0x80 #define BGP_GRF_FORWARDING 0x80
struct bgp_af_caps {
u32 afi;
u8 ready; /* Multiprotocol capability, RFC 4760 */
u8 gr_able; /* Graceful restart support, RFC 4724 */
u8 gr_af_flags; /* Graceful restart per-AF flags */
u8 add_path; /* Multiple paths support, RFC 7911 */
};
struct bgp_caps {
u32 as4_number; /* Announced ASN */
u8 as4_support; /* Four-octet AS capability, RFC 6793 */
u8 ext_messages; /* Extended message length, RFC draft */
u8 route_refresh; /* Route refresh capability, RFC 2918 */
u8 enhanced_refresh; /* Enhanced route refresh, RFC 7313 */
u8 gr_aware; /* Graceful restart capability, RFC 4724 */
u8 gr_flags; /* Graceful restart flags */
u16 gr_time; /* Graceful restart time in seconds */
u16 af_count; /* Number of af_data items */
struct bgp_af_caps af_data[0]; /* Per-AF capability data */
};
struct bgp_socket {
node n; /* Node in global bgp_sockets */
sock *sk; /* Real listening socket */
u32 uc; /* Use count */
};
struct bgp_conn { struct bgp_conn {
struct bgp_proto *bgp; struct bgp_proto *bgp;
struct birdsock *sk; struct birdsock *sk;
uint state; /* State of connection state machine */ u8 state; /* State of connection state machine */
struct timer *connect_retry_timer; u8 as4_session; /* Session uses 4B AS numbers in AS_PATH (both sides support it) */
u8 ext_messages; /* Session uses extended message length */
struct bgp_caps *local_caps;
struct bgp_caps *remote_caps;
struct timer *connect_timer;
struct timer *hold_timer; struct timer *hold_timer;
struct timer *keepalive_timer; struct timer *keepalive_timer;
struct event *tx_ev; struct event *tx_ev;
int packets_to_send; /* Bitmap of packet types to be sent */ u32 packets_to_send; /* Bitmap of packet types to be sent */
u32 channels_to_send; /* Bitmap of channels with packets to be sent */
u8 last_channel; /* Channel used last time for TX */
u8 last_channel_count; /* Number of times the last channel was used in succession */
int notify_code, notify_subcode, notify_size; int notify_code, notify_subcode, notify_size;
byte *notify_data; byte *notify_data;
u32 advertised_as; /* Temporary value for AS number received */
int start_state; /* protocol start_state snapshot when connection established */ uint hold_time, keepalive_time; /* Times calculated from my and neighbor's requirements */
u8 peer_refresh_support; /* Peer supports route refresh [RFC2918] */
u8 peer_as4_support; /* Peer supports 4B AS numbers [RFC4893] */
u8 peer_add_path; /* Peer supports ADD-PATH [draft] */
u8 peer_enhanced_refresh_support; /* Peer supports enhanced refresh [RFC7313] */
u8 peer_gr_aware;
u8 peer_gr_able;
u16 peer_gr_time;
u8 peer_gr_flags;
u8 peer_gr_aflags;
u8 peer_ext_messages_support; /* Peer supports extended message length [draft] */
unsigned hold_time, keepalive_time; /* Times calculated from my and neighbor's requirements */
}; };
struct bgp_proto { struct bgp_proto {
struct proto p; struct proto p;
struct bgp_config *cf; /* Shortcut to BGP configuration */ struct bgp_config *cf; /* Shortcut to BGP configuration */
u32 local_as, remote_as; u32 local_as, remote_as;
int start_state; /* Substates that partitions BS_START */ u32 public_as; /* Externally visible ASN (local_as or confederation id) */
u8 is_internal; /* Internal BGP connection (local_as == remote_as) */
u8 as4_session; /* Session uses 4B AS numbers in AS_PATH (both sides support it) */
u8 add_path_rx; /* Session expects receive of ADD-PATH extended NLRI */
u8 add_path_tx; /* Session expects transmit of ADD-PATH extended NLRI */
u8 ext_messages; /* Session allows to use extended messages (both sides support it) */
u32 local_id; /* BGP identifier of this router */ u32 local_id; /* BGP identifier of this router */
u32 remote_id; /* BGP identifier of the neighbor */ u32 remote_id; /* BGP identifier of the neighbor */
u32 rr_cluster_id; /* Route reflector cluster ID */ u32 rr_cluster_id; /* Route reflector cluster ID */
int rr_client; /* Whether neighbor is RR client of me */ int start_state; /* Substates that partitions BS_START */
int rs_client; /* Whether neighbor is RS client of me */ u8 is_internal; /* Internal BGP session (local_as == remote_as) */
u8 is_interior; /* Internal or intra-confederation BGP session */
u8 as4_session; /* Session uses 4B AS numbers in AS_PATH (both sides support it) */
u8 rr_client; /* Whether neighbor is RR client of me */
u8 rs_client; /* Whether neighbor is RS client of me */
u8 route_refresh; /* Route refresh allowed to send [RFC 2918] */
u8 enhanced_refresh; /* Enhanced refresh is negotiated [RFC 7313] */
u8 gr_ready; /* Neighbor could do graceful restart */ u8 gr_ready; /* Neighbor could do graceful restart */
u8 gr_active; /* Neighbor is doing graceful restart */ u8 gr_active_num; /* Neighbor is doing GR, number of active channels */
u8 feed_state; /* Feed state (TX) for EoR, RR packets, see BFS_* */ u8 channel_count; /* Number of active channels */
u8 load_state; /* Load state (RX) for EoR, RR packets, see BFS_* */ u32 *afi_map; /* Map channel index -> AFI */
struct bgp_channel **channel_map; /* Map channel index -> channel */
struct bgp_conn *conn; /* Connection we have established */ struct bgp_conn *conn; /* Connection we have established */
struct bgp_conn outgoing_conn; /* Outgoing connection we're working with */ struct bgp_conn outgoing_conn; /* Outgoing connection we're working with */
struct bgp_conn incoming_conn; /* Incoming connection we have neither accepted nor rejected yet */ struct bgp_conn incoming_conn; /* Incoming connection we have neither accepted nor rejected yet */
struct object_lock *lock; /* Lock for neighbor connection */ struct object_lock *lock; /* Lock for neighbor connection */
struct neighbor *neigh; /* Neighbor entry corresponding to remote ip, NULL if multihop */ struct neighbor *neigh; /* Neighbor entry corresponding to remote ip, NULL if multihop */
struct bgp_socket *sock; /* Shared listening socket */
struct bfd_request *bfd_req; /* BFD request, if BFD is used */ struct bfd_request *bfd_req; /* BFD request, if BFD is used */
ip_addr source_addr; /* Local address used as an advertised next hop */ ip_addr source_addr; /* Local address used as an advertised next hop */
rtable *igp_table; /* Table used for recursive next hop lookups */ ip_addr link_addr; /* Link-local version of source_addr */
struct event *event; /* Event for respawning and shutting process */ struct event *event; /* Event for respawning and shutting process */
struct timer *startup_timer; /* Timer used to delay protocol startup due to previous errors (startup_delay) */ struct timer *startup_timer; /* Timer used to delay protocol startup due to previous errors (startup_delay) */
struct timer *gr_timer; /* Timer waiting for reestablishment after graceful restart */ struct timer *gr_timer; /* Timer waiting for reestablishment after graceful restart */
struct bgp_bucket **bucket_hash; /* Hash table of attribute buckets */
uint hash_size, hash_count, hash_limit;
HASH(struct bgp_prefix) prefix_hash; /* Prefixes to be sent */
slab *prefix_slab; /* Slab holding prefix nodes */
list bucket_queue; /* Queue of buckets to send */
struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */
unsigned startup_delay; /* Time to delay protocol startup by due to errors */ unsigned startup_delay; /* Time to delay protocol startup by due to errors */
bird_clock_t last_proto_error; /* Time of last error that leads to protocol stop */ bird_clock_t last_proto_error; /* Time of last error that leads to protocol stop */
u8 last_error_class; /* Error class of last error */ u8 last_error_class; /* Error class of last error */
u32 last_error_code; /* Error code of last error. BGP protocol errors u32 last_error_code; /* Error code of last error. BGP protocol errors
are encoded as (bgp_err_code << 16 | bgp_err_subcode) */ are encoded as (bgp_err_code << 16 | bgp_err_subcode) */
#ifdef IPV6 };
byte *mp_reach_start, *mp_unreach_start; /* Multiprotocol BGP attribute notes */
unsigned mp_reach_len, mp_unreach_len; struct bgp_channel {
ip_addr local_link; /* Link-level version of source_addr */ struct channel c;
#endif
/* Rest are BGP specific data */
struct bgp_channel_config *cf;
pool *pool; /* XXXX */
u32 afi;
u32 index;
const struct bgp_af_desc *desc;
HASH(struct bgp_bucket) bucket_hash; /* Hash table of route buckets */
struct bgp_bucket *withdraw_bucket; /* Withdrawn routes */
list bucket_queue; /* Queue of buckets to send (struct bgp_bucket) */
HASH(struct bgp_prefix) prefix_hash; /* Prefixes to be sent */
slab *prefix_slab; /* Slab holding prefix nodes */
rtable *igp_table; /* Table used for recursive next hop lookups */
ip_addr next_hop_addr; /* Local address for NEXT_HOP attribute */
ip_addr link_addr; /* Link-local version of next_hop_addr */
u32 packets_to_send; /* Bitmap of packet types to be sent */
u8 gr_ready; /* Neighbor could do GR on this AF */
u8 gr_active; /* Neighbor is doing GR and keeping fwd state */
u8 add_path_rx; /* Session expects receive of ADD-PATH extended NLRI */
u8 add_path_tx; /* Session expects transmit of ADD-PATH extended NLRI */
u8 feed_state; /* Feed state (TX) for EoR, RR packets, see BFS_* */
u8 load_state; /* Load state (RX) for EoR, RR packets, see BFS_* */
}; };
struct bgp_prefix { struct bgp_prefix {
struct { node buck_node; /* Node in per-bucket list */
ip_addr prefix; struct bgp_prefix *next; /* Node in prefix hash table */
int pxlen; u32 hash;
} n;
u32 path_id; u32 path_id;
struct bgp_prefix *next; net_addr net[0];
node bucket_node; /* Node in per-bucket list */
}; };
struct bgp_bucket { struct bgp_bucket {
node send_node; /* Node in send queue */ node send_node; /* Node in send queue */
struct bgp_bucket *hash_next, *hash_prev; /* Node in bucket hash table */ struct bgp_bucket *next; /* Node in bucket hash table */
unsigned hash; /* Hash over extended attributes */ list prefixes; /* Prefixes in this bucket (struct bgp_prefix) */
list prefixes; /* Prefixes in this buckets */ u32 hash; /* Hash over extended attributes */
ea_list eattrs[0]; /* Per-bucket extended attributes */ ea_list eattrs[0]; /* Per-bucket extended attributes */
}; };
struct bgp_export_state {
struct bgp_proto *proto;
struct bgp_channel *channel;
struct linpool *pool;
struct bgp_proto *src;
rte *route;
u32 attrs_seen[1];
uint err_withdraw;
};
struct bgp_write_state {
struct bgp_proto *proto;
struct bgp_channel *channel;
struct linpool *pool;
int as4_session;
int add_path;
eattr *mp_next_hop;
};
struct bgp_parse_state {
struct bgp_proto *proto;
struct bgp_channel *channel;
struct linpool *pool;
int as4_session;
int add_path;
u32 attrs_seen[256/32];
u32 mp_reach_af;
u32 mp_unreach_af;
uint attr_len;
uint ip_reach_len;
uint ip_unreach_len;
uint ip_next_hop_len;
uint mp_reach_len;
uint mp_unreach_len;
uint mp_next_hop_len;
byte *attrs;
byte *ip_reach_nlri;
byte *ip_unreach_nlri;
byte *ip_next_hop_data;
byte *mp_reach_nlri;
byte *mp_unreach_nlri;
byte *mp_next_hop_data;
uint err_withdraw;
uint err_subcode;
jmp_buf err_jmpbuf;
/* Cached state for bgp_rte_update() */
u32 last_id;
struct rte_src *last_src;
rta *cached_rta;
};
#define BGP_PORT 179 #define BGP_PORT 179
#define BGP_VERSION 4 #define BGP_VERSION 4
#define BGP_HEADER_LENGTH 19 #define BGP_HEADER_LENGTH 19
@ -191,8 +362,21 @@ struct bgp_bucket {
#define BGP_RX_BUFFER_EXT_SIZE 65535 #define BGP_RX_BUFFER_EXT_SIZE 65535
#define BGP_TX_BUFFER_EXT_SIZE 65535 #define BGP_TX_BUFFER_EXT_SIZE 65535
static inline uint bgp_max_packet_length(struct bgp_proto *p) static inline int bgp_channel_is_ipv4(struct bgp_channel *c)
{ return p->ext_messages ? BGP_MAX_EXT_MSG_LENGTH : BGP_MAX_MESSAGE_LENGTH; } { return BGP_AFI(c->afi) == BGP_AFI_IPV4; }
static inline int bgp_channel_is_ipv6(struct bgp_channel *c)
{ return BGP_AFI(c->afi) == BGP_AFI_IPV6; }
static inline uint bgp_max_packet_length(struct bgp_conn *conn)
{ return conn->ext_messages ? BGP_MAX_EXT_MSG_LENGTH : BGP_MAX_MESSAGE_LENGTH; }
static inline void
bgp_parse_error(struct bgp_parse_state *s, uint subcode)
{
s->err_subcode = subcode;
longjmp(s->err_jmpbuf, 1);
}
extern struct linpool *bgp_linpool; extern struct linpool *bgp_linpool;
@ -207,9 +391,9 @@ void bgp_conn_enter_established_state(struct bgp_conn *conn);
void bgp_conn_enter_close_state(struct bgp_conn *conn); void bgp_conn_enter_close_state(struct bgp_conn *conn);
void bgp_conn_enter_idle_state(struct bgp_conn *conn); void bgp_conn_enter_idle_state(struct bgp_conn *conn);
void bgp_handle_graceful_restart(struct bgp_proto *p); void bgp_handle_graceful_restart(struct bgp_proto *p);
void bgp_graceful_restart_done(struct bgp_proto *p); void bgp_graceful_restart_done(struct bgp_channel *c);
void bgp_refresh_begin(struct bgp_proto *p); void bgp_refresh_begin(struct bgp_channel *c);
void bgp_refresh_end(struct bgp_proto *p); void bgp_refresh_end(struct bgp_channel *c);
void bgp_store_error(struct bgp_proto *p, struct bgp_conn *c, u8 class, u32 code); void bgp_store_error(struct bgp_proto *p, struct bgp_conn *c, u8 class, u32 code);
void bgp_stop(struct bgp_proto *p, unsigned subcode); void bgp_stop(struct bgp_proto *p, unsigned subcode);
@ -232,46 +416,83 @@ struct rte_source *bgp_get_source(struct bgp_proto *p, u32 path_id);
/* attrs.c */ /* attrs.c */
static inline eattr *
bgp_find_attr(ea_list *attrs, uint code)
{
return ea_find(attrs, EA_CODE(EAP_BGP, code));
}
eattr *
bgp_set_attr(ea_list **attrs, struct linpool *pool, uint code, uint flags, uintptr_t val);
static inline void
bgp_set_attr_u32(ea_list **to, struct linpool *pool, uint code, uint flags, u32 val)
{ bgp_set_attr(to, pool, code, flags, (uintptr_t) val); }
static inline void
bgp_set_attr_ptr(ea_list **to, struct linpool *pool, uint code, uint flags, struct adata *val)
{ bgp_set_attr(to, pool, code, flags, (uintptr_t) val); }
static inline void
bgp_set_attr_data(ea_list **to, struct linpool *pool, uint code, uint flags, void *data, uint len)
{
struct adata *a = lp_alloc_adata(pool, len);
memcpy(a->data, data, len);
bgp_set_attr(to, pool, code, flags, (uintptr_t) a);
}
static inline void
bgp_unset_attr(ea_list **to, struct linpool *pool, uint code)
{ eattr *e = bgp_set_attr(to, pool, code, 0, 0); e->type = EAF_TYPE_UNDEF; }
/* Hack: although BA_NEXT_HOP attribute has type EAF_TYPE_IP_ADDRESS, in IPv6 /* Hack: although BA_NEXT_HOP attribute has type EAF_TYPE_IP_ADDRESS, in IPv6
* we store two addesses in it - a global address and a link local address. * we store two addesses in it - a global address and a link local address.
*/ */
#ifdef IPV6 #ifdef XXX
#define NEXT_HOP_LENGTH (2*sizeof(ip_addr)) #define NEXT_HOP_LENGTH (2*sizeof(ip_addr))
static inline void set_next_hop(byte *b, ip_addr addr) { ((ip_addr *) b)[0] = addr; ((ip_addr *) b)[1] = IPA_NONE; } static inline void set_next_hop(byte *b, ip_addr addr) { ((ip_addr *) b)[0] = addr; ((ip_addr *) b)[1] = IPA_NONE; }
#else
#define NEXT_HOP_LENGTH sizeof(ip_addr) #define NEXT_HOP_LENGTH sizeof(ip_addr)
static inline void set_next_hop(byte *b, ip_addr addr) { ((ip_addr *) b)[0] = addr; } static inline void set_next_hop(byte *b, ip_addr addr) { ((ip_addr *) b)[0] = addr; }
#endif #endif
void bgp_attach_attr(struct ea_list **to, struct linpool *pool, unsigned attr, uintptr_t val); int bgp_encode_attrs(struct bgp_write_state *s, ea_list *attrs, byte *buf, byte *end);
byte *bgp_attach_attr_wa(struct ea_list **to, struct linpool *pool, unsigned attr, unsigned len); ea_list * bgp_decode_attrs(struct bgp_parse_state *s, byte *data, uint len);
struct rta *bgp_decode_attrs(struct bgp_conn *conn, byte *a, uint len, struct linpool *pool, int mandatory);
int bgp_get_attr(struct eattr *e, byte *buf, int buflen); void bgp_init_bucket_table(struct bgp_channel *c);
void bgp_free_bucket(struct bgp_channel *c, struct bgp_bucket *b);
void bgp_defer_bucket(struct bgp_channel *c, struct bgp_bucket *b);
void bgp_withdraw_bucket(struct bgp_channel *c, struct bgp_bucket *b);
void bgp_init_prefix_table(struct bgp_channel *c);
void bgp_free_prefix(struct bgp_channel *c, struct bgp_prefix *bp);
int bgp_rte_better(struct rte *, struct rte *); int bgp_rte_better(struct rte *, struct rte *);
int bgp_rte_mergable(rte *pri, rte *sec); int bgp_rte_mergable(rte *pri, rte *sec);
int bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best); int bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best);
void bgp_rt_notify(struct proto *P, rtable *tbl UNUSED, net *n, rte *new, rte *old UNUSED, ea_list *attrs); void bgp_rt_notify(struct proto *P, struct channel *C, net *n, rte *new, rte *old, ea_list *attrs);
int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *); int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *);
void bgp_init_bucket_table(struct bgp_proto *); int bgp_get_attr(struct eattr *e, byte *buf, int buflen);
void bgp_free_bucket(struct bgp_proto *p, struct bgp_bucket *buck);
void bgp_init_prefix_table(struct bgp_proto *p, u32 order);
void bgp_free_prefix(struct bgp_proto *p, struct bgp_prefix *bp);
uint bgp_encode_attrs(struct bgp_proto *p, byte *w, ea_list *attrs, int remains);
void bgp_get_route_info(struct rte *, byte *buf, struct ea_list *attrs); void bgp_get_route_info(struct rte *, byte *buf, struct ea_list *attrs);
inline static void bgp_attach_attr_ip(struct ea_list **to, struct linpool *pool, unsigned attr, ip_addr a)
{ *(ip_addr *) bgp_attach_attr_wa(to, pool, attr, sizeof(ip_addr)) = a; }
/* packets.c */ /* packets.c */
void mrt_dump_bgp_state_change(struct bgp_conn *conn, unsigned old, unsigned new); void mrt_dump_bgp_state_change(struct bgp_conn *conn, unsigned old, unsigned new);
void bgp_schedule_packet(struct bgp_conn *conn, int type); const struct bgp_af_desc *bgp_get_af_desc(u32 afi);
const struct bgp_af_caps *bgp_find_af_caps(struct bgp_caps *caps, u32 afi);
void bgp_schedule_packet(struct bgp_conn *conn, struct bgp_channel *c, int type);
void bgp_kick_tx(void *vconn); void bgp_kick_tx(void *vconn);
void bgp_tx(struct birdsock *sk); void bgp_tx(struct birdsock *sk);
int bgp_rx(struct birdsock *sk, uint size); int bgp_rx(struct birdsock *sk, uint size);
const char * bgp_error_dsc(unsigned code, unsigned subcode); const char * bgp_error_dsc(unsigned code, unsigned subcode);
void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len); void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsigned subcode, byte *data, unsigned len);
void bgp_update_next_hop(struct bgp_export_state *s, eattr *a, ea_list **to);
/* Packet types */ /* Packet types */
#define PKT_OPEN 0x01 #define PKT_OPEN 0x01
@ -305,9 +526,9 @@ void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsi
#define BA_RCID_PATH 0x0d #define BA_RCID_PATH 0x0d
#define BA_MP_REACH_NLRI 0x0e /* [RFC2283] */ #define BA_MP_REACH_NLRI 0x0e /* [RFC2283] */
#define BA_MP_UNREACH_NLRI 0x0f #define BA_MP_UNREACH_NLRI 0x0f
#define BA_EXT_COMMUNITY 0x10 /* [RFC4360] */ #define BA_EXT_COMMUNITY 0x10 /* RFC 4360 */
#define BA_AS4_PATH 0x11 /* [RFC4893] */ #define BA_AS4_PATH 0x11 /* RFC 6793 */
#define BA_AS4_AGGREGATOR 0x12 #define BA_AS4_AGGREGATOR 0x12 /* RFC 6793 */
#define BA_LARGE_COMMUNITY 0x20 /* [draft-ietf-idr-large-community] */ #define BA_LARGE_COMMUNITY 0x20 /* [draft-ietf-idr-large-community] */
/* BGP connection states */ /* BGP connection states */
@ -328,14 +549,12 @@ void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsi
* *
* When BGP protocol is started by core, it goes to BSS_PREPARE. When BGP * When BGP protocol is started by core, it goes to BSS_PREPARE. When BGP
* protocol done what is neccessary to start itself (like acquiring the lock), * protocol done what is neccessary to start itself (like acquiring the lock),
* it goes to BSS_CONNECT. When some connection attempt failed because of * it goes to BSS_CONNECT.
* option or capability error, it goes to BSS_CONNECT_NOCAP.
*/ */
#define BSS_PREPARE 0 /* Used before ordinary BGP started, i. e. waiting for lock */ #define BSS_PREPARE 0 /* Used before ordinary BGP started, i. e. waiting for lock */
#define BSS_DELAY 1 /* Startup delay due to previous errors */ #define BSS_DELAY 1 /* Startup delay due to previous errors */
#define BSS_CONNECT 2 /* Ordinary BGP connecting */ #define BSS_CONNECT 2 /* Ordinary BGP connecting */
#define BSS_CONNECT_NOCAP 3 /* Legacy BGP connecting (without capabilities) */
/* BGP feed states (TX) /* BGP feed states (TX)
@ -344,7 +563,7 @@ void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsi
* *
* RFC 7313 specifies that a route refresh should be demarcated by BoRR and EoRR packets. * RFC 7313 specifies that a route refresh should be demarcated by BoRR and EoRR packets.
* *
* These states (stored in p->feed_state) are used to keep track of these * These states (stored in c->feed_state) are used to keep track of these
* requirements. When such feed is started, BFS_LOADING / BFS_REFRESHING is * requirements. When such feed is started, BFS_LOADING / BFS_REFRESHING is
* set. When it ended, BFS_LOADED / BFS_REFRESHED is set to schedule End-of-RIB * set. When it ended, BFS_LOADED / BFS_REFRESHED is set to schedule End-of-RIB
* or EoRR packet. When the packet is sent, the state returned to BFS_NONE. * or EoRR packet. When the packet is sent, the state returned to BFS_NONE.
@ -400,15 +619,5 @@ void bgp_log_error(struct bgp_proto *p, u8 class, char *msg, unsigned code, unsi
#define ORIGIN_EGP 1 #define ORIGIN_EGP 1
#define ORIGIN_INCOMPLETE 2 #define ORIGIN_INCOMPLETE 2
/* Address families */
#define BGP_AF_IPV4 1
#define BGP_AF_IPV6 2
#ifdef IPV6
#define BGP_AF BGP_AF_IPV6
#else
#define BGP_AF BGP_AF_IPV4
#endif
#endif #endif

View File

@ -13,28 +13,32 @@ CF_HDR
CF_DEFINES CF_DEFINES
#define BGP_CFG ((struct bgp_config *) this_proto) #define BGP_CFG ((struct bgp_config *) this_proto)
#define BGP_CC ((struct bgp_channel_config *) this_channel)
CF_DECLS CF_DECLS
CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, KEEPALIVE,
KEEPALIVE, MULTIHOP, STARTUP, VIA, NEXT, HOP, SELF, DEFAULT, MULTIHOP, STARTUP, VIA, NEXT, HOP, SELF, DEFAULT, PATH, METRIC, ERROR,
PATH, METRIC, ERROR, START, DELAY, FORGET, WAIT, ENABLE, START, DELAY, FORGET, WAIT, ENABLE, DISABLE, AFTER, BGP_PATH,
DISABLE, AFTER, BGP_PATH, BGP_LOCAL_PREF, BGP_MED, BGP_ORIGIN, BGP_LOCAL_PREF, BGP_MED, BGP_ORIGIN, BGP_NEXT_HOP, BGP_ATOMIC_AGGR,
BGP_NEXT_HOP, BGP_ATOMIC_AGGR, BGP_AGGREGATOR, BGP_COMMUNITY, BGP_AGGREGATOR, BGP_COMMUNITY, BGP_EXT_COMMUNITY, BGP_LARGE_COMMUNITY,
BGP_EXT_COMMUNITY, SOURCE, ADDRESS, PASSWORD, RR, RS, CLIENT, SOURCE, ADDRESS, PASSWORD, RR, RS, CLIENT, CLUSTER, ID, AS4, ADVERTISE,
CLUSTER, ID, AS4, ADVERTISE, IPV4, CAPABILITIES, LIMIT, PASSIVE, IPV4, CAPABILITIES, LIMIT, PASSIVE, PREFER, OLDER, MISSING, LLADDR,
PREFER, OLDER, MISSING, LLADDR, DROP, IGNORE, ROUTE, REFRESH, DROP, IGNORE, ROUTE, REFRESH, INTERPRET, COMMUNITIES, BGP_ORIGINATOR_ID,
INTERPRET, COMMUNITIES, BGP_ORIGINATOR_ID, BGP_CLUSTER_LIST, IGP, BGP_CLUSTER_LIST, IGP, TABLE, GATEWAY, DIRECT, RECURSIVE, MED, TTL,
TABLE, GATEWAY, DIRECT, RECURSIVE, MED, TTL, SECURITY, DETERMINISTIC, SECURITY, DETERMINISTIC, SECONDARY, ALLOW, BFD, ADD, PATHS, RX, TX,
SECONDARY, ALLOW, BFD, ADD, PATHS, RX, TX, GRACEFUL, RESTART, AWARE, GRACEFUL, RESTART, AWARE, CHECK, LINK, PORT, EXTENDED, MESSAGES, SETKEY,
CHECK, LINK, PORT, EXTENDED, MESSAGES, SETKEY, BGP_LARGE_COMMUNITY) STRICT, BIND, CONFEDERATION, MEMBER, MULTICAST)
%type <i32> bgp_afi
CF_GRAMMAR CF_GRAMMAR
CF_ADDTO(proto, bgp_proto '}' { bgp_check_config(BGP_CFG); } ) CF_ADDTO(proto, bgp_proto '}' )
bgp_proto_start: proto_start BGP { bgp_proto_start: proto_start BGP {
this_proto = proto_config_new(&proto_bgp, $1); this_proto = proto_config_new(&proto_bgp, $1);
BGP_CFG->local_port = BGP_PORT;
BGP_CFG->remote_port = BGP_PORT; BGP_CFG->remote_port = BGP_PORT;
BGP_CFG->multihop = -1; /* undefined */ BGP_CFG->multihop = -1; /* undefined */
BGP_CFG->hold_time = 240; BGP_CFG->hold_time = 240;
@ -49,7 +53,6 @@ bgp_proto_start: proto_start BGP {
BGP_CFG->enable_refresh = 1; BGP_CFG->enable_refresh = 1;
BGP_CFG->enable_as4 = 1; BGP_CFG->enable_as4 = 1;
BGP_CFG->capabilities = 2; BGP_CFG->capabilities = 2;
BGP_CFG->advertise_ipv4 = 1;
BGP_CFG->interpret_communities = 1; BGP_CFG->interpret_communities = 1;
BGP_CFG->default_local_pref = 100; BGP_CFG->default_local_pref = 100;
BGP_CFG->gr_mode = BGP_GR_AWARE; BGP_CFG->gr_mode = BGP_GR_AWARE;
@ -58,6 +61,12 @@ bgp_proto_start: proto_start BGP {
} }
; ;
bgp_loc_opts:
/* empty */
| bgp_loc_opts PORT expr { BGP_CFG->local_port = $3; if (($3<1) || ($3>65535)) cf_error("Invalid port number"); }
| bgp_loc_opts AS expr { BGP_CFG->local_as = $3; }
;
bgp_nbr_opts: bgp_nbr_opts:
/* empty */ /* empty */
| bgp_nbr_opts PORT expr { BGP_CFG->remote_port = $3; if (($3<1) || ($3>65535)) cf_error("Invalid port number"); } | bgp_nbr_opts PORT expr { BGP_CFG->remote_port = $3; if (($3<1) || ($3>65535)) cf_error("Invalid port number"); }
@ -67,8 +76,12 @@ bgp_nbr_opts:
bgp_proto: bgp_proto:
bgp_proto_start proto_name '{' bgp_proto_start proto_name '{'
| bgp_proto proto_item ';' | bgp_proto proto_item ';'
| bgp_proto LOCAL AS expr ';' { BGP_CFG->local_as = $4; } | bgp_proto bgp_proto_channel ';'
| bgp_proto LOCAL ipa AS expr ';' { BGP_CFG->source_addr = $3; BGP_CFG->local_as = $5; } | bgp_proto LOCAL bgp_loc_opts ';'
| bgp_proto LOCAL ipa ipa_scope bgp_loc_opts ';' {
BGP_CFG->local_ip = $3;
if ($4) BGP_CFG->iface = $4;
}
| bgp_proto NEIGHBOR bgp_nbr_opts ';' | bgp_proto NEIGHBOR bgp_nbr_opts ';'
| bgp_proto NEIGHBOR ipa ipa_scope bgp_nbr_opts ';' { | bgp_proto NEIGHBOR ipa ipa_scope bgp_nbr_opts ';' {
if (ipa_nonzero(BGP_CFG->remote_ip)) if (ipa_nonzero(BGP_CFG->remote_ip))
@ -78,20 +91,16 @@ bgp_proto:
} }
| bgp_proto INTERFACE TEXT ';' { BGP_CFG->iface = if_get_by_name($3); } | bgp_proto INTERFACE TEXT ';' { BGP_CFG->iface = if_get_by_name($3); }
| bgp_proto RR CLUSTER ID idval ';' { BGP_CFG->rr_cluster_id = $5; } | bgp_proto RR CLUSTER ID idval ';' { BGP_CFG->rr_cluster_id = $5; }
| bgp_proto RR CLIENT ';' { BGP_CFG->rr_client = 1; } | bgp_proto RR CLIENT bool ';' { BGP_CFG->rr_client = $4; }
| bgp_proto RS CLIENT ';' { BGP_CFG->rs_client = 1; } | bgp_proto RS CLIENT bool ';' { BGP_CFG->rs_client = $4; }
| bgp_proto CONFEDERATION expr ';' { BGP_CFG->confederation = $3; }
| bgp_proto CONFEDERATION MEMBER bool ';' { BGP_CFG->confederation_member = $4; }
| bgp_proto HOLD TIME expr ';' { BGP_CFG->hold_time = $4; } | bgp_proto HOLD TIME expr ';' { BGP_CFG->hold_time = $4; }
| bgp_proto STARTUP HOLD TIME expr ';' { BGP_CFG->initial_hold_time = $5; } | bgp_proto STARTUP HOLD TIME expr ';' { BGP_CFG->initial_hold_time = $5; }
| bgp_proto DIRECT ';' { BGP_CFG->multihop = 0; } | bgp_proto DIRECT ';' { BGP_CFG->multihop = 0; }
| bgp_proto MULTIHOP ';' { BGP_CFG->multihop = 64; } | bgp_proto MULTIHOP ';' { BGP_CFG->multihop = 64; }
| bgp_proto MULTIHOP expr ';' { BGP_CFG->multihop = $3; if (($3<1) || ($3>255)) cf_error("Multihop must be in range 1-255"); } | bgp_proto MULTIHOP expr ';' { BGP_CFG->multihop = $3; if (($3<1) || ($3>255)) cf_error("Multihop must be in range 1-255"); }
| bgp_proto NEXT HOP SELF ';' { BGP_CFG->next_hop_self = 1; BGP_CFG->next_hop_keep = 0; } | bgp_proto STRICT BIND bool ';' { BGP_CFG->strict_bind = $4; }
| bgp_proto NEXT HOP KEEP ';' { BGP_CFG->next_hop_keep = 1; BGP_CFG->next_hop_self = 0; }
| bgp_proto MISSING LLADDR SELF ';' { BGP_CFG->missing_lladdr = MLL_SELF; }
| bgp_proto MISSING LLADDR DROP ';' { BGP_CFG->missing_lladdr = MLL_DROP; }
| bgp_proto MISSING LLADDR IGNORE ';' { BGP_CFG->missing_lladdr = MLL_IGNORE; }
| bgp_proto GATEWAY DIRECT ';' { BGP_CFG->gw_mode = GW_DIRECT; }
| bgp_proto GATEWAY RECURSIVE ';' { BGP_CFG->gw_mode = GW_RECURSIVE; }
| bgp_proto PATH METRIC bool ';' { BGP_CFG->compare_path_lengths = $4; } | bgp_proto PATH METRIC bool ';' { BGP_CFG->compare_path_lengths = $4; }
| bgp_proto MED METRIC bool ';' { BGP_CFG->med_metric = $4; } | bgp_proto MED METRIC bool ';' { BGP_CFG->med_metric = $4; }
| bgp_proto IGP METRIC bool ';' { BGP_CFG->igp_metric = $4; } | bgp_proto IGP METRIC bool ';' { BGP_CFG->igp_metric = $4; }
@ -99,7 +108,7 @@ bgp_proto:
| bgp_proto DETERMINISTIC MED bool ';' { BGP_CFG->deterministic_med = $4; } | bgp_proto DETERMINISTIC MED bool ';' { BGP_CFG->deterministic_med = $4; }
| bgp_proto DEFAULT BGP_MED expr ';' { BGP_CFG->default_med = $4; } | bgp_proto DEFAULT BGP_MED expr ';' { BGP_CFG->default_med = $4; }
| bgp_proto DEFAULT BGP_LOCAL_PREF expr ';' { BGP_CFG->default_local_pref = $4; } | bgp_proto DEFAULT BGP_LOCAL_PREF expr ';' { BGP_CFG->default_local_pref = $4; }
| bgp_proto SOURCE ADDRESS ipa ';' { BGP_CFG->source_addr = $4; } | bgp_proto SOURCE ADDRESS ipa ';' { BGP_CFG->local_ip = $4; }
| bgp_proto START DELAY TIME expr ';' { BGP_CFG->connect_delay_time = $5; log(L_WARN "%s: Start delay time option is deprecated, use connect delay time", this_proto->name); } | bgp_proto START DELAY TIME expr ';' { BGP_CFG->connect_delay_time = $5; log(L_WARN "%s: Start delay time option is deprecated, use connect delay time", this_proto->name); }
| bgp_proto CONNECT DELAY TIME expr ';' { BGP_CFG->connect_delay_time = $5; } | bgp_proto CONNECT DELAY TIME expr ';' { BGP_CFG->connect_delay_time = $5; }
| bgp_proto CONNECT RETRY TIME expr ';' { BGP_CFG->connect_retry_time = $5; } | bgp_proto CONNECT RETRY TIME expr ';' { BGP_CFG->connect_retry_time = $5; }
@ -111,26 +120,79 @@ bgp_proto:
| bgp_proto ENABLE AS4 bool ';' { BGP_CFG->enable_as4 = $4; } | bgp_proto ENABLE AS4 bool ';' { BGP_CFG->enable_as4 = $4; }
| bgp_proto ENABLE EXTENDED MESSAGES bool ';' { BGP_CFG->enable_extended_messages = $5; } | bgp_proto ENABLE EXTENDED MESSAGES bool ';' { BGP_CFG->enable_extended_messages = $5; }
| bgp_proto CAPABILITIES bool ';' { BGP_CFG->capabilities = $3; } | bgp_proto CAPABILITIES bool ';' { BGP_CFG->capabilities = $3; }
| bgp_proto ADVERTISE IPV4 bool ';' { BGP_CFG->advertise_ipv4 = $4; }
| bgp_proto PASSWORD text ';' { BGP_CFG->password = $3; } | bgp_proto PASSWORD text ';' { BGP_CFG->password = $3; }
| bgp_proto SETKEY bool ';' { BGP_CFG->setkey = $3; } | bgp_proto SETKEY bool ';' { BGP_CFG->setkey = $3; }
| bgp_proto PASSIVE bool ';' { BGP_CFG->passive = $3; } | bgp_proto PASSIVE bool ';' { BGP_CFG->passive = $3; }
| bgp_proto INTERPRET COMMUNITIES bool ';' { BGP_CFG->interpret_communities = $4; } | bgp_proto INTERPRET COMMUNITIES bool ';' { BGP_CFG->interpret_communities = $4; }
| bgp_proto SECONDARY bool ';' { BGP_CFG->secondary = $3; }
| bgp_proto ADD PATHS RX ';' { BGP_CFG->add_path = ADD_PATH_RX; }
| bgp_proto ADD PATHS TX ';' { BGP_CFG->add_path = ADD_PATH_TX; }
| bgp_proto ADD PATHS bool ';' { BGP_CFG->add_path = $4 ? ADD_PATH_FULL : 0; }
| bgp_proto ALLOW LOCAL AS ';' { BGP_CFG->allow_local_as = -1; } | bgp_proto ALLOW LOCAL AS ';' { BGP_CFG->allow_local_as = -1; }
| bgp_proto ALLOW LOCAL AS expr ';' { BGP_CFG->allow_local_as = $5; } | bgp_proto ALLOW LOCAL AS expr ';' { BGP_CFG->allow_local_as = $5; }
| bgp_proto GRACEFUL RESTART bool ';' { BGP_CFG->gr_mode = $4; } | bgp_proto GRACEFUL RESTART bool ';' { BGP_CFG->gr_mode = $4; }
| bgp_proto GRACEFUL RESTART AWARE ';' { BGP_CFG->gr_mode = BGP_GR_AWARE; } | bgp_proto GRACEFUL RESTART AWARE ';' { BGP_CFG->gr_mode = BGP_GR_AWARE; }
| bgp_proto GRACEFUL RESTART TIME expr ';' { BGP_CFG->gr_time = $5; } | bgp_proto GRACEFUL RESTART TIME expr ';' { BGP_CFG->gr_time = $5; }
| bgp_proto IGP TABLE rtable ';' { BGP_CFG->igp_table = $4; }
| bgp_proto TTL SECURITY bool ';' { BGP_CFG->ttl_security = $4; } | bgp_proto TTL SECURITY bool ';' { BGP_CFG->ttl_security = $4; }
| bgp_proto CHECK LINK bool ';' { BGP_CFG->check_link = $4; } | bgp_proto CHECK LINK bool ';' { BGP_CFG->check_link = $4; }
| bgp_proto BFD bool ';' { BGP_CFG->bfd = $3; cf_check_bfd($3); } | bgp_proto BFD bool ';' { BGP_CFG->bfd = $3; cf_check_bfd($3); }
; ;
bgp_afi:
IPV4 { $$ = BGP_AF_IPV4; }
| IPV6 { $$ = BGP_AF_IPV6; }
| IPV4 MULTICAST { $$ = BGP_AF_IPV4_MC; }
| IPV6 MULTICAST { $$ = BGP_AF_IPV6_MC; }
;
bgp_channel_start: bgp_afi
{
const struct bgp_af_desc *desc = bgp_get_af_desc($1);
if (!desc)
cf_error("Unknown AFI/SAFI");
this_channel = channel_config_new(&channel_bgp, desc->net, this_proto);
BGP_CC->c.name = desc->name;
BGP_CC->afi = $1;
BGP_CC->gr_able = 0xff; /* undefined */
};
bgp_channel_item:
channel_item
| NEXT HOP ADDRESS ipa { BGP_CC->next_hop_addr = $4; }
| NEXT HOP SELF { BGP_CC->next_hop_self = 1; BGP_CC->next_hop_keep = 0; }
| NEXT HOP KEEP { BGP_CC->next_hop_keep = 1; BGP_CC->next_hop_self = 0; }
| MISSING LLADDR SELF { BGP_CC->missing_lladdr = MLL_SELF; }
| MISSING LLADDR DROP { BGP_CC->missing_lladdr = MLL_DROP; }
| MISSING LLADDR IGNORE { BGP_CC->missing_lladdr = MLL_IGNORE; }
| GATEWAY DIRECT { BGP_CC->gw_mode = GW_DIRECT; }
| GATEWAY RECURSIVE { BGP_CC->gw_mode = GW_RECURSIVE; }
| SECONDARY bool { BGP_CC->secondary = $2; }
| GRACEFUL RESTART bool { BGP_CC->gr_able = $3; }
| ADD PATHS RX { BGP_CC->add_path = BGP_ADD_PATH_RX; }
| ADD PATHS TX { BGP_CC->add_path = BGP_ADD_PATH_TX; }
| ADD PATHS bool { BGP_CC->add_path = $3 ? BGP_ADD_PATH_FULL : 0; }
| IGP TABLE rtable { BGP_CC->igp_table = $3; }
;
bgp_channel_opts:
/* empty */
| bgp_channel_opts bgp_channel_item ';'
;
bgp_channel_opt_list:
/* empty */
| '{' bgp_channel_opts '}'
;
bgp_channel_end:
{
if (!this_channel->table)
cf_error("Routing table not specified");
this_channel = NULL;
};
bgp_proto_channel: bgp_channel_start bgp_channel_opt_list bgp_channel_end;
CF_ADDTO(dynamic_attr, BGP_ORIGIN CF_ADDTO(dynamic_attr, BGP_ORIGIN
{ $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_ENUM_BGP_ORIGIN, EA_CODE(EAP_BGP, BA_ORIGIN)); }) { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_ENUM_BGP_ORIGIN, EA_CODE(EAP_BGP, BA_ORIGIN)); })
CF_ADDTO(dynamic_attr, BGP_PATH CF_ADDTO(dynamic_attr, BGP_PATH

File diff suppressed because it is too large Load Diff

View File

@ -104,7 +104,7 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa)
} }
if (r->dest == RTDX_RECURSIVE) if (r->dest == RTDX_RECURSIVE)
rta_set_recursive_next_hop(p->main_channel->table, &a, p_igp_table(p), &r->via, &r->via); rta_set_recursive_next_hop(p->main_channel->table, &a, p_igp_table(p), r->via, IPA_NONE);
/* We skip rta_lookup() here */ /* We skip rta_lookup() here */

View File

@ -1255,7 +1255,7 @@ sk_setup(sock *s)
if (sk_is_ipv6(s)) if (sk_is_ipv6(s))
{ {
if (s->type != SK_IP) if ((s->type == SK_TCP_PASSIVE) || (s->type == SK_TCP_ACTIVE) || (s->type == SK_UDP))
if (setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, &y, sizeof(y)) < 0) if (setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, &y, sizeof(y)) < 0)
ERR("IPV6_V6ONLY"); ERR("IPV6_V6ONLY");