Skip to content

Commit

Permalink
adj-rib-out, propagate ids, static, and vrf export
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Younsi <[email protected]>
  • Loading branch information
mxyns committed Dec 4, 2023
1 parent 99dadd0 commit 7b248d2
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 86 deletions.
13 changes: 11 additions & 2 deletions bgpd/bgp_advertise.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bool bgp_adj_out_lookup(struct peer *peer, struct bgp_dest *dest,

void bgp_adj_in_set(struct bgp_dest *dest, afi_t afi, safi_t safi,
struct peer *peer, struct attr *attr, uint32_t addpath_id,
struct local_path_id *lpid)
struct local_path_id **lpid)
{
struct bgp_adj_in *adj;

Expand All @@ -174,6 +174,10 @@ void bgp_adj_in_set(struct bgp_dest *dest, afi_t afi, safi_t safi,
bgp_attr_unintern(&adj->attr);
adj->attr = bgp_attr_intern(attr);
}

if (lpid)
*lpid = adj->lpid;

return;
}
}
Expand All @@ -183,7 +187,12 @@ void bgp_adj_in_set(struct bgp_dest *dest, afi_t afi, safi_t safi,
adj->attr = bgp_attr_intern(attr);
adj->uptime = monotime(NULL);
adj->addpath_rx_id = addpath_id;
adj->lpid = local_path_id_lock(lpid);
adj->lpid =
local_path_id_lock(local_path_id_allocate_bgp(peer->bgp, dest));

if (lpid)
*lpid = adj->lpid;

BGP_ADJ_IN_ADD(dest, adj);
bgp_dest_lock_node(dest);
}
Expand Down
5 changes: 4 additions & 1 deletion bgpd/bgp_advertise.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ struct bgp_adj_out {

uint32_t addpath_tx_id;

/* Local Path-ID */
struct local_path_id *lpid;

/* Advertised attribute. */
struct attr *attr;

Expand Down Expand Up @@ -140,7 +143,7 @@ extern bool bgp_adj_out_lookup(struct peer *peer, struct bgp_dest *dest,
uint32_t addpath_tx_id);
extern void bgp_adj_in_set(struct bgp_dest *dest, afi_t afi, safi_t safi,
struct peer *peer, struct attr *attr,
uint32_t addpath_id, struct local_path_id *lpid);
uint32_t addpath_id, struct local_path_id **lpid);
extern bool bgp_adj_in_unset(struct bgp_dest **dest, afi_t afi, safi_t safi,
struct peer *peer, uint32_t addpath_id);
extern void bgp_adj_in_remove(struct bgp_dest **dest, afi_t afi, safi_t safi,
Expand Down
6 changes: 3 additions & 3 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ static int update_evpn_type5_route_entry(struct bgp *bgp_evpn,

/* create the route info from attribute */
pi = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0,
bgp_evpn->peer_self, attr_new, dest);
bgp_evpn->peer_self, attr_new, dest, NULL, false);
SET_FLAG(pi->flags, BGP_PATH_VALID);

/* Type-5 routes advertise the L3-VNI */
Expand Down Expand Up @@ -1890,7 +1890,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,

/* Create new route with its attribute. */
tmp_pi = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0,
bgp->peer_self, attr_new, dest);
bgp->peer_self, attr_new, dest, NULL, false);
SET_FLAG(tmp_pi->flags, BGP_PATH_VALID);
bgp_path_info_extra_get(tmp_pi);

