From 939a415a7dc6a59d4c4a4d8f9e7519bb142cf4a0 Mon Sep 17 00:00:00 2001 From: knakahara Date: Thu, 16 Feb 2017 08:12:43 +0000 Subject: [PATCH] add l2tp(4) L2TPv3 interface. originally implemented by IIJ SEIL team. --- distrib/sets/lists/comp/mi | 5 ++++- distrib/sets/lists/modules/mi | 4 +++- sys/conf/files | 5 ++++- sys/modules/Makefile | 3 ++- sys/net/Makefile | 4 ++-- sys/net/files.net | 5 ++++- sys/net/if_bridge.c | 17 ++++++++++------- sys/net/if_types.h | 3 ++- sys/netinet/Makefile | 4 ++-- sys/netinet/in.h | 3 ++- sys/netinet/in_proto.c | 14 ++++++++++++-- sys/netinet/ip_var.h | 5 +++-- sys/netinet6/Makefile | 4 ++-- sys/netinet6/in6_ifattach.c | 5 +++-- sys/netinet6/in6_proto.c | 14 ++++++++++++-- 15 files changed, 67 insertions(+), 28 deletions(-) diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index e4148672b194..feddf31e7d8b 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.2108 2017/02/08 03:44:40 kamil Exp $ +# $NetBSD: mi,v 1.2109 2017/02/16 08:12:43 knakahara Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. ./etc/mtree/set.comp comp-sys-root @@ -2215,6 +2215,7 @@ ./usr/include/net/if_hippi.h comp-c-include ./usr/include/net/if_ieee1394.h comp-c-include ./usr/include/net/if_ieee80211.h comp-obsolete obsolete +./usr/include/net/if_l2tp.h comp-c-include ./usr/include/net/if_llc.h comp-c-include ./usr/include/net/if_media.h comp-c-include ./usr/include/net/if_mpls.h comp-c-include @@ -2296,6 +2297,7 @@ ./usr/include/netinet/igmp_var.h comp-c-include ./usr/include/netinet/in.h comp-c-include ./usr/include/netinet/in_gif.h comp-c-include +./usr/include/netinet/in_l2tp.h comp-c-include ./usr/include/netinet/in_pcb.h comp-c-include ./usr/include/netinet/in_pcb_hdr.h comp-c-include ./usr/include/netinet/in_route.h comp-obsolete obsolete @@ -2349,6 +2351,7 @@ ./usr/include/netinet6/in6_gif.h comp-c-include ./usr/include/netinet6/in6_ifattach.h comp-c-include ./usr/include/netinet6/in6_pcb.h comp-c-include +./usr/include/netinet6/in6_l2tp.h comp-c-include ./usr/include/netinet6/in6_var.h comp-c-include ./usr/include/netinet6/ip6.h comp-obsolete obsolete ./usr/include/netinet6/ip6_mroute.h comp-c-include diff --git a/distrib/sets/lists/modules/mi b/distrib/sets/lists/modules/mi index d3417b451a31..66518fa48817 100644 --- a/distrib/sets/lists/modules/mi +++ b/distrib/sets/lists/modules/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.107 2017/01/04 15:45:18 christos Exp $ +# $NetBSD: mi,v 1.108 2017/02/16 08:12:43 knakahara Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -150,6 +150,8 @@ ./@MODULEDIR@/if_gif/if_gif.kmod base-kernel-modules kmod ./@MODULEDIR@/if_gre base-kernel-modules kmod ./@MODULEDIR@/if_gre/if_gre.kmod base-kernel-modules kmod +./@MODULEDIR@/if_l2tp base-kernel-modules kmod +./@MODULEDIR@/if_l2tp/if_l2tp.kmod base-kernel-modules kmod ./@MODULEDIR@/if_loop base-kernel-modules kmod ./@MODULEDIR@/if_loop/if_loop.kmod base-kernel-modules kmod ./@MODULEDIR@/if_mpls base-kernel-modules kmod diff --git a/sys/conf/files b/sys/conf/files index 6c2fb7337871..dca28d10b195 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.1169 2017/02/02 19:50:35 macallan Exp $ +# $NetBSD: files,v 1.1170 2017/02/16 08:12:43 knakahara Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 version 20150846 @@ -120,6 +120,8 @@ defflag opt_fileassoc.h FILEASSOC defflag opt_gre.h GRE_DEBUG +defparam opt_l2tp.h L2TP_ID_HASH_SIZE + # Write Ahead Physical Block Logging defflag opt_wapbl.h WAPBL WAPBL_DEBUG defparam opt_wapbl.h WAPBL_DEBUG_PRINT @@ -1435,6 +1437,7 @@ defpseudo stf: ifnet defpseudodev tap: ifnet, ether, arp defpseudo carp: ifnet, ether, arp defpseudodev etherip: ifnet, ether, arp +defpseudodev l2tp: ifnet, ether, arp defpseudo sequencer defpseudo clockctl diff --git a/sys/modules/Makefile b/sys/modules/Makefile index ec39f429e5dd..40a293bab51f 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.188 2016/12/15 06:48:14 pgoyette Exp $ +# $NetBSD: Makefile,v 1.189 2017/02/16 08:12:43 knakahara Exp $ .include @@ -55,6 +55,7 @@ SUBDIR+= if_axen SUBDIR+= if_faith SUBDIR+= if_gif SUBDIR+= if_gre +SUBDIR+= if_l2tp SUBDIR+= if_loop SUBDIR+= if_mpls SUBDIR+= if_npflog diff --git a/sys/net/Makefile b/sys/net/Makefile index 7ba90fae47ed..847ced6a25d2 100644 --- a/sys/net/Makefile +++ b/sys/net/Makefile @@ -1,11 +1,11 @@ -# $NetBSD: Makefile,v 1.32 2012/10/27 22:36:14 alnsn Exp $ +# $NetBSD: Makefile,v 1.33 2017/02/16 08:12:44 knakahara Exp $ INCSDIR= /usr/include/net INCS= bpf.h bpfjit.h bpfdesc.h dlt.h ethertypes.h if.h if_arc.h if_arp.h \ if_atm.h if_bridgevar.h if_dl.h if_ether.h if_etherip.h if_fddi.h if_gif.h \ if_gre.h if_hippi.h if_ieee1394.h if_llc.h if_media.h if_mpls.h \ - if_pflog.h if_ppp.h if_pppoe.h if_sppp.h if_srt.h if_stf.h \ + if_pflog.h if_ppp.h if_pppoe.h if_l2tp.h if_sppp.h if_srt.h if_stf.h \ if_tap.h if_token.h if_tun.h if_types.h if_vlanvar.h net_stats.h \ netisr.h pfil.h pfkeyv2.h pfvar.h ppp-comp.h ppp_defs.h radix.h \ raw_cb.h route.h slcompress.h slip.h zlib.h diff --git a/sys/net/files.net b/sys/net/files.net index 981ed353244a..12c89cc46969 100644 --- a/sys/net/files.net +++ b/sys/net/files.net @@ -1,4 +1,4 @@ -# $NetBSD: files.net,v 1.12 2017/02/02 02:52:10 ozaki-r Exp $ +# $NetBSD: files.net,v 1.13 2017/02/16 08:12:44 knakahara Exp $ # XXX CLEANUP define net @@ -23,6 +23,7 @@ file net/if_gre.c gre needs-flag file net/if_hippisubr.c hippi needs-flag file net/if_ieee1394subr.c ieee1394 file net/if_llatbl.c inet | inet6 +file net/if_l2tp.c l2tp needs-flag file net/if_loop.c loop file net/if_media.c net file net/if_mpls.c mpls needs-flag @@ -58,6 +59,7 @@ file netinet/if_atm.c atm file netinet/in4_cksum.c inet file netinet/in_cksum.c inet file netinet/in_gif.c gif & inet +file netinet/in_l2tp.c l2tp & inet file netinet/ip_carp.c carp & (inet | inet6) needs-flag file netinet/ip_ecn.c ipsec | gif | stf file netinet/ip_encap.c inet | inet6 @@ -65,6 +67,7 @@ file netinet/ip_etherip.c etherip & inet file netinet/wqinput.c inet | inet6 file netinet6/ip6_etherip.c etherip & inet6 file netinet6/in6_gif.c gif & inet6 +file netinet6/in6_l2tp.c l2tp & inet6 include "net/agr/files.agr" diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index d481a63c9b3d..57cb3d219967 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_bridge.c,v 1.132 2017/01/23 10:19:03 ozaki-r Exp $ */ +/* $NetBSD: if_bridge.c,v 1.133 2017/02/16 08:12:44 knakahara Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -80,7 +80,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.132 2017/01/23 10:19:03 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.133 2017/02/16 08:12:44 knakahara Exp $"); #ifdef _KERNEL_OPT #include "opt_bridge_ipf.h" @@ -735,11 +735,6 @@ bridge_ioctl_add(struct bridge_softc *sc, void *arg) if (ifs == NULL) return (ENOENT); - if (sc->sc_if.if_mtu != ifs->if_mtu) { - error = EINVAL; - goto out; - } - if (ifs->if_bridge == sc) { error = EEXIST; goto out; @@ -765,6 +760,12 @@ bridge_ioctl_add(struct bridge_softc *sc, void *arg) switch (ifs->if_type) { case IFT_ETHER: + if (sc->sc_if.if_mtu != ifs->if_mtu) { + error = EINVAL; + goto out; + } + /* FALLTHROUGH */ + case IFT_L2TP: if ((error = ether_enable_vlan_mtu(ifs)) > 0) goto out; /* @@ -840,6 +841,7 @@ bridge_ioctl_del(struct bridge_softc *sc, void *arg) switch (ifs->if_type) { case IFT_ETHER: + case IFT_L2TP: /* * Take the interface out of promiscuous mode. * Don't call it with holding a spin lock. @@ -898,6 +900,7 @@ bridge_ioctl_sifflags(struct bridge_softc *sc, void *arg) if (req->ifbr_ifsflags & IFBIF_STP) { switch (bif->bif_ifp->if_type) { case IFT_ETHER: + case IFT_L2TP: /* These can do spanning tree. */ break; diff --git a/sys/net/if_types.h b/sys/net/if_types.h index eff6d53f8e66..6c8f8b11ed41 100644 --- a/sys/net/if_types.h +++ b/sys/net/if_types.h @@ -1,4 +1,4 @@ -/* $NetBSD: if_types.h,v 1.26 2012/08/05 21:21:41 wiz Exp $ */ +/* $NetBSD: if_types.h,v 1.27 2017/02/16 08:12:44 knakahara Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -263,6 +263,7 @@ #define IFT_FAITH 0xf2 #define IFT_PFLOG 0xf5 /* Packet filter logging */ #define IFT_PFSYNC 0xf6 /* Packet filter state syncing */ +#define IFT_L2TP 0xf7 /* L2TPv3 I/F */ #define IFT_CARP 0xf8 /* Common Address Redundancy Protocol */ #endif /* !_NET_IF_TYPES_H_ */ diff --git a/sys/netinet/Makefile b/sys/netinet/Makefile index 17f500c2032a..b72d946a893f 100644 --- a/sys/netinet/Makefile +++ b/sys/netinet/Makefile @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.27 2015/10/13 21:28:35 rjs Exp $ +# $NetBSD: Makefile,v 1.28 2017/02/16 08:12:44 knakahara Exp $ INCSDIR= /usr/include/netinet INCS= dccp.h icmp6.h icmp_var.h if_atm.h if_ether.h if_inarp.h igmp.h \ - igmp_var.h in.h in_gif.h in_pcb.h in_pcb_hdr.h \ + igmp_var.h in.h in_gif.h in_l2tp.h in_pcb.h in_pcb_hdr.h \ in_selsrc.h in_systm.h \ in_var.h ip.h ip_carp.h ip6.h ip_ecn.h ip_encap.h \ ip_icmp.h ip_mroute.h ip_var.h pim.h pim_var.h portalgo.h \ diff --git a/sys/netinet/in.h b/sys/netinet/in.h index 85ac10d1f1e4..c92f378584e0 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $NetBSD: in.h,v 1.99 2016/08/01 03:15:30 ozaki-r Exp $ */ +/* $NetBSD: in.h,v 1.100 2017/02/16 08:12:44 knakahara Exp $ */ /* * Copyright (c) 1982, 1986, 1990, 1993 @@ -105,6 +105,7 @@ typedef __sa_family_t sa_family_t; #define IPPROTO_IPCOMP 108 /* IP Payload Comp. Protocol */ #define IPPROTO_VRRP 112 /* VRRP RFC 2338 */ #define IPPROTO_CARP 112 /* Common Address Resolution Protocol */ +#define IPPROTO_L2TP 115 /* L2TPv3 */ #define IPPROTO_SCTP 132 /* SCTP */ #define IPPROTO_PFSYNC 240 /* PFSYNC */ #define IPPROTO_RAW 255 /* raw IP packet */ diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 22beefc51382..7db46afd4720 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $NetBSD: in_proto.c,v 1.121 2017/02/13 07:18:20 ozaki-r Exp $ */ +/* $NetBSD: in_proto.c,v 1.122 2017/02/16 08:12:44 knakahara Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.121 2017/02/13 07:18:20 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.122 2017/02/16 08:12:44 knakahara Exp $"); #ifdef _KERNEL_OPT #include "opt_mrouting.h" @@ -360,6 +360,16 @@ const struct protosw inetsw[] = { .pr_init = carp_init, }, #endif /* NCARP > 0 */ +{ .pr_type = SOCK_RAW, + .pr_domain = &inetdomain, + .pr_protocol = IPPROTO_L2TP, + .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR, + .pr_input = encap4_input, + .pr_ctlinput = rip_ctlinput, + .pr_ctloutput = rip_ctloutput, + .pr_usrreqs = &rip_usrreqs, /*XXX*/ + .pr_init = encap_init, +}, #if NPFSYNC > 0 { .pr_type = SOCK_RAW, .pr_domain = &inetdomain, diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 5d5b5a7942d5..5baf7c5afd71 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: ip_var.h,v 1.116 2016/12/08 05:16:33 ozaki-r Exp $ */ +/* $NetBSD: ip_var.h,v 1.117 2017/02/16 08:12:44 knakahara Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -157,8 +157,9 @@ struct ip_moptions { #define IP_STAT_TOOLONG 27 /* ip length > max ip packet size */ #define IP_STAT_NOGIF 28 /* no match gif found */ #define IP_STAT_BADADDR 29 /* invalid address on header */ +#define IP_STAT_NOL2TP 30 /* no match l2tp found */ -#define IP_NSTATS 30 +#define IP_NSTATS 31 #ifdef _KERNEL diff --git a/sys/netinet6/Makefile b/sys/netinet6/Makefile index 189a43acab9f..b973ed3dccdd 100644 --- a/sys/netinet6/Makefile +++ b/sys/netinet6/Makefile @@ -1,8 +1,8 @@ -# $NetBSD: Makefile,v 1.8 2012/01/06 14:17:11 drochner Exp $ +# $NetBSD: Makefile,v 1.9 2017/02/16 08:12:44 knakahara Exp $ INCSDIR= /usr/include/netinet6 -INCS= in6.h in6_gif.h in6_ifattach.h in6_pcb.h \ +INCS= in6.h in6_gif.h in6_l2tp.h in6_ifattach.h in6_pcb.h \ in6_var.h ip6_mroute.h ip6_var.h ip6protosw.h \ mld6_var.h nd6.h pim6.h pim6_var.h \ raw_ip6.h udp6.h udp6_var.h diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index 8a0bcd3ef499..909da6a578a2 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6_ifattach.c,v 1.110 2017/01/24 07:09:25 ozaki-r Exp $ */ +/* $NetBSD: in6_ifattach.c,v 1.111 2017/02/16 08:12:44 knakahara Exp $ */ /* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.110 2017/01/24 07:09:25 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.111 2017/02/16 08:12:44 knakahara Exp $"); #include #include @@ -712,6 +712,7 @@ in6_ifattach(struct ifnet *ifp, struct ifnet *altifp) /* some of the interfaces are inherently not IPv6 capable */ switch (ifp->if_type) { case IFT_BRIDGE: + case IFT_L2TP: #ifdef IFT_PFLOG case IFT_PFLOG: #endif diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index b160c8bba99b..856c8c714bfe 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6_proto.c,v 1.115 2017/02/13 07:18:20 ozaki-r Exp $ */ +/* $NetBSD: in6_proto.c,v 1.116 2017/02/16 08:12:44 knakahara Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.115 2017/02/13 07:18:20 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.116 2017/02/16 08:12:44 knakahara Exp $"); #ifdef _KERNEL_OPT #include "opt_gateway.h" @@ -388,6 +388,16 @@ const struct ip6protosw inet6sw[] = { .pr_usrreqs = &rip6_usrreqs, }, #endif /* NCARP */ +{ .pr_type = SOCK_RAW, + .pr_domain = &inet6domain, + .pr_protocol = IPPROTO_L2TP, + .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR, + .pr_input = encap6_input, + .pr_ctlinput = rip6_ctlinput, + .pr_ctloutput = rip6_ctloutput, + .pr_usrreqs = &rip6_usrreqs, + .pr_init = encap_init, +}, { .pr_type = SOCK_RAW, .pr_domain = &inet6domain, .pr_protocol = IPPROTO_PIM,