12.07.2015 Views

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MBUF (9) <strong>NetBSD</strong> <strong>Kernel</strong> Developer’s <strong>Manual</strong> MBUF (9)off is non-zero, the packet is supposed to be trailer-encapsulated and off bytes plus the typeand length fields will be skipped before copying. Returns the top of the mbuf chain it created.m_copym(struct mbuf ∗m , int off0 , int len , int wait)Creates a copy ofanmbuf chain starting off0 bytes from the beginning, continuing for lenbytes. If the len requested is M_COPYALL, the complete mbuf chain will be copied. The waitparameter is a choice of M_WAIT / M_DONTWAIT from caller.m_copypacket(struct mbuf ∗m , int how)Copies an entire packet, including header (which must be present). This function is an optimizationof the common case m_copym(m, 0, M_COPYALL, how).m_copydata(struct mbuf ∗m , int off , int len , void ∗cp)Copies len bytes data from mbuf chain m into the buffer cp, starting off bytes from the beginning.m_copyback(struct mbuf ∗m0 , int off , int len , void ∗cp)Copies len bytes data from buffer cp back into the mbuf chain m0, starting off bytes from thebeginning of the chain, extending the mbuf chain if necessary. m_copyback() can only failwhen extending the chain. The caller should check for this kind of failure by checking the resultinglength of the chain in that case. It is an error to use m_copyback() on read-only mbufs.m_copyback_cow(struct mbuf ∗m0 , int off , int len , void ∗cp , int how)Copies len bytes data from buffer cp back into the mbuf chain m0 as m_copyback() does.Unlike m_copyback(), it is safe to use m_copyback_cow() on read-only mbufs. If needed,m_copyback_cow() automatically allocates new mbufs and adjusts the chain. On success, itreturns a pointer to the resulting mbuf chain, and frees the original mbuf m0. Otherwise, itreturns NULL. The how parameter is a choice of M_WAIT / M_DONTWAIT from the caller.Unlike m_copyback(), extending the mbuf chain isn’t supported. It is an error to attempt toextend the mbuf chain using m_copyback_cow().m_makewritable(struct mbuf ∗∗mp , int off , int len , int how)Rearranges an mbuf chain so that len bytes from offset off are writable. When it meets readonlymbufs, it allocates new mbufs, adjusts the chain as m_copyback_cow() does, and copiesthe original content into them. m_makewritable() does not guarantee that all len bytes atoff are consecutive. The how parameter is a choice of M_WAIT / M_DONTWAIT from thecaller. m_makewritable() preserves the contents of the mbuf chain even inthe case of failure.It updates a pointer to the mbuf chain pointed to by mp. Itreturns 0 on success. Otherwise,it returns an error code, typically ENOBUFS.m_cat(struct mbuf ∗m , struct mbuf ∗n)Concatenates mbuf chain n to m. Both chains must be of the same type; packet headers will notbe updated if present.m_dup(struct mbuf ∗m , int off0 , int len , int wait)Similarly to m_copym(), the function creates a copy ofanmbuf chain starting off0 bytes fromthe beginning, continuing for len bytes. While m_copym() tries to share external storage formbufs with M_EXT flag, m_dup() will deep-copy the whole data content into new mbuf chainand avoids shared external storage.m_prepend(struct mbuf ∗m , int len , int how)Lesser-used path for M_PREPEND(): allocates new mbuf m of size len to prepend to the chain,copying junk along. The how parameter is a choice of M_WAIT / M_DONTWAIT from caller.m_pulldown(struct mbuf ∗m , int off , int len , int ∗offp)Rearranges an mbuf chain so that len bytes from offset off are contiguous and in the data areaof an mbuf. The return value points to an mbuf in the middle of the mbuf chain m. Ifwecall the<strong>NetBSD</strong> 3.0 March 24, 2008 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!