Start ondemand connection when getting a DNS request while disconnected
authorSamuel Ortiz <sameo@linux.intel.com>
Mon, 26 Jul 2010 10:17:41 +0000 (12:17 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 26 Jul 2010 10:22:41 +0000 (12:22 +0200)
plugins/dnsproxy.c

index 5368ceb..04cb2ac 100644 (file)
@@ -34,6 +34,7 @@
 #include <connman/plugin.h>
 #include <connman/resolver.h>
 #include <connman/notifier.h>
+#include <connman/ondemand.h>
 #include <connman/log.h>
 
 #include <glib.h>
@@ -684,7 +685,8 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
        DBG("Received %d bytes (id 0x%04x)", len, buf[0] | buf[1] << 8);
 
        err = parse_request(buf, len, query, sizeof(query));
-       if (err < 0 || g_slist_length(server_list) == 0) {
+       if (err < 0 || (g_slist_length(server_list) == 0 &&
+                               connman_ondemand_connected())) {
                send_response(sk, buf, len, (struct sockaddr *) &sin, size);
                return TRUE;
        }
@@ -708,6 +710,33 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
        buf[0] = req->dstid & 0xff;
        buf[1] = req->dstid >> 8;
 
+       if (!connman_ondemand_connected()) {
+               DBG("Starting on demand connection");
+               /*
+                * We're not connected, let's queue the request and start
+                * an on-demand connection.
+                */
+               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));
+
+               request_pending_list = g_slist_append(request_pending_list,
+                                                                       req);
+
+               connman_ondemand_start("", 300);
+
+               return TRUE;
+       }
+
        return resolv(req, buf, query);
 }