diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-02 04:37:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-02 04:37:59 +0000 |
commit | 86a020dbabef7e047706f462840bfe66b036093c (patch) | |
tree | e19123a84f515ad810ed892811a5c6492b6b971f /src/vpn/gnunet-daemon-vpn.c | |
parent | 1fd2ff9b321277b55444c2a074e6476cc10099c2 (diff) | |
download | gnunet-86a020dbabef7e047706f462840bfe66b036093c.tar.gz gnunet-86a020dbabef7e047706f462840bfe66b036093c.zip |
-small steps towards saner DNS API
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 86f08d19c..cd587d7b1 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -118,8 +118,9 @@ cleanup (void *cls GNUNET_UNUSED, | |||
118 | * @return the hash of the IP-Address if a mapping exists, NULL otherwise | 118 | * @return the hash of the IP-Address if a mapping exists, NULL otherwise |
119 | */ | 119 | */ |
120 | GNUNET_HashCode * | 120 | GNUNET_HashCode * |
121 | address6_mapping_exists (unsigned char addr[]) | 121 | address6_mapping_exists (struct in6_addr *v6addr) |
122 | { | 122 | { |
123 | unsigned char *addr = (unsigned char*) v6addr; | ||
123 | GNUNET_HashCode *key = GNUNET_malloc (sizeof (GNUNET_HashCode)); | 124 | GNUNET_HashCode *key = GNUNET_malloc (sizeof (GNUNET_HashCode)); |
124 | unsigned char *k = (unsigned char *) key; | 125 | unsigned char *k = (unsigned char *) key; |
125 | 126 | ||
@@ -375,9 +376,11 @@ send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
375 | * Create a new Address from an answer-packet | 376 | * Create a new Address from an answer-packet |
376 | */ | 377 | */ |
377 | void | 378 | void |
378 | new_ip6addr (unsigned char *buf, const GNUNET_HashCode * peer, | 379 | new_ip6addr (struct in6_addr *v6addr, |
380 | const GNUNET_HashCode * peer, | ||
379 | const GNUNET_HashCode * service_desc) | 381 | const GNUNET_HashCode * service_desc) |
380 | { /* {{{ */ | 382 | { /* {{{ */ |
383 | unsigned char *buf = (unsigned char*) v6addr; | ||
381 | char *ipv6addr; | 384 | char *ipv6addr; |
382 | unsigned long long ipv6prefix; | 385 | unsigned long long ipv6prefix; |
383 | 386 | ||
@@ -415,8 +418,10 @@ new_ip6addr (unsigned char *buf, const GNUNET_HashCode * peer, | |||
415 | * Create a new Address from an answer-packet | 418 | * Create a new Address from an answer-packet |
416 | */ | 419 | */ |
417 | void | 420 | void |
418 | new_ip6addr_remote (unsigned char *buf, unsigned char *addr, char addrlen) | 421 | new_ip6addr_remote (struct in6_addr *v6addr, |
422 | unsigned char *addr, char addrlen) | ||
419 | { /* {{{ */ | 423 | { /* {{{ */ |
424 | unsigned char *buf = (unsigned char*) v6addr; | ||
420 | char *ipv6addr; | 425 | char *ipv6addr; |
421 | unsigned long long ipv6prefix; | 426 | unsigned long long ipv6prefix; |
422 | 427 | ||
@@ -529,7 +534,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
529 | unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); | 534 | unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); |
530 | unsigned char *k = (unsigned char *) &key; | 535 | unsigned char *k = (unsigned char *) &key; |
531 | 536 | ||
532 | new_ip6addr (c, &pkt->service_descr.peer, | 537 | new_ip6addr ((struct in6_addr*) c, |
538 | &pkt->service_descr.peer, | ||
533 | &pkt->service_descr.service_descriptor); | 539 | &pkt->service_descr.service_descriptor); |
534 | /* | 540 | /* |
535 | * Copy the newly generated ip-address to the key backwarts (as only the first part is hashed) | 541 | * Copy the newly generated ip-address to the key backwarts (as only the first part is hashed) |
@@ -655,7 +661,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
655 | 661 | ||
656 | unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); | 662 | unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); |
657 | 663 | ||
658 | new_ip6addr_remote (c, pkt->addr, pkt->addrsize); | 664 | new_ip6addr_remote ((struct in6_addr*) c, |
665 | pkt->addr, pkt->addrsize); | ||
659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
660 | "New mapping to %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", | 667 | "New mapping to %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", |
661 | c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], | 668 | c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], |
@@ -877,9 +884,9 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
877 | GNUNET_assert (pkt6 != NULL); | 884 | GNUNET_assert (pkt6 != NULL); |
878 | 885 | ||
879 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK) | 886 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK) |
880 | new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); | 887 | new_ip6addr (&pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); |
881 | else | 888 | else |
882 | new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen); | 889 | new_ip6addr_remote (&pkt6->ip6_hdr.sadr, s->addr, s->addrlen); |
883 | 890 | ||
884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
885 | "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, | 892 | "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, |
@@ -906,12 +913,12 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
906 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", | 913 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", |
907 | "IPV6ADDR", | 914 | "IPV6ADDR", |
908 | &ipv6addr)); | 915 | &ipv6addr)); |
909 | inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr); | 916 | inet_pton (AF_INET6, ipv6addr, &pkt6->ip6_hdr.dadr); |
910 | GNUNET_free (ipv6addr); | 917 | GNUNET_free (ipv6addr); |
911 | } | 918 | } |
912 | memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len)); | 919 | memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len)); |
913 | 920 | ||
914 | GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr); | 921 | GNUNET_HashCode *key = address6_mapping_exists (&pkt6->ip6_hdr.sadr); |
915 | 922 | ||
916 | GNUNET_assert (key != NULL); | 923 | GNUNET_assert (key != NULL); |
917 | 924 | ||
@@ -968,7 +975,7 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
968 | uint32_t sadr; | 975 | uint32_t sadr; |
969 | 976 | ||
970 | new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen); | 977 | new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen); |
971 | pkt4->ip_hdr.sadr = sadr; | 978 | pkt4->ip_hdr.sadr.s_addr = sadr; |
972 | 979 | ||
973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 980 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
974 | "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, | 981 | "Relaying calc:%d gnu:%d udp:%d bytes!\n", size, |
@@ -1001,11 +1008,11 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1001 | &ipv4addr)); | 1008 | &ipv4addr)); |
1002 | inet_pton (AF_INET, ipv4addr, &dadr); | 1009 | inet_pton (AF_INET, ipv4addr, &dadr); |
1003 | GNUNET_free (ipv4addr); | 1010 | GNUNET_free (ipv4addr); |
1004 | pkt4->ip_hdr.dadr = dadr; | 1011 | pkt4->ip_hdr.dadr.s_addr = dadr; |
1005 | } | 1012 | } |
1006 | memcpy (&pkt4->udp_hdr, pkt, ntohs (pkt->len)); | 1013 | memcpy (&pkt4->udp_hdr, pkt, ntohs (pkt->len)); |
1007 | 1014 | ||
1008 | GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr); | 1015 | GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr.s_addr); |
1009 | 1016 | ||
1010 | GNUNET_assert (key != NULL); | 1017 | GNUNET_assert (key != NULL); |
1011 | 1018 | ||
@@ -1061,9 +1068,9 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1061 | GNUNET_assert (pkt6 != NULL); | 1068 | GNUNET_assert (pkt6 != NULL); |
1062 | 1069 | ||
1063 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK) | 1070 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK) |
1064 | new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); | 1071 | new_ip6addr (&pkt6->ip6_hdr.sadr, &other->hashPubKey, desc); |
1065 | else | 1072 | else |
1066 | new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen); | 1073 | new_ip6addr_remote (&pkt6->ip6_hdr.sadr, s->addr, s->addrlen); |
1067 | 1074 | ||
1068 | pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1075 | pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1069 | pkt6->shdr.size = htons (size); | 1076 | pkt6->shdr.size = htons (size); |
@@ -1086,12 +1093,12 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1086 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", | 1093 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", |
1087 | "IPV6ADDR", | 1094 | "IPV6ADDR", |
1088 | &ipv6addr)); | 1095 | &ipv6addr)); |
1089 | inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr); | 1096 | inet_pton (AF_INET6, ipv6addr, &pkt6->ip6_hdr.dadr); |
1090 | GNUNET_free (ipv6addr); | 1097 | GNUNET_free (ipv6addr); |
1091 | } | 1098 | } |
1092 | memcpy (&pkt6->tcp_hdr, pkt, pktlen); | 1099 | memcpy (&pkt6->tcp_hdr, pkt, pktlen); |
1093 | 1100 | ||
1094 | GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr); | 1101 | GNUNET_HashCode *key = address6_mapping_exists (&pkt6->ip6_hdr.sadr); |
1095 | 1102 | ||
1096 | GNUNET_assert (key != NULL); | 1103 | GNUNET_assert (key != NULL); |
1097 | 1104 | ||
@@ -1141,7 +1148,7 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1141 | uint32_t sadr; | 1148 | uint32_t sadr; |
1142 | 1149 | ||
1143 | new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen); | 1150 | new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen); |
1144 | pkt4->ip_hdr.sadr = sadr; | 1151 | pkt4->ip_hdr.sadr.s_addr = sadr; |
1145 | 1152 | ||
1146 | pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | 1153 | pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); |
1147 | pkt4->shdr.size = htons (size); | 1154 | pkt4->shdr.size = htons (size); |
@@ -1170,12 +1177,12 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1170 | &ipv4addr)); | 1177 | &ipv4addr)); |
1171 | inet_pton (AF_INET, ipv4addr, &dadr); | 1178 | inet_pton (AF_INET, ipv4addr, &dadr); |
1172 | GNUNET_free (ipv4addr); | 1179 | GNUNET_free (ipv4addr); |
1173 | pkt4->ip_hdr.dadr = dadr; | 1180 | pkt4->ip_hdr.dadr.s_addr = dadr; |
1174 | } | 1181 | } |
1175 | 1182 | ||
1176 | memcpy (&pkt4->tcp_hdr, pkt, pktlen); | 1183 | memcpy (&pkt4->tcp_hdr, pkt, pktlen); |
1177 | 1184 | ||
1178 | GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr); | 1185 | GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr.s_addr); |
1179 | 1186 | ||
1180 | GNUNET_assert (key != NULL); | 1187 | GNUNET_assert (key != NULL); |
1181 | 1188 | ||
@@ -1191,10 +1198,8 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel, | |||
1191 | uint32_t sum = 0; | 1198 | uint32_t sum = 0; |
1192 | uint32_t tmp; | 1199 | uint32_t tmp; |
1193 | 1200 | ||
1194 | tmp = pkt4->ip_hdr.sadr; | 1201 | sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.sadr, 4); |
1195 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 1202 | sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.dadr, 4); |
1196 | tmp = pkt4->ip_hdr.dadr; | ||
1197 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | ||
1198 | 1203 | ||
1199 | tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP? | 1204 | tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP? |
1200 | 1205 | ||