pptp.c 17 KB

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