zebra: use prefix2str for logging where possible

This makes code more robust, consice and readable.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/zebra/interface.c b/zebra/interface.c
index 54d8b10..80eb6aa 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -1593,10 +1593,9 @@
 	      {
 		char buf[INET6_ADDRSTRLEN];
 		p = ifc->address;
-		vty_out (vty, " ip%s address %s/%d",
+		vty_out (vty, " ip%s address %s",
 			 p->family == AF_INET ? "" : "v6",
-			 inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)),
-			 p->prefixlen);
+			 prefix2str (p, buf, sizeof(buf)));
 
 		if (ifc->label)
 		  vty_out (vty, " label %s", ifc->label);
diff --git a/zebra/ioctl_solaris.c b/zebra/ioctl_solaris.c
index 6c1c254..16934f0 100644
--- a/zebra/ioctl_solaris.c
+++ b/zebra/ioctl_solaris.c
@@ -407,11 +407,11 @@
 int
 if_prefix_add_ipv6 (struct interface *ifp, struct connected *ifc)
 {
-  char addrbuf[INET_ADDRSTRLEN];
+  char addrbuf[PREFIX_STRLEN];
 
-  inet_ntop (AF_INET6, &(((struct prefix_ipv6 *) (ifc->address))->prefix),
-             addrbuf, sizeof (addrbuf));
-  zlog_warn ("Can't set %s on interface %s", addrbuf, ifp->name);
+  zlog_warn ("Can't set %s on interface %s",
+             prefix2str(ifc->address->prefix, addrbuf, sizeof(addrbuf)),
+             ifp->name);
 
   return 0;
 
@@ -420,11 +420,11 @@
 int
 if_prefix_delete_ipv6 (struct interface *ifp, struct connected *ifc)
 {
-  char addrbuf[INET_ADDRSTRLEN];
+  char addrbuf[PREFIX_STRLEN];
 
-  inet_ntop (AF_INET6, &(((struct prefix_ipv6 *) (ifc->address))->prefix),
-             addrbuf, sizeof (addrbuf));
-  zlog_warn ("Can't delete %s on interface %s", addrbuf, ifp->name);
+  zlog_warn ("Can't delete %s on interface %s",
+             prefix2str(ifc->address->prefix, addrbuf, sizeof(addrbuf)),
+             ifp->name);
 
   return 0;
 
diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c
index c297979..cf78a54 100644
--- a/zebra/irdp_main.c
+++ b/zebra/irdp_main.c
@@ -180,6 +180,7 @@
 {
   struct zebra_if *zi=ifp->info;
   struct irdp_interface *irdp=&zi->irdp;
+  char buf[PREFIX_STRLEN];
   u_int32_t dst;
   u_int32_t ttl=1;
 
@@ -191,10 +192,9 @@
     dst = htonl(INADDR_ALLHOSTS_GROUP);
 
   if(irdp->flags & IF_DEBUG_MESSAGES) 
-    zlog_debug("IRDP: TX Advert on %s %s/%d Holdtime=%d Preference=%d", 
+    zlog_debug("IRDP: TX Advert on %s %s Holdtime=%d Preference=%d",
 	      ifp->name,
-	      inet_ntoa(p->u.prefix4), 
-	      p->prefixlen,
+	      prefix2str(p, buf, sizeof buf),
 	      irdp->flags & IF_SHUTDOWN? 0 : irdp->Lifetime,
 	      get_pref(irdp, p));
 
diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c
index 916dad9..fefccdc 100644
--- a/zebra/kernel_socket.c
+++ b/zebra/kernel_socket.c
@@ -631,50 +631,32 @@
 
   if (IS_ZEBRA_DEBUG_KERNEL)
     {
-      switch (sockunion_family(addr))
+      int family = sockunion_family(addr);
+      switch (family)
         {
 	case AF_INET:
+#ifdef HAVE_IPV6
+	case AF_INET6:
+#endif
 	  {
-	    char buf[4][INET_ADDRSTRLEN];
+	    char buf[4][INET6_ADDRSTRLEN];
 	    zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, "
 			"ifam_flags 0x%x, addr %s/%d broad %s dst %s "
 			"gateway %s",
 			__func__, ifm->ifam_index,
 			(ifnlen ? ifname : "(nil)"), ifm->ifam_addrs,
 			ifm->ifam_flags,
-			inet_ntop(AF_INET,&addr->sin.sin_addr,
+			inet_ntop(family,&addr->sin.sin_addr,
 			          buf[0],sizeof(buf[0])),
 			ip_masklen(mask->sin.sin_addr),
-			inet_ntop(AF_INET,&brd->sin.sin_addr,
+			inet_ntop(family,&brd->sin.sin_addr,
 			          buf[1],sizeof(buf[1])),
-			inet_ntop(AF_INET,&dst.sin.sin_addr,
+			inet_ntop(family,&dst.sin.sin_addr,
 			          buf[2],sizeof(buf[2])),
-			inet_ntop(AF_INET,&gateway.sin.sin_addr,
+			inet_ntop(family,&gateway.sin.sin_addr,
 			          buf[3],sizeof(buf[3])));
 	  }
 	  break;
-#ifdef HAVE_IPV6
-	case AF_INET6:
-	  {
-	    char buf[4][INET6_ADDRSTRLEN];
-	    zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x, "
-			"ifam_flags 0x%x, addr %s/%d broad %s dst %s "
-			"gateway %s",
-			__func__, ifm->ifam_index, 
-			(ifnlen ? ifname : "(nil)"), ifm->ifam_addrs,
-			ifm->ifam_flags,
-			inet_ntop(AF_INET6,&addr->sin6.sin6_addr,
-			          buf[0],sizeof(buf[0])),
-			ip6_masklen(mask->sin6.sin6_addr),
-			inet_ntop(AF_INET6,&brd->sin6.sin6_addr,
-			          buf[1],sizeof(buf[1])),
-			inet_ntop(AF_INET6,&dst.sin6.sin6_addr,
-			          buf[2],sizeof(buf[2])),
-			inet_ntop(AF_INET6,&gateway.sin6.sin6_addr,
-			          buf[3],sizeof(buf[3])));
-	  }
-	  break;
-#endif /* HAVE_IPV6 */
         default:
 	  zlog_debug ("%s: ifindex %d, ifname %s, ifam_addrs 0x%x",
 		      __func__, ifm->ifam_index, 
@@ -904,12 +886,12 @@
        */
       if (rtm->rtm_type != RTM_GET && rtm->rtm_pid == pid)
       {
-        char buf[INET_ADDRSTRLEN], gate_buf[INET_ADDRSTRLEN];
+        char buf[PREFIX_STRLEN], gate_buf[INET_ADDRSTRLEN];
         int ret;
         if (! IS_ZEBRA_DEBUG_RIB)
           return;
         ret = rib_lookup_ipv4_route (&p, &gate); 
-        inet_ntop (AF_INET, &p.prefix, buf, INET_ADDRSTRLEN);
+        prefix2str (&p, buf, sizeof(buf));
         switch (rtm->rtm_type)
         {
           case RTM_ADD:
@@ -920,18 +902,18 @@
             switch (ret)
             {
               case ZEBRA_RIB_NOTFOUND:
-                zlog_debug ("%s: %s %s/%d: desync: RR isn't yet in RIB, while already in FIB",
-                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
+                zlog_debug ("%s: %s %s: desync: RR isn't yet in RIB, while already in FIB",
+                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf);
                 break;
               case ZEBRA_RIB_FOUND_CONNECTED:
               case ZEBRA_RIB_FOUND_NOGATE:
                 inet_ntop (AF_INET, &gate.sin.sin_addr, gate_buf, INET_ADDRSTRLEN);
-                zlog_debug ("%s: %s %s/%d: desync: RR is in RIB, but gate differs (ours is %s)",
-                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen, gate_buf);
+                zlog_debug ("%s: %s %s: desync: RR is in RIB, but gate differs (ours is %s)",
+                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf, gate_buf);
                 break;
               case ZEBRA_RIB_FOUND_EXACT: /* RIB RR == FIB RR */
-                zlog_debug ("%s: %s %s/%d: done Ok",
-                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
+                zlog_debug ("%s: %s %s: done Ok",
+                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf);
                 rib_lookup_and_dump (&p);
                 return;
                 break;
@@ -943,27 +925,27 @@
             switch (ret)
             {
               case ZEBRA_RIB_FOUND_EXACT:
-                zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, while already not in FIB",
-                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
+                zlog_debug ("%s: %s %s: desync: RR is still in RIB, while already not in FIB",
+                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf);
                 rib_lookup_and_dump (&p);
                 break;
               case ZEBRA_RIB_FOUND_CONNECTED:
               case ZEBRA_RIB_FOUND_NOGATE:
-                zlog_debug ("%s: %s %s/%d: desync: RR is still in RIB, plus gate differs",
-                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
+                zlog_debug ("%s: %s %s: desync: RR is still in RIB, plus gate differs",
+                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf);
                 rib_lookup_and_dump (&p);
                 break;
               case ZEBRA_RIB_NOTFOUND: /* RIB RR == FIB RR */
-                zlog_debug ("%s: %s %s/%d: done Ok",
-                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf, p.prefixlen);
+                zlog_debug ("%s: %s %s: done Ok",
+                  __func__, lookup (rtm_type_str, rtm->rtm_type), buf);
                 rib_lookup_and_dump (&p);
                 return;
                 break;
             }
             break;
           default:
-            zlog_debug ("%s: %s/%d: warning: loopback RTM of type %s received",
-              __func__, buf, p.prefixlen, lookup (rtm_type_str, rtm->rtm_type));
+            zlog_debug ("%s: %s: warning: loopback RTM of type %s received",
+              __func__, buf, lookup (rtm_type_str, rtm->rtm_type));
         }
         return;
       }
diff --git a/zebra/redistribute.c b/zebra/redistribute.c
index 8d5b4ca..94330ae 100644
--- a/zebra/redistribute.c
+++ b/zebra/redistribute.c
@@ -326,12 +326,12 @@
 
   if (IS_ZEBRA_DEBUG_EVENT)
     {
-      char buf[INET6_ADDRSTRLEN];
+      char buf[PREFIX_STRLEN];
 
       p = ifc->address;
-      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s/%d on %s",
-		  inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN),
-		  p->prefixlen, ifc->ifp->name);
+      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s",
+		  prefix2str (p, buf, sizeof(buf)),
+		  ifc->ifp->name);
     }
 
   if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
@@ -355,12 +355,12 @@
 
   if (IS_ZEBRA_DEBUG_EVENT)
     {
-      char buf[INET6_ADDRSTRLEN];
+      char buf[PREFIX_STRLEN];
 
       p = ifc->address;
-      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s/%d on %s",
-		  inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN),
-		 p->prefixlen, ifc->ifp->name);
+      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s",
+		  prefix2str (p, buf, sizeof(buf)),
+		  ifc->ifp->name);
     }
 
   router_id_del_address(ifc);
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 7e41072..45ebf20 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -933,12 +933,10 @@
 
       if (IS_ZEBRA_DEBUG_KERNEL)
         {
-          if (h->nlmsg_type == RTM_NEWROUTE)
-            zlog_debug ("RTM_NEWROUTE %s/%d",
-                       inet_ntoa (p.prefix), p.prefixlen);
-          else
-            zlog_debug ("RTM_DELROUTE %s/%d",
-                       inet_ntoa (p.prefix), p.prefixlen);
+          char buf[PREFIX_STRLEN];
+          zlog_debug ("%s %s",
+                      h->nlmsg_type == RTM_NEWROUTE ? "RTM_NEWROUTE" : "RTM_DELROUTE",
+                      prefix2str (&p, buf, sizeof(buf)));
         }
 
       if (h->nlmsg_type == RTM_NEWROUTE)
@@ -1010,7 +1008,6 @@
   if (rtm->rtm_family == AF_INET6)
     {
       struct prefix_ipv6 p;
-      char buf[BUFSIZ];
 
       p.family = AF_INET6;
       memcpy (&p.prefix, dest, 16);
@@ -1018,14 +1015,10 @@
 
       if (IS_ZEBRA_DEBUG_KERNEL)
         {
-          if (h->nlmsg_type == RTM_NEWROUTE)
-            zlog_debug ("RTM_NEWROUTE %s/%d",
-                       inet_ntop (AF_INET6, &p.prefix, buf, BUFSIZ),
-                       p.prefixlen);
-          else
-            zlog_debug ("RTM_DELROUTE %s/%d",
-                       inet_ntop (AF_INET6, &p.prefix, buf, BUFSIZ),
-                       p.prefixlen);
+          char buf[PREFIX_STRLEN];
+          zlog_debug ("%s %s",
+                      h->nlmsg_type == RTM_NEWROUTE ? "RTM_NEWROUTE" : "RTM_DELROUTE",
+                      prefix2str (&p, buf, sizeof(buf)));
         }
 
       if (h->nlmsg_type == RTM_NEWROUTE)
@@ -1563,16 +1556,12 @@
 {
   if (IS_ZEBRA_DEBUG_KERNEL)
     {
-      zlog_debug ("netlink_route_multipath() (%s): %s %s/%d type %s",
+      char buf[PREFIX_STRLEN];
+      zlog_debug ("netlink_route_multipath() (%s): %s %s type %s",
          routedesc,
          lookup (nlmsg_str, cmd),
-#ifdef HAVE_IPV6
-         (family == AF_INET) ? inet_ntoa (p->u.prefix4) :
-         inet6_ntoa (p->u.prefix6),
-#else
-         inet_ntoa (p->u.prefix4),
-#endif /* HAVE_IPV6 */
-         p->prefixlen, nexthop_type_to_str (nexthop->type));
+         prefix2str (p, buf, sizeof(buf)),
+         nexthop_type_to_str (nexthop->type));
     }
 }
 
diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c
index d8c947c..bf21ca9 100644
--- a/zebra/rt_socket.c
+++ b/zebra/rt_socket.c
@@ -77,10 +77,10 @@
   unsigned int ifindex = 0;
   int gate = 0;
   int error;
-  char prefix_buf[INET_ADDRSTRLEN];
+  char prefix_buf[PREFIX_STRLEN];
 
   if (IS_ZEBRA_DEBUG_RIB)
-    inet_ntop (AF_INET, &p->u.prefix, prefix_buf, INET_ADDRSTRLEN);
+    prefix2str (p, prefix_buf, sizeof(prefix_buf));
   memset (&sin_dest, 0, sizeof (struct sockaddr_in));
   sin_dest.sin_family = AF_INET;
 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
@@ -158,8 +158,8 @@
            {
              if (!gate)
              {
-               zlog_debug ("%s: %s/%d: attention! gate not found for rib %p",
-                 __func__, prefix_buf, p->prefixlen, rib);
+               zlog_debug ("%s: %s: attention! gate not found for rib %p",
+                 __func__, prefix_buf, rib);
                rib_dump (p, rib);
              }
              else
@@ -172,8 +172,8 @@
              case ZEBRA_ERR_NOERROR:
                nexthop_num++;
                if (IS_ZEBRA_DEBUG_RIB)
-                 zlog_debug ("%s: %s/%d: successfully did NH %s",
-                   __func__, prefix_buf, p->prefixlen, gate_buf);
+                 zlog_debug ("%s: %s: successfully did NH %s",
+                   __func__, prefix_buf, gate_buf);
                if (cmd == RTM_ADD)
                  SET_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB);
                break;
@@ -195,11 +195,9 @@
              case ZEBRA_ERR_RTNOEXIST:
              case ZEBRA_ERR_RTUNREACH:
              default:
-               /* This point is reachable regardless of debugging mode. */
-               if (!IS_ZEBRA_DEBUG_RIB)
-                 inet_ntop (AF_INET, &p->u.prefix, prefix_buf, INET_ADDRSTRLEN);
-               zlog_err ("%s: %s/%d: rtm_write() unexpectedly returned %d for command %s",
-                 __func__, prefix_buf, p->prefixlen, error, lookup (rtm_type_str, cmd));
+               zlog_err ("%s: %s: rtm_write() unexpectedly returned %d for command %s",
+                 __func__, prefix2str(p, prefix_buf, sizeof(prefix_buf)),
+                 error, lookup (rtm_type_str, cmd));
                break;
            }
          } /* if (cmd and flags make sense) */
diff --git a/zebra/rtadv.c b/zebra/rtadv.c
index 9a3fd26..b395982 100644
--- a/zebra/rtadv.c
+++ b/zebra/rtadv.c
@@ -1537,7 +1537,7 @@
   struct zebra_if *zif;
   struct listnode *node;
   struct rtadv_prefix *rprefix;
-  u_char buf[INET6_ADDRSTRLEN];
+  char buf[PREFIX_STRLEN];
   int interval;
 
   if (! rtadv)
@@ -1601,10 +1601,8 @@
 
   for (ALL_LIST_ELEMENTS_RO (zif->rtadv.AdvPrefixList, node, rprefix))
     {
-      vty_out (vty, " ipv6 nd prefix %s/%d",
-	       inet_ntop (AF_INET6, &rprefix->prefix.prefix,
-			  (char *) buf, INET6_ADDRSTRLEN),
-	       rprefix->prefix.prefixlen);
+      vty_out (vty, " ipv6 nd prefix %s",
+               prefix2str (&rprefix->prefix, buf, sizeof(buf)));
       if ((rprefix->AdvValidLifetime != RTADV_VALID_LIFETIME) || 
 	  (rprefix->AdvPreferredLifetime != RTADV_PREFERRED_LIFETIME))
 	{
diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c
index e02d174..896915c 100644
--- a/zebra/zebra_fpm.c
+++ b/zebra/zebra_fpm.c
@@ -1301,7 +1301,7 @@
 zfpm_trigger_update (struct route_node *rn, const char *reason)
 {
   rib_dest_t *dest;
-  char buf[INET6_ADDRSTRLEN];
+  char buf[PREFIX_STRLEN];
 
   /*
    * Ignore if the connection is down. We will update the FPM about
@@ -1329,9 +1329,8 @@
 
   if (reason)
     {
-      zfpm_debug ("%s/%d triggering update to FPM - Reason: %s",
-		  inet_ntop (rn->p.family, &rn->p.u.prefix, buf, sizeof (buf)),
-		  rn->p.prefixlen, reason);
+      zfpm_debug ("%s triggering update to FPM - Reason: %s",
+		  prefix2str (&rn->p, buf, sizeof(buf)), reason);
     }
 
   SET_FLAG (dest->flags, RIB_DEST_UPDATE_FPM);
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index cc7f48f..f247f1d 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -82,7 +82,7 @@
 _rnode_zlog(const char *_func, struct route_node *rn, int priority,
 	    const char *msgfmt, ...)
 {
-  char buf[INET6_ADDRSTRLEN + 4], *bptr;
+  char buf[PREFIX_STRLEN + 8];
   char msgbuf[512];
   va_list ap;
 
@@ -94,10 +94,9 @@
     {
       rib_table_info_t *info = rn->table->info;
 
-      inet_ntop (rn->p.family, &rn->p.u.prefix, buf, INET6_ADDRSTRLEN);
-      bptr = buf + strlen(buf);
-      snprintf(bptr, buf + sizeof(buf) - bptr, "/%d%s", rn->p.prefixlen,
-               info->safi == SAFI_MULTICAST ? " (MRIB)" : "");
+      prefix2str(&rn->p, buf, sizeof(buf));
+      if (info->safi == SAFI_MULTICAST)
+        strcat(buf, " (MRIB)");
     }
   else
     {
@@ -2010,13 +2009,12 @@
 		union prefix46constptr pp, const struct rib * rib)
 {
   const struct prefix *p = pp.p;
-  char straddr[INET6_ADDRSTRLEN];
+  char straddr[PREFIX_STRLEN];
   struct nexthop *nexthop, *tnexthop;
   int recursing;
 
-  inet_ntop (p->family, &p->u.prefix, straddr, INET6_ADDRSTRLEN);
-  zlog_debug ("%s: dumping RIB entry %p for %s/%d", func, (void *)rib,
-              straddr, p->prefixlen);
+  zlog_debug ("%s: dumping RIB entry %p for %s", func, (void *)rib,
+              prefix2str(p, straddr, sizeof(straddr)));
   zlog_debug
   (
     "%s: refcnt == %lu, uptime == %lu, type == %u, table == %d",
@@ -2080,14 +2078,14 @@
     return;
   }
 
-  inet_ntop (AF_INET, &p->prefix.s_addr, prefix_buf, INET_ADDRSTRLEN);
   /* Scan the RIB table for exactly matching RIB entry. */
   rn = route_node_lookup (table, (struct prefix *) p);
 
   /* No route for this prefix. */
   if (! rn)
   {
-    zlog_debug ("%s: lookup failed for %s/%d", __func__, prefix_buf, p->prefixlen);
+    zlog_debug ("%s: lookup failed for %s", __func__,
+                prefix2str((struct prefix*) p, prefix_buf, sizeof(prefix_buf)));
     return;
   }
 
@@ -2150,9 +2148,9 @@
       changed = 1;
       if (IS_ZEBRA_DEBUG_RIB)
       {
-        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);
+        char buf[PREFIX_STRLEN];
+        zlog_debug ("%s: freeing way for connected prefix %s", __func__,
+                    prefix2str(&rn->p, buf, sizeof(buf)));
         rib_dump (&rn->p, rib);
       }
       rib_uninstall (rn, rib);
@@ -2246,7 +2244,7 @@
   struct rib *same = NULL;
   struct nexthop *nexthop, *tnexthop;
   int recursing;
-  char buf1[INET_ADDRSTRLEN];
+  char buf1[PREFIX_STRLEN];
   char buf2[INET_ADDRSTRLEN];
 
   /* Lookup table.  */
@@ -2260,15 +2258,13 @@
   if (IS_ZEBRA_DEBUG_KERNEL)
     {
       if (gate)
-	zlog_debug ("rib_delete_ipv4(): route delete %s/%d via %s ifindex %d",
-		    inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-		    p->prefixlen,
+	zlog_debug ("rib_delete_ipv4(): route delete %s via %s ifindex %d",
+		    prefix2str (p, buf1, sizeof(buf1)),
 		    inet_ntoa (*gate),
 		    ifindex);
       else
-	zlog_debug ("rib_delete_ipv4(): route delete %s/%d ifindex %d",
-		    inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-		    p->prefixlen,
+	zlog_debug ("rib_delete_ipv4(): route delete %s ifindex %d",
+		    prefix2str (p, buf1, sizeof(buf1)),
 		    ifindex);
     }
 
@@ -2279,15 +2275,13 @@
       if (IS_ZEBRA_DEBUG_KERNEL)
 	{
 	  if (gate)
-	    zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib",
-		       inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-		       p->prefixlen,
+	    zlog_debug ("route %s via %s ifindex %d doesn't exist in rib",
+		       prefix2str (p, buf1, sizeof(buf1)),
 		       inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN),
 		       ifindex);
 	  else
-	    zlog_debug ("route %s/%d ifindex %d doesn't exist in rib",
-		       inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-		       p->prefixlen,
+	    zlog_debug ("route %s ifindex %d doesn't exist in rib",
+		       prefix2str (p, buf1, sizeof(buf1)),
 		       ifindex);
 	}
       return ZEBRA_ERR_RTNOEXIST;
@@ -2354,16 +2348,14 @@
 	  if (IS_ZEBRA_DEBUG_KERNEL)
 	    {
 	      if (gate)
-		zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
-			   inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-			   p->prefixlen,
+		zlog_debug ("route %s via %s ifindex %d type %d doesn't exist in rib",
+			   prefix2str (p, buf1, sizeof(buf1)),
 			   inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN),
 			   ifindex,
 			   type);
 	      else
-		zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib",
-			   inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-			   p->prefixlen,
+		zlog_debug ("route %s ifindex %d type %d doesn't exist in rib",
+			   prefix2str (p, buf1, sizeof(buf1)),
 			   ifindex,
 			   type);
 	    }
@@ -2807,7 +2799,7 @@
   struct rib *same = NULL;
   struct nexthop *nexthop, *tnexthop;
   int recursing;
-  char buf1[INET6_ADDRSTRLEN];
+  char buf1[PREFIX_STRLEN];
   char buf2[INET6_ADDRSTRLEN];
 
   /* Apply mask. */
@@ -2825,15 +2817,13 @@
       if (IS_ZEBRA_DEBUG_KERNEL)
 	{
 	  if (gate)
-	    zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib",
-		       inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-		       p->prefixlen,
+	    zlog_debug ("route %s via %s ifindex %d doesn't exist in rib",
+		       prefix2str (p, buf1, sizeof(buf1)),
 		       inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN),
 		       ifindex);
 	  else
-	    zlog_debug ("route %s/%d ifindex %d doesn't exist in rib",
-		       inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-		       p->prefixlen,
+	    zlog_debug ("route %s ifindex %d doesn't exist in rib",
+		       prefix2str (p, buf1, sizeof(buf1)),
 		       ifindex);
 	}
       return ZEBRA_ERR_RTNOEXIST;
@@ -2901,16 +2891,14 @@
 	  if (IS_ZEBRA_DEBUG_KERNEL)
 	    {
 	      if (gate)
-		zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
-			   inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-			   p->prefixlen,
+		zlog_debug ("route %s via %s ifindex %d type %d doesn't exist in rib",
+			   prefix2str (p, buf1, sizeof(buf1)),
 			   inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN),
 			   ifindex,
 			   type);
 	      else
-		zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib",
-			   inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-			   p->prefixlen,
+		zlog_debug ("route %s ifindex %d type %d doesn't exist in rib",
+			   prefix2str (p, buf1, sizeof(buf1)),
 			   ifindex,
 			   type);
 	    }