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. Therefore, make msg_post_recv() and msg_pre_send() symmetrical and cleanup the tlv_list and tlv_count. Signed-off-by: Michael Walle <[email protected]> --- msg.c | 21 +++++++++++++++------ msg.h | 7 +++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/msg.c b/msg.c index 6c20c97..e408ea4 100644 --- a/msg.c +++ b/msg.c @@ -193,6 +193,8 @@ static int suffix_post_recv(struct ptp_message *msg, int len) if (!ptr) return 0; + msg_tlv_recycle(msg); + while (len >= sizeof(struct TLV)) { extra = tlv_extra_alloc(); if (!extra) { @@ -498,6 +500,18 @@ 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) { @@ -561,18 +575,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
