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 | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/msg.c b/msg.c
index 6c20c97..d5b651f 100644
--- a/msg.c
+++ b/msg.c
@@ -174,6 +174,16 @@ static struct tlv_extra *msg_tlv_prepare(struct 
ptp_message *msg, int length)
        return extra;
 }
 
+static 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);
+       }
+}
+
 static void port_id_post_recv(struct PortIdentity *pid)
 {
        pid->portNumber = ntohs(pid->portNumber);
@@ -235,6 +245,7 @@ static void suffix_pre_send(struct ptp_message *msg)
                tlv->type = htons(tlv->type);
                tlv->length = htons(tlv->length);
        }
+       msg_tlv_recycle(msg);
 }
 
 static void timestamp_post_recv(struct ptp_message *m, struct Timestamp *ts)
@@ -561,18 +572,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);
 }
 
-- 
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

Reply via email to