]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: RX shutdown message in "show bgp neighbor"
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 25 Jan 2017 03:03:38 +0000 (04:03 +0100)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 7 Mar 2017 00:40:26 +0000 (19:40 -0500)
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
bgpd/bgp_debug.c
bgpd/bgp_debug.h
bgpd/bgp_packet.c
bgpd/bgp_vty.c
bgpd/bgpd.h

index e1e7cb1d5b677aa659696d3a54dc320d357bba7e..232f53c778a7487f59f9f9d9745e9e5e2e2344e4 100644 (file)
@@ -491,6 +491,21 @@ bgp_notify_subcode_str (char code, char subcode)
   return "";
 }
 
+/* extract notify admin reason if correctly present */
+const char *
+bgp_notify_admin_message(char *buf, size_t bufsz, u_char *data, size_t datalen)
+{
+  if (!data || datalen < 1)
+    return NULL;
+
+  u_char len = data[0];
+  if (len > 128
+      || len > datalen - 1)
+    return NULL;
+
+  return zlog_sanitize(buf, bufsz, data + 1, len);
+}
+
 /* dump notify packet */
 void
 bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
@@ -498,17 +513,37 @@ bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
 {
   const char *subcode_str;
   const char *code_str;
+  const char *msg_str = NULL;
+  char msg_buf[1024];
 
   if (BGP_DEBUG (neighbor_events, NEIGHBOR_EVENTS) || bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
     {
       code_str = bgp_notify_code_str(bgp_notify->code);
       subcode_str = bgp_notify_subcode_str(bgp_notify->code, bgp_notify->subcode);
 
-      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,
-                 code_str, subcode_str, bgp_notify->length,
-                 bgp_notify->data ? bgp_notify->data : "");
+      if (bgp_notify->code == BGP_NOTIFY_CEASE
+          && (bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
+              || bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_RESET))
+        {
+          msg_str = bgp_notify_admin_message(msg_buf, sizeof(msg_buf),
+                                             bgp_notify->raw_data, bgp_notify->length);
+        }
+
+      if (msg_str)
+        {
+          zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) \"%s\"",
+                     strcmp (direct, "received") == 0 ? "received from" : "sent to",
+                     peer->host, bgp_notify->code, bgp_notify->subcode,
+                     code_str, subcode_str, msg_str);
+        }
+      else
+        {
+          msg_str = bgp_notify->data ? bgp_notify->data : "";
+          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,
+                     code_str, subcode_str, bgp_notify->length, msg_str);
+        }
     }
 }
 
index 23ea7b0e52d9bf8cfdbd509c656dd6bb7a3620cd..0968568225b428d39d58daad2a1397755ce6359c 100644 (file)
@@ -156,4 +156,6 @@ extern int bgp_debug_zebra(struct prefix *p);
 extern int bgp_debug_count(void);
 extern const char *bgp_debug_rdpfxpath2str (struct prefix_rd *, union prefixconstptr,
                                             int, u_int32_t, char *, int);
+const char *bgp_notify_admin_message(char *buf, size_t bufsz, u_char *data, size_t datalen);
+
 #endif /* _QUAGGA_BGP_DEBUG_H */
index 0dbf41a4a18202b2b94ba60ee1298ec279f116c2..853fcc8697f6378a1d16ff8261b656dc07d2b4bc 100644 (file)
@@ -634,6 +634,7 @@ bgp_notify_send_with_data (struct peer *peer, u_char code, u_char sub_code,
     bgp_notify.subcode = sub_code;
     bgp_notify.data = NULL;
     bgp_notify.length = length - BGP_MSG_NOTIFY_MIN_SIZE;
+    bgp_notify.raw_data = data;
 
     peer->notify.code = bgp_notify.code;
     peer->notify.subcode = bgp_notify.subcode;
@@ -1678,6 +1679,7 @@ bgp_notify_receive (struct peer *peer, bgp_size_t size)
              sprintf (c, "%02x", stream_getc (peer->ibuf));
              strcpy (bgp_notify.data, c);
            }
+       bgp_notify.raw_data = (u_char*)peer->notify.data;
       }
 
     bgp_notify_print(peer, &bgp_notify, "received");
index ae3571e83d34aa6ae6990ae5a86d5a2ccfda54d6..547247206071a1661939856a16e8968ad079c968 100644 (file)
@@ -8292,6 +8292,20 @@ bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *js
               vty_out (vty, "due to NOTIFICATION %s (%s%s)%s",
                        p->last_reset == PEER_DOWN_NOTIFY_SEND ? "sent" : "received",
                        code_str, subcode_str, VTY_NEWLINE);
+              if (p->last_reset == PEER_DOWN_NOTIFY_RECEIVED
+                  && p->notify.code == BGP_NOTIFY_CEASE
+                  && (p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
+                      || p->notify.subcode == BGP_NOTIFY_CEASE_ADMIN_RESET)
+                  && p->notify.length)
+                {
+                  char msgbuf[1024];
+                  const char *msg_str;
+
+                  msg_str = bgp_notify_admin_message(msgbuf, sizeof(msgbuf),
+                                                     (u_char*)p->notify.data, p->notify.length);
+                  if (msg_str)
+                    vty_out (vty, "    Message: \"%s\"%s", msg_str, VTY_NEWLINE);
+                }
             }
           else
             {
index f0f2ed87bdc79e8c6fddf9a354ae70653f7e6baa..87d8288cfdce16dfc6c79d9e70a35718012f820e 100644 (file)
@@ -399,6 +399,7 @@ struct bgp_notify
   u_char subcode;
   char *data;
   bgp_size_t length;
+  u_char *raw_data;
 };
 
 /* Next hop self address. */