Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: Add basic support of RFC 4684 - Routing Target (RT) Constrain #13476

Draft
wants to merge 40 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e76d547
lib: Add route target constraint SAFI value from RFC 4684
Sohn123 May 9, 2023
06c87b2
yang: Add yang-model for bgp route target constraint family
Sohn123 May 9, 2023
d64000b
bgpd: Add configuration for bgp route target constraint SAFI
Sohn123 May 9, 2023
b5aeab3
bgpd: Add RTC capability to negotiated capabilities
Sohn123 May 10, 2023
d9b29ac
Add prefix for SAFI_RTC
Sohn123 Jun 8, 2023
96bd25a
bgpd: Add static route configuration for SAFI_RTC.
Sohn123 Jun 8, 2023
68f3757
bgpd: Add encoding for SAFI_RTC attribute.
Sohn123 Jun 8, 2023
28ffa9b
lib,bgpd: Add prefix_list to peer to safe filters for Route target co…
Sohn123 Jun 8, 2023
9e85d34
bgpd: Add parsing for SAFI_RTC
Sohn123 Jun 8, 2023
3c1deb7
bgpd: Implement filtering via Route target constrain prefix list.
Sohn123 Jun 8, 2023
89273f9
bgpd: Improve display of rtc_prefix in show command.
Sohn123 Jun 8, 2023
a64b210
bgpd: Put every peer that has Route target constrain configured in se…
Sohn123 Jun 8, 2023
c9d377d
bgpd: No declaration after label.
Sohn123 Jun 13, 2023
b073cf7
bgpd: Use const pointer and copy value.
Sohn123 Jun 13, 2023
389cef7
bgpd: Add prototypes.
Sohn123 Jun 13, 2023
8de224e
bgpd: Initialize ret.
Sohn123 Jun 13, 2023
ea5501c
bgpd: format bgpd code
Sohn123 Jun 13, 2023
1854ce0
lib: Format lib code
Sohn123 Jun 13, 2023
393d1fd
vtysh: Format vtysh code
Sohn123 Jun 13, 2023
6d77dcc
lib: Add configurable empty_action for plist
Sohn123 Jun 14, 2023
99bb2e9
bgpd: Extract RTC code into extra functions and extra file
Sohn123 Jun 14, 2023
cf3d201
bgpd: Generate rtc prefixes from vni route-targets
Sohn123 Jun 14, 2023
9ba1eb6
bgpd: Remove RTC testcode
Sohn123 Jun 14, 2023
330fa84
bgpd: Remove unneccesarry table initialization in bgp_rtc.c
Sohn123 Jun 15, 2023
b93cd5c
bgpd: Rename rtc command to rt-constraint
Sohn123 Jun 21, 2023
a23bfd9
lib: Remove debug logging statements
Sohn123 Jun 21, 2023
d4c4474
bgpd: Remove unused str2prefix_rtc function
Sohn123 Jun 21, 2023
1f65c62
bgpd: Replace // with /* in bgp_rtc.c
Sohn123 Jun 21, 2023
ae6ac26
bgpd: Remove debug statements.
Sohn123 Jun 21, 2023
d015879
bgpd: Add vty output if RTC configuration fails
Sohn123 Jun 21, 2023
648af91
bgpd: Remove afi/safi check for rtc filtering to make it applicable f…
Sohn123 Jun 21, 2023
bcb5fb8
bgpd: Remove dead assignments
Sohn123 Jun 21, 2023
369578d
bgpd: Introduce proper debug statements in bgp_rtc_filter
Sohn123 Jun 21, 2023
302b0e5
bgpd: Adapt write_network for SAFI_RTC
Sohn123 Jun 21, 2023
296c2d5
bgpd: Fix update group compare function to allow for deletion
Sohn123 Jul 10, 2023
446b388
bgpd: correctly delete prefix list on peer close
Sohn123 Jul 24, 2023
a70f67f
bgpd: mark path as valid for RTC
Sohn123 Aug 9, 2023
5426941
bgpd: Fix use after free of ecommunities
Sohn123 Aug 10, 2023
c82e970
bgpd: fix call of bgp_withdraw, and definition of bgp_show_table_rd
Sohn123 Aug 26, 2024
4438486
vtysh: move install_node statement for bgp_rtc_node
Sohn123 Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4163,6 +4163,7 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi,
switch (nh_afi) {
case AFI_IP:
switch (safi) {
case SAFI_RTC:
case SAFI_UNICAST:
case SAFI_MULTICAST:
case SAFI_LABELED_UNICAST:
Expand Down Expand Up @@ -4196,6 +4197,7 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi,
break;
case AFI_IP6:
switch (safi) {
case SAFI_RTC:
case SAFI_UNICAST:
case SAFI_MULTICAST:
case SAFI_LABELED_UNICAST:
Expand Down Expand Up @@ -4311,6 +4313,12 @@ void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
case SAFI_ENCAP:
assert(!"Please add proper encoding of SAFI_ENCAP");
break;
case SAFI_RTC:
stream_putc(s, p->prefixlen);
stream_putl(s, p->u.prefix_rtc.origin_as);
stream_put(s, &p->u.prefix_rtc.route_target,
PSIZE(p->prefixlen) - 4);
break;
}
}

Expand Down Expand Up @@ -4349,6 +4357,8 @@ size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi,
case SAFI_FLOWSPEC:
size = ((struct prefix_fs *)p)->prefix.prefixlen;
break;
case SAFI_RTC:
size = p->prefixlen;
}

