Skip to content

Commit

Permalink
ptp4l: pass struct interface directly instead of passing it's sub arg…
Browse files Browse the repository at this point in the history
…uments

the port_open function takes a large number of command options, a few of which
are actually all values of struct interface. This patch modifies the port_open
call to take a struct interface value instead of all the other values. This
simplifies the overall work necessary and allows for adding new port
configuration values by appending them to the struct interface

Signed-off-by: Jacob Keller <[email protected]>
  • Loading branch information
jacob-keller authored and richardcochran committed Aug 21, 2012
1 parent 0499513 commit 64dcf25
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
3 changes: 1 addition & 2 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,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, iface[i].name, iface[i].transport,
timestamping, 1+i, iface[i].dm, c);
c->port[i] = port_open(pod, phc_index, timestamping, 1+i, &iface[i], c);
if (!c->port[i]) {
pr_err("failed to open port %s", iface[i].name);
return NULL;
Expand Down
12 changes: 5 additions & 7 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1539,11 +1539,9 @@ struct ptp_message *port_management_reply(struct PortIdentity pid,

struct port *port_open(struct port_defaults *pod,
int phc_index,
char *name,
enum transport_type transport,
enum timestamp_type timestamping,
int number,
enum delay_mechanism dm,
struct interface *interface,
struct clock *clock)
{
struct port *p = malloc(sizeof(*p));
Expand All @@ -1554,7 +1552,7 @@ struct port *port_open(struct port_defaults *pod,

memset(p, 0, sizeof(*p));

if (sk_interface_phc(name, &checked_phc_index))
if (sk_interface_phc(interface->name, &checked_phc_index))
pr_warning("port %d: get_ts_info not supported", number);
else if (phc_index >= 0 && phc_index != checked_phc_index) {
pr_err("port %d: PHC device mismatch", number);
Expand All @@ -1564,9 +1562,9 @@ struct port *port_open(struct port_defaults *pod,
}

p->pod = *pod;
p->name = name;
p->name = interface->name;
p->clock = clock;
p->trp = transport_create(transport);
p->trp = transport_create(interface->transport);
if (!p->trp) {
free(p);
return NULL;
Expand All @@ -1575,7 +1573,7 @@ struct port *port_open(struct port_defaults *pod,
p->portIdentity.clockIdentity = clock_identity(clock);
p->portIdentity.portNumber = number;
p->state = PS_INITIALIZING;
p->delayMechanism = dm;
p->delayMechanism = interface->dm;
p->versionNumber = PTP_VERSION;

p->avg_delay = mave_create(PORT_MAVE_LENGTH);
Expand Down
16 changes: 7 additions & 9 deletions port.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include "fsm.h"
#include "transport.h"

struct clock; /*forward declaration*/
/* forward declarations */
struct interface;
struct clock;

/** Opaque type. */
struct port;
Expand Down Expand Up @@ -128,21 +130,17 @@ 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 name The name of the network interface.
* @param transport The network transport type to use on this port.
* @param timestamping The flavor of time stamping to use on this port.
* @param number An arbitrary port number for this port.
* @param dm Which delay mechanism to use on this port.
* @param timestamping The timestamping mode for this port.
* @param number An arbitrary number assigned to this port.
* @param interface The interface data
* @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,
char *name,
enum transport_type transport,
enum timestamp_type timestamping,
int number,
enum delay_mechanism dm,
struct interface *interface,
struct clock *clock);

/**
Expand Down

0 comments on commit 64dcf25

Please sign in to comment.