Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH 0/5 v2] Properly configure search domains for
      resolvers ([email protected])
   2. [PATCH 1/5] dnsproxy: Rename append_domain() to
      update_domain() ([email protected])
   3. [PATCH 2/5] dnsproxy: Remove domains from dns server domain
      list when needed ([email protected])
   4. [PATCH 3/5] service: Reconfigure search domains when
      nameservers have been modified ([email protected])
   5. [PATCH 4/5] resolver: Reorder call to
      __connman_service_nameserver_append() ([email protected])
   6. [PATCH 5/5] resolver: Readd search domains back when
      resolvers are redone ([email protected])
   7. [PATCH v2 (resend)] wifi: Reset device->scanning if scan has
      not returned in 60 secs ([email protected])
   8. [PATCH v4] NTP implementation for IPv6 timeserver (Naveen Singh)


----------------------------------------------------------------------

Message: 1
Date: Tue, 24 Nov 2015 22:18:55 +0200
From: [email protected]
To: [email protected]
Subject: [PATCH 0/5 v2] Properly configure search domains for
        resolvers
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

From: Pasi Sj?holm <[email protected]>

While debugging append_domain issue reported Vladimir Pavljuchenkov
I noticed that dnsproxy did not do any appended_domain-queries with
nameserver/resolvers configured by IPv6-infrastructure.

After these five small patches the things seems to be right
and all the resolvers are queried with configured search domains
(DNSSL, DHCPv4/6 and manually configured).

DHCPv4/6: siirappi.com
DNSSL: google.com

Before:

--cut--
IP 192.168.189.99.57437 > 192.168.189.1.53: 54758+ A? bz. (20)
IP 192.168.189.99.57437 > 192.168.189.1.53: 24311+ A? bz.siirappi.com. (33)
IP6 2001:470:28:241:2456:88bd:a205:211c.31364 > 2001:470:28:241::1.53: 25855+ 
A? bz. (20)
IP 192.168.189.1.53 > 192.168.189.99.57437: 54758 0/1/0 (85)
IP 192.168.189.1.53 > 192.168.189.99.57437: 24311 1/0/0 A 1.2.3.4 (49)
IP6 2001:470:28:241::1.53 > 2001:470:28:241:2456:88bd:a205:211c.31364: 25855 
0/0/0 (20)
--cut--

After the patches:

--cut--
IP 192.168.189.99.57437 > 192.168.189.1.53: 62803+ A? bz. (20)
IP 192.168.189.99.57437 > 192.168.189.1.53: 56164+ A? bz.siirappi.com. (33)
IP 192.168.189.99.57437 > 192.168.189.1.53: 56164+ A? bz.google.com. (31)
IP6 2001:470:28:241:2456:88bd:a205:211c.33378 > 2001:470:28:241::1.53: 62803+ 
A? bz. (20)
IP6 2001:470:28:241:2456:88bd:a205:211c.33378 > 2001:470:28:241::1.53: 56164+ 
A? bz.siirappi.com. (33)
IP6 2001:470:28:241:2456:88bd:a205:211c.33378 > 2001:470:28:241::1.53: 56164+ 
A? bz.google.com. (31)
IP 192.168.189.1.53 > 192.168.189.99.57437: 62803 0/0/0 (20)
IP 192.168.189.1.53 > 192.168.189.99.57437: 56164 1/0/0 A 1.2.3.4 (49)
IP 192.168.189.1.53 > 192.168.189.99.57437: 56164 NXDomain 0/1/0 (81)
IP6 2001:470:28:241::1.53 > 2001:470:28:241:2456:88bd:a205:211c.33378: 62803 
0/0/0 (20)
IP6 2001:470:28:241::1.53 > 2001:470:28:241:2456:88bd:a205:211c.33378: 56164 
1/0/0 A 1.2.3.4 (49)
IP6 2001:470:28:241::1.53 > 2001:470:28:241:2456:88bd:a205:211c.33378: 56164 
NXDomain 0/0/0 (31)
--cut--

