Commit d15b0b0a authored by Ondřej Zajíček's avatar Ondřej Zajíček

BGP redesign

Integrated and extensible BGP with generalized AFI handling,
support for IPv4+IPv6 AFI and unicast+multicast SAFI.
parent 5df4073c
...@@ -170,7 +170,7 @@ fi ...@@ -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'`
......
...@@ -1065,7 +1065,7 @@ interpret(struct f_inst *what) ...@@ -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:
......
...@@ -35,6 +35,7 @@ ...@@ -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); }
......
...@@ -91,6 +91,7 @@ typedef ip6_addr ip_addr; ...@@ -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)
......
...@@ -158,3 +158,15 @@ add_tail_list(list *to, list *l) ...@@ -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;
}
...@@ -80,6 +80,7 @@ void rem_node(node *); ...@@ -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
...@@ -109,6 +109,24 @@ net_compare(const net_addr *a, const net_addr *b) ...@@ -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)
{ {
......
...@@ -321,6 +321,8 @@ static inline u32 net_hash_roa4(const net_addr_roa4 *n) ...@@ -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)
{ {
......
...@@ -69,4 +69,22 @@ put_u64(void *p, u64 x) ...@@ -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
This diff is collapsed.
...@@ -7,6 +7,8 @@ ...@@ -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) ...@@ -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;
}
...@@ -10,6 +10,9 @@ ...@@ -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 @@ ...@@ -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 { ...@@ -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 ...@@ -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
...@@ -80,7 +80,6 @@ print_size(char *dsc, size_t val) ...@@ -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)
......
...@@ -39,7 +39,7 @@ static int graceful_restart_state; ...@@ -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) ...@@ -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) ...@@ -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 ...@@ -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 ...@@ -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));
......
...@@ -273,6 +273,7 @@ proto_get_router_id(struct proto_config *pc) ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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) */
......
...@@ -457,13 +457,22 @@ typedef struct eattr { ...@@ -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 ...@@ -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
......
...@@ -528,7 +528,7 @@ ea_do_prune(ea_list *e) ...@@ -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++;
} }
......
...@@ -2426,9 +2426,9 @@ rt_get_hostentry(rtable *tab, ip_addr a, ip_addr ll, rtable *dep) ...@@ -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));
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -13,28 +13,32 @@ CF_HDR ...@@ -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,26 +53,35 @@ bgp_proto_start: proto_start BGP { ...@@ -49,26 +53,35 @@ 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;
BGP_CFG->gr_time = 120; BGP_CFG->gr_time = 120;
BGP_CFG->setkey = 1; BGP_CFG->setkey = 1;
} }
;
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"); }
| bgp_nbr_opts AS expr { BGP_CFG->remote_as = $3; } | bgp_nbr_opts AS expr { BGP_CFG->remote_as = $3; }
; ;
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: ...@@ -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 R