Modified static router to use new interface.

This commit is contained in:
Martin Mares 1999-02-05 21:38:22 +00:00
parent 31b3e1bbf5
commit e9e3dc2659
3 changed files with 41 additions and 54 deletions

View file

@ -1,7 +1,7 @@
/* /*
* BIRD -- Static Protocol Configuration * BIRD -- Static Protocol Configuration
* *
* (c) 1998 Martin Mares <mj@ucw.cz> * (c) 1998--1999 Martin Mares <mj@ucw.cz>
* *
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
@ -21,8 +21,8 @@ CF_GRAMMAR
CF_ADDTO(proto, static_proto '}') CF_ADDTO(proto, static_proto '}')
static_proto_start: proto_start STATIC { static_proto_start: proto_start STATIC {
this_proto = proto_new(&proto_static, sizeof(struct static_proto)); this_proto = proto_config_new(&proto_static, sizeof(struct static_config));
static_init_instance((struct static_proto *) this_proto); static_init_config((struct static_config *) this_proto);
} }
; ;
@ -34,7 +34,7 @@ static_proto:
stat_route0: ROUTE IPA pxlen { stat_route0: ROUTE IPA pxlen {
this_srt = cfg_allocz(sizeof(struct static_route)); this_srt = cfg_allocz(sizeof(struct static_route));
add_tail(&((struct static_proto *) this_proto)->other_routes, &this_srt->n); add_tail(&((struct static_config *) this_proto)->other_routes, &this_srt->n);
if (!ip_is_prefix($2, $3)) cf_error("Invalid network prefix: %I/%d", $2, $3); if (!ip_is_prefix($2, $3)) cf_error("Invalid network prefix: %I/%d", $2, $3);
this_srt->net = $2; this_srt->net = $2;
this_srt->masklen = $3; this_srt->masklen = $3;
@ -50,7 +50,7 @@ stat_route:
this_srt->dest = RTD_DEVICE; this_srt->dest = RTD_DEVICE;
this_srt->if_name = $3; this_srt->if_name = $3;
rem_node(&this_srt->n); rem_node(&this_srt->n);
add_tail(&((struct static_proto *) this_proto)->iface_routes, &this_srt->n); add_tail(&((struct static_config *) this_proto)->iface_routes, &this_srt->n);
} }
| stat_route0 DROP { this_srt->dest = RTD_BLACKHOLE; } | stat_route0 DROP { this_srt->dest = RTD_BLACKHOLE; }
| stat_route0 REJECT { this_srt->dest = RTD_UNREACHABLE; } | stat_route0 REJECT { this_srt->dest = RTD_UNREACHABLE; }

View file

@ -1,7 +1,7 @@
/* /*
* BIRD -- Static Route Generator * BIRD -- Static Route Generator
* *
* (c) 1998 Martin Mares <mj@ucw.cz> * (c) 1998--1999 Martin Mares <mj@ucw.cz>
* *
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
@ -18,10 +18,8 @@
#include "static.h" #include "static.h"
#define GET_DATA struct static_proto *p = (struct static_proto *) P
static void static void
static_install(struct static_proto *p, struct static_route *r, struct iface *ifa) static_install(struct proto *p, struct static_route *r, struct iface *ifa)
{ {
net *n; net *n;
rta a, *aa; rta a, *aa;
@ -29,7 +27,7 @@ static_install(struct static_proto *p, struct static_route *r, struct iface *ifa
DBG("Installing static route %I/%d, rtd=%d\n", r->net, r->masklen, r->dest); DBG("Installing static route %I/%d, rtd=%d\n", r->net, r->masklen, r->dest);
bzero(&a, sizeof(a)); bzero(&a, sizeof(a));
a.proto = &p->p; a.proto = p;
a.source = (r->dest == RTD_DEVICE) ? RTS_STATIC_DEVICE : RTS_STATIC; a.source = (r->dest == RTD_DEVICE) ? RTS_STATIC_DEVICE : RTS_STATIC;
a.scope = SCOPE_UNIVERSE; a.scope = SCOPE_UNIVERSE;
a.cast = RTC_UNICAST; a.cast = RTC_UNICAST;
@ -43,33 +41,33 @@ static_install(struct static_proto *p, struct static_route *r, struct iface *ifa
e = rte_get_temp(aa); e = rte_get_temp(aa);
e->net = n; e->net = n;
e->pflags = 0; e->pflags = 0;
rte_update(n, &p->p, e); rte_update(n, p, e);
} }
static void static void
static_remove(struct static_proto *p, struct static_route *r) static_remove(struct proto *p, struct static_route *r)
{ {
net *n; net *n;
DBG("Removing static route %I/%d\n", r->net, r->masklen); DBG("Removing static route %I/%d\n", r->net, r->masklen);
n = net_find(&master_table, 0, r->net, r->masklen); n = net_find(&master_table, 0, r->net, r->masklen);
if (n) if (n)
rte_update(n, &p->p, NULL); rte_update(n, p, NULL);
} }
static void static int
static_start(struct proto *P) static_start(struct proto *p)
{ {
GET_DATA; struct static_config *c = (void *) p->cf;
struct static_route *r; struct static_route *r;
DBG("Static: take off!\n"); DBG("Static: take off!\n");
WALK_LIST(r, p->other_routes) WALK_LIST(r, c->other_routes)
switch (r->dest) switch (r->dest)
{ {
case RTD_ROUTER: case RTD_ROUTER:
{ {
struct neighbor *n = neigh_find(P, &r->via, NEF_STICKY); struct neighbor *n = neigh_find(p, &r->via, NEF_STICKY);
if (n) if (n)
{ {
r->chain = n->data; r->chain = n->data;
@ -87,12 +85,13 @@ static_start(struct proto *P)
default: default:
static_install(p, r, NULL); static_install(p, r, NULL);
} }
return PS_UP;
} }
static void static void
static_neigh_notify(struct neighbor *n) static_neigh_notify(struct neighbor *n)
{ {
struct static_proto *p = (struct static_proto *) n->proto; struct proto *p = n->proto;
struct static_route *r; struct static_route *r;
DBG("Static: neighbor notify for %I: iface %p\n", n->addr, n->iface); DBG("Static: neighbor notify for %I: iface %p\n", n->addr, n->iface);
@ -122,52 +121,40 @@ static_dump_rt(struct static_route *r)
} }
static void static void
static_dump(struct proto *P) static_dump(struct proto *p)
{ {
GET_DATA; struct static_config *c = (void *) p->cf;
struct static_route *r; struct static_route *r;
debug("Independent static routes:\n"); debug("Independent static routes:\n");
WALK_LIST(r, p->other_routes) WALK_LIST(r, c->other_routes)
static_dump_rt(r); static_dump_rt(r);
debug("Device static routes:\n"); debug("Device static routes:\n");
WALK_LIST(r, p->iface_routes) WALK_LIST(r, c->iface_routes)
static_dump_rt(r); static_dump_rt(r);
} }
void void
static_init_instance(struct static_proto *P) static_init_config(struct static_config *c)
{ {
struct proto *p = &P->p; c->c.preference = DEF_PREF_STATIC;
init_list(&c->iface_routes);
init_list(&c->other_routes);
}
static struct proto *
static_init(struct proto_config *c)
{
struct proto *p = proto_new(c, sizeof(struct proto));
p->preference = DEF_PREF_STATIC;
p->start = static_start;
p->neigh_notify = static_neigh_notify; p->neigh_notify = static_neigh_notify;
p->dump = static_dump; return p;
init_list(&P->iface_routes);
init_list(&P->other_routes);
}
static void
static_init(struct protocol *p)
{
}
static void
static_preconfig(struct protocol *x)
{
}
static void
static_postconfig(struct protocol *p)
{
} }
struct protocol proto_static = { struct protocol proto_static = {
{ NULL, NULL }, name: "Static",
"Static", init: static_init,
0, dump: static_dump,
static_init, start: static_start,
static_preconfig, /* FIXME: We'll need a shutdown function here */
static_postconfig
}; };

View file

@ -9,13 +9,13 @@
#ifndef _BIRD_STATIC_H_ #ifndef _BIRD_STATIC_H_
#define _BIRD_STATIC_H_ #define _BIRD_STATIC_H_
struct static_proto { struct static_config {
struct proto p; struct proto_config c;
list iface_routes; /* Routes to search on interface events */ list iface_routes; /* Routes to search on interface events */
list other_routes; /* Routes hooked to neighbor cache and reject routes */ list other_routes; /* Routes hooked to neighbor cache and reject routes */
}; };
void static_init_instance(struct static_proto *); void static_init_config(struct static_config *);
struct static_route { struct static_route {
node n; node n;