pconfig.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * pconfig.h
  3. * ptunnel is licensed under the BSD license:
  4. *
  5. * Copyright (c) 2004-2011, Daniel Stoedle <daniels@cs.uit.no>,
  6. * Yellow Lemon Software. All rights reserved.
  7. *
  8. * Copyright (c) 2017-2019, Toni Uhlig <matzeton@googlemail.com>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. *
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. *
  20. * - Neither the name of the Yellow Lemon Software nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. * Contacting the author:
  37. * You can get in touch with me, Daniel Stødle (that's the Norwegian letter oe,
  38. * in case your text editor didn't realize), here: <daniels@cs.uit.no>
  39. *
  40. * The official ptunnel website is here:
  41. * <http://www.cs.uit.no/~daniels/PingTunnel/>
  42. *
  43. * Note that the source code is best viewed with tabs set to 4 spaces.
  44. */
  45. #ifndef PCONFIG_H
  46. #define PCONFIG_H 1
  47. enum {
  48. /** Set this constant to the number of
  49. * concurrent connections you wish to handle by default.
  50. */
  51. kMax_tunnels = 10,
  52. /** numbers */
  53. kIP_packet_max_size = 576,
  54. /** In bytes, mind you */
  55. kIP_header_size = 20,
  56. kIP_actual_size = (kIP_packet_max_size - kIP_header_size) - ((kIP_packet_max_size - kIP_header_size) % 8),
  57. /** Also in bytes */
  58. kICMP_header_size = 8,
  59. /** This constant control the maximum size of
  60. * the payload-portion of the ICMP packets
  61. * we send. Note that this does not include
  62. * the IP or ICMP headers!
  63. */
  64. kDefault_buf_size = 1024,
  65. /** Type code for echo request and replies */
  66. kICMP_echo_request = 8,
  67. kICMP_echo_reply = 0,
  68. /** number of packets we can have in our send/receive ring */
  69. kPing_window_size = 64,
  70. /** Tunnels are automatically closed after one minute of inactivity. Since
  71. * we continously send acknowledgements between the two peers, this mechanism
  72. * won't disconnect "valid" connections.
  73. */
  74. kAutomatic_close_timeout = 60, // Seconds!
  75. /** size of md5 digest in bytes */
  76. kMD5_digest_size = 16,
  77. /** size of sha512 digest in bytes */
  78. kSHA512_digest_size = 64,
  79. kDNS_port = 53
  80. };
  81. enum oper_mode {
  82. /** Ping tunnel's operating mode (client) */
  83. kMode_forward = 0,
  84. /** Ping tunnel's operating mode (server) */
  85. kMode_proxy
  86. };
  87. enum pkt_flag {
  88. /** set when packet comes from a user */
  89. kUser_flag = 1 << 30,
  90. /** set when packet comes from the proxy */
  91. kProxy_flag = 1 << 31,
  92. kFlag_mask = kUser_flag | kProxy_flag
  93. };
  94. enum log_level {
  95. /** Different verbosity levels. */
  96. kNo_log = -1,
  97. kLog_error = 0,
  98. kLog_info,
  99. kLog_event,
  100. kLog_verbose,
  101. kLog_debug,
  102. kLog_sendrecv
  103. };
  104. enum proxy_state {
  105. /** These constants are used to indicate the protocol state. The protocol
  106. * works as follows:
  107. * - The identifier is used by both the proxy and the forwarder
  108. * to identify the session (and thus the relevant sockets).
  109. * - The seq-no of the ping packet is used in a sliding-window-esque
  110. * way, and to identify the order of data.
  111. *
  112. * The protocol can be in any of the following states:
  113. * kProxy_start Causes the proxy to open a connection to the given
  114. * host and port, associating the ID with the socket,
  115. * before the data on the socket are transmitted.
  116. * kProxy_data Indicates that the packet contains data from the proxy.
  117. * Data ordering is indicated by the seq-no, which will start
  118. * at 0. (The proxy and forwarder maintain different seq-nos.)
  119. * kUser_data This packet contains user data.
  120. * kConnection_close Indicates that the connection is being closed.
  121. * kProxy_ack and Acknowledges the packet (and all packets before it) with seq_no = ack.
  122. * kUser_ack This is used if there are no implicit acknowledgements due to data
  123. * being sent.
  124. *
  125. * Acknowledgements work by the remote peer acknowledging the last
  126. * continuous seq no it has received.
  127. *
  128. * Note: A proxy receiving a kProxy_data packet, or a user receiving a
  129. * kUser_data packet, should ignore it, as it is the host operating system
  130. * actually returning the ping. This is mostly relevant for users, and for
  131. * proxies running in unprivileged mode.
  132. */
  133. kProxy_start = 0,
  134. kProto_ack,
  135. kProto_data,
  136. kProto_close,
  137. kProto_authenticate,
  138. kNum_proto_types
  139. };
  140. #endif