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,7 +42,8 @@ static void scan_line(char *s, struct config *cfg)
} else if (1 == sscanf(s, " slaveOnly %d", &val)) {
dds->slaveOnly = val ? 1 : 0;
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
dds->slaveOnly = val ? 1 : 0;
} else if (1 == sscanf(s, " priority1 %hhu", &u8)) {
@ -59,7 +60,8 @@ static void scan_line(char *s, struct config *cfg)
} else if (1 == sscanf(s, " clockClass %hhu", &u8)) {
dds->clockQuality.clockClass = u8;
if (!(cfg_ignore & CFG_IGNORE_SLAVEONLY))
dds->clockQuality.clockClass = u8;
} else if (1 == sscanf(s, " clockAccuracy %hhx", &u8)) {
@ -138,58 +140,74 @@ static void scan_line(char *s, struct config *cfg)
} else if (1 == sscanf(s, " logging_level %d", &val)) {
if (val >= PRINT_LEVEL_MIN && val <= PRINT_LEVEL_MAX)
cfg->print_level = 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)) {
cfg->verbose = val ? 1 : 0;
if (!(cfg_ignore & CFG_IGNORE_VERBOSE))
cfg->verbose = val ? 1 : 0;
} else if (1 == sscanf(s, " use_syslog %d", &val)) {
cfg->use_syslog = val ? 1 : 0;
if (!(cfg_ignore & CFG_IGNORE_USE_SYSLOG))
cfg->use_syslog = val ? 1 : 0;
} else if (1 == sscanf(s, " time_stamping %1023s", string)) {
if (0 == strcasecmp("hardware", string))
if (!(cfg_ignore & CFG_IGNORE_TIMESTAMPING)) {
cfg->timestamping = TS_HARDWARE;
if (0 == strcasecmp("hardware", string))
else if (0 == strcasecmp("software", string))
cfg->timestamping = TS_HARDWARE;
cfg->timestamping = TS_SOFTWARE;
else if (0 == strcasecmp("software", string))
else if (0 == strcasecmp("legacy", string))
cfg->timestamping = TS_SOFTWARE;
cfg->timestamping = TS_LEGACY_HW;
else if (0 == strcasecmp("legacy", string))
cfg->timestamping = TS_LEGACY_HW;
}
} else if (1 == sscanf(s, " delay_mechanism %1023s", string)) {
if (0 == strcasecmp("E2E", string))
if (!(cfg_ignore & CFG_IGNORE_DM)) {
cfg->dm = DM_E2E;
if (0 == strcasecmp("E2E", string))
else if (0 == strcasecmp("P2P", string))
cfg->dm = DM_E2E;
cfg->dm = DM_P2P;
else if (0 == strcasecmp("P2P", string))
else if (0 == strcasecmp("Auto", string))
cfg->dm = DM_P2P;
else if (0 == strcasecmp("Auto", string))
cfg->dm = DM_AUTO;
}
cfg->dm = DM_AUTO;
} else if (1 == sscanf(s, " network_transport %1023s", string)) {
if (0 == strcasecmp("UDPv4", string))
if (!(cfg_ignore & CFG_IGNORE_TRANSPORT)) {
cfg->transport = TRANS_UDP_IPV4;
if (0 == strcasecmp("UDPv4", string))
else if (0 == strcasecmp("UDPv6", string))
cfg->transport = TRANS_UDP_IPV4;
cfg->transport = TRANS_UDP_IPV6;
else if (0 == strcasecmp("UDPv6", string))
else if (0 == strcasecmp("L2", string))
cfg->transport = TRANS_UDP_IPV6;
cfg->transport = TRANS_IEEE_802_3;
else if (0 == strcasecmp("L2", string))
cfg->transport = TRANS_IEEE_802_3;
}
}
}

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