Skip to content

Commit

Permalink
pimd,yang: log MSDP SA events
Browse files Browse the repository at this point in the history
Add new command to log all SA events.

Signed-off-by: Rafael Zalamena <[email protected]>
  • Loading branch information
rzalamena committed Nov 21, 2024
1 parent 21d1e85 commit fc39bfa
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 62 deletions.
17 changes: 17 additions & 0 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -8282,6 +8282,22 @@ DEFPY(msdp_log_neighbor_changes, msdp_log_neighbor_changes_cmd,
return nb_cli_apply_changes(vty, NULL);
}

DEFPY(msdp_log_sa_changes, msdp_log_sa_changes_cmd,
"[no] msdp log sa-events",
NO_STR
MSDP_STR
"MSDP log messages\n"
"MSDP log SA event messages\n")
{
char xpath_value[XPATH_MAXLEN + 32];

snprintf(xpath_value, sizeof(xpath_value), "%s/msdp/log-sa-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 @@ -8914,6 +8930,7 @@ void pim_cmd_init(void)
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, &msdp_log_sa_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 @@ -277,3 +277,8 @@ bool pim_msdp_log_neighbor_events(const struct pim_instance *pim)
{
return (pim->log_flags & PIM_MSDP_LOG_NEIGHBOR_EVENTS);
}

bool pim_msdp_log_sa_events(const struct pim_instance *pim)
{
return (pim->log_flags & PIM_MSDP_LOG_SA_EVENTS);
}
3 changes: 3 additions & 0 deletions pimd/pim_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ struct pim_instance {
uint32_t log_flags;
/** Log neighbor event messages. */
#define PIM_MSDP_LOG_NEIGHBOR_EVENTS 0x01
/** Log SA event messages. */
#define PIM_MSDP_LOG_SA_EVENTS 0x02

bool stopping;

Expand Down Expand Up @@ -224,5 +226,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);
extern bool pim_msdp_log_sa_events(const struct pim_instance *pim);

#endif
80 changes: 32 additions & 48 deletions pimd/pim_msdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,13 @@ static int pim_msdp_mg_mbr_comp(const void *p1, const void *p2);
static void pim_msdp_mg_mbr_free(struct pim_msdp_mg_mbr *mbr);

/************************ SA cache management ******************************/
static void pim_msdp_sa_timer_expiry_log(struct pim_msdp_sa *sa,
const char *timer_str)
{
zlog_debug("MSDP SA %s %s timer expired", sa->sg_str, timer_str);
}

/* RFC-3618:Sec-5.1 - global active source advertisement timer */
static void pim_msdp_sa_adv_timer_cb(struct event *t)
{
struct pim_instance *pim = EVENT_ARG(t);

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA advertisement timer expired");
}
if (pim_msdp_log_sa_events(pim))
zlog_info("MSDP SA advertisement timer expired");

pim_msdp_sa_adv_timer_setup(pim, true /* start */);
pim_msdp_pkt_sa_tx(pim);
Expand All @@ -83,9 +76,8 @@ static void pim_msdp_sa_state_timer_cb(struct event *t)

sa = EVENT_ARG(t);

if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_sa_timer_expiry_log(sa, "state");
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s state timer expired", sa->sg_str);

pim_msdp_sa_deref(sa, PIM_MSDP_SAF_PEER);
}
Expand Down Expand Up @@ -120,9 +112,8 @@ static void pim_msdp_sa_upstream_del(struct pim_msdp_sa *sa)
sa->flags &= ~PIM_MSDP_SAF_UP_DEL_IN_PROG;
}

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s de-referenced SPT", sa->sg_str);
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s de-referenced SPT", sa->sg_str);
}

static bool pim_msdp_sa_upstream_add_ok(struct pim_msdp_sa *sa,
Expand Down Expand Up @@ -185,10 +176,8 @@ static void pim_msdp_sa_upstream_update(struct pim_msdp_sa *sa,
if (up && (PIM_UPSTREAM_FLAG_TEST_SRC_MSDP(up->flags))) {
/* somehow we lost track of the upstream ptr? best log it */
sa->up = up;
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s SPT reference missing",
sa->sg_str);
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s SPT reference missing", sa->sg_str);
return;
}

Expand All @@ -204,14 +193,11 @@ static void pim_msdp_sa_upstream_update(struct pim_msdp_sa *sa,
/* should we also start the kat in parallel? we will need it
* when the
* SA ages out */
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s referenced SPT", sa->sg_str);
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s referenced SPT", sa->sg_str);
} else {
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s SPT reference failed",
sa->sg_str);
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s SPT reference failed", sa->sg_str);
}
}

