networkd-route.c revision 07630cea1f3a845c09309f197ac7c4f11edd3b62
/*-*- 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 "in-addr-util.h"
#include "netlink-util.h"
#include "networkd.h"
#include "string-util.h"
#include "util.h"
#include "networkd-route.h"
if (!route)
return -ENOMEM;
return 0;
}
int r;
if (section) {
if (route) {
return 0;
}
}
if (r < 0)
return r;
if (section) {
}
return 0;
}
if (!route)
return;
}
}
case AF_INET:
case AF_INET6:
/* Equality of routes are given by the 4-touple
(dst_prefix,dst_prefixlen,tos,priority,table) */
break;
default:
/* treat any other address family as AF_UNSPEC */
break;
}
}
return -1;
return 1;
switch (a->family) {
case AF_INET:
case AF_INET6:
//TODO: check IPv6 routes
if (a->dst_prefixlen < b->dst_prefixlen)
return -1;
if (a->dst_prefixlen > b->dst_prefixlen)
return 1;
return -1;
return 1;
return -1;
return 1;
return -1;
return 1;
default:
/* treat any other address family as AF_UNSPEC */
return 0;
}
}
static const struct hash_ops route_hash_ops = {
.hash = route_hash_func,
};
int r;
if (r < 0)
return log_error_errno(r, "Could not create RTM_DELROUTE message: %m");
if (r < 0)
return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
}
if (route->dst_prefixlen) {
if (r < 0)
return log_error_errno(r, "Could not append RTA_DST attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not set destination prefix length: %m");
}
if (route->src_prefixlen) {
if (r < 0)
return log_error_errno(r, "Could not append RTA_DST attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not set source prefix length: %m");
}
if (r < 0)
return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %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 RTA_PRIORITY attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not append RTA_OIF 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 create RTM_NEWROUTE message: %m");
if (r < 0)
return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
}
if (route->dst_prefixlen) {
if (r < 0)
return log_error_errno(r, "Could not append RTA_DST attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not set destination prefix length: %m");
}
if (route->src_prefixlen) {
if (r < 0)
return log_error_errno(r, "Could not append RTA_SRC attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not set source prefix length: %m");
}
if (r < 0)
return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %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 RTA_PRIORITY attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not append RTA_OIF attribute: %m");
if (r < 0)
return log_error_errno(r, "Could not send rtnetlink message: %m");
return 0;
}
int config_parse_gateway(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) {
union in_addr_union buffer;
int r, f;
/* we are not in an Route section, so treat
* this as the special '0' section */
section_line = 0;
}
if (r < 0)
return r;
if (r < 0) {
return 0;
}
n->family = f;
n = NULL;
return 0;
}
int config_parse_preferred_src(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) {
union in_addr_union buffer;
int r, f;
if (r < 0)
return r;
if (r < 0) {
"Preferred source is invalid, ignoring assignment: %s", rvalue);
return 0;
}
n->family = f;
n->prefsrc_addr = buffer;
n = NULL;
return 0;
}
int config_parse_destination(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;
unsigned char prefixlen;
int r, f;
if (r < 0)
return r;
/* address */
if (e)
else
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Destination is invalid, ignoring assignment: %s", address);
return 0;
}
log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown address family, ignoring assignment: %s", address);
return 0;
}
/* prefixlen */
if (e) {
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Route destination prefix length is invalid, ignoring assignment: %s", e + 1);
return 0;
}
} else {
switch (f) {
case AF_INET:
prefixlen = 32;
break;
case AF_INET6:
prefixlen = 128;
break;
}
}
n->family = f;
n->dst_prefixlen = prefixlen;
n->src_prefixlen = prefixlen;
} else
n = NULL;
return 0;
}
int config_parse_route_priority(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;
if (r < 0)
return r;
n = NULL;
return 0;
}
int config_parse_route_scope(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;
n->scope = RT_SCOPE_HOST;
n->scope = RT_SCOPE_LINK;
n->scope = RT_SCOPE_UNIVERSE;
else {
return 0;
}
n = NULL;
return 0;
}