1998-12-07 02:21:23 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- Static Route Generator
|
|
|
|
*
|
2000-01-17 19:52:50 +08:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-12-07 02:21:23 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2000-06-05 00:15:37 +08:00
|
|
|
/**
|
|
|
|
* DOC: Static
|
|
|
|
*
|
2000-06-08 20:37:21 +08:00
|
|
|
* The Static protocol is implemented in a straightforward way. It keeps
|
|
|
|
* two lists of static routes: one containing interface routes and one
|
2000-06-05 00:15:37 +08:00
|
|
|
* holding the remaining ones. Interface routes are inserted and removed according
|
2000-06-08 20:37:21 +08:00
|
|
|
* to interface events received from the core via the if_notify() hook. Routes
|
2000-06-05 00:15:37 +08:00
|
|
|
* pointing to a neighboring router use a sticky node in the neighbor cache
|
2000-06-08 20:37:21 +08:00
|
|
|
* to be notified about gaining or losing the neighbor. Special
|
2000-06-05 00:15:37 +08:00
|
|
|
* routes like black holes or rejects are inserted all the time.
|
|
|
|
*
|
2010-12-08 06:34:36 +08:00
|
|
|
* Multipath routes are tricky. Because these routes depends on
|
|
|
|
* several neighbors we need to integrate that to the neighbor
|
|
|
|
* notification handling, we use dummy static_route nodes, one for
|
|
|
|
* each nexthop. Therefore, a multipath route consists of a master
|
|
|
|
* static_route node (of dest RTD_MULTIPATH), which specifies prefix
|
|
|
|
* and is used in most circumstances, and a list of dummy static_route
|
|
|
|
* nodes (of dest RTD_NONE), which stores info about nexthops and are
|
|
|
|
* connected to neighbor entries and neighbor notifications. Dummy
|
|
|
|
* nodes are chained using mp_next, they aren't in other_routes list,
|
|
|
|
* and abuse some fields (masklen, if_name) for other purposes.
|
|
|
|
*
|
2000-06-05 00:15:37 +08:00
|
|
|
* The only other thing worth mentioning is that when asked for reconfiguration,
|
|
|
|
* Static not only compares the two configurations, but it also calculates
|
2000-06-08 20:37:21 +08:00
|
|
|
* difference between the lists of static routes and it just inserts the
|
|
|
|
* newly added routes and removes the obsolete ones.
|
2000-06-05 00:15:37 +08:00
|
|
|
*/
|
|
|
|
|
2000-03-13 05:01:38 +08:00
|
|
|
#undef LOCAL_DEBUG
|
1998-12-07 02:21:23 +08:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/route.h"
|
1999-12-03 19:41:23 +08:00
|
|
|
#include "nest/cli.h"
|
1998-12-07 02:21:23 +08:00
|
|
|
#include "conf/conf.h"
|
1999-12-03 19:41:23 +08:00
|
|
|
#include "lib/string.h"
|
2010-12-08 06:34:36 +08:00
|
|
|
#include "lib/alloca.h"
|
1998-12-07 02:21:23 +08:00
|
|
|
|
|
|
|
#include "static.h"
|
|
|
|
|
2011-09-24 08:21:52 +08:00
|
|
|
static inline rtable *
|
|
|
|
p_igp_table(struct proto *p)
|
|
|
|
{
|
|
|
|
struct static_config *cf = (void *) p->cf;
|
|
|
|
return cf->igp_table ? cf->igp_table->table : p->table;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-07 07:13:31 +08:00
|
|
|
static void
|
1999-02-06 05:38:22 +08:00
|
|
|
static_install(struct proto *p, struct static_route *r, struct iface *ifa)
|
1998-12-07 07:13:31 +08:00
|
|
|
{
|
|
|
|
net *n;
|
|
|
|
rta a, *aa;
|
|
|
|
rte *e;
|
|
|
|
|
2000-01-17 20:38:50 +08:00
|
|
|
if (r->installed)
|
|
|
|
return;
|
|
|
|
|
1998-12-07 07:13:31 +08:00
|
|
|
DBG("Installing static route %I/%d, rtd=%d\n", r->net, r->masklen, r->dest);
|
|
|
|
bzero(&a, sizeof(a));
|
1999-02-06 05:38:22 +08:00
|
|
|
a.proto = p;
|
1998-12-07 07:13:31 +08:00
|
|
|
a.source = (r->dest == RTD_DEVICE) ? RTS_STATIC_DEVICE : RTS_STATIC;
|
|
|
|
a.scope = SCOPE_UNIVERSE;
|
|
|
|
a.cast = RTC_UNICAST;
|
|
|
|
a.dest = r->dest;
|
|
|
|
a.gw = r->via;
|
|
|
|
a.iface = ifa;
|
|
|
|
|
2010-12-08 06:34:36 +08:00
|
|
|
if (r->dest == RTD_MULTIPATH)
|
|
|
|
{
|
|
|
|
struct static_route *r2;
|
|
|
|
struct mpnh *nhs = NULL;
|
|
|
|
struct mpnh **nhp = &nhs;
|
|
|
|
|
|
|
|
for (r2 = r->mp_next; r2; r2 = r2->mp_next)
|
|
|
|
if (r2->installed)
|
|
|
|
{
|
|
|
|
struct mpnh *nh = alloca(sizeof(struct mpnh));
|
|
|
|
nh->gw = r2->via;
|
|
|
|
nh->iface = r2->neigh->iface;
|
|
|
|
nh->weight = r2->masklen; /* really */
|
|
|
|
nh->next = NULL;
|
|
|
|
*nhp = nh;
|
|
|
|
nhp = &(nh->next);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There is at least one nexthop */
|
|
|
|
if (!nhs->next)
|
|
|
|
{
|
|
|
|
/* Fallback to unipath route for exactly one nexthop */
|
|
|
|
a.dest = RTD_ROUTER;
|
|
|
|
a.gw = nhs->gw;
|
|
|
|
a.iface = nhs->iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
a.nexthops = nhs;
|
|
|
|
}
|
|
|
|
|
2011-09-24 08:21:52 +08:00
|
|
|
if (r->dest == RTDX_RECURSIVE)
|
|
|
|
rta_set_recursive_next_hop(p->table, &a, p_igp_table(p), &r->via, &r->via);
|
|
|
|
|
2010-12-08 06:34:36 +08:00
|
|
|
aa = rta_lookup(&a);
|
1999-04-13 02:01:07 +08:00
|
|
|
n = net_get(p->table, r->net, r->masklen);
|
1998-12-07 07:13:31 +08:00
|
|
|
e = rte_get_temp(aa);
|
|
|
|
e->net = n;
|
|
|
|
e->pflags = 0;
|
2009-06-01 20:07:13 +08:00
|
|
|
rte_update(p->table, n, p, p, e);
|
1999-12-03 19:41:23 +08:00
|
|
|
r->installed = 1;
|
1998-12-07 07:13:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-02-06 05:38:22 +08:00
|
|
|
static_remove(struct proto *p, struct static_route *r)
|
1998-12-07 07:13:31 +08:00
|
|
|
{
|
|
|
|
net *n;
|
|
|
|
|
2000-01-17 20:38:50 +08:00
|
|
|
if (!r->installed)
|
|
|
|
return;
|
|
|
|
|
1998-12-07 07:13:31 +08:00
|
|
|
DBG("Removing static route %I/%d\n", r->net, r->masklen);
|
1999-04-13 02:01:07 +08:00
|
|
|
n = net_find(p->table, r->net, r->masklen);
|
1998-12-07 07:13:31 +08:00
|
|
|
if (n)
|
2009-06-01 20:07:13 +08:00
|
|
|
rte_update(p->table, n, p, p, NULL);
|
1999-12-03 19:41:23 +08:00
|
|
|
r->installed = 0;
|
1998-12-07 07:13:31 +08:00
|
|
|
}
|
|
|
|
|
2010-12-08 06:34:36 +08:00
|
|
|
static int
|
|
|
|
static_decide(struct static_config *cf, struct static_route *r)
|
|
|
|
{
|
|
|
|
/* r->dest != RTD_MULTIPATH, but may be RTD_NONE (part of multipath route)
|
|
|
|
the route also have to be valid (r->neigh != NULL) */
|
|
|
|
|
|
|
|
struct iface *ifa = r->neigh->iface;
|
|
|
|
|
|
|
|
if (!ifa)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (cf->check_link && !(ifa->flags & IF_LINK_UP))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-17 20:38:50 +08:00
|
|
|
static void
|
2010-11-11 19:24:27 +08:00
|
|
|
static_add(struct proto *p, struct static_config *cf, struct static_route *r)
|
2000-01-17 20:38:50 +08:00
|
|
|
{
|
2000-05-13 19:01:41 +08:00
|
|
|
DBG("static_add(%I/%d,%d)\n", r->net, r->masklen, r->dest);
|
2000-01-17 20:38:50 +08:00
|
|
|
switch (r->dest)
|
|
|
|
{
|
|
|
|
case RTD_ROUTER:
|
|
|
|
{
|
|
|
|
struct neighbor *n = neigh_find(p, &r->via, NEF_STICKY);
|
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
r->chain = n->data;
|
|
|
|
n->data = r;
|
|
|
|
r->neigh = n;
|
2010-11-11 19:24:27 +08:00
|
|
|
if (static_decide(cf, r))
|
2000-01-17 20:38:50 +08:00
|
|
|
static_install(p, r, n->iface);
|
2010-11-11 19:24:27 +08:00
|
|
|
else
|
|
|
|
static_remove(p, r);
|
2000-01-17 20:38:50 +08:00
|
|
|
}
|
|
|
|
else
|
2010-12-08 06:34:36 +08:00
|
|
|
{
|
|
|
|
log(L_ERR "Static route destination %I is invalid. Ignoring.", r->via);
|
|
|
|
static_remove(p, r);
|
|
|
|
}
|
2000-01-17 20:38:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-12-08 06:34:36 +08:00
|
|
|
|
2000-01-17 20:38:50 +08:00
|
|
|
case RTD_DEVICE:
|
|
|
|
break;
|
2010-12-08 06:34:36 +08:00
|
|
|
|
|
|
|
case RTD_MULTIPATH:
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
struct static_route *r2;
|
|
|
|
|
|
|
|
for (r2 = r->mp_next; r2; r2 = r2->mp_next)
|
|
|
|
{
|
|
|
|
struct neighbor *n = neigh_find(p, &r2->via, NEF_STICKY);
|
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
r2->chain = n->data;
|
|
|
|
n->data = r2;
|
|
|
|
r2->neigh = n;
|
|
|
|
r2->installed = static_decide(cf, r2);
|
|
|
|
count += r2->installed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log(L_ERR "Static route destination %I is invalid. Ignoring.", r2->via);
|
|
|
|
r2->installed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
static_install(p, r, NULL);
|
|
|
|
else
|
|
|
|
static_remove(p, r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-01-17 20:38:50 +08:00
|
|
|
default:
|
|
|
|
static_install(p, r, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-06 05:38:22 +08:00
|
|
|
static int
|
|
|
|
static_start(struct proto *p)
|
1998-12-07 02:21:23 +08:00
|
|
|
{
|
2011-09-24 08:21:52 +08:00
|
|
|
struct static_config *cf = (void *) p->cf;
|
1998-12-07 07:13:31 +08:00
|
|
|
struct static_route *r;
|
|
|
|
|
1998-12-07 02:21:23 +08:00
|
|
|
DBG("Static: take off!\n");
|
2011-09-24 08:21:52 +08:00
|
|
|
|
|
|
|
if (cf->igp_table)
|
|
|
|
rt_lock_table(cf->igp_table->table);
|
|
|
|
|
|
|
|
WALK_LIST(r, cf->other_routes)
|
|
|
|
static_add(p, cf, r);
|
1999-02-06 05:38:22 +08:00
|
|
|
return PS_UP;
|
1998-12-07 02:21:23 +08:00
|
|
|
}
|
|
|
|
|
2000-05-13 19:01:41 +08:00
|
|
|
static int
|
|
|
|
static_shutdown(struct proto *p)
|
|
|
|
{
|
2011-09-24 08:21:52 +08:00
|
|
|
struct static_config *cf = (void *) p->cf;
|
2000-05-13 19:01:41 +08:00
|
|
|
struct static_route *r;
|
|
|
|
|
2010-02-27 23:00:07 +08:00
|
|
|
/* Just reset the flag, the routes will be flushed by the nest */
|
2011-09-24 08:21:52 +08:00
|
|
|
WALK_LIST(r, cf->iface_routes)
|
2010-02-27 23:00:07 +08:00
|
|
|
r->installed = 0;
|
2011-09-24 08:21:52 +08:00
|
|
|
WALK_LIST(r, cf->other_routes)
|
2010-02-27 23:00:07 +08:00
|
|
|
r->installed = 0;
|
|
|
|
|
2000-05-13 19:01:41 +08:00
|
|
|
return PS_DOWN;
|
|
|
|
}
|
|
|
|
|
2011-09-24 08:21:52 +08:00
|
|
|
static void
|
|
|
|
static_cleanup(struct proto *p)
|
|
|
|
{
|
|
|
|
struct static_config *cf = (void *) p->cf;
|
|
|
|
|
|
|
|
if (cf->igp_table)
|
|
|
|
rt_unlock_table(cf->igp_table->table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-07 02:21:23 +08:00
|
|
|
static void
|
|
|
|
static_neigh_notify(struct neighbor *n)
|
|
|
|
{
|
1999-02-06 05:38:22 +08:00
|
|
|
struct proto *p = n->proto;
|
1998-12-09 02:31:31 +08:00
|
|
|
struct static_route *r;
|
|
|
|
|
2011-04-01 18:21:18 +08:00
|
|
|
DBG("Static: neighbor notify for %I: iface %p\n", n->addr, n->iface);
|
1998-12-09 02:31:31 +08:00
|
|
|
for(r=n->data; r; r=r->chain)
|
2010-12-08 06:34:36 +08:00
|
|
|
switch (r->dest)
|
|
|
|
{
|
|
|
|
case RTD_ROUTER:
|
|
|
|
if (static_decide((struct static_config *) p->cf, r))
|
|
|
|
static_install(p, r, n->iface);
|
|
|
|
else
|
|
|
|
static_remove(p, r);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTD_NONE: /* a part of multipath route */
|
|
|
|
{
|
|
|
|
int decision = static_decide((struct static_config *) p->cf, r);
|
|
|
|
if (decision == r->installed)
|
|
|
|
break; /* no change */
|
|
|
|
r->installed = decision;
|
|
|
|
|
|
|
|
struct static_route *r1, *r2;
|
|
|
|
int count = 0;
|
|
|
|
r1 = (void *) r->if_name; /* really */
|
|
|
|
for (r2 = r1->mp_next; r2; r2 = r2->mp_next)
|
|
|
|
count += r2->installed;
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
/* Set of nexthops changed - force reinstall */
|
|
|
|
r1->installed = 0;
|
|
|
|
static_install(p, r1, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
static_remove(p, r1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-12-07 07:13:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
static_dump_rt(struct static_route *r)
|
|
|
|
{
|
2001-08-19 19:15:24 +08:00
|
|
|
debug("%-1I/%2d: ", r->net, r->masklen);
|
1998-12-07 07:13:31 +08:00
|
|
|
switch (r->dest)
|
|
|
|
{
|
|
|
|
case RTD_ROUTER:
|
|
|
|
debug("via %I\n", r->via);
|
|
|
|
break;
|
|
|
|
case RTD_DEVICE:
|
|
|
|
debug("dev %s\n", r->if_name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("rtd %d\n", r->dest);
|
|
|
|
break;
|
|
|
|
}
|
1998-12-07 02:21:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-02-06 05:38:22 +08:00
|
|
|
static_dump(struct proto *p)
|
1998-12-07 02:21:23 +08:00
|
|
|
{
|
1999-02-06 05:38:22 +08:00
|
|
|
struct static_config *c = (void *) p->cf;
|
1998-12-07 07:13:31 +08:00
|
|
|
struct static_route *r;
|
|
|
|
|
|
|
|
debug("Independent static routes:\n");
|
1999-02-06 05:38:22 +08:00
|
|
|
WALK_LIST(r, c->other_routes)
|
1998-12-07 07:13:31 +08:00
|
|
|
static_dump_rt(r);
|
|
|
|
debug("Device static routes:\n");
|
1999-02-06 05:38:22 +08:00
|
|
|
WALK_LIST(r, c->iface_routes)
|
1998-12-07 07:13:31 +08:00
|
|
|
static_dump_rt(r);
|
1998-12-07 02:21:23 +08:00
|
|
|
}
|
|
|
|
|
1999-02-14 05:59:48 +08:00
|
|
|
static void
|
1999-05-07 05:38:11 +08:00
|
|
|
static_if_notify(struct proto *p, unsigned flags, struct iface *i)
|
1999-02-14 05:59:48 +08:00
|
|
|
{
|
|
|
|
struct static_route *r;
|
|
|
|
struct static_config *c = (void *) p->cf;
|
|
|
|
|
|
|
|
if (flags & IF_CHANGE_UP)
|
|
|
|
{
|
|
|
|
WALK_LIST(r, c->iface_routes)
|
1999-05-07 05:38:11 +08:00
|
|
|
if (!strcmp(r->if_name, i->name))
|
|
|
|
static_install(p, r, i);
|
1999-02-14 05:59:48 +08:00
|
|
|
}
|
|
|
|
else if (flags & IF_CHANGE_DOWN)
|
|
|
|
{
|
|
|
|
WALK_LIST(r, c->iface_routes)
|
1999-05-07 05:38:11 +08:00
|
|
|
if (!strcmp(r->if_name, i->name))
|
1999-02-14 05:59:48 +08:00
|
|
|
static_remove(p, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-07 02:21:23 +08:00
|
|
|
void
|
1999-02-06 05:38:22 +08:00
|
|
|
static_init_config(struct static_config *c)
|
1998-12-07 02:21:23 +08:00
|
|
|
{
|
1999-02-06 05:38:22 +08:00
|
|
|
c->c.preference = DEF_PREF_STATIC;
|
|
|
|
init_list(&c->iface_routes);
|
|
|
|
init_list(&c->other_routes);
|
1998-12-07 02:21:23 +08:00
|
|
|
}
|
|
|
|
|
1999-02-06 05:38:22 +08:00
|
|
|
static struct proto *
|
|
|
|
static_init(struct proto_config *c)
|
1998-12-07 02:21:23 +08:00
|
|
|
{
|
1999-02-06 05:38:22 +08:00
|
|
|
struct proto *p = proto_new(c, sizeof(struct proto));
|
1998-12-07 02:21:23 +08:00
|
|
|
|
1999-02-06 05:38:22 +08:00
|
|
|
p->neigh_notify = static_neigh_notify;
|
1999-02-14 05:59:48 +08:00
|
|
|
p->if_notify = static_if_notify;
|
1999-02-06 05:38:22 +08:00
|
|
|
return p;
|
1998-12-07 02:21:23 +08:00
|
|
|
}
|
|
|
|
|
2010-05-16 17:03:59 +08:00
|
|
|
static inline int
|
|
|
|
static_same_net(struct static_route *x, struct static_route *y)
|
2000-01-17 20:38:50 +08:00
|
|
|
{
|
2010-05-16 17:03:59 +08:00
|
|
|
return ipa_equal(x->net, y->net) && (x->masklen == y->masklen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
static_same_dest(struct static_route *x, struct static_route *y)
|
|
|
|
{
|
2010-12-08 06:34:36 +08:00
|
|
|
if (x->dest != y->dest)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (x->dest)
|
|
|
|
{
|
|
|
|
case RTD_ROUTER:
|
|
|
|
return ipa_equal(x->via, y->via);
|
|
|
|
|
|
|
|
case RTD_DEVICE:
|
|
|
|
return !strcmp(x->if_name, y->if_name);
|
|
|
|
|
|
|
|
case RTD_MULTIPATH:
|
|
|
|
for (x = x->mp_next, y = y->mp_next;
|
|
|
|
x && y;
|
|
|
|
x = x->mp_next, y = y->mp_next)
|
|
|
|
if (!ipa_equal(x->via, y->via))
|
|
|
|
return 0;
|
|
|
|
return !x && !y;
|
|
|
|
|
2011-09-24 08:21:52 +08:00
|
|
|
case RTDX_RECURSIVE:
|
|
|
|
return ipa_equal(x->via, y->via);
|
|
|
|
|
2010-12-08 06:34:36 +08:00
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
2000-01-17 20:38:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
static_match(struct proto *p, struct static_route *r, struct static_config *n)
|
|
|
|
{
|
|
|
|
struct static_route *t;
|
|
|
|
|
2010-05-16 17:03:59 +08:00
|
|
|
/*
|
|
|
|
* For given old route *r we find whether a route to the same
|
|
|
|
* network is also in the new route list. In that case, we keep the
|
|
|
|
* route and possibly update the route later if destination changed.
|
|
|
|
* Otherwise, we remove the route.
|
|
|
|
*/
|
|
|
|
|
2000-01-17 20:38:50 +08:00
|
|
|
if (r->neigh)
|
|
|
|
r->neigh->data = NULL;
|
|
|
|
WALK_LIST(t, n->iface_routes)
|
2010-05-16 17:03:59 +08:00
|
|
|
if (static_same_net(r, t))
|
2000-01-17 20:38:50 +08:00
|
|
|
{
|
2010-11-11 19:24:27 +08:00
|
|
|
t->installed = r->installed && static_same_dest(r, t);
|
2000-01-17 20:38:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
WALK_LIST(t, n->other_routes)
|
2010-05-16 17:03:59 +08:00
|
|
|
if (static_same_net(r, t))
|
2000-01-17 20:38:50 +08:00
|
|
|
{
|
2010-11-11 19:24:27 +08:00
|
|
|
t->installed = r->installed && static_same_dest(r, t);
|
2000-01-17 20:38:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
static_remove(p, r);
|
|
|
|
}
|
|
|
|
|
2011-09-24 08:21:52 +08:00
|
|
|
static inline rtable *
|
|
|
|
cf_igp_table(struct static_config *cf)
|
|
|
|
{
|
|
|
|
return cf->igp_table ? cf->igp_table->table : NULL;
|
|
|
|
}
|
|
|
|
|
2000-01-17 19:52:50 +08:00
|
|
|
static int
|
|
|
|
static_reconfigure(struct proto *p, struct proto_config *new)
|
|
|
|
{
|
2000-01-17 20:38:50 +08:00
|
|
|
struct static_config *o = (void *) p->cf;
|
|
|
|
struct static_config *n = (void *) new;
|
|
|
|
struct static_route *r;
|
|
|
|
|
2011-09-24 08:21:52 +08:00
|
|
|
if (cf_igp_table(o) != cf_igp_table(n))
|
|
|
|
return 0;
|
|
|
|
|
2000-01-17 20:38:50 +08:00
|
|
|
/* Delete all obsolete routes and reset neighbor entries */
|
|
|
|
WALK_LIST(r, o->iface_routes)
|
|
|
|
static_match(p, r, n);
|
|
|
|
WALK_LIST(r, o->other_routes)
|
|
|
|
static_match(p, r, n);
|
|
|
|
|
|
|
|
/* Now add all new routes, those not changed will be ignored by static_install() */
|
|
|
|
WALK_LIST(r, n->iface_routes)
|
|
|
|
{
|
|
|
|
struct iface *ifa;
|
|
|
|
if (ifa = if_find_by_name(r->if_name))
|
|
|
|
static_install(p, r, ifa);
|
|
|
|
}
|
|
|
|
WALK_LIST(r, n->other_routes)
|
2010-11-11 19:24:27 +08:00
|
|
|
static_add(p, n, r);
|
2000-01-17 20:38:50 +08:00
|
|
|
|
|
|
|
return 1;
|
2000-01-17 19:52:50 +08:00
|
|
|
}
|
|
|
|
|
1998-12-07 02:21:23 +08:00
|
|
|
struct protocol proto_static = {
|
1999-02-06 05:38:22 +08:00
|
|
|
name: "Static",
|
2000-01-17 19:52:50 +08:00
|
|
|
template: "static%d",
|
1999-02-06 05:38:22 +08:00
|
|
|
init: static_init,
|
|
|
|
dump: static_dump,
|
|
|
|
start: static_start,
|
2000-05-13 19:01:41 +08:00
|
|
|
shutdown: static_shutdown,
|
2011-09-24 08:21:52 +08:00
|
|
|
cleanup: static_cleanup,
|
2000-01-17 19:52:50 +08:00
|
|
|
reconfigure: static_reconfigure,
|
1998-12-07 02:21:23 +08:00
|
|
|
};
|
1999-12-03 19:41:23 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
static_show_rt(struct static_route *r)
|
|
|
|
{
|
|
|
|
byte via[STD_ADDRESS_P_LENGTH + 16];
|
|
|
|
|
|
|
|
switch (r->dest)
|
|
|
|
{
|
|
|
|
case RTD_ROUTER: bsprintf(via, "via %I", r->via); break;
|
2010-02-27 23:00:07 +08:00
|
|
|
case RTD_DEVICE: bsprintf(via, "dev %s", r->if_name); break;
|
1999-12-03 19:41:23 +08:00
|
|
|
case RTD_BLACKHOLE: bsprintf(via, "blackhole"); break;
|
2010-12-08 06:34:36 +08:00
|
|
|
case RTD_UNREACHABLE: bsprintf(via, "unreachable"); break;
|
1999-12-03 19:41:23 +08:00
|
|
|
case RTD_PROHIBIT: bsprintf(via, "prohibited"); break;
|
2010-12-08 06:34:36 +08:00
|
|
|
case RTD_MULTIPATH: bsprintf(via, "multipath"); break;
|
2011-09-24 08:21:52 +08:00
|
|
|
case RTDX_RECURSIVE: bsprintf(via, "recursive %I", r->via); break;
|
1999-12-03 19:41:23 +08:00
|
|
|
default: bsprintf(via, "???");
|
|
|
|
}
|
|
|
|
cli_msg(-1009, "%I/%d %s%s", r->net, r->masklen, via, r->installed ? "" : " (dormant)");
|
2010-12-08 06:34:36 +08:00
|
|
|
|
|
|
|
struct static_route *r2;
|
|
|
|
if (r->dest == RTD_MULTIPATH)
|
|
|
|
for (r2 = r->mp_next; r2; r2 = r2->mp_next)
|
|
|
|
cli_msg(-1009, "\tvia %I weight %d%s", r2->via, r2->masklen + 1, /* really */
|
|
|
|
r2->installed ? "" : " (dormant)");
|
1999-12-03 19:41:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
static_show(struct proto *P)
|
|
|
|
{
|
|
|
|
struct static_config *c = (void *) P->cf;
|
|
|
|
struct static_route *r;
|
|
|
|
|
|
|
|
WALK_LIST(r, c->other_routes)
|
|
|
|
static_show_rt(r);
|
|
|
|
WALK_LIST(r, c->iface_routes)
|
|
|
|
static_show_rt(r);
|
|
|
|
cli_msg(0, "");
|
|
|
|
}
|