networkd-netdev-tunnel.c revision b16492f86f13abd4a9447afd0910139af9656906
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Susant Sahani
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 <linux/if_tunnel.h>
#include <linux/ip6_tunnel.h>
#include "sd-rtnl.h"
#include "networkd-netdev-tunnel.h"
#include "networkd-link.h"
#include "network-internal.h"
#include "util.h"
#include "missing.h"
#include "conf-parser.h"
#define DEFAULT_TNL_HOP_LIMIT 64
static const char* const ip6tnl_mode_table[_NETDEV_IP6_TNL_MODE_MAX] = {
[NETDEV_IP6_TNL_MODE_IP6IP6] = "ip6ip6",
[NETDEV_IP6_TNL_MODE_IPIP6] = "ip4ipv6",
[NETDEV_IP6_TNL_MODE_ANYIP6] = "any",
};
DEFINE_CONFIG_PARSE_ENUM(config_parse_ip6tnl_mode, ip6tnl_mode, Ip6TnlMode, "Failed to parse ip6 tunnel Mode");
int r;
assert(m);
assert(t);
if (r < 0) {
"Could not append IFLA_IPTUN_LINK attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_TTL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_PMTUDISC attribute: %s",
strerror(-r));
return r;
}
return r;
}
int r;
assert(m);
assert(t);
if (r < 0) {
"Could not append IFLA_IPTUN_LINK attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_TTL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_PMTUDISC attribute: %s",
strerror(-r));
return r;
}
return r;
}
Tunnel *t;
int r;
else
assert(t);
assert(m);
if (r < 0) {
"Could not append IFLA_GRE_LINK attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_LOCAL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_REMOTE attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_TTL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_TOS attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_PMTUDISC attribute: %s",
strerror(-r));
return r;
}
return r;
}
Tunnel *t;
int r;
else
assert(t);
assert(m);
if (r < 0) {
"Could not append IFLA_GRE_LINK attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_LOCAL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_REMOTE attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_GRE_TTL attribute: %s",
strerror(-r));
return r;
}
return r;
}
int r;
assert(m);
assert(t);
if (r < 0) {
"Could not append IFLA_IPTUN_LINK attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
strerror(-r));
return r;
}
return r;
}
int r;
assert(m);
assert(t);
if (r < 0) {
"Could not append IFLA_IPTUN_LINK attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_LOCAL attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_REMOTE attribute: %s",
strerror(-r));
return r;
}
if (r < 0) {
"Could not append IFLA_IPTUN_TTL attribute: %s",
strerror(-r));
return r;
}
switch (t->ip6tnl_mode) {
break;
break;
default:
proto = 0;
break;
}
if (r < 0) {
"Could not append IFLA_IPTUN_MODE attribute: %s",
strerror(-r));
return r;
}
return r;
}
case NETDEV_KIND_IPIP:
break;
case NETDEV_KIND_SIT:
break;
case NETDEV_KIND_GRE:
break;
case NETDEV_KIND_GRETAP:
break;
case NETDEV_KIND_IP6GRE:
break;
case NETDEV_KIND_IP6GRETAP:
break;
case NETDEV_KIND_VTI:
break;
case NETDEV_KIND_IP6TNL:
break;
default:
assert_not_reached("Invalid tunnel kind");
}
assert(t);
return -EINVAL;
}
return -EINVAL;
}
if (t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID) {
return -EINVAL;
}
}
return 0;
}
int config_parse_tunnel_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) {
int r, f;
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Tunnel address is invalid, ignoring assignment: %s", rvalue);
return 0;
}
log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Tunnel addresses incompatible, ignoring assignment: %s", rvalue);
return 0;
}
t->family = f;
return 0;
}
assert(n);
assert(t);
t->pmtudisc = true;
}
assert(n);
assert(t);
t->pmtudisc = true;
}
assert(n);
assert(t);
t->pmtudisc = true;
}
Tunnel *t;
assert(n);
if (n->kind == NETDEV_KIND_GRE)
t = GRE(n);
else
t = GRETAP(n);
assert(t);
t->pmtudisc = true;
}
static void ip6gre_init(NetDev *n) {
Tunnel *t;
assert(n);
if (n->kind == NETDEV_KIND_IP6GRE)
t = IP6GRE(n);
else
t = IP6GRETAP(n);
assert(t);
t->ttl = DEFAULT_TNL_HOP_LIMIT;
}
static void ip6tnl_init(NetDev *n) {
assert(n);
assert(t);
t->ttl = DEFAULT_TNL_HOP_LIMIT;
}
const NetDevVTable ipip_vtable = {
.object_size = sizeof(Tunnel),
.sections = "Match\0NetDev\0Tunnel\0",
};
const NetDevVTable sit_vtable = {
.object_size = sizeof(Tunnel),
.sections = "Match\0NetDev\0Tunnel\0",
};
const NetDevVTable vti_vtable = {
.object_size = sizeof(Tunnel),
.sections = "Match\0NetDev\0Tunnel\0",
};
const NetDevVTable gre_vtable = {
.object_size = sizeof(Tunnel),
.sections = "Match\0NetDev\0Tunnel\0",
};
const NetDevVTable gretap_vtable = {
.object_size = sizeof(Tunnel),
.sections = "Match\0NetDev\0Tunnel\0",
};
const NetDevVTable ip6gre_vtable = {
.object_size = sizeof(Tunnel),
.init = ip6gre_init,
.sections = "Match\0NetDev\0Tunnel\0",
};
const NetDevVTable ip6gretap_vtable = {
.object_size = sizeof(Tunnel),
.init = ip6gre_init,
.sections = "Match\0NetDev\0Tunnel\0",
};
const NetDevVTable ip6tnl_vtable = {
.object_size = sizeof(Tunnel),
.init = ip6tnl_init,
.sections = "Match\0NetDev\0Tunnel\0",
};