Leave some headroom in the message buffers.

This room will be used by the Layer 2 protocols.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-03-17 17:07:13 +01:00
parent aa142c5240
commit 7d54d444f5
1 changed files with 18 additions and 4 deletions

20
msg.c
View File

@ -28,6 +28,16 @@
#define VERSION_MASK 0x0f
#define VERSION 0x02
/*
* 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;
static TAILQ_HEAD(msg_pool, ptp_message) msg_pool;
static void announce_pre_send(struct announce_msg *m)
@ -123,11 +133,15 @@ static void timestamp_pre_send(struct Timestamp *ts)
struct ptp_message *msg_allocate(void)
{
struct message_storage *s;
struct ptp_message *m = TAILQ_FIRST(&msg_pool);
if (!m)
m = malloc(sizeof(*m));
if (m)
if (!m) {
s = malloc(sizeof(*s));
if (s) {
m = &s->msg;
m->refcnt = 1;
}
}
return m;
}