aboutsummaryrefslogtreecommitdiff
path: root/src/nat
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-13 19:32:02 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-13 19:32:02 +0000
commite00e6a9687028f1e7a31ede8d413ecc981d6bf64 (patch)
tree5e49dcddec8eea244bde7dfc6926ab8b3114b0c6 /src/nat
parentf8013637fe0f9ec3b0d00fc81960321c56fc0f19 (diff)
downloadgnunet-e00e6a9687028f1e7a31ede8d413ecc981d6bf64.tar.gz
gnunet-e00e6a9687028f1e7a31ede8d413ecc981d6bf64.zip
-doxygen, indentation, fixing comments
Diffstat (limited to 'src/nat')
-rw-r--r--src/nat/nat.c210
-rw-r--r--src/nat/nat_auto.c38
-rw-r--r--src/nat/nat_test.c30
3 files changed, 162 insertions, 116 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 */
65enum LocalAddressSource 65enum 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 */
413static void 413static void
414add_to_address_list_as_is (struct GNUNET_NAT_Handle *h, 414add_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 */
443static void 445static void
444add_to_address_list (struct GNUNET_NAT_Handle *h, enum LocalAddressSource src, 446add_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 */
494static void 498static 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 */
567static void 571static void
568process_external_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen) 572process_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 */
592static void 601static void
593resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 602resolve_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 */
605static void 615static void
606process_hostname_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen) 616process_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 */
635static int 647static int
636process_interfaces (void *cls, const char *name, int isDefault, 648process_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 */
751static void 763static 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 */
771static void 783static void
772nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 784nat_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 */
909static void 923static void
910list_interfaces (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 924list_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 */
928static void 944static void
929resolve_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 945resolve_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 */
948static void 965static void
949resolve_dns (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 966resolve_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 */
971static void 990static void
972upnp_add (void *cls, int add_remove, const struct sockaddr *addr, 991upnp_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 */
1010static void 1031static void
1011add_minis (struct GNUNET_NAT_Handle *h, uint16_t port) 1032add_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 */
1035static void 1057static void
1036add_from_bind (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1058add_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 */
1101struct GNUNET_NAT_Handle * 1124struct GNUNET_NAT_Handle *
1102GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp, 1125GNUNET_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 */
1347int 1375int
1348GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, 1376GNUNET_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 */
1405int 1440int
1406GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr, 1441GNUNET_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");
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c
index 3d0040a04..9e7ff23f2 100644
--- a/src/nat/nat_auto.c
+++ b/src/nat/nat_auto.c
@@ -107,7 +107,7 @@ struct GNUNET_NAT_AutoHandle
107 GNUNET_NAT_AutoResultCallback fin_cb; 107 GNUNET_NAT_AutoResultCallback fin_cb;
108 108
109 /** 109 /**
110 * Closure for 'fin_cb'. 110 * Closure for @e fin_cb.
111 */ 111 */
112 void *fin_cb_cls; 112 void *fin_cb_cls;
113 113
@@ -161,7 +161,8 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah);
161 * @param tc scheduler callback 161 * @param tc scheduler callback
162 */ 162 */
163static void 163static void
164fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 164fail_timeout (void *cls,
165 const struct GNUNET_SCHEDULER_TaskContext *tc)
165{ 166{
166 struct GNUNET_NAT_AutoHandle *ah = cls; 167 struct GNUNET_NAT_AutoHandle *ah = cls;
167 168
@@ -183,7 +184,7 @@ fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
183 * Clean up and update GUI (with success). 184 * Clean up and update GUI (with success).
184 * 185 *
185 * @param cls the auto handle 186 * @param cls the auto handle
186 * @param success currently always GNUNET_OK 187 * @param success currently always #GNUNET_OK
187 */ 188 */
188static void 189static void
189result_callback (void *cls, int success) 190result_callback (void *cls, int success)
@@ -203,14 +204,16 @@ result_callback (void *cls, int success)
203 next_phase (ah); 204 next_phase (ah);
204} 205}
205 206
207
206/** 208/**
207 * Main function for the connection reversal test. 209 * Main function for the connection reversal test.
208 * 210 *
209 * @param cls the 'int*' for the result 211 * @param cls the `struct GNUNET_NAT_AutoHandle`
210 * @param tc scheduler context 212 * @param tc scheduler context
211 */ 213 */
212static void 214static void
213reversal_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 215reversal_test (void *cls,
216 const struct GNUNET_SCHEDULER_TaskContext *tc)
214{ 217{
215 struct GNUNET_NAT_AutoHandle *ah = cls; 218 struct GNUNET_NAT_AutoHandle *ah = cls;
216 219
@@ -249,7 +252,8 @@ test_online (struct GNUNET_NAT_AutoHandle *ah)
249 * @param addr the address, NULL on errors 252 * @param addr the address, NULL on errors
250 */ 253 */
251static void 254static void
252set_external_ipv4 (void *cls, const struct in_addr *addr) 255set_external_ipv4 (void *cls,
256 const struct in_addr *addr)
253{ 257{
254 struct GNUNET_NAT_AutoHandle *ah = cls; 258 struct GNUNET_NAT_AutoHandle *ah = cls;
255 char buf[INET_ADDRSTRLEN]; 259 char buf[INET_ADDRSTRLEN];
@@ -301,18 +305,22 @@ test_external_ip (struct GNUNET_NAT_AutoHandle *ah)
301 * Process list of local IP addresses. Find and set the 305 * Process list of local IP addresses. Find and set the
302 * one of the default interface. 306 * one of the default interface.
303 * 307 *
304 * @param cls our NAT auto handle 308 * @param cls our `struct GNUNET_NAT_AutoHandle`
305 * @param name name of the interface (can be NULL for unknown) 309 * @param name name of the interface (can be NULL for unknown)
306 * @param isDefault is this presumably the default interface 310 * @param isDefault is this presumably the default interface
307 * @param addr address of this interface (can be NULL for unknown or unassigned) 311 * @param addr address of this interface (can be NULL for unknown or unassigned)
308 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) 312 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
309 * @param netmask the network mask (can be NULL for unknown or unassigned)) 313 * @param netmask the network mask (can be NULL for unknown or unassigned))
310 * @param addrlen length of the address 314 * @param addrlen length of the @a addr and @a broadcast_addr
311 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort 315 * @return GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
312 */ 316 */
313static int 317static int
314nipo (void *cls, const char *name, int isDefault, const struct sockaddr *addr, 318nipo (void *cls,
315 const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, 319 const char *name,
320 int isDefault,
321 const struct sockaddr *addr,
322 const struct sockaddr *broadcast_addr,
323 const struct sockaddr *netmask,
316 socklen_t addrlen) 324 socklen_t addrlen)
317{ 325{
318 struct GNUNET_NAT_AutoHandle *ah = cls; 326 struct GNUNET_NAT_AutoHandle *ah = cls;
@@ -519,14 +527,13 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah)
519} 527}
520 528
521 529
522
523/** 530/**
524 * Start auto-configuration routine. The resolver service should 531 * Start auto-configuration routine. The resolver service should
525 * be available when this function is called. 532 * be available when this function is called.
526 * 533 *
527 * @param cfg initial configuration 534 * @param cfg initial configuration
528 * @param cb function to call with autoconfiguration result 535 * @param cb function to call with autoconfiguration result
529 * @param cb_cls closure for cb 536 * @param cb_cls closure for @a cb
530 * @return handle to cancel operation 537 * @return handle to cancel operation
531 */ 538 */
532struct GNUNET_NAT_AutoHandle * 539struct GNUNET_NAT_AutoHandle *
@@ -536,7 +543,7 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
536{ 543{
537 struct GNUNET_NAT_AutoHandle *ah; 544 struct GNUNET_NAT_AutoHandle *ah;
538 545
539 ah = GNUNET_malloc (sizeof (struct GNUNET_NAT_AutoHandle)); 546 ah = GNUNET_new (struct GNUNET_NAT_AutoHandle);
540 ah->fin_cb = cb; 547 ah->fin_cb = cb;
541 ah->fin_cb_cls = cb_cls; 548 ah->fin_cb_cls = cb_cls;
542 ah->cfg = GNUNET_CONFIGURATION_dup (cfg); 549 ah->cfg = GNUNET_CONFIGURATION_dup (cfg);
@@ -550,7 +557,7 @@ GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
550 return ah; 557 return ah;
551} 558}
552 559
553 560
554/** 561/**
555 * Abort autoconfiguration. 562 * Abort autoconfiguration.
556 * 563 *
@@ -580,5 +587,4 @@ GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah)
580} 587}
581 588
582 589
583
584/* end of nat_auto.c */ 590/* end of nat_auto.c */
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c
index 0cbb8abe5..c7de96d2f 100644
--- a/src/nat/nat_test.c
+++ b/src/nat/nat_test.c
@@ -195,7 +195,7 @@ reversal_cb (void *cls,
195 * Activity on our incoming socket. Read data from the 195 * Activity on our incoming socket. Read data from the
196 * incoming connection. 196 * incoming connection.
197 * 197 *
198 * @param cls the 'struct NatActivity' 198 * @param cls the `struct GNUNET_NAT_Test`
199 * @param tc scheduler context 199 * @param tc scheduler context
200 */ 200 */
201static void 201static void
@@ -205,7 +205,8 @@ do_udp_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
205 uint16_t data; 205 uint16_t data;
206 206
207 tst->ltask = 207 tst->ltask =
208 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock, 208 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
209 tst->lsock,
209 &do_udp_read, tst); 210 &do_udp_read, tst);
210 if ((NULL != tc->write_ready) && 211 if ((NULL != tc->write_ready) &&
211 (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) && 212 (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) &&
@@ -228,11 +229,12 @@ do_udp_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
228 * Activity on our incoming socket. Read data from the 229 * Activity on our incoming socket. Read data from the
229 * incoming connection. 230 * incoming connection.
230 * 231 *
231 * @param cls the 'struct NatActivity' 232 * @param cls the `struct NatActivity`
232 * @param tc scheduler context 233 * @param tc scheduler context
233 */ 234 */
234static void 235static void
235do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 236do_read (void *cls,
237 const struct GNUNET_SCHEDULER_TaskContext *tc)
236{ 238{
237 struct NatActivity *na = cls; 239 struct NatActivity *na = cls;
238 struct GNUNET_NAT_Test *tst; 240 struct GNUNET_NAT_Test *tst;
@@ -264,11 +266,12 @@ do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
264 * Activity on our listen socket. Accept the 266 * Activity on our listen socket. Accept the
265 * incoming connection. 267 * incoming connection.
266 * 268 *
267 * @param cls the 'struct GNUNET_NAT_Test' 269 * @param cls the `struct GNUNET_NAT_Test`
268 * @param tc scheduler context 270 * @param tc scheduler context
269 */ 271 */
270static void 272static void
271do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 273do_accept (void *cls,
274 const struct GNUNET_SCHEDULER_TaskContext *tc)
272{ 275{
273 struct GNUNET_NAT_Test *tst = cls; 276 struct GNUNET_NAT_Test *tst = cls;
274 struct GNUNET_NETWORK_Handle *s; 277 struct GNUNET_NETWORK_Handle *s;
@@ -288,7 +291,7 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
288 } 291 }
289 LOG (GNUNET_ERROR_TYPE_DEBUG, 292 LOG (GNUNET_ERROR_TYPE_DEBUG,
290 "Got an inbound connection, waiting for data\n"); 293 "Got an inbound connection, waiting for data\n");
291 wl = GNUNET_malloc (sizeof (struct NatActivity)); 294 wl = GNUNET_new (struct NatActivity);
292 wl->sock = s; 295 wl->sock = s;
293 wl->h = tst; 296 wl->h = tst;
294 wl->rtask = 297 wl->rtask =
@@ -305,7 +308,7 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
305 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean 308 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
306 * the previous (now invalid) one 309 * the previous (now invalid) one
307 * @param addr either the previous or the new public IP address 310 * @param addr either the previous or the new public IP address
308 * @param addrlen actual lenght of the address 311 * @param addrlen actual length of the @a addr
309 */ 312 */
310static void 313static void
311addr_cb (void *cls, 314addr_cb (void *cls,
@@ -345,7 +348,7 @@ addr_cb (void *cls,
345 _("Failed to connect to `gnunet-nat-server'\n")); 348 _("Failed to connect to `gnunet-nat-server'\n"));
346 return; 349 return;
347 } 350 }
348 ca = GNUNET_malloc (sizeof (struct ClientActivity)); 351 ca = GNUNET_new (struct ClientActivity);
349 ca->client = client; 352 ca->client = client;
350 GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca); 353 GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca);
351 GNUNET_break (GNUNET_OK == 354 GNUNET_break (GNUNET_OK ==
@@ -365,13 +368,16 @@ addr_cb (void *cls,
365 * @param bnd_port port to bind to, 0 for connection reversal 368 * @param bnd_port port to bind to, 0 for connection reversal
366 * @param adv_port externally advertised port to use 369 * @param adv_port externally advertised port to use
367 * @param report function to call with the result of the test 370 * @param report function to call with the result of the test
368 * @param report_cls closure for report 371 * @param report_cls closure for @a report
369 * @return handle to cancel NAT test 372 * @return handle to cancel NAT test
370 */ 373 */
371struct GNUNET_NAT_Test * 374struct GNUNET_NAT_Test *
372GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 375GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
373 int is_tcp, uint16_t bnd_port, uint16_t adv_port, 376 int is_tcp,
374 GNUNET_NAT_TestCallback report, void *report_cls) 377 uint16_t bnd_port,
378 uint16_t adv_port,
379 GNUNET_NAT_TestCallback report,
380 void *report_cls)
375{ 381{
376 struct GNUNET_NAT_Test *ret; 382 struct GNUNET_NAT_Test *ret;
377 struct sockaddr_in sa; 383 struct sockaddr_in sa;