Merge pull request #9538 from donaldsharp/bgp_view_not_working

Bgp view not working
This commit is contained in:
Igor Ryzhov 2021-09-02 19:21:47 +03:00 committed by GitHub
commit 3cb67fef98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 22 deletions

View File

@ -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;
return name;
if (peer->ifname)
return peer->ifname;
if (peer->bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
return NULL;
return peer->bgp->name;
}
static int bgp_update_address(struct interface *ifp, const union sockunion *dst,
@ -706,7 +706,8 @@ int bgp_connect(struct peer *peer)
ifindex_t ifindex = 0;
if (peer->conf_if && BGP_PEER_SU_UNSPEC(peer)) {
zlog_debug("Peer address not learnt: Returning from connect");
if (bgp_debug_neighbor_events(peer))
zlog_debug("Peer address not learnt: Returning from connect");
return 0;
}
frr_with_privs(&bgpd_privs) {
@ -714,8 +715,13 @@ int bgp_connect(struct peer *peer)
peer->fd = vrf_sockunion_socket(&peer->su, peer->bgp->vrf_id,
bgp_get_bound_name(peer));
}
if (peer->fd < 0)
if (peer->fd < 0) {
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s: Failure to create socket for connection to %s, error received: %s(%d)",
__func__, peer->host, safe_strerror(errno),
errno);
return -1;
}
set_nonblocking(peer->fd);
@ -725,8 +731,13 @@ int bgp_connect(struct peer *peer)
bgp_socket_set_buffer_size(peer->fd);
if (bgp_set_socket_ttl(peer, peer->fd) < 0)
if (bgp_set_socket_ttl(peer, peer->fd) < 0) {
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s: Failure to set socket ttl for connection to %s, error received: %s(%d)",
__func__, peer->host, safe_strerror(errno),
errno);
return -1;
}
sockopt_reuseaddr(peer->fd);
sockopt_reuseport(peer->fd);

View File

@ -3409,8 +3409,21 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name,
return ret;
bgp = bgp_create(as, name, inst_type);
if (bgp_option_check(BGP_OPT_NO_ZEBRA) && name)
bgp->vrf_id = vrf_generate_id();
/*
* view instances will never work inside of a vrf
* as such they must always be in the VRF_DEFAULT
* Also we must set this to something useful because
* of the vrf socket code needing an actual useful
* default value to send to the underlying OS.
*
* This code is currently ignoring vrf based
* code using the -Z option( and that is probably
* best addressed elsewhere in the code )
*/
if (inst_type == BGP_INSTANCE_TYPE_VIEW)
bgp->vrf_id = VRF_DEFAULT;
bgp_router_id_set(bgp, &bgp->router_id_zebra, true);
bgp_address_init(bgp);
bgp_tip_hash_init(bgp);

View File

@ -1068,13 +1068,6 @@ int vrf_sockunion_socket(const union sockunion *su, vrf_id_t vrf_id,
return ret;
}
vrf_id_t vrf_generate_id(void)
{
static int vrf_id_local;
return ++vrf_id_local;
}
/* ------- Northbound callbacks ------- */
/*

View File

@ -323,7 +323,6 @@ extern int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf,
extern void vrf_disable(struct vrf *vrf);
extern int vrf_enable(struct vrf *vrf);
extern void vrf_delete(struct vrf *vrf);
extern vrf_id_t vrf_generate_id(void);
extern const struct frr_yang_module_info frr_vrf_info;