1999-08-04 03:57:43 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- Table-to-Table Routing Protocol a.k.a Pipe
|
|
|
|
*
|
2000-01-17 00:44:50 +08:00
|
|
|
* (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
1999-08-04 03:57:43 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-05 00:15:37 +08:00
|
|
|
/**
|
|
|
|
* DOC: Pipe
|
|
|
|
*
|
|
|
|
* The Pipe protocol is very simple. It just connects to two routing tables
|
|
|
|
* using proto_add_announce_hook() and whenever it receives a rt_notify()
|
|
|
|
* about a change in one of the tables, it converts it to a rte_update()
|
|
|
|
* in the other one.
|
|
|
|
*
|
|
|
|
* To avoid pipe loops, Pipe keeps a `being updated' flag in each routing
|
|
|
|
* table.
|
2012-03-15 18:58:08 +08:00
|
|
|
*
|
|
|
|
* A pipe has two announce hooks, the first connected to the main
|
|
|
|
* table, the second connected to the peer table. When a new route is
|
|
|
|
* announced on the main table, it gets checked by an export filter in
|
|
|
|
* ahook 1, and, after that, it is announced to the peer table via
|
|
|
|
* rte_update(), an import filter in ahook 2 is called. When a new
|
|
|
|
* route is announced in the peer table, an export filter in ahook2
|
|
|
|
* and an import filter in ahook 1 are used. Oviously, there is no
|
2012-04-15 21:28:29 +08:00
|
|
|
* need in filtering the same route twice, so both import filters are
|
|
|
|
* set to accept, while user configured 'import' and 'export' filters
|
|
|
|
* are used as export filters in ahooks 2 and 1. Route limits are
|
|
|
|
* handled similarly, but on the import side of ahooks.
|
2000-06-05 00:15:37 +08:00
|
|
|
*/
|
|
|
|
|
2000-03-13 05:01:38 +08:00
|
|
|
#undef LOCAL_DEBUG
|
1999-08-04 03:57:43 +08:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
2012-03-15 18:58:08 +08:00
|
|
|
#include "nest/cli.h"
|
1999-08-04 03:57:43 +08:00
|
|
|
#include "conf/conf.h"
|
|
|
|
#include "filter/filter.h"
|
1999-12-01 20:01:41 +08:00
|
|
|
#include "lib/string.h"
|
1999-08-04 03:57:43 +08:00
|
|
|
|
|
|
|
#include "pipe.h"
|
|
|
|
|
|
|
|
static void
|
2010-02-13 19:26:26 +08:00
|
|
|
pipe_rt_notify(struct proto *P, rtable *src_table, net *n, rte *new, rte *old, ea_list *attrs)
|
1999-08-04 03:57:43 +08:00
|
|
|
{
|
2010-02-13 19:26:26 +08:00
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
2012-03-15 18:58:08 +08:00
|
|
|
struct announce_hook *ah = (src_table == P->table) ? p->peer_ahook : P->main_ahook;
|
|
|
|
rtable *dst_table = ah->table;
|
2012-08-14 22:25:22 +08:00
|
|
|
struct rte_src *src;
|
2010-02-13 19:26:26 +08:00
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
net *nn;
|
|
|
|
rte *e;
|
|
|
|
rta a;
|
|
|
|
|
2009-05-31 21:24:27 +08:00
|
|
|
if (!new && !old)
|
|
|
|
return;
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
if (dst_table->pipe_busy)
|
1999-08-04 03:57:43 +08:00
|
|
|
{
|
2015-11-05 19:48:52 +08:00
|
|
|
log(L_ERR "Pipe loop detected when sending %N to table %s",
|
|
|
|
n->n.addr, dst_table->name);
|
1999-08-04 03:57:43 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-03-15 18:58:08 +08:00
|
|
|
|
2015-11-05 19:48:52 +08:00
|
|
|
nn = net_get(dst_table, n->n.addr);
|
1999-08-04 03:57:43 +08:00
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
memcpy(&a, new->attrs, sizeof(rta));
|
2009-06-01 18:10:10 +08:00
|
|
|
|
|
|
|
if (p->mode == PIPE_OPAQUE)
|
|
|
|
{
|
2012-08-14 22:25:22 +08:00
|
|
|
a.src = P->main_source;
|
2009-06-01 18:10:10 +08:00
|
|
|
a.source = RTS_PIPE;
|
|
|
|
}
|
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
a.aflags = 0;
|
2000-05-13 19:02:02 +08:00
|
|
|
a.eattrs = attrs;
|
2010-07-05 23:50:19 +08:00
|
|
|
a.hostentry = NULL;
|
1999-08-04 03:57:43 +08:00
|
|
|
e = rte_get_temp(&a);
|
|
|
|
e->net = nn;
|
2009-09-17 18:40:02 +08:00
|
|
|
e->pflags = 0;
|
2009-05-31 21:24:27 +08:00
|
|
|
|
2009-06-01 18:10:10 +08:00
|
|
|
if (p->mode == PIPE_TRANSPARENT)
|
|
|
|
{
|
|
|
|
/* Copy protocol specific embedded attributes. */
|
|
|
|
memcpy(&(e->u), &(new->u), sizeof(e->u));
|
2009-09-17 18:40:02 +08:00
|
|
|
e->pref = new->pref;
|
|
|
|
e->pflags = new->pflags;
|
2009-06-01 18:10:10 +08:00
|
|
|
}
|
2009-05-31 21:24:27 +08:00
|
|
|
|
2012-08-14 22:25:22 +08:00
|
|
|
src = a.src;
|
1999-08-04 03:57:43 +08:00
|
|
|
}
|
|
|
|
else
|
2009-05-31 21:24:27 +08:00
|
|
|
{
|
|
|
|
e = NULL;
|
2012-08-14 22:25:22 +08:00
|
|
|
src = old->attrs->src;
|
2009-05-31 21:24:27 +08:00
|
|
|
}
|
|
|
|
|
2009-12-03 00:26:16 +08:00
|
|
|
src_table->pipe_busy = 1;
|
2012-08-14 22:25:22 +08:00
|
|
|
rte_update2(ah, nn, e, src);
|
2009-12-03 00:26:16 +08:00
|
|
|
src_table->pipe_busy = 0;
|
1999-08-04 03:57:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-05 17:27:35 +08:00
|
|
|
pipe_import_control(struct proto *P, rte **ee, ea_list **ea UNUSED, struct linpool *p UNUSED)
|
1999-08-04 03:57:43 +08:00
|
|
|
{
|
2012-03-15 18:58:08 +08:00
|
|
|
struct proto *pp = (*ee)->sender->proto;
|
1999-08-04 03:57:43 +08:00
|
|
|
|
2010-02-13 19:26:26 +08:00
|
|
|
if (pp == P)
|
1999-08-04 03:57:43 +08:00
|
|
|
return -1; /* Avoid local loops automatically */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-20 21:59:12 +08:00
|
|
|
static int
|
|
|
|
pipe_reload_routes(struct proto *P)
|
|
|
|
{
|
2012-04-15 21:28:29 +08:00
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
|
|
|
|
2009-12-20 21:59:12 +08:00
|
|
|
/*
|
|
|
|
* Because the pipe protocol feeds routes from both routing tables
|
|
|
|
* together, both directions are reloaded during refeed and 'reload
|
|
|
|
* out' command works like 'reload' command. For symmetry, we also
|
|
|
|
* request refeed when 'reload in' command is used.
|
|
|
|
*/
|
|
|
|
proto_request_feeding(P);
|
2012-04-15 21:28:29 +08:00
|
|
|
|
2012-04-22 03:05:36 +08:00
|
|
|
proto_reset_limit(P->main_ahook->in_limit);
|
|
|
|
proto_reset_limit(p->peer_ahook->in_limit);
|
2012-04-15 21:28:29 +08:00
|
|
|
|
2009-12-20 21:59:12 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
static struct proto *
|
|
|
|
pipe_init(struct proto_config *C)
|
|
|
|
{
|
|
|
|
struct pipe_config *c = (struct pipe_config *) C;
|
|
|
|
struct proto *P = proto_new(C, sizeof(struct pipe_proto));
|
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
|
|
|
|
|
|
|
p->mode = c->mode;
|
|
|
|
p->peer_table = c->peer->table;
|
|
|
|
P->accept_ra_types = (p->mode == PIPE_OPAQUE) ? RA_OPTIMAL : RA_ANY;
|
|
|
|
P->rt_notify = pipe_rt_notify;
|
|
|
|
P->import_control = pipe_import_control;
|
|
|
|
P->reload_routes = pipe_reload_routes;
|
|
|
|
|
|
|
|
return P;
|
|
|
|
}
|
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
static int
|
|
|
|
pipe_start(struct proto *P)
|
|
|
|
{
|
2012-04-15 21:28:29 +08:00
|
|
|
struct pipe_config *cf = (struct pipe_config *) P->cf;
|
1999-08-04 03:57:43 +08:00
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
/* Lock both tables, unlock is handled in pipe_cleanup() */
|
|
|
|
rt_lock_table(P->table);
|
|
|
|
rt_lock_table(p->peer_table);
|
2009-12-03 00:26:16 +08:00
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
/* Going directly to PS_UP - prepare for feeding,
|
|
|
|
connect the protocol to both routing tables */
|
1999-08-04 03:57:43 +08:00
|
|
|
|
2012-04-15 21:28:29 +08:00
|
|
|
P->main_ahook = proto_add_announce_hook(P, P->table, &P->stats);
|
|
|
|
P->main_ahook->out_filter = cf->c.out_filter;
|
|
|
|
P->main_ahook->in_limit = cf->c.in_limit;
|
2012-04-22 03:05:36 +08:00
|
|
|
proto_reset_limit(P->main_ahook->in_limit);
|
2012-04-15 21:28:29 +08:00
|
|
|
|
|
|
|
p->peer_ahook = proto_add_announce_hook(P, p->peer_table, &p->peer_stats);
|
|
|
|
p->peer_ahook->out_filter = cf->c.in_filter;
|
2012-04-25 05:39:57 +08:00
|
|
|
p->peer_ahook->in_limit = cf->c.out_limit;
|
2012-04-22 03:05:36 +08:00
|
|
|
proto_reset_limit(p->peer_ahook->in_limit);
|
1999-08-04 03:57:43 +08:00
|
|
|
|
2012-08-14 22:25:22 +08:00
|
|
|
if (p->mode == PIPE_OPAQUE)
|
|
|
|
{
|
|
|
|
P->main_source = rt_get_source(P, 0);
|
|
|
|
rt_lock_source(P->main_source);
|
|
|
|
}
|
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
return PS_UP;
|
|
|
|
}
|
|
|
|
|
2010-07-05 23:50:19 +08:00
|
|
|
static void
|
|
|
|
pipe_cleanup(struct proto *P)
|
|
|
|
{
|
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
bzero(&P->stats, sizeof(struct proto_stats));
|
|
|
|
bzero(&p->peer_stats, sizeof(struct proto_stats));
|
1999-08-04 03:57:43 +08:00
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
P->main_ahook = NULL;
|
|
|
|
p->peer_ahook = NULL;
|
2010-02-13 19:26:26 +08:00
|
|
|
|
2012-08-14 22:25:22 +08:00
|
|
|
if (p->mode == PIPE_OPAQUE)
|
|
|
|
rt_unlock_source(P->main_source);
|
|
|
|
P->main_source = NULL;
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
rt_unlock_table(P->table);
|
|
|
|
rt_unlock_table(p->peer_table);
|
1999-08-04 03:57:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pipe_postconfig(struct proto_config *C)
|
|
|
|
{
|
|
|
|
struct pipe_config *c = (struct pipe_config *) C;
|
|
|
|
|
|
|
|
if (!c->peer)
|
|
|
|
cf_error("Name of peer routing table not specified");
|
|
|
|
if (c->peer == C->table)
|
|
|
|
cf_error("Primary table and peer table must be different");
|
2013-01-10 20:07:33 +08:00
|
|
|
|
|
|
|
if (C->in_keep_filtered)
|
|
|
|
cf_error("Pipe protocol prohibits keeping filtered routes");
|
|
|
|
if (C->rx_limit)
|
|
|
|
cf_error("Pipe protocol does not support receive limits");
|
1999-08-04 03:57:43 +08:00
|
|
|
}
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
extern int proto_reconfig_type;
|
|
|
|
|
2000-01-17 08:20:45 +08:00
|
|
|
static int
|
2009-12-20 21:59:12 +08:00
|
|
|
pipe_reconfigure(struct proto *P, struct proto_config *new)
|
2000-01-17 08:20:45 +08:00
|
|
|
{
|
2012-03-15 18:58:08 +08:00
|
|
|
struct pipe_proto *p = (struct pipe_proto *)P;
|
|
|
|
struct proto_config *old = P->cf;
|
|
|
|
struct pipe_config *oc = (struct pipe_config *) old;
|
|
|
|
struct pipe_config *nc = (struct pipe_config *) new;
|
2000-01-17 08:20:45 +08:00
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
if ((oc->peer->table != nc->peer->table) || (oc->mode != nc->mode))
|
2009-12-20 21:59:12 +08:00
|
|
|
return 0;
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
/* Update output filters in ahooks */
|
|
|
|
if (P->main_ahook)
|
2012-04-15 21:28:29 +08:00
|
|
|
{
|
|
|
|
P->main_ahook->out_filter = new->out_filter;
|
|
|
|
P->main_ahook->in_limit = new->in_limit;
|
2014-04-27 06:46:32 +08:00
|
|
|
proto_verify_limits(P->main_ahook);
|
2012-04-15 21:28:29 +08:00
|
|
|
}
|
2012-03-15 18:58:08 +08:00
|
|
|
|
|
|
|
if (p->peer_ahook)
|
2012-04-15 21:28:29 +08:00
|
|
|
{
|
|
|
|
p->peer_ahook->out_filter = new->in_filter;
|
2012-04-25 05:39:57 +08:00
|
|
|
p->peer_ahook->in_limit = new->out_limit;
|
2014-04-27 06:46:32 +08:00
|
|
|
proto_verify_limits(p->peer_ahook);
|
2012-04-15 21:28:29 +08:00
|
|
|
}
|
2012-03-15 18:58:08 +08:00
|
|
|
|
|
|
|
if ((P->proto_state != PS_UP) || (proto_reconfig_type == RECONFIG_SOFT))
|
|
|
|
return 1;
|
2015-02-22 04:08:23 +08:00
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
if ((new->preference != old->preference)
|
|
|
|
|| ! filter_same(new->in_filter, old->in_filter)
|
|
|
|
|| ! filter_same(new->out_filter, old->out_filter))
|
|
|
|
proto_request_feeding(P);
|
|
|
|
|
2009-12-20 21:59:12 +08:00
|
|
|
return 1;
|
2000-01-17 08:20:45 +08:00
|
|
|
}
|
|
|
|
|
2011-11-07 07:31:23 +08:00
|
|
|
static void
|
|
|
|
pipe_copy_config(struct proto_config *dest, struct proto_config *src)
|
|
|
|
{
|
|
|
|
/* Just a shallow copy, not many items here */
|
|
|
|
proto_copy_rest(dest, src, sizeof(struct pipe_config));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pipe_get_status(struct proto *P, byte *buf)
|
|
|
|
{
|
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
|
|
|
|
2012-03-15 18:58:08 +08:00
|
|
|
bsprintf(buf, "%c> %s", (p->mode == PIPE_OPAQUE) ? '-' : '=', p->peer_table->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pipe_show_stats(struct pipe_proto *p)
|
|
|
|
{
|
|
|
|
struct proto_stats *s1 = &p->p.stats;
|
|
|
|
struct proto_stats *s2 = &p->peer_stats;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pipe stats (as anything related to pipes) are a bit tricky. There
|
|
|
|
* are two sets of stats - s1 for ahook to the primary routing and
|
|
|
|
* s2 for the ahook to the secondary routing table. The user point
|
|
|
|
* of view is that routes going from the primary routing table to
|
|
|
|
* the secondary routing table are 'exported', while routes going in
|
|
|
|
* the other direction are 'imported'.
|
|
|
|
*
|
|
|
|
* Each route going through a pipe is, technically, first exported
|
|
|
|
* to the pipe and then imported from that pipe and such operations
|
|
|
|
* are counted in one set of stats according to the direction of the
|
|
|
|
* route propagation. Filtering is done just in the first part
|
|
|
|
* (export). Therefore, we compose stats for one directon for one
|
|
|
|
* user direction from both import and export stats, skipping
|
|
|
|
* immediate and irrelevant steps (exp_updates_accepted,
|
|
|
|
* imp_updates_received, imp_updates_filtered, ...).
|
|
|
|
*
|
|
|
|
* Rule of thumb is that stats s1 have the correct 'polarity'
|
|
|
|
* (imp/exp), while stats s2 have switched 'polarity'.
|
|
|
|
*/
|
|
|
|
|
2015-02-22 04:08:23 +08:00
|
|
|
cli_msg(-1006, " Routes: %u imported, %u exported",
|
2012-03-15 18:58:08 +08:00
|
|
|
s1->imp_routes, s2->imp_routes);
|
|
|
|
cli_msg(-1006, " Route change stats: received rejected filtered ignored accepted");
|
|
|
|
cli_msg(-1006, " Import updates: %10u %10u %10u %10u %10u",
|
|
|
|
s2->exp_updates_received, s2->exp_updates_rejected + s1->imp_updates_invalid,
|
|
|
|
s2->exp_updates_filtered, s1->imp_updates_ignored, s1->imp_updates_accepted);
|
|
|
|
cli_msg(-1006, " Import withdraws: %10u %10u --- %10u %10u",
|
|
|
|
s2->exp_withdraws_received, s1->imp_withdraws_invalid,
|
|
|
|
s1->imp_withdraws_ignored, s1->imp_withdraws_accepted);
|
|
|
|
cli_msg(-1006, " Export updates: %10u %10u %10u %10u %10u",
|
|
|
|
s1->exp_updates_received, s1->exp_updates_rejected + s2->imp_updates_invalid,
|
|
|
|
s1->exp_updates_filtered, s2->imp_updates_ignored, s2->imp_updates_accepted);
|
|
|
|
cli_msg(-1006, " Export withdraws: %10u %10u --- %10u %10u",
|
|
|
|
s1->exp_withdraws_received, s2->imp_withdraws_invalid,
|
|
|
|
s2->imp_withdraws_ignored, s2->imp_withdraws_accepted);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pipe_show_proto_info(struct proto *P)
|
|
|
|
{
|
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
2012-04-15 21:28:29 +08:00
|
|
|
struct pipe_config *cf = (struct pipe_config *) P->cf;
|
2012-03-15 18:58:08 +08:00
|
|
|
|
|
|
|
// cli_msg(-1006, " Table: %s", P->table->name);
|
|
|
|
// cli_msg(-1006, " Peer table: %s", p->peer_table->name);
|
|
|
|
cli_msg(-1006, " Preference: %d", P->preference);
|
2012-04-15 21:28:29 +08:00
|
|
|
cli_msg(-1006, " Input filter: %s", filter_name(cf->c.in_filter));
|
|
|
|
cli_msg(-1006, " Output filter: %s", filter_name(cf->c.out_filter));
|
|
|
|
|
|
|
|
proto_show_limit(cf->c.in_limit, "Import limit:");
|
2012-04-25 05:39:57 +08:00
|
|
|
proto_show_limit(cf->c.out_limit, "Export limit:");
|
2012-03-15 18:58:08 +08:00
|
|
|
|
|
|
|
if (P->proto_state != PS_DOWN)
|
|
|
|
pipe_show_stats(p);
|
2011-11-07 07:31:23 +08:00
|
|
|
}
|
|
|
|
|
2010-02-13 17:44:46 +08:00
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
struct protocol proto_pipe = {
|
2014-12-03 17:10:34 +08:00
|
|
|
.name = "Pipe",
|
|
|
|
.template = "pipe%d",
|
|
|
|
.multitable = 1,
|
|
|
|
.preference = DEF_PREF_PIPE,
|
2015-02-22 04:08:23 +08:00
|
|
|
.config_size = sizeof(struct pipe_config),
|
2014-12-03 17:10:34 +08:00
|
|
|
.postconfig = pipe_postconfig,
|
|
|
|
.init = pipe_init,
|
|
|
|
.start = pipe_start,
|
|
|
|
.cleanup = pipe_cleanup,
|
|
|
|
.reconfigure = pipe_reconfigure,
|
|
|
|
.copy_config = pipe_copy_config,
|
|
|
|
.get_status = pipe_get_status,
|
|
|
|
.show_proto_info = pipe_show_proto_info
|
1999-08-04 03:57:43 +08:00
|
|
|
};
|