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