]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
OSPF: Improved handling of tmpattrs
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 6 Mar 2019 17:14:12 +0000 (18:14 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 6 Mar 2019 17:28:00 +0000 (18:28 +0100)
Keep track of whether OSPF tmpattrs are actually defined for given route
(using flags in rte->pflags). That makes them behave more like real
eattrs so a protocol can define just a subset of them or they can be
undefined by filters.

Do not set ospf_metric2 for other than type 2 external OSPF routes and do
not set ospf_tag for non-external OSPF routes. That also fixes a bug
where internal/inter-area route propagated from one OSPF instance to
another is initiated with infinity ospf_metric2.

Thanks to Yaroslav Dronskii for the bugreport.

nest/route.h
nest/rt-table.c
proto/ospf/ospf.c
proto/ospf/rt.c

index 8dfbb3762713a1c54751c20ebfcff12bc6af1b5e..3e835bb1532ed8f986d386ccfdc3ca7f6456071e 100644 (file)
@@ -308,6 +308,8 @@ void rte_free(rte *);
 rte *rte_do_cow(rte *);
 static inline rte * rte_cow(rte *r) { return (r->flags & REF_COW) ? rte_do_cow(r) : r; }
 rte *rte_cow_rta(rte *r, linpool *lp);
+void rte_make_tmp_attr(struct rte *r, struct ea_list *e, uint id, uint type, u32 val);
+uint rte_store_tmp_attr(struct rte *r, uint id);
 void rt_dump(rtable *);
 void rt_dump_all(void);
 int rt_feed_channel(struct channel *c);
@@ -481,6 +483,7 @@ typedef struct eattr {
 #define EA_CODE(proto,id) (((proto) << 8) | (id))
 #define EA_ID(ea) ((ea) & 0xff)
 #define EA_PROTO(ea) ((ea) >> 8)
+#define EA_ID_FLAG(ea) (1 << EA_ID(ea))
 #define EA_CUSTOM(id) ((id) | EA_CUSTOM_BIT)
 #define EA_IS_CUSTOM(ea) ((ea) & EA_CUSTOM_BIT)
 #define EA_CUSTOM_ID(ea) ((ea) & ~EA_CUSTOM_BIT)
index 6bf07a091359a70fb208d5b91499646749ac8f7d..7990fca3c01799937a3da7f220a7568d20f3918e 100644 (file)
@@ -325,6 +325,39 @@ rte_cow_rta(rte *r, linpool *lp)
   return r;
 }
 
+
+/* Note that rte_make_tmp_attr() requires free eattr in ea_list */
+void
+rte_make_tmp_attr(rte *r, ea_list *e, uint id, uint type, u32 val)
+{
+  if (r->pflags & EA_ID_FLAG(id))
+  {
+    eattr *a = &e->attrs[e->count++];
+    a->id = id;
+    a->type = type | EAF_TEMP;
+    a->flags = 0;
+    a->u.data = val;
+  }
+}
+
+/* Note that rte has to be writable */
+uint
+rte_store_tmp_attr(rte *r, uint id)
+{
+  eattr *a;
+  if (a = ea_find(r->attrs->eattrs, id))
+  {
+    r->pflags |= EA_ID_FLAG(id);
+    return a->u.data;
+  }
+  else
+  {
+    r->pflags &= ~EA_ID_FLAG(id);
+    return 0;
+  }
+}
+
+
 static int                             /* Actually better or at least as good as */
 rte_better(rte *new, rte *old)
 {
index ef2a0df43bb5261781ddf0e363fb60c2bb7ef78d..def73cb6f6a970afc2fe656e36056109ee141862 100644 (file)
@@ -364,35 +364,6 @@ ospf_rte_same(struct rte *new, struct rte *old)
     new->u.ospf.router_id == old->u.ospf.router_id;
 }
 
-static ea_list *
-ospf_build_attrs(ea_list * next, struct linpool *pool, u32 m1, u32 m2,
-                u32 tag, u32 rid)
-{
-  struct ea_list *l =
-    lp_alloc(pool, sizeof(struct ea_list) + 4 * sizeof(eattr));
-
-  l->next = next;
-  l->flags = EALF_SORTED;
-  l->count = 4;
-  l->attrs[0].id = EA_OSPF_METRIC1;
-  l->attrs[0].flags = 0;
-  l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP;
-  l->attrs[0].u.data = m1;
-  l->attrs[1].id = EA_OSPF_METRIC2;
-  l->attrs[1].flags = 0;
-  l->attrs[1].type = EAF_TYPE_INT | EAF_TEMP;
-  l->attrs[1].u.data = m2;
-  l->attrs[2].id = EA_OSPF_TAG;
-  l->attrs[2].flags = 0;
-  l->attrs[2].type = EAF_TYPE_INT | EAF_TEMP;
-  l->attrs[2].u.data = tag;
-  l->attrs[3].id = EA_OSPF_ROUTER_ID;
-  l->attrs[3].flags = 0;
-  l->attrs[3].type = EAF_TYPE_ROUTER_ID | EAF_TEMP;
-  l->attrs[3].u.data = rid;
-  return l;
-}
-
 
 void
 ospf_schedule_rtcalc(struct ospf_proto *p)
@@ -470,17 +441,27 @@ ospf_preexport(struct proto *P, rte **new, struct linpool *pool UNUSED)
 static struct ea_list *
 ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool)
 {
-  return ospf_build_attrs(NULL, pool, rt->u.ospf.metric1, rt->u.ospf.metric2,
-                         rt->u.ospf.tag, rt->u.ospf.router_id);
+  struct ea_list *e = lp_alloc(pool, sizeof(struct ea_list) + 4 * sizeof(eattr));
+
+  e->next = NULL;
+  e->flags = EALF_SORTED;
+  e->count = 0;
+
+  rte_make_tmp_attr(rt, e, EA_OSPF_METRIC1, EAF_TYPE_INT, rt->u.ospf.metric1);
+  rte_make_tmp_attr(rt, e, EA_OSPF_METRIC2, EAF_TYPE_INT, rt->u.ospf.metric2);
+  rte_make_tmp_attr(rt, e, EA_OSPF_TAG, EAF_TYPE_INT, rt->u.ospf.tag);
+  rte_make_tmp_attr(rt, e, EA_OSPF_ROUTER_ID, EAF_TYPE_ROUTER_ID, rt->u.ospf.router_id);
+
+  return e;
 }
 
 static void
 ospf_store_tmp_attrs(struct rte *rt)
 {
-  rt->u.ospf.metric1 = ea_get_int(rt->attrs->eattrs, EA_OSPF_METRIC1, LSINFINITY);
-  rt->u.ospf.metric2 = ea_get_int(rt->attrs->eattrs, EA_OSPF_METRIC2, 10000);
-  rt->u.ospf.tag = ea_get_int(rt->attrs->eattrs, EA_OSPF_TAG, 0);
-  rt->u.ospf.router_id = ea_get_int(rt->attrs->eattrs, EA_OSPF_ROUTER_ID, 0);
+  rt->u.ospf.metric1 = rte_store_tmp_attr(rt, EA_OSPF_METRIC1);
+  rt->u.ospf.metric2 = rte_store_tmp_attr(rt, EA_OSPF_METRIC2);
+  rt->u.ospf.tag = rte_store_tmp_attr(rt, EA_OSPF_TAG);
+  rt->u.ospf.router_id = rte_store_tmp_attr(rt, EA_OSPF_ROUTER_ID);
 }
 
 /**
index c580d06e51c436de30466df60900f31f75de6db0..6ddd6c9f457a13babec0b7f928e55798dcf47687 100644 (file)
@@ -402,8 +402,6 @@ add_network(struct ospf_area *oa, net_addr *net, int metric, struct top_hash_ent
     .type = RTS_OSPF,
     .options = 0,
     .metric1 = metric,
-    .metric2 = LSINFINITY,
-    .tag = 0,
     .rid = en->lsa.rt,
     .oa = oa,
     .nhs = en->nhs
@@ -459,8 +457,6 @@ spfa_process_rt(struct ospf_proto *p, struct ospf_area *oa, struct top_hash_entr
       .type = RTS_OSPF,
       .options = rt->options,
       .metric1 = act->dist,
-      .metric2 = LSINFINITY,
-      .tag = 0,
       .rid = act->lsa.rt,
       .oa = oa,
       .nhs = act->nhs
@@ -823,8 +819,6 @@ ospf_rt_sum(struct ospf_area *oa)
       .type = RTS_OSPF_IA,
       .options = options,
       .metric1 = abr->n.metric1 + metric,
-      .metric2 = LSINFINITY,
-      .tag = 0,
       .rid = en->lsa.rt, /* ABR ID */
       .oa = oa,
       .nhs = abr->n.nhs
@@ -1563,7 +1557,7 @@ ospf_ext_spf(struct ospf_proto *p)
     {
       nfa.type = RTS_OSPF_EXT1;
       nfa.metric1 = br_metric + rt.metric;
-      nfa.metric2 = LSINFINITY;
+      nfa.metric2 = 0;
     }
 
     /* Mark the LSA as reachable */
@@ -2033,7 +2027,14 @@ again1:
        e->u.ospf.metric2 = nf->old_metric2 = nf->n.metric2;
        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->pflags = EA_ID_FLAG(EA_OSPF_METRIC1) | EA_ID_FLAG(EA_OSPF_ROUTER_ID);
+
+       if (nf->n.type == RTS_OSPF_EXT2)
+         e->pflags |= EA_ID_FLAG(EA_OSPF_METRIC2);
+
+       /* Perhaps onfly if tag is non-zero? */
+       if ((nf->n.type == RTS_OSPF_EXT1) || (nf->n.type == RTS_OSPF_EXT2))
+         e->pflags |= EA_ID_FLAG(EA_OSPF_TAG);
 
        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);