summaryrefslogtreecommitdiff
path: root/zebra/kernel_netlink.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-06-20 23:56:50 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-06-21 15:22:21 +0000
commit56b40679304df9c4bfcfd5764af24f1d35b86142 (patch)
tree755de54cbc890545f73efe5f1f4d1843506d1860 /zebra/kernel_netlink.c
parentd368cd48b94cb9a22b9733200d8cfd94c71338ce (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 'zebra/kernel_netlink.c')
-rw-r--r--zebra/kernel_netlink.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c
index e23801169b..be9376b07f 100644
--- a/zebra/kernel_netlink.c
+++ b/zebra/kernel_netlink.c
@@ -83,7 +83,7 @@ static const struct message nlmsg_str[] = {
{RTM_NEWNEIGH, "RTM_NEWNEIGH"},
{RTM_DELNEIGH, "RTM_DELNEIGH"},
{RTM_GETNEIGH, "RTM_GETNEIGH"},
- {0, NULL}
+ { 0 }
};
static const struct message rtproto_str[] = {
@@ -104,7 +104,7 @@ static const struct message rtproto_str[] = {
{RTPROT_ISIS, "IS-IS"},
{RTPROT_RIP, "RIP"},
{RTPROT_RIPNG, "RIPNG"},
- {0, NULL}
+ { 0 }
};
static const struct message family_str[] = {
@@ -113,13 +113,13 @@ static const struct message family_str[] = {
{AF_BRIDGE, "bridge"},
{RTNL_FAMILY_IPMR, "ipv4MR"},
{RTNL_FAMILY_IP6MR, "ipv6MR"},
- {0, NULL},
+ { 0 }
};
static const struct message rttype_str[] = {
{RTN_UNICAST, "unicast"},
{RTN_MULTICAST, "multicast"},
- {0, NULL},
+ { 0 }
};
extern struct thread_master *master;
@@ -425,25 +425,25 @@ rta_nest_end(struct rtattr *rta, struct rtattr *nest)
const char *
nl_msg_type_to_str (uint16_t msg_type)
{
- return lookup (nlmsg_str, msg_type);
+ return lookup_msg (nlmsg_str, msg_type, "");
}
const char *
nl_rtproto_to_str (u_char rtproto)
{
- return lookup (rtproto_str, rtproto);
+ return lookup_msg (rtproto_str, rtproto, "");
}
const char *
nl_family_to_str (u_char family)
{
- return lookup (family_str, family);
+ return lookup_msg (family_str, family, "");
}
const char *
nl_rttype_to_str (u_char rttype)
{
- return lookup (rttype_str, rttype);
+ return lookup_msg (rttype_str, rttype, "");
}
/*