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_nsm.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_nsm.c')
| -rw-r--r-- | ospfd/ospf_nsm.c | 18 | 
1 files changed, 9 insertions, 9 deletions
diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c index b3888dd832..d5c41802ed 100644 --- a/ospfd/ospf_nsm.c +++ b/ospfd/ospf_nsm.c @@ -616,8 +616,8 @@ nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)    if (IS_DEBUG_OSPF (nsm, NSM_STATUS))      zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)",                 IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), -               LOOKUP (ospf_nsm_state_msg, nbr->state), -               LOOKUP (ospf_nsm_state_msg, next_state), +               lookup_msg(ospf_nsm_state_msg, nbr->state, NULL), +               lookup_msg(ospf_nsm_state_msg, next_state, NULL),                 ospf_nsm_event_str [event]);    /* Optionally notify about adjacency changes */ @@ -626,8 +626,8 @@ nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)         (next_state == NSM_Full) || (next_state < nbr->state)))      zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)",                  inet_ntoa (nbr->router_id), IF_NAME (nbr->oi), -                LOOKUP (ospf_nsm_state_msg, nbr->state), -                LOOKUP (ospf_nsm_state_msg, next_state), +                lookup_msg(ospf_nsm_state_msg, nbr->state, NULL), +                lookup_msg(ospf_nsm_state_msg, next_state, NULL),                  ospf_nsm_event_str [event]);    /* Advance in NSM */ @@ -735,8 +735,8 @@ nsm_change_state (struct ospf_neighbor *nbr, int state)        zlog_info ("nsm_change_state(%s, %s -> %s): "  		 "scheduling new router-LSA origination",  		 inet_ntoa (nbr->router_id), -		 LOOKUP(ospf_nsm_state_msg, old_state), -		 LOOKUP(ospf_nsm_state_msg, state)); +		 lookup_msg(ospf_nsm_state_msg, old_state, NULL), +		 lookup_msg(ospf_nsm_state_msg, state, NULL));        ospf_router_lsa_update_area (oi->area); @@ -807,7 +807,7 @@ ospf_nsm_event (struct thread *thread)    if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))      zlog_debug ("NSM[%s:%s]: %s (%s)", IF_NAME (nbr->oi),  	       inet_ntoa (nbr->router_id), -	       LOOKUP (ospf_nsm_state_msg, nbr->state), +	       lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),  	       ospf_nsm_event_str [event]);    next_state = NSM [nbr->state][event].next_state; @@ -829,9 +829,9 @@ ospf_nsm_event (struct thread *thread)            zlog_warn ("NSM[%s:%s]: %s (%s): "                       "Warning: action tried to change next_state to %s",                       IF_NAME (nbr->oi), inet_ntoa (nbr->router_id), -                     LOOKUP (ospf_nsm_state_msg, nbr->state), +                     lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),                       ospf_nsm_event_str [event], -                     LOOKUP (ospf_nsm_state_msg, func_state)); +                     lookup_msg(ospf_nsm_state_msg, func_state, NULL));          }      }  | 
