xref: /openbmc/linux/drivers/net/ppp/pptp.c (revision 23c2b932)
1 /*
2  *  Point-to-Point Tunneling Protocol for Linux
3  *
4  *	Authors: Dmitry Kozlov <xeb@mail.ru>
5  *
6  *	This program is free software; you can redistribute it and/or
7  *	modify it under the terms of the GNU General Public License
8  *	as published by the Free Software Foundation; either version
9  *	2 of the License, or (at your option) any later version.
10  *
11  */
12 
13 #include <linux/string.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/errno.h>
18 #include <linux/netdevice.h>
19 #include <linux/net.h>
20 #include <linux/skbuff.h>
21 #include <linux/vmalloc.h>
22 #include <linux/init.h>
23 #include <linux/ppp_channel.h>
24 #include <linux/ppp_defs.h>
25 #include <linux/if_pppox.h>
26 #include <linux/ppp-ioctl.h>
27 #include <linux/notifier.h>
28 #include <linux/file.h>
29 #include <linux/in.h>
30 #include <linux/ip.h>
31 #include <linux/rcupdate.h>
32 #include <linux/spinlock.h>
33 
34 #include <net/sock.h>
35 #include <net/protocol.h>
36 #include <net/ip.h>
37 #include <net/icmp.h>
38 #include <net/route.h>
39 #include <net/gre.h>
40 
41 #include <linux/uaccess.h>
42 
43 #define PPTP_DRIVER_VERSION "0.8.5"
44 
45 #define MAX_CALLID 65535
46 
47 static DECLARE_BITMAP(callid_bitmap, MAX_CALLID + 1);
48 static struct pppox_sock __rcu **callid_sock;
49 
50 static DEFINE_SPINLOCK(chan_lock);
51 
52 static struct proto pptp_sk_proto __read_mostly;
53 static const struct ppp_channel_ops pptp_chan_ops;
54 static const struct proto_ops pptp_ops;
55 
56 #define PPP_LCP_ECHOREQ 0x09
57 #define PPP_LCP_ECHOREP 0x0A
58 #define SC_RCV_BITS	(SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
59 
60 #define MISSING_WINDOW 20
61 #define WRAPPED(curseq, lastseq)\
62 	((((curseq) & 0xffffff00) == 0) &&\
63 	(((lastseq) & 0xffffff00) == 0xffffff00))
64 
65 #define PPTP_GRE_PROTO  0x880B
66 #define PPTP_GRE_VER    0x1
67 
68 #define PPTP_GRE_FLAG_C	0x80
69 #define PPTP_GRE_FLAG_R	0x40
70 #define PPTP_GRE_FLAG_K	0x20
71 #define PPTP_GRE_FLAG_S	0x10
72 #define PPTP_GRE_FLAG_A	0x80
73 
74 #define PPTP_GRE_IS_C(f) ((f)&PPTP_GRE_FLAG_C)
75 #define PPTP_GRE_IS_R(f) ((f)&PPTP_GRE_FLAG_R)
76 #define PPTP_GRE_IS_K(f) ((f)&PPTP_GRE_FLAG_K)
77 #define PPTP_GRE_IS_S(f) ((f)&PPTP_GRE_FLAG_S)
78 #define PPTP_GRE_IS_A(f) ((f)&PPTP_GRE_FLAG_A)
79 
80 #define PPTP_HEADER_OVERHEAD (2+sizeof(struct pptp_gre_header))
81 struct pptp_gre_header {
82 	u8  flags;
83 	u8  ver;
84 	__be16 protocol;
85 	__be16 payload_len;
86 	__be16 call_id;
87 	__be32 seq;
88 	__be32 ack;
89 } __packed;
90 
91 static struct pppox_sock *lookup_chan(u16 call_id, __be32 s_addr)
92 {
93 	struct pppox_sock *sock;
94 	struct pptp_opt *opt;
95 
96 	rcu_read_lock();
97 	sock = rcu_dereference(callid_sock[call_id]);
98 	if (sock) {
99 		opt = &sock->proto.pptp;
100 		if (opt->dst_addr.sin_addr.s_addr != s_addr)
101 			sock = NULL;
102 		else
103 			sock_hold(sk_pppox(sock));
104 	}
105 	rcu_read_unlock();
106 
107 	return sock;
108 }
109 
110 static int lookup_chan_dst(u16 call_id, __be32 d_addr)
111 {
112 	struct pppox_sock *sock;
113 	struct pptp_opt *opt;
114 	int i;
115 
116 	rcu_read_lock();
117 	i = 1;
118 	for_each_set_bit_from(i, callid_bitmap, MAX_CALLID) {
119 		sock = rcu_dereference(callid_sock[i]);
120 		if (!sock)
121 			continue;
122 		opt = &sock->proto.pptp;
123 		if (opt->dst_addr.call_id == call_id &&
124 			  opt->dst_addr.sin_addr.s_addr == d_addr)
125 			break;
126 	}
127 	rcu_read_unlock();
128 
129 	return i < MAX_CALLID;
130 }
131 
132 static int add_chan(struct pppox_sock *sock,
133 		    struct pptp_addr *sa)
134 {
135 	static int call_id;
136 
137 	spin_lock(&chan_lock);
138 	if (!sa->call_id)	{
139 		call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, call_id + 1);
140 		if (call_id == MAX_CALLID) {
141 			call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, 1);
142 			if (call_id == MAX_CALLID)
143 				goto out_err;
144 		}
145 		sa->call_id = call_id;
146 	} else if (test_bit(sa->call_id, callid_bitmap)) {
147 		goto out_err;
148 	}
149 
150 	sock->proto.pptp.src_addr = *sa;
151 	set_bit(sa->call_id, callid_bitmap);
152 	rcu_assign_pointer(callid_sock[sa->call_id], sock);
153 	spin_unlock(&chan_lock);
154 
155 	return 0;
156 
157 out_err:
158 	spin_unlock(&chan_lock);
159 	return -1;
160 }
161 
162 static void del_chan(struct pppox_sock *sock)
163 {
164 	spin_lock(&chan_lock);
165 	clear_bit(sock->proto.pptp.src_addr.call_id, callid_bitmap);
166 	RCU_INIT_POINTER(callid_sock[sock->proto.pptp.src_addr.call_id], NULL);
167 	spin_unlock(&chan_lock);
168 	synchronize_rcu();
169 }
170 
171 static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
172 {
173 	struct sock *sk = (struct sock *) chan->private;
174 	struct pppox_sock *po = pppox_sk(sk);
175 	struct net *net = sock_net(sk);
176 	struct pptp_opt *opt = &po->proto.pptp;
177 	struct pptp_gre_header *hdr;
178 	unsigned int header_len = sizeof(*hdr);
179 	struct flowi4 fl4;
180 	int islcp;
181 	int len;
182 	unsigned char *data;
183 	__u32 seq_recv;
184 
185 
186 	struct rtable *rt;
187 	struct net_device *tdev;
188 	struct iphdr  *iph;
189 	int    max_headroom;
190 
191 	if (sk_pppox(po)->sk_state & PPPOX_DEAD)
192 		goto tx_error;
193 
194 	rt = ip_route_output_ports(net, &fl4, NULL,
195 				   opt->dst_addr.sin_addr.s_addr,
196 				   opt->src_addr.sin_addr.s_addr,
197 				   0, 0, IPPROTO_GRE,
198 				   RT_TOS(0), 0);
199 	if (IS_ERR(rt))
200 		goto tx_error;
201 
202 	tdev = rt->dst.dev;
203 
204 	max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(*iph) + sizeof(*hdr) + 2;
205 
206 	if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
207 		struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
208 		if (!new_skb) {
209 			ip_rt_put(rt);
210 			goto tx_error;
211 		}
212 		if (skb->sk)
213 			skb_set_owner_w(new_skb, skb->sk);
214 		consume_skb(skb);
215 		skb = new_skb;
216 	}
217 
218 	data = skb->data;
219 	islcp = ((data[0] << 8) + data[1]) == PPP_LCP && 1 <= data[2] && data[2] <= 7;
220 
221 	/* compress protocol field */
222 	if ((opt->ppp_flags & SC_COMP_PROT) && data[0] == 0 && !islcp)
223 		skb_pull(skb, 1);
224 
225 	/* Put in the address/control bytes if necessary */
226 	if ((opt->ppp_flags & SC_COMP_AC) == 0 || islcp) {
227 		data = skb_push(skb, 2);
228 		data[0] = PPP_ALLSTATIONS;
229 		data[1] = PPP_UI;
230 	}
231 
232 	len = skb->len;
233 
234 	seq_recv = opt->seq_recv;
235 
236 	if (opt->ack_sent == seq_recv)
237 		header_len -= sizeof(hdr->ack);
238 
239 	/* Push down and install GRE header */
240 	skb_push(skb, header_len);
241 	hdr = (struct pptp_gre_header *)(skb->data);
242 
243 	hdr->flags       = PPTP_GRE_FLAG_K;
244 	hdr->ver         = PPTP_GRE_VER;
245 	hdr->protocol    = htons(PPTP_GRE_PROTO);
246 	hdr->call_id     = htons(opt->dst_addr.call_id);
247 
248 	hdr->flags      |= PPTP_GRE_FLAG_S;
249 	hdr->seq         = htonl(++opt->seq_sent);
250 	if (opt->ack_sent != seq_recv)	{
251 		/* send ack with this message */
252 		hdr->ver |= PPTP_GRE_FLAG_A;
253 		hdr->ack  = htonl(seq_recv);
254 		opt->ack_sent = seq_recv;
255 	}
256 	hdr->payload_len = htons(len);
257 
258 	/*	Push down and install the IP header. */
259 
260 	skb_reset_transport_header(skb);
261 	skb_push(skb, sizeof(*iph));
262 	skb_reset_network_header(skb);
263 	memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
264 	IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED);
265 
266 	iph =	ip_hdr(skb);
267 	iph->version =	4;
268 	iph->ihl =	sizeof(struct iphdr) >> 2;
269 	if (ip_dont_fragment(sk, &rt->dst))
270 		iph->frag_off	=	htons(IP_DF);
271 	else
272 		iph->frag_off	=	0;
273 	iph->protocol = IPPROTO_GRE;
274 	iph->tos      = 0;
275 	iph->daddr    = fl4.daddr;
276 	iph->saddr    = fl4.saddr;
277 	iph->ttl      = ip4_dst_hoplimit(&rt->dst);
278 	iph->tot_len  = htons(skb->len);
279 
280 	skb_dst_drop(skb);
281 	skb_dst_set(skb, &rt->dst);
282 
283 	nf_reset(skb);
284 
285 	skb->ip_summed = CHECKSUM_NONE;
286 	ip_select_ident(net, skb, NULL);
287 	ip_send_check(iph);
288 
289 	ip_local_out(net, skb->sk, skb);
290 	return 1;
291 
292 tx_error:
293 	kfree_skb(skb);
294 	return 1;
295 }
296 
297 static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
298 {
299 	struct pppox_sock *po = pppox_sk(sk);
300 	struct pptp_opt *opt = &po->proto.pptp;
301 	int headersize, payload_len, seq;
302 	__u8 *payload;
303 	struct pptp_gre_header *header;
304 
305 	if (!(sk->sk_state & PPPOX_CONNECTED)) {
306 		if (sock_queue_rcv_skb(sk, skb))
307 			goto drop;
308 		return NET_RX_SUCCESS;
309 	}
310 
311 	header = (struct pptp_gre_header *)(skb->data);
312 	headersize  = sizeof(*header);
313 
314 	/* test if acknowledgement present */
315 	if (PPTP_GRE_IS_A(header->ver)) {
316 		__u32 ack;
317 
318 		if (!pskb_may_pull(skb, headersize))
319 			goto drop;
320 		header = (struct pptp_gre_header *)(skb->data);
321 
322 		/* ack in different place if S = 0 */
323 		ack = PPTP_GRE_IS_S(header->flags) ? header->ack : header->seq;
324 
325 		ack = ntohl(ack);
326 
327 		if (ack > opt->ack_recv)
328 			opt->ack_recv = ack;
329 		/* also handle sequence number wrap-around  */
330 		if (WRAPPED(ack, opt->ack_recv))
331 			opt->ack_recv = ack;
332 	} else {
333 		headersize -= sizeof(header->ack);
334 	}
335 	/* test if payload present */
336 	if (!PPTP_GRE_IS_S(header->flags))
337 		goto drop;
338 
339 	payload_len = ntohs(header->payload_len);
340 	seq         = ntohl(header->seq);
341 
342 	/* check for incomplete packet (length smaller than expected) */
343 	if (!pskb_may_pull(skb, headersize + payload_len))
344 		goto drop;
345 
346 	payload = skb->data + headersize;
347 	/* check for expected sequence number */
348 	if (seq < opt->seq_recv + 1 || WRAPPED(opt->seq_recv, seq)) {
349 		if ((payload[0] == PPP_ALLSTATIONS) && (payload[1] == PPP_UI) &&
350 				(PPP_PROTOCOL(payload) == PPP_LCP) &&
351 				((payload[4] == PPP_LCP_ECHOREQ) || (payload[4] == PPP_LCP_ECHOREP)))
352 			goto allow_packet;
353 	} else {
354 		opt->seq_recv = seq;
355 allow_packet:
356 		skb_pull(skb, headersize);
357 
358 		if (payload[0] == PPP_ALLSTATIONS && payload[1] == PPP_UI) {
359 			/* chop off address/control */
360 			if (skb->len < 3)
361 				goto drop;
362 			skb_pull(skb, 2);
363 		}
364 
365 		if ((*skb->data) & 1) {
366 			/* protocol is compressed */
367 			skb_push(skb, 1)[0] = 0;
368 		}
369 
370 		skb->ip_summed = CHECKSUM_NONE;
371 		skb_set_network_header(skb, skb->head-skb->data);
372 		ppp_input(&po->chan, skb);
373 
374 		return NET_RX_SUCCESS;
375 	}
376 drop:
377 	kfree_skb(skb);
378 	return NET_RX_DROP;
379 }
380 
381 static int pptp_rcv(struct sk_buff *skb)
382 {
383 	struct pppox_sock *po;
384 	struct pptp_gre_header *header;
385 	struct iphdr *iph;
386 
387 	if (skb->pkt_type != PACKET_HOST)
388 		goto drop;
389 
390 	if (!pskb_may_pull(skb, 12))
391 		goto drop;
392 
393 	iph = ip_hdr(skb);
394 
395 	header = (struct pptp_gre_header *)skb->data;
396 
397 	if (ntohs(header->protocol) != PPTP_GRE_PROTO || /* PPTP-GRE protocol for PPTP */
398 		PPTP_GRE_IS_C(header->flags) ||                /* flag C should be clear */
399 		PPTP_GRE_IS_R(header->flags) ||                /* flag R should be clear */
400 		!PPTP_GRE_IS_K(header->flags) ||               /* flag K should be set */
401 		(header->flags&0xF) != 0)                      /* routing and recursion ctrl = 0 */
402 		/* if invalid, discard this packet */
403 		goto drop;
404 
405 	po = lookup_chan(htons(header->call_id), iph->saddr);
406 	if (po) {
407 		skb_dst_drop(skb);
408 		nf_reset(skb);
409 		return sk_receive_skb(sk_pppox(po), skb, 0);
410 	}
411 drop:
412 	kfree_skb(skb);
413 	return NET_RX_DROP;
414 }
415 
416 static int pptp_bind(struct socket *sock, struct sockaddr *uservaddr,
417 	int sockaddr_len)
418 {
419 	struct sock *sk = sock->sk;
420 	struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
421 	struct pppox_sock *po = pppox_sk(sk);
422 	int error = 0;
423 
424 	if (sockaddr_len < sizeof(struct sockaddr_pppox))
425 		return -EINVAL;
426 
427 	lock_sock(sk);
428 
429 	if (sk->sk_state & PPPOX_DEAD) {
430 		error = -EALREADY;
431 		goto out;
432 	}
433 
434 	if (sk->sk_state & PPPOX_BOUND) {
435 		error = -EBUSY;
436 		goto out;
437 	}
438 
439 	if (add_chan(po, &sp->sa_addr.pptp))
440 		error = -EBUSY;
441 	else
442 		sk->sk_state |= PPPOX_BOUND;
443 
444 out:
445 	release_sock(sk);
446 	return error;
447 }
448 
449 static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr,
450 	int sockaddr_len, int flags)
451 {
452 	struct sock *sk = sock->sk;
453 	struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
454 	struct pppox_sock *po = pppox_sk(sk);
455 	struct pptp_opt *opt = &po->proto.pptp;
456 	struct rtable *rt;
457 	struct flowi4 fl4;
458 	int error = 0;
459 
460 	if (sockaddr_len < sizeof(struct sockaddr_pppox))
461 		return -EINVAL;
462 
463 	if (sp->sa_protocol != PX_PROTO_PPTP)
464 		return -EINVAL;
465 
466 	if (lookup_chan_dst(sp->sa_addr.pptp.call_id, sp->sa_addr.pptp.sin_addr.s_addr))
467 		return -EALREADY;
468 
469 	lock_sock(sk);
470 	/* Check for already bound sockets */
471 	if (sk->sk_state & PPPOX_CONNECTED) {
472 		error = -EBUSY;
473 		goto end;
474 	}
475 
476 	/* Check for already disconnected sockets, on attempts to disconnect */
477 	if (sk->sk_state & PPPOX_DEAD) {
478 		error = -EALREADY;
479 		goto end;
480 	}
481 
482 	if (!opt->src_addr.sin_addr.s_addr || !sp->sa_addr.pptp.sin_addr.s_addr) {
483 		error = -EINVAL;
484 		goto end;
485 	}
486 
487 	po->chan.private = sk;
488 	po->chan.ops = &pptp_chan_ops;
489 
490 	rt = ip_route_output_ports(sock_net(sk), &fl4, sk,
491 				   opt->dst_addr.sin_addr.s_addr,
492 				   opt->src_addr.sin_addr.s_addr,
493 				   0, 0,
494 				   IPPROTO_GRE, RT_CONN_FLAGS(sk), 0);
495 	if (IS_ERR(rt)) {
496 		error = -EHOSTUNREACH;
497 		goto end;
498 	}
499 	sk_setup_caps(sk, &rt->dst);
500 
501 	po->chan.mtu = dst_mtu(&rt->dst);
502 	if (!po->chan.mtu)
503 		po->chan.mtu = PPP_MRU;
504 	ip_rt_put(rt);
505 	po->chan.mtu -= PPTP_HEADER_OVERHEAD;
506 
507 	po->chan.hdrlen = 2 + sizeof(struct pptp_gre_header);
508 	error = ppp_register_channel(&po->chan);
509 	if (error) {
510 		pr_err("PPTP: failed to register PPP channel (%d)\n", error);
511 		goto end;
512 	}
513 
514 	opt->dst_addr = sp->sa_addr.pptp;
515 	sk->sk_state |= PPPOX_CONNECTED;
516 
517  end:
518 	release_sock(sk);
519 	return error;
520 }
521 
522 static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
523 	int *usockaddr_len, int peer)
524 {
525 	int len = sizeof(struct sockaddr_pppox);
526 	struct sockaddr_pppox sp;
527 
528 	memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
529 
530 	sp.sa_family    = AF_PPPOX;
531 	sp.sa_protocol  = PX_PROTO_PPTP;
532 	sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
533 
534 	memcpy(uaddr, &sp, len);
535 
536 	*usockaddr_len = len;
537 
538 	return 0;
539 }
540 
541 static int pptp_release(struct socket *sock)
542 {
543 	struct sock *sk = sock->sk;
544 	struct pppox_sock *po;
545 	struct pptp_opt *opt;
546 	int error = 0;
547 
548 	if (!sk)
549 		return 0;
550 
551 	lock_sock(sk);
552 
553 	if (sock_flag(sk, SOCK_DEAD)) {
554 		release_sock(sk);
555 		return -EBADF;
556 	}
557 
558 	po = pppox_sk(sk);
559 	opt = &po->proto.pptp;
560 	del_chan(po);
561 
562 	pppox_unbind_sock(sk);
563 	sk->sk_state = PPPOX_DEAD;
564 
565 	sock_orphan(sk);
566 	sock->sk = NULL;
567 
568 	release_sock(sk);
569 	sock_put(sk);
570 
571 	return error;
572 }
573 
574 static void pptp_sock_destruct(struct sock *sk)
575 {
576 	if (!(sk->sk_state & PPPOX_DEAD)) {
577 		del_chan(pppox_sk(sk));
578 		pppox_unbind_sock(sk);
579 	}
580 	skb_queue_purge(&sk->sk_receive_queue);
581 }
582 
583 static int pptp_create(struct net *net, struct socket *sock, int kern)
584 {
585 	int error = -ENOMEM;
586 	struct sock *sk;
587 	struct pppox_sock *po;
588 	struct pptp_opt *opt;
589 
590 	sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pptp_sk_proto, kern);
591 	if (!sk)
592 		goto out;
593 
594 	sock_init_data(sock, sk);
595 
596 	sock->state = SS_UNCONNECTED;
597 	sock->ops   = &pptp_ops;
598 
599 	sk->sk_backlog_rcv = pptp_rcv_core;
600 	sk->sk_state       = PPPOX_NONE;
601 	sk->sk_type        = SOCK_STREAM;
602 	sk->sk_family      = PF_PPPOX;
603 	sk->sk_protocol    = PX_PROTO_PPTP;
604 	sk->sk_destruct    = pptp_sock_destruct;
605 
606 	po = pppox_sk(sk);
607 	opt = &po->proto.pptp;
608 
609 	opt->seq_sent = 0; opt->seq_recv = 0xffffffff;
610 	opt->ack_recv = 0; opt->ack_sent = 0xffffffff;
611 
612 	error = 0;
613 out:
614 	return error;
615 }
616 
617 static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
618 	unsigned long arg)
619 {
620 	struct sock *sk = (struct sock *) chan->private;
621 	struct pppox_sock *po = pppox_sk(sk);
622 	struct pptp_opt *opt = &po->proto.pptp;
623 	void __user *argp = (void __user *)arg;
624 	int __user *p = argp;
625 	int err, val;
626 
627 	err = -EFAULT;
628 	switch (cmd) {
629 	case PPPIOCGFLAGS:
630 		val = opt->ppp_flags;
631 		if (put_user(val, p))
632 			break;
633 		err = 0;
634 		break;
635 	case PPPIOCSFLAGS:
636 		if (get_user(val, p))
637 			break;
638 		opt->ppp_flags = val & ~SC_RCV_BITS;
639 		err = 0;
640 		break;
641 	default:
642 		err = -ENOTTY;
643 	}
644 
645 	return err;
646 }
647 
648 static const struct ppp_channel_ops pptp_chan_ops = {
649 	.start_xmit = pptp_xmit,
650 	.ioctl      = pptp_ppp_ioctl,
651 };
652 
653 static struct proto pptp_sk_proto __read_mostly = {
654 	.name     = "PPTP",
655 	.owner    = THIS_MODULE,
656 	.obj_size = sizeof(struct pppox_sock),
657 };
658 
659 static const struct proto_ops pptp_ops = {
660 	.family     = AF_PPPOX,
661 	.owner      = THIS_MODULE,
662 	.release    = pptp_release,
663 	.bind       = pptp_bind,
664 	.connect    = pptp_connect,
665 	.socketpair = sock_no_socketpair,
666 	.accept     = sock_no_accept,
667 	.getname    = pptp_getname,
668 	.poll       = sock_no_poll,
669 	.listen     = sock_no_listen,
670 	.shutdown   = sock_no_shutdown,
671 	.setsockopt = sock_no_setsockopt,
672 	.getsockopt = sock_no_getsockopt,
673 	.sendmsg    = sock_no_sendmsg,
674 	.recvmsg    = sock_no_recvmsg,
675 	.mmap       = sock_no_mmap,
676 	.ioctl      = pppox_ioctl,
677 };
678 
679 static const struct pppox_proto pppox_pptp_proto = {
680 	.create = pptp_create,
681 	.owner  = THIS_MODULE,
682 };
683 
684 static const struct gre_protocol gre_pptp_protocol = {
685 	.handler = pptp_rcv,
686 };
687 
688 static int __init pptp_init_module(void)
689 {
690 	int err = 0;
691 	pr_info("PPTP driver version " PPTP_DRIVER_VERSION "\n");
692 
693 	callid_sock = vzalloc((MAX_CALLID + 1) * sizeof(void *));
694 	if (!callid_sock)
695 		return -ENOMEM;
696 
697 	err = gre_add_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
698 	if (err) {
699 		pr_err("PPTP: can't add gre protocol\n");
700 		goto out_mem_free;
701 	}
702 
703 	err = proto_register(&pptp_sk_proto, 0);
704 	if (err) {
705 		pr_err("PPTP: can't register sk_proto\n");
706 		goto out_gre_del_protocol;
707 	}
708 
709 	err = register_pppox_proto(PX_PROTO_PPTP, &pppox_pptp_proto);
710 	if (err) {
711 		pr_err("PPTP: can't register pppox_proto\n");
712 		goto out_unregister_sk_proto;
713 	}
714 
715 	return 0;
716 
717 out_unregister_sk_proto:
718 	proto_unregister(&pptp_sk_proto);
719 out_gre_del_protocol:
720 	gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
721 out_mem_free:
722 	vfree(callid_sock);
723 
724 	return err;
725 }
726 
727 static void __exit pptp_exit_module(void)
728 {
729 	unregister_pppox_proto(PX_PROTO_PPTP);
730 	proto_unregister(&pptp_sk_proto);
731 	gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
732 	vfree(callid_sock);
733 }
734 
735 module_init(pptp_init_module);
736 module_exit(pptp_exit_module);
737 
738 MODULE_DESCRIPTION("Point-to-Point Tunneling Protocol");
739 MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
740 MODULE_LICENSE("GPL");
741 MODULE_ALIAS_NET_PF_PROTO(PF_PPPOX, PX_PROTO_PPTP);
742