Expand Down Expand Up @@ -240,9 +226,8 @@ static struct pim_msdp_sa *pim_msdp_sa_new(struct pim_instance *pim,
sa = hash_get(pim->msdp.sa_hash, sa, hash_alloc_intern);
listnode_add_sort(pim->msdp.sa_list, sa);

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s created", sa->sg_str);
}
if (pim_msdp_log_sa_events(pim))
zlog_info("MSDP SA %s created", sa->sg_str);

return sa;
}
Expand Down Expand Up @@ -282,9 +267,8 @@ static void pim_msdp_sa_del(struct pim_msdp_sa *sa)
listnode_delete(sa->pim->msdp.sa_list, sa);
hash_release(sa->pim->msdp.sa_hash, sa);

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s deleted", sa->sg_str);
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s deleted", sa->sg_str);

/* free up any associated memory */
pim_msdp_sa_free(sa);
Expand Down Expand Up @@ -333,10 +317,9 @@ static void pim_msdp_sa_deref(struct pim_msdp_sa *sa,

if ((sa->flags & PIM_MSDP_SAF_LOCAL)) {
if (flags & PIM_MSDP_SAF_LOCAL) {
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s local reference removed",
sa->sg_str);
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s local reference removed", sa->sg_str);

if (sa->pim->msdp.local_cnt)
--sa->pim->msdp.local_cnt;
}
Expand All @@ -346,10 +329,9 @@ static void pim_msdp_sa_deref(struct pim_msdp_sa *sa,
if (flags & PIM_MSDP_SAF_PEER) {
struct in_addr rp;

if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s peer reference removed",
sa->sg_str);
}
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP SA %s peer reference removed", sa->sg_str);

pim_msdp_sa_state_timer_setup(sa, false /* start */);
rp.s_addr = INADDR_ANY;
pim_msdp_sa_peer_ip_set(sa, NULL /* mp */, rp);
Expand Down Expand Up @@ -386,10 +368,8 @@ void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp,
if (mp) {
if (!(sa->flags & PIM_MSDP_SAF_PEER)) {
sa->flags |= PIM_MSDP_SAF_PEER;
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s added by peer",
sa->sg_str);
}
if (pim_msdp_log_sa_events(pim))
zlog_info("MSDP SA %s added by peer", sa->sg_str);
}
pim_msdp_sa_peer_ip_set(sa, mp, rp);
/* start/re-start the state timer to prevent cache expiry */
Expand All @@ -403,10 +383,9 @@ void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp,
if (!(sa->flags & PIM_MSDP_SAF_LOCAL)) {
sa->flags |= PIM_MSDP_SAF_LOCAL;
++sa->pim->msdp.local_cnt;
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA %s added locally",
sa->sg_str);
}
if (pim_msdp_log_sa_events(pim))
zlog_info("MSDP SA %s added locally", sa->sg_str);

/* send an immediate SA update to peers */
pim_addr_to_prefix(&grp, sa->sg.grp);
rp_info = pim_rp_find_match_group(pim, &grp);
Expand Down Expand Up @@ -710,6 +689,9 @@ bool pim_msdp_peer_rpf_check(struct pim_msdp_peer *mp, struct in_addr rp)
return true;
}

if (pim_msdp_log_sa_events(mp->pim))
zlog_info("MSDP peer %pI4 RPF failure for %pI4", &mp->peer, &rp);

return false;
}

Expand Down Expand Up @@ -1275,6 +1257,8 @@ int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty)

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

if (SLIST_EMPTY(&pim->msdp.mglist))
return count;
Expand Down
27 changes: 13 additions & 14 deletions pimd/pim_msdp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,8 @@ static void pim_msdp_pkt_sa_gen(struct pim_instance *pim,
}

