mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-05 09:17:44 +03:00
Merge pull request #21664 from yuwata/network-tunnel-cleanups
network: several cleanups for tunnel device
This commit is contained in:
commit
dc79ae23fb
@ -19,7 +19,7 @@
|
||||
#include "tunnel.h"
|
||||
#include "util.h"
|
||||
|
||||
#define DEFAULT_TNL_HOP_LIMIT 64
|
||||
#define DEFAULT_IPV6_TTL 64
|
||||
#define IP6_FLOWINFO_FLOWLABEL htobe32(0x000FFFFF)
|
||||
#define IP6_TNL_F_ALLOW_LOCAL_REMOTE 0x40
|
||||
|
||||
@ -177,13 +177,13 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_IPIP)
|
||||
t = IPIP(netdev);
|
||||
else
|
||||
t = SIT(netdev);
|
||||
|
||||
assert(m);
|
||||
assert(t);
|
||||
|
||||
if (link || t->assign_to_loopback) {
|
||||
@ -375,6 +375,7 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_IP6GRE)
|
||||
t = IP6GRE(netdev);
|
||||
@ -382,7 +383,6 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
t = IP6GRETAP(netdev);
|
||||
|
||||
assert(t);
|
||||
assert(m);
|
||||
|
||||
if (link || t->assign_to_loopback) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
|
||||
@ -495,12 +495,15 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink
|
||||
}
|
||||
|
||||
static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
Tunnel *t = IP6TNL(netdev);
|
||||
uint8_t proto;
|
||||
Tunnel *t;
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
|
||||
t = IP6TNL(netdev);
|
||||
|
||||
assert(t);
|
||||
|
||||
if (link || t->assign_to_loopback) {
|
||||
@ -564,45 +567,12 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
}
|
||||
|
||||
static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
Tunnel *t = NULL;
|
||||
Tunnel *t;
|
||||
|
||||
assert(netdev);
|
||||
assert(filename);
|
||||
|
||||
switch (netdev->kind) {
|
||||
case NETDEV_KIND_IPIP:
|
||||
t = IPIP(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_SIT:
|
||||
t = SIT(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_GRE:
|
||||
t = GRE(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_GRETAP:
|
||||
t = GRETAP(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_IP6GRE:
|
||||
t = IP6GRE(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_IP6GRETAP:
|
||||
t = IP6GRETAP(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_VTI:
|
||||
t = VTI(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_VTI6:
|
||||
t = VTI6(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_IP6TNL:
|
||||
t = IP6TNL(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_ERSPAN:
|
||||
t = ERSPAN(netdev);
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
t = TUNNEL(netdev);
|
||||
|
||||
assert(t);
|
||||
|
||||
@ -642,6 +612,9 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
if (netdev->kind == NETDEV_KIND_VTI)
|
||||
t->family = AF_INET;
|
||||
|
||||
if (t->assign_to_loopback)
|
||||
t->independent = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -862,101 +835,31 @@ int config_parse_6rd_prefix(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipip_sit_init(NetDev *n) {
|
||||
static void netdev_tunnel_init(NetDev *netdev) {
|
||||
Tunnel *t;
|
||||
|
||||
assert(n);
|
||||
assert(netdev);
|
||||
|
||||
switch (n->kind) {
|
||||
case NETDEV_KIND_IPIP:
|
||||
t = IPIP(n);
|
||||
break;
|
||||
case NETDEV_KIND_SIT:
|
||||
t = SIT(n);
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
t = TUNNEL(netdev);
|
||||
|
||||
assert(t);
|
||||
|
||||
t->pmtudisc = true;
|
||||
t->fou_encap_type = NETDEV_FOO_OVER_UDP_ENCAP_DIRECT;
|
||||
t->isatap = -1;
|
||||
}
|
||||
|
||||
static void vti_init(NetDev *n) {
|
||||
Tunnel *t;
|
||||
|
||||
assert(n);
|
||||
|
||||
if (n->kind == NETDEV_KIND_VTI)
|
||||
t = VTI(n);
|
||||
else
|
||||
t = VTI6(n);
|
||||
|
||||
assert(t);
|
||||
|
||||
t->pmtudisc = true;
|
||||
}
|
||||
|
||||
static void gre_erspan_init(NetDev *n) {
|
||||
Tunnel *t;
|
||||
|
||||
assert(n);
|
||||
|
||||
switch (n->kind) {
|
||||
case NETDEV_KIND_GRE:
|
||||
t = GRE(n);
|
||||
break;
|
||||
case NETDEV_KIND_ERSPAN:
|
||||
t = ERSPAN(n);
|
||||
break;
|
||||
case NETDEV_KIND_GRETAP:
|
||||
t = GRETAP(n);
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
assert(t);
|
||||
|
||||
t->pmtudisc = true;
|
||||
t->gre_erspan_sequence = -1;
|
||||
t->fou_encap_type = NETDEV_FOO_OVER_UDP_ENCAP_DIRECT;
|
||||
}
|
||||
|
||||
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) {
|
||||
Tunnel *t = IP6TNL(n);
|
||||
|
||||
assert(n);
|
||||
assert(t);
|
||||
|
||||
t->ttl = DEFAULT_TNL_HOP_LIMIT;
|
||||
t->encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
|
||||
t->ip6tnl_mode = _NETDEV_IP6_TNL_MODE_INVALID;
|
||||
t->ipv6_flowlabel = _NETDEV_IPV6_FLOWLABEL_INVALID;
|
||||
t->allow_localremote = -1;
|
||||
|
||||
if (IN_SET(netdev->kind, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP, NETDEV_KIND_IP6TNL))
|
||||
t->ttl = DEFAULT_IPV6_TTL;
|
||||
}
|
||||
|
||||
const NetDevVTable ipip_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = ipip_sit_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ipip_sit_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -966,7 +869,7 @@ const NetDevVTable ipip_vtable = {
|
||||
|
||||
const NetDevVTable sit_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = ipip_sit_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ipip_sit_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -976,7 +879,7 @@ const NetDevVTable sit_vtable = {
|
||||
|
||||
const NetDevVTable vti_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = vti_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_vti_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -986,7 +889,7 @@ const NetDevVTable vti_vtable = {
|
||||
|
||||
const NetDevVTable vti6_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = vti_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_vti_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -996,7 +899,7 @@ const NetDevVTable vti6_vtable = {
|
||||
|
||||
const NetDevVTable gre_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = gre_erspan_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_gre_erspan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -1006,7 +909,7 @@ const NetDevVTable gre_vtable = {
|
||||
|
||||
const NetDevVTable gretap_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = gre_erspan_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_gre_erspan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -1017,7 +920,7 @@ const NetDevVTable gretap_vtable = {
|
||||
|
||||
const NetDevVTable ip6gre_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = ip6gre_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ip6gre_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -1027,7 +930,7 @@ const NetDevVTable ip6gre_vtable = {
|
||||
|
||||
const NetDevVTable ip6gretap_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = ip6gre_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ip6gre_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -1038,7 +941,7 @@ const NetDevVTable ip6gretap_vtable = {
|
||||
|
||||
const NetDevVTable ip6tnl_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = ip6tnl_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ip6tnl_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
@ -1048,7 +951,7 @@ const NetDevVTable ip6tnl_vtable = {
|
||||
|
||||
const NetDevVTable erspan_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = gre_erspan_init,
|
||||
.init = netdev_tunnel_init,
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_gre_erspan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
|
@ -74,6 +74,36 @@ DEFINE_NETDEV_CAST(VTI, Tunnel);
|
||||
DEFINE_NETDEV_CAST(VTI6, Tunnel);
|
||||
DEFINE_NETDEV_CAST(IP6TNL, Tunnel);
|
||||
DEFINE_NETDEV_CAST(ERSPAN, Tunnel);
|
||||
|
||||
static inline Tunnel* TUNNEL(NetDev *netdev) {
|
||||
assert(netdev);
|
||||
|
||||
switch (netdev->kind) {
|
||||
case NETDEV_KIND_IPIP:
|
||||
return IPIP(netdev);
|
||||
case NETDEV_KIND_SIT:
|
||||
return SIT(netdev);
|
||||
case NETDEV_KIND_GRE:
|
||||
return GRE(netdev);
|
||||
case NETDEV_KIND_GRETAP:
|
||||
return GRETAP(netdev);
|
||||
case NETDEV_KIND_IP6GRE:
|
||||
return IP6GRE(netdev);
|
||||
case NETDEV_KIND_IP6GRETAP:
|
||||
return IP6GRETAP(netdev);
|
||||
case NETDEV_KIND_VTI:
|
||||
return VTI(netdev);
|
||||
case NETDEV_KIND_VTI6:
|
||||
return VTI6(netdev);
|
||||
case NETDEV_KIND_IP6TNL:
|
||||
return IP6TNL(netdev);
|
||||
case NETDEV_KIND_ERSPAN:
|
||||
return ERSPAN(netdev);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern const NetDevVTable ipip_vtable;
|
||||
extern const NetDevVTable sit_vtable;
|
||||
extern const NetDevVTable vti_vtable;
|
||||
|
Loading…
Reference in New Issue
Block a user