pptp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. #include <linux/string.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/slab.h>
  16. #include <linux/errno.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/net.h>
  19. #include <linux/skbuff.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/init.h>
  22. #include <linux/ppp_channel.h>
  23. #include <linux/ppp_defs.h>
  24. #include <linux/if_pppox.h>
  25. #include <linux/ppp-ioctl.h>
  26. #include <linux/notifier.h>
  27. #include <linux/file.h>
  28. #include <linux/in.h>
  29. #include <linux/ip.h>
  30. #include <linux/rcupdate.h>
  31. #include <linux/spinlock.h>
  32. #include <net/sock.h>
  33. #include <net/protocol.h>
  34. #include <net/ip.h>
  35. #include <net/icmp.h>
  36. #include <net/route.h>
  37. #include <net/gre.h>
  38. #include <net/pptp.h>
  39. #include <linux/uaccess.h>
  40. #define PPTP_DRIVER_VERSION "0.8.5"
  41. #define MAX_CALLID 65535
  42. static DECLARE_BITMAP(callid_bitmap, MAX_CALLID + 1);
  43. static struct pppox_sock __rcu **callid_sock;
  44. static DEFINE_SPINLOCK(chan_lock);
  45. static struct proto pptp_sk_proto __read_mostly;
  46. static const struct ppp_channel_ops pptp_chan_ops;
  47. static const struct proto_ops pptp_ops;
  48. static struct pppox_sock *lookup_chan(u16 call_id, __be32 s_addr)
  49. {
  50. struct pppox_sock *sock;
  51. struct pptp_opt *opt;
  52. rcu_read_lock();
  53. sock = rcu_dereference(callid_sock[call_id]);
  54. if (sock) {
  55. opt = &sock->proto.pptp;
  56. if (opt->dst_addr.sin_addr.s_addr != s_addr)
  57. sock = NULL;
  58. else
  59. sock_hold(sk_pppox(sock));
  60. }
  61. rcu_read_unlock();
  62. return sock;
  63. }
  64. static int lookup_chan_dst(u16 call_id, __be32 d_addr)
  65. {
  66. struct pppox_sock *sock;
  67. struct pptp_opt *opt;
  68. int i;
  69. rcu_read_lock();
  70. i = 1;
  71. for_each_set_bit_from(i, callid_bitmap, MAX_CALLID) {
  72. sock = rcu_dereference(callid_sock[i]);
  73. if (!sock)
  74. continue;
  75. opt = &sock->proto.pptp;
  76. if (opt->dst_addr.call_id == call_id &&
  77. opt->dst_addr.sin_addr.s_addr == d_addr)
  78. break;
  79. }
  80. rcu_read_unlock();
  81. return i < MAX_CALLID;
  82. }
  83. static int add_chan(struct pppox_sock *sock,
  84. struct pptp_addr *sa)
  85. {
  86. static int call_id;
  87. spin_lock(&chan_lock);
  88. if (!sa->call_id) {
  89. call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, call_id + 1);
  90. if (call_id == MAX_CALLID) {
  91. call_id = find_next_zero_bit(callid_bitmap, MAX_CALLID, 1);
  92. if (call_id == MAX_CALLID)
  93. goto out_err;
  94. }
  95. sa->call_id = call_id;
  96. } else if (test_bit(sa->call_id, callid_bitmap)) {
  97. goto out_err;
  98. }
  99. sock->proto.pptp.src_addr = *sa;
  100. set_bit(sa->call_id, callid_bitmap);
  101. rcu_assign_pointer(callid_sock[sa->call_id], sock);
  102. spin_unlock(&chan_lock);
  103. return 0;
  104. out_err:
  105. spin_unlock(&chan_lock);
  106. return -1;
  107. }
  108. static void del_chan(struct pppox_sock *sock)
  109. {
  110. spin_lock(&chan_lock);
  111. clear_bit(sock->proto.pptp.src_addr.call_id, callid_bitmap);
  112. RCU_INIT_POINTER(callid_sock[sock->proto.pptp.src_addr.call_id], NULL);
  113. spin_unlock(&chan_lock);
  114. }
  115. static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
  116. {
  117. struct sock *sk = (struct sock *) chan->private;
  118. struct pppox_sock *po = pppox_sk(sk);
  119. struct net *net = sock_net(sk);
  120. struct pptp_opt *opt = &po->proto.pptp;
  121. struct pptp_gre_header *hdr;
  122. unsigned int header_len = sizeof(*hdr);
  123. struct flowi4 fl4;
  124. int islcp;
  125. int len;
  126. unsigned char *data;
  127. __u32 seq_recv;
  128. struct rtable *rt;
  129. struct net_device *tdev;
  130. struct iphdr *iph;
  131. int max_headroom;
  132. if (sk_pppox(po)->sk_state & PPPOX_DEAD)
  133. goto tx_error;
  134. rt = ip_route_output_ports(net, &fl4, NULL,
  135. opt->dst_addr.sin_addr.s_addr,
  136. opt->src_addr.sin_addr.s_addr,
  137. 0, 0, IPPROTO_GRE,
  138. RT_TOS(0), 0);
  139. if (IS_ERR(rt))
  140. goto tx_error;
  141. tdev = rt->dst.dev;
  142. max_headroom = LL_RESERVED_SPACE(tdev) + sizeof(*iph) + sizeof(*hdr) + 2;
  143. if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
  144. struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
  145. if (!new_skb) {
  146. ip_rt_put(rt);
  147. goto tx_error;
  148. }
  149. if (skb->sk)
  150. skb_set_owner_w(new_skb, skb->sk);
  151. consume_skb(skb);
  152. skb = new_skb;
  153. }
  154. data = skb->data;
  155. islcp = ((data[0] << 8) + data[1]) == PPP_LCP && 1 <= data[2] && data[2] <= 7;
  156. /* compress protocol field */
  157. if ((opt->ppp_flags & SC_COMP_PROT) && data[0] == 0 && !islcp)
  158. skb_pull(skb, 1);
  159. /* Put in the address/control bytes if necessary */
  160. if ((opt->ppp_flags & SC_COMP_AC) == 0 || islcp) {
  161. data = skb_push(skb, 2);
  162. data[0] = PPP_ALLSTATIONS;
  163. data[1] = PPP_UI;
  164. }
  165. len = skb->len;
  166. seq_recv = opt->seq_recv;
  167. if (opt->ack_sent == seq_recv)
  168. header_len -= sizeof(hdr->ack);
  169. /* Push down and install GRE header */
  170. skb_push(skb, header_len);
  171. hdr = (struct pptp_gre_header *)(skb->data);
  172. hdr->gre_hd.flags = GRE_KEY | GRE_VERSION_1 | GRE_SEQ;
  173. hdr->gre_hd.protocol = GRE_PROTO_PPP;
  174. hdr->call_id = htons(opt->dst_addr.call_id);
  175. hdr->seq = htonl(++opt->seq_sent);
  176. if (opt->ack_sent != seq_recv) {
  177. /* send ack with this message */
  178. hdr->gre_hd.flags |= GRE_ACK;
  179. hdr->ack = htonl(seq_recv);
  180. opt->ack_sent = seq_recv;
  181. }
  182. hdr->payload_len = htons(len);
  183. /* Push down and install the IP header. */
  184. skb_reset_transport_header(skb);
  185. skb_push(skb, sizeof(*iph));
  186. skb_reset_network_header(skb);
  187. memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
  188. IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED);
  189. iph = ip_hdr(skb);
  190. iph->version = 4;
  191. iph->ihl = sizeof(struct iphdr) >> 2;
  192. if (ip_dont_fragment(sk, &rt->dst))
  193. iph->frag_off = htons(IP_DF);
  194. else
  195. iph->frag_off = 0;
  196. iph->protocol = IPPROTO_GRE;
  197. iph->tos = 0;
  198. iph->daddr = fl4.daddr;
  199. iph->saddr = fl4.saddr;
  200. iph->ttl = ip4_dst_hoplimit(&rt->dst);
  201. iph->tot_len = htons(skb->len);
  202. skb_dst_drop(skb);
  203. skb_dst_set(skb, &rt->dst);
  204. nf_reset(skb);
  205. skb->ip_summed = CHECKSUM_NONE;
  206. ip_select_ident(net, skb, NULL);
  207. ip_send_check(iph);
  208. ip_local_out(net, skb->sk, skb);
  209. return 1;
  210. tx_error:
  211. kfree_skb(skb);
  212. return 1;
  213. }
  214. static int pptp_rcv_core(struct sock *sk, struct sk_buff *skb)
  215. {
  216. struct pppox_sock *po = pppox_sk(sk);
  217. struct pptp_opt *opt = &po->proto.pptp;
  218. int headersize, payload_len, seq;
  219. __u8 *payload;
  220. struct pptp_gre_header *header;
  221. if (!(sk->sk_state & PPPOX_CONNECTED)) {
  222. if (sock_queue_rcv_skb(sk, skb))
  223. goto drop;
  224. return NET_RX_SUCCESS;
  225. }
  226. header = (struct pptp_gre_header *)(skb->data);
  227. headersize = sizeof(*header);
  228. /* test if acknowledgement present */
  229. if (GRE_IS_ACK(header->gre_hd.flags)) {
  230. __u32 ack;
  231. if (!pskb_may_pull(skb, headersize))
  232. goto drop;
  233. header = (struct pptp_gre_header *)(skb->data);
  234. /* ack in different place if S = 0 */
  235. ack = GRE_IS_SEQ(header->gre_hd.flags) ? header->ack : header->seq;
  236. ack = ntohl(ack);
  237. if (ack > opt->ack_recv)
  238. opt->ack_recv = ack;
  239. /* also handle sequence number wrap-around */
  240. if (WRAPPED(ack, opt->ack_recv))
  241. opt->ack_recv = ack;
  242. } else {
  243. headersize -= sizeof(header->ack);
  244. }
  245. /* test if payload present */
  246. if (!GRE_IS_SEQ(header->gre_hd.flags))
  247. goto drop;
  248. payload_len = ntohs(header->payload_len);
  249. seq = ntohl(header->seq);
  250. /* check for incomplete packet (length smaller than expected) */
  251. if (!pskb_may_pull(skb, headersize + payload_len))
  252. goto drop;
  253. payload = skb->data + headersize;
  254. /* check for expected sequence number */
  255. if (seq < opt->seq_recv + 1 || WRAPPED(opt->seq_recv, seq)) {
  256. if ((payload[0] == PPP_ALLSTATIONS) && (payload[1] == PPP_UI) &&
  257. (PPP_PROTOCOL(payload) == PPP_LCP) &&
  258. ((payload[4] == PPP_LCP_ECHOREQ) || (payload[4] == PPP_LCP_ECHOREP)))
  259. goto allow_packet;
  260. } else {
  261. opt->seq_recv = seq;
  262. allow_packet:
  263. skb_pull(skb, headersize);
  264. if (payload[0] == PPP_ALLSTATIONS && payload[1] == PPP_UI) {
  265. /* chop off address/control */
  266. if (skb->len < 3)
  267. goto drop;
  268. skb_pull(skb, 2);
  269. }
  270. if ((*skb->data) & 1) {
  271. /* protocol is compressed */
  272. *(u8 *)skb_push(skb, 1) = 0;
  273. }
  274. skb->ip_summed = CHECKSUM_NONE;
  275. skb_set_network_header(skb, skb->head-skb->data);
  276. ppp_input(&po->chan, skb);
  277. return NET_RX_SUCCESS;
  278. }
  279. drop:
  280. kfree_skb(skb);
  281. return NET_RX_DROP;
  282. }
  283. static int pptp_rcv(struct sk_buff *skb)
  284. {
  285. struct pppox_sock *po;
  286. struct pptp_gre_header *header;
  287. struct iphdr *iph;
  288. if (skb->pkt_type != PACKET_HOST)
  289. goto drop;
  290. if (!pskb_may_pull(skb, 12))
  291. goto drop;
  292. iph = ip_hdr(skb);
  293. header = (struct pptp_gre_header *)skb->data;
  294. if (header->gre_hd.protocol != GRE_PROTO_PPP || /* PPTP-GRE protocol for PPTP */
  295. GRE_IS_CSUM(header->gre_hd.flags) || /* flag CSUM should be clear */
  296. GRE_IS_ROUTING(header->gre_hd.flags) || /* flag ROUTING should be clear */
  297. !GRE_IS_KEY(header->gre_hd.flags) || /* flag KEY should be set */
  298. (header->gre_hd.flags & GRE_FLAGS)) /* flag Recursion Ctrl should be clear */
  299. /* if invalid, discard this packet */
  300. goto drop;
  301. po = lookup_chan(htons(header->call_id), iph->saddr);
  302. if (po) {
  303. skb_dst_drop(skb);
  304. nf_reset(skb);
  305. return sk_receive_skb(sk_pppox(po), skb, 0);
  306. }
  307. drop:
  308. kfree_skb(skb);
  309. return NET_RX_DROP;
  310. }
  311. static int pptp_bind(struct socket *sock, struct sockaddr *uservaddr,
  312. int sockaddr_len)
  313. {
  314. struct sock *sk = sock->sk;
  315. struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
  316. struct pppox_sock *po = pppox_sk(sk);
  317. int error = 0;
  318. if (sockaddr_len < sizeof(struct sockaddr_pppox))
  319. return -EINVAL;
  320. lock_sock(sk);
  321. if (sk->sk_state & PPPOX_DEAD) {
  322. error = -EALREADY;
  323. goto out;
  324. }
  325. if (sk->sk_state & PPPOX_BOUND) {
  326. error = -EBUSY;
  327. goto out;
  328. }
  329. if (add_chan(po, &sp->sa_addr.pptp))
  330. error = -EBUSY;
  331. else
  332. sk->sk_state |= PPPOX_BOUND;
  333. out:
  334. release_sock(sk);
  335. return error;
  336. }
  337. static int pptp_connect(struct socket *sock, struct sockaddr *uservaddr,
  338. int sockaddr_len, int flags)
  339. {
  340. struct sock *sk = sock->sk;
  341. struct sockaddr_pppox *sp = (struct sockaddr_pppox *) uservaddr;
  342. struct pppox_sock *po = pppox_sk(sk);
  343. struct pptp_opt *opt = &po->proto.pptp;
  344. struct rtable *rt;
  345. struct flowi4 fl4;
  346. int error = 0;
  347. if (sockaddr_len < sizeof(struct sockaddr_pppox))
  348. return -EINVAL;
  349. if (sp->sa_protocol != PX_PROTO_PPTP)
  350. return -EINVAL;
  351. if (lookup_chan_dst(sp->sa_addr.pptp.call_id, sp->sa_addr.pptp.sin_addr.s_addr))
  352. return -EALREADY;
  353. lock_sock(sk);
  354. /* Check for already bound sockets */
  355. if (sk->sk_state & PPPOX_CONNECTED) {
  356. error = -EBUSY;
  357. goto end;
  358. }
  359. /* Check for already disconnected sockets, on attempts to disconnect */
  360. if (sk->sk_state & PPPOX_DEAD) {
  361. error = -EALREADY;
  362. goto end;
  363. }
  364. if (!opt->src_addr.sin_addr.s_addr || !sp->sa_addr.pptp.sin_addr.s_addr) {
  365. error = -EINVAL;
  366. goto end;
  367. }
  368. po->chan.private = sk;
  369. po->chan.ops = &pptp_chan_ops;
  370. rt = ip_route_output_ports(sock_net(sk), &fl4, sk,
  371. opt->dst_addr.sin_addr.s_addr,
  372. opt->src_addr.sin_addr.s_addr,
  373. 0, 0,
  374. IPPROTO_GRE, RT_CONN_FLAGS(sk), 0);
  375. if (IS_ERR(rt)) {
  376. error = -EHOSTUNREACH;
  377. goto end;
  378. }
  379. sk_setup_caps(sk, &rt->dst);
  380. po->chan.mtu = dst_mtu(&rt->dst);
  381. if (!po->chan.mtu)
  382. po->chan.mtu = PPP_MRU;
  383. po->chan.mtu -= PPTP_HEADER_OVERHEAD;
  384. po->chan.hdrlen = 2 + sizeof(struct pptp_gre_header);
  385. error = ppp_register_channel(&po->chan);
  386. if (error) {
  387. pr_err("PPTP: failed to register PPP channel (%d)\n", error);
  388. goto end;
  389. }
  390. opt->dst_addr = sp->sa_addr.pptp;
  391. sk->sk_state |= PPPOX_CONNECTED;
  392. end:
  393. release_sock(sk);
  394. return error;
  395. }
  396. static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
  397. int peer)
  398. {
  399. int len = sizeof(struct sockaddr_pppox);
  400. struct sockaddr_pppox sp;
  401. memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
  402. sp.sa_family = AF_PPPOX;
  403. sp.sa_protocol = PX_PROTO_PPTP;
  404. sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
  405. memcpy(uaddr, &sp, len);
  406. return len;
  407. }
  408. static int pptp_release(struct socket *sock)
  409. {
  410. struct sock *sk = sock->sk;
  411. struct pppox_sock *po;
  412. int error = 0;
  413. if (!sk)
  414. return 0;
  415. lock_sock(sk);
  416. if (sock_flag(sk, SOCK_DEAD)) {
  417. release_sock(sk);
  418. return -EBADF;
  419. }
  420. po = pppox_sk(sk);
  421. del_chan(po);
  422. synchronize_rcu();
  423. pppox_unbind_sock(sk);
  424. sk->sk_state = PPPOX_DEAD;
  425. sock_orphan(sk);
  426. sock->sk = NULL;
  427. release_sock(sk);
  428. sock_put(sk);
  429. return error;
  430. }
  431. static void pptp_sock_destruct(struct sock *sk)
  432. {
  433. if (!(sk->sk_state & PPPOX_DEAD)) {
  434. del_chan(pppox_sk(sk));
  435. pppox_unbind_sock(sk);
  436. }
  437. skb_queue_purge(&sk->sk_receive_queue);
  438. dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
  439. }
  440. static int pptp_create(struct net *net, struct socket *sock, int kern)
  441. {
  442. int error = -ENOMEM;
  443. struct sock *sk;
  444. struct pppox_sock *po;
  445. struct pptp_opt *opt;
  446. sk = sk_alloc(net, PF_PPPOX, GFP_KERNEL, &pptp_sk_proto, kern);
  447. if (!sk)
  448. goto out;
  449. sock_init_data(sock, sk);
  450. sock->state = SS_UNCONNECTED;
  451. sock->ops = &pptp_ops;
  452. sk->sk_backlog_rcv = pptp_rcv_core;
  453. sk->sk_state = PPPOX_NONE;
  454. sk->sk_type = SOCK_STREAM;
  455. sk->sk_family = PF_PPPOX;
  456. sk->sk_protocol = PX_PROTO_PPTP;
  457. sk->sk_destruct = pptp_sock_destruct;
  458. po = pppox_sk(sk);
  459. opt = &po->proto.pptp;
  460. opt->seq_sent = 0; opt->seq_recv = 0xffffffff;
  461. opt->ack_recv = 0; opt->ack_sent = 0xffffffff;
  462. error = 0;
  463. out:
  464. return error;
  465. }
  466. static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
  467. unsigned long arg)
  468. {
  469. struct sock *sk = (struct sock *) chan->private;
  470. struct pppox_sock *po = pppox_sk(sk);
  471. struct pptp_opt *opt = &po->proto.pptp;
  472. void __user *argp = (void __user *)arg;
  473. int __user *p = argp;
  474. int err, val;
  475. err = -EFAULT;
  476. switch (cmd) {
  477. case PPPIOCGFLAGS:
  478. val = opt->ppp_flags;
  479. if (put_user(val, p))
  480. break;
  481. err = 0;
  482. break;
  483. case PPPIOCSFLAGS:
  484. if (get_user(val, p))
  485. break;
  486. opt->ppp_flags = val & ~SC_RCV_BITS;
  487. err = 0;
  488. break;
  489. default:
  490. err = -ENOTTY;
  491. }
  492. return err;
  493. }
  494. static const struct ppp_channel_ops pptp_chan_ops = {
  495. .start_xmit = pptp_xmit,
  496. .ioctl = pptp_ppp_ioctl,
  497. };
  498. static struct proto pptp_sk_proto __read_mostly = {
  499. .name = "PPTP",
  500. .owner = THIS_MODULE,
  501. .obj_size = sizeof(struct pppox_sock),
  502. };
  503. static const struct proto_ops pptp_ops = {
  504. .family = AF_PPPOX,
  505. .owner = THIS_MODULE,
  506. .release = pptp_release,
  507. .bind = pptp_bind,
  508. .connect = pptp_connect,
  509. .socketpair = sock_no_socketpair,
  510. .accept = sock_no_accept,
  511. .getname = pptp_getname,
  512. .listen = sock_no_listen,
  513. .shutdown = sock_no_shutdown,
  514. .setsockopt = sock_no_setsockopt,
  515. .getsockopt = sock_no_getsockopt,
  516. .sendmsg = sock_no_sendmsg,
  517. .recvmsg = sock_no_recvmsg,
  518. .mmap = sock_no_mmap,
  519. .ioctl = pppox_ioctl,
  520. #ifdef CONFIG_COMPAT
  521. .compat_ioctl = pppox_compat_ioctl,
  522. #endif
  523. };
  524. static const struct pppox_proto pppox_pptp_proto = {
  525. .create = pptp_create,
  526. .owner = THIS_MODULE,
  527. };
  528. static const struct gre_protocol gre_pptp_protocol = {
  529. .handler = pptp_rcv,
  530. };
  531. static int __init pptp_init_module(void)
  532. {
  533. int err = 0;
  534. pr_info("PPTP driver version " PPTP_DRIVER_VERSION "\n");
  535. callid_sock = vzalloc(array_size(sizeof(void *), (MAX_CALLID + 1)));
  536. if (!callid_sock)
  537. return -ENOMEM;
  538. err = gre_add_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
  539. if (err) {
  540. pr_err("PPTP: can't add gre protocol\n");
  541. goto out_mem_free;
  542. }
  543. err = proto_register(&pptp_sk_proto, 0);
  544. if (err) {
  545. pr_err("PPTP: can't register sk_proto\n");
  546. goto out_gre_del_protocol;
  547. }
  548. err = register_pppox_proto(PX_PROTO_PPTP, &pppox_pptp_proto);
  549. if (err) {
  550. pr_err("PPTP: can't register pppox_proto\n");
  551. goto out_unregister_sk_proto;
  552. }
  553. return 0;
  554. out_unregister_sk_proto:
  555. proto_unregister(&pptp_sk_proto);
  556. out_gre_del_protocol:
  557. gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
  558. out_mem_free:
  559. vfree(callid_sock);
  560. return err;
  561. }
  562. static void __exit pptp_exit_module(void)
  563. {
  564. unregister_pppox_proto(PX_PROTO_PPTP);
  565. proto_unregister(&pptp_sk_proto);
  566. gre_del_protocol(&gre_pptp_protocol, GREPROTO_PPTP);
  567. vfree(callid_sock);
  568. }
  569. module_init(pptp_init_module);
  570. module_exit(pptp_exit_module);
  571. MODULE_DESCRIPTION("Point-to-Point Tunneling Protocol");
  572. MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
  573. MODULE_LICENSE("GPL");
  574. MODULE_ALIAS_NET_PF_PROTO(PF_PPPOX, PX_PROTO_PPTP);