networkd: Introduce l2tp tunnel

This works allows networkd to configure l2tp tunnel.
See http://man7.org/linux/man-pages/man8/ip-l2tp.8.html
This commit is contained in:
Susant Sahani
2019-03-07 01:21:29 +05:30
committed by Yu Watanabe
parent 7033af49df
commit 3a56e697c8
14 changed files with 886 additions and 23 deletions

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,113 @@
</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. This address must be the address of a local interface. This option is compulsory.</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>

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) {

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 = {

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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
/* 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 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;
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);

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)

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);

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

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)

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,

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 */

View File

@@ -157,3 +157,19 @@ MACAddress=
MTUBytes=
Description=
Name=
[L2TP]
TunnelId=
PeerTunnelId=
UDPSourcePort=
UDPDestinationPort=
Local=
Remote=
EncapsulationType=
UDPCheckSum=
UDP6CheckSumRx=
UDP6CheckSumTx=
[L2TPSession]
SessionId=
PeerSessionId=
Layer2SpecificHeader=
Name=

View File

@@ -110,6 +110,7 @@ IPForward=
IPv6Token=
Description=
VXLAN=
L2TP=
LinkLocalAddressing=
ConfigureWithoutCarrier=
NTP=