]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: Refactor pim message type to an enum
authorDonald Sharp <sharpd@cumulusnetwroks.com>
Sat, 16 Jul 2016 08:49:32 +0000 (04:49 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 22 Dec 2016 01:26:02 +0000 (20:26 -0500)
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 <sharpd@cumulusnetworks.com>
pimd/pim_pim.c
pimd/pim_pim.h

index 5f5b2dd5ece5b754daccb8ef3f26e60f5c209828..b3e4eddc283c8a8034c36dfd30172cbe36cf2015 100644 (file)
@@ -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)
index 4b378fb2c31131438ecf6b9d65bb7dfac61c383d..e3559a2d97b62032854bfdbbc9d3e67fed8c2448 100644 (file)
 #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)