]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_zlookup.c
Merge remote-tracking branch 'origin/master' into pim_lib_work2
[mirror_frr.git] / pimd / pim_zlookup.c
index f6490980609e4329aa455c2367d7f6f0fbf5e07f..61e3e27261fa438b5543f70dfcea149fb9edd3bd 100644 (file)
@@ -16,7 +16,6 @@
   along with this program; see the file COPYING; if not, write to the
   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
   MA 02110-1301 USA
-  
 */
 
 #include <zebra.h>
@@ -38,8 +37,6 @@
 #include "pim_oil.h"
 #include "pim_zlookup.h"
 
-extern int zclient_debug;
-
 static struct zclient *zlookup = NULL;
 
 static void zclient_lookup_sched(struct zclient *zlookup, int delay);
@@ -164,8 +161,8 @@ static int zclient_read_nexthop(struct zclient *zlookup,
   int nexthop_num;
   int i, err;
 
-  if (PIM_DEBUG_ZEBRA) {
-    char addr_str[100];
+  if (PIM_DEBUG_PIM_TRACE_DETAIL) {
+    char addr_str[INET_ADDRSTRLEN];
     pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
     zlog_debug("%s: addr=%s", 
               __PRETTY_FUNCTION__,
@@ -197,8 +194,8 @@ static int zclient_read_nexthop(struct zclient *zlookup,
   raddr.s_addr = stream_get_ipv4(s);
 
   if (raddr.s_addr != addr.s_addr) {
-    char addr_str[100];
-    char raddr_str[100];
+    char addr_str[INET_ADDRSTRLEN];
+    char raddr_str[INET_ADDRSTRLEN];
     pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
     pim_inet4_dump("<raddr?>", raddr, raddr_str, sizeof(raddr_str));
     zlog_warn("%s: address mismatch: addr=%s raddr=%s", 
@@ -223,7 +220,7 @@ static int zclient_read_nexthop(struct zclient *zlookup,
 
     nexthop_type = stream_getc(s);
     if (num_ifindex >= tab_size) {
-      char addr_str[100];
+      char addr_str[INET_ADDRSTRLEN];
       pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
       zlog_warn("%s %s: found too many nexthop ifindexes (%d > %d) for address %s",
                __FILE__, __PRETTY_FUNCTION__,
@@ -233,8 +230,10 @@ static int zclient_read_nexthop(struct zclient *zlookup,
     switch (nexthop_type) {
     case NEXTHOP_TYPE_IFINDEX:
     case NEXTHOP_TYPE_IPV4_IFINDEX:
+    case NEXTHOP_TYPE_IPV4:
       nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET;
-      if (nexthop_type == NEXTHOP_TYPE_IPV4_IFINDEX) {
+      if (nexthop_type == NEXTHOP_TYPE_IPV4_IFINDEX ||
+         nexthop_type == NEXTHOP_TYPE_IPV4) {
        nexthop_tab[num_ifindex].nexthop_addr.u.prefix4.s_addr = stream_get_ipv4(s);
       }
       else {
@@ -245,23 +244,6 @@ static int zclient_read_nexthop(struct zclient *zlookup,
       nexthop_tab[num_ifindex].route_metric      = metric;
       ++num_ifindex;
       break;
-    case NEXTHOP_TYPE_IPV4:
-      nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET;
-      nexthop_tab[num_ifindex].nexthop_addr.u.prefix4.s_addr = stream_get_ipv4(s);
-      nexthop_tab[num_ifindex].ifindex             = 0;
-      nexthop_tab[num_ifindex].protocol_distance   = distance;
-      nexthop_tab[num_ifindex].route_metric        = metric;
-      if (PIM_DEBUG_ZEBRA) {
-       char addr_str[100];
-       char nexthop_str[100];
-       pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
-       pim_addr_dump("<nexthop?>", &nexthop_tab[num_ifindex].nexthop_addr, nexthop_str, sizeof(nexthop_str));
-       zlog_debug("%s %s: zebra returned recursive nexthop %s for address %s",
-                  __FILE__, __PRETTY_FUNCTION__,
-                  nexthop_str, addr_str);
-      }
-      ++num_ifindex;
-      break;
     case NEXTHOP_TYPE_IPV6_IFINDEX:
       nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET6;
       stream_get (&nexthop_tab[num_ifindex].nexthop_addr.u.prefix6, s, 16);
@@ -277,7 +259,7 @@ static int zclient_read_nexthop(struct zclient *zlookup,
     default:
       /* do nothing */
       {
-       char addr_str[100];
+       char addr_str[INET_ADDRSTRLEN];
        pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
        zlog_warn("%s %s: found non-ifindex nexthop type=%d for address %s",
                 __FILE__, __PRETTY_FUNCTION__,
@@ -298,8 +280,8 @@ zclient_lookup_nexthop_once (struct pim_zlookup_nexthop nexthop_tab[],
   struct stream *s;
   int ret;
 
-  if (PIM_DEBUG_ZEBRA) {
-    char addr_str[100];
+  if (PIM_DEBUG_PIM_TRACE_DETAIL) {
+    char addr_str[INET_ADDRSTRLEN];
     pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
     zlog_debug("%s: addr=%s", 
               __PRETTY_FUNCTION__,
@@ -322,8 +304,8 @@ zclient_lookup_nexthop_once (struct pim_zlookup_nexthop nexthop_tab[],
   
   ret = writen(zlookup->sock, s->data, stream_get_endp(s));
   if (ret < 0) {
-    zlog_err("%s %s: writen() failure writing to zclient lookup socket",
-            __FILE__, __PRETTY_FUNCTION__);
+    zlog_err("%s %s: writen() failure: %d writing to zclient lookup socket",
+            __FILE__, __PRETTY_FUNCTION__, errno);
     zclient_lookup_failed(zlookup);
     return -2;
   }
@@ -359,7 +341,7 @@ zclient_lookup_nexthop (struct pim_zlookup_nexthop nexthop_tab[],
                                              tab_size, addr);
     if (num_ifindex < 1) {
       if (PIM_DEBUG_ZEBRA) {
-       char addr_str[100];
+       char addr_str[INET_ADDRSTRLEN];
        pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
        zlog_debug("%s %s: lookup=%d/%d: could not find nexthop ifindex for address %s",
                   __FILE__, __PRETTY_FUNCTION__,
@@ -375,9 +357,13 @@ zclient_lookup_nexthop (struct pim_zlookup_nexthop nexthop_tab[],
     }
     
     /*
-      FIXME: Non-recursive nexthop ensured only for first ifindex.
-      However, recursive route lookup should really be fixed in zebra daemon.
-      See also TODO T24.
+     * FIXME: Non-recursive nexthop ensured only for first ifindex.
+     * However, recursive route lookup should really be fixed in zebra daemon.
+     * See also TODO T24.
+     *
+     * So Zebra for NEXTHOP_TYPE_IPV4 returns the ifindex now since
+     * it was being stored.  This Doesn't solve all cases of
+     * recursive lookup but for the most common types it does.
      */
     first_ifindex = nexthop_tab[0].ifindex;
     nexthop_addr = nexthop_tab[0].nexthop_addr;
@@ -387,7 +373,7 @@ zclient_lookup_nexthop (struct pim_zlookup_nexthop nexthop_tab[],
       if (lookup > 0) {
        /* Report non-recursive success after first lookup */
        if (PIM_DEBUG_ZEBRA) {
-         char addr_str[100];
+         char addr_str[INET_ADDRSTRLEN];
          pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
          zlog_debug("%s %s: lookup=%d/%d: found non-recursive ifindex=%d for address %s dist=%d met=%d",
                     __FILE__, __PRETTY_FUNCTION__,
@@ -408,8 +394,8 @@ zclient_lookup_nexthop (struct pim_zlookup_nexthop nexthop_tab[],
     }
 
     if (PIM_DEBUG_ZEBRA) {
-      char addr_str[100];
-      char nexthop_str[100];
+      char addr_str[INET_ADDRSTRLEN];
+      char nexthop_str[PREFIX_STRLEN];
       pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
       pim_addr_dump("<nexthop?>", &nexthop_addr, nexthop_str, sizeof(nexthop_str));
       zlog_debug("%s %s: lookup=%d/%d: zebra returned recursive nexthop %s for address %s dist=%d met=%d",
@@ -424,7 +410,7 @@ zclient_lookup_nexthop (struct pim_zlookup_nexthop nexthop_tab[],
   } /* for (max_lookup) */
 
   if (PIM_DEBUG_ZEBRA) {
-    char addr_str[100];
+    char addr_str[INET_ADDRSTRLEN];
     pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
     zlog_warn("%s %s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %s",
              __FILE__, __PRETTY_FUNCTION__,
@@ -459,7 +445,16 @@ pim_zlookup_sg_statistics (struct channel_oil *c_oil)
   struct interface *ifp = pim_if_find_by_vif_index (c_oil->oil.mfcc_parent);
 
   if (PIM_DEBUG_ZEBRA)
-    zlog_debug ("Sending Request for New Channel Oil Information");
+    {
+      struct prefix_sg more;
+
+      more.src = c_oil->oil.mfcc_origin;
+      more.grp = c_oil->oil.mfcc_mcastgrp;
+      zlog_debug ("Sending Request for New Channel Oil Information(%s)", pim_str_sg_dump (&more));
+    }
+
+  if (!ifp)
+    return -1;
 
   stream_reset (s);
   zclient_create_header (s, ZEBRA_IPMR_ROUTE_STATS, VRF_DEFAULT);
@@ -472,8 +467,8 @@ pim_zlookup_sg_statistics (struct channel_oil *c_oil)
   ret = writen (zlookup->sock, s->data, count);
   if (ret <= 0)
     {
-      zlog_err("%s %s: writen() failure writing to zclient lookup socket",
-               __FILE__, __PRETTY_FUNCTION__);
+      zlog_err("%s %s: writen() failure: %d writing to zclient lookup socket",
+               __FILE__, __PRETTY_FUNCTION__, errno);
       return -1;
     }
 
@@ -511,9 +506,10 @@ pim_zlookup_sg_statistics (struct channel_oil *c_oil)
     }
 
   stream_get (&lastused, s, sizeof (lastused));
+  ret = stream_getl (s);
 
   if (PIM_DEBUG_ZEBRA)
-    zlog_debug ("Received %lld for %s", lastused, pim_str_sg_dump (&sg));
+    zlog_debug ("Received %lld for %s success: %d", lastused, pim_str_sg_dump (&sg), ret);
 
   c_oil->cc.lastused = lastused;