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 2014 Garrett D'Amore <garrett@damore.org>
24  */
25 /*	Copyright (c) 1996 Sun Microsystems, Inc.	*/
26 /*	  All Rights Reserved	*/
27 /*
28  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
29  */
30 
31 #ifndef _XTI_H
32 #define	_XTI_H
33 
34 #include <sys/types.h>
35 
36 /*
37  * The following include file has declarations needed by both the kernel
38  * level transport providers and the user level library. This file includes
39  * it to expose its namespaces to XTI user level interface.
40  */
41 #include <sys/tpicommon.h>
42 
43 /*
44  * Include XTI interface level options management declarations
45  */
46 #include <sys/xti_xtiopt.h>
47 
48 #if !defined(_XPG5)
49 
50 /*
51  * Include declarations related to OSI transport and management data
52  * structures, and the Internet Protocol Suite.
53  * Note: The older Unix95/XNS4 XTI spec required these to be
54  * exposed through the generic interface header.
55  */
56 #include <sys/xti_osi.h>
57 #include <sys/xti_inet.h>
58 
59 #endif /* !defined(_XPG5) */
60 
61 #ifdef	__cplusplus
62 extern "C" {
63 #endif
64 
65 /*
66  * The following t_errno error codes are included in the namespace by
67  * inclusion of <sys/tpicommon.h> above. The english language error strings
68  * associated with the error values are reproduced here for easy reference.
69  *
70  * Error		Value	Error message string
71  * ----			-----	--------------------
72  * TBADADDR		1	Incorrect address format
73  * TBADOPT		2	Incorrect options format
74  * TACCES		3	Illegal permissions
75  * TBADF		4	Illegal file descriptor
76  * TNOADDR		5	Couldn't allocate address
77  * TOUTSTATE		6	Routine will place interface out of state
78  * TBADSEQ		7	Illegal called/calling sequence number
79  * TSYSERR		8	System error
80  * TLOOK		9	An event requires attention
81  * TBADDATA		10	Illegal amount of data
82  * TBUFOVFLW		11	Buffer not large enough
83  * TFLOW		12	Can't send message - (blocked)
84  * TNODATA		13	No message currently available
85  * TNODIS		14	Disconnect message not found
86  * TNOUDERR		15	Unitdata error message not found
87  * TBADFLAG		16	Incorrect flags specified
88  * TNOREL		17	Orderly release message not found
89  * TNOTSUPPORT		18	Primitive not supported by provider
90  * TSTATECHNG		19	State is in process of changing
91  * TNOSTRUCTYPE		20	Unsupported structure type requested
92  * TBADNAME		21	Invalid transport provider name
93  * TBADQLEN		22	Listener queue length limit is zero
94  * TADDRBUSY		23	Transport address is in use
95  * TINDOUT		24	Outstanding connection indications
96  * TPROVMISMATCH	25	Listener-acceptor transport provider mismatch
97  * TRESQLEN		26	Connection acceptor has listen queue length
98  *				limit greater than zero
99  * TRESADDR		27	Connection acceptor-listener addresses not
100  *				same but required by transport
101  * TQFULL		28	Incoming connection queue is full
102  * TPROTO		29	Protocol error on transport primitive
103  *
104  */
105 
106 /*
107  * The following are the events returned by t_look
108  */
109 #define	T_LISTEN	0x0001	/* connection indication received	*/
110 #define	T_CONNECT	0x0002	/* connect confirmation received	*/
111 #define	T_DATA		0x0004	/* normal data received			*/
112 #define	T_EXDATA	0x0008	/* expedited data received		*/
113 #define	T_DISCONNECT	0x0010	/* disconnect received			*/
114 #define	T_UDERR		0x0040	/* data gram error indication		*/
115 #define	T_ORDREL	0x0080	/* orderly release indication		*/
116 #define	T_GODATA	0x0100	/* sending normal data is again possible */
117 #define	T_GOEXDATA	0x0200	/* sending expedited data is again possible */
118 
119 /*
120  * Flags for data primitives
121  */
122 #define	T_MORE		0x001	/* more data		*/
123 #define	T_EXPEDITED	0x002	/* expedited data	*/
124 #define	T_PUSH		0x004	/* send data immediately */
125 
126 /*
127  * XTI error return
128  */
129 #if defined(_REENTRANT) || defined(_TS_ERRNO)
130 extern int	*__t_errno();
131 #define	t_errno (*(__t_errno()))
132 #else
133 #error "extern int t_errno?"
134 #endif	/* defined(_REENTRANT) || defined(_TS_ERRNO) */
135 
136 
137 /*
138  * The following are for t_sysconf()
139  */
140 #ifndef T_IOV_MAX
141 #define	T_IOV_MAX	16	/* Maximum number of scatter/gather buffers */
142 #endif				/* Should be <= IOV_MAX */
143 
144 #ifndef _SC_T_IOV_MAX
145 #define	_SC_T_IOV_MAX	79	/* Should be same in <unistd.h> for use by */
146 #endif				/* sysconf() */
147 
148 struct t_iovec {
149 	void	*iov_base;
150 	size_t	iov_len;
151 };
152 
153 /*
154  * Translate source level interface to binary entry point names.
155  *
156  * Note: This is done to maintain co-existence of TLI and XTI
157  * interfaces which have identical names for most functions but
158  * different semantics. The XTI names are moved to the different
159  * prefix space in the ABI. The #ifdef is required to make use of
160  * of the compiler feature to allow redefinition of external names
161  * where available. Otherwise a simple #define is used when this
162  * header is used with other compilers.
163  * The use of #define also has the effect of renaming all names (not
164  * just function names) to the new name. The TLI function names
165  * (e.g. t_bind) can have identical names for structure names
166  * (e.g struct t_bind). Therefore, this redefinition of names needs
167  * to be before all structure and function name declarations in the header.
168  */
169 
170 #ifdef __PRAGMA_REDEFINE_EXTNAME
171 
172 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
173 #pragma redefine_extname t_accept	_xti_accept
174 #else
175 #pragma redefine_extname t_accept	_xti_xns5_accept
176 #endif
177 #pragma redefine_extname t_alloc	_xti_alloc
178 #pragma redefine_extname t_bind		_xti_bind
179 #pragma redefine_extname t_close	_xti_close
180 #pragma redefine_extname t_connect	_xti_connect
181 #pragma redefine_extname t_error	_xti_error
182 #pragma redefine_extname t_free		_xti_free
183 #pragma redefine_extname t_getinfo	_xti_getinfo
184 #pragma redefine_extname t_getstate	_xti_getstate
185 #pragma redefine_extname t_getprotaddr	_xti_getprotaddr
186 #pragma redefine_extname t_listen	_xti_listen
187 #pragma redefine_extname t_look		_xti_look
188 #pragma redefine_extname t_open		_xti_open
189 #pragma redefine_extname t_optmgmt	_xti_optmgmt
190 #pragma redefine_extname t_rcv		_xti_rcv
191 #pragma redefine_extname t_rcvconnect	_xti_rcvconnect
192 #pragma redefine_extname t_rcvdis	_xti_rcvdis
193 #pragma redefine_extname t_rcvrel	_xti_rcvrel
194 #pragma redefine_extname t_rcvreldata	_xti_rcvreldata
195 #pragma redefine_extname t_rcvudata	_xti_rcvudata
196 #pragma redefine_extname t_rcvuderr	_xti_rcvuderr
197 #pragma redefine_extname t_rcvv		_xti_rcvv
198 #pragma redefine_extname t_rcvvudata	_xti_rcvvudata
199 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
200 #pragma redefine_extname t_snd		_xti_snd
201 #else
202 #pragma redefine_extname t_snd		_xti_xns5_snd
203 #endif
204 #pragma redefine_extname t_snddis	_xti_snddis
205 #pragma redefine_extname t_sndrel	_xti_sndrel
206 #pragma redefine_extname t_sndreldata	_xti_sndreldata
207 #pragma redefine_extname t_sndudata	_xti_sndudata
208 #pragma redefine_extname t_sndv		_xti_sndv
209 #pragma redefine_extname t_sndvudata	_xti_sndvudata
210 #pragma redefine_extname t_strerror	_xti_strerror
211 #pragma redefine_extname t_sync		_xti_sync
212 #pragma redefine_extname t_sysconf	_xti_sysconf
213 #pragma redefine_extname t_unbind	_xti_unbind
214 
215 #else /* __PRAGMA_REDEFINE_EXTNAME */
216 
217 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
218 #define	t_accept	_xti_accept
219 #else
220 #define	t_accept	_xti_xns5_accept
221 #endif
222 #define	t_alloc		_xti_alloc
223 #define	t_bind(a,b,c)	_xti_bind(a,b,c)
224 #define	t_close		_xti_close
225 #define	t_connect	_xti_connect
226 #define	t_error		_xti_error
227 #define	t_free		_xti_free
228 #define	t_getinfo	_xti_getinfo
229 #define	t_getstate	_xti_getstate
230 #define	t_getprotaddr	_xti_getprotaddr
231 #define	t_listen	_xti_listen
232 #define	t_look		_xti_look
233 #define	t_open		_xti_open
234 #define	t_optmgmt(a,b,c)	_xti_optmgmt(a,b,c)
235 #define	t_rcv		_xti_rcv
236 #define	t_rcvconnect	_xti_rcvconnect
237 #define	t_rcvdis	_xti_rcvdis
238 #define	t_rcvrel	_xti_rcvrel
239 #define	t_rcvreldata	_xti_rcvreldata
240 #define	t_rcvudata	_xti_rcvudata
241 #define	t_rcvuderr	_xti_rcvuderr
242 #define	t_rcvv		_xti_rcvv
243 #define	t_rcvvudata	_xti_rcvvudata
244 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
245 #define	t_snd		_xti_snd
246 #else
247 #define	t_snd		_xti_xns5_snd
248 #endif
249 #define	t_snddis	_xti_snddis
250 #define	t_sndrel	_xti_sndrel
251 #define	t_sndreldata	_xti_sndreldata
252 #define	t_sndudata	_xti_sndudata
253 #define	t_sndv		_xti_sndv
254 #define	t_sndvudata	_xti_sndvudata
255 #define	t_strerror	_xti_strerror
256 #define	t_sync		_xti_sync
257 #define	t_sysconf	_xti_sysconf
258 #define	t_unbind	_xti_unbind
259 
260 #endif /* __PRAGMA_REDEFINE_EXTNAME */
261 
262 /*
263  * All the rest of the standard xti.h removed because the structs:
264  * netbuf, t_info, t_opthdr, t_optmgmt, t_bind, t_call, ...
265  * all conflict with definitions in tiuser.h which we need
266  * for the (simulated) kernel interfaces in fake_ktli.c.
267  *
268  * The XTI library functions below would normally be defined by
269  * including tiuser.h after the defines above, which we can't.
270  */
271 
272 int _xti_accept(int, int, struct t_call *);
273 int _xti_xns5_accept(int, int, struct t_call *);
274 char *_xti_alloc(int, int, int);
275 int _xti_bind(int, struct t_bind *, struct t_bind *);
276 int _xti_close(int);
277 int _xti_connect(int, struct t_call *, struct t_call *);
278 int _xti_error(char *);
279 int _xti_free(char *, int);
280 int _xti_getinfo(int, struct t_info *);
281 int _xti_getprotaddr(int, struct t_bind *, struct t_bind *);
282 int _xti_getstate(int);
283 int _xti_listen(int, struct t_call *);
284 int _xti_look(int);
285 int _xti_open(char *, int, struct t_info *);
286 int _xti_optmgmt(int, struct t_optmgmt *, struct t_optmgmt *);
287 int _xti_rcv(int, char *, unsigned int, int *);
288 int _xti_rcvconnect(int, struct t_call *);
289 int _xti_rcvdis(int, struct t_discon *);
290 int _xti_rcvrel(int);
291 int _xti_rcvreldata(int, struct t_discon *);
292 int _xti_rcvudata(int, struct t_unitdata *, int *);
293 int _xti_rcvuderr(int, struct t_uderr *);
294 int _xti_rcvv(int, struct t_iovec *, unsigned int, int *);
295 int _xti_rcvvudata(int, struct t_unitdata *, struct t_iovec *,
296     unsigned int, int *);
297 int _xti_snd(int, char *, unsigned int, int);
298 int _xti_xns5_snd(int, char *, unsigned int, int);
299 int _xti_snddis(int, struct t_call *);
300 int _xti_sndrel(int);
301 int _xti_sndreldata(int, struct t_discon *);
302 int _xti_sndudata(int, struct t_unitdata *);
303 int _xti_sndv(int, const struct t_iovec *, unsigned int, int);
304 int _xti_sndvudata(int, struct t_unitdata *, struct t_iovec *, unsigned int);
305 char *_xti_strerror(int);
306 int _xti_sync(int);
307 int _xti_sysconf(int);
308 int _xti_unbind(int);
309 
310 #ifdef	__cplusplus
311 }
312 #endif
313 
314 #endif	/* _XTI_H */
315