]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Bug in rte_better.
authorOndrej Filip <feela@network.cz>
Wed, 16 Aug 2000 19:03:06 +0000 (19:03 +0000)
committerOndrej Filip <feela@network.cz>
Wed, 16 Aug 2000 19:03:06 +0000 (19:03 +0000)
proto/ospf/ospf.c

index 589e371ec9f94538a2599df3ccbc8a3db951692c..0a151c43b1b1bbe56b4d1df1e13f5b0a60b9dd8b 100644 (file)
@@ -175,24 +175,32 @@ ospf_rte_better(struct rte *new, struct rte *old)
 
   if(new->u.ospf.metric1=LSINFINITY) return 0;
 
+  /* External paths are always longer that internal */
   if(((new->attrs->source==RTS_OSPF) || (new->attrs->source==RTS_OSPF_IA))
     && (old->attrs->source==RTS_OSPF_EXT)) return 1;
-
   if(((old->attrs->source==RTS_OSPF) || (old->attrs->source==RTS_OSPF_IA))
     && (new->attrs->source==RTS_OSPF_EXT)) return 0;
 
-  if(new->u.ospf.metric2!=0)
+  if(new->u.ospf.metric2<old->u.ospf.metric2)
   {
-    if(old->u.ospf.metric2==0) return 0;
-    if(new->u.ospf.metric2<old->u.ospf.metric2) return 1;
-    return 0;
+    if(old->u.ospf.metric2==LSINFINITY) return 0; /* Old is E1, new is E2 */
+    return 1;  /* Both are E2 */
   }
-  else
+       
+  if(new->u.ospf.metric2>old->u.ospf.metric2)
   {
-    if(old->u.ospf.metric2!=0) return 1;
-    if(new->u.ospf.metric1<old->u.ospf.metric1) return 1;
-    return 0;
+    if(new->u.ospf.metric2==LSINFINITY) return 1; /* New is E1, old is E2 */
+    return 0;  /* Both are E2 */
   }
+
+  /* 
+   * E2 metrics are the same. It means that:
+   * 1) Paths are E2 with same metric
+   * 2) Paths are E1.
+   */
+
+  if(new->u.ospf.metric1<old->u.ospf.metric1) return 1;
+  return 0;    /* Old is shorter or same */
 }
 
 static int
@@ -419,9 +427,9 @@ ospf_get_route_info(rte *rte, byte *buf, ea_list *attrs)
   if(rte->attrs->source==RTS_OSPF) type='I';
   buf += bsprintf(buf, " %c", type);
   if(met!=' ') buf += bsprintf(buf, "%c", met);
-  buf += bsprintf(buf, " (%d/%d)", rte->pref,
-    (rte->u.ospf.metric2==LSINFINITY) ? rte->u.ospf.metric1 :
-    rte->u.ospf.metric2);
+  buf += bsprintf(buf, " (%d/%d", rte->pref, rte->u.ospf.metric1);
+  if(rte->u.ospf.metric2!=LSINFINITY) buf += bsprintf(buf, "/%d", rte->u.ospf.metric2);
+  buf += bsprintf(buf, ")");
   if(rte->attrs->source==RTS_OSPF_EXT && rte->u.ospf.tag)
   {
     buf += bsprintf(buf, " [%x]", rte->u.ospf.tag);