connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] timeserver: Add EnableNTPClient option to connman.conf
@ 2022-04-14  0:12 Jakub Jirutka
  2022-04-14 19:05 ` Daniel Wagner
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jirutka @ 2022-04-14  0:12 UTC (permalink / raw)
  To: connman; +Cc: Jakub Jirutka

The builtin NTP client can now only be disabled via DBus or manually
editing the state file /var/lib/connman/settings
(`TimeUpdates = "manual"`). These options are not optimal for a setup
where a standalone NTP client is used.

The approach for disabling NTP client (in timeserver.c) is based on the
existing code for handling state setting `TimeUpdates = "manual"`.

I originally wanted to implement this using CLI option, just
like --nodnsproxy, but after reading the message from Daniel Wagner
on ML (Unification to connman configuration? Now it 3 separated places)
regarding --nodnsproxy, I concluded that the config file is preferred.
---
 doc/connman.conf.5.in |  4 ++++
 src/main.c            | 12 ++++++++++++
 src/timeserver.c      |  3 +++
 3 files changed, 19 insertions(+)

diff --git a/doc/connman.conf.5.in b/doc/connman.conf.5.in
index cb36e9fb..9c25cf9d 100644
--- a/doc/connman.conf.5.in
+++ b/doc/connman.conf.5.in
@@ -52,6 +52,10 @@ When BackgroundScanning is false, ConnMan will not perform any scan
 regardless of wifi is connected or not, unless it is requested by
 the user through a D-Bus call.
 .TP
+.BI EnableNTPClient=true \fR|\fB\ false
+Enable or disable the builtin NTP client.
+Default is true.
+.TP
 .BI UseGatewaysAsTimeservers=true \fR|\fB\ false
 Assume that service gateways also function as timeservers.
 Default is false.
diff --git a/src/main.c b/src/main.c
index 5c632fd1..f2fc073b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -110,6 +110,7 @@ static struct {
 	bool use_gateways_as_timeservers;
 	char *localtime;
 	bool regdom_follows_timezone;
+	bool enable_ntp_client;
 } connman_settings  = {
 	.bg_scan = true,
 	.pref_timeservers = NULL,
@@ -138,6 +139,7 @@ static struct {
 	.acd = false,
 	.use_gateways_as_timeservers = false,
 	.localtime = NULL,
+	.enable_ntp_client = true,
 };
 
 #define CONF_BG_SCAN                    "BackgroundScanning"
@@ -168,6 +170,7 @@ static struct {
 #define CONF_USE_GATEWAYS_AS_TIMESERVERS "UseGatewaysAsTimeservers"
 #define CONF_LOCALTIME                  "Localtime"
 #define CONF_REGDOM_FOLLOWS_TIMEZONE    "RegdomFollowsTimezone"
+#define CONF_ENABLE_NTP_CLIENT          "EnableNTPClient"
 
 static const char *supported_options[] = {
 	CONF_BG_SCAN,
@@ -198,6 +201,7 @@ static const char *supported_options[] = {
 	CONF_USE_GATEWAYS_AS_TIMESERVERS,
 	CONF_LOCALTIME,
 	CONF_REGDOM_FOLLOWS_TIMEZONE,
+	CONF_ENABLE_NTP_CLIENT,
 	NULL
 };
 
@@ -594,6 +598,11 @@ static void parse_config(GKeyFile *config)
 	if (!error)
 		connman_settings.regdom_follows_timezone = boolean;
 
+	boolean = __connman_config_get_bool(config, "General",
+				CONF_ENABLE_NTP_CLIENT, &error);
+	if (!error)
+		connman_settings.enable_ntp_client = boolean;
+
 	g_clear_error(&error);
 }
 
@@ -830,6 +839,9 @@ bool connman_setting_get_bool(const char *key)
 	if (g_str_equal(key, CONF_REGDOM_FOLLOWS_TIMEZONE))
 		return connman_settings.regdom_follows_timezone;
 
+	if (g_str_equal(key, CONF_ENABLE_NTP_CLIENT))
+		return connman_settings.enable_ntp_client;
+
 	return false;
 }
 
diff --git a/src/timeserver.c b/src/timeserver.c
index 4c25d4b8..4be954b2 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -240,6 +240,9 @@ GSList *__connman_timeserver_get_all(struct connman_service *service)
 	char **fallback_ts;
 	int index, i;
 
+	if (!connman_setting_get_bool("EnableNTPClient"))
+		return NULL;
+
 	if (__connman_clock_timeupdates() == TIME_UPDATES_MANUAL)
 		return NULL;
 
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] timeserver: Add EnableNTPClient option to connman.conf
  2022-04-14  0:12 [PATCH] timeserver: Add EnableNTPClient option to connman.conf Jakub Jirutka
@ 2022-04-14 19:05 ` Daniel Wagner
  2022-04-15 22:51   ` Jakub Jirutka
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Wagner @ 2022-04-14 19:05 UTC (permalink / raw)
  To: Jakub Jirutka; +Cc: connman

Hi Jakub,

On Thu, Apr 14, 2022 at 02:12:08AM +0200, Jakub Jirutka wrote:
> The builtin NTP client can now only be disabled via DBus or manually
> editing the state file /var/lib/connman/settings
> (`TimeUpdates = "manual"`). These options are not optimal for a setup
> where a standalone NTP client is used.
> 
> The approach for disabling NTP client (in timeserver.c) is based on the
> existing code for handling state setting `TimeUpdates = "manual"`.
> 
> I originally wanted to implement this using CLI option, just
> like --nodnsproxy, but after reading the message from Daniel Wagner
> on ML (Unification to connman configuration? Now it 3 separated places)
> regarding --nodnsproxy, I concluded that the config file is preferred.

I am not against the idea to have the default configurable via the
config file, but please make just the default behavior so that the D-Bus
API still works (unless I read your patch wrong).

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] timeserver: Add EnableNTPClient option to connman.conf
  2022-04-14 19:05 ` Daniel Wagner
