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