diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-01-07 09:44:59 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-01-07 09:45:52 +0100 |
commit | c0a6838a1b8a3ca2c73af04b8829d6736521cba1 (patch) | |
tree | 076148fca0a229738510bd023a3271127963383f /src/gns/gnunet-service-gns_resolver.c | |
parent | e8533c8a41e3fb29e51200d643382c8d5f882e5e (diff) | |
download | gnunet-c0a6838a1b8a3ca2c73af04b8829d6736521cba1.tar.gz gnunet-c0a6838a1b8a3ca2c73af04b8829d6736521cba1.zip |
allow GNS clients to control recursion depth limit
Diffstat (limited to 'src/gns/gnunet-service-gns_resolver.c')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 2c2263e58..735742283 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -77,11 +77,6 @@ | |||
77 | */ | 77 | */ |
78 | #define DHT_GNS_REPLICATION_LEVEL 10 | 78 | #define DHT_GNS_REPLICATION_LEVEL 10 |
79 | 79 | ||
80 | /** | ||
81 | * How deep do we allow recursions to go before we abort? | ||
82 | */ | ||
83 | #define MAX_RECURSION 256 | ||
84 | |||
85 | 80 | ||
86 | /** | 81 | /** |
87 | * DLL to hold the authority chain we had to pass in the resolution | 82 | * DLL to hold the authority chain we had to pass in the resolution |
@@ -320,7 +315,7 @@ struct GNS_ResolverHandle | |||
320 | /** | 315 | /** |
321 | * closure passed to @e proc | 316 | * closure passed to @e proc |
322 | */ | 317 | */ |
323 | void*proc_cls; | 318 | void *proc_cls; |
324 | 319 | ||
325 | /** | 320 | /** |
326 | * Handle for DHT lookups. should be NULL if no lookups are in progress | 321 | * Handle for DHT lookups. should be NULL if no lookups are in progress |
@@ -395,7 +390,7 @@ struct GNS_ResolverHandle | |||
395 | struct DnsResult *dns_result_tail; | 390 | struct DnsResult *dns_result_tail; |
396 | 391 | ||
397 | /** | 392 | /** |
398 | * Current offset in 'name' where we are resolving. | 393 | * Current offset in @e name where we are resolving. |
399 | */ | 394 | */ |
400 | size_t name_resolution_pos; | 395 | size_t name_resolution_pos; |
401 | 396 | ||
@@ -423,12 +418,17 @@ struct GNS_ResolverHandle | |||
423 | 418 | ||
424 | /** | 419 | /** |
425 | * We increment the loop limiter for each step in a recursive | 420 | * We increment the loop limiter for each step in a recursive |
426 | * resolution. If it passes our threshold (i.e. due to | 421 | * resolution. If it passes our @e loop_threshold (i.e. due to |
427 | * self-recursion in the resolution, i.e CNAME fun), we stop. | 422 | * self-recursion in the resolution, i.e CNAME fun), we stop. |
428 | */ | 423 | */ |
429 | unsigned int loop_limiter; | 424 | unsigned int loop_limiter; |
430 | 425 | ||
431 | /** | 426 | /** |
427 | * Maximum value of @e loop_limiter allowed by client. | ||
428 | */ | ||
429 | unsigned int loop_threshold; | ||
430 | |||
431 | /** | ||
432 | * 16 bit random ID we used in the @e dns_request. | 432 | * 16 bit random ID we used in the @e dns_request. |
433 | */ | 433 | */ |
434 | uint16_t original_dns_id; | 434 | uint16_t original_dns_id; |
@@ -1856,6 +1856,7 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1856 | gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; | 1856 | gp->rh->record_type = GNUNET_GNSRECORD_TYPE_ANY; |
1857 | gp->rh->options = GNUNET_GNS_LO_DEFAULT; | 1857 | gp->rh->options = GNUNET_GNS_LO_DEFAULT; |
1858 | gp->rh->loop_limiter = rh->loop_limiter + 1; | 1858 | gp->rh->loop_limiter = rh->loop_limiter + 1; |
1859 | gp->rh->loop_threshold = rh->loop_threshold; | ||
1859 | gp->rh->task_id | 1860 | gp->rh->task_id |
1860 | = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | 1861 | = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, |
1861 | gp->rh); | 1862 | gp->rh); |
@@ -2744,7 +2745,7 @@ recursive_resolution (void *cls) | |||
2744 | struct GNS_ResolverHandle *rh = cls; | 2745 | struct GNS_ResolverHandle *rh = cls; |
2745 | 2746 | ||
2746 | rh->task_id = NULL; | 2747 | rh->task_id = NULL; |
2747 | if (MAX_RECURSION < rh->loop_limiter++) | 2748 | if (rh->loop_threshold < rh->loop_limiter++) |
2748 | { | 2749 | { |
2749 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2750 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2750 | "Encountered unbounded recursion resolving `%s'\n", | 2751 | "Encountered unbounded recursion resolving `%s'\n", |
@@ -2840,6 +2841,8 @@ start_resolver_lookup (void *cls) | |||
2840 | * @param record_type the record type to look up | 2841 | * @param record_type the record type to look up |
2841 | * @param name the name to look up | 2842 | * @param name the name to look up |
2842 | * @param options local options to control local lookup | 2843 | * @param options local options to control local lookup |
2844 | * @param recursion_depth_limit how many zones to traverse | ||
2845 | * at most | ||
2843 | * @param proc the processor to call on result | 2846 | * @param proc the processor to call on result |
2844 | * @param proc_cls the closure to pass to @a proc | 2847 | * @param proc_cls the closure to pass to @a proc |
2845 | * @return handle to cancel operation | 2848 | * @return handle to cancel operation |
@@ -2849,6 +2852,7 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | |||
2849 | uint32_t record_type, | 2852 | uint32_t record_type, |
2850 | const char *name, | 2853 | const char *name, |
2851 | enum GNUNET_GNS_LocalOptions options, | 2854 | enum GNUNET_GNS_LocalOptions options, |
2855 | uint16_t recursion_depth_limit, | ||
2852 | GNS_ResultProcessor proc, | 2856 | GNS_ResultProcessor proc, |
2853 | void *proc_cls) | 2857 | void *proc_cls) |
2854 | { | 2858 | { |
@@ -2868,6 +2872,7 @@ GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | |||
2868 | rh->record_type = record_type; | 2872 | rh->record_type = record_type; |
2869 | rh->name = GNUNET_strdup (name); | 2873 | rh->name = GNUNET_strdup (name); |
2870 | rh->name_resolution_pos = strlen (name); | 2874 | rh->name_resolution_pos = strlen (name); |
2875 | rh->loop_threshold = recursion_depth_limit; | ||
2871 | rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, | 2876 | rh->task_id = GNUNET_SCHEDULER_add_now (&start_resolver_lookup, |
2872 | rh); | 2877 | rh); |
2873 | return rh; | 2878 | return rh; |