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_boolean_table
[_ADDRESS_FAMILY_BOOLEAN_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_boolean_table
[_ADDRESS_FAMILY_BOOLEAN_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 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(address_family_boolean
, AddressFamilyBoolean
, ADDRESS_FAMILY_YES
);
28 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(link_local_address_family_boolean
, AddressFamilyBoolean
, ADDRESS_FAMILY_YES
);
29 DEFINE_CONFIG_PARSE_ENUM(config_parse_link_local_address_family_boolean
, link_local_address_family_boolean
,
30 AddressFamilyBoolean
, "Failed to parse option");
32 int config_parse_address_family_boolean_with_kernel(
37 unsigned section_line
,
44 AddressFamilyBoolean
*fwd
= data
, s
;
51 /* This function is mostly obsolete now. It simply redirects
52 * "kernel" to "no". In older networkd versions we used to
53 * distinguish IPForward=off from IPForward=kernel, where the
54 * former would explicitly turn off forwarding while the
55 * latter would simply not touch the setting. But that logic
56 * is gone, hence silently accept the old setting, but turn it
59 s
= address_family_boolean_from_string(rvalue
);
61 if (streq(rvalue
, "kernel"))
62 s
= ADDRESS_FAMILY_NO
;
64 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IPForward= option, ignoring: %s", rvalue
);
74 /* Router lifetime can be set with netlink interface since kernel >= 4.5
75 * so for the supported kernel we don't need to expire routes in userspace */
76 int kernel_route_expiration_supported(void) {
77 static int cached
= -1;
82 .type
= CONDITION_KERNEL_VERSION
,
83 .parameter
= (char *) ">= 4.5"
85 r
= condition_test(&c
);
94 static void network_config_hash_func(const NetworkConfigSection
*c
, struct siphash
*state
) {
95 siphash24_compress(c
->filename
, strlen(c
->filename
), state
);
96 siphash24_compress(&c
->line
, sizeof(c
->line
), state
);
99 static int network_config_compare_func(const NetworkConfigSection
*x
, const NetworkConfigSection
*y
) {
102 r
= strcmp(x
->filename
, y
->filename
);
106 return CMP(x
->line
, y
->line
);
109 DEFINE_HASH_OPS(network_config_hash_ops
, NetworkConfigSection
, network_config_hash_func
, network_config_compare_func
);
111 int network_config_section_new(const char *filename
, unsigned line
, NetworkConfigSection
**s
) {
112 NetworkConfigSection
*cs
;
114 cs
= malloc0(offsetof(NetworkConfigSection
, filename
) + strlen(filename
) + 1);
118 strcpy(cs
->filename
, filename
);
126 void network_config_section_free(NetworkConfigSection
*cs
) {