X Tutup
Skip to content

Commit de2f372

Browse files
committed
network: move ipv6ll related functions to networkd-ipv6ll.[ch]
1 parent 5573ed2 commit de2f372

File tree

8 files changed

+122
-86
lines changed

8 files changed

+122
-86
lines changed

src/network/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ sources = files('''
9393
networkd-ipv4ll.h
9494
networkd-ipv6-proxy-ndp.c
9595
networkd-ipv6-proxy-ndp.h
96+
networkd-ipv6ll.c
97+
networkd-ipv6ll.h
9698
networkd-json.c
9799
networkd-json.h
98100
networkd-link-bus.c

src/network/networkd-ipv6ll.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
3+
#include <linux/if.h>
4+
#include <linux/if_arp.h>
5+
6+
#include "in-addr-util.h"
7+
#include "networkd-address.h"
8+
#include "networkd-ipv6ll.h"
9+
#include "networkd-link.h"
10+
#include "networkd-network.h"
11+
#include "networkd-util.h"
12+
#include "socket-util.h"
13+
#include "string-table.h"
14+
#include "strv.h"
15+
16+
bool link_ipv6ll_enabled(Link *link) {
17+
assert(link);
18+
19+
if (!socket_ipv6_is_supported())
20+
return false;
21+
22+
if (link->flags & IFF_LOOPBACK)
23+
return false;
24+
25+
if (!link->network)
26+
return false;
27+
28+
if (link->iftype == ARPHRD_CAN)
29+
return false;
30+
31+
if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "sit", "vti", "nlmon"))
32+
return false;
33+
34+
if (link->network->bond)
35+
return false;
36+
37+
return link->network->link_local & ADDRESS_FAMILY_IPV6;
38+
}
39+
40+
bool link_may_have_ipv6ll(Link *link) {
41+
assert(link);
42+
43+
/*
44+
* This is equivalent to link_ipv6ll_enabled() for non-WireGuard interfaces.
45+
*
46+
* For WireGuard interface, the kernel does not assign any IPv6LL addresses, but we can assign
47+
* it manually. It is necessary to set an IPv6LL address manually to run NDisc or RADV on
48+
* WireGuard interface. Note, also Multicast=yes must be set. See #17380.
49+
*
50+
* TODO: May be better to introduce GenerateIPv6LinkLocalAddress= setting, and use algorithms
51+
* used in networkd-address-generation.c
52+
*/
53+
54+
if (link_ipv6ll_enabled(link))
55+
return true;
56+
57+
/* IPv6LL address can be manually assigned on WireGuard interface. */
58+
if (streq_ptr(link->kind, "wireguard")) {
59+
Address *a;
60+
61+
if (!link->network)
62+
return false;
63+
64+
ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) {
65+
if (a->family != AF_INET6)
66+
continue;
67+
if (in6_addr_is_set(&a->in_addr_peer.in6))
68+
continue;
69+
if (in6_addr_is_link_local(&a->in_addr.in6))
70+
return true;
71+
}
72+
}
73+
74+
return false;
75+
}
76+
77+
static const char* const ipv6_link_local_address_gen_mode_table[_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX] = {
78+
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64] = "eui64",
79+
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE] = "none",
80+
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY] = "stable-privacy",
81+
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM] = "random",
82+
};
83+
84+
DEFINE_STRING_TABLE_LOOKUP(ipv6_link_local_address_gen_mode, IPv6LinkLocalAddressGenMode);
85+
DEFINE_CONFIG_PARSE_ENUM(
86+
config_parse_ipv6_link_local_address_gen_mode,
87+
ipv6_link_local_address_gen_mode,
88+
IPv6LinkLocalAddressGenMode,
89+
"Failed to parse IPv6 link local address generation mode");

src/network/networkd-ipv6ll.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
#pragma once
3+
4+
#include <errno.h>
5+
#include <linux/if_link.h>
6+
#include <stdbool.h>
7+
8+
#include "conf-parser.h"
9+
#include "macro.h"
10+
11+
typedef struct Link Link;
12+
13+
typedef enum IPv6LinkLocalAddressGenMode {
14+
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64 = IN6_ADDR_GEN_MODE_EUI64,
15+
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE = IN6_ADDR_GEN_MODE_NONE,
16+
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY = IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
17+
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM = IN6_ADDR_GEN_MODE_RANDOM,
18+
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX,
19+
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID = -EINVAL,
20+
} IPv6LinkLocalAddressGenMode;
21+
22+
bool link_ipv6ll_enabled(Link *link);
23+
bool link_may_have_ipv6ll(Link *link);
24+
25+
const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
26+
IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
27+
28+
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);

src/network/networkd-link.c

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -105,67 +105,6 @@ bool link_ipv4ll_enabled(Link *link) {
105105
return link->network->link_local & ADDRESS_FAMILY_IPV4;
106106
}
107107

108-
bool link_ipv6ll_enabled(Link *link) {
109-
assert(link);
110-
111-
if (!socket_ipv6_is_supported())
112-
return false;
113-
114-
if (link->flags & IFF_LOOPBACK)
115-
return false;
116-
117-
if (!link->network)
118-
return false;
119-
120-
if (link->iftype == ARPHRD_CAN)
121-
return false;
122-
123-
if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "sit", "vti", "nlmon"))
124-
return false;
125-
126-
if (link->network->bond)
127-
return false;
128-
129-
return link->network->link_local & ADDRESS_FAMILY_IPV6;
130-
}
131-
132-
bool link_may_have_ipv6ll(Link *link) {
133-
assert(link);
134-
135-
/*
136-
* This is equivalent to link_ipv6ll_enabled() for non-WireGuard interfaces.
137-
*
138-
* For WireGuard interface, the kernel does not assign any IPv6LL addresses, but we can assign
139-
* it manually. It is necessary to set an IPv6LL address manually to run NDisc or RADV on
140-
* WireGuard interface. Note, also Multicast=yes must be set. See #17380.
141-
*
142-
* TODO: May be better to introduce GenerateIPv6LinkLocalAddress= setting, and use algorithms
143-
* used in networkd-address-generation.c
144-
*/
145-
146-
if (link_ipv6ll_enabled(link))
147-
return true;
148-
149-
/* IPv6LL address can be manually assigned on WireGuard interface. */
150-
if (streq_ptr(link->kind, "wireguard")) {
151-
Address *a;
152-
153-
if (!link->network)
154-
return false;
155-
156-
ORDERED_HASHMAP_FOREACH(a, link->network->addresses_by_section) {
157-
if (a->family != AF_INET6)
158-
continue;
159-
if (in6_addr_is_set(&a->in_addr_peer.in6))
160-
continue;
161-
if (in6_addr_is_link_local(&a->in_addr.in6))
162-
return true;
163-
}
164-
}
165-
166-
return false;
167-
}
168-
169108
bool link_ipv6_enabled(Link *link) {
170109
assert(link);
171110

src/network/networkd-link.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "log-link.h"
2222
#include "netif-util.h"
2323
#include "network-util.h"
24+
#include "networkd-ipv6ll.h"
2425
#include "networkd-util.h"
2526
#include "ordered-set.h"
2627
#include "resolve-util.h"
@@ -219,8 +220,6 @@ static inline bool link_has_carrier(Link *link) {
219220
}
220221

221222
bool link_ipv6_enabled(Link *link);
222-
bool link_ipv6ll_enabled(Link *link);
223-
bool link_may_have_ipv6ll(Link *link);
224223
int link_ipv6ll_gained(Link *link);
225224

226225
bool link_ipv4ll_enabled(Link *link);

src/network/networkd-network-gperf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
2222
#include "networkd-dhcp6.h"
2323
#include "networkd-ipv4ll.h"
2424
#include "networkd-ipv6-proxy-ndp.h"
25+
#include "networkd-ipv6ll.h"
2526
#include "networkd-lldp-tx.h"
2627
#include "networkd-ndisc.h"
2728
#include "networkd-network.h"

src/network/networkd-network.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,16 +1385,6 @@ static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
13851385

13861386
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(keep_configuration, KeepConfiguration, KEEP_CONFIGURATION_YES);
13871387

1388-
static const char* const ipv6_link_local_address_gen_mode_table[_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX] = {
1389-
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64] = "eui64",
1390-
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE] = "none",
1391-
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY] = "stable-privacy",
1392-
[IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM] = "random",
1393-
};
1394-
1395-
DEFINE_STRING_TABLE_LOOKUP(ipv6_link_local_address_gen_mode, IPv6LinkLocalAddressGenMode);
1396-
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");
1397-
13981388
static const char* const activation_policy_table[_ACTIVATION_POLICY_MAX] = {
13991389
[ACTIVATION_POLICY_UP] = "up",
14001390
[ACTIVATION_POLICY_ALWAYS_UP] = "always-up",

src/network/networkd-network.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "networkd-dhcp-common.h"
1919
#include "networkd-dhcp4.h"
2020
#include "networkd-dhcp6.h"
21+
#include "networkd-ipv6ll.h"
2122
#include "networkd-lldp-rx.h"
2223
#include "networkd-ndisc.h"
2324
#include "networkd-radv.h"
@@ -38,15 +39,6 @@ typedef enum KeepConfiguration {
3839
_KEEP_CONFIGURATION_INVALID = -EINVAL,
3940
} KeepConfiguration;
4041

41-
typedef enum IPv6LinkLocalAddressGenMode {
42-
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_EUI64 = IN6_ADDR_GEN_MODE_EUI64,
43-
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE = IN6_ADDR_GEN_MODE_NONE,
44-
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_STABLE_PRIVACY = IN6_ADDR_GEN_MODE_STABLE_PRIVACY,
45-
IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_RANDOM = IN6_ADDR_GEN_MODE_RANDOM,
46-
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_MAX,
47-
_IPV6_LINK_LOCAL_ADDRESS_GEN_MODE_INVALID = -EINVAL,
48-
} IPv6LinkLocalAddressGenMode;
49-
5042
typedef enum ActivationPolicy {
5143
ACTIVATION_POLICY_UP,
5244
ACTIVATION_POLICY_ALWAYS_UP,
@@ -385,7 +377,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
385377
CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
386378
CONFIG_PARSER_PROTOTYPE(config_parse_required_family_for_online);
387379
CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
388-
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
389380
CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
390381
CONFIG_PARSER_PROTOTYPE(config_parse_link_group);
391382
CONFIG_PARSER_PROTOTYPE(config_parse_ignore_carrier_loss);
@@ -395,8 +386,5 @@ const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF
395386
const char* keep_configuration_to_string(KeepConfiguration i) _const_;
396387
KeepConfiguration keep_configuration_from_string(const char *s) _pure_;
397388

398-
const char* ipv6_link_local_address_gen_mode_to_string(IPv6LinkLocalAddressGenMode s) _const_;
399-
IPv6LinkLocalAddressGenMode ipv6_link_local_address_gen_mode_from_string(const char *s) _pure_;
400-
401389
const char* activation_policy_to_string(ActivationPolicy i) _const_;
402390
ActivationPolicy activation_policy_from_string(const char *s) _pure_;

0 commit comments

Comments
 (0)
X Tutup