[quagga-dev 10825] [PATCH] zebra: apply syntactic sugar to rib_dump()

David Lamparter equinox at opensourcerouting.org
Tue Oct 22 19:10:21 BST 2013


strip the explicit __func__ present on all calls and make the prefix
argument a transparent union.

Signed-off-by: David Lamparter <equinox at opensourcerouting.org>
---

Parent patch of this applied with changes (--disable-ipv6 was broken +
adapted to apply after recursive route rework)

This patch queued as followup.

The remainder of the IPv6 ECMP patches is still giving me a headache.
I finally added readback/sync of kernel ECMP routes to zebra, but had to
fiddle with some of zebra's RIB for that.  Not satisfied with the result
yet.

 -David

---
 lib/prefix.h      | 19 +++++++++++++++++++
 zebra/rib.h       |  4 +++-
 zebra/rt_socket.c |  2 +-
 zebra/zebra_rib.c | 16 +++++++++-------
 4 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/lib/prefix.h b/lib/prefix.h
index 7f0d360..6df4fc5 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -89,6 +89,25 @@ struct prefix_rd
   u_char val[8] __attribute__ ((aligned (8)));
 };
 
+/* helper to get type safety/avoid casts on calls
+ * (w/o this, functions accepting all prefix types need casts on the caller
+ * side, which strips type safety since the cast will accept any pointer
+ * type.)
+ */
+union prefix46ptr
+{
+  struct prefix *p;
+  struct prefix_ipv4 *p4;
+  struct prefix_ipv6 *p6;
+} __attribute__ ((transparent_union));
+
+union prefix46constptr
+{
+  const struct prefix *p;
+  const struct prefix_ipv4 *p4;
+  const struct prefix_ipv6 *p6;
+} __attribute__ ((transparent_union));
+
 #ifndef INET_ADDRSTRLEN
 #define INET_ADDRSTRLEN 16
 #endif /* INET_ADDRSTRLEN */
diff --git a/zebra/rib.h b/zebra/rib.h
index 97a20af..d3a83c6 100644
--- a/zebra/rib.h
+++ b/zebra/rib.h
@@ -386,7 +386,9 @@ extern struct nexthop *nexthop_ipv4_ifindex_add (struct rib *,
 extern int nexthop_has_fib_child(struct nexthop *);
 extern void rib_lookup_and_dump (struct prefix_ipv4 *);
 extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
-extern void rib_dump (const char *, const struct prefix *, const struct rib *);
+#define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
+extern void _rib_dump (const char *,
+		       union prefix46constptr, const struct rib *);
 extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *);
 #define ZEBRA_RIB_LOOKUP_ERROR -1
 #define ZEBRA_RIB_FOUND_EXACT 0
diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c
index 5d175d8..90ed73d 100644
--- a/zebra/rt_socket.c
+++ b/zebra/rt_socket.c
@@ -160,7 +160,7 @@ kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib, int family)
              {
                zlog_debug ("%s: %s/%d: attention! gate not found for rib %p",
                  __func__, prefix_buf, p->prefixlen, rib);
-               rib_dump (__func__, (struct prefix_ipv4 *)p, rib);
+               rib_dump (p, rib);
              }
              else
                inet_ntop (AF_INET, &sin_gate.sin_addr, gate_buf, INET_ADDRSTRLEN);
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 77c0d8c..ce79513 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -1912,8 +1912,10 @@ rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
  * question are passed as 1st and 2nd arguments.
  */
 
-void rib_dump (const char * func, const struct prefix * p, const struct rib * rib)
+void _rib_dump (const char * func,
+		union prefix46constptr pp, const struct rib * rib)
 {
+  const struct prefix *p = pp.p;
   char straddr[INET6_ADDRSTRLEN];
   struct nexthop *nexthop, *tnexthop;
   int recursing;
@@ -2009,7 +2011,7 @@ void rib_lookup_and_dump (struct prefix_ipv4 * p)
       (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED) ? "removed" : "NOT removed"),
       (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED) ? "selected" : "NOT selected")
     );
-    rib_dump (__func__, (struct prefix *) p, rib);
+    rib_dump (p, rib);
   }
 }
 
@@ -2056,7 +2058,7 @@ void rib_lookup_and_pushup (struct prefix_ipv4 * p)
         char buf[INET_ADDRSTRLEN];
         inet_ntop (rn->p.family, &p->prefix, buf, INET_ADDRSTRLEN);
         zlog_debug ("%s: freeing way for connected prefix %s/%d", __func__, buf, p->prefixlen);
-        rib_dump (__func__, &rn->p, rib);
+        rib_dump (&rn->p, rib);
       }
       rib_uninstall (rn, rib);
     }
@@ -2118,7 +2120,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi)
   {
     zlog_debug ("%s: called rib_addnode (%p, %p) on new RIB entry",
       __func__, rn, rib);
-    rib_dump (__func__, (struct prefix *) p, rib);
+    rib_dump (p, rib);
   }
 
   /* Free implicit route.*/
@@ -2128,7 +2130,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi)
     {
       zlog_debug ("%s: calling rib_delnode (%p, %p) on existing RIB entry",
         __func__, rn, same);
-      rib_dump (__func__, (struct prefix *) p, same);
+      rib_dump (p, same);
     }
     rib_delnode (rn, same);
   }
@@ -2698,7 +2700,7 @@ rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
   {
     zlog_debug ("%s: called rib_addnode (%p, %p) on new RIB entry",
       __func__, rn, rib);
-    rib_dump (__func__, (struct prefix *) p, rib);
+    rib_dump (p, rib);
   }
 
   /* Free implicit route.*/
@@ -2708,7 +2710,7 @@ rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
     {
       zlog_debug ("%s: calling rib_delnode (%p, %p) on existing RIB entry",
         __func__, rn, same);
-      rib_dump (__func__, (struct prefix *) p, same);
+      rib_dump (p, same);
     }
     rib_delnode (rn, same);
   }
-- 
1.8.1.5





More information about the Quagga-dev mailing list