add NTP time synchronization module
This commit is contained in:
1 parent
f3719a28df
commit
1a0229fd4f
8 files changed
+385
-2
No files matched your search
+25
-1
@@ -48,7 +48,8 @@ typedef enum {
|
||||
SECTION_TCP_PROXY_CLIENT,
|
||||
SECTION_TCP_PROXY_SERVER,
|
||||
SECTION_MSG_TRANSPORT,
|
||||
SECTION_NETWORK
|
||||
SECTION_NETWORK,
|
||||
SECTION_NTP
|
||||
} section_type_t;
|
||||
|
||||
static char* trim(char *str) {
|
||||
@@ -763,6 +764,7 @@ static section_type_t parse_section_header(const char *line, char *name, size_t
|
||||
if (strcasecmp(section, "tcp_proxy_client") == 0) return SECTION_TCP_PROXY_CLIENT;
|
||||
if (strcasecmp(section, "tcp_proxy_server") == 0) return SECTION_TCP_PROXY_SERVER;
|
||||
if (strcasecmp(section, "msg_transport") == 0) return SECTION_MSG_TRANSPORT;
|
||||
if (strcasecmp(section, "ntp") == 0) return SECTION_NTP;
|
||||
|
||||
char *colon = strchr(section, ':');
|
||||
if (!colon) return SECTION_UNKNOWN;
|
||||
@@ -802,6 +804,9 @@ static struct utun_config* parse_config_internal(FILE *fp, const char *filename)
|
||||
cfg->global.control_allow_count = 0;
|
||||
cfg->global.db_sync_enabled = 0;
|
||||
cfg->global.db_sync_ttl = 86400;
|
||||
cfg->global.ntp_enabled = 0;
|
||||
cfg->global.ntp_server_count = 0;
|
||||
cfg->global.ntp_resync_interval = 3600;
|
||||
|
||||
section_type_t cur_section = SECTION_UNKNOWN;
|
||||
struct CFG_SERVER *cur_server = NULL;
|
||||
@@ -972,6 +977,25 @@ static struct utun_config* parse_config_internal(FILE *fp, const char *filename)
|
||||
// parse_network already printed the error
|
||||
}
|
||||
break;
|
||||
case SECTION_NTP:
|
||||
if (strcmp(key, "enabled") == 0) {
|
||||
cfg->global.ntp_enabled = strcasecmp(value, "yes") == 0 || strcasecmp(value, "1") == 0 || strcasecmp(value, "true") == 0;
|
||||
} else if (strcmp(key, "server") == 0) {
|
||||
if (cfg->global.ntp_server_count >= 5) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Too many NTP servers (max 5)", filename, line_num);
|
||||
} else {
|
||||
int idx = cfg->global.ntp_server_count;
|
||||
strncpy(cfg->global.ntp_servers[idx], value, sizeof(cfg->global.ntp_servers[idx]) - 1);
|
||||
cfg->global.ntp_servers[idx][sizeof(cfg->global.ntp_servers[idx]) - 1] = '\0';
|
||||
cfg->global.ntp_server_count++;
|
||||
}
|
||||
} else if (strcmp(key, "interval") == 0) {
|
||||
cfg->global.ntp_resync_interval = atoi(value);
|
||||
if (cfg->global.ntp_resync_interval < 60) cfg->global.ntp_resync_interval = 60;
|
||||
} else {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "%s:%d: Unknown ntp option '%s'. Valid: enabled, server, interval", filename, line_num, key);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CONFIG, "%s:%d: Key outside section: %s", filename, line_num, key);
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user