#include "gnunet_signatures.h"
#include "dns_new.h"
#include "gnunet_dns_service-new.h"
+#include "gnunet_statistics_service.h"
/* see http://www.iana.org/assignments/ethernet-numbers */
#ifndef ETH_P_IPV4
*/
static const struct GNUNET_CONFIGURATION_Handle *cfg;
+/**
+ * Statistics.
+ */
+static struct GNUNET_STATISTICS_Handle *stats;
+
/**
* Handle to DNS hijacker helper process ("gnunet-helper-dns").
*/
cleanup_rr (&requests[i]);
GNUNET_SERVER_notification_context_destroy (nc);
nc = NULL;
+ if (stats != NULL)
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
+ stats = NULL;
+ }
}
hdr,
GNUNET_YES,
NULL, NULL);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS requests answered via TUN interface"),
+ 1, GNUNET_NO);
}
/* clean up, we're done */
cleanup_rr (rr);
}
if (NULL == dnsout)
{
- /* fail, FIXME: case for statistics! */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS exit failed (address family not supported)"),
+ 1, GNUNET_NO);
cleanup_rr (rr);
return;
}
rr = &requests[dns->id];
if (rr->phase != RP_INTERNET_DNS)
{
- /* FIXME: case for statistics */
/* unexpected / bogus reply */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# External DNS response discarded (no matching request)"),
+ 1, GNUNET_NO);
return;
}
GNUNET_free_non_null (rr->payload);
rr = &requests[off];
if (rr->request_id != resp->request_id)
{
- // FIXME: this is a case for calling statistics...
- // (client is answering a request that we've lost
- // track of -- more than 64k requests ago or so...)
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# Client response discarded (no matching request)"),
+ 1, GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
(ip4->protocol != IPPROTO_UDP) )
{
/* non-IP/UDP packet received on TUN (or with options) */
- // FIXME: maybe just log with stats?
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Received malformed IPv4-UDP packet on TUN interface.\n"));
return;
}
udp = (const struct udp_packet*) &ip4[1];
(ip6->next_header != IPPROTO_UDP) )
{
/* non-IP/UDP packet received on TUN (or with extensions) */
- // FIXME: maybe just log with stats?
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Received malformed IPv6-UDP packet on TUN interface.\n"));
return;
}
udp = (const struct udp_packet*) &ip6[1];
break;
default:
/* non-IP packet received on TUN!? */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Got packet with %u bytes and protocol %u from TUN\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Got non-IP packet with %u bytes and protocol %u from TUN\n"),
(unsigned int) msize,
ntohs (tun->proto));
- GNUNET_break (0);
return;
}
if (msize <= sizeof (struct udp_packet) + sizeof (struct dns_header))
{
/* non-DNS packet received on TUN, ignore */
- /* FIXME: case for statistics... */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# Non-DNS UDP packet received via TUN interface"),
+ 1, GNUNET_NO);
return;
}
msize -= sizeof (struct udp_packet);
dsta4->sin_addr = ip4->destination_address;
srca4->sin_port = udp->spt;
dsta4->sin_port = udp->dpt;
- /* FIXME: bother with FreeBSD sin_len crap? */
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ srca4->sin_len = sizeof (sizeof (struct sockaddr_in));
+ dsta4->sin_len = sizeof (sizeof (struct sockaddr_in));
+#endif
}
else /* ipv6 */
{
dsta6->sin6_addr = ip6->destination_address;
srca6->sin6_port = udp->spt;
dsta6->sin6_port = udp->dpt;
- /* FIXME: bother with FreeBSD sin_len crap? */
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ srca6->sin_len = sizeof (sizeof (struct sockaddr_in6));
+ dsta6->sin_len = sizeof (sizeof (struct sockaddr_in6));
+#endif
}
rr->payload = GNUNET_malloc (msize);
rr->payload_length = msize;
rr->request_id = dns->id | (request_id_gen << 16);
request_id_gen++;
- /* FIXME: case for statistics... */
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# DNS requests received via TUN interface"),
+ 1, GNUNET_NO);
/* start request processing state machine */
next_phase (rr);
}
char *ipv6prefix;
cfg = cfg_;
+ stats = GNUNET_STATISTICS_create ("dns", cfg);
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
cls);