Skip to content

Commit

Permalink
export in bmp
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Younsi <[email protected]>
  • Loading branch information
mxyns committed Dec 6, 2023
1 parent 7b248d2 commit 8f5ccbb
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 69 deletions.
8 changes: 6 additions & 2 deletions bgpd/bgp_advertise.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ void bgp_adj_in_remove(struct bgp_dest **dest, afi_t afi, safi_t safi,
}

bool bgp_adj_in_unset(struct bgp_dest **dest, afi_t afi, safi_t safi,
struct peer *peer, uint32_t addpath_id)
struct peer *peer, uint32_t addpath_id,
struct local_path_id **lpid)
{
struct bgp_adj_in *adj;
struct bgp_adj_in *adj_next;
Expand All @@ -225,8 +226,11 @@ bool bgp_adj_in_unset(struct bgp_dest **dest, afi_t afi, safi_t safi,
while (adj) {
adj_next = adj->next;

if (adj->peer == peer && adj->addpath_rx_id == addpath_id)
if (adj->peer == peer && adj->addpath_rx_id == addpath_id) {
if (lpid)
*lpid = local_path_id_lock(adj->lpid);
bgp_adj_in_remove(dest, afi, safi, adj);
}

adj = adj_next;

Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_advertise.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ 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);
extern bool bgp_adj_in_unset(struct bgp_dest **dest, afi_t afi, safi_t safi,
struct peer *peer, uint32_t addpath_id);
struct peer *peer, uint32_t addpath_id, struct local_path_id **lpid);
extern void bgp_adj_in_remove(struct bgp_dest **dest, afi_t afi, safi_t safi,
struct bgp_adj_in *bai);

Expand Down
100 changes: 62 additions & 38 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "bgp_rd.h"
#include "bgpd/bgp_open.h"
#include "bgpd/bgp_aspath.h"
#include "bgpd/bgp_lpid.h"

static void bmp_close(struct bmp *bmp);
static struct bmp_bgp *bmp_bgp_find(struct bgp *bgp);
Expand Down Expand Up @@ -298,6 +299,9 @@ static inline void bmp_bqe_free(struct bmp_queue_entry *bqe)
if (!bqe)
return;

if (bqe->lpid)
local_path_id_unlock(bqe->lpid);

XFREE(MTYPE_BMP_QUEUE, bqe);
}

Expand Down Expand Up @@ -1395,7 +1399,7 @@ static void bmp_monitor(struct bmp *bmp, struct peer *peer, uint8_t flags,
uint8_t peer_type, const struct prefix *p,
struct prefix_rd *prd, struct attr *attr, afi_t afi,
safi_t safi, uint32_t addpath_id, time_t uptime,
struct bgp_path_info *bpi)
struct local_path_id *lpid, struct bgp_path_info *bpi)
{
struct stream *hdr, *msg;
struct timeval tv = { .tv_sec = uptime, .tv_usec = 0 };
Expand Down Expand Up @@ -1428,6 +1432,15 @@ static void bmp_monitor(struct bmp *bmp, struct peer *peer, uint8_t flags,
peer_distinguisher,
uptime == (time_t)(-1L) ? NULL : &uptime_real);

if (lpid) {
stream_putw(msg, 8);
stream_putw(msg, 9);
stream_putw(msg, 0);
stream_put(msg, (char *)lpid + sizeof(int), 9);
} else {
zlog_warn("%s: no lpid to identify the path", __func__);
}

stream_putl_at(hdr, BMP_LENGTH_POS,
stream_get_endp(hdr) + stream_get_endp(msg));

Expand Down Expand Up @@ -1480,10 +1493,11 @@ static int bmp_monitor_rib_out_pre_updgrp_walkcb(struct update_group *updgrp,
&ctx->bpi->tx_addpath);

bmp_monitor(ctx->bmp, PAF_PEER(paf), BMP_PEER_FLAG_O,
bmp_get_peer_type(PAF_PEER(paf)), bgp_dest_get_prefix(ctx->dest),
ctx->prd, ctx->attr, SUBGRP_AFI(subgrp),
bmp_get_peer_type(PAF_PEER(paf)),
bgp_dest_get_prefix(ctx->dest), ctx->prd,
ctx->attr, SUBGRP_AFI(subgrp),
SUBGRP_SAFI(subgrp), addpath_tx_id,
(time_t)(-1L), ctx->bpi);
(time_t)(-1L), ctx->bpi ? ctx->bpi->lpid : NULL, ctx->bpi);