Pasi Sj?holm (5):
  dnsproxy: Rename append_domain() to update_domain()
  dnsproxy: Remove domains from dns server domain list when needed
  service: Reconfigure search domains when nameservers have been
    modified
  resolver: Reorder call to __connman_service_nameserver_append()
  resolver: Readd search domains back when resolvers are redone

 src/dnsproxy.c | 25 ++++++++++++++++++++++---
 src/resolver.c | 46 ++++++++++++++++++++++++++++++++++------------
 src/service.c  | 12 ++++++------
 3 files changed, 62 insertions(+), 21 deletions(-)

-- 
2.5.0



------------------------------

Message: 2
Date: Tue, 24 Nov 2015 22:18:56 +0200
From: [email protected]
To: [email protected]
Subject: [PATCH 1/5] dnsproxy: Rename append_domain() to
        update_domain()
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

From: Pasi Sj?holm <[email protected]>

Add new append_domain()-function which calls
update_domain()-function by setting boolean append-variable
accordingly.

This enables a capability to remove domains from the dns-server's
domain list.

Signed-off-by: Pasi Sj?holm <[email protected]>
---
 src/dnsproxy.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index c37eee9..9f79d64 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -2649,7 +2649,7 @@ static bool resolv(struct request_data *req,
        return false;
 }
 
-static void append_domain(int index, const char *domain)
+static void update_domain(int index, const char *domain, bool append)
 {
        GSList *list;
 
@@ -2680,13 +2680,21 @@ static void append_domain(int index, const char *domain)
                        }
                }
 
-               if (!dom_found) {
+               if (!dom_found && append) {
                        data->domains =
                                g_list_append(data->domains, g_strdup(domain));
+               } else if (dom_found && !append) {
+                       data->domains =
+                               g_list_remove(data->domains, dom);
                }
        }
 }
 
+static void append_domain(int index, const char *domain)
+{
+       update_domain(index, domain, true);
+}
+
 static void flush_requests(struct server_data *server)
 {
        GSList *list;
-- 
2.5.0



------------------------------

Message: 3
Date: Tue, 24 Nov 2015 22:18:57 +0200
From: [email protected]
To: [email protected]
Subject: [PATCH 2/5] dnsproxy: Remove domains from dns server domain
        list when needed
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

From: Pasi Sj?holm <[email protected]>

Whenever the remove_entries() is called the __connman_dnsproxy_remove()
must act properly eg. with triggered solver_expire_cb() the expired 
DNSSL-records
from the IPv6 RA's must be removed.

Signed-off-by: Pasi Sj?holm <[email protected]>
---
 src/dnsproxy.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index 9f79d64..c497f73 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -2695,6 +2695,11 @@ static void append_domain(int index, const char *domain)
        update_domain(index, domain, true);
 }
 