if (msdp_peer_sa_filter(mp, sa)) {
if (PIM_DEBUG_MSDP_EVENTS)
zlog_debug("MSDP peer %pI4 filter SA out %s",
&mp->peer, sa->sg_str);
if (pim_msdp_log_sa_events(pim))
zlog_info("MSDP peer %pI4 filter SA out %s", &mp->peer, sa->sg_str);

continue;
}
Expand Down Expand Up @@ -551,9 +550,9 @@ void pim_msdp_pkt_sa_tx_one(struct pim_msdp_sa *sa)
pim_msdp_pkt_sa_fill_one(sa);
for (ALL_LIST_ELEMENTS_RO(sa->pim->msdp.peer_list, node, mp)) {
if (msdp_peer_sa_filter(mp, sa)) {
if (PIM_DEBUG_MSDP_EVENTS)
zlog_debug("MSDP peer %pI4 filter SA out %s",
&mp->peer, sa->sg_str);
if (pim_msdp_log_sa_events(sa->pim))
zlog_info("MSDP peer %pI4 filter SA out %s", &mp->peer, sa->sg_str);

continue;
}

Expand Down Expand Up @@ -583,9 +582,10 @@ void pim_msdp_pkt_sa_tx_one_to_one_peer(struct pim_msdp_peer *mp,

/* Don't push it if filtered. */
if (msdp_peer_sa_filter(mp, &sa)) {
if (PIM_DEBUG_MSDP_EVENTS)
zlog_debug("MSDP peer %pI4 filter SA out (%pI4, %pI4)",
&mp->peer, &sa.sg.src, &sa.sg.grp);
if (pim_msdp_log_sa_events(mp->pim))
zlog_info("MSDP peer %pI4 filter SA out (%pI4, %pI4)", &mp->peer,
&sa.sg.src, &sa.sg.grp);

return;
}

Expand Down Expand Up @@ -641,11 +641,10 @@ static void pim_msdp_pkt_sa_rx_one(struct pim_msdp_peer *mp, struct in_addr rp)
/* Filter incoming SA with configured access list. */
if (mp->acl_in) {
acl = access_list_lookup(AFI_IP, mp->acl_in);
if (msdp_access_list_apply(acl, &sg.src, &sg.grp) ==
FILTER_DENY) {
if (PIM_DEBUG_MSDP_EVENTS)
zlog_debug("MSDP peer %pI4 filter SA in (%pI4, %pI4)",
&mp->peer, &sg.src, &sg.grp);
if (msdp_access_list_apply(acl, &sg.src, &sg.grp) == FILTER_DENY) {
if (pim_msdp_log_sa_events(mp->pim))
zlog_info("MSDP peer %pI4 filter SA in (%pI4, %pI4)", &mp->peer,
&sg.src, &sg.grp);
return;
}
}
Expand Down
6 changes: 6 additions & 0 deletions pimd/pim_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ const struct frr_yang_module_info frr_pim_info = {
.modify = pim_msdp_log_neighbor_events_modify,
}
},
{
.xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp/log-sa-events",
.cbs = {
.modify = pim_msdp_log_sa_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 @@ -55,6 +55,7 @@ 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_log_sa_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 @@ -1065,6 +1065,7 @@ 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);
pim6_msdp_err(pim_msdp_log_sa_events_modify, nb_cb_modify_args);

#if PIM_IPV != 6
/*
Expand Down Expand Up @@ -1096,6 +1097,35 @@ int pim_msdp_log_neighbor_events_modify(struct nb_cb_modify_args *args)
return NB_OK;
}

/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp/log-sa-events
*/
int pim_msdp_log_sa_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_SA_EVENTS);
else
UNSET_FLAG(pim->log_flags, PIM_MSDP_LOG_SA_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
7 changes: 7 additions & 0 deletions yang/frr-pim.yang
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ module frr-pim {
description
"Log all MSDP neighbor related events.";
}

leaf log-sa-events {
type boolean;
default false;
description
"Log all MSDP SA related events.";
}
}

list msdp-mesh-groups {
Expand Down

0 comments on commit fc39bfa

Please sign in to comment.