/********************
* PRIVATE FUNCTIONS
********************/
+static int bgp_adj_out_compare(const struct bgp_adj_out *o1,
+ const struct bgp_adj_out *o2)
+{
+ if (o1->subgroup < o2->subgroup)
+ return -1;
+
+ if (o1->subgroup > o2->subgroup)
+ return 1;
+
+ return 0;
+}
+RB_GENERATE(bgp_adj_out_rb, bgp_adj_out, adj_entry, bgp_adj_out_compare);
static inline struct bgp_adj_out *adj_lookup(struct bgp_node *rn,
struct update_subgroup *subgrp,
uint32_t addpath_tx_id)
{
- struct bgp_adj_out *adj;
+ struct bgp_adj_out *adj, lookup;
struct peer *peer;
afi_t afi;
safi_t safi;
/* update-groups that do not support addpath will pass 0 for
* addpath_tx_id so do not both matching against it */
- for (adj = rn->adj_out; adj; adj = adj->next) {
- if (adj->subgroup == subgrp) {
- if (addpath_capable) {
- if (adj->addpath_tx_id == addpath_tx_id) {
- break;
- }
- } else {
- break;
- }
- }
+ lookup.subgroup = subgrp;
+ adj = RB_FIND(bgp_adj_out_rb, &rn->adj_out, &lookup);
+ if (adj) {
+ if (addpath_capable) {
+ if (adj->addpath_tx_id == addpath_tx_id)
+ return adj;
+ } else
+ return adj;
}
-
- return adj;
+ return NULL;
}
static void adj_free(struct bgp_adj_out *adj)
/* Look through all of the paths we have advertised for this rn and send
* a withdraw for the ones that are no longer present */
- for (adj = ctx->rn->adj_out; adj; adj = adj_next) {
- adj_next = adj->next;
+ RB_FOREACH_SAFE (adj, bgp_adj_out_rb, &ctx->rn->adj_out, adj_next) {
if (adj->subgroup == subgrp) {
for (pi = bgp_node_get_bgp_path_info(ctx->rn);
/* Find the addpath_tx_id of the path we
* had advertised and
* send a withdraw */
- for (adj = ctx->rn->adj_out; adj;
- adj = adj_next) {
- adj_next = adj->next;
-
+ RB_FOREACH_SAFE (adj, bgp_adj_out_rb,
+ &ctx->rn->adj_out,
+ adj_next) {
if (adj->subgroup == subgrp) {
subgroup_process_announce_selected(
subgrp, NULL,
output_count = 0;
for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn))
- for (adj = rn->adj_out; adj; adj = adj->next)
+ RB_FOREACH (adj, bgp_adj_out_rb, &rn->adj_out)
if (adj->subgroup == subgrp) {
if (header1) {
vty_out(vty,
adj = XCALLOC(MTYPE_BGP_ADJ_OUT, sizeof(struct bgp_adj_out));
adj->subgroup = subgrp;
if (rn) {
- BGP_ADJ_OUT_ADD(rn, adj);
+ RB_INSERT(bgp_adj_out_rb, &rn->adj_out, adj);
bgp_lock_node(rn);
adj->rn = rn;
}
subgroup_trigger_write(subgrp);
} else {
/* Remove myself from adjacency. */
- BGP_ADJ_OUT_DEL(rn, adj);
+ RB_REMOVE(bgp_adj_out_rb, &rn->adj_out, adj);
/* Free allocated information. */
adj_free(adj);
if (adj->adv)
bgp_advertise_clean_subgroup(subgrp, adj);
- BGP_ADJ_OUT_DEL(rn, adj);
+ RB_REMOVE(bgp_adj_out_rb, &rn->adj_out, adj);
adj_free(adj);
}
subgroup_announce_table(subgrp, NULL);
else
for (rn = bgp_table_top(update_subgroup_rib(subgrp)); rn;
- rn = bgp_route_next(rn))
- if ((table = (rn->info)) != NULL)
- subgroup_announce_table(subgrp, table);
+ rn = bgp_route_next(rn)) {
+ table = bgp_node_get_bgp_table_info(rn);
+ if (!table)
+ continue;
+ subgroup_announce_table(subgrp, table);
+ }
}
void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)