networkd-address.c revision fc2f9534d07db2b185c02b1961428b53daf1986e
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Tom Gundersen <teg@jklm.no>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "utf8.h"
#include "util.h"
#include "conf-parser.h"
#include "firewall-util.h"
#include "netlink-util.h"
#include "networkd.h"
#include "networkd-address.h"
}
if (section) {
if (address) {
return 0;
}
}
if (!address)
return -ENOMEM;
if (section) {
}
return 0;
}
if (!address)
return -ENOMEM;
return 0;
}
if (!address)
return;
}
}
bool masq;
int r;
/* Add firewall entry if this is requested */
if (r < 0)
}
return 0;
}
int r;
/* Remove masquerading firewall entry if it was added */
if (address->ip_masquerade_done) {
if (r < 0)
address->ip_masquerade_done = false;
}
return 0;
}
int r;
if (r < 0)
return log_error_errno(r, "Could not allocate RTM_DELADDR message: %m");
if (r < 0)
return log_error_errno(r, "Could not set prefixlen: %m");
if (r < 0)
return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
return 0;
}
int r;
if (r < 0)
return log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m");
if (r < 0)
return log_error_errno(r, "Could not set prefixlen: %m");
if (r < 0)
return log_error_errno(r, "Could not set flags: %m");
if (r < 0)
return log_error_errno(r, "Could not set extended flags: %m");
}
if (r < 0)
return log_error_errno(r, "Could not set scope: %m");
if (r < 0)
return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m");
}
if (r < 0)
return log_error_errno(r, "Could not append IFA_LABEL attribute: %m");
}
if (r < 0)
return log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
return 0;
}
union in_addr_union in_addr = {};
int r;
/* Something useful was configured? just use it */
return 0;
/* The address is configured to be 0.0.0.0 or [::] by the user?
* Then let's acquire something more useful from the pool. */
if (r < 0)
if (r == 0) {
return -EBUSY;
}
/* Pick first address in range for ourselves ... */
/* .. and use last as broadcast address */
r = address_new_dynamic(&na);
if (r < 0)
return r;
return -ENOMEM;
}
return 0;
}
int r;
if (r < 0)
return r;
if (r < 0)
return log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m");
if (r < 0)
return log_error_errno(r, "Could not set prefixlen: %m");
if (r < 0)
return log_error_errno(r, "Could not set flags: %m");
if (r < 0)
return log_error_errno(r, "Could not set extended flags: %m");
}
if (r < 0)
return log_error_errno(r, "Could not set scope: %m");
if (r < 0)
return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not append IFA_ADDRESS attribute: %m");
} else {
if (r < 0)
return log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m");
}
}
if (r < 0)
return log_error_errno(r, "Could not append IFA_LABEL attribute: %m");
}
if (r < 0)
return log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
return 0;
}
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
int r;
if (r < 0)
return r;
"Broadcast is not valid for IPv6 addresses, ignoring assignment: %s", rvalue);
return 0;
}
if (r < 0) {
"Broadcast is invalid, ignoring assignment: %s", rvalue);
return 0;
}
n = NULL;
return 0;
}
int config_parse_address(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
const char *address, *e;
union in_addr_union buffer;
int r, f;
/* we are not in an Address section, so treat
* this as the special '0' section */
section_line = 0;
}
if (r < 0)
return r;
/* prefixlen */
if (e) {
unsigned i;
r = safe_atou(e + 1, &i);
if (r < 0) {
"Prefix length is invalid, ignoring assignment: %s", e + 1);
return 0;
}
n->prefixlen = (unsigned char) i;
} else
if (r < 0) {
"Address is invalid, ignoring assignment: %s", address);
return 0;
}
if (!e && f == AF_INET) {
if (r < 0) {
"Prefix length not specified, and a default one can not be deduced for '%s', ignoring assignment", address);
return 0;
}
}
"Address is incompatible, ignoring assignment: %s", address);
return 0;
}
n->family = f;
else
n->in_addr_peer = buffer;
n = NULL;
return 0;
}
int config_parse_label(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
char *label;
int r;
if (r < 0)
return r;
if (!label)
return log_oom();
"Interface label is not ASCII clean or is too"
" long, ignoring assignment: %s", rvalue);
return 0;
}
if (*label)
else {
}
n = NULL;
return 0;
}
/* same object */
return true;
/* one, but not both, is NULL */
return false;
return false;
/* use the same notion of equality as the kernel does */
case AF_UNSPEC:
return true;
case AF_INET:
return false;
/* make sure we don't try to shift by 32.
return true;
else {
}
case AF_INET6: {
}
default:
assert_not_reached("Invalid address family");
}
}