Merge pull request #11968 from yuwata/network-l2tp

network: introduce L2TP tunnel
This commit is contained in:
Lennart Poettering
2019-03-14 10:36:21 +01:00
committed by GitHub
19 changed files with 1256 additions and 36 deletions
+115
View File
@@ -153,6 +153,9 @@
<row><entry><varname>geneve</varname></entry>
<entry>A GEneric NEtwork Virtualization Encapsulation (GENEVE) netdev driver.</entry></row>
<row><entry><varname>l2tp</varname></entry>
<entry>A Layer 2 Tunneling Protocol (L2TP) is a tunneling protocol used to support virtual private networks (VPNs) or as part of the delivery of services by ISPs. It does not provide any encryption or confidentiality by itself</entry></row>
<row><entry><varname>vrf</varname></entry>
<entry>A Virtual Routing and Forwarding (<ulink url="https://www.kernel.org/doc/Documentation/networking/vrf.txt">VRF</ulink>) interface to create separate routing and forwarding domains.</entry></row>
@@ -739,6 +742,118 @@
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>[L2TP] Section Options</title>
<para>The <literal>[L2TP]</literal> section only applies for
netdevs of kind <literal>l2tp</literal>, and accepts the
following keys:</para>
<variablelist class='network-directives'>
<varlistentry>
<term><varname>TunnelId=</varname></term>
<listitem>
<para>Specifies the tunnel id. The value used must match the <literal>PeerTunnelId=</literal> value being used at the peer.
Ranges a number between 1 and 4294967295). This option is compulsory.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>PeerTunnelId=</varname></term>
<listitem>
<para>Specifies the peer tunnel id. The value used must match the <literal>PeerTunnelId=</literal> value being used at the peer.
Ranges a number between 1 and 4294967295). This option is compulsory.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Remote=</varname></term>
<listitem>
<para>Specifies the IP address of the remote peer. This option is compulsory.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Local=</varname></term>
<listitem>
<para>Specifies the IP address of the local interface. Takes an IP address, or the special values
<literal>auto</literal>, <literal>static</literal>, or <literal>dynamic</literal>. When an address
is set, then the local interface must have the address. If <literal>auto</literal>, then one of the
addresses on the local interface is used. Similarly, if <literal>static</literal> or
<literal>dynamic</literal> is set, then one of the static or dynamic addresses on the local
interface is used. Defaults to <literal>auto</literal>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>EncapsulationType=</varname></term>
<listitem>
<para>Specifies the encapsulation type of the tunnel. Takes one of <literal>udp</literal> or <literal>ip</literal>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UDPSourcePort=</varname></term>
<listitem>
<para>Specifies the UDP source port to be used for the tunnel. When UDP encapsulation is selected it's mandotory. Ignored when ip
encapsulation is selected.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>DestinationPort=</varname></term>
<listitem>
<para>Specifies destination port. When UDP encapsulation is selected it's mandotory. Ignored when ip
encapsulation is selected.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UDPChecksum=</varname></term>
<listitem>
<para>Takes a boolean. When true, specifies if UDP checksum is calculated for transmitted packets over IPv4.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UDP6ZeroChecksumTx=</varname></term>
<listitem>
<para>Takes a boolean. When true, skip UDP checksum calculation for transmitted packets over IPv6.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UDP6ZeroChecksumRx=</varname></term>
<listitem>
<para>Takes a boolean. When true, allows incoming UDP packets over IPv6 with zero checksum field.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>[L2TPSession] Section Options</title>
<para>The <literal>[L2TPSession]</literal> section only applies for
netdevs of kind <literal>l2tp</literal>, and accepts the
following keys:</para>
<variablelist class='network-directives'>
<varlistentry>
<term><varname>Name=</varname></term>
<listitem>
<para>Specifies the name of the sesssion. This option is compulsory.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>SessionId=</varname></term>
<listitem>
<para>Specifies the sesssion id. The value used must match the <literal>SessionId=</literal> value being used at the peer.
Ranges a number between 1 and 4294967295). This option is compulsory.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>PeerSessionId=</varname></term>
<listitem>
<para>Specifies the peer session id. The value used must match the <literal>PeerSessionId=</literal> value being used at the peer.
Ranges a number between 1 and 4294967295). This option is compulsory.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Layer2SpecificHeader=</varname></term>
<listitem>
<para>Specifies layer2specific header type of the session. One of <literal>none</literal> or <literal>default</literal>. Defaults to <literal>default</literal>.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>[Tunnel] Section Options</title>
+2 -1
View File
@@ -10,9 +10,10 @@ typedef struct {
} genl_family;
static const genl_family genl_families[] = {
[SD_GENL_ID_CTRL] = { .name = "", .version = 1 },
[SD_GENL_ID_CTRL] = { .name = "", .version = 1 },
[SD_GENL_WIREGUARD] = { .name = "wireguard", .version = 1 },
[SD_GENL_FOU] = { .name = "fou", .version = 1 },
[SD_GENL_L2TP] = { .name = "l2tp", .version = 1},
};
int sd_genl_socket_open(sd_netlink **ret) {
+54
View File
@@ -15,6 +15,7 @@
#include <linux/if_bridge.h>
#include <linux/if_link.h>
#include <linux/if_tunnel.h>
#include <linux/l2tp.h>
#include <linux/veth.h>
#if HAVE_LINUX_FOU_H
@@ -797,10 +798,62 @@ static const NLTypeSystem genl_fou_cmds_type_system = {
.types = genl_fou_cmds,
};
static const NLType genl_l2tp_types[] = {
[L2TP_ATTR_PW_TYPE] = { .type = NETLINK_TYPE_U16 },
[L2TP_ATTR_ENCAP_TYPE] = { .type = NETLINK_TYPE_U16 },
[L2TP_ATTR_OFFSET] = { .type = NETLINK_TYPE_U16 },
[L2TP_ATTR_DATA_SEQ] = { .type = NETLINK_TYPE_U16 },
[L2TP_ATTR_L2SPEC_TYPE] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_L2SPEC_LEN] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_PROTO_VERSION] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_IFNAME] = { .type = NETLINK_TYPE_STRING },
[L2TP_ATTR_CONN_ID] = { .type = NETLINK_TYPE_U32 },
[L2TP_ATTR_PEER_CONN_ID] = { .type = NETLINK_TYPE_U32 },
[L2TP_ATTR_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
[L2TP_ATTR_PEER_SESSION_ID] = { .type = NETLINK_TYPE_U32 },
[L2TP_ATTR_UDP_CSUM] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_VLAN_ID] = { .type = NETLINK_TYPE_U16 },
[L2TP_ATTR_RECV_SEQ] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_SEND_SEQ] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_LNS_MODE] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_USING_IPSEC] = { .type = NETLINK_TYPE_U8 },
[L2TP_ATTR_FD] = { .type = NETLINK_TYPE_U32 },
[L2TP_ATTR_IP_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
[L2TP_ATTR_IP_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
[L2TP_ATTR_UDP_SPORT] = { .type = NETLINK_TYPE_U16 },
[L2TP_ATTR_UDP_DPORT] = { .type = NETLINK_TYPE_U16 },
[L2TP_ATTR_IP6_SADDR] = { .type = NETLINK_TYPE_IN_ADDR },
[L2TP_ATTR_IP6_DADDR] = { .type = NETLINK_TYPE_IN_ADDR },
[L2TP_ATTR_UDP_ZERO_CSUM6_TX] = { .type = NETLINK_TYPE_FLAG },
[L2TP_ATTR_UDP_ZERO_CSUM6_RX] = { .type = NETLINK_TYPE_FLAG },
};
static const NLTypeSystem genl_l2tp_type_system = {
.count = ELEMENTSOF(genl_l2tp_types),
.types = genl_l2tp_types,
};
static const NLType genl_l2tp[] = {
[L2TP_CMD_TUNNEL_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
[L2TP_CMD_TUNNEL_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
[L2TP_CMD_TUNNEL_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
[L2TP_CMD_TUNNEL_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
[L2TP_CMD_SESSION_CREATE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
[L2TP_CMD_SESSION_DELETE] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
[L2TP_CMD_SESSION_MODIFY] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
[L2TP_CMD_SESSION_GET] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_type_system },
};
static const NLTypeSystem genl_l2tp_tunnel_session_type_system = {
.count = ELEMENTSOF(genl_l2tp),
.types = genl_l2tp,
};
static const NLType genl_families[] = {
[SD_GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_ctrl_id_ctrl_type_system },
[SD_GENL_WIREGUARD] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_wireguard_type_system },
[SD_GENL_FOU] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_fou_cmds_type_system},
[SD_GENL_L2TP] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_l2tp_tunnel_session_type_system },
};
const NLTypeSystem genl_family_type_system_root = {
@@ -809,6 +862,7 @@ const NLTypeSystem genl_family_type_system_root = {
};
static const NLType genl_types[] = {
[NLMSG_ERROR] = { .type = NETLINK_TYPE_NESTED, .type_system = &empty_type_system, .size = sizeof(struct nlmsgerr) },
[GENL_ID_CTRL] = { .type = NETLINK_TYPE_NESTED, .type_system = &genl_get_family_type_system, .size = sizeof(struct genlmsghdr) },
};
+2
View File
@@ -37,6 +37,8 @@ sources = files('''
netdev/netdevsim.h
netdev/fou-tunnel.c
netdev/fou-tunnel.h
netdev/l2tp-tunnel.c
netdev/l2tp-tunnel.h
networkd-address-label.c
networkd-address-label.h
networkd-address-pool.c
+734
View File
@@ -0,0 +1,734 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <arpa/inet.h>
#include <linux/l2tp.h>
#include <linux/genetlink.h>
#include "sd-netlink.h"
#include "conf-parser.h"
#include "hashmap.h"
#include "l2tp-tunnel.h"
#include "missing.h"
#include "netlink-util.h"
#include "networkd-address.h"
#include "networkd-manager.h"
#include "parse-util.h"
#include "socket-util.h"
#include "string-table.h"
#include "string-util.h"
#include "util.h"
static const char* const l2tp_l2spec_type_table[_NETDEV_L2TP_L2SPECTYPE_MAX] = {
[NETDEV_L2TP_L2SPECTYPE_NONE] = "none",
[NETDEV_L2TP_L2SPECTYPE_DEFAULT] = "default",
};
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(l2tp_l2spec_type, L2tpL2specType);
static const char* const l2tp_encap_type_table[_NETDEV_L2TP_ENCAPTYPE_MAX] = {
[NETDEV_L2TP_ENCAPTYPE_UDP] = "udp",
[NETDEV_L2TP_ENCAPTYPE_IP] = "ip",
};
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(l2tp_encap_type, L2tpEncapType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_l2tp_encap_type, l2tp_encap_type, L2tpEncapType, "Failed to parse L2TP Encapsulation Type");
static const char* const l2tp_local_address_type_table[_NETDEV_L2TP_LOCAL_ADDRESS_MAX] = {
[NETDEV_L2TP_LOCAL_ADDRESS_AUTO] = "auto",
[NETDEV_L2TP_LOCAL_ADDRESS_STATIC] = "static",
[NETDEV_L2TP_LOCAL_ADDRESS_DYNAMIC] = "dynamic",
};
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(l2tp_local_address_type, L2tpLocalAddressType);
static void l2tp_session_free(L2tpSession *s) {
if (!s)
return;
if (s->tunnel && s->section)
ordered_hashmap_remove(s->tunnel->sessions_by_section, s);
network_config_section_free(s->section);
free(s->name);
free(s);
}
DEFINE_NETWORK_SECTION_FUNCTIONS(L2tpSession, l2tp_session_free);
static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned section_line, L2tpSession **ret) {
_cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
_cleanup_(l2tp_session_freep) L2tpSession *s = NULL;
int r;
assert(t);
assert(ret);
assert(filename);
assert(section_line > 0);
r = network_config_section_new(filename, section_line, &n);
if (r < 0)
return r;
s = ordered_hashmap_get(t->sessions_by_section, n);
if (s) {
*ret = TAKE_PTR(s);
return 0;
}
s = new(L2tpSession, 1);
if (!s)
return -ENOMEM;
*s = (L2tpSession) {
.l2tp_l2spec_type = NETDEV_L2TP_L2SPECTYPE_DEFAULT,
.tunnel = t,
.section = TAKE_PTR(n),
};
r = ordered_hashmap_ensure_allocated(&t->sessions_by_section, &network_config_hash_ops);
if (r < 0)
return r;
r = ordered_hashmap_put(t->sessions_by_section, s->section, s);
if (r < 0)
return r;
*ret = TAKE_PTR(s);
return 0;
}
static int netdev_l2tp_fill_message_tunnel(NetDev *netdev, union in_addr_union *local_address, sd_netlink_message **ret) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
uint16_t encap_type;
L2tpTunnel *t;
int r;
assert(netdev);
assert(local_address);
t = L2TP(netdev);
assert(t);
r = sd_genl_message_new(netdev->manager->genl, SD_GENL_L2TP, L2TP_CMD_TUNNEL_CREATE, &m);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Failed to create generic netlink message: %m");
r = sd_netlink_message_append_u32(m, L2TP_ATTR_CONN_ID, t->tunnel_id);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_CONN_ID attribute: %m");
r = sd_netlink_message_append_u32(m, L2TP_ATTR_PEER_CONN_ID, t->peer_tunnel_id);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PEER_CONN_ID attribute: %m");
r = sd_netlink_message_append_u8(m, L2TP_ATTR_PROTO_VERSION, 3);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PROTO_VERSION attribute: %m");
switch(t->l2tp_encap_type) {
case NETDEV_L2TP_ENCAPTYPE_IP:
encap_type = L2TP_ENCAPTYPE_IP;
break;
case NETDEV_L2TP_ENCAPTYPE_UDP:
default:
encap_type = L2TP_ENCAPTYPE_UDP;
break;
}
r = sd_netlink_message_append_u16(m, L2TP_ATTR_ENCAP_TYPE, encap_type);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_ENCAP_TYPE attribute: %m");
if (t->family == AF_INET) {
r = sd_netlink_message_append_in_addr(m, L2TP_ATTR_IP_SADDR, &local_address->in);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP_SADDR attribute: %m");
r = sd_netlink_message_append_in_addr(m, L2TP_ATTR_IP_DADDR, &t->remote.in);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP_DADDR attribute: %m");
} else {
r = sd_netlink_message_append_in6_addr(m, L2TP_ATTR_IP6_SADDR, &local_address->in6);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP6_SADDR attribute: %m");
r = sd_netlink_message_append_in6_addr(m, L2TP_ATTR_IP6_DADDR, &t->remote.in6);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IP6_DADDR attribute: %m");
}
if (encap_type == L2TP_ENCAPTYPE_UDP) {
r = sd_netlink_message_append_u16(m, L2TP_ATTR_UDP_SPORT, t->l2tp_udp_sport);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_SPORT, attribute: %m");
r = sd_netlink_message_append_u16(m, L2TP_ATTR_UDP_DPORT, t->l2tp_udp_dport);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_DPORT attribute: %m");
if (t->udp_csum) {
r = sd_netlink_message_append_u8(m, L2TP_ATTR_UDP_CSUM, t->udp_csum);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_CSUM attribute: %m");
}
if (t->udp6_csum_tx) {
r = sd_netlink_message_append_flag(m, L2TP_ATTR_UDP_ZERO_CSUM6_TX);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_ZERO_CSUM6_TX attribute: %m");
}
if (t->udp6_csum_rx) {
r = sd_netlink_message_append_flag(m, L2TP_ATTR_UDP_ZERO_CSUM6_RX);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_UDP_ZERO_CSUM6_RX attribute: %m");
}
}
*ret = TAKE_PTR(m);
return 0;
}
static int netdev_l2tp_fill_message_session(NetDev *netdev, L2tpSession *session, sd_netlink_message **ret) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
uint16_t l2_spec_len;
uint8_t l2_spec_type;
int r;
assert(netdev);
assert(session);
assert(session->tunnel);
r = sd_genl_message_new(netdev->manager->genl, SD_GENL_L2TP, L2TP_CMD_SESSION_CREATE, &m);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Failed to create generic netlink message: %m");
r = sd_netlink_message_append_u32(m, L2TP_ATTR_CONN_ID, session->tunnel->tunnel_id);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_CONN_ID attribute: %m");
r = sd_netlink_message_append_u32(m, L2TP_ATTR_PEER_CONN_ID, session->tunnel->peer_tunnel_id);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PEER_CONN_ID attribute: %m");
r = sd_netlink_message_append_u32(m, L2TP_ATTR_SESSION_ID, session->session_id);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_SESSION_ID attribute: %m");
r = sd_netlink_message_append_u32(m, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PEER_SESSION_ID attribute: %m");
r = sd_netlink_message_append_u16(m, L2TP_ATTR_PW_TYPE, L2TP_PWTYPE_ETH);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_PW_TYPE attribute: %m");
switch (session->l2tp_l2spec_type) {
case NETDEV_L2TP_L2SPECTYPE_NONE:
l2_spec_type = L2TP_L2SPECTYPE_NONE;
l2_spec_len = 0;
break;
case NETDEV_L2TP_L2SPECTYPE_DEFAULT:
default:
l2_spec_type = L2TP_L2SPECTYPE_DEFAULT;
l2_spec_len = 4;
break;
}
r = sd_netlink_message_append_u8(m, L2TP_ATTR_L2SPEC_TYPE, l2_spec_type);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_L2SPEC_TYPE attribute: %m");
r = sd_netlink_message_append_u8(m, L2TP_ATTR_L2SPEC_LEN, l2_spec_len);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_L2SPEC_LEN attribute: %m");
r = sd_netlink_message_append_string(m, L2TP_ATTR_IFNAME, session->name);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append L2TP_ATTR_IFNAME attribute: %m");
*ret = TAKE_PTR(m);
return 0;
}
static int l2tp_acquire_local_address_one(L2tpTunnel *t, Address *a, union in_addr_union *ret) {
if (a->family != t->family)
return -EINVAL;
if (in_addr_is_null(a->family, &a->in_addr_peer) <= 0)
return -EINVAL;
if (t->local_address_type == NETDEV_L2TP_LOCAL_ADDRESS_STATIC &&
!FLAGS_SET(a->flags, IFA_F_PERMANENT))
return -EINVAL;
if (t->local_address_type == NETDEV_L2TP_LOCAL_ADDRESS_DYNAMIC &&
FLAGS_SET(a->flags, IFA_F_PERMANENT))
return -EINVAL;
*ret = a->in_addr;
return 0;
}
static int l2tp_acquire_local_address(L2tpTunnel *t, Link *link, union in_addr_union *ret) {
Address *a;
Iterator i;
assert(t);
assert(link);
assert(ret);
assert(IN_SET(t->family, AF_INET, AF_INET6));
if (!in_addr_is_null(t->family, &t->local)) {
/* local address is explicitly specified. */
*ret = t->local;
return 0;
}
SET_FOREACH(a, link->addresses, i)
if (l2tp_acquire_local_address_one(t, a, ret) >= 0)
return 1;
SET_FOREACH(a, link->addresses_foreign, i)
if (l2tp_acquire_local_address_one(t, a, ret) >= 0)
return 1;
return -ENODATA;
}
static void l2tp_session_destroy_callback(L2tpSession *session) {
if (!session)
return;
netdev_unref(NETDEV(session->tunnel));
}
static int l2tp_create_session_handler(sd_netlink *rtnl, sd_netlink_message *m, L2tpSession *session) {
NetDev *netdev;
int r;
assert(session);
assert(session->tunnel);
netdev = NETDEV(session->tunnel);
r = sd_netlink_message_get_errno(m);
if (r == -EEXIST)
log_netdev_info(netdev, "L2TP session %s exists, using existing without changing its parameters",
session->name);
else if (r < 0) {
log_netdev_warning_errno(netdev, r, "L2TP session %s could not be created: %m", session->name);
return 1;
}
log_netdev_debug(netdev, "L2TP session %s created", session->name);
return 1;
}
static int l2tp_create_session(NetDev *netdev, L2tpSession *session) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *n = NULL;
int r;
r = netdev_l2tp_fill_message_session(netdev, session, &n);
if (r < 0)
return r;
r = netlink_call_async(netdev->manager->genl, NULL, n, l2tp_create_session_handler,
l2tp_session_destroy_callback, session);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Failed to create L2TP session %s: %m", session->name);
netdev_ref(netdev);
return 0;
}
static int l2tp_create_tunnel_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {
L2tpSession *session;
L2tpTunnel *t;
Iterator i;
int r;
assert(netdev);
assert(netdev->state != _NETDEV_STATE_INVALID);
t = L2TP(netdev);
assert(t);
r = sd_netlink_message_get_errno(m);
if (r == -EEXIST)
log_netdev_info(netdev, "netdev exists, using existing without changing its parameters");
else if (r < 0) {
log_netdev_warning_errno(netdev, r, "netdev could not be created: %m");
netdev_drop(netdev);
return 1;
}
log_netdev_debug(netdev, "L2TP tunnel is created");
ORDERED_HASHMAP_FOREACH(session, t->sessions_by_section, i)
(void) l2tp_create_session(netdev, session);
return 1;
}
static int l2tp_create_tunnel(NetDev *netdev, Link *link) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
union in_addr_union local_address;
L2tpTunnel *t;
int r;
assert(netdev);
t = L2TP(netdev);
assert(t);
r = l2tp_acquire_local_address(t, link, &local_address);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not find local address.");
if (r > 0 && DEBUG_LOGGING) {
_cleanup_free_ char *str = NULL;
(void) in_addr_to_string(t->family, &local_address, &str);
log_netdev_debug(netdev, "Local address %s acquired.", strna(str));
}
r = netdev_l2tp_fill_message_tunnel(netdev, &local_address, &m);
if (r < 0)
return r;
r = netlink_call_async(netdev->manager->genl, NULL, m, l2tp_create_tunnel_handler,
netdev_destroy_callback, netdev);
if (r < 0)
return log_netdev_error_errno(netdev, r, "Failed to create L2TP tunnel: %m");
netdev_ref(netdev);
return 0;
}
int config_parse_l2tp_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) {
L2tpTunnel *t = userdata;
union in_addr_union *addr = data;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
if (streq(lvalue, "Local")) {
L2tpLocalAddressType addr_type;
if (isempty(rvalue))
addr_type = NETDEV_L2TP_LOCAL_ADDRESS_AUTO;
else
addr_type = l2tp_local_address_type_from_string(rvalue);
if (addr_type >= 0) {
if (in_addr_is_null(t->family, &t->remote) != 0)
/* If Remote= is not specified yet, then also clear family. */
t->family = AF_UNSPEC;
t->local = IN_ADDR_NULL;
t->local_address_type = addr_type;
return 0;
}
}
if (t->family == AF_UNSPEC)
r = in_addr_from_string_auto(rvalue, &t->family, addr);
else
r = in_addr_from_string(t->family, rvalue, addr);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Invalid L2TP Tunnel address specified in %s='%s', ignoring assignment: %m", lvalue, rvalue);
return 0;
}
return 0;
}
int config_parse_l2tp_tunnel_id(
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) {
uint32_t *id = data, k;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = safe_atou32(rvalue, &k);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse L2TP tunnel id. Ignoring assignment: %s", rvalue);
return 0;
}
if (k == 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Invalid L2TP tunnel id. Ignoring assignment: %s", rvalue);
return 0;
}
*id = k;
return 0;
}
int config_parse_l2tp_session_id(
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) {
_cleanup_(l2tp_session_free_or_set_invalidp) L2tpSession *session = NULL;
L2tpTunnel *t = userdata;
uint32_t k;
int r;
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
assert(data);
r = l2tp_session_new_static(t, filename, section_line, &session);
if (r < 0)
return r;
r = safe_atou32(rvalue, &k);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse L2TP session id. Ignoring assignment: %s", rvalue);
return 0;
}
if (k == 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Invalid L2TP session id. Ignoring assignment: %s", rvalue);
return 0;
}
if (streq(lvalue, "SessionId"))
session->session_id = k;
else
session->peer_session_id = k;
session = NULL;
return 0;
}
int config_parse_l2tp_session_l2spec(
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) {
_cleanup_(l2tp_session_free_or_set_invalidp) L2tpSession *session = NULL;
L2tpTunnel *t = userdata;
L2tpL2specType spec;
int r;
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
assert(data);
r = l2tp_session_new_static(t, filename, section_line, &session);
if (r < 0)
return r;
spec = l2tp_l2spec_type_from_string(rvalue);
if (spec < 0) {
log_syntax(unit, LOG_ERR, filename, line, 0,
"Failed to parse layer2 specific header type. Ignoring assignment: %s", rvalue);
return 0;
}
session->l2tp_l2spec_type = spec;
session = NULL;
return 0;
}
int config_parse_l2tp_session_name(
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) {
_cleanup_(l2tp_session_free_or_set_invalidp) L2tpSession *session = NULL;
L2tpTunnel *t = userdata;
int r;
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
assert(data);
r = l2tp_session_new_static(t, filename, section_line, &session);
if (r < 0)
return r;
if (!ifname_valid(rvalue)) {
log_syntax(unit, LOG_ERR, filename, line, 0,
"Failed to parse L2TP tunnel session name. Ignoring assignment: %s", rvalue);
return 0;
}
session->name = strdup(rvalue);
if (!session->name)
return -ENOMEM;
session = NULL;
return 0;
}
static void l2tp_tunnel_init(NetDev *netdev) {
L2tpTunnel *t;
assert(netdev);
t = L2TP(netdev);
assert(t);
t->l2tp_encap_type = NETDEV_L2TP_ENCAPTYPE_UDP;
t->udp6_csum_rx = true;
t->udp6_csum_tx = true;
}
static int l2tp_session_verify(L2tpSession *session) {
NetDev *netdev;
assert(session);
assert(session->tunnel);
netdev = NETDEV(session->tunnel);
if (section_is_invalid(session->section))
return -EINVAL;
if (!session->name)
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
"%s: L2TP session without name configured. "
"Ignoring [L2TPSession] section from line %u",
session->section->filename, session->section->line);
if (session->session_id == 0 || session->peer_session_id == 0)
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
"%s: L2TP session without session IDs configured. "
"Ignoring [L2TPSession] section from line %u",
session->section->filename, session->section->line);
return 0;
}
static int netdev_l2tp_tunnel_verify(NetDev *netdev, const char *filename) {
L2tpTunnel *t;
L2tpSession *session;
Iterator i;
assert(netdev);
assert(filename);
t = L2TP(netdev);
assert(t);
if (!IN_SET(t->family, AF_INET, AF_INET6))
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
"%s: L2TP tunnel with invalid address family configured. Ignoring",
filename);
if (in_addr_is_null(t->family, &t->remote))
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
"%s: L2TP tunnel without a remote address configured. Ignoring",
filename);
if (t->tunnel_id == 0 || t->peer_tunnel_id == 0)
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
"%s: L2TP tunnel without tunnel IDs configured. Ignoring",
filename);
ORDERED_HASHMAP_FOREACH(session, t->sessions_by_section, i)
if (l2tp_session_verify(session) < 0)
l2tp_session_free(session);
return 0;
}
static void l2tp_tunnel_done(NetDev *netdev) {
L2tpTunnel *t;
assert(netdev);
t = L2TP(netdev);
assert(t);
ordered_hashmap_free_with_destructor(t->sessions_by_section, l2tp_session_free);
}
const NetDevVTable l2tptnl_vtable = {
.object_size = sizeof(L2tpTunnel),
.init = l2tp_tunnel_init,
.sections = "Match\0NetDev\0L2TP\0L2TPSession",
.create_after_configured = l2tp_create_tunnel,
.done = l2tp_tunnel_done,
.create_type = NETDEV_CREATE_AFTER_CONFIGURED,
.config_verify = netdev_l2tp_tunnel_verify,
};
+77
View File
@@ -0,0 +1,77 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <linux/l2tp.h>
#include "in-addr-util.h"
#include "netdev.h"
#include "networkd-util.h"
typedef enum L2tpL2specType {
NETDEV_L2TP_L2SPECTYPE_NONE = L2TP_L2SPECTYPE_NONE,
NETDEV_L2TP_L2SPECTYPE_DEFAULT = L2TP_L2SPECTYPE_DEFAULT,
_NETDEV_L2TP_L2SPECTYPE_MAX,
_NETDEV_L2TP_L2SPECTYPE_INVALID = -1,
} L2tpL2specType;
typedef enum L2tpEncapType {
NETDEV_L2TP_ENCAPTYPE_UDP = L2TP_ENCAPTYPE_UDP,
NETDEV_L2TP_ENCAPTYPE_IP = L2TP_ENCAPTYPE_IP,
_NETDEV_L2TP_ENCAPTYPE_MAX,
_NETDEV_L2TP_ENCAPTYPE_INVALID = -1,
} L2tpEncapType;
typedef enum L2tpLocalAddressType {
NETDEV_L2TP_LOCAL_ADDRESS_AUTO,
NETDEV_L2TP_LOCAL_ADDRESS_STATIC,
NETDEV_L2TP_LOCAL_ADDRESS_DYNAMIC,
_NETDEV_L2TP_LOCAL_ADDRESS_MAX,
_NETDEV_L2TP_LOCAL_ADDRESS_INVALID = -1,
} L2tpLocalAddressType;
typedef struct L2tpTunnel L2tpTunnel;
typedef struct L2tpSession {
L2tpTunnel *tunnel;
NetworkConfigSection *section;
char *name;
uint32_t session_id;
uint32_t peer_session_id;
L2tpL2specType l2tp_l2spec_type;
} L2tpSession;
struct L2tpTunnel {
NetDev meta;
uint16_t l2tp_udp_sport;
uint16_t l2tp_udp_dport;
uint32_t tunnel_id;
uint32_t peer_tunnel_id;
int family;
bool udp_csum;
bool udp6_csum_rx;
bool udp6_csum_tx;
L2tpLocalAddressType local_address_type;
union in_addr_union local;
union in_addr_union remote;
L2tpEncapType l2tp_encap_type;
OrderedHashmap *sessions_by_section;
};
DEFINE_NETDEV_CAST(L2TP, L2tpTunnel);
extern const NetDevVTable l2tptnl_vtable;
CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_tunnel_address);
CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_tunnel_id);
CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_encap_type);
CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_session_l2spec);
CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_session_id);
CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_session_name);
+15
View File
@@ -20,6 +20,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
#include "netdev/vxcan.h"
#include "netdev/wireguard.h"
#include "netdev/fou-tunnel.h"
#include "netdev/l2tp-tunnel.h"
#include "vlan-util.h"
%}
struct ConfigPerfItem;
@@ -77,6 +78,20 @@ Tunnel.ISATAP, config_parse_tristate, 0,
FooOverUDP.Protocol, config_parse_uint8, 0, offsetof(FouTunnel, fou_protocol)
FooOverUDP.Encapsulation, config_parse_fou_encap_type, 0, offsetof(FouTunnel, fou_encap_type)
FooOverUDP.Port, config_parse_ip_port, 0, offsetof(FouTunnel, port)
L2TP.TunnelId, config_parse_l2tp_tunnel_id, 0, offsetof(L2tpTunnel, tunnel_id)
L2TP.PeerTunnelId, config_parse_l2tp_tunnel_id, 0, offsetof(L2tpTunnel, peer_tunnel_id)
L2TP.UDPSourcePort, config_parse_ip_port, 0, offsetof(L2tpTunnel, l2tp_udp_sport)
L2TP.UDPDestinationPort, config_parse_ip_port, 0, offsetof(L2tpTunnel, l2tp_udp_dport)
L2TP.Local, config_parse_l2tp_tunnel_address, 0, offsetof(L2tpTunnel, local)
L2TP.Remote, config_parse_l2tp_tunnel_address, 0, offsetof(L2tpTunnel, remote)
L2TP.EncapsulationType, config_parse_l2tp_encap_type, 0, offsetof(L2tpTunnel, l2tp_encap_type)
L2TP.UDPCheckSum, config_parse_bool, 0, offsetof(L2tpTunnel, udp_csum)
L2TP.UDP6CheckSumRx, config_parse_bool, 0, offsetof(L2tpTunnel, udp6_csum_rx)
L2TP.UDP6CheckSumTx, config_parse_bool, 0, offsetof(L2tpTunnel, udp6_csum_tx)
L2TPSession.SessionId, config_parse_l2tp_session_id, 0, 0
L2TPSession.PeerSessionId, config_parse_l2tp_session_id, 0, 0
L2TPSession.Layer2SpecificHeader, config_parse_l2tp_session_l2spec, 0, 0
L2TPSession.Name, config_parse_l2tp_session_name, 0, 0
Peer.Name, config_parse_ifname, 0, offsetof(Veth, ifname_peer)
Peer.MACAddress, config_parse_hwaddr, 0, offsetof(Veth, mac_peer)
VXCAN.Peer, config_parse_ifname, 0, offsetof(VxCan, ifname_peer)
+37 -29
View File
@@ -7,35 +7,35 @@
#include "conf-parser.h"
#include "fd-util.h"
#include "list.h"
#include "netdev/bond.h"
#include "netdev/bridge.h"
#include "netdev/dummy.h"
#include "netdev/fou-tunnel.h"
#include "netdev/geneve.h"
#include "netdev/ipvlan.h"
#include "netdev/l2tp-tunnel.h"
#include "netdev/macvlan.h"
#include "netdev/netdev.h"
#include "netdev/netdevsim.h"
#include "netdev/tunnel.h"
#include "netdev/tuntap.h"
#include "netdev/vcan.h"
#include "netdev/veth.h"
#include "netdev/vlan.h"
#include "netdev/vrf.h"
#include "netdev/vxcan.h"
#include "netdev/vxlan.h"
#include "netdev/wireguard.h"
#include "netlink-util.h"
#include "network-internal.h"
#include "netdev/netdev.h"
#include "networkd-manager.h"
#include "networkd-link.h"
#include "networkd-manager.h"
#include "siphash24.h"
#include "stat-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "netdev/bridge.h"
#include "netdev/bond.h"
#include "netdev/geneve.h"
#include "netdev/vlan.h"
#include "netdev/macvlan.h"
#include "netdev/ipvlan.h"
#include "netdev/vxlan.h"
#include "netdev/tunnel.h"
#include "netdev/tuntap.h"
#include "netdev/veth.h"
#include "netdev/dummy.h"
#include "netdev/vrf.h"
#include "netdev/vcan.h"
#include "netdev/vxcan.h"
#include "netdev/wireguard.h"
#include "netdev/netdevsim.h"
#include "netdev/fou-tunnel.h"
const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_BRIDGE] = &bridge_vtable,
[NETDEV_KIND_BOND] = &bond_vtable,
@@ -65,6 +65,7 @@ const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_NETDEVSIM] = &netdevsim_vtable,
[NETDEV_KIND_FOU] = &foutnl_vtable,
[NETDEV_KIND_ERSPAN] = &erspan_vtable,
[NETDEV_KIND_L2TP] = &l2tptnl_vtable,
};
static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
@@ -96,6 +97,7 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_NETDEVSIM] = "netdevsim",
[NETDEV_KIND_FOU] = "fou",
[NETDEV_KIND_ERSPAN] = "erspan",
[NETDEV_KIND_L2TP] = "l2tp",
};
DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
@@ -598,6 +600,14 @@ static int netdev_create(NetDev *netdev, Link *link, link_netlink_message_handle
return 0;
}
static int netdev_create_after_configured(NetDev *netdev, Link *link) {
assert(netdev);
assert(link);
assert(NETDEV_VTABLE(netdev)->create_after_configured);
return NETDEV_VTABLE(netdev)->create_after_configured(netdev, link);
}
/* the callback must be called, possibly after a timeout, as otherwise the Link will hang */
int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t callback) {
int r;
@@ -605,9 +615,8 @@ int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t callb
assert(netdev);
assert(netdev->manager);
assert(netdev->manager->rtnl);
assert(NETDEV_VTABLE(netdev));
switch (NETDEV_VTABLE(netdev)->create_type) {
switch (netdev_get_create_type(netdev)) {
case NETDEV_CREATE_MASTER:
r = netdev_enslave(netdev, link, callback);
if (r < 0)
@@ -620,6 +629,11 @@ int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t callb
return r;
break;
case NETDEV_CREATE_AFTER_CONFIGURED:
r = netdev_create_after_configured(netdev, link);
if (r < 0)
return r;
break;
default:
assert_not_reached("Can not join independent netdev");
}
@@ -740,16 +754,10 @@ int netdev_load_one(Manager *manager, const char *filename) {
log_netdev_debug(netdev, "loaded %s", netdev_kind_to_string(netdev->kind));
switch (NETDEV_VTABLE(netdev)->create_type) {
case NETDEV_CREATE_MASTER:
case NETDEV_CREATE_INDEPENDENT:
if (IN_SET(netdev_get_create_type(netdev), NETDEV_CREATE_MASTER, NETDEV_CREATE_INDEPENDENT)) {
r = netdev_create(netdev, NULL, NULL);
if (r < 0)
return r;
break;
default:
break;
}
switch (netdev->kind) {
+14
View File
@@ -46,6 +46,7 @@ typedef enum NetDevKind {
NETDEV_KIND_NETDEVSIM,
NETDEV_KIND_FOU,
NETDEV_KIND_ERSPAN,
NETDEV_KIND_L2TP,
_NETDEV_KIND_MAX,
_NETDEV_KIND_TUNNEL, /* Used by config_parse_stacked_netdev() */
_NETDEV_KIND_INVALID = -1
@@ -65,6 +66,7 @@ typedef enum NetDevCreateType {
NETDEV_CREATE_INDEPENDENT,
NETDEV_CREATE_MASTER,
NETDEV_CREATE_STACKED,
NETDEV_CREATE_AFTER_CONFIGURED,
_NETDEV_CREATE_MAX,
_NETDEV_CREATE_INVALID = -1,
} NetDevCreateType;
@@ -123,6 +125,9 @@ typedef struct NetDevVTable {
/* create netdev, if not done via rtnl */
int (*create)(NetDev *netdev);
/* create netdev after link is fully configured */
int (*create_after_configured)(NetDev *netdev, Link *link);
/* perform additional configuration after netdev has been createad */
int (*post_create)(NetDev *netdev, Link *link, sd_netlink_message *message);
@@ -162,10 +167,19 @@ int netdev_get(Manager *manager, const char *name, NetDev **ret);
int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *newlink);
int netdev_get_mac(const char *ifname, struct ether_addr **ret);
int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t cb);
int netdev_join_after_configured(NetDev *netdev, Link *link, link_netlink_message_handler_t callback);
const char *netdev_kind_to_string(NetDevKind d) _const_;
NetDevKind netdev_kind_from_string(const char *d) _pure_;
static inline NetDevCreateType netdev_get_create_type(NetDev *netdev) {
assert(netdev);
assert(NETDEV_VTABLE(netdev));
return NETDEV_VTABLE(netdev)->create_type;
}
CONFIG_PARSER_PROTOTYPE(config_parse_netdev_kind);
/* gperf */
+36 -3
View File
@@ -822,6 +822,35 @@ static Address* link_find_dhcp_server_address(Link *link) {
return NULL;
}
static int link_join_netdevs_after_configured(Link *link) {
NetDev *netdev;
Iterator i;
int r;
HASHMAP_FOREACH(netdev, link->network->stacked_netdevs, i) {
if (netdev->ifindex > 0)
/* Assume already enslaved. */
continue;
if (netdev_get_create_type(netdev) != NETDEV_CREATE_AFTER_CONFIGURED)
continue;
log_struct(LOG_DEBUG,
LOG_LINK_INTERFACE(link),
LOG_NETDEV_INTERFACE(netdev),
LOG_LINK_MESSAGE(link, "Enslaving by '%s'", netdev->ifname));
r = netdev_join(netdev, link, NULL);
if (r < 0)
return log_struct_errno(LOG_WARNING, r,
LOG_LINK_INTERFACE(link),
LOG_NETDEV_INTERFACE(netdev),
LOG_LINK_MESSAGE(link, "Could not join netdev '%s': %m", netdev->ifname));
}
return 0;
}
static void link_enter_configured(Link *link) {
assert(link);
assert(link->network);
@@ -833,6 +862,8 @@ static void link_enter_configured(Link *link) {
link_set_state(link, LINK_STATE_CONFIGURED);
(void) link_join_netdevs_after_configured(link);
link_dirty(link);
}
@@ -2681,10 +2712,12 @@ static int link_enter_join_netdev(Link *link) {
HASHMAP_FOREACH(netdev, link->network->stacked_netdevs, i) {
if (netdev->ifindex > 0) {
link_joined(link);
if (netdev->ifindex > 0)
/* Assume already enslaved. */
continue;
if (netdev_get_create_type(netdev) != NETDEV_CREATE_STACKED)
continue;
}
log_struct(LOG_DEBUG,
LOG_LINK_INTERFACE(link),
+1
View File
@@ -45,6 +45,7 @@ Network.MACVLAN, config_parse_stacked_netdev,
Network.MACVTAP, config_parse_stacked_netdev, NETDEV_KIND_MACVTAP, offsetof(Network, stacked_netdev_names)
Network.IPVLAN, config_parse_stacked_netdev, NETDEV_KIND_IPVLAN, offsetof(Network, stacked_netdev_names)
Network.VXLAN, config_parse_stacked_netdev, NETDEV_KIND_VXLAN, offsetof(Network, stacked_netdev_names)
Network.L2TP, config_parse_stacked_netdev, NETDEV_KIND_L2TP, offsetof(Network, stacked_netdev_names)
Network.Tunnel, config_parse_stacked_netdev, _NETDEV_KIND_TUNNEL, offsetof(Network, stacked_netdev_names)
Network.VRF, config_parse_ifname, 0, offsetof(Network, vrf_name)
Network.DHCP, config_parse_dhcp, 0, offsetof(Network, dhcp)
+2 -1
View File
@@ -697,7 +697,8 @@ int config_parse_stacked_netdev(const char *unit,
assert(data);
assert(IN_SET(kind,
NETDEV_KIND_VLAN, NETDEV_KIND_MACVLAN, NETDEV_KIND_MACVTAP,
NETDEV_KIND_IPVLAN, NETDEV_KIND_VXLAN, _NETDEV_KIND_TUNNEL));
NETDEV_KIND_IPVLAN, NETDEV_KIND_VXLAN, NETDEV_KIND_L2TP,
_NETDEV_KIND_TUNNEL));
if (!ifname_valid(rvalue)) {
log_syntax(unit, LOG_ERR, filename, line, 0,
+7 -1
View File
@@ -34,7 +34,13 @@ typedef struct sd_netlink sd_netlink;
typedef struct sd_genl_socket sd_genl_socket;
typedef struct sd_netlink_message sd_netlink_message;
typedef struct sd_netlink_slot sd_netlink_slot;
typedef enum {SD_GENL_ID_CTRL, SD_GENL_WIREGUARD, SD_GENL_FOU} sd_genl_family;
typedef enum sd_gen_family {
SD_GENL_ID_CTRL,
SD_GENL_WIREGUARD,
SD_GENL_FOU,
SD_GENL_L2TP,
} sd_genl_family;
/* callback */
@@ -157,3 +157,19 @@ MACAddress=
MTUBytes=
Description=
Name=
[L2TP]
TunnelId=
PeerTunnelId=
UDPSourcePort=
UDPDestinationPort=
Local=
Remote=
EncapsulationType=
UDPCheckSum=
UDP6CheckSumRx=
UDP6CheckSumTx=
[L2TPSession]
SessionId=
PeerSessionId=
Layer2SpecificHeader=
Name=
@@ -110,6 +110,7 @@ IPForward=
IPv6Token=
Description=
VXLAN=
L2TP=
LinkLocalAddressing=
ConfigureWithoutCarrier=
NTP=
@@ -0,0 +1,7 @@
[Match]
Name=test1
[Network]
Address=192.168.30.100/24
IPv6AcceptRA=false
L2TP=l2tp99
+20
View File
@@ -0,0 +1,20 @@
[NetDev]
Kind=l2tp
Name=l2tp99
[L2TP]
TunnelId=10
PeerTunnelId=12
Local=static
Remote=192.168.30.101
EncapsulationType=ip
[L2TPSession]
SessionId=25
PeerSessionId=26
Name=l2tp-ses3
[L2TPSession]
SessionId=27
PeerSessionId=28
Name=l2tp-ses4
+25
View File
@@ -0,0 +1,25 @@
[NetDev]
Kind=l2tp
Name=l2tp99
[L2TP]
TunnelId=10
PeerTunnelId=11
UDPSourcePort=3000
UDPDestinationPort=4000
Local=static
Remote=192.168.30.101
EncapsulationType=udp
UDPCheckSum=true
UDP6CheckSumRx=true
UDP6CheckSumTx=true
[L2TPSession]
SessionId=15
PeerSessionId=16
Name=l2tp-ses1
[L2TPSession]
SessionId=17
PeerSessionId=18
Name=l2tp-ses2
+91 -1
View File
@@ -108,6 +108,14 @@ class Utilities():
subprocess.call(['ip', 'link', 'del', 'dev', link])
time.sleep(1)
def l2tp_tunnel_remove(self, tunnel_ids):
output = subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel']).rstrip().decode('utf-8')
for tid in tunnel_ids:
words='Tunnel ' + tid + ', encap'
if words in output:
subprocess.call(['ip', 'l2tp', 'del', 'tunnel', 'tid', tid])
time.sleep(1)
def read_ipv6_sysctl_attr(self, link, attribute):
with open(os.path.join(os.path.join(network_sysctl_ipv6_path, link), attribute)) as f:
return f.readline().strip()
@@ -580,7 +588,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
self.assertTrue(self.link_exits('ipiptun99'))
def test_vxlan(self):
self.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network','11-dummy.netdev')
self.copy_unit_to_networkd_unit_path('25-vxlan.netdev', 'vxlan.network', '11-dummy.netdev')
self.start_networkd()
self.assertTrue(self.link_exits('vxlan99'))
@@ -598,6 +606,88 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
self.assertRegex(output, 'remcsumrx')
self.assertRegex(output, 'gbp')
class NetworkdL2TPTests(unittest.TestCase, Utilities):
links =[
'l2tp-ses1',
'l2tp-ses2',
'l2tp-ses3',
'l2tp-ses4',
'test1']
units = [
'11-dummy.netdev',
'25-l2tp-dummy.network',
'25-l2tp-ip.netdev',
'25-l2tp-udp.netdev']
l2tp_tunnel_ids = [ '10' ]
def setUp(self):
self.l2tp_tunnel_remove(self.l2tp_tunnel_ids)
self.link_remove(self.links)
def tearDown(self):
self.l2tp_tunnel_remove(self.l2tp_tunnel_ids)
self.link_remove(self.links)
self.remove_unit_from_networkd_path(self.units)
@expectedFailureIfModuleIsNotAvailable('l2tp_eth')
def test_l2tp_udp(self):
self.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-udp.netdev')
self.start_networkd()
self.assertTrue(self.link_exits('test1'))
self.assertTrue(self.link_exits('l2tp-ses1'))
self.assertTrue(self.link_exits('l2tp-ses2'))
output = subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Tunnel 10, encap UDP")
self.assertRegex(output, "From 192.168.30.100 to 192.168.30.101")
self.assertRegex(output, "Peer tunnel 11")
self.assertRegex(output, "UDP source / dest ports: 3000/4000")
self.assertRegex(output, "UDP checksum: enabled")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '15']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 15 in tunnel 10")
self.assertRegex(output, "Peer session 16, tunnel 11")
self.assertRegex(output, "interface name: l2tp-ses1")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '17']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 17 in tunnel 10")
self.assertRegex(output, "Peer session 18, tunnel 11")
self.assertRegex(output, "interface name: l2tp-ses2")
@expectedFailureIfModuleIsNotAvailable('l2tp_ip')
def test_l2tp_ip(self):
self.copy_unit_to_networkd_unit_path('11-dummy.netdev', '25-l2tp-dummy.network', '25-l2tp-ip.netdev')
self.start_networkd()
self.assertTrue(self.link_exits('test1'))
self.assertTrue(self.link_exits('l2tp-ses3'))
self.assertTrue(self.link_exits('l2tp-ses4'))
output = subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '10']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Tunnel 10, encap IP")
self.assertRegex(output, "From 192.168.30.100 to 192.168.30.101")
self.assertRegex(output, "Peer tunnel 12")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '25']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 25 in tunnel 10")
self.assertRegex(output, "Peer session 26, tunnel 12")
self.assertRegex(output, "interface name: l2tp-ses3")
output = subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tid', '10', 'session_id', '27']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "Session 27 in tunnel 10")
self.assertRegex(output, "Peer session 28, tunnel 12")
self.assertRegex(output, "interface name: l2tp-ses4")
class NetworkdNetWorkTests(unittest.TestCase, Utilities):
links = [
'bond199',