From 7a69db2379616a0552294f4788e90c972406a1f0 Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Mon, 20 Aug 2012 10:56:50 -0700 Subject: [PATCH] ptp4l: Allow per-port customized port defaults this patch allows each port to maintain its own pod structure since it is only used in ports. This will allow the user to configure any special settings per port. It takes a copy of the default pod, and a future patch will allow the configuration file to set per-port specific changes -v2 * Minor change to fix merge with previous patch Signed-off-by: Jacob Keller --- clock.c | 5 ++--- clock.h | 4 +--- config.c | 2 ++ config.h | 1 + port.c | 5 ++--- port.h | 4 +--- ptp4l.c | 3 +-- 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/clock.c b/clock.c index 16a6ba2..5cccc2e 100644 --- a/clock.c +++ b/clock.c @@ -210,8 +210,7 @@ UInteger8 clock_class(struct clock *c) } struct clock *clock_create(int phc_index, struct interface *iface, int count, - enum timestamp_type timestamping, struct defaultDS *ds, - struct port_defaults *pod) + enum timestamp_type timestamping, struct defaultDS *ds) { int i, max_adj, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0; struct clock *c = &the_clock; @@ -267,7 +266,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count, c->fault_timeout = FAULT_RESET_SECONDS; for (i = 0; i < count; i++) { - c->port[i] = port_open(pod, phc_index, timestamping, 1+i, &iface[i], c); + c->port[i] = port_open(phc_index, timestamping, 1+i, &iface[i], c); if (!c->port[i]) { pr_err("failed to open port %s", iface[i].name); return NULL; diff --git a/clock.h b/clock.h index 1ca9a23..2566aa7 100644 --- a/clock.h +++ b/clock.h @@ -65,12 +65,10 @@ UInteger8 clock_class(struct clock *c); * @param count The number of elements in @a interfaces. * @param timestamping The timestamping mode for this clock. * @param ds A pointer to a default data set for the clock. - * @param pod A pointer to a default port data set for the clock. * @return A pointer to the single global clock instance. */ struct clock *clock_create(int phc_index, struct interface *iface, int count, - enum timestamp_type timestamping, struct defaultDS *ds, - struct port_defaults *pod); + enum timestamp_type timestamping, struct defaultDS *ds); /** * Obtains a clock's default data set. diff --git a/config.c b/config.c index 8ce8ad4..d583b02 100644 --- a/config.c +++ b/config.c @@ -177,6 +177,8 @@ int config_create_interface(char *name, struct config *cfg) strncpy(iface->name, name, MAX_IFNAME_SIZE); iface->dm = cfg->dm; iface->transport = cfg->transport; + memcpy(&iface->pod, &cfg->pod, sizeof(cfg->pod)); + cfg->nports++; return i; diff --git a/config.h b/config.h index cdade16..1a56ea1 100644 --- a/config.h +++ b/config.h @@ -32,6 +32,7 @@ struct interface { char name[MAX_IFNAME_SIZE + 1]; enum delay_mechanism dm; enum transport_type transport; + struct port_defaults pod; }; struct config { diff --git a/port.c b/port.c index 563c844..cafb688 100644 --- a/port.c +++ b/port.c @@ -1537,8 +1537,7 @@ struct ptp_message *port_management_reply(struct PortIdentity pid, return msg; } -struct port *port_open(struct port_defaults *pod, - int phc_index, +struct port *port_open(int phc_index, enum timestamp_type timestamping, int number, struct interface *interface, @@ -1561,7 +1560,7 @@ struct port *port_open(struct port_defaults *pod, return NULL; } - p->pod = *pod; + p->pod = interface->pod; p->name = interface->name; p->clock = clock; p->trp = transport_create(interface->transport); diff --git a/port.h b/port.h index d4c2075..852bf8b 100644 --- a/port.h +++ b/port.h @@ -128,7 +128,6 @@ struct ptp_message *port_management_reply(struct PortIdentity pid, /** * Open a network port. - * @param pod A pointer to a default port data set for this port. * @param phc_index The PHC device index for the network device. * @param timestamping The timestamping mode for this port. * @param number An arbitrary number assigned to this port. @@ -136,8 +135,7 @@ struct ptp_message *port_management_reply(struct PortIdentity pid, * @param clock A pointer to the system PTP clock. * @return A pointer to an open port on success, or NULL otherwise. */ -struct port *port_open(struct port_defaults *pod, - int phc_index, +struct port *port_open(int phc_index, enum timestamp_type timestamping, int number, struct interface *interface, diff --git a/ptp4l.c b/ptp4l.c index 7aa872a..0d4321a 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -112,7 +112,6 @@ int main(int argc, char *argv[]) enum timestamp_type *timestamping = &cfg_settings.timestamping; struct clock *clock; struct defaultDS *ds = &cfg_settings.dds; - struct port_defaults *pod = &cfg_settings.pod; int phc_index = -1; /* Process the command line arguments. */ @@ -222,7 +221,7 @@ int main(int argc, char *argv[]) ds->clockQuality.clockClass = 255; } - clock = clock_create(phc_index, iface, *nports, *timestamping, ds, pod); + clock = clock_create(phc_index, iface, *nports, *timestamping, ds); if (!clock) { fprintf(stderr, "failed to create a clock\n"); return -1;