+static void remove_domain(int index, const char *domain)
+{
+       update_domain(index, domain, false);
+}
+
 static void flush_requests(struct server_data *server)
 {
        GSList *list;
@@ -2777,9 +2782,15 @@ int __connman_dnsproxy_remove(int index, const char 
*domain,
 {
        DBG("index %d server %s", index, server);
 
-       if (!server)
+       if (!server && !domain)
                return -EINVAL;
 
+       if (!server) {
+               remove_domain(index, domain);
+
+               return 0;
+       }
+
        if (g_str_equal(server, "127.0.0.1"))
                return -ENODEV;
 
-- 
2.5.0



------------------------------

Message: 4
Date: Tue, 24 Nov 2015 22:18:58 +0200
From: [email protected]
To: [email protected]
Subject: [PATCH 3/5] service: Reconfigure search domains when
        nameservers have been modified
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

From: Pasi Sj?holm <[email protected]>

searchdomain_add_all()-function must be called when nameservers are
modified for the service as the IPv4- and IPv6-ipconfig won't
become connected at the same time and calling searchdomain_add_all()
only once when the service becomes ready-state is not enough.

Also nameserver-configuration coming from eg. IPv6 RA RDNSS
(__connman_service_nameserver_append()) must have search domains
applied to it.
---
 src/service.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/service.c b/src/service.c
index e33284d..3fc5b60 100644
--- a/src/service.c
+++ b/src/service.c
@@ -134,6 +134,7 @@ static struct connman_ipconfig *create_ip4config(struct 
connman_service *service
 static struct connman_ipconfig *create_ip6config(struct connman_service 
*service,
                int index);
 
+static int searchdomain_add_all(struct connman_service *service);
 
 struct find_data {
        const char *path;
@@ -966,11 +967,7 @@ static int nameserver_add_all(struct connman_service 
*service,
                                service->nameservers_config[i]);
                        i++;
                }
-
-               return 0;
-       }
-
-       if (service->nameservers) {
+       } else if (service->nameservers) {
                while (service->nameservers[i]) {
                        nameserver_add(service, type,
                                service->nameservers[i]);
@@ -978,6 +975,8 @@ static int nameserver_add_all(struct connman_service 
*service,
                }
        }
 
+       searchdomain_add_all(service);
+
        return 0;
 }
 
@@ -1121,6 +1120,8 @@ int __connman_service_nameserver_append(struct 
connman_service *service,
                nameserver_add(service, CONNMAN_IPCONFIG_TYPE_ALL, nameserver);
        }
 
+       searchdomain_add_all(service);
+
        return 0;
 }
 
@@ -5378,7 +5379,6 @@ static int service_indicate_state(struct connman_service 
*service)
                g_get_current_time(&service->modified);
                service_save(service);
 
-               searchdomain_add_all(service);
                dns_changed(service);
                domain_changed(service);
                proxy_changed(service);
-- 
2.5.0



------------------------------

Message: 5
Date: Tue, 24 Nov 2015 22:18:59 +0200
From: [email protected]
To: [email protected]
Subject: [PATCH 4/5] resolver: Reorder call to
        __connman_service_nameserver_append()
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

From: Pasi Sj?holm <[email protected]>

__connman_service_nameserver_append() must be called after the
resolver entry has been appended to entry_list and dnsproxy
because otherwise searchdomain_add_all()-call on service
will not add the search domain configuration to nameserver
configured through RDNSS.
---
 src/resolver.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/resolver.c b/src/resolver.c
index 6a64938..53e9ebb 100644
--- a/src/resolver.c
+++ b/src/resolver.c
@@ -378,18 +378,6 @@ static int append_resolver(int index, const char *domain,
 
                entry->timeout = g_timeout_add_seconds(interval,
                                resolver_refresh_cb, entry);
-
-               /*
-                * We update the service only for those nameservers
-                * that are automagically added via netlink (lifetime > 0)
-                */
-               if (server && entry->index >= 0) {
-                       struct connman_service *service;
-                       service = 
__connman_service_lookup_from_index(entry->index);
-                       if (service)
-                               __connman_service_nameserver_append(service,
-                                                               server, true);
-               }
        }
 
        if (entry->index >= 0 && entry->server)
@@ -402,6 +390,18 @@ static int append_resolver(int index, const char *domain,
        else
                __connman_resolvfile_append(entry->index, domain, server);
 
+       /*
+        * We update the service only for those nameservers
+        * that are automagically added via netlink (lifetime > 0)
+        */
+       if (server && entry->index >= 0 && lifetime) {
+               struct connman_service *service;
+               service = __connman_service_lookup_from_index(entry->index);
+               if (service)
+                       __connman_service_nameserver_append(service,
+                                                       server, true);
+       }
+
        return 0;
 }
 
-- 
2.5.0



------------------------------

Message: 6
Date: Tue, 24 Nov 2015 22:19:00 +0200
From: [email protected]
To: [email protected]
Subject: [PATCH 5/5] resolver: Readd search domains back when
        resolvers are redone
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

From: Pasi Sj?holm <[email protected]>

Redoing dns servers will remove the current list of search domains
from the servers/resolvers (eg. RDNSS configured ones) therefore they need
to be added back.

Signed-off-by: Pasi Sj?holm <[email protected]>
---
 src/resolver.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/resolver.c b/src/resolver.c
index 53e9ebb..3666c97 100644
--- a/src/resolver.c
+++ b/src/resolver.c
@@ -600,6 +600,28 @@ int __connman_resolver_redo_servers(int index)
                                        entry->server);
        }
 
