aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-05-07 19:34:17 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-05-07 19:34:17 +0200
commitdb227f3f975bb4be122711658efc8b03909851eb (patch)
tree295013189e8fc3ca93e4f9e081fef2c877f6fe5b /src
parent01b92dc3370e90fdb0b1eb7eda7e22420c5faa03 (diff)
download0tdns-db227f3f975bb4be122711658efc8b03909851eb.tar.gz
0tdns-db227f3f975bb4be122711658efc8b03909851eb.zip
store information on how much we trust each resolver
Diffstat (limited to 'src')
-rw-r--r--src/0tDNS.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/0tDNS.c b/src/0tDNS.c
index d389031..b4bbf42 100644
--- a/src/0tDNS.c
+++ b/src/0tDNS.c
@@ -23,6 +23,7 @@
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
+#include <stdbool.h>
#include <unbound.h>
#define DEFAULT_DEBUGLEVEL 0
@@ -163,12 +164,23 @@ struct ztdns_resolver {
struct ub_ctx *ctx;
const char *name; /* arbitrary name - only used for printing to user */
const char *address; /* IP addr in dot notation stored as string */
+ /* Compatible answer must be returned by resolvers with their
+ * trust levels summing to at least 100 - otherwise the answer is
+ * considered unreliable.
+ */
+ uint8_t trust_level;
+ /* Whether we want ztdns to report when this resolver gives answer,
+ * that is not confirmed by others (i.e. trust levels sum for this
+ * answer doesn't reach 100).
+ */
+ bool report_errors;
struct ztdns_resolver *next;
};
-struct ztdns_resolver *ztdns_create_recursive_resolver(const char *name,
- const char *address,
- int debuglevel) {
+struct ztdns_resolver *ztdns_create_recursive_resolver
+(const char *name, const char *address, uint8_t trust_level, bool report_errors,
+ int debuglevel)
+{
struct ztdns_resolver *resolver;
resolver = malloc(sizeof(struct ztdns_resolver));
if (!resolver) {
@@ -182,6 +194,8 @@ struct ztdns_resolver *ztdns_create_recursive_resolver(const char *name,
resolver->name = name;
resolver->address = address;
+ resolver->trust_level = trust_level;
+ resolver->report_errors = report_errors;
resolver->next = NULL;
return resolver;
@@ -208,6 +222,9 @@ const char *resolvers_addresses[] = {"8.8.8.8", "8.8.4.4",
"1.1.1.1", "127.0.0.1"};
const char *resolvers_names[] = {"google", "google",
"cloudflare", "localhost"};
+uint8_t resolvers_trust_levels[] = {40, 40, 80, 20};
+uint8_t resolvers_report_errors[] = {false, false, false, true};
+
#define RESOLVERS_COUNT 4
struct ztdns_instance *ztdns_create_instance(int argc, char **argv)
@@ -237,9 +254,10 @@ struct ztdns_instance *ztdns_create_instance(int argc, char **argv)
*/
ztdns->recursive_resolvers = NULL;
for (i = 0; i < RESOLVERS_COUNT; i++) {
- tmp = ztdns_create_recursive_resolver(resolvers_names[i],
- resolvers_addresses[i],
- DEFAULT_DEBUGLEVEL);
+ tmp = ztdns_create_recursive_resolver
+ (resolvers_names[i], resolvers_addresses[i],
+ resolvers_trust_levels[i], resolvers_report_errors[i],
+ DEFAULT_DEBUGLEVEL);
if (!tmp)
goto out_err_cleanup_recursive_resolvers;