summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-10-01 14:03:05 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-10-06 18:14:51 +0200
commitac77e0b3158795289fb6508d4331248c35f0f085 (patch)
tree94341bbe5fdd94209f1c7e79e537c63399f46160
parentnetwork: ndisc: ignore autonomous prefix with prefix length larger than 64 (diff)
downloadsystemd-ac77e0b3158795289fb6508d4331248c35f0f085.tar.xz
systemd-ac77e0b3158795289fb6508d4331248c35f0f085.zip
network: address-generation: always use the first 64 bits of the prefix
Hopefully, the prefix length is usually 64. Previously, if the prefix length is smaller than 64, the result address was undefined.
-rw-r--r--src/network/networkd-address-generation.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/network/networkd-address-generation.c b/src/network/networkd-address-generation.c
index 191a89dfd9..a4f53436e3 100644
--- a/src/network/networkd-address-generation.c
+++ b/src/network/networkd-address-generation.c
@@ -79,12 +79,11 @@ static bool stable_private_address_is_valid(const struct in6_addr *addr) {
return true;
}
-static int make_stable_private_address(Link *link, const struct in6_addr *prefix, uint8_t prefix_len, uint8_t dad_counter, struct in6_addr **ret) {
+static int make_stable_private_address(Link *link, const struct in6_addr *prefix, uint8_t dad_counter, struct in6_addr **ret) {
_cleanup_free_ struct in6_addr *addr = NULL;
sd_id128_t secret_key;
struct siphash state;
uint64_t rid;
- size_t l;
int r;
/* According to rfc7217 section 5.1
@@ -96,8 +95,7 @@ static int make_stable_private_address(Link *link, const struct in6_addr *prefix
siphash24_init(&state, secret_key.bytes);
- l = MAX(DIV_ROUND_UP(prefix_len, 8), 8);
- siphash24_compress(prefix, l, &state);
+ siphash24_compress(prefix, 8, &state);
siphash24_compress_string(link->ifname, &state);
/* Only last 8 bytes of IB MAC are stable */
if (link->iftype == ARPHRD_INFINIBAND)
@@ -112,8 +110,8 @@ static int make_stable_private_address(Link *link, const struct in6_addr *prefix
if (!addr)
return log_oom();
- memcpy(addr->s6_addr, prefix->s6_addr, l);
- memcpy(addr->s6_addr + l, &rid, 16 - l);
+ memcpy(addr->s6_addr, prefix->s6_addr, 8);
+ memcpy(addr->s6_addr + 8, &rid, 8);
if (!stable_private_address_is_valid(addr)) {
*ret = NULL;
@@ -147,7 +145,7 @@ int ndisc_router_generate_addresses(Link *link, struct in6_addr *address, uint8_
* only when the address generation algorithm produces an invalid address, and the loop
* may exit with an address which ends up being unusable due to duplication on the link. */
for (; j->dad_counter < DAD_CONFLICTS_IDGEN_RETRIES_RFC7217; j->dad_counter++) {
- r = make_stable_private_address(link, address, prefixlen, j->dad_counter, &new_address);
+ r = make_stable_private_address(link, address, j->dad_counter, &new_address);
if (r < 0)
return r;
if (r > 0)