summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-05-06 17:15:01 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-05-12 10:30:45 +0900
commitb8ce3b44901bd6d058b7c53ee696954f00c1942d (patch)
tree44c6445478a690775d7d03035ba1d3b264235b3f /src
parent280323984b0f4b228333f8a64a3bd531274310fb (diff)
downloadsystemd-b8ce3b44901bd6d058b7c53ee696954f00c1942d.tar.gz
network: use IPV4_ADDRESS_FMT_STR/VAL macros and in6_addr_to_string() or friends
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-address.c20
-rw-r--r--src/network/networkd-dhcp4.c36
-rw-r--r--src/network/networkd-dhcp6.c100
-rw-r--r--src/network/networkd-ndisc.c91
-rw-r--r--src/network/networkd-network.h2
5 files changed, 121 insertions, 128 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 03e33ca644..78b9be2d54 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -1304,7 +1304,6 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
}
static void static_address_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
- _cleanup_free_ char *pretty = NULL;
Address *address;
Link *link;
int r;
@@ -1315,22 +1314,26 @@ static void static_address_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
address = (Address *) userdata;
link = address->link;
- (void) in_addr_to_string(address->family, &address->in_addr, &pretty);
+ assert(address->family == AF_INET);
+
switch (event) {
case SD_IPV4ACD_EVENT_STOP:
log_link_debug(link, "Stopping ACD client...");
return;
case SD_IPV4ACD_EVENT_BIND:
- log_link_debug(link, "Successfully claimed address %s", strna(pretty));
+ log_link_debug(link, "Successfully claimed address "IPV4_ADDRESS_FMT_STR,
+ IPV4_ADDRESS_FMT_VAL(address->in_addr.in));
link_check_ready(link);
break;
case SD_IPV4ACD_EVENT_CONFLICT:
- log_link_warning(link, "DAD conflict. Dropping address %s", strna(pretty));
+ log_link_warning(link, "DAD conflict. Dropping address "IPV4_ADDRESS_FMT_STR,
+ IPV4_ADDRESS_FMT_VAL(address->in_addr.in));
r = address_remove(address, link, NULL);
if (r < 0)
- log_link_error_errno(link, r, "Failed to drop DAD conflicted address %s", strna(pretty));;
+ log_link_error_errno(link, r, "Failed to drop DAD conflicted address "IPV4_ADDRESS_FMT_STR,
+ IPV4_ADDRESS_FMT_VAL(address->in_addr.in));
link_check_ready(link);
break;
@@ -1353,12 +1356,7 @@ static int ipv4_dad_configure(Address *address) {
if (address->family != AF_INET)
return 0;
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *pretty = NULL;
-
- (void) in_addr_to_string(address->family, &address->in_addr, &pretty);
- log_link_debug(address->link, "Starting IPv4ACD client. Probing address %s", strna(pretty));
- }
+ log_address_debug(address, "Starting IPv4ACD client. Probing", address->link);
if (!address->acd) {
r = sd_ipv4acd_new(&address->acd);
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index f20264be9e..01c5fcabd4 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -783,8 +783,7 @@ static int dhcp_lease_lost(Link *link) {
}
static void dhcp_address_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
- _cleanup_free_ char *pretty = NULL;
- union in_addr_union address = {};
+ struct in_addr address;
Link *link;
int r;
@@ -795,23 +794,21 @@ static void dhcp_address_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
switch (event) {
case SD_IPV4ACD_EVENT_STOP:
- log_link_debug(link, "Stopping ACD client for DHCP4...");
+ log_link_debug(link, "Stopping ACD client for DHCPv4 address.");
return;
case SD_IPV4ACD_EVENT_BIND:
if (DEBUG_LOGGING) {
- (void) sd_dhcp_lease_get_address(link->dhcp_lease, &address.in);
- (void) in_addr_to_string(AF_INET, &address, &pretty);
- log_link_debug(link, "Successfully claimed DHCP4 address %s", strna(pretty));
+ (void) sd_dhcp_lease_get_address(link->dhcp_lease, &address);
+ log_link_debug(link, "Successfully claimed DHCPv4 address "IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(address));
}
link->dhcp4_address_bind = true;
dhcp4_check_ready(link);
break;
case SD_IPV4ACD_EVENT_CONFLICT:
- (void) sd_dhcp_lease_get_address(link->dhcp_lease, &address.in);
- (void) in_addr_to_string(AF_INET, &address, &pretty);
- log_link_warning(link, "DAD conflict. Dropping DHCP4 address %s", strna(pretty));
+ (void) sd_dhcp_lease_get_address(link->dhcp_lease, &address);
+ log_link_warning(link, "DAD conflict. Dropping DHCPv4 address "IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(address));
r = sd_dhcp_client_send_decline(link->dhcp_client);
if (r < 0)
@@ -893,8 +890,7 @@ static int dhcp4_dad_update_mac(Link *link) {
}
static int dhcp4_start_acd(Link *link) {
- union in_addr_union addr;
- struct in_addr old;
+ struct in_addr addr, old;
int r;
if (!link->network->dhcp_send_decline)
@@ -907,7 +903,7 @@ static int dhcp4_start_acd(Link *link) {
link->dhcp4_address_bind = false;
- r = sd_dhcp_lease_get_address(link->dhcp_lease, &addr.in);
+ r = sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
if (r < 0)
return r;
@@ -915,7 +911,7 @@ static int dhcp4_start_acd(Link *link) {
if (r < 0)
return r;
- r = sd_ipv4acd_set_address(link->dhcp_acd, &addr.in);
+ r = sd_ipv4acd_set_address(link->dhcp_acd, &addr);
if (r < 0)
return r;
@@ -923,18 +919,10 @@ static int dhcp4_start_acd(Link *link) {
if (r < 0)
return r;
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *pretty = NULL;
-
- (void) in_addr_to_string(AF_INET, &addr, &pretty);
- log_link_debug(link, "Starting IPv4ACD client. Probing DHCPv4 address %s", strna(pretty));
- }
+ log_link_debug(link, "Starting IPv4ACD client. Probing DHCPv4 address "IPV4_ADDRESS_FMT_STR,
+ IPV4_ADDRESS_FMT_VAL(addr));
- r = sd_ipv4acd_start(link->dhcp_acd, !in4_addr_equal(&addr.in, &old));
- if (r < 0)
- return r;
-
- return 1;
+ return sd_ipv4acd_start(link->dhcp_acd, !in4_addr_equal(&addr, &old));
}
static int dhcp4_address_ready_callback(Address *address) {
diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c
index b13a635a78..7cc912890a 100644
--- a/src/network/networkd-dhcp6.c
+++ b/src/network/networkd-dhcp6.c
@@ -43,7 +43,7 @@ bool link_dhcp6_pd_is_enabled(Link *link) {
static bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease) {
uint32_t lifetime_preferred, lifetime_valid;
- union in_addr_union pd_prefix;
+ struct in6_addr pd_prefix;
uint8_t pd_prefix_len;
if (!lease)
@@ -51,7 +51,7 @@ static bool dhcp6_lease_has_pd_prefix(sd_dhcp6_lease *lease) {
sd_dhcp6_lease_reset_pd_prefix_iter(lease);
- return sd_dhcp6_lease_get_pd(lease, &pd_prefix.in6, &pd_prefix_len, &lifetime_preferred, &lifetime_valid) >= 0;
+ return sd_dhcp6_lease_get_pd(lease, &pd_prefix, &pd_prefix_len, &lifetime_preferred, &lifetime_valid) >= 0;
}
DHCP6DelegatedPrefix *dhcp6_pd_free(DHCP6DelegatedPrefix *p) {
@@ -86,21 +86,21 @@ static int dhcp6_pd_compare_func(const DHCP6DelegatedPrefix *a, const DHCP6Deleg
DEFINE_HASH_OPS(dhcp6_pd_hash_ops, DHCP6DelegatedPrefix, dhcp6_pd_hash_func, dhcp6_pd_compare_func);
-static Link *dhcp6_pd_get_link_by_prefix(Link *link, const union in_addr_union *prefix) {
+static Link *dhcp6_pd_get_link_by_prefix(Link *link, const struct in6_addr *prefix) {
DHCP6DelegatedPrefix *pd;
assert(link);
assert(link->manager);
assert(prefix);
- pd = hashmap_get(link->manager->dhcp6_prefixes, &prefix->in6);
+ pd = hashmap_get(link->manager->dhcp6_prefixes, prefix);
if (!pd)
return NULL;
return pd->link;
}
-static int dhcp6_pd_get_assigned_prefix(Link *link, const union in_addr_union *pd_prefix, union in_addr_union *ret_prefix) {
+static int dhcp6_pd_get_assigned_prefix(Link *link, const struct in6_addr *pd_prefix, struct in6_addr *ret_prefix) {
DHCP6DelegatedPrefix *pd, in;
assert(link);
@@ -109,7 +109,7 @@ static int dhcp6_pd_get_assigned_prefix(Link *link, const union in_addr_union *p
assert(ret_prefix);
in = (DHCP6DelegatedPrefix) {
- .pd_prefix = pd_prefix->in6,
+ .pd_prefix = *pd_prefix,
.link = link,
};
@@ -117,7 +117,7 @@ static int dhcp6_pd_get_assigned_prefix(Link *link, const union in_addr_union *p
if (!pd)
return -ENOENT;
- ret_prefix->in6 = pd->prefix;
+ *ret_prefix = pd->prefix;
return 0;
}
@@ -264,7 +264,7 @@ static int dhcp6_pd_route_handler(sd_netlink *nl, sd_netlink_message *m, Link *l
return 1;
}
-static int dhcp6_set_pd_route(Link *link, const union in_addr_union *prefix, const union in_addr_union *pd_prefix) {
+static int dhcp6_set_pd_route(Link *link, const struct in6_addr *prefix, const struct in6_addr *pd_prefix) {
_cleanup_(dhcp6_pd_freep) DHCP6DelegatedPrefix *pd = NULL;
_cleanup_(route_freep) Route *route = NULL;
Link *assigned_link;
@@ -281,7 +281,7 @@ static int dhcp6_set_pd_route(Link *link, const union in_addr_union *prefix, con
return r;
route->family = AF_INET6;
- route->dst = *prefix;
+ route->dst.in6 = *prefix;
route->dst_prefixlen = 64;
route->protocol = RTPROT_DHCP;
route->priority = link->network->dhcp6_pd_route_metric;
@@ -311,8 +311,8 @@ static int dhcp6_set_pd_route(Link *link, const union in_addr_union *prefix, con
return log_oom();
*pd = (DHCP6DelegatedPrefix) {
- .prefix = prefix->in6,
- .pd_prefix = pd_prefix->in6,
+ .prefix = *prefix,
+ .pd_prefix = *pd_prefix,
.link = link_ref(link),
};
@@ -370,12 +370,15 @@ static void log_dhcp6_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;
if (log_level < log_get_max_level())
return;
- (void) in_addr_prefix_to_string(address->family, &address->in_addr, address->prefixlen, &buffer);
+ (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,
@@ -393,7 +396,7 @@ static void log_dhcp6_pd_address(Link *link, const Address *address) {
static int dhcp6_set_pd_address(
Link *link,
- const union in_addr_union *prefix,
+ const struct in6_addr *prefix,
uint32_t lifetime_preferred,
uint32_t lifetime_valid) {
@@ -412,10 +415,10 @@ static int dhcp6_set_pd_address(
if (r < 0)
return log_link_error_errno(link, r, "Failed to allocate address for DHCPv6 delegated prefix: %m");
- address->in_addr = *prefix;
+ address->in_addr.in6 = *prefix;
- if (in_addr_is_set(AF_INET6, &link->network->dhcp6_pd_token))
- memcpy(address->in_addr.in6.s6_addr + 8, link->network->dhcp6_pd_token.in6.s6_addr + 8, 8);
+ if (in6_addr_is_set(&link->network->dhcp6_pd_token))
+ memcpy(address->in_addr.in6.s6_addr + 8, link->network->dhcp6_pd_token.s6_addr + 8, 8);
else {
r = generate_ipv6_eui_64_address(link, &address->in_addr.in6);
if (r < 0)
@@ -449,8 +452,8 @@ static int dhcp6_set_pd_address(
static int dhcp6_pd_assign_prefix(
Link *link,
- const union in_addr_union *prefix,
- const union in_addr_union *pd_prefix,
+ const struct in6_addr *prefix,
+ const struct in6_addr *pd_prefix,
uint32_t lifetime_preferred,
uint32_t lifetime_valid) {
@@ -461,7 +464,7 @@ static int dhcp6_pd_assign_prefix(
assert(prefix);
if (link->network->dhcp6_pd_announce) {
- r = radv_add_prefix(link, &prefix->in6, 64, lifetime_preferred, lifetime_valid);
+ r = radv_add_prefix(link, prefix, 64, lifetime_preferred, lifetime_valid);
if (r < 0)
return r;
}
@@ -486,9 +489,9 @@ static bool link_has_preferred_subnet_id(Link *link) {
static int dhcp6_get_preferred_delegated_prefix(
Link *link,
- const union in_addr_union *masked_pd_prefix,
+ const struct in6_addr *masked_pd_prefix,
uint8_t pd_prefix_len,
- union in_addr_union *ret) {
+ struct in6_addr *ret) {
/* We start off with the original PD prefix we have been assigned and iterate from there */
union in_addr_union prefix;
@@ -502,7 +505,7 @@ static int dhcp6_get_preferred_delegated_prefix(
assert(pd_prefix_len <= 64);
n_prefixes = UINT64_C(1) << (64 - pd_prefix_len);
- prefix = *masked_pd_prefix;
+ prefix.in6 = *masked_pd_prefix;
if (link_has_preferred_subnet_id(link)) {
uint64_t subnet_id = link->network->dhcp6_pd_subnet_id;
@@ -521,28 +524,28 @@ static int dhcp6_get_preferred_delegated_prefix(
/* Verify that the prefix we did calculate fits in the pd prefix.
* This should not fail as we checked the prefix size beforehand */
- assert_se(in_addr_prefix_covers(AF_INET6, masked_pd_prefix, pd_prefix_len, &prefix) > 0);
+ assert_se(in_addr_prefix_covers(AF_INET6, (const union in_addr_union*) masked_pd_prefix, pd_prefix_len, &prefix) > 0);
- assigned_link = dhcp6_pd_get_link_by_prefix(link, &prefix);
+ assigned_link = dhcp6_pd_get_link_by_prefix(link, &prefix.in6);
if (assigned_link && assigned_link != link) {
_cleanup_free_ char *assigned_buf = NULL;
- (void) in_addr_to_string(AF_INET6, &prefix, &assigned_buf);
+ (void) in6_addr_to_string(&prefix.in6, &assigned_buf);
return log_link_warning_errno(link, SYNTHETIC_ERRNO(EAGAIN),
"The requested prefix %s is already assigned to another link.",
strna(assigned_buf));
}
- *ret = prefix;
+ *ret = prefix.in6;
return 0;
}
for (uint64_t n = 0; n < n_prefixes; n++) {
/* If we do not have an allocation preference just iterate
* through the address space and return the first free prefix. */
- assigned_link = dhcp6_pd_get_link_by_prefix(link, &prefix);
+ assigned_link = dhcp6_pd_get_link_by_prefix(link, &prefix.in6);
if (!assigned_link || assigned_link == link) {
- *ret = prefix;
+ *ret = prefix.in6;
return 0;
}
@@ -555,7 +558,7 @@ static int dhcp6_get_preferred_delegated_prefix(
}
static void dhcp6_pd_prefix_distribute(Link *dhcp6_link,
- const union in_addr_union *masked_pd_prefix,
+ const struct in6_addr *masked_pd_prefix,
uint8_t pd_prefix_len,
uint32_t lifetime_preferred,
uint32_t lifetime_valid,
@@ -571,7 +574,7 @@ static void dhcp6_pd_prefix_distribute(Link *dhcp6_link,
HASHMAP_FOREACH(link, dhcp6_link->manager->links) {
_cleanup_free_ char *assigned_buf = NULL;
- union in_addr_union assigned_prefix;
+ struct in6_addr assigned_prefix;
if (link == dhcp6_link)
continue;
@@ -594,7 +597,7 @@ static void dhcp6_pd_prefix_distribute(Link *dhcp6_link,
}
}
- (void) in_addr_to_string(AF_INET6, &assigned_prefix, &assigned_buf);
+ (void) in6_addr_to_string(&assigned_prefix, &assigned_buf);
r = dhcp6_pd_assign_prefix(link, &assigned_prefix, masked_pd_prefix,
lifetime_preferred, lifetime_valid);
if (r < 0) {
@@ -815,7 +818,7 @@ static int dhcp6_route_handler(sd_netlink *nl, sd_netlink_message *m, Link *link
return 1;
}
-static int dhcp6_set_unreachable_route(Link *link, const union in_addr_union *addr, uint8_t prefixlen) {
+static int dhcp6_set_unreachable_route(Link *link, const struct in6_addr *addr, uint8_t prefixlen) {
_cleanup_(route_freep) Route *route = NULL;
_cleanup_free_ char *buf = NULL;
Route *ret;
@@ -824,7 +827,7 @@ static int dhcp6_set_unreachable_route(Link *link, const union in_addr_union *ad
assert(link);
assert(addr);
- (void) in_addr_prefix_to_string(AF_INET6, addr, prefixlen, &buf);
+ (void) in6_addr_prefix_to_string(addr, prefixlen, &buf);
if (prefixlen == 64) {
log_link_debug(link, "Not adding a blocking route for DHCPv6 delegated subnet %s since distributed prefix is 64",
@@ -837,7 +840,7 @@ static int dhcp6_set_unreachable_route(Link *link, const union in_addr_union *ad
return log_oom();
route->family = AF_INET6;
- route->dst = *addr;
+ route->dst.in6 = *addr;
route->dst_prefixlen = prefixlen;
route->table = link_get_dhcp_route_table(link);
route->type = RTN_UNREACHABLE;
@@ -862,7 +865,7 @@ static int dhcp6_set_unreachable_route(Link *link, const union in_addr_union *ad
return 0;
}
-static int dhcp6_pd_prefix_add(Link *link, const union in_addr_union *prefix, uint8_t prefixlen) {
+static int dhcp6_pd_prefix_add(Link *link, const struct in6_addr *prefix, uint8_t prefixlen) {
_cleanup_free_ struct in_addr_prefix *p = NULL;
_cleanup_free_ char *buf = NULL;
int r;
@@ -877,10 +880,10 @@ static int dhcp6_pd_prefix_add(Link *link, const union in_addr_union *prefix, ui
*p = (struct in_addr_prefix) {
.family = AF_INET6,
.prefixlen = prefixlen,
- .address = *prefix,
+ .address.in6 = *prefix,
};
- (void) in_addr_prefix_to_string(p->family, &p->address, p->prefixlen, &buf);
+ (void) in6_addr_prefix_to_string(prefix, prefixlen, &buf);
log_link_full(link,
set_contains(link->dhcp6_pd_prefixes, p) ? LOG_DEBUG :
@@ -918,10 +921,11 @@ static int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
for (sd_dhcp6_lease_reset_pd_prefix_iter(dhcp6_link->dhcp6_lease);;) {
uint32_t lifetime_preferred, lifetime_valid;
- union in_addr_union pd_prefix, prefix;
+ struct in6_addr pd_prefix;
+ union in_addr_union prefix;
uint8_t pd_prefix_len;
- r = sd_dhcp6_lease_get_pd(dhcp6_link->dhcp6_lease, &pd_prefix.in6, &pd_prefix_len,
+ r = sd_dhcp6_lease_get_pd(dhcp6_link->dhcp6_lease, &pd_prefix, &pd_prefix_len,
&lifetime_preferred, &lifetime_valid);
if (r < 0)
break;
@@ -947,7 +951,7 @@ static int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
assert(pd_prefix_len <= 64);
- prefix = pd_prefix;
+ prefix.in6 = pd_prefix;
r = in_addr_mask(AF_INET6, &prefix, pd_prefix_len);
if (r < 0)
return log_link_error_errno(dhcp6_link, r, "Failed to mask DHCPv6 PD prefix: %m");
@@ -956,20 +960,20 @@ static int dhcp6_pd_prefix_acquired(Link *dhcp6_link) {
uint64_t n_prefixes = UINT64_C(1) << (64 - pd_prefix_len);
_cleanup_free_ char *buf = NULL;
- (void) in_addr_prefix_to_string(AF_INET6, &prefix, pd_prefix_len, &buf);
+ (void) in6_addr_prefix_to_string(&prefix.in6, pd_prefix_len, &buf);
log_link_debug(dhcp6_link, "Assigning up to %" PRIu64 " prefixes from %s",
n_prefixes, strna(buf));
}
dhcp6_pd_prefix_distribute(dhcp6_link,
- &prefix,
+ &prefix.in6,
pd_prefix_len,
lifetime_preferred,
lifetime_valid,
true);
dhcp6_pd_prefix_distribute(dhcp6_link,
- &prefix,
+ &prefix.in6,
pd_prefix_len,
lifetime_preferred,
lifetime_valid,
@@ -1032,8 +1036,9 @@ static void log_dhcp6_address(Link *link, const Address *address, char **ret) {
assert(link);
assert(address);
+ assert(address->family == AF_INET6);
- (void) in_addr_prefix_to_string(address->family, &address->in_addr, address->prefixlen, &buffer);
+ (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,
@@ -1849,7 +1854,8 @@ int config_parse_dhcp6_pd_token(
void *data,
void *userdata) {
- union in_addr_union *addr = data, tmp;
+ struct in6_addr *addr = data;
+ union in_addr_union tmp;
int r;
assert(filename);
@@ -1858,7 +1864,7 @@ int config_parse_dhcp6_pd_token(
assert(data);
if (isempty(rvalue)) {
- *addr = IN_ADDR_NULL;
+ *addr = (struct in6_addr) {};
return 0;
}
@@ -1875,7 +1881,7 @@ int config_parse_dhcp6_pd_token(
return 0;
}
- *addr = tmp;
+ *addr = tmp.in6;
return 0;
}
diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c
index 988c673255..87f55f557c 100644
--- a/src/network/networkd-ndisc.c
+++ b/src/network/networkd-ndisc.c
@@ -89,6 +89,7 @@ static int ndisc_address_callback(Address *address) {
assert(address);
assert(address->link);
+ assert(address->family == AF_INET6);
SET_FOREACH(n, address->link->ndisc_addresses)
if (n->address == address) {
@@ -99,7 +100,7 @@ static int ndisc_address_callback(Address *address) {
if (in6_addr_is_null(&router)) {
_cleanup_free_ char *buf = NULL;
- (void) in_addr_prefix_to_string(address->family, &address->in_addr, address->prefixlen, &buf);
+ (void) in6_addr_prefix_to_string(&address->in_addr.in6, address->prefixlen, &buf);
log_link_debug(address->link, "%s is called for %s, but it is already removed, ignoring.",
__func__, strna(buf));
return 0;
@@ -107,7 +108,7 @@ static int ndisc_address_callback(Address *address) {
/* Make this called only once */
SET_FOREACH(n, address->link->ndisc_addresses)
- if (IN6_ARE_ADDR_EQUAL(&n->router, &router))
+ if (in6_addr_equal(&n->router, &router))
n->address->callback = NULL;
return ndisc_remove_old_one(address->link, &router, true);
@@ -131,7 +132,7 @@ static int ndisc_remove_old_one(Link *link, const struct in6_addr *router, bool
return 0;
SET_FOREACH(na, link->ndisc_addresses)
- if (!na->marked && IN6_ARE_ADDR_EQUAL(&na->router, router)) {
+ if (!na->marked && in6_addr_equal(&na->router, router)) {
set_callback = true;
break;
}
@@ -145,13 +146,13 @@ static int ndisc_remove_old_one(Link *link, const struct in6_addr *router, bool
if (set_callback) {
SET_FOREACH(na, link->ndisc_addresses)
- if (!na->marked && IN6_ARE_ADDR_EQUAL(&na->router, router))
+ if (!na->marked && in6_addr_equal(&na->router, router))
na->address->callback = ndisc_address_callback;
if (DEBUG_LOGGING) {
_cleanup_free_ char *buf = NULL;
- (void) in_addr_to_string(AF_INET6, (const union in_addr_union*) router, &buf);
+ (void) in6_addr_to_string(router, &buf);
log_link_debug(link, "No SLAAC address obtained from %s is ready. "
"The old NDisc information will be removed later.",
strna(buf));
@@ -163,32 +164,32 @@ static int ndisc_remove_old_one(Link *link, const struct in6_addr *router, bool
if (DEBUG_LOGGING) {
_cleanup_free_ char *buf = NULL;
- (void) in_addr_to_string(AF_INET6, (const union in_addr_union*) router, &buf);
+ (void) in6_addr_to_string(router, &buf);
log_link_debug(link, "Removing old NDisc information obtained from %s.", strna(buf));
}
SET_FOREACH(na, link->ndisc_addresses)
- if (na->marked && IN6_ARE_ADDR_EQUAL(&na->router, router)) {
+ if (na->marked && in6_addr_equal(&na->router, router)) {
k = address_remove(na->address, link, NULL);
if (k < 0)
r = k;
}
SET_FOREACH(nr, link->ndisc_routes)
- if (nr->marked && IN6_ARE_ADDR_EQUAL(&nr->router, router)) {
+ if (nr->marked && in6_addr_equal(&nr->router, router)) {
k = route_remove(nr->route, NULL, link, NULL);
if (k < 0)
r = k;
}
SET_FOREACH(rdnss, link->ndisc_rdnss)
- if (rdnss->marked && IN6_ARE_ADDR_EQUAL(&rdnss->router, router)) {
+ if (rdnss->marked && in6_addr_equal(&rdnss->router, router)) {
free(set_remove(link->ndisc_rdnss, rdnss));
updated = true;
}
SET_FOREACH(dnssl, link->ndisc_dnssl)
- if (dnssl->marked && IN6_ARE_ADDR_EQUAL(&dnssl->router, router)) {
+ if (dnssl->marked && in6_addr_equal(&dnssl->router, router)) {
free(set_remove(link->ndisc_dnssl, dnssl));
updated = true;
}
@@ -476,7 +477,7 @@ static int ndisc_address_configure(Address *address, Link *link, sd_ndisc_router
static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
_cleanup_(route_freep) Route *route = NULL;
- union in_addr_union gateway;
+ struct in6_addr gateway;
uint16_t lifetime;
unsigned preference;
uint32_t table, mtu;
@@ -493,17 +494,17 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
if (lifetime == 0) /* not a default router */
return 0;
- r = sd_ndisc_router_get_address(rt, &gateway.in6);
+ r = sd_ndisc_router_get_address(rt, &gateway);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m");
- if (link_has_ipv6_address(link, &gateway.in6) > 0) {
+ if (link_has_ipv6_address(link, &gateway) > 0) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *buffer = NULL;
- (void) in_addr_to_string(AF_INET6, &gateway, &buffer);
+ (void) in6_addr_to_string(&gateway, &buffer);
log_link_debug(link, "No NDisc route added, gateway %s matches local address",
- strnull(buffer));
+ strna(buffer));
}
return 0;
}
@@ -534,7 +535,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
route->protocol = RTPROT_RA;
route->pref = preference;
route->gw_family = AF_INET6;
- route->gw = gateway;
+ route->gw.in6 = gateway;
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
route->mtu = mtu;
@@ -550,7 +551,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
if (route_gw->gw_family != AF_INET6)
continue;
- route_gw->gw = gateway;
+ route_gw->gw.in6 = gateway;
if (!route_gw->table_set)
route_gw->table = table;
if (!route_gw->priority_set)
@@ -650,7 +651,7 @@ static int ndisc_router_generate_addresses(Link *link, struct in6_addr *address,
_cleanup_free_ struct in6_addr *new_address = NULL;
if (j->address_generation_type == IPV6_TOKEN_ADDRESS_GENERATION_PREFIXSTABLE
- && (in6_addr_is_null(&j->prefix) || IN6_ARE_ADDR_EQUAL(&j->prefix, address))) {
+ && (in6_addr_is_null(&j->prefix) || in6_addr_equal(&j->prefix, address))) {
/* While this loop uses dad_counter and a retry limit as specified in RFC 7217, the loop
* does not actually attempt Duplicate Address Detection; the counter will be incremented
* only when the address generation algorithm produces an invalid address, and the loop
@@ -833,7 +834,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
_cleanup_(route_freep) Route *route = NULL;
- union in_addr_union gateway, dst;
+ struct in6_addr gateway, dst;
uint32_t lifetime;
unsigned preference, prefixlen;
usec_t time_now;
@@ -848,35 +849,35 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
if (lifetime == 0)
return 0;
- r = sd_ndisc_router_route_get_address(rt, &dst.in6);
+ r = sd_ndisc_router_route_get_address(rt, &dst);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get route address: %m");
if ((!set_isempty(link->network->ndisc_allow_listed_route_prefix) &&
- !set_contains(link->network->ndisc_allow_listed_route_prefix, &dst.in6)) ||
- set_contains(link->network->ndisc_deny_listed_route_prefix, &dst.in6)) {
+ !set_contains(link->network->ndisc_allow_listed_route_prefix, &dst)) ||
+ set_contains(link->network->ndisc_deny_listed_route_prefix, &dst)) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *buf = NULL;
- (void) in_addr_to_string(AF_INET6, &dst, &buf);
+ (void) in6_addr_to_string(&dst, &buf);
if (!set_isempty(link->network->ndisc_allow_listed_route_prefix))
- log_link_debug(link, "Route prefix '%s' is not in allow list, ignoring", strnull(buf));
+ 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", strnull(buf));
+ log_link_debug(link, "Route prefix '%s' is in deny list, ignoring", strna(buf));
}
return 0;
}
- r = sd_ndisc_router_get_address(rt, &gateway.in6);
+ r = sd_ndisc_router_get_address(rt, &gateway);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m");
- if (link_has_ipv6_address(link, &gateway.in6) > 0) {
+ if (link_has_ipv6_address(link, &gateway) > 0) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *buf = NULL;
- (void) in_addr_to_string(AF_INET6, &gateway, &buf);
- log_link_debug(link, "Advertised route gateway, %s, is local to the link, ignoring route", strnull(buf));
+ (void) in6_addr_to_string(&gateway, &buf);
+ log_link_debug(link, "Advertised route gateway %s is local to the link, ignoring route", strna(buf));
}
return 0;
}
@@ -902,9 +903,9 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
route->priority = link->network->ipv6_accept_ra_route_metric;
route->protocol = RTPROT_RA;
route->pref = preference;
- route->gw = gateway;
+ route->gw.in6 = gateway;
route->gw_family = AF_INET6;
- route->dst = dst;
+ route->dst.in6 = dst;
route->dst_prefixlen = prefixlen;
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
@@ -959,7 +960,7 @@ static int ndisc_router_process_rdnss(Link *link, sd_ndisc_router *rt) {
return log_link_error_errno(link, n, "Failed to get RDNSS addresses: %m");
SET_FOREACH(rdnss, link->ndisc_rdnss)
- if (IN6_ARE_ADDR_EQUAL(&rdnss->router, &router))
+ if (in6_addr_equal(&rdnss->router, &router))
rdnss->marked = true;
if (lifetime == 0)
@@ -1053,7 +1054,7 @@ static int ndisc_router_process_dnssl(Link *link, sd_ndisc_router *rt) {
return log_link_error_errno(link, r, "Failed to get DNSSL addresses: %m");
SET_FOREACH(dnssl, link->ndisc_dnssl)
- if (IN6_ARE_ADDR_EQUAL(&dnssl->router, &router))
+ if (in6_addr_equal(&dnssl->router, &router))
dnssl->marked = true;
if (lifetime == 0)
@@ -1119,20 +1120,20 @@ static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) {
switch (type) {
case SD_NDISC_OPTION_PREFIX_INFORMATION: {
- union in_addr_union a;
+ struct in6_addr a;
uint8_t flags;
- r = sd_ndisc_router_prefix_get_address(rt, &a.in6);
+ r = sd_ndisc_router_prefix_get_address(rt, &a);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix address: %m");
if ((!set_isempty(link->network->ndisc_allow_listed_prefix) &&
- !set_contains(link->network->ndisc_allow_listed_prefix, &a.in6)) ||
- set_contains(link->network->ndisc_deny_listed_prefix, &a.in6)) {
+ !set_contains(link->network->ndisc_allow_listed_prefix, &a)) ||
+ set_contains(link->network->ndisc_deny_listed_prefix, &a)) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *b = NULL;
- (void) in_addr_to_string(AF_INET6, &a, &b);
+ (void) in6_addr_to_string(&a, &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
@@ -1187,7 +1188,7 @@ static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) {
}
static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) {
- union in_addr_union router;
+ struct in6_addr router;
uint64_t flags;
NDiscAddress *na;
NDiscRoute *nr;
@@ -1198,17 +1199,17 @@ static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) {
assert(link->manager);
assert(rt);
- r = sd_ndisc_router_get_address(rt, &router.in6);
+ r = sd_ndisc_router_get_address(rt, &router);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get router address from RA: %m");
if ((!set_isempty(link->network->ndisc_allow_listed_router) &&
- !set_contains(link->network->ndisc_allow_listed_router, &router.in6)) ||
- set_contains(link->network->ndisc_deny_listed_router, &router.in6)) {
+ !set_contains(link->network->ndisc_allow_listed_router, &router)) ||
+ set_contains(link->network->ndisc_deny_listed_router, &router)) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *buf = NULL;
- (void) in_addr_to_string(AF_INET6, &router, &buf);
+ (void) in6_addr_to_string(&router, &buf);
if (!set_isempty(link->network->ndisc_allow_listed_router))
log_link_debug(link, "Router '%s' is not in allow list, ignoring", strna(buf));
else
@@ -1218,11 +1219,11 @@ static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) {
}
SET_FOREACH(na, link->ndisc_addresses)
- if (IN6_ARE_ADDR_EQUAL(&na->router, &router.in6))
+ if (in6_addr_equal(&na->router, &router))
na->marked = true;
SET_FOREACH(nr, link->ndisc_routes)
- if (IN6_ARE_ADDR_EQUAL(&nr->router, &router.in6))
+ if (in6_addr_equal(&nr->router, &router))
nr->marked = true;
r = sd_ndisc_router_get_flags(rt, &flags);
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index d7c216af6e..c094065a83 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -228,7 +228,7 @@ struct Network {
bool dhcp6_pd_manage_temporary_address;
int64_t dhcp6_pd_subnet_id;
uint32_t dhcp6_pd_route_metric;
- union in_addr_union dhcp6_pd_token;
+ struct in6_addr dhcp6_pd_token;
/* Bridge Support */
int use_bpdu;