pimd: Limit pim hello log messages

pimd was outputting allot of data surrounding pim hello packets.
In addition the debugging was inconsistent and not all turned
on via 'debug pim packet hello'.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c
index 1285783..bfc128b 100644
--- a/pimd/pim_hello.c
+++ b/pimd/pim_hello.c
@@ -160,7 +160,8 @@
   uint32_t hello_option_generation_id = 0;
   struct list *hello_option_addr_list = 0;
 
-  on_trace(__PRETTY_FUNCTION__, ifp, src_addr);
+  if (PIM_DEBUG_PIM_HELLO)
+    on_trace(__PRETTY_FUNCTION__, ifp, src_addr);
 
   pim_ifp = ifp->info;
   zassert(pim_ifp);
@@ -180,12 +181,14 @@
     int remain = tlv_pastend - tlv_curr;
 
     if (remain < PIM_TLV_MIN_SIZE) {
-      char src_str[100];
-      pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
-      zlog_warn("%s: short PIM hello TLV size=%d < min=%d from %s on interface %s",
-		__PRETTY_FUNCTION__,
-		remain, PIM_TLV_MIN_SIZE,
-		src_str, ifp->name);
+      if (PIM_DEBUG_PIM_HELLO) {
+	char src_str[100];
+	pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+	zlog_debug("%s: short PIM hello TLV size=%d < min=%d from %s on interface %s",
+		   __PRETTY_FUNCTION__,
+		   remain, PIM_TLV_MIN_SIZE,
+		   src_str, ifp->name);
+      }
       FREE_ADDR_LIST_THEN_RETURN(-1);
     }
 
@@ -195,16 +198,18 @@
     tlv_curr += PIM_TLV_LENGTH_SIZE;
 
     if ((tlv_curr + option_len) > tlv_pastend) {
-      char src_str[100];
-      pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
-      zlog_warn("%s: long PIM hello TLV type=%d length=%d > left=%td from %s on interface %s",
-		__PRETTY_FUNCTION__,
-		option_type, option_len, tlv_pastend - tlv_curr,
-		src_str, ifp->name);
+      if (PIM_DEBUG_PIM_HELLO) {
+	char src_str[100];
+	pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+	zlog_debug("%s: long PIM hello TLV type=%d length=%d > left=%td from %s on interface %s",
+		   __PRETTY_FUNCTION__,
+		   option_type, option_len, tlv_pastend - tlv_curr,
+		   src_str, ifp->name);
+      }
       FREE_ADDR_LIST_THEN_RETURN(-2);
     }
 
