]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: reduce indentation in log_address_debug() or friends
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Apr 2021 20:43:22 +0000 (05:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Apr 2021 20:43:22 +0000 (05:43 +0900)
src/network/networkd-address.c
src/network/networkd-nexthop.c
src/network/networkd-route.c
src/network/networkd-routing-policy-rule.c

index e589fff150d21c3d6cc0a8bb28f46f3eda17ad23..724b0f95d3142e8dcfe5aa5d464221763aa0a03f 100644 (file)
@@ -486,37 +486,38 @@ int link_has_ipv6_address(Link *link, const struct in6_addr *address) {
 }
 
 static void log_address_debug(const Address *address, const char *str, const Link *link) {
+        _cleanup_free_ char *addr = NULL, *peer = NULL;
+        char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX];
+        const char *valid_str = NULL, *preferred_str = NULL;
+        bool has_peer;
+
         assert(address);
         assert(str);
         assert(link);
 
-        if (DEBUG_LOGGING) {
-                _cleanup_free_ char *addr = NULL, *peer = NULL;
-                char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX];
-                const char *valid_str = NULL, *preferred_str = NULL;
-                bool has_peer;
-
-                (void) in_addr_to_string(address->family, &address->in_addr, &addr);
-                has_peer = in_addr_is_set(address->family, &address->in_addr_peer);
-                if (has_peer)
-                        (void) in_addr_to_string(address->family, &address->in_addr_peer, &peer);
-
-                if (address->cinfo.ifa_valid != CACHE_INFO_INFINITY_LIFE_TIME)
-                        valid_str = format_timespan(valid_buf, FORMAT_TIMESPAN_MAX,
-                                                    address->cinfo.ifa_valid * USEC_PER_SEC,
-                                                    USEC_PER_SEC);
-
-                if (address->cinfo.ifa_prefered != CACHE_INFO_INFINITY_LIFE_TIME)
-                        preferred_str = format_timespan(preferred_buf, FORMAT_TIMESPAN_MAX,
-                                                        address->cinfo.ifa_prefered * USEC_PER_SEC,
-                                                        USEC_PER_SEC);
-
-                log_link_debug(link, "%s address: %s%s%s/%u (valid %s%s, preferred %s%s)",
-                               str, strnull(addr), has_peer ? " peer " : "",
-                               has_peer ? strnull(peer) : "", address->prefixlen,
-                               valid_str ? "for " : "forever", strempty(valid_str),
-                               preferred_str ? "for " : "forever", strempty(preferred_str));
-        }
+        if (!DEBUG_LOGGING)
+                return;
+
+        (void) in_addr_to_string(address->family, &address->in_addr, &addr);
+        has_peer = in_addr_is_set(address->family, &address->in_addr_peer);
+        if (has_peer)
+                (void) in_addr_to_string(address->family, &address->in_addr_peer, &peer);
+
+        if (address->cinfo.ifa_valid != CACHE_INFO_INFINITY_LIFE_TIME)
+                valid_str = format_timespan(valid_buf, FORMAT_TIMESPAN_MAX,
+                                            address->cinfo.ifa_valid * USEC_PER_SEC,
+                                            USEC_PER_SEC);
+
+        if (address->cinfo.ifa_prefered != CACHE_INFO_INFINITY_LIFE_TIME)
+                preferred_str = format_timespan(preferred_buf, FORMAT_TIMESPAN_MAX,
+                                                address->cinfo.ifa_prefered * USEC_PER_SEC,
+                                                USEC_PER_SEC);
+
+        log_link_debug(link, "%s address: %s%s%s/%u (valid %s%s, preferred %s%s)",
+                       str, strnull(addr), has_peer ? " peer " : "",
+                       has_peer ? strnull(peer) : "", address->prefixlen,
+                       valid_str ? "for " : "forever", strempty(valid_str),
+                       preferred_str ? "for " : "forever", strempty(preferred_str));
 }
 
 static int address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
index c32cc70798b098fbaf9160796733e900ce44c792..f3dbd98ed12b0b0b60f4ff155309c9813f2984df 100644 (file)
@@ -336,23 +336,24 @@ set_manager:
 }
 
 static void log_nexthop_debug(const NextHop *nexthop, uint32_t id, const char *str, const Link *link) {
+        _cleanup_free_ char *gw = NULL;
+
         assert(nexthop);
         assert(str);
 
         /* link may be NULL. */
 
-        if (DEBUG_LOGGING) {
-                _cleanup_free_ char *gw = NULL;
+        if (!DEBUG_LOGGING)
+                return;
 
-                (void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw);
+        (void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw);
 
-                if (nexthop->id == id)
-                        log_link_debug(link, "%s nexthop: id: %"PRIu32", gw: %s, blackhole: %s",
-                                       str, nexthop->id, strna(gw), yes_no(nexthop->blackhole));
-                else
-                        log_link_debug(link, "%s nexthop: id: %"PRIu32"→%"PRIu32", gw: %s, blackhole: %s",
-                                       str, nexthop->id, id, strna(gw), yes_no(nexthop->blackhole));
-        }
+        if (nexthop->id == id)
+                log_link_debug(link, "%s nexthop: id: %"PRIu32", gw: %s, blackhole: %s",
+                               str, nexthop->id, strna(gw), yes_no(nexthop->blackhole));
+        else
+                log_link_debug(link, "%s nexthop: id: %"PRIu32"→%"PRIu32", gw: %s, blackhole: %s",
+                               str, nexthop->id, id, strna(gw), yes_no(nexthop->blackhole));
 }
 
 static int nexthop_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