*ctx->written_ref = true;
}
Expand Down Expand Up @@ -1564,10 +1578,11 @@ static int bmp_monitor_rib_out_post_updgrp_walkcb(struct update_group *updgrp,
SUBGRP_FOREACH_PEER (subgrp, paf) {
bmp_monitor(ctx->bmp, PAF_PEER(paf),
BMP_PEER_FLAG_O | BMP_PEER_FLAG_L,
bmp_get_peer_type(PAF_PEER(paf)), ctx->pfx, ctx->prd,
advertised_attr, SUBGRP_AFI(subgrp),
SUBGRP_SAFI(subgrp), addpath_tx_id,
(time_t)(-1L), ctx->bpi);
bmp_get_peer_type(PAF_PEER(paf)), ctx->pfx,
ctx->prd, advertised_attr,
SUBGRP_AFI(subgrp), SUBGRP_SAFI(subgrp),
addpath_tx_id, (time_t)(-1L),
ctx->bpi ? ctx->bpi->lpid : NULL, ctx->bpi);

*ctx->written_ref = true;
}
Expand Down Expand Up @@ -1801,9 +1816,9 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr)
bool written = false;

if (adjin) {
bmp_monitor(bmp, adjin->peer, 0, bmp_get_peer_type(adjin->peer), bn_p,
prd, adjin->attr, afi, safi, adjin->addpath_rx_id,
adjin->uptime, NULL);
bmp_monitor(bmp, adjin->peer, 0, bmp_get_peer_type(adjin->peer),
bn_p, prd, adjin->attr, afi, safi,
adjin->addpath_rx_id, adjin->uptime, adjin->lpid, NULL);
written = true;
}

Expand All @@ -1812,8 +1827,9 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr)
if (bpi && CHECK_FLAG(bpi->flags, BGP_PATH_VALID) &&
CHECK_FLAG(mon_flags, BMP_MON_IN_POSTPOLICY)) {
bmp_monitor(bmp, bpi->peer, BMP_PEER_FLAG_L,
bmp_get_peer_type(bpi->peer), bn_p, prd, bpi->attr, afi,
safi, bpi->addpath_rx_id, bpi->uptime, bpi);
bmp_get_peer_type(bpi->peer), bn_p, prd, bpi->attr,
afi, safi, bpi->addpath_rx_id, bpi->uptime,
bpi->lpid, bpi);

UNSET_FLAG(bpi->flags, BGP_PATH_BMP_ADJIN_CHG);
written = true;
Expand All @@ -1824,11 +1840,11 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr)
CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED | BGP_PATH_MULTIPATH);

if (bpi_selected && CHECK_FLAG(mon_flags, BMP_MON_LOC_RIB)) {
bmp_monitor(bmp, bpi->peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE, bn_p,
prd, bpi->attr, afi, safi, bpi->addpath_rx_id,
bmp_monitor(bmp, bpi->peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE,
bn_p, prd, bpi->attr, afi, safi, bpi->addpath_rx_id,
bpi && bpi->extra ? bpi->extra->bgp_rib_uptime
: (time_t)(-1L),
bpi);
bpi->lpid, bpi);
written = true;
}

Expand Down Expand Up @@ -2003,11 +2019,11 @@ static bool bmp_wrqueue_locrib(struct bmp *bmp, struct pullwr *pullwr)
/* rib-in post-policy configured and path is valid */
if (CHECK_FLAG(flags, BMP_MON_IN_POSTPOLICY) &&
CHECK_FLAG(bpi->flags, BGP_PATH_VALID)) {

// TODO lbpi is null here
bmp_monitor(bmp, peer, BMP_PEER_FLAG_L,
bmp_get_peer_type(peer), &bqe->p, prd,
bpi->attr, afi, safi, addpath_rx_id,
bpi->uptime, bpi);
bpi->uptime, bqe->lpid, bpi);
ribin = bpi;
written = true;
}
Expand All @@ -2016,13 +2032,13 @@ static bool bmp_wrqueue_locrib(struct bmp *bmp, struct pullwr *pullwr)
if (CHECK_FLAG(flags, BMP_MON_LOC_RIB) &&
CHECK_FLAG(bpi->flags,
BGP_PATH_SELECTED | BGP_PATH_MULTIPATH)) {

bmp_monitor(bmp, peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE,
&bqe->p, prd, bpi->attr, afi, safi,
addpath_rx_id,
// TODO lbpi is null here
bmp_monitor(bmp, peer, 0,
BMP_PEER_TYPE_LOC_RIB_INSTANCE, &bqe->p,
prd, bpi->attr, afi, safi, addpath_rx_id,
bpi->extra ? bpi->extra->bgp_rib_uptime
: (time_t)(-1L),
bpi);
bqe->lpid, bpi);
locrib = bpi;
written = true;
}
Expand All @@ -2036,15 +2052,15 @@ static bool bmp_wrqueue_locrib(struct bmp *bmp, struct pullwr *pullwr)
if (CHECK_FLAG(flags, BMP_MON_IN_POSTPOLICY) && !ribin) {
bmp_monitor(bmp, peer, BMP_PEER_FLAG_L, bmp_get_peer_type(peer),
&bqe->p, prd, NULL, afi, safi, addpath_rx_id,
(time_t)(-1), NULL);
(time_t)(-1), bqe->lpid, NULL);
written = true;
}

