connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Nicky Geerts <nicky.geerts@gmail.com>
To: connman@lists.linux.dev
Cc: Nicky Geerts <nicky.geerts@gmail.com>
Subject: [PATCH 2/2] timeserver: include the reason why a timeserver sync is requested
Date: Mon, 28 Feb 2022 13:49:30 +0100	[thread overview]
Message-ID: <20220228124930.4010311-3-nicky.geerts@gmail.com> (raw)
In-Reply-To: <20220228124930.4010311-1-nicky.geerts@gmail.com>

Except for the initial connman_timeserver_start call, and potential
updated of the default service, all subsequent calls to resynchronise
the timeserver are blocked because of the check whether service equals
ts_service in __connman_timeserver_sync.

DHCP updates, which could replace the timeserver and nameservers, and state
change updates are ignored.

As previously suggested by Daniel Wagner on Nov 19th 2019 in a mail to
Vivien Henriet, it would be best to pass the reason of the sync call,
and add the logic in __connman_timeserver_sync.

---
 include/timeserver.h |  7 +++++++
 src/connman.h        |  2 +-
 src/service.c        |  4 ++--
 src/timeserver.c     | 25 ++++++++++++++++++++-----
 4 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/include/timeserver.h b/include/timeserver.h
index 48ea1945..f1d6f1e8 100644
--- a/include/timeserver.h
+++ b/include/timeserver.h
@@ -26,6 +26,13 @@
 extern "C" {
 #endif
 
+enum connman_timeserver_sync_reason {
+    CONNMAN_TIMESERVER_SYNC_REASON_START = 0,
+    CONNMAN_TIMESERVER_SYNC_REASON_ADDRESS_UPDATE = 1,
+    CONNMAN_TIMESERVER_SYNC_REASON_STATE_UPDATE = 2,
+    CONNMAN_TIMESERVER_SYNC_REASON_TS_CHANGE = 3,
+};
+
 int __connman_timeserver_system_set(char **server);
 
 #ifdef __cplusplus
diff --git a/src/connman.h b/src/connman.h
index 33dbec69..0985cb11 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -451,7 +451,7 @@ char **__connman_timeserver_system_get();
 GSList *__connman_timeserver_add_list(GSList *server_list,
 		const char *timeserver);
 GSList *__connman_timeserver_get_all(struct connman_service *service);
-void __connman_timeserver_sync(struct connman_service *service);
+void __connman_timeserver_sync(struct connman_service *service, enum connman_timeserver_sync_reason reason);
 void __connman_timeserver_conf_update(struct connman_service *service);
 
 bool __connman_timeserver_is_synced(void);
diff --git a/src/service.c b/src/service.c
index f1abb963..52c4ee4c 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1476,7 +1476,7 @@ static void address_updated(struct connman_service *service,
 		nameserver_add_all(service, type);
 		start_online_check(service, type);
 
-		__connman_timeserver_sync(service);
+		__connman_timeserver_sync(service, CONNMAN_TIMESERVER_SYNC_REASON_ADDRESS_UPDATE);
 	}
 }
 
@@ -6504,7 +6504,7 @@ int __connman_service_ipconfig_indicate_state(struct connman_service *service,
 	if (!is_connected(old_state) && is_connected(new_state))
 		nameserver_add_all(service, type);
 
-	__connman_timeserver_sync(service);
+	__connman_timeserver_sync(service, CONNMAN_TIMESERVER_SYNC_REASON_STATE_UPDATE);
 
 	return service_indicate_state(service);
 }
diff --git a/src/timeserver.c b/src/timeserver.c
index 968739c3..3bae9074 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -309,7 +309,7 @@ static gboolean ts_recheck(gpointer user_data)
 		g_slist_free_full(ts, g_free);
 
 		service = connman_service_get_default();
-		__connman_timeserver_sync(service);
+		__connman_timeserver_sync(service, CONNMAN_TIMESERVER_SYNC_REASON_TS_CHANGE);
 
 		return FALSE;
 	}
@@ -430,12 +430,27 @@ static void ts_reset(struct connman_service *service)
 	timeserver_sync_start();
 }
 
-void __connman_timeserver_sync(struct connman_service *service)
+void __connman_timeserver_sync(struct connman_service *service, enum connman_timeserver_sync_reason reason)
 {
-	if (!service || ts_service == service)
+	if (!service)
 		return;
 
-	ts_reset(service);
+    switch (reason) {
+    case CONNMAN_TIMESERVER_SYNC_REASON_START:
+    case CONNMAN_TIMESERVER_SYNC_REASON_STATE_UPDATE:
+        if (ts_service == service)
+            return;
+        break;
+    case CONNMAN_TIMESERVER_SYNC_REASON_ADDRESS_UPDATE:
+    case CONNMAN_TIMESERVER_SYNC_REASON_TS_CHANGE:
+        if (ts_service != service)
+            return;
+        break;
+    default:
+        return;
+    }
+
+    ts_reset(service);
 }
 
 void __connman_timeserver_conf_update(struct connman_service *service)
@@ -480,7 +495,7 @@ static int timeserver_start(struct connman_service *service)
 
     ts_set_nameservers(service);
 
-	__connman_timeserver_sync(service);
+	__connman_timeserver_sync(service, CONNMAN_TIMESERVER_SYNC_REASON_START);
 
 	return 0;
 }
-- 
2.25.1


  parent reply	other threads:[~2022-02-28 12:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-28 12:49 [PATCH 0/2] timeserver not resolving ntp server Nicky Geerts
2022-02-28 12:49 ` [PATCH 1/2] timeserver: refresh the nameservers before each lookup Nicky Geerts
2022-02-28 12:49 ` Nicky Geerts [this message]
2022-03-04  8:56 ` [PATCH 0/2] timeserver not resolving ntp server Daniel Wagner
2022-03-07  8:44 ` [PATCH 1/2] timeserver: refresh the nameservers before each lookup Nicky Geerts
2022-03-07  9:19   ` Daniel Wagner
2022-03-07  8:44 ` [PATCH 2/2] timeserver: include the reason why a timeserver sync is requested Nicky Geerts
2022-03-07  9:20   ` Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220228124930.4010311-3-nicky.geerts@gmail.com \
    --to=nicky.geerts@gmail.com \
    --cc=connman@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).