summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaulo Pizarro <paulo.pizarro@gmail.com>2012-06-17 23:22:35 -0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-06-18 13:31:43 +0300
commit230905c20905f2bc5ccf4b8fab75c1b5df2ac31d (patch)
tree6599a6b6eb6490f7ae67a9edebec1464853f6f0f /src
parentc6bdd3e124cb96c03d20e028c9c33e7f3d32efd3 (diff)
downloadconnman-230905c20905f2bc5ccf4b8fab75c1b5df2ac31d.tar.gz
connman-230905c20905f2bc5ccf4b8fab75c1b5df2ac31d.tar.bz2
connman-230905c20905f2bc5ccf4b8fab75c1b5df2ac31d.zip
dnsproxy: Only one copy of the relevant buffers will be made to a TCP request
This copy will be made after scanning the list of nameservers and only if at least one TCP server is created. Otherwise, it will be sent an error response to the request.
Diffstat (limited to 'src')
-rw-r--r--src/dnsproxy.c75
1 files changed, 38 insertions, 37 deletions
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index d7ef63bb..fe1ea817 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -2046,11 +2046,9 @@ static struct server_data *create_server(const char *interface,
DBG("Adding DNS server %s", data->server);
server_list = g_slist_append(server_list, data);
-
- return data;
}
- return NULL;
+ return data;
}
static gboolean resolv(struct request_data *req,
@@ -2345,6 +2343,7 @@ static gboolean tcp_listener_event(GIOChannel *channel, GIOCondition condition,
socklen_t client_addr_len = sizeof(client_addr);
GSList *list;
struct listener_data *ifdata = user_data;
+ int waiting_for_connect = FALSE;
DBG("condition 0x%x", condition);
@@ -2399,7 +2398,6 @@ static gboolean tcp_listener_event(GIOChannel *channel, GIOCondition condition,
req->numserv = 0;
req->ifdata = (struct listener_data *) ifdata;
req->append_domain = FALSE;
- request_list = g_slist_append(request_list, req);
for (list = server_list; list; list = list->next) {
struct server_data *data = list->data;
@@ -2410,33 +2408,8 @@ static gboolean tcp_listener_event(GIOChannel *channel, GIOCondition condition,
server = create_server(data->interface, NULL,
data->server, IPPROTO_TCP);
-
- /*
- * If server is NULL, we're not connected yet.
- * Copy the relevant buffers and continue with
- * the next nameserver.
- * The request will actually be sent once we're
- * properly connected over TCP to this nameserver.
- */
- if (server == NULL) {
- req->request = g_try_malloc0(req->request_len);
- if (req->request == NULL)
- return TRUE;
-
- memcpy(req->request, buf, req->request_len);
-
- req->name = g_try_malloc0(sizeof(query));
- if (req->name == NULL) {
- g_free(req->request);
- return TRUE;
- }
- memcpy(req->name, query, sizeof(query));
-
+ if (server == NULL)
continue;
- }
-
- if (req->timeout > 0)
- g_source_remove(req->timeout);
for (domains = data->domains; domains;
domains = domains->next) {
@@ -2448,15 +2421,43 @@ static gboolean tcp_listener_event(GIOChannel *channel, GIOCondition condition,
g_strdup(dom));
}
- req->timeout = g_timeout_add_seconds(30, request_timeout, req);
- if (ns_resolv(server, req, buf, query) > 0) {
- if (req->timeout > 0) {
- g_source_remove(req->timeout);
- req->timeout = 0;
- }
- }
+ waiting_for_connect = TRUE;
}
+ if (waiting_for_connect == FALSE) {
+ /* No server is waiting for connect */
+ send_response(client_sk, buf, len, NULL, 0, IPPROTO_TCP);
+ g_free(req);
+ return TRUE;
+ }
+
+ /*
+ * The server is not connected yet.
+ * Copy the relevant buffers.
+ * The request will actually be sent once we're
+ * properly connected over TCP to the nameserver.
+ */
+ req->request = g_try_malloc0(req->request_len);
+ if (req->request == NULL) {
+ send_response(client_sk, buf, len, NULL, 0, IPPROTO_TCP);
+ g_free(req);
+ return TRUE;
+ }
+ memcpy(req->request, buf, req->request_len);
+
+ req->name = g_try_malloc0(sizeof(query));
+ if (req->name == NULL) {
+ send_response(client_sk, buf, len, NULL, 0, IPPROTO_TCP);
+ g_free(req->request);
+ g_free(req);
+ return TRUE;
+ }
+ memcpy(req->name, query, sizeof(query));
+
+ req->timeout = g_timeout_add_seconds(30, request_timeout, req);
+
+ request_list = g_slist_append(request_list, req);
+
return TRUE;
}