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
)
203 msg
->msg_namelen
= 0;
206 skb
= skb_recv_datagram(sk
, flags
& ~MSG_DONTWAIT
,
207 flags
& MSG_DONTWAIT
, &err
);
213 else if (len
< skb
->len
)
214 msg
->msg_flags
|= MSG_TRUNC
;
216 err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, len
);
217 if (likely(err
== 0))
225 static void pppol2tp_recv(struct l2tp_session
*session
, struct sk_buff
*skb
, int data_len
)
227 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
228 struct sock
*sk
= NULL
;
230 /* If the socket is bound, send it in to PPP's input queue. Otherwise
231 * queue it on the session socket.
237 if (sk
->sk_state
& PPPOX_BOUND
) {
238 struct pppox_sock
*po
;
239 PRINTK(session
->debug
, PPPOL2TP_MSG_DATA
, KERN_DEBUG
,
240 "%s: recv %d byte data frame, passing to ppp\n",
241 session
->name
, data_len
);
243 /* We need to forget all info related to the L2TP packet
244 * gathered in the skb as we are going to reuse the same
245 * skb for the inner packet.
247 * - reset xfrm (IPSec) information as it applies to
248 * the outer L2TP packet and not to the inner one
249 * - release the dst to force a route lookup on the inner
250 * IP packet since skb->dst currently points to the dst
252 * - reset netfilter information as it doesn't apply
253 * to the inner packet either
260 ppp_input(&po
->chan
, skb
);
262 PRINTK(session
->debug
, PPPOL2TP_MSG_DATA
, KERN_INFO
,
263 "%s: socket not bound\n", session
->name
);
265 /* Not bound. Nothing we can do, so discard. */
266 session
->stats
.rx_errors
++;
273 PRINTK(session
->debug
, PPPOL2TP_MSG_DATA
, KERN_INFO
,
274 "%s: no socket\n", session
->name
);
278 static void pppol2tp_session_sock_hold(struct l2tp_session
*session
)
280 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
286 static void pppol2tp_session_sock_put(struct l2tp_session
*session
)
288 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
294 /************************************************************************
296 ***********************************************************************/
298 /* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here
299 * when a user application does a sendmsg() on the session socket. L2TP and
300 * PPP headers must be inserted into the user's data.
302 static int pppol2tp_sendmsg(struct kiocb
*iocb
, struct socket
*sock
, struct msghdr
*m
,
305 static const unsigned char ppph
[2] = { 0xff, 0x03 };
306 struct sock
*sk
= sock
->sk
;
309 struct l2tp_session
*session
;
310 struct l2tp_tunnel
*tunnel
;
311 struct pppol2tp_session
*ps
;
315 if (sock_flag(sk
, SOCK_DEAD
) || !(sk
->sk_state
& PPPOX_CONNECTED
))
318 /* Get session and tunnel contexts */
320 session
= pppol2tp_sock_to_session(sk
);
324 ps
= l2tp_session_priv(session
);
325 tunnel
= l2tp_sock_to_tunnel(ps
->tunnel_sock
);
329 uhlen
= (tunnel
->encap
== L2TP_ENCAPTYPE_UDP
) ? sizeof(struct udphdr
) : 0;
331 /* Allocate a socket buffer */
333 skb
= sock_wmalloc(sk
, NET_SKB_PAD
+ sizeof(struct iphdr
) +
334 uhlen
+ session
->hdr_len
+
335 sizeof(ppph
) + total_len
,
338 goto error_put_sess_tun
;
340 /* Reserve space for headers. */
341 skb_reserve(skb
, NET_SKB_PAD
);
342 skb_reset_network_header(skb
);
343 skb_reserve(skb
, sizeof(struct iphdr
));
344 skb_reset_transport_header(skb
);
345 skb_reserve(skb
, uhlen
);
348 skb
->data
[0] = ppph
[0];
349 skb
->data
[1] = ppph
[1];
352 /* Copy user data into skb */
353 error
= memcpy_fromiovec(skb
->data
, m
->msg_iov
, total_len
);
356 goto error_put_sess_tun
;
358 skb_put(skb
, total_len
);
360 l2tp_xmit_skb(session
, skb
, session
->hdr_len
);
362 sock_put(ps
->tunnel_sock
);
367 sock_put(ps
->tunnel_sock
);
374 /* Transmit function called by generic PPP driver. Sends PPP frame
375 * over PPPoL2TP socket.
377 * This is almost the same as pppol2tp_sendmsg(), but rather than
378 * being called with a msghdr from userspace, it is called with a skb
381 * The supplied skb from ppp doesn't have enough headroom for the
382 * insertion of L2TP, UDP and IP headers so we need to allocate more
383 * headroom in the skb. This will create a cloned skb. But we must be
384 * careful in the error case because the caller will expect to free
385 * the skb it supplied, not our cloned skb. So we take care to always
386 * leave the original skb unfreed if we return an error.
388 static int pppol2tp_xmit(struct ppp_channel
*chan
, struct sk_buff
*skb
)
390 static const u8 ppph
[2] = { 0xff, 0x03 };
391 struct sock
*sk
= (struct sock
*) chan
->private;
393 struct l2tp_session
*session
;
394 struct l2tp_tunnel
*tunnel
;
395 struct pppol2tp_session
*ps
;
400 if (sock_flag(sk
, SOCK_DEAD
) || !(sk
->sk_state
& PPPOX_CONNECTED
))
403 /* Get session and tunnel contexts from the socket */
404 session
= pppol2tp_sock_to_session(sk
);
408 ps
= l2tp_session_priv(session
);
409 sk_tun
= ps
->tunnel_sock
;
412 tunnel
= l2tp_sock_to_tunnel(sk_tun
);
416 old_headroom
= skb_headroom(skb
);
417 uhlen
= (tunnel
->encap
== L2TP_ENCAPTYPE_UDP
) ? sizeof(struct udphdr
) : 0;
418 headroom
= NET_SKB_PAD
+
419 sizeof(struct iphdr
) + /* IP header */
420 uhlen
+ /* UDP header (if L2TP_ENCAPTYPE_UDP) */
421 session
->hdr_len
+ /* L2TP header */
422 sizeof(ppph
); /* PPP header */
423 if (skb_cow_head(skb
, headroom
))
424 goto abort_put_sess_tun
;
426 new_headroom
= skb_headroom(skb
);
427 skb
->truesize
+= new_headroom
- old_headroom
;
429 /* Setup PPP header */
430 __skb_push(skb
, sizeof(ppph
));
431 skb
->data
[0] = ppph
[0];
432 skb
->data
[1] = ppph
[1];
434 l2tp_xmit_skb(session
, skb
, session
->hdr_len
);
445 /* Free the original skb */
450 /*****************************************************************************
451 * Session (and tunnel control) socket create/destroy.
452 *****************************************************************************/
454 /* Called by l2tp_core when a session socket is being closed.
456 static void pppol2tp_session_close(struct l2tp_session
*session
)
458 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
459 struct sock
*sk
= ps
->sock
;
462 BUG_ON(session
->magic
!= L2TP_SESSION_MAGIC
);
464 if (session
->session_id
== 0)
470 if (sk
->sk_state
& (PPPOX_CONNECTED
| PPPOX_BOUND
)) {
471 pppox_unbind_sock(sk
);
472 sk
->sk_state
= PPPOX_DEAD
;
473 sk
->sk_state_change(sk
);
476 /* Purge any queued data */
477 skb_queue_purge(&sk
->sk_receive_queue
);
478 skb_queue_purge(&sk
->sk_write_queue
);
479 while ((skb
= skb_dequeue(&session
->reorder_q
))) {
491 /* Really kill the session socket. (Called from sock_put() if
494 static void pppol2tp_session_destruct(struct sock
*sk
)
496 struct l2tp_session
*session
;
498 if (sk
->sk_user_data
!= NULL
) {
499 session
= sk
->sk_user_data
;
503 sk
->sk_user_data
= NULL
;
504 BUG_ON(session
->magic
!= L2TP_SESSION_MAGIC
);
505 l2tp_session_dec_refcount(session
);
512 /* Called when the PPPoX socket (session) is closed.
514 static int pppol2tp_release(struct socket
*sock
)
516 struct sock
*sk
= sock
->sk
;
517 struct l2tp_session
*session
;
525 if (sock_flag(sk
, SOCK_DEAD
) != 0)
528 pppox_unbind_sock(sk
);
530 /* Signal the death of the socket. */
531 sk
->sk_state
= PPPOX_DEAD
;
535 session
= pppol2tp_sock_to_session(sk
);
537 /* Purge any queued data */
538 skb_queue_purge(&sk
->sk_receive_queue
);
539 skb_queue_purge(&sk
->sk_write_queue
);
540 if (session
!= NULL
) {
542 while ((skb
= skb_dequeue(&session
->reorder_q
))) {
551 /* This will delete the session context via
552 * pppol2tp_session_destruct() if the socket's refcnt drops to
564 static struct proto pppol2tp_sk_proto
= {
566 .owner
= THIS_MODULE
,
567 .obj_size
= sizeof(struct pppox_sock
),
570 static int pppol2tp_backlog_recv(struct sock
*sk
, struct sk_buff
*skb
)
574 rc
= l2tp_udp_encap_recv(sk
, skb
);
578 return NET_RX_SUCCESS
;
581 /* socket() handler. Initialize a new struct sock.
583 static int pppol2tp_create(struct net
*net
, struct socket
*sock
)
588 sk
= sk_alloc(net
, PF_PPPOX
, GFP_KERNEL
, &pppol2tp_sk_proto
);
592 sock_init_data(sock
, sk
);
594 sock
->state
= SS_UNCONNECTED
;
595 sock
->ops
= &pppol2tp_ops
;
597 sk
->sk_backlog_rcv
= pppol2tp_backlog_recv
;
598 sk
->sk_protocol
= PX_PROTO_OL2TP
;
599 sk
->sk_family
= PF_PPPOX
;
600 sk
->sk_state
= PPPOX_NONE
;
601 sk
->sk_type
= SOCK_STREAM
;
602 sk
->sk_destruct
= pppol2tp_session_destruct
;
610 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
611 static void pppol2tp_show(struct seq_file
*m
, void *arg
)
613 struct l2tp_session
*session
= arg
;
614 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
617 struct pppox_sock
*po
= pppox_sk(ps
->sock
);
619 seq_printf(m
, " interface %s\n", ppp_dev_name(&po
->chan
));
624 /* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
626 static int pppol2tp_connect(struct socket
*sock
, struct sockaddr
*uservaddr
,
627 int sockaddr_len
, int flags
)
629 struct sock
*sk
= sock
->sk
;
630 struct sockaddr_pppol2tp
*sp
= (struct sockaddr_pppol2tp
*) uservaddr
;
631 struct sockaddr_pppol2tpv3
*sp3
= (struct sockaddr_pppol2tpv3
*) uservaddr
;
632 struct pppox_sock
*po
= pppox_sk(sk
);
633 struct l2tp_session
*session
= NULL
;
634 struct l2tp_tunnel
*tunnel
;
635 struct pppol2tp_session
*ps
;
636 struct dst_entry
*dst
;
637 struct l2tp_session_cfg cfg
= { 0, };
639 u32 tunnel_id
, peer_tunnel_id
;
640 u32 session_id
, peer_session_id
;
647 if (sp
->sa_protocol
!= PX_PROTO_OL2TP
)
650 /* Check for already bound sockets */
652 if (sk
->sk_state
& PPPOX_CONNECTED
)
655 /* We don't supporting rebinding anyway */
657 if (sk
->sk_user_data
)
658 goto end
; /* socket is already attached */
660 /* Get params from socket address. Handle L2TPv2 and L2TPv3 */
661 if (sockaddr_len
== sizeof(struct sockaddr_pppol2tp
)) {
662 fd
= sp
->pppol2tp
.fd
;
663 tunnel_id
= sp
->pppol2tp
.s_tunnel
;
664 peer_tunnel_id
= sp
->pppol2tp
.d_tunnel
;
665 session_id
= sp
->pppol2tp
.s_session
;
666 peer_session_id
= sp
->pppol2tp
.d_session
;
667 } else if (sockaddr_len
== sizeof(struct sockaddr_pppol2tpv3
)) {
669 fd
= sp3
->pppol2tp
.fd
;
670 tunnel_id
= sp3
->pppol2tp
.s_tunnel
;
671 peer_tunnel_id
= sp3
->pppol2tp
.d_tunnel
;
672 session_id
= sp3
->pppol2tp
.s_session
;
673 peer_session_id
= sp3
->pppol2tp
.d_session
;
676 goto end
; /* bad socket address */
679 /* Don't bind if tunnel_id is 0 */
684 tunnel
= l2tp_tunnel_find(sock_net(sk
), tunnel_id
);
686 /* Special case: create tunnel context if session_id and
687 * peer_session_id is 0. Otherwise look up tunnel using supplied
690 if ((session_id
== 0) && (peer_session_id
== 0)) {
691 if (tunnel
== NULL
) {
692 struct l2tp_tunnel_cfg tcfg
= {
693 .encap
= L2TP_ENCAPTYPE_UDP
,
696 error
= l2tp_tunnel_create(sock_net(sk
), fd
, ver
, tunnel_id
, peer_tunnel_id
, &tcfg
, &tunnel
);
701 /* Error if we can't find the tunnel */
706 /* Error if socket is not prepped */
707 if (tunnel
->sock
== NULL
)
711 if (tunnel
->recv_payload_hook
== NULL
)
712 tunnel
->recv_payload_hook
= pppol2tp_recv_payload_hook
;
714 if (tunnel
->peer_tunnel_id
== 0) {
716 tunnel
->peer_tunnel_id
= sp
->pppol2tp
.d_tunnel
;
718 tunnel
->peer_tunnel_id
= sp3
->pppol2tp
.d_tunnel
;
721 /* Create session if it doesn't already exist. We handle the
722 * case where a session was previously created by the netlink
723 * interface by checking that the session doesn't already have
724 * a socket and its tunnel socket are what we expect. If any
725 * of those checks fail, return EEXIST to the caller.
727 session
= l2tp_session_find(sock_net(sk
), tunnel
, session_id
);
728 if (session
== NULL
) {
729 /* Default MTU must allow space for UDP/L2TP/PPP
732 cfg
.mtu
= cfg
.mru
= 1500 - PPPOL2TP_HEADER_OVERHEAD
;
734 /* Allocate and initialize a new session context. */
735 session
= l2tp_session_create(sizeof(struct pppol2tp_session
),
737 peer_session_id
, &cfg
);
738 if (session
== NULL
) {
743 ps
= l2tp_session_priv(session
);
745 if (ps
->sock
!= NULL
)
748 /* consistency checks */
749 if (ps
->tunnel_sock
!= tunnel
->sock
)
753 /* Associate session with its PPPoL2TP socket */
754 ps
= l2tp_session_priv(session
);
755 ps
->owner
= current
->pid
;
757 ps
->tunnel_sock
= tunnel
->sock
;
759 session
->recv_skb
= pppol2tp_recv
;
760 session
->session_close
= pppol2tp_session_close
;
761 #if defined(CONFIG_L2TP_DEBUGFS) || defined(CONFIG_L2TP_DEBUGFS_MODULE)
762 session
->show
= pppol2tp_show
;
765 /* We need to know each time a skb is dropped from the reorder
768 session
->ref
= pppol2tp_session_sock_hold
;
769 session
->deref
= pppol2tp_session_sock_put
;
771 /* If PMTU discovery was enabled, use the MTU that was discovered */
772 dst
= sk_dst_get(sk
);
774 u32 pmtu
= dst_mtu(__sk_dst_get(sk
));
776 session
->mtu
= session
->mru
= pmtu
-
777 PPPOL2TP_HEADER_OVERHEAD
;
781 /* Special case: if source & dest session_id == 0x0000, this
782 * socket is being created to manage the tunnel. Just set up
783 * the internal context for use by ioctl() and sockopt()
786 if ((session
->session_id
== 0) &&
787 (session
->peer_session_id
== 0)) {
792 /* The only header we need to worry about is the L2TP
793 * header. This size is different depending on whether
794 * sequence numbers are enabled for the data channel.
796 po
->chan
.hdrlen
= PPPOL2TP_L2TP_HDR_SIZE_NOSEQ
;
798 po
->chan
.private = sk
;
799 po
->chan
.ops
= &pppol2tp_chan_ops
;
800 po
->chan
.mtu
= session
->mtu
;
802 error
= ppp_register_net_channel(sock_net(sk
), &po
->chan
);
807 /* This is how we get the session context from the socket. */
808 sk
->sk_user_data
= session
;
809 sk
->sk_state
= PPPOX_CONNECTED
;
810 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
811 "%s: created\n", session
->name
);
819 #ifdef CONFIG_L2TP_V3
821 /* Called when creating sessions via the netlink interface.
823 static int pppol2tp_session_create(struct net
*net
, u32 tunnel_id
, u32 session_id
, u32 peer_session_id
, struct l2tp_session_cfg
*cfg
)
826 struct l2tp_tunnel
*tunnel
;
827 struct l2tp_session
*session
;
828 struct pppol2tp_session
*ps
;
830 tunnel
= l2tp_tunnel_find(net
, tunnel_id
);
832 /* Error if we can't find the tunnel */
837 /* Error if tunnel socket is not prepped */
838 if (tunnel
->sock
== NULL
)
841 /* Check that this session doesn't already exist */
843 session
= l2tp_session_find(net
, tunnel
, session_id
);
847 /* Default MTU values. */
849 cfg
->mtu
= 1500 - PPPOL2TP_HEADER_OVERHEAD
;
853 /* Allocate and initialize a new session context. */
855 session
= l2tp_session_create(sizeof(struct pppol2tp_session
),
857 peer_session_id
, cfg
);
861 ps
= l2tp_session_priv(session
);
862 ps
->tunnel_sock
= tunnel
->sock
;
864 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
865 "%s: created\n", session
->name
);
873 /* Called when deleting sessions via the netlink interface.
875 static int pppol2tp_session_delete(struct l2tp_session
*session
)
877 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
879 if (ps
->sock
== NULL
)
880 l2tp_session_dec_refcount(session
);
885 #endif /* CONFIG_L2TP_V3 */
887 /* getname() support.
889 static int pppol2tp_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
890 int *usockaddr_len
, int peer
)
894 struct l2tp_session
*session
;
895 struct l2tp_tunnel
*tunnel
;
896 struct sock
*sk
= sock
->sk
;
897 struct inet_sock
*inet
;
898 struct pppol2tp_session
*pls
;
903 if (sk
->sk_state
!= PPPOX_CONNECTED
)
907 session
= pppol2tp_sock_to_session(sk
);
911 pls
= l2tp_session_priv(session
);
912 tunnel
= l2tp_sock_to_tunnel(pls
->tunnel_sock
);
913 if (tunnel
== NULL
) {
918 inet
= inet_sk(tunnel
->sock
);
919 if (tunnel
->version
== 2) {
920 struct sockaddr_pppol2tp sp
;
923 sp
.sa_family
= AF_PPPOX
;
924 sp
.sa_protocol
= PX_PROTO_OL2TP
;
925 sp
.pppol2tp
.fd
= tunnel
->fd
;
926 sp
.pppol2tp
.pid
= pls
->owner
;
927 sp
.pppol2tp
.s_tunnel
= tunnel
->tunnel_id
;
928 sp
.pppol2tp
.d_tunnel
= tunnel
->peer_tunnel_id
;
929 sp
.pppol2tp
.s_session
= session
->session_id
;
930 sp
.pppol2tp
.d_session
= session
->peer_session_id
;
931 sp
.pppol2tp
.addr
.sin_family
= AF_INET
;
932 sp
.pppol2tp
.addr
.sin_port
= inet
->inet_dport
;
933 sp
.pppol2tp
.addr
.sin_addr
.s_addr
= inet
->inet_daddr
;
934 memcpy(uaddr
, &sp
, len
);
935 } else if (tunnel
->version
== 3) {
936 struct sockaddr_pppol2tpv3 sp
;
939 sp
.sa_family
= AF_PPPOX
;
940 sp
.sa_protocol
= PX_PROTO_OL2TP
;
941 sp
.pppol2tp
.fd
= tunnel
->fd
;
942 sp
.pppol2tp
.pid
= pls
->owner
;
943 sp
.pppol2tp
.s_tunnel
= tunnel
->tunnel_id
;
944 sp
.pppol2tp
.d_tunnel
= tunnel
->peer_tunnel_id
;
945 sp
.pppol2tp
.s_session
= session
->session_id
;
946 sp
.pppol2tp
.d_session
= session
->peer_session_id
;
947 sp
.pppol2tp
.addr
.sin_family
= AF_INET
;
948 sp
.pppol2tp
.addr
.sin_port
= inet
->inet_dport
;
949 sp
.pppol2tp
.addr
.sin_addr
.s_addr
= inet
->inet_daddr
;
950 memcpy(uaddr
, &sp
, len
);
953 *usockaddr_len
= len
;
955 sock_put(pls
->tunnel_sock
);
964 /****************************************************************************
967 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
968 * sockets. However, in order to control kernel tunnel features, we allow
969 * userspace to create a special "tunnel" PPPoX socket which is used for
970 * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
971 * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
973 ****************************************************************************/
975 static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats
*dest
,
976 struct l2tp_stats
*stats
)
978 dest
->tx_packets
= stats
->tx_packets
;
979 dest
->tx_bytes
= stats
->tx_bytes
;
980 dest
->tx_errors
= stats
->tx_errors
;
981 dest
->rx_packets
= stats
->rx_packets
;
982 dest
->rx_bytes
= stats
->rx_bytes
;
983 dest
->rx_seq_discards
= stats
->rx_seq_discards
;
984 dest
->rx_oos_packets
= stats
->rx_oos_packets
;
985 dest
->rx_errors
= stats
->rx_errors
;
988 /* Session ioctl helper.
990 static int pppol2tp_session_ioctl(struct l2tp_session
*session
,
991 unsigned int cmd
, unsigned long arg
)
997 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
998 struct l2tp_tunnel
*tunnel
= session
->tunnel
;
999 struct pppol2tp_ioc_stats stats
;
1001 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_DEBUG
,
1002 "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
1003 session
->name
, cmd
, arg
);
1011 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
1015 if (copy_from_user(&ifr
, (void __user
*) arg
, sizeof(struct ifreq
)))
1017 ifr
.ifr_mtu
= session
->mtu
;
1018 if (copy_to_user((void __user
*) arg
, &ifr
, sizeof(struct ifreq
)))
1021 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1022 "%s: get mtu=%d\n", session
->name
, session
->mtu
);
1028 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
1032 if (copy_from_user(&ifr
, (void __user
*) arg
, sizeof(struct ifreq
)))
1035 session
->mtu
= ifr
.ifr_mtu
;
1037 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1038 "%s: set mtu=%d\n", session
->name
, session
->mtu
);
1044 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
1048 if (put_user(session
->mru
, (int __user
*) arg
))
1051 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1052 "%s: get mru=%d\n", session
->name
, session
->mru
);
1058 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
1062 if (get_user(val
, (int __user
*) arg
))
1066 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1067 "%s: set mru=%d\n", session
->name
, session
->mru
);
1073 if (put_user(ps
->flags
, (int __user
*) arg
))
1076 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1077 "%s: get flags=%d\n", session
->name
, ps
->flags
);
1083 if (get_user(val
, (int __user
*) arg
))
1086 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1087 "%s: set flags=%d\n", session
->name
, ps
->flags
);
1091 case PPPIOCGL2TPSTATS
:
1093 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
1096 memset(&stats
, 0, sizeof(stats
));
1097 stats
.tunnel_id
= tunnel
->tunnel_id
;
1098 stats
.session_id
= session
->session_id
;
1099 pppol2tp_copy_stats(&stats
, &session
->stats
);
1100 if (copy_to_user((void __user
*) arg
, &stats
,
1103 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1104 "%s: get L2TP stats\n", session
->name
);
1118 /* Tunnel ioctl helper.
1120 * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
1121 * specifies a session_id, the session ioctl handler is called. This allows an
1122 * application to retrieve session stats via a tunnel socket.
1124 static int pppol2tp_tunnel_ioctl(struct l2tp_tunnel
*tunnel
,
1125 unsigned int cmd
, unsigned long arg
)
1129 struct pppol2tp_ioc_stats stats
;
1131 PRINTK(tunnel
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_DEBUG
,
1132 "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n",
1133 tunnel
->name
, cmd
, arg
);
1139 case PPPIOCGL2TPSTATS
:
1141 if (!(sk
->sk_state
& PPPOX_CONNECTED
))
1144 if (copy_from_user(&stats
, (void __user
*) arg
,
1149 if (stats
.session_id
!= 0) {
1150 /* resend to session ioctl handler */
1151 struct l2tp_session
*session
=
1152 l2tp_session_find(sock_net(sk
), tunnel
, stats
.session_id
);
1153 if (session
!= NULL
)
1154 err
= pppol2tp_session_ioctl(session
, cmd
, arg
);
1160 stats
.using_ipsec
= (sk
->sk_policy
[0] || sk
->sk_policy
[1]) ? 1 : 0;
1162 pppol2tp_copy_stats(&stats
, &tunnel
->stats
);
1163 if (copy_to_user((void __user
*) arg
, &stats
, sizeof(stats
))) {
1167 PRINTK(tunnel
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1168 "%s: get L2TP stats\n", tunnel
->name
);
1182 /* Main ioctl() handler.
1183 * Dispatch to tunnel or session helpers depending on the socket.
1185 static int pppol2tp_ioctl(struct socket
*sock
, unsigned int cmd
,
1188 struct sock
*sk
= sock
->sk
;
1189 struct l2tp_session
*session
;
1190 struct l2tp_tunnel
*tunnel
;
1191 struct pppol2tp_session
*ps
;
1198 if (sock_flag(sk
, SOCK_DEAD
) != 0)
1202 if ((sk
->sk_user_data
== NULL
) ||
1203 (!(sk
->sk_state
& (PPPOX_CONNECTED
| PPPOX_BOUND
))))
1206 /* Get session context from the socket */
1208 session
= pppol2tp_sock_to_session(sk
);
1209 if (session
== NULL
)
1212 /* Special case: if session's session_id is zero, treat ioctl as a
1215 ps
= l2tp_session_priv(session
);
1216 if ((session
->session_id
== 0) &&
1217 (session
->peer_session_id
== 0)) {
1219 tunnel
= l2tp_sock_to_tunnel(ps
->tunnel_sock
);
1223 err
= pppol2tp_tunnel_ioctl(tunnel
, cmd
, arg
);
1224 sock_put(ps
->tunnel_sock
);
1228 err
= pppol2tp_session_ioctl(session
, cmd
, arg
);
1236 /*****************************************************************************
1237 * setsockopt() / getsockopt() support.
1239 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1240 * sockets. In order to control kernel tunnel features, we allow userspace to
1241 * create a special "tunnel" PPPoX socket which is used for control only.
1242 * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
1243 * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
1244 *****************************************************************************/
1246 /* Tunnel setsockopt() helper.
1248 static int pppol2tp_tunnel_setsockopt(struct sock
*sk
,
1249 struct l2tp_tunnel
*tunnel
,
1250 int optname
, int val
)
1255 case PPPOL2TP_SO_DEBUG
:
1256 tunnel
->debug
= val
;
1257 PRINTK(tunnel
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1258 "%s: set debug=%x\n", tunnel
->name
, tunnel
->debug
);
1269 /* Session setsockopt helper.
1271 static int pppol2tp_session_setsockopt(struct sock
*sk
,
1272 struct l2tp_session
*session
,
1273 int optname
, int val
)
1276 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
1279 case PPPOL2TP_SO_RECVSEQ
:
1280 if ((val
!= 0) && (val
!= 1)) {
1284 session
->recv_seq
= val
? -1 : 0;
1285 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1286 "%s: set recv_seq=%d\n", session
->name
, session
->recv_seq
);
1289 case PPPOL2TP_SO_SENDSEQ
:
1290 if ((val
!= 0) && (val
!= 1)) {
1294 session
->send_seq
= val
? -1 : 0;
1296 struct sock
*ssk
= ps
->sock
;
1297 struct pppox_sock
*po
= pppox_sk(ssk
);
1298 po
->chan
.hdrlen
= val
? PPPOL2TP_L2TP_HDR_SIZE_SEQ
:
1299 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ
;
1301 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1302 "%s: set send_seq=%d\n", session
->name
, session
->send_seq
);
1305 case PPPOL2TP_SO_LNSMODE
:
1306 if ((val
!= 0) && (val
!= 1)) {
1310 session
->lns_mode
= val
? -1 : 0;
1311 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1312 "%s: set lns_mode=%d\n", session
->name
, session
->lns_mode
);
1315 case PPPOL2TP_SO_DEBUG
:
1316 session
->debug
= val
;
1317 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1318 "%s: set debug=%x\n", session
->name
, session
->debug
);
1321 case PPPOL2TP_SO_REORDERTO
:
1322 session
->reorder_timeout
= msecs_to_jiffies(val
);
1323 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1324 "%s: set reorder_timeout=%d\n", session
->name
, session
->reorder_timeout
);
1335 /* Main setsockopt() entry point.
1336 * Does API checks, then calls either the tunnel or session setsockopt
1337 * handler, according to whether the PPPoL2TP socket is a for a regular
1338 * session or the special tunnel type.
1340 static int pppol2tp_setsockopt(struct socket
*sock
, int level
, int optname
,
1341 char __user
*optval
, unsigned int optlen
)
1343 struct sock
*sk
= sock
->sk
;
1344 struct l2tp_session
*session
;
1345 struct l2tp_tunnel
*tunnel
;
1346 struct pppol2tp_session
*ps
;
1350 if (level
!= SOL_PPPOL2TP
)
1351 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
1353 if (optlen
< sizeof(int))
1356 if (get_user(val
, (int __user
*)optval
))
1360 if (sk
->sk_user_data
== NULL
)
1363 /* Get session context from the socket */
1365 session
= pppol2tp_sock_to_session(sk
);
1366 if (session
== NULL
)
1369 /* Special case: if session_id == 0x0000, treat as operation on tunnel
1371 ps
= l2tp_session_priv(session
);
1372 if ((session
->session_id
== 0) &&
1373 (session
->peer_session_id
== 0)) {
1375 tunnel
= l2tp_sock_to_tunnel(ps
->tunnel_sock
);
1379 err
= pppol2tp_tunnel_setsockopt(sk
, tunnel
, optname
, val
);
1380 sock_put(ps
->tunnel_sock
);
1382 err
= pppol2tp_session_setsockopt(sk
, session
, optname
, val
);
1392 /* Tunnel getsockopt helper. Called with sock locked.
1394 static int pppol2tp_tunnel_getsockopt(struct sock
*sk
,
1395 struct l2tp_tunnel
*tunnel
,
1396 int optname
, int *val
)
1401 case PPPOL2TP_SO_DEBUG
:
1402 *val
= tunnel
->debug
;
1403 PRINTK(tunnel
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1404 "%s: get debug=%x\n", tunnel
->name
, tunnel
->debug
);
1415 /* Session getsockopt helper. Called with sock locked.
1417 static int pppol2tp_session_getsockopt(struct sock
*sk
,
1418 struct l2tp_session
*session
,
1419 int optname
, int *val
)
1424 case PPPOL2TP_SO_RECVSEQ
:
1425 *val
= session
->recv_seq
;
1426 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1427 "%s: get recv_seq=%d\n", session
->name
, *val
);
1430 case PPPOL2TP_SO_SENDSEQ
:
1431 *val
= session
->send_seq
;
1432 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1433 "%s: get send_seq=%d\n", session
->name
, *val
);
1436 case PPPOL2TP_SO_LNSMODE
:
1437 *val
= session
->lns_mode
;
1438 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1439 "%s: get lns_mode=%d\n", session
->name
, *val
);
1442 case PPPOL2TP_SO_DEBUG
:
1443 *val
= session
->debug
;
1444 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1445 "%s: get debug=%d\n", session
->name
, *val
);
1448 case PPPOL2TP_SO_REORDERTO
:
1449 *val
= (int) jiffies_to_msecs(session
->reorder_timeout
);
1450 PRINTK(session
->debug
, PPPOL2TP_MSG_CONTROL
, KERN_INFO
,
1451 "%s: get reorder_timeout=%d\n", session
->name
, *val
);
1461 /* Main getsockopt() entry point.
1462 * Does API checks, then calls either the tunnel or session getsockopt
1463 * handler, according to whether the PPPoX socket is a for a regular session
1464 * or the special tunnel type.
1466 static int pppol2tp_getsockopt(struct socket
*sock
, int level
,
1467 int optname
, char __user
*optval
, int __user
*optlen
)
1469 struct sock
*sk
= sock
->sk
;
1470 struct l2tp_session
*session
;
1471 struct l2tp_tunnel
*tunnel
;
1474 struct pppol2tp_session
*ps
;
1476 if (level
!= SOL_PPPOL2TP
)
1477 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1479 if (get_user(len
, (int __user
*) optlen
))
1482 len
= min_t(unsigned int, len
, sizeof(int));
1488 if (sk
->sk_user_data
== NULL
)
1491 /* Get the session context */
1493 session
= pppol2tp_sock_to_session(sk
);
1494 if (session
== NULL
)
1497 /* Special case: if session_id == 0x0000, treat as operation on tunnel */
1498 ps
= l2tp_session_priv(session
);
1499 if ((session
->session_id
== 0) &&
1500 (session
->peer_session_id
== 0)) {
1502 tunnel
= l2tp_sock_to_tunnel(ps
->tunnel_sock
);
1506 err
= pppol2tp_tunnel_getsockopt(sk
, tunnel
, optname
, &val
);
1507 sock_put(ps
->tunnel_sock
);
1509 err
= pppol2tp_session_getsockopt(sk
, session
, optname
, &val
);
1512 if (put_user(len
, (int __user
*) optlen
))
1515 if (copy_to_user((void __user
*) optval
, &val
, len
))
1526 /*****************************************************************************
1527 * /proc filesystem for debug
1528 * Since the original pppol2tp driver provided /proc/net/pppol2tp for
1529 * L2TPv2, we dump only L2TPv2 tunnels and sessions here.
1530 *****************************************************************************/
1532 static unsigned int pppol2tp_net_id
;
1534 #ifdef CONFIG_PROC_FS
1536 struct pppol2tp_seq_data
{
1537 struct seq_net_private p
;
1538 int tunnel_idx
; /* current tunnel */
1539 int session_idx
; /* index of session within current tunnel */
1540 struct l2tp_tunnel
*tunnel
;
1541 struct l2tp_session
*session
; /* NULL means get next tunnel */
1544 static void pppol2tp_next_tunnel(struct net
*net
, struct pppol2tp_seq_data
*pd
)
1547 pd
->tunnel
= l2tp_tunnel_find_nth(net
, pd
->tunnel_idx
);
1550 if (pd
->tunnel
== NULL
)
1553 /* Ignore L2TPv3 tunnels */
1554 if (pd
->tunnel
->version
< 3)
1559 static void pppol2tp_next_session(struct net
*net
, struct pppol2tp_seq_data
*pd
)
1561 pd
->session
= l2tp_session_find_nth(pd
->tunnel
, pd
->session_idx
);
1564 if (pd
->session
== NULL
) {
1565 pd
->session_idx
= 0;
1566 pppol2tp_next_tunnel(net
, pd
);
1570 static void *pppol2tp_seq_start(struct seq_file
*m
, loff_t
*offs
)
1572 struct pppol2tp_seq_data
*pd
= SEQ_START_TOKEN
;
1579 BUG_ON(m
->private == NULL
);
1581 net
= seq_file_net(m
);
1583 if (pd
->tunnel
== NULL
)
1584 pppol2tp_next_tunnel(net
, pd
);
1586 pppol2tp_next_session(net
, pd
);
1588 /* NULL tunnel and session indicates end of list */
1589 if ((pd
->tunnel
== NULL
) && (pd
->session
== NULL
))
1596 static void *pppol2tp_seq_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
1602 static void pppol2tp_seq_stop(struct seq_file
*p
, void *v
)
1607 static void pppol2tp_seq_tunnel_show(struct seq_file
*m
, void *v
)
1609 struct l2tp_tunnel
*tunnel
= v
;
1611 seq_printf(m
, "\nTUNNEL '%s', %c %d\n",
1613 (tunnel
== tunnel
->sock
->sk_user_data
) ? 'Y' : 'N',
1614 atomic_read(&tunnel
->ref_count
) - 1);
1615 seq_printf(m
, " %08x %llu/%llu/%llu %llu/%llu/%llu\n",
1617 (unsigned long long)tunnel
->stats
.tx_packets
,
1618 (unsigned long long)tunnel
->stats
.tx_bytes
,
1619 (unsigned long long)tunnel
->stats
.tx_errors
,
1620 (unsigned long long)tunnel
->stats
.rx_packets
,
1621 (unsigned long long)tunnel
->stats
.rx_bytes
,
1622 (unsigned long long)tunnel
->stats
.rx_errors
);
1625 static void pppol2tp_seq_session_show(struct seq_file
*m
, void *v
)
1627 struct l2tp_session
*session
= v
;
1628 struct l2tp_tunnel
*tunnel
= session
->tunnel
;
1629 struct pppol2tp_session
*ps
= l2tp_session_priv(session
);
1630 struct pppox_sock
*po
= pppox_sk(ps
->sock
);
1635 struct inet_sock
*inet
= inet_sk(tunnel
->sock
);
1636 ip
= ntohl(inet
->inet_saddr
);
1637 port
= ntohs(inet
->inet_sport
);
1640 seq_printf(m
, " SESSION '%s' %08X/%d %04X/%04X -> "
1641 "%04X/%04X %d %c\n",
1642 session
->name
, ip
, port
,
1644 session
->session_id
,
1645 tunnel
->peer_tunnel_id
,
1646 session
->peer_session_id
,
1648 (session
== ps
->sock
->sk_user_data
) ?
1650 seq_printf(m
, " %d/%d/%c/%c/%s %08x %u\n",
1651 session
->mtu
, session
->mru
,
1652 session
->recv_seq
? 'R' : '-',
1653 session
->send_seq
? 'S' : '-',
1654 session
->lns_mode
? "LNS" : "LAC",
1656 jiffies_to_msecs(session
->reorder_timeout
));
1657 seq_printf(m
, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n",
1658 session
->nr
, session
->ns
,
1659 (unsigned long long)session
->stats
.tx_packets
,
1660 (unsigned long long)session
->stats
.tx_bytes
,
1661 (unsigned long long)session
->stats
.tx_errors
,
1662 (unsigned long long)session
->stats
.rx_packets
,
1663 (unsigned long long)session
->stats
.rx_bytes
,
1664 (unsigned long long)session
->stats
.rx_errors
);
1667 seq_printf(m
, " interface %s\n", ppp_dev_name(&po
->chan
));
1670 static int pppol2tp_seq_show(struct seq_file
*m
, void *v
)
1672 struct pppol2tp_seq_data
*pd
= v
;
1674 /* display header on line 1 */
1675 if (v
== SEQ_START_TOKEN
) {
1676 seq_puts(m
, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION
"\n");
1677 seq_puts(m
, "TUNNEL name, user-data-ok session-count\n");
1678 seq_puts(m
, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1679 seq_puts(m
, " SESSION name, addr/port src-tid/sid "
1680 "dest-tid/sid state user-data-ok\n");
1681 seq_puts(m
, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
1682 seq_puts(m
, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
1686 /* Show the tunnel or session context.
1688 if (pd
->session
== NULL
)
1689 pppol2tp_seq_tunnel_show(m
, pd
->tunnel
);
1691 pppol2tp_seq_session_show(m
, pd
->session
);
1697 static const struct seq_operations pppol2tp_seq_ops
= {
1698 .start
= pppol2tp_seq_start
,
1699 .next
= pppol2tp_seq_next
,
1700 .stop
= pppol2tp_seq_stop
,
1701 .show
= pppol2tp_seq_show
,
1704 /* Called when our /proc file is opened. We allocate data for use when
1705 * iterating our tunnel / session contexts and store it in the private
1706 * data of the seq_file.
1708 static int pppol2tp_proc_open(struct inode
*inode
, struct file
*file
)
1710 return seq_open_net(inode
, file
, &pppol2tp_seq_ops
,
1711 sizeof(struct pppol2tp_seq_data
));
1714 static const struct file_operations pppol2tp_proc_fops
= {
1715 .owner
= THIS_MODULE
,
1716 .open
= pppol2tp_proc_open
,
1718 .llseek
= seq_lseek
,
1719 .release
= seq_release_net
,
1722 #endif /* CONFIG_PROC_FS */
1724 /*****************************************************************************
1726 *****************************************************************************/
1728 static __net_init
int pppol2tp_init_net(struct net
*net
)
1730 struct proc_dir_entry
*pde
;
1733 pde
= proc_net_fops_create(net
, "pppol2tp", S_IRUGO
, &pppol2tp_proc_fops
);
1743 static __net_exit
void pppol2tp_exit_net(struct net
*net
)
1745 proc_net_remove(net
, "pppol2tp");
1748 static struct pernet_operations pppol2tp_net_ops
= {
1749 .init
= pppol2tp_init_net
,
1750 .exit
= pppol2tp_exit_net
,
1751 .id
= &pppol2tp_net_id
,
1754 /*****************************************************************************
1756 *****************************************************************************/
1758 static const struct proto_ops pppol2tp_ops
= {
1760 .owner
= THIS_MODULE
,
1761 .release
= pppol2tp_release
,
1762 .bind
= sock_no_bind
,
1763 .connect
= pppol2tp_connect
,
1764 .socketpair
= sock_no_socketpair
,
1765 .accept
= sock_no_accept
,
1766 .getname
= pppol2tp_getname
,
1767 .poll
= datagram_poll
,
1768 .listen
= sock_no_listen
,
1769 .shutdown
= sock_no_shutdown
,
1770 .setsockopt
= pppol2tp_setsockopt
,
1771 .getsockopt
= pppol2tp_getsockopt
,
1772 .sendmsg
= pppol2tp_sendmsg
,
1773 .recvmsg
= pppol2tp_recvmsg
,
1774 .mmap
= sock_no_mmap
,
1775 .ioctl
= pppox_ioctl
,
1778 static const struct pppox_proto pppol2tp_proto
= {
1779 .create
= pppol2tp_create
,
1780 .ioctl
= pppol2tp_ioctl
1783 #ifdef CONFIG_L2TP_V3
1785 static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops
= {
1786 .session_create
= pppol2tp_session_create
,
1787 .session_delete
= pppol2tp_session_delete
,
1790 #endif /* CONFIG_L2TP_V3 */
1792 static int __init
pppol2tp_init(void)
1796 err
= register_pernet_device(&pppol2tp_net_ops
);
1800 err
= proto_register(&pppol2tp_sk_proto
, 0);
1802 goto out_unregister_pppol2tp_pernet
;
1804 err
= register_pppox_proto(PX_PROTO_OL2TP
, &pppol2tp_proto
);
1806 goto out_unregister_pppol2tp_proto
;
1808 #ifdef CONFIG_L2TP_V3
1809 err
= l2tp_nl_register_ops(L2TP_PWTYPE_PPP
, &pppol2tp_nl_cmd_ops
);
1811 goto out_unregister_pppox
;
1814 printk(KERN_INFO
"PPPoL2TP kernel driver, %s\n",
1815 PPPOL2TP_DRV_VERSION
);
1820 #ifdef CONFIG_L2TP_V3
1821 out_unregister_pppox
:
1822 unregister_pppox_proto(PX_PROTO_OL2TP
);
1824 out_unregister_pppol2tp_proto
:
1825 proto_unregister(&pppol2tp_sk_proto
);
1826 out_unregister_pppol2tp_pernet
:
1827 unregister_pernet_device(&pppol2tp_net_ops
);
1831 static void __exit
pppol2tp_exit(void)
1833 #ifdef CONFIG_L2TP_V3
1834 l2tp_nl_unregister_ops(L2TP_PWTYPE_PPP
);
1836 unregister_pppox_proto(PX_PROTO_OL2TP
);
1837 proto_unregister(&pppol2tp_sk_proto
);
1838 unregister_pernet_device(&pppol2tp_net_ops
);
1841 module_init(pppol2tp_init
);
1842 module_exit(pppol2tp_exit
);
1844 MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
1845 MODULE_DESCRIPTION("PPP over L2TP over UDP");
1846 MODULE_LICENSE("GPL");
1847 MODULE_VERSION(PPPOL2TP_DRV_VERSION
);