-    if (PIM_DEBUG_PIM_TRACE || PIM_DEBUG_PIM_HELLO) {
+    if (PIM_DEBUG_PIM_HELLO) {
       char src_str[100];
       pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
       zlog_debug("%s: parse left_size=%d: PIM hello TLV type=%d length=%d from %s on %s",
@@ -262,7 +267,7 @@
       }
       break;
     case PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH:
-      if (PIM_DEBUG_PIM_TRACE || PIM_DEBUG_PIM_HELLO) {
+      if (PIM_DEBUG_PIM_HELLO) {
 	char src_str[100];
 	pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
 	zlog_debug("%s: ignoring PIM hello dense-mode state refresh TLV option type=%d length=%d from %s on interface %s",
@@ -272,13 +277,13 @@
       }
       break;
     default:
-      {
+      if (PIM_DEBUG_PIM_HELLO) {
 	char src_str[100];
 	pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
-	zlog_warn("%s: ignoring unknown PIM hello TLV type=%d length=%d from %s on interface %s",
-		  __PRETTY_FUNCTION__,
-		  option_type, option_len,
-		  src_str, ifp->name);
+	zlog_debug("%s: ignoring unknown PIM hello TLV type=%d length=%d from %s on interface %s",
+		   __PRETTY_FUNCTION__,
+		   option_type, option_len,
+		   src_str, ifp->name);
       }
     }
 
@@ -289,7 +294,7 @@
     Check received PIM hello options
   */
 
-  if (PIM_DEBUG_PIM_TRACE) {
+  if (PIM_DEBUG_PIM_HELLO) {
     tlv_trace_uint16(__PRETTY_FUNCTION__, "holdtime",
 		     ifp->name, src_addr,
 		     PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME),
@@ -321,11 +326,13 @@
   }
 
   if (!PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME)) {
-    char src_str[100];
-    pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
-    zlog_warn("%s: PIM hello missing holdtime from %s on interface %s",
-	      __PRETTY_FUNCTION__,
-	      src_str, ifp->name);
+    if (PIM_DEBUG_PIM_HELLO) {
+      char src_str[100];
+      pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+      zlog_debug("%s: PIM hello missing holdtime from %s on interface %s",
+		__PRETTY_FUNCTION__,
+		src_str, ifp->name);
+    }
   }
 
   /*
@@ -345,11 +352,13 @@
 			     hello_option_generation_id,
 			     hello_option_addr_list);
     if (!neigh) {
-      char src_str[100];
-      pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
-      zlog_warn("%s: failure creating PIM neighbor %s on interface %s",
-		__PRETTY_FUNCTION__,
-		src_str, ifp->name);
+      if (PIM_DEBUG_PIM_HELLO) {
+	char src_str[100];
+	pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+	zlog_warn("%s: failure creating PIM neighbor %s on interface %s",
+		  __PRETTY_FUNCTION__,
+		  src_str, ifp->name);
+      }
       FREE_ADDR_LIST_THEN_RETURN(-8);
     }
 
@@ -372,7 +381,7 @@
 
       /* GenID mismatch, then replace neighbor */
       
-      if (PIM_DEBUG_PIM_TRACE) {
+      if (PIM_DEBUG_PIM_HELLO) {
 	char src_str[100];
 	pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
 	zlog_debug("%s: GenId mismatch new=%08x old=%08x: replacing neighbor %s on %s",
@@ -394,11 +403,13 @@
 			       hello_option_generation_id,
 			       hello_option_addr_list);
       if (!neigh) {
-	char src_str[100];
-	pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
-	zlog_warn("%s: failure re-creating PIM neighbor %s on interface %s",
-		  __PRETTY_FUNCTION__,
-		  src_str, ifp->name);
+	if (PIM_DEBUG_PIM_HELLO) {
+	  char src_str[100];
+	  pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+	  zlog_debug("%s: failure re-creating PIM neighbor %s on interface %s",
+		     __PRETTY_FUNCTION__,
+		     src_str, ifp->name);
+	}
 	FREE_ADDR_LIST_THEN_RETURN(-9);
       }
       /* actual addr list is saved under neighbor */
@@ -445,8 +456,10 @@
 			       PIM_MSG_OPTION_TYPE_HOLDTIME,
 			       holdtime);
   if (!curr) {
-    zlog_warn("%s: could not set PIM hello Holdtime option for interface %s",
-	      __PRETTY_FUNCTION__, ifname);
+    if (PIM_DEBUG_PIM_HELLO) {
+      zlog_debug("%s: could not set PIM hello Holdtime option for interface %s",
+		 __PRETTY_FUNCTION__, ifname);
+    }
     return -1;
   }
 
@@ -457,8 +470,10 @@
 			       propagation_delay,
 			       override_interval);
   if (!tmp) {
-    zlog_warn("%s: could not set PIM LAN Prune Delay option for interface %s",
-	      __PRETTY_FUNCTION__, ifname);
+    if (PIM_DEBUG_PIM_HELLO) {
+      zlog_debug("%s: could not set PIM LAN Prune Delay option for interface %s",
+		 __PRETTY_FUNCTION__, ifname);
+    }
     return -1;
   }
   if (can_disable_join_suppression) {
@@ -472,8 +487,10 @@
 			       PIM_MSG_OPTION_TYPE_DR_PRIORITY,
 			       dr_priority);
   if (!curr) {
-    zlog_warn("%s: could not set PIM hello DR Priority option for interface %s",
-	      __PRETTY_FUNCTION__, ifname);
+    if (PIM_DEBUG_PIM_HELLO) {
+      zlog_debug("%s: could not set PIM hello DR Priority option for interface %s",
+		 __PRETTY_FUNCTION__, ifname);
+    }
     return -2;
   }
 
@@ -483,8 +500,10 @@
 			       PIM_MSG_OPTION_TYPE_GENERATION_ID,
 			       generation_id);
   if (!curr) {
-    zlog_warn("%s: could not set PIM hello Generation ID option for interface %s",
-	      __PRETTY_FUNCTION__, ifname);
+    if (PIM_DEBUG_PIM_HELLO) {
+      zlog_debug("%s: could not set PIM hello Generation ID option for interface %s",
+		 __PRETTY_FUNCTION__, ifname);
+    }
     return -3;
   }
 
@@ -494,8 +513,10 @@
 					 pastend,
 					 ifconnected);
     if (!curr) {
-      zlog_warn("%s: could not set PIM hello Secondary Address List option for interface %s",
-		__PRETTY_FUNCTION__, ifname);
+      if (PIM_DEBUG_PIM_HELLO) {
+	zlog_debug("%s: could not set PIM hello Secondary Address List option for interface %s",
+		  __PRETTY_FUNCTION__, ifname);
+      }
       return -4;
     }
   }
diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c
index 66fc59b..a04a0af 100644
--- a/pimd/pim_pim.c
+++ b/pimd/pim_pim.c
@@ -521,7 +521,7 @@
 
   pim_ifp = ifp->info;
 
-  if (PIM_DEBUG_PIM_PACKETS || PIM_DEBUG_PIM_HELLO) {
+  if (PIM_DEBUG_PIM_HELLO) {
     char dst_str[100];
     pim_inet4_dump("<dst?>", qpim_all_pim_routers_addr, dst_str, sizeof(dst_str));
     zlog_debug("%s: to %s on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d",
@@ -561,8 +561,10 @@
 		   pim_msg,
 		   pim_msg_size,
 		   ifp->name)) {
-    zlog_warn("%s: could not send PIM message on interface %s",
-	      __PRETTY_FUNCTION__, ifp->name);
+    if (PIM_DEBUG_PIM_HELLO) {
+      zlog_debug("%s: could not send PIM message on interface %s",
+		 __PRETTY_FUNCTION__, ifp->name);
+    }
     return -2;
   }
 
@@ -581,8 +583,10 @@
   if (hello_send(ifp, holdtime)) {
     ++pim_ifp->pim_ifstat_hello_sendfail;
 
-    zlog_warn("Could not send PIM hello on interface %s",
-	      ifp->name);
+    if (PIM_DEBUG_PIM_HELLO) {
+      zlog_warn("Could not send PIM hello on interface %s",
+		ifp->name);
+    }
     return -1;
   }
 
@@ -599,7 +603,7 @@
   pim_ifp = ifp->info;
   zassert(pim_ifp);
 
-  if (PIM_DEBUG_PIM_TRACE) {
+  if (PIM_DEBUG_PIM_HELLO) {
     zlog_debug("Rescheduling %d sec hello on interface %s",
 	       pim_ifp->pim_hello_period, ifp->name);
   }
@@ -699,7 +703,7 @@
 
   random_msec = random() % (triggered_hello_delay_msec + 1);
 
-  if (PIM_DEBUG_PIM_EVENTS) {
+  if (PIM_DEBUG_PIM_HELLO) {
     zlog_debug("Scheduling %d msec triggered hello on interface %s",
 	       random_msec, ifp->name);
   }
diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c
index 95ee5ab..ed4dbba 100644
--- a/pimd/pim_tlv.c
+++ b/pimd/pim_tlv.c
@@ -38,12 +38,8 @@
 {
   uint16_t option_len = 2;
 
-  if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend) {
-    zlog_warn("%s: buffer overflow: left=%zd needed=%d",
-	      __PRETTY_FUNCTION__,
-	      buf_pastend - buf, PIM_TLV_OPTION_SIZE(option_len));
-    return 0;
-  }
+  if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend)
+    return NULL;
 
   *(uint16_t *) buf = htons(option_type);
   buf += 2;
@@ -63,12 +59,8 @@
 {
   uint16_t option_len = 4;
 
-  if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend) {
-    zlog_warn("%s: buffer overflow: left=%zd needed=%d",
-	      __PRETTY_FUNCTION__,
-	      buf_pastend - buf, PIM_TLV_OPTION_SIZE(option_len));
-    return 0;
-  }
+  if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend)
+    return NULL;
 
   *(uint16_t *) buf = htons(option_type);
   buf += 2;
@@ -89,12 +81,8 @@
 {
   uint16_t option_len = 4;
 
-  if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend) {
-    zlog_warn("%s: buffer overflow: left=%zd needed=%d",
-	      __PRETTY_FUNCTION__,
-	      buf_pastend - buf, PIM_TLV_OPTION_SIZE(option_len));
-    return 0;
-  }
+  if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend)
+    return NULL;
 
   *(uint16_t *) buf = htons(option_type);
   buf += 2;
@@ -136,12 +124,8 @@
     if (p->family != AF_INET)
       continue;
 
-    if ((curr + ucast_ipv4_encoding_len) > buf_pastend) {
-      zlog_warn("%s: buffer overflow: left=%zd needed=%zu",
-		__PRETTY_FUNCTION__,
-		buf_pastend - curr, ucast_ipv4_encoding_len);
+    if ((curr + ucast_ipv4_encoding_len) > buf_pastend)
       return 0;
-    }
 
     /* Write encoded unicast IPv4 address */
     *(uint8_t *) curr = PIM_MSG_ADDRESS_FAMILY_IPV4; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
@@ -155,9 +139,9 @@
   }
 
   if (PIM_DEBUG_PIM_TRACE) {
-    zlog_warn("%s: number of encoded secondary unicast IPv4 addresses: %zu",
-	      __PRETTY_FUNCTION__,
-	      option_len / ucast_ipv4_encoding_len);
+    zlog_debug("%s: number of encoded secondary unicast IPv4 addresses: %zu",
+	       __PRETTY_FUNCTION__,
+	       option_len / ucast_ipv4_encoding_len);
   }
 
   if (option_len < 1) {