From 9add3b8812e75c2dc5cc858c2a6a0bc26b4316d2 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 2 Aug 2016 21:44:29 -0400 Subject: [PATCH] pimd: Add ability to debug pim Register packets Allow the user to specify the ability to debug pim register packets. Signed-off-by: Donald Sharp --- pimd/pim_cmd.c | 31 +++++++++++++++++++++---------- pimd/pim_cmd.h | 1 + pimd/pim_register.c | 31 ++++++++++++++++++++++++++++--- pimd/pim_vty.c | 5 +++++ pimd/pimd.h | 4 ++++ 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 9d1602ac40..f3d1244e9a 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -3752,23 +3752,29 @@ DEFUN (debug_pim_packets, DEFUN (debug_pim_packets_filter, debug_pim_packets_filter_cmd, - "debug pim packets ", + "debug pim packets ", DEBUG_STR DEBUG_PIM_STR DEBUG_PIM_PACKETS_STR DEBUG_PIM_HELLO_PACKETS_STR - DEBUG_PIM_J_P_PACKETS_STR) + DEBUG_PIM_J_P_PACKETS_STR + DEBUG_PIM_PIM_REG_PACKETS_STR) { int idx_hello_join = 3; - if (strncmp(argv[idx_hello_join]->arg,"h",1) == 0) + if (strncmp(argv[idx_hello_join]->arg,"h",1) == 0) { PIM_DO_DEBUG_PIM_HELLO; - vty_out (vty, "PIM Hello debugging is on %s", VTY_NEWLINE); + vty_out (vty, "PIM Hello debugging is on%s", VTY_NEWLINE); } - else if (strncmp(argv[idx_hello_join]->arg,"j",1) == 0) + else if (strncmp(argv[idx_hello_join]->arg,"j",1) == 0) { PIM_DO_DEBUG_PIM_J_P; - vty_out (vty, "PIM Join/Prune debugging is on %s", VTY_NEWLINE); + vty_out (vty, "PIM Join/Prune debugging is on%s", VTY_NEWLINE); + } + else if (strncmp(argv[idx_hello_join]->arg,"r",1) == 0) + { + PIM_DO_DEBUG_PIM_REG; + vty_out (vty, "PIM Register debugging is on%s", VTY_NEWLINE); } return CMD_SUCCESS; } @@ -3790,7 +3796,7 @@ DEFUN (no_debug_pim_packets, DEFUN (no_debug_pim_packets_filter, no_debug_pim_packets_filter_cmd, - "no debug pim packets ", + "no debug pim packets ", NO_STR DEBUG_STR DEBUG_PIM_STR @@ -3799,17 +3805,22 @@ DEFUN (no_debug_pim_packets_filter, DEBUG_PIM_J_P_PACKETS_STR) { int idx_hello_join = 4; - if (strncmp(argv[idx_hello_join]->arg,"h",1) == 0) + if (strncmp(argv[idx_hello_join]->arg,"h",1) == 0) { PIM_DONT_DEBUG_PIM_HELLO; vty_out (vty, "PIM Hello debugging is off %s", VTY_NEWLINE); } - else if (strncmp(argv[idx_hello_join]->arg,"j",1) == 0) + else if (strncmp(argv[idx_hello_join]->arg,"j",1) == 0) { PIM_DONT_DEBUG_PIM_J_P; vty_out (vty, "PIM Join/Prune debugging is off %s", VTY_NEWLINE); } - return CMD_SUCCESS; + else if (strncmp (argv[idx_hello_join]->arg, "r", 1) == 0) + { + PIM_DONT_DEBUG_PIM_REG; + vty_out (vty, "PIM Register debugging is off%s", VTY_NEWLINE); + } + return CMD_SUCCESS; } diff --git a/pimd/pim_cmd.h b/pimd/pim_cmd.h index 6e6e80d4f2..d5e5c6a304 100644 --- a/pimd/pim_cmd.h +++ b/pimd/pim_cmd.h @@ -48,6 +48,7 @@ #define DEBUG_PIM_PACKETS_STR "PIM protocol packets\n" #define DEBUG_PIM_HELLO_PACKETS_STR "PIM Hello protocol packets\n" #define DEBUG_PIM_J_P_PACKETS_STR "PIM Join/Prune protocol packets\n" +#define DEBUG_PIM_PIM_REG_PACKETS_STR "PIM Register/Reg-Stop protocol packets\n" #define DEBUG_PIM_PACKETDUMP_STR "PIM packet dump\n" #define DEBUG_PIM_PACKETDUMP_SEND_STR "Dump sent packets\n" #define DEBUG_PIM_PACKETDUMP_RECV_STR "Dump received packets\n" diff --git a/pimd/pim_register.c b/pimd/pim_register.c index aaf05bbb19..5da8a677ef 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -77,6 +77,12 @@ pim_register_stop_send (struct interface *ifp, struct prefix *sg, uint8_t *b1; struct prefix p; + if (PIM_DEBUG_PIM_REG) + { + zlog_debug ("Sending Register stop for %s to %s on %s", + pim_str_sg_dump (sg), inet_ntoa(originator), ifp->name); + } + memset (buffer, 0, 3000); b1 = (uint8_t *)buffer + PIM_MSG_REGISTER_STOP_LEN; @@ -120,9 +126,6 @@ pim_register_stop_recv (uint8_t *buf, int buf_size) struct prefix sg; int l; - if (PIM_DEBUG_PIM_PACKETDUMP_RECV) - pim_pkt_dump ("Received Register Stop", buf, buf_size); - l = pim_parse_addr_group (&group, buf, buf_size); buf += l; buf_size -= l; @@ -130,6 +133,13 @@ pim_register_stop_recv (uint8_t *buf, int buf_size) memset (&sg, 0, sizeof (struct prefix)); sg.u.sg.src = source.u.prefix4; sg.u.sg.grp = group.u.prefix4; + + if (PIM_DEBUG_PIM_REG) + { + zlog_debug ("Received Register stop for %s", + pim_str_sg_dump (&sg)); + } + upstream = pim_upstream_find (&sg); if (!upstream) { @@ -162,6 +172,13 @@ pim_register_send (const uint8_t *buf, int buf_size, struct pim_rpf *rpg, int nu struct pim_interface *pinfo; struct interface *ifp; + if (PIM_DEBUG_PIM_REG) + { + char rp_str[100]; + strcpy (rp_str, inet_ntoa (rpg->rpf_addr)); + zlog_debug ("Sending %sRegister Packet to %s", null_register ? "NULL " : "", rp_str); + } + ifp = rpg->source_nexthop.interface; pinfo = (struct pim_interface *)ifp->info; if (!pinfo) { @@ -257,6 +274,14 @@ pim_register_recv (struct interface *ifp, return 0; } + if (PIM_DEBUG_PIM_REG) + { + char src_str[100]; + + pim_inet4_dump ("", src_addr, src_str, sizeof (src_str)); + zlog_debug ("Received Register message from %s on %s", src_str, ifp->name); + } + /* * Please note this is not drawn to get the correct bit/data size * diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index c6fb3464b1..9c3df6bbdc 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -108,6 +108,11 @@ pim_debug_config_write (struct vty *vty) ++writes; } + if (PIM_DEBUG_PIM_REG) { + vty_out (vty, "debug pim packets register%s", VTY_NEWLINE); + ++writes; + } + if (PIM_DEBUG_STATIC) { vty_out (vty, "debug pim static%s", VTY_NEWLINE); ++writes; diff --git a/pimd/pimd.h b/pimd/pimd.h index 6ff36a2a51..e91959948a 100644 --- a/pimd/pimd.h +++ b/pimd/pimd.h @@ -69,6 +69,7 @@ #define PIM_MASK_PIM_HELLO (1 << 14) #define PIM_MASK_PIM_J_P (1 << 15) #define PIM_MASK_STATIC (1 << 16) +#define PIM_MASK_PIM_REG (1 << 17) const char *const PIM_ALL_SYSTEMS; const char *const PIM_ALL_ROUTERS; @@ -135,6 +136,7 @@ extern int32_t qpim_register_probe_time; #define PIM_DEBUG_MROUTE (qpim_debugs & PIM_MASK_MROUTE) #define PIM_DEBUG_PIM_HELLO (qpim_debugs & PIM_MASK_PIM_HELLO) #define PIM_DEBUG_PIM_J_P (qpim_debugs & PIM_MASK_PIM_J_P) +#define PIM_DEBUG_PIM_REG (qpim_debugs & PIM_MASK_PIM_REG) #define PIM_DEBUG_STATIC (qpim_debugs & PIM_MASK_STATIC) #define PIM_DEBUG_EVENTS (qpim_debugs & (PIM_MASK_PIM_EVENTS | PIM_MASK_IGMP_EVENTS)) @@ -155,6 +157,7 @@ extern int32_t qpim_register_probe_time; #define PIM_DO_DEBUG_MROUTE (qpim_debugs |= PIM_MASK_MROUTE) #define PIM_DO_DEBUG_PIM_HELLO (qpim_debugs |= PIM_MASK_PIM_HELLO) #define PIM_DO_DEBUG_PIM_J_P (qpim_debugs |= PIM_MASK_PIM_J_P) +#define PIM_DO_DEBUG_PIM_REG (qpim_debugs |= PIM_MASK_PIM_REG) #define PIM_DO_DEBUG_STATIC (qpim_debugs |= PIM_MASK_STATIC) #define PIM_DONT_DEBUG_PIM_EVENTS (qpim_debugs &= ~PIM_MASK_PIM_EVENTS) @@ -171,6 +174,7 @@ extern int32_t qpim_register_probe_time; #define PIM_DONT_DEBUG_MROUTE (qpim_debugs &= ~PIM_MASK_MROUTE) #define PIM_DONT_DEBUG_PIM_HELLO (qpim_debugs &= ~PIM_MASK_PIM_HELLO) #define PIM_DONT_DEBUG_PIM_J_P (qpim_debugs &= ~PIM_MASK_PIM_J_P) +#define PIM_DONT_DEBUG_PIM_REG (qpim_debugs &= ~PIM_MASK_PIM_REG) #define PIM_DONT_DEBUG_STATIC (qpim_debugs &= ~PIM_MASK_STATIC) void pim_init(void); -- 2.39.5