nat.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011, 2016 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file src/nat/nat.h
  18. * @brief Messages for interaction with gnunet-nat-server and gnunet-nat-service
  19. * @author Christian Grothoff
  20. *
  21. */
  22. #ifndef NAT_H
  23. #define NAT_H
  24. #include "gnunet_util_lib.h"
  25. GNUNET_NETWORK_STRUCT_BEGIN
  26. /**
  27. * Request to test NAT traversal, sent to the gnunet-nat-server
  28. * (not the service!).
  29. */
  30. struct GNUNET_NAT_TestMessage
  31. {
  32. /**
  33. * Header with type #GNUNET_MESSAGE_TYPE_NAT_TEST
  34. */
  35. struct GNUNET_MessageHeader header;
  36. /**
  37. * IPv4 target IP address
  38. */
  39. uint32_t dst_ipv4;
  40. /**
  41. * Port to use, 0 to send dummy ICMP response.
  42. */
  43. uint16_t dport;
  44. /**
  45. * Data to send OR advertised-port (in NBO) to use for dummy ICMP.
  46. */
  47. uint16_t data;
  48. /**
  49. * #GNUNET_YES for TCP, #GNUNET_NO for UDP.
  50. */
  51. int32_t is_tcp;
  52. };
  53. /**
  54. * Flags specifying the events this client would be
  55. * interested in being told about.
  56. */
  57. enum GNUNET_NAT_RegisterFlags
  58. {
  59. /**
  60. * This client does not want any notifications.
  61. */
  62. GNUNET_NAT_RF_NONE = 0,
  63. /**
  64. * This client wants to be informed about changes to our
  65. * applicable addresses.
  66. */
  67. GNUNET_NAT_RF_ADDRESSES = 1,
  68. /**
  69. * This client supports address reversal.
  70. */
  71. GNUNET_NAT_RF_REVERSAL = 2
  72. };
  73. /**
  74. * Message sent by a client to register with its addresses.
  75. */
  76. struct GNUNET_NAT_RegisterMessage
  77. {
  78. /**
  79. * Header with type #GNUNET_MESSAGE_TYPE_NAT_REGISTER
  80. */
  81. struct GNUNET_MessageHeader header;
  82. /**
  83. * An `enum GNUNET_NAT_RegisterFlags`.
  84. */
  85. uint8_t flags;
  86. /**
  87. * Client's IPPROTO, e.g. IPPROTO_UDP or IPPROTO_TCP.
  88. */
  89. uint8_t proto;
  90. /**
  91. * Number of bytes in the string that follow which
  92. * specifies a section name in the configuration.
  93. */
  94. uint16_t str_len GNUNET_PACKED;
  95. /**
  96. * Number of addresses that this service is bound to that follow.
  97. * Given as an array of "struct sockaddr" entries, the size of
  98. * each entry being determined by the "sa_family" at the beginning.
  99. */
  100. uint16_t num_addrs GNUNET_PACKED;
  101. /* Followed by @e num_addrs addresses of type 'struct
  102. sockaddr' */
  103. /* Followed by @e str_len section name to use for options */
  104. };
  105. /**
  106. * Client telling the service to (possibly) handle a STUN message.
  107. */
  108. struct GNUNET_NAT_HandleStunMessage
  109. {
  110. /**
  111. * Header with type #GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN
  112. */
  113. struct GNUNET_MessageHeader header;
  114. /**
  115. * Size of the sender address included, in NBO.
  116. */
  117. uint16_t sender_addr_size;
  118. /**
  119. * Number of bytes of payload included, in NBO.
  120. */
  121. uint16_t payload_size;
  122. /* followed by a `struct sockaddr` of @e sender_addr_size bytes */
  123. /* followed by payload with @e payload_size bytes */
  124. };
  125. /**
  126. * Client asking the service to initiate connection reversal.
  127. */
  128. struct GNUNET_NAT_RequestConnectionReversalMessage
  129. {
  130. /**
  131. * Header with type #GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL
  132. */
  133. struct GNUNET_MessageHeader header;
  134. /**
  135. * Size of the local address included, in NBO.
  136. */
  137. uint16_t local_addr_size;
  138. /**
  139. * Size of the remote address included, in NBO.
  140. */
  141. uint16_t remote_addr_size;
  142. /* followed by a `struct sockaddr` of @e local_addr_size bytes */
  143. /* followed by a `struct sockaddr` of @e remote_addr_size bytes */
  144. };
  145. /**
  146. * Service telling a client that connection reversal was requested.
  147. */
  148. struct GNUNET_NAT_ConnectionReversalRequestedMessage
  149. {
  150. /**
  151. * Header with type #GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED
  152. */
  153. struct GNUNET_MessageHeader header;
  154. /* followed by a `struct sockaddr_in` */
  155. };
  156. /**
  157. * Service notifying the client about changes in the set of
  158. * addresses it has.
  159. */
  160. struct GNUNET_NAT_AddressChangeNotificationMessage
  161. {
  162. /**
  163. * Header with type #GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE
  164. */
  165. struct GNUNET_MessageHeader header;
  166. /**
  167. * #GNUNET_YES to add, #GNUNET_NO to remove the address from the list.
  168. */
  169. int32_t add_remove GNUNET_PACKED;
  170. /**
  171. * Type of the address, an `enum GNUNET_NAT_AddressClass` in NBO.
  172. */
  173. uint32_t addr_class GNUNET_PACKED;
  174. /* followed by a `struct sockaddr` */
  175. };
  176. GNUNET_NETWORK_STRUCT_END
  177. #endif