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 mutex sk_lock; /* Protects .sk */
130 struct sock __rcu *sk; /* Pointer to the session
132 struct sock *__sk; /* Copy of .sk, for cleanup */
133 struct rcu_head rcu; /* For asynchronous release */
134 struct sock *tunnel_sock; /* Pointer to the tunnel UDP
136 int flags; /* accessed by PPPIOCGFLAGS.
140 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb);
142 static const struct ppp_channel_ops pppol2tp_chan_ops = {
143 .start_xmit = pppol2tp_xmit,
146 static const struct proto_ops pppol2tp_ops;
148 /* Retrieves the pppol2tp socket associated to a session.
149 * A reference is held on the returned socket, so this function must be paired
152 static struct sock *pppol2tp_session_get_sock(struct l2tp_session *session)
154 struct pppol2tp_session *ps = l2tp_session_priv(session);
158 sk = rcu_dereference(ps->sk);
166 /* Helpers to obtain tunnel/session contexts from sockets.
168 static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
170 struct l2tp_session *session;
176 session = (struct l2tp_session *)(sk->sk_user_data);
177 if (session == NULL) {
182 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
188 /*****************************************************************************
189 * Receive data handling
190 *****************************************************************************/
192 static int pppol2tp_recv_payload_hook(struct sk_buff *skb)
194 /* Skip PPP header, if present. In testing, Microsoft L2TP clients
195 * don't send the PPP header (PPP header compression enabled), but
196 * other clients can include the header. So we cope with both cases
197 * here. The PPP header is always FF03 when using L2TP.
199 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
200 * the field may be unaligned.
202 if (!pskb_may_pull(skb, 2))
205 if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
211 /* Receive message. This is the recvmsg for the PPPoL2TP socket.
213 static int pppol2tp_recvmsg(struct kiocb *iocb, struct socket *sock,
214 struct msghdr *msg, size_t len,
219 struct sock *sk = sock->sk;
222 if (sk->sk_state & PPPOX_BOUND)
226 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
227 flags & MSG_DONTWAIT, &err);
233 else if (len < skb->len)
234 msg->msg_flags |= MSG_TRUNC;
236 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len);
237 if (likely(err == 0))
245 static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len)
247 struct pppol2tp_session *ps = l2tp_session_priv(session);
248 struct sock *sk = NULL;
250 /* If the socket is bound, send it in to PPP's input queue. Otherwise
251 * queue it on the session socket.
254 sk = rcu_dereference(ps->sk);
258 if (sk->sk_state & PPPOX_BOUND) {
259 struct pppox_sock *po;
260 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
261 "%s: recv %d byte data frame, passing to ppp\n",
262 session->name, data_len);
264 /* We need to forget all info related to the L2TP packet
265 * gathered in the skb as we are going to reuse the same
266 * skb for the inner packet.
268 * - reset xfrm (IPSec) information as it applies to
269 * the outer L2TP packet and not to the inner one
270 * - release the dst to force a route lookup on the inner
271 * IP packet since skb->dst currently points to the dst
273 * - reset netfilter information as it doesn't apply
274 * to the inner packet either
281 ppp_input(&po->chan, skb);
283 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
284 "%s: socket not bound\n", session->name);
286 /* Not bound. Nothing we can do, so discard. */
287 session->stats.rx_errors++;
296 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
297 "%s: no socket\n", session->name);
301 /************************************************************************
303 ***********************************************************************/
305 /* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here
306 * when a user application does a sendmsg() on the session socket. L2TP and
307 * PPP headers must be inserted into the user's data.
309 static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
312 static const unsigned char ppph[2] = { 0xff, 0x03 };
313 struct sock *sk = sock->sk;
316 struct l2tp_session *session;
317 struct l2tp_tunnel *tunnel;
318 struct pppol2tp_session *ps;
322 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
325 /* Get session and tunnel contexts */
327 session = pppol2tp_sock_to_session(sk);
331 ps = l2tp_session_priv(session);
332 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
336 uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
338 /* Allocate a socket buffer */
340 skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) +
341 uhlen + session->hdr_len +
342 sizeof(ppph) + total_len,
345 goto error_put_sess_tun;
347 /* Reserve space for headers. */
348 skb_reserve(skb, NET_SKB_PAD);
349 skb_reset_network_header(skb);
350 skb_reserve(skb, sizeof(struct iphdr));
351 skb_reset_transport_header(skb);
352 skb_reserve(skb, uhlen);
355 skb->data[0] = ppph[0];
356 skb->data[1] = ppph[1];
359 /* Copy user data into skb */
360 error = memcpy_fromiovec(skb_put(skb, total_len), m->msg_iov,
364 goto error_put_sess_tun;
368 l2tp_xmit_skb(session, skb, session->hdr_len);
371 sock_put(ps->tunnel_sock);
377 sock_put(ps->tunnel_sock);
384 /* Transmit function called by generic PPP driver. Sends PPP frame
385 * over PPPoL2TP socket.
387 * This is almost the same as pppol2tp_sendmsg(), but rather than
388 * being called with a msghdr from userspace, it is called with a skb
391 * The supplied skb from ppp doesn't have enough headroom for the
392 * insertion of L2TP, UDP and IP headers so we need to allocate more
393 * headroom in the skb. This will create a cloned skb. But we must be
394 * careful in the error case because the caller will expect to free
395 * the skb it supplied, not our cloned skb. So we take care to always
396 * leave the original skb unfreed if we return an error.
398 static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
400 static const u8 ppph[2] = { 0xff, 0x03 };
401 struct sock *sk = (struct sock *) chan->private;
403 struct l2tp_session *session;
404 struct l2tp_tunnel *tunnel;
405 struct pppol2tp_session *ps;
410 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
413 /* Get session and tunnel contexts from the socket */
414 session = pppol2tp_sock_to_session(sk);
418 ps = l2tp_session_priv(session);
419 sk_tun = ps->tunnel_sock;
422 tunnel = l2tp_sock_to_tunnel(sk_tun);
426 old_headroom = skb_headroom(skb);
427 uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
428 headroom = NET_SKB_PAD +
429 sizeof(struct iphdr) + /* IP header */
430 uhlen + /* UDP header (if L2TP_ENCAPTYPE_UDP) */
431 session->hdr_len + /* L2TP header */
432 sizeof(ppph); /* PPP header */
433 if (skb_cow_head(skb, headroom))
434 goto abort_put_sess_tun;
436 new_headroom = skb_headroom(skb);
437 skb->truesize += new_headroom - old_headroom;
439 /* Setup PPP header */
440 __skb_push(skb, sizeof(ppph));
441 skb->data[0] = ppph[0];
442 skb->data[1] = ppph[1];
445 l2tp_xmit_skb(session, skb, session->hdr_len);
457 /* Free the original skb */
462 /*****************************************************************************
463 * Session (and tunnel control) socket create/destroy.
464 *****************************************************************************/
466 /* Called by l2tp_core when a session socket is being closed.
468 static void pppol2tp_session_close(struct l2tp_session *session)
472 /* Really kill the session socket. (Called from sock_put() if
475 static void pppol2tp_session_destruct(struct sock *sk)
477 struct l2tp_session *session;
479 if (sk->sk_user_data != NULL) {
480 session = sk->sk_user_data;
484 sk->sk_user_data = NULL;
485 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
486 l2tp_session_dec_refcount(session);
493 static void pppol2tp_put_sk(struct rcu_head *head)
495 struct pppol2tp_session *ps;
497 ps = container_of(head, typeof(*ps), rcu);
501 /* Called when the PPPoX socket (session) is closed.
503 static int pppol2tp_release(struct socket *sock)
505 struct sock *sk = sock->sk;
506 struct l2tp_session *session;
514 if (sock_flag(sk, SOCK_DEAD) != 0)
517 pppox_unbind_sock(sk);
519 /* Signal the death of the socket. */
520 sk->sk_state = PPPOX_DEAD;
524 session = pppol2tp_sock_to_session(sk);
526 if (session != NULL) {
527 struct pppol2tp_session *ps;
529 l2tp_session_delete(session);
531 ps = l2tp_session_priv(session);
532 mutex_lock(&ps->sk_lock);
533 ps->__sk = rcu_dereference_protected(ps->sk,
534 lockdep_is_held(&ps->sk_lock));
535 RCU_INIT_POINTER(ps->sk, NULL);
536 mutex_unlock(&ps->sk_lock);
537 call_rcu(&ps->rcu, pppol2tp_put_sk);
539 /* Rely on the sock_put() call at the end of the function for
540 * dropping the reference held by pppol2tp_sock_to_session().
541 * The last reference will be dropped by pppol2tp_put_sk().
544 skb_queue_purge(&sk->sk_receive_queue);
545 skb_queue_purge(&sk->sk_write_queue);
549 /* This will delete the session context via
550 * pppol2tp_session_destruct() if the socket's refcnt drops to
562 static struct proto pppol2tp_sk_proto = {
564 .owner = THIS_MODULE,
565 .obj_size = sizeof(struct pppox_sock),
568 static int pppol2tp_backlog_recv(struct sock *sk, struct sk_buff *skb)
572 rc = l2tp_udp_encap_recv(sk, skb);
576 return NET_RX_SUCCESS;
579 /* socket() handler. Initialize a new struct sock.
581 static int pppol2tp_create(struct net *net, struct socket *sock)
586 sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto);
590 sock_init_data(sock, sk);
592 sock->state = SS_UNCONNECTED;
593 sock->ops = &pppol2tp_ops;
595 sk->sk_backlog_rcv = pppol2tp_backlog_recv;
596 sk->sk_protocol = PX_PROTO_OL2TP;
597 sk->sk_family = PF_PPPOX;
598 sk->sk_state = PPPOX_NONE;
599 sk->sk_type = SOCK_STREAM;
600 sk->sk_destruct = pppol2tp_session_destruct;
608 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
609 static void pppol2tp_show(struct seq_file *m, void *arg)
611 struct l2tp_session *session = arg;
614 sk = pppol2tp_session_get_sock(session);
616 struct pppox_sock *po = pppox_sk(sk);
618 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
624 static void pppol2tp_session_init(struct l2tp_session *session)
626 struct pppol2tp_session *ps;
627 struct dst_entry *dst;
629 session->recv_skb = pppol2tp_recv;
630 session->session_close = pppol2tp_session_close;
631 #if IS_ENABLED(CONFIG_L2TP_DEBUGFS)
632 session->show = pppol2tp_show;
635 ps = l2tp_session_priv(session);
636 mutex_init(&ps->sk_lock);
637 ps->tunnel_sock = session->tunnel->sock;
638 ps->owner = current->pid;
640 /* If PMTU discovery was enabled, use the MTU that was discovered */
641 dst = sk_dst_get(session->tunnel->sock);
643 u32 pmtu = dst_mtu(dst);
646 session->mtu = pmtu - PPPOL2TP_HEADER_OVERHEAD;
647 session->mru = pmtu - PPPOL2TP_HEADER_OVERHEAD;
653 /* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
655 static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
656 int sockaddr_len, int flags)
658 struct sock *sk = sock->sk;
659 struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr;
660 struct sockaddr_pppol2tpv3 *sp3 = (struct sockaddr_pppol2tpv3 *) uservaddr;
661 struct pppox_sock *po = pppox_sk(sk);
662 struct l2tp_session *session = NULL;
663 struct l2tp_tunnel *tunnel;
664 struct pppol2tp_session *ps;
665 struct l2tp_session_cfg cfg = { 0, };
667 u32 tunnel_id, peer_tunnel_id;
668 u32 session_id, peer_session_id;
669 bool drop_refcnt = false;
670 bool drop_tunnel = false;
677 if (sp->sa_protocol != PX_PROTO_OL2TP)
680 /* Check for already bound sockets */
682 if (sk->sk_state & PPPOX_CONNECTED)
685 /* We don't supporting rebinding anyway */
687 if (sk->sk_user_data)
688 goto end; /* socket is already attached */
690 /* Get params from socket address. Handle L2TPv2 and L2TPv3 */
691 if (sockaddr_len == sizeof(struct sockaddr_pppol2tp)) {
692 fd = sp->pppol2tp.fd;
693 tunnel_id = sp->pppol2tp.s_tunnel;
694 peer_tunnel_id = sp->pppol2tp.d_tunnel;
695 session_id = sp->pppol2tp.s_session;
696 peer_session_id = sp->pppol2tp.d_session;
697 } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3)) {
699 fd = sp3->pppol2tp.fd;
700 tunnel_id = sp3->pppol2tp.s_tunnel;
701 peer_tunnel_id = sp3->pppol2tp.d_tunnel;
702 session_id = sp3->pppol2tp.s_session;
703 peer_session_id = sp3->pppol2tp.d_session;
706 goto end; /* bad socket address */
709 /* Don't bind if tunnel_id is 0 */
714 tunnel = l2tp_tunnel_get(sock_net(sk), tunnel_id);
718 /* Special case: create tunnel context if session_id and
719 * peer_session_id is 0. Otherwise look up tunnel using supplied
722 if ((session_id == 0) && (peer_session_id == 0)) {
723 if (tunnel == NULL) {
724 struct l2tp_tunnel_cfg tcfg = {
725 .encap = L2TP_ENCAPTYPE_UDP,
728 error = l2tp_tunnel_create(sock_net(sk), fd, ver, tunnel_id, peer_tunnel_id, &tcfg, &tunnel);
733 /* Error if we can't find the tunnel */
738 /* Error if socket is not prepped */
739 if (tunnel->sock == NULL)
743 if (tunnel->recv_payload_hook == NULL)
744 tunnel->recv_payload_hook = pppol2tp_recv_payload_hook;
746 if (tunnel->peer_tunnel_id == 0) {
748 tunnel->peer_tunnel_id = sp->pppol2tp.d_tunnel;
750 tunnel->peer_tunnel_id = sp3->pppol2tp.d_tunnel;
753 session = l2tp_session_get(sock_net(sk), tunnel, session_id, false);
756 ps = l2tp_session_priv(session);
758 /* Using a pre-existing session is fine as long as it hasn't
759 * been connected yet.
761 mutex_lock(&ps->sk_lock);
762 if (rcu_dereference_protected(ps->sk,
763 lockdep_is_held(&ps->sk_lock))) {
764 mutex_unlock(&ps->sk_lock);
769 /* consistency checks */
770 if (ps->tunnel_sock != tunnel->sock) {
771 mutex_unlock(&ps->sk_lock);
776 /* Default MTU must allow space for UDP/L2TP/PPP headers */
777 cfg.mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
780 session = l2tp_session_create(sizeof(struct pppol2tp_session),
782 peer_session_id, &cfg);
783 if (IS_ERR(session)) {
784 error = PTR_ERR(session);
788 pppol2tp_session_init(session);
789 ps = l2tp_session_priv(session);
790 l2tp_session_inc_refcount(session);
792 mutex_lock(&ps->sk_lock);
793 error = l2tp_session_register(session, tunnel);
795 mutex_unlock(&ps->sk_lock);
802 /* Special case: if source & dest session_id == 0x0000, this
803 * socket is being created to manage the tunnel. Just set up
804 * the internal context for use by ioctl() and sockopt()
807 if ((session->session_id == 0) &&
808 (session->peer_session_id == 0)) {
813 /* The only header we need to worry about is the L2TP
814 * header. This size is different depending on whether
815 * sequence numbers are enabled for the data channel.
817 po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
819 po->chan.private = sk;
820 po->chan.ops = &pppol2tp_chan_ops;
821 po->chan.mtu = session->mtu;
823 error = ppp_register_net_channel(sock_net(sk), &po->chan);
825 mutex_unlock(&ps->sk_lock);
830 /* This is how we get the session context from the socket. */
831 sk->sk_user_data = session;
832 rcu_assign_pointer(ps->sk, sk);
833 mutex_unlock(&ps->sk_lock);
835 /* Keep the reference we've grabbed on the session: sk doesn't expect
836 * the session to disappear. pppol2tp_session_destruct() is responsible
841 sk->sk_state = PPPOX_CONNECTED;
842 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
843 "%s: created\n", session->name);
847 l2tp_session_dec_refcount(session);
849 l2tp_tunnel_dec_refcount(tunnel);
855 #ifdef CONFIG_L2TP_V3
857 /* Called when creating sessions via the netlink interface. */
858 static int pppol2tp_session_create(struct net *net, struct l2tp_tunnel *tunnel,
859 u32 session_id, u32 peer_session_id,
860 struct l2tp_session_cfg *cfg)
863 struct l2tp_session *session;
865 /* Error if tunnel socket is not prepped */
871 /* Default MTU values. */
873 cfg->mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
877 /* Allocate and initialize a new session context. */
878 session = l2tp_session_create(sizeof(struct pppol2tp_session),
880 peer_session_id, cfg);
881 if (IS_ERR(session)) {
882 error = PTR_ERR(session);
886 pppol2tp_session_init(session);
888 error = l2tp_session_register(session, tunnel);
900 #endif /* CONFIG_L2TP_V3 */
902 /* getname() support.
904 static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
905 int *usockaddr_len, int peer)
909 struct l2tp_session *session;
910 struct l2tp_tunnel *tunnel;
911 struct sock *sk = sock->sk;
912 struct inet_sock *inet;
913 struct pppol2tp_session *pls;
918 if (sk->sk_state != PPPOX_CONNECTED)
922 session = pppol2tp_sock_to_session(sk);
926 pls = l2tp_session_priv(session);
927 tunnel = l2tp_sock_to_tunnel(pls->tunnel_sock);
931 inet = inet_sk(tunnel->sock);
932 if (tunnel->version == 2) {
933 struct sockaddr_pppol2tp sp;
936 sp.sa_family = AF_PPPOX;
937 sp.sa_protocol = PX_PROTO_OL2TP;
938 sp.pppol2tp.fd = tunnel->fd;
939 sp.pppol2tp.pid = pls->owner;
940 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
941 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
942 sp.pppol2tp.s_session = session->session_id;
943 sp.pppol2tp.d_session = session->peer_session_id;
944 sp.pppol2tp.addr.sin_family = AF_INET;
945 sp.pppol2tp.addr.sin_port = inet->inet_dport;
946 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
947 memcpy(uaddr, &sp, len);
948 } else if (tunnel->version == 3) {
949 struct sockaddr_pppol2tpv3 sp;
952 sp.sa_family = AF_PPPOX;
953 sp.sa_protocol = PX_PROTO_OL2TP;
954 sp.pppol2tp.fd = tunnel->fd;
955 sp.pppol2tp.pid = pls->owner;
956 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
957 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
958 sp.pppol2tp.s_session = session->session_id;
959 sp.pppol2tp.d_session = session->peer_session_id;
960 sp.pppol2tp.addr.sin_family = AF_INET;
961 sp.pppol2tp.addr.sin_port = inet->inet_dport;
962 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
963 memcpy(uaddr, &sp, len);
966 *usockaddr_len = len;
969 sock_put(pls->tunnel_sock);
976 /****************************************************************************
979 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
980 * sockets. However, in order to control kernel tunnel features, we allow
981 * userspace to create a special "tunnel" PPPoX socket which is used for
982 * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
983 * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
985 ****************************************************************************/
987 static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest,
988 struct l2tp_stats *stats)
990 dest->tx_packets = stats->tx_packets;
991 dest->tx_bytes = stats->tx_bytes;
992 dest->tx_errors = stats->tx_errors;
993 dest->rx_packets = stats->rx_packets;
994 dest->rx_bytes = stats->rx_bytes;
995 dest->rx_seq_discards = stats->rx_seq_discards;
996 dest->rx_oos_packets = stats->rx_oos_packets;
997 dest->rx_errors = stats->rx_errors;
1000 /* Session ioctl helper.
1002 static int pppol2tp_session_ioctl(struct l2tp_session *session,
1003 unsigned int cmd, unsigned long arg)
1008 int val = (int) arg;
1009 struct pppol2tp_session *ps = l2tp_session_priv(session);
1010 struct l2tp_tunnel *tunnel = session->tunnel;
1011 struct pppol2tp_ioc_stats stats;
1013 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1014 "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
1015 session->name, cmd, arg);
1017 sk = pppol2tp_session_get_sock(session);
1024 if (!(sk->sk_state & PPPOX_CONNECTED))
1028 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1030 ifr.ifr_mtu = session->mtu;
1031 if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
1034 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1035 "%s: get mtu=%d\n", session->name, session->mtu);
1041 if (!(sk->sk_state & PPPOX_CONNECTED))
1045 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1048 session->mtu = ifr.ifr_mtu;
1050 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1051 "%s: set mtu=%d\n", session->name, session->mtu);
1057 if (!(sk->sk_state & PPPOX_CONNECTED))
1061 if (put_user(session->mru, (int __user *) arg))
1064 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1065 "%s: get mru=%d\n", session->name, session->mru);
1071 if (!(sk->sk_state & PPPOX_CONNECTED))
1075 if (get_user(val, (int __user *) arg))
1079 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1080 "%s: set mru=%d\n", session->name, session->mru);
1086 if (put_user(ps->flags, (int __user *) arg))
1089 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1090 "%s: get flags=%d\n", session->name, ps->flags);
1096 if (get_user(val, (int __user *) arg))
1099 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1100 "%s: set flags=%d\n", session->name, ps->flags);
1104 case PPPIOCGL2TPSTATS:
1106 if (!(sk->sk_state & PPPOX_CONNECTED))
1109 memset(&stats, 0, sizeof(stats));
1110 stats.tunnel_id = tunnel->tunnel_id;
1111 stats.session_id = session->session_id;
1112 pppol2tp_copy_stats(&stats, &session->stats);
1113 if (copy_to_user((void __user *) arg, &stats,
1116 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1117 "%s: get L2TP stats\n", session->name);
1131 /* Tunnel ioctl helper.
1133 * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
1134 * specifies a session_id, the session ioctl handler is called. This allows an
1135 * application to retrieve session stats via a tunnel socket.
1137 static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel *tunnel,
1138 unsigned int cmd, unsigned long arg)
1142 struct pppol2tp_ioc_stats stats;
1144 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1145 "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n",
1146 tunnel->name, cmd, arg);
1152 case PPPIOCGL2TPSTATS:
1154 if (!(sk->sk_state & PPPOX_CONNECTED))
1157 if (copy_from_user(&stats, (void __user *) arg,
1162 if (stats.session_id != 0) {
1163 /* resend to session ioctl handler */
1164 struct l2tp_session *session =
1165 l2tp_session_get(sock_net(sk), tunnel,
1166 stats.session_id, true);
1169 err = pppol2tp_session_ioctl(session, cmd,
1172 session->deref(session);
1173 l2tp_session_dec_refcount(session);
1180 stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
1182 pppol2tp_copy_stats(&stats, &tunnel->stats);
1183 if (copy_to_user((void __user *) arg, &stats, sizeof(stats))) {
1187 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1188 "%s: get L2TP stats\n", tunnel->name);
1202 /* Main ioctl() handler.
1203 * Dispatch to tunnel or session helpers depending on the socket.
1205 static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1208 struct sock *sk = sock->sk;
1209 struct l2tp_session *session;
1210 struct l2tp_tunnel *tunnel;
1211 struct pppol2tp_session *ps;
1218 if (sock_flag(sk, SOCK_DEAD) != 0)
1222 if ((sk->sk_user_data == NULL) ||
1223 (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
1226 /* Get session context from the socket */
1228 session = pppol2tp_sock_to_session(sk);
1229 if (session == NULL)
1232 /* Special case: if session's session_id is zero, treat ioctl as a
1235 ps = l2tp_session_priv(session);
1236 if ((session->session_id == 0) &&
1237 (session->peer_session_id == 0)) {
1239 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1243 err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
1244 sock_put(ps->tunnel_sock);
1248 err = pppol2tp_session_ioctl(session, cmd, arg);
1256 /*****************************************************************************
1257 * setsockopt() / getsockopt() support.
1259 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1260 * sockets. In order to control kernel tunnel features, we allow userspace to
1261 * create a special "tunnel" PPPoX socket which is used for control only.
1262 * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
1263 * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
1264 *****************************************************************************/
1266 /* Tunnel setsockopt() helper.
1268 static int pppol2tp_tunnel_setsockopt(struct sock *sk,
1269 struct l2tp_tunnel *tunnel,
1270 int optname, int val)
1275 case PPPOL2TP_SO_DEBUG:
1276 tunnel->debug = val;
1277 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1278 "%s: set debug=%x\n", tunnel->name, tunnel->debug);
1289 /* Session setsockopt helper.
1291 static int pppol2tp_session_setsockopt(struct sock *sk,
1292 struct l2tp_session *session,
1293 int optname, int val)
1298 case PPPOL2TP_SO_RECVSEQ:
1299 if ((val != 0) && (val != 1)) {
1303 session->recv_seq = val ? -1 : 0;
1304 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1305 "%s: set recv_seq=%d\n", session->name, session->recv_seq);
1308 case PPPOL2TP_SO_SENDSEQ:
1309 if ((val != 0) && (val != 1)) {
1313 session->send_seq = val ? -1 : 0;
1315 struct pppox_sock *po = pppox_sk(sk);
1317 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1318 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1320 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1321 "%s: set send_seq=%d\n", session->name, session->send_seq);
1324 case PPPOL2TP_SO_LNSMODE:
1325 if ((val != 0) && (val != 1)) {
1329 session->lns_mode = val ? -1 : 0;
1330 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1331 "%s: set lns_mode=%d\n", session->name, session->lns_mode);
1334 case PPPOL2TP_SO_DEBUG:
1335 session->debug = val;
1336 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1337 "%s: set debug=%x\n", session->name, session->debug);
1340 case PPPOL2TP_SO_REORDERTO:
1341 session->reorder_timeout = msecs_to_jiffies(val);
1342 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1343 "%s: set reorder_timeout=%d\n", session->name, session->reorder_timeout);
1354 /* Main setsockopt() entry point.
1355 * Does API checks, then calls either the tunnel or session setsockopt
1356 * handler, according to whether the PPPoL2TP socket is a for a regular
1357 * session or the special tunnel type.
1359 static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
1360 char __user *optval, unsigned int optlen)
1362 struct sock *sk = sock->sk;
1363 struct l2tp_session *session;
1364 struct l2tp_tunnel *tunnel;
1365 struct pppol2tp_session *ps;
1369 if (level != SOL_PPPOL2TP)
1372 if (optlen < sizeof(int))
1375 if (get_user(val, (int __user *)optval))
1379 if (sk->sk_user_data == NULL)
1382 /* Get session context from the socket */
1384 session = pppol2tp_sock_to_session(sk);
1385 if (session == NULL)
1388 /* Special case: if session_id == 0x0000, treat as operation on tunnel
1390 ps = l2tp_session_priv(session);
1391 if ((session->session_id == 0) &&
1392 (session->peer_session_id == 0)) {
1394 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1398 err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
1399 sock_put(ps->tunnel_sock);
1401 err = pppol2tp_session_setsockopt(sk, session, optname, val);
1409 /* Tunnel getsockopt helper. Called with sock locked.
1411 static int pppol2tp_tunnel_getsockopt(struct sock *sk,
1412 struct l2tp_tunnel *tunnel,
1413 int optname, int *val)
1418 case PPPOL2TP_SO_DEBUG:
1419 *val = tunnel->debug;
1420 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1421 "%s: get debug=%x\n", tunnel->name, tunnel->debug);
1432 /* Session getsockopt helper. Called with sock locked.
1434 static int pppol2tp_session_getsockopt(struct sock *sk,
1435 struct l2tp_session *session,
1436 int optname, int *val)
1441 case PPPOL2TP_SO_RECVSEQ:
1442 *val = session->recv_seq;
1443 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1444 "%s: get recv_seq=%d\n", session->name, *val);
1447 case PPPOL2TP_SO_SENDSEQ:
1448 *val = session->send_seq;
1449 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1450 "%s: get send_seq=%d\n", session->name, *val);
1453 case PPPOL2TP_SO_LNSMODE:
1454 *val = session->lns_mode;
1455 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1456 "%s: get lns_mode=%d\n", session->name, *val);
1459 case PPPOL2TP_SO_DEBUG:
1460 *val = session->debug;
1461 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1462 "%s: get debug=%d\n", session->name, *val);
1465 case PPPOL2TP_SO_REORDERTO:
1466 *val = (int) jiffies_to_msecs(session->reorder_timeout);
1467 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1468 "%s: get reorder_timeout=%d\n", session->name, *val);
1478 /* Main getsockopt() entry point.
1479 * Does API checks, then calls either the tunnel or session getsockopt
1480 * handler, according to whether the PPPoX socket is a for a regular session
1481 * or the special tunnel type.
1483 static int pppol2tp_getsockopt(struct socket *sock, int level,
1484 int optname, char __user *optval, int __user *optlen)
1486 struct sock *sk = sock->sk;
1487 struct l2tp_session *session;
1488 struct l2tp_tunnel *tunnel;
1491 struct pppol2tp_session *ps;
1493 if (level != SOL_PPPOL2TP)
1496 if (get_user(len, (int __user *) optlen))
1499 len = min_t(unsigned int, len, sizeof(int));
1505 if (sk->sk_user_data == NULL)
1508 /* Get the session context */
1510 session = pppol2tp_sock_to_session(sk);
1511 if (session == NULL)
1514 /* Special case: if session_id == 0x0000, treat as operation on tunnel */
1515 ps = l2tp_session_priv(session);
1516 if ((session->session_id == 0) &&
1517 (session->peer_session_id == 0)) {
1519 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1523 err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
1524 sock_put(ps->tunnel_sock);
1528 err = pppol2tp_session_getsockopt(sk, session, optname, &val);
1534 if (put_user(len, (int __user *) optlen))
1537 if (copy_to_user((void __user *) optval, &val, len))
1548 /*****************************************************************************
1549 * /proc filesystem for debug
1550 * Since the original pppol2tp driver provided /proc/net/pppol2tp for
1551 * L2TPv2, we dump only L2TPv2 tunnels and sessions here.
1552 *****************************************************************************/
1554 static unsigned int pppol2tp_net_id;
1556 #ifdef CONFIG_PROC_FS
1558 struct pppol2tp_seq_data {
1559 struct seq_net_private p;
1560 int tunnel_idx; /* current tunnel */
1561 int session_idx; /* index of session within current tunnel */
1562 struct l2tp_tunnel *tunnel;
1563 struct l2tp_session *session; /* NULL means get next tunnel */
1566 static void pppol2tp_next_tunnel(struct net *net, struct pppol2tp_seq_data *pd)
1569 pd->tunnel = l2tp_tunnel_find_nth(net, pd->tunnel_idx);
1572 if (pd->tunnel == NULL)
1575 /* Ignore L2TPv3 tunnels */
1576 if (pd->tunnel->version < 3)
1581 static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
1583 pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx, true);
1586 if (pd->session == NULL) {
1587 pd->session_idx = 0;
1588 pppol2tp_next_tunnel(net, pd);
1592 static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
1594 struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
1601 BUG_ON(m->private == NULL);
1603 net = seq_file_net(m);
1605 if (pd->tunnel == NULL)
1606 pppol2tp_next_tunnel(net, pd);
1608 pppol2tp_next_session(net, pd);
1610 /* NULL tunnel and session indicates end of list */
1611 if ((pd->tunnel == NULL) && (pd->session == NULL))
1618 static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
1624 static void pppol2tp_seq_stop(struct seq_file *p, void *v)
1629 static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
1631 struct l2tp_tunnel *tunnel = v;
1633 seq_printf(m, "\nTUNNEL '%s', %c %d\n",
1635 (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N',
1636 atomic_read(&tunnel->ref_count) - 1);
1637 seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n",
1639 (unsigned long long)tunnel->stats.tx_packets,
1640 (unsigned long long)tunnel->stats.tx_bytes,
1641 (unsigned long long)tunnel->stats.tx_errors,
1642 (unsigned long long)tunnel->stats.rx_packets,
1643 (unsigned long long)tunnel->stats.rx_bytes,
1644 (unsigned long long)tunnel->stats.rx_errors);
1647 static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
1649 struct l2tp_session *session = v;
1650 struct l2tp_tunnel *tunnel = session->tunnel;
1651 unsigned char state;
1658 struct inet_sock *inet = inet_sk(tunnel->sock);
1659 ip = ntohl(inet->inet_saddr);
1660 port = ntohs(inet->inet_sport);
1663 sk = pppol2tp_session_get_sock(session);
1665 state = sk->sk_state;
1666 user_data_ok = (session == sk->sk_user_data) ? 'Y' : 'N';
1672 seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
1673 "%04X/%04X %d %c\n",
1674 session->name, ip, port,
1676 session->session_id,
1677 tunnel->peer_tunnel_id,
1678 session->peer_session_id,
1679 state, user_data_ok);
1680 seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
1681 session->mtu, session->mru,
1682 session->recv_seq ? 'R' : '-',
1683 session->send_seq ? 'S' : '-',
1684 session->lns_mode ? "LNS" : "LAC",
1686 jiffies_to_msecs(session->reorder_timeout));
1687 seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n",
1688 session->nr, session->ns,
1689 (unsigned long long)session->stats.tx_packets,
1690 (unsigned long long)session->stats.tx_bytes,
1691 (unsigned long long)session->stats.tx_errors,
1692 (unsigned long long)session->stats.rx_packets,
1693 (unsigned long long)session->stats.rx_bytes,
1694 (unsigned long long)session->stats.rx_errors);
1697 struct pppox_sock *po = pppox_sk(sk);
1699 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
1704 static int pppol2tp_seq_show(struct seq_file *m, void *v)
1706 struct pppol2tp_seq_data *pd = v;
1708 /* display header on line 1 */
1709 if (v == SEQ_START_TOKEN) {
1710 seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
1711 seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
1712 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1713 seq_puts(m, " SESSION name, addr/port src-tid/sid "
1714 "dest-tid/sid state user-data-ok\n");
1715 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
1716 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1720 /* Show the tunnel or session context.
1723 pppol2tp_seq_tunnel_show(m, pd->tunnel);
1725 pppol2tp_seq_session_show(m, pd->session);
1726 if (pd->session->deref)
1727 pd->session->deref(pd->session);
1728 l2tp_session_dec_refcount(pd->session);
1735 static const struct seq_operations pppol2tp_seq_ops = {
1736 .start = pppol2tp_seq_start,
1737 .next = pppol2tp_seq_next,
1738 .stop = pppol2tp_seq_stop,
1739 .show = pppol2tp_seq_show,
1742 /* Called when our /proc file is opened. We allocate data for use when
1743 * iterating our tunnel / session contexts and store it in the private
1744 * data of the seq_file.
1746 static int pppol2tp_proc_open(struct inode *inode, struct file *file)
1748 return seq_open_net(inode, file, &pppol2tp_seq_ops,
1749 sizeof(struct pppol2tp_seq_data));
1752 static const struct file_operations pppol2tp_proc_fops = {
1753 .owner = THIS_MODULE,
1754 .open = pppol2tp_proc_open,
1756 .llseek = seq_lseek,
1757 .release = seq_release_net,
1760 #endif /* CONFIG_PROC_FS */
1762 /*****************************************************************************
1764 *****************************************************************************/
1766 static __net_init int pppol2tp_init_net(struct net *net)
1768 struct proc_dir_entry *pde;
1771 pde = proc_net_fops_create(net, "pppol2tp", S_IRUGO, &pppol2tp_proc_fops);
1781 static __net_exit void pppol2tp_exit_net(struct net *net)
1783 proc_net_remove(net, "pppol2tp");
1786 static struct pernet_operations pppol2tp_net_ops = {
1787 .init = pppol2tp_init_net,
1788 .exit = pppol2tp_exit_net,
1789 .id = &pppol2tp_net_id,
1792 /*****************************************************************************
1794 *****************************************************************************/
1796 static const struct proto_ops pppol2tp_ops = {
1798 .owner = THIS_MODULE,
1799 .release = pppol2tp_release,
1800 .bind = sock_no_bind,
1801 .connect = pppol2tp_connect,
1802 .socketpair = sock_no_socketpair,
1803 .accept = sock_no_accept,
1804 .getname = pppol2tp_getname,
1805 .poll = datagram_poll,
1806 .listen = sock_no_listen,
1807 .shutdown = sock_no_shutdown,
1808 .setsockopt = pppol2tp_setsockopt,
1809 .getsockopt = pppol2tp_getsockopt,
1810 .sendmsg = pppol2tp_sendmsg,
1811 .recvmsg = pppol2tp_recvmsg,
1812 .mmap = sock_no_mmap,
1813 .ioctl = pppox_ioctl,
1816 static const struct pppox_proto pppol2tp_proto = {
1817 .create = pppol2tp_create,
1818 .ioctl = pppol2tp_ioctl,
1819 .owner = THIS_MODULE,
1822 #ifdef CONFIG_L2TP_V3
1824 static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = {
1825 .session_create = pppol2tp_session_create,
1826 .session_delete = l2tp_session_delete,
1829 #endif /* CONFIG_L2TP_V3 */
1831 static int __init pppol2tp_init(void)
1835 err = register_pernet_device(&pppol2tp_net_ops);
1839 err = proto_register(&pppol2tp_sk_proto, 0);
1841 goto out_unregister_pppol2tp_pernet;
1843 err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
1845 goto out_unregister_pppol2tp_proto;
1847 #ifdef CONFIG_L2TP_V3
1848 err = l2tp_nl_register_ops(L2TP_PWTYPE_PPP, &pppol2tp_nl_cmd_ops);
1850 goto out_unregister_pppox;
1853 printk(KERN_INFO "PPPoL2TP kernel driver, %s\n",
1854 PPPOL2TP_DRV_VERSION);
1859 #ifdef CONFIG_L2TP_V3
1860 out_unregister_pppox:
1861 unregister_pppox_proto(PX_PROTO_OL2TP);
1863 out_unregister_pppol2tp_proto:
1864 proto_unregister(&pppol2tp_sk_proto);
1865 out_unregister_pppol2tp_pernet:
1866 unregister_pernet_device(&pppol2tp_net_ops);
1870 static void __exit pppol2tp_exit(void)
1872 #ifdef CONFIG_L2TP_V3
1873 l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP);
1875 unregister_pppox_proto(PX_PROTO_OL2TP);
1876 proto_unregister(&pppol2tp_sk_proto);
1877 unregister_pernet_device(&pppol2tp_net_ops);
1880 module_init(pppol2tp_init);
1881 module_exit(pppol2tp_exit);
1883 MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
1884 MODULE_DESCRIPTION("PPP over L2TP over UDP");
1885 MODULE_LICENSE("GPL");
1886 MODULE_VERSION(PPPOL2TP_DRV_VERSION);