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