return size;
Expand Down
10 changes: 7 additions & 3 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "bgpd/bgp_trace.h"
#include "bgpd/bgp_mpath.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_rtc.h"

/*
* Definitions and external declarations.
Expand Down Expand Up @@ -547,8 +548,10 @@ static void map_vni_to_rt(struct bgp *bgp, struct bgpevpn *vpn,
/* Already mapped. */
return;

if (!irt)
if (!irt) {
irt = import_rt_new(bgp, &eval_tmp);
bgp_rtc_add_static(bgp, eval, BGP_RTC_MAX_PREFIXLEN);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always add a static RTC route regardless if the address family is configured for any peer. Is this problematic and if it is, is there a way to check if an address family is configured for at least one peer? I could also add a bgp option like advertis-all-vni that toggles the behavior of automatically generating RTC routes. Maybe even independent for l2vpn and l3vpn.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sohn123, please separate both variables: advertisement versus populating.

  • you populate a static RTC route in the BGP RIB.
  • you advertise to bgp peers the RTC route if the matching afi/safi is enabled

I think RTC will be enabled if either L2VPN or L3VPN is enabled on neighbors.
So RTC will be sent in this case.
I know you implemented something for L2VPN, and not for L3VPN.
I would say RTC should be common for both cases: are there many cases where both L3VPN and L2VPN are used?

about #13476 (comment),
I understand, RTC routes will have to be modified when dealing with iBGP, so I think this is something that will be done in bgp_updgrp_packet.c most probably. There is something done like that for BGP LU with label replacement.
I think this is something that can be done separately.

}

/* Add VNI to the hash list for this RT. */
listnode_add(irt->vnis, vpn);
Expand All @@ -559,11 +562,12 @@ static void map_vni_to_rt(struct bgp *bgp, struct bgpevpn *vpn,
* VNIs for this RT, then the RT hash is deleted.
*/
static void unmap_vni_from_rt(struct bgp *bgp, struct bgpevpn *vpn,
struct irt_node *irt)
struct irt_node *irt, struct ecommunity_val *eval)
{
/* Delete VNI from hash list for this RT. */
listnode_delete(irt->vnis, vpn);
if (!listnode_head(irt->vnis)) {
bgp_rtc_remove_static(bgp, eval, BGP_RTC_MAX_PREFIXLEN);
import_rt_free(bgp, irt);
}
}
Expand Down Expand Up @@ -6191,7 +6195,7 @@ void bgp_evpn_unmap_vni_from_its_rts(struct bgp *bgp, struct bgpevpn *vpn)

irt = lookup_import_rt(bgp, &eval_tmp);
if (irt)
unmap_vni_from_rt(bgp, vpn, irt);
unmap_vni_from_rt(bgp, vpn, irt, eval);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,12 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
}
}

/* Reset the rtc-plist */
if (peer->rtc_plist != NULL) {
prefix_list_delete(peer->rtc_plist);
peer->rtc_plist = NULL;
}