@ 2022-04-15 22:51   ` Jakub Jirutka
  2022-05-16  6:47     ` Daniel Wagner
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jirutka @ 2022-04-15 22:51 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: connman


[-- Attachment #1.1.1: Type: text/plain, Size: 1768 bytes --]

Hi Daniel,

On 14/04/22 21:05, Daniel Wagner wrote:
> Hi Jakub,
> 
> On Thu, Apr 14, 2022 at 02:12:08AM +0200, Jakub Jirutka wrote:
>> The builtin NTP client can now only be disabled via DBus or manually
>> editing the state file /var/lib/connman/settings
>> (`TimeUpdates = "manual"`). These options are not optimal for a setup
>> where a standalone NTP client is used.
>>
>> The approach for disabling NTP client (in timeserver.c) is based on the
>> existing code for handling state setting `TimeUpdates = "manual"`.
>>
>> I originally wanted to implement this using CLI option, just
>> like --nodnsproxy, but after reading the message from Daniel Wagner
>> on ML (Unification to connman configuration? Now it 3 separated places)
>> regarding --nodnsproxy, I concluded that the config file is preferred.
> 
> I am not against the idea to have the default configurable via the
> config file, but please make just the default behavior so that the D-Bus
> API still works (unless I read your patch wrong).

Do you mean that it should be possible to enable the NTP client via 
D-Bus even if it’s disabled in the config? This would introduce, in my 
opinion, a quite unexpected behaviour; it would mean that:
1. the state settings (controlled via D-Bus) have higher priority than 
the config file;
2. once the NTP client is enabled via D-Bus, it cannot be disabled via 
the config file.

I think that it should be just the opposite – if the user set 
EnableNTPClient=false in the config, the NTP client should be completely 
disabled, analogous to the --nodnsproxy option. Now that I think about 
it, I should probably also update net.connman.Clock to correctly report 
TimeUpdates=manual when the NTP client is disabled.

Jakub

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 5275 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] timeserver: Add EnableNTPClient option to connman.conf
  2022-04-15 22:51   ` Jakub Jirutka
@ 2022-05-16  6:47     ` Daniel Wagner
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Wagner @ 2022-05-16  6:47 UTC (permalink / raw)
  To: Jakub Jirutka; +Cc: connman

Hi Jakub

On Sat, Apr 16, 2022 at 12:51:09AM +0200, Jakub Jirutka wrote:
> On 14/04/22 21:05, Daniel Wagner wrote:
> > On Thu, Apr 14, 2022 at 02:12:08AM +0200, Jakub Jirutka wrote:
> > > The builtin NTP client can now only be disabled via DBus or manually
> > > editing the state file /var/lib/connman/settings
> > > (`TimeUpdates = "manual"`). These options are not optimal for a setup
> > > where a standalone NTP client is used.
> > > 
> > > The approach for disabling NTP client (in timeserver.c) is based on the
> > > existing code for handling state setting `TimeUpdates = "manual"`.
> > > 
> > > I originally wanted to implement this using CLI option, just
> > > like --nodnsproxy, but after reading the message from Daniel Wagner
> > > on ML (Unification to connman configuration? Now it 3 separated places)
> > > regarding --nodnsproxy, I concluded that the config file is preferred.
> > 
> > I am not against the idea to have the default configurable via the
> > config file, but please make just the default behavior so that the D-Bus
> > API still works (unless I read your patch wrong).
> 
> Do you mean that it should be possible to enable the NTP client via D-Bus
> even if it’s disabled in the config? This would introduce, in my opinion, a
> quite unexpected behaviour; it would mean that:
> 1. the state settings (controlled via D-Bus) have higher priority than the
> config file;
> 2. once the NTP client is enabled via D-Bus, it cannot be disabled via the
> config file.

Yes, that is what I meant. One of the reason why we have this kind of
messy configuration situation is that we tried hard to avoiding to add
options to conf file and only have the D-Bus API. As it turns out this
didn't age too well. This is why I think the D-Bus should have
preference over the static configuration as this is/was the primary way
to configure the system.

> I think that it should be just the opposite – if the user set
> EnableNTPClient=false in the config, the NTP client should be completely
> disabled, analogous to the --nodnsproxy option.

The dnsproxy setting doesn't have a corresponding D-Bus API.

> Now that I think about it, I
> should probably also update net.connman.Clock to correctly report
> TimeUpdates=manual when the NTP client is disabled.

:)

Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-16  6:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14  0:12 [PATCH] timeserver: Add EnableNTPClient option to connman.conf Jakub Jirutka
2022-04-14 19:05 ` Daniel Wagner
2022-04-15 22:51   ` Jakub Jirutka
2022-05-16  6:47     ` Daniel Wagner

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).