+       /*
+        * We want to re-add all search domains back to search
+        * domain lists as they just got removed for RDNSS IPv6-servers
+        * (above).
+        * Removal of search domains is not necessary
+        * as there can be only one instance of each search domain
+        * in the each dns-servers search domain list.
+        */
+
+       for (list = entry_list; list; list = list->next) {
+               struct entry_data *entry = list->data;
+
+               if (entry->index != index)
+                       continue;
+
+               if (entry->server)
+                       continue;
+
+               __connman_dnsproxy_append(entry->index, entry->domain,
+                                       NULL);
+       }
+
        return 0;
 }
 
-- 
2.5.0



------------------------------

Message: 7
Date: Tue, 24 Nov 2015 22:24:21 +0200
From: [email protected]
To: [email protected]
Subject: [PATCH v2 (resend)] wifi: Reset device->scanning if scan has
        not returned in 60 secs
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

From: Pasi Sj?holm <[email protected]>

Due unknown reason sometimes scan_callback()-function is not being called
after the scan has been succesfully initiated.

This will lead into deadlock situation where device->scanning is
indefinitely true and will forbid any future attemps of scanning available
wifi networks.

The deadlock can be manually sorted out by commanding wpa_supplicant
to scan available networks. If any networks are available and one or
more of them being autoconnectable ConnMan will connect them after
receiving NetworkAdded-signal from wpa_supplicant. This will cause
autoscan-feature to stop and setting the device->scanning to false.
---
 plugins/wifi.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index dfe849f..1e6507b 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -61,6 +61,7 @@
 
 #define CLEANUP_TIMEOUT   8    /* in seconds */
 #define INACTIVE_TIMEOUT  12   /* in seconds */
+#define SCAN_FAIL_TIMEOUT 60   /* in seconds */
 #define FAVORITE_MAXIMUM_RETRIES 2
 
 #define BGSCAN_DEFAULT "simple:30:-45:300"
@@ -131,6 +132,7 @@ struct wifi_data {
        struct hidden_params *hidden;
        bool postpone_hidden;
        struct wifi_tethering_info *tethering_param;
+       unsigned int scan_fail_timeout;
        /**
         * autoscan "emulation".
         */
@@ -817,9 +819,25 @@ static void reset_autoscan(struct connman_device *device)
        connman_device_unref(device);
 }
 
+static gboolean scan_fail_timeout(gpointer data)
+{
+       struct connman_device *device = data;
+       struct wifi_data *wifi = connman_device_get_data(device);
+
+       DBG("");
+
+       if (!wifi)
+               return FALSE;
+
+       connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
+       wifi->scan_fail_timeout = 0;
+
+       return FALSE;
+}
+
 static void stop_autoscan(struct connman_device *device)
 {
-       const struct wifi_data *wifi = connman_device_get_data(device);
+       struct wifi_data *wifi = connman_device_get_data(device);
 
        if (!wifi || !wifi->autoscan)
                return;
@@ -827,6 +845,11 @@ static void stop_autoscan(struct connman_device *device)
        reset_autoscan(device);
 
        connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
+
+       if (wifi->scan_fail_timeout) {
+               g_source_remove(wifi->scan_fail_timeout);
+               wifi->scan_fail_timeout = 0;
+       }
 }
 
 static void check_p2p_technology(void)
@@ -876,6 +899,10 @@ static void wifi_remove(struct connman_device *device)
        if (wifi->p2p_connection_timeout)
                g_source_remove(wifi->p2p_connection_timeout);
 
+       if (wifi->scan_fail_timeout) {
+               g_source_remove(wifi->scan_fail_timeout);
+       }
+
        remove_networks(device, wifi);
 
        connman_device_set_powered(device, false);
