From 08122e992e162831cc62fe7177030fec22712e71 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 5 Jan 2012 13:31:44 +0000 Subject: [PATCH] -stuff --- src/dns/dnsparser.c | 4 +++- src/dns/gnunet-dns-redirector.c | 32 +++++++++++++++++++++++++++++--- src/dns/gnunet-service-dns_new.c | 2 ++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c index 4149d102f..8346051d7 100644 --- a/src/dns/dnsparser.c +++ b/src/dns/dnsparser.c @@ -787,7 +787,9 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p, *buf = GNUNET_malloc (off); *buf_length = off; memcpy (*buf, tmp, off); - return trc; + if (GNUNET_YES == trc) + return GNUNET_NO; + return GNUNET_OK; } diff --git a/src/dns/gnunet-dns-redirector.c b/src/dns/gnunet-dns-redirector.c index bde869816..9c0e39625 100644 --- a/src/dns/gnunet-dns-redirector.c +++ b/src/dns/gnunet-dns-redirector.c @@ -63,19 +63,35 @@ static int verbosity; static void modify_record (const struct GNUNET_DNSPARSER_Record *record) { + char buf[INET6_ADDRSTRLEN]; + switch (record->type) { case GNUNET_DNSPARSER_TYPE_A: if (record->data.raw.data_len != sizeof (struct in_addr)) return; if (NULL != n4) + { + if (verbosity > 1) + fprintf (stderr, + "Changing A record from `%s' to `%s'\n", + inet_ntop (AF_INET, record->data.raw.data, buf, sizeof (buf)), + n4); inet_pton (AF_INET, n4, record->data.raw.data); + } break; case GNUNET_DNSPARSER_TYPE_AAAA: if (record->data.raw.data_len != sizeof (struct in6_addr)) return; if (NULL != n6) + { + if (verbosity > 1) + fprintf (stderr, + "Changing AAAA record from `%s' to `%s'\n", + inet_ntop (AF_INET6, record->data.raw.data, buf, sizeof (buf)), + n4); inet_pton (AF_INET6, n6, record->data.raw.data); + } break; case GNUNET_DNSPARSER_TYPE_NS: case GNUNET_DNSPARSER_TYPE_CNAME: @@ -128,8 +144,7 @@ modify_request (void *cls, p = GNUNET_DNSPARSER_parse (request, request_length); if (NULL == p) { - fprintf (stderr, "Received malformed DNS packet!\n"); - // FIXME: drop instead? + fprintf (stderr, "Received malformed DNS packet, leaving it untouched\n"); GNUNET_DNS_request_forward (rh); return; } @@ -138,11 +153,22 @@ modify_request (void *cls, buf = NULL; ret = GNUNET_DNSPARSER_pack (p, 1024, &buf, &len); GNUNET_DNSPARSER_free_packet (p); - fprintf (stderr, "PACK: %d\n", ret); if (GNUNET_OK != ret) + { + if (GNUNET_NO == ret) + fprintf (stderr, + "Modified DNS response did not fit, keeping old response\n"); + else + GNUNET_break (0); /* our modifications should have been sane! */ GNUNET_DNS_request_forward (rh); + } else + { + if (verbosity > 0) + fprintf (stdout, + "Injecting modified DNS response\n"); GNUNET_DNS_request_answer (rh, len, buf); + } GNUNET_free_non_null (buf); } diff --git a/src/dns/gnunet-service-dns_new.c b/src/dns/gnunet-service-dns_new.c index d814ecb47..e32198b11 100644 --- a/src/dns/gnunet-service-dns_new.c +++ b/src/dns/gnunet-service-dns_new.c @@ -1060,6 +1060,8 @@ handle_client_response (void *cls GNUNET_UNUSED, return; } GNUNET_free_non_null (rr->payload); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Changing DNS resply according to client specifications\n")); rr->payload = GNUNET_malloc (msize); memcpy (rr->payload, &resp[1], msize); if (rr->phase == RP_QUERY) -- 2.25.1