diff options
Diffstat (limited to 'src/vpn/gnunet-daemon-exit.c')
-rw-r--r-- | src/vpn/gnunet-daemon-exit.c | 1271 |
1 files changed, 684 insertions, 587 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index ac07dd4d5..de906af3b 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c | |||
@@ -132,11 +132,12 @@ struct redirect_state | |||
132 | struct redirect_service *serv; | 132 | struct redirect_service *serv; |
133 | struct remote_addr remote; | 133 | struct remote_addr remote; |
134 | 134 | ||
135 | struct GNUNET_CONTAINER_HeapNode* heap_node; | 135 | struct GNUNET_CONTAINER_HeapNode *heap_node; |
136 | struct GNUNET_CONTAINER_MultiHashMap *hashmap; | 136 | struct GNUNET_CONTAINER_MultiHashMap *hashmap; |
137 | GNUNET_HashCode hash; | 137 | GNUNET_HashCode hash; |
138 | 138 | ||
139 | enum { SERVICE, REMOTE } type; | 139 | enum |
140 | { SERVICE, REMOTE } type; | ||
140 | 141 | ||
141 | /** | 142 | /** |
142 | * The source-address and -port of this connection | 143 | * The source-address and -port of this connection |
@@ -152,9 +153,9 @@ static struct GNUNET_CONTAINER_MultiHashMap *tcp_services; | |||
152 | 153 | ||
153 | struct tunnel_notify_queue | 154 | struct tunnel_notify_queue |
154 | { | 155 | { |
155 | struct tunnel_notify_queue* next; | 156 | struct tunnel_notify_queue *next; |
156 | struct tunnel_notify_queue* prev; | 157 | struct tunnel_notify_queue *prev; |
157 | void* cls; | 158 | void *cls; |
158 | size_t len; | 159 | size_t len; |
159 | }; | 160 | }; |
160 | 161 | ||
@@ -162,9 +163,10 @@ struct tunnel_notify_queue | |||
162 | * Function that frees everything from a hashmap | 163 | * Function that frees everything from a hashmap |
163 | */ | 164 | */ |
164 | static int | 165 | static int |
165 | free_iterate(void* cls __attribute__((unused)), const GNUNET_HashCode* hash __attribute__((unused)), void* value) | 166 | free_iterate (void *cls __attribute__ ((unused)), const GNUNET_HashCode * hash |
167 | __attribute__ ((unused)), void *value) | ||
166 | { | 168 | { |
167 | GNUNET_free(value); | 169 | GNUNET_free (value); |
168 | return GNUNET_YES; | 170 | return GNUNET_YES; |
169 | } | 171 | } |
170 | 172 | ||
@@ -172,46 +174,47 @@ free_iterate(void* cls __attribute__((unused)), const GNUNET_HashCode* hash __at | |||
172 | * Function scheduled as very last function, cleans up after us | 174 | * Function scheduled as very last function, cleans up after us |
173 | */ | 175 | */ |
174 | static void | 176 | static void |
175 | cleanup(void* cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext* tskctx) { | 177 | cleanup (void *cls |
176 | GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); | 178 | __attribute__ ((unused)), |
179 | const struct GNUNET_SCHEDULER_TaskContext *tskctx) | ||
180 | { | ||
181 | GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); | ||
177 | 182 | ||
178 | GNUNET_CONTAINER_multihashmap_iterate(udp_connections, | 183 | GNUNET_CONTAINER_multihashmap_iterate (udp_connections, free_iterate, NULL); |
179 | free_iterate, | ||
180 | NULL); | ||
181 | 184 | ||
182 | GNUNET_CONTAINER_multihashmap_iterate(tcp_connections, | 185 | GNUNET_CONTAINER_multihashmap_iterate (tcp_connections, free_iterate, NULL); |
183 | free_iterate, | ||
184 | NULL); | ||
185 | 186 | ||
186 | if (mesh_handle != NULL) | 187 | if (mesh_handle != NULL) |
187 | { | 188 | { |
188 | GNUNET_MESH_disconnect(mesh_handle); | 189 | GNUNET_MESH_disconnect (mesh_handle); |
189 | mesh_handle = NULL; | 190 | mesh_handle = NULL; |
190 | } | 191 | } |
191 | } | 192 | } |
192 | 193 | ||
193 | static void | 194 | static void |
194 | collect_connections(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { | 195 | collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
195 | if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 196 | { |
196 | return; | 197 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
198 | return; | ||
197 | 199 | ||
198 | 200 | ||
199 | struct GNUNET_CONTAINER_Heap *heap = cls; | 201 | struct GNUNET_CONTAINER_Heap *heap = cls; |
200 | 202 | ||
201 | struct redirect_state* state = GNUNET_CONTAINER_heap_remove_root(heap); | 203 | struct redirect_state *state = GNUNET_CONTAINER_heap_remove_root (heap); |
202 | 204 | ||
203 | /* This is free()ed memory! */ | 205 | /* This is free()ed memory! */ |
204 | state->heap_node = NULL; | 206 | state->heap_node = NULL; |
205 | 207 | ||
206 | /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */ | 208 | /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */ |
207 | 209 | ||
208 | GNUNET_CONTAINER_multihashmap_remove(state->hashmap, &state->hash, state); | 210 | GNUNET_CONTAINER_multihashmap_remove (state->hashmap, &state->hash, state); |
209 | 211 | ||
210 | GNUNET_free(state); | 212 | GNUNET_free (state); |
211 | } | 213 | } |
212 | 214 | ||
213 | static void | 215 | static void |
214 | hash_redirect_info(GNUNET_HashCode* hash, struct redirect_info* u_i, size_t addrlen) | 216 | hash_redirect_info (GNUNET_HashCode * hash, struct redirect_info *u_i, |
217 | size_t addrlen) | ||
215 | { | 218 | { |
216 | 219 | ||
217 | /* the gnunet hashmap only uses the first sizeof(unsigned int) of the hash | 220 | /* the gnunet hashmap only uses the first sizeof(unsigned int) of the hash |
@@ -219,9 +222,12 @@ hash_redirect_info(GNUNET_HashCode* hash, struct redirect_info* u_i, size_t addr | |||
219 | * build the hash out of the last bytes of the address and the 2 bytes of | 222 | * build the hash out of the last bytes of the address and the 2 bytes of |
220 | * the port | 223 | * the port |
221 | */ | 224 | */ |
222 | memcpy(hash, &u_i->pt, sizeof(u_i->pt)); | 225 | memcpy (hash, &u_i->pt, sizeof (u_i->pt)); |
223 | memcpy(((unsigned char*)hash)+2, u_i->addr+(addrlen-(sizeof(unsigned int) - 2)), (sizeof(unsigned int) - 2)); | 226 | memcpy (((unsigned char *) hash) + 2, |
224 | memset(((unsigned char*)hash)+sizeof(unsigned int), 0, sizeof(GNUNET_HashCode) - sizeof(unsigned int)); | 227 | u_i->addr + (addrlen - (sizeof (unsigned int) - 2)), |
228 | (sizeof (unsigned int) - 2)); | ||
229 | memset (((unsigned char *) hash) + sizeof (unsigned int), 0, | ||
230 | sizeof (GNUNET_HashCode) - sizeof (unsigned int)); | ||
225 | } | 231 | } |
226 | 232 | ||
227 | /** | 233 | /** |
@@ -231,36 +237,41 @@ hash_redirect_info(GNUNET_HashCode* hash, struct redirect_info* u_i, size_t addr | |||
231 | static size_t | 237 | static size_t |
232 | send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) | 238 | send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) |
233 | { | 239 | { |
234 | struct GNUNET_MESH_Tunnel** tunnel = cls; | 240 | struct GNUNET_MESH_Tunnel **tunnel = cls; |
235 | GNUNET_MESH_tunnel_set_data(*tunnel, NULL); | 241 | |
236 | struct GNUNET_MessageHeader *hdr = (struct GNUNET_MessageHeader*)(tunnel + 1); | 242 | GNUNET_MESH_tunnel_set_data (*tunnel, NULL); |
243 | struct GNUNET_MessageHeader *hdr = | ||
244 | (struct GNUNET_MessageHeader *) (tunnel + 1); | ||
237 | GNUNET_assert (size >= ntohs (hdr->size)); | 245 | GNUNET_assert (size >= ntohs (hdr->size)); |
238 | memcpy (buf, hdr, ntohs (hdr->size)); | 246 | memcpy (buf, hdr, ntohs (hdr->size)); |
239 | size = ntohs(hdr->size); | 247 | size = ntohs (hdr->size); |
240 | 248 | ||
241 | if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel)) | 249 | if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel)) |
242 | { | 250 | { |
243 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(*tunnel); | 251 | struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head (*tunnel); |
244 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | 252 | struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel); |
245 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | 253 | struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel); |
246 | 254 | ||
247 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | 255 | GNUNET_CONTAINER_DLL_remove (head, tail, element); |
248 | 256 | ||
249 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | 257 | GNUNET_MESH_tunnel_set_head (*tunnel, head); |
250 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | 258 | GNUNET_MESH_tunnel_set_tail (*tunnel, tail); |
251 | 259 | ||
252 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, | 260 | struct GNUNET_MESH_TransmitHandle *th = |
253 | GNUNET_NO, | 261 | GNUNET_MESH_notify_transmit_ready (*tunnel, |
254 | 42, | 262 | GNUNET_NO, |
255 | GNUNET_TIME_relative_divide | 263 | 42, |
256 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 264 | GNUNET_TIME_relative_divide |
257 | (const struct GNUNET_PeerIdentity *) | 265 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
258 | NULL, element->len, | 266 | (const struct GNUNET_PeerIdentity *) |
259 | send_udp_to_peer_notify_callback, element->cls); | 267 | NULL, element->len, |
260 | /* save the handle */ | 268 | send_udp_to_peer_notify_callback, |
261 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | 269 | element->cls); |
262 | GNUNET_free(element); | 270 | |
263 | } | 271 | /* save the handle */ |
272 | GNUNET_MESH_tunnel_set_data (*tunnel, th); | ||
273 | GNUNET_free (element); | ||
274 | } | ||
264 | 275 | ||
265 | GNUNET_free (cls); | 276 | GNUNET_free (cls); |
266 | 277 | ||
@@ -291,10 +302,11 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
291 | 302 | ||
292 | /* get tunnel and service-descriptor from this */ | 303 | /* get tunnel and service-descriptor from this */ |
293 | GNUNET_HashCode hash; | 304 | GNUNET_HashCode hash; |
294 | hash_redirect_info(&hash, &u_i, addrlen); | 305 | |
306 | hash_redirect_info (&hash, &u_i, addrlen); | ||
295 | 307 | ||
296 | struct redirect_state *state = | 308 | struct redirect_state *state = |
297 | GNUNET_CONTAINER_multihashmap_get (udp_connections, &hash); | 309 | GNUNET_CONTAINER_multihashmap_get (udp_connections, &hash); |
298 | 310 | ||
299 | /* Mark this connection as freshly used */ | 311 | /* Mark this connection as freshly used */ |
300 | GNUNET_CONTAINER_heap_update_cost (udp_connections_heap, state->heap_node, | 312 | GNUNET_CONTAINER_heap_update_cost (udp_connections_heap, state->heap_node, |
@@ -303,80 +315,92 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
303 | tunnel = state->tunnel; | 315 | tunnel = state->tunnel; |
304 | 316 | ||
305 | if (state->type == SERVICE) | 317 | if (state->type == SERVICE) |
318 | { | ||
319 | /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */ | ||
320 | if (ntohs (udp->spt) == state->serv->remote_port) | ||
306 | { | 321 | { |
307 | /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */ | 322 | udp->spt = htons (state->serv->my_port); |
308 | if (ntohs (udp->spt) == state->serv->remote_port) | 323 | } |
309 | { | 324 | else |
310 | udp->spt = htons (state->serv->my_port); | 325 | { |
311 | } | 326 | /* otherwise the answer came from a different port (tftp does this) |
312 | else | 327 | * add this new port to the list of all services, so that the packets |
313 | { | 328 | * coming back from the client to this new port will be routed correctly |
314 | /* otherwise the answer came from a different port (tftp does this) | 329 | */ |
315 | * add this new port to the list of all services, so that the packets | 330 | struct redirect_service *serv = |
316 | * coming back from the client to this new port will be routed correctly | 331 | GNUNET_malloc (sizeof (struct redirect_service)); |
317 | */ | 332 | memcpy (serv, state->serv, sizeof (struct redirect_service)); |
318 | struct redirect_service *serv = | 333 | serv->my_port = ntohs (udp->spt); |
319 | GNUNET_malloc (sizeof (struct redirect_service)); | 334 | serv->remote_port = ntohs (udp->spt); |
320 | memcpy (serv, state->serv, sizeof (struct redirect_service)); | 335 | uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); |
321 | serv->my_port = ntohs (udp->spt); | 336 | |
322 | serv->remote_port = ntohs (udp->spt); | 337 | memcpy ((GNUNET_HashCode *) (desc + 1), &state->desc, |
323 | uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); | 338 | sizeof (GNUNET_HashCode)); |
324 | memcpy ((GNUNET_HashCode *) (desc + 1), &state->desc, | 339 | *desc = ntohs (udp->spt); |
325 | sizeof (GNUNET_HashCode)); | 340 | GNUNET_assert (GNUNET_OK == |
326 | *desc = ntohs (udp->spt); | 341 | GNUNET_CONTAINER_multihashmap_put (udp_services, |
327 | GNUNET_assert (GNUNET_OK == | 342 | (GNUNET_HashCode *) |
328 | GNUNET_CONTAINER_multihashmap_put (udp_services, | 343 | desc, serv, |
329 | (GNUNET_HashCode*)desc, serv, | 344 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
330 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 345 | |
331 | 346 | state->serv = serv; | |
332 | state->serv = serv; | ||
333 | } | ||
334 | } | 347 | } |
348 | } | ||
335 | 349 | ||
336 | /* send udp-packet back */ | 350 | /* send udp-packet back */ |
337 | len = | 351 | len = |
338 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + | 352 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + |
339 | ntohs (udp->len); | 353 | ntohs (udp->len); |
340 | struct GNUNET_MESH_Tunnel** ctunnel = GNUNET_malloc (sizeof(struct GNUNET_MESH_TUNNEL*) + len); | 354 | struct GNUNET_MESH_Tunnel **ctunnel = |
355 | GNUNET_malloc (sizeof (struct GNUNET_MESH_TUNNEL *) + len); | ||
341 | *ctunnel = tunnel; | 356 | *ctunnel = tunnel; |
342 | msg = (struct GNUNET_MessageHeader*)(ctunnel + 1); | 357 | msg = (struct GNUNET_MessageHeader *) (ctunnel + 1); |
343 | msg->size = htons (len); | 358 | msg->size = htons (len); |
344 | msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK : GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK); | 359 | msg->type = |
360 | htons (state->type == | ||
361 | SERVICE ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK : | ||
362 | GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK); | ||
345 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); | 363 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); |
364 | |||
346 | if (state->type == SERVICE) | 365 | if (state->type == SERVICE) |
347 | memcpy (desc, &state->desc, sizeof (GNUNET_HashCode)); | 366 | memcpy (desc, &state->desc, sizeof (GNUNET_HashCode)); |
348 | else | 367 | else |
349 | memcpy (desc, &state->remote, sizeof (struct remote_addr)); | 368 | memcpy (desc, &state->remote, sizeof (struct remote_addr)); |
350 | void *_udp = desc + 1; | 369 | void *_udp = desc + 1; |
370 | |||
351 | memcpy (_udp, udp, ntohs (udp->len)); | 371 | memcpy (_udp, udp, ntohs (udp->len)); |
352 | 372 | ||
353 | if (NULL == GNUNET_MESH_tunnel_get_data(tunnel)) | 373 | if (NULL == GNUNET_MESH_tunnel_get_data (tunnel)) |
354 | { | 374 | { |
355 | /* No notify is pending */ | 375 | /* No notify is pending */ |
356 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (tunnel, | 376 | struct GNUNET_MESH_TransmitHandle *th = |
357 | GNUNET_NO, | 377 | GNUNET_MESH_notify_transmit_ready (tunnel, |
358 | 42, | 378 | GNUNET_NO, |
359 | GNUNET_TIME_relative_divide | 379 | 42, |
360 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 380 | GNUNET_TIME_relative_divide |
361 | (const struct GNUNET_PeerIdentity *) | 381 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
362 | NULL, len, | 382 | (const struct GNUNET_PeerIdentity *) |
363 | send_udp_to_peer_notify_callback, ctunnel); | 383 | NULL, len, |
364 | /* save the handle */ | 384 | send_udp_to_peer_notify_callback, |
365 | GNUNET_MESH_tunnel_set_data(tunnel, th); | 385 | ctunnel); |
366 | } | 386 | |
387 | /* save the handle */ | ||
388 | GNUNET_MESH_tunnel_set_data (tunnel, th); | ||
389 | } | ||
367 | else | 390 | else |
368 | { | 391 | { |
369 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(tunnel); | 392 | struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (tunnel); |
370 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(tunnel); | 393 | struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (tunnel); |
371 | 394 | ||
372 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | 395 | struct tunnel_notify_queue *element = |
373 | element->cls = ctunnel; | 396 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); |
374 | element->len = len; | 397 | element->cls = ctunnel; |
375 | 398 | element->len = len; | |
376 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | 399 | |
377 | GNUNET_MESH_tunnel_set_head(tunnel, head); | 400 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); |
378 | GNUNET_MESH_tunnel_set_tail(tunnel, tail); | 401 | GNUNET_MESH_tunnel_set_head (tunnel, head); |
379 | } | 402 | GNUNET_MESH_tunnel_set_tail (tunnel, tail); |
403 | } | ||
380 | } | 404 | } |
381 | 405 | ||
382 | /** | 406 | /** |
@@ -404,16 +428,19 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
404 | 428 | ||
405 | /* get tunnel and service-descriptor from this */ | 429 | /* get tunnel and service-descriptor from this */ |
406 | GNUNET_HashCode hash; | 430 | GNUNET_HashCode hash; |
407 | hash_redirect_info(&hash, &u_i, addrlen); | 431 | |
432 | hash_redirect_info (&hash, &u_i, addrlen); | ||
408 | 433 | ||
409 | struct redirect_state *state = | 434 | struct redirect_state *state = |
410 | GNUNET_CONTAINER_multihashmap_get (tcp_connections, &hash); | 435 | GNUNET_CONTAINER_multihashmap_get (tcp_connections, &hash); |
411 | 436 | ||
412 | if (state == NULL) | 437 | if (state == NULL) |
413 | { | 438 | { |
414 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "No mapping for this connection; hash is %x\n", *((uint32_t*)&hash)); | 439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
415 | return; | 440 | "No mapping for this connection; hash is %x\n", |
416 | } | 441 | *((uint32_t *) & hash)); |
442 | return; | ||
443 | } | ||
417 | 444 | ||
418 | /* Mark this connection as freshly used */ | 445 | /* Mark this connection as freshly used */ |
419 | GNUNET_CONTAINER_heap_update_cost (tcp_connections_heap, state->heap_node, | 446 | GNUNET_CONTAINER_heap_update_cost (tcp_connections_heap, state->heap_node, |
@@ -422,61 +449,72 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
422 | tunnel = state->tunnel; | 449 | tunnel = state->tunnel; |
423 | 450 | ||
424 | if (state->type == SERVICE) | 451 | if (state->type == SERVICE) |
452 | { | ||
453 | /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */ | ||
454 | if (ntohs (tcp->spt) == state->serv->remote_port) | ||
425 | { | 455 | { |
426 | /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */ | 456 | tcp->spt = htons (state->serv->my_port); |
427 | if (ntohs (tcp->spt) == state->serv->remote_port) | 457 | } |
428 | { | 458 | else |
429 | tcp->spt = htons (state->serv->my_port); | 459 | { |
430 | } | 460 | // This is an illegal packet. |
431 | else | 461 | return; |
432 | { | ||
433 | // This is an illegal packet. | ||
434 | return; | ||
435 | } | ||
436 | } | 462 | } |
463 | } | ||
437 | 464 | ||
438 | /* send tcp-packet back */ | 465 | /* send tcp-packet back */ |
439 | len = | 466 | len = |
440 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen; | 467 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen; |
441 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen); | 468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen); |
442 | struct GNUNET_MESH_Tunnel** ctunnel = GNUNET_malloc (sizeof(struct GNUNET_MESH_TUNNEL*) + len); | 469 | struct GNUNET_MESH_Tunnel **ctunnel = |
470 | GNUNET_malloc (sizeof (struct GNUNET_MESH_TUNNEL *) + len); | ||
443 | *ctunnel = tunnel; | 471 | *ctunnel = tunnel; |
444 | msg = (struct GNUNET_MessageHeader*)(ctunnel + 1); | 472 | msg = (struct GNUNET_MessageHeader *) (ctunnel + 1); |
445 | msg->size = htons (len); | 473 | msg->size = htons (len); |
446 | msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK : GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK); | 474 | msg->type = |
475 | htons (state->type == | ||
476 | SERVICE ? GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK : | ||
477 | GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP_BACK); | ||
447 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); | 478 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); |
479 | |||
448 | if (state->type == SERVICE) | 480 | if (state->type == SERVICE) |
449 | memcpy (desc, &state->desc, sizeof (GNUNET_HashCode)); | 481 | memcpy (desc, &state->desc, sizeof (GNUNET_HashCode)); |
450 | else | 482 | else |
451 | memcpy (desc, &state->remote, sizeof (struct remote_addr)); | 483 | memcpy (desc, &state->remote, sizeof (struct remote_addr)); |
452 | void *_tcp = desc + 1; | 484 | void *_tcp = desc + 1; |
485 | |||
453 | memcpy (_tcp, tcp, pktlen); | 486 | memcpy (_tcp, tcp, pktlen); |
454 | 487 | ||
455 | if (NULL == GNUNET_MESH_tunnel_get_data(tunnel)) | 488 | if (NULL == GNUNET_MESH_tunnel_get_data (tunnel)) |
456 | { | 489 | { |
457 | /* No notify is pending */ | 490 | /* No notify is pending */ |
458 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (tunnel, | 491 | struct GNUNET_MESH_TransmitHandle *th = |
459 | GNUNET_NO, | 492 | GNUNET_MESH_notify_transmit_ready (tunnel, |
460 | 42, | 493 | GNUNET_NO, |
461 | GNUNET_TIME_relative_divide | 494 | 42, |
462 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 495 | GNUNET_TIME_relative_divide |
463 | (const struct GNUNET_PeerIdentity *)NULL, | 496 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
464 | len, send_udp_to_peer_notify_callback, | 497 | (const struct GNUNET_PeerIdentity *) |
465 | ctunnel); | 498 | NULL, |
466 | /* save the handle */ | 499 | len, |
467 | GNUNET_MESH_tunnel_set_data(tunnel, th); | 500 | send_udp_to_peer_notify_callback, |
468 | } | 501 | ctunnel); |
502 | |||
503 | /* save the handle */ | ||
504 | GNUNET_MESH_tunnel_set_data (tunnel, th); | ||
505 | } | ||
469 | else | 506 | else |
470 | { | 507 | { |
471 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(tunnel); | 508 | struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (tunnel); |
472 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(tunnel); | 509 | struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (tunnel); |
473 | 510 | ||
474 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | 511 | struct tunnel_notify_queue *element = |
475 | element->cls = ctunnel; | 512 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); |
476 | element->len = len; | 513 | element->cls = ctunnel; |
514 | element->len = len; | ||
477 | 515 | ||
478 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | 516 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); |
479 | } | 517 | } |
480 | } | 518 | } |
481 | 519 | ||
482 | 520 | ||
@@ -484,8 +522,10 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
484 | * Receive packets from the helper-process | 522 | * Receive packets from the helper-process |
485 | */ | 523 | */ |
486 | static void | 524 | static void |
487 | message_token (void *cls __attribute__((unused)), | 525 | message_token (void *cls __attribute__ ((unused)), |
488 | void *client __attribute__((unused)), const struct GNUNET_MessageHeader *message) | 526 | void *client |
527 | __attribute__ ((unused)), | ||
528 | const struct GNUNET_MessageHeader *message) | ||
489 | { | 529 | { |
490 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_HELPER); | 530 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_HELPER); |
491 | 531 | ||
@@ -493,37 +533,40 @@ message_token (void *cls __attribute__((unused)), | |||
493 | 533 | ||
494 | /* ethertype is ipv6 */ | 534 | /* ethertype is ipv6 */ |
495 | if (ntohs (pkt_tun->tun.type) == 0x86dd) | 535 | if (ntohs (pkt_tun->tun.type) == 0x86dd) |
496 | { | 536 | { |
497 | struct ip6_pkt *pkt6 = (struct ip6_pkt *) pkt_tun; | 537 | struct ip6_pkt *pkt6 = (struct ip6_pkt *) pkt_tun; |
498 | if (0x11 == pkt6->ip6_hdr.nxthdr) | 538 | |
499 | udp_from_helper (&((struct ip6_udp *) pkt6)->udp_hdr, | 539 | if (0x11 == pkt6->ip6_hdr.nxthdr) |
500 | (unsigned char *) &pkt6->ip6_hdr.dadr, 16); | 540 | udp_from_helper (&((struct ip6_udp *) pkt6)->udp_hdr, |
501 | else if (0x06 == pkt6->ip6_hdr.nxthdr) | 541 | (unsigned char *) &pkt6->ip6_hdr.dadr, 16); |
502 | tcp_from_helper (&((struct ip6_tcp *) pkt6)->tcp_hdr, | 542 | else if (0x06 == pkt6->ip6_hdr.nxthdr) |
503 | (unsigned char *) &pkt6->ip6_hdr.dadr, 16, | 543 | tcp_from_helper (&((struct ip6_tcp *) pkt6)->tcp_hdr, |
504 | ntohs (pkt6->ip6_hdr.paylgth)); | 544 | (unsigned char *) &pkt6->ip6_hdr.dadr, 16, |
505 | } | 545 | ntohs (pkt6->ip6_hdr.paylgth)); |
546 | } | ||
506 | else if (ntohs (pkt_tun->tun.type) == 0x0800) | 547 | else if (ntohs (pkt_tun->tun.type) == 0x0800) |
548 | { | ||
549 | struct ip_pkt *pkt4 = (struct ip_pkt *) pkt_tun; | ||
550 | uint32_t tmp = pkt4->ip_hdr.dadr; | ||
551 | |||
552 | if (0x11 == pkt4->ip_hdr.proto) | ||
553 | udp_from_helper (&((struct ip_udp *) pkt4)->udp_hdr, | ||
554 | (unsigned char *) &tmp, 4); | ||
555 | else if (0x06 == pkt4->ip_hdr.proto) | ||
507 | { | 556 | { |
508 | struct ip_pkt *pkt4 = (struct ip_pkt *) pkt_tun; | 557 | size_t pktlen = ntohs (pkt4->ip_hdr.tot_lngth); |
509 | uint32_t tmp = pkt4->ip_hdr.dadr; | 558 | |
510 | if (0x11 == pkt4->ip_hdr.proto) | 559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tot: %d\n", pktlen); |
511 | udp_from_helper (&((struct ip_udp *) pkt4)->udp_hdr, | 560 | pktlen -= 4 * pkt4->ip_hdr.hdr_lngth; |
512 | (unsigned char *) &tmp, 4); | 561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-hdr: %d\n", pktlen); |
513 | else if (0x06 == pkt4->ip_hdr.proto) | 562 | tcp_from_helper (&((struct ip_tcp *) pkt4)->tcp_hdr, |
514 | { | 563 | (unsigned char *) &tmp, 4, pktlen); |
515 | size_t pktlen = ntohs(pkt4->ip_hdr.tot_lngth); | ||
516 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tot: %d\n", pktlen); | ||
517 | pktlen -= 4*pkt4->ip_hdr.hdr_lngth; | ||
518 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "-hdr: %d\n", pktlen); | ||
519 | tcp_from_helper (&((struct ip_tcp *) pkt4)->tcp_hdr, | ||
520 | (unsigned char *) &tmp, 4, pktlen); | ||
521 | } | ||
522 | } | 564 | } |
565 | } | ||
523 | else | 566 | else |
524 | { | 567 | { |
525 | return; | 568 | return; |
526 | } | 569 | } |
527 | } | 570 | } |
528 | 571 | ||
529 | /** | 572 | /** |
@@ -533,18 +576,21 @@ message_token (void *cls __attribute__((unused)), | |||
533 | * @param section name of section in config, equal to hostname | 576 | * @param section name of section in config, equal to hostname |
534 | */ | 577 | */ |
535 | static void | 578 | static void |
536 | read_service_conf (void *cls __attribute__((unused)), const char *section) | 579 | read_service_conf (void *cls __attribute__ ((unused)), const char *section) |
537 | { | 580 | { |
538 | if ((strlen(section) < 8) || (0 != strcmp (".gnunet.", section + (strlen(section) - 8)))) | 581 | if ((strlen (section) < 8) || |
582 | (0 != strcmp (".gnunet.", section + (strlen (section) - 8)))) | ||
539 | return; | 583 | return; |
540 | 584 | ||
541 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %d %s %s\n", strlen(section), section, section + (strlen(section) - 8)); | 585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing dns-name %d %s %s\n", |
586 | strlen (section), section, section + (strlen (section) - 8)); | ||
542 | 587 | ||
543 | char *cpy; | 588 | char *cpy; |
544 | char *redirect; | 589 | char *redirect; |
545 | char *hostname; | 590 | char *hostname; |
546 | char *hostport; | 591 | char *hostport; |
547 | uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); | 592 | uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); |
593 | |||
548 | GNUNET_CRYPTO_hash (section, strlen (section) + 1, | 594 | GNUNET_CRYPTO_hash (section, strlen (section) + 1, |
549 | (GNUNET_HashCode *) (desc + 1)); | 595 | (GNUNET_HashCode *) (desc + 1)); |
550 | 596 | ||
@@ -554,96 +600,105 @@ read_service_conf (void *cls __attribute__((unused)), const char *section) | |||
554 | int proto = UDP; | 600 | int proto = UDP; |
555 | 601 | ||
556 | do | 602 | do |
603 | { | ||
604 | if (proto == UDP && | ||
605 | (GNUNET_OK != | ||
606 | GNUNET_CONFIGURATION_get_value_string (cfg, section, "UDP_REDIRECTS", | ||
607 | &cpy))) | ||
608 | goto next; | ||
609 | else if (proto == TCP && | ||
610 | (GNUNET_OK != | ||
611 | GNUNET_CONFIGURATION_get_value_string (cfg, section, | ||
612 | "TCP_REDIRECTS", &cpy))) | ||
613 | goto next; | ||
614 | |||
615 | for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok | ||
616 | (NULL, " ")) | ||
557 | { | 617 | { |
558 | if (proto == UDP && (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, section, "UDP_REDIRECTS", &cpy))) | 618 | if (NULL == (hostname = strstr (redirect, ":"))) |
559 | goto next; | 619 | { |
560 | else if (proto == TCP && (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, section, "TCP_REDIRECTS", &cpy))) | 620 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
561 | goto next; | 621 | "Warning: option %s is not formatted correctly!\n", |
562 | 622 | redirect); | |
563 | for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok | 623 | continue; |
564 | (NULL, " ")) | 624 | } |
565 | { | 625 | hostname[0] = '\0'; |
566 | if (NULL == (hostname = strstr (redirect, ":"))) | 626 | hostname++; |
567 | { | 627 | if (NULL == (hostport = strstr (hostname, ":"))) |
568 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", | 628 | { |
569 | redirect); | 629 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
570 | continue; | 630 | "Warning: option %s is not formatted correctly!\n", |
571 | } | 631 | redirect); |
572 | hostname[0] = '\0'; | 632 | continue; |
573 | hostname++; | 633 | } |
574 | if (NULL == (hostport = strstr (hostname, ":"))) | 634 | hostport[0] = '\0'; |
575 | { | 635 | hostport++; |
576 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: option %s is not formatted correctly!\n", | 636 | |
577 | redirect); | 637 | int local_port = atoi (redirect); |
578 | continue; | 638 | |
579 | } | 639 | if (!((local_port > 0) && (local_port < 65536))) |
580 | hostport[0] = '\0'; | 640 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
581 | hostport++; | 641 | "Warning: %s is not a correct port.", redirect); |
582 | 642 | ||
583 | int local_port = atoi (redirect); | 643 | *desc = local_port; |
584 | if (!((local_port > 0) && (local_port < 65536))) | 644 | |
585 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Warning: %s is not a correct port.", | 645 | struct redirect_service *serv = |
586 | redirect); | 646 | GNUNET_malloc (sizeof (struct redirect_service)); |
587 | 647 | memset (serv, 0, sizeof (struct redirect_service)); | |
588 | *desc = local_port; | 648 | serv->my_port = local_port; |
589 | 649 | ||
590 | struct redirect_service *serv = | 650 | if (0 == strcmp ("localhost4", hostname)) |
591 | GNUNET_malloc (sizeof (struct redirect_service)); | 651 | { |
592 | memset (serv, 0, sizeof (struct redirect_service)); | 652 | serv->version = 4; |
593 | serv->my_port = local_port; | 653 | |
594 | 654 | char *ip4addr; | |
595 | if (0 == strcmp ("localhost4", hostname)) | 655 | |
596 | { | 656 | GNUNET_assert (GNUNET_OK == |
597 | serv->version = 4; | 657 | GNUNET_CONFIGURATION_get_value_string (cfg, |
598 | 658 | "exit", | |
599 | char *ip4addr; | 659 | "IPV4ADDR", |
600 | GNUNET_assert (GNUNET_OK == | 660 | &ip4addr)); |
601 | GNUNET_CONFIGURATION_get_value_string (cfg, | 661 | GNUNET_assert (1 == inet_pton (AF_INET, ip4addr, serv->v4.ip4address)); |
602 | "exit", | 662 | GNUNET_free (ip4addr); |
603 | "IPV4ADDR", | 663 | } |
604 | &ip4addr)); | 664 | else if (0 == strcmp ("localhost6", hostname)) |
605 | GNUNET_assert (1 == | 665 | { |
606 | inet_pton (AF_INET, ip4addr, | 666 | serv->version = 6; |
607 | serv->v4.ip4address)); | 667 | |
608 | GNUNET_free (ip4addr); | 668 | char *ip6addr; |
609 | } | 669 | |
610 | else if (0 == strcmp ("localhost6", hostname)) | 670 | GNUNET_assert (GNUNET_OK == |
611 | { | 671 | GNUNET_CONFIGURATION_get_value_string (cfg, |
612 | serv->version = 6; | 672 | "exit", |
613 | 673 | "IPV6ADDR", | |
614 | char *ip6addr; | 674 | &ip6addr)); |
615 | GNUNET_assert (GNUNET_OK == | 675 | GNUNET_assert (1 == inet_pton (AF_INET6, ip6addr, serv->v6.ip6address)); |
616 | GNUNET_CONFIGURATION_get_value_string (cfg, | 676 | GNUNET_free (ip6addr); |
617 | "exit", | 677 | } |
618 | "IPV6ADDR", | 678 | else |
619 | &ip6addr)); | 679 | { |
620 | GNUNET_assert (1 == | 680 | // TODO Lookup, yadayadayada |
621 | inet_pton (AF_INET6, ip6addr, | 681 | GNUNET_assert (0); |
622 | serv->v6.ip6address)); | 682 | } |
623 | GNUNET_free (ip6addr); | 683 | serv->remote_port = atoi (hostport); |
624 | } | 684 | if (UDP == proto) |
625 | else | 685 | GNUNET_assert (GNUNET_OK == |
626 | { | 686 | GNUNET_CONTAINER_multihashmap_put (udp_services, |
627 | // TODO Lookup, yadayadayada | 687 | (GNUNET_HashCode *) |
628 | GNUNET_assert (0); | 688 | desc, serv, |
629 | } | 689 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
630 | serv->remote_port = atoi (hostport); | 690 | else |
631 | if (UDP == proto) | 691 | GNUNET_assert (GNUNET_OK == |
632 | GNUNET_assert (GNUNET_OK == | 692 | GNUNET_CONTAINER_multihashmap_put (tcp_services, |
633 | GNUNET_CONTAINER_multihashmap_put (udp_services, | 693 | (GNUNET_HashCode *) |
634 | (GNUNET_HashCode*)desc, serv, | 694 | desc, serv, |
635 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 695 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
636 | else | 696 | |
637 | GNUNET_assert (GNUNET_OK == | ||
638 | GNUNET_CONTAINER_multihashmap_put (tcp_services, | ||
639 | (GNUNET_HashCode*)desc, serv, | ||
640 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
641 | |||
642 | } | ||
643 | GNUNET_free (cpy); | ||
644 | next: | ||
645 | proto = (proto == UDP) ? TCP : UDP; | ||
646 | } | 697 | } |
698 | GNUNET_free (cpy); | ||
699 | next: | ||
700 | proto = (proto == UDP) ? TCP : UDP; | ||
701 | } | ||
647 | while (proto != UDP); | 702 | while (proto != UDP); |
648 | } | 703 | } |
649 | 704 | ||
@@ -654,71 +709,84 @@ next: | |||
654 | * helper. cls is then taken as handle to the old helper and is cleaned up. | 709 | * helper. cls is then taken as handle to the old helper and is cleaned up. |
655 | */ | 710 | */ |
656 | static void | 711 | static void |
657 | start_helper_and_schedule(void *cls, | 712 | start_helper_and_schedule (void *cls, |
658 | const struct GNUNET_SCHEDULER_TaskContext *tc) { | 713 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
659 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 714 | { |
660 | return; | 715 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
661 | 716 | return; | |
662 | if (cls != NULL) | ||
663 | cleanup_helper(cls); | ||
664 | cls = NULL; | ||
665 | |||
666 | char* ifname; | ||
667 | char* ipv6addr; | ||
668 | char* ipv6prefix; | ||
669 | char* ipv4addr; | ||
670 | char* ipv4mask; | ||
671 | |||
672 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IFNAME", &ifname)) | ||
673 | { | ||
674 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IFNAME' in configuration!\n"); | ||
675 | exit(1); | ||
676 | } | ||
677 | |||
678 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV6ADDR", &ipv6addr)) | ||
679 | { | ||
680 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6ADDR' in configuration!\n"); | ||
681 | exit(1); | ||
682 | } | ||
683 | 717 | ||
684 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV6PREFIX", &ipv6prefix)) | 718 | if (cls != NULL) |
685 | { | 719 | cleanup_helper (cls); |
686 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV6PREFIX' in configuration!\n"); | 720 | cls = NULL; |
687 | exit(1); | ||
688 | } | ||
689 | 721 | ||
690 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4ADDR", &ipv4addr)) | 722 | char *ifname; |
691 | { | 723 | char *ipv6addr; |
692 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4ADDR' in configuration!\n"); | 724 | char *ipv6prefix; |
693 | exit(1); | 725 | char *ipv4addr; |
694 | } | 726 | char *ipv4mask; |
695 | 727 | ||
696 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "exit", "IPV4MASK", &ipv4mask)) | 728 | if (GNUNET_SYSERR == |
697 | { | 729 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IFNAME", &ifname)) |
698 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No entry 'IPV4MASK' in configuration!\n"); | 730 | { |
699 | exit(1); | 731 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
700 | } | 732 | "No entry 'IFNAME' in configuration!\n"); |
733 | exit (1); | ||
734 | } | ||
735 | |||
736 | if (GNUNET_SYSERR == | ||
737 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV6ADDR", | ||
738 | &ipv6addr)) | ||
739 | { | ||
740 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
741 | "No entry 'IPV6ADDR' in configuration!\n"); | ||
742 | exit (1); | ||
743 | } | ||
744 | |||
745 | if (GNUNET_SYSERR == | ||
746 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV6PREFIX", | ||
747 | &ipv6prefix)) | ||
748 | { | ||
749 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
750 | "No entry 'IPV6PREFIX' in configuration!\n"); | ||
751 | exit (1); | ||
752 | } | ||
753 | |||
754 | if (GNUNET_SYSERR == | ||
755 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4ADDR", | ||
756 | &ipv4addr)) | ||
757 | { | ||
758 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
759 | "No entry 'IPV4ADDR' in configuration!\n"); | ||
760 | exit (1); | ||
761 | } | ||
762 | |||
763 | if (GNUNET_SYSERR == | ||
764 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4MASK", | ||
765 | &ipv4mask)) | ||
766 | { | ||
767 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
768 | "No entry 'IPV4MASK' in configuration!\n"); | ||
769 | exit (1); | ||
770 | } | ||
771 | |||
772 | /* Start the helper | ||
773 | * Messages get passed to the function message_token | ||
774 | * When the helper dies, this function will be called again with the | ||
775 | * helper_handle as cls. | ||
776 | */ | ||
777 | helper_handle = start_helper (ifname, | ||
778 | ipv6addr, | ||
779 | ipv6prefix, | ||
780 | ipv4addr, | ||
781 | ipv4mask, | ||
782 | "exit-gnunet", | ||
783 | start_helper_and_schedule, message_token, NULL); | ||
701 | 784 | ||
702 | /* Start the helper | 785 | GNUNET_free (ipv6addr); |
703 | * Messages get passed to the function message_token | 786 | GNUNET_free (ipv6prefix); |
704 | * When the helper dies, this function will be called again with the | 787 | GNUNET_free (ipv4addr); |
705 | * helper_handle as cls. | 788 | GNUNET_free (ipv4mask); |
706 | */ | 789 | GNUNET_free (ifname); |
707 | helper_handle = start_helper(ifname, | ||
708 | ipv6addr, | ||
709 | ipv6prefix, | ||
710 | ipv4addr, | ||
711 | ipv4mask, | ||
712 | "exit-gnunet", | ||
713 | start_helper_and_schedule, | ||
714 | message_token, | ||
715 | NULL); | ||
716 | |||
717 | GNUNET_free(ipv6addr); | ||
718 | GNUNET_free(ipv6prefix); | ||
719 | GNUNET_free(ipv4addr); | ||
720 | GNUNET_free(ipv4mask); | ||
721 | GNUNET_free(ifname); | ||
722 | } | 790 | } |
723 | 791 | ||
724 | static void | 792 | static void |
@@ -752,14 +820,13 @@ prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload, | |||
752 | /* Generate a new src-address */ | 820 | /* Generate a new src-address */ |
753 | char *ipv4addr; | 821 | char *ipv4addr; |
754 | char *ipv4mask; | 822 | char *ipv4mask; |
823 | |||
755 | GNUNET_assert (GNUNET_OK == | 824 | GNUNET_assert (GNUNET_OK == |
756 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", | 825 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", |
757 | "IPV4ADDR", | 826 | "IPV4ADDR", &ipv4addr)); |
758 | &ipv4addr)); | ||
759 | GNUNET_assert (GNUNET_OK == | 827 | GNUNET_assert (GNUNET_OK == |
760 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", | 828 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", |
761 | "IPV4MASK", | 829 | "IPV4MASK", &ipv4mask)); |
762 | &ipv4mask)); | ||
763 | inet_pton (AF_INET, ipv4addr, &tmp); | 830 | inet_pton (AF_INET, ipv4addr, &tmp); |
764 | inet_pton (AF_INET, ipv4mask, &tmp2); | 831 | inet_pton (AF_INET, ipv4mask, &tmp2); |
765 | GNUNET_free (ipv4addr); | 832 | GNUNET_free (ipv4addr); |
@@ -774,41 +841,44 @@ prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload, | |||
774 | 841 | ||
775 | memcpy (&state->redirect_info.addr, &tmp, 4); | 842 | memcpy (&state->redirect_info.addr, &tmp, 4); |
776 | if (0x11 == protocol) | 843 | if (0x11 == protocol) |
777 | { | 844 | { |
778 | struct ip_udp* pkt4_udp = (struct ip_udp*)pkt4; | 845 | struct ip_udp *pkt4_udp = (struct ip_udp *) pkt4; |
779 | state->redirect_info.pt = pkt4_udp->udp_hdr.spt; | ||
780 | 846 | ||
781 | pkt4_udp->udp_hdr.crc = 0; /* Optional for IPv4 */ | 847 | state->redirect_info.pt = pkt4_udp->udp_hdr.spt; |
782 | } | 848 | |
849 | pkt4_udp->udp_hdr.crc = 0; /* Optional for IPv4 */ | ||
850 | } | ||
783 | else if (0x06 == protocol) | 851 | else if (0x06 == protocol) |
784 | { | 852 | { |
785 | struct ip_tcp* pkt4_tcp = (struct ip_tcp*)pkt4; | 853 | struct ip_tcp *pkt4_tcp = (struct ip_tcp *) pkt4; |
786 | state->redirect_info.pt = pkt4_tcp->tcp_hdr.spt; | ||
787 | 854 | ||
788 | pkt4_tcp->tcp_hdr.crc = 0; | 855 | state->redirect_info.pt = pkt4_tcp->tcp_hdr.spt; |
789 | uint32_t sum = 0; | ||
790 | tmp = pkt4->ip_hdr.sadr; | ||
791 | sum = | ||
792 | calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
793 | tmp = pkt4->ip_hdr.dadr; | ||
794 | sum = | ||
795 | calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
796 | 856 | ||
797 | tmp = (protocol << 16) | (0xffff & pktlen); | 857 | pkt4_tcp->tcp_hdr.crc = 0; |
858 | uint32_t sum = 0; | ||
798 | 859 | ||
799 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "line: %08x, %x \n", tmp, (0xffff & pktlen)); | 860 | tmp = pkt4->ip_hdr.sadr; |
861 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
862 | tmp = pkt4->ip_hdr.dadr; | ||
863 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
800 | 864 | ||
801 | tmp = htonl(tmp); | 865 | tmp = (protocol << 16) | (0xffff & pktlen); |
802 | 866 | ||
803 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "line: %08x, %x \n", tmp, |
868 | (0xffff & pktlen)); | ||
804 | 869 | ||
805 | sum = | 870 | tmp = htonl (tmp); |
806 | calculate_checksum_update (sum, (uint16_t *) & pkt4_tcp->tcp_hdr, pktlen); | 871 | |
807 | pkt4_tcp->tcp_hdr.crc = calculate_checksum_end (sum); | 872 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); |
808 | } | 873 | |
874 | sum = | ||
875 | calculate_checksum_update (sum, (uint16_t *) & pkt4_tcp->tcp_hdr, | ||
876 | pktlen); | ||
877 | pkt4_tcp->tcp_hdr.crc = calculate_checksum_end (sum); | ||
878 | } | ||
809 | 879 | ||
810 | pkt4->ip_hdr.chks = | 880 | pkt4->ip_hdr.chks = |
811 | calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4); | 881 | calculate_ip_checksum ((uint16_t *) & pkt4->ip_hdr, 5 * 4); |
812 | } | 882 | } |
813 | 883 | ||
814 | static void | 884 | static void |
@@ -838,10 +908,10 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload, | |||
838 | * the host-mask*/ | 908 | * the host-mask*/ |
839 | char *ipv6addr; | 909 | char *ipv6addr; |
840 | unsigned long long ipv6prefix; | 910 | unsigned long long ipv6prefix; |
911 | |||
841 | GNUNET_assert (GNUNET_OK == | 912 | GNUNET_assert (GNUNET_OK == |
842 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", | 913 | GNUNET_CONFIGURATION_get_value_string (cfg, "exit", |
843 | "IPV6ADDR", | 914 | "IPV6ADDR", &ipv6addr)); |
844 | &ipv6addr)); | ||
845 | GNUNET_assert (GNUNET_OK == | 915 | GNUNET_assert (GNUNET_OK == |
846 | GNUNET_CONFIGURATION_get_value_number (cfg, "exit", | 916 | GNUNET_CONFIGURATION_get_value_number (cfg, "exit", |
847 | "IPV6PREFIX", | 917 | "IPV6PREFIX", |
@@ -856,6 +926,7 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload, | |||
856 | ipv6prefix = 16 - sizeof (void *); | 926 | ipv6prefix = 16 - sizeof (void *); |
857 | 927 | ||
858 | unsigned int offset = ipv6prefix - (16 - sizeof (void *)); | 928 | unsigned int offset = ipv6prefix - (16 - sizeof (void *)); |
929 | |||
859 | memcpy ((((char *) &pkt6->ip6_hdr.sadr)) + ipv6prefix, | 930 | memcpy ((((char *) &pkt6->ip6_hdr.sadr)) + ipv6prefix, |
860 | ((char *) &tunnel) + offset, 16 - ipv6prefix); | 931 | ((char *) &tunnel) + offset, 16 - ipv6prefix); |
861 | 932 | ||
@@ -863,66 +934,74 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload, | |||
863 | memcpy (&state->redirect_info.addr, &pkt6->ip6_hdr.sadr, 16); | 934 | memcpy (&state->redirect_info.addr, &pkt6->ip6_hdr.sadr, 16); |
864 | 935 | ||
865 | if (0x11 == protocol) | 936 | if (0x11 == protocol) |
866 | { | 937 | { |
867 | struct ip6_udp* pkt6_udp = (struct ip6_udp*)pkt6; | 938 | struct ip6_udp *pkt6_udp = (struct ip6_udp *) pkt6; |
868 | state->redirect_info.pt = pkt6_udp->udp_hdr.spt; | 939 | |
869 | 940 | state->redirect_info.pt = pkt6_udp->udp_hdr.spt; | |
870 | pkt6_udp->udp_hdr.crc = 0; | 941 | |
871 | uint32_t sum = 0; | 942 | pkt6_udp->udp_hdr.crc = 0; |
872 | sum = | 943 | uint32_t sum = 0; |
873 | calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.sadr, 16); | 944 | |
874 | sum = | 945 | sum = |
875 | calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.dadr, 16); | 946 | calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.sadr, |
876 | tmp = (htons (pktlen) & 0xffff); | 947 | 16); |
877 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 948 | sum = |
878 | tmp = htons (((pkt6_udp->ip6_hdr.nxthdr & 0x00ff))); | 949 | calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->ip6_hdr.dadr, |
879 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 950 | 16); |
880 | 951 | tmp = (htons (pktlen) & 0xffff); | |
881 | sum = | 952 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); |
953 | tmp = htons (((pkt6_udp->ip6_hdr.nxthdr & 0x00ff))); | ||
954 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
955 | |||
956 | sum = | ||
882 | calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->udp_hdr, | 957 | calculate_checksum_update (sum, (uint16_t *) & pkt6_udp->udp_hdr, |
883 | ntohs (pkt6_udp->udp_hdr.len)); | 958 | ntohs (pkt6_udp->udp_hdr.len)); |
884 | pkt6_udp->udp_hdr.crc = calculate_checksum_end (sum); | 959 | pkt6_udp->udp_hdr.crc = calculate_checksum_end (sum); |
885 | } | 960 | } |
886 | else if (0x06 == protocol) | 961 | else if (0x06 == protocol) |
887 | { | 962 | { |
888 | struct ip6_tcp* pkt6_tcp = (struct ip6_tcp*)pkt6; | 963 | struct ip6_tcp *pkt6_tcp = (struct ip6_tcp *) pkt6; |
889 | state->redirect_info.pt = pkt6_tcp->tcp_hdr.spt; | 964 | |
965 | state->redirect_info.pt = pkt6_tcp->tcp_hdr.spt; | ||
966 | |||
967 | pkt6_tcp->tcp_hdr.crc = 0; | ||
968 | uint32_t sum = 0; | ||
890 | 969 | ||
891 | pkt6_tcp->tcp_hdr.crc = 0; | 970 | sum = |
892 | uint32_t sum = 0; | ||
893 | sum = | ||
894 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16); | 971 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.sadr, 16); |
895 | sum = | 972 | sum = |
896 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16); | 973 | calculate_checksum_update (sum, (uint16_t *) & pkt6->ip6_hdr.dadr, 16); |
897 | tmp = htonl(pktlen); | 974 | tmp = htonl (pktlen); |
898 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 975 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); |
899 | tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff))); | 976 | tmp = htonl (((pkt6->ip6_hdr.nxthdr & 0x000000ff))); |
900 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 977 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); |
901 | 978 | ||
902 | sum = | 979 | sum = |
903 | calculate_checksum_update (sum, (uint16_t *) & pkt6_tcp->tcp_hdr, | 980 | calculate_checksum_update (sum, (uint16_t *) & pkt6_tcp->tcp_hdr, |
904 | ntohs (pkt6->ip6_hdr.paylgth)); | 981 | ntohs (pkt6->ip6_hdr.paylgth)); |
905 | pkt6_tcp->tcp_hdr.crc = calculate_checksum_end (sum); | 982 | pkt6_tcp->tcp_hdr.crc = calculate_checksum_end (sum); |
906 | } | 983 | } |
907 | } | 984 | } |
908 | 985 | ||
909 | /** | 986 | /** |
910 | * The messages are one GNUNET_HashCode for the service followed by a struct tcp_pkt | 987 | * The messages are one GNUNET_HashCode for the service followed by a struct tcp_pkt |
911 | */ | 988 | */ |
912 | static int | 989 | static int |
913 | receive_tcp_service (void *cls __attribute__((unused)), | 990 | receive_tcp_service (void *cls __attribute__ ((unused)), |
914 | struct GNUNET_MESH_Tunnel *tunnel, | 991 | struct GNUNET_MESH_Tunnel *tunnel, |
915 | void **tunnel_ctx __attribute__((unused)), | 992 | void **tunnel_ctx __attribute__ ((unused)), |
916 | const struct GNUNET_PeerIdentity *sender __attribute__((unused)), | 993 | const struct GNUNET_PeerIdentity *sender |
994 | __attribute__ ((unused)), | ||
917 | const struct GNUNET_MessageHeader *message, | 995 | const struct GNUNET_MessageHeader *message, |
918 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 996 | const struct GNUNET_TRANSPORT_ATS_Information *atsi |
997 | __attribute__ ((unused))) | ||
919 | { | 998 | { |
920 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n"); | 999 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n"); |
921 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1000 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
922 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); | 1001 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); |
923 | unsigned int pkt_len = ntohs (message->size) - sizeof (struct | 1002 | unsigned int pkt_len = ntohs (message->size) - sizeof (struct |
924 | GNUNET_MessageHeader) | 1003 | GNUNET_MessageHeader) |
925 | - sizeof (GNUNET_HashCode); | 1004 | - sizeof (GNUNET_HashCode); |
926 | 1005 | ||
927 | /** Get the configuration from the services-hashmap. | 1006 | /** Get the configuration from the services-hashmap. |
928 | * | 1007 | * |
@@ -934,13 +1013,15 @@ receive_tcp_service (void *cls __attribute__((unused)), | |||
934 | memcpy (tcp_desc + 1, desc, sizeof (GNUNET_HashCode)); | 1013 | memcpy (tcp_desc + 1, desc, sizeof (GNUNET_HashCode)); |
935 | *tcp_desc = ntohs (pkt->dpt); | 1014 | *tcp_desc = ntohs (pkt->dpt); |
936 | struct redirect_service *serv = | 1015 | struct redirect_service *serv = |
937 | GNUNET_CONTAINER_multihashmap_get (tcp_services, (GNUNET_HashCode*)tcp_desc); | 1016 | GNUNET_CONTAINER_multihashmap_get (tcp_services, |
1017 | (GNUNET_HashCode *) tcp_desc); | ||
1018 | |||
938 | if (NULL == serv) | 1019 | if (NULL == serv) |
939 | { | 1020 | { |
940 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1021 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
941 | "No service found for TCP dpt %d!\n", *tcp_desc); | 1022 | "No service found for TCP dpt %d!\n", *tcp_desc); |
942 | return GNUNET_YES; | 1023 | return GNUNET_YES; |
943 | } | 1024 | } |
944 | 1025 | ||
945 | pkt->dpt = htons (serv->remote_port); | 1026 | pkt->dpt = htons (serv->remote_port); |
946 | 1027 | ||
@@ -955,8 +1036,8 @@ receive_tcp_service (void *cls __attribute__((unused)), | |||
955 | * This will be saved in the hashmap, so that the receiving procedure knows | 1036 | * This will be saved in the hashmap, so that the receiving procedure knows |
956 | * through which tunnel this connection has to be routed. | 1037 | * through which tunnel this connection has to be routed. |
957 | */ | 1038 | */ |
958 | struct redirect_state *state = | 1039 | struct redirect_state *state = GNUNET_malloc (sizeof (struct redirect_state)); |
959 | GNUNET_malloc (sizeof (struct redirect_state)); | 1040 | |
960 | memset (state, 0, sizeof (struct redirect_state)); | 1041 | memset (state, 0, sizeof (struct redirect_state)); |
961 | state->tunnel = tunnel; | 1042 | state->tunnel = tunnel; |
962 | state->serv = serv; | 1043 | state->serv = serv; |
@@ -965,44 +1046,46 @@ receive_tcp_service (void *cls __attribute__((unused)), | |||
965 | memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); | 1046 | memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); |
966 | 1047 | ||
967 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + | 1048 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + |
968 | sizeof (struct ip6_hdr) + pkt_len; | 1049 | sizeof (struct ip6_hdr) + pkt_len; |
969 | buf = alloca (len); | 1050 | buf = alloca (len); |
970 | 1051 | ||
971 | memset (buf, 0, len); | 1052 | memset (buf, 0, len); |
972 | 1053 | ||
973 | switch (serv->version) | 1054 | switch (serv->version) |
974 | { | 1055 | { |
975 | case 4: | 1056 | case 4: |
976 | prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */ | 1057 | prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */ |
977 | &serv->v4.ip4address, | 1058 | &serv->v4.ip4address, |
978 | tunnel, state, (struct ip_pkt *) buf); | 1059 | tunnel, state, (struct ip_pkt *) buf); |
979 | break; | 1060 | break; |
980 | case 6: | 1061 | case 6: |
981 | prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */ | 1062 | prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */ |
982 | &serv->v6.ip6address, | 1063 | &serv->v6.ip6address, |
983 | tunnel, state, (struct ip6_pkt *) buf); | 1064 | tunnel, state, (struct ip6_pkt *) buf); |
984 | 1065 | ||
985 | break; | 1066 | break; |
986 | default: | 1067 | default: |
987 | GNUNET_assert (0); | 1068 | GNUNET_assert (0); |
988 | break; | 1069 | break; |
989 | } | 1070 | } |
990 | 1071 | ||
991 | hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ? 4 : 16); | 1072 | hash_redirect_info (&state->hash, &state->redirect_info, |
1073 | serv->version == 4 ? 4 : 16); | ||
992 | 1074 | ||
993 | if (GNUNET_NO == | 1075 | if (GNUNET_NO == |
994 | GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash)) | 1076 | GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash)) |
995 | { | 1077 | { |
996 | GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state, | 1078 | GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state, |
997 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1079 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
998 | 1080 | ||
999 | state->heap_node = | 1081 | state->heap_node = |
1000 | GNUNET_CONTAINER_heap_insert (tcp_connections_heap, state, | 1082 | GNUNET_CONTAINER_heap_insert (tcp_connections_heap, state, |
1001 | GNUNET_TIME_absolute_get ().abs_value); | 1083 | GNUNET_TIME_absolute_get ().abs_value); |
1002 | 1084 | ||
1003 | if (GNUNET_CONTAINER_heap_get_size(tcp_connections_heap) > max_tcp_connections) | 1085 | if (GNUNET_CONTAINER_heap_get_size (tcp_connections_heap) > |
1004 | GNUNET_SCHEDULER_add_now(collect_connections, tcp_connections_heap); | 1086 | max_tcp_connections) |
1005 | } | 1087 | GNUNET_SCHEDULER_add_now (collect_connections, tcp_connections_heap); |
1088 | } | ||
1006 | else | 1089 | else |
1007 | GNUNET_free (state); | 1090 | GNUNET_free (state); |
1008 | 1091 | ||
@@ -1011,22 +1094,26 @@ receive_tcp_service (void *cls __attribute__((unused)), | |||
1011 | } | 1094 | } |
1012 | 1095 | ||
1013 | static int | 1096 | static int |
1014 | receive_tcp_remote (void *cls __attribute__((unused)), | 1097 | receive_tcp_remote (void *cls __attribute__ ((unused)), |
1015 | struct GNUNET_MESH_Tunnel *tunnel, | 1098 | struct GNUNET_MESH_Tunnel *tunnel, |
1016 | void **tunnel_ctx __attribute__((unused)), | 1099 | void **tunnel_ctx __attribute__ ((unused)), |
1017 | const struct GNUNET_PeerIdentity *sender __attribute__((unused)), | 1100 | const struct GNUNET_PeerIdentity *sender |
1018 | const struct GNUNET_MessageHeader *message, | 1101 | __attribute__ ((unused)), |
1019 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 1102 | const struct GNUNET_MessageHeader *message, |
1103 | const struct GNUNET_TRANSPORT_ATS_Information *atsi | ||
1104 | __attribute__ ((unused))) | ||
1020 | { | 1105 | { |
1021 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1106 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1022 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); | 1107 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); |
1023 | struct remote_addr *s = (struct remote_addr *) desc; | 1108 | struct remote_addr *s = (struct remote_addr *) desc; |
1024 | char *buf; | 1109 | char *buf; |
1025 | size_t len; | 1110 | size_t len; |
1026 | unsigned int pkt_len = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - sizeof (GNUNET_HashCode); | 1111 | unsigned int pkt_len = |
1112 | ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - | ||
1113 | sizeof (GNUNET_HashCode); | ||
1114 | |||
1115 | struct redirect_state *state = GNUNET_malloc (sizeof (struct redirect_state)); | ||
1027 | 1116 | ||
1028 | struct redirect_state *state = | ||
1029 | GNUNET_malloc (sizeof (struct redirect_state)); | ||
1030 | memset (state, 0, sizeof (struct redirect_state)); | 1117 | memset (state, 0, sizeof (struct redirect_state)); |
1031 | state->tunnel = tunnel; | 1118 | state->tunnel = tunnel; |
1032 | state->type = REMOTE; | 1119 | state->type = REMOTE; |
@@ -1034,44 +1121,45 @@ receive_tcp_remote (void *cls __attribute__((unused)), | |||
1034 | memcpy (&state->remote, s, sizeof (struct remote_addr)); | 1121 | memcpy (&state->remote, s, sizeof (struct remote_addr)); |
1035 | 1122 | ||
1036 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + | 1123 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + |
1037 | sizeof (struct ip6_hdr) + pkt_len; | 1124 | sizeof (struct ip6_hdr) + pkt_len; |
1038 | buf = alloca (len); | 1125 | buf = alloca (len); |
1039 | 1126 | ||
1040 | memset (buf, 0, len); | 1127 | memset (buf, 0, len); |
1041 | 1128 | ||
1042 | switch (s->addrlen) | 1129 | switch (s->addrlen) |
1043 | { | 1130 | { |
1044 | case 4: | 1131 | case 4: |
1045 | prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */ | 1132 | prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */ |
1046 | &s->addr, tunnel, state, (struct ip_pkt *) buf); | 1133 | &s->addr, tunnel, state, (struct ip_pkt *) buf); |
1047 | break; | 1134 | break; |
1048 | case 16: | 1135 | case 16: |
1049 | prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */ | 1136 | prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */ |
1050 | &s->addr, tunnel, state, (struct ip6_pkt *) buf); | 1137 | &s->addr, tunnel, state, (struct ip6_pkt *) buf); |
1051 | break; | 1138 | break; |
1052 | default: | 1139 | default: |
1053 | return GNUNET_SYSERR; | 1140 | return GNUNET_SYSERR; |
1054 | break; | 1141 | break; |
1055 | } | 1142 | } |
1056 | 1143 | ||
1057 | hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen); | 1144 | hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen); |
1058 | 1145 | ||
1059 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packet from remote; hash is %x\n", *((uint32_t*)&state->hash)); | 1146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Packet from remote; hash is %x\n", |
1147 | *((uint32_t *) & state->hash)); | ||
1060 | 1148 | ||
1061 | if (GNUNET_NO == | 1149 | if (GNUNET_NO == |
1062 | GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash)) | 1150 | GNUNET_CONTAINER_multihashmap_contains (tcp_connections, &state->hash)) |
1063 | { | 1151 | { |
1064 | GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state, | 1152 | GNUNET_CONTAINER_multihashmap_put (tcp_connections, &state->hash, state, |
1065 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1153 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1066 | 1154 | ||
1067 | state->heap_node = | 1155 | state->heap_node = |
1068 | GNUNET_CONTAINER_heap_insert (tcp_connections_heap, state, | 1156 | GNUNET_CONTAINER_heap_insert (tcp_connections_heap, state, |
1069 | GNUNET_TIME_absolute_get ().abs_value); | 1157 | GNUNET_TIME_absolute_get ().abs_value); |
1070 | 1158 | ||
1071 | if (GNUNET_CONTAINER_heap_get_size (tcp_connections_heap) > | 1159 | if (GNUNET_CONTAINER_heap_get_size (tcp_connections_heap) > |
1072 | max_tcp_connections) | 1160 | max_tcp_connections) |
1073 | GNUNET_SCHEDULER_add_now (collect_connections, tcp_connections_heap); | 1161 | GNUNET_SCHEDULER_add_now (collect_connections, tcp_connections_heap); |
1074 | } | 1162 | } |
1075 | else | 1163 | else |
1076 | GNUNET_free (state); | 1164 | GNUNET_free (state); |
1077 | 1165 | ||
@@ -1081,12 +1169,14 @@ receive_tcp_remote (void *cls __attribute__((unused)), | |||
1081 | } | 1169 | } |
1082 | 1170 | ||
1083 | static int | 1171 | static int |
1084 | receive_udp_remote (void *cls __attribute__((unused)), | 1172 | receive_udp_remote (void *cls __attribute__ ((unused)), |
1085 | struct GNUNET_MESH_Tunnel *tunnel, | 1173 | struct GNUNET_MESH_Tunnel *tunnel, |
1086 | void **tunnel_ctx __attribute__((unused)), | 1174 | void **tunnel_ctx __attribute__ ((unused)), |
1087 | const struct GNUNET_PeerIdentity *sender __attribute__((unused)), | 1175 | const struct GNUNET_PeerIdentity *sender |
1176 | __attribute__ ((unused)), | ||
1088 | const struct GNUNET_MessageHeader *message, | 1177 | const struct GNUNET_MessageHeader *message, |
1089 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 1178 | const struct GNUNET_TRANSPORT_ATS_Information *atsi |
1179 | __attribute__ ((unused))) | ||
1090 | { | 1180 | { |
1091 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1181 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1092 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); | 1182 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); |
@@ -1103,8 +1193,8 @@ receive_udp_remote (void *cls __attribute__((unused)), | |||
1103 | * This will be saved in the hashmap, so that the receiving procedure knows | 1193 | * This will be saved in the hashmap, so that the receiving procedure knows |
1104 | * through which tunnel this connection has to be routed. | 1194 | * through which tunnel this connection has to be routed. |
1105 | */ | 1195 | */ |
1106 | struct redirect_state *state = | 1196 | struct redirect_state *state = GNUNET_malloc (sizeof (struct redirect_state)); |
1107 | GNUNET_malloc (sizeof (struct redirect_state)); | 1197 | |
1108 | memset (state, 0, sizeof (struct redirect_state)); | 1198 | memset (state, 0, sizeof (struct redirect_state)); |
1109 | state->tunnel = tunnel; | 1199 | state->tunnel = tunnel; |
1110 | state->hashmap = udp_connections; | 1200 | state->hashmap = udp_connections; |
@@ -1112,42 +1202,42 @@ receive_udp_remote (void *cls __attribute__((unused)), | |||
1112 | memcpy (&state->remote, s, sizeof (struct remote_addr)); | 1202 | memcpy (&state->remote, s, sizeof (struct remote_addr)); |
1113 | 1203 | ||
1114 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + | 1204 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + |
1115 | sizeof (struct ip6_hdr) + ntohs (pkt->len); | 1205 | sizeof (struct ip6_hdr) + ntohs (pkt->len); |
1116 | buf = alloca (len); | 1206 | buf = alloca (len); |
1117 | 1207 | ||
1118 | memset (buf, 0, len); | 1208 | memset (buf, 0, len); |
1119 | 1209 | ||
1120 | switch (s->addrlen) | 1210 | switch (s->addrlen) |
1121 | { | 1211 | { |
1122 | case 4: | 1212 | case 4: |
1123 | prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ | 1213 | prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ |
1124 | &s->addr, tunnel, state, (struct ip_pkt *) buf); | 1214 | &s->addr, tunnel, state, (struct ip_pkt *) buf); |
1125 | break; | 1215 | break; |
1126 | case 16: | 1216 | case 16: |
1127 | prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ | 1217 | prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ |
1128 | &s->addr, tunnel, state, (struct ip6_pkt *) buf); | 1218 | &s->addr, tunnel, state, (struct ip6_pkt *) buf); |
1129 | break; | 1219 | break; |
1130 | default: | 1220 | default: |
1131 | GNUNET_assert (0); | 1221 | GNUNET_assert (0); |
1132 | break; | 1222 | break; |
1133 | } | 1223 | } |
1134 | 1224 | ||
1135 | hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen); | 1225 | hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen); |
1136 | 1226 | ||
1137 | if (GNUNET_NO == | 1227 | if (GNUNET_NO == |
1138 | GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash)) | 1228 | GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash)) |
1139 | { | 1229 | { |
1140 | GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state, | 1230 | GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state, |
1141 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1231 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1142 | 1232 | ||
1143 | state->heap_node = | 1233 | state->heap_node = |
1144 | GNUNET_CONTAINER_heap_insert (udp_connections_heap, state, | 1234 | GNUNET_CONTAINER_heap_insert (udp_connections_heap, state, |
1145 | GNUNET_TIME_absolute_get ().abs_value); | 1235 | GNUNET_TIME_absolute_get ().abs_value); |
1146 | 1236 | ||
1147 | if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) > | 1237 | if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) > |
1148 | max_udp_connections) | 1238 | max_udp_connections) |
1149 | GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap); | 1239 | GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap); |
1150 | } | 1240 | } |
1151 | else | 1241 | else |
1152 | GNUNET_free (state); | 1242 | GNUNET_free (state); |
1153 | 1243 | ||
@@ -1159,12 +1249,14 @@ receive_udp_remote (void *cls __attribute__((unused)), | |||
1159 | * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt | 1249 | * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt |
1160 | */ | 1250 | */ |
1161 | static int | 1251 | static int |
1162 | receive_udp_service (void *cls __attribute__((unused)), | 1252 | receive_udp_service (void *cls __attribute__ ((unused)), |
1163 | struct GNUNET_MESH_Tunnel *tunnel, | 1253 | struct GNUNET_MESH_Tunnel *tunnel, |
1164 | void **tunnel_ctx __attribute__((unused)), | 1254 | void **tunnel_ctx __attribute__ ((unused)), |
1165 | const struct GNUNET_PeerIdentity *sender __attribute__((unused)), | 1255 | const struct GNUNET_PeerIdentity *sender |
1256 | __attribute__ ((unused)), | ||
1166 | const struct GNUNET_MessageHeader *message, | 1257 | const struct GNUNET_MessageHeader *message, |
1167 | const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) | 1258 | const struct GNUNET_TRANSPORT_ATS_Information *atsi |
1259 | __attribute__ ((unused))) | ||
1168 | { | 1260 | { |
1169 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1261 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1170 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); | 1262 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); |
@@ -1176,16 +1268,19 @@ receive_udp_service (void *cls __attribute__((unused)), | |||
1176 | 1268 | ||
1177 | /* Get the configuration from the hashmap */ | 1269 | /* Get the configuration from the hashmap */ |
1178 | uint16_t *udp_desc = alloca (sizeof (GNUNET_HashCode) + 2); | 1270 | uint16_t *udp_desc = alloca (sizeof (GNUNET_HashCode) + 2); |
1271 | |||
1179 | memcpy (udp_desc + 1, desc, sizeof (GNUNET_HashCode)); | 1272 | memcpy (udp_desc + 1, desc, sizeof (GNUNET_HashCode)); |
1180 | *udp_desc = ntohs (pkt->dpt); | 1273 | *udp_desc = ntohs (pkt->dpt); |
1181 | struct redirect_service *serv = | 1274 | struct redirect_service *serv = |
1182 | GNUNET_CONTAINER_multihashmap_get (udp_services, (GNUNET_HashCode*)udp_desc); | 1275 | GNUNET_CONTAINER_multihashmap_get (udp_services, |
1276 | (GNUNET_HashCode *) udp_desc); | ||
1277 | |||
1183 | if (NULL == serv) | 1278 | if (NULL == serv) |
1184 | { | 1279 | { |
1185 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1280 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1186 | "No service found for UDP dpt %d!\n", *udp_desc); | 1281 | "No service found for UDP dpt %d!\n", *udp_desc); |
1187 | return GNUNET_YES; | 1282 | return GNUNET_YES; |
1188 | } | 1283 | } |
1189 | 1284 | ||
1190 | pkt->dpt = htons (serv->remote_port); | 1285 | pkt->dpt = htons (serv->remote_port); |
1191 | 1286 | ||
@@ -1200,8 +1295,8 @@ receive_udp_service (void *cls __attribute__((unused)), | |||
1200 | * This will be saved in the hashmap, so that the receiving procedure knows | 1295 | * This will be saved in the hashmap, so that the receiving procedure knows |
1201 | * through which tunnel this connection has to be routed. | 1296 | * through which tunnel this connection has to be routed. |
1202 | */ | 1297 | */ |
1203 | struct redirect_state *state = | 1298 | struct redirect_state *state = GNUNET_malloc (sizeof (struct redirect_state)); |
1204 | GNUNET_malloc (sizeof (struct redirect_state)); | 1299 | |
1205 | memset (state, 0, sizeof (struct redirect_state)); | 1300 | memset (state, 0, sizeof (struct redirect_state)); |
1206 | state->tunnel = tunnel; | 1301 | state->tunnel = tunnel; |
1207 | state->serv = serv; | 1302 | state->serv = serv; |
@@ -1210,44 +1305,46 @@ receive_udp_service (void *cls __attribute__((unused)), | |||
1210 | memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); | 1305 | memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); |
1211 | 1306 | ||
1212 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + | 1307 | len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + |
1213 | sizeof (struct ip6_hdr) + ntohs (pkt->len); | 1308 | sizeof (struct ip6_hdr) + ntohs (pkt->len); |
1214 | buf = alloca (len); | 1309 | buf = alloca (len); |
1215 | 1310 | ||
1216 | memset (buf, 0, len); | 1311 | memset (buf, 0, len); |
1217 | 1312 | ||
1218 | switch (serv->version) | 1313 | switch (serv->version) |
1219 | { | 1314 | { |
1220 | case 4: | 1315 | case 4: |
1221 | prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ | 1316 | prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ |
1222 | &serv->v4.ip4address, | 1317 | &serv->v4.ip4address, |
1223 | tunnel, state, (struct ip_pkt *) buf); | 1318 | tunnel, state, (struct ip_pkt *) buf); |
1224 | break; | 1319 | break; |
1225 | case 6: | 1320 | case 6: |
1226 | prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ | 1321 | prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ |
1227 | &serv->v6.ip6address, | 1322 | &serv->v6.ip6address, |
1228 | tunnel, state, (struct ip6_pkt *) buf); | 1323 | tunnel, state, (struct ip6_pkt *) buf); |
1229 | 1324 | ||
1230 | break; | 1325 | break; |
1231 | default: | 1326 | default: |
1232 | GNUNET_assert (0); | 1327 | GNUNET_assert (0); |
1233 | break; | 1328 | break; |
1234 | } | 1329 | } |
1235 | 1330 | ||
1236 | hash_redirect_info(&state->hash, &state->redirect_info, serv->version == 4 ? 4 : 16); | 1331 | hash_redirect_info (&state->hash, &state->redirect_info, |
1332 | serv->version == 4 ? 4 : 16); | ||
1237 | 1333 | ||
1238 | if (GNUNET_NO == | 1334 | if (GNUNET_NO == |
1239 | GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash)) | 1335 | GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash)) |
1240 | { | 1336 | { |
1241 | GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state, | 1337 | GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state, |
1242 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1338 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1243 | 1339 | ||
1244 | state->heap_node = | 1340 | state->heap_node = |
1245 | GNUNET_CONTAINER_heap_insert (udp_connections_heap, state, | 1341 | GNUNET_CONTAINER_heap_insert (udp_connections_heap, state, |
1246 | GNUNET_TIME_absolute_get ().abs_value); | 1342 | GNUNET_TIME_absolute_get ().abs_value); |
1247 | 1343 | ||
1248 | if (GNUNET_CONTAINER_heap_get_size(udp_connections_heap) > max_udp_connections) | 1344 | if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) > |
1249 | GNUNET_SCHEDULER_add_now(collect_connections, udp_connections_heap); | 1345 | max_udp_connections) |
1250 | } | 1346 | GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap); |
1347 | } | ||
1251 | else | 1348 | else |
1252 | GNUNET_free (state); | 1349 | GNUNET_free (state); |
1253 | 1350 | ||
@@ -1256,13 +1353,13 @@ receive_udp_service (void *cls __attribute__((unused)), | |||
1256 | } | 1353 | } |
1257 | 1354 | ||
1258 | static void | 1355 | static void |
1259 | connect_to_mesh() | 1356 | connect_to_mesh () |
1260 | { | 1357 | { |
1261 | int udp, tcp; | 1358 | int udp, tcp; |
1262 | int handler_idx, app_idx; | 1359 | int handler_idx, app_idx; |
1263 | 1360 | ||
1264 | udp = GNUNET_CONFIGURATION_get_value_yesno(cfg, "exit", "ENABLE_UDP"); | 1361 | udp = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_UDP"); |
1265 | tcp = GNUNET_CONFIGURATION_get_value_yesno(cfg, "exit", "ENABLE_TCP"); | 1362 | tcp = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_TCP"); |
1266 | 1363 | ||
1267 | static struct GNUNET_MESH_MessageHandler handlers[] = { | 1364 | static struct GNUNET_MESH_MessageHandler handlers[] = { |
1268 | {receive_udp_service, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0}, | 1365 | {receive_udp_service, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0}, |
@@ -1272,35 +1369,34 @@ connect_to_mesh() | |||
1272 | {NULL, 0, 0} | 1369 | {NULL, 0, 0} |
1273 | }; | 1370 | }; |
1274 | 1371 | ||
1275 | static GNUNET_MESH_ApplicationType apptypes[] = | 1372 | static GNUNET_MESH_ApplicationType apptypes[] = { |
1276 | { | 1373 | GNUNET_APPLICATION_TYPE_END, |
1277 | GNUNET_APPLICATION_TYPE_END, | 1374 | GNUNET_APPLICATION_TYPE_END, |
1278 | GNUNET_APPLICATION_TYPE_END, | 1375 | GNUNET_APPLICATION_TYPE_END |
1279 | GNUNET_APPLICATION_TYPE_END | 1376 | }; |
1280 | }; | ||
1281 | 1377 | ||
1282 | app_idx = 0; | 1378 | app_idx = 0; |
1283 | handler_idx = 2; | 1379 | handler_idx = 2; |
1284 | 1380 | ||
1285 | if (GNUNET_YES == udp) | 1381 | if (GNUNET_YES == udp) |
1286 | { | 1382 | { |
1287 | handlers[handler_idx].callback = receive_udp_remote; | 1383 | handlers[handler_idx].callback = receive_udp_remote; |
1288 | handlers[handler_idx].expected_size = 0; | 1384 | handlers[handler_idx].expected_size = 0; |
1289 | handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP; | 1385 | handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP; |
1290 | apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY; | 1386 | apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY; |
1291 | handler_idx++; | 1387 | handler_idx++; |
1292 | app_idx++; | 1388 | app_idx++; |
1293 | } | 1389 | } |
1294 | 1390 | ||
1295 | if (GNUNET_YES == tcp) | 1391 | if (GNUNET_YES == tcp) |
1296 | { | 1392 | { |
1297 | handlers[handler_idx].callback = receive_tcp_remote; | 1393 | handlers[handler_idx].callback = receive_tcp_remote; |
1298 | handlers[handler_idx].expected_size = 0; | 1394 | handlers[handler_idx].expected_size = 0; |
1299 | handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP; | 1395 | handlers[handler_idx].type = GNUNET_MESSAGE_TYPE_VPN_REMOTE_TCP; |
1300 | apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY; | 1396 | apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_TCP_GATEWAY; |
1301 | handler_idx++; | 1397 | handler_idx++; |
1302 | app_idx++; | 1398 | app_idx++; |
1303 | } | 1399 | } |
1304 | 1400 | ||
1305 | mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, apptypes); | 1401 | mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, apptypes); |
1306 | } | 1402 | } |
@@ -1315,19 +1411,20 @@ connect_to_mesh() | |||
1315 | */ | 1411 | */ |
1316 | static void | 1412 | static void |
1317 | run (void *cls, | 1413 | run (void *cls, |
1318 | char *const *args __attribute__((unused)), | 1414 | char *const *args __attribute__ ((unused)), |
1319 | const char *cfgfile __attribute__((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_) | 1415 | const char *cfgfile |
1416 | __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_) | ||
1320 | { | 1417 | { |
1321 | cfg = cfg_; | 1418 | cfg = cfg_; |
1322 | 1419 | ||
1323 | connect_to_mesh(); | 1420 | connect_to_mesh (); |
1324 | 1421 | ||
1325 | udp_connections = GNUNET_CONTAINER_multihashmap_create (65536); | 1422 | udp_connections = GNUNET_CONTAINER_multihashmap_create (65536); |
1326 | udp_connections_heap = | 1423 | udp_connections_heap = |
1327 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1424 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1328 | tcp_connections = GNUNET_CONTAINER_multihashmap_create (65536); | 1425 | tcp_connections = GNUNET_CONTAINER_multihashmap_create (65536); |
1329 | tcp_connections_heap = | 1426 | tcp_connections_heap = |
1330 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1427 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
1331 | udp_services = GNUNET_CONTAINER_multihashmap_create (65536); | 1428 | udp_services = GNUNET_CONTAINER_multihashmap_create (65536); |
1332 | tcp_services = GNUNET_CONTAINER_multihashmap_create (65536); | 1429 | tcp_services = GNUNET_CONTAINER_multihashmap_create (65536); |
1333 | 1430 | ||
@@ -1350,18 +1447,18 @@ run (void *cls, | |||
1350 | * @return 0 ok, 1 on error | 1447 | * @return 0 ok, 1 on error |
1351 | */ | 1448 | */ |
1352 | int | 1449 | int |
1353 | main (int argc, char *const *argv) { | 1450 | main (int argc, char *const *argv) |
1354 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 1451 | { |
1355 | GNUNET_GETOPT_OPTION_END | 1452 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
1356 | }; | 1453 | GNUNET_GETOPT_OPTION_END |
1357 | 1454 | }; | |
1358 | return (GNUNET_OK == | 1455 | |
1359 | GNUNET_PROGRAM_run (argc, | 1456 | return (GNUNET_OK == |
1360 | argv, | 1457 | GNUNET_PROGRAM_run (argc, |
1361 | "exit", | 1458 | argv, |
1362 | gettext_noop ("help text"), | 1459 | "exit", |
1363 | options, &run, NULL)) ? ret : 1; | 1460 | gettext_noop ("help text"), |
1461 | options, &run, NULL)) ? ret : 1; | ||
1364 | } | 1462 | } |
1365 | 1463 | ||
1366 | /* end of gnunet-daemon-exit.c */ | 1464 | /* end of gnunet-daemon-exit.c */ |
1367 | |||