]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-util.c
networkd: stop managing per-interface IP forwarding settings
[thirdparty/systemd.git] / src / network / networkd-util.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "conf-parser.h"
23 #include "networkd-util.h"
24 #include "parse-util.h"
25 #include "string-table.h"
26 #include "string-util.h"
27 #include "util.h"
28
29 const char *address_family_boolean_to_string(AddressFamilyBoolean b) {
30 if (b == ADDRESS_FAMILY_YES ||
31 b == ADDRESS_FAMILY_NO)
32 return yes_no(b == ADDRESS_FAMILY_YES);
33
34 if (b == ADDRESS_FAMILY_IPV4)
35 return "ipv4";
36 if (b == ADDRESS_FAMILY_IPV6)
37 return "ipv6";
38
39 return NULL;
40 }
41
42 AddressFamilyBoolean address_family_boolean_from_string(const char *s) {
43 int r;
44
45 /* Make this a true superset of a boolean */
46
47 r = parse_boolean(s);
48 if (r > 0)
49 return ADDRESS_FAMILY_YES;
50 if (r == 0)
51 return ADDRESS_FAMILY_NO;
52
53 if (streq(s, "ipv4"))
54 return ADDRESS_FAMILY_IPV4;
55 if (streq(s, "ipv6"))
56 return ADDRESS_FAMILY_IPV6;
57
58 return _ADDRESS_FAMILY_BOOLEAN_INVALID;
59 }
60
61 DEFINE_CONFIG_PARSE_ENUM(config_parse_address_family_boolean, address_family_boolean, AddressFamilyBoolean, "Failed to parse option");
62
63 int config_parse_address_family_boolean_with_kernel(
64 const char* unit,
65 const char *filename,
66 unsigned line,
67 const char *section,
68 unsigned section_line,
69 const char *lvalue,
70 int ltype,
71 const char *rvalue,
72 void *data,
73 void *userdata) {
74
75 AddressFamilyBoolean *fwd = data, s;
76
77 assert(filename);
78 assert(lvalue);
79 assert(rvalue);
80 assert(data);
81
82 /* This function is mostly obsolete now. It simply redirects
83 * "kernel" to "no". In older networkd versions we used to
84 * distuingish IPForward=off from IPForward=kernel, where the
85 * former would explicitly turn off forwarding while the
86 * latter would simply not touch the setting. But that logic
87 * is gone, hence silently accept the old setting, but turn it
88 * to "no". */
89
90 s = address_family_boolean_from_string(rvalue);
91 if (s < 0) {
92 if (streq(rvalue, "kernel"))
93 s = ADDRESS_FAMILY_NO;
94 else {
95 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IPForward= option, ignoring: %s", rvalue);
96 return 0;
97 }
98 }
99
100 *fwd = s;
101
102 return 0;
103 }
104
105 static const char* const resolve_support_table[_RESOLVE_SUPPORT_MAX] = {
106 [RESOLVE_SUPPORT_NO] = "no",
107 [RESOLVE_SUPPORT_YES] = "yes",
108 [RESOLVE_SUPPORT_RESOLVE] = "resolve",
109 };
110
111 DEFINE_STRING_TABLE_LOOKUP(resolve_support, ResolveSupport);
112
113 int config_parse_resolve(
114 const char* unit,
115 const char *filename,
116 unsigned line,
117 const char *section,
118 unsigned section_line,
119 const char *lvalue,
120 int ltype,
121 const char *rvalue,
122 void *data,
123 void *userdata) {
124
125 ResolveSupport *resolve = data;
126 int k;
127
128 assert(filename);
129 assert(lvalue);
130 assert(rvalue);
131 assert(resolve);
132
133 /* Our enum shall be a superset of booleans, hence first try
134 * to parse as boolean, and then as enum */
135
136 k = parse_boolean(rvalue);
137 if (k > 0)
138 *resolve = RESOLVE_SUPPORT_YES;
139 else if (k == 0)
140 *resolve = RESOLVE_SUPPORT_NO;
141 else {
142 ResolveSupport s;
143
144 s = resolve_support_from_string(rvalue);
145 if (s < 0){
146 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse %s= option, ignoring: %s", lvalue, rvalue);
147 return 0;
148 }
149
150 *resolve = s;
151 }
152
153 return 0;
154 }