diff options
Diffstat (limited to 'src/exit/gnunet-daemon-exit.c')
-rw-r--r-- | src/exit/gnunet-daemon-exit.c | 4592 |
1 files changed, 2344 insertions, 2248 deletions
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index f7cadbace..578997f4a 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -66,30 +66,34 @@ | |||
66 | /** | 66 | /** |
67 | * How frequently do we re-announce the regex for the exit? | 67 | * How frequently do we re-announce the regex for the exit? |
68 | */ | 68 | */ |
69 | #define REGEX_REFRESH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) | 69 | #define REGEX_REFRESH_FREQUENCY GNUNET_TIME_relative_multiply ( \ |
70 | GNUNET_TIME_UNIT_MINUTES, 30) | ||
70 | 71 | ||
71 | /** | 72 | /** |
72 | * How frequently do we re-announce the DNS exit in the DHT? | 73 | * How frequently do we re-announce the DNS exit in the DHT? |
73 | */ | 74 | */ |
74 | #define DHT_PUT_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 75 | #define DHT_PUT_FREQUENCY GNUNET_TIME_relative_multiply ( \ |
76 | GNUNET_TIME_UNIT_MINUTES, 15) | ||
75 | 77 | ||
76 | /** | 78 | /** |
77 | * How long do we typically sign the DNS exit advertisement for? | 79 | * How long do we typically sign the DNS exit advertisement for? |
78 | */ | 80 | */ |
79 | #define DNS_ADVERTISEMENT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 3) | 81 | #define DNS_ADVERTISEMENT_TIMEOUT GNUNET_TIME_relative_multiply ( \ |
82 | GNUNET_TIME_UNIT_HOURS, 3) | ||
80 | 83 | ||
81 | 84 | ||
82 | /** | 85 | /** |
83 | * Generic logging shorthand | 86 | * Generic logging shorthand |
84 | */ | 87 | */ |
85 | #define LOG(kind, ...) \ | 88 | #define LOG(kind, ...) \ |
86 | GNUNET_log_from(kind, "exit", __VA_ARGS__); | 89 | GNUNET_log_from (kind, "exit", __VA_ARGS__); |
87 | 90 | ||
88 | 91 | ||
89 | /** | 92 | /** |
90 | * Information about an address. | 93 | * Information about an address. |
91 | */ | 94 | */ |
92 | struct SocketAddress { | 95 | struct SocketAddress |
96 | { | ||
93 | /** | 97 | /** |
94 | * AF_INET or AF_INET6. | 98 | * AF_INET or AF_INET6. |
95 | */ | 99 | */ |
@@ -98,7 +102,8 @@ struct SocketAddress { | |||
98 | /** | 102 | /** |
99 | * Remote address information. | 103 | * Remote address information. |
100 | */ | 104 | */ |
101 | union { | 105 | union |
106 | { | ||
102 | /** | 107 | /** |
103 | * Address, if af is AF_INET. | 108 | * Address, if af is AF_INET. |
104 | */ | 109 | */ |
@@ -127,7 +132,8 @@ struct SocketAddress { | |||
127 | * a service this peer is specifically offering an exit for | 132 | * a service this peer is specifically offering an exit for |
128 | * (for a specific domain name). | 133 | * (for a specific domain name). |
129 | */ | 134 | */ |
130 | struct LocalService { | 135 | struct LocalService |
136 | { | ||
131 | /** | 137 | /** |
132 | * Remote address to use for the service. | 138 | * Remote address to use for the service. |
133 | */ | 139 | */ |
@@ -160,7 +166,8 @@ struct LocalService { | |||
160 | * IP-version, protocol, source-IP, destination-IP, source-port and | 166 | * IP-version, protocol, source-IP, destination-IP, source-port and |
161 | * destinatin-port. | 167 | * destinatin-port. |
162 | */ | 168 | */ |
163 | struct RedirectInformation { | 169 | struct RedirectInformation |
170 | { | ||
164 | /** | 171 | /** |
165 | * Address information for the other party (equivalent of the | 172 | * Address information for the other party (equivalent of the |
166 | * arguments one would give to "connect"). | 173 | * arguments one would give to "connect"). |
@@ -192,7 +199,8 @@ struct RedirectInformation { | |||
192 | * with the channel's closure so we can find it again for the next | 199 | * with the channel's closure so we can find it again for the next |
193 | * message from the channel. | 200 | * message from the channel. |
194 | */ | 201 | */ |
195 | struct ChannelState { | 202 | struct ChannelState |
203 | { | ||
196 | /** | 204 | /** |
197 | * Cadet channel that is used for this connection. | 205 | * Cadet channel that is used for this connection. |
198 | */ | 206 | */ |
@@ -211,8 +219,10 @@ struct ChannelState { | |||
211 | */ | 219 | */ |
212 | int is_dns; | 220 | int is_dns; |
213 | 221 | ||
214 | union { | 222 | union |
215 | struct { | 223 | { |
224 | struct | ||
225 | { | ||
216 | /** | 226 | /** |
217 | * Heap node for this state in the connections_heap. | 227 | * Heap node for this state in the connections_heap. |
218 | */ | 228 | */ |
@@ -234,7 +244,8 @@ struct ChannelState { | |||
234 | struct RedirectInformation ri; | 244 | struct RedirectInformation ri; |
235 | } tcp_udp; | 245 | } tcp_udp; |
236 | 246 | ||
237 | struct { | 247 | struct |
248 | { | ||
238 | /** | 249 | /** |
239 | * Socket we are using to transmit this request (must match if we receive | 250 | * Socket we are using to transmit this request (must match if we receive |
240 | * a response). | 251 | * a response). |
@@ -418,7 +429,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
418 | /** | 429 | /** |
419 | * Message with a DNS response. | 430 | * Message with a DNS response. |
420 | */ | 431 | */ |
421 | struct DnsResponseMessage { | 432 | struct DnsResponseMessage |
433 | { | ||
422 | /** | 434 | /** |
423 | * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET | 435 | * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET |
424 | */ | 436 | */ |
@@ -444,35 +456,35 @@ GNUNET_NETWORK_STRUCT_END | |||
444 | * @param r number of bytes in @a dns | 456 | * @param r number of bytes in @a dns |
445 | */ | 457 | */ |
446 | static void | 458 | static void |
447 | process_dns_result(void *cls, | 459 | process_dns_result (void *cls, |
448 | const struct GNUNET_TUN_DnsHeader *dns, | 460 | const struct GNUNET_TUN_DnsHeader *dns, |
449 | size_t r) | 461 | size_t r) |
450 | { | 462 | { |
451 | struct ChannelState *ts; | 463 | struct ChannelState *ts; |
452 | struct GNUNET_MQ_Envelope *env; | 464 | struct GNUNET_MQ_Envelope *env; |
453 | struct DnsResponseMessage *resp; | 465 | struct DnsResponseMessage *resp; |
454 | 466 | ||
455 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
456 | "Processing DNS result from stub resolver\n"); | 468 | "Processing DNS result from stub resolver\n"); |
457 | GNUNET_assert(NULL == cls); | 469 | GNUNET_assert (NULL == cls); |
458 | if (NULL == dns) | 470 | if (NULL == dns) |
459 | return; | 471 | return; |
460 | /* Handle case that this is a reply to a request from a CADET DNS channel */ | 472 | /* Handle case that this is a reply to a request from a CADET DNS channel */ |
461 | ts = channels[dns->id]; | 473 | ts = channels[dns->id]; |
462 | if (NULL == ts) | 474 | if (NULL == ts) |
463 | return; | 475 | return; |
464 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 476 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
465 | "Got a response from the stub resolver for DNS request received via CADET!\n"); | 477 | "Got a response from the stub resolver for DNS request received via CADET!\n"); |
466 | channels[dns->id] = NULL; | 478 | channels[dns->id] = NULL; |
467 | env = GNUNET_MQ_msg_extra(resp, | 479 | env = GNUNET_MQ_msg_extra (resp, |
468 | r - sizeof(struct GNUNET_TUN_DnsHeader), | 480 | r - sizeof(struct GNUNET_TUN_DnsHeader), |
469 | GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET); | 481 | GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET); |
470 | GNUNET_memcpy(&resp->dns, | 482 | GNUNET_memcpy (&resp->dns, |
471 | dns, | 483 | dns, |
472 | r); | 484 | r); |
473 | resp->dns.id = ts->specifics.dns.original_id; | 485 | resp->dns.id = ts->specifics.dns.original_id; |
474 | GNUNET_MQ_send(GNUNET_CADET_get_mq(ts->channel), | 486 | GNUNET_MQ_send (GNUNET_CADET_get_mq (ts->channel), |
475 | env); | 487 | env); |
476 | } | 488 | } |
477 | 489 | ||
478 | 490 | ||
@@ -485,21 +497,21 @@ process_dns_result(void *cls, | |||
485 | * #GNUNET_SYSERR to close it (signal serious error) | 497 | * #GNUNET_SYSERR to close it (signal serious error) |
486 | */ | 498 | */ |
487 | static int | 499 | static int |
488 | check_dns_request(void *cls, | 500 | check_dns_request (void *cls, |
489 | const struct DnsResponseMessage *msg) | 501 | const struct DnsResponseMessage *msg) |
490 | { | 502 | { |
491 | struct ChannelState *ts = cls; | 503 | struct ChannelState *ts = cls; |
492 | 504 | ||
493 | if (NULL == dnsstub) | 505 | if (NULL == dnsstub) |
494 | { | 506 | { |
495 | GNUNET_break(0); | 507 | GNUNET_break (0); |
496 | return GNUNET_SYSERR; | 508 | return GNUNET_SYSERR; |
497 | } | 509 | } |
498 | if (GNUNET_NO == ts->is_dns) | 510 | if (GNUNET_NO == ts->is_dns) |
499 | { | 511 | { |
500 | GNUNET_break_op(0); | 512 | GNUNET_break_op (0); |
501 | return GNUNET_SYSERR; | 513 | return GNUNET_SYSERR; |
502 | } | 514 | } |
503 | return GNUNET_OK; | 515 | return GNUNET_OK; |
504 | } | 516 | } |
505 | 517 | ||
@@ -511,42 +523,44 @@ check_dns_request(void *cls, | |||
511 | * @param msg the actual message | 523 | * @param msg the actual message |
512 | */ | 524 | */ |
513 | static void | 525 | static void |
514 | handle_dns_request(void *cls, | 526 | handle_dns_request (void *cls, |
515 | const struct DnsResponseMessage *msg) | 527 | const struct DnsResponseMessage *msg) |
516 | { | 528 | { |
517 | struct ChannelState *ts = cls; | 529 | struct ChannelState *ts = cls; |
518 | size_t mlen = ntohs(msg->header.size); | 530 | size_t mlen = ntohs (msg->header.size); |
519 | size_t dlen = mlen - sizeof(struct GNUNET_MessageHeader); | 531 | size_t dlen = mlen - sizeof(struct GNUNET_MessageHeader); |
520 | char buf[dlen] GNUNET_ALIGN; | 532 | char buf[dlen] GNUNET_ALIGN; |
521 | struct GNUNET_TUN_DnsHeader *dout; | 533 | struct GNUNET_TUN_DnsHeader *dout; |
522 | 534 | ||
523 | if (GNUNET_SYSERR == ts->is_dns) | 535 | if (GNUNET_SYSERR == ts->is_dns) |
524 | { | 536 | { |
525 | /* channel is DNS from now on */ | 537 | /* channel is DNS from now on */ |
526 | ts->is_dns = GNUNET_YES; | 538 | ts->is_dns = GNUNET_YES; |
527 | } | 539 | } |
528 | ts->specifics.dns.original_id = msg->dns.id; | 540 | ts->specifics.dns.original_id = msg->dns.id; |
529 | if (channels[ts->specifics.dns.my_id] == ts) | 541 | if (channels[ts->specifics.dns.my_id] == ts) |
530 | channels[ts->specifics.dns.my_id] = NULL; | 542 | channels[ts->specifics.dns.my_id] = NULL; |
531 | ts->specifics.dns.my_id = (uint16_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 543 | ts->specifics.dns.my_id = (uint16_t) GNUNET_CRYPTO_random_u32 ( |
532 | UINT16_MAX + 1); | 544 | GNUNET_CRYPTO_QUALITY_WEAK, |
545 | UINT16_MAX | ||
546 | + 1); | ||
533 | channels[ts->specifics.dns.my_id] = ts; | 547 | channels[ts->specifics.dns.my_id] = ts; |
534 | GNUNET_memcpy(buf, | 548 | GNUNET_memcpy (buf, |
535 | &msg->dns, | 549 | &msg->dns, |
536 | dlen); | 550 | dlen); |
537 | dout = (struct GNUNET_TUN_DnsHeader *)buf; | 551 | dout = (struct GNUNET_TUN_DnsHeader *) buf; |
538 | dout->id = ts->specifics.dns.my_id; | 552 | dout->id = ts->specifics.dns.my_id; |
539 | ts->specifics.dns.rs = GNUNET_DNSSTUB_resolve(dnsstub, | 553 | ts->specifics.dns.rs = GNUNET_DNSSTUB_resolve (dnsstub, |
540 | buf, | 554 | buf, |
541 | dlen, | 555 | dlen, |
542 | &process_dns_result, | 556 | &process_dns_result, |
543 | NULL); | 557 | NULL); |
544 | if (NULL == ts->specifics.dns.rs) | 558 | if (NULL == ts->specifics.dns.rs) |
545 | { | 559 | { |
546 | GNUNET_break_op(0); | 560 | GNUNET_break_op (0); |
547 | return; | 561 | return; |
548 | } | 562 | } |
549 | GNUNET_CADET_receive_done(ts->channel); | 563 | GNUNET_CADET_receive_done (ts->channel); |
550 | } | 564 | } |
551 | 565 | ||
552 | 566 | ||
@@ -558,66 +572,66 @@ handle_dns_request(void *cls, | |||
558 | * @param ri information about the connection | 572 | * @param ri information about the connection |
559 | */ | 573 | */ |
560 | static void | 574 | static void |
561 | hash_redirect_info(struct GNUNET_HashCode *hash, | 575 | hash_redirect_info (struct GNUNET_HashCode *hash, |
562 | const struct RedirectInformation *ri) | 576 | const struct RedirectInformation *ri) |
563 | { | 577 | { |
564 | char *off; | 578 | char *off; |
565 | 579 | ||
566 | memset(hash, | 580 | memset (hash, |
567 | 0, | 581 | 0, |
568 | sizeof(struct GNUNET_HashCode)); | 582 | sizeof(struct GNUNET_HashCode)); |
569 | /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, | 583 | /* the GNUnet hashmap only uses the first sizeof(unsigned int) of the hash, |
570 | so we put the IP address in there (and hope for few collisions) */ | 584 | so we put the IP address in there (and hope for few collisions) */ |
571 | off = (char*)hash; | 585 | off = (char*) hash; |
572 | switch (ri->remote_address.af) | 586 | switch (ri->remote_address.af) |
573 | { | 587 | { |
574 | case AF_INET: | 588 | case AF_INET: |
575 | GNUNET_memcpy(off, | 589 | GNUNET_memcpy (off, |
576 | &ri->remote_address.address.ipv4, | 590 | &ri->remote_address.address.ipv4, |
577 | sizeof(struct in_addr)); | 591 | sizeof(struct in_addr)); |
578 | off += sizeof(struct in_addr); | 592 | off += sizeof(struct in_addr); |
579 | break; | 593 | break; |
580 | 594 | ||
581 | case AF_INET6: | 595 | case AF_INET6: |
582 | GNUNET_memcpy(off, | 596 | GNUNET_memcpy (off, |
583 | &ri->remote_address.address.ipv6, | 597 | &ri->remote_address.address.ipv6, |
584 | sizeof(struct in6_addr)); | 598 | sizeof(struct in6_addr)); |
585 | off += sizeof(struct in_addr); | 599 | off += sizeof(struct in_addr); |
586 | break; | 600 | break; |
587 | 601 | ||
588 | default: | 602 | default: |
589 | GNUNET_assert(0); | 603 | GNUNET_assert (0); |
590 | } | 604 | } |
591 | GNUNET_memcpy(off, | 605 | GNUNET_memcpy (off, |
592 | &ri->remote_address.port, | 606 | &ri->remote_address.port, |
593 | sizeof(uint16_t)); | 607 | sizeof(uint16_t)); |
594 | off += sizeof(uint16_t); | 608 | off += sizeof(uint16_t); |
595 | switch (ri->local_address.af) | 609 | switch (ri->local_address.af) |
596 | { | 610 | { |
597 | case AF_INET: | 611 | case AF_INET: |
598 | GNUNET_memcpy(off, | 612 | GNUNET_memcpy (off, |
599 | &ri->local_address.address.ipv4, | 613 | &ri->local_address.address.ipv4, |
600 | sizeof(struct in_addr)); | 614 | sizeof(struct in_addr)); |
601 | off += sizeof(struct in_addr); | 615 | off += sizeof(struct in_addr); |
602 | break; | 616 | break; |
603 | 617 | ||
604 | case AF_INET6: | 618 | case AF_INET6: |
605 | GNUNET_memcpy(off, | 619 | GNUNET_memcpy (off, |
606 | &ri->local_address.address.ipv6, | 620 | &ri->local_address.address.ipv6, |
607 | sizeof(struct in6_addr)); | 621 | sizeof(struct in6_addr)); |
608 | off += sizeof(struct in_addr); | 622 | off += sizeof(struct in_addr); |
609 | break; | 623 | break; |
610 | 624 | ||
611 | default: | 625 | default: |
612 | GNUNET_assert(0); | 626 | GNUNET_assert (0); |
613 | } | 627 | } |
614 | GNUNET_memcpy(off, | 628 | GNUNET_memcpy (off, |
615 | &ri->local_address.port, | 629 | &ri->local_address.port, |
616 | sizeof(uint16_t)); | 630 | sizeof(uint16_t)); |
617 | off += sizeof(uint16_t); | 631 | off += sizeof(uint16_t); |
618 | GNUNET_memcpy(off, | 632 | GNUNET_memcpy (off, |
619 | &ri->remote_address.proto, | 633 | &ri->remote_address.proto, |
620 | sizeof(uint8_t)); | 634 | sizeof(uint8_t)); |
621 | /* off += sizeof (uint8_t); */ | 635 | /* off += sizeof (uint8_t); */ |
622 | } | 636 | } |
623 | 637 | ||
@@ -636,13 +650,13 @@ hash_redirect_info(struct GNUNET_HashCode *hash, | |||
636 | * @return NULL if we have no tracking information for this tuple | 650 | * @return NULL if we have no tracking information for this tuple |
637 | */ | 651 | */ |
638 | static struct ChannelState * | 652 | static struct ChannelState * |
639 | get_redirect_state(int af, | 653 | get_redirect_state (int af, |
640 | int protocol, | 654 | int protocol, |
641 | const void *destination_ip, | 655 | const void *destination_ip, |
642 | uint16_t destination_port, | 656 | uint16_t destination_port, |
643 | const void *local_ip, | 657 | const void *local_ip, |
644 | uint16_t local_port, | 658 | uint16_t local_port, |
645 | struct GNUNET_HashCode *state_key) | 659 | struct GNUNET_HashCode *state_key) |
646 | { | 660 | { |
647 | struct RedirectInformation ri; | 661 | struct RedirectInformation ri; |
648 | struct GNUNET_HashCode key; | 662 | struct GNUNET_HashCode key; |
@@ -650,37 +664,37 @@ get_redirect_state(int af, | |||
650 | 664 | ||
651 | if (((af == AF_INET) && (protocol == IPPROTO_ICMP)) || | 665 | if (((af == AF_INET) && (protocol == IPPROTO_ICMP)) || |
652 | ((af == AF_INET6) && (protocol == IPPROTO_ICMPV6))) | 666 | ((af == AF_INET6) && (protocol == IPPROTO_ICMPV6))) |
653 | { | 667 | { |
654 | /* ignore ports */ | 668 | /* ignore ports */ |
655 | destination_port = 0; | 669 | destination_port = 0; |
656 | local_port = 0; | 670 | local_port = 0; |
657 | } | 671 | } |
658 | ri.remote_address.af = af; | 672 | ri.remote_address.af = af; |
659 | if (af == AF_INET) | 673 | if (af == AF_INET) |
660 | ri.remote_address.address.ipv4 = *((struct in_addr*)destination_ip); | 674 | ri.remote_address.address.ipv4 = *((struct in_addr*) destination_ip); |
661 | else | 675 | else |
662 | ri.remote_address.address.ipv6 = *((struct in6_addr*)destination_ip); | 676 | ri.remote_address.address.ipv6 = *((struct in6_addr*) destination_ip); |
663 | ri.remote_address.port = destination_port; | 677 | ri.remote_address.port = destination_port; |
664 | ri.remote_address.proto = protocol; | 678 | ri.remote_address.proto = protocol; |
665 | ri.local_address.af = af; | 679 | ri.local_address.af = af; |
666 | if (af == AF_INET) | 680 | if (af == AF_INET) |
667 | ri.local_address.address.ipv4 = *((struct in_addr*)local_ip); | 681 | ri.local_address.address.ipv4 = *((struct in_addr*) local_ip); |
668 | else | 682 | else |
669 | ri.local_address.address.ipv6 = *((struct in6_addr*)local_ip); | 683 | ri.local_address.address.ipv6 = *((struct in6_addr*) local_ip); |
670 | ri.local_address.port = local_port; | 684 | ri.local_address.port = local_port; |
671 | ri.local_address.proto = protocol; | 685 | ri.local_address.proto = protocol; |
672 | hash_redirect_info(&key, | 686 | hash_redirect_info (&key, |
673 | &ri); | 687 | &ri); |
674 | if (NULL != state_key) | 688 | if (NULL != state_key) |
675 | *state_key = key; | 689 | *state_key = key; |
676 | state = GNUNET_CONTAINER_multihashmap_get(connections_map, | 690 | state = GNUNET_CONTAINER_multihashmap_get (connections_map, |
677 | &key); | 691 | &key); |
678 | if (NULL == state) | 692 | if (NULL == state) |
679 | return NULL; | 693 | return NULL; |
680 | /* Mark this connection as freshly used */ | 694 | /* Mark this connection as freshly used */ |
681 | if (NULL == state_key) | 695 | if (NULL == state_key) |
682 | GNUNET_CONTAINER_heap_update_cost(state->specifics.tcp_udp.heap_node, | 696 | GNUNET_CONTAINER_heap_update_cost (state->specifics.tcp_udp.heap_node, |
683 | GNUNET_TIME_absolute_get().abs_value_us); | 697 | GNUNET_TIME_absolute_get ().abs_value_us); |
684 | return state; | 698 | return state; |
685 | } | 699 | } |
686 | 700 | ||
@@ -696,36 +710,36 @@ get_redirect_state(int af, | |||
696 | * #GNUNET_SYSERR to close it (signal serious error) | 710 | * #GNUNET_SYSERR to close it (signal serious error) |
697 | */ | 711 | */ |
698 | static int | 712 | static int |
699 | check_tcp_service(void *cls, | 713 | check_tcp_service (void *cls, |
700 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) | 714 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) |
701 | { | 715 | { |
702 | struct ChannelState *state = cls; | 716 | struct ChannelState *state = cls; |
703 | 717 | ||
704 | if (NULL == state) | 718 | if (NULL == state) |
705 | { | 719 | { |
706 | GNUNET_break_op(0); | 720 | GNUNET_break_op (0); |
707 | return GNUNET_SYSERR; | 721 | return GNUNET_SYSERR; |
708 | } | 722 | } |
709 | if (GNUNET_YES == state->is_dns) | 723 | if (GNUNET_YES == state->is_dns) |
710 | { | 724 | { |
711 | GNUNET_break_op(0); | 725 | GNUNET_break_op (0); |
712 | return GNUNET_SYSERR; | 726 | return GNUNET_SYSERR; |
713 | } | 727 | } |
714 | if (NULL == state->specifics.tcp_udp.serv) | 728 | if (NULL == state->specifics.tcp_udp.serv) |
715 | { | 729 | { |
716 | GNUNET_break_op(0); | 730 | GNUNET_break_op (0); |
717 | return GNUNET_SYSERR; | 731 | return GNUNET_SYSERR; |
718 | } | 732 | } |
719 | if (NULL != state->specifics.tcp_udp.heap_node) | 733 | if (NULL != state->specifics.tcp_udp.heap_node) |
720 | { | 734 | { |
721 | GNUNET_break_op(0); | 735 | GNUNET_break_op (0); |
722 | return GNUNET_SYSERR; | 736 | return GNUNET_SYSERR; |
723 | } | 737 | } |
724 | if (start->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) | 738 | if (start->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
725 | { | 739 | { |
726 | GNUNET_break_op(0); | 740 | GNUNET_break_op (0); |
727 | return GNUNET_SYSERR; | 741 | return GNUNET_SYSERR; |
728 | } | 742 | } |
729 | return GNUNET_OK; | 743 | return GNUNET_OK; |
730 | } | 744 | } |
731 | 745 | ||
@@ -749,86 +763,88 @@ check_tcp_service(void *cls, | |||
749 | * AND the payload | 763 | * AND the payload |
750 | */ | 764 | */ |
751 | static void | 765 | static void |
752 | prepare_ipv4_packet(const void *payload, | 766 | prepare_ipv4_packet (const void *payload, |
753 | size_t payload_length, | 767 | size_t payload_length, |
754 | int protocol, | 768 | int protocol, |
755 | const struct GNUNET_TUN_TcpHeader *tcp_header, | 769 | const struct GNUNET_TUN_TcpHeader *tcp_header, |
756 | const struct SocketAddress *src_address, | 770 | const struct SocketAddress *src_address, |
757 | const struct SocketAddress *dst_address, | 771 | const struct SocketAddress *dst_address, |
758 | struct GNUNET_TUN_IPv4Header *pkt4) | 772 | struct GNUNET_TUN_IPv4Header *pkt4) |
759 | { | 773 | { |
760 | size_t len; | 774 | size_t len; |
761 | 775 | ||
762 | len = payload_length; | 776 | len = payload_length; |
763 | switch (protocol) | 777 | switch (protocol) |
764 | { | 778 | { |
765 | case IPPROTO_UDP: | 779 | case IPPROTO_UDP: |
766 | len += sizeof(struct GNUNET_TUN_UdpHeader); | 780 | len += sizeof(struct GNUNET_TUN_UdpHeader); |
767 | break; | 781 | break; |
768 | 782 | ||
769 | case IPPROTO_TCP: | 783 | case IPPROTO_TCP: |
770 | len += sizeof(struct GNUNET_TUN_TcpHeader); | 784 | len += sizeof(struct GNUNET_TUN_TcpHeader); |
771 | GNUNET_assert(NULL != tcp_header); | 785 | GNUNET_assert (NULL != tcp_header); |
772 | break; | 786 | break; |
773 | 787 | ||
774 | default: | 788 | default: |
775 | GNUNET_break(0); | 789 | GNUNET_break (0); |
776 | return; | 790 | return; |
777 | } | 791 | } |
778 | if (len + sizeof(struct GNUNET_TUN_IPv4Header) > UINT16_MAX) | 792 | if (len + sizeof(struct GNUNET_TUN_IPv4Header) > UINT16_MAX) |
779 | { | 793 | { |
780 | GNUNET_break(0); | 794 | GNUNET_break (0); |
781 | return; | 795 | return; |
782 | } | 796 | } |
783 | 797 | ||
784 | GNUNET_TUN_initialize_ipv4_header(pkt4, | 798 | GNUNET_TUN_initialize_ipv4_header (pkt4, |
785 | protocol, | 799 | protocol, |
786 | len, | 800 | len, |
787 | &src_address->address.ipv4, | 801 | &src_address->address.ipv4, |
788 | &dst_address->address.ipv4); | 802 | &dst_address->address.ipv4); |
789 | switch (protocol) | 803 | switch (protocol) |
804 | { | ||
805 | case IPPROTO_UDP: | ||
790 | { | 806 | { |
791 | case IPPROTO_UDP: | 807 | struct GNUNET_TUN_UdpHeader *pkt4_udp = (struct |
792 | { | 808 | GNUNET_TUN_UdpHeader *) &pkt4[1]; |
793 | struct GNUNET_TUN_UdpHeader *pkt4_udp = (struct GNUNET_TUN_UdpHeader *)&pkt4[1]; | 809 | |
794 | 810 | pkt4_udp->source_port = htons (src_address->port); | |
795 | pkt4_udp->source_port = htons(src_address->port); | 811 | pkt4_udp->destination_port = htons (dst_address->port); |
796 | pkt4_udp->destination_port = htons(dst_address->port); | 812 | pkt4_udp->len = htons ((uint16_t) payload_length); |
797 | pkt4_udp->len = htons((uint16_t)payload_length); | 813 | GNUNET_TUN_calculate_udp4_checksum (pkt4, |
798 | GNUNET_TUN_calculate_udp4_checksum(pkt4, | 814 | pkt4_udp, |
799 | pkt4_udp, | 815 | payload, |
800 | payload, | 816 | payload_length); |
801 | payload_length); | 817 | GNUNET_memcpy (&pkt4_udp[1], |
802 | GNUNET_memcpy(&pkt4_udp[1], | 818 | payload, |
803 | payload, | 819 | payload_length); |
804 | payload_length); | ||
805 | } | 820 | } |
806 | break; | 821 | break; |
807 | 822 | ||
808 | case IPPROTO_TCP: | 823 | case IPPROTO_TCP: |
809 | { | 824 | { |
810 | struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct GNUNET_TUN_TcpHeader *)&pkt4[1]; | 825 | struct GNUNET_TUN_TcpHeader *pkt4_tcp = (struct |
826 | GNUNET_TUN_TcpHeader *) &pkt4[1]; | ||
811 | 827 | ||
812 | *pkt4_tcp = *tcp_header; | 828 | *pkt4_tcp = *tcp_header; |
813 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
814 | "Sending TCP packet from port %u to port %u\n", | 830 | "Sending TCP packet from port %u to port %u\n", |
815 | src_address->port, | 831 | src_address->port, |
816 | dst_address->port); | 832 | dst_address->port); |
817 | pkt4_tcp->source_port = htons(src_address->port); | 833 | pkt4_tcp->source_port = htons (src_address->port); |
818 | pkt4_tcp->destination_port = htons(dst_address->port); | 834 | pkt4_tcp->destination_port = htons (dst_address->port); |
819 | GNUNET_TUN_calculate_tcp4_checksum(pkt4, | 835 | GNUNET_TUN_calculate_tcp4_checksum (pkt4, |
820 | pkt4_tcp, | 836 | pkt4_tcp, |
821 | payload, | 837 | payload, |
822 | payload_length); | 838 | payload_length); |
823 | GNUNET_memcpy(&pkt4_tcp[1], | 839 | GNUNET_memcpy (&pkt4_tcp[1], |
824 | payload, | 840 | payload, |
825 | payload_length); | 841 | payload_length); |
826 | } | 842 | } |
827 | break; | 843 | break; |
828 | 844 | ||
829 | default: | 845 | default: |
830 | GNUNET_assert(0); | 846 | GNUNET_assert (0); |
831 | } | 847 | } |
832 | } | 848 | } |
833 | 849 | ||
834 | 850 | ||
@@ -851,84 +867,86 @@ prepare_ipv4_packet(const void *payload, | |||
851 | * AND the payload | 867 | * AND the payload |
852 | */ | 868 | */ |
853 | static void | 869 | static void |
854 | prepare_ipv6_packet(const void *payload, | 870 | prepare_ipv6_packet (const void *payload, |
855 | size_t payload_length, | 871 | size_t payload_length, |
856 | int protocol, | 872 | int protocol, |
857 | const struct GNUNET_TUN_TcpHeader *tcp_header, | 873 | const struct GNUNET_TUN_TcpHeader *tcp_header, |
858 | const struct SocketAddress *src_address, | 874 | const struct SocketAddress *src_address, |
859 | const struct SocketAddress *dst_address, | 875 | const struct SocketAddress *dst_address, |
860 | struct GNUNET_TUN_IPv6Header *pkt6) | 876 | struct GNUNET_TUN_IPv6Header *pkt6) |
861 | { | 877 | { |
862 | size_t len; | 878 | size_t len; |
863 | 879 | ||
864 | len = payload_length; | 880 | len = payload_length; |
865 | switch (protocol) | 881 | switch (protocol) |
866 | { | 882 | { |
867 | case IPPROTO_UDP: | 883 | case IPPROTO_UDP: |
868 | len += sizeof(struct GNUNET_TUN_UdpHeader); | 884 | len += sizeof(struct GNUNET_TUN_UdpHeader); |
869 | break; | 885 | break; |
870 | 886 | ||
871 | case IPPROTO_TCP: | 887 | case IPPROTO_TCP: |
872 | len += sizeof(struct GNUNET_TUN_TcpHeader); | 888 | len += sizeof(struct GNUNET_TUN_TcpHeader); |
873 | break; | 889 | break; |
874 | 890 | ||
875 | default: | 891 | default: |
876 | GNUNET_break(0); | 892 | GNUNET_break (0); |
877 | return; | 893 | return; |
878 | } | 894 | } |
879 | if (len > UINT16_MAX) | 895 | if (len > UINT16_MAX) |
880 | { | 896 | { |
881 | GNUNET_break(0); | 897 | GNUNET_break (0); |
882 | return; | 898 | return; |
883 | } | 899 | } |
884 | 900 | ||
885 | GNUNET_TUN_initialize_ipv6_header(pkt6, | 901 | GNUNET_TUN_initialize_ipv6_header (pkt6, |
886 | protocol, | 902 | protocol, |
887 | len, | 903 | len, |
888 | &src_address->address.ipv6, | 904 | &src_address->address.ipv6, |
889 | &dst_address->address.ipv6); | 905 | &dst_address->address.ipv6); |
890 | 906 | ||
891 | switch (protocol) | 907 | switch (protocol) |
908 | { | ||
909 | case IPPROTO_UDP: | ||
892 | { | 910 | { |
893 | case IPPROTO_UDP: | 911 | struct GNUNET_TUN_UdpHeader *pkt6_udp = (struct |
894 | { | 912 | GNUNET_TUN_UdpHeader *) &pkt6[1]; |
895 | struct GNUNET_TUN_UdpHeader *pkt6_udp = (struct GNUNET_TUN_UdpHeader *)&pkt6[1]; | 913 | |
896 | 914 | pkt6_udp->source_port = htons (src_address->port); | |
897 | pkt6_udp->source_port = htons(src_address->port); | 915 | pkt6_udp->destination_port = htons (dst_address->port); |
898 | pkt6_udp->destination_port = htons(dst_address->port); | 916 | pkt6_udp->len = htons ((uint16_t) payload_length); |
899 | pkt6_udp->len = htons((uint16_t)payload_length); | 917 | GNUNET_TUN_calculate_udp6_checksum (pkt6, |
900 | GNUNET_TUN_calculate_udp6_checksum(pkt6, | 918 | pkt6_udp, |
901 | pkt6_udp, | 919 | payload, |
902 | payload, | 920 | payload_length); |
903 | payload_length); | 921 | GNUNET_memcpy (&pkt6_udp[1], |
904 | GNUNET_memcpy(&pkt6_udp[1], | 922 | payload, |
905 | payload, | 923 | payload_length); |
906 | payload_length); | ||
907 | } | 924 | } |
908 | break; | 925 | break; |
909 | 926 | ||
910 | case IPPROTO_TCP: | 927 | case IPPROTO_TCP: |
911 | { | 928 | { |
912 | struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct GNUNET_TUN_TcpHeader *)&pkt6[1]; | 929 | struct GNUNET_TUN_TcpHeader *pkt6_tcp = (struct |
930 | GNUNET_TUN_TcpHeader *) &pkt6[1]; | ||
913 | 931 | ||
914 | /* GNUNET_memcpy first here as some TCP header fields are initialized this way! */ | 932 | /* GNUNET_memcpy first here as some TCP header fields are initialized this way! */ |
915 | *pkt6_tcp = *tcp_header; | 933 | *pkt6_tcp = *tcp_header; |
916 | pkt6_tcp->source_port = htons(src_address->port); | 934 | pkt6_tcp->source_port = htons (src_address->port); |
917 | pkt6_tcp->destination_port = htons(dst_address->port); | 935 | pkt6_tcp->destination_port = htons (dst_address->port); |
918 | GNUNET_TUN_calculate_tcp6_checksum(pkt6, | 936 | GNUNET_TUN_calculate_tcp6_checksum (pkt6, |
919 | pkt6_tcp, | 937 | pkt6_tcp, |
920 | payload, | 938 | payload, |
921 | payload_length); | 939 | payload_length); |
922 | GNUNET_memcpy(&pkt6_tcp[1], | 940 | GNUNET_memcpy (&pkt6_tcp[1], |
923 | payload, | 941 | payload, |
924 | payload_length); | 942 | payload_length); |
925 | } | 943 | } |
926 | break; | 944 | break; |
927 | 945 | ||
928 | default: | 946 | default: |
929 | GNUNET_assert(0); | 947 | GNUNET_assert (0); |
930 | break; | 948 | break; |
931 | } | 949 | } |
932 | } | 950 | } |
933 | 951 | ||
934 | 952 | ||
@@ -942,97 +960,98 @@ prepare_ipv6_packet(const void *payload, | |||
942 | * @param payload_length number of bytes in @a payload | 960 | * @param payload_length number of bytes in @a payload |
943 | */ | 961 | */ |
944 | static void | 962 | static void |
945 | send_tcp_packet_via_tun(const struct SocketAddress *destination_address, | 963 | send_tcp_packet_via_tun (const struct SocketAddress *destination_address, |
946 | const struct SocketAddress *source_address, | 964 | const struct SocketAddress *source_address, |
947 | const struct GNUNET_TUN_TcpHeader *tcp_header, | 965 | const struct GNUNET_TUN_TcpHeader *tcp_header, |
948 | const void *payload, | 966 | const void *payload, |
949 | size_t payload_length) | 967 | size_t payload_length) |
950 | { | 968 | { |
951 | size_t len; | 969 | size_t len; |
952 | 970 | ||
953 | GNUNET_STATISTICS_update(stats, | 971 | GNUNET_STATISTICS_update (stats, |
954 | gettext_noop("# TCP packets sent via TUN"), | 972 | gettext_noop ("# TCP packets sent via TUN"), |
955 | 1, | 973 | 1, |
956 | GNUNET_NO); | 974 | GNUNET_NO); |
957 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 975 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
958 | "Sending packet with %u bytes TCP payload via TUN\n", | 976 | "Sending packet with %u bytes TCP payload via TUN\n", |
959 | (unsigned int)payload_length); | 977 | (unsigned int) payload_length); |
960 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader); | 978 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct |
979 | GNUNET_TUN_Layer2PacketHeader); | ||
961 | switch (source_address->af) | 980 | switch (source_address->af) |
962 | { | 981 | { |
963 | case AF_INET: | 982 | case AF_INET: |
964 | len += sizeof(struct GNUNET_TUN_IPv4Header); | 983 | len += sizeof(struct GNUNET_TUN_IPv4Header); |
965 | break; | 984 | break; |
966 | 985 | ||
967 | case AF_INET6: | 986 | case AF_INET6: |
968 | len += sizeof(struct GNUNET_TUN_IPv6Header); | 987 | len += sizeof(struct GNUNET_TUN_IPv6Header); |
969 | break; | 988 | break; |
970 | 989 | ||
971 | default: | 990 | default: |
972 | GNUNET_break(0); | 991 | GNUNET_break (0); |
973 | return; | 992 | return; |
974 | } | 993 | } |
975 | len += sizeof(struct GNUNET_TUN_TcpHeader); | 994 | len += sizeof(struct GNUNET_TUN_TcpHeader); |
976 | len += payload_length; | 995 | len += payload_length; |
977 | if (len >= GNUNET_MAX_MESSAGE_SIZE) | 996 | if (len >= GNUNET_MAX_MESSAGE_SIZE) |
978 | { | 997 | { |
979 | GNUNET_break(0); | 998 | GNUNET_break (0); |
980 | return; | 999 | return; |
981 | } | 1000 | } |
982 | { | 1001 | { |
983 | char buf[len] GNUNET_ALIGN; | 1002 | char buf[len] GNUNET_ALIGN; |
984 | struct GNUNET_MessageHeader *hdr; | 1003 | struct GNUNET_MessageHeader *hdr; |
985 | struct GNUNET_TUN_Layer2PacketHeader *tun; | 1004 | struct GNUNET_TUN_Layer2PacketHeader *tun; |
986 | 1005 | ||
987 | hdr = (struct GNUNET_MessageHeader *)buf; | 1006 | hdr = (struct GNUNET_MessageHeader *) buf; |
988 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1007 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
989 | hdr->size = htons(len); | 1008 | hdr->size = htons (len); |
990 | tun = (struct GNUNET_TUN_Layer2PacketHeader*)&hdr[1]; | 1009 | tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1]; |
991 | tun->flags = htons(0); | 1010 | tun->flags = htons (0); |
992 | switch (source_address->af) | 1011 | switch (source_address->af) |
993 | { | 1012 | { |
994 | case AF_INET: | 1013 | case AF_INET: |
995 | { | 1014 | { |
996 | struct GNUNET_TUN_IPv4Header *ipv4 | 1015 | struct GNUNET_TUN_IPv4Header *ipv4 |
997 | = (struct GNUNET_TUN_IPv4Header*)&tun[1]; | 1016 | = (struct GNUNET_TUN_IPv4Header*) &tun[1]; |
998 | 1017 | ||
999 | tun->proto = htons(ETH_P_IPV4); | 1018 | tun->proto = htons (ETH_P_IPV4); |
1000 | prepare_ipv4_packet(payload, | 1019 | prepare_ipv4_packet (payload, |
1001 | payload_length, | 1020 | payload_length, |
1002 | IPPROTO_TCP, | 1021 | IPPROTO_TCP, |
1003 | tcp_header, | 1022 | tcp_header, |
1004 | source_address, | 1023 | source_address, |
1005 | destination_address, | 1024 | destination_address, |
1006 | ipv4); | 1025 | ipv4); |
1007 | } | 1026 | } |
1008 | break; | 1027 | break; |
1009 | 1028 | ||
1010 | case AF_INET6: | 1029 | case AF_INET6: |
1011 | { | 1030 | { |
1012 | struct GNUNET_TUN_IPv6Header *ipv6 | 1031 | struct GNUNET_TUN_IPv6Header *ipv6 |
1013 | = (struct GNUNET_TUN_IPv6Header*)&tun[1]; | 1032 | = (struct GNUNET_TUN_IPv6Header*) &tun[1]; |
1014 | 1033 | ||
1015 | tun->proto = htons(ETH_P_IPV6); | 1034 | tun->proto = htons (ETH_P_IPV6); |
1016 | prepare_ipv6_packet(payload, | 1035 | prepare_ipv6_packet (payload, |
1017 | payload_length, | 1036 | payload_length, |
1018 | IPPROTO_TCP, | 1037 | IPPROTO_TCP, |
1019 | tcp_header, | 1038 | tcp_header, |
1020 | source_address, | 1039 | source_address, |
1021 | destination_address, | 1040 | destination_address, |
1022 | ipv6); | 1041 | ipv6); |
1023 | } | 1042 | } |
1024 | break; | 1043 | break; |
1025 | 1044 | ||
1026 | default: | 1045 | default: |
1027 | GNUNET_assert(0); | 1046 | GNUNET_assert (0); |
1028 | break; | 1047 | break; |
1029 | } | 1048 | } |
1030 | if (NULL != helper_handle) | 1049 | if (NULL != helper_handle) |
1031 | (void)GNUNET_HELPER_send(helper_handle, | 1050 | (void) GNUNET_HELPER_send (helper_handle, |
1032 | (const struct GNUNET_MessageHeader*)buf, | 1051 | (const struct GNUNET_MessageHeader*) buf, |
1033 | GNUNET_YES, | 1052 | GNUNET_YES, |
1034 | NULL, | 1053 | NULL, |
1035 | NULL); | 1054 | NULL); |
1036 | } | 1055 | } |
1037 | } | 1056 | } |
1038 | 1057 | ||
@@ -1047,98 +1066,105 @@ send_tcp_packet_via_tun(const struct SocketAddress *destination_address, | |||
1047 | * @param payload_length number of bytes of data in @a payload | 1066 | * @param payload_length number of bytes of data in @a payload |
1048 | */ | 1067 | */ |
1049 | static void | 1068 | static void |
1050 | send_icmp_packet_via_tun(const struct SocketAddress *destination_address, | 1069 | send_icmp_packet_via_tun (const struct SocketAddress *destination_address, |
1051 | const struct SocketAddress *source_address, | 1070 | const struct SocketAddress *source_address, |
1052 | const struct GNUNET_TUN_IcmpHeader *icmp_header, | 1071 | const struct GNUNET_TUN_IcmpHeader *icmp_header, |
1053 | const void *payload, size_t payload_length) | 1072 | const void *payload, size_t payload_length) |
1054 | { | 1073 | { |
1055 | size_t len; | 1074 | size_t len; |
1056 | struct GNUNET_TUN_IcmpHeader *icmp; | 1075 | struct GNUNET_TUN_IcmpHeader *icmp; |
1057 | 1076 | ||
1058 | GNUNET_STATISTICS_update(stats, | 1077 | GNUNET_STATISTICS_update (stats, |
1059 | gettext_noop("# ICMP packets sent via TUN"), | 1078 | gettext_noop ("# ICMP packets sent via TUN"), |
1060 | 1, GNUNET_NO); | 1079 | 1, GNUNET_NO); |
1061 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1080 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1062 | "Sending packet with %u bytes ICMP payload via TUN\n", | 1081 | "Sending packet with %u bytes ICMP payload via TUN\n", |
1063 | (unsigned int)payload_length); | 1082 | (unsigned int) payload_length); |
1064 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader); | 1083 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct |
1084 | GNUNET_TUN_Layer2PacketHeader); | ||
1065 | switch (destination_address->af) | 1085 | switch (destination_address->af) |
1066 | { | 1086 | { |
1067 | case AF_INET: | 1087 | case AF_INET: |
1068 | len += sizeof(struct GNUNET_TUN_IPv4Header); | 1088 | len += sizeof(struct GNUNET_TUN_IPv4Header); |
1069 | break; | 1089 | break; |
1070 | 1090 | ||
1071 | case AF_INET6: | 1091 | case AF_INET6: |
1072 | len += sizeof(struct GNUNET_TUN_IPv6Header); | 1092 | len += sizeof(struct GNUNET_TUN_IPv6Header); |
1073 | break; | 1093 | break; |
1074 | 1094 | ||
1075 | default: | 1095 | default: |
1076 | GNUNET_break(0); | 1096 | GNUNET_break (0); |
1077 | return; | 1097 | return; |
1078 | } | 1098 | } |
1079 | len += sizeof(struct GNUNET_TUN_IcmpHeader); | 1099 | len += sizeof(struct GNUNET_TUN_IcmpHeader); |
1080 | len += payload_length; | 1100 | len += payload_length; |
1081 | if (len >= GNUNET_MAX_MESSAGE_SIZE) | 1101 | if (len >= GNUNET_MAX_MESSAGE_SIZE) |
1082 | { | 1102 | { |
1083 | GNUNET_break(0); | 1103 | GNUNET_break (0); |
1084 | return; | 1104 | return; |
1085 | } | 1105 | } |
1086 | { | 1106 | { |
1087 | char buf[len] GNUNET_ALIGN; | 1107 | char buf[len] GNUNET_ALIGN; |
1088 | struct GNUNET_MessageHeader *hdr; | 1108 | struct GNUNET_MessageHeader *hdr; |
1089 | struct GNUNET_TUN_Layer2PacketHeader *tun; | 1109 | struct GNUNET_TUN_Layer2PacketHeader *tun; |
1090 | 1110 | ||
1091 | hdr = (struct GNUNET_MessageHeader *)buf; | 1111 | hdr = (struct GNUNET_MessageHeader *) buf; |
1092 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1112 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1093 | hdr->size = htons(len); | 1113 | hdr->size = htons (len); |
1094 | tun = (struct GNUNET_TUN_Layer2PacketHeader*)&hdr[1]; | 1114 | tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1]; |
1095 | tun->flags = htons(0); | 1115 | tun->flags = htons (0); |
1096 | switch (source_address->af) | 1116 | switch (source_address->af) |
1117 | { | ||
1118 | case AF_INET: | ||
1097 | { | 1119 | { |
1098 | case AF_INET: | 1120 | struct GNUNET_TUN_IPv4Header *ipv4 = (struct |
1099 | { | 1121 | GNUNET_TUN_IPv4Header*) &tun[1]; |
1100 | struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*)&tun[1]; | 1122 | |
1101 | 1123 | tun->proto = htons (ETH_P_IPV4); | |
1102 | tun->proto = htons(ETH_P_IPV4); | 1124 | GNUNET_TUN_initialize_ipv4_header (ipv4, |
1103 | GNUNET_TUN_initialize_ipv4_header(ipv4, | 1125 | IPPROTO_ICMP, |
1104 | IPPROTO_ICMP, | 1126 | sizeof(struct |
1105 | sizeof(struct GNUNET_TUN_IcmpHeader) + payload_length, | 1127 | GNUNET_TUN_IcmpHeader) |
1106 | &source_address->address.ipv4, | 1128 | + payload_length, |
1107 | &destination_address->address.ipv4); | 1129 | &source_address->address.ipv4, |
1108 | icmp = (struct GNUNET_TUN_IcmpHeader*)&ipv4[1]; | 1130 | &destination_address->address.ipv4); |
1131 | icmp = (struct GNUNET_TUN_IcmpHeader*) &ipv4[1]; | ||
1109 | } | 1132 | } |
1110 | break; | 1133 | break; |
1111 | 1134 | ||
1112 | case AF_INET6: | 1135 | case AF_INET6: |
1113 | { | 1136 | { |
1114 | struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*)&tun[1]; | 1137 | struct GNUNET_TUN_IPv6Header *ipv6 = (struct |
1115 | 1138 | GNUNET_TUN_IPv6Header*) &tun[1]; | |
1116 | tun->proto = htons(ETH_P_IPV6); | 1139 | |
1117 | GNUNET_TUN_initialize_ipv6_header(ipv6, | 1140 | tun->proto = htons (ETH_P_IPV6); |
1118 | IPPROTO_ICMPV6, | 1141 | GNUNET_TUN_initialize_ipv6_header (ipv6, |
1119 | sizeof(struct GNUNET_TUN_IcmpHeader) + payload_length, | 1142 | IPPROTO_ICMPV6, |
1120 | &source_address->address.ipv6, | 1143 | sizeof(struct |
1121 | &destination_address->address.ipv6); | 1144 | GNUNET_TUN_IcmpHeader) |
1122 | icmp = (struct GNUNET_TUN_IcmpHeader*)&ipv6[1]; | 1145 | + payload_length, |
1146 | &source_address->address.ipv6, | ||
1147 | &destination_address->address.ipv6); | ||
1148 | icmp = (struct GNUNET_TUN_IcmpHeader*) &ipv6[1]; | ||
1123 | } | 1149 | } |
1124 | break; | 1150 | break; |
1125 | 1151 | ||
1126 | default: | 1152 | default: |
1127 | GNUNET_assert(0); | 1153 | GNUNET_assert (0); |
1128 | break; | 1154 | break; |
1129 | } | 1155 | } |
1130 | *icmp = *icmp_header; | 1156 | *icmp = *icmp_header; |
1131 | GNUNET_memcpy(&icmp[1], | 1157 | GNUNET_memcpy (&icmp[1], |
1132 | payload, | 1158 | payload, |
1133 | payload_length); | 1159 | payload_length); |
1134 | GNUNET_TUN_calculate_icmp_checksum(icmp, | 1160 | GNUNET_TUN_calculate_icmp_checksum (icmp, |
1135 | payload, | 1161 | payload, |
1136 | payload_length); | 1162 | payload_length); |
1137 | if (NULL != helper_handle) | 1163 | if (NULL != helper_handle) |
1138 | (void)GNUNET_HELPER_send(helper_handle, | 1164 | (void) GNUNET_HELPER_send (helper_handle, |
1139 | (const struct GNUNET_MessageHeader*)buf, | 1165 | (const struct GNUNET_MessageHeader*) buf, |
1140 | GNUNET_YES, | 1166 | GNUNET_YES, |
1141 | NULL, NULL); | 1167 | NULL, NULL); |
1142 | } | 1168 | } |
1143 | } | 1169 | } |
1144 | 1170 | ||
@@ -1152,12 +1178,12 @@ send_icmp_packet_via_tun(const struct SocketAddress *destination_address, | |||
1152 | * @param local_address address to initialize | 1178 | * @param local_address address to initialize |
1153 | */ | 1179 | */ |
1154 | static void | 1180 | static void |
1155 | setup_fresh_address(int af, | 1181 | setup_fresh_address (int af, |
1156 | uint8_t proto, | 1182 | uint8_t proto, |
1157 | struct SocketAddress *local_address) | 1183 | struct SocketAddress *local_address) |
1158 | { | 1184 | { |
1159 | local_address->af = af; | 1185 | local_address->af = af; |
1160 | local_address->proto = (uint8_t)proto; | 1186 | local_address->proto = (uint8_t) proto; |
1161 | /* default "local" port range is often 32768--61000, | 1187 | /* default "local" port range is often 32768--61000, |
1162 | so we pick a random value in that range */ | 1188 | so we pick a random value in that range */ |
1163 | if (((af == AF_INET) && (proto == IPPROTO_ICMP)) || | 1189 | if (((af == AF_INET) && (proto == IPPROTO_ICMP)) || |
@@ -1165,11 +1191,11 @@ setup_fresh_address(int af, | |||
1165 | local_address->port = 0; | 1191 | local_address->port = 0; |
1166 | else | 1192 | else |
1167 | local_address->port | 1193 | local_address->port |
1168 | = (uint16_t)32768 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1194 | = (uint16_t) 32768 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1169 | 28232); | 1195 | 28232); |
1170 | switch (af) | 1196 | switch (af) |
1171 | { | 1197 | { |
1172 | case AF_INET: | 1198 | case AF_INET: |
1173 | { | 1199 | { |
1174 | struct in_addr addr; | 1200 | struct in_addr addr; |
1175 | struct in_addr mask; | 1201 | struct in_addr mask; |
@@ -1178,27 +1204,28 @@ setup_fresh_address(int af, | |||
1178 | addr = exit_ipv4addr; | 1204 | addr = exit_ipv4addr; |
1179 | mask = exit_ipv4mask; | 1205 | mask = exit_ipv4mask; |
1180 | if (0 == ~mask.s_addr) | 1206 | if (0 == ~mask.s_addr) |
1181 | { | 1207 | { |
1182 | /* only one valid IP anyway */ | 1208 | /* only one valid IP anyway */ |
1183 | local_address->address.ipv4 = addr; | 1209 | local_address->address.ipv4 = addr; |
1184 | return; | 1210 | return; |
1185 | } | 1211 | } |
1186 | /* Given 192.168.0.1/255.255.0.0, we want a mask | 1212 | /* Given 192.168.0.1/255.255.0.0, we want a mask |
1187 | of '192.168.255.255', thus: */ | 1213 | of '192.168.255.255', thus: */ |
1188 | mask.s_addr = addr.s_addr | ~mask.s_addr; | 1214 | mask.s_addr = addr.s_addr | ~mask.s_addr; |
1189 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ | 1215 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ |
1190 | do | 1216 | do |
1191 | { | 1217 | { |
1192 | rnd.s_addr = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1218 | rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1193 | UINT32_MAX); | 1219 | UINT32_MAX); |
1194 | local_address->address.ipv4.s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; | 1220 | local_address->address.ipv4.s_addr = (addr.s_addr | rnd.s_addr) |
1195 | } | 1221 | & mask.s_addr; |
1222 | } | ||
1196 | while ((local_address->address.ipv4.s_addr == addr.s_addr) || | 1223 | while ((local_address->address.ipv4.s_addr == addr.s_addr) || |
1197 | (local_address->address.ipv4.s_addr == mask.s_addr)); | 1224 | (local_address->address.ipv4.s_addr == mask.s_addr)); |
1198 | } | 1225 | } |
1199 | break; | 1226 | break; |
1200 | 1227 | ||
1201 | case AF_INET6: | 1228 | case AF_INET6: |
1202 | { | 1229 | { |
1203 | struct in6_addr addr; | 1230 | struct in6_addr addr; |
1204 | struct in6_addr mask; | 1231 | struct in6_addr mask; |
@@ -1206,13 +1233,13 @@ setup_fresh_address(int af, | |||
1206 | int i; | 1233 | int i; |
1207 | 1234 | ||
1208 | addr = exit_ipv6addr; | 1235 | addr = exit_ipv6addr; |
1209 | GNUNET_assert(ipv6prefix < 128); | 1236 | GNUNET_assert (ipv6prefix < 128); |
1210 | if (ipv6prefix == 127) | 1237 | if (ipv6prefix == 127) |
1211 | { | 1238 | { |
1212 | /* only one valid IP anyway */ | 1239 | /* only one valid IP anyway */ |
1213 | local_address->address.ipv6 = addr; | 1240 | local_address->address.ipv6 = addr; |
1214 | return; | 1241 | return; |
1215 | } | 1242 | } |
1216 | /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, | 1243 | /* Given ABCD::/96, we want a mask of 'ABCD::FFFF:FFFF, |
1217 | thus: */ | 1244 | thus: */ |
1218 | mask = addr; | 1245 | mask = addr; |
@@ -1221,25 +1248,26 @@ setup_fresh_address(int af, | |||
1221 | 1248 | ||
1222 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ | 1249 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ |
1223 | do | 1250 | do |
1251 | { | ||
1252 | for (i = 0; i < 16; i++) | ||
1224 | { | 1253 | { |
1225 | for (i = 0; i < 16; i++) | 1254 | rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 ( |
1226 | { | 1255 | GNUNET_CRYPTO_QUALITY_WEAK, |
1227 | rnd.s6_addr[i] = (unsigned char)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 1256 | 256); |
1228 | 256); | 1257 | local_address->address.ipv6.s6_addr[i] |
1229 | local_address->address.ipv6.s6_addr[i] | 1258 | = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; |
1230 | = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; | ||
1231 | } | ||
1232 | } | 1259 | } |
1233 | while ((0 == GNUNET_memcmp(&local_address->address.ipv6, | 1260 | } |
1234 | &addr)) || | 1261 | while ((0 == GNUNET_memcmp (&local_address->address.ipv6, |
1235 | (0 == GNUNET_memcmp(&local_address->address.ipv6, | 1262 | &addr)) || |
1236 | &mask))); | 1263 | (0 == GNUNET_memcmp (&local_address->address.ipv6, |
1264 | &mask))); | ||
1237 | } | 1265 | } |
1238 | break; | 1266 | break; |
1239 | 1267 | ||
1240 | default: | 1268 | default: |
1241 | GNUNET_assert(0); | 1269 | GNUNET_assert (0); |
1242 | } | 1270 | } |
1243 | } | 1271 | } |
1244 | 1272 | ||
1245 | 1273 | ||
@@ -1265,62 +1293,63 @@ setup_fresh_address(int af, | |||
1265 | * used to test if a state has been fully setup). | 1293 | * used to test if a state has been fully setup). |
1266 | */ | 1294 | */ |
1267 | static void | 1295 | static void |
1268 | setup_state_record(struct ChannelState *state) | 1296 | setup_state_record (struct ChannelState *state) |
1269 | { | 1297 | { |
1270 | struct GNUNET_HashCode key; | 1298 | struct GNUNET_HashCode key; |
1271 | struct ChannelState *s; | 1299 | struct ChannelState *s; |
1272 | 1300 | ||
1273 | /* generate fresh, unique address */ | 1301 | /* generate fresh, unique address */ |
1274 | do | 1302 | do |
1275 | { | 1303 | { |
1276 | if (NULL == state->specifics.tcp_udp.serv) | 1304 | if (NULL == state->specifics.tcp_udp.serv) |
1277 | setup_fresh_address(state->specifics.tcp_udp.ri.remote_address.af, | 1305 | setup_fresh_address (state->specifics.tcp_udp.ri.remote_address.af, |
1278 | state->specifics.tcp_udp.ri.remote_address.proto, | 1306 | state->specifics.tcp_udp.ri.remote_address.proto, |
1279 | &state->specifics.tcp_udp.ri.local_address); | 1307 | &state->specifics.tcp_udp.ri.local_address); |
1280 | else | 1308 | else |
1281 | setup_fresh_address(state->specifics.tcp_udp.serv->address.af, | 1309 | setup_fresh_address (state->specifics.tcp_udp.serv->address.af, |
1282 | state->specifics.tcp_udp.serv->address.proto, | 1310 | state->specifics.tcp_udp.serv->address.proto, |
1283 | &state->specifics.tcp_udp.ri.local_address); | 1311 | &state->specifics.tcp_udp.ri.local_address); |
1284 | } | 1312 | } |
1285 | while (NULL != | 1313 | while (NULL != |
1286 | get_redirect_state(state->specifics.tcp_udp.ri.remote_address.af, | 1314 | get_redirect_state (state->specifics.tcp_udp.ri.remote_address.af, |
1287 | state->specifics.tcp_udp.ri.remote_address.proto, | 1315 | state->specifics.tcp_udp.ri.remote_address.proto, |
1288 | &state->specifics.tcp_udp.ri.remote_address.address, | 1316 | &state->specifics.tcp_udp.ri.remote_address.address, |
1289 | state->specifics.tcp_udp.ri.remote_address.port, | 1317 | state->specifics.tcp_udp.ri.remote_address.port, |
1290 | &state->specifics.tcp_udp.ri.local_address.address, | 1318 | &state->specifics.tcp_udp.ri.local_address.address, |
1291 | state->specifics.tcp_udp.ri.local_address.port, | 1319 | state->specifics.tcp_udp.ri.local_address.port, |
1292 | &key)); | 1320 | &key)); |
1293 | { | 1321 | { |
1294 | char buf[INET6_ADDRSTRLEN]; | 1322 | char buf[INET6_ADDRSTRLEN]; |
1295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1296 | "Picked local address %s:%u for new connection\n", | 1324 | "Picked local address %s:%u for new connection\n", |
1297 | inet_ntop(state->specifics.tcp_udp.ri.local_address.af, | 1325 | inet_ntop (state->specifics.tcp_udp.ri.local_address.af, |
1298 | &state->specifics.tcp_udp.ri.local_address.address, | 1326 | &state->specifics.tcp_udp.ri.local_address.address, |
1299 | buf, | 1327 | buf, |
1300 | sizeof(buf)), | 1328 | sizeof(buf)), |
1301 | (unsigned int)state->specifics.tcp_udp.ri.local_address.port); | 1329 | (unsigned int) state->specifics.tcp_udp.ri.local_address.port); |
1302 | } | 1330 | } |
1303 | state->specifics.tcp_udp.state_key = key; | 1331 | state->specifics.tcp_udp.state_key = key; |
1304 | GNUNET_assert(GNUNET_OK == | 1332 | GNUNET_assert (GNUNET_OK == |
1305 | GNUNET_CONTAINER_multihashmap_put(connections_map, | 1333 | GNUNET_CONTAINER_multihashmap_put (connections_map, |
1306 | &key, state, | 1334 | &key, state, |
1307 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1335 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1308 | state->specifics.tcp_udp.heap_node | 1336 | state->specifics.tcp_udp.heap_node |
1309 | = GNUNET_CONTAINER_heap_insert(connections_heap, | 1337 | = GNUNET_CONTAINER_heap_insert (connections_heap, |
1310 | state, | 1338 | state, |
1311 | GNUNET_TIME_absolute_get().abs_value_us); | 1339 | GNUNET_TIME_absolute_get ().abs_value_us); |
1312 | while (GNUNET_CONTAINER_heap_get_size(connections_heap) > max_connections) | 1340 | while (GNUNET_CONTAINER_heap_get_size (connections_heap) > max_connections) |
1313 | { | 1341 | { |
1314 | s = GNUNET_CONTAINER_heap_remove_root(connections_heap); | 1342 | s = GNUNET_CONTAINER_heap_remove_root (connections_heap); |
1315 | GNUNET_assert(state != s); | 1343 | GNUNET_assert (state != s); |
1316 | s->specifics.tcp_udp.heap_node = NULL; | 1344 | s->specifics.tcp_udp.heap_node = NULL; |
1317 | GNUNET_CADET_channel_destroy(s->channel); | 1345 | GNUNET_CADET_channel_destroy (s->channel); |
1318 | GNUNET_assert(GNUNET_OK == | 1346 | GNUNET_assert (GNUNET_OK == |
1319 | GNUNET_CONTAINER_multihashmap_remove(connections_map, | 1347 | GNUNET_CONTAINER_multihashmap_remove (connections_map, |
1320 | &s->specifics.tcp_udp.state_key, | 1348 | &s->specifics.tcp_udp. |
1349 | state_key, | ||
1321 | s)); | 1350 | s)); |
1322 | GNUNET_free(s); | 1351 | GNUNET_free (s); |
1323 | } | 1352 | } |
1324 | } | 1353 | } |
1325 | 1354 | ||
1326 | 1355 | ||
@@ -1333,91 +1362,94 @@ setup_state_record(struct ChannelState *state) | |||
1333 | * @param payload_length number of bytes of data in @a payload | 1362 | * @param payload_length number of bytes of data in @a payload |
1334 | */ | 1363 | */ |
1335 | static void | 1364 | static void |
1336 | send_udp_packet_via_tun(const struct SocketAddress *destination_address, | 1365 | send_udp_packet_via_tun (const struct SocketAddress *destination_address, |
1337 | const struct SocketAddress *source_address, | 1366 | const struct SocketAddress *source_address, |
1338 | const void *payload, size_t payload_length) | 1367 | const void *payload, size_t payload_length) |
1339 | { | 1368 | { |
1340 | size_t len; | 1369 | size_t len; |
1341 | 1370 | ||
1342 | GNUNET_STATISTICS_update(stats, | 1371 | GNUNET_STATISTICS_update (stats, |
1343 | gettext_noop("# UDP packets sent via TUN"), | 1372 | gettext_noop ("# UDP packets sent via TUN"), |
1344 | 1, GNUNET_NO); | 1373 | 1, GNUNET_NO); |
1345 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1346 | "Sending packet with %u bytes UDP payload via TUN\n", | 1375 | "Sending packet with %u bytes UDP payload via TUN\n", |
1347 | (unsigned int)payload_length); | 1376 | (unsigned int) payload_length); |
1348 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_TUN_Layer2PacketHeader); | 1377 | len = sizeof(struct GNUNET_MessageHeader) + sizeof(struct |
1378 | GNUNET_TUN_Layer2PacketHeader); | ||
1349 | switch (source_address->af) | 1379 | switch (source_address->af) |
1350 | { | 1380 | { |
1351 | case AF_INET: | 1381 | case AF_INET: |
1352 | len += sizeof(struct GNUNET_TUN_IPv4Header); | 1382 | len += sizeof(struct GNUNET_TUN_IPv4Header); |
1353 | break; | 1383 | break; |
1354 | 1384 | ||
1355 | case AF_INET6: | 1385 | case AF_INET6: |
1356 | len += sizeof(struct GNUNET_TUN_IPv6Header); | 1386 | len += sizeof(struct GNUNET_TUN_IPv6Header); |
1357 | break; | 1387 | break; |
1358 | 1388 | ||
1359 | default: | 1389 | default: |
1360 | GNUNET_break(0); | 1390 | GNUNET_break (0); |
1361 | return; | 1391 | return; |
1362 | } | 1392 | } |
1363 | len += sizeof(struct GNUNET_TUN_UdpHeader); | 1393 | len += sizeof(struct GNUNET_TUN_UdpHeader); |
1364 | len += payload_length; | 1394 | len += payload_length; |
1365 | if (len >= GNUNET_MAX_MESSAGE_SIZE) | 1395 | if (len >= GNUNET_MAX_MESSAGE_SIZE) |
1366 | { | 1396 | { |
1367 | GNUNET_break(0); | 1397 | GNUNET_break (0); |
1368 | return; | 1398 | return; |
1369 | } | 1399 | } |
1370 | { | 1400 | { |
1371 | char buf[len] GNUNET_ALIGN; | 1401 | char buf[len] GNUNET_ALIGN; |
1372 | struct GNUNET_MessageHeader *hdr; | 1402 | struct GNUNET_MessageHeader *hdr; |
1373 | struct GNUNET_TUN_Layer2PacketHeader *tun; | 1403 | struct GNUNET_TUN_Layer2PacketHeader *tun; |
1374 | 1404 | ||
1375 | hdr = (struct GNUNET_MessageHeader *)buf; | 1405 | hdr = (struct GNUNET_MessageHeader *) buf; |
1376 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1406 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1377 | hdr->size = htons(len); | 1407 | hdr->size = htons (len); |
1378 | tun = (struct GNUNET_TUN_Layer2PacketHeader*)&hdr[1]; | 1408 | tun = (struct GNUNET_TUN_Layer2PacketHeader*) &hdr[1]; |
1379 | tun->flags = htons(0); | 1409 | tun->flags = htons (0); |
1380 | switch (source_address->af) | 1410 | switch (source_address->af) |
1411 | { | ||
1412 | case AF_INET: | ||
1381 | { | 1413 | { |
1382 | case AF_INET: | 1414 | struct GNUNET_TUN_IPv4Header *ipv4 = (struct |
1383 | { | 1415 | GNUNET_TUN_IPv4Header*) &tun[1]; |
1384 | struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*)&tun[1]; | 1416 | |
1385 | 1417 | tun->proto = htons (ETH_P_IPV4); | |
1386 | tun->proto = htons(ETH_P_IPV4); | 1418 | prepare_ipv4_packet (payload, |
1387 | prepare_ipv4_packet(payload, | 1419 | payload_length, |
1388 | payload_length, | 1420 | IPPROTO_UDP, |
1389 | IPPROTO_UDP, | 1421 | NULL, |
1390 | NULL, | 1422 | source_address, |
1391 | source_address, | 1423 | destination_address, |
1392 | destination_address, | 1424 | ipv4); |
1393 | ipv4); | ||
1394 | } | 1425 | } |
1395 | break; | 1426 | break; |
1396 | 1427 | ||
1397 | case AF_INET6: | 1428 | case AF_INET6: |
1398 | { | 1429 | { |
1399 | struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*)&tun[1]; | 1430 | struct GNUNET_TUN_IPv6Header *ipv6 = (struct |
1400 | 1431 | GNUNET_TUN_IPv6Header*) &tun[1]; | |
1401 | tun->proto = htons(ETH_P_IPV6); | 1432 | |
1402 | prepare_ipv6_packet(payload, | 1433 | tun->proto = htons (ETH_P_IPV6); |
1403 | payload_length, | 1434 | prepare_ipv6_packet (payload, |
1404 | IPPROTO_UDP, | 1435 | payload_length, |
1405 | NULL, | 1436 | IPPROTO_UDP, |
1406 | source_address, | 1437 | NULL, |
1407 | destination_address, | 1438 | source_address, |
1408 | ipv6); | 1439 | destination_address, |
1440 | ipv6); | ||
1409 | } | 1441 | } |
1410 | break; | 1442 | break; |
1411 | 1443 | ||
1412 | default: | 1444 | default: |
1413 | GNUNET_assert(0); | 1445 | GNUNET_assert (0); |
1414 | break; | 1446 | break; |
1415 | } | 1447 | } |
1416 | if (NULL != helper_handle) | 1448 | if (NULL != helper_handle) |
1417 | (void)GNUNET_HELPER_send(helper_handle, | 1449 | (void) GNUNET_HELPER_send (helper_handle, |
1418 | (const struct GNUNET_MessageHeader*)buf, | 1450 | (const struct GNUNET_MessageHeader*) buf, |
1419 | GNUNET_YES, | 1451 | GNUNET_YES, |
1420 | NULL, NULL); | 1452 | NULL, NULL); |
1421 | } | 1453 | } |
1422 | } | 1454 | } |
1423 | 1455 | ||
@@ -1431,16 +1463,16 @@ send_udp_packet_via_tun(const struct SocketAddress *destination_address, | |||
1431 | * #GNUNET_SYSERR to close it (signal serious error) | 1463 | * #GNUNET_SYSERR to close it (signal serious error) |
1432 | */ | 1464 | */ |
1433 | static int | 1465 | static int |
1434 | check_udp_remote(void *cls, | 1466 | check_udp_remote (void *cls, |
1435 | const struct GNUNET_EXIT_UdpInternetMessage *msg) | 1467 | const struct GNUNET_EXIT_UdpInternetMessage *msg) |
1436 | { | 1468 | { |
1437 | struct ChannelState *state = cls; | 1469 | struct ChannelState *state = cls; |
1438 | 1470 | ||
1439 | if (GNUNET_YES == state->is_dns) | 1471 | if (GNUNET_YES == state->is_dns) |
1440 | { | 1472 | { |
1441 | GNUNET_break_op(0); | 1473 | GNUNET_break_op (0); |
1442 | return GNUNET_SYSERR; | 1474 | return GNUNET_SYSERR; |
1443 | } | 1475 | } |
1444 | return GNUNET_OK; | 1476 | return GNUNET_OK; |
1445 | } | 1477 | } |
1446 | 1478 | ||
@@ -1452,90 +1484,92 @@ check_udp_remote(void *cls, | |||
1452 | * @param msg the actual message | 1484 | * @param msg the actual message |
1453 | */ | 1485 | */ |
1454 | static void | 1486 | static void |
1455 | handle_udp_remote(void *cls, | 1487 | handle_udp_remote (void *cls, |
1456 | const struct GNUNET_EXIT_UdpInternetMessage *msg) | 1488 | const struct GNUNET_EXIT_UdpInternetMessage *msg) |
1457 | { | 1489 | { |
1458 | struct ChannelState *state = cls; | 1490 | struct ChannelState *state = cls; |
1459 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_UdpInternetMessage); | 1491 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof(struct |
1492 | GNUNET_EXIT_UdpInternetMessage); | ||
1460 | const struct in_addr *v4; | 1493 | const struct in_addr *v4; |
1461 | const struct in6_addr *v6; | 1494 | const struct in6_addr *v6; |
1462 | const void *payload; | 1495 | const void *payload; |
1463 | int af; | 1496 | int af; |
1464 | 1497 | ||
1465 | if (GNUNET_SYSERR == state->is_dns) | 1498 | if (GNUNET_SYSERR == state->is_dns) |
1466 | { | 1499 | { |
1467 | /* channel is UDP/TCP from now on */ | 1500 | /* channel is UDP/TCP from now on */ |
1468 | state->is_dns = GNUNET_NO; | 1501 | state->is_dns = GNUNET_NO; |
1469 | } | 1502 | } |
1470 | GNUNET_STATISTICS_update(stats, | 1503 | GNUNET_STATISTICS_update (stats, |
1471 | gettext_noop("# Bytes received from CADET"), | 1504 | gettext_noop ("# Bytes received from CADET"), |
1472 | pkt_len, GNUNET_NO); | 1505 | pkt_len, GNUNET_NO); |
1473 | GNUNET_STATISTICS_update(stats, | 1506 | GNUNET_STATISTICS_update (stats, |
1474 | gettext_noop("# UDP IP-exit requests received via cadet"), | 1507 | gettext_noop ( |
1475 | 1, GNUNET_NO); | 1508 | "# UDP IP-exit requests received via cadet"), |
1476 | af = (int)ntohl(msg->af); | 1509 | 1, GNUNET_NO); |
1510 | af = (int) ntohl (msg->af); | ||
1477 | state->specifics.tcp_udp.ri.remote_address.af = af; | 1511 | state->specifics.tcp_udp.ri.remote_address.af = af; |
1478 | switch (af) | 1512 | switch (af) |
1513 | { | ||
1514 | case AF_INET: | ||
1515 | if (pkt_len < sizeof(struct in_addr)) | ||
1479 | { | 1516 | { |
1480 | case AF_INET: | 1517 | GNUNET_break_op (0); |
1481 | if (pkt_len < sizeof(struct in_addr)) | 1518 | return; |
1482 | { | 1519 | } |
1483 | GNUNET_break_op(0); | 1520 | if (! ipv4_exit) |
1484 | return; | 1521 | { |
1485 | } | 1522 | GNUNET_break_op (0); |
1486 | if (!ipv4_exit) | 1523 | return; |
1487 | { | 1524 | } |
1488 | GNUNET_break_op(0); | 1525 | v4 = (const struct in_addr*) &msg[1]; |
1489 | return; | 1526 | payload = &v4[1]; |
1490 | } | 1527 | pkt_len -= sizeof(struct in_addr); |
1491 | v4 = (const struct in_addr*)&msg[1]; | 1528 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; |
1492 | payload = &v4[1]; | 1529 | break; |
1493 | pkt_len -= sizeof(struct in_addr); | ||
1494 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
1495 | break; | ||
1496 | |||
1497 | case AF_INET6: | ||
1498 | if (pkt_len < sizeof(struct in6_addr)) | ||
1499 | { | ||
1500 | GNUNET_break_op(0); | ||
1501 | return; | ||
1502 | } | ||
1503 | if (!ipv6_exit) | ||
1504 | { | ||
1505 | GNUNET_break_op(0); | ||
1506 | return; | ||
1507 | } | ||
1508 | v6 = (const struct in6_addr*)&msg[1]; | ||
1509 | payload = &v6[1]; | ||
1510 | pkt_len -= sizeof(struct in6_addr); | ||
1511 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1512 | break; | ||
1513 | 1530 | ||
1514 | default: | 1531 | case AF_INET6: |
1515 | GNUNET_break_op(0); | 1532 | if (pkt_len < sizeof(struct in6_addr)) |
1533 | { | ||
1534 | GNUNET_break_op (0); | ||
1535 | return; | ||
1536 | } | ||
1537 | if (! ipv6_exit) | ||
1538 | { | ||
1539 | GNUNET_break_op (0); | ||
1516 | return; | 1540 | return; |
1517 | } | 1541 | } |
1542 | v6 = (const struct in6_addr*) &msg[1]; | ||
1543 | payload = &v6[1]; | ||
1544 | pkt_len -= sizeof(struct in6_addr); | ||
1545 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1546 | break; | ||
1547 | |||
1548 | default: | ||
1549 | GNUNET_break_op (0); | ||
1550 | return; | ||
1551 | } | ||
1518 | { | 1552 | { |
1519 | char buf[INET6_ADDRSTRLEN]; | 1553 | char buf[INET6_ADDRSTRLEN]; |
1520 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1521 | "Received data from %s for forwarding to UDP %s:%u\n", | 1555 | "Received data from %s for forwarding to UDP %s:%u\n", |
1522 | GNUNET_i2s(&state->peer), | 1556 | GNUNET_i2s (&state->peer), |
1523 | inet_ntop(af, | 1557 | inet_ntop (af, |
1524 | &state->specifics.tcp_udp.ri.remote_address.address, | 1558 | &state->specifics.tcp_udp.ri.remote_address.address, |
1525 | buf, sizeof(buf)), | 1559 | buf, sizeof(buf)), |
1526 | (unsigned int)ntohs(msg->destination_port)); | 1560 | (unsigned int) ntohs (msg->destination_port)); |
1527 | } | 1561 | } |
1528 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_UDP; | 1562 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_UDP; |
1529 | state->specifics.tcp_udp.ri.remote_address.port = msg->destination_port; | 1563 | state->specifics.tcp_udp.ri.remote_address.port = msg->destination_port; |
1530 | if (NULL == state->specifics.tcp_udp.heap_node) | 1564 | if (NULL == state->specifics.tcp_udp.heap_node) |
1531 | setup_state_record(state); | 1565 | setup_state_record (state); |
1532 | if (0 != ntohs(msg->source_port)) | 1566 | if (0 != ntohs (msg->source_port)) |
1533 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; | 1567 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; |
1534 | send_udp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, | 1568 | send_udp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, |
1535 | &state->specifics.tcp_udp.ri.local_address, | 1569 | &state->specifics.tcp_udp.ri.local_address, |
1536 | payload, | 1570 | payload, |
1537 | pkt_len); | 1571 | pkt_len); |
1538 | GNUNET_CADET_receive_done(state->channel); | 1572 | GNUNET_CADET_receive_done (state->channel); |
1539 | } | 1573 | } |
1540 | 1574 | ||
1541 | 1575 | ||
@@ -1549,16 +1583,16 @@ handle_udp_remote(void *cls, | |||
1549 | * #GNUNET_SYSERR to close it (signal serious error) | 1583 | * #GNUNET_SYSERR to close it (signal serious error) |
1550 | */ | 1584 | */ |
1551 | static int | 1585 | static int |
1552 | check_udp_service(void *cls, | 1586 | check_udp_service (void *cls, |
1553 | const struct GNUNET_EXIT_UdpServiceMessage *msg) | 1587 | const struct GNUNET_EXIT_UdpServiceMessage *msg) |
1554 | { | 1588 | { |
1555 | struct ChannelState *state = cls; | 1589 | struct ChannelState *state = cls; |
1556 | 1590 | ||
1557 | if (NULL == state->specifics.tcp_udp.serv) | 1591 | if (NULL == state->specifics.tcp_udp.serv) |
1558 | { | 1592 | { |
1559 | GNUNET_break_op(0); | 1593 | GNUNET_break_op (0); |
1560 | return GNUNET_SYSERR; | 1594 | return GNUNET_SYSERR; |
1561 | } | 1595 | } |
1562 | return GNUNET_OK; | 1596 | return GNUNET_OK; |
1563 | } | 1597 | } |
1564 | 1598 | ||
@@ -1571,31 +1605,33 @@ check_udp_service(void *cls, | |||
1571 | * @param msg the actual message | 1605 | * @param msg the actual message |
1572 | */ | 1606 | */ |
1573 | static void | 1607 | static void |
1574 | handle_udp_service(void *cls, | 1608 | handle_udp_service (void *cls, |
1575 | const struct GNUNET_EXIT_UdpServiceMessage *msg) | 1609 | const struct GNUNET_EXIT_UdpServiceMessage *msg) |
1576 | { | 1610 | { |
1577 | struct ChannelState *state = cls; | 1611 | struct ChannelState *state = cls; |
1578 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_UdpServiceMessage); | 1612 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof(struct |
1579 | 1613 | GNUNET_EXIT_UdpServiceMessage); | |
1580 | GNUNET_STATISTICS_update(stats, | 1614 | |
1581 | gettext_noop("# Bytes received from CADET"), | 1615 | GNUNET_STATISTICS_update (stats, |
1582 | pkt_len, GNUNET_NO); | 1616 | gettext_noop ("# Bytes received from CADET"), |
1583 | GNUNET_STATISTICS_update(stats, | 1617 | pkt_len, GNUNET_NO); |
1584 | gettext_noop("# UDP service requests received via cadet"), | 1618 | GNUNET_STATISTICS_update (stats, |
1585 | 1, GNUNET_NO); | 1619 | gettext_noop ( |
1586 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1620 | "# UDP service requests received via cadet"), |
1587 | "Received data from %s for forwarding to UDP service %s on port %u\n", | 1621 | 1, GNUNET_NO); |
1588 | GNUNET_i2s(&state->peer), | 1622 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1589 | GNUNET_h2s(&state->specifics.tcp_udp.serv->descriptor), | 1623 | "Received data from %s for forwarding to UDP service %s on port %u\n", |
1590 | (unsigned int)ntohs(msg->destination_port)); | 1624 | GNUNET_i2s (&state->peer), |
1591 | setup_state_record(state); | 1625 | GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor), |
1592 | if (0 != ntohs(msg->source_port)) | 1626 | (unsigned int) ntohs (msg->destination_port)); |
1627 | setup_state_record (state); | ||
1628 | if (0 != ntohs (msg->source_port)) | ||
1593 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; | 1629 | state->specifics.tcp_udp.ri.local_address.port = msg->source_port; |
1594 | send_udp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, | 1630 | send_udp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, |
1595 | &state->specifics.tcp_udp.ri.local_address, | 1631 | &state->specifics.tcp_udp.ri.local_address, |
1596 | &msg[1], | 1632 | &msg[1], |
1597 | pkt_len); | 1633 | pkt_len); |
1598 | GNUNET_CADET_receive_done(state->channel); | 1634 | GNUNET_CADET_receive_done (state->channel); |
1599 | } | 1635 | } |
1600 | 1636 | ||
1601 | 1637 | ||
@@ -1609,39 +1645,41 @@ handle_udp_service(void *cls, | |||
1609 | * #GNUNET_SYSERR to close it (signal serious error) | 1645 | * #GNUNET_SYSERR to close it (signal serious error) |
1610 | */ | 1646 | */ |
1611 | static void | 1647 | static void |
1612 | handle_tcp_service(void *cls, | 1648 | handle_tcp_service (void *cls, |
1613 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) | 1649 | const struct GNUNET_EXIT_TcpServiceStartMessage *start) |
1614 | { | 1650 | { |
1615 | struct ChannelState *state = cls; | 1651 | struct ChannelState *state = cls; |
1616 | uint16_t pkt_len = ntohs(start->header.size) - sizeof(struct GNUNET_EXIT_TcpServiceStartMessage); | 1652 | uint16_t pkt_len = ntohs (start->header.size) - sizeof(struct |
1653 | GNUNET_EXIT_TcpServiceStartMessage); | ||
1617 | 1654 | ||
1618 | if (GNUNET_SYSERR == state->is_dns) | 1655 | if (GNUNET_SYSERR == state->is_dns) |
1619 | { | 1656 | { |
1620 | /* channel is UDP/TCP from now on */ | 1657 | /* channel is UDP/TCP from now on */ |
1621 | state->is_dns = GNUNET_NO; | 1658 | state->is_dns = GNUNET_NO; |
1622 | } | 1659 | } |
1623 | GNUNET_STATISTICS_update(stats, | 1660 | GNUNET_STATISTICS_update (stats, |
1624 | gettext_noop("# TCP service creation requests received via cadet"), | 1661 | gettext_noop ( |
1625 | 1, | 1662 | "# TCP service creation requests received via cadet"), |
1626 | GNUNET_NO); | 1663 | 1, |
1627 | GNUNET_STATISTICS_update(stats, | 1664 | GNUNET_NO); |
1628 | gettext_noop("# Bytes received from CADET"), | 1665 | GNUNET_STATISTICS_update (stats, |
1629 | pkt_len, | 1666 | gettext_noop ("# Bytes received from CADET"), |
1630 | GNUNET_NO); | 1667 | pkt_len, |
1631 | GNUNET_break_op(ntohl(start->reserved) == 0); | 1668 | GNUNET_NO); |
1669 | GNUNET_break_op (ntohl (start->reserved) == 0); | ||
1632 | /* setup fresh connection */ | 1670 | /* setup fresh connection */ |
1633 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1634 | "Received data from %s for forwarding to TCP service %s on port %u\n", | 1672 | "Received data from %s for forwarding to TCP service %s on port %u\n", |
1635 | GNUNET_i2s(&state->peer), | 1673 | GNUNET_i2s (&state->peer), |
1636 | GNUNET_h2s(&state->specifics.tcp_udp.serv->descriptor), | 1674 | GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor), |
1637 | (unsigned int)ntohs(start->tcp_header.destination_port)); | 1675 | (unsigned int) ntohs (start->tcp_header.destination_port)); |
1638 | setup_state_record(state); | 1676 | setup_state_record (state); |
1639 | send_tcp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, | 1677 | send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, |
1640 | &state->specifics.tcp_udp.ri.local_address, | 1678 | &state->specifics.tcp_udp.ri.local_address, |
1641 | &start->tcp_header, | 1679 | &start->tcp_header, |
1642 | &start[1], | 1680 | &start[1], |
1643 | pkt_len); | 1681 | pkt_len); |
1644 | GNUNET_CADET_receive_done(state->channel); | 1682 | GNUNET_CADET_receive_done (state->channel); |
1645 | } | 1683 | } |
1646 | 1684 | ||
1647 | 1685 | ||
@@ -1654,32 +1692,32 @@ handle_tcp_service(void *cls, | |||
1654 | * #GNUNET_SYSERR to close it (signal serious error) | 1692 | * #GNUNET_SYSERR to close it (signal serious error) |
1655 | */ | 1693 | */ |
1656 | static int | 1694 | static int |
1657 | check_tcp_remote(void *cls, | 1695 | check_tcp_remote (void *cls, |
1658 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) | 1696 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) |
1659 | { | 1697 | { |
1660 | struct ChannelState *state = cls; | 1698 | struct ChannelState *state = cls; |
1661 | 1699 | ||
1662 | if (NULL == state) | 1700 | if (NULL == state) |
1663 | { | 1701 | { |
1664 | GNUNET_break_op(0); | 1702 | GNUNET_break_op (0); |
1665 | return GNUNET_SYSERR; | 1703 | return GNUNET_SYSERR; |
1666 | } | 1704 | } |
1667 | if (GNUNET_YES == state->is_dns) | 1705 | if (GNUNET_YES == state->is_dns) |
1668 | { | 1706 | { |
1669 | GNUNET_break_op(0); | 1707 | GNUNET_break_op (0); |
1670 | return GNUNET_SYSERR; | 1708 | return GNUNET_SYSERR; |
1671 | } | 1709 | } |
1672 | if ((NULL != state->specifics.tcp_udp.serv) || | 1710 | if ((NULL != state->specifics.tcp_udp.serv) || |
1673 | (NULL != state->specifics.tcp_udp.heap_node)) | 1711 | (NULL != state->specifics.tcp_udp.heap_node)) |
1674 | { | 1712 | { |
1675 | GNUNET_break_op(0); | 1713 | GNUNET_break_op (0); |
1676 | return GNUNET_SYSERR; | 1714 | return GNUNET_SYSERR; |
1677 | } | 1715 | } |
1678 | if (start->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) | 1716 | if (start->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
1679 | { | 1717 | { |
1680 | GNUNET_break_op(0); | 1718 | GNUNET_break_op (0); |
1681 | return GNUNET_SYSERR; | 1719 | return GNUNET_SYSERR; |
1682 | } | 1720 | } |
1683 | return GNUNET_OK; | 1721 | return GNUNET_OK; |
1684 | } | 1722 | } |
1685 | 1723 | ||
@@ -1691,88 +1729,91 @@ check_tcp_remote(void *cls, | |||
1691 | * @param start the actual message | 1729 | * @param start the actual message |
1692 | */ | 1730 | */ |
1693 | static void | 1731 | static void |
1694 | handle_tcp_remote(void *cls, | 1732 | handle_tcp_remote (void *cls, |
1695 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) | 1733 | const struct GNUNET_EXIT_TcpInternetStartMessage *start) |
1696 | { | 1734 | { |
1697 | struct ChannelState *state = cls; | 1735 | struct ChannelState *state = cls; |
1698 | uint16_t pkt_len = ntohs(start->header.size) - sizeof(struct GNUNET_EXIT_TcpInternetStartMessage); | 1736 | uint16_t pkt_len = ntohs (start->header.size) - sizeof(struct |
1737 | GNUNET_EXIT_TcpInternetStartMessage); | ||
1699 | const struct in_addr *v4; | 1738 | const struct in_addr *v4; |
1700 | const struct in6_addr *v6; | 1739 | const struct in6_addr *v6; |
1701 | const void *payload; | 1740 | const void *payload; |
1702 | int af; | 1741 | int af; |
1703 | 1742 | ||
1704 | if (GNUNET_SYSERR == state->is_dns) | 1743 | if (GNUNET_SYSERR == state->is_dns) |
1705 | { | 1744 | { |
1706 | /* channel is UDP/TCP from now on */ | 1745 | /* channel is UDP/TCP from now on */ |
1707 | state->is_dns = GNUNET_NO; | 1746 | state->is_dns = GNUNET_NO; |
1708 | } | 1747 | } |
1709 | GNUNET_STATISTICS_update(stats, | 1748 | GNUNET_STATISTICS_update (stats, |
1710 | gettext_noop("# Bytes received from CADET"), | 1749 | gettext_noop ("# Bytes received from CADET"), |
1711 | pkt_len, GNUNET_NO); | 1750 | pkt_len, GNUNET_NO); |
1712 | GNUNET_STATISTICS_update(stats, | 1751 | GNUNET_STATISTICS_update (stats, |
1713 | gettext_noop("# TCP IP-exit creation requests received via cadet"), | 1752 | gettext_noop ( |
1714 | 1, GNUNET_NO); | 1753 | "# TCP IP-exit creation requests received via cadet"), |
1715 | af = (int)ntohl(start->af); | 1754 | 1, GNUNET_NO); |
1755 | af = (int) ntohl (start->af); | ||
1716 | state->specifics.tcp_udp.ri.remote_address.af = af; | 1756 | state->specifics.tcp_udp.ri.remote_address.af = af; |
1717 | switch (af) | 1757 | switch (af) |
1758 | { | ||
1759 | case AF_INET: | ||
1760 | if (pkt_len < sizeof(struct in_addr)) | ||
1718 | { | 1761 | { |
1719 | case AF_INET: | 1762 | GNUNET_break_op (0); |
1720 | if (pkt_len < sizeof(struct in_addr)) | 1763 | return; |
1721 | { | 1764 | } |
1722 | GNUNET_break_op(0); | 1765 | if (! ipv4_exit) |
1723 | return; | 1766 | { |
1724 | } | 1767 | GNUNET_break_op (0); |
1725 | if (!ipv4_exit) | 1768 | return; |
1726 | { | 1769 | } |
1727 | GNUNET_break_op(0); | 1770 | v4 = (const struct in_addr*) &start[1]; |
1728 | return; | 1771 | payload = &v4[1]; |
1729 | } | 1772 | pkt_len -= sizeof(struct in_addr); |
1730 | v4 = (const struct in_addr*)&start[1]; | 1773 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; |
1731 | payload = &v4[1]; | 1774 | break; |
1732 | pkt_len -= sizeof(struct in_addr); | ||
1733 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
1734 | break; | ||
1735 | |||
1736 | case AF_INET6: | ||
1737 | if (pkt_len < sizeof(struct in6_addr)) | ||
1738 | { | ||
1739 | GNUNET_break_op(0); | ||
1740 | return; | ||
1741 | } | ||
1742 | if (!ipv6_exit) | ||
1743 | { | ||
1744 | GNUNET_break_op(0); | ||
1745 | return; | ||
1746 | } | ||
1747 | v6 = (const struct in6_addr*)&start[1]; | ||
1748 | payload = &v6[1]; | ||
1749 | pkt_len -= sizeof(struct in6_addr); | ||
1750 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1751 | break; | ||
1752 | 1775 | ||
1753 | default: | 1776 | case AF_INET6: |
1754 | GNUNET_break_op(0); | 1777 | if (pkt_len < sizeof(struct in6_addr)) |
1778 | { | ||
1779 | GNUNET_break_op (0); | ||
1780 | return; | ||
1781 | } | ||
1782 | if (! ipv6_exit) | ||
1783 | { | ||
1784 | GNUNET_break_op (0); | ||
1755 | return; | 1785 | return; |
1756 | } | 1786 | } |
1787 | v6 = (const struct in6_addr*) &start[1]; | ||
1788 | payload = &v6[1]; | ||
1789 | pkt_len -= sizeof(struct in6_addr); | ||
1790 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | ||
1791 | break; | ||
1792 | |||
1793 | default: | ||
1794 | GNUNET_break_op (0); | ||
1795 | return; | ||
1796 | } | ||
1757 | { | 1797 | { |
1758 | char buf[INET6_ADDRSTRLEN]; | 1798 | char buf[INET6_ADDRSTRLEN]; |
1759 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1760 | "Received payload from %s for existing TCP stream to %s:%u\n", | 1800 | "Received payload from %s for existing TCP stream to %s:%u\n", |
1761 | GNUNET_i2s(&state->peer), | 1801 | GNUNET_i2s (&state->peer), |
1762 | inet_ntop(af, | 1802 | inet_ntop (af, |
1763 | &state->specifics.tcp_udp.ri.remote_address.address, | 1803 | &state->specifics.tcp_udp.ri.remote_address.address, |
1764 | buf, sizeof(buf)), | 1804 | buf, sizeof(buf)), |
1765 | (unsigned int)ntohs(start->tcp_header.destination_port)); | 1805 | (unsigned int) ntohs (start->tcp_header.destination_port)); |
1766 | } | 1806 | } |
1767 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_TCP; | 1807 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_TCP; |
1768 | state->specifics.tcp_udp.ri.remote_address.port = ntohs(start->tcp_header.destination_port); | 1808 | state->specifics.tcp_udp.ri.remote_address.port = ntohs ( |
1769 | setup_state_record(state); | 1809 | start->tcp_header.destination_port); |
1770 | send_tcp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, | 1810 | setup_state_record (state); |
1771 | &state->specifics.tcp_udp.ri.local_address, | 1811 | send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, |
1772 | &start->tcp_header, | 1812 | &state->specifics.tcp_udp.ri.local_address, |
1773 | payload, | 1813 | &start->tcp_header, |
1774 | pkt_len); | 1814 | payload, |
1775 | GNUNET_CADET_receive_done(state->channel); | 1815 | pkt_len); |
1816 | GNUNET_CADET_receive_done (state->channel); | ||
1776 | } | 1817 | } |
1777 | 1818 | ||
1778 | 1819 | ||
@@ -1786,31 +1827,32 @@ handle_tcp_remote(void *cls, | |||
1786 | * #GNUNET_SYSERR to close it (signal serious error) | 1827 | * #GNUNET_SYSERR to close it (signal serious error) |
1787 | */ | 1828 | */ |
1788 | static int | 1829 | static int |
1789 | check_tcp_data(void *cls, | 1830 | check_tcp_data (void *cls, |
1790 | const struct GNUNET_EXIT_TcpDataMessage *data) | 1831 | const struct GNUNET_EXIT_TcpDataMessage *data) |
1791 | { | 1832 | { |
1792 | struct ChannelState *state = cls; | 1833 | struct ChannelState *state = cls; |
1793 | 1834 | ||
1794 | if ((NULL == state) || | 1835 | if ((NULL == state) || |
1795 | (NULL == state->specifics.tcp_udp.heap_node)) | 1836 | (NULL == state->specifics.tcp_udp.heap_node)) |
1796 | { | 1837 | { |
1797 | /* connection should have been up! */ | 1838 | /* connection should have been up! */ |
1798 | GNUNET_STATISTICS_update(stats, | 1839 | GNUNET_STATISTICS_update (stats, |
1799 | gettext_noop("# TCP DATA requests dropped (no session)"), | 1840 | gettext_noop ( |
1800 | 1, GNUNET_NO); | 1841 | "# TCP DATA requests dropped (no session)"), |
1801 | GNUNET_break_op(0); | 1842 | 1, GNUNET_NO); |
1802 | return GNUNET_SYSERR; | 1843 | GNUNET_break_op (0); |
1803 | } | 1844 | return GNUNET_SYSERR; |
1845 | } | ||
1804 | if (data->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) | 1846 | if (data->tcp_header.off * 4 < sizeof(struct GNUNET_TUN_TcpHeader)) |
1805 | { | 1847 | { |
1806 | GNUNET_break_op(0); | 1848 | GNUNET_break_op (0); |
1807 | return GNUNET_SYSERR; | 1849 | return GNUNET_SYSERR; |
1808 | } | 1850 | } |
1809 | if (GNUNET_YES == state->is_dns) | 1851 | if (GNUNET_YES == state->is_dns) |
1810 | { | 1852 | { |
1811 | GNUNET_break_op(0); | 1853 | GNUNET_break_op (0); |
1812 | return GNUNET_SYSERR; | 1854 | return GNUNET_SYSERR; |
1813 | } | 1855 | } |
1814 | return GNUNET_OK; | 1856 | return GNUNET_OK; |
1815 | } | 1857 | } |
1816 | 1858 | ||
@@ -1823,42 +1865,44 @@ check_tcp_data(void *cls, | |||
1823 | * @param message the actual message | 1865 | * @param message the actual message |
1824 | */ | 1866 | */ |
1825 | static void | 1867 | static void |
1826 | handle_tcp_data(void *cls, | 1868 | handle_tcp_data (void *cls, |
1827 | const struct GNUNET_EXIT_TcpDataMessage *data) | 1869 | const struct GNUNET_EXIT_TcpDataMessage *data) |
1828 | { | 1870 | { |
1829 | struct ChannelState *state = cls; | 1871 | struct ChannelState *state = cls; |
1830 | uint16_t pkt_len = ntohs(data->header.size) - sizeof(struct GNUNET_EXIT_TcpDataMessage); | 1872 | uint16_t pkt_len = ntohs (data->header.size) - sizeof(struct |
1831 | 1873 | GNUNET_EXIT_TcpDataMessage); | |
1832 | GNUNET_STATISTICS_update(stats, | 1874 | |
1833 | gettext_noop("# Bytes received from CADET"), | 1875 | GNUNET_STATISTICS_update (stats, |
1834 | pkt_len, GNUNET_NO); | 1876 | gettext_noop ("# Bytes received from CADET"), |
1835 | GNUNET_STATISTICS_update(stats, | 1877 | pkt_len, GNUNET_NO); |
1836 | gettext_noop("# TCP data requests received via cadet"), | 1878 | GNUNET_STATISTICS_update (stats, |
1837 | 1, GNUNET_NO); | 1879 | gettext_noop ( |
1880 | "# TCP data requests received via cadet"), | ||
1881 | 1, GNUNET_NO); | ||
1838 | if (GNUNET_SYSERR == state->is_dns) | 1882 | if (GNUNET_SYSERR == state->is_dns) |
1839 | { | 1883 | { |
1840 | /* channel is UDP/TCP from now on */ | 1884 | /* channel is UDP/TCP from now on */ |
1841 | state->is_dns = GNUNET_NO; | 1885 | state->is_dns = GNUNET_NO; |
1842 | } | 1886 | } |
1843 | 1887 | ||
1844 | GNUNET_break_op(ntohl(data->reserved) == 0); | 1888 | GNUNET_break_op (ntohl (data->reserved) == 0); |
1845 | { | 1889 | { |
1846 | char buf[INET6_ADDRSTRLEN]; | 1890 | char buf[INET6_ADDRSTRLEN]; |
1847 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1848 | "Received additional %u bytes of data from %s for TCP stream to %s:%u\n", | 1892 | "Received additional %u bytes of data from %s for TCP stream to %s:%u\n", |
1849 | pkt_len, | 1893 | pkt_len, |
1850 | GNUNET_i2s(&state->peer), | 1894 | GNUNET_i2s (&state->peer), |
1851 | inet_ntop(state->specifics.tcp_udp.ri.remote_address.af, | 1895 | inet_ntop (state->specifics.tcp_udp.ri.remote_address.af, |
1852 | &state->specifics.tcp_udp.ri.remote_address.address, | 1896 | &state->specifics.tcp_udp.ri.remote_address.address, |
1853 | buf, sizeof(buf)), | 1897 | buf, sizeof(buf)), |
1854 | (unsigned int)state->specifics.tcp_udp.ri.remote_address.port); | 1898 | (unsigned int) state->specifics.tcp_udp.ri.remote_address.port); |
1855 | } | 1899 | } |
1856 | 1900 | ||
1857 | send_tcp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, | 1901 | send_tcp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, |
1858 | &state->specifics.tcp_udp.ri.local_address, | 1902 | &state->specifics.tcp_udp.ri.local_address, |
1859 | &data->tcp_header, | 1903 | &data->tcp_header, |
1860 | &data[1], pkt_len); | 1904 | &data[1], pkt_len); |
1861 | GNUNET_CADET_receive_done(state->channel); | 1905 | GNUNET_CADET_receive_done (state->channel); |
1862 | } | 1906 | } |
1863 | 1907 | ||
1864 | 1908 | ||
@@ -1872,19 +1916,23 @@ handle_tcp_data(void *cls, | |||
1872 | * also be the first 8 bytes of the TCP header | 1916 | * also be the first 8 bytes of the TCP header |
1873 | */ | 1917 | */ |
1874 | static void | 1918 | static void |
1875 | make_up_icmpv4_payload(struct ChannelState *state, | 1919 | make_up_icmpv4_payload (struct ChannelState *state, |
1876 | struct GNUNET_TUN_IPv4Header *ipp, | 1920 | struct GNUNET_TUN_IPv4Header *ipp, |
1877 | struct GNUNET_TUN_UdpHeader *udp) | 1921 | struct GNUNET_TUN_UdpHeader *udp) |
1878 | { | 1922 | { |
1879 | GNUNET_TUN_initialize_ipv4_header(ipp, | 1923 | GNUNET_TUN_initialize_ipv4_header (ipp, |
1880 | state->specifics.tcp_udp.ri.remote_address.proto, | 1924 | state->specifics.tcp_udp.ri.remote_address. |
1881 | sizeof(struct GNUNET_TUN_TcpHeader), | 1925 | proto, |
1882 | &state->specifics.tcp_udp.ri.remote_address.address.ipv4, | 1926 | sizeof(struct GNUNET_TUN_TcpHeader), |
1883 | &state->specifics.tcp_udp.ri.local_address.address.ipv4); | 1927 | &state->specifics.tcp_udp.ri.remote_address |
1884 | udp->source_port = htons(state->specifics.tcp_udp.ri.remote_address.port); | 1928 | .address.ipv4, |
1885 | udp->destination_port = htons(state->specifics.tcp_udp.ri.local_address.port); | 1929 | &state->specifics.tcp_udp.ri.local_address. |
1886 | udp->len = htons(0); | 1930 | address.ipv4); |
1887 | udp->crc = htons(0); | 1931 | udp->source_port = htons (state->specifics.tcp_udp.ri.remote_address.port); |
1932 | udp->destination_port = htons ( | ||
1933 | state->specifics.tcp_udp.ri.local_address.port); | ||
1934 | udp->len = htons (0); | ||
1935 | udp->crc = htons (0); | ||
1888 | } | 1936 | } |
1889 | 1937 | ||
1890 | 1938 | ||
@@ -1898,19 +1946,23 @@ make_up_icmpv4_payload(struct ChannelState *state, | |||
1898 | * also be the first 8 bytes of the TCP header | 1946 | * also be the first 8 bytes of the TCP header |
1899 | */ | 1947 | */ |
1900 | static void | 1948 | static void |
1901 | make_up_icmpv6_payload(struct ChannelState *state, | 1949 | make_up_icmpv6_payload (struct ChannelState *state, |
1902 | struct GNUNET_TUN_IPv6Header *ipp, | 1950 | struct GNUNET_TUN_IPv6Header *ipp, |
1903 | struct GNUNET_TUN_UdpHeader *udp) | 1951 | struct GNUNET_TUN_UdpHeader *udp) |
1904 | { | 1952 | { |
1905 | GNUNET_TUN_initialize_ipv6_header(ipp, | 1953 | GNUNET_TUN_initialize_ipv6_header (ipp, |
1906 | state->specifics.tcp_udp.ri.remote_address.proto, | 1954 | state->specifics.tcp_udp.ri.remote_address. |
1907 | sizeof(struct GNUNET_TUN_TcpHeader), | 1955 | proto, |
1908 | &state->specifics.tcp_udp.ri.remote_address.address.ipv6, | 1956 | sizeof(struct GNUNET_TUN_TcpHeader), |
1909 | &state->specifics.tcp_udp.ri.local_address.address.ipv6); | 1957 | &state->specifics.tcp_udp.ri.remote_address |
1910 | udp->source_port = htons(state->specifics.tcp_udp.ri.remote_address.port); | 1958 | .address.ipv6, |
1911 | udp->destination_port = htons(state->specifics.tcp_udp.ri.local_address.port); | 1959 | &state->specifics.tcp_udp.ri.local_address. |
1912 | udp->len = htons(0); | 1960 | address.ipv6); |
1913 | udp->crc = htons(0); | 1961 | udp->source_port = htons (state->specifics.tcp_udp.ri.remote_address.port); |
1962 | udp->destination_port = htons ( | ||
1963 | state->specifics.tcp_udp.ri.local_address.port); | ||
1964 | udp->len = htons (0); | ||
1965 | udp->crc = htons (0); | ||
1914 | } | 1966 | } |
1915 | 1967 | ||
1916 | 1968 | ||
@@ -1923,16 +1975,16 @@ make_up_icmpv6_payload(struct ChannelState *state, | |||
1923 | * #GNUNET_SYSERR to close it (signal serious error) | 1975 | * #GNUNET_SYSERR to close it (signal serious error) |
1924 | */ | 1976 | */ |
1925 | static int | 1977 | static int |
1926 | check_icmp_remote(void *cls, | 1978 | check_icmp_remote (void *cls, |
1927 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) | 1979 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) |
1928 | { | 1980 | { |
1929 | struct ChannelState *state = cls; | 1981 | struct ChannelState *state = cls; |
1930 | 1982 | ||
1931 | if (GNUNET_YES == state->is_dns) | 1983 | if (GNUNET_YES == state->is_dns) |
1932 | { | 1984 | { |
1933 | GNUNET_break_op(0); | 1985 | GNUNET_break_op (0); |
1934 | return GNUNET_SYSERR; | 1986 | return GNUNET_SYSERR; |
1935 | } | 1987 | } |
1936 | return GNUNET_OK; | 1988 | return GNUNET_OK; |
1937 | } | 1989 | } |
1938 | 1990 | ||
@@ -1944,11 +1996,12 @@ check_icmp_remote(void *cls, | |||
1944 | * @param msg the actual message | 1996 | * @param msg the actual message |
1945 | */ | 1997 | */ |
1946 | static void | 1998 | static void |
1947 | handle_icmp_remote(void *cls, | 1999 | handle_icmp_remote (void *cls, |
1948 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) | 2000 | const struct GNUNET_EXIT_IcmpInternetMessage *msg) |
1949 | { | 2001 | { |
1950 | struct ChannelState *state = cls; | 2002 | struct ChannelState *state = cls; |
1951 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_IcmpInternetMessage); | 2003 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof(struct |
2004 | GNUNET_EXIT_IcmpInternetMessage); | ||
1952 | const struct in_addr *v4; | 2005 | const struct in_addr *v4; |
1953 | const struct in6_addr *v6; | 2006 | const struct in6_addr *v6; |
1954 | const void *payload; | 2007 | const void *payload; |
@@ -1956,171 +2009,178 @@ handle_icmp_remote(void *cls, | |||
1956 | int af; | 2009 | int af; |
1957 | 2010 | ||
1958 | if (GNUNET_SYSERR == state->is_dns) | 2011 | if (GNUNET_SYSERR == state->is_dns) |
1959 | { | 2012 | { |
1960 | /* channel is UDP/TCP from now on */ | 2013 | /* channel is UDP/TCP from now on */ |
1961 | state->is_dns = GNUNET_NO; | 2014 | state->is_dns = GNUNET_NO; |
1962 | } | 2015 | } |
1963 | GNUNET_STATISTICS_update(stats, | 2016 | GNUNET_STATISTICS_update (stats, |
1964 | gettext_noop("# Bytes received from CADET"), | 2017 | gettext_noop ("# Bytes received from CADET"), |
1965 | pkt_len, GNUNET_NO); | 2018 | pkt_len, GNUNET_NO); |
1966 | GNUNET_STATISTICS_update(stats, | 2019 | GNUNET_STATISTICS_update (stats, |
1967 | gettext_noop("# ICMP IP-exit requests received via cadet"), | 2020 | gettext_noop ( |
1968 | 1, GNUNET_NO); | 2021 | "# ICMP IP-exit requests received via cadet"), |
1969 | 2022 | 1, GNUNET_NO); | |
1970 | af = (int)ntohl(msg->af); | 2023 | |
2024 | af = (int) ntohl (msg->af); | ||
1971 | if ((NULL != state->specifics.tcp_udp.heap_node) && | 2025 | if ((NULL != state->specifics.tcp_udp.heap_node) && |
1972 | (af != state->specifics.tcp_udp.ri.remote_address.af)) | 2026 | (af != state->specifics.tcp_udp.ri.remote_address.af)) |
2027 | { | ||
2028 | /* other peer switched AF on this channel; not allowed */ | ||
2029 | GNUNET_break_op (0); | ||
2030 | return; | ||
2031 | } | ||
2032 | |||
2033 | switch (af) | ||
2034 | { | ||
2035 | case AF_INET: | ||
2036 | if (pkt_len < sizeof(struct in_addr)) | ||
1973 | { | 2037 | { |
1974 | /* other peer switched AF on this channel; not allowed */ | 2038 | GNUNET_break_op (0); |
1975 | GNUNET_break_op(0); | ||
1976 | return; | 2039 | return; |
1977 | } | 2040 | } |
2041 | if (! ipv4_exit) | ||
2042 | { | ||
2043 | GNUNET_break_op (0); | ||
2044 | return; | ||
2045 | } | ||
2046 | v4 = (const struct in_addr*) &msg[1]; | ||
2047 | payload = &v4[1]; | ||
2048 | pkt_len -= sizeof(struct in_addr); | ||
2049 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | ||
2050 | if (NULL == state->specifics.tcp_udp.heap_node) | ||
2051 | { | ||
2052 | state->specifics.tcp_udp.ri.remote_address.af = af; | ||
2053 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMP; | ||
2054 | setup_state_record (state); | ||
2055 | } | ||
2056 | /* check that ICMP type is something we want to support | ||
2057 | and possibly make up payload! */ | ||
2058 | switch (msg->icmp_header.type) | ||
2059 | { | ||
2060 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
2061 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
2062 | break; | ||
1978 | 2063 | ||
1979 | switch (af) | 2064 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
2065 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2066 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2067 | if (0 != pkt_len) | ||
2068 | { | ||
2069 | GNUNET_break_op (0); | ||
2070 | return; | ||
2071 | } | ||
2072 | /* make up payload */ | ||
2073 | { | ||
2074 | struct GNUNET_TUN_IPv4Header *ipp = (struct | ||
2075 | GNUNET_TUN_IPv4Header *) buf; | ||
2076 | struct GNUNET_TUN_UdpHeader *udp = (struct | ||
2077 | GNUNET_TUN_UdpHeader *) &ipp[1]; | ||
2078 | |||
2079 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
2080 | pkt_len = sizeof(struct GNUNET_TUN_IPv4Header) + 8; | ||
2081 | make_up_icmpv4_payload (state, | ||
2082 | ipp, | ||
2083 | udp); | ||
2084 | payload = ipp; | ||
2085 | } | ||
2086 | break; | ||
2087 | |||
2088 | default: | ||
2089 | GNUNET_break_op (0); | ||
2090 | GNUNET_STATISTICS_update (stats, | ||
2091 | gettext_noop ( | ||
2092 | "# ICMPv4 packets dropped (type not allowed)"), | ||
2093 | 1, GNUNET_NO); | ||
2094 | return; | ||
2095 | } | ||
2096 | /* end AF_INET */ | ||
2097 | break; | ||
2098 | |||
2099 | case AF_INET6: | ||
2100 | if (pkt_len < sizeof(struct in6_addr)) | ||
1980 | { | 2101 | { |
1981 | case AF_INET: | 2102 | GNUNET_break_op (0); |
1982 | if (pkt_len < sizeof(struct in_addr)) | 2103 | return; |
1983 | { | 2104 | } |
1984 | GNUNET_break_op(0); | 2105 | if (! ipv6_exit) |
1985 | return; | 2106 | { |
1986 | } | 2107 | GNUNET_break_op (0); |
1987 | if (!ipv4_exit) | 2108 | return; |
1988 | { | 2109 | } |
1989 | GNUNET_break_op(0); | 2110 | v6 = (const struct in6_addr*) &msg[1]; |
1990 | return; | 2111 | payload = &v6[1]; |
1991 | } | 2112 | pkt_len -= sizeof(struct in6_addr); |
1992 | v4 = (const struct in_addr*)&msg[1]; | 2113 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; |
1993 | payload = &v4[1]; | 2114 | if (NULL == state->specifics.tcp_udp.heap_node) |
1994 | pkt_len -= sizeof(struct in_addr); | 2115 | { |
1995 | state->specifics.tcp_udp.ri.remote_address.address.ipv4 = *v4; | 2116 | state->specifics.tcp_udp.ri.remote_address.af = af; |
1996 | if (NULL == state->specifics.tcp_udp.heap_node) | 2117 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMPV6; |
1997 | { | 2118 | setup_state_record (state); |
1998 | state->specifics.tcp_udp.ri.remote_address.af = af; | 2119 | } |
1999 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMP; | 2120 | /* check that ICMP type is something we want to support |
2000 | setup_state_record(state); | 2121 | and possibly make up payload! */ |
2001 | } | 2122 | switch (msg->icmp_header.type) |
2002 | /* check that ICMP type is something we want to support | 2123 | { |
2003 | and possibly make up payload! */ | 2124 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: |
2004 | switch (msg->icmp_header.type) | 2125 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: |
2005 | { | ||
2006 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
2007 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
2008 | break; | ||
2009 | |||
2010 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
2011 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2012 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2013 | if (0 != pkt_len) | ||
2014 | { | ||
2015 | GNUNET_break_op(0); | ||
2016 | return; | ||
2017 | } | ||
2018 | /* make up payload */ | ||
2019 | { | ||
2020 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *)buf; | ||
2021 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
2022 | |||
2023 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
2024 | pkt_len = sizeof(struct GNUNET_TUN_IPv4Header) + 8; | ||
2025 | make_up_icmpv4_payload(state, | ||
2026 | ipp, | ||
2027 | udp); | ||
2028 | payload = ipp; | ||
2029 | } | ||
2030 | break; | ||
2031 | |||
2032 | default: | ||
2033 | GNUNET_break_op(0); | ||
2034 | GNUNET_STATISTICS_update(stats, | ||
2035 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
2036 | 1, GNUNET_NO); | ||
2037 | return; | ||
2038 | } | ||
2039 | /* end AF_INET */ | ||
2040 | break; | 2126 | break; |
2041 | 2127 | ||
2042 | case AF_INET6: | 2128 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: |
2043 | if (pkt_len < sizeof(struct in6_addr)) | 2129 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: |
2044 | { | 2130 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: |
2045 | GNUNET_break_op(0); | 2131 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: |
2046 | return; | 2132 | if (0 != pkt_len) |
2047 | } | 2133 | { |
2048 | if (!ipv6_exit) | 2134 | GNUNET_break_op (0); |
2049 | { | 2135 | return; |
2050 | GNUNET_break_op(0); | 2136 | } |
2051 | return; | 2137 | /* make up payload */ |
2052 | } | 2138 | { |
2053 | v6 = (const struct in6_addr*)&msg[1]; | 2139 | struct GNUNET_TUN_IPv6Header *ipp = (struct |
2054 | payload = &v6[1]; | 2140 | GNUNET_TUN_IPv6Header *) buf; |
2055 | pkt_len -= sizeof(struct in6_addr); | 2141 | struct GNUNET_TUN_UdpHeader *udp = (struct |
2056 | state->specifics.tcp_udp.ri.remote_address.address.ipv6 = *v6; | 2142 | GNUNET_TUN_UdpHeader *) &ipp[1]; |
2057 | if (NULL == state->specifics.tcp_udp.heap_node) | 2143 | |
2058 | { | 2144 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); |
2059 | state->specifics.tcp_udp.ri.remote_address.af = af; | 2145 | pkt_len = sizeof(struct GNUNET_TUN_IPv6Header) + 8; |
2060 | state->specifics.tcp_udp.ri.remote_address.proto = IPPROTO_ICMPV6; | 2146 | make_up_icmpv6_payload (state, |
2061 | setup_state_record(state); | 2147 | ipp, |
2062 | } | 2148 | udp); |
2063 | /* check that ICMP type is something we want to support | 2149 | payload = ipp; |
2064 | and possibly make up payload! */ | 2150 | } |
2065 | switch (msg->icmp_header.type) | ||
2066 | { | ||
2067 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | ||
2068 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
2069 | break; | ||
2070 | |||
2071 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | ||
2072 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
2073 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
2074 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
2075 | if (0 != pkt_len) | ||
2076 | { | ||
2077 | GNUNET_break_op(0); | ||
2078 | return; | ||
2079 | } | ||
2080 | /* make up payload */ | ||
2081 | { | ||
2082 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *)buf; | ||
2083 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *)&ipp[1]; | ||
2084 | |||
2085 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | ||
2086 | pkt_len = sizeof(struct GNUNET_TUN_IPv6Header) + 8; | ||
2087 | make_up_icmpv6_payload(state, | ||
2088 | ipp, | ||
2089 | udp); | ||
2090 | payload = ipp; | ||
2091 | } | ||
2092 | break; | ||
2093 | |||
2094 | default: | ||
2095 | GNUNET_break_op(0); | ||
2096 | GNUNET_STATISTICS_update(stats, | ||
2097 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
2098 | 1, GNUNET_NO); | ||
2099 | return; | ||
2100 | } | ||
2101 | /* end AF_INET6 */ | ||
2102 | break; | 2151 | break; |
2103 | 2152 | ||
2104 | default: | 2153 | default: |
2105 | /* bad AF */ | 2154 | GNUNET_break_op (0); |
2106 | GNUNET_break_op(0); | 2155 | GNUNET_STATISTICS_update (stats, |
2156 | gettext_noop ( | ||
2157 | "# ICMPv6 packets dropped (type not allowed)"), | ||
2158 | 1, GNUNET_NO); | ||
2107 | return; | 2159 | return; |
2108 | } | 2160 | } |
2161 | /* end AF_INET6 */ | ||
2162 | break; | ||
2163 | |||
2164 | default: | ||
2165 | /* bad AF */ | ||
2166 | GNUNET_break_op (0); | ||
2167 | return; | ||
2168 | } | ||
2109 | 2169 | ||
2110 | { | 2170 | { |
2111 | char buf[INET6_ADDRSTRLEN]; | 2171 | char buf[INET6_ADDRSTRLEN]; |
2112 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2113 | "Received ICMP data from %s for forwarding to %s\n", | 2173 | "Received ICMP data from %s for forwarding to %s\n", |
2114 | GNUNET_i2s(&state->peer), | 2174 | GNUNET_i2s (&state->peer), |
2115 | inet_ntop(af, | 2175 | inet_ntop (af, |
2116 | &state->specifics.tcp_udp.ri.remote_address.address, | 2176 | &state->specifics.tcp_udp.ri.remote_address.address, |
2117 | buf, sizeof(buf))); | 2177 | buf, sizeof(buf))); |
2118 | } | 2178 | } |
2119 | send_icmp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, | 2179 | send_icmp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, |
2120 | &state->specifics.tcp_udp.ri.local_address, | 2180 | &state->specifics.tcp_udp.ri.local_address, |
2121 | &msg->icmp_header, | 2181 | &msg->icmp_header, |
2122 | payload, pkt_len); | 2182 | payload, pkt_len); |
2123 | GNUNET_CADET_receive_done(state->channel); | 2183 | GNUNET_CADET_receive_done (state->channel); |
2124 | } | 2184 | } |
2125 | 2185 | ||
2126 | 2186 | ||
@@ -2134,44 +2194,44 @@ handle_icmp_remote(void *cls, | |||
2134 | * @return number of bytes of payload we created in buf | 2194 | * @return number of bytes of payload we created in buf |
2135 | */ | 2195 | */ |
2136 | static uint16_t | 2196 | static uint16_t |
2137 | make_up_icmp_service_payload(struct ChannelState *state, | 2197 | make_up_icmp_service_payload (struct ChannelState *state, |
2138 | char *buf) | 2198 | char *buf) |
2139 | { | 2199 | { |
2140 | switch (state->specifics.tcp_udp.serv->address.af) | 2200 | switch (state->specifics.tcp_udp.serv->address.af) |
2141 | { | 2201 | { |
2142 | case AF_INET: | 2202 | case AF_INET: |
2143 | { | 2203 | { |
2144 | struct GNUNET_TUN_IPv4Header *ipv4; | 2204 | struct GNUNET_TUN_IPv4Header *ipv4; |
2145 | struct GNUNET_TUN_UdpHeader *udp; | 2205 | struct GNUNET_TUN_UdpHeader *udp; |
2146 | 2206 | ||
2147 | ipv4 = (struct GNUNET_TUN_IPv4Header *)buf; | 2207 | ipv4 = (struct GNUNET_TUN_IPv4Header *) buf; |
2148 | udp = (struct GNUNET_TUN_UdpHeader *)&ipv4[1]; | 2208 | udp = (struct GNUNET_TUN_UdpHeader *) &ipv4[1]; |
2149 | make_up_icmpv4_payload(state, | 2209 | make_up_icmpv4_payload (state, |
2150 | ipv4, | 2210 | ipv4, |
2151 | udp); | 2211 | udp); |
2152 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | 2212 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); |
2153 | return sizeof(struct GNUNET_TUN_IPv4Header) + 8; | 2213 | return sizeof(struct GNUNET_TUN_IPv4Header) + 8; |
2154 | } | 2214 | } |
2155 | break; | 2215 | break; |
2156 | 2216 | ||
2157 | case AF_INET6: | 2217 | case AF_INET6: |
2158 | { | 2218 | { |
2159 | struct GNUNET_TUN_IPv6Header *ipv6; | 2219 | struct GNUNET_TUN_IPv6Header *ipv6; |
2160 | struct GNUNET_TUN_UdpHeader *udp; | 2220 | struct GNUNET_TUN_UdpHeader *udp; |
2161 | 2221 | ||
2162 | ipv6 = (struct GNUNET_TUN_IPv6Header *)buf; | 2222 | ipv6 = (struct GNUNET_TUN_IPv6Header *) buf; |
2163 | udp = (struct GNUNET_TUN_UdpHeader *)&ipv6[1]; | 2223 | udp = (struct GNUNET_TUN_UdpHeader *) &ipv6[1]; |
2164 | make_up_icmpv6_payload(state, | 2224 | make_up_icmpv6_payload (state, |
2165 | ipv6, | 2225 | ipv6, |
2166 | udp); | 2226 | udp); |
2167 | GNUNET_assert(8 == sizeof(struct GNUNET_TUN_UdpHeader)); | 2227 | GNUNET_assert (8 == sizeof(struct GNUNET_TUN_UdpHeader)); |
2168 | return sizeof(struct GNUNET_TUN_IPv6Header) + 8; | 2228 | return sizeof(struct GNUNET_TUN_IPv6Header) + 8; |
2169 | } | 2229 | } |
2170 | break; | 2230 | break; |
2171 | 2231 | ||
2172 | default: | 2232 | default: |
2173 | GNUNET_break(0); | 2233 | GNUNET_break (0); |
2174 | } | 2234 | } |
2175 | return 0; | 2235 | return 0; |
2176 | } | 2236 | } |
2177 | 2237 | ||
@@ -2186,21 +2246,21 @@ make_up_icmp_service_payload(struct ChannelState *state, | |||
2186 | * #GNUNET_SYSERR to close it (signal serious error) | 2246 | * #GNUNET_SYSERR to close it (signal serious error) |
2187 | */ | 2247 | */ |
2188 | static int | 2248 | static int |
2189 | check_icmp_service(void *cls, | 2249 | check_icmp_service (void *cls, |
2190 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) | 2250 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) |
2191 | { | 2251 | { |
2192 | struct ChannelState *state = cls; | 2252 | struct ChannelState *state = cls; |
2193 | 2253 | ||
2194 | if (GNUNET_YES == state->is_dns) | 2254 | if (GNUNET_YES == state->is_dns) |
2195 | { | 2255 | { |
2196 | GNUNET_break_op(0); | 2256 | GNUNET_break_op (0); |
2197 | return GNUNET_SYSERR; | 2257 | return GNUNET_SYSERR; |
2198 | } | 2258 | } |
2199 | if (NULL == state->specifics.tcp_udp.serv) | 2259 | if (NULL == state->specifics.tcp_udp.serv) |
2200 | { | 2260 | { |
2201 | GNUNET_break_op(0); | 2261 | GNUNET_break_op (0); |
2202 | return GNUNET_SYSERR; | 2262 | return GNUNET_SYSERR; |
2203 | } | 2263 | } |
2204 | return GNUNET_OK; | 2264 | return GNUNET_OK; |
2205 | } | 2265 | } |
2206 | 2266 | ||
@@ -2213,176 +2273,182 @@ check_icmp_service(void *cls, | |||
2213 | * @param msg the actual message | 2273 | * @param msg the actual message |
2214 | */ | 2274 | */ |
2215 | static void | 2275 | static void |
2216 | handle_icmp_service(void *cls, | 2276 | handle_icmp_service (void *cls, |
2217 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) | 2277 | const struct GNUNET_EXIT_IcmpServiceMessage *msg) |
2218 | { | 2278 | { |
2219 | struct ChannelState *state = cls; | 2279 | struct ChannelState *state = cls; |
2220 | uint16_t pkt_len = ntohs(msg->header.size) - sizeof(struct GNUNET_EXIT_IcmpServiceMessage); | 2280 | uint16_t pkt_len = ntohs (msg->header.size) - sizeof(struct |
2281 | GNUNET_EXIT_IcmpServiceMessage); | ||
2221 | struct GNUNET_TUN_IcmpHeader icmp; | 2282 | struct GNUNET_TUN_IcmpHeader icmp; |
2222 | char buf[sizeof(struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; | 2283 | char buf[sizeof(struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN; |
2223 | const void *payload; | 2284 | const void *payload; |
2224 | 2285 | ||
2225 | GNUNET_STATISTICS_update(stats, | 2286 | GNUNET_STATISTICS_update (stats, |
2226 | gettext_noop("# Bytes received from CADET"), | 2287 | gettext_noop ("# Bytes received from CADET"), |
2227 | pkt_len, GNUNET_NO); | 2288 | pkt_len, GNUNET_NO); |
2228 | GNUNET_STATISTICS_update(stats, | 2289 | GNUNET_STATISTICS_update (stats, |
2229 | gettext_noop("# ICMP service requests received via cadet"), | 2290 | gettext_noop ( |
2230 | 1, GNUNET_NO); | 2291 | "# ICMP service requests received via cadet"), |
2292 | 1, GNUNET_NO); | ||
2231 | /* check that we got at least a valid header */ | 2293 | /* check that we got at least a valid header */ |
2232 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2233 | "Received data from %s for forwarding to ICMP service %s\n", | 2295 | "Received data from %s for forwarding to ICMP service %s\n", |
2234 | GNUNET_i2s(&state->peer), | 2296 | GNUNET_i2s (&state->peer), |
2235 | GNUNET_h2s(&state->specifics.tcp_udp.serv->descriptor)); | 2297 | GNUNET_h2s (&state->specifics.tcp_udp.serv->descriptor)); |
2236 | icmp = msg->icmp_header; | 2298 | icmp = msg->icmp_header; |
2237 | payload = &msg[1]; | 2299 | payload = &msg[1]; |
2238 | state->specifics.tcp_udp.ri.remote_address | 2300 | state->specifics.tcp_udp.ri.remote_address |
2239 | = state->specifics.tcp_udp.serv->address; | 2301 | = state->specifics.tcp_udp.serv->address; |
2240 | setup_state_record(state); | 2302 | setup_state_record (state); |
2241 | 2303 | ||
2242 | /* check that ICMP type is something we want to support, | 2304 | /* check that ICMP type is something we want to support, |
2243 | perform ICMP PT if needed ans possibly make up payload */ | 2305 | perform ICMP PT if needed ans possibly make up payload */ |
2244 | switch (msg->af) | 2306 | switch (msg->af) |
2307 | { | ||
2308 | case AF_INET: | ||
2309 | switch (msg->icmp_header.type) | ||
2245 | { | 2310 | { |
2246 | case AF_INET: | 2311 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
2247 | switch (msg->icmp_header.type) | 2312 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2248 | { | 2313 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; |
2249 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
2250 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2251 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; | ||
2252 | break; | ||
2253 | |||
2254 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
2255 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2256 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; | ||
2257 | break; | ||
2258 | |||
2259 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
2260 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2261 | icmp.type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; | ||
2262 | if (0 != pkt_len) | ||
2263 | { | ||
2264 | GNUNET_break_op(0); | ||
2265 | return; | ||
2266 | } | ||
2267 | payload = buf; | ||
2268 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2269 | break; | ||
2270 | |||
2271 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2272 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2273 | icmp.type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; | ||
2274 | if (0 != pkt_len) | ||
2275 | { | ||
2276 | GNUNET_break_op(0); | ||
2277 | return; | ||
2278 | } | ||
2279 | payload = buf; | ||
2280 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2281 | break; | ||
2282 | |||
2283 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2284 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) | ||
2285 | { | ||
2286 | GNUNET_STATISTICS_update(stats, | ||
2287 | gettext_noop("# ICMPv4 packets dropped (impossible PT to v6)"), | ||
2288 | 1, GNUNET_NO); | ||
2289 | return; | ||
2290 | } | ||
2291 | if (0 != pkt_len) | ||
2292 | { | ||
2293 | GNUNET_break_op(0); | ||
2294 | return; | ||
2295 | } | ||
2296 | payload = buf; | ||
2297 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2298 | break; | ||
2299 | |||
2300 | default: | ||
2301 | GNUNET_break_op(0); | ||
2302 | GNUNET_STATISTICS_update(stats, | ||
2303 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
2304 | 1, GNUNET_NO); | ||
2305 | return; | ||
2306 | } | ||
2307 | /* end of AF_INET */ | ||
2308 | break; | 2314 | break; |
2309 | 2315 | ||
2310 | case AF_INET6: | 2316 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
2311 | switch (msg->icmp_header.type) | 2317 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2312 | { | 2318 | icmp.type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; |
2313 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | 2319 | break; |
2314 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2320 | |
2315 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; | 2321 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
2316 | break; | 2322 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2317 | 2323 | icmp.type = GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE; | |
2318 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | 2324 | if (0 != pkt_len) |
2319 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2325 | { |
2320 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; | 2326 | GNUNET_break_op (0); |
2321 | break; | 2327 | return; |
2322 | 2328 | } | |
2323 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | 2329 | payload = buf; |
2324 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2330 | pkt_len = make_up_icmp_service_payload (state, buf); |
2325 | icmp.type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; | 2331 | break; |
2326 | if (0 != pkt_len) | 2332 | |
2327 | { | 2333 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
2328 | GNUNET_break_op(0); | 2334 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2329 | return; | 2335 | icmp.type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; |
2330 | } | 2336 | if (0 != pkt_len) |
2331 | payload = buf; | 2337 | { |
2332 | pkt_len = make_up_icmp_service_payload(state, buf); | 2338 | GNUNET_break_op (0); |
2333 | break; | 2339 | return; |
2334 | 2340 | } | |
2335 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | 2341 | payload = buf; |
2336 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2342 | pkt_len = make_up_icmp_service_payload (state, buf); |
2337 | icmp.type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; | 2343 | break; |
2338 | if (0 != pkt_len) | 2344 | |
2339 | { | 2345 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
2340 | GNUNET_break_op(0); | 2346 | if (state->specifics.tcp_udp.serv->address.af == AF_INET6) |
2341 | return; | 2347 | { |
2342 | } | 2348 | GNUNET_STATISTICS_update (stats, |
2343 | payload = buf; | 2349 | gettext_noop ( |
2344 | pkt_len = make_up_icmp_service_payload(state, buf); | 2350 | "# ICMPv4 packets dropped (impossible PT to v6)"), |
2345 | break; | 2351 | 1, GNUNET_NO); |
2346 | 2352 | return; | |
2347 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | 2353 | } |
2348 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | 2354 | if (0 != pkt_len) |
2349 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | 2355 | { |
2350 | { | 2356 | GNUNET_break_op (0); |
2351 | GNUNET_STATISTICS_update(stats, | 2357 | return; |
2352 | gettext_noop("# ICMPv6 packets dropped (impossible PT to v4)"), | 2358 | } |
2353 | 1, GNUNET_NO); | 2359 | payload = buf; |
2354 | return; | 2360 | pkt_len = make_up_icmp_service_payload (state, buf); |
2355 | } | ||
2356 | if (0 != pkt_len) | ||
2357 | { | ||
2358 | GNUNET_break_op(0); | ||
2359 | return; | ||
2360 | } | ||
2361 | payload = buf; | ||
2362 | pkt_len = make_up_icmp_service_payload(state, buf); | ||
2363 | break; | ||
2364 | |||
2365 | default: | ||
2366 | GNUNET_break_op(0); | ||
2367 | GNUNET_STATISTICS_update(stats, | ||
2368 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
2369 | 1, GNUNET_NO); | ||
2370 | return; | ||
2371 | } | ||
2372 | /* end of AF_INET6 */ | ||
2373 | break; | 2361 | break; |
2374 | 2362 | ||
2375 | default: | 2363 | default: |
2376 | GNUNET_break_op(0); | 2364 | GNUNET_break_op (0); |
2365 | GNUNET_STATISTICS_update (stats, | ||
2366 | gettext_noop ( | ||
2367 | "# ICMPv4 packets dropped (type not allowed)"), | ||
2368 | 1, GNUNET_NO); | ||
2377 | return; | 2369 | return; |
2378 | } | 2370 | } |
2371 | /* end of AF_INET */ | ||
2372 | break; | ||
2379 | 2373 | ||
2380 | send_icmp_packet_via_tun(&state->specifics.tcp_udp.ri.remote_address, | 2374 | case AF_INET6: |
2381 | &state->specifics.tcp_udp.ri.local_address, | 2375 | switch (msg->icmp_header.type) |
2382 | &icmp, | 2376 | { |
2383 | payload, | 2377 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: |
2384 | pkt_len); | 2378 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) |
2385 | GNUNET_CADET_receive_done(state->channel); | 2379 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REPLY; |
2380 | break; | ||
2381 | |||
2382 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
2383 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | ||
2384 | icmp.type = GNUNET_TUN_ICMPTYPE_ECHO_REQUEST; | ||
2385 | break; | ||
2386 | |||
2387 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | ||
2388 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | ||
2389 | icmp.type = GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE; | ||
2390 | if (0 != pkt_len) | ||
2391 | { | ||
2392 | GNUNET_break_op (0); | ||
2393 | return; | ||
2394 | } | ||
2395 | payload = buf; | ||
2396 | pkt_len = make_up_icmp_service_payload (state, buf); | ||
2397 | break; | ||
2398 | |||
2399 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | ||
2400 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | ||
2401 | icmp.type = GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED; | ||
2402 | if (0 != pkt_len) | ||
2403 | { | ||
2404 | GNUNET_break_op (0); | ||
2405 | return; | ||
2406 | } | ||
2407 | payload = buf; | ||
2408 | pkt_len = make_up_icmp_service_payload (state, buf); | ||
2409 | break; | ||
2410 | |||
2411 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | ||
2412 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | ||
2413 | if (state->specifics.tcp_udp.serv->address.af == AF_INET) | ||
2414 | { | ||
2415 | GNUNET_STATISTICS_update (stats, | ||
2416 | gettext_noop ( | ||
2417 | "# ICMPv6 packets dropped (impossible PT to v4)"), | ||
2418 | 1, GNUNET_NO); | ||
2419 | return; | ||
2420 | } | ||
2421 | if (0 != pkt_len) | ||
2422 | { | ||
2423 | GNUNET_break_op (0); | ||
2424 | return; | ||
2425 | } | ||
2426 | payload = buf; | ||
2427 | pkt_len = make_up_icmp_service_payload (state, buf); | ||
2428 | break; | ||
2429 | |||
2430 | default: | ||
2431 | GNUNET_break_op (0); | ||
2432 | GNUNET_STATISTICS_update (stats, | ||
2433 | gettext_noop ( | ||
2434 | "# ICMPv6 packets dropped (type not allowed)"), | ||
2435 | 1, GNUNET_NO); | ||
2436 | return; | ||
2437 | } | ||
2438 | /* end of AF_INET6 */ | ||
2439 | break; | ||
2440 | |||
2441 | default: | ||
2442 | GNUNET_break_op (0); | ||
2443 | return; | ||
2444 | } | ||
2445 | |||
2446 | send_icmp_packet_via_tun (&state->specifics.tcp_udp.ri.remote_address, | ||
2447 | &state->specifics.tcp_udp.ri.local_address, | ||
2448 | &icmp, | ||
2449 | payload, | ||
2450 | pkt_len); | ||
2451 | GNUNET_CADET_receive_done (state->channel); | ||
2386 | } | 2452 | } |
2387 | 2453 | ||
2388 | 2454 | ||
@@ -2395,19 +2461,19 @@ handle_icmp_service(void *cls, | |||
2395 | * @return #GNUNET_OK | 2461 | * @return #GNUNET_OK |
2396 | */ | 2462 | */ |
2397 | static int | 2463 | static int |
2398 | free_service_record(void *cls, | 2464 | free_service_record (void *cls, |
2399 | const struct GNUNET_HashCode *key, | 2465 | const struct GNUNET_HashCode *key, |
2400 | void *value) | 2466 | void *value) |
2401 | { | 2467 | { |
2402 | struct LocalService *service = value; | 2468 | struct LocalService *service = value; |
2403 | 2469 | ||
2404 | GNUNET_assert(GNUNET_YES == | 2470 | GNUNET_assert (GNUNET_YES == |
2405 | GNUNET_CONTAINER_multihashmap_remove(services, | 2471 | GNUNET_CONTAINER_multihashmap_remove (services, |
2406 | key, | 2472 | key, |
2407 | service)); | 2473 | service)); |
2408 | GNUNET_CADET_close_port(service->port); | 2474 | GNUNET_CADET_close_port (service->port); |
2409 | GNUNET_free_non_null(service->name); | 2475 | GNUNET_free_non_null (service->name); |
2410 | GNUNET_free(service); | 2476 | GNUNET_free (service); |
2411 | return GNUNET_OK; | 2477 | return GNUNET_OK; |
2412 | } | 2478 | } |
2413 | 2479 | ||
@@ -2421,21 +2487,21 @@ free_service_record(void *cls, | |||
2421 | * @return initial channel context for the channel | 2487 | * @return initial channel context for the channel |
2422 | */ | 2488 | */ |
2423 | static void * | 2489 | static void * |
2424 | new_service_channel(void *cls, | 2490 | new_service_channel (void *cls, |
2425 | struct GNUNET_CADET_Channel *channel, | 2491 | struct GNUNET_CADET_Channel *channel, |
2426 | const struct GNUNET_PeerIdentity *initiator) | 2492 | const struct GNUNET_PeerIdentity *initiator) |
2427 | { | 2493 | { |
2428 | struct LocalService *ls = cls; | 2494 | struct LocalService *ls = cls; |
2429 | struct ChannelState *s = GNUNET_new(struct ChannelState); | 2495 | struct ChannelState *s = GNUNET_new (struct ChannelState); |
2430 | 2496 | ||
2431 | s->peer = *initiator; | 2497 | s->peer = *initiator; |
2432 | GNUNET_STATISTICS_update(stats, | 2498 | GNUNET_STATISTICS_update (stats, |
2433 | gettext_noop("# Inbound CADET channels created"), | 2499 | gettext_noop ("# Inbound CADET channels created"), |
2434 | 1, | 2500 | 1, |
2435 | GNUNET_NO); | 2501 | GNUNET_NO); |
2436 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2437 | "Received inbound channel from `%s'\n", | 2503 | "Received inbound channel from `%s'\n", |
2438 | GNUNET_i2s(initiator)); | 2504 | GNUNET_i2s (initiator)); |
2439 | s->channel = channel; | 2505 | s->channel = channel; |
2440 | s->specifics.tcp_udp.serv = ls; | 2506 | s->specifics.tcp_udp.serv = ls; |
2441 | s->specifics.tcp_udp.ri.remote_address = ls->address; | 2507 | s->specifics.tcp_udp.ri.remote_address = ls->address; |
@@ -2451,36 +2517,37 @@ new_service_channel(void *cls, | |||
2451 | * @param channel connection to the other end (henceforth invalid) | 2517 | * @param channel connection to the other end (henceforth invalid) |
2452 | */ | 2518 | */ |
2453 | static void | 2519 | static void |
2454 | clean_channel(void *cls, | 2520 | clean_channel (void *cls, |
2455 | const struct GNUNET_CADET_Channel *channel) | 2521 | const struct GNUNET_CADET_Channel *channel) |
2456 | { | 2522 | { |
2457 | struct ChannelState *s = cls; | 2523 | struct ChannelState *s = cls; |
2458 | 2524 | ||
2459 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2525 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2460 | "Channel destroyed\n"); | 2526 | "Channel destroyed\n"); |
2461 | if (GNUNET_SYSERR == s->is_dns) | 2527 | if (GNUNET_SYSERR == s->is_dns) |
2462 | { | 2528 | { |
2463 | GNUNET_free(s); | 2529 | GNUNET_free (s); |
2464 | return; | 2530 | return; |
2465 | } | 2531 | } |
2466 | if (GNUNET_YES == s->is_dns) | 2532 | if (GNUNET_YES == s->is_dns) |
2467 | { | 2533 | { |
2468 | if (channels[s->specifics.dns.my_id] == s) | 2534 | if (channels[s->specifics.dns.my_id] == s) |
2469 | channels[s->specifics.dns.my_id] = NULL; | 2535 | channels[s->specifics.dns.my_id] = NULL; |
2470 | } | 2536 | } |
2471 | else | 2537 | else |
2538 | { | ||
2539 | if (NULL != s->specifics.tcp_udp.heap_node) | ||
2472 | { | 2540 | { |
2473 | if (NULL != s->specifics.tcp_udp.heap_node) | 2541 | GNUNET_assert (GNUNET_YES == |
2474 | { | 2542 | GNUNET_CONTAINER_multihashmap_remove (connections_map, |
2475 | GNUNET_assert(GNUNET_YES == | 2543 | &s->specifics.tcp_udp |
2476 | GNUNET_CONTAINER_multihashmap_remove(connections_map, | 2544 | .state_key, |
2477 | &s->specifics.tcp_udp.state_key, | 2545 | s)); |
2478 | s)); | 2546 | GNUNET_CONTAINER_heap_remove_node (s->specifics.tcp_udp.heap_node); |
2479 | GNUNET_CONTAINER_heap_remove_node(s->specifics.tcp_udp.heap_node); | 2547 | s->specifics.tcp_udp.heap_node = NULL; |
2480 | s->specifics.tcp_udp.heap_node = NULL; | ||
2481 | } | ||
2482 | } | 2548 | } |
2483 | GNUNET_free(s); | 2549 | } |
2550 | GNUNET_free (s); | ||
2484 | } | 2551 | } |
2485 | 2552 | ||
2486 | 2553 | ||
@@ -2494,66 +2561,66 @@ clean_channel(void *cls, | |||
2494 | * @param service service information record to store (service->name will be set). | 2561 | * @param service service information record to store (service->name will be set). |
2495 | */ | 2562 | */ |
2496 | static void | 2563 | static void |
2497 | store_service(int proto, | 2564 | store_service (int proto, |
2498 | const char *name, | 2565 | const char *name, |
2499 | uint16_t destination_port, | 2566 | uint16_t destination_port, |
2500 | struct LocalService *service) | 2567 | struct LocalService *service) |
2501 | { | 2568 | { |
2502 | struct GNUNET_MQ_MessageHandler handlers[] = { | 2569 | struct GNUNET_MQ_MessageHandler handlers[] = { |
2503 | GNUNET_MQ_hd_var_size(icmp_service, | 2570 | GNUNET_MQ_hd_var_size (icmp_service, |
2504 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE, | 2571 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE, |
2505 | struct GNUNET_EXIT_IcmpServiceMessage, | 2572 | struct GNUNET_EXIT_IcmpServiceMessage, |
2506 | service), | 2573 | service), |
2507 | GNUNET_MQ_hd_var_size(udp_service, | 2574 | GNUNET_MQ_hd_var_size (udp_service, |
2508 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE, | 2575 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE, |
2509 | struct GNUNET_EXIT_UdpServiceMessage, | 2576 | struct GNUNET_EXIT_UdpServiceMessage, |
2510 | service), | 2577 | service), |
2511 | GNUNET_MQ_hd_var_size(tcp_service, | 2578 | GNUNET_MQ_hd_var_size (tcp_service, |
2512 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START, | 2579 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START, |
2513 | struct GNUNET_EXIT_TcpServiceStartMessage, | 2580 | struct GNUNET_EXIT_TcpServiceStartMessage, |
2514 | service), | 2581 | service), |
2515 | GNUNET_MQ_hd_var_size(tcp_data, | 2582 | GNUNET_MQ_hd_var_size (tcp_data, |
2516 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, | 2583 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, |
2517 | struct GNUNET_EXIT_TcpDataMessage, | 2584 | struct GNUNET_EXIT_TcpDataMessage, |
2518 | service), | 2585 | service), |
2519 | GNUNET_MQ_handler_end() | 2586 | GNUNET_MQ_handler_end () |
2520 | }; | 2587 | }; |
2521 | 2588 | ||
2522 | struct GNUNET_HashCode cadet_port; | 2589 | struct GNUNET_HashCode cadet_port; |
2523 | 2590 | ||
2524 | service->name = GNUNET_strdup(name); | 2591 | service->name = GNUNET_strdup (name); |
2525 | GNUNET_TUN_service_name_to_hash(name, | 2592 | GNUNET_TUN_service_name_to_hash (name, |
2526 | &service->descriptor); | 2593 | &service->descriptor); |
2527 | GNUNET_TUN_compute_service_cadet_port(&service->descriptor, | 2594 | GNUNET_TUN_compute_service_cadet_port (&service->descriptor, |
2528 | destination_port, | 2595 | destination_port, |
2529 | &cadet_port); | 2596 | &cadet_port); |
2530 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2531 | "Opening CADET port %s for SERVICE exit %s on port %u\n", | 2598 | "Opening CADET port %s for SERVICE exit %s on port %u\n", |
2532 | GNUNET_h2s(&cadet_port), | 2599 | GNUNET_h2s (&cadet_port), |
2533 | name, | 2600 | name, |
2534 | (unsigned int)destination_port); | 2601 | (unsigned int) destination_port); |
2535 | service->port = GNUNET_CADET_open_port(cadet_handle, | 2602 | service->port = GNUNET_CADET_open_port (cadet_handle, |
2536 | &cadet_port, | 2603 | &cadet_port, |
2537 | &new_service_channel, | 2604 | &new_service_channel, |
2538 | service, | 2605 | service, |
2539 | NULL, | 2606 | NULL, |
2540 | &clean_channel, | 2607 | &clean_channel, |
2541 | handlers); | 2608 | handlers); |
2542 | service->is_udp = (IPPROTO_UDP == proto); | 2609 | service->is_udp = (IPPROTO_UDP == proto); |
2543 | if (GNUNET_OK != | 2610 | if (GNUNET_OK != |
2544 | GNUNET_CONTAINER_multihashmap_put(services, | 2611 | GNUNET_CONTAINER_multihashmap_put (services, |
2545 | &cadet_port, | 2612 | &cadet_port, |
2546 | service, | 2613 | service, |
2547 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 2614 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
2548 | { | 2615 | { |
2549 | GNUNET_CADET_close_port(service->port); | 2616 | GNUNET_CADET_close_port (service->port); |
2550 | GNUNET_free_non_null(service->name); | 2617 | GNUNET_free_non_null (service->name); |
2551 | GNUNET_free(service); | 2618 | GNUNET_free (service); |
2552 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 2619 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2553 | _("Got duplicate service records for `%s:%u'\n"), | 2620 | _ ("Got duplicate service records for `%s:%u'\n"), |
2554 | name, | 2621 | name, |
2555 | (unsigned int)destination_port); | 2622 | (unsigned int) destination_port); |
2556 | } | 2623 | } |
2557 | } | 2624 | } |
2558 | 2625 | ||
2559 | 2626 | ||
@@ -2564,16 +2631,17 @@ store_service(int proto, | |||
2564 | * @param env message to queue | 2631 | * @param env message to queue |
2565 | */ | 2632 | */ |
2566 | static void | 2633 | static void |
2567 | send_packet_to_cadet_channel(struct ChannelState *s, | 2634 | send_packet_to_cadet_channel (struct ChannelState *s, |
2568 | struct GNUNET_MQ_Envelope *env) | 2635 | struct GNUNET_MQ_Envelope *env) |
2569 | { | 2636 | { |
2570 | GNUNET_assert(NULL != s); | 2637 | GNUNET_assert (NULL != s); |
2571 | GNUNET_STATISTICS_update(stats, | 2638 | GNUNET_STATISTICS_update (stats, |
2572 | gettext_noop("# Messages transmitted via cadet channels"), | 2639 | gettext_noop ( |
2573 | 1, | 2640 | "# Messages transmitted via cadet channels"), |
2574 | GNUNET_NO); | 2641 | 1, |
2575 | GNUNET_MQ_send(GNUNET_CADET_get_mq(s->channel), | 2642 | GNUNET_NO); |
2576 | env); | 2643 | GNUNET_MQ_send (GNUNET_CADET_get_mq (s->channel), |
2644 | env); | ||
2577 | } | 2645 | } |
2578 | 2646 | ||
2579 | 2647 | ||
@@ -2589,11 +2657,11 @@ send_packet_to_cadet_channel(struct ChannelState *s, | |||
2589 | * be the original destination address) | 2657 | * be the original destination address) |
2590 | */ | 2658 | */ |
2591 | static void | 2659 | static void |
2592 | icmp_from_helper(const struct GNUNET_TUN_IcmpHeader *icmp, | 2660 | icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp, |
2593 | size_t pktlen, | 2661 | size_t pktlen, |
2594 | int af, | 2662 | int af, |
2595 | const void *destination_ip, | 2663 | const void *destination_ip, |
2596 | const void *source_ip) | 2664 | const void *source_ip) |
2597 | { | 2665 | { |
2598 | struct ChannelState *state; | 2666 | struct ChannelState *state; |
2599 | struct GNUNET_MQ_Envelope *env; | 2667 | struct GNUNET_MQ_Envelope *env; |
@@ -2608,22 +2676,22 @@ icmp_from_helper(const struct GNUNET_TUN_IcmpHeader *icmp, | |||
2608 | { | 2676 | { |
2609 | char sbuf[INET6_ADDRSTRLEN]; | 2677 | char sbuf[INET6_ADDRSTRLEN]; |
2610 | char dbuf[INET6_ADDRSTRLEN]; | 2678 | char dbuf[INET6_ADDRSTRLEN]; |
2611 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2612 | "Received ICMP packet going from %s to %s\n", | 2680 | "Received ICMP packet going from %s to %s\n", |
2613 | inet_ntop(af, | 2681 | inet_ntop (af, |
2614 | source_ip, | 2682 | source_ip, |
2615 | sbuf, sizeof(sbuf)), | 2683 | sbuf, sizeof(sbuf)), |
2616 | inet_ntop(af, | 2684 | inet_ntop (af, |
2617 | destination_ip, | 2685 | destination_ip, |
2618 | dbuf, sizeof(dbuf))); | 2686 | dbuf, sizeof(dbuf))); |
2619 | } | 2687 | } |
2620 | 2688 | ||
2621 | if (pktlen < sizeof(struct GNUNET_TUN_IcmpHeader)) | 2689 | if (pktlen < sizeof(struct GNUNET_TUN_IcmpHeader)) |
2622 | { | 2690 | { |
2623 | /* blame kernel */ | 2691 | /* blame kernel */ |
2624 | GNUNET_break(0); | 2692 | GNUNET_break (0); |
2625 | return; | 2693 | return; |
2626 | } | 2694 | } |
2627 | 2695 | ||
2628 | /* Find out if this is an ICMP packet in response to an existing | 2696 | /* Find out if this is an ICMP packet in response to an existing |
2629 | TCP/UDP packet and if so, figure out ports / protocol of the | 2697 | TCP/UDP packet and if so, figure out ports / protocol of the |
@@ -2631,153 +2699,157 @@ icmp_from_helper(const struct GNUNET_TUN_IcmpHeader *icmp, | |||
2631 | source_port = 0; | 2699 | source_port = 0; |
2632 | destination_port = 0; | 2700 | destination_port = 0; |
2633 | switch (af) | 2701 | switch (af) |
2702 | { | ||
2703 | case AF_INET: | ||
2704 | protocol = IPPROTO_ICMP; | ||
2705 | switch (icmp->type) | ||
2634 | { | 2706 | { |
2635 | case AF_INET: | 2707 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
2636 | protocol = IPPROTO_ICMP; | 2708 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
2637 | switch (icmp->type) | ||
2638 | { | ||
2639 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | ||
2640 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | ||
2641 | break; | ||
2642 | |||
2643 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | ||
2644 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | ||
2645 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | ||
2646 | if (pktlen < | ||
2647 | sizeof(struct GNUNET_TUN_IcmpHeader) + | ||
2648 | sizeof(struct GNUNET_TUN_IPv4Header) + 8) | ||
2649 | { | ||
2650 | /* blame kernel */ | ||
2651 | GNUNET_break(0); | ||
2652 | return; | ||
2653 | } | ||
2654 | ipv4 = (const struct GNUNET_TUN_IPv4Header *)&icmp[1]; | ||
2655 | protocol = ipv4->protocol; | ||
2656 | /* could be TCP or UDP, but both have the ports in the right | ||
2657 | place, so that doesn't matter here */ | ||
2658 | udp = (const struct GNUNET_TUN_UdpHeader *)&ipv4[1]; | ||
2659 | /* swap ports, as they are from the original message */ | ||
2660 | destination_port = ntohs(udp->source_port); | ||
2661 | source_port = ntohs(udp->destination_port); | ||
2662 | /* throw away ICMP payload, won't be useful for the other side anyway */ | ||
2663 | pktlen = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2664 | break; | ||
2665 | |||
2666 | default: | ||
2667 | GNUNET_STATISTICS_update(stats, | ||
2668 | gettext_noop("# ICMPv4 packets dropped (type not allowed)"), | ||
2669 | 1, GNUNET_NO); | ||
2670 | return; | ||
2671 | } | ||
2672 | break; | 2709 | break; |
2673 | 2710 | ||
2674 | case AF_INET6: | 2711 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
2675 | protocol = IPPROTO_ICMPV6; | 2712 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
2676 | switch (icmp->type) | 2713 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
2677 | { | 2714 | if (pktlen < |
2678 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: | 2715 | sizeof(struct GNUNET_TUN_IcmpHeader) |
2679 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: | 2716 | + sizeof(struct GNUNET_TUN_IPv4Header) + 8) |
2680 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | 2717 | { |
2681 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | 2718 | /* blame kernel */ |
2682 | if (pktlen < | 2719 | GNUNET_break (0); |
2683 | sizeof(struct GNUNET_TUN_IcmpHeader) + | 2720 | return; |
2684 | sizeof(struct GNUNET_TUN_IPv6Header) + 8) | 2721 | } |
2685 | { | 2722 | ipv4 = (const struct GNUNET_TUN_IPv4Header *) &icmp[1]; |
2686 | /* blame kernel */ | 2723 | protocol = ipv4->protocol; |
2687 | GNUNET_break(0); | 2724 | /* could be TCP or UDP, but both have the ports in the right |
2688 | return; | 2725 | place, so that doesn't matter here */ |
2689 | } | 2726 | udp = (const struct GNUNET_TUN_UdpHeader *) &ipv4[1]; |
2690 | ipv6 = (const struct GNUNET_TUN_IPv6Header *)&icmp[1]; | 2727 | /* swap ports, as they are from the original message */ |
2691 | protocol = ipv6->next_header; | 2728 | destination_port = ntohs (udp->source_port); |
2692 | /* could be TCP or UDP, but both have the ports in the right | 2729 | source_port = ntohs (udp->destination_port); |
2693 | place, so that doesn't matter here */ | 2730 | /* throw away ICMP payload, won't be useful for the other side anyway */ |
2694 | udp = (const struct GNUNET_TUN_UdpHeader *)&ipv6[1]; | 2731 | pktlen = sizeof(struct GNUNET_TUN_IcmpHeader); |
2695 | /* swap ports, as they are from the original message */ | ||
2696 | destination_port = ntohs(udp->source_port); | ||
2697 | source_port = ntohs(udp->destination_port); | ||
2698 | /* throw away ICMP payload, won't be useful for the other side anyway */ | ||
2699 | pktlen = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2700 | break; | ||
2701 | |||
2702 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | ||
2703 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | ||
2704 | break; | ||
2705 | |||
2706 | default: | ||
2707 | GNUNET_STATISTICS_update(stats, | ||
2708 | gettext_noop("# ICMPv6 packets dropped (type not allowed)"), | ||
2709 | 1, GNUNET_NO); | ||
2710 | return; | ||
2711 | } | ||
2712 | break; | 2732 | break; |
2713 | 2733 | ||
2714 | default: | 2734 | default: |
2715 | GNUNET_assert(0); | 2735 | GNUNET_STATISTICS_update (stats, |
2736 | gettext_noop ( | ||
2737 | "# ICMPv4 packets dropped (type not allowed)"), | ||
2738 | 1, GNUNET_NO); | ||
2739 | return; | ||
2716 | } | 2740 | } |
2717 | switch (protocol) | 2741 | break; |
2718 | { | ||
2719 | case IPPROTO_ICMP: | ||
2720 | state = get_redirect_state(af, | ||
2721 | IPPROTO_ICMP, | ||
2722 | source_ip, | ||
2723 | 0, | ||
2724 | destination_ip, | ||
2725 | 0, | ||
2726 | NULL); | ||
2727 | break; | ||
2728 | |||
2729 | case IPPROTO_ICMPV6: | ||
2730 | state = get_redirect_state(af, | ||
2731 | IPPROTO_ICMPV6, | ||
2732 | source_ip, | ||
2733 | 0, | ||
2734 | destination_ip, | ||
2735 | 0, | ||
2736 | NULL); | ||
2737 | break; | ||
2738 | 2742 | ||
2739 | case IPPROTO_UDP: | 2743 | case AF_INET6: |
2740 | state = get_redirect_state(af, | 2744 | protocol = IPPROTO_ICMPV6; |
2741 | IPPROTO_UDP, | 2745 | switch (icmp->type) |
2742 | source_ip, | 2746 | { |
2743 | source_port, | 2747 | case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE: |
2744 | destination_ip, | 2748 | case GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG: |
2745 | destination_port, | 2749 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: |
2746 | NULL); | 2750 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: |
2751 | if (pktlen < | ||
2752 | sizeof(struct GNUNET_TUN_IcmpHeader) | ||
2753 | + sizeof(struct GNUNET_TUN_IPv6Header) + 8) | ||
2754 | { | ||
2755 | /* blame kernel */ | ||
2756 | GNUNET_break (0); | ||
2757 | return; | ||
2758 | } | ||
2759 | ipv6 = (const struct GNUNET_TUN_IPv6Header *) &icmp[1]; | ||
2760 | protocol = ipv6->next_header; | ||
2761 | /* could be TCP or UDP, but both have the ports in the right | ||
2762 | place, so that doesn't matter here */ | ||
2763 | udp = (const struct GNUNET_TUN_UdpHeader *) &ipv6[1]; | ||
2764 | /* swap ports, as they are from the original message */ | ||
2765 | destination_port = ntohs (udp->source_port); | ||
2766 | source_port = ntohs (udp->destination_port); | ||
2767 | /* throw away ICMP payload, won't be useful for the other side anyway */ | ||
2768 | pktlen = sizeof(struct GNUNET_TUN_IcmpHeader); | ||
2747 | break; | 2769 | break; |
2748 | 2770 | ||
2749 | case IPPROTO_TCP: | 2771 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: |
2750 | state = get_redirect_state(af, | 2772 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: |
2751 | IPPROTO_TCP, | ||
2752 | source_ip, | ||
2753 | source_port, | ||
2754 | destination_ip, | ||
2755 | destination_port, | ||
2756 | NULL); | ||
2757 | break; | 2773 | break; |
2758 | 2774 | ||
2759 | default: | 2775 | default: |
2760 | GNUNET_STATISTICS_update(stats, | 2776 | GNUNET_STATISTICS_update (stats, |
2761 | gettext_noop("# ICMP packets dropped (not allowed)"), | 2777 | gettext_noop ( |
2762 | 1, | 2778 | "# ICMPv6 packets dropped (type not allowed)"), |
2763 | GNUNET_NO); | 2779 | 1, GNUNET_NO); |
2764 | return; | 2780 | return; |
2765 | } | 2781 | } |
2782 | break; | ||
2783 | |||
2784 | default: | ||
2785 | GNUNET_assert (0); | ||
2786 | } | ||
2787 | switch (protocol) | ||
2788 | { | ||
2789 | case IPPROTO_ICMP: | ||
2790 | state = get_redirect_state (af, | ||
2791 | IPPROTO_ICMP, | ||
2792 | source_ip, | ||
2793 | 0, | ||
2794 | destination_ip, | ||
2795 | 0, | ||
2796 | NULL); | ||
2797 | break; | ||
2798 | |||
2799 | case IPPROTO_ICMPV6: | ||
2800 | state = get_redirect_state (af, | ||
2801 | IPPROTO_ICMPV6, | ||
2802 | source_ip, | ||
2803 | 0, | ||
2804 | destination_ip, | ||
2805 | 0, | ||
2806 | NULL); | ||
2807 | break; | ||
2808 | |||
2809 | case IPPROTO_UDP: | ||
2810 | state = get_redirect_state (af, | ||
2811 | IPPROTO_UDP, | ||
2812 | source_ip, | ||
2813 | source_port, | ||
2814 | destination_ip, | ||
2815 | destination_port, | ||
2816 | NULL); | ||
2817 | break; | ||
2818 | |||
2819 | case IPPROTO_TCP: | ||
2820 | state = get_redirect_state (af, | ||
2821 | IPPROTO_TCP, | ||
2822 | source_ip, | ||
2823 | source_port, | ||
2824 | destination_ip, | ||
2825 | destination_port, | ||
2826 | NULL); | ||
2827 | break; | ||
2828 | |||
2829 | default: | ||
2830 | GNUNET_STATISTICS_update (stats, | ||
2831 | gettext_noop ( | ||
2832 | "# ICMP packets dropped (not allowed)"), | ||
2833 | 1, | ||
2834 | GNUNET_NO); | ||
2835 | return; | ||
2836 | } | ||
2766 | if (NULL == state) | 2837 | if (NULL == state) |
2767 | { | 2838 | { |
2768 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2839 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2769 | _("ICMP Packet dropped, have no matching connection information\n")); | 2840 | _ ( |
2770 | return; | 2841 | "ICMP Packet dropped, have no matching connection information\n")); |
2771 | } | 2842 | return; |
2772 | env = GNUNET_MQ_msg_extra(i2v, | 2843 | } |
2773 | pktlen - sizeof(struct GNUNET_TUN_IcmpHeader), | 2844 | env = GNUNET_MQ_msg_extra (i2v, |
2774 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN); | 2845 | pktlen - sizeof(struct GNUNET_TUN_IcmpHeader), |
2775 | i2v->af = htonl(af); | 2846 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN); |
2776 | GNUNET_memcpy(&i2v->icmp_header, | 2847 | i2v->af = htonl (af); |
2777 | icmp, | 2848 | GNUNET_memcpy (&i2v->icmp_header, |
2778 | pktlen); | 2849 | icmp, |
2779 | send_packet_to_cadet_channel(state, | 2850 | pktlen); |
2780 | env); | 2851 | send_packet_to_cadet_channel (state, |
2852 | env); | ||
2781 | } | 2853 | } |
2782 | 2854 | ||
2783 | 2855 | ||
@@ -2793,11 +2865,11 @@ icmp_from_helper(const struct GNUNET_TUN_IcmpHeader *icmp, | |||
2793 | * be the original destination address) | 2865 | * be the original destination address) |
2794 | */ | 2866 | */ |
2795 | static void | 2867 | static void |
2796 | udp_from_helper(const struct GNUNET_TUN_UdpHeader *udp, | 2868 | udp_from_helper (const struct GNUNET_TUN_UdpHeader *udp, |
2797 | size_t pktlen, | 2869 | size_t pktlen, |
2798 | int af, | 2870 | int af, |
2799 | const void *destination_ip, | 2871 | const void *destination_ip, |
2800 | const void *source_ip) | 2872 | const void *source_ip) |
2801 | { | 2873 | { |
2802 | struct ChannelState *state; | 2874 | struct ChannelState *state; |
2803 | struct GNUNET_MQ_Envelope *env; | 2875 | struct GNUNET_MQ_Envelope *env; |
@@ -2807,53 +2879,54 @@ udp_from_helper(const struct GNUNET_TUN_UdpHeader *udp, | |||
2807 | char sbuf[INET6_ADDRSTRLEN]; | 2879 | char sbuf[INET6_ADDRSTRLEN]; |
2808 | char dbuf[INET6_ADDRSTRLEN]; | 2880 | char dbuf[INET6_ADDRSTRLEN]; |
2809 | 2881 | ||
2810 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2882 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2811 | "Received UDP packet going from %s:%u to %s:%u\n", | 2883 | "Received UDP packet going from %s:%u to %s:%u\n", |
2812 | inet_ntop(af, | 2884 | inet_ntop (af, |
2813 | source_ip, | 2885 | source_ip, |
2814 | sbuf, sizeof(sbuf)), | 2886 | sbuf, sizeof(sbuf)), |
2815 | (unsigned int)ntohs(udp->source_port), | 2887 | (unsigned int) ntohs (udp->source_port), |
2816 | inet_ntop(af, | 2888 | inet_ntop (af, |
2817 | destination_ip, | 2889 | destination_ip, |
2818 | dbuf, sizeof(dbuf)), | 2890 | dbuf, sizeof(dbuf)), |
2819 | (unsigned int)ntohs(udp->destination_port)); | 2891 | (unsigned int) ntohs (udp->destination_port)); |
2820 | } | 2892 | } |
2821 | 2893 | ||
2822 | if (pktlen < sizeof(struct GNUNET_TUN_UdpHeader)) | 2894 | if (pktlen < sizeof(struct GNUNET_TUN_UdpHeader)) |
2823 | { | 2895 | { |
2824 | /* blame kernel */ | 2896 | /* blame kernel */ |
2825 | GNUNET_break(0); | 2897 | GNUNET_break (0); |
2826 | return; | 2898 | return; |
2827 | } | 2899 | } |
2828 | if (pktlen != ntohs(udp->len)) | 2900 | if (pktlen != ntohs (udp->len)) |
2829 | { | 2901 | { |
2830 | /* blame kernel */ | 2902 | /* blame kernel */ |
2831 | GNUNET_break(0); | 2903 | GNUNET_break (0); |
2832 | return; | 2904 | return; |
2833 | } | 2905 | } |
2834 | state = get_redirect_state(af, | 2906 | state = get_redirect_state (af, |
2835 | IPPROTO_UDP, | 2907 | IPPROTO_UDP, |
2836 | source_ip, | 2908 | source_ip, |
2837 | ntohs(udp->source_port), | 2909 | ntohs (udp->source_port), |
2838 | destination_ip, | 2910 | destination_ip, |
2839 | ntohs(udp->destination_port), | 2911 | ntohs (udp->destination_port), |
2840 | NULL); | 2912 | NULL); |
2841 | if (NULL == state) | 2913 | if (NULL == state) |
2842 | { | 2914 | { |
2843 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2915 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2844 | _("UDP Packet dropped, have no matching connection information\n")); | 2916 | _ ( |
2845 | return; | 2917 | "UDP Packet dropped, have no matching connection information\n")); |
2846 | } | 2918 | return; |
2847 | env = GNUNET_MQ_msg_extra(urm, | 2919 | } |
2848 | pktlen - sizeof(struct GNUNET_TUN_UdpHeader), | 2920 | env = GNUNET_MQ_msg_extra (urm, |
2849 | GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY); | 2921 | pktlen - sizeof(struct GNUNET_TUN_UdpHeader), |
2850 | urm->source_port = htons(0); | 2922 | GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY); |
2851 | urm->destination_port = htons(0); | 2923 | urm->source_port = htons (0); |
2852 | GNUNET_memcpy(&urm[1], | 2924 | urm->destination_port = htons (0); |
2853 | &udp[1], | 2925 | GNUNET_memcpy (&urm[1], |
2854 | pktlen - sizeof(struct GNUNET_TUN_UdpHeader)); | 2926 | &udp[1], |
2855 | send_packet_to_cadet_channel(state, | 2927 | pktlen - sizeof(struct GNUNET_TUN_UdpHeader)); |
2856 | env); | 2928 | send_packet_to_cadet_channel (state, |
2929 | env); | ||
2857 | } | 2930 | } |
2858 | 2931 | ||
2859 | 2932 | ||
@@ -2869,11 +2942,11 @@ udp_from_helper(const struct GNUNET_TUN_UdpHeader *udp, | |||
2869 | * be the original destination address) | 2942 | * be the original destination address) |
2870 | */ | 2943 | */ |
2871 | static void | 2944 | static void |
2872 | tcp_from_helper(const struct GNUNET_TUN_TcpHeader *tcp, | 2945 | tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, |
2873 | size_t pktlen, | 2946 | size_t pktlen, |
2874 | int af, | 2947 | int af, |
2875 | const void *destination_ip, | 2948 | const void *destination_ip, |
2876 | const void *source_ip) | 2949 | const void *source_ip) |
2877 | { | 2950 | { |
2878 | struct ChannelState *state; | 2951 | struct ChannelState *state; |
2879 | char buf[pktlen] GNUNET_ALIGN; | 2952 | char buf[pktlen] GNUNET_ALIGN; |
@@ -2885,62 +2958,64 @@ tcp_from_helper(const struct GNUNET_TUN_TcpHeader *tcp, | |||
2885 | { | 2958 | { |
2886 | char sbuf[INET6_ADDRSTRLEN]; | 2959 | char sbuf[INET6_ADDRSTRLEN]; |
2887 | char dbuf[INET6_ADDRSTRLEN]; | 2960 | char dbuf[INET6_ADDRSTRLEN]; |
2888 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2889 | "Received TCP packet with %u bytes going from %s:%u to %s:%u\n", | 2962 | "Received TCP packet with %u bytes going from %s:%u to %s:%u\n", |
2890 | (unsigned int)(pktlen - sizeof(struct GNUNET_TUN_TcpHeader)), | 2963 | (unsigned int) (pktlen - sizeof(struct GNUNET_TUN_TcpHeader)), |
2891 | inet_ntop(af, | 2964 | inet_ntop (af, |
2892 | source_ip, | 2965 | source_ip, |
2893 | sbuf, sizeof(sbuf)), | 2966 | sbuf, sizeof(sbuf)), |
2894 | (unsigned int)ntohs(tcp->source_port), | 2967 | (unsigned int) ntohs (tcp->source_port), |
2895 | inet_ntop(af, | 2968 | inet_ntop (af, |
2896 | destination_ip, | 2969 | destination_ip, |
2897 | dbuf, sizeof(dbuf)), | 2970 | dbuf, sizeof(dbuf)), |
2898 | (unsigned int)ntohs(tcp->destination_port)); | 2971 | (unsigned int) ntohs (tcp->destination_port)); |
2899 | } | 2972 | } |
2900 | 2973 | ||
2901 | if (pktlen < sizeof(struct GNUNET_TUN_TcpHeader)) | 2974 | if (pktlen < sizeof(struct GNUNET_TUN_TcpHeader)) |
2902 | { | 2975 | { |
2903 | /* blame kernel */ | 2976 | /* blame kernel */ |
2904 | GNUNET_break(0); | 2977 | GNUNET_break (0); |
2905 | return; | 2978 | return; |
2906 | } | 2979 | } |
2907 | state = get_redirect_state(af, | 2980 | state = get_redirect_state (af, |
2908 | IPPROTO_TCP, | 2981 | IPPROTO_TCP, |
2909 | source_ip, | 2982 | source_ip, |
2910 | ntohs(tcp->source_port), | 2983 | ntohs (tcp->source_port), |
2911 | destination_ip, | 2984 | destination_ip, |
2912 | ntohs(tcp->destination_port), | 2985 | ntohs (tcp->destination_port), |
2913 | NULL); | 2986 | NULL); |
2914 | if (NULL == state) | 2987 | if (NULL == state) |
2915 | { | 2988 | { |
2916 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2989 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2917 | _("TCP Packet dropped, have no matching connection information\n")); | 2990 | _ ( |
2991 | "TCP Packet dropped, have no matching connection information\n")); | ||
2918 | 2992 | ||
2919 | return; | 2993 | return; |
2920 | } | 2994 | } |
2921 | /* mug port numbers and crc to avoid information leakage; | 2995 | /* mug port numbers and crc to avoid information leakage; |
2922 | sender will need to lookup the correct values anyway */ | 2996 | sender will need to lookup the correct values anyway */ |
2923 | GNUNET_memcpy(buf, tcp, pktlen); | 2997 | GNUNET_memcpy (buf, tcp, pktlen); |
2924 | mtcp = (struct GNUNET_TUN_TcpHeader *)buf; | 2998 | mtcp = (struct GNUNET_TUN_TcpHeader *) buf; |
2925 | mtcp->source_port = 0; | 2999 | mtcp->source_port = 0; |
2926 | mtcp->destination_port = 0; | 3000 | mtcp->destination_port = 0; |
2927 | mtcp->crc = 0; | 3001 | mtcp->crc = 0; |
2928 | 3002 | ||
2929 | mlen = sizeof(struct GNUNET_EXIT_TcpDataMessage) + (pktlen - sizeof(struct GNUNET_TUN_TcpHeader)); | 3003 | mlen = sizeof(struct GNUNET_EXIT_TcpDataMessage) + (pktlen - sizeof(struct |
3004 | GNUNET_TUN_TcpHeader)); | ||
2930 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) | 3005 | if (mlen >= GNUNET_MAX_MESSAGE_SIZE) |
2931 | { | 3006 | { |
2932 | GNUNET_break(0); | 3007 | GNUNET_break (0); |
2933 | return; | 3008 | return; |
2934 | } | 3009 | } |
2935 | env = GNUNET_MQ_msg_extra(tdm, | 3010 | env = GNUNET_MQ_msg_extra (tdm, |
2936 | pktlen - sizeof(struct GNUNET_TUN_TcpHeader), | 3011 | pktlen - sizeof(struct GNUNET_TUN_TcpHeader), |
2937 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN); | 3012 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN); |
2938 | tdm->reserved = htonl(0); | 3013 | tdm->reserved = htonl (0); |
2939 | GNUNET_memcpy(&tdm->tcp_header, | 3014 | GNUNET_memcpy (&tdm->tcp_header, |
2940 | buf, | 3015 | buf, |
2941 | pktlen); | 3016 | pktlen); |
2942 | send_packet_to_cadet_channel(state, | 3017 | send_packet_to_cadet_channel (state, |
2943 | env); | 3018 | env); |
2944 | } | 3019 | } |
2945 | 3020 | ||
2946 | 3021 | ||
@@ -2951,150 +3026,155 @@ tcp_from_helper(const struct GNUNET_TUN_TcpHeader *tcp, | |||
2951 | * @param message message received from helper | 3026 | * @param message message received from helper |
2952 | */ | 3027 | */ |
2953 | static int | 3028 | static int |
2954 | message_token(void *cls GNUNET_UNUSED, | 3029 | message_token (void *cls GNUNET_UNUSED, |
2955 | const struct GNUNET_MessageHeader *message) | 3030 | const struct GNUNET_MessageHeader *message) |
2956 | { | 3031 | { |
2957 | const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun; | 3032 | const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun; |
2958 | size_t size; | 3033 | size_t size; |
2959 | 3034 | ||
2960 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2961 | "Got %u-byte message of type %u from gnunet-helper-exit\n", | 3036 | "Got %u-byte message of type %u from gnunet-helper-exit\n", |
2962 | ntohs(message->size), | 3037 | ntohs (message->size), |
2963 | ntohs(message->type)); | 3038 | ntohs (message->type)); |
2964 | GNUNET_STATISTICS_update(stats, | 3039 | GNUNET_STATISTICS_update (stats, |
2965 | gettext_noop("# Packets received from TUN"), | 3040 | gettext_noop ("# Packets received from TUN"), |
2966 | 1, GNUNET_NO); | 3041 | 1, GNUNET_NO); |
2967 | if (ntohs(message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) | 3042 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) |
2968 | { | 3043 | { |
2969 | GNUNET_break(0); | 3044 | GNUNET_break (0); |
2970 | return GNUNET_OK; | 3045 | return GNUNET_OK; |
2971 | } | 3046 | } |
2972 | size = ntohs(message->size); | 3047 | size = ntohs (message->size); |
2973 | if (size < sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct GNUNET_MessageHeader)) | 3048 | if (size < sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct |
2974 | { | 3049 | GNUNET_MessageHeader)) |
2975 | GNUNET_break(0); | 3050 | { |
2976 | return GNUNET_OK; | 3051 | GNUNET_break (0); |
2977 | } | 3052 | return GNUNET_OK; |
2978 | GNUNET_STATISTICS_update(stats, | 3053 | } |
2979 | gettext_noop("# Bytes received from TUN"), | 3054 | GNUNET_STATISTICS_update (stats, |
2980 | size, GNUNET_NO); | 3055 | gettext_noop ("# Bytes received from TUN"), |
2981 | pkt_tun = (const struct GNUNET_TUN_Layer2PacketHeader *)&message[1]; | 3056 | size, GNUNET_NO); |
2982 | size -= sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct GNUNET_MessageHeader); | 3057 | pkt_tun = (const struct GNUNET_TUN_Layer2PacketHeader *) &message[1]; |
2983 | switch (ntohs(pkt_tun->proto)) | 3058 | size -= sizeof(struct GNUNET_TUN_Layer2PacketHeader) + sizeof(struct |
2984 | { | 3059 | GNUNET_MessageHeader); |
2985 | case ETH_P_IPV4: | 3060 | switch (ntohs (pkt_tun->proto)) |
3061 | { | ||
3062 | case ETH_P_IPV4: | ||
2986 | { | 3063 | { |
2987 | const struct GNUNET_TUN_IPv4Header *pkt4; | 3064 | const struct GNUNET_TUN_IPv4Header *pkt4; |
2988 | 3065 | ||
2989 | if (size < sizeof(struct GNUNET_TUN_IPv4Header)) | 3066 | if (size < sizeof(struct GNUNET_TUN_IPv4Header)) |
2990 | { | 3067 | { |
2991 | /* Kernel to blame? */ | 3068 | /* Kernel to blame? */ |
2992 | GNUNET_break(0); | 3069 | GNUNET_break (0); |
2993 | return GNUNET_OK; | 3070 | return GNUNET_OK; |
2994 | } | 3071 | } |
2995 | pkt4 = (const struct GNUNET_TUN_IPv4Header *)&pkt_tun[1]; | 3072 | pkt4 = (const struct GNUNET_TUN_IPv4Header *) &pkt_tun[1]; |
2996 | if (size != ntohs(pkt4->total_length)) | 3073 | if (size != ntohs (pkt4->total_length)) |
2997 | { | 3074 | { |
2998 | /* Kernel to blame? */ | 3075 | /* Kernel to blame? */ |
2999 | GNUNET_break(0); | 3076 | GNUNET_break (0); |
3000 | return GNUNET_OK; | 3077 | return GNUNET_OK; |
3001 | } | 3078 | } |
3002 | if (pkt4->header_length * 4 != sizeof(struct GNUNET_TUN_IPv4Header)) | 3079 | if (pkt4->header_length * 4 != sizeof(struct GNUNET_TUN_IPv4Header)) |
3003 | { | 3080 | { |
3004 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3081 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3005 | _("IPv4 packet options received. Ignored.\n")); | 3082 | _ ("IPv4 packet options received. Ignored.\n")); |
3006 | return GNUNET_OK; | 3083 | return GNUNET_OK; |
3007 | } | 3084 | } |
3008 | 3085 | ||
3009 | size -= sizeof(struct GNUNET_TUN_IPv4Header); | 3086 | size -= sizeof(struct GNUNET_TUN_IPv4Header); |
3010 | switch (pkt4->protocol) | 3087 | switch (pkt4->protocol) |
3011 | { | 3088 | { |
3012 | case IPPROTO_UDP: | 3089 | case IPPROTO_UDP: |
3013 | udp_from_helper((const struct GNUNET_TUN_UdpHeader *)&pkt4[1], size, | 3090 | udp_from_helper ((const struct GNUNET_TUN_UdpHeader *) &pkt4[1], size, |
3014 | AF_INET, | 3091 | AF_INET, |
3015 | &pkt4->destination_address, | 3092 | &pkt4->destination_address, |
3016 | &pkt4->source_address); | 3093 | &pkt4->source_address); |
3017 | break; | 3094 | break; |
3018 | 3095 | ||
3019 | case IPPROTO_TCP: | 3096 | case IPPROTO_TCP: |
3020 | tcp_from_helper((const struct GNUNET_TUN_TcpHeader *)&pkt4[1], size, | 3097 | tcp_from_helper ((const struct GNUNET_TUN_TcpHeader *) &pkt4[1], size, |
3098 | AF_INET, | ||
3099 | &pkt4->destination_address, | ||
3100 | &pkt4->source_address); | ||
3101 | break; | ||
3102 | |||
3103 | case IPPROTO_ICMP: | ||
3104 | icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt4[1], size, | ||
3021 | AF_INET, | 3105 | AF_INET, |
3022 | &pkt4->destination_address, | 3106 | &pkt4->destination_address, |
3023 | &pkt4->source_address); | 3107 | &pkt4->source_address); |
3024 | break; | 3108 | break; |
3025 | 3109 | ||
3026 | case IPPROTO_ICMP: | 3110 | default: |
3027 | icmp_from_helper((const struct GNUNET_TUN_IcmpHeader *)&pkt4[1], size, | 3111 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3028 | AF_INET, | 3112 | _ ( |
3029 | &pkt4->destination_address, | 3113 | "IPv4 packet with unsupported next header %u received. Ignored.\n"), |
3030 | &pkt4->source_address); | 3114 | (int) pkt4->protocol); |
3031 | break; | 3115 | return GNUNET_OK; |
3032 | 3116 | } | |
3033 | default: | ||
3034 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
3035 | _("IPv4 packet with unsupported next header %u received. Ignored.\n"), | ||
3036 | (int)pkt4->protocol); | ||
3037 | return GNUNET_OK; | ||
3038 | } | ||
3039 | } | 3117 | } |
3040 | break; | 3118 | break; |
3041 | 3119 | ||
3042 | case ETH_P_IPV6: | 3120 | case ETH_P_IPV6: |
3043 | { | 3121 | { |
3044 | const struct GNUNET_TUN_IPv6Header *pkt6; | 3122 | const struct GNUNET_TUN_IPv6Header *pkt6; |
3045 | 3123 | ||
3046 | if (size < sizeof(struct GNUNET_TUN_IPv6Header)) | 3124 | if (size < sizeof(struct GNUNET_TUN_IPv6Header)) |
3047 | { | 3125 | { |
3048 | /* Kernel to blame? */ | 3126 | /* Kernel to blame? */ |
3049 | GNUNET_break(0); | 3127 | GNUNET_break (0); |
3050 | return GNUNET_OK; | 3128 | return GNUNET_OK; |
3051 | } | 3129 | } |
3052 | pkt6 = (struct GNUNET_TUN_IPv6Header *)&pkt_tun[1]; | 3130 | pkt6 = (struct GNUNET_TUN_IPv6Header *) &pkt_tun[1]; |
3053 | if (size != ntohs(pkt6->payload_length) + sizeof(struct GNUNET_TUN_IPv6Header)) | 3131 | if (size != ntohs (pkt6->payload_length) + sizeof(struct |
3054 | { | 3132 | GNUNET_TUN_IPv6Header)) |
3055 | /* Kernel to blame? */ | 3133 | { |
3056 | GNUNET_break(0); | 3134 | /* Kernel to blame? */ |
3057 | return GNUNET_OK; | 3135 | GNUNET_break (0); |
3058 | } | 3136 | return GNUNET_OK; |
3137 | } | ||
3059 | size -= sizeof(struct GNUNET_TUN_IPv6Header); | 3138 | size -= sizeof(struct GNUNET_TUN_IPv6Header); |
3060 | switch (pkt6->next_header) | 3139 | switch (pkt6->next_header) |
3061 | { | 3140 | { |
3062 | case IPPROTO_UDP: | 3141 | case IPPROTO_UDP: |
3063 | udp_from_helper((const struct GNUNET_TUN_UdpHeader *)&pkt6[1], size, | 3142 | udp_from_helper ((const struct GNUNET_TUN_UdpHeader *) &pkt6[1], size, |
3064 | AF_INET6, | 3143 | AF_INET6, |
3065 | &pkt6->destination_address, | 3144 | &pkt6->destination_address, |
3066 | &pkt6->source_address); | 3145 | &pkt6->source_address); |
3067 | break; | 3146 | break; |
3147 | |||
3148 | case IPPROTO_TCP: | ||
3149 | tcp_from_helper ((const struct GNUNET_TUN_TcpHeader *) &pkt6[1], size, | ||
3150 | AF_INET6, | ||
3151 | &pkt6->destination_address, | ||
3152 | &pkt6->source_address); | ||
3153 | break; | ||
3068 | 3154 | ||
3069 | case IPPROTO_TCP: | 3155 | case IPPROTO_ICMPV6: |
3070 | tcp_from_helper((const struct GNUNET_TUN_TcpHeader *)&pkt6[1], size, | 3156 | icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt6[1], size, |
3071 | AF_INET6, | 3157 | AF_INET6, |
3072 | &pkt6->destination_address, | 3158 | &pkt6->destination_address, |
3073 | &pkt6->source_address); | 3159 | &pkt6->source_address); |
3074 | break; | 3160 | break; |
3075 | 3161 | ||
3076 | case IPPROTO_ICMPV6: | 3162 | default: |
3077 | icmp_from_helper((const struct GNUNET_TUN_IcmpHeader *)&pkt6[1], size, | 3163 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3078 | AF_INET6, | 3164 | _ ( |
3079 | &pkt6->destination_address, | 3165 | "IPv6 packet with unsupported next header %d received. Ignored.\n"), |
3080 | &pkt6->source_address); | 3166 | pkt6->next_header); |
3081 | break; | 3167 | return GNUNET_OK; |
3082 | 3168 | } | |
3083 | default: | ||
3084 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
3085 | _("IPv6 packet with unsupported next header %d received. Ignored.\n"), | ||
3086 | pkt6->next_header); | ||
3087 | return GNUNET_OK; | ||
3088 | } | ||
3089 | } | 3169 | } |
3090 | break; | 3170 | break; |
3091 | 3171 | ||
3092 | default: | 3172 | default: |
3093 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3173 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3094 | _("Packet from unknown protocol %u received. Ignored.\n"), | 3174 | _ ("Packet from unknown protocol %u received. Ignored.\n"), |
3095 | ntohs(pkt_tun->proto)); | 3175 | ntohs (pkt_tun->proto)); |
3096 | break; | 3176 | break; |
3097 | } | 3177 | } |
3098 | return GNUNET_OK; | 3178 | return GNUNET_OK; |
3099 | } | 3179 | } |
3100 | 3180 | ||
@@ -3108,21 +3188,21 @@ message_token(void *cls GNUNET_UNUSED, | |||
3108 | * @return initial channel context for the channel | 3188 | * @return initial channel context for the channel |
3109 | */ | 3189 | */ |
3110 | static void * | 3190 | static void * |
3111 | new_channel(void *cls, | 3191 | new_channel (void *cls, |
3112 | struct GNUNET_CADET_Channel *channel, | 3192 | struct GNUNET_CADET_Channel *channel, |
3113 | const struct GNUNET_PeerIdentity *initiator) | 3193 | const struct GNUNET_PeerIdentity *initiator) |
3114 | { | 3194 | { |
3115 | struct ChannelState *s = GNUNET_new(struct ChannelState); | 3195 | struct ChannelState *s = GNUNET_new (struct ChannelState); |
3116 | 3196 | ||
3117 | s->is_dns = GNUNET_SYSERR; | 3197 | s->is_dns = GNUNET_SYSERR; |
3118 | s->peer = *initiator; | 3198 | s->peer = *initiator; |
3119 | GNUNET_STATISTICS_update(stats, | 3199 | GNUNET_STATISTICS_update (stats, |
3120 | gettext_noop("# Inbound CADET channels created"), | 3200 | gettext_noop ("# Inbound CADET channels created"), |
3121 | 1, | 3201 | 1, |
3122 | GNUNET_NO); | 3202 | GNUNET_NO); |
3123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3124 | "Received inbound channel from `%s'\n", | 3204 | "Received inbound channel from `%s'\n", |
3125 | GNUNET_i2s(initiator)); | 3205 | GNUNET_i2s (initiator)); |
3126 | s->channel = channel; | 3206 | s->channel = channel; |
3127 | return s; | 3207 | return s; |
3128 | } | 3208 | } |
@@ -3136,11 +3216,11 @@ new_channel(void *cls, | |||
3136 | * @param value value to free | 3216 | * @param value value to free |
3137 | */ | 3217 | */ |
3138 | static int | 3218 | static int |
3139 | free_iterate(void *cls, | 3219 | free_iterate (void *cls, |
3140 | const struct GNUNET_HashCode * hash, | 3220 | const struct GNUNET_HashCode *hash, |
3141 | void *value) | 3221 | void *value) |
3142 | { | 3222 | { |
3143 | GNUNET_free(value); | 3223 | GNUNET_free (value); |
3144 | return GNUNET_YES; | 3224 | return GNUNET_YES; |
3145 | } | 3225 | } |
3146 | 3226 | ||
@@ -3155,7 +3235,7 @@ free_iterate(void *cls, | |||
3155 | * @param tc scheduler context | 3235 | * @param tc scheduler context |
3156 | */ | 3236 | */ |
3157 | static void | 3237 | static void |
3158 | dummy_task(void *cls) | 3238 | dummy_task (void *cls) |
3159 | { | 3239 | { |
3160 | /* just terminate */ | 3240 | /* just terminate */ |
3161 | } | 3241 | } |
@@ -3167,101 +3247,101 @@ dummy_task(void *cls) | |||
3167 | * @param cls NULL | 3247 | * @param cls NULL |
3168 | */ | 3248 | */ |
3169 | static void | 3249 | static void |
3170 | cleanup(void *cls) | 3250 | cleanup (void *cls) |
3171 | { | 3251 | { |
3172 | unsigned int i; | 3252 | unsigned int i; |
3173 | 3253 | ||
3174 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3175 | "Exit service is shutting down now\n"); | 3255 | "Exit service is shutting down now\n"); |
3176 | 3256 | ||
3177 | if (NULL != helper_handle) | 3257 | if (NULL != helper_handle) |
3178 | { | 3258 | { |
3179 | GNUNET_HELPER_stop(helper_handle, GNUNET_NO); | 3259 | GNUNET_HELPER_stop (helper_handle, GNUNET_NO); |
3180 | helper_handle = NULL; | 3260 | helper_handle = NULL; |
3181 | } | 3261 | } |
3182 | if (NULL != regex4) | 3262 | if (NULL != regex4) |
3183 | { | 3263 | { |
3184 | GNUNET_REGEX_announce_cancel(regex4); | 3264 | GNUNET_REGEX_announce_cancel (regex4); |
3185 | regex4 = NULL; | 3265 | regex4 = NULL; |
3186 | } | 3266 | } |
3187 | if (NULL != regex6) | 3267 | if (NULL != regex6) |
3188 | { | 3268 | { |
3189 | GNUNET_REGEX_announce_cancel(regex6); | 3269 | GNUNET_REGEX_announce_cancel (regex6); |
3190 | regex6 = NULL; | 3270 | regex6 = NULL; |
3191 | } | 3271 | } |
3192 | if (NULL != services) | 3272 | if (NULL != services) |
3193 | { | 3273 | { |
3194 | GNUNET_CONTAINER_multihashmap_iterate(services, | 3274 | GNUNET_CONTAINER_multihashmap_iterate (services, |
3195 | &free_service_record, | 3275 | &free_service_record, |
3196 | NULL); | 3276 | NULL); |
3197 | GNUNET_CONTAINER_multihashmap_destroy(services); | 3277 | GNUNET_CONTAINER_multihashmap_destroy (services); |
3198 | } | 3278 | } |
3199 | if (NULL != dns_port) | 3279 | if (NULL != dns_port) |
3200 | { | 3280 | { |
3201 | GNUNET_CADET_close_port(dns_port); | 3281 | GNUNET_CADET_close_port (dns_port); |
3202 | dns_port = NULL; | 3282 | dns_port = NULL; |
3203 | } | 3283 | } |
3204 | if (NULL != cadet_port4) | 3284 | if (NULL != cadet_port4) |
3205 | { | 3285 | { |
3206 | GNUNET_CADET_close_port(cadet_port4); | 3286 | GNUNET_CADET_close_port (cadet_port4); |
3207 | cadet_port4 = NULL; | 3287 | cadet_port4 = NULL; |
3208 | } | 3288 | } |
3209 | if (NULL != cadet_port6) | 3289 | if (NULL != cadet_port6) |
3210 | { | 3290 | { |
3211 | GNUNET_CADET_close_port(cadet_port6); | 3291 | GNUNET_CADET_close_port (cadet_port6); |
3212 | cadet_port6 = NULL; | 3292 | cadet_port6 = NULL; |
3213 | } | 3293 | } |
3214 | if (NULL != cadet_handle) | 3294 | if (NULL != cadet_handle) |
3215 | { | 3295 | { |
3216 | GNUNET_CADET_disconnect(cadet_handle); | 3296 | GNUNET_CADET_disconnect (cadet_handle); |
3217 | cadet_handle = NULL; | 3297 | cadet_handle = NULL; |
3218 | } | 3298 | } |
3219 | if (NULL != connections_map) | 3299 | if (NULL != connections_map) |
3220 | { | 3300 | { |
3221 | GNUNET_CONTAINER_multihashmap_iterate(connections_map, | 3301 | GNUNET_CONTAINER_multihashmap_iterate (connections_map, |
3222 | &free_iterate, | 3302 | &free_iterate, |
3223 | NULL); | 3303 | NULL); |
3224 | GNUNET_CONTAINER_multihashmap_destroy(connections_map); | 3304 | GNUNET_CONTAINER_multihashmap_destroy (connections_map); |
3225 | connections_map = NULL; | 3305 | connections_map = NULL; |
3226 | } | 3306 | } |
3227 | if (NULL != connections_heap) | 3307 | if (NULL != connections_heap) |
3228 | { | 3308 | { |
3229 | GNUNET_CONTAINER_heap_destroy(connections_heap); | 3309 | GNUNET_CONTAINER_heap_destroy (connections_heap); |
3230 | connections_heap = NULL; | 3310 | connections_heap = NULL; |
3231 | } | 3311 | } |
3232 | if (NULL != dnsstub) | 3312 | if (NULL != dnsstub) |
3233 | { | 3313 | { |
3234 | GNUNET_DNSSTUB_stop(dnsstub); | 3314 | GNUNET_DNSSTUB_stop (dnsstub); |
3235 | dnsstub = NULL; | 3315 | dnsstub = NULL; |
3236 | } | 3316 | } |
3237 | if (NULL != peer_key) | 3317 | if (NULL != peer_key) |
3238 | { | 3318 | { |
3239 | GNUNET_free(peer_key); | 3319 | GNUNET_free (peer_key); |
3240 | peer_key = NULL; | 3320 | peer_key = NULL; |
3241 | } | 3321 | } |
3242 | if (NULL != dht_task) | 3322 | if (NULL != dht_task) |
3243 | { | 3323 | { |
3244 | GNUNET_SCHEDULER_cancel(dht_task); | 3324 | GNUNET_SCHEDULER_cancel (dht_task); |
3245 | dht_task = NULL; | 3325 | dht_task = NULL; |
3246 | } | 3326 | } |
3247 | if (NULL != dht_put) | 3327 | if (NULL != dht_put) |
3248 | { | 3328 | { |
3249 | GNUNET_DHT_put_cancel(dht_put); | 3329 | GNUNET_DHT_put_cancel (dht_put); |
3250 | dht_put = NULL; | 3330 | dht_put = NULL; |
3251 | } | 3331 | } |
3252 | if (NULL != dht) | 3332 | if (NULL != dht) |
3253 | { | 3333 | { |
3254 | GNUNET_DHT_disconnect(dht); | 3334 | GNUNET_DHT_disconnect (dht); |
3255 | dht = NULL; | 3335 | dht = NULL; |
3256 | } | 3336 | } |
3257 | if (NULL != stats) | 3337 | if (NULL != stats) |
3258 | { | 3338 | { |
3259 | GNUNET_STATISTICS_destroy(stats, | 3339 | GNUNET_STATISTICS_destroy (stats, |
3260 | GNUNET_NO); | 3340 | GNUNET_NO); |
3261 | stats = NULL; | 3341 | stats = NULL; |
3262 | } | 3342 | } |
3263 | for (i = 0; i < 8; i++) | 3343 | for (i = 0; i < 8; i++) |
3264 | GNUNET_free_non_null(exit_argv[i]); | 3344 | GNUNET_free_non_null (exit_argv[i]); |
3265 | } | 3345 | } |
3266 | 3346 | ||
3267 | 3347 | ||
@@ -3273,9 +3353,9 @@ cleanup(void *cls) | |||
3273 | * @param name DNS name of the service | 3353 | * @param name DNS name of the service |
3274 | */ | 3354 | */ |
3275 | static void | 3355 | static void |
3276 | add_services(int proto, | 3356 | add_services (int proto, |
3277 | char *cpy, | 3357 | char *cpy, |
3278 | const char *name) | 3358 | const char *name) |
3279 | { | 3359 | { |
3280 | char *redirect; | 3360 | char *redirect; |
3281 | char *hostname; | 3361 | char *hostname; |
@@ -3284,144 +3364,150 @@ add_services(int proto, | |||
3284 | char *n; | 3364 | char *n; |
3285 | size_t slen; | 3365 | size_t slen; |
3286 | 3366 | ||
3287 | slen = strlen(name); | 3367 | slen = strlen (name); |
3288 | GNUNET_assert(slen >= 8); | 3368 | GNUNET_assert (slen >= 8); |
3289 | n = GNUNET_strndup(name, slen - 8 /* remove .gnunet. */); | 3369 | n = GNUNET_strndup (name, slen - 8 /* remove .gnunet. */); |
3290 | 3370 | ||
3291 | for (redirect = strtok(cpy, " ;"); redirect != NULL; | 3371 | for (redirect = strtok (cpy, " ;"); redirect != NULL; |
3292 | redirect = strtok(NULL, " ;")) | 3372 | redirect = strtok (NULL, " ;")) |
3373 | { | ||
3374 | if (NULL == (hostname = strstr (redirect, ":"))) | ||
3293 | { | 3375 | { |
3294 | if (NULL == (hostname = strstr(redirect, ":"))) | 3376 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3295 | { | 3377 | _ ( |
3296 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3378 | "Option `%s' for domain `%s' is not formatted correctly!\n"), |
3297 | _("Option `%s' for domain `%s' is not formatted correctly!\n"), | 3379 | redirect, |
3298 | redirect, | 3380 | name); |
3299 | name); | 3381 | continue; |
3300 | continue; | 3382 | } |
3301 | } | 3383 | hostname[0] = '\0'; |
3302 | hostname[0] = '\0'; | 3384 | hostname++; |
3303 | hostname++; | 3385 | if (NULL == (hostport = strstr (hostname, ":"))) |
3304 | if (NULL == (hostport = strstr(hostname, ":"))) | 3386 | { |
3305 | { | 3387 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3306 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3388 | _ ( |
3307 | _("Option `%s' for domain `%s' is not formatted correctly!\n"), | 3389 | "Option `%s' for domain `%s' is not formatted correctly!\n"), |
3308 | redirect, | 3390 | redirect, |
3309 | name); | 3391 | name); |
3310 | continue; | 3392 | continue; |
3311 | } | 3393 | } |
3312 | hostport[0] = '\0'; | 3394 | hostport[0] = '\0'; |
3313 | hostport++; | 3395 | hostport++; |
3314 | 3396 | ||
3315 | int local_port = atoi(redirect); | 3397 | int local_port = atoi (redirect); |
3316 | int remote_port = atoi(hostport); | 3398 | int remote_port = atoi (hostport); |
3317 | 3399 | ||
3318 | if (!((local_port > 0) && (local_port < 65536))) | 3400 | if (! ((local_port > 0) && (local_port < 65536))) |
3319 | { | 3401 | { |
3320 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3402 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3321 | _("`%s' is not a valid port number (for domain `%s')!"), | 3403 | _ ("`%s' is not a valid port number (for domain `%s')!"), |
3322 | redirect, | 3404 | redirect, |
3323 | name); | 3405 | name); |
3324 | continue; | 3406 | continue; |
3325 | } | 3407 | } |
3326 | if (!((remote_port > 0) && (remote_port < 65536))) | 3408 | if (! ((remote_port > 0) && (remote_port < 65536))) |
3409 | { | ||
3410 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3411 | _ ("`%s' is not a valid port number (for domain `%s')!"), | ||
3412 | hostport, | ||
3413 | name); | ||
3414 | continue; | ||
3415 | } | ||
3416 | |||
3417 | serv = GNUNET_new (struct LocalService); | ||
3418 | serv->address.proto = proto; | ||
3419 | serv->address.port = remote_port; | ||
3420 | if (0 == strcmp ("localhost4", | ||
3421 | hostname)) | ||
3422 | { | ||
3423 | const char *ip4addr = exit_argv[5]; | ||
3424 | |||
3425 | serv->address.af = AF_INET; | ||
3426 | GNUNET_assert (1 == inet_pton (AF_INET, | ||
3427 | ip4addr, | ||
3428 | &serv->address.address.ipv4)); | ||
3429 | } | ||
3430 | else if (0 == strcmp ("localhost6", | ||
3431 | hostname)) | ||
3432 | { | ||
3433 | const char *ip6addr = exit_argv[3]; | ||
3434 | |||
3435 | serv->address.af = AF_INET6; | ||
3436 | GNUNET_assert (1 == inet_pton (AF_INET6, | ||
3437 | ip6addr, | ||
3438 | &serv->address.address.ipv6)); | ||
3439 | } | ||
3440 | else | ||
3441 | { | ||
3442 | struct addrinfo *res; | ||
3443 | int ret; | ||
3444 | |||
3445 | ret = getaddrinfo (hostname, | ||
3446 | NULL, | ||
3447 | NULL, | ||
3448 | &res); | ||
3449 | if ((0 != ret) || (NULL == res)) | ||
3450 | { | ||
3451 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
3452 | _ ( | ||
3453 | "No addresses found for hostname `%s' of service `%s'!\n"), | ||
3454 | hostname, | ||
3455 | n); | ||
3456 | GNUNET_free (serv); | ||
3457 | continue; | ||
3458 | } | ||
3459 | |||
3460 | serv->address.af = res->ai_family; | ||
3461 | switch (res->ai_family) | ||
3462 | { | ||
3463 | case AF_INET: | ||
3464 | if (! ipv4_enabled) | ||
3327 | { | 3465 | { |
3328 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3466 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3329 | _("`%s' is not a valid port number (for domain `%s')!"), | 3467 | _ ( |
3330 | hostport, | 3468 | "Service `%s' configured for IPv4, but IPv4 is disabled!\n"), |
3331 | name); | 3469 | n); |
3470 | freeaddrinfo (res); | ||
3471 | GNUNET_free (serv); | ||
3332 | continue; | 3472 | continue; |
3333 | } | 3473 | } |
3474 | serv->address.address.ipv4 | ||
3475 | = ((struct sockaddr_in *) res->ai_addr)->sin_addr; | ||
3476 | break; | ||
3334 | 3477 | ||
3335 | serv = GNUNET_new(struct LocalService); | 3478 | case AF_INET6: |
3336 | serv->address.proto = proto; | 3479 | if (! ipv6_enabled) |
3337 | serv->address.port = remote_port; | ||
3338 | if (0 == strcmp("localhost4", | ||
3339 | hostname)) | ||
3340 | { | 3480 | { |
3341 | const char *ip4addr = exit_argv[5]; | 3481 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3342 | 3482 | _ ( | |
3343 | serv->address.af = AF_INET; | 3483 | "Service `%s' configured for IPv4, but IPv4 is disabled!\n"), |
3344 | GNUNET_assert(1 == inet_pton(AF_INET, | 3484 | n); |
3345 | ip4addr, | 3485 | freeaddrinfo (res); |
3346 | &serv->address.address.ipv4)); | 3486 | GNUNET_free (serv); |
3487 | continue; | ||
3347 | } | 3488 | } |
3348 | else if (0 == strcmp("localhost6", | 3489 | serv->address.address.ipv6 |
3349 | hostname)) | 3490 | = ((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; |
3350 | { | 3491 | break; |
3351 | const char *ip6addr = exit_argv[3]; | ||
3352 | 3492 | ||
3353 | serv->address.af = AF_INET6; | 3493 | default: |
3354 | GNUNET_assert(1 == inet_pton(AF_INET6, | 3494 | freeaddrinfo (res); |
3355 | ip6addr, | 3495 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3356 | &serv->address.address.ipv6)); | 3496 | _ ( |
3357 | } | 3497 | "No IP addresses found for hostname `%s' of service `%s'!\n"), |
3358 | else | 3498 | hostname, |
3359 | { | 3499 | n); |
3360 | struct addrinfo *res; | 3500 | GNUNET_free (serv); |
3361 | int ret; | 3501 | continue; |
3362 | 3502 | } | |
3363 | ret = getaddrinfo(hostname, | 3503 | freeaddrinfo (res); |
3364 | NULL, | ||
3365 | NULL, | ||
3366 | &res); | ||
3367 | if ((0 != ret) || (NULL == res)) | ||
3368 | { | ||
3369 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
3370 | _("No addresses found for hostname `%s' of service `%s'!\n"), | ||
3371 | hostname, | ||
3372 | n); | ||
3373 | GNUNET_free(serv); | ||
3374 | continue; | ||
3375 | } | ||
3376 | |||
3377 | serv->address.af = res->ai_family; | ||
3378 | switch (res->ai_family) | ||
3379 | { | ||
3380 | case AF_INET: | ||
3381 | if (!ipv4_enabled) | ||
3382 | { | ||
3383 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
3384 | _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"), | ||
3385 | n); | ||
3386 | freeaddrinfo(res); | ||
3387 | GNUNET_free(serv); | ||
3388 | continue; | ||
3389 | } | ||
3390 | serv->address.address.ipv4 | ||
3391 | = ((struct sockaddr_in *)res->ai_addr)->sin_addr; | ||
3392 | break; | ||
3393 | |||
3394 | case AF_INET6: | ||
3395 | if (!ipv6_enabled) | ||
3396 | { | ||
3397 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
3398 | _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"), | ||
3399 | n); | ||
3400 | freeaddrinfo(res); | ||
3401 | GNUNET_free(serv); | ||
3402 | continue; | ||
3403 | } | ||
3404 | serv->address.address.ipv6 | ||
3405 | = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; | ||
3406 | break; | ||
3407 | |||
3408 | default: | ||
3409 | freeaddrinfo(res); | ||
3410 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
3411 | _("No IP addresses found for hostname `%s' of service `%s'!\n"), | ||
3412 | hostname, | ||
3413 | n); | ||
3414 | GNUNET_free(serv); | ||
3415 | continue; | ||
3416 | } | ||
3417 | freeaddrinfo(res); | ||
3418 | } | ||
3419 | store_service(proto, | ||
3420 | n, | ||
3421 | local_port, | ||
3422 | serv); | ||
3423 | } | 3504 | } |
3424 | GNUNET_free(n); | 3505 | store_service (proto, |
3506 | n, | ||
3507 | local_port, | ||
3508 | serv); | ||
3509 | } | ||
3510 | GNUNET_free (n); | ||
3425 | } | 3511 | } |
3426 | 3512 | ||
3427 | 3513 | ||
@@ -3432,36 +3518,36 @@ add_services(int proto, | |||
3432 | * @param section name of section in config | 3518 | * @param section name of section in config |
3433 | */ | 3519 | */ |
3434 | static void | 3520 | static void |
3435 | read_service_conf(void *cls, | 3521 | read_service_conf (void *cls, |
3436 | const char *section) | 3522 | const char *section) |
3437 | { | 3523 | { |
3438 | char *cpy; | 3524 | char *cpy; |
3439 | 3525 | ||
3440 | if ((strlen(section) < 8) || | 3526 | if ((strlen (section) < 8) || |
3441 | (0 != strcmp(".gnunet.", section + (strlen(section) - 8)))) | 3527 | (0 != strcmp (".gnunet.", section + (strlen (section) - 8)))) |
3442 | return; | 3528 | return; |
3443 | if (GNUNET_OK == | 3529 | if (GNUNET_OK == |
3444 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3530 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3445 | section, | 3531 | section, |
3446 | "UDP_REDIRECTS", | 3532 | "UDP_REDIRECTS", |
3447 | &cpy)) | 3533 | &cpy)) |
3448 | { | 3534 | { |
3449 | add_services(IPPROTO_UDP, | 3535 | add_services (IPPROTO_UDP, |
3450 | cpy, | 3536 | cpy, |
3451 | section); | 3537 | section); |
3452 | GNUNET_free(cpy); | 3538 | GNUNET_free (cpy); |
3453 | } | 3539 | } |
3454 | if (GNUNET_OK == | 3540 | if (GNUNET_OK == |
3455 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3541 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3456 | section, | 3542 | section, |
3457 | "TCP_REDIRECTS", | 3543 | "TCP_REDIRECTS", |
3458 | &cpy)) | 3544 | &cpy)) |
3459 | { | 3545 | { |
3460 | add_services(IPPROTO_TCP, | 3546 | add_services (IPPROTO_TCP, |
3461 | cpy, | 3547 | cpy, |
3462 | section); | 3548 | section); |
3463 | GNUNET_free(cpy); | 3549 | GNUNET_free (cpy); |
3464 | } | 3550 | } |
3465 | } | 3551 | } |
3466 | 3552 | ||
3467 | 3553 | ||
@@ -3472,7 +3558,7 @@ read_service_conf(void *cls, | |||
3472 | * @param cls closure | 3558 | * @param cls closure |
3473 | */ | 3559 | */ |
3474 | static void | 3560 | static void |
3475 | do_dht_put(void *cls); | 3561 | do_dht_put (void *cls); |
3476 | 3562 | ||
3477 | 3563 | ||
3478 | /** | 3564 | /** |
@@ -3482,7 +3568,7 @@ do_dht_put(void *cls); | |||
3482 | * @param cls closure, NULL | 3568 | * @param cls closure, NULL |
3483 | */ | 3569 | */ |
3484 | static void | 3570 | static void |
3485 | dht_put_cont(void *cls) | 3571 | dht_put_cont (void *cls) |
3486 | { | 3572 | { |
3487 | dht_put = NULL; | 3573 | dht_put = NULL; |
3488 | } | 3574 | } |
@@ -3495,37 +3581,37 @@ dht_put_cont(void *cls) | |||
3495 | * @param cls closure | 3581 | * @param cls closure |
3496 | */ | 3582 | */ |
3497 | static void | 3583 | static void |
3498 | do_dht_put(void *cls) | 3584 | do_dht_put (void *cls) |
3499 | { | 3585 | { |
3500 | struct GNUNET_TIME_Absolute expiration; | 3586 | struct GNUNET_TIME_Absolute expiration; |
3501 | 3587 | ||
3502 | dht_task = GNUNET_SCHEDULER_add_delayed(DHT_PUT_FREQUENCY, | 3588 | dht_task = GNUNET_SCHEDULER_add_delayed (DHT_PUT_FREQUENCY, |
3503 | &do_dht_put, | 3589 | &do_dht_put, |
3504 | NULL); | 3590 | NULL); |
3505 | expiration = GNUNET_TIME_absolute_ntoh(dns_advertisement.expiration_time); | 3591 | expiration = GNUNET_TIME_absolute_ntoh (dns_advertisement.expiration_time); |
3506 | if (GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us < | 3592 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us < |
3507 | GNUNET_TIME_UNIT_HOURS.rel_value_us) | 3593 | GNUNET_TIME_UNIT_HOURS.rel_value_us) |
3508 | { | 3594 | { |
3509 | /* refresh advertisement */ | 3595 | /* refresh advertisement */ |
3510 | expiration = GNUNET_TIME_relative_to_absolute(DNS_ADVERTISEMENT_TIMEOUT); | 3596 | expiration = GNUNET_TIME_relative_to_absolute (DNS_ADVERTISEMENT_TIMEOUT); |
3511 | dns_advertisement.expiration_time = GNUNET_TIME_absolute_hton(expiration); | 3597 | dns_advertisement.expiration_time = GNUNET_TIME_absolute_hton (expiration); |
3512 | GNUNET_assert(GNUNET_OK == | 3598 | GNUNET_assert (GNUNET_OK == |
3513 | GNUNET_CRYPTO_eddsa_sign(peer_key, | 3599 | GNUNET_CRYPTO_eddsa_sign (peer_key, |
3514 | &dns_advertisement.purpose, | 3600 | &dns_advertisement.purpose, |
3515 | &dns_advertisement.signature)); | 3601 | &dns_advertisement.signature)); |
3516 | } | 3602 | } |
3517 | if (NULL != dht_put) | 3603 | if (NULL != dht_put) |
3518 | GNUNET_DHT_put_cancel(dht_put); | 3604 | GNUNET_DHT_put_cancel (dht_put); |
3519 | dht_put = GNUNET_DHT_put(dht, | 3605 | dht_put = GNUNET_DHT_put (dht, |
3520 | &dht_put_key, | 3606 | &dht_put_key, |
3521 | 1 /* replication */, | 3607 | 1 /* replication */, |
3522 | GNUNET_DHT_RO_NONE, | 3608 | GNUNET_DHT_RO_NONE, |
3523 | GNUNET_BLOCK_TYPE_DNS, | 3609 | GNUNET_BLOCK_TYPE_DNS, |
3524 | sizeof(struct GNUNET_DNS_Advertisement), | 3610 | sizeof(struct GNUNET_DNS_Advertisement), |
3525 | &dns_advertisement, | 3611 | &dns_advertisement, |
3526 | expiration, | 3612 | expiration, |
3527 | &dht_put_cont, | 3613 | &dht_put_cont, |
3528 | NULL); | 3614 | NULL); |
3529 | } | 3615 | } |
3530 | 3616 | ||
3531 | 3617 | ||
@@ -3534,48 +3620,52 @@ do_dht_put(void *cls) | |||
3534 | * are supported by the OS) according to our configuration. | 3620 | * are supported by the OS) according to our configuration. |
3535 | */ | 3621 | */ |
3536 | static void | 3622 | static void |
3537 | parse_ip_options() | 3623 | parse_ip_options () |
3538 | { | 3624 | { |
3539 | ipv4_exit = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 3625 | ipv4_exit = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
3540 | "exit", | 3626 | "exit", |
3541 | "EXIT_IPV4"); | 3627 | "EXIT_IPV4"); |
3542 | ipv6_exit = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 3628 | ipv6_exit = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
3543 | "exit", | 3629 | "exit", |
3544 | "EXIT_IPV6"); | 3630 | "EXIT_IPV6"); |
3545 | ipv4_enabled = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 3631 | ipv4_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
3546 | "exit", | 3632 | "exit", |
3547 | "ENABLE_IPV4"); | 3633 | "ENABLE_IPV4"); |
3548 | ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 3634 | ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
3549 | "exit", | 3635 | "exit", |
3550 | "ENABLE_IPV6"); | 3636 | "ENABLE_IPV6"); |
3551 | if ((ipv4_exit || ipv4_enabled) && | 3637 | if ((ipv4_exit || ipv4_enabled) && |
3552 | GNUNET_OK != GNUNET_NETWORK_test_pf(PF_INET)) | 3638 | (GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET)) ) |
3553 | { | 3639 | { |
3554 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 3640 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3555 | _("This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n")); | 3641 | _ ( |
3556 | ipv4_exit = GNUNET_NO; | 3642 | "This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n")); |
3557 | ipv4_enabled = GNUNET_NO; | 3643 | ipv4_exit = GNUNET_NO; |
3558 | } | 3644 | ipv4_enabled = GNUNET_NO; |
3645 | } | ||
3559 | if ((ipv6_exit || ipv6_enabled) && | 3646 | if ((ipv6_exit || ipv6_enabled) && |
3560 | GNUNET_OK != GNUNET_NETWORK_test_pf(PF_INET6)) | 3647 | (GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET6)) ) |
3561 | { | 3648 | { |
3562 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 3649 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3563 | _("This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n")); | 3650 | _ ( |
3564 | ipv6_exit = GNUNET_NO; | 3651 | "This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n")); |
3565 | ipv6_enabled = GNUNET_NO; | 3652 | ipv6_exit = GNUNET_NO; |
3566 | } | 3653 | ipv6_enabled = GNUNET_NO; |
3567 | if (ipv4_exit && (!ipv4_enabled)) | 3654 | } |
3568 | { | 3655 | if (ipv4_exit && (! ipv4_enabled)) |
3569 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 3656 | { |
3570 | _("Cannot enable IPv4 exit but disable IPv4 on TUN interface, will use ENABLE_IPv4=YES\n")); | 3657 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3571 | ipv4_enabled = GNUNET_YES; | 3658 | _ ( |
3572 | } | 3659 | "Cannot enable IPv4 exit but disable IPv4 on TUN interface, will use ENABLE_IPv4=YES\n")); |
3573 | if (ipv6_exit && (!ipv6_enabled)) | 3660 | ipv4_enabled = GNUNET_YES; |
3574 | { | 3661 | } |
3575 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 3662 | if (ipv6_exit && (! ipv6_enabled)) |
3576 | _("Cannot enable IPv6 exit but disable IPv6 on TUN interface, will use ENABLE_IPv6=YES\n")); | 3663 | { |
3577 | ipv6_enabled = GNUNET_YES; | 3664 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3578 | } | 3665 | _ ( |
3666 | "Cannot enable IPv6 exit but disable IPv6 on TUN interface, will use ENABLE_IPv6=YES\n")); | ||
3667 | ipv6_enabled = GNUNET_YES; | ||
3668 | } | ||
3579 | } | 3669 | } |
3580 | 3670 | ||
3581 | 3671 | ||
@@ -3584,71 +3674,74 @@ parse_ip_options() | |||
3584 | * advertise the DNS exit (if applicable). | 3674 | * advertise the DNS exit (if applicable). |
3585 | */ | 3675 | */ |
3586 | static void | 3676 | static void |
3587 | advertise_dns_exit() | 3677 | advertise_dns_exit () |
3588 | { | 3678 | { |
3589 | struct GNUNET_MQ_MessageHandler handlers[] = { | 3679 | struct GNUNET_MQ_MessageHandler handlers[] = { |
3590 | GNUNET_MQ_hd_var_size(dns_request, | 3680 | GNUNET_MQ_hd_var_size (dns_request, |
3591 | GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET, | 3681 | GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET, |
3592 | struct DnsResponseMessage, | 3682 | struct DnsResponseMessage, |
3593 | NULL), | 3683 | NULL), |
3594 | GNUNET_MQ_handler_end() | 3684 | GNUNET_MQ_handler_end () |
3595 | }; | 3685 | }; |
3596 | char *dns_exit; | 3686 | char *dns_exit; |
3597 | struct GNUNET_HashCode port; | 3687 | struct GNUNET_HashCode port; |
3598 | 3688 | ||
3599 | if (GNUNET_YES != | 3689 | if (GNUNET_YES != |
3600 | GNUNET_CONFIGURATION_get_value_yesno(cfg, | 3690 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
3601 | "exit", | 3691 | "exit", |
3602 | "EXIT_DNS")) | 3692 | "EXIT_DNS")) |
3603 | return; | 3693 | return; |
3604 | GNUNET_assert(NULL != (dnsstub = GNUNET_DNSSTUB_start(128))); | 3694 | GNUNET_assert (NULL != (dnsstub = GNUNET_DNSSTUB_start (128))); |
3605 | dns_exit = NULL; | 3695 | dns_exit = NULL; |
3606 | /* TODO: support using multiple DNS resolvers */ | 3696 | /* TODO: support using multiple DNS resolvers */ |
3607 | if ((GNUNET_OK != | 3697 | if ((GNUNET_OK != |
3608 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3698 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3609 | "exit", | 3699 | "exit", |
3610 | "DNS_RESOLVER", | 3700 | "DNS_RESOLVER", |
3611 | &dns_exit)) || | 3701 | &dns_exit)) || |
3612 | (GNUNET_OK != | 3702 | (GNUNET_OK != |
3613 | GNUNET_DNSSTUB_add_dns_ip(dnsstub, | 3703 | GNUNET_DNSSTUB_add_dns_ip (dnsstub, |
3614 | dns_exit))) | 3704 | dns_exit))) |
3615 | { | 3705 | { |
3616 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 3706 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3617 | "dns", | 3707 | "dns", |
3618 | "DNS_RESOLVER", | 3708 | "DNS_RESOLVER", |
3619 | _("need a valid IPv4 or IPv6 address\n")); | 3709 | _ ("need a valid IPv4 or IPv6 address\n")); |
3620 | GNUNET_free_non_null(dns_exit); | 3710 | GNUNET_free_non_null (dns_exit); |
3621 | return; | 3711 | return; |
3622 | } | 3712 | } |
3623 | /* open port */ | 3713 | /* open port */ |
3624 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, | 3714 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, |
3625 | strlen(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), | 3715 | strlen (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), |
3626 | &port); | 3716 | &port); |
3627 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3628 | "Opening CADET port %s for DNS exit service\n", | 3718 | "Opening CADET port %s for DNS exit service\n", |
3629 | GNUNET_h2s(&port)); | 3719 | GNUNET_h2s (&port)); |
3630 | dns_port = GNUNET_CADET_open_port(cadet_handle, | 3720 | dns_port = GNUNET_CADET_open_port (cadet_handle, |
3631 | &port, | 3721 | &port, |
3632 | &new_channel, | 3722 | &new_channel, |
3633 | NULL, | 3723 | NULL, |
3634 | NULL, | 3724 | NULL, |
3635 | &clean_channel, | 3725 | &clean_channel, |
3636 | handlers); | 3726 | handlers); |
3637 | /* advertise exit */ | 3727 | /* advertise exit */ |
3638 | dht = GNUNET_DHT_connect(cfg, | 3728 | dht = GNUNET_DHT_connect (cfg, |
3639 | 1); | 3729 | 1); |
3640 | peer_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); | 3730 | peer_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); |
3641 | GNUNET_CRYPTO_eddsa_key_get_public(peer_key, | 3731 | GNUNET_CRYPTO_eddsa_key_get_public (peer_key, |
3642 | &dns_advertisement.peer.public_key); | 3732 | &dns_advertisement.peer.public_key); |
3643 | dns_advertisement.purpose.size = htonl(sizeof(struct GNUNET_DNS_Advertisement) - | 3733 | dns_advertisement.purpose.size = htonl (sizeof(struct |
3644 | sizeof(struct GNUNET_CRYPTO_EddsaSignature)); | 3734 | GNUNET_DNS_Advertisement) |
3645 | dns_advertisement.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD); | 3735 | - sizeof(struct |
3646 | GNUNET_CRYPTO_hash("dns", | 3736 | GNUNET_CRYPTO_EddsaSignature)); |
3647 | strlen("dns"), | 3737 | dns_advertisement.purpose.purpose = htonl ( |
3648 | &dht_put_key); | 3738 | GNUNET_SIGNATURE_PURPOSE_DNS_RECORD); |
3649 | dht_task = GNUNET_SCHEDULER_add_now(&do_dht_put, | 3739 | GNUNET_CRYPTO_hash ("dns", |
3650 | NULL); | 3740 | strlen ("dns"), |
3651 | GNUNET_free(dns_exit); | 3741 | &dht_put_key); |
3742 | dht_task = GNUNET_SCHEDULER_add_now (&do_dht_put, | ||
3743 | NULL); | ||
3744 | GNUNET_free (dns_exit); | ||
3652 | } | 3745 | } |
3653 | 3746 | ||
3654 | 3747 | ||
@@ -3658,7 +3751,7 @@ advertise_dns_exit() | |||
3658 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if we should shutdown | 3751 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if we should shutdown |
3659 | */ | 3752 | */ |
3660 | static int | 3753 | static int |
3661 | setup_exit_helper_args() | 3754 | setup_exit_helper_args () |
3662 | { | 3755 | { |
3663 | char *exit_ifname; | 3756 | char *exit_ifname; |
3664 | char *tun_ifname; | 3757 | char *tun_ifname; |
@@ -3667,133 +3760,133 @@ setup_exit_helper_args() | |||
3667 | char *ipv4addr; | 3760 | char *ipv4addr; |
3668 | char *ipv4mask; | 3761 | char *ipv4mask; |
3669 | 3762 | ||
3670 | exit_argv[0] = GNUNET_strdup("exit-gnunet"); | 3763 | exit_argv[0] = GNUNET_strdup ("exit-gnunet"); |
3671 | if (GNUNET_SYSERR == | 3764 | if (GNUNET_SYSERR == |
3672 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3765 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3673 | "exit", | 3766 | "exit", |
3674 | "TUN_IFNAME", | 3767 | "TUN_IFNAME", |
3675 | &tun_ifname)) | 3768 | &tun_ifname)) |
3676 | { | 3769 | { |
3677 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 3770 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
3678 | "EXIT", | 3771 | "EXIT", |
3679 | "TUN_IFNAME"); | 3772 | "TUN_IFNAME"); |
3680 | return GNUNET_SYSERR; | 3773 | return GNUNET_SYSERR; |
3681 | } | 3774 | } |
3682 | exit_argv[1] = tun_ifname; | 3775 | exit_argv[1] = tun_ifname; |
3683 | if (ipv4_enabled) | 3776 | if (ipv4_enabled) |
3777 | { | ||
3778 | if (GNUNET_SYSERR == | ||
3779 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
3780 | "exit", | ||
3781 | "EXIT_IFNAME", | ||
3782 | &exit_ifname)) | ||
3684 | { | 3783 | { |
3685 | if (GNUNET_SYSERR == | 3784 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
3686 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3785 | "EXIT", |
3687 | "exit", | 3786 | "EXIT_IFNAME"); |
3688 | "EXIT_IFNAME", | 3787 | return GNUNET_SYSERR; |
3689 | &exit_ifname)) | ||
3690 | { | ||
3691 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | ||
3692 | "EXIT", | ||
3693 | "EXIT_IFNAME"); | ||
3694 | return GNUNET_SYSERR; | ||
3695 | } | ||
3696 | exit_argv[2] = exit_ifname; | ||
3697 | } | 3788 | } |
3789 | exit_argv[2] = exit_ifname; | ||
3790 | } | ||
3698 | else | 3791 | else |
3699 | { | 3792 | { |
3700 | exit_argv[2] = GNUNET_strdup("-"); | 3793 | exit_argv[2] = GNUNET_strdup ("-"); |
3701 | } | 3794 | } |
3702 | 3795 | ||
3703 | if (GNUNET_YES == ipv6_enabled) | 3796 | if (GNUNET_YES == ipv6_enabled) |
3704 | { | 3797 | { |
3705 | ipv6addr = NULL; | 3798 | ipv6addr = NULL; |
3706 | if ((GNUNET_SYSERR == | 3799 | if (((GNUNET_SYSERR == |
3707 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3800 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3708 | "exit", | 3801 | "exit", |
3709 | "IPV6ADDR", | 3802 | "IPV6ADDR", |
3710 | &ipv6addr) || | 3803 | &ipv6addr))|| |
3711 | (1 != inet_pton(AF_INET6, | 3804 | (1 != inet_pton (AF_INET6, |
3712 | ipv6addr, | 3805 | ipv6addr, |
3713 | &exit_ipv6addr)))) | 3806 | &exit_ipv6addr)))) |
3714 | { | 3807 | { |
3715 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 3808 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
3716 | "EXIT", | 3809 | "EXIT", |
3717 | "IPV6ADDR"); | 3810 | "IPV6ADDR"); |
3718 | GNUNET_free_non_null(ipv6addr); | 3811 | GNUNET_free_non_null (ipv6addr); |
3719 | return GNUNET_SYSERR; | 3812 | return GNUNET_SYSERR; |
3720 | } | 3813 | } |
3721 | exit_argv[3] = ipv6addr; | 3814 | exit_argv[3] = ipv6addr; |
3722 | if (GNUNET_SYSERR == | 3815 | if (GNUNET_SYSERR == |
3723 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3816 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3817 | "exit", | ||
3818 | "IPV6PREFIX", | ||
3819 | &ipv6prefix_s)) | ||
3820 | { | ||
3821 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
3822 | "EXIT", | ||
3823 | "IPV6PREFIX"); | ||
3824 | return GNUNET_SYSERR; | ||
3825 | } | ||
3826 | exit_argv[4] = ipv6prefix_s; | ||
3827 | if ((GNUNET_OK != | ||
3828 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
3724 | "exit", | 3829 | "exit", |
3725 | "IPV6PREFIX", | 3830 | "IPV6PREFIX", |
3726 | &ipv6prefix_s)) | 3831 | &ipv6prefix)) || |
3727 | { | 3832 | (ipv6prefix >= 127)) |
3728 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | ||
3729 | "EXIT", | ||
3730 | "IPV6PREFIX"); | ||
3731 | return GNUNET_SYSERR; | ||
3732 | } | ||
3733 | exit_argv[4] = ipv6prefix_s; | ||
3734 | if ((GNUNET_OK != | ||
3735 | GNUNET_CONFIGURATION_get_value_number(cfg, | ||
3736 | "exit", | ||
3737 | "IPV6PREFIX", | ||
3738 | &ipv6prefix)) || | ||
3739 | (ipv6prefix >= 127)) | ||
3740 | { | ||
3741 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | ||
3742 | "EXIT", | ||
3743 | "IPV6PREFIX", | ||
3744 | _("Must be a number")); | ||
3745 | return GNUNET_SYSERR; | ||
3746 | } | ||
3747 | } | ||
3748 | else | ||
3749 | { | 3833 | { |
3750 | /* IPv6 explicitly disabled */ | 3834 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3751 | exit_argv[3] = GNUNET_strdup("-"); | 3835 | "EXIT", |
3752 | exit_argv[4] = GNUNET_strdup("-"); | 3836 | "IPV6PREFIX", |
3837 | _ ("Must be a number")); | ||
3838 | return GNUNET_SYSERR; | ||
3753 | } | 3839 | } |
3840 | } | ||
3841 | else | ||
3842 | { | ||
3843 | /* IPv6 explicitly disabled */ | ||
3844 | exit_argv[3] = GNUNET_strdup ("-"); | ||
3845 | exit_argv[4] = GNUNET_strdup ("-"); | ||
3846 | } | ||
3754 | if (GNUNET_YES == ipv4_enabled) | 3847 | if (GNUNET_YES == ipv4_enabled) |
3755 | { | 3848 | { |
3756 | ipv4addr = NULL; | 3849 | ipv4addr = NULL; |
3757 | if ((GNUNET_SYSERR == | 3850 | if (((GNUNET_SYSERR == |
3758 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3851 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3759 | "exit", | 3852 | "exit", |
3760 | "IPV4ADDR", | 3853 | "IPV4ADDR", |
3761 | &ipv4addr) || | 3854 | &ipv4addr))|| |
3762 | (1 != inet_pton(AF_INET, | 3855 | (1 != inet_pton (AF_INET, |
3763 | ipv4addr, | 3856 | ipv4addr, |
3764 | &exit_ipv4addr)))) | 3857 | &exit_ipv4addr)))) |
3765 | { | 3858 | { |
3766 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 3859 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
3767 | "EXIT", | 3860 | "EXIT", |
3768 | "IPV4ADDR"); | 3861 | "IPV4ADDR"); |
3769 | GNUNET_free_non_null(ipv4addr); | 3862 | GNUNET_free_non_null (ipv4addr); |
3770 | return GNUNET_SYSERR; | 3863 | return GNUNET_SYSERR; |
3771 | } | 3864 | } |
3772 | exit_argv[5] = ipv4addr; | 3865 | exit_argv[5] = ipv4addr; |
3773 | ipv4mask = NULL; | 3866 | ipv4mask = NULL; |
3774 | if ((GNUNET_SYSERR == | 3867 | if (((GNUNET_SYSERR == |
3775 | GNUNET_CONFIGURATION_get_value_string(cfg, | 3868 | GNUNET_CONFIGURATION_get_value_string (cfg, |
3776 | "exit", | 3869 | "exit", |
3777 | "IPV4MASK", | 3870 | "IPV4MASK", |
3778 | &ipv4mask) || | 3871 | &ipv4mask))|| |
3779 | (1 != inet_pton(AF_INET, | 3872 | (1 != inet_pton (AF_INET, |
3780 | ipv4mask, | 3873 | ipv4mask, |
3781 | &exit_ipv4mask)))) | 3874 | &exit_ipv4mask)))) |
3782 | { | ||
3783 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | ||
3784 | "EXIT", | ||
3785 | "IPV4MASK"); | ||
3786 | GNUNET_free_non_null(ipv4mask); | ||
3787 | return GNUNET_SYSERR; | ||
3788 | } | ||
3789 | exit_argv[6] = ipv4mask; | ||
3790 | } | ||
3791 | else | ||
3792 | { | 3875 | { |
3793 | /* IPv4 explicitly disabled */ | 3876 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
3794 | exit_argv[5] = GNUNET_strdup("-"); | 3877 | "EXIT", |
3795 | exit_argv[6] = GNUNET_strdup("-"); | 3878 | "IPV4MASK"); |
3879 | GNUNET_free_non_null (ipv4mask); | ||
3880 | return GNUNET_SYSERR; | ||
3796 | } | 3881 | } |
3882 | exit_argv[6] = ipv4mask; | ||
3883 | } | ||
3884 | else | ||
3885 | { | ||
3886 | /* IPv4 explicitly disabled */ | ||
3887 | exit_argv[5] = GNUNET_strdup ("-"); | ||
3888 | exit_argv[6] = GNUNET_strdup ("-"); | ||
3889 | } | ||
3797 | exit_argv[7] = NULL; | 3890 | exit_argv[7] = NULL; |
3798 | return GNUNET_OK; | 3891 | return GNUNET_OK; |
3799 | } | 3892 | } |
@@ -3808,29 +3901,29 @@ setup_exit_helper_args() | |||
3808 | * @param cfg_ configuration | 3901 | * @param cfg_ configuration |
3809 | */ | 3902 | */ |
3810 | static void | 3903 | static void |
3811 | run(void *cls, | 3904 | run (void *cls, |
3812 | char *const *args, | 3905 | char *const *args, |
3813 | const char *cfgfile, | 3906 | const char *cfgfile, |
3814 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 3907 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
3815 | { | 3908 | { |
3816 | struct GNUNET_MQ_MessageHandler handlers[] = { | 3909 | struct GNUNET_MQ_MessageHandler handlers[] = { |
3817 | GNUNET_MQ_hd_var_size(icmp_remote, | 3910 | GNUNET_MQ_hd_var_size (icmp_remote, |
3818 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET, | 3911 | GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET, |
3819 | struct GNUNET_EXIT_IcmpInternetMessage, | 3912 | struct GNUNET_EXIT_IcmpInternetMessage, |
3820 | NULL), | 3913 | NULL), |
3821 | GNUNET_MQ_hd_var_size(udp_remote, | 3914 | GNUNET_MQ_hd_var_size (udp_remote, |
3822 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET, | 3915 | GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET, |
3823 | struct GNUNET_EXIT_UdpInternetMessage, | 3916 | struct GNUNET_EXIT_UdpInternetMessage, |
3824 | NULL), | 3917 | NULL), |
3825 | GNUNET_MQ_hd_var_size(tcp_remote, | 3918 | GNUNET_MQ_hd_var_size (tcp_remote, |
3826 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START, | 3919 | GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START, |
3827 | struct GNUNET_EXIT_TcpInternetStartMessage, | 3920 | struct GNUNET_EXIT_TcpInternetStartMessage, |
3828 | NULL), | 3921 | NULL), |
3829 | GNUNET_MQ_hd_var_size(tcp_data, | 3922 | GNUNET_MQ_hd_var_size (tcp_data, |
3830 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, | 3923 | GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, |
3831 | struct GNUNET_EXIT_TcpDataMessage, | 3924 | struct GNUNET_EXIT_TcpDataMessage, |
3832 | NULL), | 3925 | NULL), |
3833 | GNUNET_MQ_handler_end() | 3926 | GNUNET_MQ_handler_end () |
3834 | }; | 3927 | }; |
3835 | struct GNUNET_HashCode port; | 3928 | struct GNUNET_HashCode port; |
3836 | char *policy; | 3929 | char *policy; |
@@ -3840,157 +3933,159 @@ run(void *cls, | |||
3840 | 3933 | ||
3841 | cfg = cfg_; | 3934 | cfg = cfg_; |
3842 | if (GNUNET_OK != | 3935 | if (GNUNET_OK != |
3843 | GNUNET_CONFIGURATION_get_value_number(cfg, | 3936 | GNUNET_CONFIGURATION_get_value_number (cfg, |
3844 | "exit", | 3937 | "exit", |
3845 | "MAX_CONNECTIONS", | 3938 | "MAX_CONNECTIONS", |
3846 | &max_connections)) | 3939 | &max_connections)) |
3847 | max_connections = 1024; | 3940 | max_connections = 1024; |
3848 | parse_ip_options(); | 3941 | parse_ip_options (); |
3849 | binary = GNUNET_OS_get_suid_binary_path(cfg, "gnunet-helper-exit"); | 3942 | binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-exit"); |
3850 | if ((ipv4_exit) || (ipv6_exit)) | 3943 | if ((ipv4_exit) || (ipv6_exit)) |
3944 | { | ||
3945 | if (GNUNET_YES != | ||
3946 | GNUNET_OS_check_helper_binary (binary, | ||
3947 | GNUNET_YES, | ||
3948 | "gnunet-vpn - - - 169.1.3.7 255.255.255.0")) // no nat, ipv4 only | ||
3851 | { | 3949 | { |
3852 | if (GNUNET_YES != | 3950 | GNUNET_free (binary); |
3853 | GNUNET_OS_check_helper_binary(binary, | 3951 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3854 | GNUNET_YES, | 3952 | _ ( |
3855 | "gnunet-vpn - - - 169.1.3.7 255.255.255.0")) //no nat, ipv4 only | 3953 | "`%s' is not SUID or the path is invalid, EXIT will not work\n"), |
3856 | { | 3954 | "gnunet-helper-exit"); |
3857 | GNUNET_free(binary); | 3955 | GNUNET_SCHEDULER_add_shutdown (&dummy_task, |
3858 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 3956 | NULL); |
3859 | _("`%s' is not SUID or the path is invalid, EXIT will not work\n"), | 3957 | global_ret = 1; |
3860 | "gnunet-helper-exit"); | ||
3861 | GNUNET_SCHEDULER_add_shutdown(&dummy_task, | ||
3862 | NULL); | ||
3863 | global_ret = 1; | ||
3864 | return; | ||
3865 | } | ||
3866 | } | ||
3867 | if (!(ipv4_enabled || ipv6_enabled)) | ||
3868 | { | ||
3869 | GNUNET_free(binary); | ||
3870 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
3871 | _("No useful service enabled. Exiting.\n")); | ||
3872 | GNUNET_SCHEDULER_shutdown(); | ||
3873 | return; | 3958 | return; |
3874 | } | 3959 | } |
3960 | } | ||
3961 | if (! (ipv4_enabled || ipv6_enabled)) | ||
3962 | { | ||
3963 | GNUNET_free (binary); | ||
3964 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
3965 | _ ("No useful service enabled. Exiting.\n")); | ||
3966 | GNUNET_SCHEDULER_shutdown (); | ||
3967 | return; | ||
3968 | } | ||
3875 | 3969 | ||
3876 | GNUNET_SCHEDULER_add_shutdown(&cleanup, | 3970 | GNUNET_SCHEDULER_add_shutdown (&cleanup, |
3877 | NULL); | 3971 | NULL); |
3878 | stats = GNUNET_STATISTICS_create("exit", | 3972 | stats = GNUNET_STATISTICS_create ("exit", |
3879 | cfg); | 3973 | cfg); |
3880 | cadet_handle = GNUNET_CADET_connect(cfg); | 3974 | cadet_handle = GNUNET_CADET_connect (cfg); |
3881 | if (NULL == cadet_handle) | 3975 | if (NULL == cadet_handle) |
3882 | { | 3976 | { |
3883 | GNUNET_free(binary); | 3977 | GNUNET_free (binary); |
3884 | GNUNET_SCHEDULER_shutdown(); | 3978 | GNUNET_SCHEDULER_shutdown (); |
3885 | return; | 3979 | return; |
3886 | } | 3980 | } |
3887 | advertise_dns_exit(); | 3981 | advertise_dns_exit (); |
3888 | if (GNUNET_OK != | 3982 | if (GNUNET_OK != |
3889 | setup_exit_helper_args()) | 3983 | setup_exit_helper_args ()) |
3890 | { | 3984 | { |
3891 | GNUNET_free(binary); | 3985 | GNUNET_free (binary); |
3892 | GNUNET_SCHEDULER_shutdown(); | 3986 | GNUNET_SCHEDULER_shutdown (); |
3893 | return; | 3987 | return; |
3894 | } | 3988 | } |
3895 | 3989 | ||
3896 | services = GNUNET_CONTAINER_multihashmap_create(65536, | 3990 | services = GNUNET_CONTAINER_multihashmap_create (65536, |
3897 | GNUNET_NO); | 3991 | GNUNET_NO); |
3898 | connections_map = GNUNET_CONTAINER_multihashmap_create(65536, | 3992 | connections_map = GNUNET_CONTAINER_multihashmap_create (65536, |
3899 | GNUNET_NO); | 3993 | GNUNET_NO); |
3900 | connections_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 3994 | connections_heap = GNUNET_CONTAINER_heap_create ( |
3901 | GNUNET_CONFIGURATION_iterate_sections(cfg, | 3995 | GNUNET_CONTAINER_HEAP_ORDER_MIN); |
3902 | &read_service_conf, | 3996 | GNUNET_CONFIGURATION_iterate_sections (cfg, |
3903 | NULL); | 3997 | &read_service_conf, |
3998 | NULL); | ||
3904 | 3999 | ||
3905 | /* Cadet handle acquired, now open ports and announce regular | 4000 | /* Cadet handle acquired, now open ports and announce regular |
3906 | expressions matching our exit */ | 4001 | expressions matching our exit */ |
3907 | if ((GNUNET_YES == ipv4_enabled) && | 4002 | if ((GNUNET_YES == ipv4_enabled) && |
3908 | (GNUNET_YES == ipv4_exit)) | 4003 | (GNUNET_YES == ipv4_exit)) |
4004 | { | ||
4005 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV4_GATEWAY, | ||
4006 | strlen (GNUNET_APPLICATION_PORT_IPV4_GATEWAY), | ||
4007 | &port); | ||
4008 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4009 | "Opening CADET port %s for IPv4 gateway service\n", | ||
4010 | GNUNET_h2s (&port)); | ||
4011 | cadet_port4 = GNUNET_CADET_open_port (cadet_handle, | ||
4012 | &port, | ||
4013 | &new_channel, | ||
4014 | NULL, | ||
4015 | NULL, | ||
4016 | &clean_channel, | ||
4017 | handlers); | ||
4018 | policy = NULL; | ||
4019 | if (GNUNET_OK != | ||
4020 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
4021 | "exit", | ||
4022 | "EXIT_RANGE_IPV4_POLICY", | ||
4023 | &policy)) | ||
4024 | regex = NULL; | ||
4025 | else | ||
4026 | regex = GNUNET_TUN_ipv4policy2regex (policy); | ||
4027 | GNUNET_free_non_null (policy); | ||
4028 | if (NULL != regex) | ||
3909 | { | 4029 | { |
3910 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_IPV4_GATEWAY, | 4030 | (void) GNUNET_asprintf (&prefixed_regex, |
3911 | strlen(GNUNET_APPLICATION_PORT_IPV4_GATEWAY), | 4031 | "%s%s", |
3912 | &port); | 4032 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
3913 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 4033 | regex); |
3914 | "Opening CADET port %s for IPv4 gateway service\n", | 4034 | regex4 = GNUNET_REGEX_announce (cfg, |
3915 | GNUNET_h2s(&port)); | 4035 | prefixed_regex, |
3916 | cadet_port4 = GNUNET_CADET_open_port(cadet_handle, | 4036 | REGEX_REFRESH_FREQUENCY, |
3917 | &port, | 4037 | REGEX_MAX_PATH_LEN_IPV4); |
3918 | &new_channel, | 4038 | GNUNET_free (regex); |
3919 | NULL, | 4039 | GNUNET_free (prefixed_regex); |
3920 | NULL, | ||
3921 | &clean_channel, | ||
3922 | handlers); | ||
3923 | policy = NULL; | ||
3924 | if (GNUNET_OK != | ||
3925 | GNUNET_CONFIGURATION_get_value_string(cfg, | ||
3926 | "exit", | ||
3927 | "EXIT_RANGE_IPV4_POLICY", | ||
3928 | &policy)) | ||
3929 | regex = NULL; | ||
3930 | else | ||
3931 | regex = GNUNET_TUN_ipv4policy2regex(policy); | ||
3932 | GNUNET_free_non_null(policy); | ||
3933 | if (NULL != regex) | ||
3934 | { | ||
3935 | (void)GNUNET_asprintf(&prefixed_regex, | ||
3936 | "%s%s", | ||
3937 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
3938 | regex); | ||
3939 | regex4 = GNUNET_REGEX_announce(cfg, | ||
3940 | prefixed_regex, | ||
3941 | REGEX_REFRESH_FREQUENCY, | ||
3942 | REGEX_MAX_PATH_LEN_IPV4); | ||
3943 | GNUNET_free(regex); | ||
3944 | GNUNET_free(prefixed_regex); | ||
3945 | } | ||
3946 | } | 4040 | } |
4041 | } | ||
3947 | 4042 | ||
3948 | if ((GNUNET_YES == ipv6_enabled) && (GNUNET_YES == ipv6_exit)) | 4043 | if ((GNUNET_YES == ipv6_enabled) && (GNUNET_YES == ipv6_exit)) |
4044 | { | ||
4045 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_IPV6_GATEWAY, | ||
4046 | strlen (GNUNET_APPLICATION_PORT_IPV6_GATEWAY), | ||
4047 | &port); | ||
4048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4049 | "Opening CADET port %s for IPv6 gateway service\n", | ||
4050 | GNUNET_h2s (&port)); | ||
4051 | cadet_port6 = GNUNET_CADET_open_port (cadet_handle, | ||
4052 | &port, | ||
4053 | &new_channel, | ||
4054 | NULL, | ||
4055 | NULL, | ||
4056 | &clean_channel, | ||
4057 | handlers); | ||
4058 | policy = NULL; | ||
4059 | if (GNUNET_OK != | ||
4060 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
4061 | "exit", | ||
4062 | "EXIT_RANGE_IPV6_POLICY", | ||
4063 | &policy)) | ||
4064 | regex = NULL; | ||
4065 | else | ||
4066 | regex = GNUNET_TUN_ipv6policy2regex (policy); | ||
4067 | GNUNET_free_non_null (policy); | ||
4068 | if (NULL != regex) | ||
3949 | { | 4069 | { |
3950 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_IPV6_GATEWAY, | 4070 | (void) GNUNET_asprintf (&prefixed_regex, |
3951 | strlen(GNUNET_APPLICATION_PORT_IPV6_GATEWAY), | 4071 | "%s%s", |
3952 | &port); | 4072 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
3953 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 4073 | regex); |
3954 | "Opening CADET port %s for IPv6 gateway service\n", | 4074 | regex6 = GNUNET_REGEX_announce (cfg, |
3955 | GNUNET_h2s(&port)); | 4075 | prefixed_regex, |
3956 | cadet_port6 = GNUNET_CADET_open_port(cadet_handle, | 4076 | REGEX_REFRESH_FREQUENCY, |
3957 | &port, | 4077 | REGEX_MAX_PATH_LEN_IPV6); |
3958 | &new_channel, | 4078 | GNUNET_free (regex); |
3959 | NULL, | 4079 | GNUNET_free (prefixed_regex); |
3960 | NULL, | ||
3961 | &clean_channel, | ||
3962 | handlers); | ||
3963 | policy = NULL; | ||
3964 | if (GNUNET_OK != | ||
3965 | GNUNET_CONFIGURATION_get_value_string(cfg, | ||
3966 | "exit", | ||
3967 | "EXIT_RANGE_IPV6_POLICY", | ||
3968 | &policy)) | ||
3969 | regex = NULL; | ||
3970 | else | ||
3971 | regex = GNUNET_TUN_ipv6policy2regex(policy); | ||
3972 | GNUNET_free_non_null(policy); | ||
3973 | if (NULL != regex) | ||
3974 | { | ||
3975 | (void)GNUNET_asprintf(&prefixed_regex, | ||
3976 | "%s%s", | ||
3977 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | ||
3978 | regex); | ||
3979 | regex6 = GNUNET_REGEX_announce(cfg, | ||
3980 | prefixed_regex, | ||
3981 | REGEX_REFRESH_FREQUENCY, | ||
3982 | REGEX_MAX_PATH_LEN_IPV6); | ||
3983 | GNUNET_free(regex); | ||
3984 | GNUNET_free(prefixed_regex); | ||
3985 | } | ||
3986 | } | 4080 | } |
3987 | helper_handle = GNUNET_HELPER_start(GNUNET_NO, | 4081 | } |
3988 | binary, | 4082 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, |
3989 | exit_argv, | 4083 | binary, |
3990 | &message_token, | 4084 | exit_argv, |
3991 | NULL, | 4085 | &message_token, |
3992 | NULL); | 4086 | NULL, |
3993 | GNUNET_free(binary); | 4087 | NULL); |
4088 | GNUNET_free (binary); | ||
3994 | } | 4089 | } |
3995 | 4090 | ||
3996 | 4091 | ||
@@ -4002,28 +4097,29 @@ run(void *cls, | |||
4002 | * @return 0 ok, 1 on error | 4097 | * @return 0 ok, 1 on error |
4003 | */ | 4098 | */ |
4004 | int | 4099 | int |
4005 | main(int argc, | 4100 | main (int argc, |
4006 | char *const *argv) | 4101 | char *const *argv) |
4007 | { | 4102 | { |
4008 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 4103 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
4009 | GNUNET_GETOPT_OPTION_END | 4104 | GNUNET_GETOPT_OPTION_END |
4010 | }; | 4105 | }; |
4011 | 4106 | ||
4012 | if (GNUNET_OK != | 4107 | if (GNUNET_OK != |
4013 | GNUNET_STRINGS_get_utf8_args(argc, | 4108 | GNUNET_STRINGS_get_utf8_args (argc, |
4014 | argv, | 4109 | argv, |
4015 | &argc, | 4110 | &argc, |
4016 | &argv)) | 4111 | &argv)) |
4017 | return 2; | 4112 | return 2; |
4018 | 4113 | ||
4019 | return (GNUNET_OK == | 4114 | return (GNUNET_OK == |
4020 | GNUNET_PROGRAM_run(argc, | 4115 | GNUNET_PROGRAM_run (argc, |
4021 | argv, | 4116 | argv, |
4022 | "gnunet-daemon-exit", | 4117 | "gnunet-daemon-exit", |
4023 | gettext_noop("Daemon to run to provide an IP exit node for the VPN"), | 4118 | gettext_noop ( |
4024 | options, | 4119 | "Daemon to run to provide an IP exit node for the VPN"), |
4025 | &run, | 4120 | options, |
4026 | NULL)) ? global_ret : 1; | 4121 | &run, |
4122 | NULL)) ? global_ret : 1; | ||
4027 | } | 4123 | } |
4028 | 4124 | ||
4029 | 4125 | ||