and it also makes less sense to track this with ECMP or add-path.
Replace the re->active access with prefix_best(re) which does the
check on the spot.
Feedback and OK tb@
-/* $OpenBSD: rde.c,v 1.542 2022/03/21 13:33:20 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.543 2022/03/21 17:35:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
rib.validation_state = p->validation_state;
rib.flags = 0;
re = prefix_re(p);
- if (re != NULL && re->active == p)
+ if (re != NULL && prefix_best(re) == p)
rib.flags |= F_PREF_BEST;
if (!peer->conf.ebgp)
rib.flags |= F_PREF_INTERNAL;
re = prefix_re(p);
if (asp == NULL) /* skip pending withdraw in Adj-RIB-Out */
return;
- if ((req->flags & F_CTL_BEST) && re != NULL && re->active != p)
+ if ((req->flags & F_CTL_BEST) && re != NULL && prefix_best(re) != p)
return;
if ((req->flags & F_CTL_INVALID) &&
(asp->flags & F_ATTR_PARSE_ERR) == 0)
static void
rde_softreconfig_out(struct rib_entry *re, void *bula)
{
- struct prefix *p = re->active;
+ struct prefix *p;
struct rde_peer *peer;
uint8_t aid = re->prefix->aid;
- if (p == NULL)
+ if ((p = prefix_best(re)) == NULL)
/* no valid path for prefix */
return;
if (p->flags & PREFIX_NEXTHOP_LINKED)
nexthop_unlink(p);
}
- re->active = NULL;
return;
}
/* evaluation process is turned on, so evaluate all prefixes again */
- re->active = NULL;
prefixes = re->prefix_h;
LIST_INIT(&re->prefix_h);
static void
rde_softreconfig_sync_fib(struct rib_entry *re, void *bula)
{
- if (re->active)
- rde_send_kroute(re_rib(re), re->active, NULL);
+ struct prefix *p;
+
+ if ((p = prefix_best(re)) != NULL)
+ rde_send_kroute(re_rib(re), p, NULL);
}
static void
-/* $OpenBSD: rde.h,v 1.249 2022/03/21 13:33:20 claudio Exp $ */
+/* $OpenBSD: rde.h,v 1.250 2022/03/21 17:35:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
struct rib_entry {
RB_ENTRY(rib_entry) rib_e;
struct prefix_list prefix_h;
- struct prefix *active; /* for fast access */
struct pt_entry *prefix;
uint16_t rib_id;
uint16_t lock;
int community_to_rd(struct community *, uint64_t *);
/* rde_decide.c */
-int prefix_eligible(struct prefix *);
-void prefix_evaluate(struct rib_entry *, struct prefix *, struct prefix *);
+int prefix_eligible(struct prefix *);
+struct prefix *prefix_best(struct rib_entry *);
+void prefix_evaluate(struct rib_entry *, struct prefix *,
+ struct prefix *);
/* rde_filter.c */
void rde_apply_set(struct filter_set_head *, struct rde_peer *,
-/* $OpenBSD: rde_decide.c,v 1.89 2022/03/03 13:06:15 claudio Exp $ */
+/* $OpenBSD: rde_decide.c,v 1.90 2022/03/21 17:35:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
return 1;
}
+struct prefix *
+prefix_best(struct rib_entry *re)
+{
+ struct prefix *xp;
+ struct rib *rib;
+
+ rib = re_rib(re);
+ if (rib->flags & F_RIB_NOEVALUATE)
+ /* decision process is turned off */
+ return NULL;
+
+ xp = LIST_FIRST(&re->prefix_h);
+ if (xp != NULL && !prefix_eligible(xp))
+ xp = NULL;
+ return xp;
+}
+
/*
* Find the correct place to insert the prefix in the prefix list.
* If the active prefix has changed we need to send an update also special
void
prefix_evaluate(struct rib_entry *re, struct prefix *new, struct prefix *old)
{
- struct prefix *xp;
+ struct prefix *xp, *active;
struct rib *rib;
rib = re_rib(re);
LIST_REMOVE(old, entry.list.rib);
if (new != NULL)
LIST_INSERT_HEAD(&re->prefix_h, new, entry.list.rib);
- if (re->active) {
- /*
- * During reloads it is possible that the decision
- * process is turned off but prefixes are still
- * active. Clean up now to ensure that the RIB
- * is consistant.
- */
- rde_generate_updates(rib, NULL, re->active, 0);
- re->active = NULL;
- }
return;
}
+ active = prefix_best(re);
+
if (old != NULL)
prefix_remove(old, re);
* If the active prefix changed or the active prefix was removed
* and added again then generate an update.
*/
- if (re->active != xp || (old != NULL && xp == old)) {
+ if (active != xp || (old != NULL && xp == old)) {
/*
* Send update withdrawing re->active and adding xp
* but remember that xp may be NULL aka ineligible.
* Additional decision may be made by the called functions.
*/
- rde_generate_updates(rib, xp, re->active, 0);
+ rde_generate_updates(rib, xp, active, 0);
if ((rib->flags & F_RIB_NOFIB) == 0)
- rde_send_kroute(rib, xp, re->active);
- re->active = xp;
+ rde_send_kroute(rib, xp, active);
return;
}
*/
if (rde_evaluate_all())
if ((new != NULL && prefix_eligible(new)) || old != NULL)
- rde_generate_updates(rib, re->active, NULL, 1);
+ rde_generate_updates(rib, prefix_best(re), NULL, 1);
}
-/* $OpenBSD: rde_peer.c,v 1.13 2022/02/06 09:51:19 claudio Exp $ */
+/* $OpenBSD: rde_peer.c,v 1.14 2022/03/21 17:35:56 claudio Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
rde_up_dump_upcall(struct rib_entry *re, void *ptr)
{
struct rde_peer *peer = ptr;
+ struct prefix *p;
if (peer->state != PEER_UP)
return;
aid2str(re->prefix->aid));
/* no eligible prefix, not even for 'evaluate all' */
- if (re->active == NULL)
+ if ((p = prefix_best(re)) == NULL)
return;
- up_generate_updates(out_rules, peer, re->active, NULL);
+ up_generate_updates(out_rules, peer, p, NULL);
}
static void
-/* $OpenBSD: rde_rib.c,v 1.235 2022/03/21 13:33:20 claudio Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.236 2022/03/21 17:35:56 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
*/
if (state == NEXTHOP_REACH) {
if ((re_rib(re)->flags & F_RIB_NOFIB) == 0 &&
- p == re->active)
+ p == prefix_best(re))
rde_send_kroute(re_rib(re), p, NULL);
}
return;