#include <gnunet_util_lib.h>
#include <gnunet_dnsparser_lib.h>
#include <gnunet_gns_service.h>
+#include <gnunet_dnsstub_lib.h>
+#include "gns.h"
/**
* Timeout for DNS requests.
*/
#define TIMEOUT GNUNET_TIME_UNIT_MINUTES
+/**
+ * Default suffix
+ */
+#define DNS_SUFFIX ".zkey.eu"
+
+/**
+ * FCFS suffix
+ */
+#define FCFS_SUFFIX "fcfs.zkey.eu"
+
/**
* Data kept per request.
*/
*/
struct GNUNET_GNS_LookupRequest *lookup;
+ /**
+ * Our DNS request handle
+ */
+ struct GNUNET_DNSSTUB_RequestSocket *dns_lookup;
+
/**
* Task run on timeout or shutdown to clean up without
* response.
*/
struct GNUNET_GNS_Handle *gns;
+/**
+ * Stub resolver
+ */
+struct GNUNET_DNSSTUB_Context *dns_stub;
+
/**
* Listen socket for IPv4.
*/
*/
static GNUNET_SCHEDULER_TaskIdentifier t6;
+/**
+ * DNS suffix
+ */
+static char *dns_suffix;
+
+/**
+ * FCFS suffix
+ */
+static char *fcfs_suffix;
+
+/**
+ * IP of DNS server
+ */
+static char *dns_ip;
/**
* Task run on shutdown. Cleans up everything.
}
GNUNET_GNS_disconnect (gns);
gns = NULL;
+ GNUNET_DNSSTUB_stop (dns_stub);
+ dns_stub = NULL;
}
GNUNET_free (request);
}
+/**
+ * Iterator called on obtained result for a DNS
+ * lookup
+ *
+ * @param cls closure
+ * @param rs the request socket
+ * @param dns the DNS udp payload
+ * @param r size of the DNS payload
+ */
+static void
+dns_result_processor (void *cls,
+ struct GNUNET_DNSSTUB_RequestSocket *rs,
+ const struct GNUNET_TUN_DnsHeader *dns,
+ size_t r)
+{
+ struct Request *request = cls;
+ request->packet = GNUNET_DNSPARSER_parse ((char*)dns, r);
+ send_response (request);
+}
/**
* Iterator called on obtained result for a GNS
packet->flags.recursion_available = 1;
packet->flags.message_truncated = 0;
packet->flags.authoritative_answer = 0;
- packet->flags.opcode = GNUNET_DNSPARSER_OPCODE_STATUS; // ???
+ //packet->flags.opcode = GNUNET_DNSPARSER_OPCODE_STATUS; // ???
for (i=0;i<rd_count;i++)
{
+ rec.expiration_time.abs_value = rd[i].expiration_time;
switch (rd[i].record_type)
{
case GNUNET_DNSPARSER_TYPE_A:
rec);
break;
case GNUNET_DNSPARSER_TYPE_CNAME:
- GNUNET_break (0); // FIXME: CNAME is handled by the GNS resolver! We never return this unless explicitly requested!
+ rec.name = GNUNET_strdup (packet->queries[0].name);
+ rec.data.hostname = strdup (rd[i].data);
+ rec.class = GNUNET_DNSPARSER_CLASS_INTERNET;
+ rec.type = GNUNET_DNSPARSER_TYPE_CNAME;
+ memcpy (rec.data.hostname,
+ rd[i].data,
+ rd[i].data_size);
+ GNUNET_array_append (packet->answers,
+ packet->num_answers,
+ rec);
break;
default:
/* skip */
char *name;
size_t name_len;
enum GNUNET_GNS_RecordType type;
+ int use_gns;
packet = GNUNET_DNSPARSER_parse (udp_msg, udp_msg_size);
if (NULL == packet)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Received malformed DNS request from %s\n"),
+ _("Cannot parse DNS request from %s\n"),
GNUNET_a2s (addr, addr_len));
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received request with flags %u, #answers %d, #auth %d, #additional %d\n",
+ (unsigned int) packet->flags.query_or_response,
+ (int) packet->num_answers,
+ (int) packet->num_authority_records,
+ (int) packet->num_additional_records);
if ( (0 != packet->flags.query_or_response) ||
(0 != packet->num_answers) ||
- (0 != packet->num_authority_records) ||
- (0 != packet->num_additional_records) )
+ (0 != packet->num_authority_records))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Received malformed DNS request from %s\n"),
request);
name = GNUNET_strdup (packet->queries[0].name);
name_len = strlen (name);
- if ( (name_len > strlen (".zkey.eu")) &&
- (0 == strcasecmp (".zkey.eu",
- &name[name_len - strlen (".zkey.eu")])) )
+ use_gns = GNUNET_NO;
+ if ( (name_len > strlen (dns_suffix)) &&
+ (0 == strcasecmp (dns_suffix,
+ &name[name_len - strlen (dns_suffix)])) )
{
- //FIXME here check if the top label after zkey.eu is a hash and append
- //correct TLD appropriately
- name[name_len - strlen (".zkey.eu")] = '\0';
- strcat (name, ".gnunet"); /* little hack, only works because
- ".zkey.eu" is longer than ".gnunet" */
+ if ( (name_len > strlen (fcfs_suffix)) &&
+ (0 == strcasecmp (fcfs_suffix,
+ &name[name_len - strlen (fcfs_suffix)])) )
+ {
+ name[name_len - strlen (fcfs_suffix) + 1] = '\0';
+ strcat (name, GNUNET_GNS_TLD);
+ }
+ else
+ {
+ name[name_len - strlen (dns_suffix) + 1] = '\0';
+ strcat (name, GNUNET_GNS_TLD_ZKEY);
+ }
name_len = strlen (name);
}
- if ( (name_len > strlen (".gnunet")) &&
- (0 == strcasecmp (".gnunet",
- &name[name_len - strlen (".gnunet")])) )
- {
+ if ( (name_len > strlen ((GNUNET_GNS_TLD) + 1)) &&
+ (0 == strcasecmp (GNUNET_GNS_TLD,
+ &name[name_len - strlen (GNUNET_GNS_TLD)])) )
+ use_gns = GNUNET_YES;
+
+ if ( (name_len > strlen (GNUNET_GNS_TLD_ZKEY)) &&
+ (0 == strcasecmp (GNUNET_GNS_TLD_ZKEY,
+ &name[name_len - strlen (GNUNET_GNS_TLD_ZKEY)])) )
+ use_gns = GNUNET_YES;
+
+ if (GNUNET_YES == use_gns)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Calling GNS\n");
type = packet->queries[0].type;
request->lookup = GNUNET_GNS_lookup (gns,
name,
/* FIXME: do traditional *DNS* lookup; note that
gnunet-service-dns already has code to do this;
factor into library to share! Why not use GNUNET_RESOLVER here?*/
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Calling DNS at %s\n", dns_ip);
+ GNUNET_DNSPARSER_free_packet (request->packet);
+ request->dns_lookup = GNUNET_DNSSTUB_resolve2 (dns_stub,
+ udp_msg,
+ udp_msg_size,
+ &dns_result_processor,
+ request);
+
+
+
}
GNUNET_free (name);
}
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- gns = GNUNET_GNS_connect (cfg);
- if (NULL == gns)
+ if (NULL == dns_ip)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No DNS server specified!\n");
+ return;
+ }
+
+ if (NULL == dns_suffix)
+ dns_suffix = DNS_SUFFIX;
+ if (NULL == fcfs_suffix)
+ fcfs_suffix = FCFS_SUFFIX;
+ if (NULL == (gns = GNUNET_GNS_connect (cfg)))
return;
+ if (NULL == (dns_stub = GNUNET_DNSSTUB_start (dns_ip)))
+ {
+ GNUNET_GNS_disconnect (gns);
+ gns = NULL;
+ return;
+ }
listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET,
SOCK_DGRAM,
IPPROTO_UDP);
}
if ( (NULL == listen_socket4) &&
(NULL == listen_socket6) )
- return;
+ {
+ GNUNET_GNS_disconnect (gns);
+ gns = NULL;
+ GNUNET_DNSSTUB_stop (dns_stub);
+ dns_stub = NULL;
+ return;
+ }
if (NULL != listen_socket4)
t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
listen_socket4,
char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ {'d', "dns", NULL,
+ gettext_noop ("IP of recursive dns resolver to use (required)"), 1,
+ &GNUNET_GETOPT_set_string, &dns_ip},
+ {'s', "suffix", NULL,
+ gettext_noop ("Authoritative DNS suffix to use (optional); default: zkey.eu"), 1,
+ &GNUNET_GETOPT_set_string, &dns_suffix},
+ {'f', "fcfs", NULL,
+ gettext_noop ("Authoritative FCFS suffix to use (optional); default: fcfs.zkey.eu"), 1,
+ &GNUNET_GETOPT_set_string, &fcfs_suffix},
GNUNET_GETOPT_OPTION_END
};
int ret;