This moves the count adjustments into prefix_adjout_update() in a similar
way that was just done for prefix_adjout_withdraw().
Having the counts closer to the actual places where things are
added/removed makes the code a bit easier to grasp. The if cascade in
the prefix_adjout_get != NULL case can be made more similar to the code in
prefix_adjout_withdraw().
--
:wq Claudio
Index: rde.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde.h,v
retrieving revision 1.246
diff -u -p -r1.246 rde.h
--- rde.h 2 Mar 2022 14:49:25 -0000 1.246
+++ rde.h 2 Mar 2022 15:03:27 -0000
@@ -594,7 +594,7 @@ int prefix_update(struct rib *, struct
int prefix_withdraw(struct rib *, struct rde_peer *, uint32_t,
struct bgpd_addr *, int);
void prefix_add_eor(struct rde_peer *, uint8_t);
-int prefix_adjout_update(struct rde_peer *, struct filterstate *,
+void prefix_adjout_update(struct rde_peer *, struct filterstate *,
struct bgpd_addr *, int, uint8_t);
void prefix_adjout_withdraw(struct prefix *);
void prefix_adjout_destroy(struct prefix *);
Index: rde_rib.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_rib.c,v
retrieving revision 1.231
diff -u -p -r1.231 rde_rib.c
--- rde_rib.c 2 Mar 2022 14:44:46 -0000 1.231
+++ rde_rib.c 2 Mar 2022 15:37:10 -0000
@@ -1163,29 +1163,27 @@ prefix_add_eor(struct rde_peer *peer, ui
/*
* Put a prefix from the Adj-RIB-Out onto the update queue.
*/
-int
+void
prefix_adjout_update(struct rde_peer *peer, struct filterstate *state,
struct bgpd_addr *prefix, int prefixlen, uint8_t vstate)
{
- struct prefix_tree *prefix_head = NULL;
struct rde_aspath *asp;
struct rde_community *comm;
struct prefix *p;
- int created = 0;
if ((p = prefix_adjout_get(peer, 0, prefix, prefixlen)) != NULL) {
if ((p->flags & PREFIX_FLAG_ADJOUT) == 0)
fatalx("%s: prefix without PREFIX_FLAG_ADJOUT hit",
__func__);
+
/* prefix is already in the Adj-RIB-Out */
if (p->flags & PREFIX_FLAG_WITHDRAW) {
- created = 1; /* consider this a new entry */
+ RB_REMOVE(prefix_tree,
+ &peer->withdraws[prefix->aid], p);
peer->up_wcnt--;
- prefix_head = &peer->withdraws[prefix->aid];
- RB_REMOVE(prefix_tree, prefix_head, p);
- } else if (p->flags & PREFIX_FLAG_DEAD) {
- created = 1; /* consider this a new entry */
- } else {
+ }
+ if ((p->flags & (PREFIX_FLAG_WITHDRAW | PREFIX_FLAG_DEAD)) ==
+ 0) {
if (prefix_nhflags(p) == state->nhflags &&
prefix_nexthop(p) == state->nexthop &&
communities_equal(&state->communities,
@@ -1196,22 +1194,23 @@ prefix_adjout_update(struct rde_peer *pe
p->validation_state = vstate;
p->lastchange = getmonotime();
p->flags &= ~PREFIX_FLAG_STALE;
- return 0;
+ return;
}
if (p->flags & PREFIX_FLAG_UPDATE) {
- /* created = 0 so up_nlricnt is not increased */
- prefix_head = &peer->updates[prefix->aid];
- RB_REMOVE(prefix_tree, prefix_head, p);
+ RB_REMOVE(prefix_tree,
+ &peer->updates[prefix->aid], p);
+ peer->up_nlricnt--;
}
/* unlink prefix so it can be relinked below */
prefix_unlink(p);
+ peer->prefix_out_cnt--;
}
+ /* nothing needs to be done for PREFIX_FLAG_DEAD and STALE */
p->flags &= ~PREFIX_FLAG_MASK;
} else {
p = prefix_alloc();
p->flags |= PREFIX_FLAG_ADJOUT;
- created = 1;
p->pt = pt_get(prefix, prefixlen);
if (p->pt == NULL)
@@ -1237,14 +1236,14 @@ prefix_adjout_update(struct rde_peer *pe
prefix_link(p, NULL, p->pt, peer, 0, asp, comm, state->nexthop,
state->nhflags, vstate);
+ peer->prefix_out_cnt++;
if (p->flags & PREFIX_FLAG_MASK)
fatalx("%s: bad flags %x", __func__, p->flags);
p->flags |= PREFIX_FLAG_UPDATE;
if (RB_INSERT(prefix_tree, &peer->updates[prefix->aid], p) != NULL)
fatalx("%s: RB tree invariant violated", __func__);
-
- return created;
+ peer->up_nlricnt++;
}
/*
@@ -1283,7 +1282,6 @@ prefix_adjout_withdraw(struct prefix *p)
p->flags |= PREFIX_FLAG_WITHDRAW;
if (RB_INSERT(prefix_tree, &peer->withdraws[p->pt->aid], p) != NULL)
fatalx("%s: RB tree invariant violated", __func__);
-
peer->up_wcnt++;
}
Index: rde_update.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_update.c,v
retrieving revision 1.135
diff -u -p -r1.135 rde_update.c
--- rde_update.c 2 Mar 2022 14:44:46 -0000 1.135
+++ rde_update.c 2 Mar 2022 15:02:28 -0000
@@ -168,14 +168,8 @@ again:
}
up_prep_adjout(peer, &state, addr.aid);
-
- /* only send update if path changed */
- if (prefix_adjout_update(peer, &state, &addr,
- new->pt->prefixlen, prefix_vstate(new)) == 1) {
- peer->prefix_out_cnt++;
- peer->up_nlricnt++;
- }
-
+ prefix_adjout_update(peer, &state, &addr,
+ new->pt->prefixlen, prefix_vstate(new));
rde_filterstate_clean(&state);
/* max prefix checker outbound */
@@ -229,13 +223,7 @@ up_generate_default(struct filter_head *
}
up_prep_adjout(peer, &state, addr.aid);
-
- if (prefix_adjout_update(peer, &state, &addr, 0, ROA_NOTFOUND) == 1) {
- peer->prefix_out_cnt++;
- peer->up_nlricnt++;
- }
-
- /* no longer needed */
+ prefix_adjout_update(peer, &state, &addr, 0, ROA_NOTFOUND);
rde_filterstate_clean(&state);
/* max prefix checker outbound */