index 070131f4af7378e936ae0b5ffd01cfb00b364356..8f3d84129a840f8908f89b8d5864b6923a9f8305 100644 (file)
@@ -605,35 +605,36 @@ static bool route_type_is_reject(const Route *route) {
 }
 
 static void log_route_debug(const Route *route, const char *str, const Link *link, const Manager *m) {
+        _cleanup_free_ char *dst = NULL, *src = NULL, *gw = NULL, *prefsrc = NULL,
+                *table = NULL, *scope = NULL, *proto = NULL;
+
         assert(route);
         assert(str);
         assert(m);
 
         /* link may be NULL. */
 
-        if (DEBUG_LOGGING) {
-                _cleanup_free_ char *dst = NULL, *src = NULL, *gw = NULL, *prefsrc = NULL,
-                        *table = NULL, *scope = NULL, *proto = NULL;
-
-                if (in_addr_is_set(route->family, &route->dst))
-                        (void) in_addr_prefix_to_string(route->family, &route->dst, route->dst_prefixlen, &dst);
-                if (in_addr_is_set(route->family, &route->src))
-                        (void) in_addr_to_string(route->family, &route->src, &src);
-                if (in_addr_is_set(route->gw_family, &route->gw))
-                        (void) in_addr_to_string(route->gw_family, &route->gw, &gw);
-                if (in_addr_is_set(route->family, &route->prefsrc))
-                        (void) in_addr_to_string(route->family, &route->prefsrc, &prefsrc);
-                (void) route_scope_to_string_alloc(route->scope, &scope);
-                (void) manager_get_route_table_to_string(m, route->table, &table);
-                (void) route_protocol_full_to_string_alloc(route->protocol, &proto);
-
-                log_link_debug(link,
-                               "%s route: dst: %s, src: %s, gw: %s, prefsrc: %s, scope: %s, table: %s, proto: %s, type: %s, nexthop: %"PRIu32", priority: %"PRIu32,
-                               str, strna(dst), strna(src), strna(gw), strna(prefsrc),
-                               strna(scope), strna(table), strna(proto),
-                               strna(route_type_to_string(route->type)),
-                               route->nexthop_id, route->priority);
-        }
+        if (!DEBUG_LOGGING)
+                return;
+
+        if (in_addr_is_set(route->family, &route->dst))
+                (void) in_addr_prefix_to_string(route->family, &route->dst, route->dst_prefixlen, &dst);
+        if (in_addr_is_set(route->family, &route->src))
+                (void) in_addr_to_string(route->family, &route->src, &src);
+        if (in_addr_is_set(route->gw_family, &route->gw))
+                (void) in_addr_to_string(route->gw_family, &route->gw, &gw);
+        if (in_addr_is_set(route->family, &route->prefsrc))
+                (void) in_addr_to_string(route->family, &route->prefsrc, &prefsrc);
+        (void) route_scope_to_string_alloc(route->scope, &scope);
+        (void) manager_get_route_table_to_string(m, route->table, &table);
+        (void) route_protocol_full_to_string_alloc(route->protocol, &proto);
+
+        log_link_debug(link,
+                       "%s route: dst: %s, src: %s, gw: %s, prefsrc: %s, scope: %s, table: %s, proto: %s, type: %s, nexthop: %"PRIu32", priority: %"PRIu32,
+                       str, strna(dst), strna(src), strna(gw), strna(prefsrc),
+                       strna(scope), strna(table), strna(proto),
+                       strna(route_type_to_string(route->type)),
+                       route->nexthop_id, route->priority);
 }
 
 static int route_set_netlink_message(const Route *route, sd_netlink_message *req, Link *link) {
index 03bdd4e640fd02a72b0bab8dc0b80f2a7f872011..14e079eed30a77892c0012bec9014f12ac4a4b58 100644 (file)
@@ -391,6 +391,8 @@ static int routing_policy_rule_consume_foreign(Manager *m, RoutingPolicyRule *ru
 }
 
 static void log_routing_policy_rule_debug(const RoutingPolicyRule *rule, int family, const char *str, const Link *link, const Manager *m) {
+        _cleanup_free_ char *from = NULL, *to = NULL, *table = NULL;
+
         assert(rule);
         assert(IN_SET(family, AF_INET, AF_INET6));
         assert(str);
@@ -398,18 +400,17 @@ static void log_routing_policy_rule_debug(const RoutingPolicyRule *rule, int fam
 
         /* link may be NULL. */
 
-        if (DEBUG_LOGGING) {
-                _cleanup_free_ char *from = NULL, *to = NULL, *table = NULL;
+        if (!DEBUG_LOGGING)
+                return;
 
-                (void) in_addr_prefix_to_string(family, &rule->from, rule->from_prefixlen, &from);
-                (void) in_addr_prefix_to_string(family, &rule->to, rule->to_prefixlen, &to);
-                (void) manager_get_route_table_to_string(m, rule->table, &table);
+        (void) in_addr_prefix_to_string(family, &rule->from, rule->from_prefixlen, &from);
+        (void) in_addr_prefix_to_string(family, &rule->to, rule->to_prefixlen, &to);
+        (void) manager_get_route_table_to_string(m, rule->table, &table);
 
-                log_link_debug(link,
-                               "%s routing policy rule: priority: %"PRIu32", %s -> %s, iif: %s, oif: %s, table: %s",
-                               str, rule->priority, strna(from), strna(to),
-                               strna(rule->iif), strna(rule->oif), strna(table));
-        }
+        log_link_debug(link,
+                       "%s routing policy rule: priority: %"PRIu32", %s -> %s, iif: %s, oif: %s, table: %s",
+                       str, rule->priority, strna(from), strna(to),
+                       strna(rule->iif), strna(rule->oif), strna(table));
 }
 
 static int routing_policy_rule_set_netlink_message(const RoutingPolicyRule *rule, sd_netlink_message *m, Link *link) {