1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2013 Tom Gundersen <teg@jklm.no>
7 #include "conf-parser.h"
8 #include "networkd-util.h"
9 #include "parse-util.h"
10 #include "string-table.h"
11 #include "string-util.h"
14 const char *address_family_boolean_to_string(AddressFamilyBoolean b
) {
15 if (IN_SET(b
, ADDRESS_FAMILY_YES
, ADDRESS_FAMILY_NO
))
16 return yes_no(b
== ADDRESS_FAMILY_YES
);
18 if (b
== ADDRESS_FAMILY_IPV4
)
20 if (b
== ADDRESS_FAMILY_IPV6
)
26 AddressFamilyBoolean
address_family_boolean_from_string(const char *s
) {
29 /* Make this a true superset of a boolean */
33 return ADDRESS_FAMILY_YES
;
35 return ADDRESS_FAMILY_NO
;
38 return ADDRESS_FAMILY_IPV4
;
40 return ADDRESS_FAMILY_IPV6
;
42 return _ADDRESS_FAMILY_BOOLEAN_INVALID
;
45 DEFINE_CONFIG_PARSE_ENUM(config_parse_address_family_boolean
, address_family_boolean
, AddressFamilyBoolean
, "Failed to parse option");
47 int config_parse_address_family_boolean_with_kernel(
52 unsigned section_line
,
59 AddressFamilyBoolean
*fwd
= data
, s
;
66 /* This function is mostly obsolete now. It simply redirects
67 * "kernel" to "no". In older networkd versions we used to
68 * distuingish IPForward=off from IPForward=kernel, where the
69 * former would explicitly turn off forwarding while the
70 * latter would simply not touch the setting. But that logic
71 * is gone, hence silently accept the old setting, but turn it
74 s
= address_family_boolean_from_string(rvalue
);
76 if (streq(rvalue
, "kernel"))
77 s
= ADDRESS_FAMILY_NO
;
79 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse IPForward= option, ignoring: %s", rvalue
);
89 /* Router lifetime can be set with netlink interface since kernel >= 4.5
90 * so for the supported kernel we dont need to expire routes in userspace */
91 int kernel_route_expiration_supported(void) {
92 static int cached
= -1;
97 .type
= CONDITION_KERNEL_VERSION
,
98 .parameter
= (char *) ">= 4.5"
100 r
= condition_test(&c
);