summaryrefslogtreecommitdiff
path: root/bfdd/ptm_adapter.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfdd/ptm_adapter.c')
-rw-r--r--bfdd/ptm_adapter.c113
1 files changed, 58 insertions, 55 deletions
diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c
index dcca70b796..4c88922b8a 100644
--- a/bfdd/ptm_adapter.c
+++ b/bfdd/ptm_adapter.c
@@ -80,19 +80,17 @@ static void bfdd_client_deregister(struct stream *msg);
/*
* Functions
*/
-#ifdef BFD_DEBUG
-static void debug_printbpc(const char *func, unsigned int line,
- struct bfd_peer_cfg *bpc);
-
-static void debug_printbpc(const char *func, unsigned int line,
- struct bfd_peer_cfg *bpc)
+static void debug_printbpc(const struct bfd_peer_cfg *bpc, const char *fmt, ...)
{
- char addr[3][128];
- char timers[3][128];
- char cbit_str[10];
-
- addr[0][0] = addr[1][0] = addr[2][0] = timers[0][0] = timers[1][0] =
- timers[2][0] = 0;
+ char timers[3][128] = {};
+ char addr[3][128] = {};
+ char cbit_str[32];
+ char msgbuf[256];
+ va_list vl;
+
+ /* Avoid debug calculations if it's disabled. */
+ if (bglobal.debug_zebra == false)
+ return;
snprintf(addr[0], sizeof(addr[0]), "peer:%s", satostr(&bpc->bpc_peer));
if (bpc->bpc_local.sa_sin.sin_family)
@@ -107,28 +105,27 @@ static void debug_printbpc(const char *func, unsigned int line,
snprintf(addr[2], sizeof(addr[2]), " vrf:%s", bpc->bpc_vrfname);
if (bpc->bpc_has_recvinterval)
- snprintf(timers[0], sizeof(timers[0]), " rx:%lu",
+ snprintf(timers[0], sizeof(timers[0]), " rx:%" PRIu64,
bpc->bpc_recvinterval);
if (bpc->bpc_has_txinterval)
- snprintf(timers[1], sizeof(timers[1]), " tx:%lu",
+ snprintf(timers[1], sizeof(timers[1]), " tx:%" PRIu64,
bpc->bpc_recvinterval);
if (bpc->bpc_has_detectmultiplier)
snprintf(timers[2], sizeof(timers[2]), " detect-multiplier:%d",
bpc->bpc_detectmultiplier);
- sprintf(cbit_str, "CB %x", bpc->bpc_cbit);
+ snprintf(cbit_str, sizeof(cbit_str), " cbit:0x%02x", bpc->bpc_cbit);
- log_debug("%s:%d: %s %s%s%s%s%s%s %s", func, line,
- bpc->bpc_mhop ? "multi-hop" : "single-hop", addr[0], addr[1],
- addr[2], timers[0], timers[1], timers[2], cbit_str);
-}
+ va_start(vl, fmt);
+ vsnprintf(msgbuf, sizeof(msgbuf), fmt, vl);
+ va_end(vl);
-#define DEBUG_PRINTBPC(bpc) debug_printbpc(__FILE__, __LINE__, (bpc))
-#else
-#define DEBUG_PRINTBPC(bpc)
-#endif /* BFD_DEBUG */
+ zlog_debug("%s [mhop:%s %s%s%s%s%s%s%s]", msgbuf,
+ bpc->bpc_mhop ? "yes" : "no", addr[0], addr[1], addr[2],
+ timers[0], timers[1], timers[2], cbit_str);
+}
static int _ptm_msg_address(struct stream *msg, int family, const void *addr)
{
@@ -260,7 +257,7 @@ static void _ptm_msg_read_address(struct stream *msg, struct sockaddr_any *sa)
return;
default:
- log_warning("ptm-read-address: invalid family: %d", family);
+ zlog_warn("ptm-read-address: invalid family: %d", family);
break;
}
@@ -315,10 +312,6 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
STREAM_GETL(msg, pid);
*pc = pc_new(pid);
- if (*pc == NULL) {
- log_debug("ptm-read: failed to allocate memory");
- return -1;
- }
/* Register/update peer information. */
_ptm_msg_read_address(msg, &bpc->bpc_peer);
@@ -358,7 +351,7 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
*/
STREAM_GETC(msg, ifnamelen);
if (ifnamelen >= sizeof(bpc->bpc_localif)) {
- log_error("ptm-read: interface name is too big");
+ zlog_err("ptm-read: interface name is too big");
return -1;
}
@@ -376,7 +369,8 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
bpc->bpc_has_vrfname = true;
strlcpy(bpc->bpc_vrfname, vrf->name, sizeof(bpc->bpc_vrfname));
} else {
- log_error("ptm-read: vrf id %u could not be identified", vrf_id);
+ zlog_err("ptm-read: vrf id %u could not be identified",
+ vrf_id);
return -1;
}
} else {
@@ -390,7 +384,7 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id,
if (bpc->bpc_local.sa_sin.sin_family != 0
&& (bpc->bpc_local.sa_sin.sin_family
!= bpc->bpc_peer.sa_sin.sin_family)) {
- log_warning("ptm-read: peer family doesn't match local type");
+ zlog_warn("ptm-read: peer family doesn't match local type");
return -1;
}
@@ -403,7 +397,6 @@ stream_failure:
static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id)
{
struct ptm_client *pc;
- struct ptm_client_notification *pcn;
struct bfd_session *bs;
struct bfd_peer_cfg bpc;
@@ -411,29 +404,27 @@ static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id)
if (_ptm_msg_read(msg, ZEBRA_BFD_DEST_REGISTER, vrf_id, &bpc, &pc) == -1)
return;
- DEBUG_PRINTBPC(&bpc);
+ debug_printbpc(&bpc, "ptm-add-dest: register peer");
/* Find or start new BFD session. */
bs = bs_peer_find(&bpc);
if (bs == NULL) {
bs = ptm_bfd_sess_new(&bpc);
if (bs == NULL) {
- log_debug("ptm-add-dest: failed to create BFD session");
+ if (bglobal.debug_zebra)
+ zlog_debug(
+ "ptm-add-dest: failed to create BFD session");
return;
}
} else {
/* Don't try to change echo/shutdown state. */
- bpc.bpc_echo = BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
+ bpc.bpc_echo = CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO);
bpc.bpc_shutdown =
- BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
+ CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN);
}
/* Create client peer notification register. */
- pcn = pcn_new(pc, bs);
- if (pcn == NULL) {
- log_error("ptm-add-dest: failed to registrate notifications");
- return;
- }
+ pcn_new(pc, bs);
ptm_bfd_notify(bs, bs->ses_state);
}
@@ -449,12 +440,13 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id)
if (_ptm_msg_read(msg, ZEBRA_BFD_DEST_DEREGISTER, vrf_id, &bpc, &pc) == -1)
return;
- DEBUG_PRINTBPC(&bpc);
+ debug_printbpc(&bpc, "ptm-del-dest: deregister peer");
/* Find or start new BFD session. */
bs = bs_peer_find(&bpc);
if (bs == NULL) {
- log_debug("ptm-del-dest: failed to find BFD session");
+ if (bglobal.debug_zebra)
+ zlog_debug("ptm-del-dest: failed to find BFD session");
return;
}
@@ -462,7 +454,7 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id)
pcn = pcn_lookup(pc, bs);
pcn_free(pcn);
if (bs->refcount ||
- BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG))
+ CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG))
return;
bs->ses_state = PTM_BFD_ADM_DOWN;
@@ -477,22 +469,17 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id)
*/
static void bfdd_client_register(struct stream *msg)
{
- struct ptm_client *pc;
uint32_t pid;
/* Find or allocate process context data. */
STREAM_GETL(msg, pid);
- pc = pc_new(pid);
- if (pc == NULL) {
- log_error("ptm-add-client: failed to register client: %u", pid);
- return;
- }
+ pc_new(pid);
return;
stream_failure:
- log_error("ptm-add-client: failed to register client");
+ zlog_err("ptm-add-client: failed to register client");
}
/*
@@ -509,7 +496,9 @@ static void bfdd_client_deregister(struct stream *msg)
pc = pc_lookup(pid);
if (pc == NULL) {
- log_debug("ptm-del-client: failed to find client: %u", pid);
+ if (bglobal.debug_zebra)
+ zlog_debug("ptm-del-client: failed to find client: %u",
+ pid);
return;
}
@@ -518,7 +507,7 @@ static void bfdd_client_deregister(struct stream *msg)
return;
stream_failure:
- log_error("ptm-del-client: failed to deregister client");
+ zlog_err("ptm-del-client: failed to deregister client");
}
static int bfdd_replay(ZAPI_CALLBACK_ARGS)
@@ -544,14 +533,15 @@ static int bfdd_replay(ZAPI_CALLBACK_ARGS)
break;
default:
- log_debug("ptm-replay: invalid message type %u", rcmd);
+ if (bglobal.debug_zebra)
+ zlog_debug("ptm-replay: invalid message type %u", rcmd);
return -1;
}
return 0;
stream_failure:
- log_error("ptm-replay: failed to find command");
+ zlog_err("ptm-replay: failed to find command");
return -1;
}
@@ -672,6 +662,9 @@ void bfdd_sessions_disable_vrf(struct vrf *vrf)
static int bfd_ifp_destroy(struct interface *ifp)
{
+ if (bglobal.debug_zebra)
+ zlog_debug("zclient: delete interface %s", ifp->name);
+
bfdd_sessions_disable_interface(ifp);
return 0;
@@ -717,11 +710,18 @@ static void bfdd_sessions_enable_address(struct connected *ifc)
static int bfdd_interface_address_update(ZAPI_CALLBACK_ARGS)
{
struct connected *ifc;
+ char buf[64];
ifc = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id);
if (ifc == NULL)
return 0;
+ if (bglobal.debug_zebra)
+ zlog_debug("zclient: %s local address %s",
+ cmd == ZEBRA_INTERFACE_ADDRESS_ADD ? "add"
+ : "delete",
+ prefix2str(ifc->address, buf, sizeof(buf)));
+
bfdd_sessions_enable_address(ifc);
return 0;
@@ -729,6 +729,9 @@ static int bfdd_interface_address_update(ZAPI_CALLBACK_ARGS)
static int bfd_ifp_create(struct interface *ifp)
{
+ if (bglobal.debug_zebra)
+ zlog_debug("zclient: add interface %s", ifp->name);
+
bfdd_sessions_enable_interface(ifp);
return 0;