Re: How to add mbuf to the head of mbuf chain
Re: How to add mbuf to the head of mbuf chain
- Subject: Re: How to add mbuf to the head of mbuf chain
- From: Adi Masputra <email@hidden>
- Date: Thu, 17 Dec 2009 13:37:54 -0800
The assertion occurred because you replaced the contents of pkthdr (which
is private) with something else that doesn't belong with that mbuf; don't
use mbuf_pkthdr_setheader().
I'm not quite clear on what you're trying to do, but instead, if you want to
prepend data, use mbuf_prepend(). If you want to associate private data to
the mbuf, use mbuf_tag_*. If you really want to change the linkage of mbufs,
use mbuf_setnext(). For the latter, you'd have to copy over the contents of
the head mbuf to another mbuf, set the mbuf length to 0, and point the next
pointer to your mbuf which then points to the mbuf containing the original data.
Adi
On Dec 17, 2009, at 9:15 AM, Dmitriy Arekhta wrote:
> 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
_______________________________________________
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