diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-06-20 23:56:50 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-06-21 15:22:21 +0000 |
| commit | 56b40679304df9c4bfcfd5764af24f1d35b86142 (patch) | |
| tree | 755de54cbc890545f73efe5f1f4d1843506d1860 /ospfd/ospf_dump_api.c | |
| parent | d368cd48b94cb9a22b9733200d8cfd94c71338ce (diff) | |
*: simplify log message lookup
log.c provides functionality for associating a constant (typically a
protocol constant) with a string and finding the string given the
constant. However this is highly delicate code that is extremely prone
to stack overflows and off-by-one's due to requiring the developer to
always remember to update the array size constant and to do so correctly
which, as shown by example, is never a good idea.b
The original goal of this code was to try to implement lookups in O(1)
time without a linear search through the message array. Since this code
is used 99% of the time for debugs, it's worth the 5-6 additional cmp's
worst case if it means we avoid explitable bugs due to oversights...
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'ospfd/ospf_dump_api.c')
| -rw-r--r-- | ospfd/ospf_dump_api.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/ospfd/ospf_dump_api.c b/ospfd/ospf_dump_api.c index 54cc7fb666..09f5422ef5 100644 --- a/ospfd/ospf_dump_api.c +++ b/ospfd/ospf_dump_api.c @@ -40,8 +40,8 @@ const struct message ospf_ism_state_msg[] = { ISM_DROther, "DROther" }, { ISM_Backup, "Backup" }, { ISM_DR, "DR" }, + { 0 } }; -const int ospf_ism_state_msg_max = OSPF_ISM_STATE_MAX; const struct message ospf_nsm_state_msg[] = { @@ -55,8 +55,8 @@ const struct message ospf_nsm_state_msg[] = { NSM_Exchange, "Exchange" }, { NSM_Loading, "Loading" }, { NSM_Full, "Full" }, + { 0 } }; -const int ospf_nsm_state_msg_max = OSPF_NSM_STATE_MAX; const struct message ospf_lsa_type_msg[] = { @@ -72,8 +72,8 @@ const struct message ospf_lsa_type_msg[] = { OSPF_OPAQUE_LINK_LSA, "Link-Local Opaque-LSA" }, { OSPF_OPAQUE_AREA_LSA, "Area-Local Opaque-LSA" }, { OSPF_OPAQUE_AS_LSA, "AS-external Opaque-LSA" }, + { 0 } }; -const int ospf_lsa_type_msg_max = OSPF_MAX_LSA; const struct message ospf_link_state_id_type_msg[] = { @@ -89,8 +89,8 @@ const struct message ospf_link_state_id_type_msg[] = { OSPF_OPAQUE_LINK_LSA, "(Link-Local Opaque-Type/ID)" }, { OSPF_OPAQUE_AREA_LSA, "(Area-Local Opaque-Type/ID)" }, { OSPF_OPAQUE_AS_LSA, "(AS-external Opaque-Type/ID)" }, + { 0 } }; -const int ospf_link_state_id_type_msg_max = OSPF_MAX_LSA; const struct message ospf_network_type_msg[] = { @@ -100,8 +100,8 @@ const struct message ospf_network_type_msg[] = { OSPF_IFTYPE_NBMA, "NBMA" }, { OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint" }, { OSPF_IFTYPE_VIRTUALLINK, "Virtual-Link" }, + { 0 } }; -const int ospf_network_type_msg_max = OSPF_IFTYPE_MAX; /* AuType */ const struct message ospf_auth_type_str[] = @@ -109,9 +109,8 @@ const struct message ospf_auth_type_str[] = { OSPF_AUTH_NULL, "Null" }, { OSPF_AUTH_SIMPLE, "Simple" }, { OSPF_AUTH_CRYPTOGRAPHIC, "Cryptographic" }, + { 0 } }; -const size_t ospf_auth_type_str_max = sizeof (ospf_auth_type_str) / - sizeof (ospf_auth_type_str[0]); #define OSPF_OPTION_STR_MAXLEN 24 @@ -135,7 +134,7 @@ ospf_options_dump (u_char options) void ospf_lsa_header_dump (struct lsa_header *lsah) { - const char *lsah_type = LOOKUP (ospf_lsa_type_msg, lsah->type); + const char *lsah_type = lookup_msg(ospf_lsa_type_msg, lsah->type, NULL); zlog_debug (" LSA Header"); zlog_debug (" LS age %d", ntohs (lsah->ls_age)); |
