xref: /illumos-gate/usr/src/uts/common/sys/bufmod.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
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 #include <sys/types.h>
31 #include <sys/types32.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Definitions for the STREAMS Buffering module.
39  *
40  * The module gathers incoming (read-side) messages together into
41  * "chunks" and passes completed chunks up to the next module in
42  * line.  The gathering process is controlled by two ioctl-settable
43  * parameters:
44  *
45  * timeout	The maximum delay after passing the previous chunk
46  *		upward before passing the current one up, even if the
47  *		chunk isn't full.  If the timeout value passed in is
48  *		a null pointer, the timeout is infinite (as in the
49  *		select system call); this is the default.
50  * chunksize	The maximum size of a chunk of accumulated messages,
51  *		unless a single message exceeds the chunksize, in
52  *		which case it's passed up in a chunk containing only
53  *		that message.  Note that a given message's size includes
54  *		the length of any leading M_PROTO blocks it may have.
55  *
56  * There is one important side-effect: setting the timeout to zero
57  * (polling) will force the chunksize to zero, regardless of its
58  * previous setting.
59  */
60 
61 /*
62  * Ioctls.
63  */
64 #define	SBIOC	('B' << 8)
65 #define	SBIOCSTIME	(SBIOC|1)	/* set timeout info */
66 #define	SBIOCGTIME	(SBIOC|2)	/* get timeout info */
67 #define	SBIOCCTIME	(SBIOC|3)	/* clear timeout */
68 #define	SBIOCSCHUNK	(SBIOC|4)	/* set chunksize */
69 #define	SBIOCGCHUNK	(SBIOC|5)	/* get chunksize */
70 #define	SBIOCSSNAP	(SBIOC|6)	/* set snapshot length */
71 #define	SBIOCGSNAP	(SBIOC|7)	/* get snapshot length */
72 #define	SBIOCSFLAGS	(SBIOC|8)	/* set buffering modes */
73 #define	SBIOCGFLAGS	(SBIOC|9)	/* get buffering modes */
74 
75 /*
76  * Default chunk size.
77  */
78 #define	SB_DFLT_CHUNK	8192	/* arbitrary */
79 
80 /*
81  * buffering flags
82  */
83 
84 #define	SB_SEND_ON_WRITE	1	/* return buffered read data on write */
85 #define	SB_NO_HEADER		2	/* don't add header structure to data */
86 #define	SB_NO_PROTO_CVT		4	/* don't convert proto to data */
87 #define	SB_DEFER_CHUNK		8	/* fast response time buffering */
88 #define	SB_NO_DROPS		16	/* Don't drop messages */
89 
90 /*
91  * buffering state
92  */
93 #define	SB_FRCVD	1	/* first message in time window received */
94 
95 /*
96  * When adding a given message to an accumulating chunk, the module
97  * first converts any leading M_PROTO data block to M_DATA.
98  * It then constructs an sb_hdr (defined below), prepends it to
99  * the message, and pads the result out to force its length to a
100  * multiple of a machine-dependent alignment size guaranteed to be
101  * at least sizeof (ulong_t).  It then adds the padded message to the
102  * chunk.
103  *
104  * sb_origlen is the original length of the message after the M_PROTO => M_DATA
105  * conversion, but before truncating or adding the header.
106  *
107  * sb_msglen is the length of the message after truncation, but before
108  * adding the header.
109  *
110  * sb_totlen is the length of the message after truncation, and including
111  * both the header itself and the trailing padding bytes.
112  *
113  * sb_drops is the cumulative number of messages dropped by the module
114  * due to stream read-side flow control or resource exhaustion.
115  *
116  * sb_timestamp is the packet arrival time expressed as a 'struct timeval'.
117  */
118 
119 struct sb_hdr {
120 	uint_t	sbh_origlen;
121 	uint_t	sbh_msglen;
122 	uint_t	sbh_totlen;
123 	uint_t	sbh_drops;
124 #if defined(_LP64) || defined(_I32LPx)
125 	struct	timeval32 sbh_timestamp;
126 #else
127 	struct	timeval sbh_timestamp;
128 #endif /* !_LP64 */
129 };
130 
131 #ifdef	__cplusplus
132 }
133 #endif
134 
135 #endif	/* _SYS_BUFMOD_H */
136