diff options
author | Paulo Pizarro <paulo.pizarro@gmail.com> | 2012-06-17 23:22:36 -0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-06-18 13:31:47 +0300 |
commit | aab0baede4eca5fa5d539bf0cffcb712f0453486 (patch) | |
tree | 2dd8adf365d453fc2518d712b32bb0ade768b459 /src/dnsproxy.c | |
parent | 230905c20905f2bc5ccf4b8fab75c1b5df2ac31d (diff) | |
download | connman-aab0baede4eca5fa5d539bf0cffcb712f0453486.tar.gz connman-aab0baede4eca5fa5d539bf0cffcb712f0453486.tar.bz2 connman-aab0baede4eca5fa5d539bf0cffcb712f0453486.zip |
dnsproxy: If the answer is in the cache, the TCP request is released
Diffstat (limited to 'src/dnsproxy.c')
-rw-r--r-- | src/dnsproxy.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/dnsproxy.c b/src/dnsproxy.c index fe1ea817..71efe6af 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -1510,6 +1510,17 @@ static int ns_resolv(struct server_data *server, struct request_data *req, return 0; } +static void destroy_request_data(struct request_data *req) +{ + if (req->timeout > 0) + g_source_remove(req->timeout); + + g_free(req->resp); + g_free(req->request); + g_free(req->name); + g_free(req); +} + static int forward_dns_reply(unsigned char *reply, int reply_len, int protocol, struct server_data *data) { @@ -1805,29 +1816,34 @@ hangup: server->timeout = 0; } - for (list = request_list; list; list = list->next) { + for (list = request_list; list; ) { struct request_data *req = list->data; - if (req->protocol == IPPROTO_UDP) + if (req->protocol == IPPROTO_UDP) { + list = list->next; continue; + } DBG("Sending req %s over TCP", (char *)req->name); + if (ns_resolv(server, req, + req->request, req->name) > 0) { + /* + * A cached result was sent, + * so the request can be released + */ + list = list->next; + request_list = g_slist_remove(request_list, req); + destroy_request_data(req); + continue; + } + if (req->timeout > 0) g_source_remove(req->timeout); req->timeout = g_timeout_add_seconds(30, request_timeout, req); - if (ns_resolv(server, req, req->request, - req->name) > 0) { - /* We sent cached result so no need for timeout - * handler. - */ - if (req->timeout > 0) { - g_source_remove(req->timeout); - req->timeout = 0; - } - } + list = list->next; } } else if (condition & G_IO_IN) { @@ -2675,17 +2691,6 @@ static int create_listener(struct listener_data *ifdata) return 0; } -static void destroy_request_data(struct request_data *req) -{ - if (req->timeout > 0) - g_source_remove(req->timeout); - - g_free(req->resp); - g_free(req->request); - g_free(req->name); - g_free(req); -} - static void destroy_listener(struct listener_data *ifdata) { GSList *list; |