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