diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkctl.c | 6 | ||||
-rw-r--r-- | src/network/networkd-address.c | 9 | ||||
-rw-r--r-- | src/network/networkd-can.c | 8 | ||||
-rw-r--r-- | src/network/networkd-conf.c | 4 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.c | 24 | ||||
-rw-r--r-- | src/network/networkd-nexthop.c | 8 | ||||
-rw-r--r-- | src/network/networkd-route.c | 15 |
7 files changed, 26 insertions, 48 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 9bbfe177b1..0ebb11cefa 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -2121,16 +2121,14 @@ static int link_status_one( } if (info->has_bitrates) { - char tx[FORMAT_BYTES_MAX], rx[FORMAT_BYTES_MAX]; - r = table_add_many(table, TABLE_EMPTY, TABLE_STRING, "Bit Rate (Tx/Rx):"); if (r < 0) return table_log_add_error(r); r = table_add_cell_stringf(table, NULL, "%sbps/%sbps", - format_bytes_full(tx, sizeof tx, info->tx_bitrate, 0), - format_bytes_full(rx, sizeof rx, info->rx_bitrate, 0)); + FORMAT_BYTES_FULL(info->tx_bitrate, 0), + FORMAT_BYTES_FULL(info->rx_bitrate, 0)); if (r < 0) return table_log_add_error(r); } diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 35305aff99..3a4ab629f8 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -622,7 +622,6 @@ int manager_has_address(Manager *manager, int family, const union in_addr_union static void log_address_debug(const Address *address, const char *str, const Link *link) { _cleanup_free_ char *addr = NULL, *peer = NULL, *flags_str = NULL; - char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX]; const char *valid_str = NULL, *preferred_str = NULL; bool has_peer; @@ -639,14 +638,10 @@ static void log_address_debug(const Address *address, const char *str, const Lin (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); + valid_str = FORMAT_TIMESPAN(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); + preferred_str = FORMAT_TIMESPAN(address->cinfo.ifa_prefered * USEC_PER_SEC, USEC_PER_SEC); (void) address_flags_to_string_alloc(address->flags, address->family, &flags_str); diff --git a/src/network/networkd-can.c b/src/network/networkd-can.c index 1fa37a0584..950b4134dd 100644 --- a/src/network/networkd-can.c +++ b/src/network/networkd-can.c @@ -107,7 +107,6 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { } if (link->network->can_restart_us > 0) { - char time_string[FORMAT_TIMESPAN_MAX]; uint64_t restart_ms; if (link->network->can_restart_us == USEC_INFINITY) @@ -115,12 +114,11 @@ int can_set_netlink_message(Link *link, sd_netlink_message *m) { else restart_ms = DIV_ROUND_UP(link->network->can_restart_us, USEC_PER_MSEC); - format_timespan(time_string, FORMAT_TIMESPAN_MAX, restart_ms * 1000, MSEC_PER_SEC); - if (restart_ms > UINT32_MAX) - return log_link_debug_errno(link, SYNTHETIC_ERRNO(ERANGE), "restart timeout (%s) too big.", time_string); + return log_link_debug_errno(link, SYNTHETIC_ERRNO(ERANGE), "restart timeout (%s) too big.", + FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC)); - log_link_debug(link, "Setting restart = %s", time_string); + log_link_debug(link, "Setting restart = %s", FORMAT_TIMESPAN(restart_ms * 1000, MSEC_PER_SEC)); r = sd_netlink_message_append_u32(m, IFLA_CAN_RESTART_MS, restart_ms); if (r < 0) diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c index 0b55ef29a2..9190dbfc53 100644 --- a/src/network/networkd-conf.c +++ b/src/network/networkd-conf.c @@ -29,10 +29,8 @@ int manager_parse_config_file(Manager *m) { return r; if (m->use_speed_meter && m->speed_meter_interval_usec < SPEED_METER_MINIMUM_TIME_INTERVAL) { - char buf[FORMAT_TIMESPAN_MAX]; - log_warning("SpeedMeterIntervalSec= is too small, using %s.", - format_timespan(buf, sizeof buf, SPEED_METER_MINIMUM_TIME_INTERVAL, USEC_PER_SEC)); + FORMAT_TIMESPAN(SPEED_METER_MINIMUM_TIME_INTERVAL, USEC_PER_SEC)); m->speed_meter_interval_usec = SPEED_METER_MINIMUM_TIME_INTERVAL; } diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 367be0a756..ccf2ec5b3f 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -373,7 +373,6 @@ static int dhcp6_pd_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Lin } static void log_dhcp6_pd_address(Link *link, const Address *address) { - char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX]; const char *valid_str = NULL, *preferred_str = NULL; _cleanup_free_ char *buffer = NULL; int log_level; @@ -388,13 +387,9 @@ static void log_dhcp6_pd_address(Link *link, const Address *address) { (void) in6_addr_prefix_to_string(&address->in_addr.in6, address->prefixlen, &buffer); 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); + valid_str = FORMAT_TIMESPAN(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); + preferred_str = FORMAT_TIMESPAN(address->cinfo.ifa_prefered * USEC_PER_SEC, USEC_PER_SEC); log_link_full(link, log_level, "DHCPv6-PD address %s (valid %s%s, preferred %s%s)", strna(buffer), @@ -1061,8 +1056,6 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link * } static void log_dhcp6_address(Link *link, const Address *address, char **ret) { - char valid_buf[FORMAT_TIMESPAN_MAX], preferred_buf[FORMAT_TIMESPAN_MAX]; - const char *valid_str = NULL, *preferred_str = NULL; _cleanup_free_ char *buffer = NULL; bool by_ndisc = false; Address *existing; @@ -1074,14 +1067,11 @@ static void log_dhcp6_address(Link *link, const Address *address, char **ret) { assert(address->family == AF_INET6); (void) in6_addr_prefix_to_string(&address->in_addr.in6, address->prefixlen, &buffer); - 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); + + const char *valid_str = address->cinfo.ifa_valid == CACHE_INFO_INFINITY_LIFE_TIME ? NULL : + FORMAT_TIMESPAN(address->cinfo.ifa_valid * USEC_PER_SEC, USEC_PER_SEC); + const char *preferred_str = address->cinfo.ifa_prefered == CACHE_INFO_INFINITY_LIFE_TIME ? NULL : + FORMAT_TIMESPAN(address->cinfo.ifa_prefered * USEC_PER_SEC, USEC_PER_SEC); r = address_get(link, address, &existing); if (r < 0) { diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c index a52e5dcb16..87f4ee4b10 100644 --- a/src/network/networkd-nexthop.c +++ b/src/network/networkd-nexthop.c @@ -15,6 +15,7 @@ #include "networkd-route.h" #include "parse-util.h" #include "set.h" +#include "stdio-util.h" #include "string-util.h" NextHop *nexthop_free(NextHop *nexthop) { @@ -368,7 +369,7 @@ set_manager: } static void log_nexthop_debug(const NextHop *nexthop, uint32_t id, const char *str, const Link *link) { - _cleanup_free_ char *gw = NULL, *new_id = NULL, *group = NULL; + _cleanup_free_ char *gw = NULL, *group = NULL; struct nexthop_grp *nhg; assert(nexthop); @@ -379,8 +380,9 @@ static void log_nexthop_debug(const NextHop *nexthop, uint32_t id, const char *s if (!DEBUG_LOGGING) return; + char new_id[STRLEN("→") + DECIMAL_STR_MAX(uint32_t)] = ""; if (nexthop->id != id) - (void) asprintf(&new_id, "→%"PRIu32, id); + xsprintf(new_id, "→%"PRIu32, id); (void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw); @@ -388,7 +390,7 @@ static void log_nexthop_debug(const NextHop *nexthop, uint32_t id, const char *s (void) strextendf_with_separator(&group, ",", "%"PRIu32":%"PRIu32, nhg->id, nhg->weight+1); log_link_debug(link, "%s nexthop: id: %"PRIu32"%s, gw: %s, blackhole: %s, group: %s", - str, nexthop->id, strempty(new_id), strna(gw), yes_no(nexthop->blackhole), strna(group)); + str, nexthop->id, new_id, strna(gw), yes_no(nexthop->blackhole), strna(group)); } static int link_nexthop_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 0ab4419eba..b6c19223b6 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -110,6 +110,7 @@ int manager_get_route_table_from_string(const Manager *m, const char *s, uint32_ int manager_get_route_table_to_string(const Manager *m, uint32_t table, char **ret) { _cleanup_free_ char *str = NULL; const char *s; + int r; assert(m); assert(ret); @@ -121,17 +122,13 @@ int manager_get_route_table_to_string(const Manager *m, uint32_t table, char **r if (!s) s = hashmap_get(m->route_table_names_by_number, UINT32_TO_PTR(table)); - if (s) { + if (s) /* Currently, this is only used in debugging logs. To not confuse any bug * reports, let's include the table number. */ - if (asprintf(&str, "%s(%" PRIu32 ")", s, table) < 0) - return -ENOMEM; - - *ret = TAKE_PTR(str); - return 0; - } - - if (asprintf(&str, "%" PRIu32, table) < 0) + r = asprintf(&str, "%s(%" PRIu32 ")", s, table); + else + r = asprintf(&str, "%" PRIu32, table); + if (r < 0) return -ENOMEM; *ret = TAKE_PTR(str); |