diff options
-rw-r--r-- | src/nat/gnunet-helper-nat-server.c | 115 | ||||
-rw-r--r-- | src/nat/gnunet-service-nat.c | 89 | ||||
-rw-r--r-- | src/nat/gnunet-service-nat_helper.c | 65 |
3 files changed, 175 insertions, 94 deletions
diff --git a/src/nat/gnunet-helper-nat-server.c b/src/nat/gnunet-helper-nat-server.c index 8c3df749d..ef8e97482 100644 --- a/src/nat/gnunet-helper-nat-server.c +++ b/src/nat/gnunet-helper-nat-server.c | |||
@@ -264,8 +264,11 @@ send_icmp_echo (const struct in_addr *my_ip) | |||
264 | ip_pkt.src_ip = my_ip->s_addr; | 264 | ip_pkt.src_ip = my_ip->s_addr; |
265 | ip_pkt.dst_ip = dummy.s_addr; | 265 | ip_pkt.dst_ip = dummy.s_addr; |
266 | ip_pkt.checksum = | 266 | ip_pkt.checksum = |
267 | htons (calc_checksum ((uint16_t *) & ip_pkt, sizeof (struct ip_header))); | 267 | htons (calc_checksum ((uint16_t *) & ip_pkt, |
268 | memcpy (&packet[off], &ip_pkt, sizeof (struct ip_header)); | 268 | sizeof (struct ip_header))); |
269 | memcpy (&packet[off], | ||
270 | &ip_pkt, | ||
271 | sizeof (struct ip_header)); | ||
269 | off += sizeof (struct ip_header); | 272 | off += sizeof (struct ip_header); |
270 | 273 | ||
271 | icmp_echo.type = ICMP_ECHO; | 274 | icmp_echo.type = ICMP_ECHO; |
@@ -273,9 +276,12 @@ send_icmp_echo (const struct in_addr *my_ip) | |||
273 | icmp_echo.checksum = 0; | 276 | icmp_echo.checksum = 0; |
274 | icmp_echo.reserved = 0; | 277 | icmp_echo.reserved = 0; |
275 | icmp_echo.checksum = | 278 | icmp_echo.checksum = |
276 | htons (calc_checksum | 279 | htons (calc_checksum |
277 | ((uint16_t *) & icmp_echo, sizeof (struct icmp_echo_header))); | 280 | ((uint16_t *) & icmp_echo, |
278 | memcpy (&packet[off], &icmp_echo, sizeof (struct icmp_echo_header)); | 281 | sizeof (struct icmp_echo_header))); |
282 | memcpy (&packet[off], | ||
283 | &icmp_echo, | ||
284 | sizeof (struct icmp_echo_header)); | ||
279 | off += sizeof (struct icmp_echo_header); | 285 | off += sizeof (struct icmp_echo_header); |
280 | 286 | ||
281 | memset (&dst, 0, sizeof (dst)); | 287 | memset (&dst, 0, sizeof (dst)); |
@@ -284,17 +290,24 @@ send_icmp_echo (const struct in_addr *my_ip) | |||
284 | dst.sin_len = sizeof (struct sockaddr_in); | 290 | dst.sin_len = sizeof (struct sockaddr_in); |
285 | #endif | 291 | #endif |
286 | dst.sin_addr = dummy; | 292 | dst.sin_addr = dummy; |
287 | err = | 293 | err = sendto (rawsock, |
288 | sendto (rawsock, packet, off, 0, (struct sockaddr *) &dst, sizeof (dst)); | 294 | packet, |
295 | off, | ||
296 | 0, | ||
297 | (struct sockaddr *) &dst, | ||
298 | sizeof (dst)); | ||
289 | if (err < 0) | 299 | if (err < 0) |
290 | { | 300 | { |
291 | #if VERBOSE | 301 | #if VERBOSE |
292 | fprintf (stderr, "sendto failed: %s\n", strerror (errno)); | 302 | fprintf (stderr, |
303 | "sendto failed: %s\n", | ||
304 | strerror (errno)); | ||
293 | #endif | 305 | #endif |
294 | } | 306 | } |
295 | else if (sizeof (packet) != err) | 307 | else if (sizeof (packet) != err) |
296 | { | 308 | { |
297 | fprintf (stderr, "Error: partial send of ICMP message\n"); | 309 | fprintf (stderr, |
310 | "Error: partial send of ICMP message\n"); | ||
298 | } | 311 | } |
299 | } | 312 | } |
300 | 313 | ||
@@ -315,16 +328,24 @@ send_udp () | |||
315 | #endif | 328 | #endif |
316 | dst.sin_addr = dummy; | 329 | dst.sin_addr = dummy; |
317 | dst.sin_port = htons (NAT_TRAV_PORT); | 330 | dst.sin_port = htons (NAT_TRAV_PORT); |
318 | err = sendto (udpsock, NULL, 0, 0, (struct sockaddr *) &dst, sizeof (dst)); | 331 | err = sendto (udpsock, |
332 | NULL, | ||
333 | 0, | ||
334 | 0, | ||
335 | (struct sockaddr *) &dst, | ||
336 | sizeof (dst)); | ||
319 | if (err < 0) | 337 | if (err < 0) |
320 | { | 338 | { |
321 | #if VERBOSE | 339 | #if VERBOSE |
322 | fprintf (stderr, "sendto failed: %s\n", strerror (errno)); | 340 | fprintf (stderr, |
341 | "sendto failed: %s\n", | ||
342 | strerror (errno)); | ||
323 | #endif | 343 | #endif |
324 | } | 344 | } |
325 | else if (0 != err) | 345 | else if (0 != err) |
326 | { | 346 | { |
327 | fprintf (stderr, "Error: partial send of ICMP message\n"); | 347 | fprintf (stderr, |
348 | "Error: partial send of ICMP message\n"); | ||
328 | } | 349 | } |
329 | } | 350 | } |
330 | 351 | ||
@@ -348,11 +369,15 @@ process_icmp_response () | |||
348 | have = read (icmpsock, buf, sizeof (buf)); | 369 | have = read (icmpsock, buf, sizeof (buf)); |
349 | if (-1 == have) | 370 | if (-1 == have) |
350 | { | 371 | { |
351 | fprintf (stderr, "Error reading raw socket: %s\n", strerror (errno)); | 372 | fprintf (stderr, |
373 | "Error reading raw socket: %s\n", | ||
374 | strerror (errno)); | ||
352 | return; | 375 | return; |
353 | } | 376 | } |
354 | #if VERBOSE | 377 | #if VERBOSE |
355 | fprintf (stderr, "Received message of %u bytes\n", (unsigned int) have); | 378 | fprintf (stderr, |
379 | "Received message of %u bytes\n", | ||
380 | (unsigned int) have); | ||
356 | #endif | 381 | #endif |
357 | if (have < | 382 | if (have < |
358 | (ssize_t) (sizeof (struct ip_header) + | 383 | (ssize_t) (sizeof (struct ip_header) + |
@@ -433,15 +458,27 @@ setup_raw_socket () | |||
433 | const int one = 1; | 458 | const int one = 1; |
434 | 459 | ||
435 | if (-1 == | 460 | if (-1 == |
436 | setsockopt (rawsock, SOL_SOCKET, SO_BROADCAST, (char *) &one, sizeof (one))) | 461 | setsockopt (rawsock, |
462 | SOL_SOCKET, | ||
463 | SO_BROADCAST, | ||
464 | (char *) &one, | ||
465 | sizeof (one))) | ||
437 | { | 466 | { |
438 | fprintf (stderr, "setsockopt failed: %s\n", strerror (errno)); | 467 | fprintf (stderr, |
468 | "setsockopt failed: %s\n", | ||
469 | strerror (errno)); | ||
439 | return -1; | 470 | return -1; |
440 | } | 471 | } |
441 | if (-1 == | 472 | if (-1 == |
442 | setsockopt (rawsock, IPPROTO_IP, IP_HDRINCL, (char *) &one, sizeof (one))) | 473 | setsockopt (rawsock, |
474 | IPPROTO_IP, | ||
475 | IP_HDRINCL, | ||
476 | (char *) &one, | ||
477 | sizeof (one))) | ||
443 | { | 478 | { |
444 | fprintf (stderr, "setsockopt failed: %s\n", strerror (errno)); | 479 | fprintf (stderr, |
480 | "setsockopt failed: %s\n", | ||
481 | strerror (errno)); | ||
445 | return -1; | 482 | return -1; |
446 | } | 483 | } |
447 | return 0; | 484 | return 0; |
@@ -492,7 +529,8 @@ make_udp_socket (const struct in_addr *my_ip) | |||
492 | 529 | ||
493 | 530 | ||
494 | int | 531 | int |
495 | main (int argc, char *const *argv) | 532 | main (int argc, |
533 | char *const *argv) | ||
496 | { | 534 | { |
497 | struct in_addr external; | 535 | struct in_addr external; |
498 | fd_set rs; | 536 | fd_set rs; |
@@ -504,11 +542,15 @@ main (int argc, char *const *argv) | |||
504 | int global_ret; | 542 | int global_ret; |
505 | 543 | ||
506 | /* Create an ICMP raw socket for reading (we'll check errors later) */ | 544 | /* Create an ICMP raw socket for reading (we'll check errors later) */ |
507 | icmpsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); | 545 | icmpsock = socket (AF_INET, |
546 | SOCK_RAW, | ||
547 | IPPROTO_ICMP); | ||
508 | icmp_eno = errno; | 548 | icmp_eno = errno; |
509 | 549 | ||
510 | /* Create an (ICMP) raw socket for writing (we'll check errors later) */ | 550 | /* Create an (ICMP) raw socket for writing (we'll check errors later) */ |
511 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW); | 551 | rawsock = socket (AF_INET, |
552 | SOCK_RAW, | ||
553 | IPPROTO_RAW); | ||
512 | raw_eno = errno; | 554 | raw_eno = errno; |
513 | udpsock = -1; | 555 | udpsock = -1; |
514 | 556 | ||
@@ -517,14 +559,18 @@ main (int argc, char *const *argv) | |||
517 | #ifdef HAVE_SETRESUID | 559 | #ifdef HAVE_SETRESUID |
518 | if (0 != setresuid (uid, uid, uid)) | 560 | if (0 != setresuid (uid, uid, uid)) |
519 | { | 561 | { |
520 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); | 562 | fprintf (stderr, |
563 | "Failed to setresuid: %s\n", | ||
564 | strerror (errno)); | ||
521 | global_ret = 1; | 565 | global_ret = 1; |
522 | goto error_exit; | 566 | goto error_exit; |
523 | } | 567 | } |
524 | #else | 568 | #else |
525 | if (0 != (setuid (uid) | seteuid (uid))) | 569 | if (0 != (setuid (uid) | seteuid (uid))) |
526 | { | 570 | { |
527 | fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); | 571 | fprintf (stderr, |
572 | "Failed to setuid: %s\n", | ||
573 | strerror (errno)); | ||
528 | global_ret = 2; | 574 | global_ret = 2; |
529 | goto error_exit; | 575 | goto error_exit; |
530 | } | 576 | } |
@@ -540,13 +586,16 @@ main (int argc, char *const *argv) | |||
540 | } | 586 | } |
541 | if (1 != inet_pton (AF_INET, argv[1], &external)) | 587 | if (1 != inet_pton (AF_INET, argv[1], &external)) |
542 | { | 588 | { |
543 | fprintf (stderr, "Error parsing IPv4 address: %s\n", strerror (errno)); | 589 | fprintf (stderr, |
590 | "Error parsing IPv4 address: %s\n", | ||
591 | strerror (errno)); | ||
544 | global_ret = 4; | 592 | global_ret = 4; |
545 | goto error_exit; | 593 | goto error_exit; |
546 | } | 594 | } |
547 | if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy)) | 595 | if (1 != inet_pton (AF_INET, DUMMY_IP, &dummy)) |
548 | { | 596 | { |
549 | fprintf (stderr, "Internal error converting dummy IP to binary.\n"); | 597 | fprintf (stderr, |
598 | "Internal error converting dummy IP to binary.\n"); | ||
550 | global_ret = 5; | 599 | global_ret = 5; |
551 | goto error_exit; | 600 | goto error_exit; |
552 | } | 601 | } |
@@ -554,7 +603,9 @@ main (int argc, char *const *argv) | |||
554 | /* error checking icmpsock */ | 603 | /* error checking icmpsock */ |
555 | if (-1 == icmpsock) | 604 | if (-1 == icmpsock) |
556 | { | 605 | { |
557 | fprintf (stderr, "Error opening RAW socket: %s\n", strerror (icmp_eno)); | 606 | fprintf (stderr, |
607 | "Error opening RAW socket: %s\n", | ||
608 | strerror (icmp_eno)); | ||
558 | global_ret = 6; | 609 | global_ret = 6; |
559 | goto error_exit; | 610 | goto error_exit; |
560 | } | 611 | } |
@@ -562,7 +613,9 @@ main (int argc, char *const *argv) | |||
562 | { | 613 | { |
563 | /* this could happen if we were started with a large number of already-open | 614 | /* this could happen if we were started with a large number of already-open |
564 | file descriptors... */ | 615 | file descriptors... */ |
565 | fprintf (stderr, "Socket number too large (%d > %u)\n", icmpsock, | 616 | fprintf (stderr, |
617 | "Socket number too large (%d > %u)\n", | ||
618 | icmpsock, | ||
566 | (unsigned int) FD_SETSIZE); | 619 | (unsigned int) FD_SETSIZE); |
567 | global_ret = 7; | 620 | global_ret = 7; |
568 | goto error_exit; | 621 | goto error_exit; |
@@ -571,7 +624,9 @@ main (int argc, char *const *argv) | |||
571 | /* error checking rawsock */ | 624 | /* error checking rawsock */ |
572 | if (-1 == rawsock) | 625 | if (-1 == rawsock) |
573 | { | 626 | { |
574 | fprintf (stderr, "Error opening RAW socket: %s\n", strerror (raw_eno)); | 627 | fprintf (stderr, |
628 | "Error opening RAW socket: %s\n", | ||
629 | strerror (raw_eno)); | ||
575 | global_ret = 8; | 630 | global_ret = 8; |
576 | goto error_exit; | 631 | goto error_exit; |
577 | } | 632 | } |
@@ -601,7 +656,9 @@ main (int argc, char *const *argv) | |||
601 | { | 656 | { |
602 | if (errno == EINTR) | 657 | if (errno == EINTR) |
603 | continue; | 658 | continue; |
604 | fprintf (stderr, "select failed: %s\n", strerror (errno)); | 659 | fprintf (stderr, |
660 | "select failed: %s\n", | ||
661 | strerror (errno)); | ||
605 | break; | 662 | break; |
606 | } | 663 | } |
607 | if (1 == getppid ()) /* Check the parent process id, if 1 the parent has died, so we should die too */ | 664 | if (1 == getppid ()) /* Check the parent process id, if 1 the parent has died, so we should die too */ |
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c index f432eca18..e29f37108 100644 --- a/src/nat/gnunet-service-nat.c +++ b/src/nat/gnunet-service-nat.c | |||
@@ -396,6 +396,31 @@ static struct in_addr mini_external_ipv4; | |||
396 | 396 | ||
397 | 397 | ||
398 | /** | 398 | /** |
399 | * Remove and free an entry from the #lal_head DLL. | ||
400 | * | ||
401 | * @param lal entry to free | ||
402 | */ | ||
403 | static void | ||
404 | free_lal (struct LocalAddressList *lal) | ||
405 | { | ||
406 | GNUNET_CONTAINER_DLL_remove (lal_head, | ||
407 | lal_tail, | ||
408 | lal); | ||
409 | if (NULL != lal->hc) | ||
410 | { | ||
411 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
412 | "Lost NATed local address %s, stopping NAT server\n", | ||
413 | GNUNET_a2s ((const struct sockaddr *) &lal->addr, | ||
414 | sizeof (struct sockaddr_in))); | ||
415 | |||
416 | GN_stop_gnunet_nat_server_ (lal->hc); | ||
417 | lal->hc = NULL; | ||
418 | } | ||
419 | GNUNET_free (lal); | ||
420 | } | ||
421 | |||
422 | |||
423 | /** | ||
399 | * Free the DLL starting at #lal_head. | 424 | * Free the DLL starting at #lal_head. |
400 | */ | 425 | */ |
401 | static void | 426 | static void |
@@ -404,17 +429,7 @@ destroy_lal () | |||
404 | struct LocalAddressList *lal; | 429 | struct LocalAddressList *lal; |
405 | 430 | ||
406 | while (NULL != (lal = lal_head)) | 431 | while (NULL != (lal = lal_head)) |
407 | { | 432 | free_lal (lal); |
408 | GNUNET_CONTAINER_DLL_remove (lal_head, | ||
409 | lal_tail, | ||
410 | lal); | ||
411 | if (NULL != lal->hc) | ||
412 | { | ||
413 | GN_stop_gnunet_nat_server_ (lal->hc); | ||
414 | lal->hc = NULL; | ||
415 | } | ||
416 | GNUNET_free (lal); | ||
417 | } | ||
418 | } | 433 | } |
419 | 434 | ||
420 | 435 | ||
@@ -1099,6 +1114,7 @@ run_scan (void *cls) | |||
1099 | struct IfcProcContext ifc_ctx; | 1114 | struct IfcProcContext ifc_ctx; |
1100 | int found; | 1115 | int found; |
1101 | int have_nat; | 1116 | int have_nat; |
1117 | struct LocalAddressList *lnext; | ||
1102 | 1118 | ||
1103 | scan_task = GNUNET_SCHEDULER_add_delayed (SCAN_FREQ, | 1119 | scan_task = GNUNET_SCHEDULER_add_delayed (SCAN_FREQ, |
1104 | &run_scan, | 1120 | &run_scan, |
@@ -1111,8 +1127,9 @@ run_scan (void *cls) | |||
1111 | /* remove addresses that disappeared */ | 1127 | /* remove addresses that disappeared */ |
1112 | for (struct LocalAddressList *lal = lal_head; | 1128 | for (struct LocalAddressList *lal = lal_head; |
1113 | NULL != lal; | 1129 | NULL != lal; |
1114 | lal = lal->next) | 1130 | lal = lnext) |
1115 | { | 1131 | { |
1132 | lnext = lal->next; | ||
1116 | found = GNUNET_NO; | 1133 | found = GNUNET_NO; |
1117 | for (struct LocalAddressList *pos = ifc_ctx.lal_head; | 1134 | for (struct LocalAddressList *pos = ifc_ctx.lal_head; |
1118 | NULL != pos; | 1135 | NULL != pos; |
@@ -1126,20 +1143,21 @@ run_scan (void *cls) | |||
1126 | : sizeof (struct sockaddr_in6))) ) | 1143 | : sizeof (struct sockaddr_in6))) ) |
1127 | { | 1144 | { |
1128 | found = GNUNET_YES; | 1145 | found = GNUNET_YES; |
1129 | pos->hc = lal->hc; | ||
1130 | lal->hc = NULL; | ||
1131 | } | 1146 | } |
1132 | } | 1147 | } |
1133 | if (GNUNET_NO == found) | 1148 | if (GNUNET_NO == found) |
1149 | { | ||
1134 | notify_clients (lal, | 1150 | notify_clients (lal, |
1135 | GNUNET_NO); | 1151 | GNUNET_NO); |
1152 | free_lal (lal); | ||
1153 | } | ||
1136 | } | 1154 | } |
1137 | 1155 | ||
1138 | /* add addresses that appeared */ | 1156 | /* add addresses that appeared */ |
1139 | have_nat = GNUNET_NO; | 1157 | have_nat = GNUNET_NO; |
1140 | for (struct LocalAddressList *pos = ifc_ctx.lal_head; | 1158 | for (struct LocalAddressList *pos = ifc_ctx.lal_head; |
1141 | NULL != pos; | 1159 | NULL != pos; |
1142 | pos = pos->next) | 1160 | pos = ifc_ctx.lal_head) |
1143 | { | 1161 | { |
1144 | found = GNUNET_NO; | 1162 | found = GNUNET_NO; |
1145 | if (GNUNET_NAT_AC_LAN == (GNUNET_NAT_AC_LAN & pos->ac)) | 1163 | if (GNUNET_NAT_AC_LAN == (GNUNET_NAT_AC_LAN & pos->ac)) |
@@ -1156,19 +1174,34 @@ run_scan (void *cls) | |||
1156 | : sizeof (struct sockaddr_in6))) ) | 1174 | : sizeof (struct sockaddr_in6))) ) |
1157 | found = GNUNET_YES; | 1175 | found = GNUNET_YES; |
1158 | } | 1176 | } |
1159 | if (GNUNET_NO == found) | 1177 | GNUNET_CONTAINER_DLL_remove (ifc_ctx.lal_head, |
1178 | ifc_ctx.lal_tail, | ||
1179 | pos); | ||
1180 | if (GNUNET_YES == found) | ||
1181 | { | ||
1182 | GNUNET_free (pos); | ||
1183 | } | ||
1184 | else | ||
1185 | { | ||
1160 | notify_clients (pos, | 1186 | notify_clients (pos, |
1161 | GNUNET_YES); | 1187 | GNUNET_YES); |
1162 | if ( (AF_INET == pos->af) && | 1188 | GNUNET_CONTAINER_DLL_insert (lal_head, |
1163 | (NULL == pos->hc) && | 1189 | lal_tail, |
1164 | (0 != (GNUNET_NAT_AC_LAN & pos->ac)) ) | 1190 | pos); |
1165 | { | 1191 | if ( (AF_INET == pos->af) && |
1166 | const struct sockaddr_in *s4 | 1192 | (NULL == pos->hc) && |
1167 | = (const struct sockaddr_in *) &pos->addr; | 1193 | (0 != (GNUNET_NAT_AC_LAN & pos->ac)) ) |
1168 | 1194 | { | |
1169 | pos->hc = GN_start_gnunet_nat_server_ (&s4->sin_addr, | 1195 | const struct sockaddr_in *s4 |
1170 | &reversal_callback, | 1196 | = (const struct sockaddr_in *) &pos->addr; |
1171 | pos); | 1197 | |
1198 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | ||
1199 | "Found NATed local address %s, starting NAT server\n", | ||
1200 | GNUNET_a2s ((void *) &pos->addr, sizeof (*s4))); | ||
1201 | pos->hc = GN_start_gnunet_nat_server_ (&s4->sin_addr, | ||
1202 | &reversal_callback, | ||
1203 | pos); | ||
1204 | } | ||
1172 | } | 1205 | } |
1173 | } | 1206 | } |
1174 | if ( (GNUNET_YES == have_nat) && | 1207 | if ( (GNUNET_YES == have_nat) && |
@@ -1194,10 +1227,6 @@ run_scan (void *cls) | |||
1194 | probe_external_ip_op = NULL; | 1227 | probe_external_ip_op = NULL; |
1195 | } | 1228 | } |
1196 | } | 1229 | } |
1197 | |||
1198 | destroy_lal (); | ||
1199 | lal_head = ifc_ctx.lal_head; | ||
1200 | lal_tail = ifc_ctx.lal_tail; | ||
1201 | } | 1230 | } |
1202 | 1231 | ||
1203 | 1232 | ||
diff --git a/src/nat/gnunet-service-nat_helper.c b/src/nat/gnunet-service-nat_helper.c index febc3c2dd..7e5051d65 100644 --- a/src/nat/gnunet-service-nat_helper.c +++ b/src/nat/gnunet-service-nat_helper.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet-service-nat_helper.h" | 29 | #include "gnunet-service-nat_helper.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__) | ||
32 | 31 | ||
33 | /** | 32 | /** |
34 | * Information we keep per NAT helper process. | 33 | * Information we keep per NAT helper process. |
@@ -133,11 +132,11 @@ nat_server_read (void *cls) | |||
133 | sizeof (mybuf)); | 132 | sizeof (mybuf)); |
134 | if (bytes < 1) | 133 | if (bytes < 1) |
135 | { | 134 | { |
136 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
137 | "Finished reading from server stdout with code: %d\n", | 136 | "Finished reading from server stdout with code: %d\n", |
138 | bytes); | 137 | bytes); |
139 | if (0 != GNUNET_OS_process_kill (h->server_proc, | 138 | if (0 != GNUNET_OS_process_kill (h->server_proc, |
140 | - GNUNET_TERM_SIG)) | 139 | GNUNET_TERM_SIG)) |
141 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 140 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, |
142 | "nat", | 141 | "nat", |
143 | "kill"); | 142 | "kill"); |
@@ -183,10 +182,9 @@ nat_server_read (void *cls) | |||
183 | &sin_addr.sin_addr))) | 182 | &sin_addr.sin_addr))) |
184 | { | 183 | { |
185 | /* should we restart gnunet-helper-nat-server? */ | 184 | /* should we restart gnunet-helper-nat-server? */ |
186 | LOG (GNUNET_ERROR_TYPE_WARNING, | 185 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
187 | "nat", | 186 | _("gnunet-helper-nat-server generated malformed address `%s'\n"), |
188 | _("gnunet-helper-nat-server generated malformed address `%s'\n"), | 187 | mybuf); |
189 | mybuf); | ||
190 | h->server_read_task | 188 | h->server_read_task |
191 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 189 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
192 | h->server_stdout_handle, | 190 | h->server_stdout_handle, |
@@ -195,10 +193,10 @@ nat_server_read (void *cls) | |||
195 | return; | 193 | return; |
196 | } | 194 | } |
197 | sin_addr.sin_port = htons ((uint16_t) port); | 195 | sin_addr.sin_port = htons ((uint16_t) port); |
198 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
199 | "gnunet-helper-nat-server read: %s:%d\n", | 197 | "gnunet-helper-nat-server read: %s:%d\n", |
200 | mybuf, | 198 | mybuf, |
201 | port); | 199 | port); |
202 | h->cb (h->cb_cls, | 200 | h->cb (h->cb_cls, |
203 | &sin_addr); | 201 | &sin_addr); |
204 | h->server_read_task | 202 | h->server_read_task |
@@ -238,10 +236,10 @@ restart_nat_server (void *cls) | |||
238 | &h->internal_address, | 236 | &h->internal_address, |
239 | ia, | 237 | ia, |
240 | sizeof (ia))); | 238 | sizeof (ia))); |
241 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
242 | "Starting `%s' at `%s'\n", | 240 | "Starting `%s' at `%s'\n", |
243 | "gnunet-helper-nat-server", | 241 | "gnunet-helper-nat-server", |
244 | ia); | 242 | ia); |
245 | /* Start the server process */ | 243 | /* Start the server process */ |
246 | binary | 244 | binary |
247 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); | 245 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server"); |
@@ -258,10 +256,9 @@ restart_nat_server (void *cls) | |||
258 | GNUNET_free (binary); | 256 | GNUNET_free (binary); |
259 | if (NULL == h->server_proc) | 257 | if (NULL == h->server_proc) |
260 | { | 258 | { |
261 | LOG (GNUNET_ERROR_TYPE_WARNING, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
262 | "nat", | 260 | _("Failed to start %s\n"), |
263 | _("Failed to start %s\n"), | 261 | "gnunet-helper-nat-server"); |
264 | "gnunet-helper-nat-server"); | ||
265 | GNUNET_DISK_pipe_close (h->server_stdout); | 262 | GNUNET_DISK_pipe_close (h->server_stdout); |
266 | h->server_stdout = NULL; | 263 | h->server_stdout = NULL; |
267 | try_again (h); | 264 | try_again (h); |
@@ -301,6 +298,7 @@ GN_start_gnunet_nat_server_ (const struct in_addr *internal_address, | |||
301 | h->cb = cb; | 298 | h->cb = cb; |
302 | h->cb_cls = cb_cls; | 299 | h->cb_cls = cb_cls; |
303 | h->internal_address = *internal_address; | 300 | h->internal_address = *internal_address; |
301 | restart_nat_server (h); | ||
304 | if (NULL == h->server_stdout) | 302 | if (NULL == h->server_stdout) |
305 | { | 303 | { |
306 | GN_stop_gnunet_nat_server_ (h); | 304 | GN_stop_gnunet_nat_server_ (h); |
@@ -328,9 +326,8 @@ GN_stop_gnunet_nat_server_ (struct HelperContext *h) | |||
328 | { | 326 | { |
329 | if (0 != GNUNET_OS_process_kill (h->server_proc, | 327 | if (0 != GNUNET_OS_process_kill (h->server_proc, |
330 | GNUNET_TERM_SIG)) | 328 | GNUNET_TERM_SIG)) |
331 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 329 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
332 | "nat", | 330 | "kill"); |
333 | "kill"); | ||
334 | GNUNET_OS_process_wait (h->server_proc); | 331 | GNUNET_OS_process_wait (h->server_proc); |
335 | GNUNET_OS_process_destroy (h->server_proc); | 332 | GNUNET_OS_process_destroy (h->server_proc); |
336 | h->server_proc = NULL; | 333 | h->server_proc = NULL; |
@@ -375,9 +372,8 @@ GN_request_connection_reversal (const struct in_addr *internal_address, | |||
375 | intv4, | 372 | intv4, |
376 | INET_ADDRSTRLEN)) | 373 | INET_ADDRSTRLEN)) |
377 | { | 374 | { |
378 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 375 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
379 | "nat", | 376 | "inet_ntop"); |
380 | "inet_ntop"); | ||
381 | return GNUNET_SYSERR; | 377 | return GNUNET_SYSERR; |
382 | } | 378 | } |
383 | if (NULL == inet_ntop (AF_INET, | 379 | if (NULL == inet_ntop (AF_INET, |
@@ -385,20 +381,19 @@ GN_request_connection_reversal (const struct in_addr *internal_address, | |||
385 | remv4, | 381 | remv4, |
386 | INET_ADDRSTRLEN)) | 382 | INET_ADDRSTRLEN)) |
387 | { | 383 | { |
388 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | 384 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
389 | "nat", | 385 | "inet_ntop"); |
390 | "inet_ntop"); | ||
391 | return GNUNET_SYSERR; | 386 | return GNUNET_SYSERR; |
392 | } | 387 | } |
393 | GNUNET_snprintf (port_as_string, | 388 | GNUNET_snprintf (port_as_string, |
394 | sizeof (port_as_string), | 389 | sizeof (port_as_string), |
395 | "%d", | 390 | "%d", |
396 | internal_port); | 391 | internal_port); |
397 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
398 | _("Running gnunet-helper-nat-client %s %s %u\n"), | 393 | _("Running gnunet-helper-nat-client %s %s %u\n"), |
399 | intv4, | 394 | intv4, |
400 | remv4, | 395 | remv4, |
401 | internal_port); | 396 | internal_port); |
402 | binary | 397 | binary |
403 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); | 398 | = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client"); |
404 | proc | 399 | proc |