From 0bcbff42cacaa1ae2f234e2b5d37fd8b72c6b8c6 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Thu, 23 Nov 2023 23:33:44 +0100 Subject: [PATCH] Table: nicer route validation errors --- nest/rt-table.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/nest/rt-table.c b/nest/rt-table.c index a038b266d..54a471b2b 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -1614,22 +1614,19 @@ rte_validate(struct channel *ch, rte *e) int c; const net_addr *n = e->net; +#define IGNORING(pre, post) do { \ + log(L_WARN "%s.%s: Ignoring " pre " %N " post, ch->proto->name, ch->name, n); \ + return 0; \ + } while (0) + if (!net_validate(n)) - { - log(L_WARN "Ignoring bogus prefix %N received via %s", - n, ch->proto->name); - return 0; - } + IGNORING("bogus prefix", ""); /* FIXME: better handling different nettypes */ c = !net_is_flow(n) ? net_classify(n): (IADDR_HOST | SCOPE_UNIVERSE); if ((c < 0) || !(c & IADDR_HOST) || ((c & IADDR_SCOPE_MASK) <= SCOPE_LINK)) - { - log(L_WARN "Ignoring bogus route %N received via %s", - n, ch->proto->name); - return 0; - } + IGNORING("bogus route", ""); if (net_type_match(n, NB_DEST)) { @@ -1637,26 +1634,14 @@ rte_validate(struct channel *ch, rte *e) int dest = nhea_dest(nhea); if (dest == RTD_NONE) - { - log(L_WARN "Ignoring route %N with no destination received via %s", - n, ch->proto->name); - return 0; - } + IGNORING("route", "with no destination"); if ((dest == RTD_UNICAST) && !nexthop_is_sorted((struct nexthop_adata *) nhea->u.ptr)) - { - log(L_WARN "Ignoring unsorted multipath route %N received via %s", - n, ch->proto->name); - return 0; - } + IGNORING("unsorted multipath route", ""); } else if (ea_find(e->attrs, &ea_gen_nexthop)) - { - log(L_WARN "Ignoring route %N having a nexthop attribute received via %s", - n, ch->proto->name); - return 0; - } + IGNORING("route", "having a superfluous nexthop attribute"); return 1; } -- 2.47.2