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 static void pppol2tp_put_sk(struct rcu_head *head)
468 struct pppol2tp_session *ps;
470 ps = container_of(head, typeof(*ps), rcu);
474 /* Called by l2tp_core when a session socket is being closed.
476 static void pppol2tp_session_close(struct l2tp_session *session)
478 struct pppol2tp_session *ps;
480 ps = l2tp_session_priv(session);
481 mutex_lock(&ps->sk_lock);
482 ps->__sk = rcu_dereference_protected(ps->sk,
483 lockdep_is_held(&ps->sk_lock));
484 RCU_INIT_POINTER(ps->sk, NULL);
486 call_rcu(&ps->rcu, pppol2tp_put_sk);
487 mutex_unlock(&ps->sk_lock);
490 /* Really kill the session socket. (Called from sock_put() if
493 static void pppol2tp_session_destruct(struct sock *sk)
495 struct l2tp_session *session;
497 if (sk->sk_user_data != NULL) {
498 session = sk->sk_user_data;
502 sk->sk_user_data = NULL;
503 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
504 l2tp_session_dec_refcount(session);
511 /* Called when the PPPoX socket (session) is closed.
513 static int pppol2tp_release(struct socket *sock)
515 struct sock *sk = sock->sk;
516 struct l2tp_session *session;
524 if (sock_flag(sk, SOCK_DEAD) != 0)
527 pppox_unbind_sock(sk);
529 /* Signal the death of the socket. */
530 sk->sk_state = PPPOX_DEAD;
534 /* If the socket is associated with a session,
535 * l2tp_session_delete will call pppol2tp_session_close which
536 * will drop the session's ref on the socket.
538 session = pppol2tp_sock_to_session(sk);
540 l2tp_session_delete(session);
541 /* drop the ref obtained by pppol2tp_sock_to_session */
545 skb_queue_purge(&sk->sk_receive_queue);
546 skb_queue_purge(&sk->sk_write_queue);
550 /* This will delete the session context via
551 * pppol2tp_session_destruct() if the socket's refcnt drops to
563 static struct proto pppol2tp_sk_proto = {
565 .owner = THIS_MODULE,
566 .obj_size = sizeof(struct pppox_sock),
569 static int pppol2tp_backlog_recv(struct sock *sk, struct sk_buff *skb)
573 rc = l2tp_udp_encap_recv(sk, skb);
577 return NET_RX_SUCCESS;
580 /* socket() handler. Initialize a new struct sock.
582 static int pppol2tp_create(struct net *net, struct socket *sock)
587 sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto);
591 sock_init_data(sock, sk);
593 sock->state = SS_UNCONNECTED;
594 sock->ops = &pppol2tp_ops;
596 sk->sk_backlog_rcv = pppol2tp_backlog_recv;
597 sk->sk_protocol = PX_PROTO_OL2TP;
598 sk->sk_family = PF_PPPOX;
599 sk->sk_state = PPPOX_NONE;
600 sk->sk_type = SOCK_STREAM;
601 sk->sk_destruct = pppol2tp_session_destruct;
609 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
610 static void pppol2tp_show(struct seq_file *m, void *arg)
612 struct l2tp_session *session = arg;
615 sk = pppol2tp_session_get_sock(session);
617 struct pppox_sock *po = pppox_sk(sk);
619 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
625 static void pppol2tp_session_init(struct l2tp_session *session)
627 struct pppol2tp_session *ps;
628 struct dst_entry *dst;
630 session->recv_skb = pppol2tp_recv;
631 session->session_close = pppol2tp_session_close;
632 #if IS_ENABLED(CONFIG_L2TP_DEBUGFS)
633 session->show = pppol2tp_show;
636 ps = l2tp_session_priv(session);
637 mutex_init(&ps->sk_lock);
638 ps->tunnel_sock = session->tunnel->sock;
639 ps->owner = current->pid;
641 /* If PMTU discovery was enabled, use the MTU that was discovered */
642 dst = sk_dst_get(session->tunnel->sock);
644 u32 pmtu = dst_mtu(dst);
647 session->mtu = pmtu - PPPOL2TP_HEADER_OVERHEAD;
648 session->mru = pmtu - PPPOL2TP_HEADER_OVERHEAD;
654 /* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
656 static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
657 int sockaddr_len, int flags)
659 struct sock *sk = sock->sk;
660 struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr;
661 struct sockaddr_pppol2tpv3 *sp3 = (struct sockaddr_pppol2tpv3 *) uservaddr;
662 struct pppox_sock *po = pppox_sk(sk);
663 struct l2tp_session *session = NULL;
664 struct l2tp_tunnel *tunnel;
665 struct pppol2tp_session *ps;
666 struct l2tp_session_cfg cfg = { 0, };
668 u32 tunnel_id, peer_tunnel_id;
669 u32 session_id, peer_session_id;
670 bool drop_refcnt = false;
671 bool drop_tunnel = false;
678 if (sp->sa_protocol != PX_PROTO_OL2TP)
681 /* Check for already bound sockets */
683 if (sk->sk_state & PPPOX_CONNECTED)
686 /* We don't supporting rebinding anyway */
688 if (sk->sk_user_data)
689 goto end; /* socket is already attached */
691 /* Get params from socket address. Handle L2TPv2 and L2TPv3 */
692 if (sockaddr_len == sizeof(struct sockaddr_pppol2tp)) {
693 fd = sp->pppol2tp.fd;
694 tunnel_id = sp->pppol2tp.s_tunnel;
695 peer_tunnel_id = sp->pppol2tp.d_tunnel;
696 session_id = sp->pppol2tp.s_session;
697 peer_session_id = sp->pppol2tp.d_session;
698 } else if (sockaddr_len == sizeof(struct sockaddr_pppol2tpv3)) {
700 fd = sp3->pppol2tp.fd;
701 tunnel_id = sp3->pppol2tp.s_tunnel;
702 peer_tunnel_id = sp3->pppol2tp.d_tunnel;
703 session_id = sp3->pppol2tp.s_session;
704 peer_session_id = sp3->pppol2tp.d_session;
707 goto end; /* bad socket address */
710 /* Don't bind if tunnel_id is 0 */
715 tunnel = l2tp_tunnel_get(sock_net(sk), tunnel_id);
719 /* Special case: create tunnel context if session_id and
720 * peer_session_id is 0. Otherwise look up tunnel using supplied
723 if ((session_id == 0) && (peer_session_id == 0)) {
724 if (tunnel == NULL) {
725 struct l2tp_tunnel_cfg tcfg = {
726 .encap = L2TP_ENCAPTYPE_UDP,
729 error = l2tp_tunnel_create(sock_net(sk), fd, ver, tunnel_id, peer_tunnel_id, &tcfg, &tunnel);
734 /* Error if we can't find the tunnel */
739 /* Error if socket is not prepped */
740 if (tunnel->sock == NULL)
744 if (tunnel->recv_payload_hook == NULL)
745 tunnel->recv_payload_hook = pppol2tp_recv_payload_hook;
747 if (tunnel->peer_tunnel_id == 0) {
749 tunnel->peer_tunnel_id = sp->pppol2tp.d_tunnel;
751 tunnel->peer_tunnel_id = sp3->pppol2tp.d_tunnel;
754 session = l2tp_session_get(sock_net(sk), tunnel, session_id, false);
757 ps = l2tp_session_priv(session);
759 /* Using a pre-existing session is fine as long as it hasn't
760 * been connected yet.
762 mutex_lock(&ps->sk_lock);
763 if (rcu_dereference_protected(ps->sk,
764 lockdep_is_held(&ps->sk_lock))) {
765 mutex_unlock(&ps->sk_lock);
770 /* consistency checks */
771 if (ps->tunnel_sock != tunnel->sock) {
772 mutex_unlock(&ps->sk_lock);
777 /* Default MTU must allow space for UDP/L2TP/PPP headers */
778 cfg.mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
781 session = l2tp_session_create(sizeof(struct pppol2tp_session),
783 peer_session_id, &cfg);
784 if (IS_ERR(session)) {
785 error = PTR_ERR(session);
789 pppol2tp_session_init(session);
790 ps = l2tp_session_priv(session);
791 l2tp_session_inc_refcount(session);
793 mutex_lock(&ps->sk_lock);
794 error = l2tp_session_register(session, tunnel);
796 mutex_unlock(&ps->sk_lock);
803 /* Special case: if source & dest session_id == 0x0000, this
804 * socket is being created to manage the tunnel. Just set up
805 * the internal context for use by ioctl() and sockopt()
808 if ((session->session_id == 0) &&
809 (session->peer_session_id == 0)) {
814 /* The only header we need to worry about is the L2TP
815 * header. This size is different depending on whether
816 * sequence numbers are enabled for the data channel.
818 po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
820 po->chan.private = sk;
821 po->chan.ops = &pppol2tp_chan_ops;
822 po->chan.mtu = session->mtu;
824 error = ppp_register_net_channel(sock_net(sk), &po->chan);
826 mutex_unlock(&ps->sk_lock);
831 /* This is how we get the session context from the socket. */
833 sk->sk_user_data = session;
834 rcu_assign_pointer(ps->sk, sk);
835 mutex_unlock(&ps->sk_lock);
837 /* Keep the reference we've grabbed on the session: sk doesn't expect
838 * the session to disappear. pppol2tp_session_destruct() is responsible
843 sk->sk_state = PPPOX_CONNECTED;
844 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
845 "%s: created\n", session->name);
849 l2tp_session_dec_refcount(session);
851 l2tp_tunnel_dec_refcount(tunnel);
857 #ifdef CONFIG_L2TP_V3
859 /* Called when creating sessions via the netlink interface. */
860 static int pppol2tp_session_create(struct net *net, struct l2tp_tunnel *tunnel,
861 u32 session_id, u32 peer_session_id,
862 struct l2tp_session_cfg *cfg)
865 struct l2tp_session *session;
867 /* Error if tunnel socket is not prepped */
873 /* Default MTU values. */
875 cfg->mtu = 1500 - PPPOL2TP_HEADER_OVERHEAD;
879 /* Allocate and initialize a new session context. */
880 session = l2tp_session_create(sizeof(struct pppol2tp_session),
882 peer_session_id, cfg);
883 if (IS_ERR(session)) {
884 error = PTR_ERR(session);
888 pppol2tp_session_init(session);
890 error = l2tp_session_register(session, tunnel);
902 #endif /* CONFIG_L2TP_V3 */
904 /* getname() support.
906 static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
907 int *usockaddr_len, int peer)
911 struct l2tp_session *session;
912 struct l2tp_tunnel *tunnel;
913 struct sock *sk = sock->sk;
914 struct inet_sock *inet;
915 struct pppol2tp_session *pls;
920 if (sk->sk_state != PPPOX_CONNECTED)
924 session = pppol2tp_sock_to_session(sk);
928 pls = l2tp_session_priv(session);
929 tunnel = l2tp_sock_to_tunnel(pls->tunnel_sock);
933 inet = inet_sk(tunnel->sock);
934 if (tunnel->version == 2) {
935 struct sockaddr_pppol2tp sp;
938 sp.sa_family = AF_PPPOX;
939 sp.sa_protocol = PX_PROTO_OL2TP;
940 sp.pppol2tp.fd = tunnel->fd;
941 sp.pppol2tp.pid = pls->owner;
942 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
943 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
944 sp.pppol2tp.s_session = session->session_id;
945 sp.pppol2tp.d_session = session->peer_session_id;
946 sp.pppol2tp.addr.sin_family = AF_INET;
947 sp.pppol2tp.addr.sin_port = inet->inet_dport;
948 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
949 memcpy(uaddr, &sp, len);
950 } else if (tunnel->version == 3) {
951 struct sockaddr_pppol2tpv3 sp;
954 sp.sa_family = AF_PPPOX;
955 sp.sa_protocol = PX_PROTO_OL2TP;
956 sp.pppol2tp.fd = tunnel->fd;
957 sp.pppol2tp.pid = pls->owner;
958 sp.pppol2tp.s_tunnel = tunnel->tunnel_id;
959 sp.pppol2tp.d_tunnel = tunnel->peer_tunnel_id;
960 sp.pppol2tp.s_session = session->session_id;
961 sp.pppol2tp.d_session = session->peer_session_id;
962 sp.pppol2tp.addr.sin_family = AF_INET;
963 sp.pppol2tp.addr.sin_port = inet->inet_dport;
964 sp.pppol2tp.addr.sin_addr.s_addr = inet->inet_daddr;
965 memcpy(uaddr, &sp, len);
968 *usockaddr_len = len;
971 sock_put(pls->tunnel_sock);
978 /****************************************************************************
981 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
982 * sockets. However, in order to control kernel tunnel features, we allow
983 * userspace to create a special "tunnel" PPPoX socket which is used for
984 * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
985 * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
987 ****************************************************************************/
989 static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest,
990 struct l2tp_stats *stats)
992 dest->tx_packets = stats->tx_packets;
993 dest->tx_bytes = stats->tx_bytes;
994 dest->tx_errors = stats->tx_errors;
995 dest->rx_packets = stats->rx_packets;
996 dest->rx_bytes = stats->rx_bytes;
997 dest->rx_seq_discards = stats->rx_seq_discards;
998 dest->rx_oos_packets = stats->rx_oos_packets;
999 dest->rx_errors = stats->rx_errors;
1002 /* Session ioctl helper.
1004 static int pppol2tp_session_ioctl(struct l2tp_session *session,
1005 unsigned int cmd, unsigned long arg)
1010 int val = (int) arg;
1011 struct pppol2tp_session *ps = l2tp_session_priv(session);
1012 struct l2tp_tunnel *tunnel = session->tunnel;
1013 struct pppol2tp_ioc_stats stats;
1015 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1016 "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
1017 session->name, cmd, arg);
1019 sk = pppol2tp_session_get_sock(session);
1026 if (!(sk->sk_state & PPPOX_CONNECTED))
1030 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1032 ifr.ifr_mtu = session->mtu;
1033 if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
1036 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1037 "%s: get mtu=%d\n", session->name, session->mtu);
1043 if (!(sk->sk_state & PPPOX_CONNECTED))
1047 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1050 session->mtu = ifr.ifr_mtu;
1052 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1053 "%s: set mtu=%d\n", session->name, session->mtu);
1059 if (!(sk->sk_state & PPPOX_CONNECTED))
1063 if (put_user(session->mru, (int __user *) arg))
1066 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1067 "%s: get mru=%d\n", session->name, session->mru);
1073 if (!(sk->sk_state & PPPOX_CONNECTED))
1077 if (get_user(val, (int __user *) arg))
1081 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1082 "%s: set mru=%d\n", session->name, session->mru);
1088 if (put_user(ps->flags, (int __user *) arg))
1091 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1092 "%s: get flags=%d\n", session->name, ps->flags);
1098 if (get_user(val, (int __user *) arg))
1101 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1102 "%s: set flags=%d\n", session->name, ps->flags);
1106 case PPPIOCGL2TPSTATS:
1108 if (!(sk->sk_state & PPPOX_CONNECTED))
1111 memset(&stats, 0, sizeof(stats));
1112 stats.tunnel_id = tunnel->tunnel_id;
1113 stats.session_id = session->session_id;
1114 pppol2tp_copy_stats(&stats, &session->stats);
1115 if (copy_to_user((void __user *) arg, &stats,
1118 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1119 "%s: get L2TP stats\n", session->name);
1133 /* Tunnel ioctl helper.
1135 * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
1136 * specifies a session_id, the session ioctl handler is called. This allows an
1137 * application to retrieve session stats via a tunnel socket.
1139 static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel *tunnel,
1140 unsigned int cmd, unsigned long arg)
1144 struct pppol2tp_ioc_stats stats;
1146 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1147 "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n",
1148 tunnel->name, cmd, arg);
1154 case PPPIOCGL2TPSTATS:
1156 if (!(sk->sk_state & PPPOX_CONNECTED))
1159 if (copy_from_user(&stats, (void __user *) arg,
1164 if (stats.session_id != 0) {
1165 /* resend to session ioctl handler */
1166 struct l2tp_session *session =
1167 l2tp_session_get(sock_net(sk), tunnel,
1168 stats.session_id, true);
1171 err = pppol2tp_session_ioctl(session, cmd,
1174 session->deref(session);
1175 l2tp_session_dec_refcount(session);
1182 stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
1184 pppol2tp_copy_stats(&stats, &tunnel->stats);
1185 if (copy_to_user((void __user *) arg, &stats, sizeof(stats))) {
1189 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1190 "%s: get L2TP stats\n", tunnel->name);
1204 /* Main ioctl() handler.
1205 * Dispatch to tunnel or session helpers depending on the socket.
1207 static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1210 struct sock *sk = sock->sk;
1211 struct l2tp_session *session;
1212 struct l2tp_tunnel *tunnel;
1213 struct pppol2tp_session *ps;
1220 if (sock_flag(sk, SOCK_DEAD) != 0)
1224 if ((sk->sk_user_data == NULL) ||
1225 (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
1228 /* Get session context from the socket */
1230 session = pppol2tp_sock_to_session(sk);
1231 if (session == NULL)
1234 /* Special case: if session's session_id is zero, treat ioctl as a
1237 ps = l2tp_session_priv(session);
1238 if ((session->session_id == 0) &&
1239 (session->peer_session_id == 0)) {
1241 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1245 err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
1246 sock_put(ps->tunnel_sock);
1250 err = pppol2tp_session_ioctl(session, cmd, arg);
1258 /*****************************************************************************
1259 * setsockopt() / getsockopt() support.
1261 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1262 * sockets. In order to control kernel tunnel features, we allow userspace to
1263 * create a special "tunnel" PPPoX socket which is used for control only.
1264 * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
1265 * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
1266 *****************************************************************************/
1268 /* Tunnel setsockopt() helper.
1270 static int pppol2tp_tunnel_setsockopt(struct sock *sk,
1271 struct l2tp_tunnel *tunnel,
1272 int optname, int val)
1277 case PPPOL2TP_SO_DEBUG:
1278 tunnel->debug = val;
1279 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1280 "%s: set debug=%x\n", tunnel->name, tunnel->debug);
1291 /* Session setsockopt helper.
1293 static int pppol2tp_session_setsockopt(struct sock *sk,
1294 struct l2tp_session *session,
1295 int optname, int val)
1300 case PPPOL2TP_SO_RECVSEQ:
1301 if ((val != 0) && (val != 1)) {
1305 session->recv_seq = val ? -1 : 0;
1306 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1307 "%s: set recv_seq=%d\n", session->name, session->recv_seq);
1310 case PPPOL2TP_SO_SENDSEQ:
1311 if ((val != 0) && (val != 1)) {
1315 session->send_seq = val ? -1 : 0;
1317 struct pppox_sock *po = pppox_sk(sk);
1319 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1320 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1322 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1323 "%s: set send_seq=%d\n", session->name, session->send_seq);
1326 case PPPOL2TP_SO_LNSMODE:
1327 if ((val != 0) && (val != 1)) {
1331 session->lns_mode = val ? -1 : 0;
1332 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1333 "%s: set lns_mode=%d\n", session->name, session->lns_mode);
1336 case PPPOL2TP_SO_DEBUG:
1337 session->debug = val;
1338 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1339 "%s: set debug=%x\n", session->name, session->debug);
1342 case PPPOL2TP_SO_REORDERTO:
1343 session->reorder_timeout = msecs_to_jiffies(val);
1344 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1345 "%s: set reorder_timeout=%d\n", session->name, session->reorder_timeout);
1356 /* Main setsockopt() entry point.
1357 * Does API checks, then calls either the tunnel or session setsockopt
1358 * handler, according to whether the PPPoL2TP socket is a for a regular
1359 * session or the special tunnel type.
1361 static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
1362 char __user *optval, unsigned int optlen)
1364 struct sock *sk = sock->sk;
1365 struct l2tp_session *session;
1366 struct l2tp_tunnel *tunnel;
1367 struct pppol2tp_session *ps;
1371 if (level != SOL_PPPOL2TP)
1374 if (optlen < sizeof(int))
1377 if (get_user(val, (int __user *)optval))
1381 if (sk->sk_user_data == NULL)
1384 /* Get session context from the socket */
1386 session = pppol2tp_sock_to_session(sk);
1387 if (session == NULL)
1390 /* Special case: if session_id == 0x0000, treat as operation on tunnel
1392 ps = l2tp_session_priv(session);
1393 if ((session->session_id == 0) &&
1394 (session->peer_session_id == 0)) {
1396 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1400 err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
1401 sock_put(ps->tunnel_sock);
1403 err = pppol2tp_session_setsockopt(sk, session, optname, val);
1411 /* Tunnel getsockopt helper. Called with sock locked.
1413 static int pppol2tp_tunnel_getsockopt(struct sock *sk,
1414 struct l2tp_tunnel *tunnel,
1415 int optname, int *val)
1420 case PPPOL2TP_SO_DEBUG:
1421 *val = tunnel->debug;
1422 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1423 "%s: get debug=%x\n", tunnel->name, tunnel->debug);
1434 /* Session getsockopt helper. Called with sock locked.
1436 static int pppol2tp_session_getsockopt(struct sock *sk,
1437 struct l2tp_session *session,
1438 int optname, int *val)
1443 case PPPOL2TP_SO_RECVSEQ:
1444 *val = session->recv_seq;
1445 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1446 "%s: get recv_seq=%d\n", session->name, *val);
1449 case PPPOL2TP_SO_SENDSEQ:
1450 *val = session->send_seq;
1451 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1452 "%s: get send_seq=%d\n", session->name, *val);
1455 case PPPOL2TP_SO_LNSMODE:
1456 *val = session->lns_mode;
1457 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1458 "%s: get lns_mode=%d\n", session->name, *val);
1461 case PPPOL2TP_SO_DEBUG:
1462 *val = session->debug;
1463 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1464 "%s: get debug=%d\n", session->name, *val);
1467 case PPPOL2TP_SO_REORDERTO:
1468 *val = (int) jiffies_to_msecs(session->reorder_timeout);
1469 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1470 "%s: get reorder_timeout=%d\n", session->name, *val);
1480 /* Main getsockopt() entry point.
1481 * Does API checks, then calls either the tunnel or session getsockopt
1482 * handler, according to whether the PPPoX socket is a for a regular session
1483 * or the special tunnel type.
1485 static int pppol2tp_getsockopt(struct socket *sock, int level,
1486 int optname, char __user *optval, int __user *optlen)
1488 struct sock *sk = sock->sk;
1489 struct l2tp_session *session;
1490 struct l2tp_tunnel *tunnel;
1493 struct pppol2tp_session *ps;
1495 if (level != SOL_PPPOL2TP)
1498 if (get_user(len, (int __user *) optlen))
1501 len = min_t(unsigned int, len, sizeof(int));
1507 if (sk->sk_user_data == NULL)
1510 /* Get the session context */
1512 session = pppol2tp_sock_to_session(sk);
1513 if (session == NULL)
1516 /* Special case: if session_id == 0x0000, treat as operation on tunnel */
1517 ps = l2tp_session_priv(session);
1518 if ((session->session_id == 0) &&
1519 (session->peer_session_id == 0)) {
1521 tunnel = l2tp_sock_to_tunnel(ps->tunnel_sock);
1525 err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
1526 sock_put(ps->tunnel_sock);
1530 err = pppol2tp_session_getsockopt(sk, session, optname, &val);
1536 if (put_user(len, (int __user *) optlen))
1539 if (copy_to_user((void __user *) optval, &val, len))
1550 /*****************************************************************************
1551 * /proc filesystem for debug
1552 * Since the original pppol2tp driver provided /proc/net/pppol2tp for
1553 * L2TPv2, we dump only L2TPv2 tunnels and sessions here.
1554 *****************************************************************************/
1556 static unsigned int pppol2tp_net_id;
1558 #ifdef CONFIG_PROC_FS
1560 struct pppol2tp_seq_data {
1561 struct seq_net_private p;
1562 int tunnel_idx; /* current tunnel */
1563 int session_idx; /* index of session within current tunnel */
1564 struct l2tp_tunnel *tunnel;
1565 struct l2tp_session *session; /* NULL means get next tunnel */
1568 static void pppol2tp_next_tunnel(struct net *net, struct pppol2tp_seq_data *pd)
1571 pd->tunnel = l2tp_tunnel_find_nth(net, pd->tunnel_idx);
1574 if (pd->tunnel == NULL)
1577 /* Ignore L2TPv3 tunnels */
1578 if (pd->tunnel->version < 3)
1583 static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
1585 pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx, true);
1588 if (pd->session == NULL) {
1589 pd->session_idx = 0;
1590 pppol2tp_next_tunnel(net, pd);
1594 static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
1596 struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
1603 BUG_ON(m->private == NULL);
1605 net = seq_file_net(m);
1607 if (pd->tunnel == NULL)
1608 pppol2tp_next_tunnel(net, pd);
1610 pppol2tp_next_session(net, pd);
1612 /* NULL tunnel and session indicates end of list */
1613 if ((pd->tunnel == NULL) && (pd->session == NULL))
1620 static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
1626 static void pppol2tp_seq_stop(struct seq_file *p, void *v)
1631 static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
1633 struct l2tp_tunnel *tunnel = v;
1635 seq_printf(m, "\nTUNNEL '%s', %c %d\n",
1637 (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N',
1638 atomic_read(&tunnel->ref_count) - 1);
1639 seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n",
1641 (unsigned long long)tunnel->stats.tx_packets,
1642 (unsigned long long)tunnel->stats.tx_bytes,
1643 (unsigned long long)tunnel->stats.tx_errors,
1644 (unsigned long long)tunnel->stats.rx_packets,
1645 (unsigned long long)tunnel->stats.rx_bytes,
1646 (unsigned long long)tunnel->stats.rx_errors);
1649 static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
1651 struct l2tp_session *session = v;
1652 struct l2tp_tunnel *tunnel = session->tunnel;
1653 unsigned char state;
1660 struct inet_sock *inet = inet_sk(tunnel->sock);
1661 ip = ntohl(inet->inet_saddr);
1662 port = ntohs(inet->inet_sport);
1665 sk = pppol2tp_session_get_sock(session);
1667 state = sk->sk_state;
1668 user_data_ok = (session == sk->sk_user_data) ? 'Y' : 'N';
1674 seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
1675 "%04X/%04X %d %c\n",
1676 session->name, ip, port,
1678 session->session_id,
1679 tunnel->peer_tunnel_id,
1680 session->peer_session_id,
1681 state, user_data_ok);
1682 seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
1683 session->mtu, session->mru,
1684 session->recv_seq ? 'R' : '-',
1685 session->send_seq ? 'S' : '-',
1686 session->lns_mode ? "LNS" : "LAC",
1688 jiffies_to_msecs(session->reorder_timeout));
1689 seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n",
1690 session->nr, session->ns,
1691 (unsigned long long)session->stats.tx_packets,
1692 (unsigned long long)session->stats.tx_bytes,
1693 (unsigned long long)session->stats.tx_errors,
1694 (unsigned long long)session->stats.rx_packets,
1695 (unsigned long long)session->stats.rx_bytes,
1696 (unsigned long long)session->stats.rx_errors);
1699 struct pppox_sock *po = pppox_sk(sk);
1701 seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
1706 static int pppol2tp_seq_show(struct seq_file *m, void *v)
1708 struct pppol2tp_seq_data *pd = v;
1710 /* display header on line 1 */
1711 if (v == SEQ_START_TOKEN) {
1712 seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
1713 seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
1714 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1715 seq_puts(m, " SESSION name, addr/port src-tid/sid "
1716 "dest-tid/sid state user-data-ok\n");
1717 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
1718 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1722 /* Show the tunnel or session context.
1725 pppol2tp_seq_tunnel_show(m, pd->tunnel);
1727 pppol2tp_seq_session_show(m, pd->session);
1728 if (pd->session->deref)
1729 pd->session->deref(pd->session);
1730 l2tp_session_dec_refcount(pd->session);
1737 static const struct seq_operations pppol2tp_seq_ops = {
1738 .start = pppol2tp_seq_start,
1739 .next = pppol2tp_seq_next,
1740 .stop = pppol2tp_seq_stop,
1741 .show = pppol2tp_seq_show,
1744 /* Called when our /proc file is opened. We allocate data for use when
1745 * iterating our tunnel / session contexts and store it in the private
1746 * data of the seq_file.
1748 static int pppol2tp_proc_open(struct inode *inode, struct file *file)
1750 return seq_open_net(inode, file, &pppol2tp_seq_ops,
1751 sizeof(struct pppol2tp_seq_data));
1754 static const struct file_operations pppol2tp_proc_fops = {
1755 .owner = THIS_MODULE,
1756 .open = pppol2tp_proc_open,
1758 .llseek = seq_lseek,
1759 .release = seq_release_net,
1762 #endif /* CONFIG_PROC_FS */
1764 /*****************************************************************************
1766 *****************************************************************************/
1768 static __net_init int pppol2tp_init_net(struct net *net)
1770 struct proc_dir_entry *pde;
1773 pde = proc_net_fops_create(net, "pppol2tp", S_IRUGO, &pppol2tp_proc_fops);
1783 static __net_exit void pppol2tp_exit_net(struct net *net)
1785 proc_net_remove(net, "pppol2tp");
1788 static struct pernet_operations pppol2tp_net_ops = {
1789 .init = pppol2tp_init_net,
1790 .exit = pppol2tp_exit_net,
1791 .id = &pppol2tp_net_id,
1794 /*****************************************************************************
1796 *****************************************************************************/
1798 static const struct proto_ops pppol2tp_ops = {
1800 .owner = THIS_MODULE,
1801 .release = pppol2tp_release,
1802 .bind = sock_no_bind,
1803 .connect = pppol2tp_connect,
1804 .socketpair = sock_no_socketpair,
1805 .accept = sock_no_accept,
1806 .getname = pppol2tp_getname,
1807 .poll = datagram_poll,
1808 .listen = sock_no_listen,
1809 .shutdown = sock_no_shutdown,
1810 .setsockopt = pppol2tp_setsockopt,
1811 .getsockopt = pppol2tp_getsockopt,
1812 .sendmsg = pppol2tp_sendmsg,
1813 .recvmsg = pppol2tp_recvmsg,
1814 .mmap = sock_no_mmap,
1815 .ioctl = pppox_ioctl,
1818 static const struct pppox_proto pppol2tp_proto = {
1819 .create = pppol2tp_create,
1820 .ioctl = pppol2tp_ioctl,
1821 .owner = THIS_MODULE,
1824 #ifdef CONFIG_L2TP_V3
1826 static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = {
1827 .session_create = pppol2tp_session_create,
1828 .session_delete = l2tp_session_delete,
1831 #endif /* CONFIG_L2TP_V3 */
1833 static int __init pppol2tp_init(void)
1837 err = register_pernet_device(&pppol2tp_net_ops);
1841 err = proto_register(&pppol2tp_sk_proto, 0);
1843 goto out_unregister_pppol2tp_pernet;
1845 err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
1847 goto out_unregister_pppol2tp_proto;
1849 #ifdef CONFIG_L2TP_V3
1850 err = l2tp_nl_register_ops(L2TP_PWTYPE_PPP, &pppol2tp_nl_cmd_ops);
1852 goto out_unregister_pppox;
1855 printk(KERN_INFO "PPPoL2TP kernel driver, %s\n",
1856 PPPOL2TP_DRV_VERSION);
1861 #ifdef CONFIG_L2TP_V3
1862 out_unregister_pppox:
1863 unregister_pppox_proto(PX_PROTO_OL2TP);
1865 out_unregister_pppol2tp_proto:
1866 proto_unregister(&pppol2tp_sk_proto);
1867 out_unregister_pppol2tp_pernet:
1868 unregister_pernet_device(&pppol2tp_net_ops);
1872 static void __exit pppol2tp_exit(void)
1874 #ifdef CONFIG_L2TP_V3
1875 l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP);
1877 unregister_pppox_proto(PX_PROTO_OL2TP);
1878 proto_unregister(&pppol2tp_sk_proto);
1879 unregister_pernet_device(&pppol2tp_net_ops);
1882 module_init(pppol2tp_init);
1883 module_exit(pppol2tp_exit);
1885 MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
1886 MODULE_DESCRIPTION("PPP over L2TP over UDP");
1887 MODULE_LICENSE("GPL");
1888 MODULE_VERSION(PPPOL2TP_DRV_VERSION);