diff options
Diffstat (limited to 'nest')
-rw-r--r-- | nest/route.h | 19 | ||||
-rw-r--r-- | nest/rt-attr.c | 5 | ||||
-rw-r--r-- | nest/rt-dev.c | 6 | ||||
-rw-r--r-- | nest/rt-table.c | 114 |
4 files changed, 50 insertions, 94 deletions
diff --git a/nest/route.h b/nest/route.h index ebe10f1..10628cd 100644 --- a/nest/route.h +++ b/nest/route.h @@ -94,17 +94,17 @@ void fit_put(struct fib_iterator *, struct fib_node *); #define FIB_ITERATE_PUT(it, z) fit_put(it, z) /* - * Master Routing Tables. Generally speaking, each of them is a list - * of FIB (one per TOS) with each entry pointing to a list of route entries - * representing routes to given network. + * Master Routing Tables. Generally speaking, each of them contains a FIB + * with each entry pointing to a list of route entries representing routes + * to given network (with the selected one at the head). + * * Each of the RTE's contains variable data (the preference and protocol-dependent * metrics) and a pointer to a route attribute block common for many routes). - * It's guaranteed that there is at most one RTE for every (prefix,proto,source) triplet. + * + * It's guaranteed that there is at most one RTE for every (prefix,proto) pair. */ typedef struct rtable { - struct rtable *sibling; /* Our sibling for different TOS */ - byte tos; /* TOS for this table */ struct fib fib; char *name; /* Name of this table */ } rtable; @@ -156,8 +156,8 @@ extern rtable master_table; void rt_init(void); void rt_setup(pool *, rtable *, char *); -net *net_find(rtable *tab, unsigned tos, ip_addr addr, unsigned len); -net *net_get(rtable *tab, unsigned tos, ip_addr addr, unsigned len); +static inline net *net_find(rtable *tab, ip_addr addr, unsigned len) { return (net *) fib_find(&tab->fib, &addr, len); } +static inline net *net_get(rtable *tab, ip_addr addr, unsigned len) { return (net *) fib_get(&tab->fib, &addr, len); } rte *rte_find(net *net, struct proto *p); rte *rte_get_temp(struct rta *); void rte_update(net *net, struct proto *p, rte *new); @@ -188,10 +188,9 @@ typedef struct rta { byte scope; /* Route scope (SCOPE_... -- see ip.h) */ byte cast; /* Casting type (RTC_...) */ byte dest; /* Route destination type (RTD_...) */ - byte tos; /* TOS of this route */ byte flags; /* Route flags (RTF_...) */ byte aflags; /* Attribute cache flags (RTAF_...) */ - byte rfu; /* Padding */ + byte rfu, rfu2; /* Padding */ ip_addr gw; /* Next hop */ ip_addr from; /* Advertising router */ struct iface *iface; /* Outgoing interface */ diff --git a/nest/rt-attr.c b/nest/rt-attr.c index 2cb2bc5..2a369ce 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -271,7 +271,6 @@ rta_same(rta *x, rta *y) x->scope == y->scope && x->cast == y->cast && x->dest == y->dest && - x->tos == y->tos && x->flags == y->flags && ipa_equal(x->gw, y->gw) && ipa_equal(x->from, y->from) && @@ -334,9 +333,9 @@ rta_dump(rta *a) static char *rtc[] = { "", " BC", " MC", " AC" }; static char *rtd[] = { "", " DEV", " HOLE", " UNREACH", " PROHIBIT" }; - debug("p=%s uc=%d %s %s%s%s TOS=%d", + debug("p=%s uc=%d %s %s%s%s", a->proto->name, a->uc, rts[a->source], sco[a->scope], rtc[a->cast], - rtd[a->dest], a->tos); + rtd[a->dest]); if (a->flags & RTF_EXTERIOR) debug(" EXT"); if (a->flags & RTF_TAGGED) diff --git a/nest/rt-dev.c b/nest/rt-dev.c index a92fe6f..d6035f5 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -31,7 +31,7 @@ dev_if_notify(struct proto *p, unsigned c, struct iface *new, struct iface *old) net *n; debug("dev_if_notify: %s going down\n", old->name); - n = net_find(p->table, 0, old->prefix, old->pxlen); + n = net_find(p->table, old->prefix, old->pxlen); if (!n) { debug("dev_if_notify: device shutdown: prefix not found\n"); @@ -56,9 +56,9 @@ dev_if_notify(struct proto *p, unsigned c, struct iface *new, struct iface *old) A.attrs = NULL; a = rta_lookup(&A); if (new->flags & IF_UNNUMBERED) - n = net_get(p->table, 0, new->opposite, new->pxlen); + n = net_get(p->table, new->opposite, new->pxlen); else - n = net_get(p->table, 0, new->prefix, new->pxlen); + n = net_get(p->table, new->prefix, new->pxlen); e = rte_get_temp(a); e->net = n; e->pflags = 0; diff --git a/nest/rt-table.c b/nest/rt-table.c index 47b4bb7..2b60bb8 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -46,35 +46,6 @@ rt_setup(pool *p, rtable *t, char *name) t->name = name; } -net * -net_find(rtable *tab, unsigned tos, ip_addr mask, unsigned len) -{ - while (tab && tab->tos != tos) - tab = tab->sibling; - if (!tab) - return NULL; - return (net *) fib_find(&tab->fib, &mask, len); -} - -net * -net_get(rtable *tab, unsigned tos, ip_addr mask, unsigned len) -{ - rtable *t = tab; - - while (t && t->tos != tos) - t = t->sibling; - if (!t) - { - while (tab->sibling) - tab = tab->sibling; - t = mb_alloc(&root_pool, sizeof(rtable)); - rt_setup(&root_pool, t, NULL); /* FIXME: Either delete all the TOS logic or use the right pool */ - tab->sibling = t; - t->tos = tos; - } - return (net *) fib_get(&t->fib, &mask, len); -} - rte * rte_find(net *net, struct proto *p) { @@ -181,23 +152,19 @@ rt_feed_baby(struct proto *p) if (!p->rt_notify) return; debug("Announcing routes to new protocol %s\n", p->name); - while (t) + FIB_WALK(&t->fib, fn) { - FIB_WALK(&t->fib, fn) + net *n = (net *) fn; + rte *e; + for(e=n->routes; e; e=e->next) { - net *n = (net *) fn; - rte *e; - for(e=n->routes; e; e=e->next) - { - struct proto *q = e->attrs->proto; - ea_list *tmpa = q->make_tmp_attrs ? q->make_tmp_attrs(e, rte_update_pool) : NULL; - do_rte_announce(p, n, e, NULL, tmpa); - lp_flush(rte_update_pool); - } + struct proto *q = e->attrs->proto; + ea_list *tmpa = q->make_tmp_attrs ? q->make_tmp_attrs(e, rte_update_pool) : NULL; + do_rte_announce(p, n, e, NULL, tmpa); + lp_flush(rte_update_pool); } - FIB_WALK_END; - t = t->sibling; } + FIB_WALK_END; } static inline int @@ -396,21 +363,16 @@ rt_dump(rtable *t) net *n; debug("Dump of routing table <%s>\n", t->name); - while (t) - { - debug("Routes for TOS %02x:\n", t->tos); #ifdef DEBUGGING - fib_check(&t->fib); + fib_check(&t->fib); #endif - FIB_WALK(&t->fib, fn) - { - n = (net *) fn; - for(e=n->routes; e; e=e->next) - rte_dump(e); - } - FIB_WALK_END; - t = t->sibling; + FIB_WALK(&t->fib, fn) + { + n = (net *) fn; + for(e=n->routes; e; e=e->next) + rte_dump(e); } + FIB_WALK_END; debug("\n"); } @@ -449,33 +411,29 @@ rt_prune(rtable *tab) int rcnt = 0, rdel = 0, ncnt = 0, ndel = 0; DBG("Pruning route table %s\n", tab->name); - while (tab) + FIB_ITERATE_INIT(&fit, &tab->fib); +again: + FIB_ITERATE_START(&tab->fib, &fit, f) { - FIB_ITERATE_INIT(&fit, &tab->fib); - again: - FIB_ITERATE_START(&tab->fib, &fit, f) + net *n = (net *) f; + rte *e; + ncnt++; + rescan: + for (e=n->routes; e; e=e->next, rcnt++) + if (e->attrs->proto->core_state != FS_HAPPY) + { + rte_discard(e); + rdel++; + goto rescan; + } + if (!n->routes) /* Orphaned FIB entry? */ { - net *n = (net *) f; - rte *e; - ncnt++; - rescan: - for (e=n->routes; e; e=e->next, rcnt++) - if (e->attrs->proto->core_state != FS_HAPPY) - { - rte_discard(e); - rdel++; - goto rescan; - } - if (!n->routes) /* Orphaned FIB entry? */ - { - FIB_ITERATE_PUT(&fit, f); - fib_delete(&tab->fib, f); - ndel++; - goto again; - } + FIB_ITERATE_PUT(&fit, f); + fib_delete(&tab->fib, f); + ndel++; + goto again; } - FIB_ITERATE_END(f); - tab = tab->sibling; } + FIB_ITERATE_END(f); DBG("Pruned %d of %d routes and %d of %d networks\n", rcnt, rdel, ncnt, ndel); } |