@@ -1193,6 +1220,11 @@ static int throw_wifi_scan(struct connman_device *device,
        if (ret == 0) {
                connman_device_set_scanning(device,
                                CONNMAN_SERVICE_TYPE_WIFI, true);
+
+               wifi->scan_fail_timeout = g_timeout_add_seconds(
+                                               SCAN_FAIL_TIMEOUT,
+                                               scan_fail_timeout,
+                                               device);
        } else
                connman_device_unref(device);
 
@@ -1262,6 +1294,11 @@ static void scan_callback(int result, 
GSupplicantInterface *interface,
        if (scanning) {
                connman_device_set_scanning(device,
                                CONNMAN_SERVICE_TYPE_WIFI, false);
+
+               if (wifi && wifi->scan_fail_timeout) {
+                       g_source_remove(wifi->scan_fail_timeout);
+                       wifi->scan_fail_timeout = 0;
+               }
        }
 
        if (result != -ENOLINK)
@@ -1516,6 +1553,11 @@ static int wifi_disable(struct connman_device *device)
                connman_device_unref(wifi->device);
        }
 
+       if (wifi->scan_fail_timeout) {
+               g_source_remove(wifi->scan_fail_timeout);
+               wifi->scan_fail_timeout = 0;
+       }
+
        /* In case of a user scan, device is still referenced */
        if (connman_device_get_scanning(device)) {
                connman_device_set_scanning(device,
@@ -1864,6 +1906,12 @@ static int wifi_scan(enum connman_service_type type,
        if (ret == 0) {
                connman_device_set_scanning(device,
                                CONNMAN_SERVICE_TYPE_WIFI, true);
+
+               wifi->scan_fail_timeout = g_timeout_add_seconds(
+                                               SCAN_FAIL_TIMEOUT,
+                                               scan_fail_timeout,
+                                               device);
+
        } else {
                g_supplicant_free_scan_params(scan_params);
                connman_device_unref(device);
-- 
2.1.4



------------------------------

Message: 8
Date: Tue, 24 Nov 2015 20:33:17 -0800
From: Naveen Singh <[email protected]>
To: [email protected]
Subject: [PATCH v4] NTP implementation for IPv6 timeserver
Message-ID:
        <[email protected]>

From: nasingh <[email protected]>

Current NTP code is written with an assumption that
timeserver is always an IPv4 address. If there is an
IPv6 timeserver then the socket operation would fail
with error as Permission denied(13). This change in
ntp.c ensures that code works fine with both IPv4 and
IPv6 address.
---
 src/ntp.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 98 insertions(+), 33 deletions(-)

diff --git a/src/ntp.c b/src/ntp.c
index 2c313a4..9e7192d 100644
--- a/src/ntp.c
+++ b/src/ntp.c
@@ -18,7 +18,6 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -34,6 +33,7 @@
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #include <arpa/inet.h>
+#include <netdb.h>
 
 #include <glib.h>
 
@@ -117,12 +117,12 @@ static struct timespec mtx_time;
 static int transmit_fd = 0;
 
 static char *timeserver = NULL;
-static struct sockaddr_in timeserver_addr;
+static struct sockaddr_in6 timeserver_addr;
 static gint poll_id = 0;
 static gint timeout_id = 0;
 static guint retries = 0;
 
-static void send_packet(int fd, const char *server, uint32_t timeout);
+static void send_packet(int fd, struct sockaddr *server, uint32_t timeout);
 
 static void next_server(void)
 {
@@ -143,17 +143,19 @@ static gboolean send_timeout(gpointer user_data)
        if (retries++ == NTP_SEND_RETRIES)
                next_server();
        else
-               send_packet(transmit_fd, timeserver, timeout << 1);
+               send_packet(transmit_fd, (struct sockaddr *)&timeserver_addr, 
timeout << 1);
 
        return FALSE;
 }
 
-static void send_packet(int fd, const char *server, uint32_t timeout)
+static void send_packet(int fd, struct sockaddr *server, uint32_t timeout)
 {
        struct ntp_msg msg;
-       struct sockaddr_in addr;
        struct timeval transmit_timeval;
        ssize_t len;
+       void * addr;
+       int size;
+       char ipaddrstring[INET6_ADDRSTRLEN + 1];
 
        /*
         * At some point, we could specify the actual system precision with:
@@ -168,10 +170,16 @@ static void send_packet(int fd, const char *server, 
uint32_t timeout)
        msg.poll = 10;  // max
        msg.precision = NTP_PRECISION_S;
 
-       memset(&addr, 0, sizeof(addr));
-       addr.sin_family = AF_INET;
-       addr.sin_port = htons(123);
-       addr.sin_addr.s_addr = inet_addr(server);
+       if (server->sa_family == AF_INET) {
+               size = sizeof(struct sockaddr_in);
+               addr = (void *)&(((struct sockaddr_in 
*)&timeserver_addr)->sin_addr);
+       } else if (server->sa_family == AF_INET6) {
+               size = sizeof(struct sockaddr_in6);
+               addr = (void *)&timeserver_addr.sin6_addr;
+       } else {
+               connman_error("Family is neither ipv4 nor ipv6");
+               return;
+       }
 
        gettimeofday(&transmit_timeval, NULL);
        clock_gettime(CLOCK_MONOTONIC, &mtx_time);
@@ -180,10 +188,12 @@ static void send_packet(int fd, const char *server, 
uint32_t timeout)
        msg.xmttime.fraction = htonl(transmit_timeval.tv_usec * 1000);
 
        len = sendto(fd, &msg, sizeof(msg), MSG_DONTWAIT,
-                                               &addr, sizeof(addr));
+                                               server, size);
+
        if (len < 0) {
                connman_error("Time request for server %s failed (%d/%s)",
-                       server, errno, strerror(errno));
+                       inet_ntop(server->sa_family, addr, ipaddrstring, 
sizeof(ipaddrstring)),
+                       errno, strerror(errno));
 
                if (errno == ENETUNREACH)
                        __connman_timeserver_sync_next();
@@ -192,7 +202,8 @@ static void send_packet(int fd, const char *server, 
uint32_t timeout)
        }
 
        if (len != sizeof(msg)) {
-               connman_error("Broken time request for server %s", server);
+               connman_error("Broken time request for server %s",
+                       inet_ntop(server->sa_family, addr, ipaddrstring, 
sizeof(ipaddrstring)));
                return;
        }
 
@@ -213,7 +224,7 @@ static gboolean next_poll(gpointer user_data)
        if (!timeserver || transmit_fd == 0)
                return FALSE;
 
-       send_packet(transmit_fd, timeserver, NTP_SEND_TIMEOUT);
+       send_packet(transmit_fd, (struct sockaddr *)&timeserver_addr, 
NTP_SEND_TIMEOUT);
 
        return FALSE;
 }
@@ -363,7 +374,7 @@ static gboolean received_data(GIOChannel *channel, 
GIOCondition condition,
                                                        gpointer user_data)
 {
        unsigned char buf[128];
-       struct sockaddr_in sender_addr;
+       struct sockaddr_in6 sender_addr;
        struct msghdr msg;
        struct iovec iov;
        struct cmsghdr *cmsg;
@@ -372,6 +383,9 @@ static gboolean received_data(GIOChannel *channel, 
GIOCondition condition,
        char aux[128];
        ssize_t len;
        int fd;
+       int size;
+       void * addr_ptr;
+       void * src_ptr;
 
        if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
                connman_error("Problem with timer server channel");
@@ -396,8 +410,20 @@ static gboolean received_data(GIOChannel *channel, 
GIOCondition condition,
        if (len < 0)
                return TRUE;
 
-       if (timeserver_addr.sin_addr.s_addr != sender_addr.sin_addr.s_addr)
-               /* only accept messages from the timeserver */
+       if (sender_addr.sin6_family == AF_INET) {
+               size = 4;
+               addr_ptr = &((struct sockaddr_in *)&timeserver_addr)->sin_addr;
+               src_ptr = &((struct sockaddr_in *)&sender_addr)->sin_addr;
+       } else if (sender_addr.sin6_family == AF_INET6) {
+               size = 16;
+               addr_ptr = &((struct sockaddr_in6 
*)&timeserver_addr)->sin6_addr;
+               src_ptr = &((struct sockaddr_in6 *)&sender_addr)->sin6_addr;
+       } else {
+               connman_error("Not a valid family type");
+               return TRUE;
+       }
+
+       if(memcmp(addr_ptr, src_ptr, size) != 0)
                return TRUE;
 
        tv = NULL;
@@ -422,36 +448,76 @@ static gboolean received_data(GIOChannel *channel, 
GIOCondition condition,
 static void start_ntp(char *server)
 {
        GIOChannel *channel;
-       struct sockaddr_in addr;
+       struct addrinfo hint;
+       struct addrinfo *info;
+       struct sockaddr * addr;
+       struct sockaddr_in  * in4addr;
+       struct sockaddr_in6 in6addr;
+       int size;
+       int family;
        int tos = IPTOS_LOWDELAY, timestamp = 1;
+       int ret;
 
        if (!server)
                return;
 
-       DBG("server %s", server);
+       memset(&hint, 0, sizeof(hint));
+       hint.ai_family = AF_UNSPEC;
+       hint.ai_socktype = SOCK_DGRAM;
+       hint.ai_flags = AI_NUMERICHOST | AI_PASSIVE;
+       ret = getaddrinfo(server, NULL, &hint, &info);
 
-       if (channel_watch > 0)
-               goto send;
+       if (ret) {
+               connman_error("cannot get server info");
+               return;
+       }
 
-       transmit_fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
-       if (transmit_fd < 0) {
-               connman_error("Failed to open time server socket");
+       family = info->ai_family;
+
+       memcpy(&timeserver_addr, info->ai_addr, info->ai_addrlen);
+       memset(&in6addr, 0, sizeof(in6addr));
+
+       if (family == AF_INET) {
+               ((struct sockaddr_in *)&timeserver_addr)->sin_port = htons(123);
+               in4addr = (struct sockaddr_in *)&in6addr;
+               in4addr->sin_family = family;
+               addr = (struct sockaddr *)in4addr;
+               size = sizeof(struct sockaddr_in);
+       } else if (family == AF_INET6) {
+               timeserver_addr.sin6_port = htons(123);
+               in6addr.sin6_family = family;
+               addr = (struct sockaddr *)&in6addr;
+               size = sizeof(in6addr);
+       } else {
+               connman_error("Family is neither ipv4 nor ipv6");
                return;
        }
+       freeaddrinfo(info);
+
+       DBG("server %s family %d", server, family);
+
+       if (channel_watch > 0)
+               goto send;
 
-       memset(&addr, 0, sizeof(addr));
-       addr.sin_family = AF_INET;
+       transmit_fd = socket(family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
 
-       if (bind(transmit_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+       if (transmit_fd <= 0) {
+                connman_error("Failed to open time server socket");
+                return;
+       }
+
+       if (bind(transmit_fd, (struct sockaddr *) addr, size) < 0) {
                connman_error("Failed to bind time server socket");
                close(transmit_fd);
                return;
        }
 
-       if (setsockopt(transmit_fd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) 
{
-               connman_error("Failed to set type of service option");
-               close(transmit_fd);
-               return;
+       if (family == AF_INET) {
+               if (setsockopt(transmit_fd, IPPROTO_IP, IP_TOS, &tos, 
sizeof(tos)) < 0) {
+                       connman_error("Failed to set type of service option");
+                       close(transmit_fd);
+                       return;
+               }
        }
 
        if (setsockopt(transmit_fd, SOL_SOCKET, SO_TIMESTAMP, &timestamp,
@@ -479,7 +545,7 @@ static void start_ntp(char *server)
        g_io_channel_unref(channel);
 
 send:
-       send_packet(transmit_fd, server, NTP_SEND_TIMEOUT);
+       send_packet(transmit_fd, (struct sockaddr*)&timeserver_addr, 
NTP_SEND_TIMEOUT);
 }
 
 int __connman_ntp_start(char *server)
@@ -493,7 +559,6 @@ int __connman_ntp_start(char *server)
                g_free(timeserver);
 
        timeserver = g_strdup(server);
-       timeserver_addr.sin_addr.s_addr = inet_addr(server);
 
        start_ntp(timeserver);
 
-- 
2.6.0.rc2.230.g3dd15c0



------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 1, Issue 4
*************************************

Reply via email to