[quagga-dev 10185] [PATCH] bgpd: improve logging of invalid BGP Notifications

David Lamparter equinox at opensourcerouting.org
Tue Jan 15 16:24:26 GMT 2013


From: Leonid Rosenboim <lrosenbo at wrs.com>

Invalid BGP Notification messages should be logged locally, cf.
RFC4271, Sect. 6.4, p 34,
  NOTIFICATION Message Error Handling

Current notification for invalid Notification code:

  2012/10/10 02:17:54 BGP: message index 10 not found in bgp_notify_msg (max is 8)
  2012/10/10 02:17:54 BGP: 192.168.1.1 received NOTIFICATION 10/0 ((no item found)) 0 bytes

the logging should be a bit more clear. The above logging really doesn't
explain much and looks more like a programming error.

[rewrote most of it to get in something I can call a shape -David]
Signed-off-by: David Lamparter <equinox at opensourcerouting.org>
---
original patch was... way weird... and didn't really meet any code quality standard.

Anyway, applied.

-David
---
 bgpd/bgp_debug.c |   28 ++++++++++++++++------------
 lib/log.h        |    5 +++--
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c
index e3e3ec8..726dd86 100644
--- a/bgpd/bgp_debug.c
+++ b/bgpd/bgp_debug.c
@@ -243,31 +243,37 @@ bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
                  const char *direct)
 {
   const char *subcode_str;
+  const char *code_str;
 
   subcode_str = "";
+  code_str = LOOKUP_DEF (bgp_notify_msg, bgp_notify->code,
+                         "Unrecognized Error Code");
 
-  switch (bgp_notify->code) 
+  switch (bgp_notify->code)
     {
     case BGP_NOTIFY_HEADER_ERR:
-      subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode);
+      subcode_str = LOOKUP_DEF (bgp_notify_head_msg, bgp_notify->subcode,
+                                "Unrecognized Error Subcode");
       break;
     case BGP_NOTIFY_OPEN_ERR:
-      subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode);
+      subcode_str = LOOKUP_DEF (bgp_notify_open_msg, bgp_notify->subcode,
+                                "Unrecognized Error Subcode");
       break;
     case BGP_NOTIFY_UPDATE_ERR:
-      subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode);
+      subcode_str = LOOKUP_DEF (bgp_notify_update_msg, bgp_notify->subcode,
+                                "Unrecognized Error Subcode");
       break;
     case BGP_NOTIFY_HOLD_ERR:
-      subcode_str = "";
       break;
     case BGP_NOTIFY_FSM_ERR:
-      subcode_str = "";
       break;
     case BGP_NOTIFY_CEASE:
-      subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode);
+      subcode_str = LOOKUP_DEF (bgp_notify_cease_msg, bgp_notify->subcode,
+                                "Unrecognized Error Subcode");
       break;
     case BGP_NOTIFY_CAPABILITY_ERR:
-      subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode);
+      subcode_str = LOOKUP_DEF (bgp_notify_capability_msg, bgp_notify->subcode,
+                                "Unrecognized Error Subcode");
       break;
     }
 
@@ -275,15 +281,13 @@ bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
     zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
               strcmp (direct, "received") == 0 ? "received from" : "sent to",
               peer->host, bgp_notify->code, bgp_notify->subcode,
-               LOOKUP (bgp_notify_msg, bgp_notify->code),
-              subcode_str, bgp_notify->length,
+              code_str, subcode_str, bgp_notify->length,
               bgp_notify->data ? bgp_notify->data : "");
   else if (BGP_DEBUG (normal, NORMAL))
     plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
 	       peer ? peer->host : "",
 	       direct, bgp_notify->code, bgp_notify->subcode,
-	       LOOKUP (bgp_notify_msg, bgp_notify->code),
-	       subcode_str, bgp_notify->length,
+	       code_str, subcode_str, bgp_notify->length,
 	       bgp_notify->data ? bgp_notify->data : "");
 }
 
diff --git a/lib/log.h b/lib/log.h
index 27f21b3..cf247a8 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -146,8 +146,9 @@ extern int zlog_reset_file (struct zlog *zl);
 /* Rotate log. */
 extern int zlog_rotate (struct zlog *);
 
-/* For hackey massage lookup and check */
-#define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)", #x)
+/* For hackey message lookup and check */
+#define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x)
+#define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)")
 
 extern const char *lookup (const struct message *, int);
 extern const char *mes_lookup (const struct message *meslist, 
-- 
1.7.8.6





More information about the Quagga-dev mailing list