/* loc-rib path not found, send withdraw */
if (CHECK_FLAG(flags, BMP_MON_LOC_RIB) && !locrib) {
bmp_monitor(bmp, peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE, &bqe->p, prd,
NULL, afi, safi, addpath_rx_id, (time_t)(-1L),
NULL);
bmp_monitor(bmp, peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE,
&bqe->p, prd, NULL, afi, safi, addpath_rx_id,
(time_t)(-1L), bqe->lpid, NULL);
written = true;
}

Expand Down Expand Up @@ -2110,9 +2126,10 @@ static bool bmp_wrqueue_ribin(struct bmp *bmp, struct pullwr *pullwr)
break;
}

// TODO lbpi is null here
bmp_monitor(bmp, peer, 0, bmp_get_peer_type(peer), &bqe->p, prd,
adjin ? adjin->attr : NULL, afi, safi, addpath_rx_id,
adjin ? adjin->uptime : monotime(NULL), NULL);
adjin ? adjin->uptime : monotime(NULL), bqe->lpid, NULL);

written = true;

Expand Down Expand Up @@ -2188,7 +2205,7 @@ static bool bmp_wrqueue_ribout(struct bmp *bmp, struct pullwr *pullwr)

bmp_monitor(bmp, peer, BMP_PEER_FLAG_O, bmp_get_peer_type(peer),
&bqe->p, prd, bpi ? bpi->attr : NULL, afi, safi,
addpath_tx_id, (time_t)(-1L), bpi);
addpath_tx_id, (time_t)(-1L), bqe->lpid, bpi);

written = true;
}
Expand All @@ -2212,7 +2229,7 @@ static bool bmp_wrqueue_ribout(struct bmp *bmp, struct pullwr *pullwr)
bmp_monitor(bmp, peer, BMP_PEER_FLAG_L | BMP_PEER_FLAG_O,
bmp_get_peer_type(peer), &bqe->p, prd,
advertised_attr, afi, safi, addpath_tx_id,
(time_t)(-1L), NULL);
(time_t)(-1L), bqe->lpid, NULL);

