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_ism.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_ism.c')
-rw-r--r-- | ospfd/ospf_ism.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c index 2a1f7bb32..b536491d8 100644 --- a/ospfd/ospf_ism.c +++ b/ospfd/ospf_ism.c @@ -540,8 +540,8 @@ ism_change_state (struct ospf_interface *oi, int state) /* Logging change of state. */ if (IS_DEBUG_OSPF (ism, ISM_STATUS)) zlog_debug("ISM[%s]: State change %s -> %s", IF_NAME(oi), - LOOKUP(ospf_ism_state_msg, oi->state), - LOOKUP(ospf_ism_state_msg, state)); + lookup_msg(ospf_ism_state_msg, oi->state, NULL), + lookup_msg(ospf_ism_state_msg, state, NULL)); old_state = oi->state; oi->state = state; @@ -606,7 +606,7 @@ ospf_ism_event (struct thread *thread) if (IS_DEBUG_OSPF (ism, ISM_EVENTS)) zlog_debug("ISM[%s]: %s (%s)", IF_NAME(oi), - LOOKUP(ospf_ism_state_msg, oi->state), + lookup_msg(ospf_ism_state_msg, oi->state, NULL), ospf_ism_event_str[event]); /* If state is changed. */ |