1 /*****************************************************************************
2 * Linux PPP over L2TP (PPPoX/PPPoL2TP) Sockets
4 * PPPoX --- Generic PPP encapsulation socket family
5 * PPPoL2TP --- PPP over L2TP (RFC 2661)
9 * Authors: James Chapman (jchapman@katalix.com)
11 * Based on original work by Martijn van Oosterhout <kleptog@svana.org>
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
21 /* This driver handles only L2TP data frames; control frames are handled by a
22 * userspace application.
24 * To send data in an L2TP session, userspace opens a PPPoL2TP socket and
25 * attaches it to a bound UDP socket with local tunnel_id / session_id and
26 * peer tunnel_id / session_id set. Data can then be sent or received using
27 * regular socket sendmsg() / recvmsg() calls. Kernel parameters of the socket
28 * can be read or modified using ioctl() or [gs]etsockopt() calls.
30 * When a PPPoL2TP socket is connected with local and peer session_id values
31 * zero, the socket is treated as a special tunnel management socket.
33 * Here's example userspace code to create a socket for sending/receiving data
34 * over an L2TP session:-
36 * struct sockaddr_pppol2tp sax;
40 * fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
42 * sax.sa_family = AF_PPPOX;
43 * sax.sa_protocol = PX_PROTO_OL2TP;
44 * sax.pppol2tp.fd = tunnel_fd; // bound UDP socket
45 * sax.pppol2tp.addr.sin_addr.s_addr = addr->sin_addr.s_addr;
46 * sax.pppol2tp.addr.sin_port = addr->sin_port;
47 * sax.pppol2tp.addr.sin_family = AF_INET;
48 * sax.pppol2tp.s_tunnel = tunnel_id;
49 * sax.pppol2tp.s_session = session_id;
50 * sax.pppol2tp.d_tunnel = peer_tunnel_id;
51 * sax.pppol2tp.d_session = peer_session_id;
53 * session_fd = connect(fd, (struct sockaddr *)&sax, sizeof(sax));
55 * A pppd plugin that allows PPP traffic to be carried over L2TP using
56 * this driver is available from the OpenL2TP project at
57 * http://openl2tp.sourceforge.net.
60 #include <linux/module.h>
61 #include <linux/string.h>
62 #include <linux/list.h>
63 #include <linux/uaccess.h>
65 #include <linux/kernel.h>
66 #include <linux/spinlock.h>
67 #include <linux/kthread.h>
68 #include <linux/sched.h>
69 #include <linux/slab.h>
70 #include <linux/errno.h>
71 #include <linux/jiffies.h>
73 #include <linux/netdevice.h>
74 #include <linux/net.h>
75 #include <linux/inetdevice.h>
76 #include <linux/skbuff.h>
77 #include <linux/init.h>
79 #include <linux/udp.h>
80 #include <linux/if_pppox.h>
81 #include <linux/if_pppol2tp.h>
83 #include <linux/ppp_channel.h>
84 #include <linux/ppp_defs.h>
85 #include <linux/if_ppp.h>
86 #include <linux/file.h>
87 #include <linux/hash.h>
88 #include <linux/sort.h>
89 #include <linux/proc_fs.h>
90 #include <linux/l2tp.h>
91 #include <linux/nsproxy.h>
92 #include <net/net_namespace.h>
93 #include <net/netns/generic.h>
98 #include <net/inet_common.h>
100 #include <asm/byteorder.h>
101 #include <linux/atomic.h>
103 #include "l2tp_core.h"
105 #define PPPOL2TP_DRV_VERSION "V2.0"
107 /* Space for UDP, L2TP and PPP headers */
108 #define PPPOL2TP_HEADER_OVERHEAD 40
110 #define PRINTK(_mask, _type, _lvl, _fmt, args...) \
112 if ((_mask) & (_type)) \
113 printk(_lvl "PPPOL2TP: " _fmt, ##args); \
116 /* Number of bytes to build transmit L2TP headers.
117 * Unfortunately the size is different depending on whether sequence numbers
120 #define PPPOL2TP_L2TP_HDR_SIZE_SEQ 10
121 #define PPPOL2TP_L2TP_HDR_SIZE_NOSEQ 6
123 /* Private data of each session. This data lives at the end of struct
124 * l2tp_session, referenced via session->priv[].
126 struct pppol2tp_session {
127 int owner; /* pid that opened the socket */
129 struct sock *sock; /* Pointer to the session
131 struct sock *tunnel_sock; /* Pointer to the tunnel UDP
133 int flags; /* accessed by PPPIOCGFLAGS.
137 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb);
139 static const struct ppp_channel_ops pppol2tp_chan_ops = {
140 .start_xmit = pppol2tp_xmit,
143 static const struct proto_ops pppol2tp_ops;
145 /* Helpers to obtain tunnel/session contexts from sockets.
147 static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
149 struct l2tp_session *session;
155 session = (struct l2tp_session *)(sk->sk_user_data);
156 if (session == NULL) {
161 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
167 /*****************************************************************************
168 * Receive data handling
169 *****************************************************************************/
171 static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
173 /* Skip PPP header, if present. In testing, Microsoft L2TP clients
174 * don't send the PPP header (PPP header compression enabled), but
175 * other clients can include the header. So we cope with both cases
176 * here. The PPP header is always FF03 when using L2TP.
178 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
179 * the field may be unaligned.
181 if (!pskb_may_pull(skb, 2))
184 if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
190 /* Receive message. This is the recvmsg for the PPPoL2TP socket.
192 static int pppol2tp_recvmsg(struct kiocb *iocb, struct socket *sock,
193 struct msghdr *msg, size_t len,
198 struct sock *sk = sock->sk;
201 if (sk->sk_state & PPPOX_BOUND)
205 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
206 flags & MSG_DONTWAIT, &err);
212 else if (len < skb->len)
213 msg->msg_flags |= MSG_TRUNC;
215 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len);
216 if (likely(err == 0))
224 static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len)
226 struct pppol2tp_session *ps = l2tp_session_priv(session);
227 struct sock *sk = NULL;
229 /* If the socket is bound, send it in to PPP's input queue. Otherwise
230 * queue it on the session socket.
236 if (sk->sk_state & PPPOX_BOUND) {
237 struct pppox_sock *po;
238 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
239 "%s: recv %d byte data frame, passing to ppp\n",
240 session->name, data_len);
242 /* We need to forget all info related to the L2TP packet
243 * gathered in the skb as we are going to reuse the same
244 * skb for the inner packet.
246 * - reset xfrm (IPSec) information as it applies to
247 * the outer L2TP packet and not to the inner one
248 * - release the dst to force a route lookup on the inner
249 * IP packet since skb->dst currently points to the dst
251 * - reset netfilter information as it doesn't apply
252 * to the inner packet either
259 ppp_input(&po->chan, skb);
261 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
262 "%s: socket not bound\n", session->name);
264 /* Not bound. Nothing we can do, so discard. */
265 session->stats.rx_errors++;
272 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
273 "%s: no socket\n", session->name);
277 static void pppol2tp_session_sock_hold(struct l2tp_session *session)
279 struct pppol2tp_session *ps = l2tp_session_priv(session);
285 static void pppol2tp_session_sock_put(struct l2tp_session *session)
287 struct pppol2tp_session *ps = l2tp_session_priv(session);
293 /************************************************************************
295 ***********************************************************************/
297 /* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here
298 * when a user application does a sendmsg() on the session socket. L2TP and
299 * PPP headers must be inserted into the user's data.
301 static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
304 static const unsigned char ppph[2] = { 0xff, 0x03 };
305 struct sock *sk = sock->sk;
308 struct l2tp_session *session;
309 struct l2tp_tunnel *tunnel;
310 struct pppol2tp_session *ps;
314 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
317 /* Get session and tunnel contexts */
319 session = pppol2tp_sock_to_session(sk);
323 ps = l2tp_session_priv(session);
324 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
328 uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
330 /* Allocate a socket buffer */
332 skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) +
333 uhlen + session->hdr_len +
334 sizeof(ppph) + total_len,
337 goto error_put_sess_tun;
339 /* Reserve space for headers. */
340 skb_reserve(skb, NET_SKB_PAD);
341 skb_reset_network_header(skb);
342 skb_reserve(skb, sizeof(struct iphdr));
343 skb_reset_transport_header(skb);
344 skb_reserve(skb, uhlen);
347 skb->data[0] = ppph[0];
348 skb->data[1] = ppph[1];
351 /* Copy user data into skb */
352 error = memcpy_fromiovec(skb_put(skb, total_len), m->msg_iov,
356 goto error_put_sess_tun;
360 l2tp_xmit_skb(session, skb, session->hdr_len);
363 sock_put(ps->tunnel_sock);
369 sock_put(ps->tunnel_sock);
376 /* Transmit function called by generic PPP driver. Sends PPP frame
377 * over PPPoL2TP socket.
379 * This is almost the same as pppol2tp_sendmsg(), but rather than
380 * being called with a msghdr from userspace, it is called with a skb
383 * The supplied skb from ppp doesn't have enough headroom for the
384 * insertion of L2TP, UDP and IP headers so we need to allocate more
385 * headroom in the skb. This will create a cloned skb. But we must be
386 * careful in the error case because the caller will expect to free
387 * the skb it supplied, not our cloned skb. So we take care to always
388 * leave the original skb unfreed if we return an error.
390 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
392 static const u8 ppph[2] = { 0xff, 0x03 };
393 struct sock *sk = (struct sock *) chan->private;
395 struct l2tp_session *session;
396 struct l2tp_tunnel *tunnel;
397 struct pppol2tp_session *ps;
402 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
405 /* Get session and tunnel contexts from the socket */
406 session = pppol2tp_sock_to_session(sk);
410 ps = l2tp_session_priv(session);
411 sk_tun = ps->tunnel_sock;
414 tunnel = l2tp_sock_to_tunnel(sk_tun);
418 old_headroom = skb_headroom(skb);
419 uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
420 headroom = NET_SKB_PAD +
421 sizeof(struct iphdr) + /* IP header */
422 uhlen + /* UDP header (if L2TP_ENCAPTYPE_UDP) */
423 session->hdr_len + /* L2TP header */
424 sizeof(ppph); /* PPP header */
425 if (skb_cow_head(skb, headroom))
426 goto abort_put_sess_tun;
428 new_headroom = skb_headroom(skb);
429 skb->truesize += new_headroom - old_headroom;
431 /* Setup PPP header */
432 __skb_push(skb, sizeof(ppph));
433 skb->data[0] = ppph[0];
434 skb->data[1] = ppph[1];
437 l2tp_xmit_skb(session, skb, session->hdr_len);
449 /* Free the original skb */
454 /*****************************************************************************
455 * Session (and tunnel control) socket create/destroy.
456 *****************************************************************************/
458 /* Called by l2tp_core when a session socket is being closed.
460 static void pppol2tp_session_close(struct l2tp_session *session)
462 struct pppol2tp_session *ps = l2tp_session_priv(session);
463 struct sock *sk = ps->sock;
464 struct socket *sock = sk->sk_socket;
466 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
470 inet_shutdown(sock, 2);
472 /* Don't let the session go away before our socket does */
473 l2tp_session_inc_refcount(session);
477 /* Really kill the session socket. (Called from sock_put() if
480 static void pppol2tp_session_destruct(struct sock *sk)
482 struct l2tp_session *session;
484 if (sk->sk_user_data != NULL) {
485 session = sk->sk_user_data;
489 sk->sk_user_data = NULL;
490 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
491 l2tp_session_dec_refcount(session);
498 /* Called when the PPPoX socket (session) is closed.
500 static int pppol2tp_release(struct socket *sock)
502 struct sock *sk = sock->sk;
503 struct l2tp_session *session;
511 if (sock_flag(sk, SOCK_DEAD) != 0)
514 pppox_unbind_sock(sk);
516 /* Signal the death of the socket. */
517 sk->sk_state = PPPOX_DEAD;
521 session = pppol2tp_sock_to_session(sk);
523 /* Purge any queued data */
524 if (session != NULL) {
525 l2tp_session_queue_purge(session);
528 skb_queue_purge(&sk->sk_receive_queue);
529 skb_queue_purge(&sk->sk_write_queue);
533 /* This will delete the session context via
534 * pppol2tp_session_destruct() if the socket's refcnt drops to
546 static struct proto pppol2tp_sk_proto = {
548 .owner = THIS_MODULE,
549 .obj_size = sizeof(struct pppox_sock),
552 static int pppol2tp_backlog_recv(struct sock *sk, struct sk_buff *skb)
556 rc = l2tp_udp_encap_recv(sk, skb);
560 return NET_RX_SUCCESS;
563 /* socket() handler. Initialize a new struct sock.
565 static int pppol2tp_create(struct net *net, struct socket *sock)
570 sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto);
574 sock_init_data(sock, sk);
576 sock->state = SS_UNCONNECTED;
577 sock->ops = &pppol2tp_ops;
579 sk->sk_backlog_rcv = pppol2tp_backlog_recv;
580 sk->sk_protocol = PX_PROTO_OL2TP;
581 sk->sk_family = PF_PPPOX;
582 sk->sk_state = PPPOX_NONE;
583 sk->sk_type = SOCK_STREAM;
584 sk->sk_destruct = pppol2tp_session_destruct;
592 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
593 static void pppol2tp_show(struct seq_file *m, void *arg)
595 struct l2tp_session *session = arg;
596 struct pppol2tp_session *ps = l2tp_session_priv(session);
599 struct pppox_sock *po = pppox_sk(ps->sock);
601 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
606 /* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
608 static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
609 int sockaddr_len, int flags)
611 struct sock *sk = sock->sk;
612 struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr;
613 struct sockaddr_pppol2tpv3 *sp3 = (struct sockaddr_pppol2tpv3 *) uservaddr;
614 struct pppox_sock *po = pppox_sk(sk);
615 struct l2tp_session *session = NULL;
616 struct l2tp_tunnel *tunnel;
617 struct pppol2tp_session *ps;
618 struct dst_entry *dst;
619 struct l2tp_session_cfg cfg = { 0, };
621 u32 tunnel_id, peer_tunnel_id;
622 u32 session_id, peer_session_id;
623 bool drop_refcnt = false;
624 bool drop_tunnel = false;
631 if (sp->sa_protocol != PX_PROTO_OL2TP)
634 /* Check for already bound sockets */
636 if (sk->sk_state & PPPOX_CONNECTED)
639 /* We don't supporting rebinding anyway */
641 if (sk->sk_user_data)
642 goto end; /* socket is already attached */
644 /* Get params from socket address. Handle L2TPv2 and L2TPv3 */
645 if (sockaddr_len == sizeof(struct sockaddr_pppol2tp)) {
646 fd = sp->pppol2tp.fd;
647 tunnel_id = sp->pppol2tp.s_tunnel;
648 peer_tunnel_id = sp->pppol2tp.d_tunnel;
649 session_id = sp->pppol2tp.s_session;
650 peer_session_id = sp->pppol2tp.d_session;
651 } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3)) {
653 fd = sp3->pppol2tp.fd;
654 tunnel_id = sp3->pppol2tp.s_tunnel;
655 peer_tunnel_id = sp3->pppol2tp.d_tunnel;
656 session_id = sp3->pppol2tp.s_session;
657 peer_session_id = sp3->pppol2tp.d_session;
660 goto end; /* bad socket address */
663 /* Don't bind if tunnel_id is 0 */
668 tunnel = l2tp_tunnel_get(sock_net(sk), tunnel_id);
672 /* Special case: create tunnel context if session_id and
673 * peer_session_id is 0. Otherwise look up tunnel using supplied
676 if ((session_id == 0) && (peer_session_id == 0)) {
677 if (tunnel == NULL) {
678 struct l2tp_tunnel_cfg tcfg = {
679 .encap = L2TP_ENCAPTYPE_UDP,
682 error = l2tp_tunnel_create(sock_net(sk), fd, ver, tunnel_id, peer_tunnel_id, &tcfg, &tunnel);
687 /* Error if we can't find the tunnel */
692 /* Error if socket is not prepped */
693 if (tunnel->sock == NULL)
697 if (tunnel->recv_payload_hook == NULL)
698 tunnel->recv_payload_hook = pppol2tp_recv_payload_hook;
700 if (tunnel->peer_tunnel_id == 0) {
702 tunnel->peer_tunnel_id = sp->pppol2tp.d_tunnel;
704 tunnel->peer_tunnel_id = sp3->pppol2tp.d_tunnel;
707 session = l2tp_session_get(sock_net(sk), tunnel, session_id, false);
710 ps = l2tp_session_priv(session);
712 /* Using a pre-existing session is fine as long as it hasn't
713 * been connected yet.
720 /* consistency checks */
721 if (ps->tunnel_sock != tunnel->sock) {
726 /* Default MTU must allow space for UDP/L2TP/PPP headers */
727 cfg.mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
730 session = l2tp_session_create(sizeof(struct pppol2tp_session),
732 peer_session_id, &cfg);
733 if (IS_ERR(session)) {
734 error = PTR_ERR(session);
738 l2tp_session_inc_refcount(session);
739 error = l2tp_session_register(session, tunnel);
747 /* Associate session with its PPPoL2TP socket */
748 ps = l2tp_session_priv(session);
749 ps->owner = current->pid;
751 ps->tunnel_sock = tunnel->sock;
753 session->recv_skb = pppol2tp_recv;
754 session->session_close = pppol2tp_session_close;
755 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
756 session->show = pppol2tp_show;
759 /* We need to know each time a skb is dropped from the reorder
762 session->ref = pppol2tp_session_sock_hold;
763 session->deref = pppol2tp_session_sock_put;
765 /* If PMTU discovery was enabled, use the MTU that was discovered */
766 dst = sk_dst_get(tunnel->sock);
768 u32 pmtu = dst_mtu(dst);
771 session->mtu = session->mru = pmtu -
772 PPPOL2TP_HEADER_OVERHEAD;
776 /* Special case: if source & dest session_id == 0x0000, this
777 * socket is being created to manage the tunnel. Just set up
778 * the internal context for use by ioctl() and sockopt()
781 if ((session->session_id == 0) &&
782 (session->peer_session_id == 0)) {
787 /* The only header we need to worry about is the L2TP
788 * header. This size is different depending on whether
789 * sequence numbers are enabled for the data channel.
791 po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
793 po->chan.private = sk;
794 po->chan.ops = &pppol2tp_chan_ops;
795 po->chan.mtu = session->mtu;
797 error = ppp_register_net_channel(sock_net(sk), &po->chan);
802 /* This is how we get the session context from the socket. */
803 sk->sk_user_data = session;
804 sk->sk_state = PPPOX_CONNECTED;
805 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
806 "%s: created\n", session->name);
810 l2tp_session_dec_refcount(session);
812 l2tp_tunnel_dec_refcount(tunnel);
818 #ifdef CONFIG_L2TP_V3
820 /* Called when creating sessions via the netlink interface. */
821 static int pppol2tp_session_create(struct net *net, struct l2tp_tunnel *tunnel,
822 u32 session_id, u32 peer_session_id,
823 struct l2tp_session_cfg *cfg)
826 struct l2tp_session *session;
827 struct pppol2tp_session *ps;
829 /* Error if tunnel socket is not prepped */
835 /* Default MTU values. */
837 cfg->mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
841 /* Allocate and initialize a new session context. */
842 session = l2tp_session_create(sizeof(struct pppol2tp_session),
844 peer_session_id, cfg);
845 if (IS_ERR(session)) {
846 error = PTR_ERR(session);
850 ps = l2tp_session_priv(session);
851 ps->tunnel_sock = tunnel->sock;
853 error = l2tp_session_register(session, tunnel);
865 #endif /* CONFIG_L2TP_V3 */
867 /* getname() support.
869 static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
870 int *usockaddr_len, int peer)
874 struct l2tp_session *session;
875 struct l2tp_tunnel *tunnel;
876 struct sock *sk = sock->sk;
877 struct inet_sock *inet;
878 struct pppol2tp_session *pls;
883 if (sk->sk_state != PPPOX_CONNECTED)
887 session = pppol2tp_sock_to_session(sk);
891 pls = l2tp_session_priv(session);
892 tunnel = l2tp_sock_to_tunnel(pls->tunnel_sock);
896 inet = inet_sk(tunnel->sock);
897 if (tunnel->version == 2) {
898 struct sockaddr_pppol2tp sp;
901 sp.sa_family = AF_PPPOX;
902 sp.sa_protocol = PX_PROTO_OL2TP;
903 sp.pppol2tp.fd = tunnel->fd;
904 sp.pppol2tp.pid = pls->owner;
905 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
906 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
907 sp.pppol2tp.s_session = session->session_id;
908 sp.pppol2tp.d_session = session->peer_session_id;
909 sp.pppol2tp.addr.sin_family = AF_INET;
910 sp.pppol2tp.addr.sin_port = inet->inet_dport;
911 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
912 memcpy(uaddr, &sp, len);
913 } else if (tunnel->version == 3) {
914 struct sockaddr_pppol2tpv3 sp;
917 sp.sa_family = AF_PPPOX;
918 sp.sa_protocol = PX_PROTO_OL2TP;
919 sp.pppol2tp.fd = tunnel->fd;
920 sp.pppol2tp.pid = pls->owner;
921 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
922 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
923 sp.pppol2tp.s_session = session->session_id;
924 sp.pppol2tp.d_session = session->peer_session_id;
925 sp.pppol2tp.addr.sin_family = AF_INET;
926 sp.pppol2tp.addr.sin_port = inet->inet_dport;
927 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
928 memcpy(uaddr, &sp, len);
931 *usockaddr_len = len;
934 sock_put(pls->tunnel_sock);
941 /****************************************************************************
944 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
945 * sockets. However, in order to control kernel tunnel features, we allow
946 * userspace to create a special "tunnel" PPPoX socket which is used for
947 * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
948 * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
950 ****************************************************************************/
952 static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest,
953 struct l2tp_stats *stats)
955 dest->tx_packets = stats->tx_packets;
956 dest->tx_bytes = stats->tx_bytes;
957 dest->tx_errors = stats->tx_errors;
958 dest->rx_packets = stats->rx_packets;
959 dest->rx_bytes = stats->rx_bytes;
960 dest->rx_seq_discards = stats->rx_seq_discards;
961 dest->rx_oos_packets = stats->rx_oos_packets;
962 dest->rx_errors = stats->rx_errors;
965 /* Session ioctl helper.
967 static int pppol2tp_session_ioctl(struct l2tp_session *session,
968 unsigned int cmd, unsigned long arg)
974 struct pppol2tp_session *ps = l2tp_session_priv(session);
975 struct l2tp_tunnel *tunnel = session->tunnel;
976 struct pppol2tp_ioc_stats stats;
978 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
979 "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
980 session->name, cmd, arg);
991 if (!(sk->sk_state & PPPOX_CONNECTED))
995 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
997 ifr.ifr_mtu = session->mtu;
998 if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
1001 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1002 "%s: get mtu=%d\n", session->name, session->mtu);
1008 if (!(sk->sk_state & PPPOX_CONNECTED))
1012 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1015 session->mtu = ifr.ifr_mtu;
1017 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1018 "%s: set mtu=%d\n", session->name, session->mtu);
1024 if (!(sk->sk_state & PPPOX_CONNECTED))
1028 if (put_user(session->mru, (int __user *) arg))
1031 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1032 "%s: get mru=%d\n", session->name, session->mru);
1038 if (!(sk->sk_state & PPPOX_CONNECTED))
1042 if (get_user(val, (int __user *) arg))
1046 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1047 "%s: set mru=%d\n", session->name, session->mru);
1053 if (put_user(ps->flags, (int __user *) arg))
1056 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1057 "%s: get flags=%d\n", session->name, ps->flags);
1063 if (get_user(val, (int __user *) arg))
1066 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1067 "%s: set flags=%d\n", session->name, ps->flags);
1071 case PPPIOCGL2TPSTATS:
1073 if (!(sk->sk_state & PPPOX_CONNECTED))
1076 memset(&stats, 0, sizeof(stats));
1077 stats.tunnel_id = tunnel->tunnel_id;
1078 stats.session_id = session->session_id;
1079 pppol2tp_copy_stats(&stats, &session->stats);
1080 if (copy_to_user((void __user *) arg, &stats,
1083 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1084 "%s: get L2TP stats\n", session->name);
1098 /* Tunnel ioctl helper.
1100 * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
1101 * specifies a session_id, the session ioctl handler is called. This allows an
1102 * application to retrieve session stats via a tunnel socket.
1104 static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel *tunnel,
1105 unsigned int cmd, unsigned long arg)
1109 struct pppol2tp_ioc_stats stats;
1111 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1112 "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n",
1113 tunnel->name, cmd, arg);
1119 case PPPIOCGL2TPSTATS:
1121 if (!(sk->sk_state & PPPOX_CONNECTED))
1124 if (copy_from_user(&stats, (void __user *) arg,
1129 if (stats.session_id != 0) {
1130 /* resend to session ioctl handler */
1131 struct l2tp_session *session =
1132 l2tp_session_get(sock_net(sk), tunnel,
1133 stats.session_id, true);
1136 err = pppol2tp_session_ioctl(session, cmd,
1139 session->deref(session);
1140 l2tp_session_dec_refcount(session);
1147 stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
1149 pppol2tp_copy_stats(&stats, &tunnel->stats);
1150 if (copy_to_user((void __user *) arg, &stats, sizeof(stats))) {
1154 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1155 "%s: get L2TP stats\n", tunnel->name);
1169 /* Main ioctl() handler.
1170 * Dispatch to tunnel or session helpers depending on the socket.
1172 static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1175 struct sock *sk = sock->sk;
1176 struct l2tp_session *session;
1177 struct l2tp_tunnel *tunnel;
1178 struct pppol2tp_session *ps;
1185 if (sock_flag(sk, SOCK_DEAD) != 0)
1189 if ((sk->sk_user_data == NULL) ||
1190 (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
1193 /* Get session context from the socket */
1195 session = pppol2tp_sock_to_session(sk);
1196 if (session == NULL)
1199 /* Special case: if session's session_id is zero, treat ioctl as a
1202 ps = l2tp_session_priv(session);
1203 if ((session->session_id == 0) &&
1204 (session->peer_session_id == 0)) {
1206 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1210 err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
1211 sock_put(ps->tunnel_sock);
1215 err = pppol2tp_session_ioctl(session, cmd, arg);
1223 /*****************************************************************************
1224 * setsockopt() / getsockopt() support.
1226 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1227 * sockets. In order to control kernel tunnel features, we allow userspace to
1228 * create a special "tunnel" PPPoX socket which is used for control only.
1229 * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
1230 * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
1231 *****************************************************************************/
1233 /* Tunnel setsockopt() helper.
1235 static int pppol2tp_tunnel_setsockopt(struct sock *sk,
1236 struct l2tp_tunnel *tunnel,
1237 int optname, int val)
1242 case PPPOL2TP_SO_DEBUG:
1243 tunnel->debug = val;
1244 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1245 "%s: set debug=%x\n", tunnel->name, tunnel->debug);
1256 /* Session setsockopt helper.
1258 static int pppol2tp_session_setsockopt(struct sock *sk,
1259 struct l2tp_session *session,
1260 int optname, int val)
1263 struct pppol2tp_session *ps = l2tp_session_priv(session);
1266 case PPPOL2TP_SO_RECVSEQ:
1267 if ((val != 0) && (val != 1)) {
1271 session->recv_seq = val ? -1 : 0;
1272 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1273 "%s: set recv_seq=%d\n", session->name, session->recv_seq);
1276 case PPPOL2TP_SO_SENDSEQ:
1277 if ((val != 0) && (val != 1)) {
1281 session->send_seq = val ? -1 : 0;
1283 struct sock *ssk = ps->sock;
1284 struct pppox_sock *po = pppox_sk(ssk);
1285 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1286 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1288 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1289 "%s: set send_seq=%d\n", session->name, session->send_seq);
1292 case PPPOL2TP_SO_LNSMODE:
1293 if ((val != 0) && (val != 1)) {
1297 session->lns_mode = val ? -1 : 0;
1298 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1299 "%s: set lns_mode=%d\n", session->name, session->lns_mode);
1302 case PPPOL2TP_SO_DEBUG:
1303 session->debug = val;
1304 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1305 "%s: set debug=%x\n", session->name, session->debug);
1308 case PPPOL2TP_SO_REORDERTO:
1309 session->reorder_timeout = msecs_to_jiffies(val);
1310 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1311 "%s: set reorder_timeout=%d\n", session->name, session->reorder_timeout);
1322 /* Main setsockopt() entry point.
1323 * Does API checks, then calls either the tunnel or session setsockopt
1324 * handler, according to whether the PPPoL2TP socket is a for a regular
1325 * session or the special tunnel type.
1327 static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
1328 char __user *optval, unsigned int optlen)
1330 struct sock *sk = sock->sk;
1331 struct l2tp_session *session;
1332 struct l2tp_tunnel *tunnel;
1333 struct pppol2tp_session *ps;
1337 if (level != SOL_PPPOL2TP)
1340 if (optlen < sizeof(int))
1343 if (get_user(val, (int __user *)optval))
1347 if (sk->sk_user_data == NULL)
1350 /* Get session context from the socket */
1352 session = pppol2tp_sock_to_session(sk);
1353 if (session == NULL)
1356 /* Special case: if session_id == 0x0000, treat as operation on tunnel
1358 ps = l2tp_session_priv(session);
1359 if ((session->session_id == 0) &&
1360 (session->peer_session_id == 0)) {
1362 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1366 err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
1367 sock_put(ps->tunnel_sock);
1369 err = pppol2tp_session_setsockopt(sk, session, optname, val);
1377 /* Tunnel getsockopt helper. Called with sock locked.
1379 static int pppol2tp_tunnel_getsockopt(struct sock *sk,
1380 struct l2tp_tunnel *tunnel,
1381 int optname, int *val)
1386 case PPPOL2TP_SO_DEBUG:
1387 *val = tunnel->debug;
1388 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1389 "%s: get debug=%x\n", tunnel->name, tunnel->debug);
1400 /* Session getsockopt helper. Called with sock locked.
1402 static int pppol2tp_session_getsockopt(struct sock *sk,
1403 struct l2tp_session *session,
1404 int optname, int *val)
1409 case PPPOL2TP_SO_RECVSEQ:
1410 *val = session->recv_seq;
1411 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1412 "%s: get recv_seq=%d\n", session->name, *val);
1415 case PPPOL2TP_SO_SENDSEQ:
1416 *val = session->send_seq;
1417 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1418 "%s: get send_seq=%d\n", session->name, *val);
1421 case PPPOL2TP_SO_LNSMODE:
1422 *val = session->lns_mode;
1423 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1424 "%s: get lns_mode=%d\n", session->name, *val);
1427 case PPPOL2TP_SO_DEBUG:
1428 *val = session->debug;
1429 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1430 "%s: get debug=%d\n", session->name, *val);
1433 case PPPOL2TP_SO_REORDERTO:
1434 *val = (int) jiffies_to_msecs(session->reorder_timeout);
1435 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1436 "%s: get reorder_timeout=%d\n", session->name, *val);
1446 /* Main getsockopt() entry point.
1447 * Does API checks, then calls either the tunnel or session getsockopt
1448 * handler, according to whether the PPPoX socket is a for a regular session
1449 * or the special tunnel type.
1451 static int pppol2tp_getsockopt(struct socket *sock, int level,
1452 int optname, char __user *optval, int __user *optlen)
1454 struct sock *sk = sock->sk;
1455 struct l2tp_session *session;
1456 struct l2tp_tunnel *tunnel;
1459 struct pppol2tp_session *ps;
1461 if (level != SOL_PPPOL2TP)
1464 if (get_user(len, (int __user *) optlen))
1467 len = min_t(unsigned int, len, sizeof(int));
1473 if (sk->sk_user_data == NULL)
1476 /* Get the session context */
1478 session = pppol2tp_sock_to_session(sk);
1479 if (session == NULL)
1482 /* Special case: if session_id == 0x0000, treat as operation on tunnel */
1483 ps = l2tp_session_priv(session);
1484 if ((session->session_id == 0) &&
1485 (session->peer_session_id == 0)) {
1487 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1491 err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
1492 sock_put(ps->tunnel_sock);
1496 err = pppol2tp_session_getsockopt(sk, session, optname, &val);
1502 if (put_user(len, (int __user *) optlen))
1505 if (copy_to_user((void __user *) optval, &val, len))
1516 /*****************************************************************************
1517 * /proc filesystem for debug
1518 * Since the original pppol2tp driver provided /proc/net/pppol2tp for
1519 * L2TPv2, we dump only L2TPv2 tunnels and sessions here.
1520 *****************************************************************************/
1522 static unsigned int pppol2tp_net_id;
1524 #ifdef CONFIG_PROC_FS
1526 struct pppol2tp_seq_data {
1527 struct seq_net_private p;
1528 int tunnel_idx; /* current tunnel */
1529 int session_idx; /* index of session within current tunnel */
1530 struct l2tp_tunnel *tunnel;
1531 struct l2tp_session *session; /* NULL means get next tunnel */
1534 static void pppol2tp_next_tunnel(struct net *net, struct pppol2tp_seq_data *pd)
1537 pd->tunnel = l2tp_tunnel_find_nth(net, pd->tunnel_idx);
1540 if (pd->tunnel == NULL)
1543 /* Ignore L2TPv3 tunnels */
1544 if (pd->tunnel->version < 3)
1549 static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
1551 pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx, true);
1554 if (pd->session == NULL) {
1555 pd->session_idx = 0;
1556 pppol2tp_next_tunnel(net, pd);
1560 static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
1562 struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
1569 BUG_ON(m->private == NULL);
1571 net = seq_file_net(m);
1573 if (pd->tunnel == NULL)
1574 pppol2tp_next_tunnel(net, pd);
1576 pppol2tp_next_session(net, pd);
1578 /* NULL tunnel and session indicates end of list */
1579 if ((pd->tunnel == NULL) && (pd->session == NULL))
1586 static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
1592 static void pppol2tp_seq_stop(struct seq_file *p, void *v)
1597 static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
1599 struct l2tp_tunnel *tunnel = v;
1601 seq_printf(m, "\nTUNNEL '%s', %c %d\n",
1603 (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N',
1604 atomic_read(&tunnel->ref_count) - 1);
1605 seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n",
1607 (unsigned long long)tunnel->stats.tx_packets,
1608 (unsigned long long)tunnel->stats.tx_bytes,
1609 (unsigned long long)tunnel->stats.tx_errors,
1610 (unsigned long long)tunnel->stats.rx_packets,
1611 (unsigned long long)tunnel->stats.rx_bytes,
1612 (unsigned long long)tunnel->stats.rx_errors);
1615 static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
1617 struct l2tp_session *session = v;
1618 struct l2tp_tunnel *tunnel = session->tunnel;
1619 struct pppol2tp_session *ps = l2tp_session_priv(session);
1620 struct pppox_sock *po = pppox_sk(ps->sock);
1625 struct inet_sock *inet = inet_sk(tunnel->sock);
1626 ip = ntohl(inet->inet_saddr);
1627 port = ntohs(inet->inet_sport);
1630 seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
1631 "%04X/%04X %d %c\n",
1632 session->name, ip, port,
1634 session->session_id,
1635 tunnel->peer_tunnel_id,
1636 session->peer_session_id,
1638 (session == ps->sock->sk_user_data) ?
1640 seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
1641 session->mtu, session->mru,
1642 session->recv_seq ? 'R' : '-',
1643 session->send_seq ? 'S' : '-',
1644 session->lns_mode ? "LNS" : "LAC",
1646 jiffies_to_msecs(session->reorder_timeout));
1647 seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n",
1648 session->nr, session->ns,
1649 (unsigned long long)session->stats.tx_packets,
1650 (unsigned long long)session->stats.tx_bytes,
1651 (unsigned long long)session->stats.tx_errors,
1652 (unsigned long long)session->stats.rx_packets,
1653 (unsigned long long)session->stats.rx_bytes,
1654 (unsigned long long)session->stats.rx_errors);
1657 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
1660 static int pppol2tp_seq_show(struct seq_file *m, void *v)
1662 struct pppol2tp_seq_data *pd = v;
1664 /* display header on line 1 */
1665 if (v == SEQ_START_TOKEN) {
1666 seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
1667 seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
1668 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1669 seq_puts(m, " SESSION name, addr/port src-tid/sid "
1670 "dest-tid/sid state user-data-ok\n");
1671 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
1672 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1676 /* Show the tunnel or session context.
1679 pppol2tp_seq_tunnel_show(m, pd->tunnel);
1681 pppol2tp_seq_session_show(m, pd->session);
1682 if (pd->session->deref)
1683 pd->session->deref(pd->session);
1684 l2tp_session_dec_refcount(pd->session);
1691 static const struct seq_operations pppol2tp_seq_ops = {
1692 .start = pppol2tp_seq_start,
1693 .next = pppol2tp_seq_next,
1694 .stop = pppol2tp_seq_stop,
1695 .show = pppol2tp_seq_show,
1698 /* Called when our /proc file is opened. We allocate data for use when
1699 * iterating our tunnel / session contexts and store it in the private
1700 * data of the seq_file.
1702 static int pppol2tp_proc_open(struct inode *inode, struct file *file)
1704 return seq_open_net(inode, file, &pppol2tp_seq_ops,
1705 sizeof(struct pppol2tp_seq_data));
1708 static const struct file_operations pppol2tp_proc_fops = {
1709 .owner = THIS_MODULE,
1710 .open = pppol2tp_proc_open,
1712 .llseek = seq_lseek,
1713 .release = seq_release_net,
1716 #endif /* CONFIG_PROC_FS */
1718 /*****************************************************************************
1720 *****************************************************************************/
1722 static __net_init int pppol2tp_init_net(struct net *net)
1724 struct proc_dir_entry *pde;
1727 pde = proc_net_fops_create(net, "pppol2tp", S_IRUGO, &pppol2tp_proc_fops);
1737 static __net_exit void pppol2tp_exit_net(struct net *net)
1739 proc_net_remove(net, "pppol2tp");
1742 static struct pernet_operations pppol2tp_net_ops = {
1743 .init = pppol2tp_init_net,
1744 .exit = pppol2tp_exit_net,
1745 .id = &pppol2tp_net_id,
1748 /*****************************************************************************
1750 *****************************************************************************/
1752 static const struct proto_ops pppol2tp_ops = {
1754 .owner = THIS_MODULE,
1755 .release = pppol2tp_release,
1756 .bind = sock_no_bind,
1757 .connect = pppol2tp_connect,
1758 .socketpair = sock_no_socketpair,
1759 .accept = sock_no_accept,
1760 .getname = pppol2tp_getname,
1761 .poll = datagram_poll,
1762 .listen = sock_no_listen,
1763 .shutdown = sock_no_shutdown,
1764 .setsockopt = pppol2tp_setsockopt,
1765 .getsockopt = pppol2tp_getsockopt,
1766 .sendmsg = pppol2tp_sendmsg,
1767 .recvmsg = pppol2tp_recvmsg,
1768 .mmap = sock_no_mmap,
1769 .ioctl = pppox_ioctl,
1772 static const struct pppox_proto pppol2tp_proto = {
1773 .create = pppol2tp_create,
1774 .ioctl = pppol2tp_ioctl,
1775 .owner = THIS_MODULE,
1778 #ifdef CONFIG_L2TP_V3
1780 static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = {
1781 .session_create = pppol2tp_session_create,
1782 .session_delete = l2tp_session_delete,
1785 #endif /* CONFIG_L2TP_V3 */
1787 static int __init pppol2tp_init(void)
1791 err = register_pernet_device(&pppol2tp_net_ops);
1795 err = proto_register(&pppol2tp_sk_proto, 0);
1797 goto out_unregister_pppol2tp_pernet;
1799 err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
1801 goto out_unregister_pppol2tp_proto;
1803 #ifdef CONFIG_L2TP_V3
1804 err = l2tp_nl_register_ops(L2TP_PWTYPE_PPP, &pppol2tp_nl_cmd_ops);
1806 goto out_unregister_pppox;
1809 printk(KERN_INFO "PPPoL2TP kernel driver, %s\n",
1810 PPPOL2TP_DRV_VERSION);
1815 #ifdef CONFIG_L2TP_V3
1816 out_unregister_pppox:
1817 unregister_pppox_proto(PX_PROTO_OL2TP);
1819 out_unregister_pppol2tp_proto:
1820 proto_unregister(&pppol2tp_sk_proto);
1821 out_unregister_pppol2tp_pernet:
1822 unregister_pernet_device(&pppol2tp_net_ops);
1826 static void __exit pppol2tp_exit(void)
1828 #ifdef CONFIG_L2TP_V3
1829 l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP);
1831 unregister_pppox_proto(PX_PROTO_OL2TP);
1832 proto_unregister(&pppol2tp_sk_proto);
1833 unregister_pernet_device(&pppol2tp_net_ops);
1836 module_init(pppol2tp_init);
1837 module_exit(pppol2tp_exit);
1839 MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
1840 MODULE_DESCRIPTION("PPP over L2TP over UDP");
1841 MODULE_LICENSE("GPL");
1842 MODULE_VERSION(PPPOL2TP_DRV_VERSION);