summaryrefslogtreecommitdiff
path: root/bgpd/bgp_open.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_open.c')
-rw-r--r--bgpd/bgp_open.c143
1 files changed, 102 insertions, 41 deletions
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index e15690835a..a05921e7b6 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -57,6 +57,7 @@ static const struct message capcode_str[] = {
{CAPABILITY_CODE_FQDN, "FQDN"},
{CAPABILITY_CODE_ENHANCED_RR, "Enhanced Route Refresh"},
{CAPABILITY_CODE_EXT_MESSAGE, "BGP Extended Message"},
+ {CAPABILITY_CODE_LLGR, "Long-lived BGP Graceful Restart"},
{0}};
/* Minimum sizes for length field of each cap (so not inc. the header) */
@@ -75,6 +76,7 @@ static const size_t cap_minsizes[] = {
[CAPABILITY_CODE_FQDN] = CAPABILITY_CODE_MIN_FQDN_LEN,
[CAPABILITY_CODE_ENHANCED_RR] = CAPABILITY_CODE_ENHANCED_LEN,
[CAPABILITY_CODE_EXT_MESSAGE] = CAPABILITY_CODE_EXT_MESSAGE_LEN,
+ [CAPABILITY_CODE_LLGR] = CAPABILITY_CODE_LLGR_LEN,
};
/* value the capability must be a multiple of.
@@ -97,6 +99,7 @@ static const size_t cap_modsizes[] = {
[CAPABILITY_CODE_FQDN] = 1,
[CAPABILITY_CODE_ENHANCED_RR] = 1,
[CAPABILITY_CODE_EXT_MESSAGE] = 1,
+ [CAPABILITY_CODE_LLGR] = 1,
};
/* BGP-4 Multiprotocol Extentions lead us to the complex world. We can
@@ -1088,7 +1091,7 @@ static bool strict_capability_same(struct peer *peer)
/* peek into option, stores ASN to *as4 if the AS4 capability was found.
* Returns 0 if no as4 found, as4cap value otherwise.
*/
-as_t peek_for_as4_capability(struct peer *peer, uint8_t length)
+as_t peek_for_as4_capability(struct peer *peer, uint16_t length)
{
struct stream *s = BGP_INPUT(peer);
size_t orig_getp = stream_get_getp(s);
@@ -1104,7 +1107,7 @@ as_t peek_for_as4_capability(struct peer *peer, uint8_t length)
*/
while (stream_get_getp(s) < end) {
uint8_t opt_type;
- uint8_t opt_length;
+ uint16_t opt_length;
/* Check the length. */
if (stream_get_getp(s) + 2 > end)
@@ -1112,7 +1115,9 @@ as_t peek_for_as4_capability(struct peer *peer, uint8_t length)
/* Fetch option type and length. */
opt_type = stream_getc(s);
- opt_length = stream_getc(s);
+ opt_length = BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(peer)
+ ? stream_getw(s)
+ : stream_getc(s);
/* Option length check. */
if (stream_get_getp(s) + opt_length > end)
@@ -1160,7 +1165,8 @@ end:
*
* @param[out] mp_capability @see bgp_capability_parse() for semantics.
*/
-int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability)
+int bgp_open_option_parse(struct peer *peer, uint16_t length,
+ int *mp_capability)
{
int ret = 0;
uint8_t *error;
@@ -1179,7 +1185,7 @@ int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability)
while (stream_get_getp(s) < end) {
uint8_t opt_type;
- uint8_t opt_length;
+ uint16_t opt_length;
/* Must have at least an OPEN option header */
if (STREAM_READABLE(s) < 2) {
@@ -1191,11 +1197,14 @@ int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability)
/* Fetch option type and length. */
opt_type = stream_getc(s);
- opt_length = stream_getc(s);
+ opt_length = BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(peer)
+ ? stream_getw(s)
+ : stream_getc(s);
/* Option length check. */
if (STREAM_READABLE(s) < opt_length) {
- zlog_info("%s Option length error", peer->host);
+ zlog_info("%s Option length error (%d)", peer->host,
+ opt_length);
bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR,
BGP_NOTIFY_OPEN_MALFORMED_ATTR);
return -1;
@@ -1299,9 +1308,10 @@ int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability)
}
static void bgp_open_capability_orf(struct stream *s, struct peer *peer,
- afi_t afi, safi_t safi, uint8_t code)
+ afi_t afi, safi_t safi, uint8_t code,
+ bool ext_opt_params)
{
- uint8_t cap_len;
+ uint16_t cap_len;
uint8_t orf_len;
unsigned long capp;
unsigned long orfp;
@@ -1315,7 +1325,8 @@ static void bgp_open_capability_orf(struct stream *s, struct peer *peer,
stream_putc(s, BGP_OPEN_OPT_CAP);
capp = stream_get_endp(s); /* Set Capability Len Pointer */
- stream_putc(s, 0); /* Capability Length */
+ ext_opt_params ? stream_putw(s, 0)
+ : stream_putc(s, 0); /* Capability Length */
stream_putc(s, code); /* Capability Code */
orfp = stream_get_endp(s); /* Set ORF Len Pointer */
stream_putc(s, 0); /* ORF Length */
@@ -1363,11 +1374,12 @@ static void bgp_open_capability_orf(struct stream *s, struct peer *peer,
/* Total Capability Len. */
cap_len = stream_get_endp(s) - capp - 1;
- stream_putc_at(s, capp, cap_len);
+ ext_opt_params ? stream_putw_at(s, capp, cap_len)
+ : stream_putc_at(s, capp, cap_len);
}
static void bgp_peer_send_gr_capability(struct stream *s, struct peer *peer,
- unsigned long cp)
+ bool ext_opt_params)
{
int len;
iana_afi_t pkt_afi;
@@ -1389,7 +1401,8 @@ static void bgp_peer_send_gr_capability(struct stream *s, struct peer *peer,
SET_FLAG(peer->cap, PEER_CAP_RESTART_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
capp = stream_get_endp(s); /* Set Capability Len Pointer */
- stream_putc(s, 0); /* Capability Length */
+ ext_opt_params ? stream_putw(s, 0)
+ : stream_putc(s, 0); /* Capability Length */
stream_putc(s, CAPABILITY_CODE_RESTART);
/* Set Restart Capability Len Pointer */
rcapp = stream_get_endp(s);
@@ -1444,11 +1457,12 @@ static void bgp_peer_send_gr_capability(struct stream *s, struct peer *peer,
/* Total Capability Len. */
len = stream_get_endp(s) - capp - 1;
- stream_putc_at(s, capp, len);
+ ext_opt_params ? stream_putw_at(s, capp, len - 1)
+ : stream_putc_at(s, capp, len);
}
static void bgp_peer_send_llgr_capability(struct stream *s, struct peer *peer,
- unsigned long cp)
+ bool ext_opt_params)
{
int len;
iana_afi_t pkt_afi;
@@ -1465,7 +1479,8 @@ static void bgp_peer_send_llgr_capability(struct stream *s, struct peer *peer,
stream_putc(s, BGP_OPEN_OPT_CAP);
capp = stream_get_endp(s); /* Set Capability Len Pointer */
- stream_putc(s, 0); /* Capability Length */
+ ext_opt_params ? stream_putw(s, 0)
+ : stream_putc(s, 0); /* Capability Length */
stream_putc(s, CAPABILITY_CODE_LLGR);
rcapp = stream_get_endp(s);
@@ -1491,14 +1506,16 @@ static void bgp_peer_send_llgr_capability(struct stream *s, struct peer *peer,
/* Total Capability Len. */
len = stream_get_endp(s) - capp - 1;
- stream_putc_at(s, capp, len);
+ ext_opt_params ? stream_putw_at(s, capp, len - 1)
+ : stream_putc_at(s, capp, len);
}
/* Fill in capability open option to the packet. */
-void bgp_open_capability(struct stream *s, struct peer *peer)
+uint16_t bgp_open_capability(struct stream *s, struct peer *peer,
+ bool ext_opt_params)
{
- uint8_t len;
- unsigned long cp, capp, rcapp;
+ uint16_t len;
+ unsigned long cp, capp, rcapp, eopl = 0;
iana_afi_t pkt_afi;
afi_t afi;
safi_t safi;
@@ -1507,16 +1524,26 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
uint8_t afi_safi_count = 0;
int adv_addpath_tx = 0;
- /* Remember current pointer for Opt Parm Len. */
+ /* Non-Ext OP Len. */
cp = stream_get_endp(s);
-
- /* Opt Parm Len. */
stream_putc(s, 0);
+ if (ext_opt_params) {
+ /* Non-Ext OP Len. */
+ stream_putc_at(s, cp, BGP_OPEN_NON_EXT_OPT_LEN);
+
+ /* Non-Ext OP Type */
+ stream_putc(s, BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH);
+
+ /* Extended Opt. Parm. Length */
+ eopl = stream_get_endp(s);
+ stream_putw(s, 0);
+ }
+
/* Do not send capability. */
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_CAPABILITY_OPEN)
|| CHECK_FLAG(peer->flags, PEER_FLAG_DONT_CAPABILITY))
- return;
+ return 0;
/* MP capability for configured AFI, SAFI */
FOREACH_AFI_SAFI (afi, safi) {
@@ -1527,7 +1554,9 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
peer->afc_adv[afi][safi] = 1;
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_MP_LEN + 2);
+ ext_opt_params
+ ? stream_putw(s, CAPABILITY_CODE_MP_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_MP_LEN + 2);
stream_putc(s, CAPABILITY_CODE_MP);
stream_putc(s, CAPABILITY_CODE_MP_LEN);
stream_putw(s, pkt_afi);
@@ -1547,7 +1576,13 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
*/
SET_FLAG(peer->cap, PEER_CAP_ENHE_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_ENHE_LEN + 2);
+ ext_opt_params
+ ? stream_putw(s,
+ CAPABILITY_CODE_ENHE_LEN
+ + 2)
+ : stream_putc(s,
+ CAPABILITY_CODE_ENHE_LEN
+ + 2);
stream_putc(s, CAPABILITY_CODE_ENHE);
stream_putc(s, CAPABILITY_CODE_ENHE_LEN);
@@ -1568,25 +1603,29 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
/* Route refresh. */
SET_FLAG(peer->cap, PEER_CAP_REFRESH_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_REFRESH_LEN + 2);
+ ext_opt_params ? stream_putw(s, CAPABILITY_CODE_REFRESH_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_REFRESH_LEN + 2);
stream_putc(s, CAPABILITY_CODE_REFRESH_OLD);
stream_putc(s, CAPABILITY_CODE_REFRESH_LEN);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_REFRESH_LEN + 2);
+ ext_opt_params ? stream_putw(s, CAPABILITY_CODE_REFRESH_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_REFRESH_LEN + 2);
stream_putc(s, CAPABILITY_CODE_REFRESH);
stream_putc(s, CAPABILITY_CODE_REFRESH_LEN);
/* Enhanced Route Refresh. */
SET_FLAG(peer->cap, PEER_CAP_ENHANCED_RR_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_ENHANCED_LEN + 2);
+ ext_opt_params ? stream_putw(s, CAPABILITY_CODE_ENHANCED_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_ENHANCED_LEN + 2);
stream_putc(s, CAPABILITY_CODE_ENHANCED_RR);
stream_putc(s, CAPABILITY_CODE_ENHANCED_LEN);
/* AS4 */
SET_FLAG(peer->cap, PEER_CAP_AS4_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_AS4_LEN + 2);
+ ext_opt_params ? stream_putw(s, CAPABILITY_CODE_AS4_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_AS4_LEN + 2);
stream_putc(s, CAPABILITY_CODE_AS4);
stream_putc(s, CAPABILITY_CODE_AS4_LEN);
if (peer->change_local_as)
@@ -1598,7 +1637,8 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
/* Extended Message Support */
SET_FLAG(peer->cap, PEER_CAP_EXTENDED_MESSAGE_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_EXT_MESSAGE_LEN + 2);
+ ext_opt_params ? stream_putw(s, CAPABILITY_CODE_EXT_MESSAGE_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_EXT_MESSAGE_LEN + 2);
stream_putc(s, CAPABILITY_CODE_EXT_MESSAGE);
stream_putc(s, CAPABILITY_CODE_EXT_MESSAGE_LEN);
@@ -1617,7 +1657,11 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
SET_FLAG(peer->cap, PEER_CAP_ADDPATH_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, (CAPABILITY_CODE_ADDPATH_LEN * afi_safi_count) + 2);
+ ext_opt_params
+ ? stream_putw(s, (CAPABILITY_CODE_ADDPATH_LEN * afi_safi_count)
+ + 2)
+ : stream_putc(s, (CAPABILITY_CODE_ADDPATH_LEN * afi_safi_count)
+ + 2);
stream_putc(s, CAPABILITY_CODE_ADDPATH);
stream_putc(s, CAPABILITY_CODE_ADDPATH_LEN * afi_safi_count);
@@ -1664,9 +1708,11 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
|| CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_ORF_PREFIX_RM)) {
bgp_open_capability_orf(s, peer, afi, safi,
- CAPABILITY_CODE_ORF_OLD);
+ CAPABILITY_CODE_ORF_OLD,
+ ext_opt_params);
bgp_open_capability_orf(s, peer, afi, safi,
- CAPABILITY_CODE_ORF);
+ CAPABILITY_CODE_ORF,
+ ext_opt_params);
}
}
@@ -1674,11 +1720,15 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
if (CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_CAPABILITY)) {
SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN + 2);
+ ext_opt_params
+ ? stream_putw(s, CAPABILITY_CODE_DYNAMIC_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN + 2);
stream_putc(s, CAPABILITY_CODE_DYNAMIC_OLD);
stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN + 2);
+ ext_opt_params
+ ? stream_putw(s, CAPABILITY_CODE_DYNAMIC_LEN + 2)
+ : stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN + 2);
stream_putc(s, CAPABILITY_CODE_DYNAMIC);
stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN);
}
@@ -1688,7 +1738,8 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
SET_FLAG(peer->cap, PEER_CAP_HOSTNAME_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
rcapp = stream_get_endp(s); /* Ptr to length placeholder */
- stream_putc(s, 0); /* dummy len for now */
+ ext_opt_params ? stream_putw(s, 0)
+ : stream_putc(s, 0); /* Capability Length */
stream_putc(s, CAPABILITY_CODE_FQDN);
capp = stream_get_endp(s);
stream_putc(s, 0); /* dummy len for now */
@@ -1710,7 +1761,9 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
/* Set the lengths straight */
len = stream_get_endp(s) - rcapp - 1;
- stream_putc_at(s, rcapp, len);
+ ext_opt_params ? stream_putw_at(s, rcapp, len - 1)
+ : stream_putc_at(s, rcapp, len);
+
len = stream_get_endp(s) - capp - 1;
stream_putc_at(s, capp, len);
@@ -1721,10 +1774,18 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
cmd_domainname_get());
}
- bgp_peer_send_gr_capability(s, peer, cp);
- bgp_peer_send_llgr_capability(s, peer, cp);
+ bgp_peer_send_gr_capability(s, peer, ext_opt_params);
+ bgp_peer_send_llgr_capability(s, peer, ext_opt_params);
/* Total Opt Parm Len. */
len = stream_get_endp(s) - cp - 1;
- stream_putc_at(s, cp, len);
+
+ if (ext_opt_params) {
+ len = stream_get_endp(s) - eopl - 2;
+ stream_putw_at(s, eopl, len);
+ } else {
+ stream_putc_at(s, cp, len);
+ }
+
+ return len;
}