| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <net/if_arp.h> |
| 4 |
|
| 5 |
#include "sd-id128.h" |
| 6 |
|
| 7 |
#include "alloc-util.h" |
| 8 |
#include "arphrd-util.h" |
| 9 |
#include "hash-funcs.h" |
| 10 |
#include "id128-util.h" |
| 11 |
#include "networkd-address-generation.h" |
| 12 |
#include "networkd-address.h" |
| 13 |
#include "networkd-link.h" |
| 14 |
#include "networkd-network.h" |
| 15 |
#include "set.h" |
| 16 |
#include "siphash24.h" |
| 17 |
#include "string-util.h" |
| 18 |
|
| 19 |
#define DAD_CONFLICTS_IDGEN_RETRIES_RFC7217 3 |
| 20 |
|
| 21 |
/* https://www.iana.org/assignments/ipv6-interface-ids/ipv6-interface-ids.xml */ |
| 22 |
#define SUBNET_ROUTER_ANYCAST_ADDRESS ((const struct in6_addr) { .s6_addr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }) |
| 23 |
#define SUBNET_ROUTER_ANYCAST_PREFIXLEN 64 |
| 24 |
#define RESERVED_INTERFACE_IDENTIFIERS_ADDRESS ((const struct in6_addr) { .s6_addr = { 0x02, 0x00, 0x5E, 0xFF, 0xFE } }) |
| 25 |
#define RESERVED_INTERFACE_IDENTIFIERS_PREFIXLEN 40 |
| 26 |
#define RESERVED_SUBNET_ANYCAST_ADDRESSES ((const struct in6_addr) { .s6_addr = { 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80 } }) |
| 27 |
#define RESERVED_SUBNET_ANYCAST_PREFIXLEN 57 |
| 28 |
|
| 29 |
#define DHCP_PD_APP_ID SD_ID128_MAKE(fb,b9,37,ca,4a,ed,4a,4d,b0,70,7f,aa,71,c0,c9,85) |
| 30 |
#define NDISC_APP_ID SD_ID128_MAKE(13,ac,81,a7,d5,3f,49,78,92,79,5d,0c,29,3a,bc,7e) |
| 31 |
#define RADV_APP_ID SD_ID128_MAKE(1f,1e,90,c8,5c,78,4f,dc,8e,61,2d,59,0d,53,c1,25) |
| 32 |
|
| 33 |
typedef enum AddressGenerationType { |
| 34 |
ADDRESS_GENERATION_EUI64, |
| 35 |
ADDRESS_GENERATION_STATIC, |
| 36 |
ADDRESS_GENERATION_PREFIXSTABLE, |
| 37 |
_ADDRESS_GENERATION_TYPE_MAX, |
| 38 |
_ADDRESS_GENERATION_TYPE_INVALID = -EINVAL, |
| 39 |
} AddressGenerationType; |
| 40 |
|
| 41 |
struct IPv6Token { |
| 42 |
unsigned n_ref; |
| 43 |
AddressGenerationType type; |
| 44 |
struct in6_addr address; |
| 45 |
sd_id128_t secret_key; |
| 46 |
}; |
| 47 |
|
| 48 |
DEFINE_TRIVIAL_REF_UNREF_FUNC(IPv6Token, ipv6_token, mfree); |
| 49 |
DEFINE_TRIVIAL_CLEANUP_FUNC(IPv6Token*, ipv6_token_unref); |
| 50 |
|
| 51 |
static void ipv6_token_hash_func(const IPv6Token *p, struct siphash *state) { |
| 52 |
siphash24_compress_typesafe(p->type, state); |
| 53 |
siphash24_compress_typesafe(p->address, state); |
| 54 |
id128_hash_func(&p->secret_key, state); |
| 55 |
} |
| 56 |
|
| 57 |
static int ipv6_token_compare_func(const IPv6Token *a, const IPv6Token *b) { |
| 58 |
int r; |
| 59 |
|
| 60 |
r = CMP(a->type, b->type); |
| 61 |
if (r != 0) |
| 62 |
return r; |
| 63 |
|
| 64 |
r = memcmp(&a->address, &b->address, sizeof(struct in6_addr)); |
| 65 |
if (r != 0) |
| 66 |
return r; |
| 67 |
|
| 68 |
return id128_compare_func(&a->secret_key, &b->secret_key); |
| 69 |
} |
| 70 |
|
| 71 |
DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR( |
| 72 |
ipv6_token_hash_ops, |
| 73 |
IPv6Token, |
| 74 |
ipv6_token_hash_func, |
| 75 |
ipv6_token_compare_func, |
| 76 |
ipv6_token_unref); |
| 77 |
|
| 78 |
DEFINE_PRIVATE_HASH_OPS_FULL( |
| 79 |
ipv6_token_by_addr_hash_ops, |
| 80 |
struct in6_addr, |
| 81 |
in6_addr_hash_func, |
| 82 |
in6_addr_compare_func, |
| 83 |
free, |
| 84 |
IPv6Token, |
| 85 |
ipv6_token_unref); |
| 86 |
|
| 87 |
static int ipv6_token_new(AddressGenerationType type, const struct in6_addr *addr, const sd_id128_t *secret_key, IPv6Token **ret) { |
| 88 |
IPv6Token *p; |
| 89 |
|
| 90 |
assert(type >= 0 && type < _ADDRESS_GENERATION_TYPE_MAX); |
| 91 |
assert(addr); |
| 92 |
assert(secret_key); |
| 93 |
assert(ret); |
| 94 |
|
| 95 |
p = new(IPv6Token, 1); |
| 96 |
if (!p) |
| 97 |
return -ENOMEM; |
| 98 |
|
| 99 |
*p = (IPv6Token) { |
| 100 |
.n_ref = 1, |
| 101 |
.type = type, |
| 102 |
.address = *addr, |
| 103 |
.secret_key = *secret_key, |
| 104 |
}; |
| 105 |
|
| 106 |
*ret = p; |
| 107 |
return 0; |
| 108 |
} |
| 109 |
|
| 110 |
static int ipv6_token_add(Set **tokens, AddressGenerationType type, const struct in6_addr *addr, const sd_id128_t *secret_key) { |
| 111 |
IPv6Token *p; |
| 112 |
int r; |
| 113 |
|
| 114 |
assert(tokens); |
| 115 |
|
| 116 |
r = ipv6_token_new(type, addr, secret_key, &p); |
| 117 |
if (r < 0) |
| 118 |
return r; |
| 119 |
|
| 120 |
return set_ensure_consume(tokens, &ipv6_token_hash_ops, p); |
| 121 |
} |
| 122 |
|
| 123 |
static int ipv6_token_put_by_addr(Hashmap **tokens_by_address, const struct in6_addr *addr, IPv6Token *token) { |
| 124 |
_cleanup_free_ struct in6_addr *copy = NULL; |
| 125 |
int r; |
| 126 |
|
| 127 |
assert(tokens_by_address); |
| 128 |
assert(addr); |
| 129 |
assert(token); |
| 130 |
|
| 131 |
copy = newdup(struct in6_addr, addr, 1); |
| 132 |
if (!copy) |
| 133 |
return -ENOMEM; |
| 134 |
|
| 135 |
r = hashmap_ensure_put(tokens_by_address, &ipv6_token_by_addr_hash_ops, copy, token); |
| 136 |
if (r == -EEXIST) |
| 137 |
return 0; |
| 138 |
if (r < 0) |
| 139 |
return r; |
| 140 |
|
| 141 |
TAKE_PTR(copy); |
| 142 |
ipv6_token_ref(token); |
| 143 |
return 1; |
| 144 |
} |
| 145 |
|
| 146 |
static int ipv6_token_type_put_by_addr(Hashmap **tokens_by_addr, const struct in6_addr *addr, AddressGenerationType type) { |
| 147 |
_cleanup_(ipv6_token_unrefp) IPv6Token *token = NULL; |
| 148 |
int r; |
| 149 |
|
| 150 |
assert(tokens_by_addr); |
| 151 |
assert(addr); |
| 152 |
|
| 153 |
r = ipv6_token_new(type, &(struct in6_addr) {}, &SD_ID128_NULL, &token); |
| 154 |
if (r < 0) |
| 155 |
return r; |
| 156 |
|
| 157 |
return ipv6_token_put_by_addr(tokens_by_addr, addr, token); |
| 158 |
} |
| 159 |
|
| 160 |
static int generate_eui64_address(const Link *link, const struct in6_addr *prefix, struct in6_addr *ret) { |
| 161 |
assert(link); |
| 162 |
assert(prefix); |
| 163 |
assert(ret); |
| 164 |
|
| 165 |
memcpy(ret->s6_addr, prefix, 8); |
| 166 |
|
| 167 |
switch (link->iftype) { |
| 168 |
case ARPHRD_INFINIBAND: |
| 169 |
/* Use last 8 byte. See RFC4391 section 8 */ |
| 170 |
memcpy(&ret->s6_addr[8], &link->hw_addr.infiniband[INFINIBAND_ALEN - 8], 8); |
| 171 |
break; |
| 172 |
case ARPHRD_ETHER: |
| 173 |
/* see RFC4291 section 2.5.1 */ |
| 174 |
ret->s6_addr[8] = link->hw_addr.ether.ether_addr_octet[0]; |
| 175 |
ret->s6_addr[9] = link->hw_addr.ether.ether_addr_octet[1]; |
| 176 |
ret->s6_addr[10] = link->hw_addr.ether.ether_addr_octet[2]; |
| 177 |
ret->s6_addr[11] = 0xff; |
| 178 |
ret->s6_addr[12] = 0xfe; |
| 179 |
ret->s6_addr[13] = link->hw_addr.ether.ether_addr_octet[3]; |
| 180 |
ret->s6_addr[14] = link->hw_addr.ether.ether_addr_octet[4]; |
| 181 |
ret->s6_addr[15] = link->hw_addr.ether.ether_addr_octet[5]; |
| 182 |
break; |
| 183 |
default: |
| 184 |
return log_link_debug_errno(link, SYNTHETIC_ERRNO(EINVAL), |
| 185 |
"Token=eui64 is not supported for interface type %s, ignoring.", |
| 186 |
strna(arphrd_to_name(link->iftype))); |
| 187 |
} |
| 188 |
|
| 189 |
ret->s6_addr[8] ^= 1 << 1; |
| 190 |
return 0; |
| 191 |
} |
| 192 |
|
| 193 |
static bool stable_private_address_is_valid(const struct in6_addr *addr) { |
| 194 |
assert(addr); |
| 195 |
|
| 196 |
/* According to rfc4291, generated address should not be in the following ranges. */ |
| 197 |
|
| 198 |
if (in6_addr_prefix_covers(&SUBNET_ROUTER_ANYCAST_ADDRESS, SUBNET_ROUTER_ANYCAST_PREFIXLEN, addr)) |
| 199 |
return false; |
| 200 |
|
| 201 |
if (in6_addr_prefix_covers(&RESERVED_INTERFACE_IDENTIFIERS_ADDRESS, RESERVED_INTERFACE_IDENTIFIERS_PREFIXLEN, addr)) |
| 202 |
return false; |
| 203 |
|
| 204 |
if (in6_addr_prefix_covers(&RESERVED_SUBNET_ANYCAST_ADDRESSES, RESERVED_SUBNET_ANYCAST_PREFIXLEN, addr)) |
| 205 |
return false; |
| 206 |
|
| 207 |
return true; |
| 208 |
} |
| 209 |
|
| 210 |
static void generate_stable_private_address_one( |
| 211 |
Link *link, |
| 212 |
const sd_id128_t *secret_key, |
| 213 |
const struct in6_addr *prefix, |
| 214 |
uint8_t dad_counter, |
| 215 |
struct in6_addr *ret) { |
| 216 |
|
| 217 |
struct siphash state; |
| 218 |
uint64_t rid; |
| 219 |
|
| 220 |
assert(link); |
| 221 |
assert(secret_key); |
| 222 |
assert(prefix); |
| 223 |
assert(ret); |
| 224 |
|
| 225 |
/* According to RFC7217 section 5.1 |
| 226 |
* RID = F(Prefix, Net_Iface, Network_ID, DAD_Counter, secret_key) */ |
| 227 |
|
| 228 |
siphash24_init(&state, secret_key->bytes); |
| 229 |
|
| 230 |
siphash24_compress(prefix, 8, &state); |
| 231 |
siphash24_compress_string(link->ifname, &state); |
| 232 |
if (link->iftype == ARPHRD_INFINIBAND) |
| 233 |
/* Only last 8 bytes of IB MAC are stable */ |
| 234 |
siphash24_compress(&link->hw_addr.infiniband[INFINIBAND_ALEN - 8], 8, &state); |
| 235 |
else |
| 236 |
siphash24_compress(link->hw_addr.bytes, link->hw_addr.length, &state); |
| 237 |
|
| 238 |
if (link->ssid) |
| 239 |
siphash24_compress_string(link->ssid, &state); |
| 240 |
|
| 241 |
siphash24_compress_typesafe(dad_counter, &state); |
| 242 |
|
| 243 |
rid = htole64(siphash24_finalize(&state)); |
| 244 |
|
| 245 |
memcpy(ret->s6_addr, prefix->s6_addr, 8); |
| 246 |
memcpy(ret->s6_addr + 8, &rid, 8); |
| 247 |
} |
| 248 |
|
| 249 |
static int generate_stable_private_address( |
| 250 |
Link *link, |
| 251 |
const sd_id128_t *app_id, |
| 252 |
const sd_id128_t *secret_key, |
| 253 |
const struct in6_addr *prefix, |
| 254 |
const struct in6_addr *previous, |
| 255 |
struct in6_addr *ret) { |
| 256 |
|
| 257 |
sd_id128_t secret_machine_key; |
| 258 |
struct in6_addr addr; |
| 259 |
bool found = false; |
| 260 |
uint8_t i; |
| 261 |
int r; |
| 262 |
|
| 263 |
assert(link); |
| 264 |
assert(app_id); |
| 265 |
assert(secret_key); |
| 266 |
assert(prefix); |
| 267 |
assert(ret); |
| 268 |
|
| 269 |
if (sd_id128_is_null(*secret_key)) { |
| 270 |
r = sd_id128_get_machine_app_specific(*app_id, &secret_machine_key); |
| 271 |
if (r < 0) |
| 272 |
return log_link_debug_errno(link, r, "Failed to generate secret key for IPv6 stable private address: %m"); |
| 273 |
|
| 274 |
secret_key = &secret_machine_key; |
| 275 |
} |
| 276 |
|
| 277 |
/* While this loop uses dad_counter and a retry limit as specified in RFC 7217, the loop does |
| 278 |
* not actually attempt Duplicate Address Detection; the counter will be incremented only when |
| 279 |
* the address generation algorithm produces an invalid address, and the loop may exit with an |
| 280 |
* address which ends up being unusable due to duplication on the link. */ |
| 281 |
for (i = 0; i < DAD_CONFLICTS_IDGEN_RETRIES_RFC7217; i++) { |
| 282 |
generate_stable_private_address_one(link, secret_key, prefix, i, &addr); |
| 283 |
|
| 284 |
if (!stable_private_address_is_valid(&addr)) |
| 285 |
continue; |
| 286 |
|
| 287 |
/* When 'previous' is non-NULL, then this is called after DAD in the kernel triggered. |
| 288 |
* Let's increment the counter and provide the next address. */ |
| 289 |
if (previous && !found) { |
| 290 |
found = in6_addr_equal(previous, &addr); |
| 291 |
continue; |
| 292 |
} |
| 293 |
|
| 294 |
break; |
| 295 |
} |
| 296 |
if (i >= DAD_CONFLICTS_IDGEN_RETRIES_RFC7217) { |
| 297 |
/* propagate recognizable errors. */ |
| 298 |
if (previous && !found) |
| 299 |
return -EADDRNOTAVAIL; |
| 300 |
|
| 301 |
return log_link_debug_errno(link, SYNTHETIC_ERRNO(EADDRINUSE), |
| 302 |
"Failed to generate stable private address."); |
| 303 |
} |
| 304 |
|
| 305 |
*ret = addr; |
| 306 |
return 1; |
| 307 |
} |
| 308 |
|
| 309 |
static int generate_addresses( |
| 310 |
Link *link, |
| 311 |
Set *tokens, |
| 312 |
const sd_id128_t *app_id, |
| 313 |
const struct in6_addr *prefix, |
| 314 |
uint8_t prefixlen, |
| 315 |
Hashmap **ret) { |
| 316 |
|
| 317 |
_cleanup_hashmap_free_ Hashmap *tokens_by_address = NULL; |
| 318 |
struct in6_addr masked, addr; |
| 319 |
IPv6Token *j; |
| 320 |
int r; |
| 321 |
|
| 322 |
assert(link); |
| 323 |
assert(app_id); |
| 324 |
assert(prefix); |
| 325 |
assert(prefixlen > 0 && prefixlen <= 64); |
| 326 |
assert(ret); |
| 327 |
|
| 328 |
masked = *prefix; |
| 329 |
in6_addr_mask(&masked, prefixlen); |
| 330 |
|
| 331 |
SET_FOREACH(j, tokens) { |
| 332 |
switch (j->type) { |
| 333 |
case ADDRESS_GENERATION_EUI64: |
| 334 |
if (generate_eui64_address(link, &masked, &addr) < 0) |
| 335 |
continue; |
| 336 |
break; |
| 337 |
|
| 338 |
case ADDRESS_GENERATION_STATIC: |
| 339 |
memcpy(addr.s6_addr, masked.s6_addr, 8); |
| 340 |
memcpy(addr.s6_addr + 8, j->address.s6_addr + 8, 8); |
| 341 |
break; |
| 342 |
|
| 343 |
case ADDRESS_GENERATION_PREFIXSTABLE: |
| 344 |
if (in6_addr_is_set(&j->address) && !in6_addr_equal(&j->address, &masked)) |
| 345 |
continue; |
| 346 |
|
| 347 |
if (generate_stable_private_address(link, app_id, &j->secret_key, &masked, /* previous= */ NULL, &addr) < 0) |
| 348 |
continue; |
| 349 |
|
| 350 |
break; |
| 351 |
|
| 352 |
default: |
| 353 |
assert_not_reached(); |
| 354 |
} |
| 355 |
|
| 356 |
r = ipv6_token_put_by_addr(&tokens_by_address, &addr, j); |
| 357 |
if (r < 0) |
| 358 |
return r; |
| 359 |
} |
| 360 |
|
| 361 |
/* fall back to EUI-64 if no token is provided */ |
| 362 |
if (hashmap_isempty(tokens_by_address)) { |
| 363 |
AddressGenerationType type; |
| 364 |
|
| 365 |
if (IN_SET(link->iftype, ARPHRD_ETHER, ARPHRD_INFINIBAND)) { |
| 366 |
type = ADDRESS_GENERATION_EUI64; |
| 367 |
r = generate_eui64_address(link, &masked, &addr); |
| 368 |
} else { |
| 369 |
type = ADDRESS_GENERATION_PREFIXSTABLE; |
| 370 |
r = generate_stable_private_address(link, app_id, &SD_ID128_NULL, &masked, /* previous= */ NULL, &addr); |
| 371 |
} |
| 372 |
if (r < 0) |
| 373 |
return r; |
| 374 |
|
| 375 |
r = ipv6_token_type_put_by_addr(&tokens_by_address, &addr, type); |
| 376 |
if (r < 0) |
| 377 |
return r; |
| 378 |
} |
| 379 |
|
| 380 |
*ret = TAKE_PTR(tokens_by_address); |
| 381 |
return 0; |
| 382 |
} |
| 383 |
|
| 384 |
int dhcp_pd_generate_addresses(Link *link, const struct in6_addr *prefix, Hashmap **ret) { |
| 385 |
return generate_addresses(link, link->network->dhcp_pd_tokens, &DHCP_PD_APP_ID, prefix, 64, ret); |
| 386 |
} |
| 387 |
|
| 388 |
int ndisc_generate_addresses(Link *link, const struct in6_addr *prefix, uint8_t prefixlen, Hashmap **ret) { |
| 389 |
return generate_addresses(link, link->network->ndisc_tokens, &NDISC_APP_ID, prefix, prefixlen, ret); |
| 390 |
} |
| 391 |
|
| 392 |
int radv_generate_addresses(Link *link, Set *tokens, const struct in6_addr *prefix, uint8_t prefixlen, Hashmap **ret) { |
| 393 |
return generate_addresses(link, tokens, &RADV_APP_ID, prefix, prefixlen, ret); |
| 394 |
} |
| 395 |
|
| 396 |
int regenerate_address(Address *address, Link *link) { |
| 397 |
struct in6_addr masked; |
| 398 |
sd_id128_t app_id; |
| 399 |
|
| 400 |
assert(link); |
| 401 |
assert(address); |
| 402 |
assert(address->family == AF_INET6); |
| 403 |
assert(!address->link && !address->network); |
| 404 |
|
| 405 |
if (!address->token || |
| 406 |
address->token->type != ADDRESS_GENERATION_PREFIXSTABLE) |
| 407 |
return 0; |
| 408 |
|
| 409 |
switch (address->source) { |
| 410 |
case NETWORK_CONFIG_SOURCE_STATIC: |
| 411 |
app_id = RADV_APP_ID; |
| 412 |
break; |
| 413 |
case NETWORK_CONFIG_SOURCE_DHCP_PD: |
| 414 |
app_id = DHCP_PD_APP_ID; |
| 415 |
break; |
| 416 |
case NETWORK_CONFIG_SOURCE_NDISC: |
| 417 |
app_id = NDISC_APP_ID; |
| 418 |
break; |
| 419 |
default: |
| 420 |
assert_not_reached(); |
| 421 |
} |
| 422 |
|
| 423 |
masked = address->in_addr.in6; |
| 424 |
in6_addr_mask(&masked, address->prefixlen); |
| 425 |
|
| 426 |
return generate_stable_private_address(link, &app_id, &address->token->secret_key, &masked, &address->in_addr.in6, &address->in_addr.in6); |
| 427 |
} |
| 428 |
|
| 429 |
int config_parse_address_generation_type( |
| 430 |
const char *unit, |
| 431 |
const char *filename, |
| 432 |
unsigned line, |
| 433 |
const char *section, |
| 434 |
unsigned section_line, |
| 435 |
const char *lvalue, |
| 436 |
int ltype, |
| 437 |
const char *rvalue, |
| 438 |
void *data, |
| 439 |
void *userdata) { |
| 440 |
|
| 441 |
_cleanup_free_ char *addr_alloc = NULL; |
| 442 |
sd_id128_t secret_key = SD_ID128_NULL; |
| 443 |
union in_addr_union buffer = {}; |
| 444 |
AddressGenerationType type; |
| 445 |
Set **tokens = ASSERT_PTR(data); |
| 446 |
const char *addr; |
| 447 |
int r; |
| 448 |
|
| 449 |
assert(filename); |
| 450 |
assert(lvalue); |
| 451 |
assert(rvalue); |
| 452 |
|
| 453 |
if (isempty(rvalue)) { |
| 454 |
*tokens = set_free(*tokens); |
| 455 |
return 0; |
| 456 |
} |
| 457 |
|
| 458 |
if ((addr = startswith(rvalue, "prefixstable"))) { |
| 459 |
const char *comma; |
| 460 |
|
| 461 |
type = ADDRESS_GENERATION_PREFIXSTABLE; |
| 462 |
|
| 463 |
if (*addr == ':') { |
| 464 |
addr++; |
| 465 |
|
| 466 |
comma = strchr(addr, ','); |
| 467 |
if (comma) { |
| 468 |
addr_alloc = strndup(addr, comma - addr); |
| 469 |
if (!addr_alloc) |
| 470 |
return log_oom(); |
| 471 |
|
| 472 |
addr = addr_alloc; |
| 473 |
} |
| 474 |
} else if (*addr == ',') |
| 475 |
comma = TAKE_PTR(addr); |
| 476 |
else if (*addr == '\0') { |
| 477 |
comma = NULL; |
| 478 |
addr = NULL; |
| 479 |
} else { |
| 480 |
log_syntax(unit, LOG_WARNING, filename, line, 0, |
| 481 |
"Invalid IPv6 token mode in %s=, ignoring assignment: %s", |
| 482 |
lvalue, rvalue); |
| 483 |
return 0; |
| 484 |
} |
| 485 |
|
| 486 |
if (comma) { |
| 487 |
r = id128_from_string_nonzero(comma + 1, &secret_key); |
| 488 |
if (r < 0) { |
| 489 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 490 |
r == -ENXIO ? "Secret key in %s= cannot be null, ignoring assignment: %s" |
| 491 |
: "Failed to parse secret key in %s=, ignoring assignment: %s", |
| 492 |
lvalue, rvalue); |
| 493 |
return 0; |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
} else if (streq(rvalue, "eui64")) { |
| 498 |
type = ADDRESS_GENERATION_EUI64; |
| 499 |
addr = NULL; |
| 500 |
} else { |
| 501 |
type = ADDRESS_GENERATION_STATIC; |
| 502 |
|
| 503 |
addr = startswith(rvalue, "static:"); |
| 504 |
if (!addr) |
| 505 |
addr = rvalue; |
| 506 |
} |
| 507 |
|
| 508 |
if (addr) { |
| 509 |
r = in_addr_from_string(AF_INET6, addr, &buffer); |
| 510 |
if (r < 0) { |
| 511 |
log_syntax(unit, LOG_WARNING, filename, line, r, |
| 512 |
"Failed to parse IP address in %s=, ignoring assignment: %s", |
| 513 |
lvalue, rvalue); |
| 514 |
return 0; |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
switch (type) { |
| 519 |
case ADDRESS_GENERATION_EUI64: |
| 520 |
assert(in6_addr_is_null(&buffer.in6)); |
| 521 |
break; |
| 522 |
|
| 523 |
case ADDRESS_GENERATION_STATIC: |
| 524 |
/* Only last 64 bits are used. */ |
| 525 |
memzero(buffer.in6.s6_addr, 8); |
| 526 |
|
| 527 |
if (in6_addr_is_null(&buffer.in6)) { |
| 528 |
log_syntax(unit, LOG_WARNING, filename, line, 0, |
| 529 |
"IPv6 address in %s= cannot be the ANY address, ignoring assignment: %s", |
| 530 |
lvalue, rvalue); |
| 531 |
return 0; |
| 532 |
} |
| 533 |
break; |
| 534 |
|
| 535 |
case ADDRESS_GENERATION_PREFIXSTABLE: |
| 536 |
/* At most, the initial 64 bits are used. */ |
| 537 |
(void) in6_addr_mask(&buffer.in6, 64); |
| 538 |
break; |
| 539 |
|
| 540 |
default: |
| 541 |
assert_not_reached(); |
| 542 |
} |
| 543 |
|
| 544 |
r = ipv6_token_add(tokens, type, &buffer.in6, &secret_key); |
| 545 |
if (r < 0) |
| 546 |
return log_oom(); |
| 547 |
|
| 548 |
return 0; |
| 549 |
} |