]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Nest: Fix bug in recursive routes with MPLS-labeled nexthops
authorOndrej Zajicek <santiago@crfreenet.org>
Sat, 27 Jan 2024 16:38:06 +0000 (17:38 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Sat, 27 Jan 2024 16:38:06 +0000 (17:38 +0100)
When a recursive route with MPLS-labeled nexthop was exported to kernel
and read back, the nexthop_same() failed due to different labels_orig
field and kernel protocol reinstalled it unnecessarily.

For comparing hext hops, route cache has to distinguish ones with
different labels_orig, but KRT has to ignore that, so we need two
nexthop compare functions.

Thanks to Marcel Menzel for the bugreport.

nest/route.h
nest/rt-attr.c
sysdep/unix/krt.c

index d26a4b8c485427386c4fc4224c468dfc9f01c30a..e6f6c64a6c0184038d8e896dfed3058b04c8b5fb 100644 (file)
@@ -694,6 +694,9 @@ static inline size_t nexthop_size(const struct nexthop *nh)
 int nexthop__same(struct nexthop *x, struct nexthop *y); /* Compare multipath nexthops */
 static inline int nexthop_same(struct nexthop *x, struct nexthop *y)
 { return (x == y) || nexthop__same(x, y); }
+int nexthop_equal_(struct nexthop *x, struct nexthop *y); /* Compare multipath nexthops, ignore labels_orig */
+static inline int nexthop_equal(struct nexthop *x, struct nexthop *y)
+{ return (x == y) || nexthop_equal_(x, y); }
 struct nexthop *nexthop_merge(struct nexthop *x, struct nexthop *y, int rx, int ry, int max, linpool *lp);
 struct nexthop *nexthop_sort(struct nexthop *x);
 static inline void nexthop_link(struct rta *a, const struct nexthop *from)
index 7f3645ee90ddcf27c2bfec35731fc9865b5cfdfc..af864bdfa4e3db78fbbd605b2bc4532dbe001cb0 100644 (file)
@@ -185,20 +185,40 @@ nexthop_hash(struct nexthop *x)
   return h;
 }
 
+static inline int
+nexthop_equal_1(struct nexthop *x, struct nexthop *y)
+{
+  if (!ipa_equal(x->gw, y->gw) || (x->iface != y->iface) ||
+      (x->flags != y->flags) || (x->weight != y->weight) ||
+      (x->labels != y->labels))
+    return 0;
+
+  for (int i = 0; i < x->labels; i++)
+    if (x->label[i] != y->label[i])
+      return 0;
+
+  return 1;
+}
+
 int
-nexthop__same(struct nexthop *x, struct nexthop *y)
+nexthop_equal_(struct nexthop *x, struct nexthop *y)
 {
+  /* Like nexthop_same(), but ignores difference between local labels and labels from hostentry */
+
   for (; x && y; x = x->next, y = y->next)
-  {
-    if (!ipa_equal(x->gw, y->gw) || (x->iface != y->iface) ||
-       (x->flags != y->flags) || (x->weight != y->weight) ||
-       (x->labels_orig != y->labels_orig) || (x->labels != y->labels))
+    if (!nexthop_equal_1(x, y))
       return 0;
 
-    for (int i = 0; i < x->labels; i++)
-      if (x->label[i] != y->label[i])
-       return 0;
-  }
+  return x == y;
+}
+
+int
+nexthop__same(struct nexthop *x, struct nexthop *y)
+{
+  for (; x && y; x = x->next, y = y->next)
+    if (!nexthop_equal_1(x, y) ||
+       (x->labels_orig != y->labels_orig))
+      return 0;
 
   return x == y;
 }
index 3a4b24dceb050fce31d06eb3ec922d0e026b1048..7a078fb9d79f2c5a34e420dbee32bbccf96be29d 100644 (file)
@@ -619,7 +619,7 @@ krt_same_dest(rte *k, rte *e)
     return 0;
 
   if (ka->dest == RTD_UNICAST)
-    return nexthop_same(&(ka->nh), &(ea->nh));
+    return nexthop_equal(&(ka->nh), &(ea->nh));
 
   return 1;
 }