aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat_auto.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/nat_auto.c')
-rw-r--r--src/nat/nat_auto.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c
index 82e067f73..4611edc62 100644
--- a/src/nat/nat_auto.c
+++ b/src/nat/nat_auto.c
@@ -273,7 +273,9 @@ do_udp_read (void *cls)
273 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 273 (GNUNET_NETWORK_fdset_isset (tc->read_ready,
274 lsock4))) 274 lsock4)))
275 { 275 {
276 rlen = GNUNET_NETWORK_socket_recv (lsock4, reply_buf, sizeof (reply_buf)); 276 rlen = GNUNET_NETWORK_socket_recv (lsock4,
277 reply_buf,
278 sizeof (reply_buf));
277 279
278 //Lets handle the packet 280 //Lets handle the packet
279 memset(&answer, 0, sizeof(struct sockaddr_in)); 281 memset(&answer, 0, sizeof(struct sockaddr_in));
@@ -288,7 +290,8 @@ do_udp_read (void *cls)
288 } 290 }
289 else 291 else
290 { 292 {
291 if (GNUNET_OK == GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer)) 293 if (GNUNET_OK ==
294 GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer))
292 { 295 {
293 //Process the answer 296 //Process the answer
294 process_stun_reply (&answer, ah); 297 process_stun_reply (&answer, ah);
@@ -310,9 +313,6 @@ do_udp_read (void *cls)
310 313
311 next_phase (ah); 314 next_phase (ah);
312 } 315 }
313
314
315
316} 316}
317 317
318 318
@@ -352,10 +352,9 @@ bind_v4 ()
352} 352}
353 353
354 354
355 355static void
356 356request_callback (void *cls,
357static void request_callback (void *cls, 357 enum GNUNET_NAT_StatusCode result)
358 enum GNUNET_NAT_StatusCode result)
359{ 358{
360 // struct GNUNET_NAT_AutoHandle *ah = cls; 359 // struct GNUNET_NAT_AutoHandle *ah = cls;
361 360
@@ -363,10 +362,7 @@ static void request_callback (void *cls,
363 stop_stun (); 362 stop_stun ();
364 363
365 // next_phase (ah); FIXME this always will be NULL, as called in test_stun() 364 // next_phase (ah); FIXME this always will be NULL, as called in test_stun()
366}; 365}
367
368
369
370 366
371 367
372/** 368/**
@@ -518,17 +514,20 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah)
518 { 514 {
519 //Lets call our function now when it accepts 515 //Lets call our function now when it accepts
520 ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT, 516 ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
521 lsock4, &do_udp_read, ah); 517 lsock4,
522 518 &do_udp_read,
519 ah);
523 } 520 }
524 521
525 522
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "STUN service listens on port %u\n", 524 "STUN service listens on port %u\n",
528 port); 525 port);
529 if (GNUNET_NO == GNUNET_NAT_stun_make_request (stun_server, stun_port, 526 if (GNUNET_NO ==
530 lsock4, &request_callback, 527 GNUNET_NAT_stun_make_request (stun_server, stun_port,
531 NULL)) 528 lsock4,
529 &request_callback,
530 NULL))
532 { 531 {
533 /*An error happened*/ 532 /*An error happened*/
534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n"); 533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n");
@@ -538,7 +537,6 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah)
538} 537}
539 538
540 539
541
542/** 540/**
543 * Process list of local IP addresses. Find and set the 541 * Process list of local IP addresses. Find and set the
544 * one of the default interface. 542 * one of the default interface.
@@ -550,16 +548,16 @@ test_stun (struct GNUNET_NAT_AutoHandle *ah)
550 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) 548 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
551 * @param netmask the network mask (can be NULL for unknown or unassigned)) 549 * @param netmask the network mask (can be NULL for unknown or unassigned))
552 * @param addrlen length of the @a addr and @a broadcast_addr 550 * @param addrlen length of the @a addr and @a broadcast_addr
553 * @return GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 551 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
554 */ 552 */
555static int 553static int
556process_if (void *cls, 554process_if (void *cls,
557 const char *name, 555 const char *name,
558 int isDefault, 556 int isDefault,
559 const struct sockaddr *addr, 557 const struct sockaddr *addr,
560 const struct sockaddr *broadcast_addr, 558 const struct sockaddr *broadcast_addr,
561 const struct sockaddr *netmask, 559 const struct sockaddr *netmask,
562 socklen_t addrlen) 560 socklen_t addrlen)
563{ 561{
564 struct GNUNET_NAT_AutoHandle *ah = cls; 562 struct GNUNET_NAT_AutoHandle *ah = cls;
565 const struct sockaddr_in *in; 563 const struct sockaddr_in *in;
@@ -640,11 +638,9 @@ test_local_ip (struct GNUNET_NAT_AutoHandle *ah)
640static void 638static void
641test_nat_punched (struct GNUNET_NAT_AutoHandle *ah) 639test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
642{ 640{
643
644 struct GNUNET_CLIENT_Connection *client; 641 struct GNUNET_CLIENT_Connection *client;
645 struct GNUNET_NAT_TestMessage msg; 642 struct GNUNET_NAT_TestMessage msg;
646 643
647
648 if (ah->stun_ip) 644 if (ah->stun_ip)
649 { 645 {
650 LOG (GNUNET_ERROR_TYPE_INFO, 646 LOG (GNUNET_ERROR_TYPE_INFO,
@@ -676,9 +672,10 @@ test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
676 { 672 {
677 GNUNET_SCHEDULER_cancel (ltask4); 673 GNUNET_SCHEDULER_cancel (ltask4);
678 ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT, 674 ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
679 lsock4, &do_udp_read, ah); 675 lsock4,
676 &do_udp_read,
677 ah);
680 } 678 }
681
682 } 679 }
683 else 680 else
684 { 681 {
@@ -686,13 +683,9 @@ test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
686 "We don't have a STUN IP"); 683 "We don't have a STUN IP");
687 next_phase(ah); 684 next_phase(ah);
688 } 685 }
689
690
691} 686}
692 687
693 688
694
695
696/** 689/**
697 * Test if UPnPC works. 690 * Test if UPnPC works.
698 * 691 *
@@ -772,7 +765,6 @@ err:
772 ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, ah); 765 ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, ah);
773 else 766 else
774 next_phase (ah); 767 next_phase (ah);
775
776} 768}
777 769
778 770
@@ -784,8 +776,6 @@ err:
784static void 776static void
785test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) 777test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
786{ 778{
787
788
789 char *tmp; 779 char *tmp;
790 char *helper; 780 char *helper;
791 781
@@ -802,7 +792,8 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
802 792
803 if (GNUNET_YES != 793 if (GNUNET_YES !=
804 GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){ 794 GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){
805 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n")); 795 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
796 _("test_icmp_server not possible, as we are not behind NAT\n"));
806 } 797 }
807 else 798 else
808 goto err; 799 goto err;
@@ -810,14 +801,14 @@ test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
810 if (GNUNET_YES == 801 if (GNUNET_YES ==
811 GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){ 802 GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){
812 // none of these parameters are actually used in privilege testing mode 803 // none of these parameters are actually used in privilege testing mode
813 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n")); 804 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
805 _("No working gnunet-helper-nat-server found\n"));
814 } 806 }
815err: 807err:
816 GNUNET_free_non_null (tmp); 808 GNUNET_free_non_null (tmp);
817 GNUNET_free (helper); 809 GNUNET_free (helper);
818 810
819 next_phase (ah); 811 next_phase (ah);
820
821} 812}
822 813
823 814
@@ -940,11 +931,7 @@ next_phase (struct GNUNET_NAT_AutoHandle *ah)
940 GNUNET_CONFIGURATION_destroy (diff); 931 GNUNET_CONFIGURATION_destroy (diff);
941 GNUNET_NAT_autoconfig_cancel (ah); 932 GNUNET_NAT_autoconfig_cancel (ah);
942 return; 933 return;
943
944 } 934 }
945
946
947
948} 935}
949 936
950 937