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 /eigrpd/eigrp_hello.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 'eigrpd/eigrp_hello.c')
| -rw-r--r-- | eigrpd/eigrp_hello.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/eigrpd/eigrp_hello.c b/eigrpd/eigrp_hello.c index 3ac7c8add9..8750cf2dcd 100644 --- a/eigrpd/eigrp_hello.c +++ b/eigrpd/eigrp_hello.c @@ -66,11 +66,9 @@ static const struct message eigrp_general_tlv_type_str[] = { EIGRP_TLV_PEER_TERMINATION, "PEER_TERMINATION" }, { EIGRP_TLV_PEER_MTRLIST, "PEER_MTRLIST" }, { EIGRP_TLV_PEER_TIDLIST, "PEER_TIDLIST" }, + { 0 } }; -static const size_t eigrp_general_tlv_type_str_max = sizeof(eigrp_general_tlv_type_str) / - sizeof(eigrp_general_tlv_type_str[0]); - /* * @fn eigrp_hello_timer @@ -346,7 +344,7 @@ eigrp_hello_receive (struct eigrp *eigrp, struct ip *iph, struct eigrp_header *e if ((length > 0) && (length <= size)) { if (IS_DEBUG_EIGRP_PACKET(0, RECV)) - zlog_debug(" General TLV(%s)", LOOKUP(eigrp_general_tlv_type_str, type)); + zlog_debug(" General TLV(%s)", lookup_msg(eigrp_general_tlv_type_str, type, NULL)); // determine what General TLV is being processed switch (type) |
