1998-06-03 16:42:16 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- Direct Device Routes
|
|
|
|
*
|
1999-02-06 05:37:34 +08:00
|
|
|
* (c) 1998--1999 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOCAL_DEBUG
|
|
|
|
|
1998-06-05 04:28:43 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
static void
|
1999-02-14 05:58:53 +08:00
|
|
|
dev_if_notify(struct proto *p, unsigned c, struct iface *new, struct iface *old)
|
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
|
|
|
|
|
|
|
if (old && !iface_patt_match(&P->iface_list, old) ||
|
|
|
|
new && !iface_patt_match(&P->iface_list, new))
|
|
|
|
return;
|
1998-06-05 04:28:43 +08:00
|
|
|
if (c & IF_CHANGE_DOWN)
|
|
|
|
{
|
|
|
|
net *n;
|
|
|
|
|
|
|
|
debug("dev_if_notify: %s going down\n", old->name);
|
1999-03-27 05:50:43 +08:00
|
|
|
n = net_find(p->table, 0, old->prefix, old->pxlen);
|
1998-06-05 04:28:43 +08:00
|
|
|
if (!n)
|
|
|
|
{
|
|
|
|
debug("dev_if_notify: device shutdown: prefix not found\n");
|
|
|
|
return;
|
|
|
|
}
|
1998-10-18 19:50:36 +08:00
|
|
|
rte_update(n, p, NULL);
|
1998-06-05 04:28:43 +08:00
|
|
|
}
|
|
|
|
else if (c & IF_CHANGE_UP)
|
|
|
|
{
|
|
|
|
rta *a, A;
|
|
|
|
net *n;
|
|
|
|
rte *e;
|
|
|
|
|
|
|
|
debug("dev_if_notify: %s going up\n", new->name);
|
|
|
|
bzero(&A, sizeof(A));
|
1998-10-18 19:50:36 +08:00
|
|
|
A.proto = p;
|
1998-06-05 04:28:43 +08:00
|
|
|
A.source = RTS_DEVICE;
|
|
|
|
A.scope = (new->flags & IF_LOOPBACK) ? SCOPE_HOST : SCOPE_UNIVERSE;
|
|
|
|
A.cast = RTC_UNICAST;
|
|
|
|
A.dest = RTD_DEVICE;
|
|
|
|
A.iface = new;
|
|
|
|
A.attrs = NULL;
|
|
|
|
a = rta_lookup(&A);
|
1998-10-20 01:46:45 +08:00
|
|
|
if (new->flags & IF_UNNUMBERED)
|
1999-03-27 05:50:43 +08:00
|
|
|
n = net_get(p->table, 0, new->opposite, new->pxlen);
|
1998-10-20 01:46:45 +08:00
|
|
|
else
|
1999-03-27 05:50:43 +08:00
|
|
|
n = net_get(p->table, 0, new->prefix, new->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;
|
1998-10-18 19:50:36 +08:00
|
|
|
rte_update(n, p, e);
|
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-02-06 05:37:34 +08:00
|
|
|
p->if_notify = dev_if_notify;
|
|
|
|
return p;
|
1998-06-03 16:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct protocol proto_device = {
|
1999-03-27 05:44:38 +08:00
|
|
|
name: "Direct",
|
|
|
|
priority: 90,
|
1999-02-06 05:37:34 +08:00
|
|
|
init: dev_init,
|
1998-06-03 16:42:16 +08:00
|
|
|
};
|