aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-10 13:55:15 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-10 13:55:15 +0000
commit2d32b2ca9b0497490e4215a2c15d236b16a77f19 (patch)
treea2631ca253fff9acbfd7cd95fc4ab1e159e1d959 /src/nat/nat.c
parenta2939bc01a0ee9a002735f04d8c731130d7a3248 (diff)
downloadgnunet-2d32b2ca9b0497490e4215a2c15d236b16a77f19.tar.gz
gnunet-2d32b2ca9b0497490e4215a2c15d236b16a77f19.zip
use LOG macro in nat.c
Diffstat (limited to 'src/nat/nat.c')
-rw-r--r--src/nat/nat.c82
1 files changed, 40 insertions, 42 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c
index fc20fe54d..6e2011347 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -31,6 +31,8 @@
31#include "gnunet_nat_lib.h" 31#include "gnunet_nat_lib.h"
32#include "nat.h" 32#include "nat.h"
33 33
34#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
35
34/** 36/**
35 * How often do we scan for changes in our IP address from our local 37 * How often do we scan for changes in our IP address from our local
36 * interfaces? 38 * interfaces?
@@ -416,10 +418,8 @@ add_to_address_list_as_is (struct GNUNET_NAT_Handle *h,
416 lal->source = src; 418 lal->source = src;
417 GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal); 419 GNUNET_CONTAINER_DLL_insert (h->lal_head, h->lal_tail, lal);
418#if DEBUG_NAT 420#if DEBUG_NAT
419 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", 421 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address `%s' from source %d\n",
420 "Adding address `%s' from source %d\n", GNUNET_a2s (arg, 422 GNUNET_a2s (arg, arg_size), src);
421 arg_size),
422 src);
423#endif 423#endif
424 if (NULL != h->address_callback) 424 if (NULL != h->address_callback)
425 h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size); 425 h->address_callback (h->callback_cls, GNUNET_YES, arg, arg_size);
@@ -724,12 +724,11 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
724 if (bytes < 1) 724 if (bytes < 1)
725 { 725 {
726#if DEBUG_NAT 726#if DEBUG_NAT
727 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", 727 LOG (GNUNET_ERROR_TYPE_DEBUG,
728 "Finished reading from server stdout with code: %d\n", 728 "Finished reading from server stdout with code: %d\n", bytes);
729 bytes);
730#endif 729#endif
731 if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM)) 730 if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM))
732 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 731 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill");
733 GNUNET_OS_process_wait (h->server_proc); 732 GNUNET_OS_process_wait (h->server_proc);
734 GNUNET_OS_process_close (h->server_proc); 733 GNUNET_OS_process_close (h->server_proc);
735 h->server_proc = NULL; 734 h->server_proc = NULL;
@@ -773,10 +772,9 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
773 (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr))) 772 (-1 == inet_pton (AF_INET, mybuf, &sin_addr.sin_addr)))
774 { 773 {
775 /* should we restart gnunet-helper-nat-server? */ 774 /* should we restart gnunet-helper-nat-server? */
776 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat", 775 LOG (GNUNET_ERROR_TYPE_WARNING, "nat",
777 _ 776 _("gnunet-helper-nat-server generated malformed address `%s'\n"),
778 ("gnunet-helper-nat-server generated malformed address `%s'\n"), 777 mybuf);
779 mybuf);
780 h->server_read_task = 778 h->server_read_task =
781 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 779 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
782 h->server_stdout_handle, 780 h->server_stdout_handle,
@@ -785,8 +783,8 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
785 } 783 }
786 sin_addr.sin_port = htons ((uint16_t) port); 784 sin_addr.sin_port = htons ((uint16_t) port);
787#if DEBUG_NAT 785#if DEBUG_NAT
788 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", 786 LOG (GNUNET_ERROR_TYPE_DEBUG, "gnunet-helper-nat-server read: %s:%d\n", mybuf,
789 "gnunet-helper-nat-server read: %s:%d\n", mybuf, port); 787 port);
790#endif 788#endif
791 h->reversal_callback (h->callback_cls, (const struct sockaddr *) &sin_addr, 789 h->reversal_callback (h->callback_cls, (const struct sockaddr *) &sin_addr,
792 sizeof (sin_addr)); 790 sizeof (sin_addr));
@@ -813,8 +811,8 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
813 GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES)))) 811 GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES))))
814 { 812 {
815#if DEBUG_NAT 813#if DEBUG_NAT
816 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat" "Starting %s at `%s'\n", 814 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting `%s' at `%s'\n",
817 "gnunet-helper-nat-server", h->internal_address); 815 "gnunet-helper-nat-server", h->internal_address);
818#endif 816#endif
819 /* Start the server process */ 817 /* Start the server process */
820 h->server_proc = 818 h->server_proc =
@@ -824,8 +822,8 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
824 h->internal_address, NULL); 822 h->internal_address, NULL);
825 if (h->server_proc == NULL) 823 if (h->server_proc == NULL)
826 { 824 {
827 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat", 825 LOG (GNUNET_ERROR_TYPE_WARNING, "nat", _("Failed to start %s\n"),
828 _("Failed to start %s\n"), "gnunet-helper-nat-server"); 826 "gnunet-helper-nat-server");
829 GNUNET_DISK_pipe_close (h->server_stdout); 827 GNUNET_DISK_pipe_close (h->server_stdout);
830 h->server_stdout = NULL; 828 h->server_stdout = NULL;
831 } 829 }
@@ -1055,9 +1053,9 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp,
1055 unsigned int i; 1053 unsigned int i;
1056 1054
1057#if DEBUG_NAT 1055#if DEBUG_NAT
1058 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", 1056 LOG (GNUNET_ERROR_TYPE_DEBUG,
1059 "Registered with NAT service at port %u with %u IP bound local addresses\n", 1057 "Registered with NAT service at port %u with %u IP bound local addresses\n",
1060 (unsigned int) adv_port, num_addrs); 1058 (unsigned int) adv_port, num_addrs);
1061#endif 1059#endif
1062 h = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle)); 1060 h = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle));
1063 h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS; 1061 h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS;
@@ -1092,9 +1090,9 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp,
1092 if ((h->internal_address != NULL) && 1090 if ((h->internal_address != NULL) &&
1093 (inet_pton (AF_INET, h->internal_address, &in_addr) != 1)) 1091 (inet_pton (AF_INET, h->internal_address, &in_addr) != 1))
1094 { 1092 {
1095 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat", 1093 LOG (GNUNET_ERROR_TYPE_WARNING, "nat",
1096 _("Malformed %s `%s' given in configuration!\n"), 1094 _("Malformed %s `%s' given in configuration!\n"), "INTERNAL_ADDRESS",
1097 "INTERNAL_ADDRESS", h->internal_address); 1095 h->internal_address);
1098 GNUNET_free (h->internal_address); 1096 GNUNET_free (h->internal_address);
1099 h->internal_address = NULL; 1097 h->internal_address = NULL;
1100 } 1098 }
@@ -1153,20 +1151,20 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp,
1153 GNUNET_OS_check_helper_binary ("gnunet-helper-nat-server"))) 1151 GNUNET_OS_check_helper_binary ("gnunet-helper-nat-server")))
1154 { 1152 {
1155 h->enable_nat_server = GNUNET_NO; 1153 h->enable_nat_server = GNUNET_NO;
1156 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1154 LOG (GNUNET_ERROR_TYPE_WARNING,
1157 _ 1155 _
1158 ("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"), 1156 ("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"),
1159 "gnunet-helper-nat-server"); 1157 "gnunet-helper-nat-server");
1160 } 1158 }
1161 if ((GNUNET_YES == h->enable_nat_client) && 1159 if ((GNUNET_YES == h->enable_nat_client) &&
1162 (GNUNET_YES != 1160 (GNUNET_YES !=
1163 GNUNET_OS_check_helper_binary ("gnunet-helper-nat-client"))) 1161 GNUNET_OS_check_helper_binary ("gnunet-helper-nat-client")))
1164 { 1162 {
1165 h->enable_nat_client = GNUNET_NO; 1163 h->enable_nat_client = GNUNET_NO;
1166 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1164 LOG (GNUNET_ERROR_TYPE_WARNING,
1167 _ 1165 _
1168 ("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"), 1166 ("Configuration requires `%s', but binary is not installed properly (SUID bit not set). Option disabled.\n"),
1169 "gnunet-helper-nat-client"); 1167 "gnunet-helper-nat-client");
1170 } 1168 }
1171 1169
1172 start_gnunet_nat_server (h); 1170 start_gnunet_nat_server (h);
@@ -1242,7 +1240,7 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h)
1242 if (NULL != h->server_proc) 1240 if (NULL != h->server_proc)
1243 { 1241 {
1244 if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM)) 1242 if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM))
1245 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 1243 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill");
1246 GNUNET_OS_process_wait (h->server_proc); 1244 GNUNET_OS_process_wait (h->server_proc);
1247 GNUNET_OS_process_close (h->server_proc); 1245 GNUNET_OS_process_close (h->server_proc);
1248 h->server_proc = NULL; 1246 h->server_proc = NULL;
@@ -1295,22 +1293,22 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h,
1295 1293
1296 if (h->internal_address == NULL) 1294 if (h->internal_address == NULL)
1297 { 1295 {
1298 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "nat", 1296 LOG (GNUNET_ERROR_TYPE_WARNING, "nat",
1299 _ 1297 _
1300 ("Internal IP address not known, cannot use ICMP NAT traversal method\n")); 1298 ("Internal IP address not known, cannot use ICMP NAT traversal method\n"));
1301 return; 1299 return;
1302 } 1300 }
1303 GNUNET_assert (sa->sin_family == AF_INET); 1301 GNUNET_assert (sa->sin_family == AF_INET);
1304 if (NULL == inet_ntop (AF_INET, &sa->sin_addr, inet4, INET_ADDRSTRLEN)) 1302 if (NULL == inet_ntop (AF_INET, &sa->sin_addr, inet4, INET_ADDRSTRLEN))
1305 { 1303 {
1306 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 1304 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "inet_ntop");
1307 return; 1305 return;
1308 } 1306 }
1309 GNUNET_snprintf (port_as_string, sizeof (port_as_string), "%d", h->adv_port); 1307 GNUNET_snprintf (port_as_string, sizeof (port_as_string), "%d", h->adv_port);
1310#if DEBUG_NAT 1308#if DEBUG_NAT
1311 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", 1309 LOG (GNUNET_ERROR_TYPE_DEBUG,
1312 _("Running gnunet-helper-nat-client %s %s %u\n"), 1310 _("Running gnunet-helper-nat-client %s %s %u\n"), h->internal_address,
1313 h->internal_address, inet4, (unsigned int) h->adv_port); 1311 inet4, (unsigned int) h->adv_port);
1314#endif 1312#endif
1315 proc = 1313 proc =
1316 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-nat-client", 1314 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-nat-client",
@@ -1372,8 +1370,8 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr,
1372 } 1370 }
1373 pos = pos->next; 1371 pos = pos->next;
1374 } 1372 }
1375 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1373 LOG (GNUNET_ERROR_TYPE_WARNING,
1376 "Asked to validate one of my addresses and validation failed!\n"); 1374 "Asked to validate one of my addresses and validation failed!\n");
1377 return GNUNET_NO; 1375 return GNUNET_NO;
1378} 1376}
1379 1377