Make sure that we handle only one PTP clock (node). This is for an extra safety.
Signed-off-by: Jiri Benc <jb...@redhat.com> --- phc2sys.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index e184fc9cd637..108a03f83b8b 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -102,6 +102,8 @@ struct node { int pmc_ds_requested; uint64_t pmc_last_update; int state_changed; + int clock_identity_set; + struct ClockIdentity clock_identity; LIST_HEAD(port_head, port) ports; LIST_HEAD(clock_head, clock) clocks; struct clock *master; @@ -607,6 +609,15 @@ static int do_loop(struct node *node, int subscriptions) return 0; /* unreachable */ } +static int check_clock_identity(struct node *node, struct ptp_message *msg) +{ + if (!node->clock_identity_set) + return 1; + return !memcmp(&node->clock_identity, + &msg->header.sourcePortIdentity.clockIdentity, + sizeof(struct ClockIdentity)); +} + static int is_msg_mgt(struct ptp_message *msg) { struct TLV *tlv; @@ -767,7 +778,8 @@ static int run_pmc(struct node *node, int timeout, int ds_id, if (!*msg) continue; - if (!is_msg_mgt(*msg) || + if (!check_clock_identity(node, *msg) || + !is_msg_mgt(*msg) || recv_subscribed(node, *msg, ds_id) || get_mgt_id(*msg) != ds_id) { msg_put(*msg); @@ -885,6 +897,24 @@ out: return res; } +static int run_pmc_clock_identity(struct node *node, int timeout) +{ + struct ptp_message *msg; + struct defaultDS *dds; + int res; + + res = run_pmc(node, timeout, DEFAULT_DATA_SET, &msg); + if (res <= 0) + return res; + + dds = (struct defaultDS *)get_mgt_data(msg); + memcpy(&node->clock_identity, &dds->clockIdentity, + sizeof(struct ClockIdentity)); + node->clock_identity_set = 1; + msg_put(msg); + return 1; +} + static void close_pmc(struct node *node) { pmc_destroy(node->pmc); @@ -903,7 +933,7 @@ static int auto_init_ports(struct node *node, int add_rt) char iface[IFNAMSIZ]; while (1) { - res = run_pmc(node, 1000, PORT_ENUMERATION_NP, &msg); + res = run_pmc_clock_identity(node, 1000); if (res < 0) return -1; if (res > 0) @@ -911,6 +941,11 @@ static int auto_init_ports(struct node *node, int add_rt) /* res == 0, timeout */ pr_notice("Waiting for ptp4l..."); } + res = run_pmc(node, 1000, PORT_ENUMERATION_NP, &msg); + if (res <= 0) { + pr_err("failed to enumerate ports"); + return -1; + } pen = get_mgt_data(msg); res = run_pmc_subscribe(node, 1000); -- 1.7.6.5 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel