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.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#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;
|
|
|
|
rtable *dest = (src_table == P->table) ? p->peer : P->table; /* The other side of the pipe */
|
2009-05-31 21:24:27 +08:00
|
|
|
struct proto *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;
|
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
if (dest->pipe_busy)
|
|
|
|
{
|
|
|
|
log(L_ERR "Pipe loop detected when sending %I/%d to table %s",
|
|
|
|
n->n.prefix, n->n.pxlen, dest->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nn = net_get(dest, n->n.prefix, n->n.pxlen);
|
|
|
|
if (new)
|
|
|
|
{
|
|
|
|
memcpy(&a, new->attrs, sizeof(rta));
|
2009-06-01 18:10:10 +08:00
|
|
|
|
|
|
|
if (p->mode == PIPE_OPAQUE)
|
|
|
|
{
|
|
|
|
a.proto = &p->p;
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
src = new->attrs->proto;
|
1999-08-04 03:57:43 +08:00
|
|
|
}
|
|
|
|
else
|
2009-05-31 21:24:27 +08:00
|
|
|
{
|
|
|
|
e = NULL;
|
|
|
|
src = old->attrs->proto;
|
|
|
|
}
|
|
|
|
|
2009-12-03 00:26:16 +08:00
|
|
|
src_table->pipe_busy = 1;
|
2009-06-01 20:07:13 +08:00
|
|
|
rte_update(dest, nn, &p->p, (p->mode == PIPE_OPAQUE) ? &p->p : src, e);
|
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
|
|
|
{
|
2009-05-31 21:24:27 +08:00
|
|
|
struct proto *pp = (*ee)->sender;
|
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)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
static int
|
|
|
|
pipe_start(struct proto *P)
|
|
|
|
{
|
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
|
|
|
struct announce_hook *a;
|
|
|
|
|
2010-02-13 19:26:26 +08:00
|
|
|
/* Clean up the secondary stats */
|
|
|
|
bzero(&p->peer_stats, sizeof(struct proto_stats));
|
2009-12-03 00:26:16 +08:00
|
|
|
|
2010-02-13 19:26:26 +08:00
|
|
|
/* Lock the peer table, unlock is handled in proto_fell_down() */
|
|
|
|
rt_lock_table(p->peer);
|
1999-08-04 03:57:43 +08:00
|
|
|
|
2010-02-13 19:26:26 +08:00
|
|
|
/* Connect the protocol also to the peer routing table. */
|
1999-08-04 03:57:43 +08:00
|
|
|
a = proto_add_announce_hook(P, p->peer);
|
|
|
|
|
|
|
|
return PS_UP;
|
|
|
|
}
|
|
|
|
|
|
|
|
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->peer = c->peer->table;
|
2009-06-01 18:10:10 +08:00
|
|
|
p->mode = c->mode;
|
|
|
|
P->accept_ra_types = (p->mode == PIPE_OPAQUE) ? RA_OPTIMAL : RA_ANY;
|
2010-02-13 19:26:26 +08:00
|
|
|
P->rt_notify = pipe_rt_notify;
|
1999-08-04 03:57:43 +08:00
|
|
|
P->import_control = pipe_import_control;
|
2009-12-20 21:59:12 +08:00
|
|
|
P->reload_routes = pipe_reload_routes;
|
2010-02-13 19:26:26 +08:00
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
return P;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
1999-12-01 20:01:41 +08:00
|
|
|
static void
|
|
|
|
pipe_get_status(struct proto *P, byte *buf)
|
|
|
|
{
|
|
|
|
struct pipe_proto *p = (struct pipe_proto *) P;
|
|
|
|
|
2009-06-01 18:10:10 +08:00
|
|
|
bsprintf(buf, "%c> %s", (p->mode == PIPE_OPAQUE) ? '-' : '=', p->peer->name);
|
1999-12-01 20:01:41 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-02-21 21:34:53 +08:00
|
|
|
// struct pipe_proto *p = (struct pipe_proto *) P;
|
2009-12-20 21:59:12 +08:00
|
|
|
struct pipe_config *o = (struct pipe_config *) P->cf;
|
2000-01-17 08:20:45 +08:00
|
|
|
struct pipe_config *n = (struct pipe_config *) new;
|
|
|
|
|
2009-12-20 21:59:12 +08:00
|
|
|
if ((o->peer->table != n->peer->table) || (o->mode != n->mode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
2000-01-17 08:20:45 +08:00
|
|
|
}
|
|
|
|
|
2010-02-13 17:44:46 +08:00
|
|
|
|
1999-08-04 03:57:43 +08:00
|
|
|
struct protocol proto_pipe = {
|
|
|
|
name: "Pipe",
|
2000-01-17 19:52:50 +08:00
|
|
|
template: "pipe%d",
|
1999-08-04 03:57:43 +08:00
|
|
|
postconfig: pipe_postconfig,
|
|
|
|
init: pipe_init,
|
|
|
|
start: pipe_start,
|
2000-01-17 08:20:45 +08:00
|
|
|
reconfigure: pipe_reconfigure,
|
1999-12-01 20:01:41 +08:00
|
|
|
get_status: pipe_get_status,
|
1999-08-04 03:57:43 +08:00
|
|
|
};
|