]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: simplify some netlink debug messages
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Fri, 29 Nov 2019 21:15:02 +0000 (18:15 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 14 Apr 2020 14:44:39 +0000 (11:44 -0300)
*   Use `inet_ntop` instead of `inet_ntoa`
*   Replace function name with `__func__`
*   Inline functions

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
zebra/rt_netlink.c

index dec18317d94a3ded5ee83b2e574b0366d2faefea..a645c05e62ee23882ec0d786f0fb8cdfa1eeada9 100644 (file)
@@ -1123,6 +1123,7 @@ static void _netlink_route_build_singlepath(const struct prefix *p,
        char label_buf[256];
        int num_labels = 0;
        struct vrf *vrf;
+       char addrstr[INET6_ADDRSTRLEN];
 
        assert(nexthop);
 
@@ -1179,11 +1180,10 @@ static void _netlink_route_build_singlepath(const struct prefix *p,
                                  &nexthop->src.ipv4, bytelen);
 
                if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               " 5549: _netlink_route_build_singlepath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
-                               routedesc, p, ipv4_ll_buf, label_buf,
-                               nexthop->ifindex, VRF_LOGNAME(vrf),
-                               nexthop->vrf_id);
+                       zlog_debug("%s: 5549 (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
+                                  __func__, routedesc, p, ipv4_ll_buf,
+                                  label_buf, nexthop->ifindex,
+                                  VRF_LOGNAME(vrf), nexthop->vrf_id);
                return;
        }
 
@@ -1204,12 +1204,14 @@ static void _netlink_route_build_singlepath(const struct prefix *p,
                                          &nexthop->src.ipv4, bytelen);
                }
 
-               if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
-                               routedesc, p, inet_ntoa(nexthop->gate.ipv4),
-                               label_buf, nexthop->ifindex, VRF_LOGNAME(vrf),
-                               nexthop->vrf_id);
+               if (IS_ZEBRA_DEBUG_KERNEL) {
+                       inet_ntop(AF_INET, &nexthop->gate.ipv4, addrstr,
+                                 sizeof(addrstr));
+                       zlog_debug("%s: (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
+                                  __func__, routedesc, p, addrstr, label_buf,
+                                  nexthop->ifindex, VRF_LOGNAME(vrf),
+                                  nexthop->vrf_id);
+               }
        }
 
        if (nexthop->type == NEXTHOP_TYPE_IPV6
@@ -1227,12 +1229,14 @@ static void _netlink_route_build_singlepath(const struct prefix *p,
                                          &nexthop->src.ipv6, bytelen);
                }
 
