xref: /titanic_44/usr/src/uts/common/netsmb/mchain.h (revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce)
14bff34e3Sthurlow /*
24bff34e3Sthurlow  * Copyright (c) 2000, 2001 Boris Popov
34bff34e3Sthurlow  * All rights reserved.
44bff34e3Sthurlow  *
54bff34e3Sthurlow  * Redistribution and use in source and binary forms, with or without
64bff34e3Sthurlow  * modification, are permitted provided that the following conditions
74bff34e3Sthurlow  * are met:
84bff34e3Sthurlow  * 1. Redistributions of source code must retain the above copyright
94bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer.
104bff34e3Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
114bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer in the
124bff34e3Sthurlow  *    documentation and/or other materials provided with the distribution.
134bff34e3Sthurlow  * 3. All advertising materials mentioning features or use of this software
144bff34e3Sthurlow  *    must display the following acknowledgement:
154bff34e3Sthurlow  *    This product includes software developed by Boris Popov.
164bff34e3Sthurlow  * 4. Neither the name of the author nor the names of any co-contributors
174bff34e3Sthurlow  *    may be used to endorse or promote products derived from this software
184bff34e3Sthurlow  *    without specific prior written permission.
194bff34e3Sthurlow  *
204bff34e3Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
214bff34e3Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224bff34e3Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234bff34e3Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
244bff34e3Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254bff34e3Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264bff34e3Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274bff34e3Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284bff34e3Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294bff34e3Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304bff34e3Sthurlow  * SUCH DAMAGE.
314bff34e3Sthurlow  *
324bff34e3Sthurlow  * $FreeBSD: src/sys/sys/mchain.h,v 1.1 2001/02/24 15:44:30 bp Exp $
334bff34e3Sthurlow  */
34*613a2f6bSGordon Ross 
354bff34e3Sthurlow /*
36*613a2f6bSGordon Ross  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
374bff34e3Sthurlow  * Use is subject to license terms.
384bff34e3Sthurlow  */
394bff34e3Sthurlow 
404bff34e3Sthurlow #ifndef _MCHAIN_H_
414bff34e3Sthurlow #define	_MCHAIN_H_
424bff34e3Sthurlow 
434bff34e3Sthurlow #include <sys/types.h>
444bff34e3Sthurlow #include <sys/isa_defs.h>
454bff34e3Sthurlow #include <sys/byteorder.h>
464bff34e3Sthurlow 
474bff34e3Sthurlow #ifdef _LITTLE_ENDIAN
484bff34e3Sthurlow 
494bff34e3Sthurlow /* little-endian values on little-endian */
504bff34e3Sthurlow #define	htoles(x)	((uint16_t)(x))
514bff34e3Sthurlow #define	letohs(x)	((uint16_t)(x))
524bff34e3Sthurlow #define	htolel(x)	((uint32_t)(x))
534bff34e3Sthurlow #define	letohl(x)	((uint32_t)(x))
544bff34e3Sthurlow #define	htoleq(x)	((uint64_t)(x))
554bff34e3Sthurlow #define	letohq(x)	((uint64_t)(x))
564bff34e3Sthurlow 
574bff34e3Sthurlow /*
584bff34e3Sthurlow  * big-endian values on little-endian (swap)
594bff34e3Sthurlow  *
604bff34e3Sthurlow  * Use the BSWAP macros because they're fastest, and they're
614bff34e3Sthurlow  * available in all environments where we use this header.
624bff34e3Sthurlow  */
634bff34e3Sthurlow #define	htobes(x)	BSWAP_16(x)
644bff34e3Sthurlow #define	betohs(x)	BSWAP_16(x)
654bff34e3Sthurlow #define	htobel(x)	BSWAP_32(x)
664bff34e3Sthurlow #define	betohl(x)	BSWAP_32(x)
674bff34e3Sthurlow #define	htobeq(x)	BSWAP_64(x)
684bff34e3Sthurlow #define	betohq(x)	BSWAP_64(x)
694bff34e3Sthurlow 
704bff34e3Sthurlow #else	/* (BYTE_ORDER == LITTLE_ENDIAN) */
714bff34e3Sthurlow 
724bff34e3Sthurlow /* little-endian values on big-endian (swap) */
734bff34e3Sthurlow #define	letohs(x) 	BSWAP_16(x)
744bff34e3Sthurlow #define	htoles(x) 	BSWAP_16(x)
754bff34e3Sthurlow #define	letohl(x) 	BSWAP_32(x)
764bff34e3Sthurlow #define	htolel(x) 	BSWAP_32(x)
774bff34e3Sthurlow #define	letohq(x)	BSWAP_64(x)
784bff34e3Sthurlow #define	htoleq(x)	BSWAP_64(x)
794bff34e3Sthurlow 
804bff34e3Sthurlow /* big-endian values on big-endian */
814bff34e3Sthurlow #define	htobes(x)	((uint16_t)(x))
824bff34e3Sthurlow #define	betohs(x)	((uint16_t)(x))
834bff34e3Sthurlow #define	htobel(x)	((uint32_t)(x))
844bff34e3Sthurlow #define	betohl(x)	((uint32_t)(x))
854bff34e3Sthurlow #define	htobeq(x)	((uint64_t)(x))
864bff34e3Sthurlow #define	betohq(x)	((uint64_t)(x))
874bff34e3Sthurlow #endif	/* (BYTE_ORDER == LITTLE_ENDIAN) */
884bff34e3Sthurlow 
894bff34e3Sthurlow 
904bff34e3Sthurlow #ifdef _KERNEL
914bff34e3Sthurlow 
924bff34e3Sthurlow /* BEGIN CSTYLED */
934bff34e3Sthurlow /*
944bff34e3Sthurlow  * BSD-style mbufs, vs SysV-style mblks:
954bff34e3Sthurlow  * One big difference: the mbuf payload is:
964bff34e3Sthurlow  *   m_data ... (m_data + m_len)
974bff34e3Sthurlow  * In Unix STREAMS, the mblk payload is:
984bff34e3Sthurlow  *   b_rptr ... b_wptr
994bff34e3Sthurlow  *
1004bff34e3Sthurlow  * Here are some handy conversion notes:
1014bff34e3Sthurlow  *
1024bff34e3Sthurlow  * struct mbuf                     struct mblk
1034bff34e3Sthurlow  *   m->m_next                       m->b_cont
1044bff34e3Sthurlow  *   m->m_nextpkt                    m->b_next
1054bff34e3Sthurlow  *   m->m_data                       m->b_rptr
1064bff34e3Sthurlow  *   m->m_len                        MBLKL(m)
1074bff34e3Sthurlow  *   m->m_dat[]                      m->b_datap->db_base
1084bff34e3Sthurlow  *   &m->m_dat[MLEN]                 m->b_datap->db_lim
1094bff34e3Sthurlow  *   M_TRAILINGSPACE(m)              MBLKTAIL(m)
1104bff34e3Sthurlow  *   m_freem(m)                      freemsg(m)
1114bff34e3Sthurlow  *
1124bff34e3Sthurlow  * Note that mbufs chains also have a special "packet" header,
1134bff34e3Sthurlow  * which has the length of the whole message.  In STREAMS one
1144bff34e3Sthurlow  * typically just calls msgdsize(m) to get that.
1154bff34e3Sthurlow  */
1164bff34e3Sthurlow /* END CSTYLED */
1174bff34e3Sthurlow 
1184bff34e3Sthurlow #include <sys/stream.h> /* mblk_t */
1194bff34e3Sthurlow 
1204bff34e3Sthurlow /*
1214bff34e3Sthurlow  * Type of copy for mb_{put|get}_mem()
1224bff34e3Sthurlow  */
1234bff34e3Sthurlow #define	MB_MSYSTEM	0		/* use bcopy() */
1244bff34e3Sthurlow #define	MB_MUSER	1		/* use copyin()/copyout() */
1254bff34e3Sthurlow #define	MB_MINLINE	2		/* use an inline copy loop */
1264bff34e3Sthurlow #define	MB_MZERO	3		/* bzero(), mb_put_mem only */
1274bff34e3Sthurlow #define	MB_MCUSTOM	4		/* use an user defined function */
1284bff34e3Sthurlow 
1294bff34e3Sthurlow struct mbchain {
1304bff34e3Sthurlow 	mblk_t *mb_top;
1314bff34e3Sthurlow 	mblk_t *mb_cur;
1324bff34e3Sthurlow 	uint_t mb_count;
1334bff34e3Sthurlow };
1344bff34e3Sthurlow typedef struct mbchain mbchain_t;
1354bff34e3Sthurlow 
1364bff34e3Sthurlow struct mdchain {
1374bff34e3Sthurlow 	mblk_t *md_top;		/* head of mblk chain */
1384bff34e3Sthurlow 	mblk_t *md_cur;		/* current mblk */
1394bff34e3Sthurlow 	uchar_t *md_pos;		/* offset in the current mblk */
1404bff34e3Sthurlow };
1414bff34e3Sthurlow typedef struct mdchain mdchain_t;
1424bff34e3Sthurlow 
1434bff34e3Sthurlow int  m_fixhdr(mblk_t *m);
1444bff34e3Sthurlow 
1454bff34e3Sthurlow int  mb_init(struct mbchain *mbp);
1464bff34e3Sthurlow void mb_initm(struct mbchain *mbp, mblk_t *m);
1474bff34e3Sthurlow void mb_done(struct mbchain *mbp);
1484bff34e3Sthurlow mblk_t *mb_detach(struct mbchain *mbp);
1494bff34e3Sthurlow int  mb_fixhdr(struct mbchain *mbp);
1504bff34e3Sthurlow void *mb_reserve(struct mbchain *mbp, int size);
1514bff34e3Sthurlow 
1524bff34e3Sthurlow int  mb_put_padbyte(struct mbchain *mbp);
1534bff34e3Sthurlow int  mb_put_uint8(struct mbchain *mbp, uint8_t x);
1544bff34e3Sthurlow int  mb_put_uint16be(struct mbchain *mbp, uint16_t x);
1554bff34e3Sthurlow int  mb_put_uint16le(struct mbchain *mbp, uint16_t x);
1564bff34e3Sthurlow int  mb_put_uint32be(struct mbchain *mbp, uint32_t x);
1574bff34e3Sthurlow int  mb_put_uint32le(struct mbchain *mbp, uint32_t x);
1584bff34e3Sthurlow int  mb_put_uint64be(struct mbchain *mbp, uint64_t x);
1594bff34e3Sthurlow int  mb_put_uint64le(struct mbchain *mbp, uint64_t x);
160*613a2f6bSGordon Ross int  mb_put_mem(struct mbchain *mbp, const void *src, int size, int type);
1614bff34e3Sthurlow 
1627568150aSgwr int  mb_put_mbuf(struct mbchain *mbp, mblk_t *m);
163*613a2f6bSGordon Ross int  mb_put_uio(struct mbchain *mbp, uio_t *uiop, size_t size);
1644bff34e3Sthurlow 
1654bff34e3Sthurlow int  md_init(struct mdchain *mdp);
1664bff34e3Sthurlow void md_initm(struct mdchain *mbp, mblk_t *m);
1674bff34e3Sthurlow void md_done(struct mdchain *mdp);
1684bff34e3Sthurlow void md_append_record(struct mdchain *mdp, mblk_t *top);
1694bff34e3Sthurlow int  md_next_record(struct mdchain *mdp);
1704bff34e3Sthurlow int  md_get_uint8(struct mdchain *mdp, uint8_t *x);
1714bff34e3Sthurlow int  md_get_uint16le(struct mdchain *mdp, uint16_t *x);
1724bff34e3Sthurlow int  md_get_uint16be(struct mdchain *mdp, uint16_t *x);
1734bff34e3Sthurlow int  md_get_uint32be(struct mdchain *mdp, uint32_t *x);
1744bff34e3Sthurlow int  md_get_uint32le(struct mdchain *mdp, uint32_t *x);
1754bff34e3Sthurlow int  md_get_uint64be(struct mdchain *mdp, uint64_t *x);
1764bff34e3Sthurlow int  md_get_uint64le(struct mdchain *mdp, uint64_t *x);
177*613a2f6bSGordon Ross int  md_get_mem(struct mdchain *mdp, void *vdst, int size, int type);
1787568150aSgwr int  md_get_mbuf(struct mdchain *mdp, int size, mblk_t **m);
179*613a2f6bSGordon Ross int  md_get_uio(struct mdchain *mdp, uio_t *uiop, size_t size);
1804bff34e3Sthurlow 
1814bff34e3Sthurlow /*
1824bff34e3Sthurlow  * Additions for Solaris to replace things that came from
1834bff34e3Sthurlow  * <sys/mbuf.h> in the Darwin code.  These are mostly just
1844bff34e3Sthurlow  * wrappers for streams functions.  See: subr_mchain.c
1854bff34e3Sthurlow  */
1864bff34e3Sthurlow 
1874bff34e3Sthurlow #define	mtod(m, t) ((t)((m)->b_rptr))
1884bff34e3Sthurlow 
1894bff34e3Sthurlow /* length to m_copym to copy all */
1904bff34e3Sthurlow #define	M_COPYALL		-1
1914bff34e3Sthurlow 
1924bff34e3Sthurlow mblk_t *m_copym(mblk_t *, int, int, int);
1934bff34e3Sthurlow mblk_t *m_pullup(mblk_t *, int);
1944bff34e3Sthurlow mblk_t *m_split(mblk_t *, int, int);
1954bff34e3Sthurlow void m_cat(mblk_t *, mblk_t *);
1964bff34e3Sthurlow #define	m_freem(x)	freemsg(x)
1974bff34e3Sthurlow mblk_t *m_getblk(int, int);
1984bff34e3Sthurlow 
1994bff34e3Sthurlow #endif	/* ifdef _KERNEL */
2004bff34e3Sthurlow #endif	/* !_MCHAIN_H_ */
201