summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-ntp.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-04-16 03:13:14 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-04-19 03:23:00 +0200
commitd12fb2bc7b088f990e4ef0dc2f35a55adbc8f009 (patch)
tree61ea414e0a1a529c779c0c75747f9be06d957b9d /src/network/networkd-ntp.c
parentnetwork: move NTP related conf parsers to networkd-ntp.[ch] (diff)
downloadsystemd-d12fb2bc7b088f990e4ef0dc2f35a55adbc8f009.tar.xz
systemd-d12fb2bc7b088f990e4ef0dc2f35a55adbc8f009.zip
network: introduce link_get_use_ntp()
No functional change, just refactoring.
Diffstat (limited to 'src/network/networkd-ntp.c')
-rw-r--r--src/network/networkd-ntp.c84
1 files changed, 33 insertions, 51 deletions
diff --git a/src/network/networkd-ntp.c b/src/network/networkd-ntp.c
index 38e0ee547a..e764feacb9 100644
--- a/src/network/networkd-ntp.c
+++ b/src/network/networkd-ntp.c
@@ -9,6 +9,39 @@
/* Let's assume that anything above this number is a user misconfiguration. */
#define MAX_NTP_SERVERS 128U
+bool link_get_use_ntp(Link *link, NetworkConfigSource proto) {
+ int n, c;
+
+ assert(link);
+
+ if (!link->network)
+ return false;
+
+ switch (proto) {
+ case NETWORK_CONFIG_SOURCE_DHCP4:
+ n = link->network->dhcp_use_ntp;
+ c = link->network->compat_dhcp_use_ntp;
+ break;
+ case NETWORK_CONFIG_SOURCE_DHCP6:
+ n = link->network->dhcp6_use_ntp;
+ c = link->network->compat_dhcp_use_ntp;
+ break;
+ default:
+ assert_not_reached();
+ }
+
+ /* If per-network and per-protocol setting is specified, use it. */
+ if (n >= 0)
+ return n;
+
+ /* If compat setting is specified, use it. */
+ if (c >= 0)
+ return c;
+
+ /* Otherwise, defaults to yes. */
+ return true;
+}
+
int config_parse_ntp(
const char *unit,
const char *filename,
@@ -66,54 +99,3 @@ int config_parse_ntp(
return log_oom();
}
}
-
-int config_parse_dhcp_use_ntp(
- const char* unit,
- const char *filename,
- unsigned line,
- const char *section,
- unsigned section_line,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- Network *network = userdata;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
- assert(rvalue);
- assert(data);
-
- r = parse_boolean(rvalue);
- if (r < 0) {
- log_syntax(unit, LOG_WARNING, filename, line, r,
- "Failed to parse UseNTP=%s, ignoring assignment: %m", rvalue);
- return 0;
- }
-
- switch (ltype) {
- case AF_INET:
- network->dhcp_use_ntp = r;
- network->dhcp_use_ntp_set = true;
- break;
- case AF_INET6:
- network->dhcp6_use_ntp = r;
- network->dhcp6_use_ntp_set = true;
- break;
- case AF_UNSPEC:
- /* For backward compatibility. */
- if (!network->dhcp_use_ntp_set)
- network->dhcp_use_ntp = r;
- if (!network->dhcp6_use_ntp_set)
- network->dhcp6_use_ntp = r;
- break;
- default:
- assert_not_reached();
- }
-
- return 0;
-}