From 5b204a113c89e1e881a115db9ecbe0ac9f9b460c Mon Sep 17 00:00:00 2001 From: Kip Macy Date: Fri, 19 Jun 2009 21:14:39 +0000 Subject: [PATCH] define helper routines for deferred mbuf initialization --- sys/kern/kern_mbuf.c | 26 ++++++++++++++++++++++++++ sys/sys/mbuf.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/sys/kern/kern_mbuf.c b/sys/kern/kern_mbuf.c index 80274edb7f48..67c955c101be 100644 --- a/sys/kern/kern_mbuf.c +++ b/sys/kern/kern_mbuf.c @@ -645,6 +645,32 @@ mb_ctor_pack(void *mem, int size, void *arg, int how) return (0); } +int +m_pkthdr_init(struct mbuf *m, int how) +{ +#ifdef MAC + int error; +#endif + m->m_data = m->m_pktdat; + SLIST_INIT(&m->m_pkthdr.tags); + m->m_pkthdr.rcvif = NULL; + m->m_pkthdr.header = NULL; + m->m_pkthdr.len = 0; + m->m_pkthdr.flowid = 0; + m->m_pkthdr.csum_flags = 0; + m->m_pkthdr.csum_data = 0; + m->m_pkthdr.tso_segsz = 0; + m->m_pkthdr.ether_vtag = 0; +#ifdef MAC + /* If the label init fails, fail the alloc */ + error = mac_mbuf_init(m, how); + if (error) + return (error); +#endif + + return (0); +} + /* * This is the protocol drain routine. * diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 18b14887184f..43126887d277 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -366,12 +366,15 @@ static __inline struct mbuf *m_gethdr(int how, short type); static __inline struct mbuf *m_getjcl(int how, short type, int flags, int size); static __inline struct mbuf *m_getclr(int how, short type); /* XXX */ +static __inline int m_init(struct mbuf *m, uma_zone_t zone, + int size, int how, short type, int flags); static __inline struct mbuf *m_free(struct mbuf *m); static __inline void m_clget(struct mbuf *m, int how); static __inline void *m_cljget(struct mbuf *m, int how, int size); static __inline void m_chtype(struct mbuf *m, short new_type); void mb_free_ext(struct mbuf *); static __inline struct mbuf *m_last(struct mbuf *m); +int m_pkthdr_init(struct mbuf *m, int how); static __inline int m_gettype(int size) @@ -433,6 +436,33 @@ m_getzone(int size) return (zone); } +/* + * Initialize an mbuf with linear storage. + * + * Inline because the consumer text overhead will be roughly the same to + * initialize or call a function with this many parameters and M_PKTHDR + * should go away with constant propagation for !MGETHDR. + */ +static __inline int +m_init(struct mbuf *m, uma_zone_t zone, int size, int how, short type, + int flags) +{ + int error; + + m->m_next = NULL; + m->m_nextpkt = NULL; + m->m_data = m->m_dat; + m->m_len = 0; + m->m_flags = flags; + m->m_type = type; + if (flags & M_PKTHDR) { + if ((error = m_pkthdr_init(m, how)) != 0) + return (error); + } + + return (0); +} + static __inline struct mbuf * m_get(int how, short type) {