Since commit 7fe69e7ba0c3bdce88d3a89d5ed43d0b382ef022 management messages are dropped in some cases because the tlv_count isn't 1. Further analysis shows that this is the case when the message is forwarded in clock_forward_mgmt_msg(). This is because msg_post_recv() will append TLVs and - in the forwarding case - there is already one TLV in the list, which results in tlv_count being 2 and thus dropped in subsequent code.
msg_post_recv() is intended to be the cleanup code for msg_pre_send() which is called earlier. For the TLVs to be correct, we have to drop them entirely and let them recreate in msg_post_recv(). Signed-off-by: Michael Walle <[email protected]> --- This is the first (not preferred) variant to fix this. It isn't that invasive as the second one. clock.c | 1 + msg.c | 18 ++++++++++++------ msg.h | 7 +++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/clock.c b/clock.c index 7bbb848..fb5b6cc 100644 --- a/clock.c +++ b/clock.c @@ -1290,6 +1290,7 @@ static void clock_forward_mgmt_msg(struct clock *c, struct port *p, struct ptp_m if (clock_do_forward_mgmt(c, p, c->uds_port, msg, &msg_ready)) pr_err("uds port: management forward failed"); if (msg_ready) { + msg_tlv_recycle(msg); msg_post_recv(msg, pdulen); msg->management.boundaryHops++; } diff --git a/msg.c b/msg.c index 090715b..bc1199e 100644 --- a/msg.c +++ b/msg.c @@ -496,6 +496,17 @@ void msg_tlv_attach(struct ptp_message *msg, struct tlv_extra *extra) msg->tlv_count++; } +void msg_tlv_recycle(struct ptp_message *msg) +{ + struct tlv_extra *extra; + + while ((extra = TAILQ_FIRST(&msg->tlv_list)) != NULL) { + TAILQ_REMOVE(&msg->tlv_list, extra, list); + tlv_extra_recycle(extra); + } + msg->tlv_count = 0; +} + const char *msg_type_string(int type) { switch (type) { @@ -559,18 +570,13 @@ void msg_print(struct ptp_message *m, FILE *fp) void msg_put(struct ptp_message *m) { - struct tlv_extra *extra; - m->refcnt--; if (m->refcnt) { return; } pool_stats.count++; pool_debug("recycle", m); - while ((extra = TAILQ_FIRST(&m->tlv_list)) != NULL) { - TAILQ_REMOVE(&m->tlv_list, extra, list); - tlv_extra_recycle(extra); - } + msg_tlv_recycle(m); TAILQ_INSERT_HEAD(&msg_pool, m, list); } diff --git a/msg.h b/msg.h index 58a916c..6a3509b 100644 --- a/msg.h +++ b/msg.h @@ -280,6 +280,13 @@ struct tlv_extra *msg_tlv_append(struct ptp_message *msg, int length); void msg_tlv_attach(struct ptp_message *msg, struct tlv_extra *extra); /** + * Drop all TLVs of a message. + * + * @param msg A message obtained using msg_allocate(). + */ +void msg_tlv_recycle(struct ptp_message *msg); + +/** * Obtain the transportSpecific field from a message. * @param m Message to test. * @return The value of the transportSpecific field. Note that the -- 2.11.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linuxptp-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
