mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
network: address-genereation: introduce generate_addresses()
Preparation for later commits. This does not change functionality.
This commit is contained in:
parent
d207581fc5
commit
868bd1aa1c
@ -150,13 +150,21 @@ static int generate_stable_private_address(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ndisc_router_generate_addresses(Link *link, struct in6_addr *prefix, uint8_t prefixlen, Set **ret) {
|
||||
static int generate_addresses(
|
||||
Link *link,
|
||||
Set *tokens,
|
||||
const sd_id128_t *app_id,
|
||||
const struct in6_addr *prefix,
|
||||
uint8_t prefixlen,
|
||||
Set **ret) {
|
||||
|
||||
_cleanup_set_free_ Set *addresses = NULL;
|
||||
struct in6_addr masked;
|
||||
IPv6Token *j;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(app_id);
|
||||
assert(prefix);
|
||||
assert(prefixlen > 0 && prefixlen <= 64);
|
||||
assert(ret);
|
||||
@ -164,7 +172,7 @@ int ndisc_router_generate_addresses(Link *link, struct in6_addr *prefix, uint8_t
|
||||
masked = *prefix;
|
||||
in6_addr_mask(&masked, prefixlen);
|
||||
|
||||
SET_FOREACH(j, link->network->ndisc_tokens) {
|
||||
SET_FOREACH(j, tokens) {
|
||||
struct in6_addr addr, *copy;
|
||||
|
||||
switch (j->type) {
|
||||
@ -177,7 +185,7 @@ int ndisc_router_generate_addresses(Link *link, struct in6_addr *prefix, uint8_t
|
||||
if (in6_addr_is_set(&j->address) && !in6_addr_equal(&j->address, &masked))
|
||||
continue;
|
||||
|
||||
if (generate_stable_private_address(link, &NDISC_APP_ID, &masked, &addr) < 0)
|
||||
if (generate_stable_private_address(link, app_id, &masked, &addr) < 0)
|
||||
continue;
|
||||
|
||||
break;
|
||||
@ -214,6 +222,10 @@ int ndisc_router_generate_addresses(Link *link, struct in6_addr *prefix, uint8_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ndisc_generate_addresses(Link *link, const struct in6_addr *prefix, uint8_t prefixlen, Set **ret) {
|
||||
return generate_addresses(link, link->network->ndisc_tokens, &NDISC_APP_ID, prefix, prefixlen, ret);
|
||||
}
|
||||
|
||||
static void ipv6_token_hash_func(const IPv6Token *p, struct siphash *state) {
|
||||
siphash24_compress(&p->type, sizeof(p->type), state);
|
||||
siphash24_compress(&p->address, sizeof(p->address), state);
|
||||
|
@ -9,6 +9,6 @@ typedef struct Link Link;
|
||||
|
||||
void generate_eui64_address(const Link *link, const struct in6_addr *prefix, struct in6_addr *ret);
|
||||
|
||||
int ndisc_router_generate_addresses(Link *link, struct in6_addr *address, uint8_t prefixlen, Set **ret);
|
||||
int ndisc_generate_addresses(Link *link, const struct in6_addr *prefix, uint8_t prefixlen, Set **ret);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_address_generation_type);
|
||||
|
@ -404,7 +404,7 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
|
||||
|
||||
/* ndisc_router_generate_addresses() below requires the prefix length <= 64. */
|
||||
/* ndisc_generate_addresses() below requires the prefix length <= 64. */
|
||||
if (prefixlen > 64) {
|
||||
_cleanup_free_ char *buf = NULL;
|
||||
|
||||
@ -430,7 +430,7 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
|
||||
if (lifetime_preferred > lifetime_valid)
|
||||
return 0;
|
||||
|
||||
r = ndisc_router_generate_addresses(link, &prefix, prefixlen, &addresses);
|
||||
r = ndisc_generate_addresses(link, &prefix, prefixlen, &addresses);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to generate SLAAC addresses: %m");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user