networkd-address.c revision 6666907869fb3bc7fe6a6025540db5b887c7a78b
/*-*- 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 "conf-parser.h"
#include "firewall-util.h"
#include "netlink-util.h"
#include "set.h"
#include "utf8.h"
#include "util.h"
#include "networkd.h"
#include "networkd-address.h"
if (!address)
return -ENOMEM;
return 0;
}
int r;
if (section) {
if (address) {
return 0;
}
}
r = address_new(&address);
if (r < 0)
return r;
if (section) {
}
return 0;
}
if (!address)
return;
}
}
const Address *a = b;
assert(a);
switch (a->family) {
case AF_INET:
/* peer prefix */
if (a->prefixlen != 0) {
else
}
/* fallthrough */
case AF_INET6:
/* local address */
break;
default:
/* treat any other address family as AF_UNSPEC */
break;
}
}
return -1;
return 1;
/* use the same notion of equality as the kernel does */
case AF_INET:
return -1;
return 1;
/* compare the peer prefixes */
/* make sure we don't try to shift by 32.
else
else
return -1;
return 1;
}
/* fall-through */
case AF_INET6:
default:
/* treat any other address family as AF_UNSPEC */
return 0;
}
}
static const struct hash_ops address_hash_ops = {
};
return true;
return false;
}
bool masq;
int r;
/* Add firewall entry if this is requested */
if (r < 0)
}
return 0;
}
int address_add(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) {
int r;
r = address_new(&address);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
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 address_update(Address *address, unsigned char flags, unsigned char scope, struct ifa_cacheinfo *cinfo) {
bool ready;
return 0;
}
bool ready;
return 0;
}
int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) {
if (!existing)
return -ENOENT;
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;
}
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(&na);
if (r < 0)
return r;
return -ENOMEM;
}
return 0;
}
int address_configure(Address *address, Link *link, sd_netlink_message_handler_t callback, bool update) {
int r;
if (r < 0)
return r;
if (update)
else
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;
log_syntax(unit, LOG_ERR, filename, line, 0, "Broadcast is not valid for IPv6 addresses, ignoring assignment: %s", rvalue);
return 0;
}
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "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) {
log_syntax(unit, LOG_ERR, filename, line, r, "Prefix length is invalid, ignoring assignment: %s", e + 1);
return 0;
}
n->prefixlen = (unsigned char) i;
} else
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Address is invalid, ignoring assignment: %s", address);
return 0;
}
if (!e && f == AF_INET) {
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Prefix length not specified, and a default one can not be deduced for '%s', ignoring assignment", address);
return 0;
}
}
log_syntax(unit, LOG_ERR, filename, line, 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();
log_syntax(unit, LOG_ERR, filename, line, 0, "Interface label is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
return 0;
}
if (*label)
else {
}
n = NULL;
return 0;
}
bool address_is_ready(const Address *a) {
assert(a);
}