]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Add error messages in places where we have a decode problem
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 22 Jun 2018 18:22:02 +0000 (14:22 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 25 Jun 2018 14:02:48 +0000 (10:02 -0400)
When we receive a netlink message from the kernel we have
handler functions for when we send a netlink command, if these
return a failure ( < 0 ) then we output that we had a parse
issue.  But if all we get is:

2018-06-21T23:47:45.298156+00:00 qct-ix1-08 zebra[1484]: netlink-cmd (NS 0) filter function error

Then it is not very useful to figure out *where* the error happened.

Add more error code when in a decode path to hopefully allow us
to figure out where this message is coming from.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/if_netlink.c
zebra/rt_netlink.c
zebra/rule_netlink.c

index e6d324ab6a64d0697e44943f31c7bdd55e620bcb..5c84219418422842abf7cad504a8da98aa8408dd 100644 (file)
@@ -586,8 +586,13 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__,
+                        h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg)));
                return -1;
+       }
 
        /* We are interested in some AF_BRIDGE notifications. */
        if (ifi->ifi_family == AF_BRIDGE)
@@ -893,8 +898,13 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__,
+                        h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg)));
                return -1;
+       }
 
        memset(tb, 0, sizeof tb);
        netlink_parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
@@ -1105,8 +1115,12 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
        }
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg)));
                return -1;
+       }
 
        /* We are interested in some AF_BRIDGE notifications. */
        if (ifi->ifi_family == AF_BRIDGE)
index a5f288f54117f155eb1d8b652c0f9dd27e4d4528..90334915491e1c9f69c51314602c78fbf4386b3d 100644 (file)
@@ -295,8 +295,12 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
        }
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
                return -1;
+       }
 
        memset(tb, 0, sizeof tb);
        netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);
@@ -747,8 +751,13 @@ int netlink_route_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__,
+                        h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
                return -1;
+       }
 
        if (rtm->rtm_type == RTN_MULTICAST)
                netlink_route_change_read_multicast(h, ns_id, startup);
@@ -2356,8 +2365,12 @@ int netlink_neigh_change(struct nlmsghdr *h, ns_id_t ns_id)
 
        /* Length validity. */
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct ndmsg)));
                return -1;
+       }
 
        /* Is this a notification for the MAC FDB or IP neighbor table? */
        ndm = NLMSG_DATA(h);
index bcffdf47221e9980a4eb7d18f076322112db7d0e..c7a8517e17c73c0ea496db700a5df9db85d24960 100644 (file)
@@ -196,8 +196,12 @@ int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                return 0;
 
        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct fib_rule_hdr));
-       if (len < 0)
+       if (len < 0) {
+               zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
+                        __PRETTY_FUNCTION__, h->nlmsg_len,
+                        (size_t)NLMSG_LENGTH(sizeof(struct fib_rule_hdr)));
                return -1;
+       }
 
        frh = NLMSG_DATA(h);
        if (frh->family != AF_INET && frh->family != AF_INET6)