Skip to content

Commit

Permalink
pimd,yang: log MSDP neighbor events
Browse files Browse the repository at this point in the history
Move MSDP neighbor events global debug to per PIM instance.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
  • Loading branch information
rzalamena committed Nov 21, 2024
1 parent 8884f42 commit 21d1e85
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 62 deletions.
16 changes: 16 additions & 0 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -8267,6 +8267,21 @@ DEFUN (show_ip_msdp_sa_sg_vrf_all,
return CMD_SUCCESS;
}

DEFPY(msdp_log_neighbor_changes, msdp_log_neighbor_changes_cmd,
"[no] msdp log neighbor-events",
NO_STR
MSDP_STR
"MSDP log messages\n"
"MSDP log neighbor event messages\n")
{
char xpath_value[XPATH_MAXLEN + 32];

snprintf(xpath_value, sizeof(xpath_value), "%s/msdp/log-neighbor-events", VTY_CURR_XPATH);
nb_cli_enqueue_change(vty, xpath_value, no ? NB_OP_DESTROY : NB_OP_MODIFY, "true");

return nb_cli_apply_changes(vty, NULL);
}

struct pim_sg_cache_walk_data {
struct vty *vty;
json_object *json;
Expand Down Expand Up @@ -8898,6 +8913,7 @@ void pim_cmd_init(void)
install_element(PIM_NODE, &pim_msdp_mesh_group_source_cmd);
install_element(PIM_NODE, &no_pim_msdp_mesh_group_source_cmd);
install_element(PIM_NODE, &no_pim_msdp_mesh_group_cmd);
install_element(PIM_NODE, &msdp_log_neighbor_changes_cmd);

install_element(PIM_NODE, &pim_bsr_candidate_rp_cmd);
install_element(PIM_NODE, &pim_bsr_candidate_rp_group_cmd);
Expand Down
5 changes: 5 additions & 0 deletions pimd/pim_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,8 @@ void pim_vrf_terminate(void)

vrf_terminate();
}

bool pim_msdp_log_neighbor_events(const struct pim_instance *pim)
{
return (pim->log_flags & PIM_MSDP_LOG_NEIGHBOR_EVENTS);
}
7 changes: 7 additions & 0 deletions pimd/pim_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ struct pim_instance {

uint64_t gm_rx_drop_sys;

/** Log information flags. */
uint32_t log_flags;
/** Log neighbor event messages. */
#define PIM_MSDP_LOG_NEIGHBOR_EVENTS 0x01

bool stopping;

#if PIM_IPV == 6
Expand All @@ -218,4 +223,6 @@ extern struct pim_router *router;

struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id);

extern bool pim_msdp_log_neighbor_events(const struct pim_instance *pim);

#endif
106 changes: 44 additions & 62 deletions pimd/pim_msdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ static void pim_msdp_peer_state_chg_log(struct pim_msdp_peer *mp)
char state_str[PIM_MSDP_STATE_STRLEN];

pim_msdp_state_dump(mp->state, state_str, sizeof(state_str));
zlog_debug("MSDP peer %s state chg to %s", mp->key_str, state_str);
zlog_info("MSDP peer %s state changed to %s", mp->key_str, state_str);
}

/* MSDP Connection State Machine actions (defined in RFC-3618:Sec-11.2) */
Expand All @@ -753,9 +753,8 @@ static void pim_msdp_peer_state_chg_log(struct pim_msdp_peer *mp)
static void pim_msdp_peer_connect(struct pim_msdp_peer *mp)
{
mp->state = PIM_MSDP_CONNECTING;
if (PIM_DEBUG_MSDP_EVENTS) {
if (pim_msdp_log_neighbor_events(mp->pim))
pim_msdp_peer_state_chg_log(mp);
}

pim_msdp_peer_cr_timer_setup(mp, true /* start */);
}
Expand All @@ -764,9 +763,8 @@ static void pim_msdp_peer_connect(struct pim_msdp_peer *mp)
static void pim_msdp_peer_listen(struct pim_msdp_peer *mp)
{
mp->state = PIM_MSDP_LISTEN;
if (PIM_DEBUG_MSDP_EVENTS) {
if (pim_msdp_log_neighbor_events(mp->pim))
pim_msdp_peer_state_chg_log(mp);
}

/* this is interntionally asymmetric i.e. we set up listen-socket when
* the
Expand All @@ -790,9 +788,8 @@ void pim_msdp_peer_established(struct pim_msdp_peer *mp)
mp->state = PIM_MSDP_ESTABLISHED;
mp->uptime = pim_time_monotonic_sec();

if (PIM_DEBUG_MSDP_EVENTS) {
if (pim_msdp_log_neighbor_events(mp->pim))
pim_msdp_peer_state_chg_log(mp);
}

/* stop retry timer on active peers */
pim_msdp_peer_cr_timer_setup(mp, false /* start */);
Expand All @@ -816,9 +813,9 @@ void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state)
++mp->est_flaps;
}
mp->state = PIM_MSDP_INACTIVE;
if (PIM_DEBUG_MSDP_EVENTS) {

if (pim_msdp_log_neighbor_events(mp->pim))
pim_msdp_peer_state_chg_log(mp);
}
}

