]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_zlookup.c
Merge pull request #561 from donaldsharp/static_config2
[mirror_frr.git] / pimd / pim_zlookup.c
index 636552abd77297001c6ca9307b8db5022337ab48..9c26745e77b9ce09d55ee87b9940b515d5b18392 100644 (file)
@@ -1,23 +1,21 @@
 /*
-  PIM for Quagga
-  Copyright (C) 2008  Everton da Silva Marques
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  General Public License for more details.
-  
-  You should have received a copy of the GNU General Public License
-  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
-  
-*/
+ * PIM for Quagga
+ * Copyright (C) 2008  Everton da Silva Marques
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 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>
 #include "zebra/rib.h"
@@ -38,8 +36,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);
@@ -80,9 +76,8 @@ static void zclient_lookup_sched(struct zclient *zlookup, int delay)
 {
   zassert(!zlookup->t_connect);
 
-  THREAD_TIMER_ON(master, zlookup->t_connect,
-                 zclient_lookup_connect,
-                 zlookup, delay);
+  thread_add_timer(master, zclient_lookup_connect, zlookup, delay,
+                   &zlookup->t_connect);
 
   zlog_notice("%s: zclient lookup connection scheduled for %d seconds",
              __PRETTY_FUNCTION__, delay);
@@ -92,9 +87,8 @@ static void zclient_lookup_sched(struct zclient *zlookup, int delay)
 static void zclient_lookup_sched_now(struct zclient *zlookup)
 {
   zassert(!zlookup->t_connect);
-
-  zlookup->t_connect = thread_add_event(master, zclient_lookup_connect,
-                                       zlookup, 0);
+  thread_add_event(master, zclient_lookup_connect, zlookup, 0,
+                   &zlookup->t_connect);
 
   zlog_notice("%s: zclient lookup immediate connection scheduled",
              __PRETTY_FUNCTION__);
@@ -123,6 +117,13 @@ static void zclient_lookup_failed(struct zclient *zlookup)
   zclient_lookup_reconnect(zlookup);
 }
 
+void
+zclient_lookup_free (void)
+{
+  zclient_free (zlookup);
+  zlookup = NULL;
+}
+
 void
 zclient_lookup_new (void)
 {
@@ -134,9 +135,7 @@ zclient_lookup_new (void)
   }
 
   zlookup->sock = -1;
-  zlookup->ibuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
-  zlookup->obuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
-  zlookup->t_connect = 0;
+  zlookup->t_connect = NULL;
 
   zclient_lookup_sched_now(zlookup);
 
@@ -164,8 +163,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 +196,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", 
@@ -220,10 +219,11 @@ static int zclient_read_nexthop(struct zclient *zlookup,
   for (i = 0; i < nexthop_num; ++i) {
     enum nexthop_types_t nexthop_type;
     struct pim_neighbor *nbr;
+    struct prefix p;
 
     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__,
@@ -249,9 +249,24 @@ static int zclient_read_nexthop(struct zclient *zlookup,
       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);
+      stream_get (&nexthop_tab[num_ifindex].nexthop_addr.u.prefix6,
+                 s,
+                 sizeof(struct in6_addr));
       nexthop_tab[num_ifindex].ifindex = stream_getl (s);
-      nbr = pim_neighbor_find_if (if_lookup_by_index_vrf (nexthop_tab[num_ifindex].ifindex, VRF_DEFAULT));
+
+      p.family = AF_INET6;
+      p.prefixlen = IPV6_MAX_PREFIXLEN;
+      memcpy (&p.u.prefix6,
+             &nexthop_tab[num_ifindex].nexthop_addr.u.prefix6,
+             sizeof(struct in6_addr));
+
+      /*
+       * If we are sending v6 secondary assume we receive v6 secondary
+       */
+      if (pimg->send_v6_secondary)
+        nbr = pim_neighbor_find_by_secondary(if_lookup_by_index (nexthop_tab[num_ifindex].ifindex, VRF_DEFAULT), &p);
+      else
+        nbr = pim_neighbor_find_if (if_lookup_by_index (nexthop_tab[num_ifindex].ifindex, VRF_DEFAULT));
       if (nbr)
         {
           nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET;
@@ -262,7 +277,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__,
@@ -283,8 +298,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__,
@@ -307,8 +322,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;
   }
@@ -332,7 +347,6 @@ zclient_lookup_nexthop (struct pim_zlookup_nexthop nexthop_tab[],
   int lookup;
   uint32_t route_metric = 0xFFFFFFFF;
   uint8_t  protocol_distance = 0xFF;
-  int i;
 
   qpim_nexthop_lookups++;
 
@@ -345,7 +359,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__,
@@ -377,7 +391,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__,
@@ -394,33 +408,12 @@ zclient_lookup_nexthop (struct pim_zlookup_nexthop nexthop_tab[],
        nexthop_tab[0].protocol_distance = protocol_distance;
       }
 
-      /*
-       * Let's see if any of the nexthops can actually be used.
-       * We need to check them against the neighbors that we
-       * have formed.  As that we shouldn't be sending
-       * j/p messages upstream towards non-neighbors
-       */
-      for (i = 0; i < num_ifindex ; i++)
-       {
-         struct interface *ifp;
-         struct pim_neighbor *nbr;
-
-         ifp = if_lookup_by_index_vrf (nexthop_tab[i].ifindex, VRF_DEFAULT);
-         nbr = pim_neighbor_find (ifp, nexthop_tab[i].nexthop_addr.u.prefix4);
-         if (ifp->info && !nbr && !if_is_loopback (ifp))
-           {
-             num_ifindex--;
-             if (i != num_ifindex)
-               memcpy (&nexthop_tab[i], &nexthop_tab[i+1], sizeof (nexthop_tab[i]));
-             i--;
-           }
-       }
       return num_ifindex;
     }
 
     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",
@@ -435,7 +428,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__,
@@ -470,7 +463,17 @@ 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) VIIF %d",
+            pim_str_sg_dump (&more), c_oil->oil.mfcc_parent);
+    }
+
+  if (!ifp)
+    return -1;
 
   stream_reset (s);
   zclient_create_header (s, ZEBRA_IPMR_ROUTE_STATS, VRF_DEFAULT);
@@ -483,8 +486,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;
     }
 
@@ -522,9 +525,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;