aboutsummaryrefslogtreecommitdiff
path: root/src/nat/gnunet-service-nat.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-11-27 23:50:04 +0100
committerChristian Grothoff <christian@grothoff.org>2016-11-27 23:50:04 +0100
commit7f2df8873e6642cc562ef95945117c151a46aa0c (patch)
treea447a1225bef97fe288e5e88f2604520bffce7cb /src/nat/gnunet-service-nat.c
parent6aa3cedfa5e9df7aacbbdcf62c977e09b0e7f6c3 (diff)
downloadgnunet-7f2df8873e6642cc562ef95945117c151a46aa0c.tar.gz
gnunet-7f2df8873e6642cc562ef95945117c151a46aa0c.zip
fix proper setting of scope information for IPv6
Diffstat (limited to 'src/nat/gnunet-service-nat.c')
-rw-r--r--src/nat/gnunet-service-nat.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index a6aa21cd1..bd1cffd55 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -116,11 +116,10 @@ struct LocalAddressList
116 struct LocalAddressList *prev; 116 struct LocalAddressList *prev;
117 117
118 /** 118 /**
119 * The address itself (i.e. `struct in_addr` or `struct in6_addr`, 119 * The address itself (i.e. `struct sockaddr_in` or `struct
120 * in the respective byte order). Allocated at the end of this 120 * sockaddr_in6`, in the respective byte order).
121 * struct.
122 */ 121 */
123 const void *addr; 122 struct sockaddr_storage addr;
124 123
125 /** 124 /**
126 * Address family. 125 * Address family.
@@ -701,7 +700,7 @@ ifc_proc (void *cls,
701 switch (addr->sa_family) 700 switch (addr->sa_family)
702 { 701 {
703 case AF_INET: 702 case AF_INET:
704 alen = sizeof (struct in_addr); 703 alen = sizeof (struct sockaddr_in);
705 ip = &((const struct sockaddr_in *) addr)->sin_addr; 704 ip = &((const struct sockaddr_in *) addr)->sin_addr;
706 if (match_ipv4 ("127.0.0.0", ip, 8)) 705 if (match_ipv4 ("127.0.0.0", ip, 8))
707 ac = GNUNET_NAT_AC_LOOPBACK; 706 ac = GNUNET_NAT_AC_LOOPBACK;
@@ -715,7 +714,7 @@ ifc_proc (void *cls,
715 ac = GNUNET_NAT_AC_GLOBAL; 714 ac = GNUNET_NAT_AC_GLOBAL;
716 break; 715 break;
717 case AF_INET6: 716 case AF_INET6:
718 alen = sizeof (struct in6_addr); 717 alen = sizeof (struct sockaddr_in6);
719 ip = &((const struct sockaddr_in6 *) addr)->sin6_addr; 718 ip = &((const struct sockaddr_in6 *) addr)->sin6_addr;
720 if (match_ipv6 ("::1", ip, 128)) 719 if (match_ipv6 ("::1", ip, 128))
721 ac = GNUNET_NAT_AC_LOOPBACK; 720 ac = GNUNET_NAT_AC_LOOPBACK;
@@ -742,12 +741,11 @@ ifc_proc (void *cls,
742 GNUNET_break (0); 741 GNUNET_break (0);
743 return GNUNET_OK; 742 return GNUNET_OK;
744 } 743 }
745 lal = GNUNET_malloc (sizeof (*lal) + alen); 744 lal = GNUNET_malloc (sizeof (*lal));
746 lal->af = addr->sa_family; 745 lal->af = addr->sa_family;
747 lal->addr = &lal[1];
748 lal->ac = ac; 746 lal->ac = ac;
749 GNUNET_memcpy (&lal[1], 747 GNUNET_memcpy (&lal->addr,
750 ip, 748 addr,
751 alen); 749 alen);
752 GNUNET_CONTAINER_DLL_insert (ifc_ctx->lal_head, 750 GNUNET_CONTAINER_DLL_insert (ifc_ctx->lal_head,
753 ifc_ctx->lal_tail, 751 ifc_ctx->lal_tail,
@@ -773,9 +771,6 @@ notify_clients (struct LocalAddressList *delta,
773 { 771 {
774 struct GNUNET_MQ_Envelope *env; 772 struct GNUNET_MQ_Envelope *env;
775 struct GNUNET_NAT_AddressChangeNotificationMessage *msg; 773 struct GNUNET_NAT_AddressChangeNotificationMessage *msg;
776 void *addr;
777 struct sockaddr_in v4;
778 struct sockaddr_in6 v6;
779 size_t alen; 774 size_t alen;
780 775
781 if (0 == (ch->flags & GNUNET_NAT_RF_ADDRESSES)) 776 if (0 == (ch->flags & GNUNET_NAT_RF_ADDRESSES))
@@ -784,23 +779,9 @@ notify_clients (struct LocalAddressList *delta,
784 { 779 {
785 case AF_INET: 780 case AF_INET:
786 alen = sizeof (struct sockaddr_in); 781 alen = sizeof (struct sockaddr_in);
787 addr = &v4;
788 memset (&v4, 0, sizeof (v4));
789 v4.sin_family = AF_INET;
790 GNUNET_memcpy (&v4.sin_addr,
791 delta->addr,
792 sizeof (struct in_addr));
793 /* FIXME: set port */
794 break; 782 break;
795 case AF_INET6: 783 case AF_INET6:
796 alen = sizeof (struct sockaddr_in6); 784 alen = sizeof (struct sockaddr_in6);
797 addr = &v6;
798 memset (&v6, 0, sizeof (v6));
799 v6.sin6_family = AF_INET6;
800 GNUNET_memcpy (&v6.sin6_addr,
801 delta->addr,
802 sizeof (struct in6_addr));
803 /* FIXME: set port, and link/interface! */
804 break; 785 break;
805 default: 786 default:
806 GNUNET_break (0); 787 GNUNET_break (0);
@@ -812,7 +793,7 @@ notify_clients (struct LocalAddressList *delta,
812 msg->add_remove = htonl (add); 793 msg->add_remove = htonl (add);
813 msg->addr_class = htonl (delta->ac); 794 msg->addr_class = htonl (delta->ac);
814 GNUNET_memcpy (&msg[1], 795 GNUNET_memcpy (&msg[1],
815 addr, 796 &delta->addr,
816 alen); 797 alen);
817 GNUNET_MQ_send (ch->mq, 798 GNUNET_MQ_send (ch->mq,
818 env); 799 env);
@@ -849,11 +830,11 @@ run_scan (void *cls)
849 pos = pos->next) 830 pos = pos->next)
850 { 831 {
851 if ( (pos->af == lal->af) && 832 if ( (pos->af == lal->af) &&
852 (0 == memcmp (lal->addr, 833 (0 == memcmp (&lal->addr,
853 pos->addr, 834 &pos->addr,
854 (AF_INET == lal->af) 835 (AF_INET == lal->af)
855 ? sizeof (struct in_addr) 836 ? sizeof (struct sockaddr_in)
856 : sizeof (struct in6_addr))) ) 837 : sizeof (struct sockaddr_in6))) )
857 found = GNUNET_YES; 838 found = GNUNET_YES;
858 } 839 }
859 if (GNUNET_NO == found) 840 if (GNUNET_NO == found)
@@ -871,11 +852,11 @@ run_scan (void *cls)
871 lal = lal->next) 852 lal = lal->next)
872 { 853 {
873 if ( (pos->af == lal->af) && 854 if ( (pos->af == lal->af) &&
874 (0 == memcmp (lal->addr, 855 (0 == memcmp (&lal->addr,
875 pos->addr, 856 &pos->addr,
876 (AF_INET == lal->af) 857 (AF_INET == lal->af)
877 ? sizeof (struct in_addr) 858 ? sizeof (struct sockaddr_in)
878 : sizeof (struct in6_addr))) ) 859 : sizeof (struct sockaddr_in6))) )
879 found = GNUNET_YES; 860 found = GNUNET_YES;
880 } 861 }
881 if (GNUNET_NO == found) 862 if (GNUNET_NO == found)