]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ppp/pptp.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/ide
[karo-tx-linux.git] / drivers / net / ppp / pptp.c
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 {
134         static int call_id;
135
136         spin_lock(&chan_lock);
137         if (!sock->proto.pptp.src_addr.call_id) {
138                 call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, call_id + 1);
139                 if (call_id == MAX_CALLID) {
140                         call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, 1);
141                         if (call_id == MAX_CALLID)
142                                 goto out_err;
143                 }
144                 sock->proto.pptp.src_addr.call_id = call_id;
145         } else if (test_bit(sock->proto.pptp.src_addr.call_id, callid_bitmap))
146                 goto out_err;
147
148         set_bit(sock->proto.pptp.src_addr.call_id, callid_bitmap);
149         rcu_assign_pointer(callid_sock[sock->proto.pptp.src_addr.call_id], sock);
150         spin_unlock(&chan_lock);
151
152         return 0;
153
154 out_err:
155         spin_unlock(&chan_lock);
156         return -1;
157 }
158
159 static void del_chan(struct pppox_sock *sock)
160 {
161         spin_lock(&chan_lock);
162         clear_bit(sock->proto.pptp.src_addr.call_id, callid_bitmap);
163         RCU_INIT_POINTER(callid_sock[sock->proto.pptp.src_addr.call_id], NULL);
164         spin_unlock(&chan_lock);
165         synchronize_rcu();
166 }
167
168 static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
169 {
170         struct sock *sk = (struct sock *) chan->private;
171         struct pppox_sock *po = pppox_sk(sk);
172         struct net *net = sock_net(sk);
173         struct pptp_opt *opt = &po->proto.pptp;
174         struct pptp_gre_header *hdr;
175         unsigned int header_len = sizeof(*hdr);
176         struct flowi4 fl4;
177         int islcp;
178         int len;
179         unsigned char *data;
180         __u32 seq_recv;
181
182
183         struct rtable *rt;
184         struct net_device *tdev;
185         struct iphdr  *iph;
186         int    max_headroom;
187
188         if (sk_pppox(po)->sk_state & PPPOX_DEAD)
189                 goto tx_error;
190
191         rt = ip_route_output_ports(net, &fl4, NULL,
192                                    opt->dst_addr.sin_addr.s_addr,
193                                    opt->src_addr.sin_addr.s_addr,
194                                    0, 0, IPPROTO_GRE,
195                                    RT_TOS(0), 0);
196         if (IS_ERR(rt))
197                 goto tx_error;
198
199         tdev = rt->dst.dev;
200
201         max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(*iph) + sizeof(*hdr) + 2;
202
203         if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
204                 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
205                 if (!new_skb) {
206                         ip_rt_put(rt);
207                         goto tx_error;
208                 }
209                 if (skb->sk)
210                         skb_set_owner_w(new_skb, skb->sk);
211                 consume_skb(skb);
212                 skb = new_skb;
213         }
214
215         data = skb->data;
216         islcp = ((data[0] << 8) + data[1]) == PPP_LCP && 1 <= data[2] && data[2] <= 7;
217
218         /* compress protocol field */
219         if ((opt->ppp_flags & SC_COMP_PROT) && data[0] == 0 && !islcp)
220                 skb_pull(skb, 1);
221
222         /* Put in the address/control bytes if necessary */
223         if ((opt->ppp_flags & SC_COMP_AC) == 0 || islcp) {
224                 data = skb_push(skb, 2);
225                 data[0] = PPP_ALLSTATIONS;
226                 data[1] = PPP_UI;
227         }
228
229         len = skb->len;
230
231         seq_recv = opt->seq_recv;
232
233         if (opt->ack_sent == seq_recv)
234                 header_len -= sizeof(hdr->ack);
235
236         /* Push down and install GRE header */
237         skb_push(skb, header_len);
238         hdr = (struct pptp_gre_header *)(skb->data);
239
240         hdr->flags       = PPTP_GRE_FLAG_K;
241         hdr->ver         = PPTP_GRE_VER;
242         hdr->protocol    = htons(PPTP_GRE_PROTO);
243         hdr->call_id     = htons(opt->dst_addr.call_id);
244
245         hdr->flags      |= PPTP_GRE_FLAG_S;
246         hdr->seq         = htonl(++opt->seq_sent);
247         if (opt->ack_sent != seq_recv)  {
248                 /* send ack with this message */
249                 hdr->ver |= PPTP_GRE_FLAG_A;
250                 hdr->ack  = htonl(seq_recv);
251                 opt->ack_sent = seq_recv;
252         }
253         hdr->payload_len = htons(len);
254
255         /*      Push down and install the IP header. */
256
257         skb_reset_transport_header(skb);
258         skb_push(skb, sizeof(*iph));
259         skb_reset_network_header(skb);
260         memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
261         IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED);
262
263         iph =   ip_hdr(skb);
264         iph->version =  4;
265         iph->ihl =      sizeof(struct iphdr) >> 2;
266         if (ip_dont_fragment(sk, &rt->dst))
267                 iph->frag_off   =       htons(IP_DF);
268         else
269                 iph->frag_off   =       0;
270         iph->protocol = IPPROTO_GRE;
271         iph->tos      = 0;
272         iph->daddr    = fl4.daddr;
273         iph->saddr    = fl4.saddr;
274         iph->ttl      = ip4_dst_hoplimit(&rt->dst);
275         iph->tot_len  = htons(skb->len);
276
277         skb_dst_drop(skb);
278         skb_dst_set(skb, &rt->dst);
279
280         nf_reset(skb);
281
282         skb->ip_summed = CHECKSUM_NONE;
283         ip_select_ident(net, skb, NULL);
284         ip_send_check(iph);
285
286         ip_local_out(net, skb->sk, skb);
287         return 1;
288
289 tx_error:
290         kfree_skb(skb);
291         return 1;
292 }
293
294 static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
295 {
296         struct pppox_sock *po = pppox_sk(sk);
297         struct pptp_opt *opt = &po->proto.pptp;
298         int headersize, payload_len, seq;
299         __u8 *payload;
300         struct pptp_gre_header *header;
301
302         if (!(sk->sk_state & PPPOX_CONNECTED)) {
303                 if (sock_queue_rcv_skb(sk, skb))
304                         goto drop;
305                 return NET_RX_SUCCESS;
306         }
307
308         header = (struct pptp_gre_header *)(skb->data);
309         headersize  = sizeof(*header);
310
311         /* test if acknowledgement present */
312         if (PPTP_GRE_IS_A(header->ver)) {
313                 __u32 ack;
314
315                 if (!pskb_may_pull(skb, headersize))
316                         goto drop;
317                 header = (struct pptp_gre_header *)(skb->data);
318
319                 /* ack in different place if S = 0 */
320                 ack = PPTP_GRE_IS_S(header->flags) ? header->ack : header->seq;
321
322                 ack = ntohl(ack);
323
324                 if (ack > opt->ack_recv)
325                         opt->ack_recv = ack;
326                 /* also handle sequence number wrap-around  */
327                 if (WRAPPED(ack, opt->ack_recv))
328                         opt->ack_recv = ack;
329         } else {
330                 headersize -= sizeof(header->ack);
331         }
332         /* test if payload present */
333         if (!PPTP_GRE_IS_S(header->flags))
334                 goto drop;
335
336         payload_len = ntohs(header->payload_len);
337         seq         = ntohl(header->seq);
338
339         /* check for incomplete packet (length smaller than expected) */
340         if (!pskb_may_pull(skb, headersize + payload_len))
341                 goto drop;
342
343         payload = skb->data + headersize;
344         /* check for expected sequence number */
345         if (seq < opt->seq_recv + 1 || WRAPPED(opt->seq_recv, seq)) {
346                 if ((payload[0] == PPP_ALLSTATIONS) && (payload[1] == PPP_UI) &&
347                                 (PPP_PROTOCOL(payload) == PPP_LCP) &&
348                                 ((payload[4] == PPP_LCP_ECHOREQ) || (payload[4] == PPP_LCP_ECHOREP)))
349                         goto allow_packet;
350         } else {
351                 opt->seq_recv = seq;
352 allow_packet:
353                 skb_pull(skb, headersize);
354
355                 if (payload[0] == PPP_ALLSTATIONS && payload[1] == PPP_UI) {
356                         /* chop off address/control */
357                         if (skb->len < 3)
358                                 goto drop;
359                         skb_pull(skb, 2);
360                 }
361
362                 if ((*skb->data) & 1) {
363                         /* protocol is compressed */
364                         skb_push(skb, 1)[0] = 0;
365                 }
366
367                 skb->ip_summed = CHECKSUM_NONE;
368                 skb_set_network_header(skb, skb->head-skb->data);
369                 ppp_input(&po->chan, skb);
370
371                 return NET_RX_SUCCESS;
372         }
373 drop:
374         kfree_skb(skb);
375         return NET_RX_DROP;
376 }
377
378 static int pptp_rcv(struct sk_buff *skb)
379 {
380         struct pppox_sock *po;
381         struct pptp_gre_header *header;
382         struct iphdr *iph;
383
384         if (skb->pkt_type != PACKET_HOST)
385                 goto drop;
386
387         if (!pskb_may_pull(skb, 12))
388                 goto drop;
389
390         iph = ip_hdr(skb);
391
392         header = (struct pptp_gre_header *)skb->data;
393
394         if (ntohs(header->protocol) != PPTP_GRE_PROTO || /* PPTP-GRE protocol for PPTP */
395                 PPTP_GRE_IS_C(header->flags) ||                /* flag C should be clear */
396                 PPTP_GRE_IS_R(header->flags) ||                /* flag R should be clear */
397                 !PPTP_GRE_IS_K(header->flags) ||               /* flag K should be set */
398                 (header->flags&0xF) != 0)                      /* routing and recursion ctrl = 0 */
399                 /* if invalid, discard this packet */
400                 goto drop;
401
402         po = lookup_chan(htons(header->call_id), iph->saddr);
403         if (po) {
404                 skb_dst_drop(skb);
405                 nf_reset(skb);
406                 return sk_receive_skb(sk_pppox(po), skb, 0);
407         }
408 drop:
409         kfree_skb(skb);
410         return NET_RX_DROP;
411 }
412
413 static int pptp_bind(struct socket *sock, struct sockaddr *uservaddr,
414         int sockaddr_len)
415 {
416         struct sock *sk = sock->sk;
417         struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
418         struct pppox_sock *po = pppox_sk(sk);
419         struct pptp_opt *opt = &po->proto.pptp;
420         int error = 0;
421
422         lock_sock(sk);
423
424         opt->src_addr = sp->sa_addr.pptp;
425         if (add_chan(po))
426                 error = -EBUSY;
427
428         release_sock(sk);
429         return error;
430 }
431
432 static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr,
433         int sockaddr_len, int flags)
434 {
435         struct sock *sk = sock->sk;
436         struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
437         struct pppox_sock *po = pppox_sk(sk);
438         struct pptp_opt *opt = &po->proto.pptp;
439         struct rtable *rt;
440         struct flowi4 fl4;
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         rt = ip_route_output_ports(sock_net(sk), &fl4, sk,
471                                    opt->dst_addr.sin_addr.s_addr,
472                                    opt->src_addr.sin_addr.s_addr,
473                                    0, 0,
474                                    IPPROTO_GRE, RT_CONN_FLAGS(sk), 0);
475         if (IS_ERR(rt)) {
476                 error = -EHOSTUNREACH;
477                 goto end;
478         }
479         sk_setup_caps(sk, &rt->dst);
480
481         po->chan.mtu = dst_mtu(&rt->dst);
482         if (!po->chan.mtu)
483                 po->chan.mtu = PPP_MRU;
484         ip_rt_put(rt);
485         po->chan.mtu -= PPTP_HEADER_OVERHEAD;
486
487         po->chan.hdrlen = 2 + sizeof(struct pptp_gre_header);
488         error = ppp_register_channel(&po->chan);
489         if (error) {
490                 pr_err("PPTP: failed to register PPP channel (%d)\n", error);
491                 goto end;
492         }
493
494         opt->dst_addr = sp->sa_addr.pptp;
495         sk->sk_state = PPPOX_CONNECTED;
496
497  end:
498         release_sock(sk);
499         return error;
500 }
501
502 static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
503         int *usockaddr_len, int peer)
504 {
505         int len = sizeof(struct sockaddr_pppox);
506         struct sockaddr_pppox sp;
507
508         memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
509
510         sp.sa_family    = AF_PPPOX;
511         sp.sa_protocol  = PX_PROTO_PPTP;
512         sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
513
514         memcpy(uaddr, &sp, len);
515
516         *usockaddr_len = len;
517
518         return 0;
519 }
520
521 static int pptp_release(struct socket *sock)
522 {
523         struct sock *sk = sock->sk;
524         struct pppox_sock *po;
525         struct pptp_opt *opt;
526         int error = 0;
527
528         if (!sk)
529                 return 0;
530
531         lock_sock(sk);
532
533         if (sock_flag(sk, SOCK_DEAD)) {
534                 release_sock(sk);
535                 return -EBADF;
536         }
537
538         po = pppox_sk(sk);
539         opt = &po->proto.pptp;
540         del_chan(po);
541
542         pppox_unbind_sock(sk);
543         sk->sk_state = PPPOX_DEAD;
544
545         sock_orphan(sk);
546         sock->sk = NULL;
547
548         release_sock(sk);
549         sock_put(sk);
550
551         return error;
552 }
553
554 static void pptp_sock_destruct(struct sock *sk)
555 {
556         if (!(sk->sk_state & PPPOX_DEAD)) {
557                 del_chan(pppox_sk(sk));
558                 pppox_unbind_sock(sk);
559         }
560         skb_queue_purge(&sk->sk_receive_queue);
561 }
562
563 static int pptp_create(struct net *net, struct socket *sock, int kern)
564 {
565         int error = -ENOMEM;
566         struct sock *sk;
567         struct pppox_sock *po;
568         struct pptp_opt *opt;
569
570         sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pptp_sk_proto, kern);
571         if (!sk)
572                 goto out;
573
574         sock_init_data(sock, sk);
575
576         sock->state = SS_UNCONNECTED;
577         sock->ops   = &pptp_ops;
578
579         sk->sk_backlog_rcv = pptp_rcv_core;
580         sk->sk_state       = PPPOX_NONE;
581         sk->sk_type        = SOCK_STREAM;
582         sk->sk_family      = PF_PPPOX;
583         sk->sk_protocol    = PX_PROTO_PPTP;
584         sk->sk_destruct    = pptp_sock_destruct;
585
586         po = pppox_sk(sk);
587         opt = &po->proto.pptp;
588
589         opt->seq_sent = 0; opt->seq_recv = 0xffffffff;
590         opt->ack_recv = 0; opt->ack_sent = 0xffffffff;
591
592         error = 0;
593 out:
594         return error;
595 }
596
597 static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
598         unsigned long arg)
599 {
600         struct sock *sk = (struct sock *) chan->private;
601         struct pppox_sock *po = pppox_sk(sk);
602         struct pptp_opt *opt = &po->proto.pptp;
603         void __user *argp = (void __user *)arg;
604         int __user *p = argp;
605         int err, val;
606
607         err = -EFAULT;
608         switch (cmd) {
609         case PPPIOCGFLAGS:
610                 val = opt->ppp_flags;
611                 if (put_user(val, p))
612                         break;
613                 err = 0;
614                 break;
615         case PPPIOCSFLAGS:
616                 if (get_user(val, p))
617                         break;
618                 opt->ppp_flags = val & ~SC_RCV_BITS;
619                 err = 0;
620                 break;
621         default:
622                 err = -ENOTTY;
623         }
624
625         return err;
626 }
627
628 static const struct ppp_channel_ops pptp_chan_ops = {
629         .start_xmit = pptp_xmit,
630         .ioctl      = pptp_ppp_ioctl,
631 };
632
633 static struct proto pptp_sk_proto __read_mostly = {
634         .name     = "PPTP",
635         .owner    = THIS_MODULE,
636         .obj_size = sizeof(struct pppox_sock),
637 };
638
639 static const struct proto_ops pptp_ops = {
640         .family     = AF_PPPOX,
641         .owner      = THIS_MODULE,
642         .release    = pptp_release,
643         .bind       = pptp_bind,
644         .connect    = pptp_connect,
645         .socketpair = sock_no_socketpair,
646         .accept     = sock_no_accept,
647         .getname    = pptp_getname,
648         .poll       = sock_no_poll,
649         .listen     = sock_no_listen,
650         .shutdown   = sock_no_shutdown,
651         .setsockopt = sock_no_setsockopt,
652         .getsockopt = sock_no_getsockopt,
653         .sendmsg    = sock_no_sendmsg,
654         .recvmsg    = sock_no_recvmsg,
655         .mmap       = sock_no_mmap,
656         .ioctl      = pppox_ioctl,
657 };
658
659 static const struct pppox_proto pppox_pptp_proto = {
660         .create = pptp_create,
661         .owner  = THIS_MODULE,
662 };
663
664 static const struct gre_protocol gre_pptp_protocol = {
665         .handler = pptp_rcv,
666 };
667
668 static int __init pptp_init_module(void)
669 {
670         int err = 0;
671         pr_info("PPTP driver version " PPTP_DRIVER_VERSION "\n");
672
673         callid_sock = vzalloc((MAX_CALLID + 1) * sizeof(void *));
674         if (!callid_sock)
675                 return -ENOMEM;
676
677         err = gre_add_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
678         if (err) {
679                 pr_err("PPTP: can't add gre protocol\n");
680                 goto out_mem_free;
681         }
682
683         err = proto_register(&pptp_sk_proto, 0);
684         if (err) {
685                 pr_err("PPTP: can't register sk_proto\n");
686                 goto out_gre_del_protocol;
687         }
688
689         err = register_pppox_proto(PX_PROTO_PPTP, &pppox_pptp_proto);
690         if (err) {
691                 pr_err("PPTP: can't register pppox_proto\n");
692                 goto out_unregister_sk_proto;
693         }
694
695         return 0;
696
697 out_unregister_sk_proto:
698         proto_unregister(&pptp_sk_proto);
699 out_gre_del_protocol:
700         gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
701 out_mem_free:
702         vfree(callid_sock);
703
704         return err;
705 }
706
707 static void __exit pptp_exit_module(void)
708 {
709         unregister_pppox_proto(PX_PROTO_PPTP);
710         proto_unregister(&pptp_sk_proto);
711         gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
712         vfree(callid_sock);
713 }
714
715 module_init(pptp_init_module);
716 module_exit(pptp_exit_module);
717
718 MODULE_DESCRIPTION("Point-to-Point Tunneling Protocol");
719 MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
720 MODULE_LICENSE("GPL");