network: move ipv6ll related functions to networkd-ipv6ll.[ch]

This commit is contained in:
Yu Watanabe
2022-02-08 21:56:02 +09:00
parent 5573ed2230
commit de2f372ea2
8 changed files with 122 additions and 86 deletions

View File

@@ -93,6 +93,8 @@ sources = files('''
networkd-ipv4ll.h
networkd-ipv6-proxy-ndp.c
networkd-ipv6-proxy-ndp.h
networkd-ipv6ll.c
networkd-ipv6ll.h
networkd-json.c
networkd-json.h
networkd-link-bus.c

View File

@@ -0,0 +1,89 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <linux/if.h>
#include <linux/if_arp.h>
#include "in-addr-util.h"
#include "networkd-address.h"
#include "networkd-ipv6ll.h"
#include "networkd-link.h"
#include "networkd-network.h"
#include "networkd-util.h"
#include "socket-util.h"
#include "string-table.h"
#include "strv.h"
bool link_ipv6ll_enabled(Link *link) {
assert(link);
if (!socket_ipv6_is_supported())
return false;
if (link->flags & IFF_LOOPBACK)
return false;
if (!link->network)
return false;
if (link->iftype == ARPHRD_CAN)
return false;
if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "sit", "vti", "nlmon"))
return false;
if (link->network->bond)
return false;
return link->network->link_local & ADDRESS_FAMILY_IPV6;
}
bool link_may_have_ipv6ll(Link *link) {
assert(link);
/*
* This is equivalent to link_ipv6ll_enabled() for non-WireGuard interfaces.
*
* For WireGuard interface, the kernel does not assign any IPv6LL addresses, but we can assign
* it manually. It is necessary to set an IPv6LL address manually to run NDisc or RADV on
* WireGuard interface. Note, also Multicast=yes must be set. See #17380.
*
* TODO: May be better to introduce GenerateIPv6LinkLocalAddress= setting, and use algorithms
* used in networkd-address-generation.c
*/
if (link_ipv6ll_enabled(link))
return true;
/* IPv6LL address can be manually assigned on WireGuard interface. */
if (streq_ptr(link->kind, "wireguard")) {
Address *a;
if (!link->network)
return false;
ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) {
if (a->family != AF_INET6)
continue;
if (in6_addr_is_set(&a->in_addr_peer.in6))
continue;
if (in6_addr_is_link_local(&a->in_addr.in6))
return true;
}
}
return false;
}
static const char* const ipv6_link_local_address_gen_mode_table[_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX] = {
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64] = "eui64",
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE] = "none",
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY] = "stable-privacy",
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM] = "random",
};
DEFINE_STRING_TABLE_LOOKUP(ipv6_link_local_address_gen_mode, IPv6LinkLocalAddressGenMode);
DEFINE_CONFIG_PARSE_ENUM(
config_parse_ipv6_link_local_address_gen_mode,
ipv6_link_local_address_gen_mode,
IPv6LinkLocalAddressGenMode,
"Failed to parse IPv6 link local address generation mode");

View File

@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <linux/if_link.h>
#include <stdbool.h>
#include "conf-parser.h"
#include "macro.h"
typedef struct Link Link;
typedef enum IPv6LinkLocalAddressGenMode {
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64 = IN6_ADDR_GEN_MODE_EUI64,
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE = IN6_ADDR_GEN_MODE_NONE,
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY = IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM = IN6_ADDR_GEN_MODE_RANDOM,
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX,
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID = -EINVAL,
} IPv6LinkLocalAddressGenMode;
bool link_ipv6ll_enabled(Link *link);
bool link_may_have_ipv6ll(Link *link);
const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);

View File

@@ -105,67 +105,6 @@ bool link_ipv4ll_enabled(Link *link) {
return link->network->link_local & ADDRESS_FAMILY_IPV4;
}
bool link_ipv6ll_enabled(Link *link) {
assert(link);
if (!socket_ipv6_is_supported())
return false;
if (link->flags & IFF_LOOPBACK)
return false;
if (!link->network)
return false;
if (link->iftype == ARPHRD_CAN)
return false;
if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "sit", "vti", "nlmon"))
return false;
if (link->network->bond)
return false;
return link->network->link_local & ADDRESS_FAMILY_IPV6;
}
bool link_may_have_ipv6ll(Link *link) {
assert(link);
/*
* This is equivalent to link_ipv6ll_enabled() for non-WireGuard interfaces.
*
* For WireGuard interface, the kernel does not assign any IPv6LL addresses, but we can assign
* it manually. It is necessary to set an IPv6LL address manually to run NDisc or RADV on
* WireGuard interface. Note, also Multicast=yes must be set. See #17380.
*
* TODO: May be better to introduce GenerateIPv6LinkLocalAddress= setting, and use algorithms
* used in networkd-address-generation.c
*/
if (link_ipv6ll_enabled(link))
return true;
/* IPv6LL address can be manually assigned on WireGuard interface. */
if (streq_ptr(link->kind, "wireguard")) {
Address *a;
if (!link->network)
return false;
ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) {
if (a->family != AF_INET6)
continue;
if (in6_addr_is_set(&a->in_addr_peer.in6))
continue;
if (in6_addr_is_link_local(&a->in_addr.in6))
return true;
}
}
return false;
}
bool link_ipv6_enabled(Link *link) {
assert(link);

View File

@@ -21,6 +21,7 @@
#include "log-link.h"
#include "netif-util.h"
#include "network-util.h"
#include "networkd-ipv6ll.h"
#include "networkd-util.h"
#include "ordered-set.h"
#include "resolve-util.h"
@@ -219,8 +220,6 @@ static inline bool link_has_carrier(Link *link) {
}
bool link_ipv6_enabled(Link *link);
bool link_ipv6ll_enabled(Link *link);
bool link_may_have_ipv6ll(Link *link);
int link_ipv6ll_gained(Link *link);
bool link_ipv4ll_enabled(Link *link);

View File

@@ -22,6 +22,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
#include "networkd-dhcp6.h"
#include "networkd-ipv4ll.h"
#include "networkd-ipv6-proxy-ndp.h"
#include "networkd-ipv6ll.h"
#include "networkd-lldp-tx.h"
#include "networkd-ndisc.h"
#include "networkd-network.h"

View File

@@ -1385,16 +1385,6 @@ static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES);
static const char* const ipv6_link_local_address_gen_mode_table[_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX] = {
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64] = "eui64",
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE] = "none",
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY] = "stable-privacy",
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM] = "random",
};
DEFINE_STRING_TABLE_LOOKUP(ipv6_link_local_address_gen_mode, IPv6LinkLocalAddressGenMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipv6_link_local_address_gen_mode, ipv6_link_local_address_gen_mode, IPv6LinkLocalAddressGenMode, "Failed to parse IPv6 link local address generation mode");
static const char* const activation_policy_table[_ACTIVATION_POLICY_MAX] = {
[ACTIVATION_POLICY_UP] = "up",
[ACTIVATION_POLICY_ALWAYS_UP] = "always-up",

View File

@@ -18,6 +18,7 @@
#include "networkd-dhcp-common.h"
#include "networkd-dhcp4.h"
#include "networkd-dhcp6.h"
#include "networkd-ipv6ll.h"
#include "networkd-lldp-rx.h"
#include "networkd-ndisc.h"
#include "networkd-radv.h"
@@ -38,15 +39,6 @@ typedef enum KeepConfiguration {
_KEEP_CONFIGURATION_INVALID = -EINVAL,
} KeepConfiguration;
typedef enum IPv6LinkLocalAddressGenMode {
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64 = IN6_ADDR_GEN_MODE_EUI64,
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE = IN6_ADDR_GEN_MODE_NONE,
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY = IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM = IN6_ADDR_GEN_MODE_RANDOM,
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX,
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID = -EINVAL,
} IPv6LinkLocalAddressGenMode;
typedef enum ActivationPolicy {
ACTIVATION_POLICY_UP,
ACTIVATION_POLICY_ALWAYS_UP,
@@ -385,7 +377,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online);
CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
CONFIG_PARSER_PROTOTYPE(config_parse_link_group);
CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss);
@@ -395,8 +386,5 @@ const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF
const char* keep_configuration_to_string(KeepConfiguration i) _const_;
KeepConfiguration keep_configuration_from_string(const char *s) _pure_;
const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
const char* activation_policy_to_string(ActivationPolicy i) _const_;
ActivationPolicy activation_policy_from_string(const char *s) _pure_;