diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-21 13:55:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-21 13:55:13 +0000 |
commit | 4edd3c4bf4606e7bb824c5e34c9fa120596b4bd4 (patch) | |
tree | 6f37615b0a05f3727a6095ea10b654c5779d389d /src/gns | |
parent | a3aecc1584246fef20413c9b4a6097f2a9f3e64b (diff) | |
download | gnunet-4edd3c4bf4606e7bb824c5e34c9fa120596b4bd4.tar.gz gnunet-4edd3c4bf4606e7bb824c5e34c9fa120596b4bd4.zip |
-more work on dns2gns
Diffstat (limited to 'src/gns')
-rw-r--r-- | src/gns/gnunet-dns2gns.c | 123 |
1 files changed, 107 insertions, 16 deletions
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index cb7abe6ec..3c48c4268 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c | |||
@@ -175,8 +175,10 @@ do_timeout (void *cls, | |||
175 | { | 175 | { |
176 | struct Request *request = cls; | 176 | struct Request *request = cls; |
177 | 177 | ||
178 | GNUNET_DNSPARSER_free_packet (request->packet); | 178 | if (NULL != request->packet) |
179 | GNUNET_GNS_cancel_lookup_request (request->lookup); | 179 | GNUNET_DNSPARSER_free_packet (request->packet); |
180 | if (NULL != request->lookup) | ||
181 | GNUNET_GNS_cancel_lookup_request (request->lookup); | ||
180 | GNUNET_free (request); | 182 | GNUNET_free (request); |
181 | } | 183 | } |
182 | 184 | ||
@@ -196,12 +198,57 @@ result_processor (void *cls, | |||
196 | const struct GNUNET_NAMESTORE_RecordData *rd) | 198 | const struct GNUNET_NAMESTORE_RecordData *rd) |
197 | { | 199 | { |
198 | struct Request *request = cls; | 200 | struct Request *request = cls; |
201 | struct GNUNET_DNSPARSER_Packet *packet; | ||
202 | uint32_t i; | ||
203 | struct GNUNET_DNSPARSER_Record rec; | ||
199 | 204 | ||
200 | // FIXME: is 'processor' called only once or | ||
201 | // possibly more than once? | ||
202 | request->lookup = NULL; | 205 | request->lookup = NULL; |
203 | GNUNET_break (0); | 206 | packet = request->packet; |
204 | // FIXME: convert 'rd' to response here... | 207 | packet->flags.query_or_response = 1; |
208 | packet->flags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; | ||
209 | packet->flags.checking_disabled = 0; | ||
210 | packet->flags.authenticated_data = 1; | ||
211 | packet->flags.zero = 0; | ||
212 | packet->flags.recursion_available = 1; | ||
213 | packet->flags.message_truncated = 0; | ||
214 | packet->flags.authoritative_answer = 0; | ||
215 | packet->flags.opcode = GNUNET_DNSPARSER_OPCODE_STATUS; // ??? | ||
216 | for (i=0;i<rd_count;i++) | ||
217 | { | ||
218 | switch (rd[i].record_type) | ||
219 | { | ||
220 | case GNUNET_DNSPARSER_TYPE_A: | ||
221 | GNUNET_assert (sizeof (struct in_addr) == rd[i].data_size); | ||
222 | rec.name = GNUNET_strdup (packet->queries[0].name); | ||
223 | rec.data.raw.data = GNUNET_malloc (sizeof (struct in_addr)); | ||
224 | memcpy (rec.data.raw.data, | ||
225 | rd[i].data, | ||
226 | rd[i].data_size); | ||
227 | rec.data.raw.data_len = sizeof (struct in_addr); | ||
228 | GNUNET_array_append (packet->answers, | ||
229 | packet->num_answers, | ||
230 | rec); | ||
231 | break; | ||
232 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
233 | GNUNET_assert (sizeof (struct in6_addr) == rd[i].data_size); | ||
234 | rec.name = GNUNET_strdup ("foo"); // request->name | ||
235 | rec.data.raw.data = GNUNET_malloc (sizeof (struct in6_addr)); | ||
236 | memcpy (rec.data.raw.data, | ||
237 | rd[i].data, | ||
238 | rd[i].data_size); | ||
239 | rec.data.raw.data_len = sizeof (struct in6_addr); | ||
240 | GNUNET_array_append (packet->answers, | ||
241 | packet->num_answers, | ||
242 | rec); | ||
243 | break; | ||
244 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
245 | GNUNET_break (0); // FIXME: not implemented! | ||
246 | break; | ||
247 | default: | ||
248 | /* skip */ | ||
249 | break; | ||
250 | } | ||
251 | } | ||
205 | send_response (request); | 252 | send_response (request); |
206 | } | 253 | } |
207 | 254 | ||
@@ -224,6 +271,9 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
224 | { | 271 | { |
225 | struct Request *request; | 272 | struct Request *request; |
226 | struct GNUNET_DNSPARSER_Packet *packet; | 273 | struct GNUNET_DNSPARSER_Packet *packet; |
274 | char *name; | ||
275 | size_t name_len; | ||
276 | enum GNUNET_GNS_RecordType type; | ||
227 | 277 | ||
228 | packet = GNUNET_DNSPARSER_parse (udp_msg, udp_msg_size); | 278 | packet = GNUNET_DNSPARSER_parse (udp_msg, udp_msg_size); |
229 | if (NULL == packet) | 279 | if (NULL == packet) |
@@ -233,6 +283,25 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
233 | GNUNET_a2s (addr, addr_len)); | 283 | GNUNET_a2s (addr, addr_len)); |
234 | return; | 284 | return; |
235 | } | 285 | } |
286 | if ( (0 != packet->flags.query_or_response) || | ||
287 | (0 != packet->num_answers) || | ||
288 | (0 != packet->num_authority_records) || | ||
289 | (0 != packet->num_additional_records) ) | ||
290 | { | ||
291 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
292 | _("Received malformed DNS request from %s\n"), | ||
293 | GNUNET_a2s (addr, addr_len)); | ||
294 | GNUNET_DNSPARSER_free_packet (packet); | ||
295 | return; | ||
296 | } | ||
297 | if ( (1 != packet->num_queries) ) | ||
298 | { | ||
299 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
300 | _("Received unsupported DNS request from %s\n"), | ||
301 | GNUNET_a2s (addr, addr_len)); | ||
302 | GNUNET_DNSPARSER_free_packet (packet); | ||
303 | return; | ||
304 | } | ||
236 | request = GNUNET_malloc (sizeof (struct Request) + addr_len); | 305 | request = GNUNET_malloc (sizeof (struct Request) + addr_len); |
237 | request->lsock = lsock; | 306 | request->lsock = lsock; |
238 | request->packet = packet; | 307 | request->packet = packet; |
@@ -242,16 +311,38 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, | |||
242 | request->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 311 | request->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
243 | &do_timeout, | 312 | &do_timeout, |
244 | request); | 313 | request); |
245 | // FIXME: extract name and type from 'request->packet' | 314 | name = GNUNET_strdup (packet->queries[0].name); |
246 | const char *name = "foo"; | 315 | name_len = strlen (name); |
247 | enum GNUNET_GNS_RecordType type = GNUNET_GNS_RECORD_A; | 316 | if ( (name_len > strlen (".zkey.eu")) && |
248 | request->lookup = GNUNET_GNS_lookup (gns, | 317 | (0 == strcasecmp (".zkey.eu", |
249 | name, | 318 | &name[name_len - strlen (".zkey.eu")])) ) |
250 | type, | 319 | { |
251 | GNUNET_NO, | 320 | name[name_len - strlen (".zkey.eu")] = '\0'; |
252 | NULL, | 321 | strcat (name, ".gnunet"); /* little hack, only works because |
253 | &result_processor, | 322 | ".zkey.eu" is longer than ".gnunet" */ |
254 | request); | 323 | name_len = strlen (name); |
324 | } | ||
325 | if ( (name_len > strlen (".gnunet")) && | ||
326 | (0 == strcasecmp (".gnunet", | ||
327 | &name[name_len - strlen (".gnunet")])) ) | ||
328 | { | ||
329 | type = packet->queries[0].type; | ||
330 | request->lookup = GNUNET_GNS_lookup (gns, | ||
331 | name, | ||
332 | type, | ||
333 | GNUNET_NO, | ||
334 | NULL, | ||
335 | &result_processor, | ||
336 | request); | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | /* FIXME: do traditional *DNS* lookup; note that | ||
341 | gnunet-service-dns already has code to do this; | ||
342 | factor into library to share! */ | ||
343 | GNUNET_break (0); | ||
344 | } | ||
345 | GNUNET_free (name); | ||
255 | } | 346 | } |
256 | 347 | ||
257 | 348 | ||