diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2017-01-25 04:03:38 +0100 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-03-07 01:40:26 +0100 |
commit | 38de8d0229d342f84ce550dc05be6b220b388a5d (patch) | |
tree | 5a3434788e431c28196264159e730a7b49d2d866 /bgpd | |
parent | lib: add zlog_sanitize function (diff) | |
download | frr-38de8d0229d342f84ce550dc05be6b220b388a5d.tar.xz frr-38de8d0229d342f84ce550dc05be6b220b388a5d.zip |
bgpd: RX shutdown message in "show bgp neighbor"
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Diffstat (limited to '')
-rw-r--r-- | bgpd/bgp_debug.c | 45 | ||||
-rw-r--r-- | bgpd/bgp_debug.h | 2 | ||||
-rw-r--r-- | bgpd/bgp_packet.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 14 | ||||
-rw-r--r-- | bgpd/bgpd.h | 1 |
5 files changed, 59 insertions, 5 deletions
diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index e1e7cb1d5..232f53c77 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -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); + } } } diff --git a/bgpd/bgp_debug.h b/bgpd/bgp_debug.h index 23ea7b0e5..096856822 100644 --- a/bgpd/bgp_debug.h +++ b/bgpd/bgp_debug.h @@ -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 */ diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 0dbf41a4a..853fcc869 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -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"); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index ae3571e83..547247206 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -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 { diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index f0f2ed87b..87d8288cf 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -399,6 +399,7 @@ struct bgp_notify u_char subcode; char *data; bgp_size_t length; + u_char *raw_data; }; /* Next hop self address. */ |