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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOCAL_DEBUG
|
|
|
|
|
1998-06-04 20:28:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
static void
|
1999-05-06 21:38:11 +00:00
|
|
|
dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
|
1998-06-03 08:42:16 +00:00
|
|
|
{
|
1999-02-05 21:37:34 +00:00
|
|
|
struct rt_dev_config *P = (void *) p->cf;
|
1998-11-29 22:03:58 +00:00
|
|
|
|
1999-08-03 19:30:49 +00:00
|
|
|
if (!EMPTY_LIST(P->iface_list) &&
|
|
|
|
!iface_patt_match(&P->iface_list, ad->iface))
|
|
|
|
/* Empty list is automagically treated as "*" */
|
1998-11-29 22:03:58 +00:00
|
|
|
return;
|
1998-06-04 20:28:43 +00:00
|
|
|
if (c & IF_CHANGE_DOWN)
|
|
|
|
{
|
|
|
|
net *n;
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
|
|
|
|
n = net_find(p->table, ad->prefix, ad->pxlen);
|
1998-06-04 20:28:43 +00:00
|
|
|
if (!n)
|
|
|
|
{
|
|
|
|
debug("dev_if_notify: device shutdown: prefix not found\n");
|
|
|
|
return;
|
|
|
|
}
|
1999-05-17 20:16:53 +00:00
|
|
|
rte_update(p->table, n, p, NULL);
|
1998-06-04 20:28:43 +00:00
|
|
|
}
|
|
|
|
else if (c & IF_CHANGE_UP)
|
|
|
|
{
|
|
|
|
rta *a, A;
|
|
|
|
net *n;
|
|
|
|
rte *e;
|
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
debug("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
|
1998-06-04 20:28:43 +00:00
|
|
|
bzero(&A, sizeof(A));
|
1998-10-18 11:50:36 +00:00
|
|
|
A.proto = p;
|
1998-06-04 20:28:43 +00:00
|
|
|
A.source = RTS_DEVICE;
|
1999-05-06 21:38:11 +00:00
|
|
|
A.scope = ad->scope;
|
1998-06-04 20:28:43 +00:00
|
|
|
A.cast = RTC_UNICAST;
|
|
|
|
A.dest = RTD_DEVICE;
|
1999-05-06 21:38:11 +00:00
|
|
|
A.iface = ad->iface;
|
1999-11-04 13:29:43 +00:00
|
|
|
A.eattrs = NULL;
|
1998-06-04 20:28:43 +00:00
|
|
|
a = rta_lookup(&A);
|
1999-05-06 21:38:11 +00:00
|
|
|
if (ad->flags & IF_UNNUMBERED)
|
|
|
|
n = net_get(p->table, ad->opposite, ad->pxlen);
|
1998-10-19 17:46:45 +00:00
|
|
|
else
|
1999-05-06 21:38:11 +00:00
|
|
|
n = net_get(p->table, ad->prefix, ad->pxlen);
|
1998-06-04 20:28:43 +00:00
|
|
|
e = rte_get_temp(a);
|
1998-10-20 15:13:18 +00:00
|
|
|
e->net = n;
|
1998-06-04 20:28:43 +00:00
|
|
|
e->pflags = 0;
|
1999-05-17 20:16:53 +00:00
|
|
|
rte_update(p->table, n, p, e);
|
1998-06-04 20:28:43 +00:00
|
|
|
}
|
1998-06-03 08:42:16 +00:00
|
|
|
}
|
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
static struct proto *
|
|
|
|
dev_init(struct proto_config *c)
|
1998-06-03 08:42:16 +00:00
|
|
|
{
|
1999-02-05 21:37:34 +00:00
|
|
|
struct proto *p = proto_new(c, sizeof(struct proto));
|
1998-06-03 08:42:16 +00:00
|
|
|
|
1999-05-06 21:38:11 +00:00
|
|
|
p->ifa_notify = dev_ifa_notify;
|
2000-01-16 16:40:57 +00:00
|
|
|
p->min_scope = SCOPE_HOST;
|
1999-02-05 21:37:34 +00:00
|
|
|
return p;
|
1998-06-03 08:42:16 +00:00
|
|
|
}
|
|
|
|
|
2000-01-17 00:20:17 +00: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;
|
|
|
|
|
|
|
|
return iface_patts_equal(&o->iface_list, &n->iface_list, NULL);
|
|
|
|
}
|
|
|
|
|
1998-06-03 08:42:16 +00:00
|
|
|
struct protocol proto_device = {
|
1999-03-26 21:44:38 +00:00
|
|
|
name: "Direct",
|
|
|
|
priority: 90,
|
1999-02-05 21:37:34 +00:00
|
|
|
init: dev_init,
|
2000-01-17 00:20:17 +00:00
|
|
|
reconfigure: dev_reconfigure
|
1998-06-03 08:42:16 +00:00
|
|
|
};
|