BGP: Moved the suppressed and stale flags to pflags
This commit is contained in:
parent
e42eedb912
commit
ddd89ba12d
5 changed files with 39 additions and 32 deletions
|
@ -244,12 +244,6 @@ typedef struct rte {
|
|||
byte pflags; /* Protocol-specific flags */
|
||||
btime lastmod; /* Last modified */
|
||||
union { /* Protocol-dependent data (metrics etc.) */
|
||||
#ifdef CONFIG_BGP
|
||||
struct {
|
||||
u8 suppressed; /* Used for deterministic MED comparison */
|
||||
s8 stale; /* Route is LLGR_STALE, -1 if unknown */
|
||||
} bgp;
|
||||
#endif
|
||||
} u;
|
||||
} rte;
|
||||
|
||||
|
|
|
@ -1887,14 +1887,24 @@ bgp_get_neighbor(rte *r)
|
|||
static inline int
|
||||
rte_stale(rte *r)
|
||||
{
|
||||
if (r->u.bgp.stale < 0)
|
||||
{
|
||||
/* If staleness is unknown, compute and cache it */
|
||||
eattr *a = ea_find(r->attrs->eattrs, EA_CODE(PROTOCOL_BGP, BA_COMMUNITY));
|
||||
r->u.bgp.stale = a && int_set_contains(a->u.ptr, BGP_COMM_LLGR_STALE);
|
||||
}
|
||||
if (r->pflags & BGP_REF_STALE)
|
||||
return 1;
|
||||
|
||||
return r->u.bgp.stale;
|
||||
if (r->pflags & BGP_REF_NOT_STALE)
|
||||
return 0;
|
||||
|
||||
/* If staleness is unknown, compute and cache it */
|
||||
eattr *a = ea_find(r->attrs->eattrs, EA_CODE(PROTOCOL_BGP, BA_COMMUNITY));
|
||||
if (a && int_set_contains(a->u.ptr, BGP_COMM_LLGR_STALE))
|
||||
{
|
||||
r->pflags |= BGP_REF_STALE;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
r->pflags |= BGP_REF_NOT_STALE;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1906,8 +1916,8 @@ bgp_rte_better(rte *new, rte *old)
|
|||
u32 n, o;
|
||||
|
||||
/* Skip suppressed routes (see bgp_rte_recalculate()) */
|
||||
n = new->u.bgp.suppressed;
|
||||
o = old->u.bgp.suppressed;
|
||||
n = new->pflags & BGP_REF_SUPPRESSED;
|
||||
o = old->pflags & BGP_REF_SUPPRESSED;
|
||||
if (n > o)
|
||||
return 0;
|
||||
if (n < o)
|
||||
|
@ -2051,17 +2061,14 @@ bgp_rte_mergable(rte *pri, rte *sec)
|
|||
u32 p, s;
|
||||
|
||||
/* Skip suppressed routes (see bgp_rte_recalculate()) */
|
||||
if (pri->u.bgp.suppressed != sec->u.bgp.suppressed)
|
||||
/* LLGR draft - depreference stale routes */
|
||||
if (pri->pflags != sec->pflags)
|
||||
return 0;
|
||||
|
||||
/* RFC 4271 9.1.2.1. Route resolvability test */
|
||||
if (rte_resolvable(pri) != rte_resolvable(sec))
|
||||
return 0;
|
||||
|
||||
/* LLGR draft - depreference stale routes */
|
||||
if (rte_stale(pri) != rte_stale(sec))
|
||||
return 0;
|
||||
|
||||
/* Start with local preferences */
|
||||
x = ea_find(pri->attrs->eattrs, EA_CODE(PROTOCOL_BGP, BA_LOCAL_PREF));
|
||||
y = ea_find(sec->attrs->eattrs, EA_CODE(PROTOCOL_BGP, BA_LOCAL_PREF));
|
||||
|
@ -2141,7 +2148,7 @@ bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best)
|
|||
rte *key = new ? new : old;
|
||||
u32 lpref = key->attrs->pref;
|
||||
u32 lasn = bgp_get_neighbor(key);
|
||||
int old_suppressed = old ? old->u.bgp.suppressed : 0;
|
||||
int old_suppressed = old ? !!(old->pflags & BGP_REF_SUPPRESSED) : 0;
|
||||
|
||||
/*
|
||||
* Proper RFC 4271 path selection is a bit complicated, it cannot be
|
||||
|
@ -2193,11 +2200,11 @@ bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best)
|
|||
*/
|
||||
|
||||
if (new)
|
||||
new->u.bgp.suppressed = 1;
|
||||
new->pflags |= BGP_REF_SUPPRESSED;
|
||||
|
||||
if (old)
|
||||
{
|
||||
old->u.bgp.suppressed = 1;
|
||||
old->pflags |= BGP_REF_SUPPRESSED;
|
||||
|
||||
/* The fast case - replace not best with worse (or remove not best) */
|
||||
if (old_suppressed && !(new && bgp_rte_better(new, old)))
|
||||
|
@ -2209,7 +2216,7 @@ bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best)
|
|||
for (s=net->routes; rte_is_valid(s); s=s->next)
|
||||
if (use_deterministic_med(s) && same_group(s, lpref, lasn))
|
||||
{
|
||||
s->u.bgp.suppressed = 1;
|
||||
s->pflags |= BGP_REF_SUPPRESSED;
|
||||
if (!r || bgp_rte_better(s, r))
|
||||
r = s;
|
||||
}
|
||||
|
@ -2220,16 +2227,16 @@ bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best)
|
|||
|
||||
/* Found if new is mergable with best-in-group */
|
||||
if (new && (new != r) && bgp_rte_mergable(r, new))
|
||||
new->u.bgp.suppressed = 0;
|
||||
new->pflags &= ~BGP_REF_SUPPRESSED;
|
||||
|
||||
/* Found all existing routes mergable with best-in-group */
|
||||
for (s=net->routes; rte_is_valid(s); s=s->next)
|
||||
if (use_deterministic_med(s) && same_group(s, lpref, lasn))
|
||||
if ((s != r) && bgp_rte_mergable(r, s))
|
||||
s->u.bgp.suppressed = 0;
|
||||
s->pflags &= ~BGP_REF_SUPPRESSED;
|
||||
|
||||
/* Found best-in-group */
|
||||
r->u.bgp.suppressed = 0;
|
||||
r->pflags &= ~BGP_REF_SUPPRESSED;
|
||||
|
||||
/*
|
||||
* There are generally two reasons why we have to force
|
||||
|
@ -2277,7 +2284,7 @@ bgp_rte_modify_stale(struct rte *r, struct linpool *pool)
|
|||
r = rte_cow_rta(r, pool);
|
||||
bgp_set_attr_ptr(&(r->attrs->eattrs), pool, BA_COMMUNITY, flags,
|
||||
int_set_add(pool, ad, BGP_COMM_LLGR_STALE));
|
||||
r->u.bgp.stale = 1;
|
||||
r->pflags |= BGP_REF_STALE;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -2364,7 +2371,7 @@ bgp_get_route_info(rte *e, byte *buf)
|
|||
|
||||
buf += bsprintf(buf, " (%d", e->attrs->pref);
|
||||
|
||||
if (e->u.bgp.suppressed)
|
||||
if (e->pflags & BGP_REF_SUPPRESSED)
|
||||
buf += bsprintf(buf, "-");
|
||||
|
||||
if (rte_stale(e))
|
||||
|
|
|
@ -200,6 +200,10 @@ struct bgp_channel_config {
|
|||
|
||||
#define BGP_BFD_GRACEFUL 2 /* BFD down triggers graceful restart */
|
||||
|
||||
/* rte->pflags */
|
||||
#define BGP_REF_SUPPRESSED 0x1 /* Used for deterministic MED comparison */
|
||||
#define BGP_REF_STALE 0x2 /* Route is LLGR_STATE */
|
||||
#define BGP_REF_NOT_STALE 0x4 /* Route is NOT LLGR_STATE */
|
||||
|
||||
struct bgp_af_caps {
|
||||
u32 afi;
|
||||
|
|
|
@ -1366,8 +1366,6 @@ bgp_rte_update(struct bgp_parse_state *s, net_addr *n, u32 path_id, rta *a0)
|
|||
rte *e = rte_get_temp(a, s->last_src);
|
||||
|
||||
e->pflags = 0;
|
||||
e->u.bgp.suppressed = 0;
|
||||
e->u.bgp.stale = -1;
|
||||
rte_update3(&s->channel->c, n, e, s->last_src);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,10 @@
|
|||
|
||||
#include "pipe.h"
|
||||
|
||||
#ifdef CONFIG_BGP
|
||||
#include "proto/bgp/bgp.h"
|
||||
#endif
|
||||
|
||||
static void
|
||||
pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *old)
|
||||
{
|
||||
|
@ -82,7 +86,7 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o
|
|||
#ifdef CONFIG_BGP
|
||||
/* Hack to cleanup cached value */
|
||||
if (e->src->proto->proto == &proto_bgp)
|
||||
e->u.bgp.stale = -1;
|
||||
e->pflags &= ~(BGP_REF_STALE | BGP_REF_NOT_STALE);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue