]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: show route scope, table, and type in debugging logs
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 7 Jul 2019 12:50:05 +0000 (21:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 12 Jul 2019 00:39:43 +0000 (09:39 +0900)
src/network/networkd-manager.c
src/network/networkd-route.c
src/network/networkd-route.h

index 5b2581a3ee3977ebee4418b214b007dfdacca30b..69af9746e054b782dc74db885b46c4c8c5a074f3 100644 (file)
@@ -436,6 +436,7 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, vo
         if (DEBUG_LOGGING) {
                 _cleanup_free_ char *buf_dst = NULL, *buf_dst_prefixlen = NULL,
                         *buf_src = NULL, *buf_gw = NULL, *buf_prefsrc = NULL;
+                char buf_scope[ROUTE_SCOPE_STR_MAX], buf_table[ROUTE_TABLE_STR_MAX];
 
                 if (!in_addr_is_null(family, &dst)) {
                         (void) in_addr_to_string(family, &dst, &buf_dst);
@@ -449,10 +450,13 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, vo
                         (void) in_addr_to_string(family, &prefsrc, &buf_prefsrc);
 
                 log_link_debug(link,
-                               "%s route: dst: %s%s, src: %s, gw: %s, prefsrc: %s",
+                               "%s route: dst: %s%s, src: %s, gw: %s, prefsrc: %s, scope: %s, table: %s, type: %s",
                                type == RTM_DELROUTE ? "Forgetting" : route ? "Updating remembered" : "Remembering",
                                strna(buf_dst), strempty(buf_dst_prefixlen),
-                               strna(buf_src), strna(buf_gw), strna(buf_prefsrc));
+                               strna(buf_src), strna(buf_gw), strna(buf_prefsrc),
+                               format_route_scope(scope, buf_scope, sizeof buf_scope),
+                               format_route_table(table, buf_table, sizeof buf_table),
+                               strna(route_type_to_string(rt_type)));
         }
 
         switch (type) {
index f13214c5ee6091e07dc5dc0b9c67f3cb1a549b4a..98fc8e4fe01fcf0c7085eea5903c7f030e282766 100644 (file)
@@ -14,6 +14,7 @@
 #include "set.h"
 #include "string-table.h"
 #include "string-util.h"
+#include "strxcpyx.h"
 #include "sysctl-util.h"
 #include "util.h"
 
@@ -413,6 +414,28 @@ int route_remove(Route *route, Link *link,
         if (r < 0)
                 return log_link_error_errno(link, r, "Could not create RTM_DELROUTE message: %m");
 
+        if (DEBUG_LOGGING) {
+                _cleanup_free_ char *dst = NULL, *dst_prefixlen = NULL, *src = NULL, *gw = NULL, *prefsrc = NULL;
+                char scope[ROUTE_SCOPE_STR_MAX], table[ROUTE_TABLE_STR_MAX];
+
+                if (!in_addr_is_null(route->family, &route->dst)) {
+                        (void) in_addr_to_string(route->family, &route->dst, &dst);
+                        (void) asprintf(&dst_prefixlen, "/%u", route->dst_prefixlen);
+                }
+                if (!in_addr_is_null(route->family, &route->src))
+                        (void) in_addr_to_string(route->family, &route->src, &src);
+                if (!in_addr_is_null(route->family, &route->gw))
+                        (void) in_addr_to_string(route->family, &route->gw, &gw);
+                if (!in_addr_is_null(route->family, &route->prefsrc))
+                        (void) in_addr_to_string(route->family, &route->prefsrc, &prefsrc);
+
+                log_link_debug(link, "Removing route: dst: %s%s, src: %s, gw: %s, prefsrc: %s, scope: %s, table: %s, type: %s",
+                               strna(dst), strempty(dst_prefixlen), strna(src), strna(gw), strna(prefsrc),
+                               format_route_scope(route->scope, scope, sizeof(scope)),
+                               format_route_table(route->table, table, sizeof(table)),
+                               strna(route_type_to_string(route->type)));
+        }
+
         if (in_addr_is_null(route->family, &route->gw) == 0) {
                 r = netlink_message_append_in_addr_union(req, RTA_GATEWAY, route->family, &route->gw);
                 if (r < 0)
@@ -514,6 +537,7 @@ int route_configure(
 
         if (DEBUG_LOGGING) {
                 _cleanup_free_ char *dst = NULL, *dst_prefixlen = NULL, *src = NULL, *gw = NULL, *prefsrc = NULL;
+                char scope[ROUTE_SCOPE_STR_MAX], table[ROUTE_TABLE_STR_MAX];
 
                 if (!in_addr_is_null(route->family, &route->dst)) {
                         (void) in_addr_to_string(route->family, &route->dst, &dst);
@@ -526,8 +550,11 @@ int route_configure(
                 if (!in_addr_is_null(route->family, &route->prefsrc))
                         (void) in_addr_to_string(route->family, &route->prefsrc, &prefsrc);
 
-                log_link_debug(link, "Configuring route: dst: %s%s, src: %s, gw: %s, prefsrc: %s",
-                               strna(dst), strempty(dst_prefixlen), strna(src), strna(gw), strna(prefsrc));
+                log_link_debug(link, "Configuring route: dst: %s%s, src: %s, gw: %s, prefsrc: %s, scope: %s, table: %s, type: %s",
+                               strna(dst), strempty(dst_prefixlen), strna(src), strna(gw), strna(prefsrc),
+                               format_route_scope(route->scope, scope, sizeof(scope)),
+                               format_route_table(route->table, table, sizeof(table)),
+                               strna(route_type_to_string(route->type)));
         }
 
         r = sd_rtnl_message_new_route(link->manager->rtnl, &req,
@@ -769,6 +796,50 @@ static const char * const route_type_table[__RTN_MAX] = {
 assert_cc(__RTN_MAX <= UCHAR_MAX);
 DEFINE_STRING_TABLE_LOOKUP(route_type, int);
 
+static const char * const route_scope_table[] = {
+        [RT_SCOPE_UNIVERSE] = "global",
+        [RT_SCOPE_SITE]     = "site",
+        [RT_SCOPE_LINK]     = "link",
+        [RT_SCOPE_HOST]     = "host",
+        [RT_SCOPE_NOWHERE]  = "nowhere",
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(route_scope, int);
+
+const char *format_route_scope(int scope, char *buf, size_t size) {
+        const char *s;
+        char *p = buf;
+
+        s = route_scope_to_string(scope);
+        if (s)
+                strpcpy(&p, size, s);
+        else
+                strpcpyf(&p, size, "%d", scope);
+
+        return buf;
+}
+
+static const char * const route_table_table[] = {
+        [RT_TABLE_DEFAULT] = "default",
+        [RT_TABLE_MAIN]    = "main",
+        [RT_TABLE_LOCAL]   = "local",
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(route_table, int);
+
+const char *format_route_table(int table, char *buf, size_t size) {
+        const char *s;
+        char *p = buf;
+
+        s = route_table_to_string(table);
+        if (s)
+                strpcpy(&p, size, s);
+        else
+                strpcpyf(&p, size, "%d", table);
+
+        return buf;
+}
+
 int config_parse_gateway(
                 const char *unit,
                 const char *filename,
index 2f0d052325eef019141967a293ad571a96d0b930..d6a023e930ed9f7cace6790134522c9d80422560 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #include "conf-parser.h"
+#include "macro.h"
 
 typedef struct Route Route;
 typedef struct NetworkConfigSection NetworkConfigSection;
@@ -70,6 +71,12 @@ int network_add_default_route_on_device(Network *network);
 const char* route_type_to_string(int t) _const_;
 int route_type_from_string(const char *s) _pure_;
 
+#define ROUTE_SCOPE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("nowhere") + 1)
+const char *format_route_scope(int scope, char *buf, size_t size);
+
+#define ROUTE_TABLE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("default") + 1)
+const char *format_route_table(int table, char *buf, size_t size);
+
 CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
 CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
 CONFIG_PARSER_PROTOTYPE(config_parse_destination);