From b59a739d0fa7fda2d91328a025b6db40dc35ba6d Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Mon, 6 May 2019 21:04:25 -0700 Subject: [PATCH] Ignore signaling messages on target port mismatch. IEEE 1588 specifies dropping signaling messages if the targetPortIdentity does not match the receiving port. Up until now the unicast code did check that field, but only for the unicast transmission request and cancel operations. This patch moves the target port identity check so that it applies to each and every received signaling message. Signed-off-by: Richard Cochran --- port_signaling.c | 13 +++++++++++++ unicast_client.c | 11 ----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/port_signaling.c b/port_signaling.c index f845d36..ec3ad87 100644 --- a/port_signaling.c +++ b/port_signaling.c @@ -21,6 +21,13 @@ #include "unicast_client.h" #include "unicast_service.h" +static struct PortIdentity wildcard = { + .clockIdentity = { + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} + }, + .portNumber = 0xffff, +}; + struct ptp_message *port_signaling_construct(struct port *p, struct address *address, struct PortIdentity *tpid) @@ -67,6 +74,12 @@ int process_signaling(struct port *p, struct ptp_message *m) break; } + /* Ignore signaling messages not addressed to this port. */ + if (!pid_eq(&m->signaling.targetPortIdentity, &p->portIdentity) && + !pid_eq(&m->signaling.targetPortIdentity, &wildcard)) { + return 0; + } + TAILQ_FOREACH(extra, &m->tlv_list, list) { switch (extra->tlv->type) { case TLV_REQUEST_UNICAST_TRANSMISSION: diff --git a/unicast_client.c b/unicast_client.c index de5eee9..91b99ed 100644 --- a/unicast_client.c +++ b/unicast_client.c @@ -25,13 +25,6 @@ #define E2E_SYDY_MASK (1 << ANNOUNCE | 1 << SYNC | 1 << DELAY_RESP) #define P2P_SYDY_MASK (1 << ANNOUNCE | 1 << SYNC) -static struct PortIdentity wildcard = { - .clockIdentity = { - {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} - }, - .portNumber = 0xffff, -}; - static int attach_ack(struct ptp_message *msg, uint8_t message_type_flags) { struct ack_cancel_unicast_xmit_tlv *ack; @@ -101,10 +94,6 @@ static struct unicast_master_address *unicast_client_ok(struct port *p, if (!unicast_client_enabled(p)) { return NULL; } - if (!pid_eq(&m->signaling.targetPortIdentity, &p->portIdentity) && - !pid_eq(&m->signaling.targetPortIdentity, &wildcard)) { - return NULL; - } STAILQ_FOREACH(ucma, &p->unicast_master_table->addrs, list) { if (addreq(transport_type(p->trp), &ucma->address, &m->address)) { break;