From 7d54d444f58086f1f1ff65b2e8a448beecdae588 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 17 Mar 2012 17:07:13 +0100 Subject: [PATCH] Leave some headroom in the message buffers. This room will be used by the Layer 2 protocols. Signed-off-by: Richard Cochran --- msg.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/msg.c b/msg.c index b3e5bf1..e7168b0 100644 --- a/msg.c +++ b/msg.c @@ -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) - m->refcnt = 1; + if (!m) { + s = malloc(sizeof(*s)); + if (s) { + m = &s->msg; + m->refcnt = 1; + } + } return m; }