summaryrefslogtreecommitdiff
path: root/bgpd/bgp_debug.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-06-20 23:56:50 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-06-21 15:22:21 +0000
commit56b40679304df9c4bfcfd5764af24f1d35b86142 (patch)
tree755de54cbc890545f73efe5f1f4d1843506d1860 /bgpd/bgp_debug.c
parentd368cd48b94cb9a22b9733200d8cfd94c71338ce (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 'bgpd/bgp_debug.c')
-rw-r--r--bgpd/bgp_debug.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c
index a39ec90cc6..8a2ec3b498 100644
--- a/bgpd/bgp_debug.c
+++ b/bgpd/bgp_debug.c
@@ -85,8 +85,8 @@ const struct message bgp_status_msg[] =
{ Established, "Established" },
{ Clearing, "Clearing" },
{ Deleted, "Deleted" },
+ { 0 }
};
-const int bgp_status_msg_max = BGP_STATUS_MAX;
/* BGP message type string. */
const char *bgp_type_str[] =
@@ -110,16 +110,16 @@ static const struct message bgp_notify_msg[] =
{ BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"},
{ BGP_NOTIFY_CEASE, "Cease"},
{ BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
+ { 0 }
};
-static const int bgp_notify_msg_max = BGP_NOTIFY_MAX;
static const struct message bgp_notify_head_msg[] =
{
{ BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
{ BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
- { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}
+ { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"},
+ { 0 }
};
-static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
static const struct message bgp_notify_open_msg[] =
{
@@ -131,8 +131,8 @@ static const struct message bgp_notify_open_msg[] =
{ BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
{ BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
{ BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
+ { 0 }
};
-static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
static const struct message bgp_notify_update_msg[] =
{
@@ -148,8 +148,8 @@ static const struct message bgp_notify_update_msg[] =
{ BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
{ BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
{ BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
+ { 0 }
};
-static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
static const struct message bgp_notify_cease_msg[] =
{
@@ -162,8 +162,8 @@ static const struct message bgp_notify_cease_msg[] =
{ BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
{ BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
{ BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
+ { 0 }
};
-static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
static const struct message bgp_notify_capability_msg[] =
{
@@ -171,8 +171,8 @@ static const struct message bgp_notify_capability_msg[] =
{ BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
{ BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
{ BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
+ { 0 }
};
-static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
/* Origin strings. */
const char *bgp_origin_str[] = {"i","e","?"};
@@ -464,7 +464,7 @@ bgp_dump_attr (struct attr *attr, char *buf, size_t size)
const char *
bgp_notify_code_str (char code)
{
- return LOOKUP_DEF (bgp_notify_msg, code, "Unrecognized Error Code");
+ return lookup_msg (bgp_notify_msg, code, "Unrecognized Error Code");
}
const char *
@@ -474,23 +474,23 @@ bgp_notify_subcode_str (char code, char subcode)
switch (code)
{
case BGP_NOTIFY_HEADER_ERR:
- return LOOKUP_DEF (bgp_notify_head_msg, subcode,
+ return lookup_msg (bgp_notify_head_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_OPEN_ERR:
- return LOOKUP_DEF (bgp_notify_open_msg, subcode,
+ return lookup_msg (bgp_notify_open_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_UPDATE_ERR:
- return LOOKUP_DEF (bgp_notify_update_msg, subcode,
+ return lookup_msg (bgp_notify_update_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_HOLD_ERR:
break;
case BGP_NOTIFY_FSM_ERR:
break;
case BGP_NOTIFY_CEASE:
- return LOOKUP_DEF (bgp_notify_cease_msg, subcode,
+ return lookup_msg (bgp_notify_cease_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_CAPABILITY_ERR:
- return LOOKUP_DEF (bgp_notify_capability_msg, subcode,
+ return lookup_msg (bgp_notify_capability_msg, subcode,
"Unrecognized Error Subcode");
}
return "";