]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce log_nexthop_debug()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Feb 2021 00:44:49 +0000 (09:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 17 Feb 2021 18:54:50 +0000 (03:54 +0900)
src/network/networkd-nexthop.c

index 7a5a648148208fab8f7089e79acdf68e745d8f27..44a1a9100c234267c339edc76a9e8be01bd019b7 100644 (file)
@@ -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: