aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-daemon-vpn.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-02 05:03:07 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-02 05:03:07 +0000
commitb75373955d92c8ac1e9554182025843c01cbb96c (patch)
tree701cd50e4282eabc8bbd4ab622ee6e5b1d00447b /src/vpn/gnunet-daemon-vpn.c
parenta0ba564746ecdff082ac3982d4d911f91deb8ab7 (diff)
downloadgnunet-b75373955d92c8ac1e9554182025843c01cbb96c.tar.gz
gnunet-b75373955d92c8ac1e9554182025843c01cbb96c.zip
-again moving towards DNS API sanity
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r--src/vpn/gnunet-daemon-vpn.c157
1 files changed, 69 insertions, 88 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index cd587d7b1..7d303ecd5 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -80,6 +80,47 @@ GNUNET_SCHEDULER_TaskIdentifier conn_task;
80 80
81GNUNET_SCHEDULER_TaskIdentifier shs_task; 81GNUNET_SCHEDULER_TaskIdentifier shs_task;
82 82
83
84/**
85 * Sets a bit active in a bitArray.
86 *
87 * @param bitArray memory area to set the bit in
88 * @param bitIdx which bit to set
89 */
90static void
91setBit (char *bitArray, unsigned int bitIdx)
92{
93 size_t arraySlot;
94 unsigned int targetBit;
95
96 arraySlot = bitIdx / 8;
97 targetBit = (1L << (bitIdx % 8));
98 bitArray[arraySlot] |= targetBit;
99}
100
101
102/**
103 * Checks if a bit is active in the bitArray
104 *
105 * @param bitArray memory area to set the bit in
106 * @param bitIdx which bit to test
107 * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
108 */
109int
110testBit (char *bitArray, unsigned int bitIdx)
111{
112 size_t slot;
113 unsigned int targetBit;
114
115 slot = bitIdx / 8;
116 targetBit = (1L << (bitIdx % 8));
117 if (bitArray[slot] & targetBit)
118 return GNUNET_YES;
119 else
120 return GNUNET_NO;
121}
122
123
83/** 124/**
84 * Function scheduled as very last function, cleans up after us 125 * Function scheduled as very last function, cleans up after us
85 *{{{ 126 *{{{
@@ -510,12 +551,9 @@ new_ip4addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
510 * doing nothing for "real" services. 551 * doing nothing for "real" services.
511 */ 552 */
512void 553void
513process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 554process_answer (void *cls,
555 const struct answer_packet *pkt)
514{ 556{
515 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
516 return;
517
518 struct answer_packet *pkt = cls;
519 struct answer_packet_list *list; 557 struct answer_packet_list *list;
520 558
521 /* This answer is about a .gnunet-service 559 /* This answer is about a .gnunet-service
@@ -525,13 +563,18 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
525 */ 563 */
526 if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE) 564 if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_SERVICE)
527 { 565 {
528 pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
529 566
530 GNUNET_HashCode key; 567 GNUNET_HashCode key;
531 568
532 memset (&key, 0, sizeof (GNUNET_HashCode)); 569 memset (&key, 0, sizeof (GNUNET_HashCode));
533 570
534 unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); 571 list =
572 GNUNET_malloc (htons (pkt->hdr.size) +
573 sizeof (struct answer_packet_list) -
574 sizeof (struct answer_packet));
575 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
576
577 unsigned char *c = ((unsigned char *) &list->pkt) + ntohs (pkt->addroffset);
535 unsigned char *k = (unsigned char *) &key; 578 unsigned char *k = (unsigned char *) &key;
536 579
537 new_ip6addr ((struct in6_addr*) c, 580 new_ip6addr ((struct in6_addr*) c,
@@ -576,12 +619,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
576 GNUNET_free (value); 619 GNUNET_free (value);
577 620
578 621
579 list = 622 list->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
580 GNUNET_malloc (htons (pkt->hdr.size) +
581 sizeof (struct answer_packet_list) -
582 sizeof (struct answer_packet));
583 623
584 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
585 624
586 } 625 }
587 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV) 626 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REV)
@@ -590,7 +629,7 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
590 629
591 memset (&key, 0, sizeof key); 630 memset (&key, 0, sizeof key);
592 unsigned char *k = (unsigned char *) &key; 631 unsigned char *k = (unsigned char *) &key;
593 unsigned char *s = pkt->data + 12; 632 const unsigned char *s = pkt->data + 12;
594 int i = 0; 633 int i = 0;
595 634
596 /* Whoever designed the reverse IPv6-lookup is batshit insane */ 635 /* Whoever designed the reverse IPv6-lookup is batshit insane */
@@ -614,10 +653,7 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
614 uint16_t offset = ntohs (pkt->addroffset); 653 uint16_t offset = ntohs (pkt->addroffset);
615 654
616 if (map_entry == NULL) 655 if (map_entry == NULL)
617 {
618 GNUNET_free (pkt);
619 return; 656 return;
620 }
621 657
622 GNUNET_CONTAINER_heap_update_cost (heap, map_entry->heap_node, 658 GNUNET_CONTAINER_heap_update_cost (heap, map_entry->heap_node,
623 GNUNET_TIME_absolute_get ().abs_value); 659 GNUNET_TIME_absolute_get ().abs_value);
@@ -653,16 +689,23 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
653 } 689 }
654 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA) 690 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA)
655 { 691 {
656 pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
657 692
658 GNUNET_HashCode key; 693 GNUNET_HashCode key;
659 694
660 memset (&key, 0, sizeof (GNUNET_HashCode)); 695 memset (&key, 0, sizeof (GNUNET_HashCode));
661 696
662 unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); 697 list =
698 GNUNET_malloc (htons (pkt->hdr.size) +
699 sizeof (struct answer_packet_list) -
700 sizeof (struct answer_packet));
701
702 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
703 list->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
704
705 unsigned char *c = ((unsigned char *) &list->pkt) + ntohs (list->pkt.addroffset);
663 706
664 new_ip6addr_remote ((struct in6_addr*) c, 707 new_ip6addr_remote ((struct in6_addr*) c,
665 pkt->addr, pkt->addrsize); 708 list->pkt.addr, list->pkt.addrsize);
666 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
667 "New mapping to %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", 710 "New mapping to %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
668 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], 711 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9],
@@ -707,24 +750,25 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
707 else 750 else
708 GNUNET_free (value); 751 GNUNET_free (value);
709 752
753
754 }
755 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_A)
756 {
710 list = 757 list =
711 GNUNET_malloc (htons (pkt->hdr.size) + 758 GNUNET_malloc (htons (pkt->hdr.size) +
712 sizeof (struct answer_packet_list) - 759 sizeof (struct answer_packet_list) -
713 sizeof (struct answer_packet)); 760 sizeof (struct answer_packet));
714 761
715 memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); 762 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
716 } 763 list->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_IP;
717 else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_A)
718 {
719 pkt->subtype = GNUNET_DNS_ANSWER_TYPE_IP;
720 764
721 GNUNET_HashCode key; 765 GNUNET_HashCode key;
722 766
723 memset (&key, 0, sizeof (GNUNET_HashCode)); 767 memset (&key, 0, sizeof (GNUNET_HashCode));
724 768
725 unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); 769 unsigned char *c = ((unsigned char *) &list->pkt) + ntohs (pkt->addroffset);
726 770
727 new_ip4addr_remote (c, pkt->addr, pkt->addrsize); 771 new_ip4addr_remote (c, list->pkt.addr, pkt->addrsize);
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n", c[0], 772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n", c[0],
729 c[1], c[2], c[3]); 773 c[1], c[2], c[3]);
730 unsigned char *k = (unsigned char *) &key; 774 unsigned char *k = (unsigned char *) &key;
@@ -770,22 +814,13 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
770 else 814 else
771 GNUNET_free (value); 815 GNUNET_free (value);
772 816
773 list =
774 GNUNET_malloc (htons (pkt->hdr.size) +
775 sizeof (struct answer_packet_list) -
776 sizeof (struct answer_packet));
777
778 memcpy (&list->pkt, pkt, htons (pkt->hdr.size));
779 } 817 }
780 else 818 else
781 { 819 {
782 GNUNET_break (0); 820 GNUNET_break (0);
783 GNUNET_free (pkt);
784 return; 821 return;
785 } 822 }
786 823
787 GNUNET_free (pkt);
788
789 GNUNET_CONTAINER_DLL_insert_after (answer_proc_head, answer_proc_tail, 824 GNUNET_CONTAINER_DLL_insert_after (answer_proc_head, answer_proc_tail,
790 answer_proc_tail, list); 825 answer_proc_tail, list);
791 826
@@ -794,60 +829,6 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
794 return; 829 return;
795} 830}
796 831
797/**
798 * Sets a bit active in a bitArray.
799 *
800 * @param bitArray memory area to set the bit in
801 * @param bitIdx which bit to set
802 */
803void
804setBit (char *bitArray, unsigned int bitIdx)
805{
806 size_t arraySlot;
807 unsigned int targetBit;
808
809 arraySlot = bitIdx / 8;
810 targetBit = (1L << (bitIdx % 8));
811 bitArray[arraySlot] |= targetBit;
812}
813
814/**
815 * Clears a bit from bitArray.
816 *
817 * @param bitArray memory area to set the bit in
818 * @param bitIdx which bit to unset
819 */
820void
821clearBit (char *bitArray, unsigned int bitIdx)
822{
823 size_t slot;
824 unsigned int targetBit;
825
826 slot = bitIdx / 8;
827 targetBit = (1L << (bitIdx % 8));
828 bitArray[slot] = bitArray[slot] & (~targetBit);
829}
830
831/**
832 * Checks if a bit is active in the bitArray
833 *
834 * @param bitArray memory area to set the bit in
835 * @param bitIdx which bit to test
836 * @return GNUNET_YES if the bit is set, GNUNET_NO if not.
837 */
838int
839testBit (char *bitArray, unsigned int bitIdx)
840{
841 size_t slot;
842 unsigned int targetBit;
843
844 slot = bitIdx / 8;
845 targetBit = (1L << (bitIdx % 8));
846 if (bitArray[slot] & targetBit)
847 return GNUNET_YES;
848 else
849 return GNUNET_NO;
850}
851 832
852/** 833/**
853 * @brief Add the port to the list of additional ports in the map_entry 834 * @brief Add the port to the list of additional ports in the map_entry