aboutsummaryrefslogtreecommitdiff
path: root/src/nat/gnunet-service-nat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/gnunet-service-nat.c')
-rw-r--r--src/nat/gnunet-service-nat.c70
1 files changed, 47 insertions, 23 deletions
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index bfe212308..0695c7ac7 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -662,6 +662,11 @@ notify_client (enum GNUNET_NAT_AddressClass ac,
662 struct GNUNET_MQ_Envelope *env; 662 struct GNUNET_MQ_Envelope *env;
663 struct GNUNET_NAT_AddressChangeNotificationMessage *msg; 663 struct GNUNET_NAT_AddressChangeNotificationMessage *msg;
664 664
665 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
666 "Notifying client about %s of IP %s\n",
667 add ? "addition" : "removal",
668 GNUNET_a2s (addr,
669 addr_len));
665 env = GNUNET_MQ_msg_extra (msg, 670 env = GNUNET_MQ_msg_extra (msg,
666 addr_len, 671 addr_len,
667 GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE); 672 GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE);
@@ -693,7 +698,11 @@ check_notify_client (struct LocalAddressList *delta,
693 struct sockaddr_in6 v6; 698 struct sockaddr_in6 v6;
694 699
695 if (0 == (ch->flags & GNUNET_NAT_RF_ADDRESSES)) 700 if (0 == (ch->flags & GNUNET_NAT_RF_ADDRESSES))
701 {
702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 "Not notifying client as it does not care about addresses\n");
696 return; 704 return;
705 }
697 switch (delta->af) 706 switch (delta->af)
698 { 707 {
699 case AF_INET: 708 case AF_INET:
@@ -715,25 +724,24 @@ check_notify_client (struct LocalAddressList *delta,
715 (! match_ipv4 ("127.0.0.1", &v4.sin_addr, 8)) ) 724 (! match_ipv4 ("127.0.0.1", &v4.sin_addr, 8)) )
716 continue; /* bound to loopback, but this is not loopback */ 725 continue; /* bound to loopback, but this is not loopback */
717 if ( (! match_ipv4 ("127.0.0.1", &c4->sin_addr, 8) ) && 726 if ( (! match_ipv4 ("127.0.0.1", &c4->sin_addr, 8) ) &&
718 (0 != c4->sin_addr.s_addr) &&
719 match_ipv4 ("127.0.0.1", &v4.sin_addr, 8) ) 727 match_ipv4 ("127.0.0.1", &v4.sin_addr, 8) )
720 continue; /* bound to non-loopback, but this is loopback */ 728 continue; /* bound to non-loopback, but this is loopback */
721 if ( (0 != (ch->flags & GNUNET_NAT_AC_EXTERN)) && 729 if ( (0 != (delta->ac & GNUNET_NAT_AC_EXTERN)) &&
722 (0 != c4->sin_addr.s_addr) && 730 (0 != c4->sin_addr.s_addr) &&
723 (! is_nat_v4 (&v4.sin_addr)) ) 731 (! is_nat_v4 (&v4.sin_addr)) )
724 continue; /* based on external-IP, but this IP is not 732 continue; /* based on external-IP, but this IP is not
725 from private address range. */ 733 from private address range. */
726 if ( (0 != memcmp (&v4.sin_addr, 734 if ( (0 != memcmp (&v4.sin_addr,
727 &c4->sin_addr, 735 &c4->sin_addr,
728 sizeof (struct in_addr))) && 736 sizeof (struct in_addr))) &&
729 (0 != c4->sin_addr.s_addr) && 737 (0 != c4->sin_addr.s_addr) &&
730 ( (! is_nat_v4 (&c4->sin_addr)) || 738 (! is_nat_v4 (&c4->sin_addr)) )
731 (0 == (ch->flags & GNUNET_NAT_AC_EXTERN))) )
732 continue; /* this IP is not from private address range, 739 continue; /* this IP is not from private address range,
733 and IP does not match. */ 740 and IP does not match. */
734 741
735 /* OK, IP seems relevant, notify client */ 742 /* OK, IP seems relevant, notify client */
736 v4.sin_port = c4->sin_port; 743 if (0 == htons (v4.sin_port))
744 v4.sin_port = c4->sin_port;
737 notify_client (delta->ac, 745 notify_client (delta->ac,
738 ch, 746 ch,
739 add, 747 add,
@@ -760,13 +768,10 @@ check_notify_client (struct LocalAddressList *delta,
760 (! match_ipv6 ("::1", &v6.sin6_addr, 128)) ) 768 (! match_ipv6 ("::1", &v6.sin6_addr, 128)) )
761 continue; /* bound to loopback, but this is not loopback */ 769 continue; /* bound to loopback, but this is not loopback */
762 if ( (! match_ipv6 ("::1", &c6->sin6_addr, 128) ) && 770 if ( (! match_ipv6 ("::1", &c6->sin6_addr, 128) ) &&
763 (0 != memcmp (&c6->sin6_addr,
764 &in6addr_any,
765 sizeof (struct in6_addr))) &&
766 match_ipv6 ("::1", &v6.sin6_addr, 128) ) 771 match_ipv6 ("::1", &v6.sin6_addr, 128) )
767 continue; /* bound to non-loopback, but this is loopback */ 772 continue; /* bound to non-loopback, but this is loopback */
768 if ( (0 != (ch->flags & GNUNET_NAT_AC_EXTERN)) && 773 if ( (0 != (delta->ac & GNUNET_NAT_AC_EXTERN)) &&
769 (0 != memcmp (&c6->sin6_addr, 774 (0 != memcmp (&c6->sin6_addr,
770 &in6addr_any, 775 &in6addr_any,
771 sizeof (struct in6_addr))) && 776 sizeof (struct in6_addr))) &&
772 (! is_nat_v6 (&v6.sin6_addr)) ) 777 (! is_nat_v6 (&v6.sin6_addr)) )
@@ -793,7 +798,8 @@ check_notify_client (struct LocalAddressList *delta,
793 does not match and is not an external IP */ 798 does not match and is not an external IP */
794 799
795 /* OK, IP seems relevant, notify client */ 800 /* OK, IP seems relevant, notify client */
796 v6.sin6_port = c6->sin6_port; 801 if (0 == htons (v6.sin6_port))
802 v6.sin6_port = c6->sin6_port;
797 notify_client (delta->ac, 803 notify_client (delta->ac,
798 ch, 804 ch,
799 add, 805 add,
@@ -853,6 +859,10 @@ notify_client_external_ipv4_change (void *cls,
853 struct LocalAddressList lal; 859 struct LocalAddressList lal;
854 struct sockaddr_in *s4; 860 struct sockaddr_in *s4;
855 861
862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
863 "Detected eternal IP, can now back-fill AUTO:%u in hole punching specification of `%s'\n",
864 (unsigned int) ch->ext_dns_port,
865 ch->section_name);
856 memset (&lal, 0, sizeof (lal)); 866 memset (&lal, 0, sizeof (lal));
857 s4 = (struct sockaddr_in *) &lal.addr; 867 s4 = (struct sockaddr_in *) &lal.addr;
858 s4->sin_family = AF_INET; 868 s4->sin_family = AF_INET;
@@ -868,8 +878,6 @@ notify_client_external_ipv4_change (void *cls,
868 /* (1) check if client cares. */ 878 /* (1) check if client cares. */
869 if (! ch->natted_address) 879 if (! ch->natted_address)
870 return; 880 return;
871 if (0 == (GNUNET_NAT_RF_ADDRESSES & ch->flags))
872 return;
873 have_v4 = GNUNET_NO; 881 have_v4 = GNUNET_NO;
874 for (unsigned int i=0;i<ch->num_caddrs;i++) 882 for (unsigned int i=0;i<ch->num_caddrs;i++)
875 { 883 {
@@ -891,6 +899,10 @@ notify_client_external_ipv4_change (void *cls,
891 sa.sin_addr = *v4; 899 sa.sin_addr = *v4;
892 sa.sin_port = htons (0); 900 sa.sin_port = htons (0);
893 901
902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
903 "Detected eternal IP %s, notifying client of external IP (without port)\n",
904 GNUNET_a2s ((const struct sockaddr *) &sa,
905 sizeof (sa)));
894 /* (3) notify client of change */ 906 /* (3) notify client of change */
895 notify_client (is_nat_v4 (v4) 907 notify_client (is_nat_v4 (v4)
896 ? GNUNET_NAT_AC_EXTERN | GNUNET_NAT_AC_LAN 908 ? GNUNET_NAT_AC_EXTERN | GNUNET_NAT_AC_LAN
@@ -1055,7 +1067,8 @@ run_scan (void *cls)
1055 1067
1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1057 "Found NATed local address %s, starting NAT server\n", 1069 "Found NATed local address %s, starting NAT server\n",
1058 GNUNET_a2s ((void *) &pos->addr, sizeof (*s4))); 1070 GNUNET_a2s ((const struct sockaddr *) &pos->addr,
1071 sizeof (*s4)));
1059 pos->hc = GN_start_gnunet_nat_server_ (&s4->sin_addr, 1072 pos->hc = GN_start_gnunet_nat_server_ (&s4->sin_addr,
1060 &reversal_callback, 1073 &reversal_callback,
1061 pos); 1074 pos);
@@ -1280,6 +1293,11 @@ dyndns_lookup (void *cls)
1280 struct ClientHandle *ch = cls; 1293 struct ClientHandle *ch = cls;
1281 struct LocalAddressList *lal; 1294 struct LocalAddressList *lal;
1282 1295
1296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1297 "Performing DNS lookup for punched hole given for `%s' as `%s:%u'\n",
1298 ch->section_name,
1299 ch->hole_external,
1300 (unsigned int) ch->ext_dns_port);
1283 for (lal = ch->ext_addr_head; NULL != lal; lal = lal->next) 1301 for (lal = ch->ext_addr_head; NULL != lal; lal = lal->next)
1284 lal->old = GNUNET_YES; 1302 lal->old = GNUNET_YES;
1285 ch->ext_dns_task = NULL; 1303 ch->ext_dns_task = NULL;
@@ -1374,6 +1392,11 @@ lookup_hole_external (struct ClientHandle *ch)
1374 ch->hole_external, 1392 ch->hole_external,
1375 &s4->sin_addr)) 1393 &s4->sin_addr))
1376 { 1394 {
1395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1396 "IPv4 punched hole given for `%s' via `%s:%u'\n",
1397 ch->section_name,
1398 ch->hole_external,
1399 (unsigned int) ch->ext_dns_port);
1377 s4->sin_port = htons (ch->ext_dns_port); 1400 s4->sin_port = htons (ch->ext_dns_port);
1378 lal->af = AF_INET; 1401 lal->af = AF_INET;
1379 lal->ac = GNUNET_NAT_AC_GLOBAL | GNUNET_NAT_AC_MANUAL; 1402 lal->ac = GNUNET_NAT_AC_GLOBAL | GNUNET_NAT_AC_MANUAL;
@@ -1423,8 +1446,6 @@ handle_register (void *cls,
1423 GNUNET_SERVICE_client_drop (ch->client); 1446 GNUNET_SERVICE_client_drop (ch->client);
1424 return; 1447 return;
1425 } 1448 }
1426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1427 "Received REGISTER message from client\n");
1428 ch->flags = message->flags; 1449 ch->flags = message->flags;
1429 ch->proto = message->proto; 1450 ch->proto = message->proto;
1430 ch->num_caddrs = ntohs (message->num_addrs); 1451 ch->num_caddrs = ntohs (message->num_addrs);
@@ -1512,6 +1533,9 @@ handle_register (void *cls,
1512 ch->section_name 1533 ch->section_name
1513 = GNUNET_strndup (off, 1534 = GNUNET_strndup (off,
1514 ntohs (message->str_len)); 1535 ntohs (message->str_len));
1536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1537 "Received REGISTER message from client for subsystem `%s'\n",
1538 ch->section_name);
1515 if (GNUNET_OK == 1539 if (GNUNET_OK ==
1516 GNUNET_CONFIGURATION_get_value_string (cfg, 1540 GNUNET_CONFIGURATION_get_value_string (cfg,
1517 ch->section_name, 1541 ch->section_name,