if (PIM_DEBUG_MSDP_INTERNAL) {
Expand Down Expand Up @@ -851,10 +848,10 @@ void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state)
/* RFC-3618:Sec-5.6 - stop the peer tcp connection and startover */
void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str)
{
if (PIM_DEBUG_EVENTS) {
zlog_debug("MSDP peer %s tcp reset %s", mp->key_str, rc_str);
snprintf(mp->last_reset, sizeof(mp->last_reset), "%s", rc_str);
}
if (pim_msdp_log_neighbor_events(mp->pim))
zlog_info("MSDP peer %s tcp reset %s", mp->key_str, rc_str);

snprintf(mp->last_reset, sizeof(mp->last_reset), "%s", rc_str);

/* close the connection and transition to listening or connecting */
pim_msdp_peer_stop_tcp_conn(mp, true /* chg_state */);
Expand All @@ -865,30 +862,23 @@ void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str)
}
}

static void pim_msdp_peer_timer_expiry_log(struct pim_msdp_peer *mp,
const char *timer_str)
{
zlog_debug("MSDP peer %s %s timer expired", mp->key_str, timer_str);
}

/* RFC-3618:Sec-5.4 - peer hold timer */
static void pim_msdp_peer_hold_timer_cb(struct event *t)
{
struct pim_msdp_peer *mp;

mp = EVENT_ARG(t);

if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_peer_timer_expiry_log(mp, "hold");
}
if (pim_msdp_log_neighbor_events(mp->pim))
zlog_info("MSDP peer %s hold timer expired", mp->key_str);

if (mp->state != PIM_MSDP_ESTABLISHED) {
return;
}

if (PIM_DEBUG_MSDP_EVENTS) {
if (pim_msdp_log_neighbor_events(mp->pim))
pim_msdp_peer_state_chg_log(mp);
}

pim_msdp_peer_reset_tcp_conn(mp, "ht-expired");
}

Expand All @@ -910,9 +900,8 @@ static void pim_msdp_peer_ka_timer_cb(struct event *t)

mp = EVENT_ARG(t);

if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_peer_timer_expiry_log(mp, "ka");
}
if (pim_msdp_log_neighbor_events(mp->pim))
zlog_info("MSDP peer %s keep alive timer expired", mp->key_str);

pim_msdp_pkt_ka_tx(mp);
pim_msdp_peer_ka_timer_setup(mp, true /* start */);
Expand Down Expand Up @@ -970,9 +959,8 @@ static void pim_msdp_peer_cr_timer_cb(struct event *t)

mp = EVENT_ARG(t);

if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_peer_timer_expiry_log(mp, "connect-retry");
}
if (pim_msdp_log_neighbor_events(mp->pim))
zlog_info("MSDP peer %s connection retry timer expired", mp->key_str);

