How to add mbuf to the head of mbuf chain
How to add mbuf to the head of mbuf chain
- Subject: How to add mbuf to the head of mbuf chain
- From: Dmitriy Arekhta <email@hidden>
- Date: Thu, 17 Dec 2009 19:15:24 +0200
Hi List,
I'm working with interface filter and I should add to the output network packets custom header. In my ctl_send routine I have pointer to the source mbuf, so I do the following to chain custom mbuf to front:
UInt32 srcMbufDataLen = mbuf_chain_size(m); // len of current buffer
UInt32 dstMbufDataLen = srcMbufDataLen;
mbuf_t dstMbuf = NULL; // mbuf that will be passed to dlil
mbuf_t mbufToSend = m;
unsigned int dstMbufChunks = 1;
UInt32 srcMbufOffset = 0;
errno_t result = KERN_SUCCESS;
KTHPAdapter *adapter = static_cast<KTHPAdapter *>(userdata);
if (adapter->fFilter.IsThpModeEnabled)
{
dstMbufDataLen += sizeof(KTHPPacketHeader);
// Let's try to allocate new mbuf
result = mbuf_allocpacket(MBUF_DONTWAIT, // blocking or non-blocking
sizeof(KTHPPacketHeader), // entire packet len
&dstMbufChunks, // total packet chunks
&dstMbuf
);
if (result != KERN_SUCCESS || !dstMbuf || !mbuf_data(dstMbuf))
{
ALERT(dstMbufDataLen, result, "Couldn't allocate packet to send, dstMbufDataLen, result");
mbuf_freem(m);
return result;
}
mbuf_setlen(dstMbuf, sizeof(KTHPPacketHeader));
mbufToSend = dstMbuf;
mbuf_setnext(mbufToSend, m);
// Update an old packets
for(mbuf_t c = m; c != NULL; c = mbuf_next(c))
{
mbuf_pkthdr_setheader(c, mbuf_data(mbufToSend));
}
mbuf_pkthdr_setlen(m, dstMbufDataLen);
// Update the new packet
mbuf_setflags(mbufToSend, mbuf_flags(m));
mbuf_settype(mbufToSend, mbuf_type(m));
mbuf_pkthdr_setheader(mbufToSend, 0);
mbuf_pkthdr_setlen(mbufToSend, dstMbufDataLen);
// Clear status fiels of the old mbuf
mbuf_setflags(m, 0); }
When I try to send this packet to the network interface I got the kernel panic in m_freem_list(struct mbuf *m)
panic(cpu 0 caller 0x0038DA21): assertion failed: m->m_ext.ext_free == m_16kfree, file: /SourceCache/xnu/xnu-1228.15.4/bsd/kern/uipc_mbuf.c, line: 3639
What do I do wrong? Any advice?
Thanks :)
Dmitri
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden