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 /ospf6d/ospf6_message.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 'ospf6d/ospf6_message.c')
| -rw-r--r-- | ospf6d/ospf6_message.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index 87c905af3f..9bd337ba12 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -56,8 +56,8 @@ static const struct message ospf6_message_type_str [] = { OSPF6_MESSAGE_TYPE_LSREQ, "LSReq" }, { OSPF6_MESSAGE_TYPE_LSUPDATE, "LSUpdate" }, { OSPF6_MESSAGE_TYPE_LSACK, "LSAck" }, + { 0 } }; -static const size_t ospf6_message_type_str_max = array_size(ospf6_message_type_str); /* Minimum (besides the standard OSPF packet header) lengths for OSPF packets of particular types, offset is the "type" field. */ @@ -1207,7 +1207,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) { if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) zlog_debug ("%s: undersized (%u B) %s packet", __func__, - bytesonwire, LOOKUP (ospf6_message_type_str, oh->type)); + bytesonwire, lookup_msg(ospf6_message_type_str, oh->type, NULL)); return MSG_NG; } /* type-specific deeper validation */ @@ -1220,7 +1220,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) return MSG_OK; if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) zlog_debug ("%s: alignment error in %s packet", - __func__, LOOKUP (ospf6_message_type_str, oh->type)); + __func__, lookup_msg(ospf6_message_type_str, oh->type, NULL)); return MSG_NG; case OSPF6_MESSAGE_TYPE_DBDESC: /* RFC5340 A.3.3, packet header + OSPF6_DB_DESC_MIN_SIZE bytes followed @@ -1239,7 +1239,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) return MSG_OK; if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) zlog_debug ("%s: alignment error in %s packet", - __func__, LOOKUP (ospf6_message_type_str, oh->type)); + __func__, lookup_msg(ospf6_message_type_str, oh->type, NULL)); return MSG_NG; case OSPF6_MESSAGE_TYPE_LSUPDATE: /* RFC5340 A.3.5, packet header + OSPF6_LS_UPD_MIN_SIZE bytes followed @@ -1269,7 +1269,7 @@ ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) return MSG_NG; } if (test != MSG_OK && IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) - zlog_debug ("%s: anomaly in %s packet", __func__, LOOKUP (ospf6_message_type_str, oh->type)); + zlog_debug ("%s: anomaly in %s packet", __func__, lookup_msg(ospf6_message_type_str, oh->type, NULL)); return test; } @@ -1577,7 +1577,7 @@ ospf6_receive (struct thread *thread) inet_ntop (AF_INET6, &src, srcname, sizeof (srcname)); inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname)); zlog_debug ("%s received on %s", - LOOKUP (ospf6_message_type_str, oh->type), oi->interface->name); + lookup_msg(ospf6_message_type_str, oh->type, NULL), oi->interface->name); zlog_debug (" src: %s", srcname); zlog_debug (" dst: %s", dstname); @@ -1665,7 +1665,7 @@ ospf6_send (struct in6_addr *src, struct in6_addr *dst, else memset (srcname, 0, sizeof (srcname)); zlog_debug ("%s send on %s", - LOOKUP (ospf6_message_type_str, oh->type), oi->interface->name); + lookup_msg(ospf6_message_type_str, oh->type, NULL), oi->interface->name); zlog_debug (" src: %s", srcname); zlog_debug (" dst: %s", dstname); |
