xref: /illumos-gate/usr/src/uts/common/sys/bufmod.h (revision 69b1fd3f24d0ee2e682883606201c61f52085805)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1991, 1997-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_SYS_BUFMOD_H
28 #define	_SYS_BUFMOD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/types32.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * Definitions for the STREAMS Buffering module.
41  *
42  * The module gathers incoming (read-side) messages together into
43  * "chunks" and passes completed chunks up to the next module in
44  * line.  The gathering process is controlled by two ioctl-settable
45  * parameters:
46  *
47  * timeout	The maximum delay after passing the previous chunk
48  *		upward before passing the current one up, even if the
49  *		chunk isn't full.  If the timeout value passed in is
50  *		a null pointer, the timeout is infinite (as in the
51  *		select system call); this is the default.
52  * chunksize	The maximum size of a chunk of accumulated messages,
53  *		unless a single message exceeds the chunksize, in
54  *		which case it's passed up in a chunk containing only
55  *		that message.  Note that a given message's size includes
56  *		the length of any leading M_PROTO blocks it may have.
57  *
58  * There is one important side-effect: setting the timeout to zero
59  * (polling) will force the chunksize to zero, regardless of its
60  * previous setting.
61  */
62 
63 /*
64  * Ioctls.
65  */
66 #define	SBIOC	('B' << 8)
67 #define	SBIOCSTIME	(SBIOC|1)	/* set timeout info */
68 #define	SBIOCGTIME	(SBIOC|2)	/* get timeout info */
69 #define	SBIOCCTIME	(SBIOC|3)	/* clear timeout */
70 #define	SBIOCSCHUNK	(SBIOC|4)	/* set chunksize */
71 #define	SBIOCGCHUNK	(SBIOC|5)	/* get chunksize */
72 #define	SBIOCSSNAP	(SBIOC|6)	/* set snapshot length */
73 #define	SBIOCGSNAP	(SBIOC|7)	/* get snapshot length */
74 #define	SBIOCSFLAGS	(SBIOC|8)	/* set buffering modes */
75 #define	SBIOCGFLAGS	(SBIOC|9)	/* get buffering modes */
76 
77 /*
78  * Default chunk size.
79  */
80 #define	SB_DFLT_CHUNK	8192	/* arbitrary */
81 
82 /*
83  * buffering flags
84  */
85 
86 #define	SB_SEND_ON_WRITE	1	/* return buffered read data on write */
87 #define	SB_NO_HEADER		2	/* don't add header structure to data */
88 #define	SB_NO_PROTO_CVT		4	/* don't convert proto to data */
89 #define	SB_DEFER_CHUNK		8	/* fast response time buffering */
90 #define	SB_NO_DROPS		16	/* Don't drop messages */
91 
92 /*
93  * buffering state
94  */
95 #define	SB_FRCVD	1	/* first message in time window received */
96 
97 /*
98  * When adding a given message to an accumulating chunk, the module
99  * first converts any leading M_PROTO data block to M_DATA.
100  * It then constructs an sb_hdr (defined below), prepends it to
101  * the message, and pads the result out to force its length to a
102  * multiple of a machine-dependent alignment size guaranteed to be
103  * at least sizeof (ulong_t).  It then adds the padded message to the
104  * chunk.
105  *
106  * sb_origlen is the original length of the message after the M_PROTO => M_DATA
107  * conversion, but before truncating or adding the header.
108  *
109  * sb_msglen is the length of the message after truncation, but before
110  * adding the header.
111  *
112  * sb_totlen is the length of the message after truncation, and including
113  * both the header itself and the trailing padding bytes.
114  *
115  * sb_drops is the cumulative number of messages dropped by the module
116  * due to stream read-side flow control or resource exhaustion.
117  *
118  * sb_timestamp is the packet arrival time expressed as a 'struct timeval'.
119  */
120 
121 struct sb_hdr {
122 	uint_t	sbh_origlen;
123 	uint_t	sbh_msglen;
124 	uint_t	sbh_totlen;
125 	uint_t	sbh_drops;
126 #if defined(_LP64) || defined(_I32LPx)
127 	struct	timeval32 sbh_timestamp;
128 #else
129 	struct	timeval sbh_timestamp;
130 #endif /* !_LP64 */
131 };
132 
133 #ifdef	__cplusplus
134 }
135 #endif
136 
137 #endif	/* _SYS_BUFMOD_H */
138