pptp.c 16 KB

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