From 35a1e798f8bacf1bcfec7cfabe7c05432323ca23 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 15 Aug 2021 10:15:38 -0400 Subject: [PATCH] bgpd: Limit processing to what is needed in rpki validation The processing was looping over all bgp instances then over all peers then over all safi's to find a match for a prefix received in order to validate it. Suppose you have 100 peers each sending you the same prefix. This code will cause it to look at each node 100 times since we look at for each peer. This is especially egregarious because we never ever do anything with the peer when we are looping over them. Remove the peer loop, significantly reduce processing. Signed-off-by: Donald Sharp --- bgpd/bgp_rpki.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index a8bccecacf..451264ef7d 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -388,33 +388,25 @@ static int bgpd_sync_callback(struct thread *thread) afi_t afi = (rec.prefix.ver == LRTR_IPV4) ? AFI_IP : AFI_IP6; for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp)) { - struct peer *peer; - struct listnode *peer_listnode; - - for (ALL_LIST_ELEMENTS_RO(bgp->peer, peer_listnode, peer)) { - safi_t safi; - - for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { - if (!peer->bgp->rib[afi][safi]) - continue; + safi_t safi; - struct bgp_dest *match; - struct bgp_dest *node; + for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { + if (!bgp->rib[afi][safi]) + continue; - match = bgp_table_subtree_lookup( - peer->bgp->rib[afi][safi], prefix); - node = match; + struct bgp_dest *match; + struct bgp_dest *node; - while (node) { - if (bgp_dest_has_bgp_path_info_data( - node)) { - revalidate_bgp_node(node, afi, - safi); - } + match = bgp_table_subtree_lookup(bgp->rib[afi][safi], + prefix); + node = match; - node = bgp_route_next_until(node, - match); + while (node) { + if (bgp_dest_has_bgp_path_info_data(node)) { + revalidate_bgp_node(node, afi, safi); } + + node = bgp_route_next_until(node, match); } } } -- 2.39.5