iproute2: Introduce new commands for L2TPv3 unmanaged tunnels
Subsystems (3)
cover iproute2: Introduce new commands for L2TPv3 unmanaged tunnels
Add new iproute2 commands for L2TPv3 unmanaged tunnels. It requires L2TPv3 kernel support, patches for which have been submitted to netdev for review. These iproute2 changes should not be pulled into iproute2 until the kernel support is accepted. I am posting the iproute2 code now to let people play with L2TPv3 unmanaged tunnels.
To create an L2TPv3 ethernet pseudowire between local host 192.168.1.1 and peer 192.168.1.2, using IP addresses 10.5.1.1 and 10.5.1.2 for the tunnel endpoints:-
# modprobe l2tp_eth # modprobe l2tp_netlink
# ip l2tp add tunnel tunnel_id 1 peer_tunnel_id 1 udp_sport 5000 \ udp_dport 5000 encap udp local 192.168.1.1 remote 192.168.1.2 # ip l2tp add session tunnel_id 1 session_id 1 peer_session_id 1 # ifconfig -a # ip addr add 10.5.1.2/32 peer 10.5.1.1/32 dev l2tpeth0 # ifconfig l2tpeth0 up
Choose IP addresses to be the address of a local IP interface and that of the remote system. The IP addresses of the l2tpeth0 interface can be anything suitable.
Repeat the above at the peer, with ports, tunnel/session ids and IP addresses reversed. The tunnel and session IDs can be any non-zero 32-bit number, but the values must be reversed at the peer.
Host 1 Host2 udp_sport=5000 udp_sport=5001 udp_dport=5001 udp_dport=5000 tunnel_id=42 tunnel_id=45 peer_tunnel_id=45 peer_tunnel_id=42 session_id=128 session_id=5196755 peer_session_id=5196755 peer_session_id=128
When done at both ends of the tunnel, it should be possible to send data over the tunnel. e.g.
# ping 10.5.1.1
TODO:-
- Add more config params to control offset and sequence number options.
- Update man page to cover the new ip l2tp command set.
---
James Chapman (2):
iproute2: Add libnl support.
iproute2: Add support for static L2TPv3 tunnels.
Makefile | 2 include/linux/l2tp.h | 164 ++++++++++ ip/Makefile | 2 ip/ip.c | 3 ip/ip_common.h | 1 ip/ipl2tp.c | 815 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 984 insertions(+), 3 deletions(-) create mode 100644 include/linux/l2tp.h create mode 100644 ip/ipl2tp.c
RFC PATCH 1/2 iproute2: Add libnl support.
This patch links the ip utility with libnl, which must be separately installed. This lets new functionality use libnl to implement its netlink interfaces.
Package developers will need to add libnl to the iproute2 package dependencies.
--- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -33,7 +33,7 @@ CCOPTS = -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall CFLAGS = $(CCOPTS) -I../include $(DEFINES) YACCFLAGS = -d -t -v -LDLIBS += -L../lib -lnetlink -lutil +LDLIBS += -L../lib -lnetlink -lutil -lnl SUBDIRS=lib ip tc misc netem genl
RFC PATCH 2/2 iproute2: Add support for static L2TPv3 tunnels.
In reply to James ChapmanRequires kernel with L2TPv3 ethernet support.
This patch adds a new series of commands under "ip l2tp", to configure and show L2TPv3 static tunnels. Only L2TPv3 ethernet pseudowires are supported at the moment.
Usage: ip l2tp add tunnel
remote ADDR local ADDR
tunnel_id ID peer_tunnel_id ID
[ encap { ip | udp } ]
[ udp_sport PORT ] [ udp_dport PORT ]
ip l2tp add session
tunnel_id ID
session_id ID peer_session_id ID
[ cookie HEXSTR ] [ peer_cookie HEXSTR ]
[ offset OFFSET ] [ peer_offset OFFSET ]
ip l2tp del tunnel tunnel_id ID
ip l2tp del session tunnel_id ID session_id ID ip l2tp show tunnel [ tunnel_id ID ]
ip l2tp show session [ tunnel_id ID ] [ session_id ID ]
Where: NAME := STRING
ADDR := { IP_ADDRESS | any }
PORT := { 0..65535 }
ID := { 1..4294967295 }
HEXSTR := { 8 or 16 hex digits (4 / 8 bytes) }
---
include/linux/l2tp.h | 164 ++++++++++
ip/Makefile | 2
ip/ip.c | 3
ip/ip_common.h | 1
ip/ipl2tp.c | 815 ++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 983 insertions(+), 2 deletions(-)
create mode 100644 include/linux/l2tp.h
create mode 100644 ip/ipl2tp.cinclude/linux/l2tp.h new file +164 -0
@@ -0,0 +1,164 @@ +/* +* L2TP public kernel interfaces. +* +* Author: James Chapman <[email protected]> +*/ + +#ifndef _LINUX_L2TP_H_ +#define _LINUX_L2TP_H_ + +#include <linux/types.h> +#ifdef __KERNEL__ +#include <linux/socket.h> +#include <linux/in.h> +#else +#include <netinet/in.h> +#endif + +#define IPPROTO_L2TP 115 + +/** +* struct sockaddr_l2tpip - the sockaddr structure for L2TP-over-IP sockets +* @l2tp_family: address family number AF_L2TPIP. +* @l2tp_addr: protocol specific address information +* @l2tp_conn_id: connection id of tunnel +*/ +#define __SOCK_SIZE__ 16/* sizeof(struct sockaddr) */ +struct sockaddr_l2tpip { +/* The first fields must match struct sockaddr_in */ +sa_family_t l2tp_family;/* AF_INET */ +__be16 l2tp_unused;/* INET port number (unused) */ +struct in_addr l2tp_addr;/* Internet address */ + +__u32 l2tp_conn_id;/* Connection ID of tunnel */ + +/* Pad to size of `struct sockaddr'. */ +unsigned char __pad[sizeof (struct sockaddr ) -sizeof (sa_family_t) - +sizeof (__be16) -sizeof (struct in_addr ) - +sizeof (__u32)]; +}; + +/***************************************************************************** +* NETLINK_GENERIC netlink family. +*****************************************************************************/ + +/* +* Commands. +* Valid TLVs of each command are:- +* TUNNEL_CREATE - CONN_ID, pw_type, netns, ifname, ipinfo, udpinfo, udpcsum, vlanid +* TUNNEL_DELETE - CONN_ID +* TUNNEL_MODIFY - CONN_ID, udpcsum +* TUNNEL_GETSTATS - CONN_ID, (stats) +* TUNNEL_GET - CONN_ID, (...) +* SESSION_CREATE - SESSION_ID, PW_TYPE, offset, data_seq, cookie, peer_cookie, offset, l2spec +* SESSION_DELETE - SESSION_ID +* SESSION_MODIFY - SESSION_ID, data_seq +* SESSION_GET - SESSION_ID, (...) +* SESSION_GETSTATS - SESSION_ID, (stats) +* +*/ +enum { +L2TP_CMD_NOOP , +L2TP_CMD_TUNNEL_CREATE , +L2TP_CMD_TUNNEL_DELETE , +L2TP_CMD_TUNNEL_MODIFY , +L2TP_CMD_TUNNEL_GET , +L2TP_CMD_SESSION_CREATE , +L2TP_CMD_SESSION_DELETE , +L2TP_CMD_SESSION_MODIFY , +L2TP_CMD_SESSION_GET , + __L2TP_CMD_MAX, +}; + +#define L2TP_CMD_MAX (__L2TP_CMD_MAX - 1) + +/* +* ATTR types defined for L2TP +*/ +enum { +L2TP_ATTR_NONE ,/* no data */ +L2TP_ATTR_PW_TYPE ,/* u16, enum l2tp_pwtype */ +L2TP_ATTR_ENCAP_TYPE ,/* u16, enum l2tp_encap_type */ +L2TP_ATTR_OFFSET ,/* u16 */ +L2TP_ATTR_DATA_SEQ ,/* u16 */ +L2TP_ATTR_L2SPEC_TYPE ,/* u8, enum l2tp_l2spec_type */ +L2TP_ATTR_L2SPEC_LEN ,/* u8, enum l2tp_l2spec_type */ +L2TP_ATTR_PROTO_VERSION ,/* u8 */ +L2TP_ATTR_IFNAME ,/* string */ +L2TP_ATTR_CONN_ID ,/* u32 */ +L2TP_ATTR_PEER_CONN_ID ,/* u32 */ +L2TP_ATTR_SESSION_ID ,/* u32 */ +L2TP_ATTR_PEER_SESSION_ID ,/* u32 */ +L2TP_ATTR_UDP_CSUM ,/* flag */ +L2TP_ATTR_VLAN_ID ,/* u16 */ +L2TP_ATTR_COOKIE ,/* 0, 4 or 8 bytes */ +L2TP_ATTR_PEER_COOKIE ,/* 0, 4 or 8 bytes */ +L2TP_ATTR_DEBUG ,/* u32 */ +L2TP_ATTR_RECV_SEQ ,/* flag */ +L2TP_ATTR_SEND_SEQ ,/* flag */ +L2TP_ATTR_LNS_MODE ,/* flag */ +L2TP_ATTR_USING_IPSEC ,/* flag */ +L2TP_ATTR_RECV_TIMEOUT ,/* msec */ +L2TP_ATTR_FD ,/* int */ +L2TP_ATTR_IP_SADDR ,/* u32 */ +L2TP_ATTR_IP_DADDR ,/* u32 */ +L2TP_ATTR_UDP_SPORT ,/* u16 */ +L2TP_ATTR_UDP_DPORT ,/* u16 */ +L2TP_ATTR_MTU ,/* u16 */ +L2TP_ATTR_MRU ,/* u16 */ +L2TP_ATTR_STATS ,/* nested */ + __L2TP_ATTR_MAX, +}; + +#define L2TP_ATTR_MAX (__L2TP_ATTR_MAX - 1) + +/* Nested in L2TP_ATTR_STATS */ +enum { +L2TP_ATTR_STATS_NONE ,/* no data */ +L2TP_ATTR_TX_PACKETS ,/* u64 */ +L2TP_ATTR_TX_BYTES ,/* u64 */ +L2TP_ATTR_TX_ERRORS ,/* u64 */ +L2TP_ATTR_RX_PACKETS ,/* u64 */ +L2TP_ATTR_RX_BYTES ,/* u64 */ +L2TP_ATTR_RX_SEQ_DISCARDS ,/* u64 */ +L2TP_ATTR_RX_OOS_PACKETS ,/* u64 */ +L2TP_ATTR_RX_ERRORS ,/* u64 */ + __L2TP_ATTR_STATS_MAX, +}; + +#define L2TP_ATTR_STATS_MAX (__L2TP_ATTR_STATS_MAX - 1) + +enum l2tp_pwtype { +L2TP_PWTYPE_NONE =0x0000 , +L2TP_PWTYPE_ETH_VLAN =0x0004 , +L2TP_PWTYPE_ETH =0x0005 , +L2TP_PWTYPE_PPP =0x0007 , +L2TP_PWTYPE_PPP_AC =0x0008 , +L2TP_PWTYPE_IP =0x000b , + __L2TP_PWTYPE_MAX +}; + +enum l2tp_l2spec_type { +L2TP_L2SPECTYPE_NONE , +L2TP_L2SPECTYPE_DEFAULT , +}; + +enum l2tp_encap_type { +L2TP_ENCAPTYPE_UDP , +L2TP_ENCAPTYPE_IP , +}; + + +enum l2tp_seqmode { +L2TP_SEQ_NONE =0 , +L2TP_SEQ_IP =1 , +L2TP_SEQ_ALL =2 , +}; + +/* +* NETLINK_GENERIC related info +*/ +#define L2TP_GENL_NAME "l2tp" +#define L2TP_GENL_VERSION 0x1 + +#endif
ip/Makefile +1 -1
@@ -3,7 +3,7 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o \ ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o iptuntap.o \ ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o \ iplink_vlan.o link_veth.o link_gre.o iplink_can.o \ - iplink_macvlan.o + iplink_macvlan.o ipl2tp.o RTMONOBJ=rtmon.o
ip/ip.c +2 -1
@@ -42,7 +42,7 @@ static void usage(void)"Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }\n" " ip [ -force ] -batch filename\n" "where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |\n" -" tunnel | tuntap | maddr | mroute | monitor | xfrm }\n" +" tunnel | tuntap | maddr | mroute | monitor | xfrm | l2tp }\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" " -f[amily] { inet | inet6 | ipx | dnet | link } |\n" " -o[neline] | -t[imestamp] | -b[atch] [filename] |\n"
@@ -73,6 +73,7 @@ static const struct cmd { { "tunl", do_iptunnel }, { "tuntap", do_iptuntap }, { "tap", do_iptuntap }, + { "l2tp", do_ipl2tp }, { "monitor", do_ipmonitor }, { "xfrm", do_xfrm }, { "mroute", do_multiroute },
ip/ip_common.h +1 -0
@@ -38,6 +38,7 @@ extern int do_ipmonitor(int argc, char **argv);extern int do_multiaddr (int argc,char **argv);extern int do_multiroute (int argc,char **argv);extern int do_xfrm (int argc,char **argv); +extern int do_ipl2tp (int argc,char **argv);static inline int rtm_get_table (struct rtmsg *r,struct rtattr **tb) {
ip/ipl2tp.c new file +815 -0
815 lines not on this page · raw message