From: Donald Sharp Date: Sat, 16 Jul 2016 08:49:32 +0000 (-0400) Subject: pimd: Refactor pim message type to an enum X-Git-Tag: frr-3.0-branchpoint~64^2~10^2~370 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=7643f0a1c651b84ff26a661cd6b7de806fe7fb3c;p=matthieu%2Ffrr.git pimd: Refactor pim message type to an enum Change the pim message type to an enum and add the ability to output a string based upon message type. Signed-off-by: Donald Sharp --- diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 5f5b2dd5ec..b3e4eddc28 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -46,6 +46,25 @@ static int on_pim_hello_send(struct thread *t); static int pim_hello_send(struct interface *ifp, uint16_t holdtime); +static +const char *pim_pim_msgtype2str (enum pim_msg_type type) +{ + switch (type) + { + case PIM_MSG_TYPE_HELLO: return "HELLO"; + case PIM_MSG_TYPE_REGISTER: return "REGISTER"; + case PIM_MSG_TYPE_REG_STOP: return "REGSTOP"; + case PIM_MSG_TYPE_JOIN_PRUNE: return "JP"; + case PIM_MSG_TYPE_BOOTSTRAP: return "BOOT"; + case PIM_MSG_TYPE_ASSERT: return "ASSERT"; + case PIM_MSG_TYPE_GRAFT: return "GRAFT"; + case PIM_MSG_TYPE_GRAFT_ACK: return "GACK"; + case PIM_MSG_TYPE_CANDIDATE: return "CANDIDATE"; + } + + return "UNKNOWN"; +} + static void sock_close(struct interface *ifp) { struct pim_interface *pim_ifp = ifp->info; @@ -121,7 +140,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) uint8_t *pim_msg; int pim_msg_len; uint8_t pim_version; - uint8_t pim_type; + enum pim_msg_type pim_type; uint16_t pim_checksum; /* received checksum */ uint16_t checksum; /* computed checksum */ struct pim_neighbor *neigh; @@ -203,9 +222,9 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) } if (PIM_DEBUG_PIM_PACKETS) { - zlog_debug("Recv PIM packet from %s to %s on %s: ttl=%d pim_version=%d pim_type=%d pim_msg_size=%d checksum=%x", - src_str, dst_str, ifp->name, ip_hdr->ip_ttl, - pim_version, pim_type, pim_msg_len, checksum); + zlog_debug("Recv PIM %s packet from %s to %s on %s: ttl=%d pim_version=%d pim_msg_size=%d checksum=%x", + pim_pim_msgtype2str (pim_type), src_str, dst_str, ifp->name, + ip_hdr->ip_ttl, pim_version, pim_msg_len, checksum); } switch (pim_type) diff --git a/pimd/pim_pim.h b/pimd/pim_pim.h index 4b378fb2c3..e3559a2d97 100644 --- a/pimd/pim_pim.h +++ b/pimd/pim_pim.h @@ -40,15 +40,17 @@ #define PIM_DEFAULT_CAN_DISABLE_JOIN_SUPPRESSION (0) /* boolean */ #define PIM_DEFAULT_T_PERIODIC (60) /* RFC 4601: 4.11. Timer Values */ -#define PIM_MSG_TYPE_HELLO (0) -#define PIM_MSG_TYPE_REGISTER (1) -#define PIM_MSG_TYPE_REG_STOP (2) -#define PIM_MSG_TYPE_JOIN_PRUNE (3) -#define PIM_MSG_TYPE_BOOTSTRAP (4) -#define PIM_MSG_TYPE_ASSERT (5) -#define PIM_MSG_TYPE_GRAFT (6) -#define PIM_MSG_TYPE_GRAFT_ACK (7) -#define PIM_MSG_TYPE_CANDIDATE (8) +enum pim_msg_type { + PIM_MSG_TYPE_HELLO = 0, + PIM_MSG_TYPE_REGISTER, + PIM_MSG_TYPE_REG_STOP, + PIM_MSG_TYPE_JOIN_PRUNE, + PIM_MSG_TYPE_BOOTSTRAP, + PIM_MSG_TYPE_ASSERT, + PIM_MSG_TYPE_GRAFT, + PIM_MSG_TYPE_GRAFT_ACK, + PIM_MSG_TYPE_CANDIDATE +}; #define PIM_MSG_HDR_OFFSET_VERSION(pim_msg) (pim_msg) #define PIM_MSG_HDR_OFFSET_TYPE(pim_msg) (pim_msg)