]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Route update: move table lookup from protocols into rte_update2().
authorJan Moskyto Matejka <mq@ucw.cz>
Fri, 8 Apr 2016 11:08:03 +0000 (13:08 +0200)
committerJan Moskyto Matejka <mq@ucw.cz>
Fri, 8 Apr 2016 11:09:06 +0000 (13:09 +0200)
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.

nest/protocol.h
nest/route.h
nest/rt-dev.c
nest/rt-table.c
proto/ospf/rt.c
proto/pipe/pipe.c
proto/rip/rip.c
proto/static/static.c
sysdep/unix/krt.c

index 19f5d0701edd96641e3a5add6880276acb6c36d0..68f0d5c592933cc8f763b27b58fc39e3fe4b4df5 100644 (file)
@@ -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;
 
index 22fca331754f5e889a3d47ac337a0eb9d69a34d8..5f34d47a88dc7bda10f18c89061da5b83bff33a3 100644 (file)
@@ -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);
index a996f4fc4b868e6c55fd1c4395498768100db822..098885b9271b88795b57f75bd223035eb5465065 100644 (file)
@@ -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);
     }
 }
 
index 03ab3b92f0980916c9117bc16401eb9db959c841..9614d9ef28bfa29c2b469e35a34acf651462be3e 100644 (file)
@@ -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;
 
index 0855f21fb05adbcdf690409932105028186f96b3..5538f4c8668e987af0eca4e4e882cfbfd0f23bd1 100644 (file)
@@ -1973,7 +1973,6 @@ again1:
 
       if (reload || ort_changed(nf, &a0))
       {
-       net *ne = net_get(p->p.main_channel->table, nf->fn.addr);
        rta *a = rta_lookup(&a0);
        rte *e = rte_get_temp(a);
 
@@ -1984,11 +1983,10 @@ again1:
        e->u.ospf.tag = nf->old_tag = nf->n.tag;
        e->u.ospf.router_id = nf->old_rid = nf->n.rid;
        e->pflags = 0;
-       e->net = ne;
 
        DBG("Mod rte type %d - %N via %I on iface %s, met %d\n",
            a0.source, nf->fn.addr, a0.gw, a0.iface ? a0.iface->name : "(none)", nf->n.metric1);
-       rte_update(&p->p, ne, e);
+       rte_update(&p->p, nf->fn.addr, e);
       }
     }
     else if (nf->old_rta)
@@ -1997,8 +1995,7 @@ again1:
       rta_free(nf->old_rta);
       nf->old_rta = NULL;
 
-      net *ne = net_get(p->p.main_channel->table, nf->fn.addr);
-      rte_update(&p->p, ne, NULL);
+      rte_update(&p->p, nf->fn.addr, NULL);
     }
 
     /* Remove unused rt entry, some special entries are persistent */
index f3df3e7148701f79fa20550ced08d713a90deb25..d40b3f91e1170bfa32cb50221c5eac31fc95b8a7 100644 (file)
@@ -50,7 +50,6 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o
   struct channel *dst = (src_ch == p->pri) ? p->sec : p->pri;
   struct rte_src *src;
 
-  net *nn;
   rte *e;
   rta a;
 
@@ -64,7 +63,6 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o
       return;
     }
 
-  nn = net_get(dst->table, n->n.addr);
   if (new)
     {
       memcpy(&a, new->attrs, sizeof(rta));
@@ -73,7 +71,6 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o
       a.eattrs = attrs;
       a.hostentry = NULL;
       e = rte_get_temp(&a);
-      e->net = nn;
       e->pflags = 0;
 
       /* Copy protocol specific embedded attributes. */
@@ -90,7 +87,7 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o
     }
 
   src_ch->table->pipe_busy = 1;
-  rte_update2(dst, nn, e, src);
+  rte_update2(dst, n->n.addr, e, src);
   src_ch->table->pipe_busy = 0;
 }
 
index 2202327929ef67b0eec789a7bb8cc6058647ef47..131c09ce1221495b8c65a5ebfe78cf1dfbeb81ba 100644 (file)
@@ -143,8 +143,6 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
   if (rt)
   {
     /* Update */
-    net *n = net_get(p->p.main_channel->table, en->n.addr);
-
     rta a0 = {
       .src = p->p.main_source,
       .source = RTS_RIP,
@@ -204,16 +202,14 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
     e->u.rip.metric = rt_metric;
     e->u.rip.tag = rt_tag;
 
-    e->net = n;
     e->pflags = 0;
 
-    rte_update(&p->p, n, e);
+    rte_update(&p->p, en->n.addr, e);
   }
   else
   {
     /* Withdraw */
-    net *n = net_find(p->p.main_channel->table, en->n.addr);
-    rte_update(&p->p, n, NULL);
+    rte_update(&p->p, en->n.addr, NULL);
   }
 }
 
index 6239fccbb9bf0a91be72f69332751248c99d25cd..28cb1e77163cbda3daa64a2f52612b9fb5db5798 100644 (file)
@@ -60,7 +60,6 @@ p_igp_table(struct proto *p)
 static void
 static_install(struct proto *p, struct static_route *r, struct iface *ifa)
 {
-  net *n;
   rta a;
   rte *e;
 
@@ -112,15 +111,13 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa)
 
   /* We skip rta_lookup() here */
 
-  n = net_get(p->main_channel->table, r->net);
   e = rte_get_temp(&a);
-  e->net = n;
   e->pflags = 0;
 
   if (r->cmds)
     f_eval_rte(r->cmds, &e, static_lp);
 
-  rte_update(p, n, e);
+  rte_update(p, r->net, e);
   r->installed = 1;
 
   if (r->cmds)
@@ -130,14 +127,11 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa)
 static void
 static_remove(struct proto *p, struct static_route *r)
 {
-  net *n;
-
   if (!r->installed)
     return;
 
   DBG("Removing static route %N via %I\n", r->net, r->via);
-  n = net_find(p->main_channel->table, r->net);
-  rte_update(p, n, NULL);
+  rte_update(p, r->net, NULL);
   r->installed = 0;
 }
 
index 6b3b4eee004b735c2fbff4ba3f309d15ccc73ac2..fe8af1c0593d6492ba73780c08b5d6b6550de9cf 100644 (file)
@@ -345,18 +345,15 @@ krt_learn_announce_update(struct krt_proto *p, rte *e)
   net *n = e->net;
   rta *aa = rta_clone(e->attrs);
   rte *ee = rte_get_temp(aa);
-  net *nn = net_get(p->p.main_channel->table, n->n.addr);
-  ee->net = nn;
   ee->pflags = 0;
   ee->u.krt = e->u.krt;
-  rte_update(&p->p, nn, ee);
+  rte_update(&p->p, n->n.addr, ee);
 }
 
 static void
 krt_learn_announce_delete(struct krt_proto *p, net *n)
 {
-  n = net_find(p->p.main_channel->table, n->n.addr);
-  rte_update(&p->p, n, NULL);
+  rte_update(&p->p, n->n.addr, NULL);
 }
 
 /* Called when alien route is discovered during scan */