summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/generator/network-generator.c43
-rw-r--r--src/network/netdev/wireguard.c10
-rw-r--r--src/network/networkd-address-pool.c7
-rw-r--r--src/network/networkd-address.c12
-rw-r--r--src/network/networkd-dhcp-prefix-delegation.c59
-rw-r--r--src/network/networkd-link.c9
-rw-r--r--src/network/networkd-ndisc.c37
-rw-r--r--src/network/networkd-radv.c12
-rw-r--r--src/network/networkd-route.c14
-rw-r--r--src/network/networkd-routing-policy-rule.c8
10 files changed, 72 insertions, 139 deletions
diff --git a/src/network/generator/network-generator.c b/src/network/generator/network-generator.c
index a1b5511338..fee222f88e 100644
--- a/src/network/generator/network-generator.c
+++ b/src/network/generator/network-generator.c
@@ -1081,48 +1081,23 @@ void context_clear(Context *context) {
}
static int address_dump(Address *address, FILE *f) {
- _cleanup_free_ char *addr = NULL, *peer = NULL;
- int r;
-
- r = in_addr_prefix_to_string(address->family, &address->address, address->prefixlen, &addr);
- if (r < 0)
- return r;
-
- if (in_addr_is_set(address->family, &address->peer)) {
- r = in_addr_to_string(address->family, &address->peer, &peer);
- if (r < 0)
- return r;
- }
-
fprintf(f,
"\n[Address]\n"
"Address=%s\n",
- addr);
-
- if (peer)
- fprintf(f, "Peer=%s\n", peer);
-
+ IN_ADDR_PREFIX_TO_STRING(address->family, &address->address, address->prefixlen));
+ if (in_addr_is_set(address->family, &address->peer))
+ fprintf(f, "Peer=%s\n",
+ IN_ADDR_TO_STRING(address->family, &address->peer));
return 0;
}
static int route_dump(Route *route, FILE *f) {
- _cleanup_free_ char *dest = NULL, *gateway = NULL;
- int r;
-
- if (in_addr_is_set(route->family, &route->dest)) {
- r = in_addr_prefix_to_string(route->family, &route->dest, route->prefixlen, &dest);
- if (r < 0)
- return r;
- }
-
- r = in_addr_to_string(route->family, &route->gateway, &gateway);
- if (r < 0)
- return r;
-
fputs("\n[Route]\n", f);
- if (dest)
- fprintf(f, "Destination=%s\n", dest);
- fprintf(f, "Gateway=%s\n", gateway);
+ if (in_addr_is_set(route->family, &route->dest))
+ fprintf(f, "Destination=%s\n",
+ IN_ADDR_PREFIX_TO_STRING(route->family, &route->dest, route->prefixlen));
+ fprintf(f, "Gateway=%s\n",
+ IN_ADDR_TO_STRING(route->family, &route->gateway));
return 0;
}
diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c
index fc2c6288ae..2667a9fb2a 100644
--- a/src/network/netdev/wireguard.c
+++ b/src/network/netdev/wireguard.c
@@ -712,13 +712,11 @@ int config_parse_wireguard_allowed_ips(
masked = addr;
assert_se(in_addr_mask(family, &masked, prefixlen) >= 0);
- if (!in_addr_equal(family, &masked, &addr)) {
- _cleanup_free_ char *buf = NULL;
-
- (void) in_addr_prefix_to_string(family, &masked, prefixlen, &buf);
+ if (!in_addr_equal(family, &masked, &addr))
log_syntax(unit, LOG_WARNING, filename, line, 0,
- "Specified address '%s' is not properly masked, assuming '%s'.", word, strna(buf));
- }
+ "Specified address '%s' is not properly masked, assuming '%s'.",
+ word,
+ IN_ADDR_PREFIX_TO_STRING(family, &masked, prefixlen));
ipmask = new(WireguardIPmask, 1);
if (!ipmask)
diff --git a/src/network/networkd-address-pool.c b/src/network/networkd-address-pool.c
index 47dedfe6f2..51f092ac69 100644
--- a/src/network/networkd-address-pool.c
+++ b/src/network/networkd-address-pool.c
@@ -146,12 +146,7 @@ static int address_pool_acquire_one(AddressPool *p, int family, unsigned prefixl
return r;
if (!address_pool_prefix_is_taken(p, &u, prefixlen)) {
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *s = NULL;
-
- (void) in_addr_prefix_to_string(p->family, &u, prefixlen, &s);
- log_debug("Found range %s", strna(s));
- }
+ log_debug("Found range %s", IN_ADDR_PREFIX_TO_STRING(p->family, &u, prefixlen));
*found = u;
return 1;
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 5e37dc9907..8e8d5f7781 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -1465,11 +1465,8 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
r = address_add(link, tmp);
if (r < 0) {
- _cleanup_free_ char *buf = NULL;
-
- (void) in_addr_prefix_to_string(tmp->family, &tmp->in_addr, tmp->prefixlen, &buf);
log_link_warning_errno(link, r, "Failed to remember foreign address %s, ignoring: %m",
- strnull(buf));
+ IN_ADDR_PREFIX_TO_STRING(tmp->family, &tmp->in_addr, tmp->prefixlen));
return 0;
}
@@ -2022,12 +2019,11 @@ int network_drop_invalid_addresses(Network *network) {
/* Always use the setting specified later. So, remove the previously assigned setting. */
dup = set_remove(addresses, address);
if (dup) {
- _cleanup_free_ char *buf = NULL;
-
- (void) in_addr_prefix_to_string(address->family, &address->in_addr, address->prefixlen, &buf);
log_warning("%s: Duplicated address %s is specified at line %u and %u, "
"dropping the address setting specified at line %u.",
- dup->section->filename, strna(buf), address->section->line,
+ dup->section->filename,
+ IN_ADDR_PREFIX_TO_STRING(address->family, &address->in_addr, address->prefixlen),
+ address->section->line,
dup->section->line, dup->section->line);
/* address_free() will drop the address from addresses_by_section. */
address_free(dup);
diff --git a/src/network/networkd-dhcp-prefix-delegation.c b/src/network/networkd-dhcp-prefix-delegation.c
index d8d9475635..5c923c258c 100644
--- a/src/network/networkd-dhcp-prefix-delegation.c
+++ b/src/network/networkd-dhcp-prefix-delegation.c
@@ -358,21 +358,16 @@ static int dhcp_pd_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Requ
}
static void log_dhcp_pd_address(Link *link, const Address *address) {
- _cleanup_free_ char *buffer = NULL;
- int log_level;
-
assert(address);
assert(address->family == AF_INET6);
- log_level = address_get(link, address, NULL) >= 0 ? LOG_DEBUG : LOG_INFO;
+ int log_level = address_get(link, address, NULL) >= 0 ? LOG_DEBUG : LOG_INFO;
if (log_level < log_get_max_level())
return;
- (void) in6_addr_prefix_to_string(&address->in_addr.in6, address->prefixlen, &buffer);
-
log_link_full(link, log_level, "DHCP-PD address %s (valid %s, preferred %s)",
- strna(buffer),
+ IN6_ADDR_PREFIX_TO_STRING(&address->in_addr.in6, address->prefixlen),
FORMAT_LIFETIME(address->lifetime_valid_usec),
FORMAT_LIFETIME(address->lifetime_preferred_usec));
}
@@ -524,7 +519,6 @@ static int dhcp_pd_assign_subnet_prefix(
usec_t lifetime_valid_usec,
bool is_uplink) {
- _cleanup_free_ char *buf = NULL;
struct in6_addr prefix;
int r;
@@ -536,7 +530,7 @@ static int dhcp_pd_assign_subnet_prefix(
if (r < 0)
return r == -ERANGE ? 0 : r;
- (void) in6_addr_prefix_to_string(&prefix, 64, &buf);
+ const char *pretty = IN6_ADDR_PREFIX_TO_STRING(&prefix, 64);
if (link_radv_enabled(link) && link->network->dhcp_pd_announce) {
if (is_uplink)
@@ -546,23 +540,21 @@ static int dhcp_pd_assign_subnet_prefix(
if (r < 0)
return log_link_warning_errno(link, r,
"Failed to assign/update prefix %s to IPv6 Router Advertisement: %m",
- strna(buf));
+ pretty);
}
}
r = dhcp_pd_request_route(link, &prefix, lifetime_valid_usec);
if (r < 0)
return log_link_warning_errno(link, r,
- "Failed to assign/update route for prefix %s: %m",
- strna(buf));
+ "Failed to assign/update route for prefix %s: %m", pretty);
r = dhcp_pd_request_address(link, &prefix, lifetime_preferred_usec, lifetime_valid_usec);
if (r < 0)
return log_link_warning_errno(link, r,
- "Failed to assign/update address for prefix %s: %m",
- strna(buf));
+ "Failed to assign/update address for prefix %s: %m", pretty);
- log_link_debug(link, "Assigned prefix %s", strna(buf));
+ log_link_debug(link, "Assigned prefix %s", pretty);
return 1;
}
@@ -706,11 +698,8 @@ static int dhcp_request_unreachable_route(
assert(callback);
if (prefixlen >= 64) {
- _cleanup_free_ char *buf = NULL;
-
- (void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
log_link_debug(link, "Not adding a blocking route for DHCP delegated prefix %s since the prefix has length >= 64.",
- strna(buf));
+ IN6_ADDR_PREFIX_TO_STRING(addr, prefixlen));
return 0;
}
@@ -734,13 +723,9 @@ static int dhcp_request_unreachable_route(
route_unmark(existing);
r = link_request_route(link, TAKE_PTR(route), true, counter, callback, NULL);
- if (r < 0) {
- _cleanup_free_ char *buf = NULL;
-
- (void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
+ if (r < 0)
return log_link_error_errno(link, r, "Failed to request unreachable route for DHCP delegated prefix %s: %m",
- strna(buf));
- }
+ IN6_ADDR_PREFIX_TO_STRING(addr, prefixlen));
return 0;
}
@@ -770,7 +755,6 @@ static int dhcp6_request_unreachable_route(
}
static int dhcp_pd_prefix_add(Link *link, const struct in6_addr *prefix, uint8_t prefixlen) {
- _cleanup_free_ char *buf = NULL;
struct in_addr_prefix *p;
int r;
@@ -787,21 +771,20 @@ static int dhcp_pd_prefix_add(Link *link, const struct in6_addr *prefix, uint8_t
.address.in6 = *prefix,
};
- (void) in6_addr_prefix_to_string(prefix, prefixlen, &buf);
-
+ int log_level = set_contains(link->dhcp_pd_prefixes, p) ? LOG_DEBUG :
+ prefixlen > 64 || prefixlen < 48 ? LOG_WARNING : LOG_INFO;
log_link_full(link,
- set_contains(link->dhcp_pd_prefixes, p) ? LOG_DEBUG :
- prefixlen > 64 || prefixlen < 48 ? LOG_WARNING : LOG_INFO,
+ log_level,
"DHCP: received delegated prefix %s%s",
- strna(buf),
+ IN6_ADDR_PREFIX_TO_STRING(prefix, prefixlen),
prefixlen > 64 ? " with prefix length > 64, ignoring." :
prefixlen < 48 ? " with prefix length < 48, looks unusual.": "");
/* Store PD prefix even if prefixlen > 64, not to make logged at warning level so frequently. */
r = set_ensure_consume(&link->dhcp_pd_prefixes, &in_addr_prefix_hash_ops_free, p);
if (r < 0)
- return log_link_error_errno(link, r, "Failed to store DHCP delegated prefix %s: %m", strna(buf));
-
+ return log_link_error_errno(link, r, "Failed to store DHCP delegated prefix %s: %m",
+ IN6_ADDR_PREFIX_TO_STRING(prefix, prefixlen));
return 0;
}
@@ -968,13 +951,11 @@ int dhcp4_pd_prefix_acquired(Link *uplink) {
if (r < 0)
return log_link_warning_errno(uplink, r, "Failed to get DHCPv4 6rd option: %m");
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *buf = NULL;
-
- (void) in6_addr_prefix_to_string(&sixrd_prefix, sixrd_prefixlen, &buf);
+ if (DEBUG_LOGGING)
log_link_debug(uplink, "DHCPv4: 6rd option is acquired: IPv4_masklen=%u, 6rd_prefix=%s, br_address="IPV4_ADDRESS_FMT_STR,
- ipv4masklen, strna(buf), IPV4_ADDRESS_FMT_VAL(*br_addresses));
- }
+ ipv4masklen,
+ IN6_ADDR_PREFIX_TO_STRING(&sixrd_prefix, sixrd_prefixlen),
+ IPV4_ADDRESS_FMT_VAL(*br_addresses));
/* Calculate PD prefix */
dhcp4_calculate_pd_prefix(&ipv4address, ipv4masklen, &sixrd_prefix, sixrd_prefixlen, &pd_prefix, &pd_prefixlen);
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 63679505f7..e781f54a3c 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -426,12 +426,9 @@ void link_check_ready(Link *link) {
return (void) log_link_debug(link, "%s(): static addresses are not configured.", __func__);
SET_FOREACH(a, link->addresses)
- if (!address_is_ready(a)) {
- _cleanup_free_ char *str = NULL;
-
- (void) in_addr_prefix_to_string(a->family, &a->in_addr, a->prefixlen, &str);
- return (void) log_link_debug(link, "%s(): address %s is not ready.", __func__, strna(str));
- }
+ if (!address_is_ready(a))
+ return (void) log_link_debug(link, "%s(): address %s is not ready.", __func__,
+ IN_ADDR_PREFIX_TO_STRING(a->family, &a->in_addr, a->prefixlen));
if (!link->static_address_labels_configured)
return (void) log_link_debug(link, "%s(): static address labels are not configured.", __func__);
diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c
index 66127f36c9..2b663e57cc 100644
--- a/src/network/networkd-ndisc.c
+++ b/src/network/networkd-ndisc.c
@@ -420,10 +420,8 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
/* ndisc_generate_addresses() below requires the prefix length <= 64. */
if (prefixlen > 64) {
- _cleanup_free_ char *buf = NULL;
-
- (void) in6_addr_prefix_to_string(&prefix, prefixlen, &buf);
- log_link_debug(link, "Prefix is longer than 64, ignoring autonomous prefix %s.", strna(buf));
+ log_link_debug(link, "Prefix is longer than 64, ignoring autonomous prefix %s.",
+ IN6_ADDR_PREFIX_TO_STRING(&prefix, prefixlen));
return 0;
}
@@ -553,15 +551,11 @@ static int ndisc_router_process_prefix(Link *link, sd_ndisc_router *rt) {
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
if (in6_prefix_is_filtered(&a, prefixlen, link->network->ndisc_allow_listed_prefix, link->network->ndisc_deny_listed_prefix)) {
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *b = NULL;
-
- (void) in6_addr_prefix_to_string(&a, prefixlen, &b);
- if (!set_isempty(link->network->ndisc_allow_listed_prefix))
- log_link_debug(link, "Prefix '%s' is not in allow list, ignoring", strna(b));
- else
- log_link_debug(link, "Prefix '%s' is in deny list, ignoring", strna(b));
- }
+ if (DEBUG_LOGGING)
+ log_link_debug(link, "Prefix '%s' is %s, ignoring",
+ !set_isempty(link->network->ndisc_allow_listed_prefix) ? "not in allow list"
+ : "in deny list",
+ IN6_ADDR_PREFIX_TO_STRING(&a, prefixlen));
return 0;
}
@@ -617,16 +611,15 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
return 0;
}
- if (in6_prefix_is_filtered(&dst, prefixlen, link->network->ndisc_allow_listed_route_prefix, link->network->ndisc_deny_listed_route_prefix)) {
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *buf = NULL;
+ if (in6_prefix_is_filtered(&dst, prefixlen,
+ link->network->ndisc_allow_listed_route_prefix,
+ link->network->ndisc_deny_listed_route_prefix)) {
- (void) in6_addr_prefix_to_string(&dst, prefixlen, &buf);
- if (!set_isempty(link->network->ndisc_allow_listed_route_prefix))
- log_link_debug(link, "Route prefix '%s' is not in allow list, ignoring", strna(buf));
- else
- log_link_debug(link, "Route prefix '%s' is in deny list, ignoring", strna(buf));
- }
+ if (DEBUG_LOGGING)
+ log_link_debug(link, "Route prefix %s is %s, ignoring",
+ !set_isempty(link->network->ndisc_allow_listed_route_prefix) ? "not in allow list"
+ : "in deny list",
+ IN6_ADDR_PREFIX_TO_STRING(&dst, prefixlen));
return 0;
}
diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c
index 7fc1306d19..26448b518d 100644
--- a/src/network/networkd-radv.c
+++ b/src/network/networkd-radv.c
@@ -711,15 +711,11 @@ static int prefix_section_verify(Prefix *p) {
p->section->filename, p->prefixlen, p->section->line);
if (p->prefixlen > 64) {
- _cleanup_free_ char *str = NULL;
-
- if (p->assign)
- (void) in6_addr_prefix_to_string(&p->prefix, p->prefixlen, &str);
-
- log_info("%s: Unusual prefix length %u (> 64) is specified in [IPv6Prefix] section from line %u%s%s.",
- p->section->filename, p->prefixlen, p->section->line,
+ log_info("%s:%u: Unusual prefix length %u (> 64) is specified in [IPv6Prefix] section from line %s%s.",
+ p->section->filename, p->section->line,
+ p->prefixlen,
p->assign ? ", refusing to assign an address in " : "",
- p->assign ? strna(str) : "");
+ p->assign ? IN6_ADDR_PREFIX_TO_STRING(&p->prefix, p->prefixlen) : "");
p->assign = false;
}
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index 934fed3b7f..2708f9d79d 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -544,9 +544,9 @@ void link_mark_routes(Link *link, NetworkConfigSource source, const struct in6_a
}
static void log_route_debug(const Route *route, const char *str, const Link *link, const Manager *manager) {
- _cleanup_free_ char *state = NULL, *dst = NULL, *src = NULL, *gw_alloc = NULL, *prefsrc = NULL,
+ _cleanup_free_ char *state = NULL, *gw_alloc = NULL, *prefsrc = NULL,
*table = NULL, *scope = NULL, *proto = NULL, *flags = NULL;
- const char *gw = NULL;
+ const char *gw = NULL, *dst, *src;
assert(route);
assert(str);
@@ -558,10 +558,12 @@ static void log_route_debug(const Route *route, const char *str, const Link *lin
return;
(void) network_config_state_to_string_alloc(route->state, &state);
- if (in_addr_is_set(route->family, &route->dst) || route->dst_prefixlen > 0)
- (void) in_addr_prefix_to_string(route->family, &route->dst, route->dst_prefixlen, &dst);
- if (in_addr_is_set(route->family, &route->src) || route->src_prefixlen > 0)
- (void) in_addr_prefix_to_string(route->family, &route->src, route->src_prefixlen, &src);
+
+ dst = in_addr_is_set(route->family, &route->dst) || route->dst_prefixlen > 0 ?
+ IN_ADDR_PREFIX_TO_STRING(route->family, &route->dst, route->dst_prefixlen) : NULL;
+ src = in_addr_is_set(route->family, &route->src) || route->src_prefixlen > 0 ?
+ IN_ADDR_PREFIX_TO_STRING(route->family, &route->src, route->src_prefixlen) : NULL;
+
if (in_addr_is_set(route->gw_family, &route->gw)) {
(void) in_addr_to_string(route->gw_family, &route->gw, &gw_alloc);
gw = gw_alloc;
diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c
index 8f4297a86a..71c4360fa3 100644
--- a/src/network/networkd-routing-policy-rule.c
+++ b/src/network/networkd-routing-policy-rule.c
@@ -414,7 +414,7 @@ static int routing_policy_rule_acquire_priority(Manager *manager, RoutingPolicyR
}
static void log_routing_policy_rule_debug(const RoutingPolicyRule *rule, const char *str, const Link *link, const Manager *m) {
- _cleanup_free_ char *state = NULL, *from = NULL, *to = NULL, *table = NULL;
+ _cleanup_free_ char *state = NULL, *table = NULL;
assert(rule);
assert(IN_SET(rule->family, AF_INET, AF_INET6));
@@ -427,14 +427,14 @@ static void log_routing_policy_rule_debug(const RoutingPolicyRule *rule, const c
return;
(void) network_config_state_to_string_alloc(rule->state, &state);
- (void) in_addr_prefix_to_string(rule->family, &rule->from, rule->from_prefixlen, &from);
- (void) in_addr_prefix_to_string(rule->family, &rule->to, rule->to_prefixlen, &to);
(void) manager_get_route_table_to_string(m, rule->table, &table);
log_link_debug(link,
"%s %s routing policy rule (%s): priority: %"PRIu32", %s -> %s, iif: %s, oif: %s, table: %s",
str, strna(network_config_source_to_string(rule->source)), strna(state),
- rule->priority, strna(from), strna(to),
+ rule->priority,
+ IN_ADDR_PREFIX_TO_STRING(rule->family, &rule->from, rule->from_prefixlen),
+ IN_ADDR_PREFIX_TO_STRING(rule->family, &rule->to, rule->to_prefixlen),
strna(rule->iif), strna(rule->oif), strna(table));
}