diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-10-26 22:13:01 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-10-26 22:13:01 +0000 |
commit | 64d3e46cfb99a711e500fa1f114e7c44bdf10040 (patch) | |
tree | 83093d92761d5c1b8b2fded713adaa19af29274c /src/gns/gnunet-service-gns_interceptor.c | |
parent | ef6f05f63769263a5201636c4b7f71eaa455cdf3 (diff) | |
download | gnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.tar.gz gnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.zip |
-bugfixes, code cleanup
Diffstat (limited to 'src/gns/gnunet-service-gns_interceptor.c')
-rw-r--r-- | src/gns/gnunet-service-gns_interceptor.c | 134 |
1 files changed, 61 insertions, 73 deletions
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 0081bc833..9c1c3a666 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -17,9 +17,7 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * | ||
23 | * @file gns/gnunet-service-gns_interceptor.c | 21 | * @file gns/gnunet-service-gns_interceptor.c |
24 | * @brief GNUnet GNS interceptor logic | 22 | * @brief GNUnet GNS interceptor logic |
25 | * @author Martin Schanzenbach | 23 | * @author Martin Schanzenbach |
@@ -86,8 +84,8 @@ static struct GNUNET_TIME_Relative default_lookup_timeout; | |||
86 | * @param rd the record data | 84 | * @param rd the record data |
87 | */ | 85 | */ |
88 | static void | 86 | static void |
89 | reply_to_dns(void* cls, uint32_t rd_count, | 87 | reply_to_dns (void* cls, uint32_t rd_count, |
90 | const struct GNUNET_NAMESTORE_RecordData *rd) | 88 | const struct GNUNET_NAMESTORE_RecordData *rd) |
91 | { | 89 | { |
92 | uint32_t i; | 90 | uint32_t i; |
93 | size_t len; | 91 | size_t len; |
@@ -199,23 +197,25 @@ reply_to_dns(void* cls, uint32_t rd_count, | |||
199 | 1024, /* FIXME magic from dns redirector */ | 197 | 1024, /* FIXME magic from dns redirector */ |
200 | &buf, | 198 | &buf, |
201 | &len); | 199 | &len); |
202 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
203 | "Built DNS response! (ret=%d,len=%d)\n", ret, len); | 201 | "Built DNS response! (ret=%d,len=%d)\n", |
202 | ret, len); | ||
204 | if (ret == GNUNET_OK) | 203 | if (ret == GNUNET_OK) |
205 | { | 204 | { |
206 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
207 | "Answering DNS request\n"); | 206 | "Answering DNS request\n"); |
208 | GNUNET_DNS_request_answer(ilh->request_handle, | 207 | GNUNET_DNS_request_answer (ilh->request_handle, |
209 | len, | 208 | len, |
210 | buf); | 209 | buf); |
211 | 210 | ||
212 | GNUNET_free(buf); | 211 | GNUNET_free (buf); |
213 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answered DNS request\n"); | 212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
213 | "Answered DNS request\n"); | ||
214 | } | 214 | } |
215 | else | 215 | else |
216 | { | 216 | { |
217 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
218 | "Error building DNS response! (ret=%d)", ret); | 218 | "Error building DNS response! (ret=%d)", ret); |
219 | } | 219 | } |
220 | 220 | ||
221 | packet->num_answers = 0; | 221 | packet->num_answers = 0; |
@@ -236,8 +236,8 @@ reply_to_dns(void* cls, uint32_t rd_count, | |||
236 | * @param q the DNS query we received parsed from p | 236 | * @param q the DNS query we received parsed from p |
237 | */ | 237 | */ |
238 | static void | 238 | static void |
239 | start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request, | 239 | start_resolution_for_dns (struct GNUNET_DNS_RequestHandle *request, |
240 | struct GNUNET_DNSPARSER_Packet *p, | 240 | struct GNUNET_DNSPARSER_Packet *p, |
241 | struct GNUNET_DNSPARSER_Query *q) | 241 | struct GNUNET_DNSPARSER_Query *q) |
242 | { | 242 | { |
243 | struct InterceptLookupHandle* ilh; | 243 | struct InterceptLookupHandle* ilh; |
@@ -245,7 +245,6 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request, | |||
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
246 | "Starting resolution for %s (type=%d)!\n", | 246 | "Starting resolution for %s (type=%d)!\n", |
247 | q->name, q->type); | 247 | q->name, q->type); |
248 | |||
249 | ilh = GNUNET_malloc(sizeof(struct InterceptLookupHandle)); | 248 | ilh = GNUNET_malloc(sizeof(struct InterceptLookupHandle)); |
250 | ilh->packet = p; | 249 | ilh->packet = p; |
251 | ilh->query = q; | 250 | ilh->query = q; |
@@ -260,7 +259,6 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request, | |||
260 | } | 259 | } |
261 | 260 | ||
262 | 261 | ||
263 | |||
264 | /** | 262 | /** |
265 | * The DNS request handler | 263 | * The DNS request handler |
266 | * Called for every incoming DNS request. | 264 | * Called for every incoming DNS request. |
@@ -271,17 +269,16 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request, | |||
271 | * @param request udp payload of the DNS request | 269 | * @param request udp payload of the DNS request |
272 | */ | 270 | */ |
273 | static void | 271 | static void |
274 | handle_dns_request(void *cls, | 272 | handle_dns_request (void *cls, |
275 | struct GNUNET_DNS_RequestHandle *rh, | 273 | struct GNUNET_DNS_RequestHandle *rh, |
276 | size_t request_length, | 274 | size_t request_length, |
277 | const char *request) | 275 | const char *request) |
278 | { | 276 | { |
279 | struct GNUNET_DNSPARSER_Packet *p; | 277 | struct GNUNET_DNSPARSER_Packet *p; |
280 | 278 | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacked a DNS request...processing\n"); | 279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
282 | p = GNUNET_DNSPARSER_parse (request, request_length); | 280 | "Hijacked a DNS request...processing\n"); |
283 | 281 | if (NULL == (p = GNUNET_DNSPARSER_parse (request, request_length))) | |
284 | if (NULL == p) | ||
285 | { | 282 | { |
286 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 283 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
287 | "Received malformed DNS packet, leaving it untouched\n"); | 284 | "Received malformed DNS packet, leaving it untouched\n"); |
@@ -302,7 +299,7 @@ handle_dns_request(void *cls, | |||
302 | * The way it is implemented here now is buggy and will lead to erratic | 299 | * The way it is implemented here now is buggy and will lead to erratic |
303 | * behaviour (if multiple queries are present). | 300 | * behaviour (if multiple queries are present). |
304 | */ | 301 | */ |
305 | if (p->num_queries == 0) | 302 | if (0 == p->num_queries) |
306 | { | 303 | { |
307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
308 | "No Queries in DNS packet... forwarding\n"); | 305 | "No Queries in DNS packet... forwarding\n"); |
@@ -311,14 +308,6 @@ handle_dns_request(void *cls, | |||
311 | return; | 308 | return; |
312 | } | 309 | } |
313 | 310 | ||
314 | if (p->num_queries > 1) | ||
315 | { | ||
316 | /* Note: We could also look for .gads */ | ||
317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
318 | ">1 queriy in DNS packet... odd. We only process #1\n"); | ||
319 | } | ||
320 | |||
321 | |||
322 | /** | 311 | /** |
323 | * Check for .gads/.zkey | 312 | * Check for .gads/.zkey |
324 | */ | 313 | */ |
@@ -327,19 +316,23 @@ handle_dns_request(void *cls, | |||
327 | (is_zkey_tld(p->queries[0].name) == GNUNET_YES) || | 316 | (is_zkey_tld(p->queries[0].name) == GNUNET_YES) || |
328 | (strcmp(p->queries[0].name, GNUNET_GNS_TLD) == 0)) | 317 | (strcmp(p->queries[0].name, GNUNET_GNS_TLD) == 0)) |
329 | { | 318 | { |
330 | start_resolution_for_dns(rh, p, p->queries); | 319 | if (p->num_queries > 1) |
331 | } | 320 | { |
332 | else | 321 | /* Note: We could also look for .gads */ |
333 | { | 322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
334 | /** | 323 | ">1 queriy in DNS packet... odd. We only process #1\n"); |
335 | * This request does not concern us. Forward to real DNS. | 324 | } |
336 | */ | 325 | start_resolution_for_dns (rh, p, p->queries); |
337 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 326 | return; |
338 | "Request for %s is forwarded to DNS\n", p->queries[0].name); | ||
339 | GNUNET_DNS_request_forward (rh); | ||
340 | GNUNET_DNSPARSER_free_packet (p); | ||
341 | } | 327 | } |
342 | 328 | /** | |
329 | * This request does not concern us. Forward to real DNS. | ||
330 | */ | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
332 | "Request for %s is forwarded to DNS\n", | ||
333 | p->queries[0].name); | ||
334 | GNUNET_DNS_request_forward (rh); | ||
335 | GNUNET_DNSPARSER_free_packet (p); | ||
343 | } | 336 | } |
344 | 337 | ||
345 | 338 | ||
@@ -352,53 +345,48 @@ handle_dns_request(void *cls, | |||
352 | * @return GNUNET_OK on success | 345 | * @return GNUNET_OK on success |
353 | */ | 346 | */ |
354 | int | 347 | int |
355 | gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone, | 348 | gns_interceptor_init (struct GNUNET_CRYPTO_ShortHashCode zone, |
356 | struct GNUNET_CRYPTO_RsaPrivateKey *key, | 349 | struct GNUNET_CRYPTO_RsaPrivateKey *key, |
357 | const struct GNUNET_CONFIGURATION_Handle *c) | 350 | const struct GNUNET_CONFIGURATION_Handle *c) |
358 | { | 351 | { |
359 | unsigned long long default_lookup_timeout_secs = 0; | ||
360 | |||
361 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 352 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
362 | "DNS hijacking enabled... connecting to service.\n"); | 353 | "DNS hijacking enabled... connecting to service.\n"); |
363 | |||
364 | our_zone = zone; | 354 | our_zone = zone; |
365 | our_key = key; | 355 | our_key = key; |
366 | /** | 356 | /** |
367 | * Do gnunet dns init here | 357 | * Do gnunet dns init here |
368 | */ | 358 | */ |
369 | dns_handle = GNUNET_DNS_connect(c, | 359 | dns_handle = GNUNET_DNS_connect (c, |
370 | GNUNET_DNS_FLAG_PRE_RESOLUTION, | 360 | GNUNET_DNS_FLAG_PRE_RESOLUTION, |
371 | &handle_dns_request, /* rh */ | 361 | &handle_dns_request, /* rh */ |
372 | NULL); /* Closure */ | 362 | NULL); /* Closure */ |
373 | 363 | ||
374 | if (GNUNET_OK == | 364 | if (GNUNET_OK != |
375 | GNUNET_CONFIGURATION_get_value_number(c, "gns", | 365 | GNUNET_CONFIGURATION_get_value_time (c, "gns", |
376 | "DEFAULT_LOOKUP_TIMEOUT", | 366 | "DEFAULT_LOOKUP_TIMEOUT", |
377 | &default_lookup_timeout_secs)) | 367 | &default_lookup_timeout)) |
378 | { | 368 | default_lookup_timeout = GNUNET_TIME_UNIT_ZERO; |
379 | default_lookup_timeout = GNUNET_TIME_relative_multiply( | ||
380 | GNUNET_TIME_UNIT_SECONDS, | ||
381 | default_lookup_timeout_secs); | ||
382 | } | ||
383 | |||
384 | if (NULL == dns_handle) | 369 | if (NULL == dns_handle) |
385 | { | 370 | { |
386 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 371 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
387 | "Failed to connect to the dnsservice!\n"); | 372 | "Failed to connect to the dnsservice!\n"); |
388 | return GNUNET_SYSERR; | 373 | return GNUNET_SYSERR; |
389 | } | 374 | } |
390 | |||
391 | return GNUNET_YES; | 375 | return GNUNET_YES; |
392 | } | 376 | } |
393 | 377 | ||
378 | |||
394 | /** | 379 | /** |
395 | * Disconnect from interceptor | 380 | * Disconnect from interceptor |
396 | */ | 381 | */ |
397 | void | 382 | void |
398 | gns_interceptor_stop(void) | 383 | gns_interceptor_stop () |
399 | { | 384 | { |
400 | if (dns_handle) | 385 | if (NULL != dns_handle) |
386 | { | ||
401 | GNUNET_DNS_disconnect(dns_handle); | 387 | GNUNET_DNS_disconnect(dns_handle); |
388 | dns_handle = NULL; | ||
389 | } | ||
402 | } | 390 | } |
403 | 391 | ||
404 | /* end of gns_interceptor.c */ | 392 | /* end of gns_interceptor.c */ |