2017-05-15 10:10:51 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- Route Display Routines
|
|
|
|
*
|
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
|
|
|
* (c) 2017 Jan Moskyto Matejka <mq@jmq.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef LOCAL_DEBUG
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
2023-10-29 15:25:01 +00:00
|
|
|
#include "nest/route.h"
|
2017-05-15 10:10:51 +00:00
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/cli.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "filter/filter.h"
|
2021-12-02 02:30:39 +00:00
|
|
|
#include "filter/data.h"
|
2019-12-19 15:34:35 +00:00
|
|
|
#include "sysdep/unix/krt.h"
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
static void rt_show_cont(struct cli *c);
|
|
|
|
static void rt_show_done(struct rt_show_data *d);
|
|
|
|
|
2017-05-15 10:10:51 +00:00
|
|
|
static void
|
2022-06-24 13:27:26 +00:00
|
|
|
rt_show_table(struct rt_show_data *d)
|
2017-05-15 10:10:51 +00:00
|
|
|
{
|
2022-06-24 13:27:26 +00:00
|
|
|
struct cli *c = d->cli;
|
|
|
|
|
2017-05-15 10:10:51 +00:00
|
|
|
/* No table blocks in 'show route count' */
|
|
|
|
if (d->stats == 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d->last_table) cli_printf(c, -1007, "");
|
2022-06-16 21:24:56 +00:00
|
|
|
cli_printf(c, -1007, "Table %s:",
|
2022-06-27 17:53:06 +00:00
|
|
|
d->tab->name);
|
2017-05-15 10:10:51 +00:00
|
|
|
d->last_table = d->tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-25 11:28:51 +00:00
|
|
|
rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary)
|
2017-05-15 10:10:51 +00:00
|
|
|
{
|
|
|
|
byte from[IPA_MAX_TEXT_LENGTH+8];
|
|
|
|
byte tm[TM_DATETIME_BUFFER_SIZE], info[256];
|
2022-05-30 10:03:03 +00:00
|
|
|
ea_list *a = e->attrs;
|
2022-06-27 17:53:06 +00:00
|
|
|
int sync_error = d->tab->kernel ? krt_get_sync_error(d->tab->kernel, e) : 0;
|
2023-03-30 09:37:16 +00:00
|
|
|
void (*get_route_info)(const rte *, byte *buf);
|
2023-11-08 20:51:46 +00:00
|
|
|
const eattr *nhea = net_type_match(e->net, NB_DEST) ?
|
2022-06-08 13:31:28 +00:00
|
|
|
ea_find(a, &ea_gen_nexthop) : NULL;
|
2022-05-05 16:08:37 +00:00
|
|
|
struct nexthop_adata *nhad = nhea ? (struct nexthop_adata *) nhea->u.ptr : NULL;
|
2022-06-08 09:47:49 +00:00
|
|
|
int dest = nhad ? (NEXTHOP_IS_REACHABLE(nhad) ? RTD_UNICAST : nhad->dest) : RTD_NONE;
|
|
|
|
int flowspec_valid = net_is_flow(e->net) ? rt_get_flowspec_valid(e) : FLOWSPEC_UNKNOWN;
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2017-06-06 14:47:30 +00:00
|
|
|
tm_format_time(tm, &config->tf_route, e->lastmod);
|
2022-05-30 10:03:03 +00:00
|
|
|
ip_addr a_from = ea_get_ip(a, &ea_gen_from, IPA_NONE);
|
2022-05-05 16:08:37 +00:00
|
|
|
if (ipa_nonzero(a_from) && (!nhad || !ipa_equal(a_from, nhad->nh.gw)))
|
2022-04-20 11:56:04 +00:00
|
|
|
bsprintf(from, " from %I", a_from);
|
2017-05-15 10:10:51 +00:00
|
|
|
else
|
|
|
|
from[0] = 0;
|
|
|
|
|
2024-04-04 10:01:35 +00:00
|
|
|
/* Need to normalize the attributes for dumping */
|
|
|
|
if (d->verbose && !a->stored)
|
|
|
|
a = ea_normalize(a, EALS_NONE);
|
2019-03-14 16:22:22 +00:00
|
|
|
|
2021-09-27 14:40:28 +00:00
|
|
|
get_route_info = e->src->owner->class ? e->src->owner->class->get_route_info : NULL;
|
2017-05-15 10:10:51 +00:00
|
|
|
if (get_route_info)
|
2018-05-29 10:08:12 +00:00
|
|
|
get_route_info(e, info);
|
2017-05-15 10:10:51 +00:00
|
|
|
else
|
2022-04-20 10:24:26 +00:00
|
|
|
bsprintf(info, " (%d)", rt_get_preference(e));
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
if (d->last_table != d->tab)
|
2022-06-24 13:27:26 +00:00
|
|
|
rt_show_table(d);
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2023-11-08 20:51:46 +00:00
|
|
|
const eattr *heea;
|
2022-06-16 10:39:08 +00:00
|
|
|
struct hostentry_adata *had = NULL;
|
|
|
|
if (!net_is_flow(e->net) && (dest == RTD_NONE) && (heea = ea_find(a, &ea_gen_hostentry)))
|
|
|
|
had = (struct hostentry_adata *) heea->u.ptr;
|
|
|
|
|
|
|
|
cli_printf(c, -1007, "%-20s %s [%s %s%s]%s%s", ia,
|
|
|
|
net_is_flow(e->net) ? flowspec_valid_name(flowspec_valid) : had ? "recursive" : rta_dest_name(dest),
|
2022-08-02 20:08:59 +00:00
|
|
|
e->src->owner->name, tm, from, primary ? (sync_error ? " !" : " *") : "", info);
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
if (d->verbose)
|
Route refresh in tables uses a stale counter.
Until now, we were marking routes as REF_STALE and REF_DISCARD to
cleanup old routes after route refresh. This needed a synchronous route
table walk at both beginning and the end of route refresh routine,
marking the routes by the flags.
We avoid these walks by using a stale counter. Every route contains:
u8 stale_cycle;
Every import hook contains:
u8 stale_set;
u8 stale_valid;
u8 stale_pruned;
u8 stale_pruning;
In base_state, stale_set == stale_valid == stale_pruned == stale_pruning
and all routes' stale_cycle also have the same value.
The route refresh looks like follows:
+ ----------- + --------- + ----------- + ------------- + ------------ +
| | stale_set | stale_valid | stale_pruning | stale_pruned |
| Base | x | x | x | x |
| Begin | x+1 | x | x | x |
... now routes are being inserted with stale_cycle == (x+1)
| End | x+1 | x+1 | x | x |
... now table pruning routine is scheduled
| Prune begin | x+1 | x+1 | x+1 | x |
... now routes with stale_cycle not between stale_set and stale_valid
are deleted
| Prune end | x+1 | x+1 | x+1 | x+1 |
+ ----------- + --------- + ----------- + ------------- + ------------ +
The pruning routine is asynchronous and may have high latency in
high-load environments. Therefore, multiple route refresh requests may
happen before the pruning routine starts, leading to this situation:
| Prune begin | x+k | x+k | x -> x+k | x |
... or even
| Prune begin | x+k+1 | x+k | x -> x+k | x |
... if the prune event starts while another route refresh is running.
In such a case, the pruning routine still deletes routes not fitting
between stale_set and and stale_valid, effectively pruning the remnants
of all unpruned route refreshes from before:
| Prune end | x+k | x+k | x+k | x+k |
In extremely rare cases, there may happen too many route refreshes
before any route prune routine finishes. If the difference between
stale_valid and stale_pruned becomes more than 128 when requesting for
another route refresh, the routine walks the table synchronously and
resets all the stale values to a base state, while logging a warning.
2022-07-12 08:36:10 +00:00
|
|
|
{
|
2022-05-30 10:03:03 +00:00
|
|
|
ea_show_list(c, a);
|
2023-11-01 17:08:49 +00:00
|
|
|
cli_printf(c, -1008, "\tInternal route handling values: %luL %uG %uS id %u",
|
2022-07-15 12:57:02 +00:00
|
|
|
e->src->private_id, e->src->global_id, e->stale_cycle, e->id);
|
Route refresh in tables uses a stale counter.
Until now, we were marking routes as REF_STALE and REF_DISCARD to
cleanup old routes after route refresh. This needed a synchronous route
table walk at both beginning and the end of route refresh routine,
marking the routes by the flags.
We avoid these walks by using a stale counter. Every route contains:
u8 stale_cycle;
Every import hook contains:
u8 stale_set;
u8 stale_valid;
u8 stale_pruned;
u8 stale_pruning;
In base_state, stale_set == stale_valid == stale_pruned == stale_pruning
and all routes' stale_cycle also have the same value.
The route refresh looks like follows:
+ ----------- + --------- + ----------- + ------------- + ------------ +
| | stale_set | stale_valid | stale_pruning | stale_pruned |
| Base | x | x | x | x |
| Begin | x+1 | x | x | x |
... now routes are being inserted with stale_cycle == (x+1)
| End | x+1 | x+1 | x | x |
... now table pruning routine is scheduled
| Prune begin | x+1 | x+1 | x+1 | x |
... now routes with stale_cycle not between stale_set and stale_valid
are deleted
| Prune end | x+1 | x+1 | x+1 | x+1 |
+ ----------- + --------- + ----------- + ------------- + ------------ +
The pruning routine is asynchronous and may have high latency in
high-load environments. Therefore, multiple route refresh requests may
happen before the pruning routine starts, leading to this situation:
| Prune begin | x+k | x+k | x -> x+k | x |
... or even
| Prune begin | x+k+1 | x+k | x -> x+k | x |
... if the prune event starts while another route refresh is running.
In such a case, the pruning routine still deletes routes not fitting
between stale_set and and stale_valid, effectively pruning the remnants
of all unpruned route refreshes from before:
| Prune end | x+k | x+k | x+k | x+k |
In extremely rare cases, there may happen too many route refreshes
before any route prune routine finishes. If the difference between
stale_valid and stale_pruned becomes more than 128 when requesting for
another route refresh, the routine walks the table synchronously and
resets all the stale values to a base state, while logging a warning.
2022-07-12 08:36:10 +00:00
|
|
|
}
|
2022-06-27 11:39:28 +00:00
|
|
|
else if (dest == RTD_UNICAST)
|
|
|
|
ea_show_nexthop_list(c, nhad);
|
|
|
|
else if (had)
|
|
|
|
{
|
|
|
|
char hetext[256];
|
|
|
|
ea_show_hostentry(&had->ad, hetext, sizeof hetext);
|
|
|
|
cli_printf(c, -1007, "\t%s", hetext);
|
|
|
|
}
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
2021-06-21 15:07:31 +00:00
|
|
|
static void
|
2024-05-02 09:39:34 +00:00
|
|
|
rt_show_net(struct rt_show_data *d, const struct rt_export_feed *feed)
|
2017-05-15 10:10:51 +00:00
|
|
|
{
|
2022-06-24 13:27:26 +00:00
|
|
|
struct cli *c = d->cli;
|
2022-09-14 23:38:18 +00:00
|
|
|
byte ia[NET_MAX_TEXT_LENGTH+16+1];
|
2017-05-15 10:10:51 +00:00
|
|
|
struct channel *ec = d->tab->export_channel;
|
2019-08-17 06:59:06 +00:00
|
|
|
|
|
|
|
/* The Clang static analyzer complains that ec may be NULL.
|
|
|
|
* It should be ensured to be not NULL by rt_show_prepare_tables() */
|
2020-05-01 13:41:42 +00:00
|
|
|
ASSUME(!d->export_mode || ec);
|
2019-08-17 06:59:06 +00:00
|
|
|
|
2017-05-15 10:10:51 +00:00
|
|
|
int first = 1;
|
2021-12-02 03:05:17 +00:00
|
|
|
int first_show = 1;
|
2023-11-08 20:51:46 +00:00
|
|
|
uint last_label = 0;
|
2017-05-15 10:10:51 +00:00
|
|
|
int pass = 0;
|
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
for (uint i = 0; i < feed->count_routes; i++)
|
2017-05-15 10:10:51 +00:00
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
rte *e = &feed->block[i];
|
|
|
|
if (e->flags & REF_OBSOLETE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!d->tab->prefilter && (rte_is_filtered(e) != d->filtered))
|
2017-05-15 10:10:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
d->rt_counter++;
|
|
|
|
d->net_counter += first;
|
|
|
|
first = 0;
|
|
|
|
|
|
|
|
if (pass)
|
|
|
|
continue;
|
|
|
|
|
2022-06-16 21:24:56 +00:00
|
|
|
if (d->tab->prefilter)
|
2024-05-02 09:39:34 +00:00
|
|
|
if (e->sender != d->tab->prefilter->in_req.hook)
|
2022-06-16 21:24:56 +00:00
|
|
|
continue;
|
2024-05-02 09:39:34 +00:00
|
|
|
else
|
|
|
|
e->attrs = ea_strip_to(e->attrs, BIT32_ALL(EALS_PREIMPORT));
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
/* Export channel is down, do not try to export routes to it */
|
2024-05-02 09:39:34 +00:00
|
|
|
if (ec && (rt_export_get_state(&ec->out_req) == TES_DOWN))
|
2017-05-15 10:10:51 +00:00
|
|
|
goto skip;
|
|
|
|
|
2019-09-09 00:55:32 +00:00
|
|
|
if (d->export_mode == RSEM_EXPORTED)
|
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
if (!bmap_test(&ec->export_accepted_map, e->id))
|
2019-09-09 00:55:32 +00:00
|
|
|
goto skip;
|
|
|
|
|
|
|
|
// if (ec->ra_mode != RA_ANY)
|
|
|
|
// pass = 1;
|
|
|
|
}
|
|
|
|
else if ((d->export_mode == RSEM_EXPORT) && (ec->ra_mode == RA_MERGED))
|
2018-02-06 16:43:55 +00:00
|
|
|
{
|
2019-09-09 00:55:32 +00:00
|
|
|
/* Special case for merged export */
|
2017-05-15 10:10:51 +00:00
|
|
|
pass = 1;
|
2024-05-02 09:39:34 +00:00
|
|
|
rte *em = rt_export_merged(ec, feed, tmp_linpool, 1);
|
2021-06-21 15:07:31 +00:00
|
|
|
|
2020-01-28 10:42:46 +00:00
|
|
|
if (em)
|
2024-05-02 09:39:34 +00:00
|
|
|
e = em;
|
2020-01-28 10:42:46 +00:00
|
|
|
else
|
|
|
|
goto skip;
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
else if (d->export_mode)
|
|
|
|
{
|
|
|
|
struct proto *ep = ec->proto;
|
2024-05-02 09:39:34 +00:00
|
|
|
int ic = ep->preexport ? ep->preexport(ec, e) : 0;
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
if (ec->ra_mode == RA_OPTIMAL || ec->ra_mode == RA_MERGED)
|
|
|
|
pass = 1;
|
|
|
|
|
|
|
|
if (ic < 0)
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
if (d->export_mode > RSEM_PREEXPORT)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* FIXME - This shows what should be exported according to current
|
|
|
|
* filters, but not what was really exported. 'configure soft'
|
|
|
|
* command may change the export filter and do not update routes.
|
|
|
|
*/
|
|
|
|
int do_export = (ic > 0) ||
|
2024-05-02 09:39:34 +00:00
|
|
|
(f_run(ec->out_filter, e, FF_SILENT) <= F_ACCEPT);
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
if (do_export != (d->export_mode == RSEM_EXPORT))
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
if ((d->export_mode == RSEM_EXPORT) && (ec->ra_mode == RA_ACCEPTED))
|
|
|
|
pass = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
if (d->show_protocol && (&d->show_protocol->sources != e->src->owner))
|
2017-05-15 10:10:51 +00:00
|
|
|
goto skip;
|
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
if (f_run(d->filter, e, 0) > F_ACCEPT)
|
2017-05-15 10:10:51 +00:00
|
|
|
goto skip;
|
|
|
|
|
|
|
|
if (d->stats < 2)
|
2021-12-02 03:05:17 +00:00
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
uint label = ea_get_int(e->attrs, &ea_gen_mpls_label, ~0U);
|
2022-09-14 23:38:18 +00:00
|
|
|
|
|
|
|
if (first_show || (last_label != label))
|
|
|
|
{
|
2023-11-08 20:51:46 +00:00
|
|
|
if (!~label)
|
2024-05-02 09:39:34 +00:00
|
|
|
net_format(feed->ni->addr, ia, sizeof(ia));
|
2022-09-14 23:38:18 +00:00
|
|
|
else
|
2024-05-02 09:39:34 +00:00
|
|
|
bsnprintf(ia, sizeof(ia), "%N mpls %d", feed->ni->addr, label);
|
2022-09-14 23:38:18 +00:00
|
|
|
}
|
2021-12-02 03:05:17 +00:00
|
|
|
else
|
|
|
|
ia[0] = 0;
|
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
rt_show_rte(c, ia, e, d, !d->tab->prefilter && !i);
|
2021-12-02 03:05:17 +00:00
|
|
|
first_show = 0;
|
2022-09-14 23:38:18 +00:00
|
|
|
last_label = label;
|
2021-12-02 03:05:17 +00:00
|
|
|
}
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
d->show_counter++;
|
|
|
|
|
|
|
|
skip:
|
|
|
|
if (d->primary_only)
|
|
|
|
break;
|
2024-05-02 09:39:34 +00:00
|
|
|
#undef e
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
2022-06-24 13:27:26 +00:00
|
|
|
|
|
|
|
if ((d->show_counter - d->show_counter_last_flush) > 64)
|
|
|
|
{
|
|
|
|
d->show_counter_last_flush = d->show_counter;
|
|
|
|
cli_write_trigger(d->cli);
|
|
|
|
}
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-06-24 13:27:26 +00:00
|
|
|
rt_show_cleanup(struct cli *c)
|
2017-05-15 10:10:51 +00:00
|
|
|
{
|
|
|
|
struct rt_show_data *d = c->rover;
|
2024-05-02 09:39:34 +00:00
|
|
|
struct rt_show_data_rtable *tab, *tabx;
|
2023-01-19 09:53:09 +00:00
|
|
|
c->cleanup = NULL;
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
/* Cancel the feeds */
|
|
|
|
WALK_LIST_DELSAFE(tab, tabx, d->tables)
|
2017-05-15 10:10:51 +00:00
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
if (rt_export_feed_active(&tab->req))
|
|
|
|
rt_feeder_unsubscribe(&tab->req);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
2022-06-24 13:27:26 +00:00
|
|
|
}
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2022-06-24 13:27:26 +00:00
|
|
|
static void
|
2024-05-02 09:39:34 +00:00
|
|
|
rt_show_done(struct rt_show_data *d)
|
2022-06-24 13:27:26 +00:00
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
/* Force the cleanup */
|
|
|
|
rt_show_cleanup(d->cli);
|
2021-12-02 02:30:39 +00:00
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
/* Write pending messages */
|
|
|
|
cli_write_trigger(d->cli);
|
2022-06-24 13:27:26 +00:00
|
|
|
|
2022-07-13 09:19:00 +00:00
|
|
|
/* No more action */
|
|
|
|
d->cli->cleanup = NULL;
|
|
|
|
d->cli->cont = NULL;
|
|
|
|
d->cli->rover = NULL;
|
|
|
|
}
|
|
|
|
|
2022-06-24 13:27:26 +00:00
|
|
|
static void
|
2024-05-02 09:39:34 +00:00
|
|
|
rt_show_cont(struct cli *c)
|
2022-06-24 13:27:26 +00:00
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
struct rt_show_data *d = c->rover;
|
2021-12-02 02:30:39 +00:00
|
|
|
|
2022-06-24 13:27:26 +00:00
|
|
|
if (d->running_on_config && (d->running_on_config != config))
|
|
|
|
{
|
|
|
|
cli_printf(c, 8004, "Stopped due to reconfiguration");
|
2022-07-13 09:19:00 +00:00
|
|
|
return rt_show_done(d);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 13:27:26 +00:00
|
|
|
d->table_counter++;
|
2021-12-02 02:30:39 +00:00
|
|
|
|
2022-06-24 13:27:26 +00:00
|
|
|
d->show_counter_last = d->show_counter;
|
|
|
|
d->rt_counter_last = d->rt_counter;
|
|
|
|
d->net_counter_last = d->net_counter;
|
2022-02-04 04:34:02 +00:00
|
|
|
|
2022-06-24 13:27:26 +00:00
|
|
|
if (d->tables_defined_by & RSD_TDB_SET)
|
|
|
|
rt_show_table(d);
|
2021-12-02 01:22:30 +00:00
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
RT_FEED_WALK(&d->tab->req, f)
|
|
|
|
if (f->count_routes)
|
|
|
|
rt_show_net(d, f);
|
2021-12-02 02:30:39 +00:00
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
if (rt_export_feed_active(&d->tab->req))
|
|
|
|
rt_feeder_unsubscribe(&d->tab->req);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cli_printf(c, 8004, "Table is shutting down");
|
|
|
|
return rt_show_done(d);
|
|
|
|
}
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
if (d->stats)
|
|
|
|
{
|
|
|
|
if (d->last_table != d->tab)
|
2022-06-24 13:27:26 +00:00
|
|
|
rt_show_table(d);
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2022-06-24 13:27:26 +00:00
|
|
|
cli_printf(d->cli, -1007, "%d of %d routes for %d networks in table %s",
|
2024-05-02 09:39:34 +00:00
|
|
|
d->show_counter - d->show_counter_last, d->rt_counter - d->rt_counter_last,
|
|
|
|
d->net_counter - d->net_counter_last, d->tab->name);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
d->tab = NODE_NEXT(d->tab);
|
|
|
|
|
|
|
|
if (NODE_VALID(d->tab))
|
2024-05-02 09:39:34 +00:00
|
|
|
/* Gonna be called later by this_cli->cont() */
|
|
|
|
return;
|
2022-06-24 13:27:26 +00:00
|
|
|
|
|
|
|
/* Printout total stats */
|
2017-05-15 10:10:51 +00:00
|
|
|
if (d->stats && (d->table_counter > 1))
|
|
|
|
{
|
2022-06-24 13:27:26 +00:00
|
|
|
if (d->last_table) cli_printf(d->cli, -1007, "");
|
|
|
|
cli_printf(d->cli, 14, "Total: %d of %d routes for %d networks in %d tables",
|
2024-05-02 09:39:34 +00:00
|
|
|
d->show_counter, d->rt_counter, d->net_counter, d->table_counter);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
2022-06-27 17:53:06 +00:00
|
|
|
else if (!d->rt_counter && ((d->addr_mode == TE_ADDR_EQUAL) || (d->addr_mode == TE_ADDR_FOR)))
|
|
|
|
cli_printf(d->cli, 8001, "Network not found");
|
2017-05-15 10:10:51 +00:00
|
|
|
else
|
2022-06-24 13:27:26 +00:00
|
|
|
cli_printf(d->cli, 0, "");
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2022-07-13 09:19:00 +00:00
|
|
|
/* No more route showing */
|
|
|
|
rt_show_done(d);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 17:53:06 +00:00
|
|
|
struct rt_show_data_rtable *
|
2024-05-29 07:33:42 +00:00
|
|
|
rt_show_add_exporter(struct rt_show_data *d, struct rt_exporter *e)
|
2022-06-27 17:53:06 +00:00
|
|
|
{
|
2024-02-29 13:04:05 +00:00
|
|
|
struct rt_show_data_rtable *tab = cfg_allocz(sizeof(struct rt_show_data_rtable));
|
2024-05-29 07:33:42 +00:00
|
|
|
tab->name = e->name;
|
|
|
|
tab->exporter = e;
|
2024-02-29 13:04:05 +00:00
|
|
|
add_tail(&(d->tables), &(tab->n));
|
2024-05-29 07:33:42 +00:00
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rt_show_data_rtable *
|
|
|
|
rt_show_add_table(struct rt_show_data *d, rtable *t)
|
|
|
|
{
|
|
|
|
struct rt_show_data_rtable *tab = rt_show_add_exporter(d, &t->export_all);
|
|
|
|
tab->name = t->name;
|
2022-06-27 17:53:06 +00:00
|
|
|
|
|
|
|
struct proto_config *krt = t->config->krt_attached;
|
|
|
|
if (krt)
|
2024-02-29 13:04:05 +00:00
|
|
|
tab->kernel = (struct krt_proto *) krt->proto;
|
2022-06-27 17:53:06 +00:00
|
|
|
|
2024-02-29 13:04:05 +00:00
|
|
|
return tab;
|
2022-06-27 17:53:06 +00:00
|
|
|
}
|
|
|
|
|
2017-05-15 10:10:51 +00:00
|
|
|
static inline void
|
|
|
|
rt_show_get_default_tables(struct rt_show_data *d)
|
|
|
|
{
|
|
|
|
struct channel *c;
|
|
|
|
struct rt_show_data_rtable *tab;
|
|
|
|
|
|
|
|
if (d->export_channel)
|
|
|
|
{
|
|
|
|
c = d->export_channel;
|
|
|
|
tab = rt_show_add_table(d, c->table);
|
|
|
|
tab->export_channel = c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->export_protocol)
|
|
|
|
{
|
|
|
|
WALK_LIST(c, d->export_protocol->channels)
|
|
|
|
{
|
2024-05-02 09:39:34 +00:00
|
|
|
if (rt_export_get_state(&c->out_req) == TES_DOWN)
|
2017-05-15 10:10:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
tab = rt_show_add_table(d, c->table);
|
|
|
|
tab->export_channel = c;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->show_protocol)
|
|
|
|
{
|
|
|
|
WALK_LIST(c, d->show_protocol->channels)
|
|
|
|
rt_show_add_table(d, c->table);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=1; i<NET_MAX; i++)
|
2022-09-01 12:21:56 +00:00
|
|
|
if (config->def_tables[i] && config->def_tables[i]->table && config->def_tables[i]->table->table)
|
|
|
|
rt_show_add_table(d, config->def_tables[i]->table->table);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
rt_show_prepare_tables(struct rt_show_data *d)
|
|
|
|
{
|
|
|
|
struct rt_show_data_rtable *tab, *tabx;
|
|
|
|
|
|
|
|
/* Add implicit tables if no table is specified */
|
|
|
|
if (EMPTY_LIST(d->tables))
|
|
|
|
rt_show_get_default_tables(d);
|
|
|
|
|
|
|
|
WALK_LIST_DELSAFE(tab, tabx, d->tables)
|
|
|
|
{
|
2024-05-29 07:33:42 +00:00
|
|
|
struct rt_exporter *ex = tab->exporter;
|
|
|
|
|
2017-05-15 10:10:51 +00:00
|
|
|
/* Ensure there is defined export_channel for each table */
|
|
|
|
if (d->export_mode)
|
|
|
|
{
|
|
|
|
if (!tab->export_channel && d->export_channel &&
|
2024-05-29 07:33:42 +00:00
|
|
|
(ex == &d->export_channel->table->export_all))
|
2017-05-15 10:10:51 +00:00
|
|
|
tab->export_channel = d->export_channel;
|
|
|
|
|
|
|
|
if (!tab->export_channel && d->export_protocol)
|
2024-05-29 07:33:42 +00:00
|
|
|
tab->export_channel = proto_find_channel_by_table(d->export_protocol, SKIP_BACK(rtable, export_all, ex));
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
if (!tab->export_channel)
|
|
|
|
{
|
|
|
|
if (d->tables_defined_by & RSD_TDB_NMN)
|
2022-06-27 17:53:06 +00:00
|
|
|
cf_error("No export channel for table %s", tab->name);
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
rem_node(&(tab->n));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure specified network is compatible with each table */
|
2024-05-29 07:33:42 +00:00
|
|
|
if (d->addr && (ex->net_type != d->addr->type))
|
2017-05-15 10:10:51 +00:00
|
|
|
{
|
|
|
|
if (d->tables_defined_by & RSD_TDB_NMN)
|
2022-06-27 17:53:06 +00:00
|
|
|
cf_error("Incompatible type of prefix/ip for table %s", tab->name);
|
2017-05-15 10:10:51 +00:00
|
|
|
|
|
|
|
rem_node(&(tab->n));
|
|
|
|
continue;
|
|
|
|
}
|
2024-05-02 09:39:34 +00:00
|
|
|
|
|
|
|
/* Open the export request */
|
|
|
|
tab->req = (struct rt_export_feeder) {
|
|
|
|
.name = "cli.feeder",
|
|
|
|
.prefilter = {
|
|
|
|
.addr = d->addr,
|
|
|
|
.mode = d->addr_mode,
|
|
|
|
},
|
|
|
|
.trace_routes = config->show_route_debug,
|
|
|
|
};
|
|
|
|
|
2024-05-29 07:33:42 +00:00
|
|
|
rt_feeder_subscribe(ex, &tab->req);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure there is at least one table */
|
|
|
|
if (EMPTY_LIST(d->tables))
|
|
|
|
cf_error("No valid tables");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rt_show(struct rt_show_data *d)
|
|
|
|
{
|
|
|
|
/* Filtered routes are neither exported nor have sensible ordering */
|
|
|
|
if (d->filtered && (d->export_mode || d->primary_only))
|
|
|
|
cf_error("Incompatible show route options");
|
|
|
|
|
|
|
|
rt_show_prepare_tables(d);
|
|
|
|
|
2022-06-27 17:53:06 +00:00
|
|
|
if (EMPTY_LIST(d->tables))
|
|
|
|
cf_error("No suitable tables found");
|
2022-06-24 13:27:26 +00:00
|
|
|
|
2022-06-27 17:53:06 +00:00
|
|
|
d->tab = HEAD(d->tables);
|
2022-06-24 13:27:26 +00:00
|
|
|
|
2022-06-27 17:53:06 +00:00
|
|
|
this_cli->cleanup = rt_show_cleanup;
|
|
|
|
this_cli->rover = d;
|
2024-05-02 09:39:34 +00:00
|
|
|
this_cli->cont = rt_show_cont;
|
2017-05-15 10:10:51 +00:00
|
|
|
|
2024-05-02 09:39:34 +00:00
|
|
|
cli_write_trigger(this_cli);
|
2017-05-15 10:10:51 +00:00
|
|
|
}
|