diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-13 19:32:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-13 19:32:02 +0000 |
commit | e00e6a9687028f1e7a31ede8d413ecc981d6bf64 (patch) | |
tree | 5e49dcddec8eea244bde7dfc6926ab8b3114b0c6 /src/nat/nat.c | |
parent | f8013637fe0f9ec3b0d00fc81960321c56fc0f19 (diff) | |
download | gnunet-e00e6a9687028f1e7a31ede8d413ecc981d6bf64.tar.gz gnunet-e00e6a9687028f1e7a31ede8d413ecc981d6bf64.zip |
-doxygen, indentation, fixing comments
Diffstat (limited to 'src/nat/nat.c')
-rw-r--r-- | src/nat/nat.c | 210 |
1 files changed, 122 insertions, 88 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c index 6e55e3bc7..1d2afdfbd 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -64,36 +64,36 @@ | |||
64 | */ | 64 | */ |
65 | enum LocalAddressSource | 65 | enum LocalAddressSource |
66 | { | 66 | { |
67 | /** | 67 | /** |
68 | * Address was obtained by DNS resolution of the external hostname | 68 | * Address was obtained by DNS resolution of the external hostname |
69 | * given in the configuration (i.e. hole-punched DynDNS setup). | 69 | * given in the configuration (i.e. hole-punched DynDNS setup). |
70 | */ | 70 | */ |
71 | LAL_EXTERNAL_IP, | 71 | LAL_EXTERNAL_IP, |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Address was obtained by looking up our own hostname in DNS. | 74 | * Address was obtained by looking up our own hostname in DNS. |
75 | */ | 75 | */ |
76 | LAL_HOSTNAME_DNS, | 76 | LAL_HOSTNAME_DNS, |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Address was obtained by scanning our hosts's network interfaces | 79 | * Address was obtained by scanning our hosts's network interfaces |
80 | * and taking their address (no DNS involved). | 80 | * and taking their address (no DNS involved). |
81 | */ | 81 | */ |
82 | LAL_INTERFACE_ADDRESS, | 82 | LAL_INTERFACE_ADDRESS, |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Addresses we were explicitly bound to. | 85 | * Addresses we were explicitly bound to. |
86 | */ | 86 | */ |
87 | LAL_BINDTO_ADDRESS, | 87 | LAL_BINDTO_ADDRESS, |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Addresses from UPnP or PMP | 90 | * Addresses from UPnP or PMP |
91 | */ | 91 | */ |
92 | LAL_UPNP, | 92 | LAL_UPNP, |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * End of the list. | 95 | * End of the list. |
96 | */ | 96 | */ |
97 | LAL_END | 97 | LAL_END |
98 | }; | 98 | }; |
99 | 99 | ||
@@ -181,7 +181,7 @@ struct GNUNET_NAT_Handle | |||
181 | GNUNET_NAT_ReversalCallback reversal_callback; | 181 | GNUNET_NAT_ReversalCallback reversal_callback; |
182 | 182 | ||
183 | /** | 183 | /** |
184 | * Closure for 'callback'. | 184 | * Closure for callbacks (@e address_callback and @e reversal_callback) |
185 | */ | 185 | */ |
186 | void *callback_cls; | 186 | void *callback_cls; |
187 | 187 | ||
@@ -272,7 +272,7 @@ struct GNUNET_NAT_Handle | |||
272 | struct sockaddr **local_addrs; | 272 | struct sockaddr **local_addrs; |
273 | 273 | ||
274 | /** | 274 | /** |
275 | * Length of the 'local_addrs'. | 275 | * Length of the @e local_addrs. |
276 | */ | 276 | */ |
277 | socklen_t *local_addrlens; | 277 | socklen_t *local_addrlens; |
278 | 278 | ||
@@ -407,8 +407,8 @@ remove_from_address_list_by_source (struct GNUNET_NAT_Handle *h, | |||
407 | * | 407 | * |
408 | * @param h handle to NAT | 408 | * @param h handle to NAT |
409 | * @param src where did the local address originate from? | 409 | * @param src where did the local address originate from? |
410 | * @param arg the address, some 'struct sockaddr' | 410 | * @param arg the address, some `struct sockaddr` |
411 | * @param arg_size number of bytes in arg | 411 | * @param arg_size number of bytes in @a arg |
412 | */ | 412 | */ |
413 | static void | 413 | static void |
414 | add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, | 414 | add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, |
@@ -422,8 +422,10 @@ add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, | |||
422 | lal->addrlen = arg_size; | 422 | lal->addrlen = arg_size; |
423 | lal->source = src; | 423 | lal->source = src; |
424 | GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal); | 424 | GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal); |
425 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address `%s' from source %d\n", | 425 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
426 | GNUNET_a2s (arg, arg_size), src); | 426 | "Adding address `%s' from source %d\n", |
427 | GNUNET_a2s (arg, arg_size), | ||
428 | src); | ||
427 | if (NULL != h->address_callback) | 429 | if (NULL != h->address_callback) |
428 | h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size); | 430 | h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size); |
429 | } | 431 | } |
@@ -437,12 +439,14 @@ add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, | |||
437 | * | 439 | * |
438 | * @param h handle to NAT | 440 | * @param h handle to NAT |
439 | * @param src where did the local address originate from? | 441 | * @param src where did the local address originate from? |
440 | * @param arg the address, some 'struct sockaddr' | 442 | * @param arg the address, some `struct sockaddr` |
441 | * @param arg_size number of bytes in arg | 443 | * @param arg_size number of bytes in @a arg |
442 | */ | 444 | */ |
443 | static void | 445 | static void |
444 | add_to_address_list (struct GNUNET_NAT_Handle *h, enum LocalAddressSource src, | 446 | add_to_address_list (struct GNUNET_NAT_Handle *h, |
445 | const struct sockaddr *arg, socklen_t arg_size) | 447 | enum LocalAddressSource src, |
448 | const struct sockaddr *arg, | ||
449 | socklen_t arg_size) | ||
446 | { | 450 | { |
447 | struct sockaddr_in s4; | 451 | struct sockaddr_in s4; |
448 | const struct sockaddr_in *in4; | 452 | const struct sockaddr_in *in4; |
@@ -488,7 +492,7 @@ add_to_address_list (struct GNUNET_NAT_Handle *h, enum LocalAddressSource src, | |||
488 | * | 492 | * |
489 | * @param h handle to NAT | 493 | * @param h handle to NAT |
490 | * @param src where did the local address originate from? | 494 | * @param src where did the local address originate from? |
491 | * @param addr the address, some 'struct in_addr' or 'struct in6_addr' | 495 | * @param addr the address, some `struct in_addr` or `struct in6_addr` |
492 | * @param addrlen number of bytes in addr | 496 | * @param addrlen number of bytes in addr |
493 | */ | 497 | */ |
494 | static void | 498 | static void |
@@ -560,23 +564,28 @@ resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
560 | * Our (external) hostname was resolved and the configuration says that | 564 | * Our (external) hostname was resolved and the configuration says that |
561 | * the NAT was hole-punched. | 565 | * the NAT was hole-punched. |
562 | * | 566 | * |
563 | * @param cls the 'struct Plugin' | 567 | * @param cls the `struct GNUNET_NAT_Handle` |
564 | * @param addr NULL on error, otherwise result of DNS lookup | 568 | * @param addr NULL on error, otherwise result of DNS lookup |
565 | * @param addrlen number of bytes in addr | 569 | * @param addrlen number of bytes in @a addr |
566 | */ | 570 | */ |
567 | static void | 571 | static void |
568 | process_external_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen) | 572 | process_external_ip (void *cls, |
573 | const struct sockaddr *addr, | ||
574 | socklen_t addrlen) | ||
569 | { | 575 | { |
570 | struct GNUNET_NAT_Handle *h = cls; | 576 | struct GNUNET_NAT_Handle *h = cls; |
571 | struct in_addr dummy; | 577 | struct in_addr dummy; |
572 | 578 | ||
573 | if (addr == NULL) | 579 | if (NULL == addr) |
574 | { | 580 | { |
575 | h->ext_dns = NULL; | 581 | h->ext_dns = NULL; |
576 | if (1 == inet_pton (AF_INET, h->external_address, &dummy)) | 582 | if (1 == inet_pton (AF_INET, |
583 | h->external_address, | ||
584 | &dummy)) | ||
577 | return; /* repated lookup pointless: was numeric! */ | 585 | return; /* repated lookup pointless: was numeric! */ |
578 | h->dns_task = | 586 | h->dns_task = |
579 | GNUNET_SCHEDULER_add_delayed (h->dyndns_frequency, &resolve_dns, h); | 587 | GNUNET_SCHEDULER_add_delayed (h->dyndns_frequency, |
588 | &resolve_dns, h); | ||
580 | return; | 589 | return; |
581 | } | 590 | } |
582 | add_to_address_list (h, LAL_EXTERNAL_IP, addr, addrlen); | 591 | add_to_address_list (h, LAL_EXTERNAL_IP, addr, addrlen); |
@@ -590,7 +599,8 @@ process_external_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen) | |||
590 | * @param tc scheduler context | 599 | * @param tc scheduler context |
591 | */ | 600 | */ |
592 | static void | 601 | static void |
593 | resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 602 | resolve_hostname (void *cls, |
603 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
594 | 604 | ||
595 | 605 | ||
596 | /** | 606 | /** |
@@ -600,14 +610,16 @@ resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
600 | * | 610 | * |
601 | * @param cls closure | 611 | * @param cls closure |
602 | * @param addr one of the addresses of the host, NULL for the last address | 612 | * @param addr one of the addresses of the host, NULL for the last address |
603 | * @param addrlen length of the address | 613 | * @param addrlen length of the @a addr |
604 | */ | 614 | */ |
605 | static void | 615 | static void |
606 | process_hostname_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen) | 616 | process_hostname_ip (void *cls, |
617 | const struct sockaddr *addr, | ||
618 | socklen_t addrlen) | ||
607 | { | 619 | { |
608 | struct GNUNET_NAT_Handle *h = cls; | 620 | struct GNUNET_NAT_Handle *h = cls; |
609 | 621 | ||
610 | if (addr == NULL) | 622 | if (NULL == addr) |
611 | { | 623 | { |
612 | h->hostname_dns = NULL; | 624 | h->hostname_dns = NULL; |
613 | h->hostname_task = | 625 | h->hostname_task = |
@@ -623,14 +635,14 @@ process_hostname_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen) | |||
623 | * Add the IP of our network interface to the list of | 635 | * Add the IP of our network interface to the list of |
624 | * our IP addresses. | 636 | * our IP addresses. |
625 | * | 637 | * |
626 | * @param cls the 'struct GNUNET_NAT_Handle' | 638 | * @param cls the `struct GNUNET_NAT_Handle` |
627 | * @param name name of the interface | 639 | * @param name name of the interface |
628 | * @param isDefault do we think this may be our default interface | 640 | * @param isDefault do we think this may be our default interface |
629 | * @param addr address of the interface | 641 | * @param addr address of the interface |
630 | * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) | 642 | * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) |
631 | * @param netmask the network mask (can be NULL for unknown or unassigned)) | 643 | * @param netmask the network mask (can be NULL for unknown or unassigned)) |
632 | * @param addrlen number of bytes in addr | 644 | * @param addrlen number of bytes in @a addr and @a broadcast_addr |
633 | * @return GNUNET_OK to continue iterating | 645 | * @return #GNUNET_OK to continue iterating |
634 | */ | 646 | */ |
635 | static int | 647 | static int |
636 | process_interfaces (void *cls, const char *name, int isDefault, | 648 | process_interfaces (void *cls, const char *name, int isDefault, |
@@ -745,7 +757,7 @@ process_interfaces (void *cls, const char *name, int isDefault, | |||
745 | * Task that restarts the gnunet-helper-nat-server process after a crash | 757 | * Task that restarts the gnunet-helper-nat-server process after a crash |
746 | * after a certain delay. | 758 | * after a certain delay. |
747 | * | 759 | * |
748 | * @param cls the 'struct GNUNET_NAT_Handle' | 760 | * @param cls the `struct GNUNET_NAT_Handle` |
749 | * @param tc scheduler context | 761 | * @param tc scheduler context |
750 | */ | 762 | */ |
751 | static void | 763 | static void |
@@ -754,22 +766,23 @@ restart_nat_server (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
754 | struct GNUNET_NAT_Handle *h = cls; | 766 | struct GNUNET_NAT_Handle *h = cls; |
755 | 767 | ||
756 | h->server_read_task = GNUNET_SCHEDULER_NO_TASK; | 768 | h->server_read_task = GNUNET_SCHEDULER_NO_TASK; |
757 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 769 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
758 | return; | 770 | return; |
759 | start_gnunet_nat_server (h); | 771 | start_gnunet_nat_server (h); |
760 | } | 772 | } |
761 | 773 | ||
762 | 774 | ||
763 | /** | 775 | /** |
764 | * We have been notified that gnunet-helper-nat-server has written something to stdout. | 776 | * We have been notified that gnunet-helper-nat-server has written |
765 | * Handle the output, then reschedule this function to be called again once | 777 | * something to stdout. Handle the output, then reschedule this |
766 | * more is available. | 778 | * function to be called again once more is available. |
767 | * | 779 | * |
768 | * @param cls the NAT handle | 780 | * @param cls the NAT handle |
769 | * @param tc the scheduling context | 781 | * @param tc the scheduling context |
770 | */ | 782 | */ |
771 | static void | 783 | static void |
772 | nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 784 | nat_server_read (void *cls, |
785 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
773 | { | 786 | { |
774 | struct GNUNET_NAT_Handle *h = cls; | 787 | struct GNUNET_NAT_Handle *h = cls; |
775 | char mybuf[40]; | 788 | char mybuf[40]; |
@@ -784,11 +797,12 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
784 | return; | 797 | return; |
785 | memset (mybuf, 0, sizeof (mybuf)); | 798 | memset (mybuf, 0, sizeof (mybuf)); |
786 | bytes = | 799 | bytes = |
787 | GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf)); | 800 | GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf)); |
788 | if (bytes < 1) | 801 | if (bytes < 1) |
789 | { | 802 | { |
790 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 803 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
791 | "Finished reading from server stdout with code: %d\n", bytes); | 804 | "Finished reading from server stdout with code: %d\n", |
805 | bytes); | ||
792 | if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG)) | 806 | if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG)) |
793 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill"); | 807 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill"); |
794 | GNUNET_OS_process_wait (h->server_proc); | 808 | GNUNET_OS_process_wait (h->server_proc); |
@@ -907,7 +921,8 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h) | |||
907 | * @param tc scheduler context | 921 | * @param tc scheduler context |
908 | */ | 922 | */ |
909 | static void | 923 | static void |
910 | list_interfaces (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 924 | list_interfaces (void *cls, |
925 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
911 | { | 926 | { |
912 | struct GNUNET_NAT_Handle *h = cls; | 927 | struct GNUNET_NAT_Handle *h = cls; |
913 | 928 | ||
@@ -915,7 +930,8 @@ list_interfaces (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
915 | remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS); | 930 | remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS); |
916 | GNUNET_OS_network_interfaces_list (&process_interfaces, h); | 931 | GNUNET_OS_network_interfaces_list (&process_interfaces, h); |
917 | h->ifc_task = | 932 | h->ifc_task = |
918 | GNUNET_SCHEDULER_add_delayed (h->ifc_scan_frequency, &list_interfaces, h); | 933 | GNUNET_SCHEDULER_add_delayed (h->ifc_scan_frequency, |
934 | &list_interfaces, h); | ||
919 | } | 935 | } |
920 | 936 | ||
921 | 937 | ||
@@ -926,7 +942,8 @@ list_interfaces (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
926 | * @param tc scheduler context | 942 | * @param tc scheduler context |
927 | */ | 943 | */ |
928 | static void | 944 | static void |
929 | resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 945 | resolve_hostname (void *cls, |
946 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
930 | { | 947 | { |
931 | struct GNUNET_NAT_Handle *h = cls; | 948 | struct GNUNET_NAT_Handle *h = cls; |
932 | 949 | ||
@@ -946,30 +963,34 @@ resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
946 | * @param tc scheduler context | 963 | * @param tc scheduler context |
947 | */ | 964 | */ |
948 | static void | 965 | static void |
949 | resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 966 | resolve_dns (void *cls, |
967 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
950 | { | 968 | { |
951 | struct GNUNET_NAT_Handle *h = cls; | 969 | struct GNUNET_NAT_Handle *h = cls; |
952 | 970 | ||
953 | h->dns_task = GNUNET_SCHEDULER_NO_TASK; | 971 | h->dns_task = GNUNET_SCHEDULER_NO_TASK; |
972 | /* NOTE #3213, bugnote #7878 */ | ||
954 | remove_from_address_list_by_source (h, LAL_EXTERNAL_IP); | 973 | remove_from_address_list_by_source (h, LAL_EXTERNAL_IP); |
955 | h->ext_dns = | 974 | h->ext_dns = |
956 | GNUNET_RESOLVER_ip_get (h->external_address, AF_INET, | 975 | GNUNET_RESOLVER_ip_get (h->external_address, AF_INET, |
957 | GNUNET_TIME_UNIT_MINUTES, &process_external_ip, | 976 | GNUNET_TIME_UNIT_MINUTES, |
958 | h); | 977 | &process_external_ip, h); |
959 | } | 978 | } |
960 | 979 | ||
961 | 980 | ||
962 | /** | 981 | /** |
963 | * Add or remove UPnP-mapped addresses. | 982 | * Add or remove UPnP-mapped addresses. |
964 | * | 983 | * |
965 | * @param cls the GNUNET_NAT_Handle | 984 | * @param cls the `struct GNUNET_NAT_Handle` |
966 | * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean | 985 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean |
967 | * the previous (now invalid) one | 986 | * the previous (now invalid) one |
968 | * @param addr either the previous or the new public IP address | 987 | * @param addr either the previous or the new public IP address |
969 | * @param addrlen actual lenght of the address | 988 | * @param addrlen actual lenght of @a addr |
970 | */ | 989 | */ |
971 | static void | 990 | static void |
972 | upnp_add (void *cls, int add_remove, const struct sockaddr *addr, | 991 | upnp_add (void *cls, |
992 | int add_remove, | ||
993 | const struct sockaddr *addr, | ||
973 | socklen_t addrlen) | 994 | socklen_t addrlen) |
974 | { | 995 | { |
975 | struct GNUNET_NAT_Handle *h = cls; | 996 | struct GNUNET_NAT_Handle *h = cls; |
@@ -1008,7 +1029,8 @@ upnp_add (void *cls, int add_remove, const struct sockaddr *addr, | |||
1008 | * @param port port to map with UPnP | 1029 | * @param port port to map with UPnP |
1009 | */ | 1030 | */ |
1010 | static void | 1031 | static void |
1011 | add_minis (struct GNUNET_NAT_Handle *h, uint16_t port) | 1032 | add_minis (struct GNUNET_NAT_Handle *h, |
1033 | uint16_t port) | ||
1012 | { | 1034 | { |
1013 | struct MiniList *ml; | 1035 | struct MiniList *ml; |
1014 | 1036 | ||
@@ -1019,7 +1041,7 @@ add_minis (struct GNUNET_NAT_Handle *h, uint16_t port) | |||
1019 | return; /* already got this port */ | 1041 | return; /* already got this port */ |
1020 | ml = ml->next; | 1042 | ml = ml->next; |
1021 | } | 1043 | } |
1022 | ml = GNUNET_malloc (sizeof (struct MiniList)); | 1044 | ml = GNUNET_new (struct MiniList); |
1023 | ml->port = port; | 1045 | ml->port = port; |
1024 | ml->mini = GNUNET_NAT_mini_map_start (port, h->is_tcp, &upnp_add, h); | 1046 | ml->mini = GNUNET_NAT_mini_map_start (port, h->is_tcp, &upnp_add, h); |
1025 | GNUNET_CONTAINER_DLL_insert (h->mini_head, h->mini_tail, ml); | 1047 | GNUNET_CONTAINER_DLL_insert (h->mini_head, h->mini_tail, ml); |
@@ -1033,7 +1055,8 @@ add_minis (struct GNUNET_NAT_Handle *h, uint16_t port) | |||
1033 | * @param tc scheduler context | 1055 | * @param tc scheduler context |
1034 | */ | 1056 | */ |
1035 | static void | 1057 | static void |
1036 | add_from_bind (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1058 | add_from_bind (void *cls, |
1059 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1037 | { | 1060 | { |
1038 | static struct in6_addr any = IN6ADDR_ANY_INIT; | 1061 | static struct in6_addr any = IN6ADDR_ANY_INIT; |
1039 | struct GNUNET_NAT_Handle *h = cls; | 1062 | struct GNUNET_NAT_Handle *h = cls; |
@@ -1087,7 +1110,7 @@ add_from_bind (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1087 | * is taken from the corresponding sockaddr_in[6] field. | 1110 | * is taken from the corresponding sockaddr_in[6] field. |
1088 | * | 1111 | * |
1089 | * @param cfg configuration to use | 1112 | * @param cfg configuration to use |
1090 | * @param is_tcp GNUNET_YES for TCP, GNUNET_NO for UDP | 1113 | * @param is_tcp #GNUNET_YES for TCP, #GNUNET_NO for UDP |
1091 | * @param adv_port advertised port (port we are either bound to or that our OS | 1114 | * @param adv_port advertised port (port we are either bound to or that our OS |
1092 | * locally performs redirection from to our bound port). | 1115 | * locally performs redirection from to our bound port). |
1093 | * @param num_addrs number of addresses in 'addrs' | 1116 | * @param num_addrs number of addresses in 'addrs' |
@@ -1099,9 +1122,12 @@ add_from_bind (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1099 | * @return NULL on error, otherwise handle that can be used to unregister | 1122 | * @return NULL on error, otherwise handle that can be used to unregister |
1100 | */ | 1123 | */ |
1101 | struct GNUNET_NAT_Handle * | 1124 | struct GNUNET_NAT_Handle * |
1102 | GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp, | 1125 | GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1103 | uint16_t adv_port, unsigned int num_addrs, | 1126 | int is_tcp, |
1104 | const struct sockaddr **addrs, const socklen_t * addrlens, | 1127 | uint16_t adv_port, |
1128 | unsigned int num_addrs, | ||
1129 | const struct sockaddr **addrs, | ||
1130 | const socklen_t * addrlens, | ||
1105 | GNUNET_NAT_AddressCallback address_callback, | 1131 | GNUNET_NAT_AddressCallback address_callback, |
1106 | GNUNET_NAT_ReversalCallback reversal_callback, | 1132 | GNUNET_NAT_ReversalCallback reversal_callback, |
1107 | void *callback_cls) | 1133 | void *callback_cls) |
@@ -1114,7 +1140,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp, | |||
1114 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1140 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1115 | "Registered with NAT service at port %u with %u IP bound local addresses\n", | 1141 | "Registered with NAT service at port %u with %u IP bound local addresses\n", |
1116 | (unsigned int) adv_port, num_addrs); | 1142 | (unsigned int) adv_port, num_addrs); |
1117 | h = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle)); | 1143 | h = GNUNET_new (struct GNUNET_NAT_Handle); |
1118 | h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS; | 1144 | h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS; |
1119 | h->cfg = cfg; | 1145 | h->cfg = cfg; |
1120 | h->is_tcp = is_tcp; | 1146 | h->is_tcp = is_tcp; |
@@ -1266,7 +1292,7 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h) | |||
1266 | GNUNET_NAT_mini_map_stop (ml->mini); | 1292 | GNUNET_NAT_mini_map_stop (ml->mini); |
1267 | GNUNET_free (ml); | 1293 | GNUNET_free (ml); |
1268 | } | 1294 | } |
1269 | if (h->ext_dns != NULL) | 1295 | if (NULL != h->ext_dns) |
1270 | { | 1296 | { |
1271 | GNUNET_RESOLVER_request_cancel (h->ext_dns); | 1297 | GNUNET_RESOLVER_request_cancel (h->ext_dns); |
1272 | h->ext_dns = NULL; | 1298 | h->ext_dns = NULL; |
@@ -1341,8 +1367,10 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h) | |||
1341 | * gnunet-helper-nat-client to send dummy ICMP responses to cause | 1367 | * gnunet-helper-nat-client to send dummy ICMP responses to cause |
1342 | * that peer to connect to us (connection reversal). | 1368 | * that peer to connect to us (connection reversal). |
1343 | * | 1369 | * |
1344 | * @return GNUNET_SYSERR on error, GNUNET_NO if nat client is disabled, | 1370 | * @param h handle (used for configuration) |
1345 | * GNUNET_OK otherwise | 1371 | * @param sa the address of the peer (IPv4-only) |
1372 | * @return #GNUNET_SYSERR on error, #GNUNET_NO if nat client is disabled, | ||
1373 | * #GNUNET_OK otherwise | ||
1346 | */ | 1374 | */ |
1347 | int | 1375 | int |
1348 | GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, | 1376 | GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, |
@@ -1361,25 +1389,32 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, | |||
1361 | if (h->internal_address == NULL) | 1389 | if (h->internal_address == NULL) |
1362 | { | 1390 | { |
1363 | LOG (GNUNET_ERROR_TYPE_WARNING, "nat", | 1391 | LOG (GNUNET_ERROR_TYPE_WARNING, "nat", |
1364 | _ | 1392 | _("Internal IP address not known, cannot use ICMP NAT traversal method\n")); |
1365 | ("Internal IP address not known, cannot use ICMP NAT traversal method\n")); | ||
1366 | return GNUNET_SYSERR; | 1393 | return GNUNET_SYSERR; |
1367 | } | 1394 | } |
1368 | GNUNET_assert (sa->sin_family == AF_INET); | 1395 | GNUNET_assert (sa->sin_family == AF_INET); |
1369 | if (NULL == inet_ntop (AF_INET, &sa->sin_addr, inet4, INET_ADDRSTRLEN)) | 1396 | if (NULL == inet_ntop (AF_INET, &sa->sin_addr, inet4, INET_ADDRSTRLEN)) |
1370 | { | 1397 | { |
1371 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "inet_ntop"); | 1398 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, |
1399 | "nat", | ||
1400 | "inet_ntop"); | ||
1372 | return GNUNET_SYSERR; | 1401 | return GNUNET_SYSERR; |
1373 | } | 1402 | } |
1374 | GNUNET_snprintf (port_as_string, sizeof (port_as_string), "%d", h->adv_port); | 1403 | GNUNET_snprintf (port_as_string, |
1404 | sizeof (port_as_string), | ||
1405 | "%d", | ||
1406 | h->adv_port); | ||
1375 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1407 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1376 | _("Running gnunet-helper-nat-client %s %s %u\n"), h->internal_address, | 1408 | _("Running gnunet-helper-nat-client %s %s %u\n"), |
1377 | inet4, (unsigned int) h->adv_port); | 1409 | h->internal_address, |
1410 | inet4, | ||
1411 | (unsigned int) h->adv_port); | ||
1378 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); | 1412 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); |
1379 | proc = | 1413 | proc = |
1380 | GNUNET_OS_start_process (GNUNET_NO, 0, NULL, NULL, | 1414 | GNUNET_OS_start_process (GNUNET_NO, 0, NULL, NULL, |
1381 | binary, | 1415 | binary, |
1382 | "gnunet-helper-nat-client", h->internal_address, | 1416 | "gnunet-helper-nat-client", |
1417 | h->internal_address, | ||
1383 | inet4, port_as_string, NULL); | 1418 | inet4, port_as_string, NULL); |
1384 | GNUNET_free (binary); | 1419 | GNUNET_free (binary); |
1385 | if (NULL == proc) | 1420 | if (NULL == proc) |
@@ -1397,13 +1432,14 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, | |||
1397 | * | 1432 | * |
1398 | * @param h the handle returned by register | 1433 | * @param h the handle returned by register |
1399 | * @param addr IP address to test (IPv4 or IPv6) | 1434 | * @param addr IP address to test (IPv4 or IPv6) |
1400 | * @param addrlen number of bytes in addr | 1435 | * @param addrlen number of bytes in @a addr |
1401 | * @return GNUNET_YES if the address is plausible, | 1436 | * @return #GNUNET_YES if the address is plausible, |
1402 | * GNUNET_NO if the address is not plausible, | 1437 | * #GNUNET_NO if the address is not plausible, |
1403 | * GNUNET_SYSERR if the address is malformed | 1438 | * #GNUNET_SYSERR if the address is malformed |
1404 | */ | 1439 | */ |
1405 | int | 1440 | int |
1406 | GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr, | 1441 | GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, |
1442 | const void *addr, | ||
1407 | socklen_t addrlen) | 1443 | socklen_t addrlen) |
1408 | { | 1444 | { |
1409 | struct LocalAddressList *pos; | 1445 | struct LocalAddressList *pos; |
@@ -1416,8 +1452,7 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr, | |||
1416 | GNUNET_break (0); | 1452 | GNUNET_break (0); |
1417 | return GNUNET_SYSERR; | 1453 | return GNUNET_SYSERR; |
1418 | } | 1454 | } |
1419 | pos = h->lal_head; | 1455 | for (pos = h->lal_head; NULL != pos; pos = pos->next) |
1420 | while (NULL != pos) | ||
1421 | { | 1456 | { |
1422 | if (pos->addrlen == sizeof (struct sockaddr_in)) | 1457 | if (pos->addrlen == sizeof (struct sockaddr_in)) |
1423 | { | 1458 | { |
@@ -1437,7 +1472,6 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr, | |||
1437 | { | 1472 | { |
1438 | GNUNET_assert (0); | 1473 | GNUNET_assert (0); |
1439 | } | 1474 | } |
1440 | pos = pos->next; | ||
1441 | } | 1475 | } |
1442 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1476 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1443 | "Asked to validate one of my addresses and validation failed!\n"); | 1477 | "Asked to validate one of my addresses and validation failed!\n"); |