written = true;
}
Expand Down Expand Up @@ -2294,7 +2311,7 @@ static struct bmp_queue_entry *
bmp_process_one(struct bmp_targets *bt, struct bmp_qhash_head *updhash,
struct bmp_qlist_head *updlist, afi_t afi, safi_t safi,
struct bgp_dest *bn, uint32_t addpath_id, struct peer *peer,
uint8_t mon_flag)
uint8_t mon_flag, struct local_path_id *lpid)
{
struct bmp_queue_entry *bqe, bqeref;
size_t refcount;
Expand All @@ -2310,6 +2327,7 @@ bmp_process_one(struct bmp_targets *bt, struct bmp_qhash_head *updhash,
bqeref.safi = safi;
bqeref.flags = mon_flag;
bqeref.addpath_id = addpath_id;
bqeref.lpid = lpid;

if ((afi == AFI_L2VPN && safi == SAFI_EVPN && bn->pdest) ||
(safi == SAFI_MPLS_VPN))
Expand All @@ -2331,6 +2349,7 @@ bmp_process_one(struct bmp_targets *bt, struct bmp_qhash_head *updhash,
} else {
bqe = XMALLOC(MTYPE_BMP_QUEUE, sizeof(*bqe));
memcpy(bqe, &bqeref, sizeof(*bqe));
local_path_id_lock(bqe->lpid);

bmp_qhash_add(updhash, bqe);
}
Expand All @@ -2348,7 +2367,8 @@ bmp_process_one(struct bmp_targets *bt, struct bmp_qhash_head *updhash,
*/
static int bmp_process_ribinpre(struct bgp *bgp, afi_t afi, safi_t safi,
struct bgp_dest *bn, uint32_t addpath_id,
struct peer *peer, bool post)
struct peer *peer, bool post,
struct local_path_id *lpid)
{
struct bmp_bgp *bmpbgp = bmp_bgp_find(peer->bgp);
struct bmp_targets *bt;
Expand Down Expand Up @@ -2388,7 +2408,7 @@ static int bmp_process_ribinpre(struct bgp *bgp, afi_t afi, safi_t safi,

struct bmp_queue_entry *new_item = bmp_process_one(
bt, &bt->mon_in_updhash, &bt->mon_in_updlist, afi, safi,
bn, addpath_id, peer, BMP_MON_IN_PREPOLICY);
bn, addpath_id, peer, BMP_MON_IN_PREPOLICY, lpid);

/* if bmp_process_one returns NULL
* we don't have anything to do next
Expand Down Expand Up @@ -2444,7 +2464,7 @@ static int bmp_process_ribinpost(struct bgp *bgp, afi_t afi, safi_t safi,
bt, &bt->mon_loc_updhash,
&bt->mon_loc_updlist, afi, safi, bn,
bpi->addpath_rx_id, bpi->peer,
BMP_MON_IN_POSTPOLICY);
BMP_MON_IN_POSTPOLICY, bpi->lpid);

new_head = !new_head ? new_item : new_head;

Expand Down Expand Up @@ -4105,13 +4125,13 @@ static int bmp_route_update(struct bgp *bgp, afi_t afi, safi_t safi,
new_head = bmp_process_one(
bt, &bt->mon_loc_updhash, &bt->mon_loc_updlist,
afi, safi, bn, old_route->addpath_rx_id,
old_route->peer, BMP_MON_LOC_RIB);
old_route->peer, BMP_MON_LOC_RIB, old_route->lpid);
}

struct bmp_queue_entry *new_item = bmp_process_one(
bt, &bt->mon_loc_updhash, &bt->mon_loc_updlist, afi,
safi, bn, updated_route->addpath_rx_id,
updated_route->peer, BMP_MON_LOC_RIB);
updated_route->peer, BMP_MON_LOC_RIB, updated_route->lpid);
new_head = !new_head ? new_item : new_head;

/* if bmp_process_one returns NULL
Expand Down Expand Up @@ -4140,7 +4160,8 @@ static int bmp_adj_out_changed(struct update_subgroup *subgrp,
struct bgp_dest *dest,
struct bgp_path_info *locked_path,
uint32_t addpath_id, struct attr *attr,
bool post_policy, bool withdraw)
bool post_policy, bool withdraw,
struct local_path_id *lpid)
{

if (!subgrp)
Expand Down Expand Up @@ -4209,6 +4230,9 @@ static int bmp_adj_out_changed(struct update_subgroup *subgrp,
struct peer *peer;
struct bmp *bmp;

if (!lpid && locked_path)
lpid = locked_path->lpid;

frr_each (bmp_targets, &bmpbgp->targets, bt) {
if (!CHECK_FLAG(bt->afimon[afi][safi], mon_flag))
continue;
Expand All @@ -4218,7 +4242,7 @@ static int bmp_adj_out_changed(struct update_subgroup *subgrp,

struct bmp_queue_entry *new_item = bmp_process_one(
bt, &bt->mon_out_updhash, &bt->mon_out_updlist,
afi, safi, dest, addpath_id, peer, mon_flag);
afi, safi, dest, addpath_id, peer, mon_flag, lpid);

/* if bmp_process_one returns NULL
* we don't have anything to do next
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct bmp_queue_entry {
struct bmp_qhash_item bhi;

uint32_t addpath_id;
struct local_path_id *lpid;

#define BMP_QUEUE_FLAGS_NONE (0)
uint8_t flags;
Expand Down
9 changes: 5 additions & 4 deletions bgpd/bgp_conditional_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
subgrp, dest, pi,
!addpath_capable
? 0
: bgp_addpath_id_for_peer(
peer, afi, safi,
&pi->tx_addpath),
: bgp_addpath_id_for_peer(peer,
afi,
safi,
&pi->tx_addpath),
&attr, false,
update_type == UPDATE_TYPE_ADVERTISE
? false
: true,
__func__);
__func__, pi->lpid);
}


Expand Down
Loading

0 comments on commit 8f5ccbb

Please sign in to comment.