]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: use LOOKUP() for ospf_packet_type_str
authorDenis Ovsienko <infrastation@yandex.ru>
Sun, 15 Jan 2012 15:12:19 +0000 (19:12 +0400)
committerDavid Lamparter <equinox@diac24.net>
Mon, 12 Mar 2012 10:04:54 +0000 (11:04 +0100)
* ospf_packet.h: add proper str/max extern declarations
* ospf_packet.c
  * ospf_packet_type_str: rewrite in "struct message", add max value
  * ospf_packet_add(): use LOOKUP()
  * ospf_write(): ditto
  * ospf_hello(): ditto
  * ospf_read(): ditto
* ospf_dump.h: the declaration does not belong here
* ospf_dump.c
  * ospf_header_dump(): use LOOKUP()
  * show_debugging_ospf(): ditto

ospfd/ospf_dump.c
ospfd/ospf_dump.h
ospfd/ospf_packet.c
ospfd/ospf_packet.h

index e65b2e3366b38bc7a576409c662eb6262d9d393d..8ace09578262d7d75ba13e588a8da57c4eb7d607 100644 (file)
@@ -661,7 +661,7 @@ ospf_header_dump (struct ospf_header *ospfh)
   zlog_debug ("Header");
   zlog_debug ("  Version %d", ospfh->version);
   zlog_debug ("  Type %d (%s)", ospfh->type,
-            ospf_packet_type_str[ospfh->type]);
+            LOOKUP (ospf_packet_type_str, ospfh->type));
   zlog_debug ("  Packet Len %d", ntohs (ospfh->length));
   zlog_debug ("  Router ID %s", inet_ntoa (ospfh->router_id));
   zlog_debug ("  Area ID %s", inet_ntoa (ospfh->area_id));
@@ -1457,7 +1457,7 @@ DEFUN (show_debugging_ospf,
     if (IS_DEBUG_OSPF_PACKET (i, SEND) && IS_DEBUG_OSPF_PACKET (i, RECV))
       {
        vty_out (vty, "  OSPF packet %s%s debugging is on%s",
-                ospf_packet_type_str[i + 1],
+                LOOKUP (ospf_packet_type_str, i + 1),
                 IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
                 VTY_NEWLINE);
       }
@@ -1465,12 +1465,12 @@ DEFUN (show_debugging_ospf,
       {
        if (IS_DEBUG_OSPF_PACKET (i, SEND))
          vty_out (vty, "  OSPF packet %s send%s debugging is on%s",
-                  ospf_packet_type_str[i + 1],
+                  LOOKUP (ospf_packet_type_str, i + 1),
                   IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
                   VTY_NEWLINE);
        if (IS_DEBUG_OSPF_PACKET (i, RECV))
          vty_out (vty, "  OSPF packet %s receive%s debugging is on%s",
-                  ospf_packet_type_str[i + 1],
+                  LOOKUP (ospf_packet_type_str, i + 1),
                   IS_DEBUG_OSPF_PACKET (i, DETAIL) ? " detail" : "",
                   VTY_NEWLINE);
       }
index fb813719b2eeb17e31a79e61685b80da89dc801a..455214f5f37bd4178db6d244699258be55558b61 100644 (file)
@@ -121,7 +121,6 @@ extern unsigned long term_debug_ospf_zebra;
 extern unsigned long term_debug_ospf_nssa;
 
 /* Message Strings. */
-extern const char *ospf_packet_type_str[];
 extern char *ospf_lsa_type_str[];
 
 /* Prototypes. */
index b714c27de0f73e33bd95d79967d76eea2218fffb..a8102da42e1f40f61cec9f883e93ad23723406c7 100644 (file)
 #include "ospfd/ospf_dump.h"
 
 /* Packet Type String. */
-const char *ospf_packet_type_str[] =
-{
-  "unknown",
-  "Hello",
-  "Database Description",
-  "Link State Request",
-  "Link State Update",
-  "Link State Acknowledgment",
+const struct message ospf_packet_type_str[] =
+{
+  { OSPF_MSG_HELLO,   "Hello"                     },
+  { OSPF_MSG_DB_DESC, "Database Description"      },
+  { OSPF_MSG_LS_REQ,  "Link State Request"        },
+  { OSPF_MSG_LS_UPD,  "Link State Update"         },
+  { OSPF_MSG_LS_ACK,  "Link State Acknowledgment" },
 };
+const size_t ospf_packet_type_str_max = sizeof (ospf_packet_type_str) /
+  sizeof (ospf_packet_type_str[0]);
 
 /* OSPF authentication checking function */
 static int
@@ -201,7 +202,7 @@ ospf_packet_add (struct ospf_interface *oi, struct ospf_packet *op)
               "destination %s) called with NULL obuf, ignoring "
               "(please report this bug)!\n",
               IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state),
-              ospf_packet_type_str[stream_getc_from(op->s, 1)],
+              LOOKUP (ospf_packet_type_str, stream_getc_from(op->s, 1)),
               inet_ntoa (op->dst));
       return;
     }
@@ -755,7 +756,7 @@ ospf_write (struct thread *thread)
        }
 
       zlog_debug ("%s sent to [%s] via [%s].",
-                ospf_packet_type_str[type], inet_ntoa (op->dst),
+                LOOKUP (ospf_packet_type_str, type), inet_ntoa (op->dst),
                 IF_NAME (oi));
 
       if (IS_DEBUG_OSPF_PACKET (type - 1, DETAIL))
@@ -801,7 +802,7 @@ ospf_hello (struct ip *iph, struct ospf_header *ospfh,
         {
           zlog_debug ("ospf_header[%s/%s]: selforiginated, "
                      "dropping.",
-                     ospf_packet_type_str[ospfh->type],
+                     LOOKUP (ospf_packet_type_str, ospfh->type),
                      inet_ntoa (iph->ip_src));
         }
       return;
@@ -2576,7 +2577,7 @@ ospf_read (struct thread *thread)
         }
 
       zlog_debug ("%s received from [%s] via [%s]",
-                 ospf_packet_type_str[ospfh->type],
+                 LOOKUP (ospf_packet_type_str, ospfh->type),
                  inet_ntoa (ospfh->router_id), IF_NAME (oi));
       zlog_debug (" src [%s],", inet_ntoa (iph->ip_src));
       zlog_debug (" dst [%s]", inet_ntoa (iph->ip_dst));
index 9a472081a6718c165140749ec620b380d4b39ee0..2115f111fb665774fcd8834cc5e2c79b8b9736c3 100644 (file)
@@ -163,4 +163,7 @@ extern int ospf_ls_ack_timer (struct thread *);
 extern int ospf_poll_timer (struct thread *);
 extern int ospf_hello_reply_timer (struct thread *);
 
+extern const struct message ospf_packet_type_str[];
+extern const size_t ospf_packet_type_str_max;
+
 #endif /* _ZEBRA_OSPF_PACKET_H */