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>
99 #include <asm/byteorder.h>
100 #include <linux/atomic.h>
102 #include "l2tp_core.h"
104 #define PPPOL2TP_DRV_VERSION "V2.0"
106 /* Space for UDP, L2TP and PPP headers */
107 #define PPPOL2TP_HEADER_OVERHEAD 40
109 #define PRINTK(_mask, _type, _lvl, _fmt, args...) \
111 if ((_mask) & (_type)) \
112 printk(_lvl "PPPOL2TP: " _fmt, ##args); \
115 /* Number of bytes to build transmit L2TP headers.
116 * Unfortunately the size is different depending on whether sequence numbers
119 #define PPPOL2TP_L2TP_HDR_SIZE_SEQ 10
120 #define PPPOL2TP_L2TP_HDR_SIZE_NOSEQ 6
122 /* Private data of each session. This data lives at the end of struct
123 * l2tp_session, referenced via session->priv[].
125 struct pppol2tp_session {
126 int owner; /* pid that opened the socket */
128 struct sock *sock; /* Pointer to the session
130 struct sock *tunnel_sock; /* Pointer to the tunnel UDP
132 int flags; /* accessed by PPPIOCGFLAGS.
136 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb);
138 static const struct ppp_channel_ops pppol2tp_chan_ops = {
139 .start_xmit = pppol2tp_xmit,
142 static const struct proto_ops pppol2tp_ops;
144 /* Helpers to obtain tunnel/session contexts from sockets.
146 static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
148 struct l2tp_session *session;
154 session = (struct l2tp_session *)(sk->sk_user_data);
155 if (session == NULL) {
160 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
166 /*****************************************************************************
167 * Receive data handling
168 *****************************************************************************/
170 static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
172 /* Skip PPP header, if present. In testing, Microsoft L2TP clients
173 * don't send the PPP header (PPP header compression enabled), but
174 * other clients can include the header. So we cope with both cases
175 * here. The PPP header is always FF03 when using L2TP.
177 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
178 * the field may be unaligned.
180 if (!pskb_may_pull(skb, 2))
183 if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
189 /* Receive message. This is the recvmsg for the PPPoL2TP socket.
191 static int pppol2tp_recvmsg(struct kiocb *iocb, struct socket *sock,
192 struct msghdr *msg, size_t len,
197 struct sock *sk = sock->sk;
200 if (sk->sk_state & PPPOX_BOUND)
204 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
205 flags & MSG_DONTWAIT, &err);
211 else if (len < skb->len)
212 msg->msg_flags |= MSG_TRUNC;
214 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len);
215 if (likely(err == 0))
223 static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len)
225 struct pppol2tp_session *ps = l2tp_session_priv(session);
226 struct sock *sk = NULL;
228 /* If the socket is bound, send it in to PPP's input queue. Otherwise
229 * queue it on the session socket.
235 if (sk->sk_state & PPPOX_BOUND) {
236 struct pppox_sock *po;
237 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
238 "%s: recv %d byte data frame, passing to ppp\n",
239 session->name, data_len);
241 /* We need to forget all info related to the L2TP packet
242 * gathered in the skb as we are going to reuse the same
243 * skb for the inner packet.
245 * - reset xfrm (IPSec) information as it applies to
246 * the outer L2TP packet and not to the inner one
247 * - release the dst to force a route lookup on the inner
248 * IP packet since skb->dst currently points to the dst
250 * - reset netfilter information as it doesn't apply
251 * to the inner packet either
258 ppp_input(&po->chan, skb);
260 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
261 "%s: socket not bound\n", session->name);
263 /* Not bound. Nothing we can do, so discard. */
264 session->stats.rx_errors++;
271 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
272 "%s: no socket\n", session->name);
276 static void pppol2tp_session_sock_hold(struct l2tp_session *session)
278 struct pppol2tp_session *ps = l2tp_session_priv(session);
284 static void pppol2tp_session_sock_put(struct l2tp_session *session)
286 struct pppol2tp_session *ps = l2tp_session_priv(session);
292 /************************************************************************
294 ***********************************************************************/
296 /* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here
297 * when a user application does a sendmsg() on the session socket. L2TP and
298 * PPP headers must be inserted into the user's data.
300 static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
303 static const unsigned char ppph[2] = { 0xff, 0x03 };
304 struct sock *sk = sock->sk;
307 struct l2tp_session *session;
308 struct l2tp_tunnel *tunnel;
309 struct pppol2tp_session *ps;
313 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
316 /* Get session and tunnel contexts */
318 session = pppol2tp_sock_to_session(sk);
322 ps = l2tp_session_priv(session);
323 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
327 uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
329 /* Allocate a socket buffer */
331 skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) +
332 uhlen + session->hdr_len +
333 sizeof(ppph) + total_len,
336 goto error_put_sess_tun;
338 /* Reserve space for headers. */
339 skb_reserve(skb, NET_SKB_PAD);
340 skb_reset_network_header(skb);
341 skb_reserve(skb, sizeof(struct iphdr));
342 skb_reset_transport_header(skb);
343 skb_reserve(skb, uhlen);
346 skb->data[0] = ppph[0];
347 skb->data[1] = ppph[1];
350 /* Copy user data into skb */
351 error = memcpy_fromiovec(skb_put(skb, total_len), m->msg_iov,
355 goto error_put_sess_tun;
359 l2tp_xmit_skb(session, skb, session->hdr_len);
362 sock_put(ps->tunnel_sock);
368 sock_put(ps->tunnel_sock);
375 /* Transmit function called by generic PPP driver. Sends PPP frame
376 * over PPPoL2TP socket.
378 * This is almost the same as pppol2tp_sendmsg(), but rather than
379 * being called with a msghdr from userspace, it is called with a skb
382 * The supplied skb from ppp doesn't have enough headroom for the
383 * insertion of L2TP, UDP and IP headers so we need to allocate more
384 * headroom in the skb. This will create a cloned skb. But we must be
385 * careful in the error case because the caller will expect to free
386 * the skb it supplied, not our cloned skb. So we take care to always
387 * leave the original skb unfreed if we return an error.
389 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
391 static const u8 ppph[2] = { 0xff, 0x03 };
392 struct sock *sk = (struct sock *) chan->private;
394 struct l2tp_session *session;
395 struct l2tp_tunnel *tunnel;
396 struct pppol2tp_session *ps;
401 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
404 /* Get session and tunnel contexts from the socket */
405 session = pppol2tp_sock_to_session(sk);
409 ps = l2tp_session_priv(session);
410 sk_tun = ps->tunnel_sock;
413 tunnel = l2tp_sock_to_tunnel(sk_tun);
417 old_headroom = skb_headroom(skb);
418 uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
419 headroom = NET_SKB_PAD +
420 sizeof(struct iphdr) + /* IP header */
421 uhlen + /* UDP header (if L2TP_ENCAPTYPE_UDP) */
422 session->hdr_len + /* L2TP header */
423 sizeof(ppph); /* PPP header */
424 if (skb_cow_head(skb, headroom))
425 goto abort_put_sess_tun;
427 new_headroom = skb_headroom(skb);
428 skb->truesize += new_headroom - old_headroom;
430 /* Setup PPP header */
431 __skb_push(skb, sizeof(ppph));
432 skb->data[0] = ppph[0];
433 skb->data[1] = ppph[1];
436 l2tp_xmit_skb(session, skb, session->hdr_len);
448 /* Free the original skb */
453 /*****************************************************************************
454 * Session (and tunnel control) socket create/destroy.
455 *****************************************************************************/
457 /* Called by l2tp_core when a session socket is being closed.
459 static void pppol2tp_session_close(struct l2tp_session *session)
461 struct pppol2tp_session *ps = l2tp_session_priv(session);
462 struct sock *sk = ps->sock;
465 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
467 if (session->session_id == 0)
473 if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
474 pppox_unbind_sock(sk);
475 sk->sk_state = PPPOX_DEAD;
476 sk->sk_state_change(sk);
479 /* Purge any queued data */
480 skb_queue_purge(&sk->sk_receive_queue);
481 skb_queue_purge(&sk->sk_write_queue);
482 while ((skb = skb_dequeue(&session->reorder_q))) {
494 /* Really kill the session socket. (Called from sock_put() if
497 static void pppol2tp_session_destruct(struct sock *sk)
499 struct l2tp_session *session;
501 if (sk->sk_user_data != NULL) {
502 session = sk->sk_user_data;
506 sk->sk_user_data = NULL;
507 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
508 l2tp_session_dec_refcount(session);
515 /* Called when the PPPoX socket (session) is closed.
517 static int pppol2tp_release(struct socket *sock)
519 struct sock *sk = sock->sk;
520 struct l2tp_session *session;
528 if (sock_flag(sk, SOCK_DEAD) != 0)
531 pppox_unbind_sock(sk);
533 /* Signal the death of the socket. */
534 sk->sk_state = PPPOX_DEAD;
538 session = pppol2tp_sock_to_session(sk);
540 /* Purge any queued data */
541 skb_queue_purge(&sk->sk_receive_queue);
542 skb_queue_purge(&sk->sk_write_queue);
543 if (session != NULL) {
545 while ((skb = skb_dequeue(&session->reorder_q))) {
554 /* This will delete the session context via
555 * pppol2tp_session_destruct() if the socket's refcnt drops to
567 static struct proto pppol2tp_sk_proto = {
569 .owner = THIS_MODULE,
570 .obj_size = sizeof(struct pppox_sock),
573 static int pppol2tp_backlog_recv(struct sock *sk, struct sk_buff *skb)
577 rc = l2tp_udp_encap_recv(sk, skb);
581 return NET_RX_SUCCESS;
584 /* socket() handler. Initialize a new struct sock.
586 static int pppol2tp_create(struct net *net, struct socket *sock)
591 sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto);
595 sock_init_data(sock, sk);
597 sock->state = SS_UNCONNECTED;
598 sock->ops = &pppol2tp_ops;
600 sk->sk_backlog_rcv = pppol2tp_backlog_recv;
601 sk->sk_protocol = PX_PROTO_OL2TP;
602 sk->sk_family = PF_PPPOX;
603 sk->sk_state = PPPOX_NONE;
604 sk->sk_type = SOCK_STREAM;
605 sk->sk_destruct = pppol2tp_session_destruct;
613 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
614 static void pppol2tp_show(struct seq_file *m, void *arg)
616 struct l2tp_session *session = arg;
617 struct pppol2tp_session *ps = l2tp_session_priv(session);
620 struct pppox_sock *po = pppox_sk(ps->sock);
622 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
627 /* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
629 static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
630 int sockaddr_len, int flags)
632 struct sock *sk = sock->sk;
633 struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr;
634 struct sockaddr_pppol2tpv3 *sp3 = (struct sockaddr_pppol2tpv3 *) uservaddr;
635 struct pppox_sock *po = pppox_sk(sk);
636 struct l2tp_session *session = NULL;
637 struct l2tp_tunnel *tunnel;
638 struct pppol2tp_session *ps;
639 struct dst_entry *dst;
640 struct l2tp_session_cfg cfg = { 0, };
642 u32 tunnel_id, peer_tunnel_id;
643 u32 session_id, peer_session_id;
650 if (sp->sa_protocol != PX_PROTO_OL2TP)
653 /* Check for already bound sockets */
655 if (sk->sk_state & PPPOX_CONNECTED)
658 /* We don't supporting rebinding anyway */
660 if (sk->sk_user_data)
661 goto end; /* socket is already attached */
663 /* Get params from socket address. Handle L2TPv2 and L2TPv3 */
664 if (sockaddr_len == sizeof(struct sockaddr_pppol2tp)) {
665 fd = sp->pppol2tp.fd;
666 tunnel_id = sp->pppol2tp.s_tunnel;
667 peer_tunnel_id = sp->pppol2tp.d_tunnel;
668 session_id = sp->pppol2tp.s_session;
669 peer_session_id = sp->pppol2tp.d_session;
670 } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3)) {
672 fd = sp3->pppol2tp.fd;
673 tunnel_id = sp3->pppol2tp.s_tunnel;
674 peer_tunnel_id = sp3->pppol2tp.d_tunnel;
675 session_id = sp3->pppol2tp.s_session;
676 peer_session_id = sp3->pppol2tp.d_session;
679 goto end; /* bad socket address */
682 /* Don't bind if tunnel_id is 0 */
687 tunnel = l2tp_tunnel_find(sock_net(sk), tunnel_id);
689 /* Special case: create tunnel context if session_id and
690 * peer_session_id is 0. Otherwise look up tunnel using supplied
693 if ((session_id == 0) && (peer_session_id == 0)) {
694 if (tunnel == NULL) {
695 struct l2tp_tunnel_cfg tcfg = {
696 .encap = L2TP_ENCAPTYPE_UDP,
699 error = l2tp_tunnel_create(sock_net(sk), fd, ver, tunnel_id, peer_tunnel_id, &tcfg, &tunnel);
704 /* Error if we can't find the tunnel */
709 /* Error if socket is not prepped */
710 if (tunnel->sock == NULL)
714 if (tunnel->recv_payload_hook == NULL)
715 tunnel->recv_payload_hook = pppol2tp_recv_payload_hook;
717 if (tunnel->peer_tunnel_id == 0) {
719 tunnel->peer_tunnel_id = sp->pppol2tp.d_tunnel;
721 tunnel->peer_tunnel_id = sp3->pppol2tp.d_tunnel;
724 /* Create session if it doesn't already exist. We handle the
725 * case where a session was previously created by the netlink
726 * interface by checking that the session doesn't already have
727 * a socket and its tunnel socket are what we expect. If any
728 * of those checks fail, return EEXIST to the caller.
730 session = l2tp_session_find(sock_net(sk), tunnel, session_id);
731 if (session == NULL) {
732 /* Default MTU must allow space for UDP/L2TP/PPP
735 cfg.mtu = cfg.mru = 1500 - PPPOL2TP_HEADER_OVERHEAD;
737 /* Allocate and initialize a new session context. */
738 session = l2tp_session_create(sizeof(struct pppol2tp_session),
740 peer_session_id, &cfg);
741 if (session == NULL) {
746 ps = l2tp_session_priv(session);
748 if (ps->sock != NULL)
751 /* consistency checks */
752 if (ps->tunnel_sock != tunnel->sock)
756 /* Associate session with its PPPoL2TP socket */
757 ps = l2tp_session_priv(session);
758 ps->owner = current->pid;
760 ps->tunnel_sock = tunnel->sock;
762 session->recv_skb = pppol2tp_recv;
763 session->session_close = pppol2tp_session_close;
764 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
765 session->show = pppol2tp_show;
768 /* We need to know each time a skb is dropped from the reorder
771 session->ref = pppol2tp_session_sock_hold;
772 session->deref = pppol2tp_session_sock_put;
774 /* If PMTU discovery was enabled, use the MTU that was discovered */
775 dst = sk_dst_get(tunnel->sock);
777 u32 pmtu = dst_mtu(dst);
780 session->mtu = session->mru = pmtu -
781 PPPOL2TP_HEADER_OVERHEAD;
785 /* Special case: if source & dest session_id == 0x0000, this
786 * socket is being created to manage the tunnel. Just set up
787 * the internal context for use by ioctl() and sockopt()
790 if ((session->session_id == 0) &&
791 (session->peer_session_id == 0)) {
796 /* The only header we need to worry about is the L2TP
797 * header. This size is different depending on whether
798 * sequence numbers are enabled for the data channel.
800 po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
802 po->chan.private = sk;
803 po->chan.ops = &pppol2tp_chan_ops;
804 po->chan.mtu = session->mtu;
806 error = ppp_register_net_channel(sock_net(sk), &po->chan);
811 /* This is how we get the session context from the socket. */
812 sk->sk_user_data = session;
813 sk->sk_state = PPPOX_CONNECTED;
814 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
815 "%s: created\n", session->name);
823 #ifdef CONFIG_L2TP_V3
825 /* Called when creating sessions via the netlink interface.
827 static int pppol2tp_session_create(struct net *net, u32 tunnel_id, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
830 struct l2tp_tunnel *tunnel;
831 struct l2tp_session *session;
832 struct pppol2tp_session *ps;
834 tunnel = l2tp_tunnel_find(net, tunnel_id);
836 /* Error if we can't find the tunnel */
841 /* Error if tunnel socket is not prepped */
842 if (tunnel->sock == NULL)
845 /* Check that this session doesn't already exist */
847 session = l2tp_session_find(net, tunnel, session_id);
851 /* Default MTU values. */
853 cfg->mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
857 /* Allocate and initialize a new session context. */
859 session = l2tp_session_create(sizeof(struct pppol2tp_session),
861 peer_session_id, cfg);
865 ps = l2tp_session_priv(session);
866 ps->tunnel_sock = tunnel->sock;
868 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
869 "%s: created\n", session->name);
877 /* Called when deleting sessions via the netlink interface.
879 static int pppol2tp_session_delete(struct l2tp_session *session)
881 struct pppol2tp_session *ps = l2tp_session_priv(session);
883 if (ps->sock == NULL)
884 l2tp_session_dec_refcount(session);
889 #endif /* CONFIG_L2TP_V3 */
891 /* getname() support.
893 static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
894 int *usockaddr_len, int peer)
898 struct l2tp_session *session;
899 struct l2tp_tunnel *tunnel;
900 struct sock *sk = sock->sk;
901 struct inet_sock *inet;
902 struct pppol2tp_session *pls;
907 if (sk->sk_state != PPPOX_CONNECTED)
911 session = pppol2tp_sock_to_session(sk);
915 pls = l2tp_session_priv(session);
916 tunnel = l2tp_sock_to_tunnel(pls->tunnel_sock);
920 inet = inet_sk(tunnel->sock);
921 if (tunnel->version == 2) {
922 struct sockaddr_pppol2tp sp;
925 sp.sa_family = AF_PPPOX;
926 sp.sa_protocol = PX_PROTO_OL2TP;
927 sp.pppol2tp.fd = tunnel->fd;
928 sp.pppol2tp.pid = pls->owner;
929 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
930 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
931 sp.pppol2tp.s_session = session->session_id;
932 sp.pppol2tp.d_session = session->peer_session_id;
933 sp.pppol2tp.addr.sin_family = AF_INET;
934 sp.pppol2tp.addr.sin_port = inet->inet_dport;
935 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
936 memcpy(uaddr, &sp, len);
937 } else if (tunnel->version == 3) {
938 struct sockaddr_pppol2tpv3 sp;
941 sp.sa_family = AF_PPPOX;
942 sp.sa_protocol = PX_PROTO_OL2TP;
943 sp.pppol2tp.fd = tunnel->fd;
944 sp.pppol2tp.pid = pls->owner;
945 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
946 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
947 sp.pppol2tp.s_session = session->session_id;
948 sp.pppol2tp.d_session = session->peer_session_id;
949 sp.pppol2tp.addr.sin_family = AF_INET;
950 sp.pppol2tp.addr.sin_port = inet->inet_dport;
951 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
952 memcpy(uaddr, &sp, len);
955 *usockaddr_len = len;
958 sock_put(pls->tunnel_sock);
965 /****************************************************************************
968 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
969 * sockets. However, in order to control kernel tunnel features, we allow
970 * userspace to create a special "tunnel" PPPoX socket which is used for
971 * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
972 * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
974 ****************************************************************************/
976 static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest,
977 struct l2tp_stats *stats)
979 dest->tx_packets = stats->tx_packets;
980 dest->tx_bytes = stats->tx_bytes;
981 dest->tx_errors = stats->tx_errors;
982 dest->rx_packets = stats->rx_packets;
983 dest->rx_bytes = stats->rx_bytes;
984 dest->rx_seq_discards = stats->rx_seq_discards;
985 dest->rx_oos_packets = stats->rx_oos_packets;
986 dest->rx_errors = stats->rx_errors;
989 /* Session ioctl helper.
991 static int pppol2tp_session_ioctl(struct l2tp_session *session,
992 unsigned int cmd, unsigned long arg)
998 struct pppol2tp_session *ps = l2tp_session_priv(session);
999 struct l2tp_tunnel *tunnel = session->tunnel;
1000 struct pppol2tp_ioc_stats stats;
1002 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1003 "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
1004 session->name, cmd, arg);
1012 if (!(sk->sk_state & PPPOX_CONNECTED))
1016 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1018 ifr.ifr_mtu = session->mtu;
1019 if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
1022 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1023 "%s: get mtu=%d\n", session->name, session->mtu);
1029 if (!(sk->sk_state & PPPOX_CONNECTED))
1033 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1036 session->mtu = ifr.ifr_mtu;
1038 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1039 "%s: set mtu=%d\n", session->name, session->mtu);
1045 if (!(sk->sk_state & PPPOX_CONNECTED))
1049 if (put_user(session->mru, (int __user *) arg))
1052 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1053 "%s: get mru=%d\n", session->name, session->mru);
1059 if (!(sk->sk_state & PPPOX_CONNECTED))
1063 if (get_user(val, (int __user *) arg))
1067 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1068 "%s: set mru=%d\n", session->name, session->mru);
1074 if (put_user(ps->flags, (int __user *) arg))
1077 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1078 "%s: get flags=%d\n", session->name, ps->flags);
1084 if (get_user(val, (int __user *) arg))
1087 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1088 "%s: set flags=%d\n", session->name, ps->flags);
1092 case PPPIOCGL2TPSTATS:
1094 if (!(sk->sk_state & PPPOX_CONNECTED))
1097 memset(&stats, 0, sizeof(stats));
1098 stats.tunnel_id = tunnel->tunnel_id;
1099 stats.session_id = session->session_id;
1100 pppol2tp_copy_stats(&stats, &session->stats);
1101 if (copy_to_user((void __user *) arg, &stats,
1104 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1105 "%s: get L2TP stats\n", session->name);
1119 /* Tunnel ioctl helper.
1121 * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
1122 * specifies a session_id, the session ioctl handler is called. This allows an
1123 * application to retrieve session stats via a tunnel socket.
1125 static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel *tunnel,
1126 unsigned int cmd, unsigned long arg)
1130 struct pppol2tp_ioc_stats stats;
1132 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1133 "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n",
1134 tunnel->name, cmd, arg);
1140 case PPPIOCGL2TPSTATS:
1142 if (!(sk->sk_state & PPPOX_CONNECTED))
1145 if (copy_from_user(&stats, (void __user *) arg,
1150 if (stats.session_id != 0) {
1151 /* resend to session ioctl handler */
1152 struct l2tp_session *session =
1153 l2tp_session_get(sock_net(sk), tunnel,
1154 stats.session_id, true);
1157 err = pppol2tp_session_ioctl(session, cmd,
1160 session->deref(session);
1161 l2tp_session_dec_refcount(session);
1168 stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
1170 pppol2tp_copy_stats(&stats, &tunnel->stats);
1171 if (copy_to_user((void __user *) arg, &stats, sizeof(stats))) {
1175 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1176 "%s: get L2TP stats\n", tunnel->name);
1190 /* Main ioctl() handler.
1191 * Dispatch to tunnel or session helpers depending on the socket.
1193 static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1196 struct sock *sk = sock->sk;
1197 struct l2tp_session *session;
1198 struct l2tp_tunnel *tunnel;
1199 struct pppol2tp_session *ps;
1206 if (sock_flag(sk, SOCK_DEAD) != 0)
1210 if ((sk->sk_user_data == NULL) ||
1211 (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
1214 /* Get session context from the socket */
1216 session = pppol2tp_sock_to_session(sk);
1217 if (session == NULL)
1220 /* Special case: if session's session_id is zero, treat ioctl as a
1223 ps = l2tp_session_priv(session);
1224 if ((session->session_id == 0) &&
1225 (session->peer_session_id == 0)) {
1227 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1231 err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
1232 sock_put(ps->tunnel_sock);
1236 err = pppol2tp_session_ioctl(session, cmd, arg);
1244 /*****************************************************************************
1245 * setsockopt() / getsockopt() support.
1247 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1248 * sockets. In order to control kernel tunnel features, we allow userspace to
1249 * create a special "tunnel" PPPoX socket which is used for control only.
1250 * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
1251 * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
1252 *****************************************************************************/
1254 /* Tunnel setsockopt() helper.
1256 static int pppol2tp_tunnel_setsockopt(struct sock *sk,
1257 struct l2tp_tunnel *tunnel,
1258 int optname, int val)
1263 case PPPOL2TP_SO_DEBUG:
1264 tunnel->debug = val;
1265 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1266 "%s: set debug=%x\n", tunnel->name, tunnel->debug);
1277 /* Session setsockopt helper.
1279 static int pppol2tp_session_setsockopt(struct sock *sk,
1280 struct l2tp_session *session,
1281 int optname, int val)
1284 struct pppol2tp_session *ps = l2tp_session_priv(session);
1287 case PPPOL2TP_SO_RECVSEQ:
1288 if ((val != 0) && (val != 1)) {
1292 session->recv_seq = val ? -1 : 0;
1293 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1294 "%s: set recv_seq=%d\n", session->name, session->recv_seq);
1297 case PPPOL2TP_SO_SENDSEQ:
1298 if ((val != 0) && (val != 1)) {
1302 session->send_seq = val ? -1 : 0;
1304 struct sock *ssk = ps->sock;
1305 struct pppox_sock *po = pppox_sk(ssk);
1306 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1307 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1309 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1310 "%s: set send_seq=%d\n", session->name, session->send_seq);
1313 case PPPOL2TP_SO_LNSMODE:
1314 if ((val != 0) && (val != 1)) {
1318 session->lns_mode = val ? -1 : 0;
1319 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1320 "%s: set lns_mode=%d\n", session->name, session->lns_mode);
1323 case PPPOL2TP_SO_DEBUG:
1324 session->debug = val;
1325 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1326 "%s: set debug=%x\n", session->name, session->debug);
1329 case PPPOL2TP_SO_REORDERTO:
1330 session->reorder_timeout = msecs_to_jiffies(val);
1331 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1332 "%s: set reorder_timeout=%d\n", session->name, session->reorder_timeout);
1343 /* Main setsockopt() entry point.
1344 * Does API checks, then calls either the tunnel or session setsockopt
1345 * handler, according to whether the PPPoL2TP socket is a for a regular
1346 * session or the special tunnel type.
1348 static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
1349 char __user *optval, unsigned int optlen)
1351 struct sock *sk = sock->sk;
1352 struct l2tp_session *session;
1353 struct l2tp_tunnel *tunnel;
1354 struct pppol2tp_session *ps;
1358 if (level != SOL_PPPOL2TP)
1361 if (optlen < sizeof(int))
1364 if (get_user(val, (int __user *)optval))
1368 if (sk->sk_user_data == NULL)
1371 /* Get session context from the socket */
1373 session = pppol2tp_sock_to_session(sk);
1374 if (session == NULL)
1377 /* Special case: if session_id == 0x0000, treat as operation on tunnel
1379 ps = l2tp_session_priv(session);
1380 if ((session->session_id == 0) &&
1381 (session->peer_session_id == 0)) {
1383 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1387 err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
1388 sock_put(ps->tunnel_sock);
1390 err = pppol2tp_session_setsockopt(sk, session, optname, val);
1400 /* Tunnel getsockopt helper. Called with sock locked.
1402 static int pppol2tp_tunnel_getsockopt(struct sock *sk,
1403 struct l2tp_tunnel *tunnel,
1404 int optname, int *val)
1409 case PPPOL2TP_SO_DEBUG:
1410 *val = tunnel->debug;
1411 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1412 "%s: get debug=%x\n", tunnel->name, tunnel->debug);
1423 /* Session getsockopt helper. Called with sock locked.
1425 static int pppol2tp_session_getsockopt(struct sock *sk,
1426 struct l2tp_session *session,
1427 int optname, int *val)
1432 case PPPOL2TP_SO_RECVSEQ:
1433 *val = session->recv_seq;
1434 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1435 "%s: get recv_seq=%d\n", session->name, *val);
1438 case PPPOL2TP_SO_SENDSEQ:
1439 *val = session->send_seq;
1440 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1441 "%s: get send_seq=%d\n", session->name, *val);
1444 case PPPOL2TP_SO_LNSMODE:
1445 *val = session->lns_mode;
1446 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1447 "%s: get lns_mode=%d\n", session->name, *val);
1450 case PPPOL2TP_SO_DEBUG:
1451 *val = session->debug;
1452 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1453 "%s: get debug=%d\n", session->name, *val);
1456 case PPPOL2TP_SO_REORDERTO:
1457 *val = (int) jiffies_to_msecs(session->reorder_timeout);
1458 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1459 "%s: get reorder_timeout=%d\n", session->name, *val);
1469 /* Main getsockopt() entry point.
1470 * Does API checks, then calls either the tunnel or session getsockopt
1471 * handler, according to whether the PPPoX socket is a for a regular session
1472 * or the special tunnel type.
1474 static int pppol2tp_getsockopt(struct socket *sock, int level,
1475 int optname, char __user *optval, int __user *optlen)
1477 struct sock *sk = sock->sk;
1478 struct l2tp_session *session;
1479 struct l2tp_tunnel *tunnel;
1482 struct pppol2tp_session *ps;
1484 if (level != SOL_PPPOL2TP)
1487 if (get_user(len, (int __user *) optlen))
1490 len = min_t(unsigned int, len, sizeof(int));
1496 if (sk->sk_user_data == NULL)
1499 /* Get the session context */
1501 session = pppol2tp_sock_to_session(sk);
1502 if (session == NULL)
1505 /* Special case: if session_id == 0x0000, treat as operation on tunnel */
1506 ps = l2tp_session_priv(session);
1507 if ((session->session_id == 0) &&
1508 (session->peer_session_id == 0)) {
1510 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1514 err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
1515 sock_put(ps->tunnel_sock);
1517 err = pppol2tp_session_getsockopt(sk, session, optname, &val);
1520 if (put_user(len, (int __user *) optlen))
1523 if (copy_to_user((void __user *) optval, &val, len))
1534 /*****************************************************************************
1535 * /proc filesystem for debug
1536 * Since the original pppol2tp driver provided /proc/net/pppol2tp for
1537 * L2TPv2, we dump only L2TPv2 tunnels and sessions here.
1538 *****************************************************************************/
1540 static unsigned int pppol2tp_net_id;
1542 #ifdef CONFIG_PROC_FS
1544 struct pppol2tp_seq_data {
1545 struct seq_net_private p;
1546 int tunnel_idx; /* current tunnel */
1547 int session_idx; /* index of session within current tunnel */
1548 struct l2tp_tunnel *tunnel;
1549 struct l2tp_session *session; /* NULL means get next tunnel */
1552 static void pppol2tp_next_tunnel(struct net *net, struct pppol2tp_seq_data *pd)
1555 pd->tunnel = l2tp_tunnel_find_nth(net, pd->tunnel_idx);
1558 if (pd->tunnel == NULL)
1561 /* Ignore L2TPv3 tunnels */
1562 if (pd->tunnel->version < 3)
1567 static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
1569 pd->session = l2tp_session_find_nth(pd->tunnel, pd->session_idx);
1572 if (pd->session == NULL) {
1573 pd->session_idx = 0;
1574 pppol2tp_next_tunnel(net, pd);
1578 static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
1580 struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
1587 BUG_ON(m->private == NULL);
1589 net = seq_file_net(m);
1591 if (pd->tunnel == NULL)
1592 pppol2tp_next_tunnel(net, pd);
1594 pppol2tp_next_session(net, pd);
1596 /* NULL tunnel and session indicates end of list */
1597 if ((pd->tunnel == NULL) && (pd->session == NULL))
1604 static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
1610 static void pppol2tp_seq_stop(struct seq_file *p, void *v)
1615 static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
1617 struct l2tp_tunnel *tunnel = v;
1619 seq_printf(m, "\nTUNNEL '%s', %c %d\n",
1621 (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N',
1622 atomic_read(&tunnel->ref_count) - 1);
1623 seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n",
1625 (unsigned long long)tunnel->stats.tx_packets,
1626 (unsigned long long)tunnel->stats.tx_bytes,
1627 (unsigned long long)tunnel->stats.tx_errors,
1628 (unsigned long long)tunnel->stats.rx_packets,
1629 (unsigned long long)tunnel->stats.rx_bytes,
1630 (unsigned long long)tunnel->stats.rx_errors);
1633 static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
1635 struct l2tp_session *session = v;
1636 struct l2tp_tunnel *tunnel = session->tunnel;
1637 struct pppol2tp_session *ps = l2tp_session_priv(session);
1638 struct pppox_sock *po = pppox_sk(ps->sock);
1643 struct inet_sock *inet = inet_sk(tunnel->sock);
1644 ip = ntohl(inet->inet_saddr);
1645 port = ntohs(inet->inet_sport);
1648 seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
1649 "%04X/%04X %d %c\n",
1650 session->name, ip, port,
1652 session->session_id,
1653 tunnel->peer_tunnel_id,
1654 session->peer_session_id,
1656 (session == ps->sock->sk_user_data) ?
1658 seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
1659 session->mtu, session->mru,
1660 session->recv_seq ? 'R' : '-',
1661 session->send_seq ? 'S' : '-',
1662 session->lns_mode ? "LNS" : "LAC",
1664 jiffies_to_msecs(session->reorder_timeout));
1665 seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n",
1666 session->nr, session->ns,
1667 (unsigned long long)session->stats.tx_packets,
1668 (unsigned long long)session->stats.tx_bytes,
1669 (unsigned long long)session->stats.tx_errors,
1670 (unsigned long long)session->stats.rx_packets,
1671 (unsigned long long)session->stats.rx_bytes,
1672 (unsigned long long)session->stats.rx_errors);
1675 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
1678 static int pppol2tp_seq_show(struct seq_file *m, void *v)
1680 struct pppol2tp_seq_data *pd = v;
1682 /* display header on line 1 */
1683 if (v == SEQ_START_TOKEN) {
1684 seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
1685 seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
1686 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1687 seq_puts(m, " SESSION name, addr/port src-tid/sid "
1688 "dest-tid/sid state user-data-ok\n");
1689 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
1690 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1694 /* Show the tunnel or session context.
1696 if (pd->session == NULL)
1697 pppol2tp_seq_tunnel_show(m, pd->tunnel);
1699 pppol2tp_seq_session_show(m, pd->session);
1705 static const struct seq_operations pppol2tp_seq_ops = {
1706 .start = pppol2tp_seq_start,
1707 .next = pppol2tp_seq_next,
1708 .stop = pppol2tp_seq_stop,
1709 .show = pppol2tp_seq_show,
1712 /* Called when our /proc file is opened. We allocate data for use when
1713 * iterating our tunnel / session contexts and store it in the private
1714 * data of the seq_file.
1716 static int pppol2tp_proc_open(struct inode *inode, struct file *file)
1718 return seq_open_net(inode, file, &pppol2tp_seq_ops,
1719 sizeof(struct pppol2tp_seq_data));
1722 static const struct file_operations pppol2tp_proc_fops = {
1723 .owner = THIS_MODULE,
1724 .open = pppol2tp_proc_open,
1726 .llseek = seq_lseek,
1727 .release = seq_release_net,
1730 #endif /* CONFIG_PROC_FS */
1732 /*****************************************************************************
1734 *****************************************************************************/
1736 static __net_init int pppol2tp_init_net(struct net *net)
1738 struct proc_dir_entry *pde;
1741 pde = proc_net_fops_create(net, "pppol2tp", S_IRUGO, &pppol2tp_proc_fops);
1751 static __net_exit void pppol2tp_exit_net(struct net *net)
1753 proc_net_remove(net, "pppol2tp");
1756 static struct pernet_operations pppol2tp_net_ops = {
1757 .init = pppol2tp_init_net,
1758 .exit = pppol2tp_exit_net,
1759 .id = &pppol2tp_net_id,
1762 /*****************************************************************************
1764 *****************************************************************************/
1766 static const struct proto_ops pppol2tp_ops = {
1768 .owner = THIS_MODULE,
1769 .release = pppol2tp_release,
1770 .bind = sock_no_bind,
1771 .connect = pppol2tp_connect,
1772 .socketpair = sock_no_socketpair,
1773 .accept = sock_no_accept,
1774 .getname = pppol2tp_getname,
1775 .poll = datagram_poll,
1776 .listen = sock_no_listen,
1777 .shutdown = sock_no_shutdown,
1778 .setsockopt = pppol2tp_setsockopt,
1779 .getsockopt = pppol2tp_getsockopt,
1780 .sendmsg = pppol2tp_sendmsg,
1781 .recvmsg = pppol2tp_recvmsg,
1782 .mmap = sock_no_mmap,
1783 .ioctl = pppox_ioctl,
1786 static const struct pppox_proto pppol2tp_proto = {
1787 .create = pppol2tp_create,
1788 .ioctl = pppol2tp_ioctl,
1789 .owner = THIS_MODULE,
1792 #ifdef CONFIG_L2TP_V3
1794 static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = {
1795 .session_create = pppol2tp_session_create,
1796 .session_delete = pppol2tp_session_delete,
1799 #endif /* CONFIG_L2TP_V3 */
1801 static int __init pppol2tp_init(void)
1805 err = register_pernet_device(&pppol2tp_net_ops);
1809 err = proto_register(&pppol2tp_sk_proto, 0);
1811 goto out_unregister_pppol2tp_pernet;
1813 err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
1815 goto out_unregister_pppol2tp_proto;
1817 #ifdef CONFIG_L2TP_V3
1818 err = l2tp_nl_register_ops(L2TP_PWTYPE_PPP, &pppol2tp_nl_cmd_ops);
1820 goto out_unregister_pppox;
1823 printk(KERN_INFO "PPPoL2TP kernel driver, %s\n",
1824 PPPOL2TP_DRV_VERSION);
1829 #ifdef CONFIG_L2TP_V3
1830 out_unregister_pppox:
1831 unregister_pppox_proto(PX_PROTO_OL2TP);
1833 out_unregister_pppol2tp_proto:
1834 proto_unregister(&pppol2tp_sk_proto);
1835 out_unregister_pppol2tp_pernet:
1836 unregister_pernet_device(&pppol2tp_net_ops);
1840 static void __exit pppol2tp_exit(void)
1842 #ifdef CONFIG_L2TP_V3
1843 l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP);
1845 unregister_pppox_proto(PX_PROTO_OL2TP);
1846 proto_unregister(&pppol2tp_sk_proto);
1847 unregister_pernet_device(&pppol2tp_net_ops);
1850 module_init(pppol2tp_init);
1851 module_exit(pppol2tp_exit);
1853 MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
1854 MODULE_DESCRIPTION("PPP over L2TP over UDP");
1855 MODULE_LICENSE("GPL");
1856 MODULE_VERSION(PPPOL2TP_DRV_VERSION);