2011-11-06 16:02:57 +08:00
|
|
|
/**
|
|
|
|
* @file msg.c
|
|
|
|
* @note Copyright (C) 2011 Richard Cochran <richardcochran@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <malloc.h>
|
2012-07-08 02:10:28 +08:00
|
|
|
#include <string.h>
|
2011-11-06 16:02:57 +08:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
2012-08-28 03:09:10 +08:00
|
|
|
#include "contain.h"
|
2011-11-06 16:02:57 +08:00
|
|
|
#include "msg.h"
|
2012-03-11 16:53:28 +08:00
|
|
|
#include "print.h"
|
2012-07-29 13:24:59 +08:00
|
|
|
#include "tlv.h"
|
2011-11-06 16:02:57 +08:00
|
|
|
|
|
|
|
#define VERSION_MASK 0x0f
|
|
|
|
#define VERSION 0x02
|
|
|
|
|
2012-03-18 00:07:13 +08:00
|
|
|
/*
|
|
|
|
* Head room fits a VLAN Ethernet header, and 'msg' is 32 bit aligned.
|
|
|
|
*/
|
|
|
|
#define MSG_HEADROOM 20
|
|
|
|
|
|
|
|
struct message_storage {
|
|
|
|
unsigned char reserved[MSG_HEADROOM];
|
|
|
|
struct ptp_message msg;
|
|
|
|
} PACKED;
|
|
|
|
|
2011-11-06 16:02:57 +08:00
|
|
|
static TAILQ_HEAD(msg_pool, ptp_message) msg_pool;
|
|
|
|
|
2012-07-08 02:10:28 +08:00
|
|
|
static struct {
|
|
|
|
int total;
|
|
|
|
int count;
|
|
|
|
} pool_stats;
|
|
|
|
|
|
|
|
#ifdef DEBUG_POOL
|
|
|
|
static void pool_debug(const char *str, void *addr)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "*** %p %10s total %d count %d used %d\n",
|
|
|
|
addr, str, pool_stats.total, pool_stats.count,
|
|
|
|
pool_stats.total - pool_stats.count);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void pool_debug(const char *str, void *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-27 21:35:35 +08:00
|
|
|
static void announce_pre_send(struct announce_msg *m)
|
|
|
|
{
|
|
|
|
m->currentUtcOffset = htons(m->currentUtcOffset);
|
|
|
|
m->grandmasterClockQuality.offsetScaledLogVariance =
|
|
|
|
htons(m->grandmasterClockQuality.offsetScaledLogVariance);
|
|
|
|
m->stepsRemoved = htons(m->stepsRemoved);
|
|
|
|
}
|
|
|
|
|
2011-11-06 16:02:57 +08:00
|
|
|
static void announce_post_recv(struct announce_msg *m)
|
|
|
|
{
|
|
|
|
m->currentUtcOffset = ntohs(m->currentUtcOffset);
|
|
|
|
m->grandmasterClockQuality.offsetScaledLogVariance =
|
|
|
|
ntohs(m->grandmasterClockQuality.offsetScaledLogVariance);
|
|
|
|
m->stepsRemoved = ntohs(m->stepsRemoved);
|
|
|
|
}
|
|
|
|
|
2012-08-10 02:33:47 +08:00
|
|
|
int64_t host2net64(int64_t val)
|
2011-11-06 16:02:57 +08:00
|
|
|
{
|
|
|
|
return __cpu_to_be64(val);
|
|
|
|
}
|
|
|
|
|
2012-08-10 02:33:47 +08:00
|
|
|
int64_t net2host64(int64_t val)
|
2011-11-06 16:02:57 +08:00
|
|
|
{
|
|
|
|
return __be64_to_cpu(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hdr_post_recv(struct ptp_header *m)
|
|
|
|
{
|
|
|
|
if ((m->ver & VERSION_MASK) != VERSION)
|
|
|
|
return -1;
|
|
|
|
m->messageLength = ntohs(m->messageLength);
|
|
|
|
m->correction = net2host64(m->correction);
|
|
|
|
m->sourcePortIdentity.portNumber = ntohs(m->sourcePortIdentity.portNumber);
|
|
|
|
m->sequenceId = ntohs(m->sequenceId);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hdr_pre_send(struct ptp_header *m)
|
|
|
|
{
|
|
|
|
m->messageLength = htons(m->messageLength);
|
|
|
|
m->correction = host2net64(m->correction);
|
|
|
|
m->sourcePortIdentity.portNumber = htons(m->sourcePortIdentity.portNumber);
|
|
|
|
m->sequenceId = htons(m->sequenceId);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *msg_type_string(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case SYNC:
|
|
|
|
return "SYNC";
|
|
|
|
case DELAY_REQ:
|
|
|
|
return "DELAY_REQ";
|
|
|
|
case PDELAY_REQ:
|
|
|
|
return "PDELAY_REQ";
|
|
|
|
case PDELAY_RESP:
|
|
|
|
return "PDELAY_RESP";
|
|
|
|
case FOLLOW_UP:
|
|
|
|
return "FOLLOW_UP";
|
|
|
|
case DELAY_RESP:
|
|
|
|
return "DELAY_RESP";
|
|
|
|
case PDELAY_RESP_FOLLOW_UP:
|
|
|
|
return "PDELAY_RESP_FOLLOW_UP";
|
|
|
|
case ANNOUNCE:
|
|
|
|
return "ANNOUNCE";
|
|
|
|
case SIGNALING:
|
|
|
|
return "SIGNALING";
|
|
|
|
case MANAGEMENT:
|
|
|
|
return "MANAGEMENT";
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2012-04-02 23:20:04 +08:00
|
|
|
static void port_id_post_recv(struct PortIdentity *pid)
|
|
|
|
{
|
|
|
|
pid->portNumber = ntohs(pid->portNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void port_id_pre_send(struct PortIdentity *pid)
|
|
|
|
{
|
|
|
|
pid->portNumber = htons(pid->portNumber);
|
|
|
|
}
|
|
|
|
|
2012-07-29 00:54:26 +08:00
|
|
|
static int suffix_post_recv(uint8_t *ptr, int len)
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
struct TLV *tlv;
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (cnt = 0; len > sizeof(struct TLV); cnt++) {
|
|
|
|
tlv = (struct TLV *) ptr;
|
|
|
|
tlv->type = ntohs(tlv->type);
|
|
|
|
tlv->length = ntohs(tlv->length);
|
|
|
|
if (tlv->length % 2) {
|
2013-01-22 00:41:17 +08:00
|
|
|
return -1;
|
2012-07-29 00:54:26 +08:00
|
|
|
}
|
|
|
|
len -= sizeof(struct TLV);
|
|
|
|
ptr += sizeof(struct TLV);
|
|
|
|
if (tlv->length > len) {
|
2013-01-22 00:41:17 +08:00
|
|
|
return -1;
|
2012-07-29 00:54:26 +08:00
|
|
|
}
|
|
|
|
len -= tlv->length;
|
|
|
|
ptr += tlv->length;
|
2013-01-22 00:41:17 +08:00
|
|
|
if (tlv_post_recv(tlv)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-07-29 00:54:26 +08:00
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2012-07-29 01:14:04 +08:00
|
|
|
static void suffix_pre_send(uint8_t *ptr, int cnt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct TLV *tlv;
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
|
|
tlv = (struct TLV *) ptr;
|
2012-07-29 13:24:59 +08:00
|
|
|
tlv_pre_send(tlv);
|
2012-07-29 01:14:04 +08:00
|
|
|
ptr += sizeof(struct TLV) + tlv->length;
|
|
|
|
tlv->type = htons(tlv->type);
|
|
|
|
tlv->length = htons(tlv->length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 16:02:57 +08:00
|
|
|
static void timestamp_post_recv(struct ptp_message *m, struct Timestamp *ts)
|
|
|
|
{
|
|
|
|
uint32_t lsb = ntohl(ts->seconds_lsb);
|
|
|
|
uint16_t msb = ntohs(ts->seconds_msb);
|
|
|
|
|
|
|
|
m->ts.pdu.sec = ((uint64_t)lsb) | (((uint64_t)msb) << 32);
|
|
|
|
m->ts.pdu.nsec = ntohl(ts->nanoseconds);
|
|
|
|
}
|
|
|
|
|
2011-12-28 00:31:36 +08:00
|
|
|
static void timestamp_pre_send(struct Timestamp *ts)
|
2011-11-06 16:02:57 +08:00
|
|
|
{
|
2011-12-28 00:31:36 +08:00
|
|
|
ts->seconds_lsb = htonl(ts->seconds_lsb);
|
|
|
|
ts->seconds_msb = htons(ts->seconds_msb);
|
|
|
|
ts->nanoseconds = htonl(ts->nanoseconds);
|
2011-11-06 16:02:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* public methods */
|
|
|
|
|
|
|
|
struct ptp_message *msg_allocate(void)
|
|
|
|
{
|
2012-03-18 00:07:13 +08:00
|
|
|
struct message_storage *s;
|
2011-11-06 16:02:57 +08:00
|
|
|
struct ptp_message *m = TAILQ_FIRST(&msg_pool);
|
2012-07-08 02:10:28 +08:00
|
|
|
|
|
|
|
if (m) {
|
|
|
|
TAILQ_REMOVE(&msg_pool, m, list);
|
|
|
|
pool_stats.count--;
|
|
|
|
pool_debug("dequeue", m);
|
|
|
|
} else {
|
2012-03-18 00:07:13 +08:00
|
|
|
s = malloc(sizeof(*s));
|
|
|
|
if (s) {
|
|
|
|
m = &s->msg;
|
2012-07-08 02:10:28 +08:00
|
|
|
pool_stats.total++;
|
|
|
|
pool_debug("allocate", m);
|
2012-03-18 00:07:13 +08:00
|
|
|
}
|
|
|
|
}
|
2012-07-08 02:10:28 +08:00
|
|
|
if (m) {
|
|
|
|
memset(m, 0, sizeof(*m));
|
|
|
|
m->refcnt = 1;
|
|
|
|
}
|
|
|
|
|
2011-11-06 16:02:57 +08:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2012-08-28 03:09:10 +08:00
|
|
|
void msg_cleanup(void)
|
|
|
|
{
|
|
|
|
struct message_storage *s;
|
|
|
|
struct ptp_message *m;
|
|
|
|
while ((m = TAILQ_FIRST(&msg_pool)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&msg_pool, m, list);
|
|
|
|
s = container_of(m, struct message_storage, msg);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 16:02:57 +08:00
|
|
|
void msg_get(struct ptp_message *m)
|
|
|
|
{
|
|
|
|
m->refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int msg_post_recv(struct ptp_message *m, int cnt)
|
|
|
|
{
|
2012-06-04 01:56:56 +08:00
|
|
|
int pdulen, type;
|
2012-07-29 00:54:26 +08:00
|
|
|
uint8_t *suffix = NULL;
|
2011-11-06 16:02:57 +08:00
|
|
|
|
|
|
|
if (cnt < sizeof(struct ptp_header))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (hdr_post_recv(&m->header))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
type = msg_type(m);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYNC:
|
2012-06-04 01:56:56 +08:00
|
|
|
pdulen = sizeof(struct sync_msg);
|
|
|
|
break;
|
|
|
|
case DELAY_REQ:
|
|
|
|
pdulen = sizeof(struct delay_req_msg);
|
|
|
|
break;
|
|
|
|
case PDELAY_REQ:
|
|
|
|
pdulen = sizeof(struct pdelay_req_msg);
|
|
|
|
break;
|
|
|
|
case PDELAY_RESP:
|
|
|
|
pdulen = sizeof(struct pdelay_resp_msg);
|
|
|
|
break;
|
|
|
|
case FOLLOW_UP:
|
|
|
|
pdulen = sizeof(struct follow_up_msg);
|
|
|
|
break;
|
|
|
|
case DELAY_RESP:
|
|
|
|
pdulen = sizeof(struct delay_resp_msg);
|
|
|
|
break;
|
|
|
|
case PDELAY_RESP_FOLLOW_UP:
|
|
|
|
pdulen = sizeof(struct pdelay_resp_fup_msg);
|
|
|
|
break;
|
|
|
|
case ANNOUNCE:
|
|
|
|
pdulen = sizeof(struct announce_msg);
|
|
|
|
break;
|
|
|
|
case SIGNALING:
|
|
|
|
pdulen = sizeof(struct signaling_msg);
|
|
|
|
break;
|
|
|
|
case MANAGEMENT:
|
|
|
|
pdulen = sizeof(struct management_msg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt < pdulen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYNC:
|
2011-11-06 16:02:57 +08:00
|
|
|
timestamp_post_recv(m, &m->sync.originTimestamp);
|
|
|
|
break;
|
|
|
|
case DELAY_REQ:
|
|
|
|
break;
|
|
|
|
case PDELAY_REQ:
|
|
|
|
break;
|
|
|
|
case PDELAY_RESP:
|
2012-04-02 23:20:04 +08:00
|
|
|
timestamp_post_recv(m, &m->pdelay_resp.requestReceiptTimestamp);
|
|
|
|
port_id_post_recv(&m->pdelay_resp.requestingPortIdentity);
|
2011-11-06 16:02:57 +08:00
|
|
|
break;
|
|
|
|
case FOLLOW_UP:
|
|
|
|
timestamp_post_recv(m, &m->follow_up.preciseOriginTimestamp);
|
2012-07-29 00:54:26 +08:00
|
|
|
suffix = m->follow_up.suffix;
|
2011-11-06 16:02:57 +08:00
|
|
|
break;
|
|
|
|
case DELAY_RESP:
|
|
|
|
timestamp_post_recv(m, &m->delay_resp.receiveTimestamp);
|
2012-07-29 00:54:26 +08:00
|
|
|
suffix = m->delay_resp.suffix;
|
2011-11-06 16:02:57 +08:00
|
|
|
break;
|
|
|
|
case PDELAY_RESP_FOLLOW_UP:
|
2012-04-02 23:20:04 +08:00
|
|
|
timestamp_post_recv(m, &m->pdelay_resp_fup.responseOriginTimestamp);
|
|
|
|
port_id_post_recv(&m->pdelay_resp_fup.requestingPortIdentity);
|
2012-07-29 00:54:26 +08:00
|
|
|
suffix = m->pdelay_resp_fup.suffix;
|
2011-11-06 16:02:57 +08:00
|
|
|
break;
|
|
|
|
case ANNOUNCE:
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &m->ts.host);
|
|
|
|
timestamp_post_recv(m, &m->announce.originTimestamp);
|
|
|
|
announce_post_recv(&m->announce);
|
2012-07-29 00:54:26 +08:00
|
|
|
suffix = m->announce.suffix;
|
2011-11-06 16:02:57 +08:00
|
|
|
break;
|
|
|
|
case SIGNALING:
|
2012-07-29 00:54:26 +08:00
|
|
|
suffix = m->signaling.suffix;
|
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case MANAGEMENT:
|
2012-07-29 00:54:26 +08:00
|
|
|
suffix = m->management.suffix;
|
2011-12-30 17:17:17 +08:00
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
}
|
2012-03-11 16:53:28 +08:00
|
|
|
|
|
|
|
if (msg_sots_missing(m)) {
|
|
|
|
pr_err("received %s without timestamp", msg_type_string(type));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-29 00:54:26 +08:00
|
|
|
m->tlv_count = suffix_post_recv(suffix, cnt - pdulen);
|
2013-01-22 00:41:17 +08:00
|
|
|
if (m->tlv_count == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2012-07-29 00:54:26 +08:00
|
|
|
|
2011-11-06 16:02:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int msg_pre_send(struct ptp_message *m)
|
|
|
|
{
|
|
|
|
int type;
|
2012-07-29 01:14:04 +08:00
|
|
|
uint8_t *suffix = NULL;
|
2011-11-06 16:02:57 +08:00
|
|
|
|
|
|
|
if (hdr_pre_send(&m->header))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
type = msg_type(m);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYNC:
|
2011-12-28 00:56:01 +08:00
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case DELAY_REQ:
|
|
|
|
break;
|
|
|
|
case PDELAY_REQ:
|
2012-04-02 23:20:04 +08:00
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case PDELAY_RESP:
|
2012-04-02 23:20:04 +08:00
|
|
|
timestamp_pre_send(&m->pdelay_resp.requestReceiptTimestamp);
|
|
|
|
port_id_pre_send(&m->pdelay_resp.requestingPortIdentity);
|
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case FOLLOW_UP:
|
2011-12-28 00:31:36 +08:00
|
|
|
timestamp_pre_send(&m->follow_up.preciseOriginTimestamp);
|
2012-07-29 01:14:04 +08:00
|
|
|
suffix = m->follow_up.suffix;
|
2011-12-28 00:31:36 +08:00
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case DELAY_RESP:
|
2011-12-28 00:31:36 +08:00
|
|
|
timestamp_pre_send(&m->delay_resp.receiveTimestamp);
|
|
|
|
m->delay_resp.requestingPortIdentity.portNumber =
|
|
|
|
htons(m->delay_resp.requestingPortIdentity.portNumber);
|
2012-07-29 01:14:04 +08:00
|
|
|
suffix = m->delay_resp.suffix;
|
2011-12-28 00:31:36 +08:00
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case PDELAY_RESP_FOLLOW_UP:
|
2012-04-02 23:20:04 +08:00
|
|
|
timestamp_pre_send(&m->pdelay_resp_fup.responseOriginTimestamp);
|
|
|
|
port_id_pre_send(&m->pdelay_resp_fup.requestingPortIdentity);
|
2012-07-29 01:14:04 +08:00
|
|
|
suffix = m->pdelay_resp_fup.suffix;
|
2012-04-02 23:20:04 +08:00
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case ANNOUNCE:
|
2011-12-27 21:35:35 +08:00
|
|
|
announce_pre_send(&m->announce);
|
2012-07-29 01:14:04 +08:00
|
|
|
suffix = m->announce.suffix;
|
2011-12-27 21:35:35 +08:00
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case SIGNALING:
|
2012-07-29 01:14:04 +08:00
|
|
|
suffix = m->signaling.suffix;
|
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
case MANAGEMENT:
|
2012-07-29 01:14:04 +08:00
|
|
|
suffix = m->management.suffix;
|
|
|
|
break;
|
2011-11-06 16:02:57 +08:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2012-07-29 01:14:04 +08:00
|
|
|
suffix_pre_send(suffix, m->tlv_count);
|
2011-11-06 16:02:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void msg_print(struct ptp_message *m, FILE *fp)
|
|
|
|
{
|
|
|
|
fprintf(fp,
|
|
|
|
"\t"
|
|
|
|
"%-10s "
|
|
|
|
// "versionPTP 0x%02X "
|
|
|
|
// "messageLength %hu "
|
|
|
|
// "domainNumber %u "
|
|
|
|
// "reserved1 0x%02X "
|
|
|
|
// "flagField 0x%02X%02X "
|
|
|
|
// "correction %lld "
|
|
|
|
// "reserved2 %u "
|
|
|
|
// "sourcePortIdentity ... "
|
|
|
|
"sequenceId %4hu "
|
|
|
|
// "control %u "
|
|
|
|
// "logMessageInterval %d "
|
|
|
|
,
|
|
|
|
msg_type_string(msg_type(m)),
|
|
|
|
// m->header.ver,
|
|
|
|
// m->header.messageLength,
|
|
|
|
// m->header.domainNumber,
|
|
|
|
// m->header.reserved1,
|
|
|
|
// m->header.flagField[0],
|
|
|
|
// m->header.flagField[1],
|
|
|
|
// m->header.correction,
|
|
|
|
// m->header.reserved2,
|
|
|
|
// m->header.sourcePortIdentity,
|
|
|
|
m->header.sequenceId
|
|
|
|
// m->header.control,
|
|
|
|
// m->header.logMessageInterval
|
|
|
|
);
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void msg_put(struct ptp_message *m)
|
|
|
|
{
|
|
|
|
m->refcnt--;
|
2012-07-08 02:10:28 +08:00
|
|
|
if (!m->refcnt) {
|
|
|
|
pool_stats.count++;
|
|
|
|
pool_debug("recycle", m);
|
2011-11-06 16:02:57 +08:00
|
|
|
TAILQ_INSERT_HEAD(&msg_pool, m, list);
|
2012-07-08 02:10:28 +08:00
|
|
|
}
|
2011-11-06 16:02:57 +08:00
|
|
|
}
|
2012-03-11 16:53:28 +08:00
|
|
|
|
|
|
|
int msg_sots_missing(struct ptp_message *m)
|
|
|
|
{
|
|
|
|
int type = msg_type(m);
|
|
|
|
switch (type) {
|
|
|
|
case SYNC:
|
|
|
|
case DELAY_REQ:
|
|
|
|
case PDELAY_REQ:
|
|
|
|
case PDELAY_RESP:
|
|
|
|
break;
|
|
|
|
case FOLLOW_UP:
|
|
|
|
case DELAY_RESP:
|
|
|
|
case PDELAY_RESP_FOLLOW_UP:
|
|
|
|
case ANNOUNCE:
|
|
|
|
case SIGNALING:
|
|
|
|
case MANAGEMENT:
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (!m->hwts.ts.tv_sec && !m->hwts.ts.tv_nsec) ? 1 : 0;
|
|
|
|
}
|