pptp.c 16 KB

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