diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-06-21 01:56:50 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-06-21 17:22:21 +0200 |
commit | 56b40679304df9c4bfcfd5764af24f1d35b86142 (patch) | |
tree | 755de54cbc890545f73efe5f1f4d1843506d1860 /ospfd/ospf_vty.c | |
parent | Merge pull request #730 from opensourcerouting/rbtree-improvement (diff) | |
download | frr-56b40679304df9c4bfcfd5764af24f1d35b86142.tar.xz frr-56b40679304df9c4bfcfd5764af24f1d35b86142.zip |
*: 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_vty.c')
-rw-r--r-- | ospfd/ospf_vty.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 99c8368a5..c831b1382 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -3372,7 +3372,7 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface json_object_string_add(json_interface_sub, "networkType", ospf_network_type_str[oi->type]); json_object_int_add(json_interface_sub, "cost", oi->output_cost); json_object_int_add(json_interface_sub, "transmitDelayMsecs", 1000 / OSPF_IF_PARAM (oi,transmit_delay)); - json_object_string_add(json_interface_sub, "state", LOOKUP (ospf_ism_state_msg, oi->state)); + json_object_string_add(json_interface_sub, "state", lookup_msg(ospf_ism_state_msg, oi->state, NULL)); json_object_int_add(json_interface_sub, "priority", PRIORITY (oi)); } else @@ -3388,7 +3388,7 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface oi->output_cost, VTY_NEWLINE); vty_out (vty, " Transmit Delay is %d sec, State %s, Priority %d%s", - OSPF_IF_PARAM (oi,transmit_delay), LOOKUP (ospf_ism_state_msg, oi->state), + OSPF_IF_PARAM (oi,transmit_delay), lookup_msg(ospf_ism_state_msg, oi->state, NULL), PRIORITY (oi), VTY_NEWLINE); } @@ -4123,11 +4123,11 @@ show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi, if (use_json) { json_object_int_add(json_sub, "nbrPriority", nbr->priority); - json_object_string_add(json_sub, "nbrState", LOOKUP (ospf_nsm_state_msg, nbr->state)); + json_object_string_add(json_sub, "nbrState", lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); } else vty_out (vty, " Neighbor priority is %d, State is %s,", - nbr->priority, LOOKUP (ospf_nsm_state_msg, nbr->state)); + nbr->priority, lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); /* Show state changes. */ if (use_json) @@ -4798,9 +4798,9 @@ show_ip_ospf_database_header (struct vty *vty, struct ospf_lsa *lsa) vty_out (vty, "%s", VTY_NEWLINE); } vty_out (vty, " LS Type: %s%s", - LOOKUP (ospf_lsa_type_msg, lsa->data->type), VTY_NEWLINE); + lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL), VTY_NEWLINE); vty_out (vty, " Link State ID: %s %s%s", inet_ntoa (lsa->data->id), - LOOKUP (ospf_link_state_id_type_msg, lsa->data->type), VTY_NEWLINE); + lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL), VTY_NEWLINE); vty_out (vty, " Advertising Router: %s%s", inet_ntoa (lsa->data->adv_router), VTY_NEWLINE); vty_out (vty, " LS Seq Number: %08lx%s", (u_long)ntohl (lsa->data->ls_seqnum), |