From 7461e33ce1bf8c4593b03522e9e269e7fef3e67d Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 22 Jul 2011 16:17:10 -0500 Subject: [PATCH] core: move route logging to nm-netlink-utils.c --- src/nm-netlink-utils.c | 53 ++++++++++++++++++++++++++++++++++++++++++ src/nm-netlink-utils.h | 2 ++ src/nm-system.c | 42 +-------------------------------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/nm-netlink-utils.c b/src/nm-netlink-utils.c index 3e855b42d..643122582 100644 --- a/src/nm-netlink-utils.c +++ b/src/nm-netlink-utils.c @@ -18,9 +18,11 @@ * Copyright (C) 2011 Red Hat, Inc. */ +#include "logging/nm-logging.h" #include "nm-netlink-utils.h" #include "nm-netlink-monitor.h" +#include #include #include #include @@ -136,3 +138,54 @@ nm_netlink_route_delete (struct rtnl_route *route) return err == 0 ? TRUE : FALSE; } + +/** + * nm_netlink_dump_route: + * @route: the route to dump + * + * Logs the details of a route. + **/ +void +nm_netlink_dump_route (struct rtnl_route *route) +{ + char buf6[INET6_ADDRSTRLEN]; + char buf4[INET_ADDRSTRLEN]; + struct nl_addr *nl; + struct in6_addr *addr6 = NULL; + struct in_addr *addr4 = NULL; + int prefixlen = 0; + const char *sf = "UNSPEC"; + int family = rtnl_route_get_family (route); + guint32 log_level = LOGD_IP4 | LOGD_IP6; + + memset (buf6, 0, sizeof (buf6)); + memset (buf4, 0, sizeof (buf4)); + nl = rtnl_route_get_dst (route); + if (nl) { + if (nl_addr_get_family (nl) == AF_INET) { + addr4 = nl_addr_get_binary_addr (nl); + if (addr4) + inet_ntop (AF_INET, addr4, &buf4[0], sizeof (buf4)); + } else if (nl_addr_get_family (nl) == AF_INET6) { + addr6 = nl_addr_get_binary_addr (nl); + if (addr6) + inet_ntop (AF_INET6, addr6, &buf6[0], sizeof (buf6)); + } + prefixlen = nl_addr_get_prefixlen (nl); + } + + if (family == AF_INET) { + sf = "INET"; + log_level = LOGD_IP4; + } else if (family == AF_INET6) { + sf = "INET6"; + log_level = LOGD_IP6; + } + + nm_log_dbg (log_level, " route idx %d family %s (%d) addr %s/%d", + rtnl_route_get_oif (route), + sf, family, + strlen (buf4) ? buf4 : (strlen (buf6) ? buf6 : ""), + prefixlen); +} + diff --git a/src/nm-netlink-utils.h b/src/nm-netlink-utils.h index b85b98ad6..87531740e 100644 --- a/src/nm-netlink-utils.h +++ b/src/nm-netlink-utils.h @@ -32,4 +32,6 @@ gboolean nm_netlink_find_address (int ifindex, gboolean nm_netlink_route_delete (struct rtnl_route *route); +void nm_netlink_dump_route (struct rtnl_route *route); + #endif /* NM_NETLINK_MONITOR_H */ diff --git a/src/nm-system.c b/src/nm-system.c index 032990aad..a1dd69104 100644 --- a/src/nm-system.c +++ b/src/nm-system.c @@ -1245,46 +1245,6 @@ foreach_route (void (*callback)(struct nl_object *, gpointer), nl_cache_free (route_cache); } -static void -dump_route (struct rtnl_route *route) -{ - char buf6[INET6_ADDRSTRLEN]; - char buf4[INET_ADDRSTRLEN]; - struct nl_addr *nl; - struct in6_addr *addr6 = NULL; - struct in_addr *addr4 = NULL; - int prefixlen = 0; - const char *sf = "UNSPEC"; - int family = rtnl_route_get_family (route); - - memset (buf6, 0, sizeof (buf6)); - memset (buf4, 0, sizeof (buf4)); - nl = rtnl_route_get_dst (route); - if (nl) { - if (nl_addr_get_family (nl) == AF_INET) { - addr4 = nl_addr_get_binary_addr (nl); - if (addr4) - inet_ntop (AF_INET, addr4, &buf4[0], sizeof (buf4)); - } else if (nl_addr_get_family (nl) == AF_INET6) { - addr6 = nl_addr_get_binary_addr (nl); - if (addr6) - inet_ntop (AF_INET6, addr6, &buf6[0], sizeof (buf6)); - } - prefixlen = nl_addr_get_prefixlen (nl); - } - - if (family == AF_INET) - sf = "INET"; - else if (family == AF_INET6) - sf = "INET6"; - - nm_log_dbg (LOGD_IP4 | LOGD_IP6, " route idx %d family %s (%d) addr %s/%d", - rtnl_route_get_oif (route), - sf, family, - strlen (buf4) ? buf4 : (strlen (buf6) ? buf6 : ""), - prefixlen); -} - typedef struct { const char *iface; int iface_idx; @@ -1299,7 +1259,7 @@ check_one_route (struct nl_object *object, void *user_data) guint32 log_level = LOGD_IP4 | LOGD_IP6; if (nm_logging_level_enabled (LOGL_DEBUG)) - dump_route (route); + nm_netlink_dump_route (route); /* Delete all routes from this interface */ if (rtnl_route_get_oif (route) != data->iface_idx)