From 55443115621c4e1b7b2478bdf5d1d19178b6cf06 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 6 Aug 2020 17:23:06 +0200 Subject: [PATCH] bgpd: implement bgpPeerTable accross VRFs Currently, bgpPeerTable only looks the default BGP instance. Most vendors return all the available peers in this table. This commit exposes all BGP instances. The other tables are unchanged as it doesn't make sense to expose routes from random VRFs into a single table. Vendors are using SNMP contexts for that but we don't have support for it. Therefore, do nothing. Fix #6077 Signed-off-by: Vincent Bernat --- bgpd/bgp_snmp.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index 719ff1452b..303f4ca56e 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -356,17 +356,16 @@ static struct peer *peer_lookup_addr_ipv4(struct in_addr *src) struct bgp *bgp; struct peer *peer; struct listnode *node; + struct listnode *bgpnode; - bgp = bgp_get_default(); - if (!bgp) - return NULL; + for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { + for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + if (sockunion_family(&peer->su) != AF_INET) + continue; - for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - if (sockunion_family(&peer->su) != AF_INET) - continue; - - if (sockunion2ip(&peer->su) == src->s_addr) - return peer; + if (sockunion2ip(&peer->su) == src->s_addr) + return peer; + } } return NULL; @@ -378,21 +377,20 @@ static struct peer *bgp_peer_lookup_next(struct in_addr *src) struct peer *peer; struct peer *next_peer = NULL; struct listnode *node; - - bgp = bgp_get_default(); - if (!bgp) - return NULL; - - for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - if (sockunion_family(&peer->su) != AF_INET) - continue; - if (ntohl(sockunion2ip(&peer->su)) <= ntohl(src->s_addr)) - continue; - - if (!next_peer - || ntohl(sockunion2ip(&next_peer->su)) - > ntohl(sockunion2ip(&peer->su))) { - next_peer = peer; + struct listnode *bgpnode; + + for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { + for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + if (sockunion_family(&peer->su) != AF_INET) + continue; + if (ntohl(sockunion2ip(&peer->su)) <= ntohl(src->s_addr)) + continue; + + if (!next_peer + || ntohl(sockunion2ip(&next_peer->su)) + > ntohl(sockunion2ip(&peer->su))) { + next_peer = peer; + } } } -- 2.39.5