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. [RFC v0] timeserver: Retry NTP servers periodically on
      startup (Daniel Wagner)
   2. Re: [RFC v0] timeserver: Retry NTP servers periodically on
      startup (Reverend Homer)
   3. Re: [RFC v0] timeserver: Retry NTP servers periodically on
      startup (Daniel Wagner)
   4. [PATCH 0/3] Add options to configure Online check
      (Christophe Ronco)
   5. [PATCH 1/3] main: add options to configure Online check
      (Christophe Ronco)
   6. [PATCH 2/3] wispr: implement options to configure Online
      check (Christophe Ronco)


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

Message: 1
Date: Sun, 29 Oct 2017 22:13:07 +0100
From: Daniel Wagner <[email protected]>
To: [email protected]
Cc: [email protected],  Daniel Wagner <[email protected]>
Subject: [RFC v0] timeserver: Retry NTP servers periodically on
        startup
Message-ID: <[email protected]>

When ConnMan starts up and we haven't connected to a timeserver, the
current algorithm will try all server once in the timer server list
and then stops. There is a recheck interval (7200 seconds) but that is
far too long if we no server has been selected so far. So we don't
find any server at startup we just retry in 5 seconds again.

The current code uses __timeserver_sync_next() to start the connection
attempt and also to select next server in the list when something goes
wrong. Therefore, __timeserver_sync_next() is called from ntp.c and
timeserver.c. Instead handing in the reason why
__timeserver_sync_next() is called we rather just add a new function
for starting the work timeserver_sync_start(). So we know, whenever
__timeserver_sync_next() something was amiss. When the timeserver list
is empty we program a timeout to which calls timeserver_sync_start().

The back off timeout is set hard to 5 seconds which could made into an
exponential value, though for a starting point let's try if this cures
the problem reported with Raspberry Pi boards which lacks a battery
buffered RTC.

Fixes CM-636
---
Hi,

This patch is tested only lightly. Propably there are still some
problems. So Kodi users with a Rasperry Pi and crapy router or uplink,
please give it a try if you can :)

Thanks,
Daniel


src/timeserver.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 73 insertions(+), 13 deletions(-)

diff --git a/src/timeserver.c b/src/timeserver.c
index 0e555a73c3bf..fa878949dfba 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -34,9 +34,11 @@
 
 #define TS_RECHECK_INTERVAL     7200
 
+static GSList *timeservers_list = NULL;
 static GSList *ts_list = NULL;
 static char *ts_current = NULL;
 static int ts_recheck_id = 0;
+static int ts_backoff_id = 0;
 
 static GResolv *resolv = NULL;
 static int resolv_id = 0;
@@ -114,13 +116,59 @@ static void resolv_result(GResolvResultStatus status, 
char **results,
 }
 
 /*
- * Once the timeserver list (ts_list) is created, we start querying the
- * servers one by one. If resolving fails on one of them, we move to the
- * next one. The user can enter either an IP address or a URL for the
- * timeserver. We only resolve the URLs. Once we have an IP for the NTP
- * server, we start querying it for time corrections.
+ * Once the timeserver list (timeserver_list) is created, we start
+ * querying the servers one by one. If resolving fails on one of them,
+ * we move to the next one. The user can enter either an IP address or
+ * a URL for the timeserver. We only resolve the URLs. Once we have an
+ * IP for the NTP server, we start querying it for time corrections.
  */
