#include "bgpd/bgp_mpath.h"
#include "bgpd/bgp_nexthop.h"
#include "bgpd/bgp_nht.h"
+#include "bgpd/bgp_bfd.h"
+#if ENABLE_BGP_VNC
+# include "bgpd/rfapi/rfapi_backend.h"
+# include "bgpd/rfapi/vnc_export_bgp.h"
+#endif
/* All information about zebra. */
struct zclient *zclient = NULL;
return 1;
}
+int zclient_num_connects;
+
/* Router-id update message from zebra. */
static int
bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length,
for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
{
+#if defined(HAVE_CUMULUS)
+ /* Take down directly connected EBGP peers as well as 1-hop BFD
+ * tracked (directly connected) IBGP peers.
+ */
+ if ((peer->ttl != 1) && (peer->gtsm_hops != 1) &&
+ (!peer->bfd_info || bgp_bfd_is_peer_multihop(peer)))
+#else
+ /* Take down directly connected EBGP peers */
if ((peer->ttl != 1) && (peer->gtsm_hops != 1))
+#endif
continue;
if (ifp == peer->nexthop.ifp)
/* Type, flags, message. */
api.type = stream_getc (s);
api.instance = stream_getw (s);
- api.flags = stream_getc (s);
+ api.flags = stream_getl (s);
api.message = stream_getc (s);
/* IPv4 prefix. */
memset (&p, 0, sizeof (struct prefix_ipv4));
p.family = AF_INET;
- p.prefixlen = stream_getc (s);
+ p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, stream_getc (s));
stream_get (&p.prefix, s, PSIZE (p.prefixlen));
/* Nexthop, ifindex, distance, metric. */
api.metric = 0;
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
- api.tag = stream_getw (s);
+ api.tag = stream_getl (s);
else
api.tag = 0;
if (bgp_debug_zebra((struct prefix *)&p))
{
char buf[2][INET_ADDRSTRLEN];
- zlog_debug("Rx IPv4 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %d",
+ zlog_debug("Rx IPv4 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %"ROUTE_TAG_PRI,
vrf_id,
zebra_route_string(api.type), api.instance,
inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])),
{
char buf[2][INET_ADDRSTRLEN];
zlog_debug("Rx IPv4 route delete VRF %u %s[%d] %s/%d "
- "nexthop %s metric %u tag %d",
+ "nexthop %s metric %u tag %"ROUTE_TAG_PRI,
vrf_id,
zebra_route_string(api.type), api.instance,
inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])),
/* Type, flags, message. */
api.type = stream_getc (s);
api.instance = stream_getw (s);
- api.flags = stream_getc (s);
+ api.flags = stream_getl (s);
api.message = stream_getc (s);
/* IPv6 prefix. */
memset (&p, 0, sizeof (struct prefix_ipv6));
p.family = AF_INET6;
- p.prefixlen = stream_getc (s);
+ p.prefixlen = MIN(IPV6_MAX_PREFIXLEN, stream_getc (s));
stream_get (&p.prefix, s, PSIZE (p.prefixlen));
/* Nexthop, ifindex, distance, metric. */
api.metric = 0;
if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
- api.tag = stream_getw (s);
+ api.tag = stream_getl (s);
else
api.tag = 0;
if (bgp_debug_zebra((struct prefix *)&p))
{
char buf[2][INET6_ADDRSTRLEN];
- zlog_debug("Rx IPv6 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %d",
+ zlog_debug("Rx IPv6 route add VRF %u %s[%d] %s/%d nexthop %s metric %u tag %"ROUTE_TAG_PRI,
vrf_id,
zebra_route_string(api.type), api.instance,
inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])),
{
char buf[2][INET6_ADDRSTRLEN];
zlog_debug("Rx IPv6 route delete VRF %u %s[%d] %s/%d "
- "nexthop %s metric %u tag %d",
+ "nexthop %s metric %u tag %"ROUTE_TAG_PRI,
vrf_id,
zebra_route_string(api.type), api.instance,
inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])),
bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp,
afi_t afi, safi_t safi)
{
- int flags;
+ u_int32_t flags;
u_char distance;
struct peer *peer;
struct bgp_info *mpinfo;
u_int32_t nhcount, metric;
struct bgp_info local_info;
struct bgp_info *info_cp = &local_info;
- u_short tag;
+ route_tag_t tag;
/* Don't try to install if we're not connected to Zebra or Zebra doesn't
* know of this instance.
api.tag = tag;
}
- distance = bgp_distance_apply (p, info, bgp);
-
+ distance = bgp_distance_apply (p, info, afi, safi, bgp);
if (distance)
{
SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
if (bgp_debug_zebra(p))
{
int i;
- zlog_debug("Tx IPv4 route %s VRF %u %s/%d metric %u tag %d"
+ zlog_debug("Tx IPv4 route %s VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI
" count %d", (valid_nh_count ? "add":"delete"),
bgp->vrf_id,
inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])),
if (!ifindex)
{
if (info->peer->conf_if || info->peer->ifname)
- ifindex = if_nametoindex (info->peer->conf_if ? info->peer->conf_if : info->peer->ifname);
+ ifindex = ifname2ifindex_vrf (info->peer->conf_if ? info->peer->conf_if :
+ info->peer->ifname, bgp->vrf_id);
else if (info->peer->nexthop.ifp)
ifindex = info->peer->nexthop.ifp->ifindex;
}
if (!ifindex)
{
if (mpinfo->peer->conf_if || mpinfo->peer->ifname)
- ifindex = ifname2ifindex (mpinfo->peer->conf_if ? mpinfo->peer->conf_if : mpinfo->peer->ifname);
+ ifindex = ifname2ifindex_vrf (mpinfo->peer->conf_if ? mpinfo->peer->conf_if :
+ mpinfo->peer->ifname, bgp->vrf_id);
else if (mpinfo->peer->nexthop.ifp)
ifindex = mpinfo->peer->nexthop.ifp->ifindex;
}
api.tag = tag;
}
+ distance = bgp_distance_apply (p, info, afi, safi, bgp);
+ if (distance)
+ {
+ SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
+ api.distance = distance;
+ }
+
if (p->family == AF_INET)
{
if (bgp_debug_zebra(p))
{
int i;
- zlog_debug("Tx IPv4 route %s VRF %u %s/%d metric %u tag %d",
+ zlog_debug("Tx IPv4 route %s VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI,
valid_nh_count ? "add" : "delete", bgp->vrf_id,
inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])),
p->prefixlen, api.metric, api.tag);
if (bgp_debug_zebra(p))
{
int i;
- zlog_debug("Tx IPv6 route %s VRF %u %s/%d metric %u tag %d",
+ zlog_debug("Tx IPv6 route %s VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI,
valid_nh_count ? "add" : "delete", bgp->vrf_id,
inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])),
p->prefixlen, api.metric, api.tag);
void
bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi)
{
- int flags;
+ u_int32_t flags;
struct peer *peer;
peer = info->peer;
if (bgp_debug_zebra(p))
{
char buf[2][INET_ADDRSTRLEN];
- zlog_debug("Tx IPv4 route delete VRF %u %s/%d metric %u tag %d",
+ zlog_debug("Tx IPv4 route delete VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI,
peer->bgp->vrf_id,
inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])),
p->prefixlen, api.metric, api.tag);
if (bgp_debug_zebra(p))
{
char buf[2][INET6_ADDRSTRLEN];
- zlog_debug("Tx IPv6 route delete VRF %u %s/%d metric %u tag %d",
+ zlog_debug("Tx IPv6 route delete VRF %u %s/%d metric %u tag %"ROUTE_TAG_PRI,
peer->bgp->vrf_id,
inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])),
p->prefixlen, api.metric, api.tag);
if (red)
{
listnode_delete(bgp->redist[afi][type], red);
+ XFREE (MTYPE_BGP_REDIST, red);
if (!bgp->redist[afi][type]->count)
{
list_free(bgp->redist[afi][type]);
if (vrf_bitmap_check (zclient->redist[afi][type], bgp->vrf_id))
return CMD_WARNING;
+#if ENABLE_BGP_VNC
+ if (bgp->vrf_id == VRF_DEFAULT &&
+ type == ZEBRA_ROUTE_VNC_DIRECT) {
+ vnc_export_bgp_enable(bgp, afi); /* only enables if mode bits cfg'd */
+ }
+#endif
+
vrf_bitmap_set (zclient->redist[afi][type], bgp->vrf_id);
}
vrf_bitmap_unset (zclient->redist[afi][type], bgp->vrf_id);
}
+#if ENABLE_BGP_VNC
+ if (bgp->vrf_id == VRF_DEFAULT &&
+ type == ZEBRA_ROUTE_VNC_DIRECT) {
+ vnc_export_bgp_disable(bgp, afi);
+ }
+#endif
+
if (bgp_install_info_to_zebra (bgp))
{
/* Send distribute delete message to zebra. */
{
struct bgp *bgp;
+ zclient_num_connects++; /* increment even if not responding */
+
/* At this point, we may or may not have BGP instances configured, but
* we're only interested in the default VRF (others wouldn't have learnt
* the VRF from Zebra yet.)
void
bgp_zebra_init (struct thread_master *master)
{
+ zclient_num_connects = 0;
+
/* Set default values. */
zclient = zclient_new (master);
zclient_init (zclient, ZEBRA_ROUTE_BGP, 0);
zclient->interface_nbr_address_add = bgp_interface_nbr_address_add;
zclient->interface_nbr_address_delete = bgp_interface_nbr_address_delete;
zclient->interface_vrf_update = bgp_interface_vrf_update;
- zclient->ipv4_route_add = zebra_read_ipv4;
- zclient->ipv4_route_delete = zebra_read_ipv4;
zclient->redistribute_route_ipv4_add = zebra_read_ipv4;
zclient->redistribute_route_ipv4_del = zebra_read_ipv4;
zclient->interface_up = bgp_interface_up;
zclient->interface_down = bgp_interface_down;
- zclient->ipv6_route_add = zebra_read_ipv6;
- zclient->ipv6_route_delete = zebra_read_ipv6;
zclient->redistribute_route_ipv6_add = zebra_read_ipv6;
zclient->redistribute_route_ipv6_del = zebra_read_ipv6;
zclient->nexthop_update = bgp_read_nexthop_update;
zclient_free(zclient);
zclient = NULL;
}
+
+int
+bgp_zebra_num_connects(void)
+{
+ return zclient_num_connects;
+}