aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-daemon-vpn.c
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-07-27 07:28:21 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-07-27 07:28:21 +0000
commitca51d9b99345521ca990e092234e140316ff95bd (patch)
tree8d901d96a0f98f6d528eeaf6ae7c8aa76a43b7e0 /src/vpn/gnunet-daemon-vpn.c
parent51074a30f34eee12cb388451a0fd94bfa78d3dd4 (diff)
downloadgnunet-ca51d9b99345521ca990e092234e140316ff95bd.tar.gz
gnunet-ca51d9b99345521ca990e092234e140316ff95bd.zip
reply ipv4-icmp
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r--src/vpn/gnunet-daemon-vpn.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 257ab22b8..ef54cdf2d 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -113,7 +113,7 @@ cleanup(void* cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskCon
113 * @return the hash of the IP-Address if a mapping exists, NULL otherwise 113 * @return the hash of the IP-Address if a mapping exists, NULL otherwise
114 */ 114 */
115GNUNET_HashCode* 115GNUNET_HashCode*
116address_mapping_exists(unsigned char addr[]) { 116address6_mapping_exists(unsigned char addr[]) {
117 GNUNET_HashCode* key = GNUNET_malloc(sizeof(GNUNET_HashCode)); 117 GNUNET_HashCode* key = GNUNET_malloc(sizeof(GNUNET_HashCode));
118 unsigned char* k = (unsigned char*)key; 118 unsigned char* k = (unsigned char*)key;
119 memset(key, 0, sizeof(GNUNET_HashCode)); 119 memset(key, 0, sizeof(GNUNET_HashCode));
@@ -130,6 +130,34 @@ address_mapping_exists(unsigned char addr[]) {
130 } 130 }
131} 131}
132 132
133/**
134 * @return the hash of the IP-Address if a mapping exists, NULL otherwise
135 */
136GNUNET_HashCode *
137address4_mapping_exists (uint32_t addr)
138{
139 GNUNET_HashCode *key = GNUNET_malloc (sizeof (GNUNET_HashCode));
140 memset (key, 0, sizeof (GNUNET_HashCode));
141 unsigned char *c = (unsigned char *) &addr;
142 unsigned char *k = (unsigned char *) key;
143 unsigned int i;
144 for (i = 0; i < 4; i++)
145 k[3 - i] = c[i];
146
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "a4_m_e: getting with key %08x, addr is %08x, %d.%d.%d.%d\n",
149 *((uint32_t *) (key)), addr, c[0], c[1], c[2], c[3]);
150
151 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (hashmap, key))
152 return key;
153 else
154 {
155 GNUNET_free (key);
156 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Mapping not found!\n");
157 return NULL;
158 }
159}
160
133static void 161static void
134collect_mappings(void* cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext* tc) { 162collect_mappings(void* cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext* tc) {
135 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 163 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
@@ -148,7 +176,47 @@ collect_mappings(void* cls __attribute__((unused)), const struct GNUNET_SCHEDULE
148} 176}
149 177
150void 178void
151send_icmp_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { 179send_icmp4_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
180 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
181 return;
182
183 struct ip_icmp* request = cls;
184
185 struct ip_icmp* response = alloca(ntohs(request->shdr.size));
186 GNUNET_assert(response != NULL);
187 memset(response, 0, ntohs(request->shdr.size));
188
189 response->shdr.size = request->shdr.size;
190 response->shdr.type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
191
192 response->tun.flags = 0;
193 response->tun.type = htons(0x0800);
194
195 response->ip_hdr.hdr_lngth = 5;
196 response->ip_hdr.version = 4;
197 response->ip_hdr.proto = 0x01;
198 response->ip_hdr.dadr = request->ip_hdr.sadr;
199 response->ip_hdr.sadr = request->ip_hdr.dadr;
200 response->ip_hdr.tot_lngth = request->ip_hdr.tot_lngth;
201
202 response->ip_hdr.chks = calculate_ip_checksum((uint16_t*)&response->ip_hdr, 20);
203
204 response->icmp_hdr.code = 0;
205 response->icmp_hdr.type = 0x0;
206
207 /* Magic, more Magic! */
208 response->icmp_hdr.chks = request->icmp_hdr.chks + 0x8;
209
210 /* Copy the rest of the packet */
211 memcpy(response+1, request+1, ntohs(request->shdr.size) - sizeof(struct ip_icmp));
212
213 write_to_helper(response, ntohs(response->shdr.size));
214
215 GNUNET_free(request);
216}
217
218void
219send_icmp6_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
152 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 220 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
153 return; 221 return;
154 222
@@ -626,6 +694,8 @@ process_answer(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tc) {
626 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 694 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
627 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, 695 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value,
628 GNUNET_TIME_absolute_get ().abs_value); 696 GNUNET_TIME_absolute_get ().abs_value);
697 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Mapping is saved in the hashmap with key %08x.\n",
698 *((uint32_t*)(&key)));
629 if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings) 699 if (GNUNET_CONTAINER_heap_get_size(heap) > max_mappings)
630 GNUNET_SCHEDULER_add_now(collect_mappings, NULL); 700 GNUNET_SCHEDULER_add_now(collect_mappings, NULL);
631 } 701 }
@@ -766,7 +836,7 @@ receive_udp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel*
766 } 836 }
767 memcpy(&pkt6->udp_hdr, pkt, ntohs(pkt->len)); 837 memcpy(&pkt6->udp_hdr, pkt, ntohs(pkt->len));
768 838
769 GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr); 839 GNUNET_HashCode* key = address6_mapping_exists(pkt6->ip6_hdr.sadr);
770 GNUNET_assert (key != NULL); 840 GNUNET_assert (key != NULL);
771 841
772 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key); 842 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);
@@ -849,7 +919,7 @@ receive_tcp_back (void *cls __attribute__((unused)), struct GNUNET_MESH_Tunnel*
849 } 919 }
850 memcpy(&pkt6->tcp_hdr, pkt, pktlen); 920 memcpy(&pkt6->tcp_hdr, pkt, pktlen);
851 921
852 GNUNET_HashCode* key = address_mapping_exists(pkt6->ip6_hdr.sadr); 922 GNUNET_HashCode* key = address6_mapping_exists(pkt6->ip6_hdr.sadr);
853 GNUNET_assert (key != NULL); 923 GNUNET_assert (key != NULL);
854 924
855 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key); 925 struct map_entry *me = GNUNET_CONTAINER_multihashmap_get(hashmap, key);