networkd-address.c revision 407fe036a24834203aca6c1eec7d74d9ad3e9ee0
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering/***
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering This file is part of systemd.
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering Copyright 2013 Tom Gundersen <teg@jklm.no>
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering systemd is free software; you can redistribute it and/or modify it
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering under the terms of the GNU Lesser General Public License as published by
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering (at your option) any later version.
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering systemd is distributed in the hope that it will be useful, but
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering Lesser General Public License for more details.
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering You should have received a copy of the GNU Lesser General Public License
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering***/
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering#include <net/if.h>
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering#include "networkd.h"
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering#include "utf8.h"
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering#include "util.h"
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering#include "conf-parser.h"
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering#include "net-util.h"
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poetteringint address_new(Network *network, unsigned section, Address **ret) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering _cleanup_address_free_ Address *address = NULL;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (section) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering uint64_t key = section;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering address = hashmap_get(network->addresses_by_section, &key);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (address) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering *ret = address;
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering address = NULL;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return 0;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering }
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering }
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering address = new0(Address, 1);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (!address)
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return -ENOMEM;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering address->network = network;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering LIST_PREPEND(addresses, network->addresses, address);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (section) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering address->section = section;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering hashmap_put(network->addresses_by_section, &address->section, address);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering }
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering *ret = address;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering address = NULL;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return 0;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering}
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poetteringvoid address_free(Address *address) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (!address)
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering LIST_REMOVE(addresses, address->network->addresses, address);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (address->section)
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering hashmap_remove(address->network->addresses_by_section,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering &address->section);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering free(address);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering}
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poetteringint address_drop(Address *address, Link *link,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering sd_rtnl_message_handler_t callback) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering int r;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(address);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(address->family == AF_INET || address->family == AF_INET6);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(link);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(link->ifindex > 0);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(link->manager);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(link->manager->rtnl);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering r = sd_rtnl_message_addr_new(RTM_DELADDR, link->ifindex,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering address->family, address->prefixlen, 0, 0, &req);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (r < 0) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering log_error("Could not allocate RTM_DELADDR message: %s",
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering strerror(-r));
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering return r;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering }
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (address->family == AF_INET)
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering else if (address->family == AF_INET6)
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (r < 0) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering log_error("Could not append IFA_LOCAL attribute: %s",
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering strerror(-r));
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering return r;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering }
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (r < 0) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering log_error("Could not send rtnetlink message: %s", strerror(-r));
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering return r;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering }
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering return 0;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering}
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poetteringint address_configure(Address *address, Link *link,
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering sd_rtnl_message_handler_t callback) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering int r;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering assert(address);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering assert(address->family == AF_INET || address->family == AF_INET6);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering assert(link);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering assert(link->ifindex > 0);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering assert(link->manager);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering assert(link->manager->rtnl);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering r = sd_rtnl_message_addr_new(RTM_NEWADDR, link->ifindex,
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering address->family, address->prefixlen,
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering IFA_F_PERMANENT, RT_SCOPE_UNIVERSE, &req);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (r < 0) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering log_error("Could not allocate RTM_NEWADDR message: %s",
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering strerror(-r));
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering return r;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering }
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (address->family == AF_INET)
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering else if (address->family == AF_INET6)
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (r < 0) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering log_error("Could not append IFA_LOCAL attribute: %s",
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering strerror(-r));
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering return r;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering }
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering if (address->family == AF_INET) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering struct in_addr broadcast;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering broadcast.s_addr = address->in_addr.in.s_addr | address->netmask.s_addr;
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &broadcast);
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering if (r < 0) {
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering log_error("Could not append IFA_BROADCAST attribute: %s",
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering strerror(-r));
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering return r;
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering }
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering }
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering if (address->label) {
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label);
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering if (r < 0) {
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering log_error("Could not append IFA_LABEL attribute: %s",
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering strerror(-r));
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering return r;
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering }
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering }
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering if (r < 0) {
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering log_error("Could not send rtnetlink message: %s", strerror(-r));
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering return r;
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering }
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering return 0;
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering}
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poetteringint config_parse_address(const char *unit,
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering const char *filename,
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering unsigned line,
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering const char *section,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering unsigned section_line,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering const char *lvalue,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering int ltype,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering const char *rvalue,
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering void *data,
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering void *userdata) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering Network *network = userdata;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering _cleanup_address_free_ Address *n = NULL;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering _cleanup_free_ char *address = NULL;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering const char *e;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering int r;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(filename);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(section);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(lvalue);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(rvalue);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(data);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (streq(section, "Network")) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering /* we are not in an Address section, so treat
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering * this as the special '0' section */
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering section_line = 0;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering }
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering r = address_new(network, section_line, &n);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (r < 0)
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return r;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering /* Address=address/prefixlen */
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering /* prefixlen */
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering e = strchr(rvalue, '/');
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (e) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering unsigned i;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering r = safe_atou(e + 1, &i);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (r < 0) {
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, EINVAL,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering "Interface prefix length is invalid, "
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering "ignoring assignment: %s", e + 1);
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering return 0;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering }
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering n->prefixlen = (unsigned char) i;
ab1525bc2d92780b4dc64bc5b9cdb52594e2df7dLennart Poettering n->netmask.s_addr = htonl(0xfffffffflu >> n->prefixlen);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering address = strndup(rvalue, e - rvalue);
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering if (!address)
df3fb561b2df486a495a5f0bcc83168bd1860533Lennart Poettering return log_oom();
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering } else {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering address = strdup(rvalue);
d6731e4c7964ee2860d4f5abdb0b52acd7a66960Tom Gundersen if (!address)
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering return log_oom();
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering }
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering r = net_parse_inaddr(address, &n->family, &n->in_addr);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (r < 0) {
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering log_syntax(unit, LOG_ERR, filename, line, EINVAL,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering "Address is invalid, ignoring assignment: %s", address);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return 0;
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering }
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering n = NULL;
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering return 0;
d57c365bf8f09fbcc649e00f7060ff30809f67c2Lennart Poettering}
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poetteringint config_parse_label(const char *unit,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering const char *filename,
6d0c65ffb4f82e8c6dceb453919b3db54343fc27Lennart Poettering unsigned line,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering const char *section,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering unsigned section_line,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering const char *lvalue,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering int ltype,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering const char *rvalue,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering void *data,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering void *userdata) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering Network *network = userdata;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering _cleanup_address_free_ Address *n = NULL;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering char *label;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering int r;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(filename);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(section);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(lvalue);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(rvalue);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering assert(data);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering r = address_new(network, section_line, &n);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (r < 0)
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return r;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering label = strdup(rvalue);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (!label)
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return log_oom();
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (!ascii_is_valid(label) || strlen(label) >= IFNAMSIZ) {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering log_syntax(unit, LOG_ERR, filename, line, EINVAL,
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering "Interface label is not ASCII clean or is too"
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering " long, ignoring assignment: %s", rvalue);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering free(label);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering return 0;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering }
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering free(n->label);
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering if (*label)
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering n->label = label;
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering else {
ee8c45689526ca973407cbb77bce7b96a062c40bLennart Poettering free(label);
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering n->label = NULL;
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering }
ab1525bc2d92780b4dc64bc5b9cdb52594e2df7dLennart Poettering
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering n = NULL;
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering return 0;
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering}
9085f64a6694f2928c79fcce365edb1dca6937d4Lennart Poettering