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
|
|
|
|
2016-01-26 18:48:58 +08:00
|
|
|
|
1998-06-03 16:42:16 +08:00
|
|
|
static void
|
2016-01-26 18:48:58 +08:00
|
|
|
dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
|
1998-06-03 16:42:16 +08:00
|
|
|
{
|
2016-01-26 18:48:58 +08:00
|
|
|
struct rt_dev_proto *p = (void *) P;
|
|
|
|
struct rt_dev_config *cf = (void *) P->cf;
|
|
|
|
struct channel *c;
|
1998-11-30 06:03:58 +08:00
|
|
|
|
2016-01-26 18:48:58 +08:00
|
|
|
if (!EMPTY_LIST(cf->iface_list) &&
|
|
|
|
!iface_patt_find(&cf->iface_list, ad->iface, ad->iface->addr))
|
2016-02-03 01:14:53 +08:00
|
|
|
/* Empty list is automatically 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;
|
|
|
|
|
2016-01-26 18:48:58 +08:00
|
|
|
if (ad->prefix.type == NET_IP4)
|
|
|
|
c = p->ip4_channel;
|
|
|
|
else if (ad->prefix.type == NET_IP6)
|
|
|
|
c = p->ip6_channel;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!c)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (flags & IF_CHANGE_DOWN)
|
1998-06-05 04:28:43 +08:00
|
|
|
{
|
1999-05-07 05:38:11 +08:00
|
|
|
DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
|
2015-07-18 19:05:05 +08:00
|
|
|
|
|
|
|
/* Use iface ID as local source ID */
|
2016-01-26 18:48:58 +08:00
|
|
|
struct rte_src *src = rt_get_source(P, ad->iface->index);
|
2016-04-08 19:08:03 +08:00
|
|
|
rte_update2(c, &ad->prefix, NULL, src);
|
1998-06-05 04:28:43 +08:00
|
|
|
}
|
2016-01-26 18:48:58 +08:00
|
|
|
else if (flags & IF_CHANGE_UP)
|
1998-06-05 04:28:43 +08:00
|
|
|
{
|
2012-08-14 22:25:22 +08:00
|
|
|
rta *a;
|
1998-06-05 04:28:43 +08:00
|
|
|
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 */
|
2016-01-26 18:48:58 +08:00
|
|
|
struct rte_src *src = rt_get_source(P, ad->iface->index);
|
2015-07-18 19:05:05 +08:00
|
|
|
|
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);
|
1998-06-05 04:28:43 +08:00
|
|
|
e = rte_get_temp(a);
|
|
|
|
e->pflags = 0;
|
2016-04-08 19:08:03 +08:00
|
|
|
rte_update2(c, &ad->prefix, 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 *
|
2016-01-26 18:48:58 +08:00
|
|
|
dev_init(struct proto_config *CF)
|
1998-06-03 16:42:16 +08:00
|
|
|
{
|
2016-01-26 18:48:58 +08:00
|
|
|
struct proto *P = proto_new(CF);
|
|
|
|
struct rt_dev_proto *p = (void *) P;
|
|
|
|
// struct rt_dev_config *cf = (void *) CF;
|
1998-06-03 16:42:16 +08:00
|
|
|
|
2016-01-26 18:48:58 +08:00
|
|
|
proto_configure_channel(P, &p->ip4_channel, proto_cf_find_channel(CF, NET_IP4));
|
|
|
|
proto_configure_channel(P, &p->ip6_channel, proto_cf_find_channel(CF, NET_IP6));
|
|
|
|
|
|
|
|
P->ifa_notify = dev_ifa_notify;
|
|
|
|
|
|
|
|
return P;
|
1998-06-03 16:42:16 +08:00
|
|
|
}
|
|
|
|
|
2000-01-17 08:20:17 +08:00
|
|
|
static int
|
2016-01-26 18:48:58 +08:00
|
|
|
dev_reconfigure(struct proto *P, struct proto_config *CF)
|
2000-01-17 08:20:17 +08:00
|
|
|
{
|
2016-01-26 18:48:58 +08:00
|
|
|
struct rt_dev_proto *p = (void *) P;
|
|
|
|
struct rt_dev_config *o = (void *) P->cf;
|
|
|
|
struct rt_dev_config *n = (void *) CF;
|
|
|
|
|
|
|
|
if (!iface_patts_equal(&o->iface_list, &n->iface_list, NULL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return
|
|
|
|
proto_configure_channel(P, &p->ip4_channel, proto_cf_find_channel(CF, NET_IP4)) &&
|
|
|
|
proto_configure_channel(P, &p->ip6_channel, proto_cf_find_channel(CF, NET_IP6));
|
2015-02-22 04:08:23 +08:00
|
|
|
|
2016-01-26 18:48:58 +08:00
|
|
|
return 1;
|
2000-01-17 08:20:17 +08:00
|
|
|
}
|
|
|
|
|
2011-11-07 07:31:23 +08:00
|
|
|
static void
|
|
|
|
dev_copy_config(struct proto_config *dest, struct proto_config *src)
|
|
|
|
{
|
2016-01-26 18:48:58 +08:00
|
|
|
struct rt_dev_config *d = (void *) dest;
|
|
|
|
struct rt_dev_config *s = (void *) src;
|
2011-11-07 07:31:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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",
|
2016-01-26 18:48:58 +08:00
|
|
|
.preference = DEF_PREF_DIRECT,
|
|
|
|
.channel_mask = NB_IP,
|
|
|
|
.proto_size = sizeof(struct rt_dev_proto),
|
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
|
|
|
};
|