1998-06-03 08:42:16 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- Direct Device Routes
|
|
|
|
*
|
2000-01-16 16:40:57 +00:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-06-03 08:42:16 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-04 16:16:08 +00:00
|
|
|
/**
|
|
|
|
* DOC: Direct
|
|
|
|
*
|
2000-06-07 12:29:08 +00:00
|
|
|
* The Direct protocol works by converting all ifa_notify() events it receives
|
2000-06-04 16:16:08 +00:00
|
|
|
* to rte_update() calls for the corresponding network.
|
|
|
|
*/
|
|
|
|
|
2000-03-12 21:01:38 +00:00
|
|
|
#undef LOCAL_DEBUG
|
1998-06-03 08:42:16 +00:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
1998-11-29 22:03:58 +00:00
|
|
|
#include "nest/rt-dev.h"
|
|
|
|
#include "conf/conf.h"
|
1998-06-03 08:42:16 +00:00
|
|
|
#include "lib/resource.h"
|
2000-03-31 23:30:21 +00:00
|
|
|
#include "lib/string.h"
|
1998-06-03 08:42:16 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
|
1998-06-03 08:42:16 +00:00
|
|
|
static void
|
2016-01-26 10:48:58 +00:00
|
|
|
dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
|
1998-06-03 08:42:16 +00:00
|
|
|
{
|
2016-01-26 10:48:58 +00:00
|
|
|
struct rt_dev_proto *p = (void *) P;
|
|
|
|
struct rt_dev_config *cf = (void *) P->cf;
|
|
|
|
struct channel *c;
|
1998-11-29 22:03:58 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
if (!EMPTY_LIST(cf->iface_list) &&
|
|
|
|
!iface_patt_find(&cf->iface_list, ad->iface, ad->iface->addr))
|
2016-02-02 17:14:53 +00:00
|
|
|
/* Empty list is automatically treated as "*" */
|
1998-11-29 22:03:58 +00:00
|
|
|
return;
|
2010-02-26 09:55:58 +00:00
|
|
|
|
2013-09-10 11:03:58 +00:00
|
|
|
if (ad->flags & IA_SECONDARY)
|
|
|
|
return;
|
2010-02-26 09:55:58 +00:00
|
|
|
|
|
|
|
if (ad->scope <= SCOPE_LINK)
|
|
|
|
return;
|
|
|
|
|
2016-01-26 10:48:58 +00: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-04 20:28:43 +00:00
|
|
|
{
|
1999-05-06 21:38:11 +00:00
|
|
|
DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
|
2015-07-18 11:05:05 +00:00
|
|
|
|
|
|
|
/* Use iface ID as local source ID */
|
2016-01-26 10:48:58 +00:00
|
|
|
struct rte_src *src = rt_get_source(P, ad->iface->index);
|
2016-04-08 11:08:03 +00:00
|
|
|
rte_update2(c, &ad->prefix, NULL, src);
|
1998-06-04 20:28:43 +00:00
|
|
|
}
|
2016-01-26 10:48:58 +00:00
|
|
|
else if (flags & IF_CHANGE_UP)
|
1998-06-04 20:28:43 +00:00
|
|
|
{
|
2012-08-14 14:25:22 +00:00
|
|
|
rta *a;
|
1998-06-04 20:28:43 +00:00
|
|
|
rte *e;
|
|
|
|
|
2000-03-12 21:01:38 +00:00
|
|
|
DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
|
2012-08-14 14:25:22 +00:00
|
|
|
|
2016-05-12 15:49:12 +00:00
|
|
|
if (cf->check_link && !(ad->iface->flags & IF_LINK_UP))
|
2016-04-08 13:10:57 +00:00
|
|
|
return;
|
|
|
|
|
2015-07-18 11:05:05 +00:00
|
|
|
/* Use iface ID as local source ID */
|
2016-01-26 10:48:58 +00:00
|
|
|
struct rte_src *src = rt_get_source(P, ad->iface->index);
|
2015-07-18 11:05:05 +00:00
|
|
|
|
2012-08-14 14:25:22 +00:00
|
|
|
rta a0 = {
|
2015-07-18 11:05:05 +00:00
|
|
|
.src = src,
|
2012-08-14 14:25:22 +00:00
|
|
|
.source = RTS_DEVICE,
|
|
|
|
.scope = SCOPE_UNIVERSE,
|
2016-05-06 13:48:35 +00:00
|
|
|
.dest = RTD_UNICAST,
|
2017-02-20 01:26:45 +00:00
|
|
|
.nh.iface = ad->iface,
|
2012-08-14 14:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
a = rta_lookup(&a0);
|
1998-06-04 20:28:43 +00:00
|
|
|
e = rte_get_temp(a);
|
|
|
|
e->pflags = 0;
|
2016-04-08 11:08:03 +00:00
|
|
|
rte_update2(c, &ad->prefix, e, src);
|
1998-06-04 20:28:43 +00:00
|
|
|
}
|
1998-06-03 08:42:16 +00:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:10:57 +00:00
|
|
|
static void
|
|
|
|
dev_if_notify(struct proto *p, uint c, struct iface *iface)
|
|
|
|
{
|
|
|
|
struct rt_dev_config *cf = (void *) p->cf;
|
|
|
|
|
|
|
|
if (c & (IF_CHANGE_UP | IF_CHANGE_DOWN))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((c & IF_CHANGE_LINK) && cf->check_link)
|
|
|
|
{
|
|
|
|
uint ac = (iface->flags & IF_LINK_UP) ? IF_CHANGE_UP : IF_CHANGE_DOWN;
|
|
|
|
|
|
|
|
struct ifa *a;
|
|
|
|
WALK_LIST(a, iface->addrs)
|
|
|
|
dev_ifa_notify(p, ac, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
static struct proto *
|
2016-01-26 10:48:58 +00:00
|
|
|
dev_init(struct proto_config *CF)
|
1998-06-03 08:42:16 +00:00
|
|
|
{
|
2016-01-26 10:48:58 +00:00
|
|
|
struct proto *P = proto_new(CF);
|
|
|
|
struct rt_dev_proto *p = (void *) P;
|
|
|
|
// struct rt_dev_config *cf = (void *) CF;
|
1998-06-03 08:42:16 +00:00
|
|
|
|
2016-01-26 10:48:58 +00: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));
|
|
|
|
|
2016-05-12 15:49:12 +00:00
|
|
|
P->if_notify = dev_if_notify;
|
2016-01-26 10:48:58 +00:00
|
|
|
P->ifa_notify = dev_ifa_notify;
|
|
|
|
|
|
|
|
return P;
|
1998-06-03 08:42:16 +00:00
|
|
|
}
|
|
|
|
|
2000-01-17 00:20:17 +00:00
|
|
|
static int
|
2016-01-26 10:48:58 +00:00
|
|
|
dev_reconfigure(struct proto *P, struct proto_config *CF)
|
2000-01-17 00:20:17 +00:00
|
|
|
{
|
2016-01-26 10:48:58 +00:00
|
|
|
struct rt_dev_proto *p = (void *) P;
|
|
|
|
struct rt_dev_config *o = (void *) P->cf;
|
|
|
|
struct rt_dev_config *n = (void *) CF;
|
|
|
|
|
2016-05-12 15:49:12 +00:00
|
|
|
if (!iface_patts_equal(&o->iface_list, &n->iface_list, NULL) ||
|
|
|
|
(o->check_link != n->check_link))
|
2016-01-26 10:48:58 +00:00
|
|
|
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-21 20:08:23 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
return 1;
|
2000-01-17 00:20:17 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 23:31:23 +00:00
|
|
|
static void
|
|
|
|
dev_copy_config(struct proto_config *dest, struct proto_config *src)
|
|
|
|
{
|
2016-01-26 10:48:58 +00:00
|
|
|
struct rt_dev_config *d = (void *) dest;
|
|
|
|
struct rt_dev_config *s = (void *) src;
|
2011-11-06 23:31:23 +00: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));
|
2016-04-08 13:10:57 +00:00
|
|
|
|
|
|
|
d->check_link = s->check_link;
|
2011-11-06 23:31:23 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 08:42:16 +00:00
|
|
|
struct protocol proto_device = {
|
2014-12-03 09:10:34 +00:00
|
|
|
.name = "Direct",
|
|
|
|
.template = "direct%d",
|
2016-01-26 10:48:58 +00:00
|
|
|
.preference = DEF_PREF_DIRECT,
|
|
|
|
.channel_mask = NB_IP,
|
|
|
|
.proto_size = sizeof(struct rt_dev_proto),
|
2015-02-21 20:08:23 +00:00
|
|
|
.config_size = sizeof(struct rt_dev_config),
|
2014-12-03 09:10:34 +00:00
|
|
|
.init = dev_init,
|
|
|
|
.reconfigure = dev_reconfigure,
|
|
|
|
.copy_config = dev_copy_config
|
1998-06-03 08:42:16 +00:00
|
|
|
};
|