/* Reset keepalive and holdtime */
if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER)) {
peer->v_keepalive = peer->keepalive;
Expand Down
36 changes: 23 additions & 13 deletions bgpd/bgp_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ void bgp_capability_vty_out(struct vty *vty, struct peer *peer, bool use_json,
"capabilityErrorMultiProtocolSafi",
"flowspec");
break;
case SAFI_RTC:
json_object_string_add(
json_cap,
"capabilityErrorMultiProtocolSafi",
"rtc");
break;
case SAFI_UNSPEC:
case SAFI_MAX:
json_object_int_add(
Expand Down Expand Up @@ -250,6 +256,9 @@ void bgp_capability_vty_out(struct vty *vty, struct peer *peer, bool use_json,
case SAFI_EVPN:
vty_out(vty, "SAFI EVPN");
break;
case SAFI_RTC:
vty_out(vty, "SAFI RTC");
break;
case SAFI_UNSPEC:
case SAFI_MAX:
vty_out(vty, "SAFI Unknown %d ",
Expand Down Expand Up @@ -1475,19 +1484,20 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length,
error. */
if (*mp_capability
&& !CHECK_FLAG(peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY)) {
if (!peer->afc_nego[AFI_IP][SAFI_UNICAST]
&& !peer->afc_nego[AFI_IP][SAFI_MULTICAST]
&& !peer->afc_nego[AFI_IP][SAFI_LABELED_UNICAST]
&& !peer->afc_nego[AFI_IP][SAFI_MPLS_VPN]
&& !peer->afc_nego[AFI_IP][SAFI_ENCAP]
&& !peer->afc_nego[AFI_IP][SAFI_FLOWSPEC]
&& !peer->afc_nego[AFI_IP6][SAFI_UNICAST]
&& !peer->afc_nego[AFI_IP6][SAFI_MULTICAST]
&& !peer->afc_nego[AFI_IP6][SAFI_LABELED_UNICAST]
&& !peer->afc_nego[AFI_IP6][SAFI_MPLS_VPN]
&& !peer->afc_nego[AFI_IP6][SAFI_ENCAP]
&& !peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC]
&& !peer->afc_nego[AFI_L2VPN][SAFI_EVPN]) {
if (!peer->afc_nego[AFI_IP][SAFI_UNICAST] &&
!peer->afc_nego[AFI_IP][SAFI_MULTICAST] &&
!peer->afc_nego[AFI_IP][SAFI_LABELED_UNICAST] &&
!peer->afc_nego[AFI_IP][SAFI_MPLS_VPN] &&
!peer->afc_nego[AFI_IP][SAFI_ENCAP] &&
!peer->afc_nego[AFI_IP][SAFI_FLOWSPEC] &&
!peer->afc_nego[AFI_IP][SAFI_RTC] &&
!peer->afc_nego[AFI_IP6][SAFI_UNICAST] &&
!peer->afc_nego[AFI_IP6][SAFI_MULTICAST] &&
!peer->afc_nego[AFI_IP6][SAFI_LABELED_UNICAST] &&
!peer->afc_nego[AFI_IP6][SAFI_MPLS_VPN] &&
!peer->afc_nego[AFI_IP6][SAFI_ENCAP] &&
!peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC] &&
!peer->afc_nego[AFI_L2VPN][SAFI_EVPN]) {
flog_err(EC_BGP_PKT_OPEN,
"%s [Error] Configured AFI/SAFIs do not overlap with received MP capabilities",
peer->host);
Expand Down
4 changes: 4 additions & 0 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "bgpd/bgp_keepalives.h"
#include "bgpd/bgp_flowspec.h"
#include "bgpd/bgp_trace.h"
#include "bgpd/bgp_rtc.h"

DEFINE_HOOK(bgp_packet_dump,
(struct peer *peer, uint8_t type, bgp_size_t size,
Expand Down Expand Up @@ -351,6 +352,8 @@ int bgp_nlri_parse(struct peer *peer, struct attr *attr,
return bgp_nlri_parse_evpn(peer, attr, packet, mp_withdraw);
case SAFI_FLOWSPEC:
return bgp_nlri_parse_flowspec(peer, attr, packet, mp_withdraw);
case SAFI_RTC:
return bgp_nlri_parse_rtc(peer, attr, packet, mp_withdraw);
}
return BGP_NLRI_PARSE_ERROR;
}
Expand Down Expand Up @@ -2146,6 +2149,7 @@ static int bgp_open_receive(struct peer_connection *connection,
peer->afc[AFI_IP][SAFI_LABELED_UNICAST];
peer->afc_nego[AFI_IP][SAFI_FLOWSPEC] =
peer->afc[AFI_IP][SAFI_FLOWSPEC];
peer->afc_nego[AFI_IP][SAFI_RTC] = peer->afc[AFI_IP][SAFI_RTC];
peer->afc_nego[AFI_IP6][SAFI_UNICAST] =
peer->afc[AFI_IP6][SAFI_UNICAST];
peer->afc_nego[AFI_IP6][SAFI_MULTICAST] =
Expand Down
107 changes: 103 additions & 4 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/* BGP routing information
* Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
* Copyright (C) 2016 Job Snijders <[email protected]>
Expand Down Expand Up @@ -75,6 +74,7 @@
#include "bgpd/bgp_flowspec.h"
#include "bgpd/bgp_flowspec_util.h"
#include "bgpd/bgp_pbr.h"
#include "bgpd/bgp_rtc.h"

#include "bgpd/bgp_route_clippy.c"

Expand Down Expand Up @@ -2515,6 +2515,14 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
bgp_otc_egress(peer, attr))
return false;

/* RTC-Filtering */
if (peer->afc[AFI_IP][SAFI_RTC]) {
/* The update group should only have one peer */
onlypeer = SUBGRP_PFIRST(subgrp)->peer;
if (bgp_rtc_filter(onlypeer, attr, p))
return false;
}

if (filter->advmap.update_type == UPDATE_TYPE_WITHDRAW &&
filter->advmap.aname &&
route_map_lookup_by_name(filter->advmap.aname)) {
Expand Down Expand Up @@ -3549,6 +3557,7 @@ static void bgp_lu_handle_label_allocation(struct bgp *bgp,
CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) {
bgp_unregister_for_label(dest);
}

}

static struct interface *
Expand Down Expand Up @@ -6634,6 +6643,11 @@ static void bgp_nexthop_reachability_check(afi_t afi, safi_t safi,
struct bgp *bgp,
struct bgp *bgp_nexthop)
{
if (safi == SAFI_RTC) {
bgp_unlink_nexthop(bpi);

bgp_path_info_set_flag(dest, bpi, BGP_PATH_VALID);
}
/* Nexthop reachability check. */
if (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST) {
if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) {
Expand Down Expand Up @@ -6665,12 +6679,12 @@ static void bgp_nexthop_reachability_check(afi_t afi, safi_t safi,
}
}

static struct bgp_static *bgp_static_new(void)
struct bgp_static *bgp_static_new(void)
{
return XCALLOC(MTYPE_BGP_STATIC, sizeof(struct bgp_static));
}

static void bgp_static_free(struct bgp_static *bgp_static)
void bgp_static_free(struct bgp_static *bgp_static)
{
XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
route_map_counter_decrement(bgp_static->rmap.map);
Expand Down Expand Up @@ -12036,6 +12050,69 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t sa
return CMD_SUCCESS;
}

int bgp_show_table_rtc(struct vty *vty, struct bgp *bgp, safi_t safi,
struct bgp_table *table, enum bgp_show_type type,
void *output_arg, uint16_t show_flags);
int bgp_show_table_rtc(struct vty *vty, struct bgp *bgp, safi_t safi,
struct bgp_table *table, enum bgp_show_type type,
void *output_arg, uint16_t show_flags)
{
struct bgp_dest *dest, *next;
unsigned long output_cum = 0;
unsigned long total_cum = 0;
struct bgp_table *itable;
bool show_msg;
bool use_json = !!CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);

show_msg = (!use_json && type == bgp_show_type_normal);

for (dest = bgp_table_top(table); dest; dest = next) {
struct prefix local_p = {};
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
local_p = *dest_p;

next = bgp_route_next(dest);

itable = bgp_dest_get_bgp_table_info(dest);
if (itable != NULL) {

struct bgp_path_info *pi =
bgp_dest_get_bgp_path_info(dest);
struct ecommunity *ecom = ecommunity_parse(
local_p.u.prefix_rtc.route_target, 8, true);
char *ecomstr = ecommunity_ecom2str(
ecom, ECOMMUNITY_FORMAT_DISPLAY, 0);
vty_out(vty,
"Prefix: \n\tRoute Target: %s/%u\n\tOrigin-as: %u\n",
ecomstr, local_p.prefixlen,
local_p.u.prefix_rtc.origin_as);
XFREE(MTYPE_ECOMMUNITY_STR, ecomstr);
ecommunity_unintern(&ecom);
route_vty_out_detail_header(vty, bgp, dest, &local_p,
NULL, AFI_IP, safi, NULL,
false);
route_vty_out_detail(vty, bgp, dest, &local_p, pi,
AFI_IP, safi, RPKI_NOT_BEING_USED,
NULL);
if (next == NULL)
show_msg = false;
}
}
if (show_msg) {
if (output_cum == 0)
vty_out(vty, "No BGP prefixes displayed, %ld exist\n",
total_cum);
else
vty_out(vty,
"\nDisplayed %ld routes and %ld total paths\n",
output_cum, total_cum);
} else {
if (use_json && output_cum == 0)
vty_out(vty, "{}\n");
}
return CMD_SUCCESS;
}

int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
struct bgp_table *table, struct prefix_rd *prd_match,
enum bgp_show_type type, void *output_arg,
Expand Down Expand Up @@ -12481,6 +12558,7 @@ const struct prefix_rd *bgp_rd_from_dest(const struct bgp_dest *dest,
case SAFI_UNICAST:
case SAFI_MULTICAST:
case SAFI_LABELED_UNICAST:
case SAFI_RTC:
case SAFI_FLOWSPEC:
case SAFI_MAX:
return NULL;
Expand Down Expand Up @@ -16153,7 +16231,28 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi,

p = bgp_dest_get_prefix(dest);

vty_out(vty, " network %pFX", p);
if (safi == SAFI_RTC) {
/* Only prefixes with a length of more than 48 have the
* type and subtype field set. If those aren't set
* ecommunity_ecom2str returns just UNK: */
if (p->prefixlen >= 48) {
struct ecommunity *ecom = ecommunity_parse(
(unsigned char *)&p->u.prefix_rtc
.route_target,
8, false);
char *b = ecommunity_ecom2str(
ecom, ECOMMUNITY_FORMAT_ROUTE_MAP,
ECOMMUNITY_ROUTE_TARGET);
vty_out(vty, " rt %s", b);
ecommunity_unintern(&ecom);
XFREE(MTYPE_ECOMMUNITY_STR, b);
} else {
vty_out(vty, " rt 0:0");
}
vty_out(vty, "/%d", p->prefixlen);
} else {
vty_out(vty, " network %pFX", p);
}

if (bgp_static->label_index != BGP_INVALID_LABEL_INDEX)
vty_out(vty, " label-index %u",
Expand Down
8 changes: 8 additions & 0 deletions bgpd/bgp_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ extern int bgp_static_set(struct vty *vty, bool negate, const char *ip_str,
uint32_t label_index, int evpn_type, const char *esi,
const char *gwip, const char *ethtag,
const char *routermac);
extern struct bgp_static *bgp_static_new(void);
extern void bgp_static_free(struct bgp_static *bgp_static);

/* this is primarily for MPLS-VPN */
extern void bgp_update(struct peer *peer, const struct prefix *p,
Expand All @@ -800,6 +802,12 @@ extern void bgp_withdraw(struct peer *peer, const struct prefix *p,
int sub_type, struct prefix_rd *prd,
mpls_label_t *label, uint8_t num_labels);

extern void bgp_static_update(struct bgp *bgp, const struct prefix *p,
struct bgp_static *bgp_static, afi_t afi,
safi_t safi);
extern void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi, struct prefix_rd *prd);

/* for bgp_nexthop and bgp_damp */
extern void bgp_process(struct bgp *bgp, struct bgp_dest *dest,
struct bgp_path_info *pi, afi_t afi, safi_t safi);
Expand Down
Loading
Loading