From f41233d2cf47a661abee65d4a6dce082cf02432d Mon Sep 17 00:00:00 2001 From: rwatson Date: Tue, 30 Jul 2002 18:28:58 +0000 Subject: [PATCH] Make M_COPY_PKTHDR() macro into a wrapper for a m_copy_pkthdr() function. This permits conditionally compiled extensions to the packet header copying semantic, such as extensions to copy MAC labels. Reviewed by: bmilekic Obtained from: TrustedBSD Project Sponsored by: DARPA, NAI Labs --- sys/kern/uipc_mbuf.c | 19 +++++++++++++++++++ sys/sys/mbuf.h | 17 ++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 2c74a4c04fda..e8a679ed8d86 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -62,6 +62,25 @@ SYSCTL_INT(_kern_ipc, KIPC_MAX_HDR, max_hdr, CTLFLAG_RW, &max_hdr, 0, ""); SYSCTL_INT(_kern_ipc, KIPC_MAX_DATALEN, max_datalen, CTLFLAG_RW, &max_datalen, 0, ""); +/* + * Copy mbuf pkthdr from "from" to "to". + * "from" must have M_PKTHDR set, and "to" must be empty. + * aux pointer will be moved to "to". + */ +void +m_copy_pkthdr(struct mbuf *to, struct mbuf *from) +{ + +#if 0 + KASSERT(to->m_flags & M_PKTHDR, + ("m_copy_pkthdr() called on non-header")); +#endif + to->m_data = to->m_pktdat; + to->m_flags = from->m_flags & M_COPYFLAGS; + to->m_pkthdr = from->m_pkthdr; + from->m_pkthdr.aux = NULL; +} + /* * Lesser-used path for M_PREPEND: * allocate new mbuf to prepend to chain, diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 0f3669476b9c..437a19220c40 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -280,6 +280,7 @@ struct mbstat { * mbuf, cluster, and external object allocation macros * (for compatibility purposes). */ +#define M_COPY_PKTHDR(to, from) m_copy_pkthdr(to, from) #define m_getclr m_get_clrd #define MGET(m, how, type) (m) = m_get((how), (type)) #define MGETHDR(m, how, type) (m) = m_gethdr((how), (type)) @@ -312,21 +313,6 @@ struct mbstat { #define M_WRITABLE(m) (!((m)->m_flags & M_RDONLY) && (!((m)->m_flags \ & M_EXT) || !MEXT_IS_REF(m))) -/*- - * Copy mbuf pkthdr from "from" to "to". - * "from" must have M_PKTHDR set, and "to" must be empty. - * aux pointer will be moved to "to". - */ -#define M_COPY_PKTHDR(to, from) do { \ - struct mbuf *_mfrom = (from); \ - struct mbuf *_mto = (to); \ - \ - _mto->m_data = _mto->m_pktdat; \ - _mto->m_flags = _mfrom->m_flags & M_COPYFLAGS; \ - _mto->m_pkthdr = _mfrom->m_pkthdr; \ - _mfrom->m_pkthdr.aux = NULL; \ -} while (0) - /* * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place * an object of the specified size at the end of the mbuf, longword aligned. @@ -487,6 +473,7 @@ void m_copyback(struct mbuf *, int, int, caddr_t); void m_copydata(const struct mbuf *, int, int, caddr_t); struct mbuf *m_copym(struct mbuf *, int, int, int); struct mbuf *m_copypacket(struct mbuf *, int); +void m_copy_pkthdr(struct mbuf *to, struct mbuf *from); struct mbuf *m_devget(char *, int, int, struct ifnet *, void (*copy)(char *, caddr_t, u_int)); struct mbuf *m_dup(struct mbuf *, int);