From aab9f46b0488e0dd80c728b6d642fa4de853e63f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Fri, 29 Apr 2011 13:13:54 +0000 Subject: [PATCH] handle the reception of dns-answers in daemon-vpn --- src/vpn/gnunet-daemon-vpn.c | 77 ++++++++++++++++++++++++++++++++++++- src/vpn/gnunet-daemon-vpn.h | 4 ++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 726a013c0..6829b3cd9 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -236,6 +236,34 @@ new_ip6addr(unsigned char* buf, const GNUNET_HashCode *peer, const GNUNET_HashCo } /*}}}*/ +/** + * Create a new Address from an answer-packet + */ +void +new_ip6addr_remote (unsigned char *buf, unsigned char *addr, char addrlen) +{ /* {{{ */ + char *ipv6addr; + unsigned long long ipv6prefix; + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", + "IPV6ADDR", + &ipv6addr)); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", + "IPV6PREFIX", + &ipv6prefix)); + GNUNET_assert (ipv6prefix < 127); + ipv6prefix = (ipv6prefix + 7) / 8; + + inet_pton (AF_INET6, ipv6addr, buf); + GNUNET_free (ipv6addr); + + int local_length = 16 - ipv6prefix; + + memcpy (buf + ipv6prefix, addr, max (addrlen, local_length)); +} +/*}}}*/ + /** * This gets scheduled with cls pointing to an answer_packet and does everything * needed in order to send it to the helper. @@ -360,7 +388,54 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) { list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*)); memcpy(&list->pkt, pkt, htons(pkt->hdr.size)); } - /* TODO GNUNET_DNS_ANSWER_TYPE_REMOTE */ + else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE) + { + pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP; + + GNUNET_HashCode key; + memset(&key, 0, sizeof(GNUNET_HashCode)); + + unsigned char* c = ((unsigned char*)pkt)+ntohs(pkt->addroffset); + new_ip6addr_remote(c, &pkt->addr, pkt->addrsize); + unsigned char* k = (unsigned char*)&key; + /* + * Copy the newly generated ip-address to the key backwards (as only the first part is used in the hash-table) + */ + unsigned int i; + for (i = 0; i < 16; i++) + k[15-i] = c[i]; + + uint16_t namelen = strlen((char*)pkt->data+12)+1; + + struct map_entry* value = GNUNET_malloc(sizeof(struct map_entry) + namelen); + char* name = (char*)(value +1); + + value->namelen = namelen; + memcpy(name, pkt->data+12, namelen); + + value->addrlen = pkt->addrsize; + memcpy(&value->addr, &pkt->addr, pkt->addrsize); + memset(value->additional_ports, 0, 8192); + + memcpy(&value->hash, &key, sizeof(GNUNET_HashCode)); + + if (GNUNET_NO == + GNUNET_CONTAINER_multihashmap_contains (hashmap, &key)) + { + GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, + GNUNET_TIME_absolute_get ().abs_value); + if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings) + GNUNET_SCHEDULER_add_now(collect_mappings, NULL); + } + else + GNUNET_free(value); + + list = GNUNET_malloc(htons(pkt->hdr.size) + 2*sizeof(struct answer_packet_list*)); + + memcpy(&list->pkt, pkt, htons(pkt->hdr.size)); + } else { GNUNET_break(0); diff --git a/src/vpn/gnunet-daemon-vpn.h b/src/vpn/gnunet-daemon-vpn.h index 11d3fa43b..3ddd6eef6 100644 --- a/src/vpn/gnunet-daemon-vpn.h +++ b/src/vpn/gnunet-daemon-vpn.h @@ -70,6 +70,10 @@ extern struct GNUNET_CONTAINER_MultiHashMap* hashmap; struct map_entry { struct GNUNET_vpn_service_descriptor desc; + + char addrlen; + char addr[16]; + struct GNUNET_MESH_Tunnel *tunnel; uint16_t namelen; char additional_ports[8192]; -- 2.25.1