From 9f33eea39a5858dc05cbcee7ca1068d1cef48713 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 5 Jan 2022 12:11:27 +0200 Subject: [PATCH] bgpd: Increase administrative shutdown message size to 255 Extended BGP Administrative Shutdown Communication (rfc9003): Basically, shutdown message size is increased to 255 from 128. Signed-off-by: Donatas Abraitis --- bgpd/bgp_debug.c | 2 +- bgpd/bgpd.c | 7 +++---- bgpd/bgpd.h | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index fde1bdd7ce..64f71bebc9 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -509,7 +509,7 @@ const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data, return NULL; uint8_t len = data[0]; - if (len > 128 || len > datalen - 1) + if (!len || len > datalen - 1) return NULL; return zlog_sanitize(buf, bufsz, data + 1, len); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 789c156da4..3921ad2367 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4272,17 +4272,16 @@ static void peer_flag_modify_action(struct peer *peer, uint32_t flag) if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { char *msg = peer->tx_shutdown_message; size_t msglen; + uint8_t msgbuf[BGP_ADMIN_SHUTDOWN_MSG_LEN + 1]; if (!msg && peer_group_active(peer)) msg = peer->group->conf ->tx_shutdown_message; msglen = msg ? strlen(msg) : 0; - if (msglen > 128) - msglen = 128; + if (msglen > BGP_ADMIN_SHUTDOWN_MSG_LEN) + msglen = BGP_ADMIN_SHUTDOWN_MSG_LEN; if (msglen) { - uint8_t msgbuf[129]; - msgbuf[0] = msglen; memcpy(msgbuf + 1, msg, msglen); diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index f4d7ab769a..865a50757f 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1731,6 +1731,9 @@ struct bgp_nlri { /* Default BGP port number. */ #define BGP_PORT_DEFAULT 179 +/* Extended BGP Administrative Shutdown Communication */ +#define BGP_ADMIN_SHUTDOWN_MSG_LEN 255 + /* BGP minimum message size. */ #define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10) #define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)