Expand Down Expand Up @@ -2846,7 +2846,7 @@ bgp_create_evpn_bgp_path_info(struct bgp_path_info *parent_pi,

/* Create new route with its attribute. */
pi = info_make(parent_pi->type, BGP_ROUTE_IMPORTED, 0, parent_pi->peer,
attr_new, dest);
attr_new, dest, NULL, false);
SET_FLAG(pi->flags, BGP_PATH_VALID);
bgp_path_info_extra_get(pi);
if (!pi->extra->vrfleak)
Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_evpn_mh.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static int bgp_evpn_es_route_install(struct bgp *bgp,

/* Create new route with its attribute. */
pi = info_make(parent_pi->type, BGP_ROUTE_IMPORTED, 0,
parent_pi->peer, attr_new, dest);
parent_pi->peer, attr_new, dest, NULL, false);
SET_FLAG(pi->flags, BGP_PATH_VALID);
bgp_path_info_extra_get(pi);
if (!pi->extra->vrfleak)
Expand Down Expand Up @@ -394,7 +394,7 @@ int bgp_evpn_mh_route_update(struct bgp *bgp, struct bgp_evpn_es *es,

/* Create new route with its attribute. */
tmp_pi = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0,
bgp->peer_self, attr_new, dest);
bgp->peer_self, attr_new, dest, NULL, false);
SET_FLAG(tmp_pi->flags, BGP_PATH_VALID);

if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE) {
Expand Down
10 changes: 6 additions & 4 deletions bgpd/bgp_lpid.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"

DECLARE_MTYPE(LPID_BGP);
DEFINE_MGROUP(LPID, "Local Path-ID");
DEFINE_MTYPE(LPID, LPID_BGP, "BGP Local-Path ID");

struct local_path_id *local_path_id_allocate_bgp(struct bgp *bgp, struct bgp_dest *dest) {

Expand Down Expand Up @@ -62,7 +63,8 @@ struct local_path_id *local_path_id_allocate_bgp(struct bgp *bgp, struct bgp_des
return lpid;
};

struct local_path_id *local_path_id_lock(struct local_path_id *lpid) {
struct local_path_id *local_path_id_lock(struct local_path_id *lpid)
{
if (lpid)
lpid->lock++;

Expand All @@ -73,8 +75,8 @@ void local_path_id_free(struct local_path_id *lpid) {
XFREE(MTYPE_LPID_BGP, lpid);
}

void local_path_id_unlock(struct local_path_id *lpid) {

void local_path_id_unlock(struct local_path_id *lpid)
{
assert(lpid && lpid->lock > 0);
lpid->lock--;

Expand Down
5 changes: 3 additions & 2 deletions bgpd/bgp_lpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

#include "lib/typesafe.h"

DEFINE_MGROUP(LPID, "Local Path-ID");
DEFINE_MTYPE(LPID, LPID_BGP, "BGP Local-Path ID");
DECLARE_MGROUP(LPID);
DECLARE_MTYPE(LPID_BGP);


struct local_path_id {
int lock;
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
}

new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_IMPORTED, 0,
to_bgp->peer_self, new_attr, bn);
to_bgp->peer_self, new_attr, bn, source_bpi->lpid,
false);

bgp_path_info_extra_get(new);
if (!new->extra->vrfleak)
Expand Down
151 changes: 93 additions & 58 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "bgpd/bgp_flowspec.h"
#include "bgpd/bgp_flowspec_util.h"
#include "bgpd/bgp_pbr.h"
#include "bgpd/bgp_rd.h"

#include "bgpd/bgp_route_clippy.c"

Expand Down Expand Up @@ -4066,7 +4067,8 @@ static void bgp_rib_withdraw(struct bgp_dest *dest, struct bgp_path_info *pi,

struct bgp_path_info *info_make(int type, int sub_type, unsigned short instance,
struct peer *peer, struct attr *attr,
struct bgp_dest *dest)
struct bgp_dest *dest,
struct local_path_id *lpid, bool generate_lpid)
{
struct bgp_path_info *new;

Expand All @@ -4079,6 +4081,12 @@ struct bgp_path_info *info_make(int type, int sub_type, unsigned short instance,
new->attr = attr;
new->uptime = monotime(NULL);
new->net = dest;

if (generate_lpid && !lpid)
lpid = local_path_id_allocate_bgp(peer->bgp, dest);

new->lpid = local_path_id_lock(lpid);

return new;
}

Expand Down Expand Up @@ -4323,8 +4331,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
memcpy(&attr->evpn_overlay, evpn,
sizeof(struct bgp_route_evpn));
}
lpid = local_path_id_allocate_bgp(bgp, dest);
bgp_adj_in_set(dest, afi, safi, peer, attr, addpath_id, lpid);
bgp_adj_in_set(dest, afi, safi, peer, attr, addpath_id, &lpid);
}

/* Update permitted loop count */
Expand Down Expand Up @@ -4970,7 +4977,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
}

/* Make new BGP info. */
new = info_make(type, sub_type, 0, peer, attr_new, dest);
new = info_make(type, sub_type, 0, peer, attr_new, dest, lpid, true);

/* Update MPLS label */
if (has_valid_label) {
Expand Down Expand Up @@ -5038,12 +5045,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
/* Addpath ID */
new->addpath_rx_id = addpath_id;

/* Local Path-Id */
if (!lpid)
lpid = local_path_id_allocate_bgp(bgp, dest);

new->lpid = local_path_id_lock(lpid);

/* Increment prefix */
bgp_aggregate_increment(bgp, p, new, afi, safi);

Expand Down Expand Up @@ -6615,7 +6616,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,

/* Make new BGP info. */
new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
attr_new, dest);
attr_new, dest, NULL, true);

if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN) {
SET_FLAG(new->flags, BGP_PATH_VALID);
Expand Down Expand Up @@ -7482,7 +7483,7 @@ static void bgp_aggregate_install(
}

new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0,
bgp->peer_self, attr, dest);
bgp->peer_self, attr, dest, NULL, false);

