From 56223d926dc6ff75f16a97b2ca62b49589aac2cb Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 5 Feb 2021 09:44:49 +0900 Subject: [PATCH] network: introduce log_nexthop_debug() --- src/network/networkd-nexthop.c | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c index 7a5a648148..44a1a9100c 100644 --- a/src/network/networkd-nexthop.c +++ b/src/network/networkd-nexthop.c @@ -217,6 +217,21 @@ static int nexthop_add(Link *link, NextHop *in, NextHop **ret) { return is_new; } +static void log_nexthop_debug(const NextHop *nexthop, const char *str, const Link *link) { + assert(nexthop); + assert(str); + assert(link); + + if (DEBUG_LOGGING) { + _cleanup_free_ char *gw = NULL; + + (void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw); + + log_link_debug(link, "%s nexthop: id: %"PRIu32", gw: %s", + str, nexthop->id, strna(gw)); + } +} + static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { int r; @@ -254,14 +269,7 @@ static int nexthop_configure(NextHop *nexthop, Link *link) { assert(link->ifindex > 0); assert(IN_SET(nexthop->family, AF_INET, AF_INET6)); - if (DEBUG_LOGGING) { - _cleanup_free_ char *gw = NULL; - - if (!in_addr_is_null(nexthop->family, &nexthop->gw)) - (void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw); - - log_link_debug(link, "Configuring nexthop: gw: %s", strna(gw)); - } + log_nexthop_debug(nexthop, "Configuring", link); r = sd_rtnl_message_new_nexthop(link->manager->rtnl, &req, RTM_NEWNEXTHOP, nexthop->family, @@ -343,7 +351,6 @@ int link_set_nexthop(Link *link) { int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) { _cleanup_(nexthop_freep) NextHop *tmp = NULL; - _cleanup_free_ char *gateway = NULL; NextHop *nexthop = NULL; uint32_t ifindex; uint16_t type; @@ -415,15 +422,12 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, (void) nexthop_get(link, tmp, &nexthop); - if (DEBUG_LOGGING) - (void) in_addr_to_string(tmp->family, &tmp->gw, &gateway); - switch (type) { case RTM_NEWNEXTHOP: if (nexthop) - log_link_debug(link, "Received remembered nexthop: %s, id: %d", strna(gateway), tmp->id); + log_nexthop_debug(tmp, "Received remembered", link); else { - log_link_debug(link, "Remembering foreign nexthop: %s, id: %d", strna(gateway), tmp->id); + log_nexthop_debug(tmp, "Remembering foreign", link); r = nexthop_add_foreign(link, tmp, &nexthop); if (r < 0) { log_link_warning_errno(link, r, "Could not remember foreign nexthop, ignoring: %m"); @@ -432,12 +436,8 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, } break; case RTM_DELNEXTHOP: - if (nexthop) { - log_link_debug(link, "Forgetting nexthop: %s, id: %d", strna(gateway), tmp->id); - nexthop_free(nexthop); - } else - log_link_debug(link, "Kernel removed a nexthop we don't remember: %s, id: %d, ignoring.", - strna(gateway), tmp->id); + log_nexthop_debug(tmp, nexthop ? "Forgetting" : "Kernel removed unknown", link); + nexthop_free(nexthop); break; default: