Skip to content

Commit

Permalink
bgpd: Fix no form for neighbor X capability software-version
Browse files Browse the repository at this point in the history
If `bgp default software-version-capability` is enabled, allow unsetting this
for a single neighbor also.

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Mar 9, 2024
1 parent aa6ceee commit 70b4f5b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 30 deletions.
1 change: 0 additions & 1 deletion bgpd/bgp_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,6 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer,
* or disable its use, and that switch MUST be off by default.
*/
if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION) ||
CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SOFT_VERSION_CAPABILITY) ||
peer->sort == BGP_PEER_IBGP || peer->sub_sort == BGP_PEER_EBGP_OAD) {
SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
Expand Down
65 changes: 39 additions & 26 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,37 +1240,50 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
/* Encode MP_EXT capability. */
switch (capability_code) {
case CAPABILITY_CODE_SOFT_VERSION:
SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_ADV);
stream_putc(s, action);
stream_putc(s, CAPABILITY_CODE_SOFT_VERSION);
cap_len = stream_get_endp(s);
stream_putc(s, 0); /* Capability Length */

/* The Capability Length SHOULD be no greater than 64.
* This is the limit to allow other capabilities as much
* space as they require.
/* Software Version capability
* An implementation is REQUIRED Extended Optional Parameters
* Length for BGP OPEN Message support as defined in [RFC9072].
* The inclusion of the Software Version Capability is OPTIONAL.
* If an implementation supports the inclusion of the capability,
* the implementation MUST include a configuration switch to enable
* or disable its use, and that switch MUST be off by default.
*/
const char *soft_version = cmd_software_version_get();
if (peergroup_flag_check(peer,
PEER_FLAG_CAPABILITY_SOFT_VERSION) ||
peer->sort == BGP_PEER_IBGP ||
peer->sub_sort == BGP_PEER_EBGP_OAD) {
SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_ADV);
stream_putc(s, action);
stream_putc(s, CAPABILITY_CODE_SOFT_VERSION);
cap_len = stream_get_endp(s);
stream_putc(s, 0); /* Capability Length */

len = strlen(soft_version);
if (len > BGP_MAX_SOFT_VERSION)
len = BGP_MAX_SOFT_VERSION;
/* The Capability Length SHOULD be no greater than 64.
* This is the limit to allow other capabilities as much
* space as they require.
*/
const char *soft_version = cmd_software_version_get();

stream_putc(s, len);
stream_put(s, soft_version, len);
len = strlen(soft_version);
if (len > BGP_MAX_SOFT_VERSION)
len = BGP_MAX_SOFT_VERSION;

/* Software Version capability Len. */
len = stream_get_endp(s) - cap_len - 1;
stream_putc_at(s, cap_len, len);
stream_putc(s, len);
stream_put(s, soft_version, len);

if (bgp_debug_neighbor_events(peer))
zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s",
peer,
action == CAPABILITY_ACTION_SET
? "Advertising"
: "Removing",
capability, iana_afi2str(pkt_afi),
iana_safi2str(pkt_safi));
/* Software Version capability Len. */
len = stream_get_endp(s) - cap_len - 1;
stream_putc_at(s, cap_len, len);

if (bgp_debug_neighbor_events(peer))
zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s",
peer,
action == CAPABILITY_ACTION_SET
? "Advertising"
: "Removing",
capability, iana_afi2str(pkt_afi),
iana_safi2str(pkt_safi));
}
break;
case CAPABILITY_CODE_MP:
stream_putc(s, action);
Expand Down
16 changes: 13 additions & 3 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -18416,9 +18416,19 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
}

/* capability software-version */
if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION))
vty_out(vty, " neighbor %s capability software-version\n",
addr);
if (CHECK_FLAG(bgp->flags, BGP_FLAG_SOFT_VERSION_CAPABILITY)) {
if (!peergroup_flag_check(peer,
PEER_FLAG_CAPABILITY_SOFT_VERSION))
vty_out(vty,
" no neighbor %s capability software-version\n",
addr);
} else {
if (peergroup_flag_check(peer,
PEER_FLAG_CAPABILITY_SOFT_VERSION))
vty_out(vty,
" neighbor %s capability software-version\n",
addr);
}

/* dont-capability-negotiation */
if (peergroup_flag_check(peer, PEER_FLAG_DONT_CAPABILITY))
Expand Down
3 changes: 3 additions & 0 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,9 @@ struct peer *peer_new(struct bgp *bgp)
if (CHECK_FLAG(bgp->flags, BGP_FLAG_ENFORCE_FIRST_AS))
SET_FLAG(peer->flags, PEER_FLAG_ENFORCE_FIRST_AS);

if (CHECK_FLAG(bgp->flags, BGP_FLAG_SOFT_VERSION_CAPABILITY))
SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_SOFT_VERSION);

SET_FLAG(peer->flags_invert, PEER_FLAG_CAPABILITY_FQDN);
SET_FLAG(peer->flags, PEER_FLAG_CAPABILITY_FQDN);

Expand Down

0 comments on commit 70b4f5b

Please sign in to comment.