-/* $OpenBSD: mrt.c,v 1.106 2022/02/06 09:51:19 claudio Exp $ */
+/* $OpenBSD: mrt.c,v 1.107 2022/03/22 10:53:08 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
*np = 0;
*app = 0;
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib) {
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) {
struct nexthop *nexthop;
struct bgpd_addr *nh;
struct ibuf *tbuf;
* dumps the table so we do the same. If only the active route should
* be dumped p should be set to p = pt->active.
*/
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib) {
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) {
if (mrtbuf->type == MRT_TABLE_DUMP)
mrt_dump_entry(mrtbuf, p, mrtbuf->seqnum++,
prefix_peer(p));
-/* $OpenBSD: rde.c,v 1.543 2022/03/21 17:35:56 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.544 2022/03/22 10:53:08 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
struct rde_dump_ctx *ctx = ptr;
struct prefix *p;
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib)
rde_dump_filter(p, &ctx->req, 0);
}
return;
if (!prefix_compare(&ctx->req.prefix, &addr,
ctx->req.prefixlen))
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib)
rde_dump_filter(p, &ctx->req, 0);
} else {
if (ctx->req.prefixlen < pt->prefixlen)
return;
if (!prefix_compare(&addr, &ctx->req.prefix,
pt->prefixlen))
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib)
rde_dump_filter(p, &ctx->req, 0);
}
}
pt = re->prefix;
pt_getaddr(pt, &prefix);
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib) {
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) {
asp = prefix_aspath(p);
peer = prefix_peer(p);
static void
rde_softreconfig_sync_reeval(struct rib_entry *re, void *arg)
{
- struct prefix_list prefixes;
+ struct prefix_queue prefixes = TAILQ_HEAD_INITIALIZER(prefixes);
struct prefix *p, *next;
struct rib *rib = arg;
* all dependent adj-rib-out were already flushed
* unlink nexthop if it was linked
*/
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib) {
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) {
if (p->flags & PREFIX_NEXTHOP_LINKED)
nexthop_unlink(p);
}
}
/* evaluation process is turned on, so evaluate all prefixes again */
- prefixes = re->prefix_h;
- LIST_INIT(&re->prefix_h);
+ TAILQ_CONCAT(&prefixes, &re->prefix_h, entry.list.rib);
/*
* TODO: this code works but is not optimal. prefix_evaluate()
* to resort the list once and then call rde_generate_updates()
* and rde_send_kroute() once.
*/
- LIST_FOREACH_SAFE(p, &prefixes, entry.list.rib, next) {
+ TAILQ_FOREACH_SAFE(p, &prefixes, entry.list.rib, next) {
/* need to re-link the nexthop if not already linked */
- LIST_REMOVE(p, entry.list.rib);
+ TAILQ_REMOVE(&prefixes, p, entry.list.rib);
if ((p->flags & PREFIX_NEXTHOP_LINKED) == 0)
nexthop_link(p);
prefix_evaluate(re, p, NULL);
pt = re->prefix;
pt_getaddr(pt, &prefix);
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib) {
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) {
asp = prefix_aspath(p);
peer = prefix_peer(p);
struct bgpd_addr addr;
struct rde_dump_ctx *ctx = ptr;
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib) {
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) {
asp = prefix_aspath(p);
if (!(asp->flags & F_PREFIX_ANNOUNCED))
continue;
-/* $OpenBSD: rde.h,v 1.250 2022/03/21 17:35:56 claudio Exp $ */
+/* $OpenBSD: rde.h,v 1.251 2022/03/22 10:53:08 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
};
LIST_HEAD(prefix_list, prefix);
+TAILQ_HEAD(prefix_queue, prefix);
RB_HEAD(rib_tree, rib_entry);
struct rib_entry {
RB_ENTRY(rib_entry) rib_e;
- struct prefix_list prefix_h;
+ struct prefix_queue prefix_h;
struct pt_entry *prefix;
uint16_t rib_id;
uint16_t lock;
struct prefix {
union {
struct {
- LIST_ENTRY(prefix) rib, nexthop;
+ TAILQ_ENTRY(prefix) rib;
+ LIST_ENTRY(prefix) nexthop;
struct rib_entry *re;
} list;
struct {
-/* $OpenBSD: rde_decide.c,v 1.90 2022/03/21 17:35:56 claudio Exp $ */
+/* $OpenBSD: rde_decide.c,v 1.91 2022/03/22 10:53:08 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
void
prefix_insert(struct prefix *new, struct prefix *ep, struct rib_entry *re)
{
- struct prefix_list redo = LIST_HEAD_INITIALIZER(redo);
- struct prefix *xp, *np, *tailp = NULL, *insertp = ep;
+ struct prefix_queue redo = TAILQ_HEAD_INITIALIZER(redo);
+ struct prefix *xp, *np, *insertp = ep;
int testall, selected = 0;
/* start scan at the entry point (ep) or the head if ep == NULL */
if (ep == NULL)
- ep = LIST_FIRST(&re->prefix_h);
+ ep = TAILQ_FIRST(&re->prefix_h);
for (xp = ep; xp != NULL; xp = np) {
- np = LIST_NEXT(xp, entry.list.rib);
+ np = TAILQ_NEXT(xp, entry.list.rib);
if (prefix_cmp(new, xp, &testall) > 0) {
/* new is preferred over xp */
* MED inversion, take out prefix and
* put it onto redo queue.
*/
- LIST_REMOVE(xp, entry.list.rib);
- if (tailp == NULL)
- LIST_INSERT_HEAD(&redo, xp,
- entry.list.rib);
- else
- LIST_INSERT_AFTER(tailp, xp,
- entry.list.rib);
- tailp = xp;
+ TAILQ_REMOVE(&re->prefix_h, xp, entry.list.rib);
+ TAILQ_INSERT_TAIL(&redo, xp, entry.list.rib);
} else {
/*
* lock insertion point and
}
if (insertp == NULL)
- LIST_INSERT_HEAD(&re->prefix_h, new, entry.list.rib);
+ TAILQ_INSERT_HEAD(&re->prefix_h, new, entry.list.rib);
else
- LIST_INSERT_AFTER(insertp, new, entry.list.rib);
+ TAILQ_INSERT_AFTER(&re->prefix_h, insertp, new, entry.list.rib);
/* Fixup MED order again. All elements are < new */
- while (!LIST_EMPTY(&redo)) {
- xp = LIST_FIRST(&redo);
- LIST_REMOVE(xp, entry.list.rib);
+ while (!TAILQ_EMPTY(&redo)) {
+ xp = TAILQ_FIRST(&redo);
+ TAILQ_REMOVE(&redo, xp, entry.list.rib);
prefix_insert(xp, new, re);
}
void
prefix_remove(struct prefix *old, struct rib_entry *re)
{
- struct prefix_list redo = LIST_HEAD_INITIALIZER(redo);
- struct prefix *xp, *np, *tailp = NULL;
+ struct prefix_queue redo = TAILQ_HEAD_INITIALIZER(redo);
+ struct prefix *xp, *np;
int testall;
- xp = LIST_NEXT(old, entry.list.rib);
- LIST_REMOVE(old, entry.list.rib);
+ xp = TAILQ_NEXT(old, entry.list.rib);
+ TAILQ_REMOVE(&re->prefix_h, old, entry.list.rib);
/* check if a MED inversion could be possible */
prefix_cmp(old, xp, &testall);
if (testall > 0) {
/* maybe MED route, scan tail for other possible routes */
for (; xp != NULL; xp = np) {
- np = LIST_NEXT(xp, entry.list.rib);
+ np = TAILQ_NEXT(xp, entry.list.rib);
/* only interested in the testall result */
prefix_cmp(old, xp, &testall);
* possible MED inversion, take out prefix and
* put it onto redo queue.
*/
- LIST_REMOVE(xp, entry.list.rib);
- if (tailp == NULL)
- LIST_INSERT_HEAD(&redo, xp,
- entry.list.rib);
- else
- LIST_INSERT_AFTER(tailp, xp,
- entry.list.rib);
- tailp = xp;
+ TAILQ_REMOVE(&re->prefix_h, xp, entry.list.rib);
+ TAILQ_INSERT_TAIL(&redo, xp, entry.list.rib);
}
}
}
/* Fixup MED order again, reinsert prefixes from the start */
- while (!LIST_EMPTY(&redo)) {
- xp = LIST_FIRST(&redo);
- LIST_REMOVE(xp, entry.list.rib);
+ while (!TAILQ_EMPTY(&redo)) {
+ xp = TAILQ_FIRST(&redo);
+ TAILQ_REMOVE(&redo, xp, entry.list.rib);
prefix_insert(xp, NULL, re);
}
/* decision process is turned off */
return NULL;
- xp = LIST_FIRST(&re->prefix_h);
+ xp = TAILQ_FIRST(&re->prefix_h);
if (xp != NULL && !prefix_eligible(xp))
xp = NULL;
return xp;
if (rib->flags & F_RIB_NOEVALUATE) {
/* decision process is turned off */
if (old != NULL)
- LIST_REMOVE(old, entry.list.rib);
+ TAILQ_REMOVE(&re->prefix_h, old, entry.list.rib);
if (new != NULL)
- LIST_INSERT_HEAD(&re->prefix_h, new, entry.list.rib);
+ TAILQ_INSERT_HEAD(&re->prefix_h, new, entry.list.rib);
return;
}
if (new != NULL)
prefix_insert(new, NULL, re);
- xp = LIST_FIRST(&re->prefix_h);
+ xp = TAILQ_FIRST(&re->prefix_h);
if (xp != NULL && !prefix_eligible(xp))
xp = NULL;
-/* $OpenBSD: rde_peer.c,v 1.14 2022/03/21 17:35:56 claudio Exp $ */
+/* $OpenBSD: rde_peer.c,v 1.15 2022/03/22 10:53:08 claudio Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
pt_getaddr(re->prefix, &addr);
prefixlen = re->prefix->prefixlen;
- LIST_FOREACH_SAFE(p, &re->prefix_h, entry.list.rib, np) {
+ TAILQ_FOREACH_SAFE(p, &re->prefix_h, entry.list.rib, np) {
if (peer != prefix_peer(p))
continue;
if (staletime && p->lastchange > staletime)
-/* $OpenBSD: rde_rib.c,v 1.236 2022/03/21 17:35:56 claudio Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.237 2022/03/22 10:53:08 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
* an empty check in prefix_destroy() it is not possible to
* use the default for loop.
*/
- while ((p = LIST_FIRST(&re->prefix_h))) {
+ while ((p = TAILQ_FIRST(&re->prefix_h))) {
struct rde_aspath *asp = prefix_aspath(p);
if (asp && asp->pftableid)
rde_pftable_del(asp->pftableid, p);
if ((re = calloc(1, sizeof(*re))) == NULL)
fatal("rib_add");
- LIST_INIT(&re->prefix_h);
+ TAILQ_INIT(&re->prefix_h);
re->prefix = pt_ref(pte);
re->rib_id = rib->id;
int
rib_empty(struct rib_entry *re)
{
- return LIST_EMPTY(&re->prefix_h);
+ return TAILQ_EMPTY(&re->prefix_h);
}
static struct rib_entry *
{
struct prefix *p;
- LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
+ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib)
if (prefix_peer(p) == peer && p->path_id == path_id)
return (p);
return (NULL);
-/* $OpenBSD: rde_update.c,v 1.137 2022/03/15 16:50:29 claudio Exp $ */
+/* $OpenBSD: rde_update.c,v 1.138 2022/03/22 10:53:08 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
prefixlen, prefix_vstate(new), &state) == ACTION_DENY) {
rde_filterstate_clean(&state);
if (peer->flags & PEERFLAG_EVALUATE_ALL)
- new = LIST_NEXT(new, entry.list.rib);
+ new = TAILQ_NEXT(new, entry.list.rib);
else
new = NULL;
if (new != NULL && !prefix_eligible(new))