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