-void __connman_timeserver_sync_next()
+static void timeserver_sync_start(void)
+{
+       GSList *list;
+
+       for (list = timeservers_list; list; list = list->next) {
+               char *timeserver = list->data;
+
+               ts_list = g_slist_prepend(ts_list, g_strdup(timeserver));
+       }
+       ts_list = g_slist_reverse(ts_list);
+
+       ts_current = ts_list->data;
+
+       ts_list = g_slist_delete_link(ts_list, ts_list);
+
+       /* if it's an IP, directly query it. */
+       if (connman_inet_check_ipaddress(ts_current) > 0) {
+               DBG("Using timeserver %s", ts_current);
+
+               __connman_ntp_start(ts_current);
+
+               return;
+       }
+
+       DBG("Resolving timeserver %s", ts_current);
+
+       resolv_id = g_resolv_lookup_hostname(resolv, ts_current,
+                                               resolv_result, NULL);
+
+       return;
+}
+
+static gboolean timeserver_sync_restart(gpointer user_data)
+{
+       timeserver_sync_start();
+       ts_backoff_id = 0;
+
+       return FALSE;
+}
+
+/*
+ * Select the next time server from the working list (ts_list) because
+ * for some reason the first time server in the list didn't work. If
+ * none of the server did work we start over with the first server
+ * with a backoff.
+ */
+void __connman_timeserver_sync_next(void)
 {
        if (ts_current) {
                g_free(ts_current);
@@ -130,8 +178,13 @@ void __connman_timeserver_sync_next()
        __connman_ntp_stop();
 
        /* Get the 1st server in the list */
-       if (!ts_list)
+       if (!ts_list) {
+               DBG("No timeserver could be used, restart probing in 5 
seconds");
+
+               ts_backoff_id = g_timeout_add_seconds(5,
+                                       timeserver_sync_restart, NULL);
                return;
+       }
 
        ts_current = ts_list->data;
 
@@ -269,6 +322,11 @@ static void ts_recheck_disable(void)
        g_source_remove(ts_recheck_id);
        ts_recheck_id = 0;
 
+       if (ts_backoff_id) {
+               g_source_remove(ts_backoff_id);
+               ts_backoff_id = 0;
+       }
+
        if (ts_current) {
                g_free(ts_current);
                ts_current = NULL;
@@ -327,20 +385,20 @@ int __connman_timeserver_sync(struct connman_service 
*default_service)
 
        g_strfreev(nameservers);
 
-       g_slist_free_full(ts_list, g_free);
+       g_slist_free_full(timeservers_list, g_free);
 
-       ts_list = __connman_timeserver_get_all(service);
+       timeservers_list = __connman_timeserver_get_all(service);
 
-       __connman_service_timeserver_changed(service, ts_list);
+       __connman_service_timeserver_changed(service, timeservers_list);
 
-       if (!ts_list) {
+       if (!timeservers_list) {
                DBG("No timeservers set.");
                return 0;
        }
 
        ts_recheck_enable();
 
-       __connman_timeserver_sync_next();
+       timeserver_sync_start();
 
        return 0;
 }
@@ -396,8 +454,10 @@ static void timeserver_stop(void)
                resolv = NULL;
        }
 
-       g_slist_free_full(ts_list, g_free);
+       g_slist_free_full(timeservers_list, g_free);
+       timeservers_list = NULL;
 
+       g_slist_free_full(ts_list, g_free);
        ts_list = NULL;
 
        __connman_ntp_stop();
-- 
2.9.5


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

Message: 2
Date: Mon, 30 Oct 2017 13:30:04 +0300
From: Reverend Homer <[email protected]>
To: Daniel Wagner <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: [RFC v0] timeserver: Retry NTP servers periodically on
        startup
Message-ID: <[email protected]>
Content-Type: text/plain


Just a little nitpick

Daniel Wagner <[email protected]> writes:

> When ConnMan starts up and we haven't connected to a timeserver, the
> current algorithm will try all server once in the timer server list
> and then stops. There is a recheck interval (7200 seconds) but that is
> far too long if we no server has been selected so far. So we don't
> find any server at startup we just retry in 5 seconds again.
>
> The current code uses __timeserver_sync_next() to start the connection
> attempt and also to select next server in the list when something goes
> wrong. Therefore, __timeserver_sync_next() is called from ntp.c and
> timeserver.c. Instead handing in the reason why
> __timeserver_sync_next() is called we rather just add a new function
> for starting the work timeserver_sync_start(). So we know, whenever
> __timeserver_sync_next() something was amiss. When the timeserver list
> is empty we program a timeout to which calls timeserver_sync_start().
>
> The back off timeout is set hard to 5 seconds which could made into an
> exponential value, though for a starting point let's try if this cures
> the problem reported with Raspberry Pi boards which lacks a battery
> buffered RTC.
>
> Fixes CM-636
> ---
> Hi,
>
> This patch is tested only lightly. Propably there are still some
> problems. So Kodi users with a Rasperry Pi and crapy router or uplink,
> please give it a try if you can :)
>
> Thanks,
> Daniel
>
>
> src/timeserver.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 73 insertions(+), 13 deletions(-)
>
> diff --git a/src/timeserver.c b/src/timeserver.c
> index 0e555a73c3bf..fa878949dfba 100644
> --- a/src/timeserver.c
> +++ b/src/timeserver.c
> @@ -34,9 +34,11 @@
>  
>  #define TS_RECHECK_INTERVAL     7200
>  
> +static GSList *timeservers_list = NULL;
>  static GSList *ts_list = NULL;
>  static char *ts_current = NULL;
>  static int ts_recheck_id = 0;
> +static int ts_backoff_id = 0;
>  
>  static GResolv *resolv = NULL;
>  static int resolv_id = 0;
> @@ -114,13 +116,59 @@ static void resolv_result(GResolvResultStatus status, 
> char **results,
>  }
>  
>  /*
> - * Once the timeserver list (ts_list) is created, we start querying the
> - * servers one by one. If resolving fails on one of them, we move to the
> - * next one. The user can enter either an IP address or a URL for the
> - * timeserver. We only resolve the URLs. Once we have an IP for the NTP
> - * server, we start querying it for time corrections.
> + * Once the timeserver list (timeserver_list) is created, we start
> + * querying the servers one by one. If resolving fails on one of them,
> + * we move to the next one. The user can enter either an IP address or
> + * a URL for the timeserver. We only resolve the URLs. Once we have an
> + * IP for the NTP server, we start querying it for time corrections.
>   */
> -void __connman_timeserver_sync_next()
> +static void timeserver_sync_start(void)
> +{
> +     GSList *list;
> +
> +     for (list = timeservers_list; list; list = list->next) {
> +             char *timeserver = list->data;
> +
> +             ts_list = g_slist_prepend(ts_list, g_strdup(timeserver));
> +     }
> +     ts_list = g_slist_reverse(ts_list);
> +
> +     ts_current = ts_list->data;
> +
> +     ts_list = g_slist_delete_link(ts_list, ts_list);
> +
> +     /* if it's an IP, directly query it. */
> +     if (connman_inet_check_ipaddress(ts_current) > 0) {
> +             DBG("Using timeserver %s", ts_current);
> +
> +             __connman_ntp_start(ts_current);
> +
> +             return;
> +     }
> +
> +     DBG("Resolving timeserver %s", ts_current);
> +
> +     resolv_id = g_resolv_lookup_hostname(resolv, ts_current,
> +                                             resolv_result, NULL);
> +
> +     return;
You don't need "return;" here, do you?

> +}
> +
> +static gboolean timeserver_sync_restart(gpointer user_data)
> +{
> +     timeserver_sync_start();
> +     ts_backoff_id = 0;
> +
> +     return FALSE;
> +}
> +
> +/*
> + * Select the next time server from the working list (ts_list) because
> + * for some reason the first time server in the list didn't work. If
> + * none of the server did work we start over with the first server
> + * with a backoff.
> + */
> +void __connman_timeserver_sync_next(void)
>  {
>       if (ts_current) {
>               g_free(ts_current);
> @@ -130,8 +178,13 @@ void __connman_timeserver_sync_next()
>       __connman_ntp_stop();
>  
>       /* Get the 1st server in the list */
> -     if (!ts_list)
> +     if (!ts_list) {
> +             DBG("No timeserver could be used, restart probing in 5 
> seconds");
> +
> +             ts_backoff_id = g_timeout_add_seconds(5,
> +                                     timeserver_sync_restart, NULL);
>               return;
> +     }
>  
>       ts_current = ts_list->data;
>  
> @@ -269,6 +322,11 @@ static void ts_recheck_disable(void)
>       g_source_remove(ts_recheck_id);
>       ts_recheck_id = 0;
>  
> +     if (ts_backoff_id) {
> +             g_source_remove(ts_backoff_id);
> +             ts_backoff_id = 0;
> +     }
> +
>       if (ts_current) {
>               g_free(ts_current);
>               ts_current = NULL;
> @@ -327,20 +385,20 @@ int __connman_timeserver_sync(struct connman_service 
> *default_service)
>  
>       g_strfreev(nameservers);
>  
> -     g_slist_free_full(ts_list, g_free);
> +     g_slist_free_full(timeservers_list, g_free);
>  
> -     ts_list = __connman_timeserver_get_all(service);
> +     timeservers_list = __connman_timeserver_get_all(service);
>  
> -     __connman_service_timeserver_changed(service, ts_list);
> +     __connman_service_timeserver_changed(service, timeservers_list);
>  
> -     if (!ts_list) {
> +     if (!timeservers_list) {
>               DBG("No timeservers set.");
>               return 0;
>       }
>  
>       ts_recheck_enable();
>  
> -     __connman_timeserver_sync_next();
> +     timeserver_sync_start();
>  
>       return 0;
>  }
> @@ -396,8 +454,10 @@ static void timeserver_stop(void)
>               resolv = NULL;
>       }
>  
> -     g_slist_free_full(ts_list, g_free);
> +     g_slist_free_full(timeservers_list, g_free);
> +     timeservers_list = NULL;
>  
> +     g_slist_free_full(ts_list, g_free);
>       ts_list = NULL;
>  
>       __connman_ntp_stop();



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

Message: 3
Date: Mon, 30 Oct 2017 14:17:42 +0100
From: Daniel Wagner <[email protected]>
To: Reverend Homer <[email protected]>
Cc: [email protected], [email protected]
Subject: Re: [RFC v0] timeserver: Retry NTP servers periodically on
        startup
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

Hi,

On 10/30/2017 11:30 AM, Reverend Homer wrote:
> 
> Just a little nitpick
> 
>> +    resolv_id = g_resolv_lookup_hostname(resolv, ts_current,
>> +                                            resolv_result, NULL);
>> +
>> +    return;
> You don't need "return;" here, do you?

Nope, that is a copy & pasty :)

Thanks,
Daniel


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

Message: 4
Date: Mon, 30 Oct 2017 17:36:22 +0100
From: Christophe Ronco <[email protected]>
To: [email protected]
Subject: [PATCH 0/3] Add options to configure Online check
Message-ID: <[email protected]>

Hi,

I have added some options to configure URLs used to do the online check.
I have added to options to set the URLs for IPv4 and IPv6 and another option
to disable the check of X-ConnMan-Status HTTP header.

The goal is to have this feature for boards that do not have access to Internet.

Best Regards,

Christophe Ronco

Christophe Ronco (3):
  main: add options to configure Online check
  wispr: implement options to configure Online check
  main.conf: document options to configure Online check

 doc/connman.conf.5.in | 15 +++++++++++++++
 include/setting.h     |  1 +
 src/main.c            | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/main.conf         | 15 +++++++++++++++
 src/wispr.c           | 17 +++++++++++------
 5 files changed, 93 insertions(+), 7 deletions(-)

-- 
2.7.4



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

Message: 5
Date: Mon, 30 Oct 2017 17:36:23 +0100
From: Christophe Ronco <[email protected]>
To: [email protected]
Subject: [PATCH 1/3] main: add options to configure Online check
Message-ID: <[email protected]>

Add options to configure URL of HTTP servers.
Add option to say if we want to check connman specific header or not.
---
 include/setting.h |  1 +
 src/main.c        | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/include/setting.h b/include/setting.h
index a882021..3c87e77 100644
--- a/include/setting.h
+++ b/include/setting.h
@@ -29,6 +29,7 @@ extern "C" {
 #endif
 
 bool connman_setting_get_bool(const char *key);
+char *connman_setting_get_string(const char *key);
 char **connman_setting_get_string_list(const char *key);
 unsigned int *connman_setting_get_uint_list(const char *key);
 
diff --git a/src/main.c b/src/main.c
index 7b00eb3..c853d0f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -41,6 +41,8 @@
 
 #define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
 #define DEFAULT_BROWSER_LAUNCH_TIMEOUT (300 * 1000)
+#define DEFAULT_CONNMAN_SERVER_URL_IPV4 
"http://ipv4.connman.net/online/status.html";
+#define DEFAULT_CONNMAN_SERVER_URL_IPV6 
"http://ipv6.connman.net/online/status.html";
 
 #define MAINFILE "main.conf"
 #define CONFIGMAINFILE CONFIGDIR "/" MAINFILE
@@ -79,6 +81,9 @@ static struct {
        bool enable_6to4;
        char *vendor_class_id;
        bool enable_online_check;
+       bool online_check_use_connman_headers;
+       char *online_check_server_ipv4_url;
+       char *online_check_server_ipv6_url;
 } connman_settings  = {
        .bg_scan = true,
        .pref_timeservers = NULL,
@@ -96,6 +101,9 @@ static struct {
        .enable_6to4 = false,
        .vendor_class_id = NULL,
        .enable_online_check = true,
+       .online_check_use_connman_headers = true,
+       .online_check_server_ipv4_url = DEFAULT_CONNMAN_SERVER_URL_IPV4,
+       .online_check_server_ipv6_url = DEFAULT_CONNMAN_SERVER_URL_IPV6,
 };
 
 #define CONF_BG_SCAN                    "BackgroundScanning"
@@ -114,6 +122,9 @@ static struct {
 #define CONF_ENABLE_6TO4                "Enable6to4"
 #define CONF_VENDOR_CLASS_ID            "VendorClassID"
 #define CONF_ENABLE_ONLINE_CHECK        "EnableOnlineCheck"
+#define CONF_ONLINE_CHECK_USE_CONNMAN_HEADERS "OnlineCheckUseConnmanHeaders"
+#define CONF_ONLINE_CHECK_SERVER_IPV4_URL "OnlineCheckServerIpV4Url"
+#define CONF_ONLINE_CHECK_SERVER_IPV6_URL "OnlineCheckServerIpV6Url"
 
 static const char *supported_options[] = {
        CONF_BG_SCAN,
@@ -132,6 +143,9 @@ static const char *supported_options[] = {
        CONF_ENABLE_6TO4,
        CONF_VENDOR_CLASS_ID,
        CONF_ENABLE_ONLINE_CHECK,
+       CONF_ONLINE_CHECK_USE_CONNMAN_HEADERS,
+       CONF_ONLINE_CHECK_SERVER_IPV4_URL,
+       CONF_ONLINE_CHECK_SERVER_IPV6_URL,
        NULL
 };
 
@@ -254,7 +268,8 @@ static void parse_config(GKeyFile *config)
        char **interfaces;
        char **str_list;
        char **tethering;
-        char *vendor_class_id;
+       char *vendor_class_id;
+       char *url;
        gsize len;
        int timeout;
 
@@ -408,6 +423,27 @@ static void parse_config(GKeyFile *config)
        }
 
        g_clear_error(&error);
+
+       boolean = __connman_config_get_bool(config, "General",
+                               CONF_ONLINE_CHECK_USE_CONNMAN_HEADERS, &error);
+       if (!error)
+               connman_settings.online_check_use_connman_headers = boolean;
+
+       g_clear_error(&error);
+
+       url = __connman_config_get_string(config, "General",
+                               CONF_ONLINE_CHECK_SERVER_IPV4_URL, &error);
+       if (!error)
+               connman_settings.online_check_server_ipv4_url = url;
+
+       g_clear_error(&error);
+
+       url = __connman_config_get_string(config, "General",
+                               CONF_ONLINE_CHECK_SERVER_IPV6_URL, &error);
+       if (!error)
+               connman_settings.online_check_server_ipv6_url = url;
+
+       g_clear_error(&error);
 }
 
 static int config_init(const char *file)
@@ -615,9 +651,23 @@ bool connman_setting_get_bool(const char *key)
        if (g_str_equal(key, CONF_ENABLE_ONLINE_CHECK))
                return connman_settings.enable_online_check;
 
+       if (g_str_equal(key, CONF_ONLINE_CHECK_USE_CONNMAN_HEADERS))
+               return connman_settings.online_check_use_connman_headers;
+
        return false;
 }
 
+char *connman_setting_get_string(const char *key)
+{
+       if (g_str_equal(key, CONF_ONLINE_CHECK_SERVER_IPV4_URL))
+               return connman_settings.online_check_server_ipv4_url;
+
+       if (g_str_equal(key, CONF_ONLINE_CHECK_SERVER_IPV6_URL))
+               return connman_settings.online_check_server_ipv6_url;
+
+       return NULL;
+}
+
 char **connman_setting_get_string_list(const char *key)
 {
        if (g_str_equal(key, CONF_PREF_TIMESERVERS))
-- 
2.7.4



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

Message: 6
Date: Mon, 30 Oct 2017 17:36:24 +0100
From: Christophe Ronco <[email protected]>
To: [email protected]
Subject: [PATCH 2/3] wispr: implement options to configure Online
        check
Message-ID: <[email protected]>

Use URL of HTTP servers from configuration.
Use OnlineCheckUseConnmanHeaders configuration option to see if connman
specific headers are needed or not to go to Online state.
---
 src/wispr.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/wispr.c b/src/wispr.c
index 03b38bb..e280049 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -28,10 +28,9 @@
 
 #include <gweb/gweb.h>
 
-#include "connman.h"
+#include <connman/setting.h>
 
-#define STATUS_URL_IPV4  "http://ipv4.connman.net/online/status.html";
-#define STATUS_URL_IPV6  "http://ipv6.connman.net/online/status.html";
+#include "connman.h"
 
 struct connman_wispr_message {
        bool has_error;
@@ -688,6 +687,7 @@ static bool wispr_portal_web_result(GWebResult *result, 
gpointer user_data)
        const char *str = NULL;
        guint16 status;
        gsize length;
+       bool checkForConnmanHeader;
 
        DBG("");
 
@@ -722,7 +722,10 @@ static bool wispr_portal_web_result(GWebResult *result, 
gpointer user_data)
                if (wp_context->wispr_msg.message_type >= 0)
                        break;
 
-               if (g_web_result_get_header(result, "X-ConnMan-Status",
+               checkForConnmanHeader = connman_setting_get_bool(
+                                               "OnlineCheckUseConnmanHeaders");
+               if (!checkForConnmanHeader ||
+                       g_web_result_get_header(result, "X-ConnMan-Status",
                                                &str)) {
                        portal_manage_status(result, wp_context);
                        return false;
@@ -884,10 +887,12 @@ static int wispr_portal_detect(struct 
connman_wispr_portal_context *wp_context)
 
        if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
                g_web_set_address_family(wp_context->web, AF_INET);
-               wp_context->status_url = STATUS_URL_IPV4;
+               wp_context->status_url = connman_setting_get_string(
+                                               "OnlineCheckServerIpV4Url");
        } else {
                g_web_set_address_family(wp_context->web, AF_INET6);
-               wp_context->status_url = STATUS_URL_IPV6;
+               wp_context->status_url = connman_setting_get_string(
+                                               "OnlineCheckServerIpV6Url");
        }
 
        for (i = 0; nameservers[i]; i++)
-- 
2.7.4



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

Subject: Digest Footer

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


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

End of connman Digest, Vol 24, Issue 31
***************************************

Reply via email to