msg: Introduce a TLV list.

In order to support multiple TLVs per message, a list is needed.
This patch adds the list to the message structure.  This list will
eventually replace the 'last_tlv' field.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2018-01-25 09:01:55 -08:00
parent c8d9d05e7a
commit 22b894b687
2 changed files with 17 additions and 4 deletions

12
msg.c
View File

@ -204,6 +204,7 @@ struct ptp_message *msg_allocate(void)
if (m) {
memset(m, 0, sizeof(*m));
m->refcnt = 1;
TAILQ_INIT(&m->tlv_list);
}
return m;
@ -447,12 +448,19 @@ 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) {
if (m->refcnt) {
return;
}
pool_stats.count++;
pool_debug("recycle", m);
TAILQ_INSERT_HEAD(&msg_pool, m, list);
while ((extra = TAILQ_FIRST(&m->tlv_list)) != NULL) {
TAILQ_REMOVE(&m->tlv_list, extra, list);
tlv_extra_recycle(extra);
}
TAILQ_INSERT_HEAD(&msg_pool, m, list);
}
int msg_sots_missing(struct ptp_message *m)

5
msg.h
View File

@ -219,6 +219,11 @@ struct ptp_message {
* sent to.
*/
struct address address;
/**
* List of TLV descriptors. Each item in the list contains
* pointers to the appended TLVs.
*/
TAILQ_HEAD(tlv_list, tlv_extra) tlv_list;
/**
* Contains the number of TLVs in the suffix.
*/