SET_FLAG(new->flags, BGP_PATH_VALID);

Expand Down Expand Up @@ -8796,7 +8797,7 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
}

new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance,
bgp->peer_self, new_attr, bn);
bgp->peer_self, new_attr, bn, NULL, false);
SET_FLAG(new->flags, BGP_PATH_VALID);

bgp_aggregate_increment(bgp, p, new, afi, SAFI_UNICAST);
Expand Down Expand Up @@ -15954,71 +15955,105 @@ void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi,
}
}

static void show_lpid(struct vty *vty, struct local_path_id *lpid) {
if (lpid)
vty_out(vty, "local-path-id %p = {pid=%d, vrf=%"PRIu32", path_id=%"PRIu8", lock=%d}\n", lpid, lpid->process_id, lpid->vrf_id, lpid->path_id, lpid->lock);
else
vty_out(vty, "local-path-id { NULL }\n");
}

static void show_all_lpids(struct vty *vty, const struct prefix *prefix, struct bgp_dest *dest) {

for (struct bgp_adj_in *adj = dest->adj_in; adj; adj = adj->next) {
vty_out(vty, "[adj-in] Prefix %pBD from peer %pBP ", dest, adj->peer);
show_lpid(vty, adj->lpid);
}

for (struct bgp_path_info *bpi = bgp_dest_get_bgp_path_info(dest); bpi; bpi = bpi->next) {
vty_out(vty, "[loc-rib] Prefix %pBD from peer %pBP ", dest, bpi->peer);
show_lpid(vty, bpi->lpid);
}

struct bgp_adj_out *adj;
RB_FOREACH (adj, bgp_adj_out_rb, &dest->adj_out) {
vty_out(vty, "[adj-out] Prefix %pBD (can't track original peer) ", dest);
show_lpid(vty, adj->lpid);
}

}

DEFUN (show_bgp_local_path_id,
DEFPY (show_bgp_local_path_id,
show_bgp_local_path_id_cmd,
"show bgp local-path-id <ipv4|ipv6> <A.B.C.D/M|X:X::X:X/M>",
SHOW_STR
BGP_STR
"local path identifier\n"
BGP_AF_STR
BGP_AF_STR
"show bgp local-path-id [<vrf|view> VIEWVRFNAME$vrf] [<ipv4|ipv6>$afi] [<unicast|multipath|vpn>$safi] <A.B.C.D/M|X:X::X:X/M>$prefix",
SHOW_STR
BGP_STR
"local path identifier\n"
BGP_INSTANCE_HELP_STR
BGP_AF_STR
BGP_AF_STR
BGP_AF_MODIFIER_STR
BGP_AF_MODIFIER_STR
BGP_AF_MODIFIER_STR
"Network in the BGP routing table to display\n"
"Network in the BGP routing table to display\n")
{

int idx = AFI_IP;
char *network = NULL;
afi_t afi;
safi_t safi = SAFI_UNICAST;
afi_t afiz = AFI_IP;
safi_t safiz = SAFI_UNICAST;

argv_find_and_parse_afi(argv, argc, &idx, &afi);
if (afi)
afiz = bgp_vty_afi_from_str(afi);

zlog_tls_buffer_flush();
if (safi)
safiz = bgp_vty_safi_from_str(safi);

if (argv_find(argv, argc, "A.B.C.D/M", &idx) ||
argv_find(argv, argc, "X:X::X:X/M", &idx)) {
network = argv[idx]->arg;
} else {
vty_out(vty, "Unable to figure out Network\n");
return CMD_WARNING;
}
struct bgp *bgp = vrf ? bgp_lookup_by_name(vrf) : bgp_get_default();

zlog_tls_buffer_flush();

struct prefix p;
if (!str2prefix(network, &p)) {
if (!bgp)
return CMD_ERR_NO_MATCH;
}

zlog_info("afi=%d safi=%d => %s", afiz, safiz, get_afi_safi_str(afiz, safiz, false));
zlog_info("bgp %p %s, prefix=%pFX", bgp, bgp ? bgp->name_pretty : "None", prefix);
zlog_tls_buffer_flush();

struct bgp *bgp = bgp_get_default();
struct bgp_dest *dest = bgp_safi_node_lookup(bgp->rib[afi][safi], safi, &p, NULL);
struct bgp_table *rib = bgp->rib[afiz][safiz];
if (safiz == SAFI_MPLS_VPN) {
for (struct bgp_dest *dest = bgp_table_top(rib); dest;
dest = bgp_route_next(dest)) {
struct bgp_table *table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;

zlog_tls_buffer_flush();
struct prefix_rd *prd = (struct prefix_rd *)bgp_dest_get_prefix(dest);

if (!dest) {
return CMD_ERR_NO_MATCH;
}
if (prd) {
vty_out(vty, "VPN RD: ");
vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation), prd);
vty_out(vty, "\n");
}
else vty_out(vty, "prd null\n");

for (struct bgp_adj_in *adj = dest->adj_in; adj; adj = adj->next) {
vty_out(vty, "[adj-in] Prefix %pFX from peer %pBP ", &p, adj->peer);
if (adj->lpid)
vty_out(vty, "local-path-id {pid=%d, vrf=%"PRIu32", path_id=%"PRIu8"}\n", adj->lpid->process_id, adj->lpid->vrf_id, adj->lpid->path_id);
else
vty_out(vty, "local-path-id { NULL }\n");
}
struct bgp_dest *ndest = bgp_safi_node_lookup(rib, safiz, prefix, prd);

for (struct bgp_path_info *bpi = bgp_dest_get_bgp_path_info(dest); bpi; bpi = bpi->next) {
vty_out(vty, "[loc-rib] Prefix %pFX from peer %pBP ", &p, bpi->peer);
if (bpi->lpid)
vty_out(vty, "local-path-id {pid=%d, vrf=%"PRIu32", path_id=%"PRIu8"}\n", bpi->lpid->process_id, bpi->lpid->vrf_id, bpi->lpid->path_id);
else
vty_out(vty, "local-path-id { NULL }\n");
if (!ndest)
continue;

show_all_lpids(vty, prefix, ndest);

bgp_dest_unlock_node(ndest);
}
} else {
struct bgp_dest *dest = bgp_safi_node_lookup(rib, safiz, prefix, NULL);

if (!dest) {
return CMD_ERR_NO_MATCH;
}

show_all_lpids(vty, prefix, dest);

bgp_dest_unlock_node(dest);
}

bgp_dest_unlock_node(dest);
return CMD_SUCCESS;
}

Expand Down
Loading

0 comments on commit 7b248d2

Please sign in to comment.