xref: /illumos-gate/usr/src/head/xti.h (revision 6e270ca825f06ec0e2d77db462b83074ec585f2f)
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 
29 #ifndef _XTI_H
30 #define	_XTI_H
31 
32 #include <sys/types.h>
33 
34 /*
35  * The following include file has declarations needed by both the kernel
36  * level transport providers and the user level library. This file includes
37  * it to expose its namespaces to XTI user level interface.
38  */
39 #include <sys/tpicommon.h>
40 
41 /*
42  * Include XTI interface level options management declarations
43  */
44 #include <sys/xti_xtiopt.h>
45 
46 #if !defined(_XPG5)
47 
48 /*
49  * Include declarations related to OSI transport and management data
50  * structures, and the Internet Protocol Suite.
51  * Note: The older Unix95/XNS4 XTI spec required these to be
52  * exposed through the generic interface header.
53  */
54 #include <sys/xti_osi.h>
55 #include <sys/xti_inet.h>
56 
57 #endif /* !defined(_XPG5) */
58 
59 #ifdef	__cplusplus
60 extern "C" {
61 #endif
62 
63 /*
64  * The following t_errno error codes are included in the namespace by
65  * inclusion of <sys/tpicommon.h> above. The english language error strings
66  * associated with the error values are reproduced here for easy reference.
67  *
68  * Error		Value	Error message string
69  * ----			-----	--------------------
70  * TBADADDR		1	Incorrect address format
71  * TBADOPT		2	Incorrect options format
72  * TACCES		3	Illegal permissions
73  * TBADF		4	Illegal file descriptor
74  * TNOADDR		5	Couldn't allocate address
75  * TOUTSTATE		6	Routine will place interface out of state
76  * TBADSEQ		7	Illegal called/calling sequence number
77  * TSYSERR		8	System error
78  * TLOOK		9	An event requires attention
79  * TBADDATA		10	Illegal amount of data
80  * TBUFOVFLW		11	Buffer not large enough
81  * TFLOW		12	Can't send message - (blocked)
82  * TNODATA		13	No message currently available
83  * TNODIS		14	Disconnect message not found
84  * TNOUDERR		15	Unitdata error message not found
85  * TBADFLAG		16	Incorrect flags specified
86  * TNOREL		17	Orderly release message not found
87  * TNOTSUPPORT		18	Primitive not supported by provider
88  * TSTATECHNG		19	State is in process of changing
89  * TNOSTRUCTYPE		20	Unsupported structure type requested
90  * TBADNAME		21	Invalid transport provider name
91  * TBADQLEN		22	Listener queue length limit is zero
92  * TADDRBUSY		23	Transport address is in use
93  * TINDOUT		24	Outstanding connection indications
94  * TPROVMISMATCH	25	Listener-acceptor transport provider mismatch
95  * TRESQLEN		26	Connection acceptor has listen queue length
96  *				limit greater than zero
97  * TRESADDR		27	Connection acceptor-listener addresses not
98  *				same but required by transport
99  * TQFULL		28	Incoming connection queue is full
100  * TPROTO		29	Protocol error on transport primitive
101  *
102  */
103 
104 /*
105  * The following are the events returned by t_look
106  */
107 #define	T_LISTEN	0x0001	/* connection indication received	*/
108 #define	T_CONNECT	0x0002	/* connect confirmation received	*/
109 #define	T_DATA		0x0004	/* normal data received			*/
110 #define	T_EXDATA	0x0008	/* expedited data received		*/
111 #define	T_DISCONNECT	0x0010	/* disconnect received			*/
112 #define	T_UDERR		0x0040	/* data gram error indication		*/
113 #define	T_ORDREL	0x0080	/* orderly release indication		*/
114 #define	T_GODATA	0x0100	/* sending normal data is again possible */
115 #define	T_GOEXDATA	0x0200	/* sending expedited data is again possible */
116 
117 /*
118  * Flags for data primitives
119  */
120 #define	T_MORE		0x001	/* more data		*/
121 #define	T_EXPEDITED	0x002	/* expedited data	*/
122 #define	T_PUSH		0x004	/* send data immediately */
123 
124 /*
125  * XTI error return
126  */
127 #if defined(_REENTRANT) || defined(_TS_ERRNO)
128 extern int	*__t_errno();
129 #define	t_errno (*(__t_errno()))
130 #else
131 extern int t_errno;
132 #endif	/* defined(_REENTRANT) || defined(_TS_ERRNO) */
133 
134 
135 /*
136  * The following are for t_sysconf()
137  */
138 #ifndef T_IOV_MAX
139 #define	T_IOV_MAX	16	/* Maximum number of scatter/gather buffers */
140 #endif				/* Should be <= IOV_MAX */
141 
142 #ifndef _SC_T_IOV_MAX
143 #define	_SC_T_IOV_MAX	79	/* Should be same in <unistd.h> for use by */
144 #endif				/* sysconf() */
145 
146 struct t_iovec {
147 	void	*iov_base;
148 	size_t	iov_len;
149 };
150 
151 /*
152  * Translate source level interface to binary entry point names.
153  *
154  * Note: This is done to maintain co-existence of TLI and XTI
155  * interfaces which have identical names for most functions but
156  * different semantics. The XTI names are moved to the different
157  * prefix space in the ABI. The #ifdef is required to make use of
158  * of the compiler feature to allow redefinition of external names
159  * where available. Otherwise a simple #define is used when this
160  * header is used with other compilers.
161  * The use of #define also has the effect of renaming all names (not
162  * just function names) to the new name. The TLI function names
163  * (e.g. t_bind) can have identical names for structure names
164  * (e.g struct t_bind). Therefore, this redefinition of names needs
165  * to be before all structure and function name declarations in the header.
166  */
167 
168 #ifdef __PRAGMA_REDEFINE_EXTNAME
169 
170 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
171 #pragma redefine_extname t_accept	_xti_accept
172 #else
173 #pragma redefine_extname t_accept	_xti_xns5_accept
174 #endif
175 #pragma redefine_extname t_alloc	_xti_alloc
176 #pragma redefine_extname t_bind		_xti_bind
177 #pragma redefine_extname t_close	_xti_close
178 #pragma redefine_extname t_connect	_xti_connect
179 #pragma redefine_extname t_error	_xti_error
180 #pragma redefine_extname t_free		_xti_free
181 #pragma redefine_extname t_getinfo	_xti_getinfo
182 #pragma redefine_extname t_getstate	_xti_getstate
183 #pragma redefine_extname t_getprotaddr	_xti_getprotaddr
184 #pragma redefine_extname t_listen	_xti_listen
185 #pragma redefine_extname t_look		_xti_look
186 #pragma redefine_extname t_open		_xti_open
187 #pragma redefine_extname t_optmgmt	_xti_optmgmt
188 #pragma redefine_extname t_rcv		_xti_rcv
189 #pragma redefine_extname t_rcvconnect	_xti_rcvconnect
190 #pragma redefine_extname t_rcvdis	_xti_rcvdis
191 #pragma redefine_extname t_rcvrel	_xti_rcvrel
192 #pragma redefine_extname t_rcvreldata	_xti_rcvreldata
193 #pragma redefine_extname t_rcvudata	_xti_rcvudata
194 #pragma redefine_extname t_rcvuderr	_xti_rcvuderr
195 #pragma redefine_extname t_rcvv		_xti_rcvv
196 #pragma redefine_extname t_rcvvudata	_xti_rcvvudata
197 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
198 #pragma redefine_extname t_snd		_xti_snd
199 #else
200 #pragma redefine_extname t_snd		_xti_xns5_snd
201 #endif
202 #pragma redefine_extname t_snddis	_xti_snddis
203 #pragma redefine_extname t_sndrel	_xti_sndrel
204 #pragma redefine_extname t_sndreldata	_xti_sndreldata
205 #pragma redefine_extname t_sndudata	_xti_sndudata
206 #pragma redefine_extname t_sndv		_xti_sndv
207 #pragma redefine_extname t_sndvudata	_xti_sndvudata
208 #pragma redefine_extname t_strerror	_xti_strerror
209 #pragma redefine_extname t_sync		_xti_sync
210 #pragma redefine_extname t_sysconf	_xti_sysconf
211 #pragma redefine_extname t_unbind	_xti_unbind
212 
213 #else /* __PRAGMA_REDEFINE_EXTNAME */
214 
215 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
216 #define	t_accept	_xti_accept
217 #else
218 #define	t_accept	_xti_xns5_accept
219 #endif
220 #define	t_alloc		_xti_alloc
221 #define	t_bind		_xti_bind
222 #define	t_close		_xti_close
223 #define	t_connect	_xti_connect
224 #define	t_error		_xti_error
225 #define	t_free		_xti_free
226 #define	t_getinfo	_xti_getinfo
227 #define	t_getstate	_xti_getstate
228 #define	t_getprotaddr	_xti_getprotaddr
229 #define	t_listen	_xti_listen
230 #define	t_look		_xti_look
231 #define	t_open		_xti_open
232 #define	t_optmgmt	_xti_optmgmt
233 #define	t_rcv		_xti_rcv
234 #define	t_rcvconnect	_xti_rcvconnect
235 #define	t_rcvdis	_xti_rcvdis
236 #define	t_rcvrel	_xti_rcvrel
237 #define	t_rcvreldata	_xti_rcvreldata
238 #define	t_rcvudata	_xti_rcvudata
239 #define	t_rcvuderr	_xti_rcvuderr
240 #define	t_rcvv		_xti_rcvv
241 #define	t_rcvvudata	_xti_rcvvudata
242 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
243 #define	t_snd		_xti_snd
244 #else
245 #define	t_snd		_xti_xns5_snd
246 #endif
247 #define	t_snddis	_xti_snddis
248 #define	t_sndrel	_xti_sndrel
249 #define	t_sndreldata	_xti_sndreldata
250 #define	t_sndudata	_xti_sndudata
251 #define	t_sndv		_xti_sndv
252 #define	t_sndvudata	_xti_sndvudata
253 #define	t_strerror	_xti_strerror
254 #define	t_sync		_xti_sync
255 #define	t_sysconf	_xti_sysconf
256 #define	t_unbind	_xti_unbind
257 
258 #endif /* __PRAGMA_REDEFINE_EXTNAME */
259 
260 /*
261  * protocol specific service limits
262  */
263 struct t_info {
264 	t_scalar_t addr;	/* max size of protocol address		*/
265 	t_scalar_t options;	/* max size of protocol options		*/
266 	t_scalar_t tsdu;	/* max size of max transport service	*/
267 				/* data unit	*/
268 	t_scalar_t etsdu;	/* max size of max expedited tsdu	*/
269 	t_scalar_t connect;	/* max data for connection primitives	*/
270 	t_scalar_t discon;	/* max data for disconnect primitives	*/
271 	t_scalar_t servtype;	/* provider service type		*/
272 	t_scalar_t flags;	/* other info about transport providers	*/
273 };
274 
275 /*
276  * Flags definitions for the t_info structure
277  */
278 #define	T_SENDZERO	0x001	/* supports 0-length TSDUs */
279 #define	T_ORDRELDATA	0x002	/* supports orderly release data */
280 
281 /*
282  * netbuf structure
283  */
284 struct netbuf {
285 	unsigned int maxlen;
286 	unsigned int len;
287 #if defined(_XPG5)
288 	void *buf;
289 #else
290 	char *buf;
291 #endif
292 };
293 
294 /*
295  * t_opthdr structure
296  */
297 struct t_opthdr {
298 	t_uscalar_t	len;	/* total length of option */
299 	t_uscalar_t	level;	/* protocol level */
300 	t_uscalar_t	name;	/* option name */
301 	t_uscalar_t	status;	/* status value */
302 	/* followed by option value */
303 };
304 
305 /*
306  * t_bind - format of the addres and options arguments of bind
307  */
308 
309 struct t_bind {
310 	struct netbuf	addr;
311 	unsigned int	qlen;
312 };
313 
314 /*
315  * options management
316  */
317 struct t_optmgmt {
318 	struct netbuf	opt;
319 	t_scalar_t	flags;
320 };
321 
322 /*
323  * disconnect structure
324  */
325 struct t_discon {
326 	struct netbuf	udata;		/* user data		*/
327 	int		reason;		/* reason code		*/
328 	int		sequence;	/* sequence number	*/
329 };
330 
331 /*
332  * call structure
333  */
334 struct t_call {
335 	struct netbuf	addr;		/*  address		*/
336 	struct netbuf	opt;		/* options		*/
337 	struct netbuf	udata;		/* user data		*/
338 	int		sequence;	/* sequence number	*/
339 };
340 
341 /*
342  * data gram structure
343  */
344 struct t_unitdata {
345 	struct netbuf	addr;		/*  address		*/
346 	struct netbuf	opt;		/* options		*/
347 	struct netbuf	udata;		/* user data		*/
348 };
349 
350 /*
351  * unitdata error
352  */
353 struct t_uderr {
354 	struct netbuf	addr;		/* address		*/
355 	struct netbuf	opt;		/* options		*/
356 	t_scalar_t	error;		/* error code		*/
357 };
358 
359 /*
360  * The following are structure types used when dynamically
361  * allocating the above structures via t_structalloc().
362  */
363 #define	T_BIND		1		/* struct t_bind	*/
364 #define	T_OPTMGMT	2		/* struct t_optmgmt	*/
365 #define	T_CALL		3		/* struct t_call	*/
366 #define	T_DIS		4		/* struct t_discon	*/
367 #define	T_UNITDATA	5		/* struct t_unitdata	*/
368 #define	T_UDERROR	6		/* struct t_uderr	*/
369 #define	T_INFO		7		/* struct t_info	*/
370 
371 /*
372  * The following bits specify which fields of the above
373  * structures should be allocated by t_alloc().
374  */
375 #define	T_ADDR	0x01			/* address		*/
376 #define	T_OPT	0x02			/* options		*/
377 #define	T_UDATA	0x04			/* user data		*/
378 #define	T_ALL	0xffff			/* all the above fields */
379 
380 
381 /*
382  * the following are the states for the user
383  */
384 
385 #define	T_UNINIT	0		/* uninitialized		*/
386 #define	T_UNBND		1		/* unbound			*/
387 #define	T_IDLE		2		/* idle				*/
388 #define	T_OUTCON	3		/* outgoing connection pending	*/
389 #define	T_INCON		4		/* incoming connection pending	*/
390 #define	T_DATAXFER	5		/* data transfer		*/
391 #define	T_OUTREL	6		/* outgoing release pending	*/
392 #define	T_INREL		7		/* incoming release pending	*/
393 
394 
395 #define	T_UNUSED		-1
396 #define	T_NULL			0
397 
398 
399 /*
400  * Allegedly general purpose constant. Used with (and needs to be bitwise
401  * distinct from) T_NOPROTECT, T_PASSIVEPROTECT and T_ACTIVEPROTECT
402  * which are OSI specific constants but part of this header (defined
403  * in <xti_osi.h> which is included in this header for historical
404  * XTI specification reasons)
405  */
406 #define	T_ABSREQ		0x8000
407 
408 /*
409  * General definitions for option management
410  *
411  * Multiple variable length options may be packed into a single option buffer.
412  * Each option consists of a fixed length header followed by variable length
413  * data. The header and data will have to be aligned at appropriate
414  * boundaries. The following macros are used to manipulate the options.
415  *
416  * Helper Macros: Macros beginning with a "_T" prefix are helper macros.
417  *		  They are private, not meant for public use and may
418  *		  change without notice. Users  should use the standard
419  *		  XTI macros beginning with "T_" prefix
420  */
421 
422 #define	_T_OPT_HALIGN_SZ	(sizeof (t_scalar_t)) /* Hdr Alignment size  */
423 #define	_T_OPT_DALIGN_SZ	(sizeof (int32_t))    /* Data Alignment size */
424 #define	_T_OPTHDR_SZ	(sizeof (struct t_opthdr))
425 
426 /* Align 'x' to the next 'asize' alignment  boundary */
427 #define	_T_OPT_ALIGN(x, asize) \
428 	(((uintptr_t)(x) + ((asize) - 1L)) & ~((asize) - 1L))
429 
430 /* Align 'x' to the next header alignment  boundary */
431 #define	_T_OPTHDR_ALIGN(x) \
432 	(_T_OPT_ALIGN((x), _T_OPT_HALIGN_SZ))
433 
434 /* Align 'x' to the next data alignment  boundary */
435 #define	_T_OPTDATA_ALIGN(x) \
436 	(_T_OPT_ALIGN((x), _T_OPT_DALIGN_SZ))
437 
438 /*
439  * struct t_opthdr *T_OPT_FIRSTHDR(struct netbuf *nbp):
440  *     Get aligned start of first option header
441  *
442  * unsigned char *T_OPT_DATA(struct t_opthdr *tohp):
443  *     Get aligned start of data part after option header
444  *
445  * struct t_opthdr *T_OPT_NEXTHDR(struct netbuf *nbp, struct t_opthdr *tohp):
446  *	Skip to next option header
447  */
448 
449 #define	T_OPT_FIRSTHDR(nbp)    \
450 	((nbp)->len >= _T_OPTHDR_SZ ? (struct t_opthdr *)(nbp)->buf : \
451 	    (struct t_opthdr *)0)
452 
453 #define	T_OPT_DATA(tohp)	\
454 	((unsigned char *)_T_OPTDATA_ALIGN((char *)(tohp) + _T_OPTHDR_SZ))
455 
456 #define	_T_NEXTHDR(pbuf, buflen, popt) \
457 	(((char *)_T_OPTHDR_ALIGN((char *)(popt) + (popt)->len) + \
458 	    _T_OPTHDR_SZ <= ((char *)(pbuf) + (buflen))) ? \
459 	(struct t_opthdr *)((char *)_T_OPTHDR_ALIGN((char *)(popt) + \
460 	    (popt)->len)) : (struct t_opthdr *)0)
461 
462 #define	T_OPT_NEXTHDR(nbp, tohp)   (_T_NEXTHDR((nbp)->buf, (nbp)->len, (tohp)))
463 
464 #if !defined(_XPG5)
465 /*
466  * The macros below are meant for older applications for compatibility.
467  * New applications should use the T_OPT_* macros, obviating the need
468  * to explicitly use the T_ALIGN macro
469  *
470  * struct t_opthdr *OPT_NEXTHDR(char *pbuf, unsigned int buflen,
471  *                               struct t_opthdr *popt):
472  *         Skip to next option header
473  */
474 #define	T_ALIGN(p)	(((uintptr_t)(p) + (sizeof (t_scalar_t) - 1))\
475 					& ~(sizeof (t_scalar_t) - 1))
476 #define	OPT_NEXTHDR(pbuf, buflen, popt)	(_T_NEXTHDR((pbuf), (buflen), (popt)))
477 #endif
478 
479 /*
480  * XTI LIBRARY FUNCTIONS
481  */
482 
483 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
484 extern int t_accept(int, int, struct t_call *);
485 extern char *t_alloc(int, int, int);
486 extern int t_bind(int, struct t_bind *, struct t_bind *);
487 extern int t_connect(int, struct t_call *, struct t_call *);
488 extern int t_error(char *);
489 extern int t_free(char *, int);
490 extern int t_open(char *, int, struct t_info *);
491 extern int t_optmgmt(int, struct t_optmgmt *, struct t_optmgmt *);
492 extern int t_rcv(int, char *, unsigned int, int *);
493 extern int t_snd(int, char *, unsigned int, int);
494 extern int t_snddis(int, struct t_call *);
495 extern int t_sndudata(int, struct t_unitdata *);
496 extern char *t_strerror(int);
497 #else
498 extern int t_accept(int, int, const struct t_call *);
499 extern void *t_alloc(int, int, int);
500 extern int t_bind(int, const struct t_bind *, struct t_bind *);
501 extern int t_connect(int, const struct t_call *, struct t_call *);
502 extern int t_error(const char *);
503 extern int t_free(void *, int);
504 extern int t_open(const char *, int, struct t_info *);
505 extern int t_optmgmt(int, const struct t_optmgmt *, struct t_optmgmt *);
506 extern int t_rcv(int, void *, unsigned int, int *);
507 extern int t_snd(int, void *, unsigned int, int);
508 extern int t_snddis(int, const struct t_call *);
509 extern int t_sndudata(int, const struct t_unitdata *);
510 extern const char *t_strerror(int);
511 #endif
512 extern int t_close(int);
513 extern int t_getinfo(int, struct t_info *);
514 extern int t_getstate(int);
515 extern int t_getprotaddr(int, struct t_bind *, struct t_bind *);
516 extern int t_listen(int, struct t_call *);
517 extern int t_look(int);
518 extern int t_rcvconnect(int, struct t_call *);
519 extern int t_rcvdis(int, struct t_discon *);
520 extern int t_rcvrel(int);
521 extern int t_rcvreldata(int, struct t_discon *);
522 extern int t_rcvudata(int, struct t_unitdata *, int *);
523 extern int t_rcvuderr(int, struct t_uderr *);
524 extern int t_rcvv(int, struct t_iovec *, unsigned int, int *);
525 extern int t_rcvvudata(int, struct t_unitdata *, struct t_iovec *,
526 	unsigned int, int *);
527 extern int t_sndrel(int);
528 extern int t_sndreldata(int, struct t_discon *);
529 extern int t_sndv(int, const struct t_iovec *,  unsigned int, int);
530 extern int t_sndvudata(int, struct t_unitdata *, struct t_iovec *,
531 	unsigned int);
532 extern int t_sync(int);
533 extern int t_sysconf(int);
534 extern int t_unbind(int);
535 
536 #ifdef	__cplusplus
537 }
538 #endif
539 
540 #endif	/* _XTI_H */
541