summaryrefslogtreecommitdiff
path: root/src/dnsproxy.c
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@linux.intel.com>2012-01-09 16:08:45 -0800
committerDaniel Wagner <daniel.wagner@bmw-carit.de>2012-01-10 13:43:57 +0100
commitce243d289f022921d21168e3682abe5d6f901340 (patch)
tree39dc1351c6ad2afed802b8f277a4a652ca711553 /src/dnsproxy.c
parent441e41382b97c7ff8802a2ed78f4ca6a0c672489 (diff)
downloadconnman-ce243d289f022921d21168e3682abe5d6f901340.tar.gz
connman-ce243d289f022921d21168e3682abe5d6f901340.tar.bz2
connman-ce243d289f022921d21168e3682abe5d6f901340.zip
dnsproxy: Track cache hit statistics
For various decisions (which entries to prune, which entries to refresh) and for debugging, it's useful to track how many hits a cache entry gets. This patch adds the basic counting for this; the only tricky aspect is that we serve DNS entries out of the cache, even in case of a miss, so we need to compensate for that by subtracting a hit first.
Diffstat (limited to 'src/dnsproxy.c')
-rw-r--r--src/dnsproxy.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index a30f4c46..d2fa07cb 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -138,6 +138,7 @@ struct cache_data {
struct cache_entry {
char *key;
+ int hits;
struct cache_data *ipv4;
struct cache_data *ipv6;
};
@@ -1085,6 +1086,13 @@ static int cache_update(struct server_data *srv, unsigned char *msg,
data->cache_until = entry->ipv4->cache_until;
memcpy(data->data, msg, msg_len);
entry->ipv6 = data;
+ /*
+ * we will get a "hit" when we serve the response
+ * out of the cache
+ */
+ entry->hits--;
+ if (entry->hits < 0)
+ entry->hits = 0;
return 0;
}
}
@@ -1116,6 +1124,7 @@ static int cache_update(struct server_data *srv, unsigned char *msg,
entry->key = g_strdup(question);
entry->ipv4 = entry->ipv6 = NULL;
+ entry->hits = 0;
if (type == 1)
entry->ipv4 = data;
@@ -1137,6 +1146,14 @@ static int cache_update(struct server_data *srv, unsigned char *msg,
else
entry->ipv6 = data;
+ /*
+ * compensate for the hit we'll get for serving
+ * the response out of the cache
+ */
+ entry->hits--;
+ if (entry->hits < 0)
+ entry->hits = 0;
+
new_entry = FALSE;
}
@@ -1208,8 +1225,10 @@ static int ns_resolv(struct server_data *server, struct request_data *req,
else
data = entry->ipv6;
- if (data)
+ if (data) {
ttl_left = data->valid_until - time(0);
+ entry->hits++;
+ }
if (data != NULL && req->protocol == IPPROTO_TCP) {
send_cached_response(req->client_sk, data->data,