diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/vpn/gnunet-service-vpn.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/vpn/gnunet-service-vpn.c')
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 3594 |
1 files changed, 1802 insertions, 1792 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 4c042ea80..a716a770d 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -65,7 +65,8 @@ struct DestinationEntry; | |||
65 | * List of channels we keep for each destination port for a given | 65 | * List of channels we keep for each destination port for a given |
66 | * destination entry. | 66 | * destination entry. |
67 | */ | 67 | */ |
68 | struct DestinationChannel { | 68 | struct DestinationChannel |
69 | { | ||
69 | /** | 70 | /** |
70 | * Kept in a DLL. | 71 | * Kept in a DLL. |
71 | */ | 72 | */ |
@@ -92,7 +93,8 @@ struct DestinationChannel { | |||
92 | * Information we track for each IP address to determine which channel | 93 | * Information we track for each IP address to determine which channel |
93 | * to send the traffic over to the destination. | 94 | * to send the traffic over to the destination. |
94 | */ | 95 | */ |
95 | struct DestinationEntry { | 96 | struct DestinationEntry |
97 | { | ||
96 | /** | 98 | /** |
97 | * Key under which this entry is in the 'destination_map' (only valid | 99 | * Key under which this entry is in the 'destination_map' (only valid |
98 | * if 'heap_node != NULL'). | 100 | * if 'heap_node != NULL'). |
@@ -123,8 +125,10 @@ struct DestinationEntry { | |||
123 | /** | 125 | /** |
124 | * Details about the connection (depending on is_service). | 126 | * Details about the connection (depending on is_service). |
125 | */ | 127 | */ |
126 | union { | 128 | union |
127 | struct { | 129 | { |
130 | struct | ||
131 | { | ||
128 | /** | 132 | /** |
129 | * The description of the service (only used for service channels). | 133 | * The description of the service (only used for service channels). |
130 | */ | 134 | */ |
@@ -136,7 +140,8 @@ struct DestinationEntry { | |||
136 | struct GNUNET_PeerIdentity target; | 140 | struct GNUNET_PeerIdentity target; |
137 | } service_destination; | 141 | } service_destination; |
138 | 142 | ||
139 | struct { | 143 | struct |
144 | { | ||
140 | /** | 145 | /** |
141 | * Address family used (AF_INET or AF_INET6). | 146 | * Address family used (AF_INET or AF_INET6). |
142 | */ | 147 | */ |
@@ -145,7 +150,8 @@ struct DestinationEntry { | |||
145 | /** | 150 | /** |
146 | * IP address of the ultimate destination (only used for exit channels). | 151 | * IP address of the ultimate destination (only used for exit channels). |
147 | */ | 152 | */ |
148 | union { | 153 | union |
154 | { | ||
149 | /** | 155 | /** |
150 | * Address if af is AF_INET. | 156 | * Address if af is AF_INET. |
151 | */ | 157 | */ |
@@ -164,7 +170,8 @@ struct DestinationEntry { | |||
164 | /** | 170 | /** |
165 | * A messages we have in queue for a particular channel. | 171 | * A messages we have in queue for a particular channel. |
166 | */ | 172 | */ |
167 | struct ChannelMessageQueueEntry { | 173 | struct ChannelMessageQueueEntry |
174 | { | ||
168 | /** | 175 | /** |
169 | * This is a doubly-linked list. | 176 | * This is a doubly-linked list. |
170 | */ | 177 | */ |
@@ -190,7 +197,8 @@ struct ChannelMessageQueueEntry { | |||
190 | /** | 197 | /** |
191 | * State we keep for each of our channels. | 198 | * State we keep for each of our channels. |
192 | */ | 199 | */ |
193 | struct ChannelState { | 200 | struct ChannelState |
201 | { | ||
194 | /** | 202 | /** |
195 | * Information about the channel to use, NULL if no channel | 203 | * Information about the channel to use, NULL if no channel |
196 | * is available right now. | 204 | * is available right now. |
@@ -250,7 +258,8 @@ struct ChannelState { | |||
250 | /** | 258 | /** |
251 | * IP address of the source on our end, initially uninitialized. | 259 | * IP address of the source on our end, initially uninitialized. |
252 | */ | 260 | */ |
253 | union { | 261 | union |
262 | { | ||
254 | /** | 263 | /** |
255 | * Address if af is AF_INET. | 264 | * Address if af is AF_INET. |
256 | */ | 265 | */ |
@@ -266,7 +275,8 @@ struct ChannelState { | |||
266 | * Destination IP address used by the source on our end (this is the IP | 275 | * Destination IP address used by the source on our end (this is the IP |
267 | * that we pick freely within the VPN's channel IP range). | 276 | * that we pick freely within the VPN's channel IP range). |
268 | */ | 277 | */ |
269 | union { | 278 | union |
279 | { | ||
270 | /** | 280 | /** |
271 | * Address if af is AF_INET. | 281 | * Address if af is AF_INET. |
272 | */ | 282 | */ |
@@ -370,24 +380,24 @@ static unsigned long long max_channel_mappings; | |||
370 | * @param key where to store the key | 380 | * @param key where to store the key |
371 | */ | 381 | */ |
372 | static void | 382 | static void |
373 | get_destination_key_from_ip(int af, | 383 | get_destination_key_from_ip (int af, |
374 | const void *address, | 384 | const void *address, |
375 | struct GNUNET_HashCode *key) | 385 | struct GNUNET_HashCode *key) |
376 | { | 386 | { |
377 | switch (af) | 387 | switch (af) |
378 | { | 388 | { |
379 | case AF_INET: | 389 | case AF_INET: |
380 | GNUNET_CRYPTO_hash(address, sizeof(struct in_addr), key); | 390 | GNUNET_CRYPTO_hash (address, sizeof(struct in_addr), key); |
381 | break; | 391 | break; |
382 | 392 | ||
383 | case AF_INET6: | 393 | case AF_INET6: |
384 | GNUNET_CRYPTO_hash(address, sizeof(struct in6_addr), key); | 394 | GNUNET_CRYPTO_hash (address, sizeof(struct in6_addr), key); |
385 | break; | 395 | break; |
386 | 396 | ||
387 | default: | 397 | default: |
388 | GNUNET_assert(0); | 398 | GNUNET_assert (0); |
389 | break; | 399 | break; |
390 | } | 400 | } |
391 | } | 401 | } |
392 | 402 | ||
393 | 403 | ||
@@ -404,45 +414,45 @@ get_destination_key_from_ip(int af, | |||
404 | * @param key where to store the key | 414 | * @param key where to store the key |
405 | */ | 415 | */ |
406 | static void | 416 | static void |
407 | get_channel_key_from_ips(int af, | 417 | get_channel_key_from_ips (int af, |
408 | uint8_t protocol, | 418 | uint8_t protocol, |
409 | const void *source_ip, | 419 | const void *source_ip, |
410 | uint16_t source_port, | 420 | uint16_t source_port, |
411 | const void *destination_ip, | 421 | const void *destination_ip, |
412 | uint16_t destination_port, | 422 | uint16_t destination_port, |
413 | struct GNUNET_HashCode *key) | 423 | struct GNUNET_HashCode *key) |
414 | { | 424 | { |
415 | char *off; | 425 | char *off; |
416 | 426 | ||
417 | memset(key, 0, sizeof(struct GNUNET_HashCode)); | 427 | memset (key, 0, sizeof(struct GNUNET_HashCode)); |
418 | /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, | 428 | /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, |
419 | so we put the ports in there (and hope for few collisions) */ | 429 | so we put the ports in there (and hope for few collisions) */ |
420 | off = (char *)key; | 430 | off = (char *) key; |
421 | GNUNET_memcpy(off, &source_port, sizeof(uint16_t)); | 431 | GNUNET_memcpy (off, &source_port, sizeof(uint16_t)); |
422 | off += sizeof(uint16_t); | 432 | off += sizeof(uint16_t); |
423 | GNUNET_memcpy(off, &destination_port, sizeof(uint16_t)); | 433 | GNUNET_memcpy (off, &destination_port, sizeof(uint16_t)); |
424 | off += sizeof(uint16_t); | 434 | off += sizeof(uint16_t); |
425 | switch (af) | 435 | switch (af) |
426 | { | 436 | { |
427 | case AF_INET: | 437 | case AF_INET: |
428 | GNUNET_memcpy(off, source_ip, sizeof(struct in_addr)); | 438 | GNUNET_memcpy (off, source_ip, sizeof(struct in_addr)); |
429 | off += sizeof(struct in_addr); | 439 | off += sizeof(struct in_addr); |
430 | GNUNET_memcpy(off, destination_ip, sizeof(struct in_addr)); | 440 | GNUNET_memcpy (off, destination_ip, sizeof(struct in_addr)); |
431 | off += sizeof(struct in_addr); | 441 | off += sizeof(struct in_addr); |
432 | break; | 442 | break; |
433 | 443 | ||
434 | case AF_INET6: | 444 | case AF_INET6: |
435 | GNUNET_memcpy(off, source_ip, sizeof(struct in6_addr)); | 445 | GNUNET_memcpy (off, source_ip, sizeof(struct in6_addr)); |
436 | off += sizeof(struct in6_addr); | 446 | off += sizeof(struct in6_addr); |
437 | GNUNET_memcpy(off, destination_ip, sizeof(struct in6_addr)); | 447 | GNUNET_memcpy (off, destination_ip, sizeof(struct in6_addr)); |
438 | off += sizeof(struct in6_addr); | 448 | off += sizeof(struct in6_addr); |
439 | break; | 449 | break; |
440 | 450 | ||
441 | default: | 451 | default: |
442 | GNUNET_assert(0); | 452 | GNUNET_assert (0); |
443 | break; | 453 | break; |
444 | } | 454 | } |
445 | GNUNET_memcpy(off, &protocol, sizeof(uint8_t)); | 455 | GNUNET_memcpy (off, &protocol, sizeof(uint8_t)); |
446 | /* off += sizeof (uint8_t); */ | 456 | /* off += sizeof (uint8_t); */ |
447 | } | 457 | } |
448 | 458 | ||
@@ -456,38 +466,38 @@ get_channel_key_from_ips(int af, | |||
456 | * @param addr resulting IP address | 466 | * @param addr resulting IP address |
457 | */ | 467 | */ |
458 | static void | 468 | static void |
459 | send_client_reply(struct GNUNET_SERVICE_Client *client, | 469 | send_client_reply (struct GNUNET_SERVICE_Client *client, |
460 | uint64_t request_id, | 470 | uint64_t request_id, |
461 | int result_af, | 471 | int result_af, |
462 | const void *addr) | 472 | const void *addr) |
463 | { | 473 | { |
464 | struct GNUNET_MQ_Envelope *env; | 474 | struct GNUNET_MQ_Envelope *env; |
465 | struct RedirectToIpResponseMessage *res; | 475 | struct RedirectToIpResponseMessage *res; |
466 | size_t rlen; | 476 | size_t rlen; |
467 | 477 | ||
468 | switch (result_af) | 478 | switch (result_af) |
469 | { | 479 | { |
470 | case AF_INET: | 480 | case AF_INET: |
471 | rlen = sizeof(struct in_addr); | 481 | rlen = sizeof(struct in_addr); |
472 | break; | 482 | break; |
473 | 483 | ||
474 | case AF_INET6: | 484 | case AF_INET6: |
475 | rlen = sizeof(struct in6_addr); | 485 | rlen = sizeof(struct in6_addr); |
476 | break; | 486 | break; |
477 | 487 | ||
478 | case AF_UNSPEC: | 488 | case AF_UNSPEC: |
479 | rlen = 0; | 489 | rlen = 0; |
480 | break; | 490 | break; |
481 | 491 | ||
482 | default: | 492 | default: |
483 | GNUNET_assert(0); | 493 | GNUNET_assert (0); |
484 | return; | 494 | return; |
485 | } | 495 | } |
486 | env = GNUNET_MQ_msg_extra(res, rlen, GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP); | 496 | env = GNUNET_MQ_msg_extra (res, rlen, GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP); |
487 | res->result_af = htonl(result_af); | 497 | res->result_af = htonl (result_af); |
488 | res->request_id = request_id; | 498 | res->request_id = request_id; |
489 | GNUNET_memcpy(&res[1], addr, rlen); | 499 | GNUNET_memcpy (&res[1], addr, rlen); |
490 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); | 500 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
491 | } | 501 | } |
492 | 502 | ||
493 | 503 | ||
@@ -497,52 +507,52 @@ send_client_reply(struct GNUNET_SERVICE_Client *client, | |||
497 | * @param ts state to free | 507 | * @param ts state to free |
498 | */ | 508 | */ |
499 | static void | 509 | static void |
500 | free_channel_state(struct ChannelState *ts) | 510 | free_channel_state (struct ChannelState *ts) |
501 | { | 511 | { |
502 | struct GNUNET_HashCode key; | 512 | struct GNUNET_HashCode key; |
503 | struct ChannelMessageQueueEntry *tnq; | 513 | struct ChannelMessageQueueEntry *tnq; |
504 | struct GNUNET_CADET_Channel *channel; | 514 | struct GNUNET_CADET_Channel *channel; |
505 | 515 | ||
506 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up channel state\n"); | 516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up channel state\n"); |
507 | if (NULL != (channel = ts->channel)) | 517 | if (NULL != (channel = ts->channel)) |
508 | { | 518 | { |
509 | ts->channel = NULL; | 519 | ts->channel = NULL; |
510 | GNUNET_CADET_channel_destroy(channel); | 520 | GNUNET_CADET_channel_destroy (channel); |
511 | return; | 521 | return; |
512 | } | 522 | } |
513 | GNUNET_STATISTICS_update(stats, | 523 | GNUNET_STATISTICS_update (stats, |
514 | gettext_noop("# Active channels"), | 524 | gettext_noop ("# Active channels"), |
515 | -1, | 525 | -1, |
516 | GNUNET_NO); | 526 | GNUNET_NO); |
517 | while (NULL != (tnq = ts->tmq_head)) | 527 | while (NULL != (tnq = ts->tmq_head)) |
518 | { | 528 | { |
519 | GNUNET_CONTAINER_DLL_remove(ts->tmq_head, ts->tmq_tail, tnq); | 529 | GNUNET_CONTAINER_DLL_remove (ts->tmq_head, ts->tmq_tail, tnq); |
520 | ts->tmq_length--; | 530 | ts->tmq_length--; |
521 | GNUNET_free(tnq); | 531 | GNUNET_free (tnq); |
522 | } | 532 | } |
523 | GNUNET_assert(0 == ts->tmq_length); | 533 | GNUNET_assert (0 == ts->tmq_length); |
524 | GNUNET_assert(NULL == ts->destination.heap_node); | 534 | GNUNET_assert (NULL == ts->destination.heap_node); |
525 | if (NULL != ts->search) | 535 | if (NULL != ts->search) |
526 | { | 536 | { |
527 | GNUNET_REGEX_search_cancel(ts->search); | 537 | GNUNET_REGEX_search_cancel (ts->search); |
528 | ts->search = NULL; | 538 | ts->search = NULL; |
529 | } | 539 | } |
530 | if (NULL != ts->heap_node) | 540 | if (NULL != ts->heap_node) |
531 | { | 541 | { |
532 | GNUNET_CONTAINER_heap_remove_node(ts->heap_node); | 542 | GNUNET_CONTAINER_heap_remove_node (ts->heap_node); |
533 | ts->heap_node = NULL; | 543 | ts->heap_node = NULL; |
534 | get_channel_key_from_ips(ts->af, | 544 | get_channel_key_from_ips (ts->af, |
535 | ts->protocol, | 545 | ts->protocol, |
536 | &ts->source_ip, | 546 | &ts->source_ip, |
537 | ts->source_port, | 547 | ts->source_port, |
538 | &ts->destination_ip, | 548 | &ts->destination_ip, |
539 | ts->destination_port, | 549 | ts->destination_port, |
540 | &key); | 550 | &key); |
541 | GNUNET_assert( | 551 | GNUNET_assert ( |
542 | GNUNET_YES == | 552 | GNUNET_YES == |
543 | GNUNET_CONTAINER_multihashmap_remove(channel_map, &key, ts)); | 553 | GNUNET_CONTAINER_multihashmap_remove (channel_map, &key, ts)); |
544 | } | 554 | } |
545 | GNUNET_free(ts); | 555 | GNUNET_free (ts); |
546 | } | 556 | } |
547 | 557 | ||
548 | 558 | ||
@@ -554,27 +564,27 @@ free_channel_state(struct ChannelState *ts) | |||
554 | * @param env message to queue | 564 | * @param env message to queue |
555 | */ | 565 | */ |
556 | static void | 566 | static void |
557 | send_to_channel(struct ChannelState *ts, struct GNUNET_MQ_Envelope *env) | 567 | send_to_channel (struct ChannelState *ts, struct GNUNET_MQ_Envelope *env) |
558 | { | 568 | { |
559 | struct GNUNET_MQ_Handle *mq; | 569 | struct GNUNET_MQ_Handle *mq; |
560 | 570 | ||
561 | GNUNET_assert(NULL != ts->channel); | 571 | GNUNET_assert (NULL != ts->channel); |
562 | mq = GNUNET_CADET_get_mq(ts->channel); | 572 | mq = GNUNET_CADET_get_mq (ts->channel); |
563 | GNUNET_MQ_env_set_options(env, | 573 | GNUNET_MQ_env_set_options (env, |
564 | GNUNET_MQ_PRIO_BEST_EFFORT | | 574 | GNUNET_MQ_PRIO_BEST_EFFORT |
565 | GNUNET_MQ_PREF_OUT_OF_ORDER); | 575 | | GNUNET_MQ_PREF_OUT_OF_ORDER); |
566 | GNUNET_MQ_send(mq, env); | 576 | GNUNET_MQ_send (mq, env); |
567 | if (GNUNET_MQ_get_length(mq) > MAX_MESSAGE_QUEUE_SIZE) | 577 | if (GNUNET_MQ_get_length (mq) > MAX_MESSAGE_QUEUE_SIZE) |
568 | { | 578 | { |
569 | env = GNUNET_MQ_unsent_head(mq); | 579 | env = GNUNET_MQ_unsent_head (mq); |
570 | GNUNET_assert(NULL != env); | 580 | GNUNET_assert (NULL != env); |
571 | GNUNET_STATISTICS_update(stats, | 581 | GNUNET_STATISTICS_update (stats, |
572 | gettext_noop( | 582 | gettext_noop ( |
573 | "# Messages dropped in cadet queue (overflow)"), | 583 | "# Messages dropped in cadet queue (overflow)"), |
574 | 1, | 584 | 1, |
575 | GNUNET_NO); | 585 | GNUNET_NO); |
576 | GNUNET_MQ_discard(env); | 586 | GNUNET_MQ_discard (env); |
577 | } | 587 | } |
578 | } | 588 | } |
579 | 589 | ||
580 | 590 | ||
@@ -585,26 +595,26 @@ send_to_channel(struct ChannelState *ts, struct GNUNET_MQ_Envelope *env) | |||
585 | * @return diagnostic string describing destination | 595 | * @return diagnostic string describing destination |
586 | */ | 596 | */ |
587 | static const char * | 597 | static const char * |
588 | print_channel_destination(const struct DestinationEntry *de) | 598 | print_channel_destination (const struct DestinationEntry *de) |
589 | { | 599 | { |
590 | static char dest[256]; | 600 | static char dest[256]; |
591 | 601 | ||
592 | if (de->is_service) | 602 | if (de->is_service) |
593 | { | 603 | { |
594 | GNUNET_snprintf(dest, | 604 | GNUNET_snprintf (dest, |
595 | sizeof(dest), | 605 | sizeof(dest), |
596 | "HS: %s-%s", | 606 | "HS: %s-%s", |
597 | GNUNET_i2s(&de->details.service_destination.target), | 607 | GNUNET_i2s (&de->details.service_destination.target), |
598 | GNUNET_h2s( | 608 | GNUNET_h2s ( |
599 | &de->details.service_destination.service_descriptor)); | 609 | &de->details.service_destination.service_descriptor)); |
600 | } | 610 | } |
601 | else | 611 | else |
602 | { | 612 | { |
603 | inet_ntop(de->details.exit_destination.af, | 613 | inet_ntop (de->details.exit_destination.af, |
604 | &de->details.exit_destination.ip, | 614 | &de->details.exit_destination.ip, |
605 | dest, | 615 | dest, |
606 | sizeof(dest)); | 616 | sizeof(dest)); |
607 | } | 617 | } |
608 | return dest; | 618 | return dest; |
609 | } | 619 | } |
610 | 620 | ||
@@ -617,16 +627,16 @@ print_channel_destination(const struct DestinationEntry *de) | |||
617 | * @param channel connection to the other end (henceforth invalid) | 627 | * @param channel connection to the other end (henceforth invalid) |
618 | */ | 628 | */ |
619 | static void | 629 | static void |
620 | channel_cleaner(void *cls, const struct GNUNET_CADET_Channel *channel) | 630 | channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel) |
621 | { | 631 | { |
622 | struct ChannelState *ts = cls; | 632 | struct ChannelState *ts = cls; |
623 | 633 | ||
624 | ts->channel = | 634 | ts->channel = |
625 | NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */ | 635 | NULL; /* we must not call GNUNET_CADET_channel_destroy() anymore */ |
626 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 636 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
627 | "CADET notified us about death of channel to `%s'\n", | 637 | "CADET notified us about death of channel to `%s'\n", |
628 | print_channel_destination(&ts->destination)); | 638 | print_channel_destination (&ts->destination)); |
629 | free_channel_state(ts); | 639 | free_channel_state (ts); |
630 | } | 640 | } |
631 | 641 | ||
632 | 642 | ||
@@ -640,19 +650,19 @@ channel_cleaner(void *cls, const struct GNUNET_CADET_Channel *channel) | |||
640 | * also be the first 8 bytes of the TCP header | 650 | * also be the first 8 bytes of the TCP header |
641 | */ | 651 | */ |
642 | static void | 652 | static void |
643 | make_up_icmpv4_payload(struct ChannelState *ts, | 653 | make_up_icmpv4_payload (struct ChannelState *ts, |
644 | struct GNUNET_TUN_IPv4Header *ipp, | 654 | struct GNUNET_TUN_IPv4Header *ipp, |
645 | struct GNUNET_TUN_UdpHeader *udp) | 655 | struct GNUNET_TUN_UdpHeader *udp) |
646 | { | 656 | { |
647 | GNUNET_TUN_initialize_ipv4_header(ipp, | 657 | GNUNET_TUN_initialize_ipv4_header (ipp, |
648 | ts->protocol, | 658 | ts->protocol, |
649 | sizeof(struct GNUNET_TUN_TcpHeader), | 659 | sizeof(struct GNUNET_TUN_TcpHeader), |
650 | &ts->source_ip.v4, | 660 | &ts->source_ip.v4, |
651 | &ts->destination_ip.v4); | 661 | &ts->destination_ip.v4); |
652 | udp->source_port = htons(ts->source_port); | 662 | udp->source_port = htons (ts->source_port); |
653 | udp->destination_port = htons(ts->destination_port); | 663 | udp->destination_port = htons (ts->destination_port); |
654 | udp->len = htons(0); | 664 | udp->len = htons (0); |
655 | udp->crc = htons(0); | 665 | udp->crc = htons (0); |
656 | } | 666 | } |
657 | 667 | ||
658 | 668 | ||
@@ -666,19 +676,19 @@ make_up_icmpv4_payload(struct ChannelState *ts, | |||
666 | * also be the first 8 bytes of the TCP header | 676 | * also be the first 8 bytes of the TCP header |
667 | */ | 677 | */ |
668 | static void | 678 | static void |
669 | make_up_icmpv6_payload(struct ChannelState *ts, | 679 | make_up_icmpv6_payload (struct ChannelState *ts, |
670 | struct GNUNET_TUN_IPv6Header *ipp, | 680 | struct GNUNET_TUN_IPv6Header *ipp, |
671 | struct GNUNET_TUN_UdpHeader *udp) | 681 | struct GNUNET_TUN_UdpHeader *udp) |
672 | { | 682 | { |
673 | GNUNET_TUN_initialize_ipv6_header(ipp, | 683 | GNUNET_TUN_initialize_ipv6_header (ipp, |
674 | ts->protocol, | 684 | ts->protocol, |
675 | sizeof(struct GNUNET_TUN_TcpHeader), | 685 | sizeof(struct GNUNET_TUN_TcpHeader), |
676 | &ts->source_ip.v6, | 686 | &ts->source_ip.v6, |
677 | &ts->destination_ip.v6); | 687 | &ts->destination_ip.v6); |
678 | udp->source_port = htons(ts->source_port); | 688 | udp->source_port = htons (ts->source_port); |
679 | udp->destination_port = htons(ts->destination_port); | 689 | udp->destination_port = htons (ts->destination_port); |
680 | udp->len = htons(0); | 690 | udp->len = htons (0); |
681 | udp->crc = htons(0); | 691 | udp->crc = htons (0); |
682 | } | 692 | } |
683 | 693 | ||
684 | 694 | ||
@@ -691,20 +701,20 @@ make_up_icmpv6_payload(struct ChannelState *ts, | |||
691 | * #GNUNET_SYSERR to close it (signal serious error) | 701 | * #GNUNET_SYSERR to close it (signal serious error) |
692 | */ | 702 | */ |
693 | static int | 703 | static int |
694 | check_icmp_back(void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) | 704 | check_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) |
695 | { | 705 | { |
696 | struct ChannelState *ts = cls; | 706 | struct ChannelState *ts = cls; |
697 | 707 | ||
698 | if (NULL == ts->heap_node) | 708 | if (NULL == ts->heap_node) |
699 | { | 709 | { |
700 | GNUNET_break_op(0); | 710 | GNUNET_break_op (0); |
701 | return GNUNET_SYSERR; | 711 | return GNUNET_SYSERR; |
702 | } | 712 | } |
703 | if (AF_UNSPEC == ts->af) | 713 | if (AF_UNSPEC == ts->af) |
704 | { | 714 | { |
705 | GNUNET_break_op(0); | 715 | GNUNET_break_op (0); |
706 | return GNUNET_SYSERR; | 716 | return GNUNET_SYSERR; |
707 | } | 717 | } |
708 | return GNUNET_OK; | 718 | return GNUNET_OK; |
709 | } | 719 | } |
710 | 720 | ||
@@ -717,344 +727,344 @@ check_icmp_back(void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) | |||
717 | * @param message the actual message | 727 | * @param message the actual message |
718 | */ | 728 | */ |
719 | static void | 729 | static void |
720 | handle_icmp_back(void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) | 730 | handle_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) |
721 | { | 731 | { |
722 | struct ChannelState *ts = cls; | 732 | struct ChannelState *ts = cls; |
723 | size_t mlen; | 733 | size_t mlen; |
724 | 734 | ||
725 | GNUNET_STATISTICS_update(stats, | 735 | GNUNET_STATISTICS_update (stats, |
726 | gettext_noop("# ICMP packets received from cadet"), | 736 | gettext_noop ("# ICMP packets received from cadet"), |
727 | 1, | 737 | 1, |
728 | GNUNET_NO); | 738 | GNUNET_NO); |
729 | mlen = | 739 | mlen = |
730 | ntohs(i2v->header.size) - sizeof(struct GNUNET_EXIT_IcmpToVPNMessage); | 740 | ntohs (i2v->header.size) - sizeof(struct GNUNET_EXIT_IcmpToVPNMessage); |
731 | { | 741 | { |
732 | char sbuf[INET6_ADDRSTRLEN]; | 742 | char sbuf[INET6_ADDRSTRLEN]; |
733 | char dbuf[INET6_ADDRSTRLEN]; | 743 | char dbuf[INET6_ADDRSTRLEN]; |
734 | 744 | ||
735 | GNUNET_log( | 745 | GNUNET_log ( |
736 | GNUNET_ERROR_TYPE_DEBUG, | 746 | GNUNET_ERROR_TYPE_DEBUG, |
737 | "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n", | 747 | "Received ICMP packet from cadet, sending %u bytes from %s -> %s via TUN\n", |
738 | (unsigned int)mlen, | 748 | (unsigned int) mlen, |
739 | inet_ntop(ts->af, &ts->destination_ip, sbuf, sizeof(sbuf)), | 749 | inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof(sbuf)), |
740 | inet_ntop(ts->af, &ts->source_ip, dbuf, sizeof(dbuf))); | 750 | inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof(dbuf))); |
741 | } | 751 | } |
742 | switch (ts->af) | 752 | switch (ts->af) |
743 | { | 753 | { |
744 | case AF_INET: { | 754 | case AF_INET: { |
745 | size_t size = sizeof(struct GNUNET_TUN_IPv4Header) + | 755 | size_t size = sizeof(struct GNUNET_TUN_IPv4Header) |
746 | sizeof(struct GNUNET_TUN_IcmpHeader) + | 756 | + sizeof(struct GNUNET_TUN_IcmpHeader) |
747 | sizeof(struct GNUNET_MessageHeader) + | 757 | + sizeof(struct GNUNET_MessageHeader) |
748 | sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; | 758 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; |
749 | { | 759 | { |
750 | /* reserve some extra space in case we have an ICMP type here where | 760 | /* reserve some extra space in case we have an ICMP type here where |
751 | we will need to make up the payload ourselves */ | 761 | we will need to make up the payload ourselves */ |
752 | char buf[size + sizeof(struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN; | 762 | char buf[size + sizeof(struct GNUNET_TUN_IPv4Header) + 8] GNUNET_ALIGN; |
753 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)buf; | 763 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; |
754 | struct GNUNET_TUN_Layer2PacketHeader *tun = | 764 | struct GNUNET_TUN_Layer2PacketHeader *tun = |
755 | (struct GNUNET_TUN_Layer2PacketHeader *)&msg[1]; | 765 | (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; |
756 | struct GNUNET_TUN_IPv4Header *ipv4 = | 766 | struct GNUNET_TUN_IPv4Header *ipv4 = |
757 | (struct GNUNET_TUN_IPv4Header *)&tun[1]; | 767 | (struct GNUNET_TUN_IPv4Header *) &tun[1]; |
758 | struct GNUNET_TUN_IcmpHeader *icmp = | 768 | struct GNUNET_TUN_IcmpHeader *icmp = |
759 | (struct GNUNET_TUN_IcmpHeader *)&ipv4[1]; | 769 | (struct GNUNET_TUN_IcmpHeader *) &ipv4[1]; |
760 | msg->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 770 | msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
761 | tun->flags = htons(0); | 771 | tun->flags = htons (0); |
762 | tun->proto = htons(ETH_P_IPV4); | 772 | tun->proto = htons (ETH_P_IPV4); |
763 | GNUNET_TUN_initialize_ipv4_header(ipv4, | 773 | GNUNET_TUN_initialize_ipv4_header (ipv4, |
764 | IPPROTO_ICMP, | 774 | IPPROTO_ICMP, |
765 | sizeof(struct GNUNET_TUN_IcmpHeader) + | 775 | sizeof(struct GNUNET_TUN_IcmpHeader) |
766 | mlen, | 776 | + mlen, |
767 | &ts->destination_ip.v4, | 777 | &ts->destination_ip.v4, |
768 | &ts->source_ip.v4); | 778 | &ts->source_ip.v4); |
769 | *icmp = i2v->icmp_header; | 779 | *icmp = i2v->icmp_header; |
770 | GNUNET_memcpy(&icmp[1], &i2v[1], mlen); | 780 | GNUNET_memcpy (&icmp[1], &i2v[1], mlen); |
771 | /* For some ICMP types, we need to adjust (make up) the payload here. | 781 | /* For some ICMP types, we need to adjust (make up) the payload here. |
772 | Also, depending on the AF used on the other side, we have to | 782 | Also, depending on the AF used on the other side, we have to |
773 | do ICMP PT (translate ICMP types) */ | 783 | do ICMP PT (translate ICMP types) */ |
774 | switch (ntohl(i2v->af)) | 784 | switch (ntohl (i2v->af)) |
785 | { | ||
786 | case AF_INET: | ||
787 | switch (icmp->type) | ||
775 | { | 788 | { |
776 | case AF_INET: | 789 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
777 | switch (icmp->type) | 790 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
791 | break; | ||
792 | |||
793 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
794 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
795 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: { | ||
796 | struct GNUNET_TUN_IPv4Header *ipp = | ||
797 | (struct GNUNET_TUN_IPv4Header *) &icmp[1]; | ||
798 | struct GNUNET_TUN_UdpHeader *udp = | ||
799 | (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | ||
800 | |||
801 | if (mlen != 0) | ||
778 | { | 802 | { |
779 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | 803 | /* sender did not strip ICMP payload? */ |
780 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | 804 | GNUNET_break_op (0); |
781 | break; | ||
782 | |||
783 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
784 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
785 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: { | ||
786 | struct GNUNET_TUN_IPv4Header *ipp = | ||
787 | (struct GNUNET_TUN_IPv4Header *)&icmp[1]; | ||
788 | struct GNUNET_TUN_UdpHeader *udp = | ||
789 | (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
790 | |||
791 | if (mlen != 0) | ||
792 | { | ||
793 | /* sender did not strip ICMP payload? */ | ||
794 | GNUNET_break_op(0); | ||
795 | return; | ||
796 | } | ||
797 | size += sizeof(struct GNUNET_TUN_IPv4Header) + 8; | ||
798 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
799 | make_up_icmpv4_payload(ts, ipp, udp); | ||
800 | } | ||
801 | break; | ||
802 | |||
803 | default: | ||
804 | GNUNET_break_op(0); | ||
805 | GNUNET_STATISTICS_update( | ||
806 | stats, | ||
807 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
808 | 1, | ||
809 | GNUNET_NO); | ||
810 | return; | 805 | return; |
811 | } | 806 | } |
812 | /* end AF_INET */ | 807 | size += sizeof(struct GNUNET_TUN_IPv4Header) + 8; |
808 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
809 | make_up_icmpv4_payload (ts, ipp, udp); | ||
810 | } | ||
813 | break; | 811 | break; |
814 | 812 | ||
815 | case AF_INET6: | 813 | default: |
816 | /* ICMP PT 6-to-4 and possibly making up payloads */ | 814 | GNUNET_break_op (0); |
817 | switch (icmp->type) | 815 | GNUNET_STATISTICS_update ( |
816 | stats, | ||
817 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), | ||
818 | 1, | ||
819 | GNUNET_NO); | ||
820 | return; | ||
821 | } | ||
822 | /* end AF_INET */ | ||
823 | break; | ||
824 | |||
825 | case AF_INET6: | ||
826 | /* ICMP PT 6-to-4 and possibly making up payloads */ | ||
827 | switch (icmp->type) | ||
828 | { | ||
829 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | ||
830 | icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; | ||
831 | { | ||
832 | struct GNUNET_TUN_IPv4Header *ipp = | ||
833 | (struct GNUNET_TUN_IPv4Header *) &icmp[1]; | ||
834 | struct GNUNET_TUN_UdpHeader *udp = | ||
835 | (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | ||
836 | |||
837 | if (mlen != 0) | ||
818 | { | 838 | { |
819 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | 839 | /* sender did not strip ICMP payload? */ |
820 | icmp->type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; | 840 | GNUNET_break_op (0); |
821 | { | ||
822 | struct GNUNET_TUN_IPv4Header *ipp = | ||
823 | (struct GNUNET_TUN_IPv4Header *)&icmp[1]; | ||
824 | struct GNUNET_TUN_UdpHeader *udp = | ||
825 | (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
826 | |||
827 | if (mlen != 0) | ||
828 | { | ||
829 | /* sender did not strip ICMP payload? */ | ||
830 | GNUNET_break_op(0); | ||
831 | return; | ||
832 | } | ||
833 | size += sizeof(struct GNUNET_TUN_IPv4Header) + 8; | ||
834 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
835 | make_up_icmpv4_payload(ts, ipp, udp); | ||
836 | } | ||
837 | break; | ||
838 | |||
839 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
840 | icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; | ||
841 | { | ||
842 | struct GNUNET_TUN_IPv4Header *ipp = | ||
843 | (struct GNUNET_TUN_IPv4Header *)&icmp[1]; | ||
844 | struct GNUNET_TUN_UdpHeader *udp = | ||
845 | (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
846 | |||
847 | if (mlen != 0) | ||
848 | { | ||
849 | /* sender did not strip ICMP payload? */ | ||
850 | GNUNET_break_op(0); | ||
851 | return; | ||
852 | } | ||
853 | size += sizeof(struct GNUNET_TUN_IPv4Header) + 8; | ||
854 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
855 | make_up_icmpv4_payload(ts, ipp, udp); | ||
856 | } | ||
857 | break; | ||
858 | |||
859 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
860 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
861 | GNUNET_STATISTICS_update( | ||
862 | stats, | ||
863 | gettext_noop("# ICMPv6 packets dropped (impossible PT to v4)"), | ||
864 | 1, | ||
865 | GNUNET_NO); | ||
866 | return; | 841 | return; |
842 | } | ||
843 | size += sizeof(struct GNUNET_TUN_IPv4Header) + 8; | ||
844 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
845 | make_up_icmpv4_payload (ts, ipp, udp); | ||
846 | } | ||
847 | break; | ||
867 | 848 | ||
868 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | 849 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: |
869 | icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; | 850 | icmp->type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; |
870 | break; | 851 | { |
871 | 852 | struct GNUNET_TUN_IPv4Header *ipp = | |
872 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | 853 | (struct GNUNET_TUN_IPv4Header *) &icmp[1]; |
873 | icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; | 854 | struct GNUNET_TUN_UdpHeader *udp = |
874 | break; | 855 | (struct GNUNET_TUN_UdpHeader *) &ipp[1]; |
875 | 856 | ||
876 | default: | 857 | if (mlen != 0) |
877 | GNUNET_break_op(0); | 858 | { |
878 | GNUNET_STATISTICS_update( | 859 | /* sender did not strip ICMP payload? */ |
879 | stats, | 860 | GNUNET_break_op (0); |
880 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
881 | 1, | ||
882 | GNUNET_NO); | ||
883 | return; | 861 | return; |
884 | } | 862 | } |
885 | /* end AF_INET6 */ | 863 | size += sizeof(struct GNUNET_TUN_IPv4Header) + 8; |
864 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
865 | make_up_icmpv4_payload (ts, ipp, udp); | ||
866 | } | ||
867 | break; | ||
868 | |||
869 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
870 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
871 | GNUNET_STATISTICS_update ( | ||
872 | stats, | ||
873 | gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), | ||
874 | 1, | ||
875 | GNUNET_NO); | ||
876 | return; | ||
877 | |||
878 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
879 | icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; | ||
880 | break; | ||
881 | |||
882 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | ||
883 | icmp->type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; | ||
886 | break; | 884 | break; |
887 | 885 | ||
888 | default: | 886 | default: |
889 | GNUNET_break_op(0); | 887 | GNUNET_break_op (0); |
888 | GNUNET_STATISTICS_update ( | ||
889 | stats, | ||
890 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), | ||
891 | 1, | ||
892 | GNUNET_NO); | ||
890 | return; | 893 | return; |
891 | } | 894 | } |
892 | msg->size = htons(size); | 895 | /* end AF_INET6 */ |
893 | GNUNET_TUN_calculate_icmp_checksum(icmp, &i2v[1], mlen); | 896 | break; |
894 | (void)GNUNET_HELPER_send(helper_handle, msg, GNUNET_YES, NULL, NULL); | 897 | |
898 | default: | ||
899 | GNUNET_break_op (0); | ||
900 | return; | ||
901 | } | ||
902 | msg->size = htons (size); | ||
903 | GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen); | ||
904 | (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); | ||
895 | } | 905 | } |
896 | } | 906 | } |
897 | break; | 907 | break; |
898 | 908 | ||
899 | case AF_INET6: { | 909 | case AF_INET6: { |
900 | size_t size = sizeof(struct GNUNET_TUN_IPv6Header) + | 910 | size_t size = sizeof(struct GNUNET_TUN_IPv6Header) |
901 | sizeof(struct GNUNET_TUN_IcmpHeader) + | 911 | + sizeof(struct GNUNET_TUN_IcmpHeader) |
902 | sizeof(struct GNUNET_MessageHeader) + | 912 | + sizeof(struct GNUNET_MessageHeader) |
903 | sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; | 913 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; |
904 | { | 914 | { |
905 | char buf[size + sizeof(struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; | 915 | char buf[size + sizeof(struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; |
906 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)buf; | 916 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; |
907 | struct GNUNET_TUN_Layer2PacketHeader *tun = | 917 | struct GNUNET_TUN_Layer2PacketHeader *tun = |
908 | (struct GNUNET_TUN_Layer2PacketHeader *)&msg[1]; | 918 | (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; |
909 | struct GNUNET_TUN_IPv6Header *ipv6 = | 919 | struct GNUNET_TUN_IPv6Header *ipv6 = |
910 | (struct GNUNET_TUN_IPv6Header *)&tun[1]; | 920 | (struct GNUNET_TUN_IPv6Header *) &tun[1]; |
911 | struct GNUNET_TUN_IcmpHeader *icmp = | 921 | struct GNUNET_TUN_IcmpHeader *icmp = |
912 | (struct GNUNET_TUN_IcmpHeader *)&ipv6[1]; | 922 | (struct GNUNET_TUN_IcmpHeader *) &ipv6[1]; |
913 | msg->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 923 | msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
914 | tun->flags = htons(0); | 924 | tun->flags = htons (0); |
915 | tun->proto = htons(ETH_P_IPV6); | 925 | tun->proto = htons (ETH_P_IPV6); |
916 | GNUNET_TUN_initialize_ipv6_header(ipv6, | 926 | GNUNET_TUN_initialize_ipv6_header (ipv6, |
917 | IPPROTO_ICMPV6, | 927 | IPPROTO_ICMPV6, |
918 | sizeof(struct GNUNET_TUN_IcmpHeader) + | 928 | sizeof(struct GNUNET_TUN_IcmpHeader) |
919 | mlen, | 929 | + mlen, |
920 | &ts->destination_ip.v6, | 930 | &ts->destination_ip.v6, |
921 | &ts->source_ip.v6); | 931 | &ts->source_ip.v6); |
922 | *icmp = i2v->icmp_header; | 932 | *icmp = i2v->icmp_header; |
923 | GNUNET_memcpy(&icmp[1], &i2v[1], mlen); | 933 | GNUNET_memcpy (&icmp[1], &i2v[1], mlen); |
924 | 934 | ||
925 | /* For some ICMP types, we need to adjust (make up) the payload here. | 935 | /* For some ICMP types, we need to adjust (make up) the payload here. |
926 | Also, depending on the AF used on the other side, we have to | 936 | Also, depending on the AF used on the other side, we have to |
927 | do ICMP PT (translate ICMP types) */ | 937 | do ICMP PT (translate ICMP types) */ |
928 | switch (ntohl(i2v->af)) | 938 | switch (ntohl (i2v->af)) |
939 | { | ||
940 | case AF_INET: | ||
941 | /* ICMP PT 4-to-6 and possibly making up payloads */ | ||
942 | switch (icmp->type) | ||
929 | { | 943 | { |
930 | case AF_INET: | 944 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
931 | /* ICMP PT 4-to-6 and possibly making up payloads */ | 945 | icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; |
932 | switch (icmp->type) | 946 | break; |
947 | |||
948 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
949 | icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; | ||
950 | break; | ||
951 | |||
952 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
953 | icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; | ||
954 | { | ||
955 | struct GNUNET_TUN_IPv6Header *ipp = | ||
956 | (struct GNUNET_TUN_IPv6Header *) &icmp[1]; | ||
957 | struct GNUNET_TUN_UdpHeader *udp = | ||
958 | (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | ||
959 | |||
960 | if (mlen != 0) | ||
933 | { | 961 | { |
934 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | 962 | /* sender did not strip ICMP payload? */ |
935 | icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; | 963 | GNUNET_break_op (0); |
936 | break; | ||
937 | |||
938 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
939 | icmp->type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; | ||
940 | break; | ||
941 | |||
942 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
943 | icmp->type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; | ||
944 | { | ||
945 | struct GNUNET_TUN_IPv6Header *ipp = | ||
946 | (struct GNUNET_TUN_IPv6Header *)&icmp[1]; | ||
947 | struct GNUNET_TUN_UdpHeader *udp = | ||
948 | (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
949 | |||
950 | if (mlen != 0) | ||
951 | { | ||
952 | /* sender did not strip ICMP payload? */ | ||
953 | GNUNET_break_op(0); | ||
954 | return; | ||
955 | } | ||
956 | size += sizeof(struct GNUNET_TUN_IPv6Header) + 8; | ||
957 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
958 | make_up_icmpv6_payload(ts, ipp, udp); | ||
959 | } | ||
960 | break; | ||
961 | |||
962 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
963 | icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; | ||
964 | { | ||
965 | struct GNUNET_TUN_IPv6Header *ipp = | ||
966 | (struct GNUNET_TUN_IPv6Header *)&icmp[1]; | ||
967 | struct GNUNET_TUN_UdpHeader *udp = | ||
968 | (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
969 | |||
970 | if (mlen != 0) | ||
971 | { | ||
972 | /* sender did not strip ICMP payload? */ | ||
973 | GNUNET_break_op(0); | ||
974 | return; | ||
975 | } | ||
976 | size += sizeof(struct GNUNET_TUN_IPv6Header) + 8; | ||
977 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
978 | make_up_icmpv6_payload(ts, ipp, udp); | ||
979 | } | ||
980 | break; | ||
981 | |||
982 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
983 | GNUNET_STATISTICS_update( | ||
984 | stats, | ||
985 | gettext_noop("# ICMPv4 packets dropped (impossible PT to v6)"), | ||
986 | 1, | ||
987 | GNUNET_NO); | ||
988 | return; | 964 | return; |
965 | } | ||
966 | size += sizeof(struct GNUNET_TUN_IPv6Header) + 8; | ||
967 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
968 | make_up_icmpv6_payload (ts, ipp, udp); | ||
969 | } | ||
970 | break; | ||
971 | |||
972 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
973 | icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; | ||
974 | { | ||
975 | struct GNUNET_TUN_IPv6Header *ipp = | ||
976 | (struct GNUNET_TUN_IPv6Header *) &icmp[1]; | ||
977 | struct GNUNET_TUN_UdpHeader *udp = | ||
978 | (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | ||
989 | 979 | ||
990 | default: | 980 | if (mlen != 0) |
991 | GNUNET_break_op(0); | 981 | { |
992 | GNUNET_STATISTICS_update( | 982 | /* sender did not strip ICMP payload? */ |
993 | stats, | 983 | GNUNET_break_op (0); |
994 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
995 | 1, | ||
996 | GNUNET_NO); | ||
997 | return; | 984 | return; |
998 | } | 985 | } |
999 | /* end AF_INET */ | 986 | size += sizeof(struct GNUNET_TUN_IPv6Header) + 8; |
987 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
988 | make_up_icmpv6_payload (ts, ipp, udp); | ||
989 | } | ||
1000 | break; | 990 | break; |
1001 | 991 | ||
1002 | case AF_INET6: | 992 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
1003 | switch (icmp->type) | 993 | GNUNET_STATISTICS_update ( |
994 | stats, | ||
995 | gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), | ||
996 | 1, | ||
997 | GNUNET_NO); | ||
998 | return; | ||
999 | |||
1000 | default: | ||
1001 | GNUNET_break_op (0); | ||
1002 | GNUNET_STATISTICS_update ( | ||
1003 | stats, | ||
1004 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), | ||
1005 | 1, | ||
1006 | GNUNET_NO); | ||
1007 | return; | ||
1008 | } | ||
1009 | /* end AF_INET */ | ||
1010 | break; | ||
1011 | |||
1012 | case AF_INET6: | ||
1013 | switch (icmp->type) | ||
1014 | { | ||
1015 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | ||
1016 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
1017 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
1018 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: { | ||
1019 | struct GNUNET_TUN_IPv6Header *ipp = | ||
1020 | (struct GNUNET_TUN_IPv6Header *) &icmp[1]; | ||
1021 | struct GNUNET_TUN_UdpHeader *udp = | ||
1022 | (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | ||
1023 | |||
1024 | if (mlen != 0) | ||
1004 | { | 1025 | { |
1005 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | 1026 | /* sender did not strip ICMP payload? */ |
1006 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | 1027 | GNUNET_break_op (0); |
1007 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
1008 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: { | ||
1009 | struct GNUNET_TUN_IPv6Header *ipp = | ||
1010 | (struct GNUNET_TUN_IPv6Header *)&icmp[1]; | ||
1011 | struct GNUNET_TUN_UdpHeader *udp = | ||
1012 | (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
1013 | |||
1014 | if (mlen != 0) | ||
1015 | { | ||
1016 | /* sender did not strip ICMP payload? */ | ||
1017 | GNUNET_break_op(0); | ||
1018 | return; | ||
1019 | } | ||
1020 | size += sizeof(struct GNUNET_TUN_IPv6Header) + 8; | ||
1021 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
1022 | make_up_icmpv6_payload(ts, ipp, udp); | ||
1023 | } | ||
1024 | break; | ||
1025 | |||
1026 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
1027 | break; | ||
1028 | |||
1029 | default: | ||
1030 | GNUNET_break_op(0); | ||
1031 | GNUNET_STATISTICS_update( | ||
1032 | stats, | ||
1033 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
1034 | 1, | ||
1035 | GNUNET_NO); | ||
1036 | return; | 1028 | return; |
1037 | } | 1029 | } |
1038 | /* end AF_INET6 */ | 1030 | size += sizeof(struct GNUNET_TUN_IPv6Header) + 8; |
1031 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
1032 | make_up_icmpv6_payload (ts, ipp, udp); | ||
1033 | } | ||
1034 | break; | ||
1035 | |||
1036 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
1039 | break; | 1037 | break; |
1040 | 1038 | ||
1041 | default: | 1039 | default: |
1042 | GNUNET_break_op(0); | 1040 | GNUNET_break_op (0); |
1041 | GNUNET_STATISTICS_update ( | ||
1042 | stats, | ||
1043 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), | ||
1044 | 1, | ||
1045 | GNUNET_NO); | ||
1043 | return; | 1046 | return; |
1044 | } | 1047 | } |
1045 | msg->size = htons(size); | 1048 | /* end AF_INET6 */ |
1046 | GNUNET_TUN_calculate_icmp_checksum(icmp, &i2v[1], mlen); | 1049 | break; |
1047 | (void)GNUNET_HELPER_send(helper_handle, msg, GNUNET_YES, NULL, NULL); | 1050 | |
1051 | default: | ||
1052 | GNUNET_break_op (0); | ||
1053 | return; | ||
1054 | } | ||
1055 | msg->size = htons (size); | ||
1056 | GNUNET_TUN_calculate_icmp_checksum (icmp, &i2v[1], mlen); | ||
1057 | (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); | ||
1048 | } | 1058 | } |
1049 | } | 1059 | } |
1050 | break; | 1060 | break; |
1051 | 1061 | ||
1052 | default: | 1062 | default: |
1053 | GNUNET_assert(0); | 1063 | GNUNET_assert (0); |
1054 | } | 1064 | } |
1055 | GNUNET_CONTAINER_heap_update_cost(ts->heap_node, | 1065 | GNUNET_CONTAINER_heap_update_cost (ts->heap_node, |
1056 | GNUNET_TIME_absolute_get().abs_value_us); | 1066 | GNUNET_TIME_absolute_get ().abs_value_us); |
1057 | GNUNET_CADET_receive_done(ts->channel); | 1067 | GNUNET_CADET_receive_done (ts->channel); |
1058 | } | 1068 | } |
1059 | 1069 | ||
1060 | 1070 | ||
@@ -1067,20 +1077,20 @@ handle_icmp_back(void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) | |||
1067 | * #GNUNET_SYSERR to close it (signal serious error) | 1077 | * #GNUNET_SYSERR to close it (signal serious error) |
1068 | */ | 1078 | */ |
1069 | static int | 1079 | static int |
1070 | check_udp_back(void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) | 1080 | check_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) |
1071 | { | 1081 | { |
1072 | struct ChannelState *ts = cls; | 1082 | struct ChannelState *ts = cls; |
1073 | 1083 | ||
1074 | if (NULL == ts->heap_node) | 1084 | if (NULL == ts->heap_node) |
1075 | { | 1085 | { |
1076 | GNUNET_break_op(0); | 1086 | GNUNET_break_op (0); |
1077 | return GNUNET_SYSERR; | 1087 | return GNUNET_SYSERR; |
1078 | } | 1088 | } |
1079 | if (AF_UNSPEC == ts->af) | 1089 | if (AF_UNSPEC == ts->af) |
1080 | { | 1090 | { |
1081 | GNUNET_break_op(0); | 1091 | GNUNET_break_op (0); |
1082 | return GNUNET_SYSERR; | 1092 | return GNUNET_SYSERR; |
1083 | } | 1093 | } |
1084 | return GNUNET_OK; | 1094 | return GNUNET_OK; |
1085 | } | 1095 | } |
1086 | 1096 | ||
@@ -1093,118 +1103,118 @@ check_udp_back(void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) | |||
1093 | * @param reply the actual message | 1103 | * @param reply the actual message |
1094 | */ | 1104 | */ |
1095 | static void | 1105 | static void |
1096 | handle_udp_back(void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) | 1106 | handle_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) |
1097 | { | 1107 | { |
1098 | struct ChannelState *ts = cls; | 1108 | struct ChannelState *ts = cls; |
1099 | size_t mlen; | 1109 | size_t mlen; |
1100 | 1110 | ||
1101 | GNUNET_STATISTICS_update(stats, | 1111 | GNUNET_STATISTICS_update (stats, |
1102 | gettext_noop("# UDP packets received from cadet"), | 1112 | gettext_noop ("# UDP packets received from cadet"), |
1103 | 1, | 1113 | 1, |
1104 | GNUNET_NO); | 1114 | GNUNET_NO); |
1105 | mlen = | 1115 | mlen = |
1106 | ntohs(reply->header.size) - sizeof(struct GNUNET_EXIT_UdpReplyMessage); | 1116 | ntohs (reply->header.size) - sizeof(struct GNUNET_EXIT_UdpReplyMessage); |
1107 | { | 1117 | { |
1108 | char sbuf[INET6_ADDRSTRLEN]; | 1118 | char sbuf[INET6_ADDRSTRLEN]; |
1109 | char dbuf[INET6_ADDRSTRLEN]; | 1119 | char dbuf[INET6_ADDRSTRLEN]; |
1110 | 1120 | ||
1111 | GNUNET_log( | 1121 | GNUNET_log ( |
1112 | GNUNET_ERROR_TYPE_DEBUG, | 1122 | GNUNET_ERROR_TYPE_DEBUG, |
1113 | "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", | 1123 | "Received UDP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", |
1114 | (unsigned int)mlen, | 1124 | (unsigned int) mlen, |
1115 | inet_ntop(ts->af, &ts->destination_ip, sbuf, sizeof(sbuf)), | 1125 | inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof(sbuf)), |
1116 | ts->destination_port, | 1126 | ts->destination_port, |
1117 | inet_ntop(ts->af, &ts->source_ip, dbuf, sizeof(dbuf)), | 1127 | inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof(dbuf)), |
1118 | ts->source_port); | 1128 | ts->source_port); |
1119 | } | 1129 | } |
1120 | switch (ts->af) | 1130 | switch (ts->af) |
1121 | { | 1131 | { |
1122 | case AF_INET: { | 1132 | case AF_INET: { |
1123 | size_t size = sizeof(struct GNUNET_TUN_IPv4Header) + | 1133 | size_t size = sizeof(struct GNUNET_TUN_IPv4Header) |
1124 | sizeof(struct GNUNET_TUN_UdpHeader) + | 1134 | + sizeof(struct GNUNET_TUN_UdpHeader) |
1125 | sizeof(struct GNUNET_MessageHeader) + | 1135 | + sizeof(struct GNUNET_MessageHeader) |
1126 | sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; | 1136 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; |
1127 | { | 1137 | { |
1128 | char buf[size] GNUNET_ALIGN; | 1138 | char buf[size] GNUNET_ALIGN; |
1129 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)buf; | 1139 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; |
1130 | struct GNUNET_TUN_Layer2PacketHeader *tun = | 1140 | struct GNUNET_TUN_Layer2PacketHeader *tun = |
1131 | (struct GNUNET_TUN_Layer2PacketHeader *)&msg[1]; | 1141 | (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; |
1132 | struct GNUNET_TUN_IPv4Header *ipv4 = | 1142 | struct GNUNET_TUN_IPv4Header *ipv4 = |
1133 | (struct GNUNET_TUN_IPv4Header *)&tun[1]; | 1143 | (struct GNUNET_TUN_IPv4Header *) &tun[1]; |
1134 | struct GNUNET_TUN_UdpHeader *udp = | 1144 | struct GNUNET_TUN_UdpHeader *udp = |
1135 | (struct GNUNET_TUN_UdpHeader *)&ipv4[1]; | 1145 | (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; |
1136 | msg->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1146 | msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1137 | msg->size = htons(size); | 1147 | msg->size = htons (size); |
1138 | tun->flags = htons(0); | 1148 | tun->flags = htons (0); |
1139 | tun->proto = htons(ETH_P_IPV4); | 1149 | tun->proto = htons (ETH_P_IPV4); |
1140 | GNUNET_TUN_initialize_ipv4_header(ipv4, | 1150 | GNUNET_TUN_initialize_ipv4_header (ipv4, |
1141 | IPPROTO_UDP, | 1151 | IPPROTO_UDP, |
1142 | sizeof(struct GNUNET_TUN_UdpHeader) + | 1152 | sizeof(struct GNUNET_TUN_UdpHeader) |
1143 | mlen, | 1153 | + mlen, |
1144 | &ts->destination_ip.v4, | 1154 | &ts->destination_ip.v4, |
1145 | &ts->source_ip.v4); | 1155 | &ts->source_ip.v4); |
1146 | if (0 == ntohs(reply->source_port)) | 1156 | if (0 == ntohs (reply->source_port)) |
1147 | udp->source_port = htons(ts->destination_port); | 1157 | udp->source_port = htons (ts->destination_port); |
1148 | else | 1158 | else |
1149 | udp->source_port = reply->source_port; | 1159 | udp->source_port = reply->source_port; |
1150 | if (0 == ntohs(reply->destination_port)) | 1160 | if (0 == ntohs (reply->destination_port)) |
1151 | udp->destination_port = htons(ts->source_port); | 1161 | udp->destination_port = htons (ts->source_port); |
1152 | else | 1162 | else |
1153 | udp->destination_port = reply->destination_port; | 1163 | udp->destination_port = reply->destination_port; |
1154 | udp->len = htons(mlen + sizeof(struct GNUNET_TUN_UdpHeader)); | 1164 | udp->len = htons (mlen + sizeof(struct GNUNET_TUN_UdpHeader)); |
1155 | GNUNET_TUN_calculate_udp4_checksum(ipv4, udp, &reply[1], mlen); | 1165 | GNUNET_TUN_calculate_udp4_checksum (ipv4, udp, &reply[1], mlen); |
1156 | GNUNET_memcpy(&udp[1], &reply[1], mlen); | 1166 | GNUNET_memcpy (&udp[1], &reply[1], mlen); |
1157 | (void)GNUNET_HELPER_send(helper_handle, msg, GNUNET_YES, NULL, NULL); | 1167 | (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); |
1158 | } | 1168 | } |
1159 | } | 1169 | } |
1160 | break; | 1170 | break; |
1161 | 1171 | ||
1162 | case AF_INET6: { | 1172 | case AF_INET6: { |
1163 | size_t size = sizeof(struct GNUNET_TUN_IPv6Header) + | 1173 | size_t size = sizeof(struct GNUNET_TUN_IPv6Header) |
1164 | sizeof(struct GNUNET_TUN_UdpHeader) + | 1174 | + sizeof(struct GNUNET_TUN_UdpHeader) |
1165 | sizeof(struct GNUNET_MessageHeader) + | 1175 | + sizeof(struct GNUNET_MessageHeader) |
1166 | sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; | 1176 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; |
1167 | { | 1177 | { |
1168 | char buf[size] GNUNET_ALIGN; | 1178 | char buf[size] GNUNET_ALIGN; |
1169 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)buf; | 1179 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; |
1170 | struct GNUNET_TUN_Layer2PacketHeader *tun = | 1180 | struct GNUNET_TUN_Layer2PacketHeader *tun = |
1171 | (struct GNUNET_TUN_Layer2PacketHeader *)&msg[1]; | 1181 | (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; |
1172 | struct GNUNET_TUN_IPv6Header *ipv6 = | 1182 | struct GNUNET_TUN_IPv6Header *ipv6 = |
1173 | (struct GNUNET_TUN_IPv6Header *)&tun[1]; | 1183 | (struct GNUNET_TUN_IPv6Header *) &tun[1]; |
1174 | struct GNUNET_TUN_UdpHeader *udp = | 1184 | struct GNUNET_TUN_UdpHeader *udp = |
1175 | (struct GNUNET_TUN_UdpHeader *)&ipv6[1]; | 1185 | (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; |
1176 | msg->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1186 | msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1177 | msg->size = htons(size); | 1187 | msg->size = htons (size); |
1178 | tun->flags = htons(0); | 1188 | tun->flags = htons (0); |
1179 | tun->proto = htons(ETH_P_IPV6); | 1189 | tun->proto = htons (ETH_P_IPV6); |
1180 | GNUNET_TUN_initialize_ipv6_header(ipv6, | 1190 | GNUNET_TUN_initialize_ipv6_header (ipv6, |
1181 | IPPROTO_UDP, | 1191 | IPPROTO_UDP, |
1182 | sizeof(struct GNUNET_TUN_UdpHeader) + | 1192 | sizeof(struct GNUNET_TUN_UdpHeader) |
1183 | mlen, | 1193 | + mlen, |
1184 | &ts->destination_ip.v6, | 1194 | &ts->destination_ip.v6, |
1185 | &ts->source_ip.v6); | 1195 | &ts->source_ip.v6); |
1186 | if (0 == ntohs(reply->source_port)) | 1196 | if (0 == ntohs (reply->source_port)) |
1187 | udp->source_port = htons(ts->destination_port); | 1197 | udp->source_port = htons (ts->destination_port); |
1188 | else | 1198 | else |
1189 | udp->source_port = reply->source_port; | 1199 | udp->source_port = reply->source_port; |
1190 | if (0 == ntohs(reply->destination_port)) | 1200 | if (0 == ntohs (reply->destination_port)) |
1191 | udp->destination_port = htons(ts->source_port); | 1201 | udp->destination_port = htons (ts->source_port); |
1192 | else | 1202 | else |
1193 | udp->destination_port = reply->destination_port; | 1203 | udp->destination_port = reply->destination_port; |
1194 | udp->len = htons(mlen + sizeof(struct GNUNET_TUN_UdpHeader)); | 1204 | udp->len = htons (mlen + sizeof(struct GNUNET_TUN_UdpHeader)); |
1195 | GNUNET_TUN_calculate_udp6_checksum(ipv6, udp, &reply[1], mlen); | 1205 | GNUNET_TUN_calculate_udp6_checksum (ipv6, udp, &reply[1], mlen); |
1196 | GNUNET_memcpy(&udp[1], &reply[1], mlen); | 1206 | GNUNET_memcpy (&udp[1], &reply[1], mlen); |
1197 | (void)GNUNET_HELPER_send(helper_handle, msg, GNUNET_YES, NULL, NULL); | 1207 | (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); |
1198 | } | 1208 | } |
1199 | } | 1209 | } |
1200 | break; | 1210 | break; |
1201 | 1211 | ||
1202 | default: | 1212 | default: |
1203 | GNUNET_assert(0); | 1213 | GNUNET_assert (0); |
1204 | } | 1214 | } |
1205 | GNUNET_CONTAINER_heap_update_cost(ts->heap_node, | 1215 | GNUNET_CONTAINER_heap_update_cost (ts->heap_node, |
1206 | GNUNET_TIME_absolute_get().abs_value_us); | 1216 | GNUNET_TIME_absolute_get ().abs_value_us); |
1207 | GNUNET_CADET_receive_done(ts->channel); | 1217 | GNUNET_CADET_receive_done (ts->channel); |
1208 | } | 1218 | } |
1209 | 1219 | ||
1210 | 1220 | ||
@@ -1217,20 +1227,20 @@ handle_udp_back(void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) | |||
1217 | * #GNUNET_SYSERR to close it (signal serious error) | 1227 | * #GNUNET_SYSERR to close it (signal serious error) |
1218 | */ | 1228 | */ |
1219 | static int | 1229 | static int |
1220 | check_tcp_back(void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) | 1230 | check_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) |
1221 | { | 1231 | { |
1222 | struct ChannelState *ts = cls; | 1232 | struct ChannelState *ts = cls; |
1223 | 1233 | ||
1224 | if (NULL == ts->heap_node) | 1234 | if (NULL == ts->heap_node) |
1225 | { | 1235 | { |
1226 | GNUNET_break_op(0); | 1236 | GNUNET_break_op (0); |
1227 | return GNUNET_SYSERR; | 1237 | return GNUNET_SYSERR; |
1228 | } | 1238 | } |
1229 | if (data->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) | 1239 | if (data->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
1230 | { | 1240 | { |
1231 | GNUNET_break_op(0); | 1241 | GNUNET_break_op (0); |
1232 | return GNUNET_SYSERR; | 1242 | return GNUNET_SYSERR; |
1233 | } | 1243 | } |
1234 | return GNUNET_OK; | 1244 | return GNUNET_OK; |
1235 | } | 1245 | } |
1236 | 1246 | ||
@@ -1243,102 +1253,102 @@ check_tcp_back(void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) | |||
1243 | * @param data the actual message | 1253 | * @param data the actual message |
1244 | */ | 1254 | */ |
1245 | static void | 1255 | static void |
1246 | handle_tcp_back(void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) | 1256 | handle_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) |
1247 | { | 1257 | { |
1248 | struct ChannelState *ts = cls; | 1258 | struct ChannelState *ts = cls; |
1249 | size_t mlen; | 1259 | size_t mlen; |
1250 | 1260 | ||
1251 | GNUNET_STATISTICS_update(stats, | 1261 | GNUNET_STATISTICS_update (stats, |
1252 | gettext_noop("# TCP packets received from cadet"), | 1262 | gettext_noop ("# TCP packets received from cadet"), |
1253 | 1, | 1263 | 1, |
1254 | GNUNET_NO); | 1264 | GNUNET_NO); |
1255 | mlen = ntohs(data->header.size) - sizeof(struct GNUNET_EXIT_TcpDataMessage); | 1265 | mlen = ntohs (data->header.size) - sizeof(struct GNUNET_EXIT_TcpDataMessage); |
1256 | { | 1266 | { |
1257 | char sbuf[INET6_ADDRSTRLEN]; | 1267 | char sbuf[INET6_ADDRSTRLEN]; |
1258 | char dbuf[INET6_ADDRSTRLEN]; | 1268 | char dbuf[INET6_ADDRSTRLEN]; |
1259 | 1269 | ||
1260 | GNUNET_log( | 1270 | GNUNET_log ( |
1261 | GNUNET_ERROR_TYPE_DEBUG, | 1271 | GNUNET_ERROR_TYPE_DEBUG, |
1262 | "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", | 1272 | "Received TCP reply from cadet, sending %u bytes from [%s]:%u -> [%s]:%u via TUN\n", |
1263 | (unsigned int)mlen, | 1273 | (unsigned int) mlen, |
1264 | inet_ntop(ts->af, &ts->destination_ip, sbuf, sizeof(sbuf)), | 1274 | inet_ntop (ts->af, &ts->destination_ip, sbuf, sizeof(sbuf)), |
1265 | ts->destination_port, | 1275 | ts->destination_port, |
1266 | inet_ntop(ts->af, &ts->source_ip, dbuf, sizeof(dbuf)), | 1276 | inet_ntop (ts->af, &ts->source_ip, dbuf, sizeof(dbuf)), |
1267 | ts->source_port); | 1277 | ts->source_port); |
1268 | } | 1278 | } |
1269 | switch (ts->af) | 1279 | switch (ts->af) |
1270 | { | 1280 | { |
1271 | case AF_INET: { | 1281 | case AF_INET: { |
1272 | size_t size = sizeof(struct GNUNET_TUN_IPv4Header) + | 1282 | size_t size = sizeof(struct GNUNET_TUN_IPv4Header) |
1273 | sizeof(struct GNUNET_TUN_TcpHeader) + | 1283 | + sizeof(struct GNUNET_TUN_TcpHeader) |
1274 | sizeof(struct GNUNET_MessageHeader) + | 1284 | + sizeof(struct GNUNET_MessageHeader) |
1275 | sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; | 1285 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; |
1276 | { | 1286 | { |
1277 | char buf[size] GNUNET_ALIGN; | 1287 | char buf[size] GNUNET_ALIGN; |
1278 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)buf; | 1288 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; |
1279 | struct GNUNET_TUN_Layer2PacketHeader *tun = | 1289 | struct GNUNET_TUN_Layer2PacketHeader *tun = |
1280 | (struct GNUNET_TUN_Layer2PacketHeader *)&msg[1]; | 1290 | (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; |
1281 | struct GNUNET_TUN_IPv4Header *ipv4 = | 1291 | struct GNUNET_TUN_IPv4Header *ipv4 = |
1282 | (struct GNUNET_TUN_IPv4Header *)&tun[1]; | 1292 | (struct GNUNET_TUN_IPv4Header *) &tun[1]; |
1283 | struct GNUNET_TUN_TcpHeader *tcp = | 1293 | struct GNUNET_TUN_TcpHeader *tcp = |
1284 | (struct GNUNET_TUN_TcpHeader *)&ipv4[1]; | 1294 | (struct GNUNET_TUN_TcpHeader *) &ipv4[1]; |
1285 | msg->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1295 | msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1286 | msg->size = htons(size); | 1296 | msg->size = htons (size); |
1287 | tun->flags = htons(0); | 1297 | tun->flags = htons (0); |
1288 | tun->proto = htons(ETH_P_IPV4); | 1298 | tun->proto = htons (ETH_P_IPV4); |
1289 | GNUNET_TUN_initialize_ipv4_header(ipv4, | 1299 | GNUNET_TUN_initialize_ipv4_header (ipv4, |
1290 | IPPROTO_TCP, | 1300 | IPPROTO_TCP, |
1291 | sizeof(struct GNUNET_TUN_TcpHeader) + | 1301 | sizeof(struct GNUNET_TUN_TcpHeader) |
1292 | mlen, | 1302 | + mlen, |
1293 | &ts->destination_ip.v4, | 1303 | &ts->destination_ip.v4, |
1294 | &ts->source_ip.v4); | 1304 | &ts->source_ip.v4); |
1295 | *tcp = data->tcp_header; | 1305 | *tcp = data->tcp_header; |
1296 | tcp->source_port = htons(ts->destination_port); | 1306 | tcp->source_port = htons (ts->destination_port); |
1297 | tcp->destination_port = htons(ts->source_port); | 1307 | tcp->destination_port = htons (ts->source_port); |
1298 | GNUNET_TUN_calculate_tcp4_checksum(ipv4, tcp, &data[1], mlen); | 1308 | GNUNET_TUN_calculate_tcp4_checksum (ipv4, tcp, &data[1], mlen); |
1299 | GNUNET_memcpy(&tcp[1], &data[1], mlen); | 1309 | GNUNET_memcpy (&tcp[1], &data[1], mlen); |
1300 | (void)GNUNET_HELPER_send(helper_handle, msg, GNUNET_YES, NULL, NULL); | 1310 | (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); |
1301 | } | 1311 | } |
1302 | } | 1312 | } |
1303 | break; | 1313 | break; |
1304 | 1314 | ||
1305 | case AF_INET6: { | 1315 | case AF_INET6: { |
1306 | size_t size = sizeof(struct GNUNET_TUN_IPv6Header) + | 1316 | size_t size = sizeof(struct GNUNET_TUN_IPv6Header) |
1307 | sizeof(struct GNUNET_TUN_TcpHeader) + | 1317 | + sizeof(struct GNUNET_TUN_TcpHeader) |
1308 | sizeof(struct GNUNET_MessageHeader) + | 1318 | + sizeof(struct GNUNET_MessageHeader) |
1309 | sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; | 1319 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader) + mlen; |
1310 | { | 1320 | { |
1311 | char buf[size] GNUNET_ALIGN; | 1321 | char buf[size] GNUNET_ALIGN; |
1312 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *)buf; | 1322 | struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) buf; |
1313 | struct GNUNET_TUN_Layer2PacketHeader *tun = | 1323 | struct GNUNET_TUN_Layer2PacketHeader *tun = |
1314 | (struct GNUNET_TUN_Layer2PacketHeader *)&msg[1]; | 1324 | (struct GNUNET_TUN_Layer2PacketHeader *) &msg[1]; |
1315 | struct GNUNET_TUN_IPv6Header *ipv6 = | 1325 | struct GNUNET_TUN_IPv6Header *ipv6 = |
1316 | (struct GNUNET_TUN_IPv6Header *)&tun[1]; | 1326 | (struct GNUNET_TUN_IPv6Header *) &tun[1]; |
1317 | struct GNUNET_TUN_TcpHeader *tcp = | 1327 | struct GNUNET_TUN_TcpHeader *tcp = |
1318 | (struct GNUNET_TUN_TcpHeader *)&ipv6[1]; | 1328 | (struct GNUNET_TUN_TcpHeader *) &ipv6[1]; |
1319 | msg->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1329 | msg->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1320 | msg->size = htons(size); | 1330 | msg->size = htons (size); |
1321 | tun->flags = htons(0); | 1331 | tun->flags = htons (0); |
1322 | tun->proto = htons(ETH_P_IPV6); | 1332 | tun->proto = htons (ETH_P_IPV6); |
1323 | GNUNET_TUN_initialize_ipv6_header(ipv6, | 1333 | GNUNET_TUN_initialize_ipv6_header (ipv6, |
1324 | IPPROTO_TCP, | 1334 | IPPROTO_TCP, |
1325 | sizeof(struct GNUNET_TUN_TcpHeader) + | 1335 | sizeof(struct GNUNET_TUN_TcpHeader) |
1326 | mlen, | 1336 | + mlen, |
1327 | &ts->destination_ip.v6, | 1337 | &ts->destination_ip.v6, |
1328 | &ts->source_ip.v6); | 1338 | &ts->source_ip.v6); |
1329 | *tcp = data->tcp_header; | 1339 | *tcp = data->tcp_header; |
1330 | tcp->source_port = htons(ts->destination_port); | 1340 | tcp->source_port = htons (ts->destination_port); |
1331 | tcp->destination_port = htons(ts->source_port); | 1341 | tcp->destination_port = htons (ts->source_port); |
1332 | GNUNET_TUN_calculate_tcp6_checksum(ipv6, tcp, &data[1], mlen); | 1342 | GNUNET_TUN_calculate_tcp6_checksum (ipv6, tcp, &data[1], mlen); |
1333 | GNUNET_memcpy(&tcp[1], &data[1], mlen); | 1343 | GNUNET_memcpy (&tcp[1], &data[1], mlen); |
1334 | (void)GNUNET_HELPER_send(helper_handle, msg, GNUNET_YES, NULL, NULL); | 1344 | (void) GNUNET_HELPER_send (helper_handle, msg, GNUNET_YES, NULL, NULL); |
1335 | } | 1345 | } |
1336 | } | 1346 | } |
1337 | break; | 1347 | break; |
1338 | } | 1348 | } |
1339 | GNUNET_CONTAINER_heap_update_cost(ts->heap_node, | 1349 | GNUNET_CONTAINER_heap_update_cost (ts->heap_node, |
1340 | GNUNET_TIME_absolute_get().abs_value_us); | 1350 | GNUNET_TIME_absolute_get ().abs_value_us); |
1341 | GNUNET_CADET_receive_done(ts->channel); | 1351 | GNUNET_CADET_receive_done (ts->channel); |
1342 | } | 1352 | } |
1343 | 1353 | ||
1344 | 1354 | ||
@@ -1351,32 +1361,32 @@ handle_tcp_back(void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) | |||
1351 | * @return the channel handle | 1361 | * @return the channel handle |
1352 | */ | 1362 | */ |
1353 | static struct GNUNET_CADET_Channel * | 1363 | static struct GNUNET_CADET_Channel * |
1354 | create_channel(struct ChannelState *ts, | 1364 | create_channel (struct ChannelState *ts, |
1355 | const struct GNUNET_PeerIdentity *target, | 1365 | const struct GNUNET_PeerIdentity *target, |
1356 | const struct GNUNET_HashCode *port) | 1366 | const struct GNUNET_HashCode *port) |
1357 | { | 1367 | { |
1358 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1368 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1359 | { GNUNET_MQ_hd_var_size(udp_back, | 1369 | { GNUNET_MQ_hd_var_size (udp_back, |
1360 | GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, | 1370 | GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, |
1361 | struct GNUNET_EXIT_UdpReplyMessage, | 1371 | struct GNUNET_EXIT_UdpReplyMessage, |
1362 | ts), | 1372 | ts), |
1363 | GNUNET_MQ_hd_var_size(tcp_back, | 1373 | GNUNET_MQ_hd_var_size (tcp_back, |
1364 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, | 1374 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, |
1365 | struct GNUNET_EXIT_TcpDataMessage, | 1375 | struct GNUNET_EXIT_TcpDataMessage, |
1366 | ts), | 1376 | ts), |
1367 | GNUNET_MQ_hd_var_size(icmp_back, | 1377 | GNUNET_MQ_hd_var_size (icmp_back, |
1368 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, | 1378 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, |
1369 | struct GNUNET_EXIT_IcmpToVPNMessage, | 1379 | struct GNUNET_EXIT_IcmpToVPNMessage, |
1370 | ts), | 1380 | ts), |
1371 | GNUNET_MQ_handler_end() }; | 1381 | GNUNET_MQ_handler_end () }; |
1372 | 1382 | ||
1373 | return GNUNET_CADET_channel_create(cadet_handle, | 1383 | return GNUNET_CADET_channel_create (cadet_handle, |
1374 | ts, | 1384 | ts, |
1375 | target, | 1385 | target, |
1376 | port, | 1386 | port, |
1377 | NULL, | 1387 | NULL, |
1378 | &channel_cleaner, | 1388 | &channel_cleaner, |
1379 | cadet_handlers); | 1389 | cadet_handlers); |
1380 | } | 1390 | } |
1381 | 1391 | ||
1382 | 1392 | ||
@@ -1391,47 +1401,47 @@ create_channel(struct ChannelState *ts, | |||
1391 | * @param put_path_length Length of the @a put_path. | 1401 | * @param put_path_length Length of the @a put_path. |
1392 | */ | 1402 | */ |
1393 | static void | 1403 | static void |
1394 | handle_regex_result(void *cls, | 1404 | handle_regex_result (void *cls, |
1395 | const struct GNUNET_PeerIdentity *id, | 1405 | const struct GNUNET_PeerIdentity *id, |
1396 | const struct GNUNET_PeerIdentity *get_path, | 1406 | const struct GNUNET_PeerIdentity *get_path, |
1397 | unsigned int get_path_length, | 1407 | unsigned int get_path_length, |
1398 | const struct GNUNET_PeerIdentity *put_path, | 1408 | const struct GNUNET_PeerIdentity *put_path, |
1399 | unsigned int put_path_length) | 1409 | unsigned int put_path_length) |
1400 | { | 1410 | { |
1401 | struct ChannelState *ts = cls; | 1411 | struct ChannelState *ts = cls; |
1402 | struct GNUNET_HashCode port; | 1412 | struct GNUNET_HashCode port; |
1403 | 1413 | ||
1404 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1414 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1405 | "Exit %s found for destination %s!\n", | 1415 | "Exit %s found for destination %s!\n", |
1406 | GNUNET_i2s(id), | 1416 | GNUNET_i2s (id), |
1407 | print_channel_destination(&ts->destination)); | 1417 | print_channel_destination (&ts->destination)); |
1408 | GNUNET_REGEX_search_cancel(ts->search); | 1418 | GNUNET_REGEX_search_cancel (ts->search); |
1409 | ts->search = NULL; | 1419 | ts->search = NULL; |
1410 | switch (ts->af) | 1420 | switch (ts->af) |
1411 | { | 1421 | { |
1412 | case AF_INET: | 1422 | case AF_INET: |
1413 | /* these must match the strings used in gnunet-daemon-exit */ | 1423 | /* these must match the strings used in gnunet-daemon-exit */ |
1414 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_IPV4_GATEWAY, | 1424 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV4_GATEWAY, |
1415 | strlen(GNUNET_APPLICATION_PORT_IPV4_GATEWAY), | 1425 | strlen (GNUNET_APPLICATION_PORT_IPV4_GATEWAY), |
1416 | &port); | 1426 | &port); |
1417 | break; | 1427 | break; |
1418 | 1428 | ||
1419 | case AF_INET6: | 1429 | case AF_INET6: |
1420 | /* these must match the strings used in gnunet-daemon-exit */ | 1430 | /* these must match the strings used in gnunet-daemon-exit */ |
1421 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_IPV6_GATEWAY, | 1431 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV6_GATEWAY, |
1422 | strlen(GNUNET_APPLICATION_PORT_IPV6_GATEWAY), | 1432 | strlen (GNUNET_APPLICATION_PORT_IPV6_GATEWAY), |
1423 | &port); | 1433 | &port); |
1424 | break; | 1434 | break; |
1425 | 1435 | ||
1426 | default: | 1436 | default: |
1427 | GNUNET_break(0); | 1437 | GNUNET_break (0); |
1428 | return; | 1438 | return; |
1429 | } | 1439 | } |
1430 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1440 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1431 | "Creating tunnel to %s for destination %s!\n", | 1441 | "Creating tunnel to %s for destination %s!\n", |
1432 | GNUNET_i2s(id), | 1442 | GNUNET_i2s (id), |
1433 | print_channel_destination(&ts->destination)); | 1443 | print_channel_destination (&ts->destination)); |
1434 | ts->channel = create_channel(ts, id, &port); | 1444 | ts->channel = create_channel (ts, id, &port); |
1435 | } | 1445 | } |
1436 | 1446 | ||
1437 | 1447 | ||
@@ -1443,92 +1453,92 @@ handle_regex_result(void *cls, | |||
1443 | * @return channel state of the channel that was created | 1453 | * @return channel state of the channel that was created |
1444 | */ | 1454 | */ |
1445 | static struct ChannelState * | 1455 | static struct ChannelState * |
1446 | create_channel_to_destination(struct DestinationChannel *dt, int client_af) | 1456 | create_channel_to_destination (struct DestinationChannel *dt, int client_af) |
1447 | { | 1457 | { |
1448 | struct ChannelState *ts; | 1458 | struct ChannelState *ts; |
1449 | 1459 | ||
1450 | GNUNET_STATISTICS_update(stats, | 1460 | GNUNET_STATISTICS_update (stats, |
1451 | gettext_noop("# Cadet channels created"), | 1461 | gettext_noop ("# Cadet channels created"), |
1452 | 1, | 1462 | 1, |
1453 | GNUNET_NO); | 1463 | GNUNET_NO); |
1454 | ts = GNUNET_new(struct ChannelState); | 1464 | ts = GNUNET_new (struct ChannelState); |
1455 | ts->af = client_af; | 1465 | ts->af = client_af; |
1456 | ts->destination = *dt->destination; | 1466 | ts->destination = *dt->destination; |
1457 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ | 1467 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ |
1458 | ts->destination_port = dt->destination_port; | 1468 | ts->destination_port = dt->destination_port; |
1459 | if (dt->destination->is_service) | 1469 | if (dt->destination->is_service) |
1470 | { | ||
1471 | struct GNUNET_HashCode cadet_port; | ||
1472 | |||
1473 | GNUNET_TUN_compute_service_cadet_port (&ts->destination.details | ||
1474 | .service_destination | ||
1475 | .service_descriptor, | ||
1476 | ts->destination_port, | ||
1477 | &cadet_port); | ||
1478 | ts->channel = | ||
1479 | create_channel (ts, | ||
1480 | &dt->destination->details.service_destination.target, | ||
1481 | &cadet_port); | ||
1482 | |||
1483 | if (NULL == ts->channel) | ||
1460 | { | 1484 | { |
1461 | struct GNUNET_HashCode cadet_port; | 1485 | GNUNET_break (0); |
1462 | 1486 | GNUNET_free (ts); | |
1463 | GNUNET_TUN_compute_service_cadet_port(&ts->destination.details | 1487 | return NULL; |
1464 | .service_destination | 1488 | } |
1465 | .service_descriptor, | 1489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1466 | ts->destination_port, | 1490 | "Creating channel to peer %s offering service %s on port %u\n", |
1467 | &cadet_port); | 1491 | GNUNET_i2s ( |
1468 | ts->channel = | 1492 | &dt->destination->details.service_destination.target), |
1469 | create_channel(ts, | 1493 | GNUNET_h2s (&ts->destination.details.service_destination |
1470 | &dt->destination->details.service_destination.target, | ||
1471 | &cadet_port); | ||
1472 | |||
1473 | if (NULL == ts->channel) | ||
1474 | { | ||
1475 | GNUNET_break(0); | ||
1476 | GNUNET_free(ts); | ||
1477 | return NULL; | ||
1478 | } | ||
1479 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1480 | "Creating channel to peer %s offering service %s on port %u\n", | ||
1481 | GNUNET_i2s( | ||
1482 | &dt->destination->details.service_destination.target), | ||
1483 | GNUNET_h2s(&ts->destination.details.service_destination | ||
1484 | .service_descriptor), | 1494 | .service_descriptor), |
1485 | (unsigned int)ts->destination_port); | 1495 | (unsigned int) ts->destination_port); |
1486 | } | 1496 | } |
1487 | else | 1497 | else |
1488 | { | 1498 | { |
1489 | char *policy; | 1499 | char *policy; |
1490 | |||
1491 | switch (dt->destination->details.exit_destination.af) | ||
1492 | { | ||
1493 | case AF_INET: { | ||
1494 | char address[GNUNET_TUN_IPV4_REGEXLEN]; | ||
1495 | |||
1496 | GNUNET_TUN_ipv4toregexsearch(&dt->destination->details.exit_destination | ||
1497 | .ip.v4, | ||
1498 | dt->destination_port, | ||
1499 | address); | ||
1500 | GNUNET_asprintf(&policy, | ||
1501 | "%s%s", | ||
1502 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
1503 | address); | ||
1504 | break; | ||
1505 | } | ||
1506 | 1500 | ||
1507 | case AF_INET6: { | 1501 | switch (dt->destination->details.exit_destination.af) |
1508 | char address[GNUNET_TUN_IPV6_REGEXLEN]; | 1502 | { |
1509 | 1503 | case AF_INET: { | |
1510 | GNUNET_TUN_ipv6toregexsearch(&dt->destination->details.exit_destination | 1504 | char address[GNUNET_TUN_IPV4_REGEXLEN]; |
1511 | .ip.v6, | 1505 | |
1512 | dt->destination_port, | 1506 | GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination |
1513 | address); | 1507 | .ip.v4, |
1514 | GNUNET_asprintf(&policy, | 1508 | dt->destination_port, |
1515 | "%s%s", | 1509 | address); |
1516 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | 1510 | GNUNET_asprintf (&policy, |
1517 | address); | 1511 | "%s%s", |
1518 | break; | 1512 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
1519 | } | 1513 | address); |
1514 | break; | ||
1515 | } | ||
1520 | 1516 | ||
1521 | default: | 1517 | case AF_INET6: { |
1522 | GNUNET_assert(0); | 1518 | char address[GNUNET_TUN_IPV6_REGEXLEN]; |
1523 | break; | 1519 | |
1524 | } | 1520 | GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination |
1521 | .ip.v6, | ||
1522 | dt->destination_port, | ||
1523 | address); | ||
1524 | GNUNET_asprintf (&policy, | ||
1525 | "%s%s", | ||
1526 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
1527 | address); | ||
1528 | break; | ||
1529 | } | ||
1525 | 1530 | ||
1526 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1531 | default: |
1527 | "Requesting connect by string: %s\n", | 1532 | GNUNET_assert (0); |
1528 | policy); | 1533 | break; |
1529 | ts->search = GNUNET_REGEX_search(cfg, policy, &handle_regex_result, ts); | ||
1530 | GNUNET_free(policy); | ||
1531 | } | 1534 | } |
1535 | |||
1536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1537 | "Requesting connect by string: %s\n", | ||
1538 | policy); | ||
1539 | ts->search = GNUNET_REGEX_search (cfg, policy, &handle_regex_result, ts); | ||
1540 | GNUNET_free (policy); | ||
1541 | } | ||
1532 | return ts; | 1542 | return ts; |
1533 | } | 1543 | } |
1534 | 1544 | ||
@@ -1539,18 +1549,18 @@ create_channel_to_destination(struct DestinationChannel *dt, int client_af) | |||
1539 | * @param except channel that must NOT be cleaned up, even if it is the oldest | 1549 | * @param except channel that must NOT be cleaned up, even if it is the oldest |
1540 | */ | 1550 | */ |
1541 | static void | 1551 | static void |
1542 | expire_channel(struct ChannelState *except) | 1552 | expire_channel (struct ChannelState *except) |
1543 | { | 1553 | { |
1544 | struct ChannelState *ts; | 1554 | struct ChannelState *ts; |
1545 | 1555 | ||
1546 | ts = GNUNET_CONTAINER_heap_peek(channel_heap); | 1556 | ts = GNUNET_CONTAINER_heap_peek (channel_heap); |
1547 | GNUNET_assert(NULL != ts); | 1557 | GNUNET_assert (NULL != ts); |
1548 | if (except == ts) | 1558 | if (except == ts) |
1549 | return; /* can't do this */ | 1559 | return; /* can't do this */ |
1550 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1551 | "Tearing down expired channel to %s\n", | 1561 | "Tearing down expired channel to %s\n", |
1552 | print_channel_destination(&except->destination)); | 1562 | print_channel_destination (&except->destination)); |
1553 | free_channel_state(ts); | 1563 | free_channel_state (ts); |
1554 | } | 1564 | } |
1555 | 1565 | ||
1556 | 1566 | ||
@@ -1566,13 +1576,13 @@ expire_channel(struct ChannelState *except) | |||
1566 | * @param payload_length number of bytes in @a payload | 1576 | * @param payload_length number of bytes in @a payload |
1567 | */ | 1577 | */ |
1568 | static void | 1578 | static void |
1569 | route_packet(struct DestinationEntry *destination, | 1579 | route_packet (struct DestinationEntry *destination, |
1570 | int af, | 1580 | int af, |
1571 | uint8_t protocol, | 1581 | uint8_t protocol, |
1572 | const void *source_ip, | 1582 | const void *source_ip, |
1573 | const void *destination_ip, | 1583 | const void *destination_ip, |
1574 | const void *payload, | 1584 | const void *payload, |
1575 | size_t payload_length) | 1585 | size_t payload_length) |
1576 | { | 1586 | { |
1577 | struct GNUNET_HashCode key; | 1587 | struct GNUNET_HashCode key; |
1578 | struct ChannelState *ts; | 1588 | struct ChannelState *ts; |
@@ -1587,663 +1597,663 @@ route_packet(struct DestinationEntry *destination, | |||
1587 | uint16_t destination_port; | 1597 | uint16_t destination_port; |
1588 | 1598 | ||
1589 | switch (protocol) | 1599 | switch (protocol) |
1590 | { | 1600 | { |
1591 | case IPPROTO_UDP: { | 1601 | case IPPROTO_UDP: { |
1592 | if (payload_length < sizeof(struct GNUNET_TUN_UdpHeader)) | 1602 | if (payload_length < sizeof(struct GNUNET_TUN_UdpHeader)) |
1593 | { | 1603 | { |
1594 | /* blame kernel? */ | 1604 | /* blame kernel? */ |
1595 | GNUNET_break(0); | 1605 | GNUNET_break (0); |
1596 | return; | 1606 | return; |
1597 | } | 1607 | } |
1598 | tcp = NULL; /* make compiler happy */ | 1608 | tcp = NULL; /* make compiler happy */ |
1599 | icmp = NULL; /* make compiler happy */ | 1609 | icmp = NULL; /* make compiler happy */ |
1600 | udp = payload; | 1610 | udp = payload; |
1601 | if (udp->len < sizeof(struct GNUNET_TUN_UdpHeader)) | 1611 | if (udp->len < sizeof(struct GNUNET_TUN_UdpHeader)) |
1602 | { | 1612 | { |
1603 | GNUNET_break_op(0); | 1613 | GNUNET_break_op (0); |
1604 | return; | 1614 | return; |
1605 | } | 1615 | } |
1606 | source_port = ntohs(udp->source_port); | 1616 | source_port = ntohs (udp->source_port); |
1607 | destination_port = ntohs(udp->destination_port); | 1617 | destination_port = ntohs (udp->destination_port); |
1608 | get_channel_key_from_ips(af, | 1618 | get_channel_key_from_ips (af, |
1609 | IPPROTO_UDP, | 1619 | IPPROTO_UDP, |
1610 | source_ip, | 1620 | source_ip, |
1611 | source_port, | 1621 | source_port, |
1612 | destination_ip, | 1622 | destination_ip, |
1613 | destination_port, | 1623 | destination_port, |
1614 | &key); | 1624 | &key); |
1615 | } | 1625 | } |
1616 | break; | 1626 | break; |
1617 | 1627 | ||
1618 | case IPPROTO_TCP: { | 1628 | case IPPROTO_TCP: { |
1619 | if (payload_length < sizeof(struct GNUNET_TUN_TcpHeader)) | 1629 | if (payload_length < sizeof(struct GNUNET_TUN_TcpHeader)) |
1620 | { | 1630 | { |
1621 | /* blame kernel? */ | 1631 | /* blame kernel? */ |
1622 | GNUNET_break(0); | 1632 | GNUNET_break (0); |
1623 | return; | 1633 | return; |
1624 | } | 1634 | } |
1625 | udp = NULL; /* make compiler happy */ | 1635 | udp = NULL; /* make compiler happy */ |
1626 | icmp = NULL; /* make compiler happy */ | 1636 | icmp = NULL; /* make compiler happy */ |
1627 | tcp = payload; | 1637 | tcp = payload; |
1628 | if (tcp->off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) | 1638 | if (tcp->off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
1629 | { | 1639 | { |
1630 | GNUNET_break_op(0); | 1640 | GNUNET_break_op (0); |
1631 | return; | 1641 | return; |
1632 | } | 1642 | } |
1633 | source_port = ntohs(tcp->source_port); | 1643 | source_port = ntohs (tcp->source_port); |
1634 | destination_port = ntohs(tcp->destination_port); | 1644 | destination_port = ntohs (tcp->destination_port); |
1635 | get_channel_key_from_ips(af, | 1645 | get_channel_key_from_ips (af, |
1636 | IPPROTO_TCP, | 1646 | IPPROTO_TCP, |
1637 | source_ip, | 1647 | source_ip, |
1638 | source_port, | 1648 | source_port, |
1639 | destination_ip, | 1649 | destination_ip, |
1640 | destination_port, | 1650 | destination_port, |
1641 | &key); | 1651 | &key); |
1642 | } | 1652 | } |
1643 | break; | 1653 | break; |
1644 | 1654 | ||
1645 | case IPPROTO_ICMP: | 1655 | case IPPROTO_ICMP: |
1646 | case IPPROTO_ICMPV6: { | 1656 | case IPPROTO_ICMPV6: { |
1647 | if ((AF_INET == af) ^ (protocol == IPPROTO_ICMP)) | 1657 | if ((AF_INET == af) ^ (protocol == IPPROTO_ICMP)) |
1648 | { | 1658 | { |
1649 | GNUNET_break(0); | 1659 | GNUNET_break (0); |
1650 | return; | 1660 | return; |
1651 | } | 1661 | } |
1652 | if (payload_length < sizeof(struct GNUNET_TUN_IcmpHeader)) | 1662 | if (payload_length < sizeof(struct GNUNET_TUN_IcmpHeader)) |
1653 | { | 1663 | { |
1654 | /* blame kernel? */ | 1664 | /* blame kernel? */ |
1655 | GNUNET_break(0); | 1665 | GNUNET_break (0); |
1656 | return; | 1666 | return; |
1657 | } | 1667 | } |
1658 | tcp = NULL; /* make compiler happy */ | 1668 | tcp = NULL; /* make compiler happy */ |
1659 | udp = NULL; /* make compiler happy */ | 1669 | udp = NULL; /* make compiler happy */ |
1660 | icmp = payload; | 1670 | icmp = payload; |
1661 | source_port = 0; | 1671 | source_port = 0; |
1662 | destination_port = 0; | 1672 | destination_port = 0; |
1663 | get_channel_key_from_ips(af, | 1673 | get_channel_key_from_ips (af, |
1664 | protocol, | 1674 | protocol, |
1665 | source_ip, | 1675 | source_ip, |
1666 | 0, | 1676 | 0, |
1667 | destination_ip, | 1677 | destination_ip, |
1668 | 0, | 1678 | 0, |
1669 | &key); | 1679 | &key); |
1670 | } | 1680 | } |
1671 | break; | 1681 | break; |
1672 | 1682 | ||
1673 | default: | 1683 | default: |
1674 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1684 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1675 | _("Protocol %u not supported, dropping\n"), | 1685 | _ ("Protocol %u not supported, dropping\n"), |
1676 | (unsigned int)protocol); | 1686 | (unsigned int) protocol); |
1677 | return; | 1687 | return; |
1678 | } | 1688 | } |
1679 | alen = 0; | 1689 | alen = 0; |
1680 | if (!destination->is_service) | 1690 | if (! destination->is_service) |
1691 | { | ||
1692 | switch (destination->details.exit_destination.af) | ||
1681 | { | 1693 | { |
1682 | switch (destination->details.exit_destination.af) | 1694 | case AF_INET: |
1683 | { | 1695 | alen = sizeof(struct in_addr); |
1684 | case AF_INET: | 1696 | break; |
1685 | alen = sizeof(struct in_addr); | ||
1686 | break; | ||
1687 | |||
1688 | case AF_INET6: | ||
1689 | alen = sizeof(struct in6_addr); | ||
1690 | break; | ||
1691 | 1697 | ||
1692 | default: | 1698 | case AF_INET6: |
1693 | GNUNET_assert(0); | 1699 | alen = sizeof(struct in6_addr); |
1694 | } | 1700 | break; |
1695 | 1701 | ||
1696 | { | 1702 | default: |
1697 | char sbuf[INET6_ADDRSTRLEN]; | 1703 | GNUNET_assert (0); |
1698 | char dbuf[INET6_ADDRSTRLEN]; | ||
1699 | char xbuf[INET6_ADDRSTRLEN]; | ||
1700 | |||
1701 | GNUNET_log( | ||
1702 | GNUNET_ERROR_TYPE_DEBUG, | ||
1703 | "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n", | ||
1704 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", | ||
1705 | inet_ntop(af, source_ip, sbuf, sizeof(sbuf)), | ||
1706 | source_port, | ||
1707 | inet_ntop(af, destination_ip, dbuf, sizeof(dbuf)), | ||
1708 | destination_port, | ||
1709 | inet_ntop(destination->details.exit_destination.af, | ||
1710 | &destination->details.exit_destination.ip, | ||
1711 | xbuf, | ||
1712 | sizeof(xbuf)), | ||
1713 | destination_port); | ||
1714 | } | ||
1715 | for (dt = destination->dt_head; NULL != dt; dt = dt->next) | ||
1716 | if (dt->destination_port == destination_port) | ||
1717 | break; | ||
1718 | } | 1704 | } |
1705 | |||
1706 | { | ||
1707 | char sbuf[INET6_ADDRSTRLEN]; | ||
1708 | char dbuf[INET6_ADDRSTRLEN]; | ||
1709 | char xbuf[INET6_ADDRSTRLEN]; | ||
1710 | |||
1711 | GNUNET_log ( | ||
1712 | GNUNET_ERROR_TYPE_DEBUG, | ||
1713 | "Routing %s packet from [%s]:%u -> [%s]:%u to destination [%s]:%u\n", | ||
1714 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", | ||
1715 | inet_ntop (af, source_ip, sbuf, sizeof(sbuf)), | ||
1716 | source_port, | ||
1717 | inet_ntop (af, destination_ip, dbuf, sizeof(dbuf)), | ||
1718 | destination_port, | ||
1719 | inet_ntop (destination->details.exit_destination.af, | ||
1720 | &destination->details.exit_destination.ip, | ||
1721 | xbuf, | ||
1722 | sizeof(xbuf)), | ||
1723 | destination_port); | ||
1724 | } | ||
1725 | for (dt = destination->dt_head; NULL != dt; dt = dt->next) | ||
1726 | if (dt->destination_port == destination_port) | ||
1727 | break; | ||
1728 | } | ||
1719 | else | 1729 | else |
1730 | { | ||
1720 | { | 1731 | { |
1721 | { | 1732 | char sbuf[INET6_ADDRSTRLEN]; |
1722 | char sbuf[INET6_ADDRSTRLEN]; | 1733 | char dbuf[INET6_ADDRSTRLEN]; |
1723 | char dbuf[INET6_ADDRSTRLEN]; | 1734 | |
1724 | 1735 | GNUNET_log ( | |
1725 | GNUNET_log( | 1736 | GNUNET_ERROR_TYPE_DEBUG, |
1726 | GNUNET_ERROR_TYPE_DEBUG, | 1737 | "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n", |
1727 | "Routing %s packet from [%s]:%u -> [%s]:%u to service %s at peer %s\n", | 1738 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", |
1728 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", | 1739 | inet_ntop (af, source_ip, sbuf, sizeof(sbuf)), |
1729 | inet_ntop(af, source_ip, sbuf, sizeof(sbuf)), | 1740 | source_port, |
1730 | source_port, | 1741 | inet_ntop (af, destination_ip, dbuf, sizeof(dbuf)), |
1731 | inet_ntop(af, destination_ip, dbuf, sizeof(dbuf)), | 1742 | destination_port, |
1732 | destination_port, | 1743 | GNUNET_h2s ( |
1733 | GNUNET_h2s( | 1744 | &destination->details.service_destination.service_descriptor), |
1734 | &destination->details.service_destination.service_descriptor), | 1745 | GNUNET_i2s (&destination->details.service_destination.target)); |
1735 | GNUNET_i2s(&destination->details.service_destination.target)); | 1746 | } |
1736 | } | 1747 | for (dt = destination->dt_head; NULL != dt; dt = dt->next) |
1737 | for (dt = destination->dt_head; NULL != dt; dt = dt->next) | 1748 | if (dt->destination_port == destination_port) |
1738 | if (dt->destination_port == destination_port) | 1749 | break; |
1739 | break; | 1750 | } |
1740 | } | ||
1741 | if (NULL == dt) | 1751 | if (NULL == dt) |
1742 | { | 1752 | { |
1743 | dt = GNUNET_new(struct DestinationChannel); | 1753 | dt = GNUNET_new (struct DestinationChannel); |
1744 | dt->destination = destination; | 1754 | dt->destination = destination; |
1745 | GNUNET_CONTAINER_DLL_insert(destination->dt_head, | 1755 | GNUNET_CONTAINER_DLL_insert (destination->dt_head, |
1746 | destination->dt_tail, | 1756 | destination->dt_tail, |
1747 | dt); | 1757 | dt); |
1748 | dt->destination_port = destination_port; | 1758 | dt->destination_port = destination_port; |
1749 | } | 1759 | } |
1750 | 1760 | ||
1751 | /* see if we have an existing channel for this destination */ | 1761 | /* see if we have an existing channel for this destination */ |
1752 | ts = GNUNET_CONTAINER_multihashmap_get(channel_map, &key); | 1762 | ts = GNUNET_CONTAINER_multihashmap_get (channel_map, &key); |
1753 | if (NULL == ts) | 1763 | if (NULL == ts) |
1764 | { | ||
1765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1766 | "Creating new channel for key %s\n", | ||
1767 | GNUNET_h2s (&key)); | ||
1768 | /* need to either use the existing channel from the destination (if still | ||
1769 | available) or create a fresh one */ | ||
1770 | ts = create_channel_to_destination (dt, af); | ||
1771 | if (NULL == ts) | ||
1772 | return; | ||
1773 | /* now bind existing "unbound" channel to our IP/port tuple */ | ||
1774 | ts->protocol = protocol; | ||
1775 | ts->af = af; | ||
1776 | if (AF_INET == af) | ||
1754 | { | 1777 | { |
1755 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1778 | ts->source_ip.v4 = *(const struct in_addr *) source_ip; |
1756 | "Creating new channel for key %s\n", | 1779 | ts->destination_ip.v4 = *(const struct in_addr *) destination_ip; |
1757 | GNUNET_h2s(&key)); | ||
1758 | /* need to either use the existing channel from the destination (if still | ||
1759 | available) or create a fresh one */ | ||
1760 | ts = create_channel_to_destination(dt, af); | ||
1761 | if (NULL == ts) | ||
1762 | return; | ||
1763 | /* now bind existing "unbound" channel to our IP/port tuple */ | ||
1764 | ts->protocol = protocol; | ||
1765 | ts->af = af; | ||
1766 | if (AF_INET == af) | ||
1767 | { | ||
1768 | ts->source_ip.v4 = *(const struct in_addr *)source_ip; | ||
1769 | ts->destination_ip.v4 = *(const struct in_addr *)destination_ip; | ||
1770 | } | ||
1771 | else | ||
1772 | { | ||
1773 | ts->source_ip.v6 = *(const struct in6_addr *)source_ip; | ||
1774 | ts->destination_ip.v6 = *(const struct in6_addr *)destination_ip; | ||
1775 | } | ||
1776 | ts->source_port = source_port; | ||
1777 | ts->destination_port = destination_port; | ||
1778 | ts->heap_node = | ||
1779 | GNUNET_CONTAINER_heap_insert(channel_heap, | ||
1780 | ts, | ||
1781 | GNUNET_TIME_absolute_get().abs_value_us); | ||
1782 | GNUNET_assert(GNUNET_YES == | ||
1783 | GNUNET_CONTAINER_multihashmap_put( | ||
1784 | channel_map, | ||
1785 | &key, | ||
1786 | ts, | ||
1787 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1788 | GNUNET_STATISTICS_update(stats, | ||
1789 | gettext_noop("# Active channels"), | ||
1790 | 1, | ||
1791 | GNUNET_NO); | ||
1792 | while (GNUNET_CONTAINER_multihashmap_size(channel_map) > | ||
1793 | max_channel_mappings) | ||
1794 | expire_channel(ts); | ||
1795 | } | 1780 | } |
1796 | else | 1781 | else |
1797 | { | 1782 | { |
1798 | GNUNET_CONTAINER_heap_update_cost(ts->heap_node, | 1783 | ts->source_ip.v6 = *(const struct in6_addr *) source_ip; |
1799 | GNUNET_TIME_absolute_get() | 1784 | ts->destination_ip.v6 = *(const struct in6_addr *) destination_ip; |
1800 | .abs_value_us); | 1785 | } |
1801 | } | 1786 | ts->source_port = source_port; |
1787 | ts->destination_port = destination_port; | ||
1788 | ts->heap_node = | ||
1789 | GNUNET_CONTAINER_heap_insert (channel_heap, | ||
1790 | ts, | ||
1791 | GNUNET_TIME_absolute_get ().abs_value_us); | ||
1792 | GNUNET_assert (GNUNET_YES == | ||
1793 | GNUNET_CONTAINER_multihashmap_put ( | ||
1794 | channel_map, | ||
1795 | &key, | ||
1796 | ts, | ||
1797 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1798 | GNUNET_STATISTICS_update (stats, | ||
1799 | gettext_noop ("# Active channels"), | ||
1800 | 1, | ||
1801 | GNUNET_NO); | ||
1802 | while (GNUNET_CONTAINER_multihashmap_size (channel_map) > | ||
1803 | max_channel_mappings) | ||
1804 | expire_channel (ts); | ||
1805 | } | ||
1806 | else | ||
1807 | { | ||
1808 | GNUNET_CONTAINER_heap_update_cost (ts->heap_node, | ||
1809 | GNUNET_TIME_absolute_get () | ||
1810 | .abs_value_us); | ||
1811 | } | ||
1802 | if (NULL == ts->channel) | 1812 | if (NULL == ts->channel) |
1803 | { | 1813 | { |
1804 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1814 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1805 | "Packet dropped, channel to %s not yet ready (%s)\n", | 1815 | "Packet dropped, channel to %s not yet ready (%s)\n", |
1806 | print_channel_destination(&ts->destination), | 1816 | print_channel_destination (&ts->destination), |
1807 | (NULL == ts->search) ? "EXIT search failed" | 1817 | (NULL == ts->search) ? "EXIT search failed" |
1808 | : "EXIT search active"); | 1818 | : "EXIT search active"); |
1809 | GNUNET_STATISTICS_update(stats, | 1819 | GNUNET_STATISTICS_update (stats, |
1810 | gettext_noop( | 1820 | gettext_noop ( |
1811 | "# Packets dropped (channel not yet online)"), | 1821 | "# Packets dropped (channel not yet online)"), |
1812 | 1, | 1822 | 1, |
1813 | GNUNET_NO); | 1823 | GNUNET_NO); |
1814 | return; | 1824 | return; |
1815 | } | 1825 | } |
1816 | 1826 | ||
1817 | /* send via channel */ | 1827 | /* send via channel */ |
1818 | switch (protocol) | 1828 | switch (protocol) |
1829 | { | ||
1830 | case IPPROTO_UDP: | ||
1831 | if (destination->is_service) | ||
1832 | { | ||
1833 | struct GNUNET_EXIT_UdpServiceMessage *usm; | ||
1834 | |||
1835 | mlen = sizeof(struct GNUNET_EXIT_UdpServiceMessage) + payload_length | ||
1836 | - sizeof(struct GNUNET_TUN_UdpHeader); | ||
1837 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
1838 | { | ||
1839 | GNUNET_break (0); | ||
1840 | return; | ||
1841 | } | ||
1842 | env = GNUNET_MQ_msg_extra (usm, | ||
1843 | payload_length | ||
1844 | - sizeof(struct GNUNET_TUN_UdpHeader), | ||
1845 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE); | ||
1846 | /* if the source port is below 32000, we assume it has a special | ||
1847 | meaning; if not, we pick a random port (this is a heuristic) */ | ||
1848 | usm->source_port = | ||
1849 | (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; | ||
1850 | usm->destination_port = udp->destination_port; | ||
1851 | GNUNET_memcpy (&usm[1], | ||
1852 | &udp[1], | ||
1853 | payload_length - sizeof(struct GNUNET_TUN_UdpHeader)); | ||
1854 | } | ||
1855 | else | ||
1856 | { | ||
1857 | struct GNUNET_EXIT_UdpInternetMessage *uim; | ||
1858 | struct in_addr *ip4dst; | ||
1859 | struct in6_addr *ip6dst; | ||
1860 | void *payload; | ||
1861 | |||
1862 | mlen = sizeof(struct GNUNET_EXIT_UdpInternetMessage) + alen | ||
1863 | + payload_length - sizeof(struct GNUNET_TUN_UdpHeader); | ||
1864 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
1865 | { | ||
1866 | GNUNET_break (0); | ||
1867 | return; | ||
1868 | } | ||
1869 | env = GNUNET_MQ_msg_extra (uim, | ||
1870 | payload_length + alen | ||
1871 | - sizeof(struct GNUNET_TUN_UdpHeader), | ||
1872 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); | ||
1873 | uim->af = htonl (destination->details.exit_destination.af); | ||
1874 | uim->source_port = | ||
1875 | (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; | ||
1876 | uim->destination_port = udp->destination_port; | ||
1877 | switch (destination->details.exit_destination.af) | ||
1878 | { | ||
1879 | case AF_INET: | ||
1880 | ip4dst = (struct in_addr *) &uim[1]; | ||
1881 | *ip4dst = destination->details.exit_destination.ip.v4; | ||
1882 | payload = &ip4dst[1]; | ||
1883 | break; | ||
1884 | |||
1885 | case AF_INET6: | ||
1886 | ip6dst = (struct in6_addr *) &uim[1]; | ||
1887 | *ip6dst = destination->details.exit_destination.ip.v6; | ||
1888 | payload = &ip6dst[1]; | ||
1889 | break; | ||
1890 | |||
1891 | default: | ||
1892 | GNUNET_assert (0); | ||
1893 | } | ||
1894 | GNUNET_memcpy (payload, | ||
1895 | &udp[1], | ||
1896 | payload_length - sizeof(struct GNUNET_TUN_UdpHeader)); | ||
1897 | } | ||
1898 | break; | ||
1899 | |||
1900 | case IPPROTO_TCP: | ||
1901 | if (GNUNET_NO == ts->is_established) | ||
1819 | { | 1902 | { |
1820 | case IPPROTO_UDP: | ||
1821 | if (destination->is_service) | 1903 | if (destination->is_service) |
1822 | { | 1904 | { |
1823 | struct GNUNET_EXIT_UdpServiceMessage *usm; | 1905 | struct GNUNET_EXIT_TcpServiceStartMessage *tsm; |
1824 | 1906 | ||
1825 | mlen = sizeof(struct GNUNET_EXIT_UdpServiceMessage) + payload_length - | 1907 | mlen = sizeof(struct GNUNET_EXIT_TcpServiceStartMessage) |
1826 | sizeof(struct GNUNET_TUN_UdpHeader); | 1908 | + payload_length - sizeof(struct GNUNET_TUN_TcpHeader); |
1827 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | 1909 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) |
1828 | { | 1910 | { |
1829 | GNUNET_break(0); | 1911 | GNUNET_break (0); |
1830 | return; | 1912 | return; |
1831 | } | ||
1832 | env = GNUNET_MQ_msg_extra(usm, | ||
1833 | payload_length - | ||
1834 | sizeof(struct GNUNET_TUN_UdpHeader), | ||
1835 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE); | ||
1836 | /* if the source port is below 32000, we assume it has a special | ||
1837 | meaning; if not, we pick a random port (this is a heuristic) */ | ||
1838 | usm->source_port = | ||
1839 | (ntohs(udp->source_port) < 32000) ? udp->source_port : 0; | ||
1840 | usm->destination_port = udp->destination_port; | ||
1841 | GNUNET_memcpy(&usm[1], | ||
1842 | &udp[1], | ||
1843 | payload_length - sizeof(struct GNUNET_TUN_UdpHeader)); | ||
1844 | } | 1913 | } |
1914 | env = | ||
1915 | GNUNET_MQ_msg_extra (tsm, | ||
1916 | payload_length | ||
1917 | - sizeof(struct GNUNET_TUN_TcpHeader), | ||
1918 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); | ||
1919 | tsm->reserved = htonl (0); | ||
1920 | tsm->tcp_header = *tcp; | ||
1921 | GNUNET_memcpy (&tsm[1], | ||
1922 | &tcp[1], | ||
1923 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader)); | ||
1924 | } | ||
1845 | else | 1925 | else |
1926 | { | ||
1927 | struct GNUNET_EXIT_TcpInternetStartMessage *tim; | ||
1928 | struct in_addr *ip4dst; | ||
1929 | struct in6_addr *ip6dst; | ||
1930 | void *payload; | ||
1931 | |||
1932 | mlen = sizeof(struct GNUNET_EXIT_TcpInternetStartMessage) + alen | ||
1933 | + payload_length - sizeof(struct GNUNET_TUN_TcpHeader); | ||
1934 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
1846 | { | 1935 | { |
1847 | struct GNUNET_EXIT_UdpInternetMessage *uim; | 1936 | GNUNET_break (0); |
1848 | struct in_addr *ip4dst; | 1937 | return; |
1849 | struct in6_addr *ip6dst; | ||
1850 | void *payload; | ||
1851 | |||
1852 | mlen = sizeof(struct GNUNET_EXIT_UdpInternetMessage) + alen + | ||
1853 | payload_length - sizeof(struct GNUNET_TUN_UdpHeader); | ||
1854 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
1855 | { | ||
1856 | GNUNET_break(0); | ||
1857 | return; | ||
1858 | } | ||
1859 | env = GNUNET_MQ_msg_extra(uim, | ||
1860 | payload_length + alen - | ||
1861 | sizeof(struct GNUNET_TUN_UdpHeader), | ||
1862 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); | ||
1863 | uim->af = htonl(destination->details.exit_destination.af); | ||
1864 | uim->source_port = | ||
1865 | (ntohs(udp->source_port) < 32000) ? udp->source_port : 0; | ||
1866 | uim->destination_port = udp->destination_port; | ||
1867 | switch (destination->details.exit_destination.af) | ||
1868 | { | ||
1869 | case AF_INET: | ||
1870 | ip4dst = (struct in_addr *)&uim[1]; | ||
1871 | *ip4dst = destination->details.exit_destination.ip.v4; | ||
1872 | payload = &ip4dst[1]; | ||
1873 | break; | ||
1874 | |||
1875 | case AF_INET6: | ||
1876 | ip6dst = (struct in6_addr *)&uim[1]; | ||
1877 | *ip6dst = destination->details.exit_destination.ip.v6; | ||
1878 | payload = &ip6dst[1]; | ||
1879 | break; | ||
1880 | |||
1881 | default: | ||
1882 | GNUNET_assert(0); | ||
1883 | } | ||
1884 | GNUNET_memcpy(payload, | ||
1885 | &udp[1], | ||
1886 | payload_length - sizeof(struct GNUNET_TUN_UdpHeader)); | ||
1887 | } | 1938 | } |
1888 | break; | 1939 | env = |
1940 | GNUNET_MQ_msg_extra (tim, | ||
1941 | payload_length + alen | ||
1942 | - sizeof(struct GNUNET_TUN_TcpHeader), | ||
1943 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); | ||
1944 | tim->af = htonl (destination->details.exit_destination.af); | ||
1945 | tim->tcp_header = *tcp; | ||
1946 | switch (destination->details.exit_destination.af) | ||
1947 | { | ||
1948 | case AF_INET: | ||
1949 | ip4dst = (struct in_addr *) &tim[1]; | ||
1950 | *ip4dst = destination->details.exit_destination.ip.v4; | ||
1951 | payload = &ip4dst[1]; | ||
1952 | break; | ||
1889 | 1953 | ||
1890 | case IPPROTO_TCP: | 1954 | case AF_INET6: |
1891 | if (GNUNET_NO == ts->is_established) | 1955 | ip6dst = (struct in6_addr *) &tim[1]; |
1956 | *ip6dst = destination->details.exit_destination.ip.v6; | ||
1957 | payload = &ip6dst[1]; | ||
1958 | break; | ||
1959 | |||
1960 | default: | ||
1961 | GNUNET_assert (0); | ||
1962 | } | ||
1963 | GNUNET_memcpy (payload, | ||
1964 | &tcp[1], | ||
1965 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader)); | ||
1966 | } | ||
1967 | } | ||
1968 | else | ||
1969 | { | ||
1970 | struct GNUNET_EXIT_TcpDataMessage *tdm; | ||
1971 | |||
1972 | mlen = sizeof(struct GNUNET_EXIT_TcpDataMessage) + payload_length | ||
1973 | - sizeof(struct GNUNET_TUN_TcpHeader); | ||
1974 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
1975 | { | ||
1976 | GNUNET_break (0); | ||
1977 | return; | ||
1978 | } | ||
1979 | env = GNUNET_MQ_msg_extra (tdm, | ||
1980 | payload_length | ||
1981 | - sizeof(struct GNUNET_TUN_TcpHeader), | ||
1982 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT); | ||
1983 | tdm->reserved = htonl (0); | ||
1984 | tdm->tcp_header = *tcp; | ||
1985 | GNUNET_memcpy (&tdm[1], | ||
1986 | &tcp[1], | ||
1987 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader)); | ||
1988 | } | ||
1989 | break; | ||
1990 | |||
1991 | case IPPROTO_ICMP: | ||
1992 | case IPPROTO_ICMPV6: | ||
1993 | if (destination->is_service) | ||
1994 | { | ||
1995 | struct GNUNET_EXIT_IcmpServiceMessage *ism; | ||
1996 | |||
1997 | /* ICMP protocol translation will be done by the receiver (as we don't know | ||
1998 | the target AF); however, we still need to possibly discard the payload | ||
1999 | depending on the ICMP type */ | ||
2000 | switch (af) | ||
2001 | { | ||
2002 | case AF_INET: | ||
2003 | switch (icmp->type) | ||
1892 | { | 2004 | { |
1893 | if (destination->is_service) | 2005 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
1894 | { | 2006 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
1895 | struct GNUNET_EXIT_TcpServiceStartMessage *tsm; | 2007 | break; |
1896 | 2008 | ||
1897 | mlen = sizeof(struct GNUNET_EXIT_TcpServiceStartMessage) + | 2009 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
1898 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader); | 2010 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
1899 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | 2011 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
1900 | { | 2012 | /* throw away ICMP payload, won't be useful for the other side anyway */ |
1901 | GNUNET_break(0); | 2013 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); |
1902 | return; | 2014 | break; |
1903 | } | 2015 | |
1904 | env = | 2016 | default: |
1905 | GNUNET_MQ_msg_extra(tsm, | 2017 | GNUNET_STATISTICS_update (stats, |
1906 | payload_length - | 2018 | gettext_noop ( |
1907 | sizeof(struct GNUNET_TUN_TcpHeader), | 2019 | "# ICMPv4 packets dropped (not allowed)"), |
1908 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START); | 2020 | 1, |
1909 | tsm->reserved = htonl(0); | 2021 | GNUNET_NO); |
1910 | tsm->tcp_header = *tcp; | 2022 | return; |
1911 | GNUNET_memcpy(&tsm[1], | ||
1912 | &tcp[1], | ||
1913 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader)); | ||
1914 | } | ||
1915 | else | ||
1916 | { | ||
1917 | struct GNUNET_EXIT_TcpInternetStartMessage *tim; | ||
1918 | struct in_addr *ip4dst; | ||
1919 | struct in6_addr *ip6dst; | ||
1920 | void *payload; | ||
1921 | |||
1922 | mlen = sizeof(struct GNUNET_EXIT_TcpInternetStartMessage) + alen + | ||
1923 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader); | ||
1924 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
1925 | { | ||
1926 | GNUNET_break(0); | ||
1927 | return; | ||
1928 | } | ||
1929 | env = | ||
1930 | GNUNET_MQ_msg_extra(tim, | ||
1931 | payload_length + alen - | ||
1932 | sizeof(struct GNUNET_TUN_TcpHeader), | ||
1933 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START); | ||
1934 | tim->af = htonl(destination->details.exit_destination.af); | ||
1935 | tim->tcp_header = *tcp; | ||
1936 | switch (destination->details.exit_destination.af) | ||
1937 | { | ||
1938 | case AF_INET: | ||
1939 | ip4dst = (struct in_addr *)&tim[1]; | ||
1940 | *ip4dst = destination->details.exit_destination.ip.v4; | ||
1941 | payload = &ip4dst[1]; | ||
1942 | break; | ||
1943 | |||
1944 | case AF_INET6: | ||
1945 | ip6dst = (struct in6_addr *)&tim[1]; | ||
1946 | *ip6dst = destination->details.exit_destination.ip.v6; | ||
1947 | payload = &ip6dst[1]; | ||
1948 | break; | ||
1949 | |||
1950 | default: | ||
1951 | GNUNET_assert(0); | ||
1952 | } | ||
1953 | GNUNET_memcpy(payload, | ||
1954 | &tcp[1], | ||
1955 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader)); | ||
1956 | } | ||
1957 | } | 2023 | } |
1958 | else | 2024 | /* end of AF_INET */ |
2025 | break; | ||
2026 | |||
2027 | case AF_INET6: | ||
2028 | switch (icmp->type) | ||
1959 | { | 2029 | { |
1960 | struct GNUNET_EXIT_TcpDataMessage *tdm; | 2030 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: |
2031 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
2032 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
2033 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
2034 | /* throw away ICMP payload, won't be useful for the other side anyway */ | ||
2035 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2036 | break; | ||
1961 | 2037 | ||
1962 | mlen = sizeof(struct GNUNET_EXIT_TcpDataMessage) + payload_length - | 2038 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: |
1963 | sizeof(struct GNUNET_TUN_TcpHeader); | 2039 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: |
1964 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | 2040 | break; |
1965 | { | 2041 | |
1966 | GNUNET_break(0); | 2042 | default: |
1967 | return; | 2043 | GNUNET_STATISTICS_update (stats, |
1968 | } | 2044 | gettext_noop ( |
1969 | env = GNUNET_MQ_msg_extra(tdm, | 2045 | "# ICMPv6 packets dropped (not allowed)"), |
1970 | payload_length - | 2046 | 1, |
1971 | sizeof(struct GNUNET_TUN_TcpHeader), | 2047 | GNUNET_NO); |
1972 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT); | 2048 | return; |
1973 | tdm->reserved = htonl(0); | ||
1974 | tdm->tcp_header = *tcp; | ||
1975 | GNUNET_memcpy(&tdm[1], | ||
1976 | &tcp[1], | ||
1977 | payload_length - sizeof(struct GNUNET_TUN_TcpHeader)); | ||
1978 | } | 2049 | } |
1979 | break; | 2050 | /* end of AF_INET6 */ |
2051 | break; | ||
1980 | 2052 | ||
1981 | case IPPROTO_ICMP: | 2053 | default: |
1982 | case IPPROTO_ICMPV6: | 2054 | GNUNET_assert (0); |
1983 | if (destination->is_service) | 2055 | break; |
2056 | } | ||
2057 | |||
2058 | /* update length calculations, as payload_length may have changed */ | ||
2059 | mlen = sizeof(struct GNUNET_EXIT_IcmpServiceMessage) + alen | ||
2060 | + payload_length - sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2061 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
2062 | { | ||
2063 | GNUNET_break (0); | ||
2064 | return; | ||
2065 | } | ||
2066 | |||
2067 | env = GNUNET_MQ_msg_extra (ism, | ||
2068 | payload_length | ||
2069 | - sizeof(struct GNUNET_TUN_IcmpHeader), | ||
2070 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); | ||
2071 | ism->af = htonl (af); /* need to tell destination ICMP protocol family! */ | ||
2072 | ism->icmp_header = *icmp; | ||
2073 | GNUNET_memcpy (&ism[1], | ||
2074 | &icmp[1], | ||
2075 | payload_length - sizeof(struct GNUNET_TUN_IcmpHeader)); | ||
2076 | } | ||
2077 | else | ||
2078 | { | ||
2079 | struct GNUNET_EXIT_IcmpInternetMessage *iim; | ||
2080 | struct in_addr *ip4dst; | ||
2081 | struct in6_addr *ip6dst; | ||
2082 | void *payload; | ||
2083 | uint8_t new_type; | ||
2084 | |||
2085 | new_type = icmp->type; | ||
2086 | /* Perform ICMP protocol-translation (depending on destination AF and source AF) | ||
2087 | and throw away ICMP payload depending on ICMP message type */ | ||
2088 | switch (af) | ||
2089 | { | ||
2090 | case AF_INET: | ||
2091 | switch (icmp->type) | ||
1984 | { | 2092 | { |
1985 | struct GNUNET_EXIT_IcmpServiceMessage *ism; | 2093 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
2094 | if (destination->details.exit_destination.af == AF_INET6) | ||
2095 | new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; | ||
2096 | break; | ||
1986 | 2097 | ||
1987 | /* ICMP protocol translation will be done by the receiver (as we don't know | 2098 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
1988 | the target AF); however, we still need to possibly discard the payload | 2099 | if (destination->details.exit_destination.af == AF_INET6) |
1989 | depending on the ICMP type */ | 2100 | new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; |
1990 | switch (af) | 2101 | break; |
1991 | { | ||
1992 | case AF_INET: | ||
1993 | switch (icmp->type) | ||
1994 | { | ||
1995 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
1996 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
1997 | break; | ||
1998 | |||
1999 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
2000 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2001 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2002 | /* throw away ICMP payload, won't be useful for the other side anyway */ | ||
2003 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2004 | break; | ||
2005 | |||
2006 | default: | ||
2007 | GNUNET_STATISTICS_update(stats, | ||
2008 | gettext_noop( | ||
2009 | "# ICMPv4 packets dropped (not allowed)"), | ||
2010 | 1, | ||
2011 | GNUNET_NO); | ||
2012 | return; | ||
2013 | } | ||
2014 | /* end of AF_INET */ | ||
2015 | break; | ||
2016 | |||
2017 | case AF_INET6: | ||
2018 | switch (icmp->type) | ||
2019 | { | ||
2020 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | ||
2021 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
2022 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
2023 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
2024 | /* throw away ICMP payload, won't be useful for the other side anyway */ | ||
2025 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2026 | break; | ||
2027 | |||
2028 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
2029 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | ||
2030 | break; | ||
2031 | |||
2032 | default: | ||
2033 | GNUNET_STATISTICS_update(stats, | ||
2034 | gettext_noop( | ||
2035 | "# ICMPv6 packets dropped (not allowed)"), | ||
2036 | 1, | ||
2037 | GNUNET_NO); | ||
2038 | return; | ||
2039 | } | ||
2040 | /* end of AF_INET6 */ | ||
2041 | break; | ||
2042 | |||
2043 | default: | ||
2044 | GNUNET_assert(0); | ||
2045 | break; | ||
2046 | } | ||
2047 | 2102 | ||
2048 | /* update length calculations, as payload_length may have changed */ | 2103 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
2049 | mlen = sizeof(struct GNUNET_EXIT_IcmpServiceMessage) + alen + | 2104 | if (destination->details.exit_destination.af == AF_INET6) |
2050 | payload_length - sizeof(struct GNUNET_TUN_IcmpHeader); | 2105 | new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; |
2051 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | 2106 | /* throw away IP-payload, exit will have to make it up anyway */ |
2052 | { | 2107 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); |
2053 | GNUNET_break(0); | 2108 | break; |
2054 | return; | 2109 | |
2055 | } | 2110 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
2111 | if (destination->details.exit_destination.af == AF_INET6) | ||
2112 | new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; | ||
2113 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2114 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2115 | break; | ||
2056 | 2116 | ||
2057 | env = GNUNET_MQ_msg_extra(ism, | 2117 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
2058 | payload_length - | 2118 | if (destination->details.exit_destination.af == AF_INET6) |
2059 | sizeof(struct GNUNET_TUN_IcmpHeader), | 2119 | { |
2060 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE); | 2120 | GNUNET_STATISTICS_update ( |
2061 | ism->af = htonl(af); /* need to tell destination ICMP protocol family! */ | 2121 | stats, |
2062 | ism->icmp_header = *icmp; | 2122 | gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), |
2063 | GNUNET_memcpy(&ism[1], | 2123 | 1, |
2064 | &icmp[1], | 2124 | GNUNET_NO); |
2065 | payload_length - sizeof(struct GNUNET_TUN_IcmpHeader)); | 2125 | return; |
2126 | } | ||
2127 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2128 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2129 | break; | ||
2130 | |||
2131 | default: | ||
2132 | GNUNET_STATISTICS_update ( | ||
2133 | stats, | ||
2134 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), | ||
2135 | 1, | ||
2136 | GNUNET_NO); | ||
2137 | return; | ||
2066 | } | 2138 | } |
2067 | else | 2139 | /* end of AF_INET */ |
2140 | break; | ||
2141 | |||
2142 | case AF_INET6: | ||
2143 | switch (icmp->type) | ||
2068 | { | 2144 | { |
2069 | struct GNUNET_EXIT_IcmpInternetMessage *iim; | 2145 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: |
2070 | struct in_addr *ip4dst; | 2146 | if (destination->details.exit_destination.af == AF_INET) |
2071 | struct in6_addr *ip6dst; | 2147 | new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; |
2072 | void *payload; | 2148 | /* throw away IP-payload, exit will have to make it up anyway */ |
2073 | uint8_t new_type; | 2149 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); |
2074 | 2150 | break; | |
2075 | new_type = icmp->type; | ||
2076 | /* Perform ICMP protocol-translation (depending on destination AF and source AF) | ||
2077 | and throw away ICMP payload depending on ICMP message type */ | ||
2078 | switch (af) | ||
2079 | { | ||
2080 | case AF_INET: | ||
2081 | switch (icmp->type) | ||
2082 | { | ||
2083 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
2084 | if (destination->details.exit_destination.af == AF_INET6) | ||
2085 | new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; | ||
2086 | break; | ||
2087 | |||
2088 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
2089 | if (destination->details.exit_destination.af == AF_INET6) | ||
2090 | new_type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; | ||
2091 | break; | ||
2092 | |||
2093 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
2094 | if (destination->details.exit_destination.af == AF_INET6) | ||
2095 | new_type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; | ||
2096 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2097 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2098 | break; | ||
2099 | |||
2100 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2101 | if (destination->details.exit_destination.af == AF_INET6) | ||
2102 | new_type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; | ||
2103 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2104 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2105 | break; | ||
2106 | |||
2107 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2108 | if (destination->details.exit_destination.af == AF_INET6) | ||
2109 | { | ||
2110 | GNUNET_STATISTICS_update( | ||
2111 | stats, | ||
2112 | gettext_noop("# ICMPv4 packets dropped (impossible PT to v6)"), | ||
2113 | 1, | ||
2114 | GNUNET_NO); | ||
2115 | return; | ||
2116 | } | ||
2117 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2118 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2119 | break; | ||
2120 | |||
2121 | default: | ||
2122 | GNUNET_STATISTICS_update( | ||
2123 | stats, | ||
2124 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
2125 | 1, | ||
2126 | GNUNET_NO); | ||
2127 | return; | ||
2128 | } | ||
2129 | /* end of AF_INET */ | ||
2130 | break; | ||
2131 | |||
2132 | case AF_INET6: | ||
2133 | switch (icmp->type) | ||
2134 | { | ||
2135 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | ||
2136 | if (destination->details.exit_destination.af == AF_INET) | ||
2137 | new_type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; | ||
2138 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2139 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2140 | break; | ||
2141 | |||
2142 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
2143 | if (destination->details.exit_destination.af == AF_INET) | ||
2144 | new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; | ||
2145 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2146 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2147 | break; | ||
2148 | |||
2149 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
2150 | if (destination->details.exit_destination.af == AF_INET) | ||
2151 | { | ||
2152 | GNUNET_STATISTICS_update( | ||
2153 | stats, | ||
2154 | gettext_noop("# ICMPv6 packets dropped (impossible PT to v4)"), | ||
2155 | 1, | ||
2156 | GNUNET_NO); | ||
2157 | return; | ||
2158 | } | ||
2159 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2160 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2161 | break; | ||
2162 | |||
2163 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
2164 | if (destination->details.exit_destination.af == AF_INET) | ||
2165 | { | ||
2166 | GNUNET_STATISTICS_update( | ||
2167 | stats, | ||
2168 | gettext_noop("# ICMPv6 packets dropped (impossible PT to v4)"), | ||
2169 | 1, | ||
2170 | GNUNET_NO); | ||
2171 | return; | ||
2172 | } | ||
2173 | /* throw away IP-payload, exit will have to make it up anyway */ | ||
2174 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2175 | break; | ||
2176 | |||
2177 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
2178 | if (destination->details.exit_destination.af == AF_INET) | ||
2179 | new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; | ||
2180 | break; | ||
2181 | |||
2182 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | ||
2183 | if (destination->details.exit_destination.af == AF_INET) | ||
2184 | new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; | ||
2185 | break; | ||
2186 | |||
2187 | default: | ||
2188 | GNUNET_STATISTICS_update( | ||
2189 | stats, | ||
2190 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
2191 | 1, | ||
2192 | GNUNET_NO); | ||
2193 | return; | ||
2194 | } | ||
2195 | /* end of AF_INET6 */ | ||
2196 | break; | ||
2197 | |||
2198 | default: | ||
2199 | GNUNET_assert(0); | ||
2200 | } | ||
2201 | 2151 | ||
2202 | /* update length calculations, as payload_length may have changed */ | 2152 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: |
2203 | mlen = sizeof(struct GNUNET_EXIT_IcmpInternetMessage) + alen + | 2153 | if (destination->details.exit_destination.af == AF_INET) |
2204 | payload_length - sizeof(struct GNUNET_TUN_IcmpHeader); | 2154 | new_type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; |
2205 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | 2155 | /* throw away IP-payload, exit will have to make it up anyway */ |
2206 | { | 2156 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); |
2207 | GNUNET_break(0); | 2157 | break; |
2208 | return; | 2158 | |
2209 | } | 2159 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: |
2210 | env = GNUNET_MQ_msg_extra(iim, | 2160 | if (destination->details.exit_destination.af == AF_INET) |
2211 | alen + payload_length - | 2161 | { |
2212 | sizeof(struct GNUNET_TUN_IcmpHeader), | 2162 | GNUNET_STATISTICS_update ( |
2213 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); | 2163 | stats, |
2214 | iim->icmp_header = *icmp; | 2164 | gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), |
2215 | iim->icmp_header.type = new_type; | 2165 | 1, |
2216 | iim->af = htonl(destination->details.exit_destination.af); | 2166 | GNUNET_NO); |
2217 | switch (destination->details.exit_destination.af) | 2167 | return; |
2218 | { | 2168 | } |
2219 | case AF_INET: | 2169 | /* throw away IP-payload, exit will have to make it up anyway */ |
2220 | ip4dst = (struct in_addr *)&iim[1]; | 2170 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); |
2221 | *ip4dst = destination->details.exit_destination.ip.v4; | 2171 | break; |
2222 | payload = &ip4dst[1]; | 2172 | |
2223 | break; | 2173 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: |
2224 | 2174 | if (destination->details.exit_destination.af == AF_INET) | |
2225 | case AF_INET6: | 2175 | { |
2226 | ip6dst = (struct in6_addr *)&iim[1]; | 2176 | GNUNET_STATISTICS_update ( |
2227 | *ip6dst = destination->details.exit_destination.ip.v6; | 2177 | stats, |
2228 | payload = &ip6dst[1]; | 2178 | gettext_noop ("# ICMPv6 packets dropped (impossible PT to v4)"), |
2229 | break; | 2179 | 1, |
2230 | 2180 | GNUNET_NO); | |
2231 | default: | 2181 | return; |
2232 | GNUNET_assert(0); | 2182 | } |
2233 | } | 2183 | /* throw away IP-payload, exit will have to make it up anyway */ |
2234 | GNUNET_memcpy(payload, | 2184 | payload_length = sizeof(struct GNUNET_TUN_IcmpHeader); |
2235 | &icmp[1], | 2185 | break; |
2236 | payload_length - sizeof(struct GNUNET_TUN_IcmpHeader)); | 2186 | |
2187 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
2188 | if (destination->details.exit_destination.af == AF_INET) | ||
2189 | new_type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; | ||
2190 | break; | ||
2191 | |||
2192 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | ||
2193 | if (destination->details.exit_destination.af == AF_INET) | ||
2194 | new_type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; | ||
2195 | break; | ||
2196 | |||
2197 | default: | ||
2198 | GNUNET_STATISTICS_update ( | ||
2199 | stats, | ||
2200 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), | ||
2201 | 1, | ||
2202 | GNUNET_NO); | ||
2203 | return; | ||
2237 | } | 2204 | } |
2238 | break; | 2205 | /* end of AF_INET6 */ |
2206 | break; | ||
2239 | 2207 | ||
2240 | default: | 2208 | default: |
2241 | /* not supported above, how can we get here !? */ | 2209 | GNUNET_assert (0); |
2242 | GNUNET_assert(0); | 2210 | } |
2243 | break; | 2211 | |
2212 | /* update length calculations, as payload_length may have changed */ | ||
2213 | mlen = sizeof(struct GNUNET_EXIT_IcmpInternetMessage) + alen | ||
2214 | + payload_length - sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2215 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | ||
2216 | { | ||
2217 | GNUNET_break (0); | ||
2218 | return; | ||
2219 | } | ||
2220 | env = GNUNET_MQ_msg_extra (iim, | ||
2221 | alen + payload_length | ||
2222 | - sizeof(struct GNUNET_TUN_IcmpHeader), | ||
2223 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); | ||
2224 | iim->icmp_header = *icmp; | ||
2225 | iim->icmp_header.type = new_type; | ||
2226 | iim->af = htonl (destination->details.exit_destination.af); | ||
2227 | switch (destination->details.exit_destination.af) | ||
2228 | { | ||
2229 | case AF_INET: | ||
2230 | ip4dst = (struct in_addr *) &iim[1]; | ||
2231 | *ip4dst = destination->details.exit_destination.ip.v4; | ||
2232 | payload = &ip4dst[1]; | ||
2233 | break; | ||
2234 | |||
2235 | case AF_INET6: | ||
2236 | ip6dst = (struct in6_addr *) &iim[1]; | ||
2237 | *ip6dst = destination->details.exit_destination.ip.v6; | ||
2238 | payload = &ip6dst[1]; | ||
2239 | break; | ||
2240 | |||
2241 | default: | ||
2242 | GNUNET_assert (0); | ||
2243 | } | ||
2244 | GNUNET_memcpy (payload, | ||
2245 | &icmp[1], | ||
2246 | payload_length - sizeof(struct GNUNET_TUN_IcmpHeader)); | ||
2244 | } | 2247 | } |
2248 | break; | ||
2249 | |||
2250 | default: | ||
2251 | /* not supported above, how can we get here !? */ | ||
2252 | GNUNET_assert (0); | ||
2253 | break; | ||
2254 | } | ||
2245 | ts->is_established = GNUNET_YES; | 2255 | ts->is_established = GNUNET_YES; |
2246 | send_to_channel(ts, env); | 2256 | send_to_channel (ts, env); |
2247 | } | 2257 | } |
2248 | 2258 | ||
2249 | 2259 | ||
@@ -2260,108 +2270,108 @@ route_packet(struct DestinationEntry *destination, | |||
2260 | * #GNUNET_SYSERR to stop further processing with error | 2270 | * #GNUNET_SYSERR to stop further processing with error |
2261 | */ | 2271 | */ |
2262 | static int | 2272 | static int |
2263 | message_token(void *cls, const struct GNUNET_MessageHeader *message) | 2273 | message_token (void *cls, const struct GNUNET_MessageHeader *message) |
2264 | { | 2274 | { |
2265 | const struct GNUNET_TUN_Layer2PacketHeader *tun; | 2275 | const struct GNUNET_TUN_Layer2PacketHeader *tun; |
2266 | size_t mlen; | 2276 | size_t mlen; |
2267 | struct GNUNET_HashCode key; | 2277 | struct GNUNET_HashCode key; |
2268 | struct DestinationEntry *de; | 2278 | struct DestinationEntry *de; |
2269 | 2279 | ||
2270 | GNUNET_STATISTICS_update(stats, | 2280 | GNUNET_STATISTICS_update (stats, |
2271 | gettext_noop( | 2281 | gettext_noop ( |
2272 | "# Packets received from TUN interface"), | 2282 | "# Packets received from TUN interface"), |
2273 | 1, | 2283 | 1, |
2274 | GNUNET_NO); | 2284 | GNUNET_NO); |
2275 | mlen = ntohs(message->size); | 2285 | mlen = ntohs (message->size); |
2276 | if ((ntohs(message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || | 2286 | if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || |
2277 | (mlen < sizeof(struct GNUNET_MessageHeader) + | 2287 | (mlen < sizeof(struct GNUNET_MessageHeader) |
2278 | sizeof(struct GNUNET_TUN_Layer2PacketHeader))) | 2288 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader))) |
2279 | { | 2289 | { |
2280 | GNUNET_break(0); | 2290 | GNUNET_break (0); |
2281 | return GNUNET_OK; | 2291 | return GNUNET_OK; |
2282 | } | 2292 | } |
2283 | tun = (const struct GNUNET_TUN_Layer2PacketHeader *)&message[1]; | 2293 | tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; |
2284 | mlen -= (sizeof(struct GNUNET_MessageHeader) + | 2294 | mlen -= (sizeof(struct GNUNET_MessageHeader) |
2285 | sizeof(struct GNUNET_TUN_Layer2PacketHeader)); | 2295 | + sizeof(struct GNUNET_TUN_Layer2PacketHeader)); |
2286 | switch (ntohs(tun->proto)) | 2296 | switch (ntohs (tun->proto)) |
2287 | { | 2297 | { |
2288 | case ETH_P_IPV6: { | 2298 | case ETH_P_IPV6: { |
2289 | const struct GNUNET_TUN_IPv6Header *pkt6; | 2299 | const struct GNUNET_TUN_IPv6Header *pkt6; |
2290 | 2300 | ||
2291 | if (mlen < sizeof(struct GNUNET_TUN_IPv6Header)) | 2301 | if (mlen < sizeof(struct GNUNET_TUN_IPv6Header)) |
2292 | { | 2302 | { |
2293 | /* blame kernel */ | 2303 | /* blame kernel */ |
2294 | GNUNET_break(0); | 2304 | GNUNET_break (0); |
2295 | return GNUNET_OK; | 2305 | return GNUNET_OK; |
2296 | } | 2306 | } |
2297 | pkt6 = (const struct GNUNET_TUN_IPv6Header *)&tun[1]; | 2307 | pkt6 = (const struct GNUNET_TUN_IPv6Header *) &tun[1]; |
2298 | get_destination_key_from_ip(AF_INET6, &pkt6->destination_address, &key); | 2308 | get_destination_key_from_ip (AF_INET6, &pkt6->destination_address, &key); |
2299 | de = GNUNET_CONTAINER_multihashmap_get(destination_map, &key); | 2309 | de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key); |
2300 | if (NULL == de) | 2310 | if (NULL == de) |
2301 | { | 2311 | { |
2302 | char buf[INET6_ADDRSTRLEN]; | 2312 | char buf[INET6_ADDRSTRLEN]; |
2303 | 2313 | ||
2304 | GNUNET_log( | 2314 | GNUNET_log ( |
2305 | GNUNET_ERROR_TYPE_INFO, | 2315 | GNUNET_ERROR_TYPE_INFO, |
2306 | _("Packet received for unmapped destination `%s' (dropping it)\n"), | 2316 | _ ("Packet received for unmapped destination `%s' (dropping it)\n"), |
2307 | inet_ntop(AF_INET6, &pkt6->destination_address, buf, sizeof(buf))); | 2317 | inet_ntop (AF_INET6, &pkt6->destination_address, buf, sizeof(buf))); |
2308 | return GNUNET_OK; | 2318 | return GNUNET_OK; |
2309 | } | 2319 | } |
2310 | route_packet(de, | 2320 | route_packet (de, |
2311 | AF_INET6, | 2321 | AF_INET6, |
2312 | pkt6->next_header, | 2322 | pkt6->next_header, |
2313 | &pkt6->source_address, | 2323 | &pkt6->source_address, |
2314 | &pkt6->destination_address, | 2324 | &pkt6->destination_address, |
2315 | &pkt6[1], | 2325 | &pkt6[1], |
2316 | mlen - sizeof(struct GNUNET_TUN_IPv6Header)); | 2326 | mlen - sizeof(struct GNUNET_TUN_IPv6Header)); |
2317 | } | 2327 | } |
2318 | break; | 2328 | break; |
2319 | 2329 | ||
2320 | case ETH_P_IPV4: { | 2330 | case ETH_P_IPV4: { |
2321 | struct GNUNET_TUN_IPv4Header *pkt4; | 2331 | struct GNUNET_TUN_IPv4Header *pkt4; |
2322 | 2332 | ||
2323 | if (mlen < sizeof(struct GNUNET_TUN_IPv4Header)) | 2333 | if (mlen < sizeof(struct GNUNET_TUN_IPv4Header)) |
2324 | { | 2334 | { |
2325 | /* blame kernel */ | 2335 | /* blame kernel */ |
2326 | GNUNET_break(0); | 2336 | GNUNET_break (0); |
2327 | return GNUNET_OK; | 2337 | return GNUNET_OK; |
2328 | } | 2338 | } |
2329 | pkt4 = (struct GNUNET_TUN_IPv4Header *)&tun[1]; | 2339 | pkt4 = (struct GNUNET_TUN_IPv4Header *) &tun[1]; |
2330 | get_destination_key_from_ip(AF_INET, &pkt4->destination_address, &key); | 2340 | get_destination_key_from_ip (AF_INET, &pkt4->destination_address, &key); |
2331 | de = GNUNET_CONTAINER_multihashmap_get(destination_map, &key); | 2341 | de = GNUNET_CONTAINER_multihashmap_get (destination_map, &key); |
2332 | if (NULL == de) | 2342 | if (NULL == de) |
2333 | { | 2343 | { |
2334 | char buf[INET_ADDRSTRLEN]; | 2344 | char buf[INET_ADDRSTRLEN]; |
2335 | 2345 | ||
2336 | GNUNET_log( | 2346 | GNUNET_log ( |
2337 | GNUNET_ERROR_TYPE_INFO, | 2347 | GNUNET_ERROR_TYPE_INFO, |
2338 | _("Packet received for unmapped destination `%s' (dropping it)\n"), | 2348 | _ ("Packet received for unmapped destination `%s' (dropping it)\n"), |
2339 | inet_ntop(AF_INET, &pkt4->destination_address, buf, sizeof(buf))); | 2349 | inet_ntop (AF_INET, &pkt4->destination_address, buf, sizeof(buf))); |
2340 | return GNUNET_OK; | 2350 | return GNUNET_OK; |
2341 | } | 2351 | } |
2342 | if (pkt4->header_length * 4 != sizeof(struct GNUNET_TUN_IPv4Header)) | 2352 | if (pkt4->header_length * 4 != sizeof(struct GNUNET_TUN_IPv4Header)) |
2343 | { | 2353 | { |
2344 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2354 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2345 | _("Received IPv4 packet with options (dropping it)\n")); | 2355 | _ ("Received IPv4 packet with options (dropping it)\n")); |
2346 | return GNUNET_OK; | 2356 | return GNUNET_OK; |
2347 | } | 2357 | } |
2348 | route_packet(de, | 2358 | route_packet (de, |
2349 | AF_INET, | 2359 | AF_INET, |
2350 | pkt4->protocol, | 2360 | pkt4->protocol, |
2351 | &pkt4->source_address, | 2361 | &pkt4->source_address, |
2352 | &pkt4->destination_address, | 2362 | &pkt4->destination_address, |
2353 | &pkt4[1], | 2363 | &pkt4[1], |
2354 | mlen - sizeof(struct GNUNET_TUN_IPv4Header)); | 2364 | mlen - sizeof(struct GNUNET_TUN_IPv4Header)); |
2355 | } | 2365 | } |
2356 | break; | 2366 | break; |
2357 | 2367 | ||
2358 | default: | 2368 | default: |
2359 | GNUNET_log( | 2369 | GNUNET_log ( |
2360 | GNUNET_ERROR_TYPE_INFO, | 2370 | GNUNET_ERROR_TYPE_INFO, |
2361 | _("Received packet of unknown protocol %d from TUN (dropping it)\n"), | 2371 | _ ("Received packet of unknown protocol %d from TUN (dropping it)\n"), |
2362 | (unsigned int)ntohs(tun->proto)); | 2372 | (unsigned int) ntohs (tun->proto)); |
2363 | break; | 2373 | break; |
2364 | } | 2374 | } |
2365 | return GNUNET_OK; | 2375 | return GNUNET_OK; |
2366 | } | 2376 | } |
2367 | 2377 | ||
@@ -2375,7 +2385,7 @@ message_token(void *cls, const struct GNUNET_MessageHeader *message) | |||
2375 | * #GNUNET_SYSERR on error | 2385 | * #GNUNET_SYSERR on error |
2376 | */ | 2386 | */ |
2377 | static int | 2387 | static int |
2378 | allocate_v4_address(struct in_addr *v4) | 2388 | allocate_v4_address (struct in_addr *v4) |
2379 | { | 2389 | { |
2380 | const char *ipv4addr = vpn_argv[4]; | 2390 | const char *ipv4addr = vpn_argv[4]; |
2381 | const char *ipv4mask = vpn_argv[5]; | 2391 | const char *ipv4mask = vpn_argv[5]; |
@@ -2385,30 +2395,30 @@ allocate_v4_address(struct in_addr *v4) | |||
2385 | struct GNUNET_HashCode key; | 2395 | struct GNUNET_HashCode key; |
2386 | unsigned int tries; | 2396 | unsigned int tries; |
2387 | 2397 | ||
2388 | GNUNET_assert(1 == inet_pton(AF_INET, ipv4addr, &addr)); | 2398 | GNUNET_assert (1 == inet_pton (AF_INET, ipv4addr, &addr)); |
2389 | GNUNET_assert(1 == inet_pton(AF_INET, ipv4mask, &mask)); | 2399 | GNUNET_assert (1 == inet_pton (AF_INET, ipv4mask, &mask)); |
2390 | /* Given 192.168.0.1/255.255.0.0, we want a mask | 2400 | /* Given 192.168.0.1/255.255.0.0, we want a mask |
2391 | of '192.168.255.255', thus: */ | 2401 | of '192.168.255.255', thus: */ |
2392 | mask.s_addr = addr.s_addr | ~mask.s_addr; | 2402 | mask.s_addr = addr.s_addr | ~mask.s_addr; |
2393 | tries = 0; | 2403 | tries = 0; |
2394 | do | 2404 | do |
2405 | { | ||
2406 | tries++; | ||
2407 | if (tries > 16) | ||
2395 | { | 2408 | { |
2396 | tries++; | 2409 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2397 | if (tries > 16) | 2410 | _ ( |
2398 | { | 2411 | "Failed to find unallocated IPv4 address in VPN's range\n")); |
2399 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 2412 | return GNUNET_SYSERR; |
2400 | _( | ||
2401 | "Failed to find unallocated IPv4 address in VPN's range\n")); | ||
2402 | return GNUNET_SYSERR; | ||
2403 | } | ||
2404 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ | ||
2405 | rnd.s_addr = | ||
2406 | GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | ||
2407 | v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; | ||
2408 | get_destination_key_from_ip(AF_INET, v4, &key); | ||
2409 | } | 2413 | } |
2414 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ | ||
2415 | rnd.s_addr = | ||
2416 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); | ||
2417 | v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; | ||
2418 | get_destination_key_from_ip (AF_INET, v4, &key); | ||
2419 | } | ||
2410 | while ((GNUNET_YES == | 2420 | while ((GNUNET_YES == |
2411 | GNUNET_CONTAINER_multihashmap_contains(destination_map, &key)) || | 2421 | GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) || |
2412 | (v4->s_addr == addr.s_addr) || (v4->s_addr == mask.s_addr)); | 2422 | (v4->s_addr == addr.s_addr) || (v4->s_addr == mask.s_addr)); |
2413 | return GNUNET_OK; | 2423 | return GNUNET_OK; |
2414 | } | 2424 | } |
@@ -2423,7 +2433,7 @@ allocate_v4_address(struct in_addr *v4) | |||
2423 | * #GNUNET_SYSERR on error | 2433 | * #GNUNET_SYSERR on error |
2424 | */ | 2434 | */ |
2425 | static int | 2435 | static int |
2426 | allocate_v6_address(struct in6_addr *v6) | 2436 | allocate_v6_address (struct in6_addr *v6) |
2427 | { | 2437 | { |
2428 | const char *ipv6addr = vpn_argv[2]; | 2438 | const char *ipv6addr = vpn_argv[2]; |
2429 | struct in6_addr addr; | 2439 | struct in6_addr addr; |
@@ -2433,8 +2443,8 @@ allocate_v6_address(struct in6_addr *v6) | |||
2433 | struct GNUNET_HashCode key; | 2443 | struct GNUNET_HashCode key; |
2434 | unsigned int tries; | 2444 | unsigned int tries; |
2435 | 2445 | ||
2436 | GNUNET_assert(1 == inet_pton(AF_INET6, ipv6addr, &addr)); | 2446 | GNUNET_assert (1 == inet_pton (AF_INET6, ipv6addr, &addr)); |
2437 | GNUNET_assert(ipv6prefix < 128); | 2447 | GNUNET_assert (ipv6prefix < 128); |
2438 | /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, | 2448 | /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, |
2439 | thus: */ | 2449 | thus: */ |
2440 | mask = addr; | 2450 | mask = addr; |
@@ -2444,28 +2454,28 @@ allocate_v6_address(struct in6_addr *v6) | |||
2444 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ | 2454 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ |
2445 | tries = 0; | 2455 | tries = 0; |
2446 | do | 2456 | do |
2457 | { | ||
2458 | tries++; | ||
2459 | if (tries > 16) | ||
2447 | { | 2460 | { |
2448 | tries++; | 2461 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2449 | if (tries > 16) | 2462 | _ ( |
2450 | { | 2463 | "Failed to find unallocated IPv6 address in VPN's range\n")); |
2451 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 2464 | return GNUNET_SYSERR; |
2452 | _( | 2465 | } |
2453 | "Failed to find unallocated IPv6 address in VPN's range\n")); | 2466 | for (i = 0; i < 16; i++) |
2454 | return GNUNET_SYSERR; | 2467 | { |
2455 | } | 2468 | rnd.s6_addr[i] = |
2456 | for (i = 0; i < 16; i++) | 2469 | (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
2457 | { | 2470 | 256); |
2458 | rnd.s6_addr[i] = | 2471 | v6->s6_addr[i] = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; |
2459 | (unsigned char)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | ||
2460 | 256); | ||
2461 | v6->s6_addr[i] = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; | ||
2462 | } | ||
2463 | get_destination_key_from_ip(AF_INET6, v6, &key); | ||
2464 | } | 2472 | } |
2473 | get_destination_key_from_ip (AF_INET6, v6, &key); | ||
2474 | } | ||
2465 | while ((GNUNET_YES == | 2475 | while ((GNUNET_YES == |
2466 | GNUNET_CONTAINER_multihashmap_contains(destination_map, &key)) || | 2476 | GNUNET_CONTAINER_multihashmap_contains (destination_map, &key)) || |
2467 | (0 == GNUNET_memcmp(v6, &addr)) || | 2477 | (0 == GNUNET_memcmp (v6, &addr)) || |
2468 | (0 == GNUNET_memcmp(v6, &mask))); | 2478 | (0 == GNUNET_memcmp (v6, &mask))); |
2469 | return GNUNET_OK; | 2479 | return GNUNET_OK; |
2470 | } | 2480 | } |
2471 | 2481 | ||
@@ -2476,31 +2486,31 @@ allocate_v6_address(struct in6_addr *v6) | |||
2476 | * @param de entry to free | 2486 | * @param de entry to free |
2477 | */ | 2487 | */ |
2478 | static void | 2488 | static void |
2479 | free_destination_entry(struct DestinationEntry *de) | 2489 | free_destination_entry (struct DestinationEntry *de) |
2480 | { | 2490 | { |
2481 | struct DestinationChannel *dt; | 2491 | struct DestinationChannel *dt; |
2482 | 2492 | ||
2483 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2484 | "Cleaning up destination entry `%s'\n", | 2494 | "Cleaning up destination entry `%s'\n", |
2485 | print_channel_destination(de)); | 2495 | print_channel_destination (de)); |
2486 | GNUNET_STATISTICS_update(stats, | 2496 | GNUNET_STATISTICS_update (stats, |
2487 | gettext_noop("# Active destinations"), | 2497 | gettext_noop ("# Active destinations"), |
2488 | -1, | 2498 | -1, |
2489 | GNUNET_NO); | 2499 | GNUNET_NO); |
2490 | while (NULL != (dt = de->dt_head)) | 2500 | while (NULL != (dt = de->dt_head)) |
2491 | { | 2501 | { |
2492 | GNUNET_CONTAINER_DLL_remove(de->dt_head, de->dt_tail, dt); | 2502 | GNUNET_CONTAINER_DLL_remove (de->dt_head, de->dt_tail, dt); |
2493 | GNUNET_free(dt); | 2503 | GNUNET_free (dt); |
2494 | } | 2504 | } |
2495 | if (NULL != de->heap_node) | 2505 | if (NULL != de->heap_node) |
2496 | { | 2506 | { |
2497 | GNUNET_CONTAINER_heap_remove_node(de->heap_node); | 2507 | GNUNET_CONTAINER_heap_remove_node (de->heap_node); |
2498 | de->heap_node = NULL; | 2508 | de->heap_node = NULL; |
2499 | GNUNET_assert( | 2509 | GNUNET_assert ( |
2500 | GNUNET_YES == | 2510 | GNUNET_YES == |
2501 | GNUNET_CONTAINER_multihashmap_remove(destination_map, &de->key, de)); | 2511 | GNUNET_CONTAINER_multihashmap_remove (destination_map, &de->key, de)); |
2502 | } | 2512 | } |
2503 | GNUNET_free(de); | 2513 | GNUNET_free (de); |
2504 | } | 2514 | } |
2505 | 2515 | ||
2506 | 2516 | ||
@@ -2510,15 +2520,15 @@ free_destination_entry(struct DestinationEntry *de) | |||
2510 | * @param except destination that must NOT be cleaned up, even if it is the oldest | 2520 | * @param except destination that must NOT be cleaned up, even if it is the oldest |
2511 | */ | 2521 | */ |
2512 | static void | 2522 | static void |
2513 | expire_destination(struct DestinationEntry *except) | 2523 | expire_destination (struct DestinationEntry *except) |
2514 | { | 2524 | { |
2515 | struct DestinationEntry *de; | 2525 | struct DestinationEntry *de; |
2516 | 2526 | ||
2517 | de = GNUNET_CONTAINER_heap_peek(destination_heap); | 2527 | de = GNUNET_CONTAINER_heap_peek (destination_heap); |
2518 | GNUNET_assert(NULL != de); | 2528 | GNUNET_assert (NULL != de); |
2519 | if (except == de) | 2529 | if (except == de) |
2520 | return; /* can't do this */ | 2530 | return; /* can't do this */ |
2521 | free_destination_entry(de); | 2531 | free_destination_entry (de); |
2522 | } | 2532 | } |
2523 | 2533 | ||
2524 | 2534 | ||
@@ -2537,45 +2547,45 @@ expire_destination(struct DestinationEntry *except) | |||
2537 | * an unsupported address family (not AF_INET, AF_INET6 or AF_UNSPEC) | 2547 | * an unsupported address family (not AF_INET, AF_INET6 or AF_UNSPEC) |
2538 | */ | 2548 | */ |
2539 | static int | 2549 | static int |
2540 | allocate_response_ip(int *result_af, | 2550 | allocate_response_ip (int *result_af, |
2541 | void **addr, | 2551 | void **addr, |
2542 | struct in_addr *v4, | 2552 | struct in_addr *v4, |
2543 | struct in6_addr *v6) | 2553 | struct in6_addr *v6) |
2544 | { | 2554 | { |
2545 | *addr = NULL; | 2555 | *addr = NULL; |
2546 | switch (*result_af) | 2556 | switch (*result_af) |
2547 | { | 2557 | { |
2548 | case AF_INET: | 2558 | case AF_INET: |
2549 | if (GNUNET_OK != allocate_v4_address(v4)) | 2559 | if (GNUNET_OK != allocate_v4_address (v4)) |
2550 | *result_af = AF_UNSPEC; | 2560 | *result_af = AF_UNSPEC; |
2551 | else | 2561 | else |
2552 | *addr = v4; | 2562 | *addr = v4; |
2553 | break; | 2563 | break; |
2554 | |||
2555 | case AF_INET6: | ||
2556 | if (GNUNET_OK != allocate_v6_address(v6)) | ||
2557 | *result_af = AF_UNSPEC; | ||
2558 | else | ||
2559 | *addr = v6; | ||
2560 | break; | ||
2561 | 2564 | ||
2562 | case AF_UNSPEC: | 2565 | case AF_INET6: |
2563 | if (GNUNET_OK == allocate_v4_address(v4)) | 2566 | if (GNUNET_OK != allocate_v6_address (v6)) |
2564 | { | 2567 | *result_af = AF_UNSPEC; |
2565 | *addr = v4; | 2568 | else |
2566 | *result_af = AF_INET; | 2569 | *addr = v6; |
2567 | } | 2570 | break; |
2568 | else if (GNUNET_OK == allocate_v6_address(v6)) | ||
2569 | { | ||
2570 | *addr = v6; | ||
2571 | *result_af = AF_INET6; | ||
2572 | } | ||
2573 | break; | ||
2574 | 2571 | ||
2575 | default: | 2572 | case AF_UNSPEC: |
2576 | GNUNET_break(0); | 2573 | if (GNUNET_OK == allocate_v4_address (v4)) |
2577 | return GNUNET_SYSERR; | 2574 | { |
2575 | *addr = v4; | ||
2576 | *result_af = AF_INET; | ||
2577 | } | ||
2578 | else if (GNUNET_OK == allocate_v6_address (v6)) | ||
2579 | { | ||
2580 | *addr = v6; | ||
2581 | *result_af = AF_INET6; | ||
2578 | } | 2582 | } |
2583 | break; | ||
2584 | |||
2585 | default: | ||
2586 | GNUNET_break (0); | ||
2587 | return GNUNET_SYSERR; | ||
2588 | } | ||
2579 | return GNUNET_OK; | 2589 | return GNUNET_OK; |
2580 | } | 2590 | } |
2581 | 2591 | ||
@@ -2590,36 +2600,36 @@ allocate_response_ip(int *result_af, | |||
2590 | * @return #GNUNET_OK if @a msg is well-formed | 2600 | * @return #GNUNET_OK if @a msg is well-formed |
2591 | */ | 2601 | */ |
2592 | static int | 2602 | static int |
2593 | check_client_redirect_to_ip(void *cls, | 2603 | check_client_redirect_to_ip (void *cls, |
2594 | const struct RedirectToIpRequestMessage *msg) | 2604 | const struct RedirectToIpRequestMessage *msg) |
2595 | { | 2605 | { |
2596 | size_t alen; | 2606 | size_t alen; |
2597 | int addr_af; | 2607 | int addr_af; |
2598 | 2608 | ||
2599 | alen = ntohs(msg->header.size) - sizeof(struct RedirectToIpRequestMessage); | 2609 | alen = ntohs (msg->header.size) - sizeof(struct RedirectToIpRequestMessage); |
2600 | addr_af = (int)htonl(msg->addr_af); | 2610 | addr_af = (int) htonl (msg->addr_af); |
2601 | switch (addr_af) | 2611 | switch (addr_af) |
2612 | { | ||
2613 | case AF_INET: | ||
2614 | if (alen != sizeof(struct in_addr)) | ||
2602 | { | 2615 | { |
2603 | case AF_INET: | 2616 | GNUNET_break (0); |
2604 | if (alen != sizeof(struct in_addr)) | 2617 | return GNUNET_SYSERR; |
2605 | { | 2618 | } |
2606 | GNUNET_break(0); | 2619 | break; |
2607 | return GNUNET_SYSERR; | ||
2608 | } | ||
2609 | break; | ||
2610 | |||
2611 | case AF_INET6: | ||
2612 | if (alen != sizeof(struct in6_addr)) | ||
2613 | { | ||
2614 | GNUNET_break(0); | ||
2615 | return GNUNET_SYSERR; | ||
2616 | } | ||
2617 | break; | ||
2618 | 2620 | ||
2619 | default: | 2621 | case AF_INET6: |
2620 | GNUNET_break(0); | 2622 | if (alen != sizeof(struct in6_addr)) |
2623 | { | ||
2624 | GNUNET_break (0); | ||
2621 | return GNUNET_SYSERR; | 2625 | return GNUNET_SYSERR; |
2622 | } | 2626 | } |
2627 | break; | ||
2628 | |||
2629 | default: | ||
2630 | GNUNET_break (0); | ||
2631 | return GNUNET_SYSERR; | ||
2632 | } | ||
2623 | return GNUNET_OK; | 2633 | return GNUNET_OK; |
2624 | } | 2634 | } |
2625 | 2635 | ||
@@ -2633,8 +2643,8 @@ check_client_redirect_to_ip(void *cls, | |||
2633 | * @param msg redirection request | 2643 | * @param msg redirection request |
2634 | */ | 2644 | */ |
2635 | static void | 2645 | static void |
2636 | handle_client_redirect_to_ip(void *cls, | 2646 | handle_client_redirect_to_ip (void *cls, |
2637 | const struct RedirectToIpRequestMessage *msg) | 2647 | const struct RedirectToIpRequestMessage *msg) |
2638 | { | 2648 | { |
2639 | struct GNUNET_SERVICE_Client *client = cls; | 2649 | struct GNUNET_SERVICE_Client *client = cls; |
2640 | size_t alen; | 2650 | size_t alen; |
@@ -2646,59 +2656,59 @@ handle_client_redirect_to_ip(void *cls, | |||
2646 | struct DestinationEntry *de; | 2656 | struct DestinationEntry *de; |
2647 | struct GNUNET_HashCode key; | 2657 | struct GNUNET_HashCode key; |
2648 | 2658 | ||
2649 | alen = ntohs(msg->header.size) - sizeof(struct RedirectToIpRequestMessage); | 2659 | alen = ntohs (msg->header.size) - sizeof(struct RedirectToIpRequestMessage); |
2650 | addr_af = (int)htonl(msg->addr_af); | 2660 | addr_af = (int) htonl (msg->addr_af); |
2651 | /* allocate response IP */ | 2661 | /* allocate response IP */ |
2652 | result_af = (int)htonl(msg->result_af); | 2662 | result_af = (int) htonl (msg->result_af); |
2653 | if (GNUNET_OK != allocate_response_ip(&result_af, &addr, &v4, &v6)) | 2663 | if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6)) |
2654 | { | 2664 | { |
2655 | GNUNET_SERVICE_client_drop(client); | 2665 | GNUNET_SERVICE_client_drop (client); |
2656 | return; | 2666 | return; |
2657 | } | 2667 | } |
2658 | /* send reply with our IP address */ | 2668 | /* send reply with our IP address */ |
2659 | send_client_reply(client, msg->request_id, result_af, addr); | 2669 | send_client_reply (client, msg->request_id, result_af, addr); |
2660 | if (result_af == AF_UNSPEC) | 2670 | if (result_af == AF_UNSPEC) |
2661 | { | 2671 | { |
2662 | /* failure, we're done */ | 2672 | /* failure, we're done */ |
2663 | GNUNET_SERVICE_client_continue(client); | 2673 | GNUNET_SERVICE_client_continue (client); |
2664 | return; | 2674 | return; |
2665 | } | 2675 | } |
2666 | 2676 | ||
2667 | { | 2677 | { |
2668 | char sbuf[INET6_ADDRSTRLEN]; | 2678 | char sbuf[INET6_ADDRSTRLEN]; |
2669 | char dbuf[INET6_ADDRSTRLEN]; | 2679 | char dbuf[INET6_ADDRSTRLEN]; |
2670 | 2680 | ||
2671 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2672 | "Allocated address %s for redirection via exit to %s\n", | 2682 | "Allocated address %s for redirection via exit to %s\n", |
2673 | inet_ntop(result_af, addr, sbuf, sizeof(sbuf)), | 2683 | inet_ntop (result_af, addr, sbuf, sizeof(sbuf)), |
2674 | inet_ntop(addr_af, &msg[1], dbuf, sizeof(dbuf))); | 2684 | inet_ntop (addr_af, &msg[1], dbuf, sizeof(dbuf))); |
2675 | } | 2685 | } |
2676 | 2686 | ||
2677 | /* setup destination record */ | 2687 | /* setup destination record */ |
2678 | de = GNUNET_new(struct DestinationEntry); | 2688 | de = GNUNET_new (struct DestinationEntry); |
2679 | de->is_service = GNUNET_NO; | 2689 | de->is_service = GNUNET_NO; |
2680 | de->details.exit_destination.af = addr_af; | 2690 | de->details.exit_destination.af = addr_af; |
2681 | GNUNET_memcpy(&de->details.exit_destination.ip, &msg[1], alen); | 2691 | GNUNET_memcpy (&de->details.exit_destination.ip, &msg[1], alen); |
2682 | get_destination_key_from_ip(result_af, addr, &key); | 2692 | get_destination_key_from_ip (result_af, addr, &key); |
2683 | de->key = key; | 2693 | de->key = key; |
2684 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( | 2694 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( |
2685 | destination_map, | 2695 | destination_map, |
2686 | &key, | 2696 | &key, |
2687 | de, | 2697 | de, |
2688 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 2698 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
2689 | de->heap_node = GNUNET_CONTAINER_heap_insert(destination_heap, | 2699 | de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap, |
2690 | de, | 2700 | de, |
2691 | GNUNET_TIME_absolute_ntoh( | 2701 | GNUNET_TIME_absolute_ntoh ( |
2692 | msg->expiration_time) | 2702 | msg->expiration_time) |
2693 | .abs_value_us); | 2703 | .abs_value_us); |
2694 | GNUNET_STATISTICS_update(stats, | 2704 | GNUNET_STATISTICS_update (stats, |
2695 | gettext_noop("# Active destinations"), | 2705 | gettext_noop ("# Active destinations"), |
2696 | 1, | 2706 | 1, |
2697 | GNUNET_NO); | 2707 | GNUNET_NO); |
2698 | while (GNUNET_CONTAINER_multihashmap_size(destination_map) > | 2708 | while (GNUNET_CONTAINER_multihashmap_size (destination_map) > |
2699 | max_destination_mappings) | 2709 | max_destination_mappings) |
2700 | expire_destination(de); | 2710 | expire_destination (de); |
2701 | GNUNET_SERVICE_client_continue(client); | 2711 | GNUNET_SERVICE_client_continue (client); |
2702 | } | 2712 | } |
2703 | 2713 | ||
2704 | 2714 | ||
@@ -2711,7 +2721,7 @@ handle_client_redirect_to_ip(void *cls, | |||
2711 | * @param msg redirection request | 2721 | * @param msg redirection request |
2712 | */ | 2722 | */ |
2713 | static void | 2723 | static void |
2714 | handle_client_redirect_to_service( | 2724 | handle_client_redirect_to_service ( |
2715 | void *cls, | 2725 | void *cls, |
2716 | const struct RedirectToServiceRequestMessage *msg) | 2726 | const struct RedirectToServiceRequestMessage *msg) |
2717 | { | 2727 | { |
@@ -2725,59 +2735,59 @@ handle_client_redirect_to_service( | |||
2725 | struct DestinationChannel *dt; | 2735 | struct DestinationChannel *dt; |
2726 | 2736 | ||
2727 | /* allocate response IP */ | 2737 | /* allocate response IP */ |
2728 | result_af = (int)htonl(msg->result_af); | 2738 | result_af = (int) htonl (msg->result_af); |
2729 | if (GNUNET_OK != allocate_response_ip(&result_af, &addr, &v4, &v6)) | 2739 | if (GNUNET_OK != allocate_response_ip (&result_af, &addr, &v4, &v6)) |
2730 | { | 2740 | { |
2731 | GNUNET_break(0); | 2741 | GNUNET_break (0); |
2732 | GNUNET_SERVICE_client_drop(client); | 2742 | GNUNET_SERVICE_client_drop (client); |
2733 | return; | 2743 | return; |
2734 | } | 2744 | } |
2735 | send_client_reply(client, msg->request_id, result_af, addr); | 2745 | send_client_reply (client, msg->request_id, result_af, addr); |
2736 | if (result_af == AF_UNSPEC) | 2746 | if (result_af == AF_UNSPEC) |
2737 | { | 2747 | { |
2738 | /* failure, we're done */ | 2748 | /* failure, we're done */ |
2739 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 2749 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2740 | _("Failed to allocate IP address for new destination\n")); | 2750 | _ ("Failed to allocate IP address for new destination\n")); |
2741 | GNUNET_SERVICE_client_continue(client); | 2751 | GNUNET_SERVICE_client_continue (client); |
2742 | return; | 2752 | return; |
2743 | } | 2753 | } |
2744 | 2754 | ||
2745 | { | 2755 | { |
2746 | char sbuf[INET6_ADDRSTRLEN]; | 2756 | char sbuf[INET6_ADDRSTRLEN]; |
2747 | 2757 | ||
2748 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2749 | "Allocated address %s for redirection to service %s on peer %s\n", | 2759 | "Allocated address %s for redirection to service %s on peer %s\n", |
2750 | inet_ntop(result_af, addr, sbuf, sizeof(sbuf)), | 2760 | inet_ntop (result_af, addr, sbuf, sizeof(sbuf)), |
2751 | GNUNET_h2s(&msg->service_descriptor), | 2761 | GNUNET_h2s (&msg->service_descriptor), |
2752 | GNUNET_i2s(&msg->target)); | 2762 | GNUNET_i2s (&msg->target)); |
2753 | } | 2763 | } |
2754 | 2764 | ||
2755 | /* setup destination record */ | 2765 | /* setup destination record */ |
2756 | de = GNUNET_new(struct DestinationEntry); | 2766 | de = GNUNET_new (struct DestinationEntry); |
2757 | de->is_service = GNUNET_YES; | 2767 | de->is_service = GNUNET_YES; |
2758 | de->details.service_destination.target = msg->target; | 2768 | de->details.service_destination.target = msg->target; |
2759 | de->details.service_destination.service_descriptor = msg->service_descriptor; | 2769 | de->details.service_destination.service_descriptor = msg->service_descriptor; |
2760 | get_destination_key_from_ip(result_af, addr, &key); | 2770 | get_destination_key_from_ip (result_af, addr, &key); |
2761 | de->key = key; | 2771 | de->key = key; |
2762 | GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( | 2772 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put ( |
2763 | destination_map, | 2773 | destination_map, |
2764 | &key, | 2774 | &key, |
2765 | de, | 2775 | de, |
2766 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 2776 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
2767 | de->heap_node = GNUNET_CONTAINER_heap_insert(destination_heap, | 2777 | de->heap_node = GNUNET_CONTAINER_heap_insert (destination_heap, |
2768 | de, | 2778 | de, |
2769 | GNUNET_TIME_absolute_ntoh( | 2779 | GNUNET_TIME_absolute_ntoh ( |
2770 | msg->expiration_time) | 2780 | msg->expiration_time) |
2771 | .abs_value_us); | 2781 | .abs_value_us); |
2772 | while (GNUNET_CONTAINER_multihashmap_size(destination_map) > | 2782 | while (GNUNET_CONTAINER_multihashmap_size (destination_map) > |
2773 | max_destination_mappings) | 2783 | max_destination_mappings) |
2774 | expire_destination(de); | 2784 | expire_destination (de); |
2775 | 2785 | ||
2776 | dt = GNUNET_new(struct DestinationChannel); | 2786 | dt = GNUNET_new (struct DestinationChannel); |
2777 | dt->destination = de; | 2787 | dt->destination = de; |
2778 | GNUNET_CONTAINER_DLL_insert(de->dt_head, de->dt_tail, dt); | 2788 | GNUNET_CONTAINER_DLL_insert (de->dt_head, de->dt_tail, dt); |
2779 | /* we're done */ | 2789 | /* we're done */ |
2780 | GNUNET_SERVICE_client_continue(client); | 2790 | GNUNET_SERVICE_client_continue (client); |
2781 | } | 2791 | } |
2782 | 2792 | ||
2783 | 2793 | ||
@@ -2790,11 +2800,11 @@ handle_client_redirect_to_service( | |||
2790 | * @return #GNUNET_OK (continue to iterate) | 2800 | * @return #GNUNET_OK (continue to iterate) |
2791 | */ | 2801 | */ |
2792 | static int | 2802 | static int |
2793 | cleanup_destination(void *cls, const struct GNUNET_HashCode *key, void *value) | 2803 | cleanup_destination (void *cls, const struct GNUNET_HashCode *key, void *value) |
2794 | { | 2804 | { |
2795 | struct DestinationEntry *de = value; | 2805 | struct DestinationEntry *de = value; |
2796 | 2806 | ||
2797 | free_destination_entry(de); | 2807 | free_destination_entry (de); |
2798 | return GNUNET_OK; | 2808 | return GNUNET_OK; |
2799 | } | 2809 | } |
2800 | 2810 | ||
@@ -2808,14 +2818,14 @@ cleanup_destination(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
2808 | * @return #GNUNET_OK (continue to iterate) | 2818 | * @return #GNUNET_OK (continue to iterate) |
2809 | */ | 2819 | */ |
2810 | static int | 2820 | static int |
2811 | cleanup_channel(void *cls, const struct GNUNET_HashCode *key, void *value) | 2821 | cleanup_channel (void *cls, const struct GNUNET_HashCode *key, void *value) |
2812 | { | 2822 | { |
2813 | struct ChannelState *ts = value; | 2823 | struct ChannelState *ts = value; |
2814 | 2824 | ||
2815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2816 | "Tearing down channel to `%s' during cleanup\n", | 2826 | "Tearing down channel to `%s' during cleanup\n", |
2817 | print_channel_destination(&ts->destination)); | 2827 | print_channel_destination (&ts->destination)); |
2818 | free_channel_state(ts); | 2828 | free_channel_state (ts); |
2819 | return GNUNET_OK; | 2829 | return GNUNET_OK; |
2820 | } | 2830 | } |
2821 | 2831 | ||
@@ -2826,53 +2836,53 @@ cleanup_channel(void *cls, const struct GNUNET_HashCode *key, void *value) | |||
2826 | * @param cls unused | 2836 | * @param cls unused |
2827 | */ | 2837 | */ |
2828 | static void | 2838 | static void |
2829 | cleanup(void *cls) | 2839 | cleanup (void *cls) |
2830 | { | 2840 | { |
2831 | unsigned int i; | 2841 | unsigned int i; |
2832 | 2842 | ||
2833 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "VPN is shutting down\n"); | 2843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "VPN is shutting down\n"); |
2834 | if (NULL != destination_map) | 2844 | if (NULL != destination_map) |
2835 | { | 2845 | { |
2836 | GNUNET_CONTAINER_multihashmap_iterate(destination_map, | 2846 | GNUNET_CONTAINER_multihashmap_iterate (destination_map, |
2837 | &cleanup_destination, | 2847 | &cleanup_destination, |
2838 | NULL); | 2848 | NULL); |
2839 | GNUNET_CONTAINER_multihashmap_destroy(destination_map); | 2849 | GNUNET_CONTAINER_multihashmap_destroy (destination_map); |
2840 | destination_map = NULL; | 2850 | destination_map = NULL; |
2841 | } | 2851 | } |
2842 | if (NULL != destination_heap) | 2852 | if (NULL != destination_heap) |
2843 | { | 2853 | { |
2844 | GNUNET_CONTAINER_heap_destroy(destination_heap); | 2854 | GNUNET_CONTAINER_heap_destroy (destination_heap); |
2845 | destination_heap = NULL; | 2855 | destination_heap = NULL; |
2846 | } | 2856 | } |
2847 | if (NULL != channel_map) | 2857 | if (NULL != channel_map) |
2848 | { | 2858 | { |
2849 | GNUNET_CONTAINER_multihashmap_iterate(channel_map, &cleanup_channel, NULL); | 2859 | GNUNET_CONTAINER_multihashmap_iterate (channel_map, &cleanup_channel, NULL); |
2850 | GNUNET_CONTAINER_multihashmap_destroy(channel_map); | 2860 | GNUNET_CONTAINER_multihashmap_destroy (channel_map); |
2851 | channel_map = NULL; | 2861 | channel_map = NULL; |
2852 | } | 2862 | } |
2853 | if (NULL != channel_heap) | 2863 | if (NULL != channel_heap) |
2854 | { | 2864 | { |
2855 | GNUNET_CONTAINER_heap_destroy(channel_heap); | 2865 | GNUNET_CONTAINER_heap_destroy (channel_heap); |
2856 | channel_heap = NULL; | 2866 | channel_heap = NULL; |
2857 | } | 2867 | } |
2858 | if (NULL != cadet_handle) | 2868 | if (NULL != cadet_handle) |
2859 | { | 2869 | { |
2860 | GNUNET_CADET_disconnect(cadet_handle); | 2870 | GNUNET_CADET_disconnect (cadet_handle); |
2861 | cadet_handle = NULL; | 2871 | cadet_handle = NULL; |
2862 | } | 2872 | } |
2863 | if (NULL != helper_handle) | 2873 | if (NULL != helper_handle) |
2864 | { | 2874 | { |
2865 | GNUNET_HELPER_kill(helper_handle, GNUNET_NO); | 2875 | GNUNET_HELPER_kill (helper_handle, GNUNET_NO); |
2866 | GNUNET_HELPER_wait(helper_handle); | 2876 | GNUNET_HELPER_wait (helper_handle); |
2867 | helper_handle = NULL; | 2877 | helper_handle = NULL; |
2868 | } | 2878 | } |
2869 | if (NULL != stats) | 2879 | if (NULL != stats) |
2870 | { | 2880 | { |
2871 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 2881 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
2872 | stats = NULL; | 2882 | stats = NULL; |
2873 | } | 2883 | } |
2874 | for (i = 0; i < 5; i++) | 2884 | for (i = 0; i < 5; i++) |
2875 | GNUNET_free_non_null(vpn_argv[i]); | 2885 | GNUNET_free_non_null (vpn_argv[i]); |
2876 | } | 2886 | } |
2877 | 2887 | ||
2878 | 2888 | ||
@@ -2885,9 +2895,9 @@ cleanup(void *cls) | |||
2885 | * @return @a c | 2895 | * @return @a c |
2886 | */ | 2896 | */ |
2887 | static void * | 2897 | static void * |
2888 | client_connect_cb(void *cls, | 2898 | client_connect_cb (void *cls, |
2889 | struct GNUNET_SERVICE_Client *c, | 2899 | struct GNUNET_SERVICE_Client *c, |
2890 | struct GNUNET_MQ_Handle *mq) | 2900 | struct GNUNET_MQ_Handle *mq) |
2891 | { | 2901 | { |
2892 | return c; | 2902 | return c; |
2893 | } | 2903 | } |
@@ -2901,11 +2911,11 @@ client_connect_cb(void *cls, | |||
2901 | * @param internal_cls should be equal to @a c | 2911 | * @param internal_cls should be equal to @a c |
2902 | */ | 2912 | */ |
2903 | static void | 2913 | static void |
2904 | client_disconnect_cb(void *cls, | 2914 | client_disconnect_cb (void *cls, |
2905 | struct GNUNET_SERVICE_Client *c, | 2915 | struct GNUNET_SERVICE_Client *c, |
2906 | void *internal_cls) | 2916 | void *internal_cls) |
2907 | { | 2917 | { |
2908 | GNUNET_assert(c == internal_cls); | 2918 | GNUNET_assert (c == internal_cls); |
2909 | } | 2919 | } |
2910 | 2920 | ||
2911 | 2921 | ||
@@ -2917,9 +2927,9 @@ client_disconnect_cb(void *cls, | |||
2917 | * @param service the initialized service | 2927 | * @param service the initialized service |
2918 | */ | 2928 | */ |
2919 | static void | 2929 | static void |
2920 | run(void *cls, | 2930 | run (void *cls, |
2921 | const struct GNUNET_CONFIGURATION_Handle *cfg_, | 2931 | const struct GNUNET_CONFIGURATION_Handle *cfg_, |
2922 | struct GNUNET_SERVICE_Handle *service) | 2932 | struct GNUNET_SERVICE_Handle *service) |
2923 | { | 2933 | { |
2924 | char *ifname; | 2934 | char *ifname; |
2925 | char *ipv6addr; | 2935 | char *ipv6addr; |
@@ -2930,187 +2940,187 @@ run(void *cls, | |||
2930 | struct in6_addr v6; | 2940 | struct in6_addr v6; |
2931 | char *binary; | 2941 | char *binary; |
2932 | 2942 | ||
2933 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-helper-vpn"); | 2943 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); |
2934 | 2944 | ||
2935 | if (GNUNET_YES != | 2945 | if (GNUNET_YES != |
2936 | GNUNET_OS_check_helper_binary( | 2946 | GNUNET_OS_check_helper_binary ( |
2937 | binary, | 2947 | binary, |
2938 | GNUNET_YES, | 2948 | GNUNET_YES, |
2939 | "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) //ipv4 only please! | 2949 | "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) // ipv4 only please! |
2940 | { | 2950 | { |
2941 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 2951 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2942 | "`%s' is not SUID, refusing to run.\n", | 2952 | "`%s' is not SUID, refusing to run.\n", |
2943 | "gnunet-helper-vpn"); | 2953 | "gnunet-helper-vpn"); |
2944 | GNUNET_free(binary); | 2954 | GNUNET_free (binary); |
2945 | global_ret = 1; | 2955 | global_ret = 1; |
2946 | /* we won't "really" exit here, as the 'service' is still running; | 2956 | /* we won't "really" exit here, as the 'service' is still running; |
2947 | however, as no handlers are registered, the service won't do | 2957 | however, as no handlers are registered, the service won't do |
2948 | anything either */ | 2958 | anything either */ |
2949 | return; | 2959 | return; |
2950 | } | 2960 | } |
2951 | GNUNET_free(binary); | 2961 | GNUNET_free (binary); |
2952 | cfg = cfg_; | 2962 | cfg = cfg_; |
2953 | stats = GNUNET_STATISTICS_create("vpn", cfg); | 2963 | stats = GNUNET_STATISTICS_create ("vpn", cfg); |
2954 | if (GNUNET_OK != | 2964 | if (GNUNET_OK != |
2955 | GNUNET_CONFIGURATION_get_value_number(cfg, | 2965 | GNUNET_CONFIGURATION_get_value_number (cfg, |
2956 | "VPN", | 2966 | "VPN", |
2957 | "MAX_MAPPING", | 2967 | "MAX_MAPPING", |
2958 | &max_destination_mappings)) | 2968 | &max_destination_mappings)) |
2959 | max_destination_mappings = 200; | 2969 | max_destination_mappings = 200; |
2960 | if (GNUNET_OK != | 2970 | if (GNUNET_OK != |
2961 | GNUNET_CONFIGURATION_get_value_number(cfg, | 2971 | GNUNET_CONFIGURATION_get_value_number (cfg, |
2962 | "VPN", | 2972 | "VPN", |
2963 | "MAX_TUNNELS", | 2973 | "MAX_TUNNELS", |
2964 | &max_channel_mappings)) | 2974 | &max_channel_mappings)) |
2965 | max_channel_mappings = 200; | 2975 | max_channel_mappings = 200; |
2966 | 2976 | ||
2967 | destination_map = | 2977 | destination_map = |
2968 | GNUNET_CONTAINER_multihashmap_create(max_destination_mappings * 2, | 2978 | GNUNET_CONTAINER_multihashmap_create (max_destination_mappings * 2, |
2969 | GNUNET_NO); | 2979 | GNUNET_NO); |
2970 | destination_heap = | 2980 | destination_heap = |
2971 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2981 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2972 | channel_map = | 2982 | channel_map = |
2973 | GNUNET_CONTAINER_multihashmap_create(max_channel_mappings * 2, GNUNET_NO); | 2983 | GNUNET_CONTAINER_multihashmap_create (max_channel_mappings * 2, GNUNET_NO); |
2974 | channel_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2984 | channel_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2975 | 2985 | ||
2976 | 2986 | ||
2977 | vpn_argv[0] = GNUNET_strdup("vpn-gnunet"); | 2987 | vpn_argv[0] = GNUNET_strdup ("vpn-gnunet"); |
2978 | if (GNUNET_SYSERR == | 2988 | if (GNUNET_SYSERR == |
2979 | GNUNET_CONFIGURATION_get_value_string(cfg, "VPN", "IFNAME", &ifname)) | 2989 | GNUNET_CONFIGURATION_get_value_string (cfg, "VPN", "IFNAME", &ifname)) |
2980 | { | 2990 | { |
2981 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "VPN", "IFNAME"); | 2991 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IFNAME"); |
2982 | GNUNET_SCHEDULER_shutdown(); | 2992 | GNUNET_SCHEDULER_shutdown (); |
2983 | return; | 2993 | return; |
2984 | } | 2994 | } |
2985 | vpn_argv[1] = ifname; | 2995 | vpn_argv[1] = ifname; |
2986 | ipv6addr = NULL; | 2996 | ipv6addr = NULL; |
2987 | if (GNUNET_OK == GNUNET_NETWORK_test_pf(PF_INET6)) | 2997 | if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6)) |
2988 | { | 2998 | { |
2989 | if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | 2999 | if (((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, |
2990 | "VPN", | 3000 | "VPN", |
2991 | "IPV6ADDR", | 3001 | "IPV6ADDR", |
2992 | &ipv6addr) || | 3002 | &ipv6addr))|| |
2993 | (1 != inet_pton(AF_INET6, ipv6addr, &v6)))) | 3003 | (1 != inet_pton (AF_INET6, ipv6addr, &v6)))) |
2994 | { | 3004 | { |
2995 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 3005 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
2996 | "VPN", | 3006 | "VPN", |
2997 | "IPV6ADDR", | 3007 | "IPV6ADDR", |
2998 | _("Must specify valid IPv6 address")); | 3008 | _ ("Must specify valid IPv6 address")); |
2999 | GNUNET_SCHEDULER_shutdown(); | 3009 | GNUNET_SCHEDULER_shutdown (); |
3000 | GNUNET_free_non_null(ipv6addr); | 3010 | GNUNET_free_non_null (ipv6addr); |
3001 | return; | 3011 | return; |
3002 | } | ||
3003 | vpn_argv[2] = ipv6addr; | ||
3004 | ipv6prefix_s = NULL; | ||
3005 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | ||
3006 | "VPN", | ||
3007 | "IPV6PREFIX", | ||
3008 | &ipv6prefix_s)) | ||
3009 | { | ||
3010 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6PREFIX"); | ||
3011 | GNUNET_SCHEDULER_shutdown(); | ||
3012 | GNUNET_free_non_null(ipv6prefix_s); | ||
3013 | return; | ||
3014 | } | ||
3015 | vpn_argv[3] = ipv6prefix_s; | ||
3016 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | ||
3017 | "VPN", | ||
3018 | "IPV6PREFIX", | ||
3019 | &ipv6prefix)) || | ||
3020 | (ipv6prefix >= 127)) | ||
3021 | { | ||
3022 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | ||
3023 | "VPN", | ||
3024 | "IPV4MASK", | ||
3025 | _("Must specify valid IPv6 mask")); | ||
3026 | GNUNET_SCHEDULER_shutdown(); | ||
3027 | return; | ||
3028 | } | ||
3029 | } | 3012 | } |
3030 | else | 3013 | vpn_argv[2] = ipv6addr; |
3014 | ipv6prefix_s = NULL; | ||
3015 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | ||
3016 | "VPN", | ||
3017 | "IPV6PREFIX", | ||
3018 | &ipv6prefix_s)) | ||
3031 | { | 3019 | { |
3032 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 3020 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6PREFIX"); |
3033 | _( | 3021 | GNUNET_SCHEDULER_shutdown (); |
3034 | "IPv6 support disabled as this system does not support IPv6\n")); | 3022 | GNUNET_free_non_null (ipv6prefix_s); |
3035 | vpn_argv[2] = GNUNET_strdup("-"); | 3023 | return; |
3036 | vpn_argv[3] = GNUNET_strdup("-"); | ||
3037 | } | 3024 | } |
3038 | if (GNUNET_OK == GNUNET_NETWORK_test_pf(PF_INET)) | 3025 | vpn_argv[3] = ipv6prefix_s; |
3026 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | ||
3027 | "VPN", | ||
3028 | "IPV6PREFIX", | ||
3029 | &ipv6prefix)) || | ||
3030 | (ipv6prefix >= 127)) | ||
3039 | { | 3031 | { |
3040 | ipv4addr = NULL; | 3032 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3041 | if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | 3033 | "VPN", |
3034 | "IPV4MASK", | ||
3035 | _ ("Must specify valid IPv6 mask")); | ||
3036 | GNUNET_SCHEDULER_shutdown (); | ||
3037 | return; | ||
3038 | } | ||
3039 | } | ||
3040 | else | ||
3041 | { | ||
3042 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
3043 | _ ( | ||
3044 | "IPv6 support disabled as this system does not support IPv6\n")); | ||
3045 | vpn_argv[2] = GNUNET_strdup ("-"); | ||
3046 | vpn_argv[3] = GNUNET_strdup ("-"); | ||
3047 | } | ||
3048 | if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET)) | ||
3049 | { | ||
3050 | ipv4addr = NULL; | ||
3051 | if (((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | ||
3042 | "vpn", | 3052 | "vpn", |
3043 | "IPV4ADDR", | 3053 | "IPV4ADDR", |
3044 | &ipv4addr) || | 3054 | &ipv4addr))|| |
3045 | (1 != inet_pton(AF_INET, ipv4addr, &v4)))) | 3055 | (1 != inet_pton (AF_INET, ipv4addr, &v4)))) |
3046 | { | 3056 | { |
3047 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 3057 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3048 | "VPN", | 3058 | "VPN", |
3049 | "IPV4ADDR", | 3059 | "IPV4ADDR", |
3050 | _("Must specify valid IPv4 address")); | 3060 | _ ("Must specify valid IPv4 address")); |
3051 | GNUNET_SCHEDULER_shutdown(); | 3061 | GNUNET_SCHEDULER_shutdown (); |
3052 | GNUNET_free_non_null(ipv4addr); | 3062 | GNUNET_free_non_null (ipv4addr); |
3053 | return; | 3063 | return; |
3054 | } | 3064 | } |
3055 | vpn_argv[4] = ipv4addr; | 3065 | vpn_argv[4] = ipv4addr; |
3056 | ipv4mask = NULL; | 3066 | ipv4mask = NULL; |
3057 | if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | 3067 | if (((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, |
3058 | "vpn", | 3068 | "vpn", |
3059 | "IPV4MASK", | 3069 | "IPV4MASK", |
3060 | &ipv4mask) || | 3070 | &ipv4mask))|| |
3061 | (1 != inet_pton(AF_INET, ipv4mask, &v4)))) | 3071 | (1 != inet_pton (AF_INET, ipv4mask, &v4)))) |
3062 | { | ||
3063 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | ||
3064 | "VPN", | ||
3065 | "IPV4MASK", | ||
3066 | _("Must specify valid IPv4 mask")); | ||
3067 | GNUNET_SCHEDULER_shutdown(); | ||
3068 | GNUNET_free_non_null(ipv4mask); | ||
3069 | return; | ||
3070 | } | ||
3071 | vpn_argv[5] = ipv4mask; | ||
3072 | } | ||
3073 | else | ||
3074 | { | 3072 | { |
3075 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 3073 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3076 | _( | 3074 | "VPN", |
3077 | "IPv4 support disabled as this system does not support IPv4\n")); | 3075 | "IPV4MASK", |
3078 | vpn_argv[4] = GNUNET_strdup("-"); | 3076 | _ ("Must specify valid IPv4 mask")); |
3079 | vpn_argv[5] = GNUNET_strdup("-"); | 3077 | GNUNET_SCHEDULER_shutdown (); |
3078 | GNUNET_free_non_null (ipv4mask); | ||
3079 | return; | ||
3080 | } | 3080 | } |
3081 | vpn_argv[5] = ipv4mask; | ||
3082 | } | ||
3083 | else | ||
3084 | { | ||
3085 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
3086 | _ ( | ||
3087 | "IPv4 support disabled as this system does not support IPv4\n")); | ||
3088 | vpn_argv[4] = GNUNET_strdup ("-"); | ||
3089 | vpn_argv[5] = GNUNET_strdup ("-"); | ||
3090 | } | ||
3081 | vpn_argv[6] = NULL; | 3091 | vpn_argv[6] = NULL; |
3082 | 3092 | ||
3083 | cadet_handle = GNUNET_CADET_connect(cfg_); | 3093 | cadet_handle = GNUNET_CADET_connect (cfg_); |
3084 | // FIXME never opens ports??? | 3094 | // FIXME never opens ports??? |
3085 | helper_handle = GNUNET_HELPER_start(GNUNET_NO, | 3095 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, |
3086 | "gnunet-helper-vpn", | 3096 | "gnunet-helper-vpn", |
3087 | vpn_argv, | 3097 | vpn_argv, |
3088 | &message_token, | 3098 | &message_token, |
3089 | NULL, | 3099 | NULL, |
3090 | NULL); | 3100 | NULL); |
3091 | GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); | 3101 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
3092 | } | 3102 | } |
3093 | 3103 | ||
3094 | 3104 | ||
3095 | /** | 3105 | /** |
3096 | * Define "main" method using service macro. | 3106 | * Define "main" method using service macro. |
3097 | */ | 3107 | */ |
3098 | GNUNET_SERVICE_MAIN( | 3108 | GNUNET_SERVICE_MAIN ( |
3099 | "vpn", | 3109 | "vpn", |
3100 | GNUNET_SERVICE_OPTION_NONE, | 3110 | GNUNET_SERVICE_OPTION_NONE, |
3101 | &run, | 3111 | &run, |
3102 | &client_connect_cb, | 3112 | &client_connect_cb, |
3103 | &client_disconnect_cb, | 3113 | &client_disconnect_cb, |
3104 | NULL, | 3114 | NULL, |
3105 | GNUNET_MQ_hd_var_size(client_redirect_to_ip, | 3115 | GNUNET_MQ_hd_var_size (client_redirect_to_ip, |
3106 | GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, | 3116 | GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, |
3107 | struct RedirectToIpRequestMessage, | 3117 | struct RedirectToIpRequestMessage, |
3108 | NULL), | 3118 | NULL), |
3109 | GNUNET_MQ_hd_fixed_size(client_redirect_to_service, | 3119 | GNUNET_MQ_hd_fixed_size (client_redirect_to_service, |
3110 | GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, | 3120 | GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, |
3111 | struct RedirectToServiceRequestMessage, | 3121 | struct RedirectToServiceRequestMessage, |
3112 | NULL), | 3122 | NULL), |
3113 | GNUNET_MQ_handler_end()); | 3123 | GNUNET_MQ_handler_end ()); |
3114 | 3124 | ||
3115 | 3125 | ||
3116 | /* end of gnunet-service-vpn.c */ | 3126 | /* end of gnunet-service-vpn.c */ |