Skip to content

Commit

Permalink
transport: pass struct interface to transport_open
Browse files Browse the repository at this point in the history
Pass struct interface so we can use ts_iface in HW filter.

Signed-off-by: Hangbin Liu <[email protected]>
  • Loading branch information
liuhangbin authored and richardcochran committed Oct 14, 2017
1 parent 536a710 commit 8923bcd
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
5 changes: 4 additions & 1 deletion pmc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
int zero_datalen)
{
struct pmc *pmc;
struct interface iface;

pmc = calloc(1, sizeof *pmc);
if (!pmc)
Expand All @@ -90,7 +91,9 @@ struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
pr_err("failed to create transport");
goto failed;
}
if (transport_open(pmc->transport, iface_name,

strncpy(iface.name, iface_name, MAX_IFNAME_SIZE);
if (transport_open(pmc->transport, &iface,
&pmc->fdarray, TS_SOFTWARE)) {
pr_err("failed to open transport");
goto failed;
Expand Down
4 changes: 2 additions & 2 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ static int port_initialize(struct port *p)
goto no_timers;
}
}
if (transport_open(p->trp, p->name, &p->fda, p->timestamping))
if (transport_open(p->trp, p->iface, &p->fda, p->timestamping))
goto no_tropen;

for (i = 0; i < N_TIMER_FDS; i++) {
Expand Down Expand Up @@ -1547,7 +1547,7 @@ static int port_renew_transport(struct port *p)
}
transport_close(p->trp, &p->fda);
port_clear_fda(p, FD_ANNOUNCE_TIMER);
res = transport_open(p->trp, p->name, &p->fda, p->timestamping);
res = transport_open(p->trp, p->iface, &p->fda, p->timestamping);
/* Need to call clock_fda_changed even if transport_open failed in
* order to update clock to the now closed descriptors. */
clock_fda_changed(p->clock);
Expand Down
5 changes: 3 additions & 2 deletions raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,16 @@ static void addr_to_mac(void *mac, struct address *addr)
memcpy(mac, &addr->sll.sll_addr, MAC_LEN);
}

static int raw_open(struct transport *t, const char *name,
static int raw_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type ts_type)
{
struct raw *raw = container_of(t, struct raw, t);
unsigned char ptp_dst_mac[MAC_LEN];
unsigned char p2p_dst_mac[MAC_LEN];
int efd, gfd;
char *str;
char *str, *name;

name = iface->ts_label;
str = config_get_string(t->cfg, name, "ptp_dst_mac");
if (str2mac(str, ptp_dst_mac)) {
pr_err("invalid ptp_dst_mac %s", str);
Expand Down
4 changes: 2 additions & 2 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ int transport_close(struct transport *t, struct fdarray *fda)
return t->close(t, fda);
}

int transport_open(struct transport *t, const char *name,
int transport_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type tt)
{
return t->open(t, name, fda, tt);
return t->open(t, iface, fda, tt);
}

int transport_recv(struct transport *t, int fd, struct ptp_message *msg)
Expand Down
3 changes: 2 additions & 1 deletion transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "msg.h"

struct config;
struct interface;

/* Values from networkProtocol enumeration 7.4.1 Table 3 */
enum transport_type {
Expand Down Expand Up @@ -54,7 +55,7 @@ struct transport;

int transport_close(struct transport *t, struct fdarray *fda);

int transport_open(struct transport *t, const char *name,
int transport_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type tt);

int transport_recv(struct transport *t, int fd, struct ptp_message *msg);
Expand Down
4 changes: 2 additions & 2 deletions transport_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct transport {

int (*close)(struct transport *t, struct fdarray *fda);

int (*open)(struct transport *t, const char *name, struct fdarray *fda,
enum timestamp_type tt);
int (*open)(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type tt);

int (*recv)(struct transport *t, int fd, void *buf, int buflen,
struct address *addr, struct hw_timestamp *hwts);
Expand Down
7 changes: 4 additions & 3 deletions udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ enum { MC_PRIMARY, MC_PDELAY };

static struct in_addr mcast_addr[2];

static int udp_open(struct transport *t, const char *name, struct fdarray *fda,
enum timestamp_type ts_type)
static int udp_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type ts_type)
{
struct udp *udp = container_of(t, struct udp, t);
uint8_t event_dscp, general_dscp;
int efd, gfd, ttl;
char *name = iface->name;

ttl = config_get_int(t->cfg, name, "udp_ttl");
udp->mac.len = 0;
Expand All @@ -180,7 +181,7 @@ static int udp_open(struct transport *t, const char *name, struct fdarray *fda,
if (gfd < 0)
goto no_general;

if (sk_timestamping_init(efd, name, ts_type, TRANS_UDP_IPV4))
if (sk_timestamping_init(efd, iface->ts_label, ts_type, TRANS_UDP_IPV4))
goto no_timestamping;

if (sk_general_init(gfd))
Expand Down
7 changes: 4 additions & 3 deletions udp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ enum { MC_PRIMARY, MC_PDELAY };

static struct in6_addr mc6_addr[2];

static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
enum timestamp_type ts_type)
static int udp6_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type ts_type)
{
struct udp6 *udp6 = container_of(t, struct udp6, t);
uint8_t event_dscp, general_dscp;
int efd, gfd, hop_limit;
char *name = iface->name;

hop_limit = config_get_int(t->cfg, name, "udp_ttl");
udp6->mac.len = 0;
Expand All @@ -190,7 +191,7 @@ static int udp6_open(struct transport *t, const char *name, struct fdarray *fda,
if (gfd < 0)
goto no_general;

if (sk_timestamping_init(efd, name, ts_type, TRANS_UDP_IPV6))
if (sk_timestamping_init(efd, iface->ts_label, ts_type, TRANS_UDP_IPV6))
goto no_timestamping;

if (sk_general_init(gfd))
Expand Down
3 changes: 2 additions & 1 deletion uds.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ static int uds_close(struct transport *t, struct fdarray *fda)
return 0;
}

static int uds_open(struct transport *t, const char *name, struct fdarray *fda,
static int uds_open(struct transport *t, struct interface *iface, struct fdarray *fda,
enum timestamp_type tt)
{
int fd, err;
struct sockaddr_un sa;
struct uds *uds = container_of(t, struct uds, t);
char *uds_path = config_get_string(t->cfg, NULL, "uds_address");
char *name = iface->name;

fd = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (fd < 0) {
Expand Down

0 comments on commit 8923bcd

Please sign in to comment.