bird/nest/rt-dev.c

92 lines
2 KiB
C
Raw Normal View History

/*
* BIRD -- Direct Device Routes
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#undef LOCAL_DEBUG
1998-06-05 04:28:43 +08:00
#include <string.h>
#include "nest/bird.h"
#include "nest/iface.h"
#include "nest/protocol.h"
#include "nest/route.h"
#include "nest/rt-dev.h"
#include "conf/conf.h"
#include "lib/resource.h"
static void
dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
{
struct rt_dev_config *P = (void *) p->cf;
if (!EMPTY_LIST(P->iface_list) &&
!iface_patt_match(&P->iface_list, ad->iface))
/* Empty list is automagically treated as "*" */
return;
1998-06-05 04:28:43 +08:00
if (c & IF_CHANGE_DOWN)
{
net *n;
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-05 04:28:43 +08:00
if (!n)
{
DBG("dev_if_notify: device shutdown: prefix not found\n");
1998-06-05 04:28:43 +08:00
return;
}
rte_update(p->table, n, p, NULL);
1998-06-05 04:28:43 +08:00
}
else if (c & IF_CHANGE_UP)
{
rta *a, A;
net *n;
rte *e;
DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
1998-06-05 04:28:43 +08:00
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 = ad->scope;
1998-06-05 04:28:43 +08:00
A.cast = RTC_UNICAST;
A.dest = RTD_DEVICE;
A.iface = ad->iface;
1999-11-04 21:29:43 +08:00
A.eattrs = NULL;
1998-06-05 04:28:43 +08:00
a = rta_lookup(&A);
n = net_get(p->table, ad->prefix, ad->pxlen);
1998-06-05 04:28:43 +08:00
e = rte_get_temp(a);
e->net = n;
1998-06-05 04:28:43 +08:00
e->pflags = 0;
rte_update(p->table, n, p, e);
1998-06-05 04:28:43 +08:00
}
}
static struct proto *
dev_init(struct proto_config *c)
{
struct proto *p = proto_new(c, sizeof(struct proto));
p->ifa_notify = dev_ifa_notify;
p->min_scope = SCOPE_HOST;
return p;
}
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);
}
struct protocol proto_device = {
name: "Direct",
template: "direct%d",
init: dev_init,
reconfigure: dev_reconfigure
};