pptp.c 17 KB

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