Skip to content

Commit

Permalink
interface: Add an optional remote address for use by the UDS transport.
Browse files Browse the repository at this point in the history
Because of the implementation of the UDS module, it is not possible
for a process to act as both a PTP management client (PMC) and server.
Going forward, one ptp4l instance will need to subscribe to another
using the PMC methods.  Pave the way by allowing the interface to
include an optional remote UDS address.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
  • Loading branch information
richardcochran committed Feb 20, 2024
1 parent f271257 commit 653c71f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
/* Configure the UDS. */

uds_ifname = config_get_string(config, NULL, "uds_address");
c->uds_rw_if = interface_create(uds_ifname);
c->uds_rw_if = interface_create(uds_ifname, NULL);
if (config_set_section_int(config, interface_name(c->uds_rw_if),
"announceReceiptTimeout", 0)) {
return NULL;
Expand All @@ -1261,7 +1261,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
}

uds_ifname = config_get_string(config, NULL, "uds_ro_address");
c->uds_ro_if = interface_create(uds_ifname);
c->uds_ro_if = interface_create(uds_ifname, NULL);
if (config_set_section_int(config, interface_name(c->uds_ro_if),
"announceReceiptTimeout", 0)) {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ struct interface *config_create_interface(const char *name, struct config *cfg)
return iface;
}

iface = interface_create(name);
iface = interface_create(name, NULL);
if (!iface) {
fprintf(stderr, "cannot allocate memory for a port\n");
return NULL;
Expand Down
12 changes: 10 additions & 2 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ struct interface {
STAILQ_ENTRY(interface) list;
char name[MAX_IFNAME_SIZE + 1];
char ts_label[MAX_IFNAME_SIZE + 1];
char remote[MAX_IFNAME_SIZE + 1];
struct sk_ts_info ts_info;
struct sk_if_info if_info;
int vclock;
};

struct interface *interface_create(const char *name)
struct interface *interface_create(const char *name, const char *remote)
{
struct interface *iface;

Expand All @@ -27,6 +28,9 @@ struct interface *interface_create(const char *name)
}
strncpy(iface->name, name, MAX_IFNAME_SIZE);
strncpy(iface->ts_label, name, MAX_IFNAME_SIZE);
if (remote) {
strncpy(iface->remote, remote, MAX_IFNAME_SIZE);
}
iface->vclock = -1;

return iface;
Expand Down Expand Up @@ -57,7 +61,6 @@ bool interface_ifinfo_valid(struct interface *iface)
return iface->if_info.valid ? true : false;
}


const char *interface_name(struct interface *iface)
{
return iface->name;
Expand All @@ -68,6 +71,11 @@ int interface_phc_index(struct interface *iface)
return iface->ts_info.phc_index;
}

const char *interface_remote(struct interface *iface)
{
return iface->remote;
}

void interface_set_label(struct interface *iface, const char *label)
{
strncpy(iface->ts_label, label, MAX_IFNAME_SIZE);
Expand Down
10 changes: 9 additions & 1 deletion interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ struct interface;
/**
* Creates an instance of an interface.
* @param name The device which indentifies this interface.
* @param remote For UDS interfaces, the address of the remote server, possibly NULL.
* @return A pointer to an interface instance on success, NULL otherwise.
*/
struct interface *interface_create(const char *name);
struct interface *interface_create(const char *name, const char *remote);

/**
* Destroys an instance of an interface.
Expand Down Expand Up @@ -70,6 +71,13 @@ const char *interface_name(struct interface *iface);
*/
int interface_phc_index(struct interface *iface);

/**
* Obtains the remote address from a UDS interface.
* @param iface The interface of interest.
* @return The device name of the network interface.
*/
const char *interface_remote(struct interface *iface);

/**
* Set the time stamping label of a given interface.
* @param iface The interface of interest.
Expand Down
2 changes: 1 addition & 1 deletion pmc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
goto failed;
}

pmc->iface = interface_create(iface_name);
pmc->iface = interface_create(iface_name, NULL);
if (!pmc->iface) {
pr_err("failed to create interface");
goto failed;
Expand Down

0 comments on commit 653c71f

Please sign in to comment.