]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-util.c
Merge pull request #2222 from snakeroot/eventsplat
[thirdparty/systemd.git] / src / network / networkd-util.c
CommitLineData
fc2f9534
LP
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
fc2f9534 22#include "conf-parser.h"
fc2f9534 23#include "networkd-util.h"
6bedfcbb 24#include "parse-util.h"
8b43440b 25#include "string-table.h"
07630cea
LP
26#include "string-util.h"
27#include "util.h"
fc2f9534
LP
28
29const 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
42AddressFamilyBoolean 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
61DEFINE_CONFIG_PARSE_ENUM(config_parse_address_family_boolean, address_family_boolean, AddressFamilyBoolean, "Failed to parse option");
62
63int 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
765afd5c
LP
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
fc2f9534
LP
90 s = address_family_boolean_from_string(rvalue);
91 if (s < 0) {
92 if (streq(rvalue, "kernel"))
765afd5c 93 s = ADDRESS_FAMILY_NO;
fc2f9534 94 else {
85e070c2 95 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IPForward= option, ignoring: %s", rvalue);
fc2f9534
LP
96 return 0;
97 }
98 }
99
100 *fwd = s;
101
102 return 0;
103}