Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[cascardo/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 pptp_opt *opt = &po->proto.pptp;
173         struct pptp_gre_header *hdr;
174         unsigned int header_len = sizeof(*hdr);
175         struct flowi4 fl4;
176         int islcp;
177         int len;
178         unsigned char *data;
179         __u32 seq_recv;
180
181
182         struct rtable *rt;
183         struct net_device *tdev;
184         struct iphdr  *iph;
185         int    max_headroom;
186
187         if (sk_pppox(po)->sk_state & PPPOX_DEAD)
188                 goto tx_error;
189
190         rt = ip_route_output_ports(sock_net(sk), &fl4, NULL,
191                                    opt->dst_addr.sin_addr.s_addr,
192                                    opt->src_addr.sin_addr.s_addr,
193                                    0, 0, IPPROTO_GRE,
194                                    RT_TOS(0), 0);
195         if (IS_ERR(rt))
196                 goto tx_error;
197
198         tdev = rt->dst.dev;
199
200         max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(*iph) + sizeof(*hdr) + 2;
201
202         if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
203                 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
204                 if (!new_skb) {
205                         ip_rt_put(rt);
206                         goto tx_error;
207                 }
208                 if (skb->sk)
209                         skb_set_owner_w(new_skb, skb->sk);
210                 consume_skb(skb);
211                 skb = new_skb;
212         }
213
214         data = skb->data;
215         islcp = ((data[0] << 8) + data[1]) == PPP_LCP && 1 <= data[2] && data[2] <= 7;
216
217         /* compress protocol field */
218         if ((opt->ppp_flags & SC_COMP_PROT) && data[0] == 0 && !islcp)
219                 skb_pull(skb, 1);
220
221         /* Put in the address/control bytes if necessary */
222         if ((opt->ppp_flags & SC_COMP_AC) == 0 || islcp) {
223                 data = skb_push(skb, 2);
224                 data[0] = PPP_ALLSTATIONS;
225                 data[1] = PPP_UI;
226         }
227
228         len = skb->len;
229
230         seq_recv = opt->seq_recv;
231
232         if (opt->ack_sent == seq_recv)
233                 header_len -= sizeof(hdr->ack);
234
235         /* Push down and install GRE header */
236         skb_push(skb, header_len);
237         hdr = (struct pptp_gre_header *)(skb->data);
238
239         hdr->flags       = PPTP_GRE_FLAG_K;
240         hdr->ver         = PPTP_GRE_VER;
241         hdr->protocol    = htons(PPTP_GRE_PROTO);
242         hdr->call_id     = htons(opt->dst_addr.call_id);
243
244         hdr->flags      |= PPTP_GRE_FLAG_S;
245         hdr->seq         = htonl(++opt->seq_sent);
246         if (opt->ack_sent != seq_recv)  {
247                 /* send ack with this message */
248                 hdr->ver |= PPTP_GRE_FLAG_A;
249                 hdr->ack  = htonl(seq_recv);
250                 opt->ack_sent = seq_recv;
251         }
252         hdr->payload_len = htons(len);
253
254         /*      Push down and install the IP header. */
255
256         skb_reset_transport_header(skb);
257         skb_push(skb, sizeof(*iph));
258         skb_reset_network_header(skb);
259         memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
260         IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED);
261
262         iph =   ip_hdr(skb);
263         iph->version =  4;
264         iph->ihl =      sizeof(struct iphdr) >> 2;
265         if (ip_dont_fragment(sk, &rt->dst))
266                 iph->frag_off   =       htons(IP_DF);
267         else
268                 iph->frag_off   =       0;
269         iph->protocol = IPPROTO_GRE;
270         iph->tos      = 0;
271         iph->daddr    = fl4.daddr;
272         iph->saddr    = fl4.saddr;
273         iph->ttl      = ip4_dst_hoplimit(&rt->dst);
274         iph->tot_len  = htons(skb->len);
275
276         skb_dst_drop(skb);
277         skb_dst_set(skb, &rt->dst);
278
279         nf_reset(skb);
280
281         skb->ip_summed = CHECKSUM_NONE;
282         ip_select_ident(sock_net(sk), skb, NULL);
283         ip_send_check(iph);
284
285         ip_local_out(skb);
286         return 1;
287
288 tx_error:
289         kfree_skb(skb);
290         return 1;
291 }
292
293 static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
294 {
295         struct pppox_sock *po = pppox_sk(sk);
296         struct pptp_opt *opt = &po->proto.pptp;
297         int headersize, payload_len, seq;
298         __u8 *payload;
299         struct pptp_gre_header *header;
300
301         if (!(sk->sk_state & PPPOX_CONNECTED)) {
302                 if (sock_queue_rcv_skb(sk, skb))
303                         goto drop;
304                 return NET_RX_SUCCESS;
305         }
306
307         header = (struct pptp_gre_header *)(skb->data);
308         headersize  = sizeof(*header);
309
310         /* test if acknowledgement present */
311         if (PPTP_GRE_IS_A(header->ver)) {
312                 __u32 ack;
313
314                 if (!pskb_may_pull(skb, headersize))
315                         goto drop;
316                 header = (struct pptp_gre_header *)(skb->data);
317
318                 /* ack in different place if S = 0 */
319                 ack = PPTP_GRE_IS_S(header->flags) ? header->ack : header->seq;
320
321                 ack = ntohl(ack);
322
323                 if (ack > opt->ack_recv)
324                         opt->ack_recv = ack;
325                 /* also handle sequence number wrap-around  */
326                 if (WRAPPED(ack, opt->ack_recv))
327                         opt->ack_recv = ack;
328         } else {
329                 headersize -= sizeof(header->ack);
330         }
331         /* test if payload present */
332         if (!PPTP_GRE_IS_S(header->flags))
333                 goto drop;
334
335         payload_len = ntohs(header->payload_len);
336         seq         = ntohl(header->seq);
337
338         /* check for incomplete packet (length smaller than expected) */
339         if (!pskb_may_pull(skb, 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;
351 allow_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         }
372 drop:
373         kfree_skb(skb);
374         return NET_RX_DROP;
375 }
376
377 static 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         }
407 drop:
408         kfree_skb(skb);
409         return NET_RX_DROP;
410 }
411
412 static 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                 error = -EBUSY;
426
427         release_sock(sk);
428         return error;
429 }
430
431 static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr,
432         int sockaddr_len, int flags)
433 {
434         struct sock *sk = sock->sk;
435         struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
436         struct pppox_sock *po = pppox_sk(sk);
437         struct pptp_opt *opt = &po->proto.pptp;
438         struct rtable *rt;
439         struct flowi4 fl4;
440         int error = 0;
441
442         if (sp->sa_protocol != PX_PROTO_PPTP)
443                 return -EINVAL;
444
445         if (lookup_chan_dst(sp->sa_addr.pptp.call_id, sp->sa_addr.pptp.sin_addr.s_addr))
446                 return -EALREADY;
447
448         lock_sock(sk);
449         /* Check for already bound sockets */
450         if (sk->sk_state & PPPOX_CONNECTED) {
451                 error = -EBUSY;
452                 goto end;
453         }
454
455         /* Check for already disconnected sockets, on attempts to disconnect */
456         if (sk->sk_state & PPPOX_DEAD) {
457                 error = -EALREADY;
458                 goto end;
459         }
460
461         if (!opt->src_addr.sin_addr.s_addr || !sp->sa_addr.pptp.sin_addr.s_addr) {
462                 error = -EINVAL;
463                 goto end;
464         }
465
466         po->chan.private = sk;
467         po->chan.ops = &pptp_chan_ops;
468
469         rt = ip_route_output_ports(sock_net(sk), &fl4, sk,
470                                    opt->dst_addr.sin_addr.s_addr,
471                                    opt->src_addr.sin_addr.s_addr,
472                                    0, 0,
473                                    IPPROTO_GRE, RT_CONN_FLAGS(sk), 0);
474         if (IS_ERR(rt)) {
475                 error = -EHOSTUNREACH;
476                 goto end;
477         }
478         sk_setup_caps(sk, &rt->dst);
479
480         po->chan.mtu = dst_mtu(&rt->dst);
481         if (!po->chan.mtu)
482                 po->chan.mtu = PPP_MRU;
483         ip_rt_put(rt);
484         po->chan.mtu -= PPTP_HEADER_OVERHEAD;
485
486         po->chan.hdrlen = 2 + sizeof(struct pptp_gre_header);
487         error = ppp_register_channel(&po->chan);
488         if (error) {
489                 pr_err("PPTP: failed to register PPP channel (%d)\n", error);
490                 goto end;
491         }
492
493         opt->dst_addr = sp->sa_addr.pptp;
494         sk->sk_state = PPPOX_CONNECTED;
495
496  end:
497         release_sock(sk);
498         return error;
499 }
500
501 static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
502         int *usockaddr_len, int peer)
503 {
504         int len = sizeof(struct sockaddr_pppox);
505         struct sockaddr_pppox sp;
506
507         memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
508
509         sp.sa_family    = AF_PPPOX;
510         sp.sa_protocol  = PX_PROTO_PPTP;
511         sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
512
513         memcpy(uaddr, &sp, len);
514
515         *usockaddr_len = len;
516
517         return 0;
518 }
519
520 static int pptp_release(struct socket *sock)
521 {
522         struct sock *sk = sock->sk;
523         struct pppox_sock *po;
524         struct pptp_opt *opt;
525         int error = 0;
526
527         if (!sk)
528                 return 0;
529
530         lock_sock(sk);
531
532         if (sock_flag(sk, SOCK_DEAD)) {
533                 release_sock(sk);
534                 return -EBADF;
535         }
536
537         po = pppox_sk(sk);
538         opt = &po->proto.pptp;
539         del_chan(po);
540
541         pppox_unbind_sock(sk);
542         sk->sk_state = PPPOX_DEAD;
543
544         sock_orphan(sk);
545         sock->sk = NULL;
546
547         release_sock(sk);
548         sock_put(sk);
549
550         return error;
551 }
552
553 static void pptp_sock_destruct(struct sock *sk)
554 {
555         if (!(sk->sk_state & PPPOX_DEAD)) {
556                 del_chan(pppox_sk(sk));
557                 pppox_unbind_sock(sk);
558         }
559         skb_queue_purge(&sk->sk_receive_queue);
560 }
561
562 static int pptp_create(struct net *net, struct socket *sock, int kern)
563 {
564         int error = -ENOMEM;
565         struct sock *sk;
566         struct pppox_sock *po;
567         struct pptp_opt *opt;
568
569         sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pptp_sk_proto, kern);
570         if (!sk)
571                 goto out;
572
573         sock_init_data(sock, sk);
574
575         sock->state = SS_UNCONNECTED;
576         sock->ops   = &pptp_ops;
577
578         sk->sk_backlog_rcv = pptp_rcv_core;
579         sk->sk_state       = PPPOX_NONE;
580         sk->sk_type        = SOCK_STREAM;
581         sk->sk_family      = PF_PPPOX;
582         sk->sk_protocol    = PX_PROTO_PPTP;
583         sk->sk_destruct    = pptp_sock_destruct;
584
585         po = pppox_sk(sk);
586         opt = &po->proto.pptp;
587
588         opt->seq_sent = 0; opt->seq_recv = 0xffffffff;
589         opt->ack_recv = 0; opt->ack_sent = 0xffffffff;
590
591         error = 0;
592 out:
593         return error;
594 }
595
596 static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
597         unsigned long arg)
598 {
599         struct sock *sk = (struct sock *) chan->private;
600         struct pppox_sock *po = pppox_sk(sk);
601         struct pptp_opt *opt = &po->proto.pptp;
602         void __user *argp = (void __user *)arg;
603         int __user *p = argp;
604         int err, val;
605
606         err = -EFAULT;
607         switch (cmd) {
608         case PPPIOCGFLAGS:
609                 val = opt->ppp_flags;
610                 if (put_user(val, p))
611                         break;
612                 err = 0;
613                 break;
614         case PPPIOCSFLAGS:
615                 if (get_user(val, p))
616                         break;
617                 opt->ppp_flags = val & ~SC_RCV_BITS;
618                 err = 0;
619                 break;
620         default:
621                 err = -ENOTTY;
622         }
623
624         return err;
625 }
626
627 static const struct ppp_channel_ops pptp_chan_ops = {
628         .start_xmit = pptp_xmit,
629         .ioctl      = pptp_ppp_ioctl,
630 };
631
632 static struct proto pptp_sk_proto __read_mostly = {
633         .name     = "PPTP",
634         .owner    = THIS_MODULE,
635         .obj_size = sizeof(struct pppox_sock),
636 };
637
638 static const struct proto_ops pptp_ops = {
639         .family     = AF_PPPOX,
640         .owner      = THIS_MODULE,
641         .release    = pptp_release,
642         .bind       = pptp_bind,
643         .connect    = pptp_connect,
644         .socketpair = sock_no_socketpair,
645         .accept     = sock_no_accept,
646         .getname    = pptp_getname,
647         .poll       = sock_no_poll,
648         .listen     = sock_no_listen,
649         .shutdown   = sock_no_shutdown,
650         .setsockopt = sock_no_setsockopt,
651         .getsockopt = sock_no_getsockopt,
652         .sendmsg    = sock_no_sendmsg,
653         .recvmsg    = sock_no_recvmsg,
654         .mmap       = sock_no_mmap,
655         .ioctl      = pppox_ioctl,
656 };
657
658 static const struct pppox_proto pppox_pptp_proto = {
659         .create = pptp_create,
660         .owner  = THIS_MODULE,
661 };
662
663 static const struct gre_protocol gre_pptp_protocol = {
664         .handler = pptp_rcv,
665 };
666
667 static int __init pptp_init_module(void)
668 {
669         int err = 0;
670         pr_info("PPTP driver version " PPTP_DRIVER_VERSION "\n");
671
672         callid_sock = vzalloc((MAX_CALLID + 1) * sizeof(void *));
673         if (!callid_sock)
674                 return -ENOMEM;
675
676         err = gre_add_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
677         if (err) {
678                 pr_err("PPTP: can't add gre protocol\n");
679                 goto out_mem_free;
680         }
681
682         err = proto_register(&pptp_sk_proto, 0);
683         if (err) {
684                 pr_err("PPTP: can't register sk_proto\n");
685                 goto out_gre_del_protocol;
686         }
687
688         err = register_pppox_proto(PX_PROTO_PPTP, &pppox_pptp_proto);
689         if (err) {
690                 pr_err("PPTP: can't register pppox_proto\n");
691                 goto out_unregister_sk_proto;
692         }
693
694         return 0;
695
696 out_unregister_sk_proto:
697         proto_unregister(&pptp_sk_proto);
698 out_gre_del_protocol:
699         gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
700 out_mem_free:
701         vfree(callid_sock);
702
703         return err;
704 }
705
706 static void __exit pptp_exit_module(void)
707 {
708         unregister_pppox_proto(PX_PROTO_PPTP);
709         proto_unregister(&pptp_sk_proto);
710         gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
711         vfree(callid_sock);
712 }
713
714 module_init(pptp_init_module);
715 module_exit(pptp_exit_module);
716
717 MODULE_DESCRIPTION("Point-to-Point Tunneling Protocol");
718 MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
719 MODULE_LICENSE("GPL");