fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering/***
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering This file is part of systemd.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering Copyright 2013 Tom Gundersen <teg@jklm.no>
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering systemd is free software; you can redistribute it and/or modify it
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering under the terms of the GNU Lesser General Public License as published by
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering (at your option) any later version.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering systemd is distributed in the hope that it will be useful, but
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering Lesser General Public License for more details.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering You should have received a copy of the GNU Lesser General Public License
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering***/
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#include "conf-parser.h"
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering#include "networkd-util.h"
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering#include "parse-util.h"
8b43440b7ef4b81c69c31de7ff820dc07a780254Lennart Poettering#include "string-table.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "string-util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "util.h"
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringconst char *address_family_boolean_to_string(AddressFamilyBoolean b) {
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (b == ADDRESS_FAMILY_YES ||
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering b == ADDRESS_FAMILY_NO)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return yes_no(b == ADDRESS_FAMILY_YES);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (b == ADDRESS_FAMILY_IPV4)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return "ipv4";
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (b == ADDRESS_FAMILY_IPV6)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return "ipv6";
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return NULL;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering}
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart PoetteringAddressFamilyBoolean address_family_boolean_from_string(const char *s) {
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering int r;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering /* Make this a true superset of a boolean */
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering r = parse_boolean(s);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (r > 0)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return ADDRESS_FAMILY_YES;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (r == 0)
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return ADDRESS_FAMILY_NO;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (streq(s, "ipv4"))
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return ADDRESS_FAMILY_IPV4;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (streq(s, "ipv6"))
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return ADDRESS_FAMILY_IPV6;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return _ADDRESS_FAMILY_BOOLEAN_INVALID;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering}
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart PoetteringDEFINE_CONFIG_PARSE_ENUM(config_parse_address_family_boolean, address_family_boolean, AddressFamilyBoolean, "Failed to parse option");
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poetteringint config_parse_address_family_boolean_with_kernel(
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering const char* unit,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering const char *filename,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering unsigned line,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering const char *section,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering unsigned section_line,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering const char *lvalue,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering int ltype,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering const char *rvalue,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering void *data,
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering void *userdata) {
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering AddressFamilyBoolean *fwd = data, s;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering assert(filename);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering assert(lvalue);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering assert(rvalue);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering assert(data);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering /* This function is mostly obsolete now. It simply redirects
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering * "kernel" to "no". In older networkd versions we used to
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering * distuingish IPForward=off from IPForward=kernel, where the
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering * former would explicitly turn off forwarding while the
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering * latter would simply not touch the setting. But that logic
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering * is gone, hence silently accept the old setting, but turn it
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering * to "no". */
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering s = address_family_boolean_from_string(rvalue);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (s < 0) {
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering if (streq(rvalue, "kernel"))
765afd5c4dbc71940d6dd6007ecc3eaa5a0b2aa1Lennart Poettering s = ADDRESS_FAMILY_NO;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering else {
85e070c2b3f66d838c11f8f008106b9e42c9afafMichal Sekletar log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IPForward= option, ignoring: %s", rvalue);
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return 0;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering }
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering }
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering *fwd = s;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering return 0;
fc2f9534d07db2b185c02b1961428b53daf1986eLennart Poettering}