#include "vty.h"
#include "bfd.h"
+DEFINE_MTYPE_STATIC(LIB, BFD_INFO, "BFD info")
+
+int bfd_debug = 0;
+struct bfd_gbl bfd_gbl;
+
+/*
+ * bfd_gbl_init - Initialize the BFD global structure
+ */
+void
+bfd_gbl_init(void)
+{
+ memset(&bfd_gbl, 0, sizeof (struct bfd_gbl));
+}
+
+/*
+ * bfd_gbl_exit - Called when daemon exits
+ */
+void
+bfd_gbl_exit(void)
+{
+ SET_FLAG (bfd_gbl.flags, BFD_GBL_FLAG_IN_SHUTDOWN);
+}
+
/*
* bfd_info_create - Allocate the BFD information
*/
assert(bfd_info);
bfd_info->status = BFD_STATUS_UNKNOWN;
+ bfd_info->type = BFD_TYPE_NOT_CONFIGURED;
bfd_info->last_update = 0;
return bfd_info;
}
void
bfd_peer_sendmsg (struct zclient *zclient, struct bfd_info *bfd_info,
int family, void *dst_ip, void *src_ip, char *if_name,
- int ttl, int multihop, int command, int set_flag)
+ int ttl, int multihop, int command, int set_flag,
+ vrf_id_t vrf_id)
{
struct stream *s;
int ret;
int len;
+ /* Individual reg/dereg messages are supressed during shutdown. */
+ if (CHECK_FLAG (bfd_gbl.flags, BFD_GBL_FLAG_IN_SHUTDOWN))
+ {
+ if (bfd_debug)
+ zlog_debug("%s: Suppressing BFD peer reg/dereg messages", __FUNCTION__);
+ return;
+ }
+
/* Check socket. */
if (!zclient || zclient->sock < 0)
{
- zlog_debug("%s: Can't send BFD peer register, Zebra client not "
- "established", __FUNCTION__);
+ if (bfd_debug)
+ zlog_debug("%s: Can't send BFD peer register, Zebra client not "
+ "established", __FUNCTION__);
return;
}
s = zclient->obuf;
stream_reset (s);
- zclient_create_header (s, command);
+ zclient_create_header (s, command, vrf_id);
+
+ stream_putl(s, getpid());
stream_putw(s, family);
switch (family)
if (ret < 0)
{
- zlog_warn("bfd_peer_sendmsg: zclient_send_message() failed");
+ if (bfd_debug)
+ zlog_debug("bfd_peer_sendmsg: zclient_send_message() failed");
return;
}
*/
struct interface *
bfd_get_peer_info (struct stream *s, struct prefix *dp, struct prefix *sp,
- int *status)
+ int *status, vrf_id_t vrf_id)
{
unsigned int ifindex;
struct interface *ifp = NULL;
/* Lookup index. */
if (ifindex != 0)
{
- ifp = if_lookup_by_index (ifindex);
+ ifp = if_lookup_by_index_vrf (ifindex, vrf_id);
if (ifp == NULL)
{
- zlog_warn ("zebra_interface_bfd_read: "
- "Can't find interface by ifindex: %d ", ifindex);
+ if (bfd_debug)
+ zlog_debug ("zebra_interface_bfd_read: "
+ "Can't find interface by ifindex: %d ", ifindex);
return NULL;
}
}
else
vty_out (vty, "%s", VTY_NEWLINE);
}
+
+/*
+ * bfd_client_sendmsg - Format and send a client register
+ * command to Zebra to be forwarded to BFD
+ */
+void
+bfd_client_sendmsg (struct zclient *zclient, int command)
+{
+ struct stream *s;
+ int ret;
+
+ /* Check socket. */
+ if (!zclient || zclient->sock < 0)
+ {
+ if (bfd_debug)
+ zlog_debug ("%s: Can't send BFD client register, Zebra client not "
+ "established", __FUNCTION__);
+ return;
+ }
+
+ s = zclient->obuf;
+ stream_reset (s);
+ zclient_create_header (s, command, VRF_DEFAULT);
+
+ stream_putl(s, getpid());
+
+ stream_putw_at (s, 0, stream_get_endp (s));
+
+ ret = zclient_send_message(zclient);
+
+ if (ret < 0)
+ {
+ if (bfd_debug)
+ zlog_debug ("bfd_client_sendmsg %ld: zclient_send_message() failed",
+ (long) getpid());
+ return;
+ }
+
+ return;
+}