ptp4l: add override flag in cfg_settings to apply cmdline options

This patch adds a flag field for setting overflag flags so that command line
options override any value in the configuration file. This will be done by
ensuring the flags set whether the config parser accepts the values specified.
This patch also streamlines the handling for the slave only command line
option, as it no longer needs special treatment.

-v2
* Minor change to fix merge with previous patch

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
master
Jacob Keller 2012-08-20 10:57:01 -07:00 committed by Richard Cochran
parent fcdc675f99
commit 11a334b93e
3 changed files with 73 additions and 32 deletions

View File

@ -25,7 +25,7 @@
static void scan_line(char *s, struct config *cfg)
{
double df;
int i, val;
int i, val, cfg_ignore = cfg->cfg_ignore;
Integer8 i8;
UInteger16 u16;
UInteger8 u8;
@ -42,6 +42,7 @@ static void scan_line(char *s, struct config *cfg)
} else if (1 == sscanf(s, " slaveOnly %d", &val)) {
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
dds->slaveOnly = val ? 1 : 0;
} else if (1 == sscanf(s, " priority1 %hhu", &u8)) {
@ -59,6 +60,7 @@ static void scan_line(char *s, struct config *cfg)
} else if (1 == sscanf(s, " clockClass %hhu", &u8)) {
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
dds->clockQuality.clockClass = u8;
} else if (1 == sscanf(s, " clockAccuracy %hhx", &u8)) {
@ -138,19 +140,27 @@ static void scan_line(char *s, struct config *cfg)
} else if (1 == sscanf(s, " logging_level %d", &val)) {
if (!(cfg_ignore & CFG_IGNORE_VERBOSE)) {
if (val >= PRINT_LEVEL_MIN && val <= PRINT_LEVEL_MAX)
cfg->print_level = val;
}
} else if (1 == sscanf(s, " verbose %d", &val)) {
if (!(cfg_ignore & CFG_IGNORE_VERBOSE))
cfg->verbose = val ? 1 : 0;
} else if (1 == sscanf(s, " use_syslog %d", &val)) {
if (!(cfg_ignore & CFG_IGNORE_USE_SYSLOG))
cfg->use_syslog = val ? 1 : 0;
} else if (1 == sscanf(s, " time_stamping %1023s", string)) {
if (!(cfg_ignore & CFG_IGNORE_TIMESTAMPING)) {
if (0 == strcasecmp("hardware", string))
cfg->timestamping = TS_HARDWARE;
@ -162,9 +172,12 @@ static void scan_line(char *s, struct config *cfg)
else if (0 == strcasecmp("legacy", string))
cfg->timestamping = TS_LEGACY_HW;
}
} else if (1 == sscanf(s, " delay_mechanism %1023s", string)) {
if (!(cfg_ignore & CFG_IGNORE_DM)) {
if (0 == strcasecmp("E2E", string))
cfg->dm = DM_E2E;
@ -176,8 +189,12 @@ static void scan_line(char *s, struct config *cfg)
else if (0 == strcasecmp("Auto", string))
cfg->dm = DM_AUTO;
}
} else if (1 == sscanf(s, " network_transport %1023s", string)) {
if (!(cfg_ignore & CFG_IGNORE_TRANSPORT)) {
if (0 == strcasecmp("UDPv4", string))
cfg->transport = TRANS_UDP_IPV4;
@ -192,6 +209,7 @@ static void scan_line(char *s, struct config *cfg)
}
}
}
int config_read(char *name, struct config *cfg)
{

View File

@ -35,7 +35,18 @@ struct interface {
struct port_defaults pod;
};
#define CFG_IGNORE_DM (1 << 0)
#define CFG_IGNORE_TRANSPORT (1 << 1)
#define CFG_IGNORE_TIMESTAMPING (1 << 2)
#define CFG_IGNORE_SLAVEONLY (1 << 3)
#define CFG_IGNORE_PRINT_LEVEL (1 << 4)
#define CFG_IGNORE_USE_SYSLOG (1 << 5)
#define CFG_IGNORE_VERBOSE (1 << 6)
struct config {
/* configuration override */
int cfg_ignore;
/* configured interfaces */
struct interface iface[MAX_PORTS];
int nports;

26
ptp4l.c
View File

@ -72,6 +72,8 @@ static struct config cfg_settings = {
.print_level = LOG_INFO,
.use_syslog = 1,
.verbose = 0,
.cfg_ignore = 0,
};
static void usage(char *progname)
@ -108,9 +110,10 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
char *config = NULL, *req_phc = NULL, *progname;
int c, slaveonly = 0;
int c;
struct interface *iface = cfg_settings.iface;
int *nports = &cfg_settings.nports;
int *cfg_ignore = &cfg_settings.cfg_ignore;
enum delay_mechanism *dm = &cfg_settings.dm;
enum transport_type *transport = &cfg_settings.transport;
enum timestamp_type *timestamping = &cfg_settings.timestamping;
@ -125,30 +128,39 @@ int main(int argc, char *argv[])
switch (c) {
case 'A':
*dm = DM_AUTO;
*cfg_ignore |= CFG_IGNORE_DM;
break;
case 'E':
*dm = DM_E2E;
*cfg_ignore |= CFG_IGNORE_DM;
break;
case 'P':
*dm = DM_P2P;
*cfg_ignore |= CFG_IGNORE_DM;
break;
case '2':
*transport = TRANS_IEEE_802_3;
*cfg_ignore |= CFG_IGNORE_TRANSPORT;
break;
case '4':
*transport = TRANS_UDP_IPV4;
*cfg_ignore |= CFG_IGNORE_TRANSPORT;
break;
case '6':
*transport = TRANS_UDP_IPV6;
*cfg_ignore |= CFG_IGNORE_TRANSPORT;
break;
case 'H':
*timestamping = TS_HARDWARE;
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
break;
case 'S':
*timestamping = TS_SOFTWARE;
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
break;
case 'L':
*timestamping = TS_LEGACY_HW;
*cfg_ignore |= CFG_IGNORE_TIMESTAMPING;
break;
case 'f':
config = optarg;
@ -163,16 +175,21 @@ int main(int argc, char *argv[])
req_phc = optarg;
break;
case 's':
slaveonly = 1;
ds->slaveOnly = TRUE;
ds->clockQuality.clockClass = 255;
*cfg_ignore |= CFG_IGNORE_SLAVEONLY;
break;
case 'l':
cfg_settings.print_level = atoi(optarg);
*cfg_ignore |= CFG_IGNORE_PRINT_LEVEL;
break;
case 'q':
cfg_settings.use_syslog = 0;
*cfg_ignore |= CFG_IGNORE_USE_SYSLOG;
break;
case 'v':
cfg_settings.verbose = 1;
*cfg_ignore |= CFG_IGNORE_VERBOSE;
break;
case 'h':
usage(progname);
@ -220,11 +237,6 @@ int main(int argc, char *argv[])
return -1;
}
if (slaveonly) {
ds->slaveOnly = TRUE;
ds->clockQuality.clockClass = 255;
}
print_set_verbose(cfg_settings.verbose);
print_set_syslog(cfg_settings.use_syslog);
print_set_level(cfg_settings.print_level);