if (mp->state != PIM_MSDP_CONNECTING || PIM_MSDP_PEER_IS_LISTENER(mp)) {
return;
Expand Down Expand Up @@ -1051,8 +1039,8 @@ struct pim_msdp_peer *pim_msdp_peer_add(struct pim_instance *pim,
mp = hash_get(pim->msdp.peer_hash, mp, hash_alloc_intern);
listnode_add_sort(pim->msdp.peer_list, mp);

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP peer %s created", mp->key_str);
if (pim_msdp_log_neighbor_events(pim)) {
zlog_info("MSDP peer %s created", mp->key_str);

pim_msdp_peer_state_chg_log(mp);
}
Expand Down Expand Up @@ -1116,9 +1104,8 @@ void pim_msdp_peer_del(struct pim_msdp_peer **mp)
listnode_delete((*mp)->pim->msdp.peer_list, *mp);
hash_release((*mp)->pim->msdp.peer_hash, *mp);

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP peer %s deleted", (*mp)->key_str);
}
if (pim_msdp_log_neighbor_events((*mp)->pim))
zlog_info("MSDP peer %s deleted", (*mp)->key_str);

/* free up any associated memory */
pim_msdp_peer_free(*mp);
Expand Down Expand Up @@ -1193,10 +1180,8 @@ void pim_msdp_mg_free(struct pim_instance *pim, struct pim_msdp_mg **mgp)
for (ALL_LIST_ELEMENTS((*mgp)->mbr_list, n, nn, mbr))
pim_msdp_mg_mbr_del((*mgp), mbr);

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP mesh-group %s deleted",
(*mgp)->mesh_group_name);
}
if (pim_msdp_log_neighbor_events(pim))
zlog_info("MSDP mesh-group %s deleted", (*mgp)->mesh_group_name);

XFREE(MTYPE_PIM_MSDP_MG_NAME, (*mgp)->mesh_group_name);

Expand All @@ -1213,15 +1198,14 @@ struct pim_msdp_mg *pim_msdp_mg_new(struct pim_instance *pim,
struct pim_msdp_mg *mg;

mg = XCALLOC(MTYPE_PIM_MSDP_MG, sizeof(*mg));

mg->pim = pim;
mg->mesh_group_name = XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name);
mg->mbr_list = list_new();
mg->mbr_list->del = (void (*)(void *))pim_msdp_mg_mbr_free;
mg->mbr_list->cmp = (int (*)(void *, void *))pim_msdp_mg_mbr_comp;

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP mesh-group %s created", mg->mesh_group_name);
}
if (pim_msdp_log_neighbor_events(pim))
zlog_info("MSDP mesh-group %s created", mg->mesh_group_name);

SLIST_INSERT_HEAD(&pim->msdp.mglist, mg, mg_entry);

Expand Down Expand Up @@ -1255,12 +1239,10 @@ void pim_msdp_mg_mbr_del(struct pim_msdp_mg *mg, struct pim_msdp_mg_mbr *mbr)
}

listnode_delete(mg->mbr_list, mbr);
if (PIM_DEBUG_MSDP_EVENTS) {
char ip_str[INET_ADDRSTRLEN];
pim_inet4_dump("<mbr?>", mbr->mbr_ip, ip_str, sizeof(ip_str));
zlog_debug("MSDP mesh-group %s mbr %s deleted",
mg->mesh_group_name, ip_str);
}
if (pim_msdp_log_neighbor_events(mg->pim))
zlog_info("MSDP mesh-group %s neighbor %pI4 deleted", mg->mesh_group_name,
&mbr->mbr_ip);

pim_msdp_mg_mbr_free(mbr);
if (mg->mbr_cnt) {
--mg->mbr_cnt;
Expand All @@ -1277,10 +1259,9 @@ static void pim_msdp_src_del(struct pim_msdp_mg *mg)
if (mbr->mp)
pim_msdp_peer_del(&mbr->mp);
}
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP mesh-group %s src cleared",
mg->mesh_group_name);
}

if (pim_msdp_log_neighbor_events(mg->pim))
zlog_info("MSDP mesh-group %s source cleared", mg->mesh_group_name);
}

/*********************** MSDP feature APIs *********************************/
Expand All @@ -1292,6 +1273,9 @@ int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty)
char src_str[INET_ADDRSTRLEN];
int count = 0;

if (pim_msdp_log_neighbor_events(pim))
vty_out(vty, " msdp log neighbor-events\n");

if (SLIST_EMPTY(&pim->msdp.mglist))
return count;

