ptp4l: add missing options to config file

This patch adds support to the configuration file for all of the options
specified on the command line.

-v2
* Fix string length to account for null byte
* Add PRINT_LEVEL_MIN/MAX defines

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
master
Jacob Keller 2012-08-20 10:56:56 -07:00 committed by Richard Cochran
parent 7a69db2379
commit fcdc675f99
4 changed files with 76 additions and 4 deletions

View File

@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
#include "ether.h" #include "ether.h"
#include "print.h"
static void scan_line(char *s, struct config *cfg) static void scan_line(char *s, struct config *cfg)
{ {
@ -29,6 +30,7 @@ static void scan_line(char *s, struct config *cfg)
UInteger16 u16; UInteger16 u16;
UInteger8 u8; UInteger8 u8;
unsigned char mac[MAC_LEN]; unsigned char mac[MAC_LEN];
char string[1024];
struct defaultDS *dds = &cfg->dds; struct defaultDS *dds = &cfg->dds;
struct port_defaults *pod = &cfg->pod; struct port_defaults *pod = &cfg->pod;
@ -133,6 +135,61 @@ static void scan_line(char *s, struct config *cfg)
for (i = 0; i < MAC_LEN; i++) for (i = 0; i < MAC_LEN; i++)
cfg->p2p_dst_mac[i] = mac[i]; cfg->p2p_dst_mac[i] = mac[i];
} else if (1 == sscanf(s, " logging_level %d", &val)) {
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;
} else if (1 == sscanf(s, " use_syslog %d", &val)) {
cfg->use_syslog = val ? 1 : 0;
} else if (1 == sscanf(s, " time_stamping %1023s", string)) {
if (0 == strcasecmp("hardware", string))
cfg->timestamping = TS_HARDWARE;
else if (0 == strcasecmp("software", string))
cfg->timestamping = TS_SOFTWARE;
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))
cfg->dm = DM_E2E;
else if (0 == strcasecmp("P2P", string))
cfg->dm = DM_P2P;
else if (0 == strcasecmp("Auto", string))
cfg->dm = DM_AUTO;
} else if (1 == sscanf(s, " network_transport %1023s", string)) {
if (0 == strcasecmp("UDPv4", string))
cfg->transport = TRANS_UDP_IPV4;
else if (0 == strcasecmp("UDPv6", string))
cfg->transport = TRANS_UDP_IPV6;
else if (0 == strcasecmp("L2", string))
cfg->transport = TRANS_IEEE_802_3;
} }
} }

View File

@ -53,6 +53,10 @@ struct config {
double *pi_integral_const; double *pi_integral_const;
unsigned char *ptp_dst_mac; unsigned char *ptp_dst_mac;
unsigned char *p2p_dst_mac; unsigned char *p2p_dst_mac;
int print_level;
int use_syslog;
int verbose;
}; };
int config_read(char *name, struct config *cfg); int config_read(char *name, struct config *cfg);

View File

@ -22,6 +22,9 @@
#include <syslog.h> #include <syslog.h>
#define PRINT_LEVEL_MIN LOG_EMERG
#define PRINT_LEVEL_MAX LOG_DEBUG
void print(int level, char const *format, ...); void print(int level, char const *format, ...);
void print_set_syslog(int value); void print_set_syslog(int value);

14
ptp4l.c
View File

@ -68,6 +68,10 @@ static struct config cfg_settings = {
.pi_integral_const = &configured_pi_ki, .pi_integral_const = &configured_pi_ki,
.ptp_dst_mac = ptp_dst_mac, .ptp_dst_mac = ptp_dst_mac,
.p2p_dst_mac = p2p_dst_mac, .p2p_dst_mac = p2p_dst_mac,
.print_level = LOG_INFO,
.use_syslog = 1,
.verbose = 0,
}; };
static void usage(char *progname) static void usage(char *progname)
@ -162,13 +166,13 @@ int main(int argc, char *argv[])
slaveonly = 1; slaveonly = 1;
break; break;
case 'l': case 'l':
print_set_level(atoi(optarg)); cfg_settings.print_level = atoi(optarg);
break; break;
case 'q': case 'q':
print_set_syslog(1); cfg_settings.use_syslog = 0;
break; break;
case 'v': case 'v':
print_set_verbose(1); cfg_settings.verbose = 1;
break; break;
case 'h': case 'h':
usage(progname); usage(progname);
@ -221,6 +225,10 @@ int main(int argc, char *argv[])
ds->clockQuality.clockClass = 255; ds->clockQuality.clockClass = 255;
} }
print_set_verbose(cfg_settings.verbose);
print_set_syslog(cfg_settings.use_syslog);
print_set_level(cfg_settings.print_level);
clock = clock_create(phc_index, iface, *nports, *timestamping, ds); clock = clock_create(phc_index, iface, *nports, *timestamping, ds);
if (!clock) { if (!clock) {
fprintf(stderr, "failed to create a clock\n"); fprintf(stderr, "failed to create a clock\n");