1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include "conf-parser.h"
5 #include "networkd-util.h"
6 #include "parse-util.h"
7 #include "string-table.h"
8 #include "string-util.h"
11 static const char* const address_family_table
[_ADDRESS_FAMILY_MAX
] = {
12 [ADDRESS_FAMILY_NO
] = "no",
13 [ADDRESS_FAMILY_YES
] = "yes",
14 [ADDRESS_FAMILY_IPV4
] = "ipv4",
15 [ADDRESS_FAMILY_IPV6
] = "ipv6",
18 static const char* const link_local_address_family_table
[_ADDRESS_FAMILY_MAX
] = {
19 [ADDRESS_FAMILY_NO
] = "no",
20 [ADDRESS_FAMILY_YES
] = "yes",
21 [ADDRESS_FAMILY_IPV4
] = "ipv4",
22 [ADDRESS_FAMILY_IPV6
] = "ipv6",
23 [ADDRESS_FAMILY_FALLBACK
] = "fallback",
24 [ADDRESS_FAMILY_FALLBACK_IPV4
] = "ipv4-fallback",
27 static const char* const routing_policy_rule_address_family_table
[_ADDRESS_FAMILY_MAX
] = {
28 [ADDRESS_FAMILY_YES
] = "both",
29 [ADDRESS_FAMILY_IPV4
] = "ipv4",
30 [ADDRESS_FAMILY_IPV6
] = "ipv6",
33 static const char* const duplicate_address_detection_address_family_table
[_ADDRESS_FAMILY_MAX
] = {
34 [ADDRESS_FAMILY_NO
] = "none",
35 [ADDRESS_FAMILY_YES
] = "both",
36 [ADDRESS_FAMILY_IPV4
] = "ipv4",
37 [ADDRESS_FAMILY_IPV6
] = "ipv6",
40 static const char* const dhcp_lease_info_table
[_SD_DHCP_LEASE_INFO_MAX
] = {
41 [SD_DHCP_LEASE_DNS_SERVERS
] = "DNS servers",
42 [SD_DHCP_LEASE_NTP_SERVERS
] = "NTP servers",
43 [SD_DHCP_LEASE_SIP_SERVERS
] = "SIP servers",
44 [SD_DHCP_LEASE_POP3_SERVERS
] = "POP3 servers",
45 [SD_DHCP_LEASE_SMTP_SERVERS
] = "SMTP servers",
46 [SD_DHCP_LEASE_LPR_SERVERS
] = "LPR servers",
49 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(address_family
, AddressFamily
, ADDRESS_FAMILY_YES
);
50 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(link_local_address_family
, AddressFamily
, ADDRESS_FAMILY_YES
);
51 DEFINE_STRING_TABLE_LOOKUP(routing_policy_rule_address_family
, AddressFamily
);
52 DEFINE_STRING_TABLE_LOOKUP(duplicate_address_detection_address_family
, AddressFamily
);
53 DEFINE_CONFIG_PARSE_ENUM(config_parse_link_local_address_family
, link_local_address_family
,
54 AddressFamily
, "Failed to parse option");
55 DEFINE_STRING_TABLE_LOOKUP(dhcp_lease_info
, sd_dhcp_lease_info
);
57 int config_parse_address_family_with_kernel(
62 unsigned section_line
,
69 AddressFamily
*fwd
= data
, s
;
76 /* This function is mostly obsolete now. It simply redirects
77 * "kernel" to "no". In older networkd versions we used to
78 * distinguish IPForward=off from IPForward=kernel, where the
79 * former would explicitly turn off forwarding while the
80 * latter would simply not touch the setting. But that logic
81 * is gone, hence silently accept the old setting, but turn it
84 s
= address_family_from_string(rvalue
);
86 if (streq(rvalue
, "kernel"))
87 s
= ADDRESS_FAMILY_NO
;
89 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IPForward= option, ignoring: %s", rvalue
);
99 /* Router lifetime can be set with netlink interface since kernel >= 4.5
100 * so for the supported kernel we don't need to expire routes in userspace */
101 int kernel_route_expiration_supported(void) {
102 static int cached
= -1;
107 .type
= CONDITION_KERNEL_VERSION
,
108 .parameter
= (char *) ">= 4.5"
110 r
= condition_test(&c
, NULL
);
119 static void network_config_hash_func(const NetworkConfigSection
*c
, struct siphash
*state
) {
120 siphash24_compress(c
->filename
, strlen(c
->filename
), state
);
121 siphash24_compress(&c
->line
, sizeof(c
->line
), state
);
124 static int network_config_compare_func(const NetworkConfigSection
*x
, const NetworkConfigSection
*y
) {
127 r
= strcmp(x
->filename
, y
->filename
);
131 return CMP(x
->line
, y
->line
);
134 DEFINE_HASH_OPS(network_config_hash_ops
, NetworkConfigSection
, network_config_hash_func
, network_config_compare_func
);
136 int network_config_section_new(const char *filename
, unsigned line
, NetworkConfigSection
**s
) {
137 NetworkConfigSection
*cs
;
139 cs
= malloc0(offsetof(NetworkConfigSection
, filename
) + strlen(filename
) + 1);
143 strcpy(cs
->filename
, filename
);
151 void network_config_section_free(NetworkConfigSection
*cs
) {