1998-06-03 16:42:16 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- Direct Device Routes
|
|
|
|
*
|
2000-01-17 00:40:57 +08:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-06-03 16:42:16 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-05 00:16:08 +08:00
|
|
|
/**
|
|
|
|
* DOC: Direct
|
|
|
|
*
|
2000-06-07 20:29:08 +08:00
|
|
|
* The Direct protocol works by converting all ifa_notify() events it receives
|
2000-06-05 00:16:08 +08:00
|
|
|
* to rte_update() calls for the corresponding network.
|
|
|
|
*/
|
|
|
|
|
2000-03-13 05:01:38 +08:00
|
|
|
#undef LOCAL_DEBUG
|
1998-06-03 16:42:16 +08:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
1998-11-30 06:03:58 +08:00
|
|
|
#include "nest/rt-dev.h"
|
|
|
|
#include "conf/conf.h"
|
1998-06-03 16:42:16 +08:00
|
|
|
#include "lib/resource.h"
|
2000-04-01 07:30:21 +08:00
|
|
|
#include "lib/string.h"
|
1998-06-03 16:42:16 +08:00
|
|
|
|
|
|
|
static void
|
1999-05-07 05:38:11 +08:00
|
|
|
dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
|
1998-06-03 16:42:16 +08:00
|
|
|
{
|
1999-02-06 05:37:34 +08:00
|
|
|
struct rt_dev_config *P = (void *) p->cf;
|
1998-11-30 06:03:58 +08:00
|
|
|
|
1999-08-04 03:30:49 +08:00
|
|
|
if (!EMPTY_LIST(P->iface_list) &&
|
2010-03-14 23:36:59 +08:00
|
|
|
!iface_patt_find(&P->iface_list, ad->iface, ad->iface->addr))
|
1999-08-04 03:30:49 +08:00
|
|
|
/* Empty list is automagically treated as "*" */
|
1998-11-30 06:03:58 +08:00
|
|
|
return;
|
2010-02-26 17:55:58 +08:00
|
|
|
|
2013-09-10 19:03:58 +08:00
|
|
|
if (ad->flags & IA_SECONDARY)
|
|
|
|
return;
|
2010-02-26 17:55:58 +08:00
|
|
|
|
|
|
|
if (ad->scope <= SCOPE_LINK)
|
|
|
|
return;
|
|
|
|
|
1998-06-05 04:28:43 +08:00
|
|
|
if (c & IF_CHANGE_DOWN)
|
|
|
|
{
|
|
|
|
net *n;
|
|
|
|
|
1999-05-07 05:38:11 +08:00
|
|
|
DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
|
2015-11-05 19:48:52 +08:00
|
|
|
n = net_find_ipa(p->table, ad->prefix, ad->pxlen);
|
1998-06-05 04:28:43 +08:00
|
|
|
if (!n)
|
|
|
|
{
|
2000-03-13 05:01:38 +08:00
|
|
|
DBG("dev_if_notify: device shutdown: prefix not found\n");
|
1998-06-05 04:28:43 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-07-18 19:05:05 +08:00
|
|
|
|
|
|
|
/* Use iface ID as local source ID */
|
|
|
|
struct rte_src *src = rt_get_source(p, ad->iface->index);
|
|
|
|
rte_update2(p->main_ahook, n, NULL, src);
|
1998-06-05 04:28:43 +08:00
|
|
|
}
|
|
|
|
else if (c & IF_CHANGE_UP)
|
|
|
|
{
|
2012-08-14 22:25:22 +08:00
|
|
|
rta *a;
|
1998-06-05 04:28:43 +08:00
|
|
|
net *n;
|
|
|
|
rte *e;
|
|
|
|
|
2000-03-13 05:01:38 +08:00
|
|
|
DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
|
2012-08-14 22:25:22 +08:00
|
|
|
|
2015-07-18 19:05:05 +08:00
|
|
|
/* Use iface ID as local source ID */
|
|
|
|
struct rte_src *src = rt_get_source(p, ad->iface->index);
|
|
|
|
|
2012-08-14 22:25:22 +08:00
|
|
|
rta a0 = {
|
2015-07-18 19:05:05 +08:00
|
|
|
.src = src,
|
2012-08-14 22:25:22 +08:00
|
|
|
.source = RTS_DEVICE,
|
|
|
|
.scope = SCOPE_UNIVERSE,
|
|
|
|
.cast = RTC_UNICAST,
|
|
|
|
.dest = RTD_DEVICE,
|
|
|
|
.iface = ad->iface
|
|
|
|
};
|
|
|
|
|
|
|
|
a = rta_lookup(&a0);
|
2015-11-05 19:48:52 +08:00
|
|
|
n = net_get_ipa(p->table, ad->prefix, ad->pxlen);
|
1998-06-05 04:28:43 +08:00
|
|
|
e = rte_get_temp(a);
|
1998-10-20 23:13:18 +08:00
|
|
|
e->net = n;
|
1998-06-05 04:28:43 +08:00
|
|
|
e->pflags = 0;
|
2015-07-18 19:05:05 +08:00
|
|
|
rte_update2(p->main_ahook, n, e, src);
|
1998-06-05 04:28:43 +08:00
|
|
|
}
|
1998-06-03 16:42:16 +08:00
|
|
|
}
|
|
|
|
|
1999-02-06 05:37:34 +08:00
|
|
|
static struct proto *
|
|
|
|
dev_init(struct proto_config *c)
|
1998-06-03 16:42:16 +08:00
|
|
|
{
|
1999-02-06 05:37:34 +08:00
|
|
|
struct proto *p = proto_new(c, sizeof(struct proto));
|
1998-06-03 16:42:16 +08:00
|
|
|
|
1999-05-07 05:38:11 +08:00
|
|
|
p->ifa_notify = dev_ifa_notify;
|
1999-02-06 05:37:34 +08:00
|
|
|
return p;
|
1998-06-03 16:42:16 +08:00
|
|
|
}
|
|
|
|
|
2000-01-17 08:20:17 +08:00
|
|
|
static int
|
|
|
|
dev_reconfigure(struct proto *p, struct proto_config *new)
|
|
|
|
{
|
|
|
|
struct rt_dev_config *o = (struct rt_dev_config *) p->cf;
|
|
|
|
struct rt_dev_config *n = (struct rt_dev_config *) new;
|
2015-02-22 04:08:23 +08:00
|
|
|
|
2000-01-17 08:20:17 +08:00
|
|
|
return iface_patts_equal(&o->iface_list, &n->iface_list, NULL);
|
|
|
|
}
|
|
|
|
|
2011-11-07 07:31:23 +08:00
|
|
|
static void
|
|
|
|
dev_copy_config(struct proto_config *dest, struct proto_config *src)
|
|
|
|
{
|
|
|
|
struct rt_dev_config *d = (struct rt_dev_config *) dest;
|
|
|
|
struct rt_dev_config *s = (struct rt_dev_config *) src;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We copy iface_list as ifaces can be shared by more direct protocols.
|
|
|
|
* Copy suffices to be is shallow, because new nodes can be added, but
|
|
|
|
* old nodes cannot be modified (although they contain internal lists).
|
|
|
|
*/
|
|
|
|
cfg_copy_list(&d->iface_list, &s->iface_list, sizeof(struct iface_patt));
|
|
|
|
}
|
|
|
|
|
1998-06-03 16:42:16 +08:00
|
|
|
struct protocol proto_device = {
|
2014-12-03 17:10:34 +08:00
|
|
|
.name = "Direct",
|
|
|
|
.template = "direct%d",
|
|
|
|
.preference = DEF_PREF_DIRECT,
|
2015-02-22 04:08:23 +08:00
|
|
|
.config_size = sizeof(struct rt_dev_config),
|
2014-12-03 17:10:34 +08:00
|
|
|
.init = dev_init,
|
|
|
|
.reconfigure = dev_reconfigure,
|
|
|
|
.copy_config = dev_copy_config
|
1998-06-03 16:42:16 +08:00
|
|
|
};
|