networkd-netdev-tunnel.c revision 8b43440b7ef4b81c69c31de7ff820dc07a780254
/*-*- 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-netlink.h"
#include "conf-parser.h"
#include "missing.h"
#include "networkd-link.h"
#include "networkd-netdev-tunnel.h"
#include "parse-util.h"
#include "string-table.h"
#include "string-util.h"
#include "util.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] = "ipip6",
[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)
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
return r;
}
int r;
assert(m);
assert(t);
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
return r;
}
Tunnel *t;
int r;
else
assert(t);
assert(m);
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
return r;
}
Tunnel *t;
int r;
else
assert(t);
assert(m);
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) {
if (r < 0)
}
if (r < 0)
return r;
}
int r;
assert(m);
assert(t);
if (r < 0)
if (r < 0)
if (r < 0)
return r;
}
int r;
assert(m);
assert(t);
if (r < 0)
if (r < 0)
if (r < 0)
return r;
}
int r;
assert(m);
assert(t);
if (r < 0)
if (r < 0)
if (r < 0)
if (r < 0)
if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) {
if (r < 0)
}
if (t->copy_dscp)
t->flags |= IP6_TNL_F_RCV_DSCP_COPY;
if (t->encap_limit != IPV6_DEFAULT_TNL_ENCAP_LIMIT) {
if (r < 0)
}
if (r < 0)
switch (t->ip6tnl_mode) {
break;
break;
default:
proto = 0;
break;
}
if (r < 0)
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_VTI6:
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, r, "Tunnel address is invalid, ignoring assignment: %s", rvalue);
return 0;
}
log_syntax(unit, LOG_ERR, filename, line, 0, "Tunnel addresses incompatible, ignoring assignment: %s", rvalue);
return 0;
}
t->family = f;
return 0;
}
int config_parse_ipv6_flowlabel(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 k = 0;
int r;
} else {
r = config_parse_int(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &k, userdata);
if (r < 0)
return r;
if (k > 0xFFFFF)
log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IPv6 flowlabel option, ignoring: %s", rvalue);
else {
t->flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL;
}
}
return 0;
}
int config_parse_encap_limit(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 k = 0;
int r;
t->flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
else {
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse Tunnel Encapsulation Limit option, ignoring: %s", rvalue);
return 0;
}
if (k > 255 || k < 0)
log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid Tunnel Encapsulation value, ignoring: %d", k);
else {
t->encap_limit = k;
t->flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
}
}
return 0;
}
assert(n);
assert(t);
t->pmtudisc = true;
}
assert(n);
assert(t);
t->pmtudisc = true;
}
Tunnel *t;
assert(n);
if (n->kind == NETDEV_KIND_VTI)
t = VTI(n);
else
t = VTI6(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 vti6_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",
};