2011-12-31 16:14:18 +08:00
|
|
|
/**
|
|
|
|
* @file config.c
|
|
|
|
* @note Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-06-10 15:16:26 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include <limits.h>
|
2011-12-31 16:14:18 +08:00
|
|
|
#include <stdio.h>
|
2014-08-14 21:56:06 +08:00
|
|
|
#include <stdlib.h>
|
2011-12-31 16:14:18 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include "config.h"
|
2012-07-27 17:30:22 +08:00
|
|
|
#include "ether.h"
|
2012-08-21 01:56:56 +08:00
|
|
|
#include "print.h"
|
2013-02-04 06:01:52 +08:00
|
|
|
#include "util.h"
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-08-21 07:03:26 +08:00
|
|
|
enum config_section {
|
|
|
|
GLOBAL_SECTION,
|
2012-08-21 01:57:27 +08:00
|
|
|
PORT_SECTION,
|
2012-08-21 07:03:26 +08:00
|
|
|
UNKNOWN_SECTION,
|
|
|
|
};
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
static enum parser_result parse_section_line(char *s, enum config_section *section)
|
2012-08-21 07:03:26 +08:00
|
|
|
{
|
2012-11-08 01:20:29 +08:00
|
|
|
if (!strcasecmp(s, "[global]")) {
|
2012-08-21 07:03:26 +08:00
|
|
|
*section = GLOBAL_SECTION;
|
|
|
|
} else if (s[0] == '[') {
|
2012-08-21 01:57:27 +08:00
|
|
|
char c;
|
|
|
|
*section = PORT_SECTION;
|
|
|
|
/* Replace square brackets with white space. */
|
|
|
|
while (0 != (c = *s)) {
|
|
|
|
if (c == '[' || c == ']')
|
|
|
|
*s = ' ';
|
|
|
|
s++;
|
|
|
|
}
|
2012-11-08 01:20:29 +08:00
|
|
|
} else
|
|
|
|
return NOT_PARSED;
|
|
|
|
return PARSED_OK;
|
2012-08-21 07:03:26 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
static enum parser_result parse_pod_setting(const char *option,
|
|
|
|
const char *value,
|
|
|
|
struct port_defaults *pod)
|
2012-08-21 01:57:06 +08:00
|
|
|
{
|
|
|
|
int val;
|
2013-06-10 15:16:26 +08:00
|
|
|
unsigned int uval;
|
|
|
|
|
|
|
|
enum parser_result r;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2012-12-10 21:39:08 +08:00
|
|
|
if (!strcmp(option, "delayAsymmetry")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-12-10 21:39:08 +08:00
|
|
|
pod->asymmetry = (Integer64) val << 16;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "logAnnounceInterval")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->logAnnounceInterval = val;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "logSyncInterval")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->logSyncInterval = val;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "logMinDelayReqInterval")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->logMinDelayReqInterval = val;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "logMinPdelayReqInterval")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->logMinPdelayReqInterval = val;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "announceReceiptTimeout")) {
|
2013-08-26 19:31:03 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 2, UINT8_MAX);
|
2013-06-10 15:16:26 +08:00
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->announceReceiptTimeout = uval;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2013-08-26 20:36:49 +08:00
|
|
|
} else if (!strcmp(option, "syncReceiptTimeout")) {
|
|
|
|
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->syncReceiptTimeout = uval;
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "transportSpecific")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, 0x0F);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->transportSpecific = uval << 4;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "path_trace_enabled")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->path_trace_enabled = val;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "follow_up_info")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->follow_up_info = val;
|
2012-08-21 01:57:06 +08:00
|
|
|
|
2013-03-14 03:16:59 +08:00
|
|
|
} else if (!strcmp(option, "neighborPropDelayThresh")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, UINT32_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->neighborPropDelayThresh = uval;
|
2013-03-14 03:16:59 +08:00
|
|
|
|
2014-02-22 01:18:08 +08:00
|
|
|
} else if (!strcmp(option, "min_neighbor_prop_delay")) {
|
|
|
|
r = get_ranged_int(value, &val, INT_MIN, -1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->min_neighbor_prop_delay = val;
|
|
|
|
|
2014-12-07 05:14:28 +08:00
|
|
|
} else if (!strcmp(option, "egressLatency")) {
|
|
|
|
r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->tx_timestamp_offset = val;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "ingressLatency")) {
|
|
|
|
r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->rx_timestamp_offset = val;
|
|
|
|
|
2013-03-19 00:08:22 +08:00
|
|
|
} else if (!strcmp(option, "fault_badpeernet_interval")) {
|
|
|
|
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].type = FTMO_LINEAR_SECONDS;
|
|
|
|
if (!strcasecmp("ASAP", value)) {
|
|
|
|
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].val = 0;
|
|
|
|
} else {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT32_MIN, INT32_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->flt_interval_pertype[FT_BAD_PEER_NETWORK].val = val;
|
2013-03-19 00:08:22 +08:00
|
|
|
}
|
|
|
|
|
2013-01-30 23:28:54 +08:00
|
|
|
} else if (!strcmp(option, "fault_reset_interval")) {
|
2013-03-19 00:08:21 +08:00
|
|
|
pod->flt_interval_pertype[FT_UNSPECIFIED].type = FTMO_LOG2_SECONDS;
|
2013-01-30 23:28:54 +08:00
|
|
|
if (!strcasecmp("ASAP", value)) {
|
2013-03-19 00:08:21 +08:00
|
|
|
pod->flt_interval_pertype[FT_UNSPECIFIED].val = FRI_ASAP;
|
2013-01-30 23:28:54 +08:00
|
|
|
} else {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT8_MIN, INT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
pod->flt_interval_pertype[FT_UNSPECIFIED].val = val;
|
2013-01-30 23:28:54 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else
|
|
|
|
return NOT_PARSED;
|
|
|
|
|
|
|
|
return PARSED_OK;
|
2012-08-21 01:57:06 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
static enum parser_result parse_port_setting(const char *option,
|
|
|
|
const char *value,
|
2014-08-14 21:56:06 +08:00
|
|
|
struct interface *iface)
|
2012-08-21 01:57:27 +08:00
|
|
|
{
|
2012-11-08 01:20:29 +08:00
|
|
|
enum parser_result r;
|
2013-10-29 18:58:20 +08:00
|
|
|
int val;
|
2012-08-21 01:57:27 +08:00
|
|
|
|
2014-08-14 21:56:06 +08:00
|
|
|
r = parse_pod_setting(option, value, &iface->pod);
|
2012-11-08 01:20:29 +08:00
|
|
|
if (r != NOT_PARSED)
|
|
|
|
return r;
|
2012-08-21 01:57:27 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
if (!strcmp(option, "network_transport")) {
|
|
|
|
if (!strcasecmp("L2", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->transport = TRANS_IEEE_802_3;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (!strcasecmp("UDPv4", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->transport = TRANS_UDP_IPV4;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (!strcasecmp("UDPv6", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->transport = TRANS_UDP_IPV6;
|
2012-11-08 01:20:29 +08:00
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
2012-08-21 01:57:27 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "delay_mechanism")) {
|
|
|
|
if (!strcasecmp("Auto", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->dm = DM_AUTO;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (!strcasecmp("E2E", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->dm = DM_E2E;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (!strcasecmp("P2P", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->dm = DM_P2P;
|
2012-11-08 01:20:29 +08:00
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
2013-10-29 18:58:20 +08:00
|
|
|
|
2015-03-26 23:32:14 +08:00
|
|
|
} else if (!strcmp(option, "tsproc_mode")) {
|
|
|
|
if (!strcasecmp("filter", value))
|
|
|
|
iface->tsproc_mode = TSPROC_FILTER;
|
|
|
|
else if (!strcasecmp("raw", value))
|
|
|
|
iface->tsproc_mode = TSPROC_RAW;
|
|
|
|
else if (!strcasecmp("filter_weight", value))
|
|
|
|
iface->tsproc_mode = TSPROC_FILTER_WEIGHT;
|
|
|
|
else if (!strcasecmp("raw_weight", value))
|
|
|
|
iface->tsproc_mode = TSPROC_RAW_WEIGHT;
|
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
2013-10-29 18:58:20 +08:00
|
|
|
} else if (!strcmp(option, "delay_filter")) {
|
|
|
|
if (!strcasecmp("moving_average", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->delay_filter = FILTER_MOVING_AVERAGE;
|
2013-10-29 18:58:20 +08:00
|
|
|
else if (!strcasecmp("moving_median", value))
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->delay_filter = FILTER_MOVING_MEDIAN;
|
2013-10-29 18:58:20 +08:00
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "delay_filter_length")) {
|
|
|
|
r = get_ranged_int(value, &val, 1, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2014-08-14 21:56:06 +08:00
|
|
|
iface->delay_filter_length = val;
|
2013-10-29 18:58:20 +08:00
|
|
|
|
2014-11-02 01:59:13 +08:00
|
|
|
} else if (!strcmp(option, "boundary_clock_jbod")) {
|
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
iface->boundary_clock_jbod = val;
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else
|
|
|
|
return NOT_PARSED;
|
2012-08-21 01:57:27 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
return PARSED_OK;
|
2012-08-21 01:57:27 +08:00
|
|
|
}
|
|
|
|
|
2013-02-04 06:01:52 +08:00
|
|
|
static int count_char(const char *str, char c)
|
|
|
|
{
|
|
|
|
int num = 0;
|
|
|
|
char s;
|
|
|
|
while ((s = *(str++))) {
|
|
|
|
if (s == c)
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
static enum parser_result parse_global_setting(const char *option,
|
|
|
|
const char *value,
|
|
|
|
struct config *cfg)
|
2011-12-31 16:14:18 +08:00
|
|
|
{
|
2012-05-03 17:17:34 +08:00
|
|
|
double df;
|
2012-08-21 01:57:01 +08:00
|
|
|
int i, val, cfg_ignore = cfg->cfg_ignore;
|
2013-06-10 15:16:26 +08:00
|
|
|
unsigned int uval;
|
2012-07-27 17:30:22 +08:00
|
|
|
unsigned char mac[MAC_LEN];
|
2013-02-04 06:01:52 +08:00
|
|
|
unsigned char oui[OUI_LEN];
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-12-01 04:52:37 +08:00
|
|
|
struct defaultDS *dds = &cfg->dds.dds;
|
2012-08-21 01:56:29 +08:00
|
|
|
struct port_defaults *pod = &cfg->pod;
|
2012-03-21 03:09:40 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
enum parser_result r;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
r = parse_pod_setting(option, value, pod);
|
|
|
|
if (r != NOT_PARSED)
|
|
|
|
return r;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
if (!strcmp(option, "twoStepFlag")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-12-01 04:52:37 +08:00
|
|
|
if (val)
|
|
|
|
dds->flags |= DDS_TWO_STEP_FLAG;
|
|
|
|
else
|
|
|
|
dds->flags &= ~DDS_TWO_STEP_FLAG;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "slaveOnly")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-12-01 04:52:37 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY)) {
|
|
|
|
if (val)
|
|
|
|
dds->flags |= DDS_SLAVE_ONLY;
|
|
|
|
else
|
|
|
|
dds->flags &= ~DDS_SLAVE_ONLY;
|
|
|
|
}
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2013-12-02 03:50:34 +08:00
|
|
|
} else if (!strcmp(option, "gmCapable")) {
|
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
cfg->dds.grand_master_capable = val;
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "priority1")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
dds->priority1 = uval;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "priority2")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
dds->priority2 = uval;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "domainNumber")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, 127);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
dds->domainNumber = uval;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "clockClass")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-08-21 01:57:01 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
|
2013-06-10 15:16:26 +08:00
|
|
|
dds->clockQuality.clockClass = uval;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "clockAccuracy")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, UINT8_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
dds->clockQuality.clockAccuracy = uval;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "offsetScaledLogVariance")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0, UINT16_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
dds->clockQuality.offsetScaledLogVariance = uval;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "free_running")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
cfg->dds.free_running = val;
|
2012-08-21 22:41:36 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "freq_est_interval")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-12-01 04:52:37 +08:00
|
|
|
cfg->dds.freq_est_interval = val;
|
2012-11-08 01:20:29 +08:00
|
|
|
pod->freq_est_interval = val;
|
2012-07-28 04:34:34 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "assume_two_step")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->assume_two_step = val;
|
2012-07-28 04:34:34 +08:00
|
|
|
|
2013-04-05 23:52:14 +08:00
|
|
|
} else if (!strcmp(option, "tx_timestamp_timeout")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 1, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2013-04-05 23:52:14 +08:00
|
|
|
*cfg->tx_timestamp_timeout = val;
|
2012-11-08 01:20:29 +08:00
|
|
|
|
2013-08-29 17:01:27 +08:00
|
|
|
} else if (!strcmp(option, "check_fup_sync")) {
|
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->check_fup_sync = val;
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "pi_proportional_const")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-11-08 01:20:29 +08:00
|
|
|
*cfg->pi_proportional_const = df;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "pi_integral_const")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-11-08 01:20:29 +08:00
|
|
|
*cfg->pi_integral_const = df;
|
|
|
|
|
2013-06-28 23:09:14 +08:00
|
|
|
} else if (!strcmp(option, "pi_proportional_scale")) {
|
|
|
|
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->pi_proportional_scale = df;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "pi_proportional_exponent")) {
|
|
|
|
r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->pi_proportional_exponent = df;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "pi_proportional_norm_max")) {
|
|
|
|
r = get_ranged_double(value, &df, DBL_MIN, 1.0);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->pi_proportional_norm_max = df;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "pi_integral_scale")) {
|
|
|
|
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->pi_integral_scale = df;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "pi_integral_exponent")) {
|
|
|
|
r = get_ranged_double(value, &df, -DBL_MAX, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->pi_integral_exponent = df;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "pi_integral_norm_max")) {
|
|
|
|
r = get_ranged_double(value, &df, DBL_MIN, 2.0);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->pi_integral_norm_max = df;
|
|
|
|
|
2014-03-19 01:25:14 +08:00
|
|
|
} else if (!strcmp(option, "step_threshold")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2014-03-14 01:34:17 +08:00
|
|
|
*cfg->step_threshold = df;
|
2012-11-08 01:20:29 +08:00
|
|
|
|
2014-03-19 01:25:14 +08:00
|
|
|
} else if (!strcmp(option, "first_step_threshold")) {
|
2013-06-25 08:46:16 +08:00
|
|
|
r = get_ranged_double(value, &df, 0.0, DBL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2014-03-14 01:34:17 +08:00
|
|
|
*cfg->first_step_threshold = df;
|
2013-06-25 08:46:16 +08:00
|
|
|
|
2014-03-19 01:25:14 +08:00
|
|
|
} else if (!strcmp(option, "max_frequency")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2014-03-14 01:34:17 +08:00
|
|
|
*cfg->max_frequency = val;
|
2013-04-11 02:07:48 +08:00
|
|
|
|
2013-10-23 00:57:15 +08:00
|
|
|
} else if (!strcmp(option, "sanity_freq_limit")) {
|
|
|
|
r = get_ranged_int(value, &val, 0, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
cfg->dds.sanity_freq_limit = val;
|
|
|
|
|
2014-07-09 22:25:08 +08:00
|
|
|
} else if (!strcmp(option, "ntpshm_segment")) {
|
|
|
|
r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->ntpshm_segment = val;
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "ptp_dst_mac")) {
|
|
|
|
if (MAC_LEN != sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
|
|
|
|
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]))
|
|
|
|
return BAD_VALUE;
|
2012-07-27 17:30:22 +08:00
|
|
|
for (i = 0; i < MAC_LEN; i++)
|
|
|
|
cfg->ptp_dst_mac[i] = mac[i];
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "p2p_dst_mac")) {
|
|
|
|
if (MAC_LEN != sscanf(value, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
|
|
|
|
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]))
|
|
|
|
return BAD_VALUE;
|
2012-07-27 17:30:22 +08:00
|
|
|
for (i = 0; i < MAC_LEN; i++)
|
|
|
|
cfg->p2p_dst_mac[i] = mac[i];
|
2012-08-21 01:56:56 +08:00
|
|
|
|
2012-11-26 03:30:14 +08:00
|
|
|
} else if (!strcmp(option, "udp6_scope")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_uint(value, &uval, 0x00, 0x0F);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
*cfg->udp6_scope = uval;
|
2012-11-26 03:30:14 +08:00
|
|
|
|
2013-09-30 02:57:00 +08:00
|
|
|
} else if (!strcmp(option, "uds_address")) {
|
|
|
|
if (strlen(value) > MAX_IFNAME_SIZE)
|
|
|
|
return OUT_OF_RANGE;
|
|
|
|
strncpy(cfg->uds_address, value, MAX_IFNAME_SIZE);
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "logging_level")) {
|
2013-06-04 13:00:31 +08:00
|
|
|
r = get_ranged_int(value, &val,
|
|
|
|
PRINT_LEVEL_MIN, PRINT_LEVEL_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-08-31 22:44:21 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_PRINT_LEVEL)) {
|
2012-11-08 01:20:29 +08:00
|
|
|
cfg->print_level = val;
|
2012-08-21 01:57:01 +08:00
|
|
|
}
|
2012-08-21 01:56:56 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "verbose")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-08-21 01:57:01 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_VERBOSE))
|
2013-06-10 15:16:26 +08:00
|
|
|
cfg->verbose = val;
|
2012-08-21 01:56:56 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "use_syslog")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2012-08-21 01:57:01 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_USE_SYSLOG))
|
2013-06-10 15:16:26 +08:00
|
|
|
cfg->use_syslog = val;
|
2012-08-21 01:56:56 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "time_stamping")) {
|
2012-08-21 01:57:01 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_TIMESTAMPING)) {
|
2012-11-08 01:20:29 +08:00
|
|
|
if (0 == strcasecmp("hardware", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->timestamping = TS_HARDWARE;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (0 == strcasecmp("software", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->timestamping = TS_SOFTWARE;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (0 == strcasecmp("legacy", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->timestamping = TS_LEGACY_HW;
|
2012-11-08 01:20:29 +08:00
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
2012-08-21 01:57:01 +08:00
|
|
|
}
|
2012-08-21 01:56:56 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "delay_mechanism")) {
|
2012-08-21 01:57:01 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_DM)) {
|
2012-11-08 01:20:29 +08:00
|
|
|
if (0 == strcasecmp("E2E", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->dm = DM_E2E;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (0 == strcasecmp("P2P", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->dm = DM_P2P;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (0 == strcasecmp("Auto", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->dm = DM_AUTO;
|
2012-11-08 01:20:29 +08:00
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
2012-08-21 01:57:01 +08:00
|
|
|
}
|
2012-08-21 01:56:56 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "network_transport")) {
|
2012-08-21 01:57:01 +08:00
|
|
|
if (!(cfg_ignore & CFG_IGNORE_TRANSPORT)) {
|
2012-11-08 01:20:29 +08:00
|
|
|
if (!strcasecmp("UDPv4", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->transport = TRANS_UDP_IPV4;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (!strcasecmp("UDPv6", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->transport = TRANS_UDP_IPV6;
|
2012-11-08 01:20:29 +08:00
|
|
|
else if (!strcasecmp("L2", value))
|
2012-08-21 01:57:01 +08:00
|
|
|
cfg->transport = TRANS_IEEE_802_3;
|
2012-11-08 01:20:29 +08:00
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
2012-08-21 01:57:01 +08:00
|
|
|
}
|
2012-09-29 02:45:54 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else if (!strcmp(option, "clock_servo")) {
|
|
|
|
if (!strcasecmp("pi", value))
|
|
|
|
cfg->clock_servo = CLOCK_SERVO_PI;
|
2014-03-14 01:34:18 +08:00
|
|
|
else if (!strcasecmp("linreg", value))
|
|
|
|
cfg->clock_servo = CLOCK_SERVO_LINREG;
|
2014-06-12 00:07:08 +08:00
|
|
|
else if (!strcasecmp("ntpshm", value))
|
|
|
|
cfg->clock_servo = CLOCK_SERVO_NTPSHM;
|
2015-06-08 22:08:29 +08:00
|
|
|
else if (!strcasecmp("nullf", value))
|
|
|
|
cfg->clock_servo = CLOCK_SERVO_NULLF;
|
2012-11-08 01:20:29 +08:00
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
2012-09-29 02:45:54 +08:00
|
|
|
|
2013-02-04 06:01:52 +08:00
|
|
|
} else if (!strcmp(option, "productDescription")) {
|
|
|
|
if (count_char(value, ';') != 2)
|
|
|
|
return BAD_VALUE;
|
|
|
|
if (static_ptp_text_set(&cfg->dds.clock_desc.productDescription, value) != 0)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "revisionData")) {
|
|
|
|
if (count_char(value, ';') != 2)
|
|
|
|
return BAD_VALUE;
|
|
|
|
if (static_ptp_text_set(&cfg->dds.clock_desc.revisionData, value) != 0)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "userDescription")) {
|
|
|
|
if (static_ptp_text_set(&cfg->dds.clock_desc.userDescription, value) != 0)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "manufacturerIdentity")) {
|
|
|
|
if (OUI_LEN != sscanf(value, "%hhx:%hhx:%hhx",
|
|
|
|
&oui[0], &oui[1], &oui[2]))
|
|
|
|
return BAD_VALUE;
|
|
|
|
for (i = 0; i < OUI_LEN; i++)
|
|
|
|
cfg->dds.clock_desc.manufacturerIdentity[i] = oui[i];
|
|
|
|
|
2013-02-08 02:56:53 +08:00
|
|
|
} else if (!strcmp(option, "summary_interval")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, INT_MIN, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2013-02-09 17:45:30 +08:00
|
|
|
cfg->dds.stats_interval = val;
|
2013-02-08 02:56:53 +08:00
|
|
|
|
2013-03-08 00:27:33 +08:00
|
|
|
} else if (!strcmp(option, "kernel_leap")) {
|
2013-06-10 15:16:26 +08:00
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
2013-03-08 00:27:33 +08:00
|
|
|
cfg->dds.kernel_leap = val;
|
|
|
|
|
2013-07-06 03:40:06 +08:00
|
|
|
} else if (!strcmp(option, "timeSource")) {
|
|
|
|
r = get_ranged_int(value, &val, 0x10, 0xfe);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
cfg->dds.time_source = val;
|
|
|
|
|
2015-03-26 23:32:14 +08:00
|
|
|
} else if (!strcmp(option, "tsproc_mode")) {
|
|
|
|
if (!strcasecmp("filter", value))
|
|
|
|
cfg->dds.tsproc_mode = TSPROC_FILTER;
|
|
|
|
else if (!strcasecmp("raw", value))
|
|
|
|
cfg->dds.tsproc_mode = TSPROC_RAW;
|
|
|
|
else if (!strcasecmp("filter_weight", value))
|
|
|
|
cfg->dds.tsproc_mode = TSPROC_FILTER_WEIGHT;
|
|
|
|
else if (!strcasecmp("raw_weight", value))
|
|
|
|
cfg->dds.tsproc_mode = TSPROC_RAW_WEIGHT;
|
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
2013-10-29 18:58:20 +08:00
|
|
|
} else if (!strcmp(option, "delay_filter")) {
|
|
|
|
if (!strcasecmp("moving_average", value))
|
|
|
|
cfg->dds.delay_filter = FILTER_MOVING_AVERAGE;
|
|
|
|
else if (!strcasecmp("moving_median", value))
|
|
|
|
cfg->dds.delay_filter = FILTER_MOVING_MEDIAN;
|
|
|
|
else
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
} else if (!strcmp(option, "delay_filter_length")) {
|
|
|
|
r = get_ranged_int(value, &val, 1, INT_MAX);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
cfg->dds.delay_filter_length = val;
|
|
|
|
|
2014-11-02 01:59:13 +08:00
|
|
|
} else if (!strcmp(option, "boundary_clock_jbod")) {
|
|
|
|
r = get_ranged_int(value, &val, 0, 1);
|
|
|
|
if (r != PARSED_OK)
|
|
|
|
return r;
|
|
|
|
cfg->dds.boundary_clock_jbod = val;
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
} else
|
|
|
|
return NOT_PARSED;
|
2012-09-29 02:45:54 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
return PARSED_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-19 01:25:14 +08:00
|
|
|
static enum parser_result parse_setting_line(char *line,
|
|
|
|
const char **option,
|
|
|
|
const char **value)
|
2012-11-08 01:20:29 +08:00
|
|
|
{
|
|
|
|
*option = line;
|
2012-09-29 02:45:54 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
while (!isspace(line[0])) {
|
|
|
|
if (line[0] == '\0')
|
|
|
|
return NOT_PARSED;
|
|
|
|
line++;
|
2011-12-31 16:14:18 +08:00
|
|
|
}
|
2012-11-08 01:20:29 +08:00
|
|
|
|
|
|
|
while (isspace(line[0])) {
|
|
|
|
line[0] = '\0';
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = line;
|
|
|
|
|
|
|
|
return PARSED_OK;
|
2011-12-31 16:14:18 +08:00
|
|
|
}
|
|
|
|
|
2014-03-19 01:25:14 +08:00
|
|
|
static void check_deprecated_options(const char **option)
|
|
|
|
{
|
|
|
|
const char *new_option = NULL;
|
|
|
|
|
|
|
|
if (!strcmp(*option, "pi_offset_const")) {
|
|
|
|
new_option = "step_threshold";
|
|
|
|
} else if (!strcmp(*option, "pi_f_offset_const")) {
|
|
|
|
new_option = "first_step_threshold";
|
|
|
|
} else if (!strcmp(*option, "pi_max_frequency")) {
|
|
|
|
new_option = "max_frequency";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_option) {
|
|
|
|
fprintf(stderr, "option %s is deprecated, please use %s instead\n",
|
|
|
|
*option, new_option);
|
|
|
|
*option = new_option;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 03:09:40 +08:00
|
|
|
int config_read(char *name, struct config *cfg)
|
2011-12-31 16:14:18 +08:00
|
|
|
{
|
2012-11-08 01:20:29 +08:00
|
|
|
enum config_section current_section = UNKNOWN_SECTION;
|
|
|
|
enum parser_result parser_res;
|
2011-12-31 16:14:18 +08:00
|
|
|
FILE *fp;
|
2014-03-19 01:25:14 +08:00
|
|
|
char buf[1024], *line, *c;
|
|
|
|
const char *option, *value;
|
2014-08-14 21:56:06 +08:00
|
|
|
struct interface *current_port = NULL;
|
|
|
|
int line_num;
|
2011-12-31 16:14:18 +08:00
|
|
|
|
2012-08-22 00:03:45 +08:00
|
|
|
fp = 0 == strncmp(name, "-", 2) ? stdin : fopen(name, "r");
|
2011-12-31 16:14:18 +08:00
|
|
|
|
|
|
|
if (!fp) {
|
2012-11-08 01:20:29 +08:00
|
|
|
fprintf(stderr, "failed to open configuration file %s: %m\n", name);
|
2011-12-31 16:14:18 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
for (line_num = 1; fgets(buf, sizeof(buf), fp); line_num++) {
|
|
|
|
c = buf;
|
2012-11-07 02:00:00 +08:00
|
|
|
|
|
|
|
/* skip whitespace characters */
|
2012-11-08 01:20:29 +08:00
|
|
|
while (isspace(*c))
|
|
|
|
c++;
|
2012-11-07 02:00:00 +08:00
|
|
|
|
|
|
|
/* ignore empty lines and comments */
|
2012-11-08 01:20:29 +08:00
|
|
|
if (*c == '#' || *c == '\n' || *c == '\0')
|
2012-11-07 02:00:00 +08:00
|
|
|
continue;
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
line = c;
|
|
|
|
|
|
|
|
/* remove trailing whitespace characters and \n */
|
|
|
|
c += strlen(line) - 1;
|
|
|
|
while (c > line && (*c == '\n' || isspace(*c)))
|
|
|
|
*c-- = '\0';
|
|
|
|
|
|
|
|
if (parse_section_line(line, ¤t_section) == PARSED_OK) {
|
2012-08-21 01:57:27 +08:00
|
|
|
if (current_section == PORT_SECTION) {
|
|
|
|
char port[17];
|
|
|
|
if (1 != sscanf(line, " %16s", port)) {
|
2012-11-08 01:20:29 +08:00
|
|
|
fprintf(stderr, "could not parse port name on line %d\n",
|
|
|
|
line_num);
|
|
|
|
goto parse_error;
|
2012-08-21 01:57:27 +08:00
|
|
|
}
|
|
|
|
current_port = config_create_interface(port, cfg);
|
2014-08-14 21:56:06 +08:00
|
|
|
if (!current_port)
|
2012-11-08 01:20:29 +08:00
|
|
|
goto parse_error;
|
2014-08-14 21:56:06 +08:00
|
|
|
config_init_interface(current_port, cfg);
|
2012-08-21 01:57:27 +08:00
|
|
|
}
|
2012-08-21 07:03:26 +08:00
|
|
|
continue;
|
2012-08-21 01:57:27 +08:00
|
|
|
}
|
2012-08-21 07:03:26 +08:00
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
switch (current_section) {
|
2012-08-21 07:03:26 +08:00
|
|
|
case GLOBAL_SECTION:
|
2012-08-21 01:57:27 +08:00
|
|
|
case PORT_SECTION:
|
2012-11-08 01:20:29 +08:00
|
|
|
if (parse_setting_line(line, &option, &value)) {
|
|
|
|
fprintf(stderr, "could not parse line %d in %s section\n",
|
|
|
|
line_num,
|
|
|
|
current_section == GLOBAL_SECTION ?
|
2014-08-14 21:56:06 +08:00
|
|
|
"global" : current_port->name);
|
2012-11-08 01:20:29 +08:00
|
|
|
goto parse_error;
|
|
|
|
}
|
|
|
|
|
2014-03-19 01:25:14 +08:00
|
|
|
check_deprecated_options(&option);
|
|
|
|
|
2012-11-08 01:20:29 +08:00
|
|
|
if (current_section == GLOBAL_SECTION)
|
|
|
|
parser_res = parse_global_setting(option, value, cfg);
|
|
|
|
else
|
2014-11-01 22:08:01 +08:00
|
|
|
parser_res = parse_port_setting(option, value, current_port);
|
2012-11-08 01:20:29 +08:00
|
|
|
|
|
|
|
switch (parser_res) {
|
|
|
|
case PARSED_OK:
|
|
|
|
break;
|
|
|
|
case NOT_PARSED:
|
|
|
|
fprintf(stderr, "unknown option %s at line %d in %s section\n",
|
|
|
|
option, line_num,
|
|
|
|
current_section == GLOBAL_SECTION ?
|
2014-08-14 21:56:06 +08:00
|
|
|
"global" : current_port->name);
|
2012-11-08 01:20:29 +08:00
|
|
|
goto parse_error;
|
|
|
|
case BAD_VALUE:
|
|
|
|
fprintf(stderr, "%s is a bad value for option %s at line %d\n",
|
|
|
|
value, option, line_num);
|
2013-06-04 12:57:22 +08:00
|
|
|
goto parse_error;
|
|
|
|
case MALFORMED:
|
|
|
|
fprintf(stderr, "%s is a malformed value for option %s at line %d\n",
|
|
|
|
value, option, line_num);
|
|
|
|
goto parse_error;
|
|
|
|
case OUT_OF_RANGE:
|
|
|
|
fprintf(stderr, "%s is an out of range value for option %s at line %d\n",
|
|
|
|
value, option, line_num);
|
2012-11-08 01:20:29 +08:00
|
|
|
goto parse_error;
|
|
|
|
}
|
|
|
|
|
2012-08-21 01:57:27 +08:00
|
|
|
break;
|
2012-11-08 01:20:29 +08:00
|
|
|
case UNKNOWN_SECTION:
|
|
|
|
fprintf(stderr, "line %d is not in a section\n", line_num);
|
|
|
|
goto parse_error;
|
2012-08-21 07:03:26 +08:00
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-31 16:14:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
2012-11-08 01:20:29 +08:00
|
|
|
|
|
|
|
parse_error:
|
|
|
|
fprintf(stderr, "failed to parse configuration file %s\n", name);
|
|
|
|
fclose(fp);
|
|
|
|
return -2;
|
2011-12-31 16:14:18 +08:00
|
|
|
}
|
2012-08-21 01:56:45 +08:00
|
|
|
|
2014-08-14 21:56:06 +08:00
|
|
|
struct interface *config_create_interface(char *name, struct config *cfg)
|
2012-08-21 01:56:45 +08:00
|
|
|
{
|
|
|
|
struct interface *iface;
|
|
|
|
|
2014-08-14 21:56:06 +08:00
|
|
|
/* only create each interface once (by name) */
|
|
|
|
STAILQ_FOREACH(iface, &cfg->interfaces, list) {
|
|
|
|
if (0 == strncmp(name, iface->name, MAX_IFNAME_SIZE))
|
|
|
|
return iface;
|
2012-08-21 01:56:45 +08:00
|
|
|
}
|
|
|
|
|
2014-08-14 21:56:06 +08:00
|
|
|
iface = calloc(1, sizeof(struct interface));
|
|
|
|
if (!iface) {
|
|
|
|
fprintf(stderr, "cannot allocate memory for a port\n");
|
|
|
|
return NULL;
|
2012-08-21 01:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(iface->name, name, MAX_IFNAME_SIZE);
|
2014-08-14 21:56:06 +08:00
|
|
|
STAILQ_INSERT_TAIL(&cfg->interfaces, iface, list);
|
|
|
|
return iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void config_init_interface(struct interface *iface, struct config *cfg)
|
|
|
|
{
|
2012-08-21 01:56:45 +08:00
|
|
|
iface->dm = cfg->dm;
|
|
|
|
iface->transport = cfg->transport;
|
2012-08-21 01:56:50 +08:00
|
|
|
memcpy(&iface->pod, &cfg->pod, sizeof(cfg->pod));
|
|
|
|
|
2014-08-14 21:56:06 +08:00
|
|
|
sk_get_ts_info(iface->name, &iface->ts_info);
|
2012-11-14 05:35:04 +08:00
|
|
|
|
2013-10-29 18:58:20 +08:00
|
|
|
iface->delay_filter = cfg->dds.delay_filter;
|
|
|
|
iface->delay_filter_length = cfg->dds.delay_filter_length;
|
2014-11-02 01:59:13 +08:00
|
|
|
iface->boundary_clock_jbod = cfg->dds.boundary_clock_jbod;
|
2014-08-14 21:56:06 +08:00
|
|
|
}
|
2013-10-29 18:58:20 +08:00
|
|
|
|
2014-08-14 21:56:06 +08:00
|
|
|
void config_destroy(struct config *cfg)
|
|
|
|
{
|
|
|
|
struct interface *iface;
|
2012-08-21 01:56:45 +08:00
|
|
|
|
2014-08-14 21:56:06 +08:00
|
|
|
while ((iface = STAILQ_FIRST(&cfg->interfaces))) {
|
|
|
|
STAILQ_REMOVE_HEAD(&cfg->interfaces, list);
|
|
|
|
free(iface);
|
|
|
|
}
|
2012-08-21 01:56:45 +08:00
|
|
|
}
|