Expand Down Expand Up @@ -1426,9 +1410,8 @@ void pim_msdp_mg_src_add(struct pim_instance *pim, struct pim_msdp_mg *mg,

/* No new address, disable everyone. */
if (ai->s_addr == INADDR_ANY) {
if (PIM_DEBUG_MSDP_EVENTS)
zlog_debug("MSDP mesh-group %s src unset",
mg->mesh_group_name);
if (pim_msdp_log_neighbor_events(pim))
zlog_info("MSDP mesh-group %s source unset", mg->mesh_group_name);
return;
}

Expand All @@ -1437,9 +1420,8 @@ void pim_msdp_mg_src_add(struct pim_instance *pim, struct pim_msdp_mg *mg,
mbr->mp = pim_msdp_peer_add(pim, &mbr->mbr_ip, &mg->src_ip,
mg->mesh_group_name);

if (PIM_DEBUG_MSDP_EVENTS)
zlog_debug("MSDP mesh-group %s src %pI4 set",
mg->mesh_group_name, &mg->src_ip);
if (pim_msdp_log_neighbor_events(pim))
zlog_info("MSDP mesh-group %s source %pI4 set", mg->mesh_group_name, &mg->src_ip);
}

struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_add(struct pim_instance *pim,
Expand All @@ -1457,9 +1439,9 @@ struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_add(struct pim_instance *pim,
mbr->mp = pim_msdp_peer_add(pim, &mbr->mbr_ip, &mg->src_ip,
mg->mesh_group_name);

if (PIM_DEBUG_MSDP_EVENTS)
zlog_debug("MSDP mesh-group %s mbr %pI4 created",
mg->mesh_group_name, &mbr->mbr_ip);
if (pim_msdp_log_neighbor_events(pim))
zlog_info("MSDP mesh-group %s neighbor %pI4 created", mg->mesh_group_name,
&mbr->mbr_ip);

++mg->mbr_cnt;

Expand Down
1 change: 1 addition & 0 deletions pimd/pim_msdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ struct pim_msdp_mg {
struct in_addr src_ip;
uint32_t mbr_cnt;
struct list *mbr_list;
struct pim_instance *pim;

/** Belongs to PIM instance list. */
SLIST_ENTRY(pim_msdp_mg) mg_entry;
Expand Down
6 changes: 6 additions & 0 deletions pimd/pim_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ const struct frr_yang_module_info frr_pim_info = {
.modify = pim_msdp_connection_retry_modify,
}
},
{
.xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp/log-neighbor-events",
.cbs = {
.modify = pim_msdp_log_neighbor_events_modify,
}
},
{
.xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp-mesh-groups",
.cbs = {
Expand Down
1 change: 1 addition & 0 deletions pimd/pim_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_ss
int pim_msdp_hold_time_modify(struct nb_cb_modify_args *args);
int pim_msdp_keep_alive_modify(struct nb_cb_modify_args *args);
int pim_msdp_connection_retry_modify(struct nb_cb_modify_args *args);
int pim_msdp_log_neighbor_events_modify(struct nb_cb_modify_args *args);
int pim_msdp_mesh_group_create(struct nb_cb_create_args *args);
int pim_msdp_mesh_group_destroy(struct nb_cb_destroy_args *args);
int pim_msdp_mesh_group_members_create(struct nb_cb_create_args *args);
Expand Down
30 changes: 30 additions & 0 deletions pimd/pim_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,38 @@ pim6_msdp_err(routing_control_plane_protocols_control_plane_protocol_pim_address
pim6_msdp_err(pim_msdp_peer_authentication_type_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_authentication_key_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_authentication_key_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_log_neighbor_events_modify, nb_cb_modify_args);

#if PIM_IPV != 6
/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp/log-neighbor-events
*/
int pim_msdp_log_neighbor_events_modify(struct nb_cb_modify_args *args)
{
struct pim_instance *pim;
struct vrf *vrf;

switch (args->event) {
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
/* NOTHING */
break;

case NB_EV_APPLY:
vrf = nb_running_get_entry(args->dnode, NULL, true);
pim = vrf->info;
if (yang_dnode_get_bool(args->dnode, NULL))
SET_FLAG(pim->log_flags, PIM_MSDP_LOG_NEIGHBOR_EVENTS);
else
UNSET_FLAG(pim->log_flags, PIM_MSDP_LOG_NEIGHBOR_EVENTS);
break;
}

return NB_OK;
}

/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp-mesh-groups
Expand Down
Loading

0 comments on commit 21d1e85

Please sign in to comment.