diff --git a/ptp4l.c b/ptp4l.c index c75e8ce..c50384b 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -22,6 +22,7 @@ #include #include "clock.h" +#include "config.h" #include "print.h" #include "transport.h" #include "udp.h" @@ -30,6 +31,7 @@ static int running = 1; static struct defaultDS ds; +static struct port_defaults pod; static int generate_clock_identity(struct ClockIdentity *ci, char *name) { @@ -60,11 +62,12 @@ static void usage(char *progname) " -s SOFTWARE\n" " -z LEGACY HW\n\n" " Other Options\n\n" + " -f [file] read configuration from 'file'\n" " -h prints this message and exits\n" " -i [dev] interface device to use, for example 'eth0'\n" " (may be specified multiple times)\n" " -l [num] set the logging level to 'num'\n" - " -m slave only mode\n" + " -m slave only mode (overrides configuration file)\n" " -p [dev] PTP hardware clock device to use, default '%s'\n" " (ignored for SOFTWARE/LEGACY HW time stamping)\n\n", progname, DEFAULT_PHC); @@ -72,7 +75,7 @@ static void usage(char *progname) int main(int argc, char *argv[]) { - char *phc = DEFAULT_PHC, *progname; + char *config = NULL, *phc = DEFAULT_PHC, *progname; int c, i, nports = 0, slaveonly = 0; struct interface iface[MAX_PORTS]; enum transport_type transport = TRANS_UDP_IPV4; @@ -82,7 +85,7 @@ int main(int argc, char *argv[]) /* Process the command line arguments. */ progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt(argc, argv, "246hi:l:mp:rsz"))) { + while (EOF != (c = getopt(argc, argv, "246f:hi:l:mp:rsz"))) { switch (c) { case '2': transport = TRANS_IEEE_802_3; @@ -93,6 +96,9 @@ int main(int argc, char *argv[]) case '6': transport = TRANS_UDP_IPV6; break; + case 'f': + config = optarg; + break; case 'i': if (nports < MAX_PORTS) { iface[nports++].name = optarg; @@ -143,9 +149,9 @@ int main(int argc, char *argv[]) phc = NULL; } - ds.slaveOnly = slaveonly ? TRUE : FALSE; + ds.slaveOnly = FALSE; ds.priority1 = 128; - ds.clockQuality.clockClass = slaveonly ? 255 : 248; + ds.clockQuality.clockClass = 248; ds.clockQuality.clockAccuracy = 0xfe; ds.clockQuality.offsetScaledLogVariance = 0xffff; ds.priority2 = 128; @@ -155,6 +161,16 @@ int main(int argc, char *argv[]) return -1; } + if (config && config_read(config, &ds, &pod)) { + fprintf(stderr, "failed to read configuration file\n"); + return -1; + } + + if (slaveonly) { + ds.slaveOnly = TRUE; + ds.clockQuality.clockClass = 255; + } + clock = clock_create(phc, iface, nports, &ds); if (!clock) { fprintf(stderr, "failed to create a clock\n");