From 7224dcd86a9e8bee0430801f16c137721b2fb8dc Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Thu, 2 Sep 2021 15:29:18 +0300 Subject: [PATCH] bgpd: fix bgp_get_bound_name to handle views better The vrf socket code needs a interface/vrf name to be passed in, in order for it to properly bind to the correct vrf. In the case where bgp is using a view based instance the bgp_get_bound_name should handle views better and not return anything to be bound to. Fixes #9519. Signed-off-by: Igor Ryzhov --- bgpd/bgp_network.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 3c061ef1e0..7c9aa44c80 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -611,8 +611,6 @@ static int bgp_accept(struct thread *thread) /* BGP socket bind. */ static char *bgp_get_bound_name(struct peer *peer) { - char *name = NULL; - if (!peer) return NULL; @@ -628,14 +626,16 @@ static char *bgp_get_bound_name(struct peer *peer) * takes precedence over VRF. For IPv4 peering, explicit interface or * VRF are the situations to bind. */ - if (peer->su.sa.sa_family == AF_INET6) - name = (peer->conf_if ? peer->conf_if - : (peer->ifname ? peer->ifname - : peer->bgp->name)); - else - name = peer->ifname ? peer->ifname : peer->bgp->name; + if (peer->su.sa.sa_family == AF_INET6 && peer->conf_if) + return peer->conf_if; + + if (peer->ifname) + return peer->ifname; + + if (peer->bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) + return NULL; - return name; + return peer->bgp->name; } static int bgp_update_address(struct interface *ifp, const union sockunion *dst, -- 2.39.5