bgpd: RX shutdown message in "show bgp neighbor"

Signed-off-by: Christian Franke <chris@opensourcerouting.org>
This commit is contained in:
David Lamparter 2017-01-25 04:03:38 +01:00 committed by Donald Sharp
parent 1f806fc2c8
commit 38de8d0229
5 changed files with 59 additions and 5 deletions

View File

@ -491,6 +491,21 @@ bgp_notify_subcode_str (char code, char subcode)
return ""; 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 */ /* dump notify packet */
void void
bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, 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 *subcode_str;
const char *code_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)) 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); code_str = bgp_notify_code_str(bgp_notify->code);
subcode_str = bgp_notify_subcode_str(bgp_notify->code, bgp_notify->subcode); 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", if (bgp_notify->code == BGP_NOTIFY_CEASE
strcmp (direct, "received") == 0 ? "received from" : "sent to", && (bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
peer->host, bgp_notify->code, bgp_notify->subcode, || bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_RESET))
code_str, subcode_str, bgp_notify->length, {
bgp_notify->data ? bgp_notify->data : ""); 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);
}
} }
} }

View File

@ -156,4 +156,6 @@ extern int bgp_debug_zebra(struct prefix *p);
extern int bgp_debug_count(void); extern int bgp_debug_count(void);
extern const char *bgp_debug_rdpfxpath2str (struct prefix_rd *, union prefixconstptr, extern const char *bgp_debug_rdpfxpath2str (struct prefix_rd *, union prefixconstptr,
int, u_int32_t, char *, int); 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 */ #endif /* _QUAGGA_BGP_DEBUG_H */

View 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.subcode = sub_code;
bgp_notify.data = NULL; bgp_notify.data = NULL;
bgp_notify.length = length - BGP_MSG_NOTIFY_MIN_SIZE; bgp_notify.length = length - BGP_MSG_NOTIFY_MIN_SIZE;
bgp_notify.raw_data = data;
peer->notify.code = bgp_notify.code; peer->notify.code = bgp_notify.code;
peer->notify.subcode = bgp_notify.subcode; 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)); sprintf (c, "%02x", stream_getc (peer->ibuf));
strcpy (bgp_notify.data, c); strcpy (bgp_notify.data, c);
} }
bgp_notify.raw_data = (u_char*)peer->notify.data;
} }
bgp_notify_print(peer, &bgp_notify, "received"); bgp_notify_print(peer, &bgp_notify, "received");

View 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", vty_out (vty, "due to NOTIFICATION %s (%s%s)%s",
p->last_reset == PEER_DOWN_NOTIFY_SEND ? "sent" : "received", p->last_reset == PEER_DOWN_NOTIFY_SEND ? "sent" : "received",
code_str, subcode_str, VTY_NEWLINE); 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 else
{ {

View File

@ -399,6 +399,7 @@ struct bgp_notify
u_char subcode; u_char subcode;
char *data; char *data;
bgp_size_t length; bgp_size_t length;
u_char *raw_data;
}; };
/* Next hop self address. */ /* Next hop self address. */