diff options
Diffstat (limited to 'src/vpn/gnunet-service-dns.c')
-rw-r--r-- | src/vpn/gnunet-service-dns.c | 676 |
1 files changed, 352 insertions, 324 deletions
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 489235ed4..c8d790b56 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c | |||
@@ -99,7 +99,7 @@ static struct | |||
99 | char *name; | 99 | char *name; |
100 | uint8_t namelen; | 100 | uint8_t namelen; |
101 | uint16_t qtype; | 101 | uint16_t qtype; |
102 | } query_states[UINT16_MAX+1]; | 102 | } query_states[UINT16_MAX + 1]; |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * A struct used to give more than one value as | 105 | * A struct used to give more than one value as |
@@ -122,39 +122,45 @@ struct tunnel_notify_queue | |||
122 | 122 | ||
123 | struct tunnel_state | 123 | struct tunnel_state |
124 | { | 124 | { |
125 | struct tunnel_notify_queue *head,*tail; | 125 | struct tunnel_notify_queue *head, *tail; |
126 | struct GNUNET_MESH_TransmitHandle *th; | 126 | struct GNUNET_MESH_TransmitHandle *th; |
127 | }; | 127 | }; |
128 | 128 | ||
129 | static size_t send_answer (void *cls, size_t size, void *buf); | 129 | static size_t |
130 | send_answer (void *cls, size_t size, void *buf); | ||
130 | 131 | ||
131 | static void | 132 | static void |
132 | client_disconnect(void* cls, struct GNUNET_SERVER_Client *client) | 133 | client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
133 | { | 134 | { |
134 | if (NULL == head) return; | 135 | if (NULL == head) |
136 | return; | ||
135 | 137 | ||
136 | if (head->client == client) | 138 | if (head->client == client) |
137 | { | 139 | { |
138 | GNUNET_CONNECTION_notify_transmit_ready_cancel(server_notify); | 140 | GNUNET_CONNECTION_notify_transmit_ready_cancel (server_notify); |
139 | server_notify = GNUNET_SERVER_notify_transmit_ready (head->next->client, ntohs (head->next->pkt.hdr.size), | 141 | server_notify = |
140 | GNUNET_TIME_UNIT_FOREVER_REL, | 142 | GNUNET_SERVER_notify_transmit_ready (head->next->client, |
141 | &send_answer, NULL); | 143 | ntohs (head->next->pkt.hdr.size), |
142 | } | 144 | GNUNET_TIME_UNIT_FOREVER_REL, |
145 | &send_answer, NULL); | ||
146 | } | ||
143 | 147 | ||
144 | struct answer_packet_list *element = head; | 148 | struct answer_packet_list *element = head; |
149 | |||
145 | while (element != NULL) | 150 | while (element != NULL) |
151 | { | ||
152 | if (element->client == client) | ||
146 | { | 153 | { |
147 | if (element->client == client) | 154 | GNUNET_SERVER_client_drop (client); |
148 | { | 155 | GNUNET_CONTAINER_DLL_remove (head, tail, element); |
149 | GNUNET_SERVER_client_drop(client); | 156 | struct answer_packet_list *t = element; |
150 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | 157 | |
151 | struct answer_packet_list* t = element; | 158 | element = element->next; |
152 | element = element->next; | 159 | GNUNET_free (t); |
153 | GNUNET_free(t); | ||
154 | } | ||
155 | else | ||
156 | element = element->next; | ||
157 | } | 160 | } |
161 | else | ||
162 | element = element->next; | ||
163 | } | ||
158 | } | 164 | } |
159 | 165 | ||
160 | /** | 166 | /** |
@@ -201,24 +207,26 @@ hijack (void *cls | |||
201 | } | 207 | } |
202 | 208 | ||
203 | static void * | 209 | static void * |
204 | new_tunnel (void *cls __attribute__((unused)), | 210 | new_tunnel (void *cls |
205 | struct GNUNET_MESH_Tunnel *tunnel, | 211 | __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, |
206 | const struct GNUNET_PeerIdentity *initiator __attribute__((unused)), | 212 | const struct GNUNET_PeerIdentity *initiator |
207 | const struct GNUNET_ATS_Information *ats __attribute__((unused))) | 213 | __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats |
214 | __attribute__ ((unused))) | ||
208 | { | 215 | { |
209 | struct tunnel_state *s = GNUNET_malloc(sizeof *s); | 216 | struct tunnel_state *s = GNUNET_malloc (sizeof *s); |
210 | s->head = NULL; | 217 | |
211 | s->tail = NULL; | 218 | s->head = NULL; |
212 | s->th = NULL; | 219 | s->tail = NULL; |
213 | return s; | 220 | s->th = NULL; |
221 | return s; | ||
214 | } | 222 | } |
215 | 223 | ||
216 | static void | 224 | static void |
217 | clean_tunnel (void *cls __attribute__((unused)), | 225 | clean_tunnel (void *cls |
218 | const struct GNUNET_MESH_Tunnel *tunnel, | 226 | __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel, |
219 | void *tunnel_ctx) | 227 | void *tunnel_ctx) |
220 | { | 228 | { |
221 | GNUNET_free(tunnel_ctx); | 229 | GNUNET_free (tunnel_ctx); |
222 | } | 230 | } |
223 | 231 | ||
224 | /** | 232 | /** |
@@ -246,10 +254,10 @@ unhijack (unsigned short port) | |||
246 | GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns", | 254 | GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns", |
247 | "gnunet-hijack-dns", "-d", port_s, virt_dns, | 255 | "gnunet-hijack-dns", "-d", port_s, virt_dns, |
248 | NULL))) | 256 | NULL))) |
249 | { | 257 | { |
250 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc)); | 258 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (proc)); |
251 | GNUNET_OS_process_close (proc); | 259 | GNUNET_OS_process_close (proc); |
252 | } | 260 | } |
253 | GNUNET_free (virt_dns); | 261 | GNUNET_free (virt_dns); |
254 | } | 262 | } |
255 | 263 | ||
@@ -272,11 +280,13 @@ send_answer (void *cls, size_t size, void *buf) | |||
272 | 280 | ||
273 | /* When more data is to be sent, reschedule */ | 281 | /* When more data is to be sent, reschedule */ |
274 | if (head != NULL) | 282 | if (head != NULL) |
275 | server_notify = GNUNET_SERVER_notify_transmit_ready (head->client, ntohs (head->pkt.hdr.size), | 283 | server_notify = |
276 | GNUNET_TIME_UNIT_FOREVER_REL, | 284 | GNUNET_SERVER_notify_transmit_ready (head->client, |
277 | &send_answer, NULL); | 285 | ntohs (head->pkt.hdr.size), |
286 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
287 | &send_answer, NULL); | ||
278 | 288 | ||
279 | GNUNET_SERVER_client_drop(query->client); | 289 | GNUNET_SERVER_client_drop (query->client); |
280 | GNUNET_free (query); | 290 | GNUNET_free (query); |
281 | return len; | 291 | return len; |
282 | } | 292 | } |
@@ -311,7 +321,8 @@ mesh_send_response (void *cls, size_t size, void *buf) | |||
311 | GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader))); | 321 | GNUNET_assert (size >= (*sz + sizeof (struct GNUNET_MessageHeader))); |
312 | 322 | ||
313 | memcpy (hdr + 1, dns, *sz); | 323 | memcpy (hdr + 1, dns, *sz); |
314 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel); | 324 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel); |
325 | |||
315 | if (NULL != s->head) | 326 | if (NULL != s->head) |
316 | { | 327 | { |
317 | struct tunnel_notify_queue *element = s->head; | 328 | struct tunnel_notify_queue *element = s->head; |
@@ -321,14 +332,12 @@ mesh_send_response (void *cls, size_t size, void *buf) | |||
321 | GNUNET_CONTAINER_DLL_remove (head, tail, element); | 332 | GNUNET_CONTAINER_DLL_remove (head, tail, element); |
322 | 333 | ||
323 | s->th = | 334 | s->th = |
324 | GNUNET_MESH_notify_transmit_ready (*tunnel, | 335 | GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, |
325 | GNUNET_NO, | ||
326 | 42, | ||
327 | GNUNET_TIME_relative_divide | 336 | GNUNET_TIME_relative_divide |
328 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 337 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
329 | (const struct GNUNET_PeerIdentity *) | 338 | (const struct GNUNET_PeerIdentity *) |
330 | NULL, element->len, | 339 | NULL, element->len, element->cb, |
331 | element->cb, element->cls); | 340 | element->cls); |
332 | } | 341 | } |
333 | 342 | ||
334 | GNUNET_free (cls); | 343 | GNUNET_free (cls); |
@@ -350,27 +359,23 @@ mesh_send (void *cls, size_t size, void *buf) | |||
350 | 359 | ||
351 | memcpy (buf, &cls_->hdr, size); | 360 | memcpy (buf, &cls_->hdr, size); |
352 | 361 | ||
353 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel); | 362 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel); |
363 | |||
354 | if (NULL != s->head) | 364 | if (NULL != s->head) |
355 | { | 365 | { |
356 | struct tunnel_notify_queue *element = | 366 | struct tunnel_notify_queue *element = s->head; |
357 | s->head; | 367 | struct tunnel_notify_queue *head = s->head; |
358 | struct tunnel_notify_queue *head = | 368 | struct tunnel_notify_queue *tail = s->tail;; |
359 | s->head; | ||
360 | struct tunnel_notify_queue *tail = | ||
361 | s->tail;; | ||
362 | 369 | ||
363 | GNUNET_CONTAINER_DLL_remove (head, tail, element); | 370 | GNUNET_CONTAINER_DLL_remove (head, tail, element); |
364 | 371 | ||
365 | s->th = | 372 | s->th = |
366 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, | 373 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_NO, 42, |
367 | GNUNET_NO, | ||
368 | 42, | ||
369 | GNUNET_TIME_relative_divide | 374 | GNUNET_TIME_relative_divide |
370 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 375 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
371 | (const struct GNUNET_PeerIdentity *) | 376 | (const struct GNUNET_PeerIdentity *) |
372 | NULL, element->len, | 377 | NULL, element->len, element->cb, |
373 | element->cb, element->cls); | 378 | element->cls); |
374 | 379 | ||
375 | GNUNET_free (element); | 380 | GNUNET_free (element); |
376 | } | 381 | } |
@@ -392,26 +397,20 @@ mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
392 | "Connected to peer %s, %x, sending query with id %d\n", | 397 | "Connected to peer %s, %x, sending query with id %d\n", |
393 | GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id)); | 398 | GNUNET_i2s (peer), peer, ntohs (cls_->dns.s.id)); |
394 | 399 | ||
395 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(cls_->tunnel); | 400 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (cls_->tunnel); |
401 | |||
396 | if (NULL == s->head) | 402 | if (NULL == s->head) |
397 | { | 403 | { |
398 | s->th = | 404 | s->th = |
399 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, | 405 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, GNUNET_YES, 42, |
400 | GNUNET_YES, | 406 | GNUNET_TIME_UNIT_MINUTES, NULL, |
401 | 42, | 407 | cls_->hdr.size, mesh_send, cls); |
402 | GNUNET_TIME_UNIT_MINUTES, | ||
403 | NULL, | ||
404 | cls_->hdr.size, | ||
405 | mesh_send, | ||
406 | cls); | ||
407 | 408 | ||
408 | } | 409 | } |
409 | else | 410 | else |
410 | { | 411 | { |
411 | struct tunnel_notify_queue *head = | 412 | struct tunnel_notify_queue *head = s->head; |
412 | s->head; | 413 | struct tunnel_notify_queue *tail = s->tail; |
413 | struct tunnel_notify_queue *tail = | ||
414 | s->tail; | ||
415 | 414 | ||
416 | struct tunnel_notify_queue *element = | 415 | struct tunnel_notify_queue *element = |
417 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); | 416 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); |
@@ -432,13 +431,14 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
432 | 431 | ||
433 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; | 432 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; |
434 | 433 | ||
435 | struct tunnel_state *s = GNUNET_malloc(sizeof *s); | 434 | struct tunnel_state *s = GNUNET_malloc (sizeof *s); |
435 | |||
436 | s->head = NULL; | 436 | s->head = NULL; |
437 | s->tail = NULL; | 437 | s->tail = NULL; |
438 | s->th = NULL; | 438 | s->th = NULL; |
439 | 439 | ||
440 | cls_->tunnel = | 440 | cls_->tunnel = |
441 | GNUNET_MESH_tunnel_create(mesh_handle, s, mesh_connect, NULL, cls_); | 441 | GNUNET_MESH_tunnel_create (mesh_handle, s, mesh_connect, NULL, cls_); |
442 | 442 | ||
443 | GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel, | 443 | GNUNET_MESH_peer_request_connect_by_type (cls_->tunnel, |
444 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER); | 444 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER); |
@@ -461,12 +461,15 @@ receive_mesh_query (void *cls | |||
461 | 461 | ||
462 | struct sockaddr_in dest; | 462 | struct sockaddr_in dest; |
463 | 463 | ||
464 | struct dns_pkt_parsed *pdns = parse_dns_packet(dns); | 464 | struct dns_pkt_parsed *pdns = parse_dns_packet (dns); |
465 | 465 | ||
466 | memset (&dest, 0, sizeof dest); | 466 | memset (&dest, 0, sizeof dest); |
467 | dest.sin_port = htons (53); | 467 | dest.sin_port = htons (53); |
468 | char *dns_resolver; | 468 | char *dns_resolver; |
469 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "dns", "EXTERNAL_DNS", &dns_resolver) || | 469 | |
470 | if (GNUNET_OK != | ||
471 | GNUNET_CONFIGURATION_get_value_string (cfg, "dns", "EXTERNAL_DNS", | ||
472 | &dns_resolver) || | ||
470 | 1 != inet_pton (AF_INET, dns_resolver, &dest.sin_addr)) | 473 | 1 != inet_pton (AF_INET, dns_resolver, &dest.sin_addr)) |
471 | inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr); | 474 | inet_pton (AF_INET, "8.8.8.8", &dest.sin_addr); |
472 | 475 | ||
@@ -476,16 +479,17 @@ receive_mesh_query (void *cls | |||
476 | query_states[dns->s.id].valid = GNUNET_YES; | 479 | query_states[dns->s.id].valid = GNUNET_YES; |
477 | 480 | ||
478 | int i; | 481 | int i; |
479 | for (i= 0; i < ntohs(pdns->s.qdcount); i++) | 482 | |
483 | for (i = 0; i < ntohs (pdns->s.qdcount); i++) | ||
484 | { | ||
485 | if (pdns->queries[i]->qtype == htons (28) || | ||
486 | pdns->queries[i]->qtype == htons (1)) | ||
480 | { | 487 | { |
481 | if (pdns->queries[i]->qtype == htons(28) || | 488 | query_states[dns->s.id].qtype = pdns->queries[i]->qtype; |
482 | pdns->queries[i]->qtype == htons(1)) | 489 | break; |
483 | { | ||
484 | query_states[dns->s.id].qtype = pdns->queries[i]->qtype; | ||
485 | break; | ||
486 | } | ||
487 | } | 490 | } |
488 | free_parsed_dns_packet(pdns); | 491 | } |
492 | free_parsed_dns_packet (pdns); | ||
489 | 493 | ||
490 | GNUNET_NETWORK_socket_sendto (dnsout, dns, | 494 | GNUNET_NETWORK_socket_sendto (dnsout, dns, |
491 | ntohs (message->size) - | 495 | ntohs (message->size) - |
@@ -528,7 +532,8 @@ receive_mesh_answer (void *cls | |||
528 | + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ | 532 | + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ |
529 | 533 | ||
530 | struct answer_packet_list *answer = | 534 | struct answer_packet_list *answer = |
531 | GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); | 535 | GNUNET_malloc (len + sizeof (struct answer_packet_list) - |
536 | sizeof (struct answer_packet)); | ||
532 | 537 | ||
533 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | 538 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); |
534 | answer->pkt.hdr.size = htons (len); | 539 | answer->pkt.hdr.size = htons (len); |
@@ -546,17 +551,18 @@ receive_mesh_answer (void *cls | |||
546 | 551 | ||
547 | int i = 0; | 552 | int i = 0; |
548 | 553 | ||
549 | while (i < ntohs(pdns->s.ancount) && | 554 | while (i < ntohs (pdns->s.ancount) && ntohs (pdns->answers[i]->type) != 28 && |
550 | ntohs(pdns->answers[i]->type) != 28 && | 555 | ntohs (pdns->answers[i]->type) != 1) |
551 | ntohs(pdns->answers[i]->type) != 1) | 556 | { |
552 | { | 557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n", |
553 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n", ntohs(pdns->answers[i]->type)); | 558 | ntohs (pdns->answers[i]->type)); |
554 | i++; | 559 | i++; |
555 | } | 560 | } |
556 | 561 | ||
557 | if (i >= ntohs (pdns->s.ancount)) | 562 | if (i >= ntohs (pdns->s.ancount)) |
558 | { | 563 | { |
559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer does not contain any usable answers.\n"); | 564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
565 | "Answer does not contain any usable answers.\n"); | ||
560 | free_parsed_dns_packet (pdns); | 566 | free_parsed_dns_packet (pdns); |
561 | GNUNET_free (answer); | 567 | GNUNET_free (answer); |
562 | return GNUNET_OK; | 568 | return GNUNET_OK; |
@@ -568,8 +574,10 @@ receive_mesh_answer (void *cls | |||
568 | memcpy (answer->pkt.addr, pdns->answers[i]->data, | 574 | memcpy (answer->pkt.addr, pdns->answers[i]->data, |
569 | ntohs (pdns->answers[i]->data_len)); | 575 | ntohs (pdns->answers[i]->data_len)); |
570 | 576 | ||
571 | memcpy(answer->pkt.from, query_states[dns->s.id].remote_ip, query_states[dns->s.id].addrlen); | 577 | memcpy (answer->pkt.from, query_states[dns->s.id].remote_ip, |
572 | memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, query_states[dns->s.id].addrlen); | 578 | query_states[dns->s.id].addrlen); |
579 | memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, | ||
580 | query_states[dns->s.id].addrlen); | ||
573 | answer->pkt.addrlen = query_states[dns->s.id].addrlen; | 581 | answer->pkt.addrlen = query_states[dns->s.id].addrlen; |
574 | answer->pkt.dst_port = query_states[dns->s.id].local_port; | 582 | answer->pkt.dst_port = query_states[dns->s.id].local_port; |
575 | 583 | ||
@@ -595,14 +603,14 @@ receive_mesh_answer (void *cls | |||
595 | (struct dns_record_line *) (dpkt->data + | 603 | (struct dns_record_line *) (dpkt->data + |
596 | (query_states[dns->s.id].namelen) + | 604 | (query_states[dns->s.id].namelen) + |
597 | sizeof (struct dns_query_line) + 2); | 605 | sizeof (struct dns_query_line) + 2); |
598 | if (htons(28) == query_states[dns->s.id].qtype) | 606 | if (htons (28) == query_states[dns->s.id].qtype) |
599 | { | 607 | { |
600 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA; | 608 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA; |
601 | dque->type = htons (28); /* AAAA */ | 609 | dque->type = htons (28); /* AAAA */ |
602 | drec_data->type = htons (28); /* AAAA */ | 610 | drec_data->type = htons (28); /* AAAA */ |
603 | drec_data->data_len = htons (16); | 611 | drec_data->data_len = htons (16); |
604 | } | 612 | } |
605 | else if (htons(1) == query_states[dns->s.id].qtype) | 613 | else if (htons (1) == query_states[dns->s.id].qtype) |
606 | { | 614 | { |
607 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A; | 615 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REMOTE_A; |
608 | dque->type = htons (1); /* A */ | 616 | dque->type = htons (1); /* A */ |
@@ -610,10 +618,11 @@ receive_mesh_answer (void *cls | |||
610 | drec_data->data_len = htons (4); | 618 | drec_data->data_len = htons (4); |
611 | } | 619 | } |
612 | else | 620 | else |
613 | { | 621 | { |
614 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n", query_states[dns->s.id].qtype); | 622 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dns-answer with pending qtype = %d\n", |
615 | GNUNET_assert(0); | 623 | query_states[dns->s.id].qtype); |
616 | } | 624 | GNUNET_assert (0); |
625 | } | ||
617 | dque->class = htons (1); /* IN */ | 626 | dque->class = htons (1); /* IN */ |
618 | 627 | ||
619 | char *anname = | 628 | char *anname = |
@@ -634,10 +643,10 @@ receive_mesh_answer (void *cls | |||
634 | answer->client = query_states[dns->s.id].client; | 643 | answer->client = query_states[dns->s.id].client; |
635 | 644 | ||
636 | if (server_notify == NULL) | 645 | if (server_notify == NULL) |
637 | server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, len, | 646 | server_notify = |
638 | GNUNET_TIME_UNIT_FOREVER_REL, | 647 | GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, |
639 | &send_answer, | 648 | len, GNUNET_TIME_UNIT_FOREVER_REL, |
640 | NULL); | 649 | &send_answer, NULL); |
641 | 650 | ||
642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 651 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
643 | "Sent answer of length %d on to client, addroffset = %d\n", len, | 652 | "Sent answer of length %d on to client, addroffset = %d\n", len, |
@@ -672,14 +681,16 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
672 | 2 /* We do not know the lenght of the answer yet */ ; | 681 | 2 /* We do not know the lenght of the answer yet */ ; |
673 | 682 | ||
674 | struct answer_packet_list *answer = | 683 | struct answer_packet_list *answer = |
675 | GNUNET_malloc (len + sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); | 684 | GNUNET_malloc (len + sizeof (struct answer_packet_list) - |
685 | sizeof (struct answer_packet)); | ||
676 | 686 | ||
677 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | 687 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); |
678 | answer->pkt.hdr.size = htons (len); | 688 | answer->pkt.hdr.size = htons (len); |
679 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV; | 689 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_REV; |
680 | 690 | ||
681 | memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen); | 691 | memcpy (answer->pkt.from, query_states[id].remote_ip, |
682 | memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); | 692 | query_states[id].addrlen); |
693 | memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); | ||
683 | 694 | ||
684 | answer->pkt.dst_port = query_states[id].local_port; | 695 | answer->pkt.dst_port = query_states[id].local_port; |
685 | 696 | ||
@@ -728,9 +739,10 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
728 | answer->client = query_states[id].client; | 739 | answer->client = query_states[id].client; |
729 | 740 | ||
730 | if (server_notify == NULL) | 741 | if (server_notify == NULL) |
731 | server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len, | 742 | server_notify = |
732 | GNUNET_TIME_UNIT_FOREVER_REL, | 743 | GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len, |
733 | &send_answer, NULL); | 744 | GNUNET_TIME_UNIT_FOREVER_REL, |
745 | &send_answer, NULL); | ||
734 | } | 746 | } |
735 | 747 | ||
736 | /** | 748 | /** |
@@ -740,11 +752,12 @@ static void | |||
740 | receive_dht (void *cls, struct GNUNET_TIME_Absolute exp | 752 | receive_dht (void *cls, struct GNUNET_TIME_Absolute exp |
741 | __attribute__ ((unused)), const GNUNET_HashCode * key | 753 | __attribute__ ((unused)), const GNUNET_HashCode * key |
742 | __attribute__ ((unused)), | 754 | __attribute__ ((unused)), |
743 | const struct GNUNET_PeerIdentity *get_path __attribute__ ((unused)), | 755 | const struct GNUNET_PeerIdentity *get_path |
744 | unsigned int get_path_length __attribute__ ((unused)), | 756 | __attribute__ ((unused)), unsigned int get_path_length |
745 | const struct GNUNET_PeerIdentity *put_path __attribute__ ((unused)), | 757 | __attribute__ ((unused)), |
746 | unsigned int put_path_length __attribute__ ((unused)), | 758 | const struct GNUNET_PeerIdentity *put_path |
747 | enum GNUNET_BLOCK_Type type, size_t size, | 759 | __attribute__ ((unused)), unsigned int put_path_length |
760 | __attribute__ ((unused)), enum GNUNET_BLOCK_Type type, size_t size, | ||
748 | const void *data) | 761 | const void *data) |
749 | { | 762 | { |
750 | 763 | ||
@@ -773,8 +786,8 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp | |||
773 | + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ | 786 | + sizeof (struct dns_record_line) - 1 + 16; /* To hold the IPv6-Address */ |
774 | 787 | ||
775 | struct answer_packet_list *answer = | 788 | struct answer_packet_list *answer = |
776 | GNUNET_malloc (len + | 789 | GNUNET_malloc (len + sizeof (struct answer_packet_list) - |
777 | sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); | 790 | sizeof (struct answer_packet)); |
778 | 791 | ||
779 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | 792 | answer->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); |
780 | answer->pkt.hdr.size = htons (len); | 793 | answer->pkt.hdr.size = htons (len); |
@@ -792,8 +805,9 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp | |||
792 | memcpy (&answer->pkt.service_descr.ports, &rec->ports, | 805 | memcpy (&answer->pkt.service_descr.ports, &rec->ports, |
793 | sizeof (answer->pkt.service_descr.ports)); | 806 | sizeof (answer->pkt.service_descr.ports)); |
794 | 807 | ||
795 | memcpy(answer->pkt.from, query_states[id].remote_ip, query_states[id].addrlen); | 808 | memcpy (answer->pkt.from, query_states[id].remote_ip, |
796 | memcpy(answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); | 809 | query_states[id].addrlen); |
810 | memcpy (answer->pkt.to, query_states[id].local_ip, query_states[id].addrlen); | ||
797 | answer->pkt.addrlen = query_states[id].addrlen; | 811 | answer->pkt.addrlen = query_states[id].addrlen; |
798 | 812 | ||
799 | answer->pkt.dst_port = query_states[id].local_port; | 813 | answer->pkt.dst_port = query_states[id].local_port; |
@@ -844,9 +858,10 @@ receive_dht (void *cls, struct GNUNET_TIME_Absolute exp | |||
844 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); | 858 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); |
845 | 859 | ||
846 | if (server_notify == NULL) | 860 | if (server_notify == NULL) |
847 | server_notify = GNUNET_SERVER_notify_transmit_ready (answer->client, len, | 861 | server_notify = |
848 | GNUNET_TIME_UNIT_FOREVER_REL, | 862 | GNUNET_SERVER_notify_transmit_ready (answer->client, len, |
849 | &send_answer, NULL); | 863 | GNUNET_TIME_UNIT_FOREVER_REL, |
864 | &send_answer, NULL); | ||
850 | } | 865 | } |
851 | 866 | ||
852 | /** | 867 | /** |
@@ -877,11 +892,11 @@ receive_query (void *cls | |||
877 | 892 | ||
878 | query_states[dns->s.id].valid = GNUNET_YES; | 893 | query_states[dns->s.id].valid = GNUNET_YES; |
879 | query_states[dns->s.id].client = client; | 894 | query_states[dns->s.id].client = client; |
880 | GNUNET_SERVER_client_keep(client); | 895 | GNUNET_SERVER_client_keep (client); |
881 | memcpy(query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen); | 896 | memcpy (query_states[dns->s.id].local_ip, pkt->orig_from, pkt->addrlen); |
882 | query_states[dns->s.id].addrlen = pkt->addrlen; | 897 | query_states[dns->s.id].addrlen = pkt->addrlen; |
883 | query_states[dns->s.id].local_port = pkt->src_port; | 898 | query_states[dns->s.id].local_port = pkt->src_port; |
884 | memcpy(query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen); | 899 | memcpy (query_states[dns->s.id].remote_ip, pkt->orig_to, pkt->addrlen); |
885 | query_states[dns->s.id].namelen = strlen ((char *) dns->data) + 1; | 900 | query_states[dns->s.id].namelen = strlen ((char *) dns->data) + 1; |
886 | if (query_states[dns->s.id].name != NULL) | 901 | if (query_states[dns->s.id].name != NULL) |
887 | GNUNET_free (query_states[dns->s.id].name); | 902 | GNUNET_free (query_states[dns->s.id].name); |
@@ -891,15 +906,16 @@ receive_query (void *cls | |||
891 | query_states[dns->s.id].namelen); | 906 | query_states[dns->s.id].namelen); |
892 | 907 | ||
893 | int i; | 908 | int i; |
894 | for (i= 0; i < ntohs(pdns->s.qdcount); i++) | 909 | |
910 | for (i = 0; i < ntohs (pdns->s.qdcount); i++) | ||
911 | { | ||
912 | if (pdns->queries[i]->qtype == htons (28) || | ||
913 | pdns->queries[i]->qtype == htons (1)) | ||
895 | { | 914 | { |
896 | if (pdns->queries[i]->qtype == htons(28) || | 915 | query_states[dns->s.id].qtype = pdns->queries[i]->qtype; |
897 | pdns->queries[i]->qtype == htons(1)) | 916 | break; |
898 | { | ||
899 | query_states[dns->s.id].qtype = pdns->queries[i]->qtype; | ||
900 | break; | ||
901 | } | ||
902 | } | 917 | } |
918 | } | ||
903 | 919 | ||
904 | /* The query is for a .gnunet-address */ | 920 | /* The query is for a .gnunet-address */ |
905 | if (pdns->queries[0]->namelen > 9 && | 921 | if (pdns->queries[0]->namelen > 9 && |
@@ -922,8 +938,8 @@ receive_query (void *cls | |||
922 | cls->handle = | 938 | cls->handle = |
923 | GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES, | 939 | GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES, |
924 | GNUNET_BLOCK_TYPE_DNS, &key, | 940 | GNUNET_BLOCK_TYPE_DNS, &key, |
925 | 5 /* DEFAULT_GET_REPLICATION */, GNUNET_DHT_RO_NONE, NULL, | 941 | 5 /* DEFAULT_GET_REPLICATION */ , |
926 | 0, &receive_dht, cls); | 942 | GNUNET_DHT_RO_NONE, NULL, 0, &receive_dht, cls); |
927 | 943 | ||
928 | goto outfree; | 944 | goto outfree; |
929 | } | 945 | } |
@@ -992,53 +1008,55 @@ receive_query (void *cls | |||
992 | unsigned char virt_dns_bytes[16]; | 1008 | unsigned char virt_dns_bytes[16]; |
993 | 1009 | ||
994 | if (pkt->addrlen == 4) | 1010 | if (pkt->addrlen == 4) |
995 | { | 1011 | { |
996 | char *virt_dns; | 1012 | char *virt_dns; |
997 | |||
998 | if (GNUNET_SYSERR == | ||
999 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", &virt_dns)) | ||
1000 | { | ||
1001 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1002 | "No entry 'VIRTDNS' in configuration!\n"); | ||
1003 | exit (1); | ||
1004 | } | ||
1005 | |||
1006 | if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) | ||
1007 | { | ||
1008 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n", | ||
1009 | virt_dns); | ||
1010 | exit (1); | ||
1011 | } | ||
1012 | 1013 | ||
1013 | GNUNET_free (virt_dns); | 1014 | if (GNUNET_SYSERR == |
1014 | } | 1015 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", |
1015 | else if (pkt->addrlen == 16) | 1016 | &virt_dns)) |
1016 | { | 1017 | { |
1017 | char *virt_dns; | 1018 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1019 | "No entry 'VIRTDNS' in configuration!\n"); | ||
1020 | exit (1); | ||
1021 | } | ||
1018 | 1022 | ||
1019 | if (GNUNET_SYSERR == | 1023 | if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) |
1020 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6", &virt_dns)) | 1024 | { |
1021 | { | 1025 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n", |
1022 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1026 | virt_dns); |
1023 | "No entry 'VIRTDNS6' in configuration!\n"); | 1027 | exit (1); |
1024 | exit (1); | 1028 | } |
1025 | } | ||
1026 | 1029 | ||
1027 | if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes)) | 1030 | GNUNET_free (virt_dns); |
1028 | { | 1031 | } |
1029 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS6': %s; %m!\n", | 1032 | else if (pkt->addrlen == 16) |
1030 | virt_dns); | 1033 | { |
1031 | exit (1); | 1034 | char *virt_dns; |
1032 | } | ||
1033 | 1035 | ||
1034 | GNUNET_free (virt_dns); | 1036 | if (GNUNET_SYSERR == |
1037 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS6", | ||
1038 | &virt_dns)) | ||
1039 | { | ||
1040 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1041 | "No entry 'VIRTDNS6' in configuration!\n"); | ||
1042 | exit (1); | ||
1035 | } | 1043 | } |
1036 | else | 1044 | |
1045 | if (1 != inet_pton (AF_INET6, virt_dns, &virt_dns_bytes)) | ||
1037 | { | 1046 | { |
1038 | GNUNET_assert(0); | 1047 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1048 | "Error parsing 'VIRTDNS6': %s; %m!\n", virt_dns); | ||
1049 | exit (1); | ||
1039 | } | 1050 | } |
1040 | 1051 | ||
1041 | if (memcmp(virt_dns_bytes,pkt->orig_to, pkt->addrlen) == 0) | 1052 | GNUNET_free (virt_dns); |
1053 | } | ||
1054 | else | ||
1055 | { | ||
1056 | GNUNET_assert (0); | ||
1057 | } | ||
1058 | |||
1059 | if (memcmp (virt_dns_bytes, pkt->orig_to, pkt->addrlen) == 0) | ||
1042 | { | 1060 | { |
1043 | /* This is a packet that was sent directly to the virtual dns-server | 1061 | /* This is a packet that was sent directly to the virtual dns-server |
1044 | * | 1062 | * |
@@ -1061,36 +1079,36 @@ receive_query (void *cls | |||
1061 | cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); | 1079 | cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); |
1062 | GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); | 1080 | GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); |
1063 | 1081 | ||
1064 | if (ntohs(pdns->s.qdcount) == 1) | 1082 | if (ntohs (pdns->s.qdcount) == 1) |
1083 | { | ||
1084 | if (ntohs (pdns->queries[0]->qtype) == 1) | ||
1085 | pdns->queries[0]->qtype = htons (28); | ||
1086 | else if (ntohs (pdns->queries[0]->qtype) == 28) | ||
1087 | pdns->queries[0]->qtype = htons (1); | ||
1088 | else | ||
1065 | { | 1089 | { |
1066 | if (ntohs(pdns->queries[0]->qtype) == 1) | 1090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n"); |
1067 | pdns->queries[0]->qtype = htons(28); | 1091 | goto outfree; |
1068 | else if (ntohs(pdns->queries[0]->qtype) == 28) | 1092 | } |
1069 | pdns->queries[0]->qtype = htons(1); | 1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n"); |
1070 | else | 1094 | struct dns_pkt *rdns = unparse_dns_packet (pdns); |
1071 | { | 1095 | size_t size = |
1072 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n"); | ||
1073 | goto outfree; | ||
1074 | } | ||
1075 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n"); | ||
1076 | struct dns_pkt *rdns = unparse_dns_packet (pdns); | ||
1077 | size_t size = | ||
1078 | sizeof (struct GNUNET_MESH_Tunnel *) + | 1096 | sizeof (struct GNUNET_MESH_Tunnel *) + |
1079 | sizeof (struct GNUNET_MessageHeader) + (ntohs (message->size) - | 1097 | sizeof (struct GNUNET_MessageHeader) + (ntohs (message->size) - |
1080 | sizeof (struct query_packet) + | 1098 | sizeof (struct query_packet) + |
1081 | 1); | 1099 | 1); |
1082 | struct tunnel_cls *cls_ = GNUNET_malloc (size); | 1100 | struct tunnel_cls *cls_ = GNUNET_malloc (size); |
1083 | 1101 | ||
1084 | cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *); | 1102 | cls_->hdr.size = size - sizeof (struct GNUNET_MESH_Tunnel *); |
1085 | 1103 | ||
1086 | cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS); | 1104 | cls_->hdr.type = ntohs (GNUNET_MESSAGE_TYPE_VPN_REMOTE_QUERY_DNS); |
1087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size); | 1105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "size: %d\n", size); |
1088 | 1106 | ||
1089 | memcpy (&cls_->dns, rdns, | 1107 | memcpy (&cls_->dns, rdns, |
1090 | cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); | 1108 | cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); |
1091 | GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); | 1109 | GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); |
1092 | GNUNET_free (rdns); | 1110 | GNUNET_free (rdns); |
1093 | } | 1111 | } |
1094 | 1112 | ||
1095 | goto outfree; | 1113 | goto outfree; |
1096 | } | 1114 | } |
@@ -1098,31 +1116,31 @@ receive_query (void *cls | |||
1098 | 1116 | ||
1099 | /* The query should be sent to the network */ | 1117 | /* The query should be sent to the network */ |
1100 | if (pkt->addrlen == 4) | 1118 | if (pkt->addrlen == 4) |
1101 | { | 1119 | { |
1102 | struct sockaddr_in dest; | 1120 | struct sockaddr_in dest; |
1103 | 1121 | ||
1104 | memset (&dest, 0, sizeof dest); | 1122 | memset (&dest, 0, sizeof dest); |
1105 | dest.sin_port = htons (53); | 1123 | dest.sin_port = htons (53); |
1106 | memcpy(&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen); | 1124 | memcpy (&dest.sin_addr.s_addr, pkt->orig_to, pkt->addrlen); |
1107 | 1125 | ||
1108 | GNUNET_NETWORK_socket_sendto (dnsout, dns, | 1126 | GNUNET_NETWORK_socket_sendto (dnsout, dns, |
1109 | ntohs (pkt->hdr.size) - | 1127 | ntohs (pkt->hdr.size) - |
1110 | sizeof (struct query_packet) + 1, | 1128 | sizeof (struct query_packet) + 1, |
1111 | (struct sockaddr *) &dest, sizeof dest); | 1129 | (struct sockaddr *) &dest, sizeof dest); |
1112 | } | 1130 | } |
1113 | else if (pkt->addrlen == 16) | 1131 | else if (pkt->addrlen == 16) |
1114 | { | 1132 | { |
1115 | struct sockaddr_in6 dest; | 1133 | struct sockaddr_in6 dest; |
1116 | 1134 | ||
1117 | memset (&dest, 0, sizeof dest); | 1135 | memset (&dest, 0, sizeof dest); |
1118 | dest.sin6_port = htons (53); | 1136 | dest.sin6_port = htons (53); |
1119 | memcpy(&dest.sin6_addr, pkt->orig_to, pkt->addrlen); | 1137 | memcpy (&dest.sin6_addr, pkt->orig_to, pkt->addrlen); |
1120 | 1138 | ||
1121 | GNUNET_NETWORK_socket_sendto (dnsout6, dns, | 1139 | GNUNET_NETWORK_socket_sendto (dnsout6, dns, |
1122 | ntohs (pkt->hdr.size) - | 1140 | ntohs (pkt->hdr.size) - |
1123 | sizeof (struct query_packet) + 1, | 1141 | sizeof (struct query_packet) + 1, |
1124 | (struct sockaddr *) &dest, sizeof dest); | 1142 | (struct sockaddr *) &dest, sizeof dest); |
1125 | } | 1143 | } |
1126 | 1144 | ||
1127 | outfree: | 1145 | outfree: |
1128 | free_parsed_dns_packet (pdns); | 1146 | free_parsed_dns_packet (pdns); |
@@ -1144,10 +1162,10 @@ open_port6 () | |||
1144 | 1162 | ||
1145 | dnsout6 = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_DGRAM, 0); | 1163 | dnsout6 = GNUNET_NETWORK_socket_create (AF_INET6, SOCK_DGRAM, 0); |
1146 | if (dnsout6 == NULL) | 1164 | if (dnsout6 == NULL) |
1147 | { | 1165 | { |
1148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n"); | 1166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create socket: %m\n"); |
1149 | return GNUNET_SYSERR; | 1167 | return GNUNET_SYSERR; |
1150 | } | 1168 | } |
1151 | memset (&addr, 0, sizeof (struct sockaddr_in6)); | 1169 | memset (&addr, 0, sizeof (struct sockaddr_in6)); |
1152 | 1170 | ||
1153 | addr.sin6_family = AF_INET6; | 1171 | addr.sin6_family = AF_INET6; |
@@ -1205,7 +1223,9 @@ open_port () | |||
1205 | return GNUNET_YES; | 1223 | return GNUNET_YES; |
1206 | } | 1224 | } |
1207 | 1225 | ||
1208 | void handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r); | 1226 | void |
1227 | handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen, | ||
1228 | int r); | ||
1209 | 1229 | ||
1210 | /** | 1230 | /** |
1211 | * Read a response-packet of the UDP-Socket | 1231 | * Read a response-packet of the UDP-Socket |
@@ -1228,7 +1248,7 @@ read_response6 (void *cls | |||
1228 | #ifndef MINGW | 1248 | #ifndef MINGW |
1229 | if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout6), FIONREAD, &len)) | 1249 | if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout6), FIONREAD, &len)) |
1230 | { | 1250 | { |
1231 | (void)open_port6 (); | 1251 | (void) open_port6 (); |
1232 | return; | 1252 | return; |
1233 | } | 1253 | } |
1234 | #else | 1254 | #else |
@@ -1243,14 +1263,15 @@ read_response6 (void *cls | |||
1243 | (struct sockaddr *) &addr, &addrlen); | 1263 | (struct sockaddr *) &addr, &addrlen); |
1244 | 1264 | ||
1245 | if (r < 0) | 1265 | if (r < 0) |
1246 | { | 1266 | { |
1247 | (void)open_port6 (); | 1267 | (void) open_port6 (); |
1248 | return; | 1268 | return; |
1249 | } | 1269 | } |
1270 | |||
1271 | struct sockaddr *addr_ = GNUNET_malloc (sizeof addr); | ||
1250 | 1272 | ||
1251 | struct sockaddr *addr_ = GNUNET_malloc(sizeof addr); | ||
1252 | memcpy (addr_, &addr, sizeof addr); | 1273 | memcpy (addr_, &addr, sizeof addr); |
1253 | handle_response(dns, addr_, 4, r); | 1274 | handle_response (dns, addr_, 4, r); |
1254 | 1275 | ||
1255 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout6, | 1276 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout6, |
1256 | &read_response6, NULL); | 1277 | &read_response6, NULL); |
@@ -1277,8 +1298,7 @@ read_response (void *cls | |||
1277 | #ifndef MINGW | 1298 | #ifndef MINGW |
1278 | if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len)) | 1299 | if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len)) |
1279 | { | 1300 | { |
1280 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 1301 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl"); |
1281 | "ioctl"); | ||
1282 | unhijack (dnsoutport); | 1302 | unhijack (dnsoutport); |
1283 | if (GNUNET_YES == open_port ()) | 1303 | if (GNUNET_YES == open_port ()) |
1284 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); | 1304 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); |
@@ -1296,114 +1316,118 @@ read_response (void *cls | |||
1296 | (struct sockaddr *) &addr, &addrlen); | 1316 | (struct sockaddr *) &addr, &addrlen); |
1297 | 1317 | ||
1298 | if (r < 0) | 1318 | if (r < 0) |
1299 | { | 1319 | { |
1300 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 1320 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); |
1301 | "recvfrom"); | 1321 | unhijack (dnsoutport); |
1302 | unhijack (dnsoutport); | 1322 | if (GNUNET_YES == open_port ()) |
1303 | if (GNUNET_YES == open_port ()) | 1323 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); |
1304 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &hijack, NULL); | 1324 | return; |
1305 | return; | 1325 | } |
1306 | } | 1326 | |
1327 | struct sockaddr *addr_ = GNUNET_malloc (sizeof addr); | ||
1307 | 1328 | ||
1308 | struct sockaddr *addr_ = GNUNET_malloc(sizeof addr); | ||
1309 | memcpy (addr_, &addr, sizeof addr); | 1329 | memcpy (addr_, &addr, sizeof addr); |
1310 | handle_response(dns, addr_, 4, r); | 1330 | handle_response (dns, addr_, 4, r); |
1311 | 1331 | ||
1312 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout, | 1332 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout, |
1313 | &read_response, NULL); | 1333 | &read_response, NULL); |
1314 | } | 1334 | } |
1315 | 1335 | ||
1316 | void | 1336 | void |
1317 | handle_response(struct dns_pkt* dns, struct sockaddr *addr, socklen_t addrlen, int r) | 1337 | handle_response (struct dns_pkt *dns, struct sockaddr *addr, socklen_t addrlen, |
1338 | int r) | ||
1318 | { | 1339 | { |
1319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", | 1340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", |
1320 | ntohs (dns->s.id)); | 1341 | ntohs (dns->s.id)); |
1321 | 1342 | ||
1322 | 1343 | ||
1323 | if (query_states[dns->s.id].valid == GNUNET_YES) | 1344 | if (query_states[dns->s.id].valid == GNUNET_YES) |
1345 | { | ||
1346 | if (query_states[dns->s.id].tunnel != NULL) | ||
1347 | { | ||
1348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1349 | "Answer to query %d for a remote peer!\n", ntohs (dns->s.id)); | ||
1350 | /* This response should go through a tunnel */ | ||
1351 | uint32_t *c = | ||
1352 | GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r); | ||
1353 | *c = r; | ||
1354 | struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1); | ||
1355 | |||
1356 | *t = query_states[dns->s.id].tunnel; | ||
1357 | memcpy (t + 1, dns, r); | ||
1358 | struct tunnel_state *s = | ||
1359 | GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel); | ||
1360 | if (NULL == s->th) | ||
1361 | { | ||
1362 | s->th = | ||
1363 | GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, | ||
1364 | GNUNET_YES, 32, | ||
1365 | GNUNET_TIME_UNIT_MINUTES, NULL, | ||
1366 | r + | ||
1367 | sizeof (struct | ||
1368 | GNUNET_MessageHeader), | ||
1369 | mesh_send_response, c); | ||
1370 | } | ||
1371 | else | ||
1372 | { | ||
1373 | struct tunnel_notify_queue *element = | ||
1374 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); | ||
1375 | element->cls = c; | ||
1376 | element->len = r + sizeof (struct GNUNET_MessageHeader); | ||
1377 | element->cb = mesh_send_response; | ||
1378 | |||
1379 | GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element); | ||
1380 | } | ||
1381 | } | ||
1382 | else | ||
1324 | { | 1383 | { |
1325 | if (query_states[dns->s.id].tunnel != NULL) | 1384 | query_states[dns->s.id].valid = GNUNET_NO; |
1326 | { | 1385 | |
1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1386 | size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */ |
1328 | "Answer to query %d for a remote peer!\n", | 1387 | struct answer_packet_list *answer = |
1329 | ntohs (dns->s.id)); | 1388 | GNUNET_malloc (len + sizeof (struct answer_packet_list) - |
1330 | /* This response should go through a tunnel */ | 1389 | (sizeof (struct answer_packet))); |
1331 | uint32_t *c = | 1390 | answer->pkt.hdr.type = |
1332 | GNUNET_malloc (4 + sizeof (struct GNUNET_MESH_Tunnel *) + r); | 1391 | htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); |
1333 | *c = r; | 1392 | answer->pkt.hdr.size = htons (len); |
1334 | struct GNUNET_MESH_Tunnel **t = (struct GNUNET_MESH_Tunnel **) (c + 1); | 1393 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP; |
1335 | 1394 | answer->pkt.addrlen = addrlen; | |
1336 | *t = query_states[dns->s.id].tunnel; | 1395 | if (addrlen == 16) |
1337 | memcpy (t + 1, dns, r); | 1396 | { |
1338 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel); | 1397 | struct sockaddr_in6 *addr_ = (struct sockaddr_in6 *) addr; |
1339 | if (NULL == s->th) | 1398 | |
1340 | { | 1399 | memcpy (answer->pkt.from, &addr_->sin6_addr, addrlen); |
1341 | s->th = | 1400 | memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); |
1342 | GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, | 1401 | } |
1343 | GNUNET_YES, | 1402 | else if (addrlen == 4) |
1344 | 32, | 1403 | { |
1345 | GNUNET_TIME_UNIT_MINUTES, | 1404 | struct sockaddr_in *addr_ = (struct sockaddr_in *) addr; |
1346 | NULL, | 1405 | |
1347 | r + | 1406 | memcpy (answer->pkt.from, &addr_->sin_addr.s_addr, addrlen); |
1348 | sizeof (struct | 1407 | memcpy (answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); |
1349 | GNUNET_MessageHeader), | 1408 | } |
1350 | mesh_send_response, c); | ||
1351 | } | ||
1352 | else | ||
1353 | { | ||
1354 | struct tunnel_notify_queue *element = | ||
1355 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); | ||
1356 | element->cls = c; | ||
1357 | element->len = r + sizeof (struct GNUNET_MessageHeader); | ||
1358 | element->cb = mesh_send_response; | ||
1359 | |||
1360 | GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, element); | ||
1361 | } | ||
1362 | } | ||
1363 | else | 1409 | else |
1364 | { | 1410 | { |
1365 | query_states[dns->s.id].valid = GNUNET_NO; | 1411 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen); |
1366 | 1412 | GNUNET_assert (0); | |
1367 | size_t len = sizeof (struct answer_packet) + r - 1; /* 1 for the unsigned char data[1]; */ | 1413 | } |
1368 | struct answer_packet_list *answer = | 1414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n", |
1369 | GNUNET_malloc (len + sizeof(struct answer_packet_list) - (sizeof(struct answer_packet))); | 1415 | addrlen); |
1370 | answer->pkt.hdr.type = | 1416 | answer->pkt.dst_port = query_states[dns->s.id].local_port; |
1371 | htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS); | 1417 | memcpy (answer->pkt.data, dns, r); |
1372 | answer->pkt.hdr.size = htons (len); | 1418 | answer->client = query_states[dns->s.id].client; |
1373 | answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP; | 1419 | |
1374 | answer->pkt.addrlen = addrlen; | 1420 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); |
1375 | if (addrlen == 16) | 1421 | |
1376 | { | 1422 | if (server_notify == NULL) |
1377 | struct sockaddr_in6 *addr_ = (struct sockaddr_in6*)addr; | 1423 | server_notify = |
1378 | memcpy(answer->pkt.from, &addr_->sin6_addr, addrlen); | 1424 | GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, |
1379 | memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); | 1425 | len, |
1380 | } | 1426 | GNUNET_TIME_UNIT_FOREVER_REL, |
1381 | else if (addrlen == 4) | 1427 | &send_answer, NULL); |
1382 | { | ||
1383 | struct sockaddr_in *addr_ = (struct sockaddr_in*)addr; | ||
1384 | memcpy(answer->pkt.from, &addr_->sin_addr.s_addr, addrlen); | ||
1385 | memcpy(answer->pkt.to, query_states[dns->s.id].local_ip, addrlen); | ||
1386 | } | ||
1387 | else | ||
1388 | { | ||
1389 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "addrlen = %d\n", addrlen); | ||
1390 | GNUNET_assert(0); | ||
1391 | } | ||
1392 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending answer with addrlen = %d\n", addrlen); | ||
1393 | answer->pkt.dst_port = query_states[dns->s.id].local_port; | ||
1394 | memcpy (answer->pkt.data, dns, r); | ||
1395 | answer->client = query_states[dns->s.id].client; | ||
1396 | |||
1397 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); | ||
1398 | |||
1399 | if (server_notify == NULL) | ||
1400 | server_notify = GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, | ||
1401 | len, GNUNET_TIME_UNIT_FOREVER_REL, | ||
1402 | &send_answer, | ||
1403 | NULL); | ||
1404 | } | ||
1405 | } | 1428 | } |
1406 | GNUNET_free(addr); | 1429 | } |
1430 | GNUNET_free (addr); | ||
1407 | } | 1431 | } |
1408 | 1432 | ||
1409 | 1433 | ||
@@ -1535,8 +1559,9 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, | |||
1535 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer); | 1559 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &data.peer); |
1536 | 1560 | ||
1537 | data.expiration_time = | 1561 | data.expiration_time = |
1538 | GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply | 1562 | GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute |
1539 | (GNUNET_TIME_UNIT_HOURS, 2))); | 1563 | (GNUNET_TIME_relative_multiply |
1564 | (GNUNET_TIME_UNIT_HOURS, 2))); | ||
1540 | 1565 | ||
1541 | /* Sign the block */ | 1566 | /* Sign the block */ |
1542 | if (GNUNET_OK != | 1567 | if (GNUNET_OK != |
@@ -1549,7 +1574,8 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type, | |||
1549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n", | 1574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n", |
1550 | *((unsigned int *) &data.service_descriptor), size); | 1575 | *((unsigned int *) &data.service_descriptor), size); |
1551 | 1576 | ||
1552 | GNUNET_DHT_put (dht, &data.service_descriptor, 5 /* DEFAULT_PUT_REPLICATION */, | 1577 | GNUNET_DHT_put (dht, &data.service_descriptor, |
1578 | 5 /* DEFAULT_PUT_REPLICATION */ , | ||
1553 | GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size, | 1579 | GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size, |
1554 | (char *) &data, | 1580 | (char *) &data, |
1555 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), | 1581 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), |
@@ -1694,13 +1720,15 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1694 | if (GNUNET_YES == | 1720 | if (GNUNET_YES == |
1695 | GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) | 1721 | GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) |
1696 | apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER; | 1722 | apptypes[0] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER; |
1697 | mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, mesh_handlers, apptypes); | 1723 | mesh_handle = |
1724 | GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, clean_tunnel, | ||
1725 | mesh_handlers, apptypes); | ||
1698 | 1726 | ||
1699 | cfg = cfg_; | 1727 | cfg = cfg_; |
1700 | dht = GNUNET_DHT_connect (cfg, 1024); | 1728 | dht = GNUNET_DHT_connect (cfg, 1024); |
1701 | GNUNET_SCHEDULER_add_now (publish_names, NULL); | 1729 | GNUNET_SCHEDULER_add_now (publish_names, NULL); |
1702 | GNUNET_SERVER_add_handlers (server, handlers); | 1730 | GNUNET_SERVER_add_handlers (server, handlers); |
1703 | GNUNET_SERVER_disconnect_notify(server, &client_disconnect, NULL); | 1731 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); |
1704 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, | 1732 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, |
1705 | cls); | 1733 | cls); |
1706 | } | 1734 | } |