Merge pull request #21648 from yuwata/network-tunnel-local-automatic-address-selection
network: tunnel: automatic local address selection
This commit is contained in:
@@ -1148,8 +1148,13 @@
|
||||
<varlistentry>
|
||||
<term><varname>Local=</varname></term>
|
||||
<listitem>
|
||||
<para>A static local address for tunneled packets. It must be an address on another interface of
|
||||
this host, or the special value <literal>any</literal>.</para>
|
||||
<para>A static local address for tunneled packets. It must be an address on another interface
|
||||
of this host, or one of the special values <literal>any</literal>,
|
||||
<literal>ipv4_link_local</literal>, <literal>ipv6_link_local</literal>,
|
||||
<literal>dhcp4</literal>, <literal>dhcp6</literal>, and <literal>slaac</literal>. If one
|
||||
of the special values except for <literal>any</literal> is specified, an address which
|
||||
matches the corresponding type on the underlying interface will be used. Defaults to
|
||||
<literal>any</literal>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
|
||||
@@ -20,6 +20,8 @@ sources = files('''
|
||||
netdev/macvlan.c
|
||||
netdev/macvlan.h
|
||||
netdev/netdev.c
|
||||
netdev/netdev-util.c
|
||||
netdev/netdev-util.h
|
||||
netdev/netdev.h
|
||||
netdev/nlmon.c
|
||||
netdev/nlmon.h
|
||||
|
||||
@@ -68,8 +68,8 @@ IPVLAN.Mode, config_parse_ipvlan_mode,
|
||||
IPVLAN.Flags, config_parse_ipvlan_flags, 0, offsetof(IPVlan, flags)
|
||||
IPVTAP.Mode, config_parse_ipvlan_mode, 0, offsetof(IPVlan, mode)
|
||||
IPVTAP.Flags, config_parse_ipvlan_flags, 0, offsetof(IPVlan, flags)
|
||||
Tunnel.Local, config_parse_tunnel_address, 0, offsetof(Tunnel, local)
|
||||
Tunnel.Remote, config_parse_tunnel_address, 0, offsetof(Tunnel, remote)
|
||||
Tunnel.Local, config_parse_tunnel_local_address, 0, 0
|
||||
Tunnel.Remote, config_parse_tunnel_remote_address, 0, 0
|
||||
Tunnel.TOS, config_parse_unsigned, 0, offsetof(Tunnel, tos)
|
||||
Tunnel.TTL, config_parse_unsigned, 0, offsetof(Tunnel, ttl)
|
||||
Tunnel.Key, config_parse_tunnel_key, 0, offsetof(Tunnel, key)
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "netdev-util.h"
|
||||
#include "networkd-address.h"
|
||||
#include "networkd-link.h"
|
||||
#include "string-table.h"
|
||||
|
||||
static const char * const netdev_local_address_type_table[_NETDEV_LOCAL_ADDRESS_TYPE_MAX] = {
|
||||
[NETDEV_LOCAL_ADDRESS_IPV4LL] = "ipv4_link_local",
|
||||
[NETDEV_LOCAL_ADDRESS_IPV6LL] = "ipv6_link_local",
|
||||
[NETDEV_LOCAL_ADDRESS_DHCP4] = "dhcp4",
|
||||
[NETDEV_LOCAL_ADDRESS_DHCP6] = "dhcp6",
|
||||
[NETDEV_LOCAL_ADDRESS_SLAAC] = "slaac",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(netdev_local_address_type, NetDevLocalAddressType);
|
||||
|
||||
int link_get_local_address(
|
||||
Link *link,
|
||||
NetDevLocalAddressType type,
|
||||
int family,
|
||||
int *ret_family,
|
||||
union in_addr_union *ret_address) {
|
||||
|
||||
Address *a;
|
||||
|
||||
assert(link);
|
||||
|
||||
switch (type) {
|
||||
case NETDEV_LOCAL_ADDRESS_IPV4LL:
|
||||
assert(IN_SET(family, AF_UNSPEC, AF_INET));
|
||||
family = AF_INET;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_IPV6LL:
|
||||
assert(IN_SET(family, AF_UNSPEC, AF_INET6));
|
||||
family = AF_INET6;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_DHCP4:
|
||||
assert(IN_SET(family, AF_UNSPEC, AF_INET));
|
||||
family = AF_INET;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_DHCP6:
|
||||
assert(IN_SET(family, AF_UNSPEC, AF_INET6));
|
||||
family = AF_INET6;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_SLAAC:
|
||||
assert(IN_SET(family, AF_UNSPEC, AF_INET6));
|
||||
family = AF_INET6;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
SET_FOREACH(a, link->addresses) {
|
||||
if (!address_exists(a))
|
||||
continue;
|
||||
|
||||
if (a->family != family)
|
||||
continue;
|
||||
|
||||
if (in_addr_is_set(a->family, &a->in_addr_peer))
|
||||
continue;
|
||||
|
||||
switch (type) {
|
||||
case NETDEV_LOCAL_ADDRESS_IPV4LL:
|
||||
if (a->source != NETWORK_CONFIG_SOURCE_IPV4LL)
|
||||
continue;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_IPV6LL:
|
||||
if (!in6_addr_is_link_local(&a->in_addr.in6))
|
||||
continue;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_DHCP4:
|
||||
if (a->source != NETWORK_CONFIG_SOURCE_DHCP4)
|
||||
continue;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_DHCP6:
|
||||
if (a->source != NETWORK_CONFIG_SOURCE_DHCP6)
|
||||
continue;
|
||||
break;
|
||||
case NETDEV_LOCAL_ADDRESS_SLAAC:
|
||||
if (a->source != NETWORK_CONFIG_SOURCE_NDISC)
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
if (ret_family)
|
||||
*ret_family = a->family;
|
||||
if (ret_address)
|
||||
*ret_address = a->in_addr;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -ENXIO;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "in-addr-util.h"
|
||||
#include "macro.h"
|
||||
|
||||
typedef struct Link Link;
|
||||
|
||||
typedef enum NetDevLocalAddressType {
|
||||
NETDEV_LOCAL_ADDRESS_IPV4LL,
|
||||
NETDEV_LOCAL_ADDRESS_IPV6LL,
|
||||
NETDEV_LOCAL_ADDRESS_DHCP4,
|
||||
NETDEV_LOCAL_ADDRESS_DHCP6,
|
||||
NETDEV_LOCAL_ADDRESS_SLAAC,
|
||||
_NETDEV_LOCAL_ADDRESS_TYPE_MAX,
|
||||
_NETDEV_LOCAL_ADDRESS_TYPE_INVALID = -EINVAL,
|
||||
} NetDevLocalAddressType;
|
||||
|
||||
const char *netdev_local_address_type_to_string(NetDevLocalAddressType t) _const_;
|
||||
NetDevLocalAddressType netdev_local_address_type_from_string(const char *s) _pure_;
|
||||
|
||||
int link_get_local_address(
|
||||
Link *link,
|
||||
NetDevLocalAddressType type,
|
||||
int family,
|
||||
int *ret_family,
|
||||
union in_addr_union *ret_address);
|
||||
@@ -628,6 +628,9 @@ static bool netdev_is_ready_to_create(NetDev *netdev, Link *link) {
|
||||
if (link->set_link_messages > 0)
|
||||
return false;
|
||||
|
||||
if (NETDEV_VTABLE(netdev)->is_ready_to_create)
|
||||
return NETDEV_VTABLE(netdev)->is_ready_to_create(netdev, link);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,9 @@ typedef struct NetDevVTable {
|
||||
/* specifies if netdev is independent, or a master device or a stacked device */
|
||||
NetDevCreateType create_type;
|
||||
|
||||
/* This is used for stacked netdev. Return true when the underlying link is ready. */
|
||||
int (*is_ready_to_create)(NetDev *netdev, Link *link);
|
||||
|
||||
/* create netdev, if not done via rtnl */
|
||||
int (*create)(NetDev *netdev);
|
||||
|
||||
|
||||
+141
-21
@@ -168,7 +168,20 @@ int dhcp4_pd_create_6rd_tunnel(Link *link, link_netlink_message_handler_t callba
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tunnel_get_local_address(Tunnel *t, Link *link, union in_addr_union *ret) {
|
||||
assert(t);
|
||||
|
||||
if (t->local_type < 0) {
|
||||
if (ret)
|
||||
*ret = t->local;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return link_get_local_address(link, t->local_type, t->family, NULL, ret);
|
||||
}
|
||||
|
||||
static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
union in_addr_union local;
|
||||
Tunnel *t;
|
||||
int r;
|
||||
|
||||
@@ -188,7 +201,11 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
|
||||
r = tunnel_get_local_address(t, link, &local);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &local.in);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
|
||||
|
||||
@@ -247,6 +264,7 @@ static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_ne
|
||||
}
|
||||
|
||||
static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
union in_addr_union local;
|
||||
uint32_t ikey = 0;
|
||||
uint32_t okey = 0;
|
||||
uint16_t iflags = 0;
|
||||
@@ -285,7 +303,11 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_ERSPAN_INDEX attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in);
|
||||
r = tunnel_get_local_address(t, link, &local);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &local.in);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m");
|
||||
|
||||
@@ -363,6 +385,7 @@ static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_
|
||||
}
|
||||
|
||||
static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
union in_addr_union local;
|
||||
uint32_t ikey = 0;
|
||||
uint32_t okey = 0;
|
||||
uint16_t iflags = 0;
|
||||
@@ -386,7 +409,11 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6);
|
||||
r = tunnel_get_local_address(t, link, &local);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
|
||||
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &local.in6);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m");
|
||||
|
||||
@@ -444,6 +471,7 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
}
|
||||
|
||||
static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
union in_addr_union local;
|
||||
uint32_t ikey, okey;
|
||||
Tunnel *t;
|
||||
int r;
|
||||
@@ -479,7 +507,11 @@ static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_OKEY attribute: %m");
|
||||
|
||||
r = netlink_message_append_in_addr_union(m, IFLA_VTI_LOCAL, t->family, &t->local);
|
||||
r = tunnel_get_local_address(t, link, &local);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
|
||||
|
||||
r = netlink_message_append_in_addr_union(m, IFLA_VTI_LOCAL, t->family, &local);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_LOCAL attribute: %m");
|
||||
|
||||
@@ -491,6 +523,7 @@ 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) {
|
||||
union in_addr_union local;
|
||||
uint8_t proto;
|
||||
Tunnel *t;
|
||||
int r;
|
||||
@@ -508,7 +541,11 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6);
|
||||
r = tunnel_get_local_address(t, link, &local);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
|
||||
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &local.in6);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
|
||||
|
||||
@@ -562,6 +599,19 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
return r;
|
||||
}
|
||||
|
||||
static int netdev_tunnel_is_ready_to_create(NetDev *netdev, Link *link) {
|
||||
Tunnel *t;
|
||||
|
||||
assert(netdev);
|
||||
assert(link);
|
||||
|
||||
t = TUNNEL(netdev);
|
||||
|
||||
assert(t);
|
||||
|
||||
return tunnel_get_local_address(t, link, NULL) >= 0;
|
||||
}
|
||||
|
||||
static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
Tunnel *t;
|
||||
|
||||
@@ -611,10 +661,15 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
if (t->assign_to_loopback)
|
||||
t->independent = true;
|
||||
|
||||
if (t->independent && t->local_type >= 0)
|
||||
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
|
||||
"The local address cannot be '%s' when Independent= or AssignToLoopback= is enabled, ignoring.",
|
||||
strna(netdev_local_address_type_to_string(t->local_type)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_tunnel_address(
|
||||
int config_parse_tunnel_local_address(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
@@ -626,28 +681,82 @@ int config_parse_tunnel_address(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
union in_addr_union buffer = IN_ADDR_NULL;
|
||||
NetDevLocalAddressType type;
|
||||
Tunnel *t = userdata;
|
||||
union in_addr_union *addr = data, buffer;
|
||||
int r, f;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
assert(userdata);
|
||||
|
||||
/* This is used to parse addresses on both local and remote ends of the tunnel.
|
||||
* Address families must match.
|
||||
*
|
||||
* "any" is a special value which means that the address is unspecified.
|
||||
*/
|
||||
if (isempty(rvalue) || streq(rvalue, "any")) {
|
||||
/* Unset the previous assignment. */
|
||||
t->local = IN_ADDR_NULL;
|
||||
t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
|
||||
|
||||
if (streq(rvalue, "any")) {
|
||||
*addr = IN_ADDR_NULL;
|
||||
/* If the remote address is not specified, also clear the address family. */
|
||||
if (!in_addr_is_set(t->family, &t->remote))
|
||||
t->family = AF_UNSPEC;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* As a special case, if both the local and remote addresses are
|
||||
* unspecified, also clear the address family. */
|
||||
if (!in_addr_is_set(t->family, &t->local) &&
|
||||
!in_addr_is_set(t->family, &t->remote))
|
||||
type = netdev_local_address_type_from_string(rvalue);
|
||||
if (IN_SET(type, NETDEV_LOCAL_ADDRESS_IPV4LL, NETDEV_LOCAL_ADDRESS_DHCP4))
|
||||
f = AF_INET;
|
||||
else if (IN_SET(type, NETDEV_LOCAL_ADDRESS_IPV6LL, NETDEV_LOCAL_ADDRESS_DHCP6, NETDEV_LOCAL_ADDRESS_SLAAC))
|
||||
f = AF_INET6;
|
||||
else {
|
||||
type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
|
||||
r = in_addr_from_string_auto(rvalue, &f, &buffer);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Tunnel address \"%s\" invalid, ignoring assignment: %m", rvalue);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (t->family != AF_UNSPEC && t->family != f) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Address family does not match the previous assignment, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
t->family = f;
|
||||
t->local = buffer;
|
||||
t->local_type = type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_tunnel_remote_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) {
|
||||
|
||||
union in_addr_union buffer;
|
||||
Tunnel *t = userdata;
|
||||
int r, f;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(userdata);
|
||||
|
||||
if (isempty(rvalue) || streq(rvalue, "any")) {
|
||||
/* Unset the previous assignment. */
|
||||
t->remote = IN_ADDR_NULL;
|
||||
|
||||
/* If the local address is not specified, also clear the address family. */
|
||||
if (t->local_type == _NETDEV_LOCAL_ADDRESS_TYPE_INVALID &&
|
||||
!in_addr_is_set(t->family, &t->local))
|
||||
t->family = AF_UNSPEC;
|
||||
return 0;
|
||||
}
|
||||
@@ -661,12 +770,12 @@ int config_parse_tunnel_address(
|
||||
|
||||
if (t->family != AF_UNSPEC && t->family != f) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"Tunnel addresses incompatible, ignoring assignment: %s", rvalue);
|
||||
"Address family does not match the previous assignment, ignoring assignment: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
t->family = f;
|
||||
*addr = buffer;
|
||||
t->remote = buffer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -840,6 +949,7 @@ static void netdev_tunnel_init(NetDev *netdev) {
|
||||
|
||||
assert(t);
|
||||
|
||||
t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
|
||||
t->pmtudisc = true;
|
||||
t->fou_encap_type = NETDEV_FOO_OVER_UDP_ENCAP_DIRECT;
|
||||
t->isatap = -1;
|
||||
@@ -859,6 +969,7 @@ const NetDevVTable ipip_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ipip_sit_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_TUNNEL,
|
||||
};
|
||||
@@ -869,6 +980,7 @@ const NetDevVTable sit_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ipip_sit_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_SIT,
|
||||
};
|
||||
@@ -879,6 +991,7 @@ const NetDevVTable vti_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_vti_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_TUNNEL,
|
||||
};
|
||||
@@ -889,6 +1002,7 @@ const NetDevVTable vti6_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_vti_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_TUNNEL6,
|
||||
};
|
||||
@@ -899,6 +1013,7 @@ const NetDevVTable gre_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_gre_erspan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_IPGRE,
|
||||
};
|
||||
@@ -909,6 +1024,7 @@ const NetDevVTable gretap_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_gre_erspan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_ETHER,
|
||||
.generate_mac = true,
|
||||
@@ -920,6 +1036,7 @@ const NetDevVTable ip6gre_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ip6gre_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_IP6GRE,
|
||||
};
|
||||
@@ -930,6 +1047,7 @@ const NetDevVTable ip6gretap_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ip6gre_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_ETHER,
|
||||
.generate_mac = true,
|
||||
@@ -941,6 +1059,7 @@ const NetDevVTable ip6tnl_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_ip6tnl_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_TUNNEL6,
|
||||
};
|
||||
@@ -951,6 +1070,7 @@ const NetDevVTable erspan_vtable = {
|
||||
.sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
|
||||
.fill_message_create = netdev_gre_erspan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.is_ready_to_create = netdev_tunnel_is_ready_to_create,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
.iftype = ARPHRD_ETHER,
|
||||
.generate_mac = true,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "fou-tunnel.h"
|
||||
#include "netdev-util.h"
|
||||
#include "netdev.h"
|
||||
#include "networkd-link.h"
|
||||
|
||||
@@ -42,6 +43,7 @@ typedef struct Tunnel {
|
||||
uint32_t okey;
|
||||
uint32_t erspan_index;
|
||||
|
||||
NetDevLocalAddressType local_type;
|
||||
union in_addr_union local;
|
||||
union in_addr_union remote;
|
||||
|
||||
@@ -119,7 +121,8 @@ const char *ip6tnl_mode_to_string(Ip6TnlMode d) _const_;
|
||||
Ip6TnlMode ip6tnl_mode_from_string(const char *d) _pure_;
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ip6tnl_mode);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_address);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_local_address);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_remote_address);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_flowlabel);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_encap_limit);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_key);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
[NetDev]
|
||||
Name=ip6tnl-slaac
|
||||
Kind=ip6tnl
|
||||
|
||||
[Tunnel]
|
||||
Mode=ip6ip6
|
||||
Local=slaac
|
||||
Remote=2001:473:fece:cafe::5179
|
||||
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
[Match]
|
||||
Name=ip6tnl-slaac
|
||||
|
||||
[Network]
|
||||
IPv6AcceptRA=no
|
||||
LinkLocalAddressing=yes
|
||||
|
||||
[Route]
|
||||
Destination=0.0.0.0/0
|
||||
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
[Match]
|
||||
Name=veth99
|
||||
|
||||
[Network]
|
||||
IPv6AcceptRA=yes
|
||||
Tunnel=ip6tnl-slaac
|
||||
|
||||
[IPv6AcceptRA]
|
||||
PrefixAllowList=2002:da8:1::/64
|
||||
@@ -900,6 +900,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
|
||||
'ip6gretun97',
|
||||
'ip6gretun98',
|
||||
'ip6gretun99',
|
||||
'ip6tnl-slaac',
|
||||
'ip6tnl97',
|
||||
'ip6tnl98',
|
||||
'ip6tnl99',
|
||||
@@ -986,6 +987,8 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
|
||||
'25-ip6gre-tunnel.netdev',
|
||||
'25-ip6tnl-tunnel-any-any.netdev',
|
||||
'25-ip6tnl-tunnel-local-any.netdev',
|
||||
'25-ip6tnl-tunnel-local-slaac.netdev',
|
||||
'25-ip6tnl-tunnel-local-slaac.network',
|
||||
'25-ip6tnl-tunnel-remote-any.netdev',
|
||||
'25-ip6tnl-tunnel.netdev',
|
||||
'25-ipip-tunnel-any-any.netdev',
|
||||
@@ -1044,8 +1047,10 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
|
||||
'gretun.network',
|
||||
'ip6gretap.network',
|
||||
'ip6gretun.network',
|
||||
'ip6tnl-slaac.network',
|
||||
'ip6tnl.network',
|
||||
'ipip.network',
|
||||
'ipv6-prefix.network',
|
||||
'ipvlan.network',
|
||||
'ipvtap.network',
|
||||
'isatap.network',
|
||||
@@ -1664,19 +1669,33 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
|
||||
copy_unit_to_networkd_unit_path('12-dummy.netdev', 'ip6tnl.network',
|
||||
'25-ip6tnl-tunnel.netdev', '25-tunnel.network',
|
||||
'25-ip6tnl-tunnel-local-any.netdev', '25-tunnel-local-any.network',
|
||||
'25-ip6tnl-tunnel-remote-any.netdev', '25-tunnel-remote-any.network')
|
||||
'25-ip6tnl-tunnel-remote-any.netdev', '25-tunnel-remote-any.network',
|
||||
'25-veth.netdev', 'ip6tnl-slaac.network', 'ipv6-prefix.network',
|
||||
'25-ip6tnl-tunnel-local-slaac.netdev', '25-ip6tnl-tunnel-local-slaac.network')
|
||||
start_networkd()
|
||||
self.wait_online(['ip6tnl99:routable', 'ip6tnl98:routable', 'ip6tnl97:routable', 'dummy98:degraded'])
|
||||
self.wait_online(['ip6tnl99:routable', 'ip6tnl98:routable', 'ip6tnl97:routable', 'ip6tnl-slaac:degraded',
|
||||
'dummy98:degraded', 'veth99:routable', 'veth-peer:degraded'])
|
||||
|
||||
output = check_output('ip -d link show ip6tnl99')
|
||||
print(output)
|
||||
self.assertRegex(output, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98')
|
||||
self.assertIn('ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2a00:ffde:4567:edde::4987 dev dummy98', output)
|
||||
output = check_output('ip -d link show ip6tnl98')
|
||||
print(output)
|
||||
self.assertRegex(output, 'ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local (any|::) dev dummy98')
|
||||
output = check_output('ip -d link show ip6tnl97')
|
||||
print(output)
|
||||
self.assertRegex(output, 'ip6tnl ip6ip6 remote (any|::) local 2a00:ffde:4567:edde::4987 dev dummy98')
|
||||
output = check_output('ip -d link show ip6tnl-slaac')
|
||||
print(output)
|
||||
self.assertIn('ip6tnl ip6ip6 remote 2001:473:fece:cafe::5179 local 2002:da8:1:0:1034:56ff:fe78:9abc dev veth99', output)
|
||||
|
||||
output = check_output('ip -6 address show veth99')
|
||||
print(output)
|
||||
self.assertIn('inet6 2002:da8:1:0:1034:56ff:fe78:9abc/64 scope global dynamic', output)
|
||||
|
||||
output = check_output('ip -4 route show default')
|
||||
print(output)
|
||||
self.assertIn('default dev ip6tnl-slaac proto static', output)
|
||||
|
||||
def test_sit_tunnel(self):
|
||||
copy_unit_to_networkd_unit_path('12-dummy.netdev', 'sit.network',
|
||||
|
||||
Reference in New Issue
Block a user