summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-03-09 12:30:05 +0100
committerMaria Matejka <mq@ucw.cz>2022-03-09 12:30:05 +0100
commit1b9189d5fdab672f91600b7e72a1deeab277eafc (patch)
treea6f5c92209a9c290fd0bb7c583fb1d606b133e66 /nest
parent69d1ffde4c724882398b3b630ea1199f12c0c288 (diff)
Route validity check converted to generic macro dispatch
Diffstat (limited to 'nest')
-rw-r--r--nest/route.h5
-rw-r--r--nest/rt-table.c27
2 files changed, 16 insertions, 16 deletions
diff --git a/nest/route.h b/nest/route.h
index ade14857..4944a854 100644
--- a/nest/route.h
+++ b/nest/route.h
@@ -259,7 +259,10 @@ struct rte_storage {
#define REF_MODIFY 16 /* Route is scheduled for modify */
/* Route is valid for propagation (may depend on other flags in the future), accepts NULL */
-static inline int rte_is_valid(rte *r) { return r && !(r->flags & REF_FILTERED); }
+static inline int rte_is_valid_rte(rte *r) { return r && !(r->flags & REF_FILTERED); }
+static inline int rte_is_valid_storage(struct rte_storage *r) { return r && rte_is_valid_rte(&r->rte); }
+
+#define rte_is_valid(r) _Generic((*r), rte: rte_is_valid_rte, struct rte_storage: rte_is_valid_storage)(r)
/* Route just has REF_FILTERED flag */
static inline int rte_is_filtered(rte *r) { return !!(r->flags & REF_FILTERED); }
diff --git a/nest/rt-table.c b/nest/rt-table.c
index ee69d7c4..c49400b7 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -170,7 +170,7 @@ net_roa_check_ip4(rtable *tab, const net_addr_ip4 *px, u32 asn)
net_addr_roa4 *roa = (void *) fn->addr;
net *r = fib_node_to_user(&tab->fib, fn);
- if (net_equal_prefix_roa4(roa, &n) && r->routes && rte_is_valid(&r->routes->rte))
+ if (net_equal_prefix_roa4(roa, &n) && rte_is_valid(r->routes))
{
anything = 1;
if (asn && (roa->asn == asn) && (roa->max_pxlen >= px->pxlen))
@@ -202,7 +202,7 @@ net_roa_check_ip6(rtable *tab, const net_addr_ip6 *px, u32 asn)
net_addr_roa6 *roa = (void *) fn->addr;
net *r = fib_node_to_user(&tab->fib, fn);
- if (net_equal_prefix_roa6(roa, &n) && r->routes && rte_is_valid(&r->routes->rte))
+ if (net_equal_prefix_roa6(roa, &n) && rte_is_valid(r->routes))
{
anything = 1;
if (asn && (roa->asn == asn) && (roa->max_pxlen >= px->pxlen))
@@ -543,7 +543,7 @@ rt_notify_accepted(struct channel *c, net *net, rte *new_changed, rte *old_chang
old_best = old_changed;
else
{
- for (struct rte_storage *r = net->routes; r && rte_is_valid(&r->rte); r = r->next)
+ for (struct rte_storage *r = net->routes; rte_is_valid(r); r = r->next)
{
if (bmap_test(&c->export_map, r->rte.id))
{
@@ -561,7 +561,7 @@ rt_notify_accepted(struct channel *c, net *net, rte *new_changed, rte *old_chang
if ((new_changed == old_changed) || (old_best == old_changed))
{
/* Feed or old_best changed -> find first accepted by filters */
- for (struct rte_storage *r = net->routes; r && rte_is_valid(&r->rte); r = r->next)
+ for (struct rte_storage *r = net->routes; rte_is_valid(r); r = r->next)
if (new_best = export_filter(c, ((nb0 = r->rte), &nb0), 0))
break;
}
@@ -596,7 +596,7 @@ rt_export_merged(struct channel *c, net *net, linpool *pool, int silent)
struct rte_storage *best0 = net->routes;
rte *best;
- if (!best0 || !rte_is_valid(&best0->rte))
+ if (!rte_is_valid(best0))
return NULL;
best = export_filter_(c, ((rme = best0->rte), &rme), pool, silent);
@@ -714,16 +714,16 @@ static void
rte_announce(rtable *tab, uint type, net *net, struct rte_storage *new, struct rte_storage *old,
struct rte_storage *new_best, struct rte_storage *old_best)
{
- if (!new || !rte_is_valid(&new->rte))
+ if (!rte_is_valid(new))
new = NULL;
- if (!old || !rte_is_valid(&old->rte))
+ if (!rte_is_valid(old))
old = NULL;
- if (!new_best || !rte_is_valid(&new_best->rte))
+ if (!rte_is_valid(new_best))
new_best = NULL;
- if (!old_best || !rte_is_valid(&old_best->rte))
+ if (!rte_is_valid(old_best))
old_best = NULL;
if (!new && !old && !new_best && !old_best)
@@ -1246,14 +1246,11 @@ rt_examine(rtable *t, net_addr *a, struct channel *c, const struct filter *filte
{
net *n = net_find(t, a);
- if (!n || !n->routes)
+ if (!n || !rte_is_valid(n->routes))
return 0;
rte rt = n->routes->rte;
- if (!rte_is_valid(&rt))
- return 0;
-
rte_update_lock();
/* Rest is stripped down export_filter() */
@@ -2151,7 +2148,7 @@ rt_feed_channel(struct channel *c)
if ((c->ra_mode == RA_OPTIMAL) ||
(c->ra_mode == RA_ACCEPTED) ||
(c->ra_mode == RA_MERGED))
- if (e && rte_is_valid(&e->rte))
+ if (rte_is_valid(e))
{
/* In the meantime, the protocol may fell down */
if (c->export_state != ES_FEEDING)
@@ -2168,7 +2165,7 @@ rt_feed_channel(struct channel *c)
if (c->export_state != ES_FEEDING)
goto done;
- if (!rte_is_valid(&e->rte))
+ if (!rte_is_valid(e))
continue;
do_feed_channel(c, n, &e->rte);