From e47549e73f61225d8bb2e179847d55196d884f67 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Fri, 30 Dec 2011 11:04:20 +0100 Subject: [PATCH] Ignore messages from ourselves and from the wrong domain. Signed-off-by: Richard Cochran --- port.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/port.c b/port.c index 7eb096f..e762b1f 100644 --- a/port.c +++ b/port.c @@ -229,6 +229,26 @@ static int port_clr_tmo(int fd) return timerfd_settime(fd, 0, &tmo, NULL); } +static int port_ignore(struct port *p, struct ptp_message *m) +{ + struct ClockIdentity c1, c2; + + if (pid_eq(&m->header.sourcePortIdentity, &p->portIdentity)) { + return 1; + } + if (m->header.domainNumber != clock_domain_number(p->clock)) { + return 1; + } + + c1 = clock_identity(p->clock); + c2 = m->header.sourcePortIdentity.clockIdentity; + + if (0 == memcmp(&c1, &c2, sizeof(c1))) { + return 1; + } + return 0; +} + static int port_set_announce_tmo(struct port *p) { struct itimerspec tmo = { @@ -876,12 +896,15 @@ enum fsm_event port_event(struct port *p, int fd_index) msg_put(msg); return EV_FAULT_DETECTED; } - if (msg_post_recv(msg, cnt)) { pr_err("port %hu: bad message", portnum(p)); msg_put(msg); return EV_NONE; } + if (port_ignore(p, msg)) { + msg_put(msg); + return EV_NONE; + } switch (msg_type(msg)) { case SYNC: