aboutsummaryrefslogtreecommitdiff
path: root/src/pt/gnunet-daemon-pt.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-16 19:21:48 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-16 19:21:48 +0000
commit41f6a12245348e4f6aa482386a8ffc713b51f2eb (patch)
tree51e2a1f4d862bf4cc37acaddd7f1dc35a3fbd0f8 /src/pt/gnunet-daemon-pt.c
parent4d93b2e4ef9f1cbb0118f67cc0391dd849cfed46 (diff)
downloadgnunet-41f6a12245348e4f6aa482386a8ffc713b51f2eb.tar.gz
gnunet-41f6a12245348e4f6aa482386a8ffc713b51f2eb.zip
-expanding draft code
Diffstat (limited to 'src/pt/gnunet-daemon-pt.c')
-rw-r--r--src/pt/gnunet-daemon-pt.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c
index f8d83237a..762df276e 100644
--- a/src/pt/gnunet-daemon-pt.c
+++ b/src/pt/gnunet-daemon-pt.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_dns_service.h" 29#include "gnunet_dns_service.h"
30#include "gnunet_dnsparser_lib.h"
30#include "gnunet_vpn_service.h" 31#include "gnunet_vpn_service.h"
31#include "gnunet_statistics_service.h" 32#include "gnunet_statistics_service.h"
32 33
@@ -62,6 +63,36 @@ static int ipv4_pt;
62static int ipv6_pt; 63static int ipv6_pt;
63 64
64 65
66/**
67 * Test if any of the given records need protocol-translation work.
68 *
69 * @param ra array of records
70 * @param ra_len number of entries in ra
71 * @return GNUNET_YES if any of the given records require protocol-translation
72 */
73static int
74work_test (const struct GNUNET_DNSPARSER_Record *ra,
75 unsigned int ra_len)
76{
77 unsigned int i;
78
79 for (i=0;i<ra_len;i++)
80 {
81 switch (ra[i].type)
82 {
83 case GNUNET_DNSPARSER_TYPE_A:
84 if (ipv4_pt)
85 return GNUNET_YES;
86 break;
87 case GNUNET_DNSPARSER_TYPE_AAAA:
88 if (ipv6_pt)
89 return GNUNET_YES;
90 break;
91 }
92 }
93 return GNUNET_NO;
94}
95
65 96
66/** 97/**
67 * Signature of a function that is called whenever the DNS service 98 * Signature of a function that is called whenever the DNS service
@@ -92,6 +123,27 @@ dns_request_handler (void *cls,
92 size_t request_length, 123 size_t request_length,
93 const char *request) 124 const char *request)
94{ 125{
126 struct GNUNET_DNSPARSER_Packet *dns;
127 int work;
128
129 dns = GNUNET_DNSPARSER_parse (request, request_length);
130 if (NULL == dns)
131 {
132 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
133 _("Failed to parse DNS request. Dropping.\n"));
134 GNUNET_DNS_request_drop (rh);
135 return;
136 }
137 work = GNUNET_NO;
138 work |= work_test (dns->answers, dns->num_answers);
139 work |= work_test (dns->authority_records, dns->num_authority_records);
140 work |= work_test (dns->additional_records, dns->num_additional_records);
141 if (! work)
142 {
143 GNUNET_DNS_request_forward (rh);
144 return;
145 }
146 /* FIXME: translate A/AAAA records using VPN! */
95} 147}
96 148
97 149