diff options
author | Jan Moskyto Matejka <mq@ucw.cz> | 2016-04-08 13:08:03 +0200 |
---|---|---|
committer | Jan Moskyto Matejka <mq@ucw.cz> | 2016-04-08 13:09:06 +0200 |
commit | 2003a1840731bd57365876e48c96c5a1ea0348cb (patch) | |
tree | c473a93f4027ea2706ccac3502ccef36736fbb6d /nest | |
parent | 4bdf1881dc6230b742d7efcaad8eeac4ed25f445 (diff) |
Route update: move table lookup from protocols into rte_update2().
Many protocols do almost the same when creating a rte_update request
before calling rte_update2(). This commit should simplify the protocol
side of the route-creation routine.
Diffstat (limited to 'nest')
-rw-r--r-- | nest/protocol.h | 2 | ||||
-rw-r--r-- | nest/route.h | 2 | ||||
-rw-r--r-- | nest/rt-dev.c | 15 | ||||
-rw-r--r-- | nest/rt-table.c | 14 |
4 files changed, 13 insertions, 20 deletions
diff --git a/nest/protocol.h b/nest/protocol.h index 19f5d070..68f0d5c5 100644 --- a/nest/protocol.h +++ b/nest/protocol.h @@ -271,7 +271,7 @@ proto_get_router_id(struct proto_config *pc) } /* Moved from route.h to avoid dependency conflicts */ -static inline void rte_update(struct proto *p, net *net, rte *new) { rte_update2(p->main_channel, net, new, p->main_source); } +static inline void rte_update(struct proto *p, net_addr *n, rte *new) { rte_update2(p->main_channel, n, new, p->main_source); } extern list proto_list; diff --git a/nest/route.h b/nest/route.h index 22fca331..5f34d47a 100644 --- a/nest/route.h +++ b/nest/route.h @@ -276,7 +276,7 @@ static inline net *net_get(rtable *tab, const net_addr *addr) { return (net *) f rte *rte_find(net *net, struct rte_src *src); rte *rte_get_temp(struct rta *); -void rte_update2(struct channel *c, net *net, rte *new, struct rte_src *src); +void rte_update2(struct channel *c, net_addr *n, rte *new, struct rte_src *src); /* rte_update() moved to protocol.h to avoid dependency conflicts */ void rte_discard(rtable *tab, rte *old); int rt_examine(rtable *t, net_addr *a, struct proto *p, struct filter *filter); diff --git a/nest/rt-dev.c b/nest/rt-dev.c index a996f4fc..098885b9 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -55,24 +55,15 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad) if (flags & IF_CHANGE_DOWN) { - net *n; - DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip); - n = net_find(c->table, &ad->prefix); - if (!n) - { - DBG("dev_if_notify: device shutdown: prefix not found\n"); - return; - } /* Use iface ID as local source ID */ struct rte_src *src = rt_get_source(P, ad->iface->index); - rte_update2(c, n, NULL, src); + rte_update2(c, &ad->prefix, NULL, src); } else if (flags & IF_CHANGE_UP) { rta *a; - net *n; rte *e; DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip); @@ -90,11 +81,9 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad) }; a = rta_lookup(&a0); - n = net_get(c->table, &ad->prefix); e = rte_get_temp(a); - e->net = n; e->pflags = 0; - rte_update2(c, n, e, src); + rte_update2(c, &ad->prefix, e, src); } } diff --git a/nest/rt-table.c b/nest/rt-table.c index 03ab3b92..9614d9ef 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -1267,19 +1267,23 @@ rte_unhide_dummy_routes(net *net, rte **dummy) */ void -rte_update2(struct channel *c, net *net, rte *new, struct rte_src *src) +rte_update2(struct channel *c, net_addr *n, rte *new, struct rte_src *src) { struct proto *p = c->proto; struct proto_stats *stats = &c->stats; struct filter *filter = c->in_filter; ea_list *tmpa = NULL; rte *dummy = NULL; + net *nn; ASSERT(c->channel_state == CS_UP); rte_update_lock(); if (new) { + nn = net_get(c->table, n); + + new->net = nn; new->sender = c; if (!new->pref) @@ -1333,7 +1337,7 @@ rte_update2(struct channel *c, net *net, rte *new, struct rte_src *src) { stats->imp_withdraws_received++; - if (!net || !src) + if (!(nn = net_find(c->table, n)) || !src) { stats->imp_withdraws_ignored++; rte_update_unlock(); @@ -1342,9 +1346,9 @@ rte_update2(struct channel *c, net *net, rte *new, struct rte_src *src) } recalc: - rte_hide_dummy_routes(net, &dummy); - rte_recalculate(c, net, new, src); - rte_unhide_dummy_routes(net, &dummy); + rte_hide_dummy_routes(nn, &dummy); + rte_recalculate(c, nn, new, src); + rte_unhide_dummy_routes(nn, &dummy); rte_update_unlock(); return; |