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
parent
aa142c5240
commit
7d54d444f5
22
msg.c
22
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue