diff --git a/e2e_tc.c b/e2e_tc.c index 5a5c092..03b1a4f 100644 --- a/e2e_tc.c +++ b/e2e_tc.c @@ -147,7 +147,7 @@ enum fsm_event e2e_event(struct port *p, int fd_index) if (msg_sots_valid(msg)) { ts_add(&msg->hwts.ts, -p->rx_timestamp_offset); } - if (msg->header.flagField[0] & UNICAST) { + if (msg_unicast(msg)) { pl_warning(600, "cannot handle unicast messages!"); msg_put(msg); return EV_NONE; diff --git a/msg.h b/msg.h index 38d16ef..58a916c 100644 --- a/msg.h +++ b/msg.h @@ -394,6 +394,16 @@ static inline int msg_sots_valid(struct ptp_message *m) return !tmv_is_zero(m->hwts.ts); } +/** + * Test whether a message is a unicast message. + * @param m Message to test. + * @return One if the message is unicast, zero otherwise. + */ +static inline Boolean msg_unicast(struct ptp_message *m) +{ + return field_is_set(m, 0, UNICAST); +} + /** * Work around buggy 802.1AS switches. */ diff --git a/nsm.c b/nsm.c index 461ef7d..1a6475f 100644 --- a/nsm.c +++ b/nsm.c @@ -138,7 +138,7 @@ static void nsm_handle_msg(struct nsm *nsm, struct ptp_message *msg, FILE *fp) ntohs(nsm->nsm_delay_req->header.sequenceId)) { return; } - if (!(msg->header.flagField[0] & UNICAST)) { + if (!msg_unicast(msg)) { return; } diff --git a/p2p_tc.c b/p2p_tc.c index b2a444e..22ec9a7 100644 --- a/p2p_tc.c +++ b/p2p_tc.c @@ -150,7 +150,7 @@ enum fsm_event p2p_event(struct port *p, int fd_index) if (msg_sots_valid(msg)) { ts_add(&msg->hwts.ts, -p->rx_timestamp_offset); } - if (msg->header.flagField[0] & UNICAST) { + if (msg_unicast(msg)) { pl_warning(600, "cannot switch unicast messages!"); msg_put(msg); return EV_NONE; diff --git a/port.c b/port.c index 957a3b4..a777701 100644 --- a/port.c +++ b/port.c @@ -697,7 +697,7 @@ static int port_nsm_reply(struct port *p, struct ptp_message *m) if (!p->hybrid_e2e) { return 0; } - if (!(m->header.flagField[0] & UNICAST)) { + if (!msg_unicast(m)) { return 0; } TAILQ_FOREACH(extra, &m->tlv_list, list) { @@ -1753,7 +1753,7 @@ static int process_delay_req(struct port *p, struct ptp_message *m) msg->delay_resp.requestingPortIdentity = m->header.sourcePortIdentity; - if (p->hybrid_e2e && m->header.flagField[0] & UNICAST) { + if (p->hybrid_e2e && msg_unicast(m)) { msg->address = m->address; msg->header.flagField[0] |= UNICAST; msg->header.logMessageInterval = 0x7f; @@ -1819,7 +1819,7 @@ void process_delay_resp(struct port *p, struct ptp_message *m) if (p->logMinDelayReqInterval == rsp->hdr.logMessageInterval) { return; } - if (m->header.flagField[0] & UNICAST) { + if (msg_unicast(m)) { /* Unicast responses have logMinDelayReqInterval set to 0x7F. */ return; } @@ -2563,7 +2563,7 @@ int port_prepare_and_send(struct port *p, struct ptp_message *msg, if (msg_pre_send(msg)) { return -1; } - if (msg->header.flagField[0] & UNICAST) { + if (msg_unicast(msg)) { cnt = transport_sendto(p->trp, &p->fda, event, msg); } else { cnt = transport_send(p->trp, &p->fda, event, msg);