-               if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
-                               routedesc, p, inet6_ntoa(nexthop->gate.ipv6),
-                               label_buf, nexthop->ifindex, VRF_LOGNAME(vrf),
-                               nexthop->vrf_id);
+               if (IS_ZEBRA_DEBUG_KERNEL) {
+                       inet_ntop(AF_INET6, &nexthop->gate.ipv6, addrstr,
+                                 sizeof(addrstr));
+                       zlog_debug("%s: (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
+                                  __func__, routedesc, p, addrstr, label_buf,
+                                  nexthop->ifindex, VRF_LOGNAME(vrf),
+                                  nexthop->vrf_id);
+               }
        }
 
        /*
@@ -1254,10 +1258,9 @@ static void _netlink_route_build_singlepath(const struct prefix *p,
                }
 
                if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               "netlink_route_multipath() (%s): %pFX nexthop via if %u vrf %s(%u)",
-                               routedesc, p, nexthop->ifindex,
-                               VRF_LOGNAME(vrf), nexthop->vrf_id);
+                       zlog_debug("%s: (%s): %pFX nexthop via if %u vrf %s(%u)",
+                                  __func__, routedesc, p, nexthop->ifindex,
+                                  VRF_LOGNAME(vrf), nexthop->vrf_id);
        }
 }
 
@@ -1287,6 +1290,7 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc,
        char label_buf[256];
        int num_labels = 0;
        struct vrf *vrf;
+       char addrstr[INET6_ADDRSTRLEN];
 
        rtnh->rtnh_len = sizeof(*rtnh);
        rtnh->rtnh_flags = 0;
@@ -1356,8 +1360,8 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc,
 
                if (IS_ZEBRA_DEBUG_KERNEL)
                        zlog_debug(
-                               " 5549: netlink_route_build_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
-                               routedesc, p, ipv4_ll_buf, label_buf,
+                               "%s: 5549 (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
+                               __func__, routedesc, p, ipv4_ll_buf, label_buf,
                                nexthop->ifindex, VRF_LOGNAME(vrf),
                                nexthop->vrf_id);
                return;
@@ -1373,12 +1377,14 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc,
                else if (nexthop->src.ipv4.s_addr != INADDR_ANY)
                        *src = &nexthop->src;
 
-               if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
-                               routedesc, p, inet_ntoa(nexthop->gate.ipv4),
-                               label_buf, nexthop->ifindex, VRF_LOGNAME(vrf),
-                               nexthop->vrf_id);
+               if (IS_ZEBRA_DEBUG_KERNEL) {
+                       inet_ntop(AF_INET, &nexthop->gate.ipv4, addrstr,
+                                 sizeof(addrstr));
+                       zlog_debug( "%s: (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
+                                  __func__, routedesc, p, addrstr, label_buf,
+                                  nexthop->ifindex, VRF_LOGNAME(vrf),
+                                  nexthop->vrf_id);
+               }
        }
        if (nexthop->type == NEXTHOP_TYPE_IPV6
            || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
@@ -1391,12 +1397,14 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc,
                else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6))
                        *src = &nexthop->src;
 
-               if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
-                               routedesc, p, inet6_ntoa(nexthop->gate.ipv6),
-                               label_buf, nexthop->ifindex, VRF_LOGNAME(vrf),
-                               nexthop->vrf_id);
+               if (IS_ZEBRA_DEBUG_KERNEL) {
+                       inet_ntop(AF_INET, &nexthop->gate.ipv6, addrstr,
+                                 sizeof(addrstr));
+                       zlog_debug( "%s: (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
+                                  __func__, routedesc, p, addrstr, label_buf,
+                                  nexthop->ifindex, VRF_LOGNAME(vrf),
+                                  nexthop->vrf_id);
+               }
        }
 
        /*
@@ -1415,10 +1423,9 @@ _netlink_route_build_multipath(const struct prefix *p, const char *routedesc,
                        *src = &nexthop->src;
 
                if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               "netlink_route_multipath() (%s): %pFX nexthop via if %u vrf %s(%u)",
-                               routedesc, p, nexthop->ifindex,
-                               VRF_LOGNAME(vrf), nexthop->vrf_id);
+                       zlog_debug("%s: (%s): %pFX nexthop via if %u vrf %s(%u)",
+                                  __func__, routedesc, p, nexthop->ifindex,
+                                  VRF_LOGNAME(vrf), nexthop->vrf_id);
        }
 
        if (nexthop->weight)
@@ -1457,37 +1464,6 @@ _netlink_mpls_build_multipath(const struct prefix *p, const char *routedesc,
                                       rta, rtnh, rtmsg, src);
 }
 
-
-/* Log debug information for netlink_route_multipath
- * if debug logging is enabled.
- *
- * @param cmd: Netlink command which is to be processed
- * @param p: Prefix for which the change is due
- * @param family: Address family which the change concerns
- * @param zvrf: The vrf we are in
- * @param tableid: The table we are working on
- */
-static void _netlink_route_debug(int cmd, const struct prefix *p,
-                                int family, vrf_id_t vrfid,
-                                uint32_t tableid)
-{
-       if (IS_ZEBRA_DEBUG_KERNEL) {
-               char buf[PREFIX_STRLEN];
-               zlog_debug(
-                       "netlink_route_multipath(): %s %s vrf %s(%u) table_id: %u",
-                       nl_msg_type_to_str(cmd),
-                       prefix2str(p, buf, sizeof(buf)), vrf_id_to_name(vrfid),
-                       vrfid, tableid);
-       }
-}
-
-static void _netlink_nexthop_debug(int cmd, uint32_t id)
-{
-       if (IS_ZEBRA_DEBUG_KERNEL)
-               zlog_debug("netlink_nexthop(): %s, id=%u",
-                          nl_msg_type_to_str(cmd), id);
-}
-
 static void _netlink_mpls_debug(int cmd, uint32_t label, const char *routedesc)
 {
        if (IS_ZEBRA_DEBUG_KERNEL)
@@ -1650,7 +1626,11 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx,
                addattr32(&req->n, datalen, RTA_TABLE, table_id);
        }
 
-       _netlink_route_debug(cmd, p, family, dplane_ctx_get_vrf(ctx), table_id);
+       if (IS_ZEBRA_DEBUG_KERNEL)
+               zlog_debug(
+                       "%s: %s %pFX vrf %u(%u)", __func__,
+                       nl_msg_type_to_str(cmd), p, dplane_ctx_get_vrf(ctx),
+                       table_id);
 
        /*
         * If we are not updating the route and we have received
@@ -1840,8 +1820,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx,
        /* If there is no useful nexthop then return. */
        if (nexthop_num == 0) {
                if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug(
-                               "netlink_route_multipath(): No useful nexthop.");
+                       zlog_debug("%s: No useful nexthop.", __func__);
        }
 
        return 0;
@@ -2103,7 +2082,9 @@ nexthop_done:
                return -1;
        }
 
-       _netlink_nexthop_debug(cmd, id);
+       if (IS_ZEBRA_DEBUG_KERNEL)
+               zlog_debug("%s: %s, id=%u", __func__, nl_msg_type_to_str(cmd),
+                          id);
 
        return netlink_talk_info(netlink_talk_filter, &req.n,
                                 dplane_ctx_get_ns(ctx), 0);