pimd: merge pimd as of 2015-01-19

Welcome pimd to the Quagga daemon zoo!

This is a merge of commit 77ae369 ("pimd: Log ifindex found for an
interface when zebra lib reports a new connected address."), with
the intermediate "reconnect" changes removed (c9adf00...d274381).
d274381 is replaced with b162ab7, which includes some changes.  In
addition, 4 reconnect-related changes and 1 cosmetic one have been
bumped out.

The rebase command used to produce the branch that is merged here is:
  git rebase --onto b162ab7 c9adf00 77ae369

Note that 3 patches had their author rewritten from
    "Anonymous SR#108542 <>" (which is not a valid git author ID)
to: "Savannah SR#108542 <nbahr@atcorp.com>" (which is the e-mail address
                               listed in the associated Savannah ticket)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index 8a326a8..482e76b 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -688,7 +688,7 @@
 	  eas.val = (*pnt++ << 8);
 	  eas.val |= (*pnt++);
 
-	  len = sprintf( str_buf + str_pnt, "%s%u:%d", prefix,
+	  len = sprintf( str_buf + str_pnt, "%s%u:%u", prefix,
                         eas.as, eas.val );
 	  str_pnt += len;
 	  first = 0;
@@ -703,7 +703,7 @@
 	  eas.val |= (*pnt++ << 8);
 	  eas.val |= (*pnt++);
 
-	  len = sprintf (str_buf + str_pnt, "%s%u:%d", prefix,
+	  len = sprintf (str_buf + str_pnt, "%s%u:%u", prefix,
 			 eas.as, eas.val);
 	  str_pnt += len;
 	  first = 0;
@@ -715,7 +715,7 @@
 	  eip.val = (*pnt++ << 8);
 	  eip.val |= (*pnt++);
 
-	  len = sprintf (str_buf + str_pnt, "%s%s:%d", prefix,
+	  len = sprintf (str_buf + str_pnt, "%s%s:%u", prefix,
 			 inet_ntoa (eip.ip), eip.val);
 	  str_pnt += len;
 	  first = 0;
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index ca44774..e6a3660 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -6937,7 +6937,7 @@
   int len;
 
   /* Header string for each address family. */
-  static char header[] = "Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd";
+  static char header[] = "Neighbor        V         AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd";
   
   for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
     {
@@ -8302,7 +8302,7 @@
 
   vty_out (vty, "4 ");
 
-  vty_out (vty, "%11d ", rsclient->as);
+  vty_out (vty, "%10u ", rsclient->as);
 
   rmname = ROUTE_MAP_EXPORT_NAME(&rsclient->filter[afi][safi]);
   if ( rmname && strlen (rmname) > 13 )
@@ -8347,7 +8347,7 @@
   int count = 0;
 
   /* Header string for each address family. */
-  static char header[] = "Neighbor        V    AS  Export-Policy  Import-Policy  Up/Down  State";
+  static char header[] = "Neighbor        V         AS  Export-Policy  Import-Policy  Up/Down  State";
 
   for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, peer))
     {
diff --git a/isisd/isis_events.c b/isisd/isis_events.c
index 3887b7c..96d5762 100644
--- a/isisd/isis_events.c
+++ b/isisd/isis_events.c
@@ -280,26 +280,29 @@
       return;
     }
 
-  switch (circuit->is_type)
+  if (! circuit->is_passive)
     {
-    case IS_LEVEL_1:
-      if (newtype == IS_LEVEL_2)
-	circuit_resign_level (circuit, 1);
-      circuit_commence_level (circuit, 2);
-      break;
-    case IS_LEVEL_1_AND_2:
-      if (newtype == IS_LEVEL_1)
-	circuit_resign_level (circuit, 2);
-      else
-	circuit_resign_level (circuit, 1);
-      break;
-    case IS_LEVEL_2:
-      if (newtype == IS_LEVEL_1)
-	circuit_resign_level (circuit, 2);
-      circuit_commence_level (circuit, 1);
-      break;
-    default:
-      break;
+      switch (circuit->is_type)
+        {
+        case IS_LEVEL_1:
+          if (newtype == IS_LEVEL_2)
+            circuit_resign_level (circuit, 1);
+          circuit_commence_level (circuit, 2);
+          break;
+        case IS_LEVEL_1_AND_2:
+          if (newtype == IS_LEVEL_1)
+            circuit_resign_level (circuit, 2);
+          else
+            circuit_resign_level (circuit, 1);
+          break;
+        case IS_LEVEL_2:
+          if (newtype == IS_LEVEL_1)
+            circuit_resign_level (circuit, 2);
+          circuit_commence_level (circuit, 1);
+          break;
+        default:
+          break;
+        }
     }
 
   circuit->is_type = newtype;
diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c
index 8d8a5e0..166dd7c 100644
--- a/isisd/isis_pdu.c
+++ b/isisd/isis_pdu.c
@@ -566,6 +566,17 @@
    * the circuit
    */
   adj = circuit->u.p2p.neighbor;
+  /* If an adjacency exists, check it is with the source of the hello
+   * packets */
+  if (adj)
+    {
+      if (memcmp(hdr->source_id, adj->sysid, ISIS_SYS_ID_LEN))
+	{
+          zlog_debug("hello source and adjacency do not match, set adj down\n");
+          isis_adj_state_change (adj, ISIS_ADJ_DOWN, "adj do not exist");
+          return 0;
+        }
+    }
   if (!adj || adj->level != hdr->circuit_t)
     {
       if (!adj)
diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c
index 744952c..ecb28ff 100644
--- a/ospfd/ospf_opaque.c
+++ b/ospfd/ospf_opaque.c
@@ -2126,10 +2126,12 @@
  *------------------------------------------------------------------------*/
 
 static void ospf_opaque_exclude_lsa_from_lsreq (struct route_table *nbrs, struct ospf_neighbor *inbr, struct ospf_lsa *lsa);
+#ifdef BUGGY_UNLOCK
 static void ospf_opaque_type9_lsa_rxmt_nbr_check (struct ospf_interface *oi);
 static void ospf_opaque_type10_lsa_rxmt_nbr_check (struct ospf_area *area);
 static void ospf_opaque_type11_lsa_rxmt_nbr_check (struct ospf *top);
 static unsigned long ospf_opaque_nrxmt_self (struct route_table *nbrs, int lsa_type);
+#endif /* BUGGY_UNLOCK */
 
 void
 ospf_opaque_adjust_lsreq (struct ospf_neighbor *nbr, struct list *lsas)
@@ -2296,17 +2298,20 @@
     {
     case OSPF_OPAQUE_LINK_LSA:
       if (CHECK_FLAG (top->opaque, OPAQUE_BLOCK_TYPE_09_LSA_BIT))
-        ospf_opaque_type9_lsa_rxmt_nbr_check (nbr->oi);
+        UNSET_FLAG (top->opaque, OPAQUE_BLOCK_TYPE_09_LSA_BIT);
+        /* BUGGY_UNLOCK: ospf_opaque_type9_lsa_rxmt_nbr_check (nbr->oi); */
       /* Callback function... */
       break;
     case OSPF_OPAQUE_AREA_LSA:
       if (CHECK_FLAG (top->opaque, OPAQUE_BLOCK_TYPE_10_LSA_BIT))
-        ospf_opaque_type10_lsa_rxmt_nbr_check (nbr->oi->area);
+        UNSET_FLAG (top->opaque, OPAQUE_BLOCK_TYPE_10_LSA_BIT);
+        /* BUGGY_UNLOCK: ospf_opaque_type10_lsa_rxmt_nbr_check (nbr->oi->area); */
       /* Callback function... */
       break;
     case OSPF_OPAQUE_AS_LSA:
       if (CHECK_FLAG (top->opaque, OPAQUE_BLOCK_TYPE_11_LSA_BIT))
-        ospf_opaque_type11_lsa_rxmt_nbr_check (top);
+        UNSET_FLAG (top->opaque, OPAQUE_BLOCK_TYPE_11_LSA_BIT);
+        /* BUGGY_UNLOCK: ospf_opaque_type11_lsa_rxmt_nbr_check (top); */
       /* Callback function... */
       break;
     default:
@@ -2315,11 +2320,10 @@
     }
   
   if (IS_OPAQUE_LSA_ORIGINATION_BLOCKED (top->opaque))
-    {
-      if (IS_DEBUG_OSPF_EVENT)
-        zlog_debug ("Block Opaque-LSA origination: ON -> OFF");
       return; /* Blocking still in progress. */
-    }
+
+  if (IS_DEBUG_OSPF_EVENT)
+    zlog_debug ("Block Opaque-LSA origination: ON -> OFF");
   
   if (! CHECK_FLAG (top->config, OSPF_OPAQUE_CAPABLE))
     return; /* Opaque capability condition must have changed. */
@@ -2339,6 +2343,7 @@
   return;
 }
 
+#ifdef BUGGY_UNLOCK
 static void
 ospf_opaque_type9_lsa_rxmt_nbr_check (struct ospf_interface *oi)
 {
@@ -2439,6 +2444,7 @@
 
   return n;
 }
+#endif /* BUGGY_UNLOCK */
 
 /*------------------------------------------------------------------------*
  * Followings are util functions; probably be used by Opaque-LSAs only...
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 36aa895..98b1af3 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -3143,22 +3143,7 @@
   options = OPTIONS (oi);
 #ifdef HAVE_OPAQUE_LSA
   if (CHECK_FLAG (oi->ospf->config, OSPF_OPAQUE_CAPABLE))
-    {
-      if (IS_SET_DD_I (nbr->dd_flags)
-      ||  CHECK_FLAG (nbr->options, OSPF_OPTION_O))
-        /*
-         * Set O-bit in the outgoing DD packet for capablity negotiation,
-         * if one of following case is applicable. 
-         *
-         * 1) WaitTimer expiration event triggered the neighbor state to
-         *    change to Exstart, but no (valid) DD packet has received
-         *    from the neighbor yet.
-         *
-         * 2) At least one DD packet with O-bit on has received from the
-         *    neighbor.
-         */
-        SET_FLAG (options, OSPF_OPTION_O);
-    }
+    SET_FLAG (options, OSPF_OPTION_O);
 #endif /* HAVE_OPAQUE_LSA */
   stream_putc (s, options);
 
diff --git a/tests/aspath_test.c b/tests/aspath_test.c
index 71a3102..0aa3e47 100644
--- a/tests/aspath_test.c
+++ b/tests/aspath_test.c
@@ -457,8 +457,11 @@
       BGP_ATTR_FLAG_TRANS, \
       BGP_ATTR_ORIGIN, \
       1, \
-      BGP_ORIGIN_EGP
-#define COMMON_ATTR_SIZE 4
+      BGP_ORIGIN_EGP, \
+      BGP_ATTR_FLAG_TRANS, \
+      BGP_ATTR_NEXT_HOP, \
+      4, 192, 0, 2, 0
+#define COMMON_ATTR_SIZE 11
 
 /* */
 static struct aspath_tests {