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
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.
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]
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25 /* Copyright (c) 1996 Sun Microsystems, Inc. */
26 /* All Rights Reserved */
32 #include <sys/types.h>
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.
39 #include <sys/tpicommon.h>
42 * Include XTI interface level options management declarations
44 #include <sys/xti_xtiopt.h>
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.
54 #include <sys/xti_osi.h>
55 #include <sys/xti_inet.h>
57 #endif /* !defined(_XPG5) */
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.
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
105 * The following are the events returned by t_look
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 */
118 * Flags for data primitives
120 #define T_MORE 0x001 /* more data */
121 #define T_EXPEDITED 0x002 /* expedited data */
122 #define T_PUSH 0x004 /* send data immediately */
127 extern int *__t_errno();
128 #define t_errno (*(__t_errno()))
132 * The following are for t_sysconf()
135 #define T_IOV_MAX 16 /* Maximum number of scatter/gather buffers */
136 #endif /* Should be <= IOV_MAX */
138 #ifndef _SC_T_IOV_MAX
139 #define _SC_T_IOV_MAX 79 /* Should be same in <unistd.h> for use by */
140 #endif /* sysconf() */
148 * Translate source level interface to binary entry point names.
150 * Note: This is done to maintain co-existence of TLI and XTI
151 * interfaces which have identical names for most functions but
152 * different semantics. The XTI names are moved to the different
153 * prefix space in the ABI. The #ifdef is required to make use of
154 * of the compiler feature to allow redefinition of external names
155 * where available. Otherwise a simple #define is used when this
156 * header is used with other compilers.
157 * The use of #define also has the effect of renaming all names (not
158 * just function names) to the new name. The TLI function names
159 * (e.g. t_bind) can have identical names for structure names
160 * (e.g struct t_bind). Therefore, this redefinition of names needs
161 * to be before all structure and function name declarations in the header.
164 #ifdef __PRAGMA_REDEFINE_EXTNAME
166 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
167 #pragma redefine_extname t_accept _xti_accept
169 #pragma redefine_extname t_accept _xti_xns5_accept
171 #pragma redefine_extname t_alloc _xti_alloc
172 #pragma redefine_extname t_bind _xti_bind
173 #pragma redefine_extname t_close _xti_close
174 #pragma redefine_extname t_connect _xti_connect
175 #pragma redefine_extname t_error _xti_error
176 #pragma redefine_extname t_free _xti_free
177 #pragma redefine_extname t_getinfo _xti_getinfo
178 #pragma redefine_extname t_getstate _xti_getstate
179 #pragma redefine_extname t_getprotaddr _xti_getprotaddr
180 #pragma redefine_extname t_listen _xti_listen
181 #pragma redefine_extname t_look _xti_look
182 #pragma redefine_extname t_open _xti_open
183 #pragma redefine_extname t_optmgmt _xti_optmgmt
184 #pragma redefine_extname t_rcv _xti_rcv
185 #pragma redefine_extname t_rcvconnect _xti_rcvconnect
186 #pragma redefine_extname t_rcvdis _xti_rcvdis
187 #pragma redefine_extname t_rcvrel _xti_rcvrel
188 #pragma redefine_extname t_rcvreldata _xti_rcvreldata
189 #pragma redefine_extname t_rcvudata _xti_rcvudata
190 #pragma redefine_extname t_rcvuderr _xti_rcvuderr
191 #pragma redefine_extname t_rcvv _xti_rcvv
192 #pragma redefine_extname t_rcvvudata _xti_rcvvudata
193 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
194 #pragma redefine_extname t_snd _xti_snd
196 #pragma redefine_extname t_snd _xti_xns5_snd
198 #pragma redefine_extname t_snddis _xti_snddis
199 #pragma redefine_extname t_sndrel _xti_sndrel
200 #pragma redefine_extname t_sndreldata _xti_sndreldata
201 #pragma redefine_extname t_sndudata _xti_sndudata
202 #pragma redefine_extname t_sndv _xti_sndv
203 #pragma redefine_extname t_sndvudata _xti_sndvudata
204 #pragma redefine_extname t_strerror _xti_strerror
205 #pragma redefine_extname t_sync _xti_sync
206 #pragma redefine_extname t_sysconf _xti_sysconf
207 #pragma redefine_extname t_unbind _xti_unbind
209 #else /* __PRAGMA_REDEFINE_EXTNAME */
211 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
212 #define t_accept _xti_accept
214 #define t_accept _xti_xns5_accept
216 #define t_alloc _xti_alloc
217 #define t_bind _xti_bind
218 #define t_close _xti_close
219 #define t_connect _xti_connect
220 #define t_error _xti_error
221 #define t_free _xti_free
222 #define t_getinfo _xti_getinfo
223 #define t_getstate _xti_getstate
224 #define t_getprotaddr _xti_getprotaddr
225 #define t_listen _xti_listen
226 #define t_look _xti_look
227 #define t_open _xti_open
228 #define t_optmgmt _xti_optmgmt
229 #define t_rcv _xti_rcv
230 #define t_rcvconnect _xti_rcvconnect
231 #define t_rcvdis _xti_rcvdis
232 #define t_rcvrel _xti_rcvrel
233 #define t_rcvreldata _xti_rcvreldata
234 #define t_rcvudata _xti_rcvudata
235 #define t_rcvuderr _xti_rcvuderr
236 #define t_rcvv _xti_rcvv
237 #define t_rcvvudata _xti_rcvvudata
238 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
239 #define t_snd _xti_snd
241 #define t_snd _xti_xns5_snd
243 #define t_snddis _xti_snddis
244 #define t_sndrel _xti_sndrel
245 #define t_sndreldata _xti_sndreldata
246 #define t_sndudata _xti_sndudata
247 #define t_sndv _xti_sndv
248 #define t_sndvudata _xti_sndvudata
249 #define t_strerror _xti_strerror
250 #define t_sync _xti_sync
251 #define t_sysconf _xti_sysconf
252 #define t_unbind _xti_unbind
254 #endif /* __PRAGMA_REDEFINE_EXTNAME */
257 * protocol specific service limits
260 t_scalar_t addr
; /* max size of protocol address */
261 t_scalar_t options
; /* max size of protocol options */
262 t_scalar_t tsdu
; /* max size of max transport service */
264 t_scalar_t etsdu
; /* max size of max expedited tsdu */
265 t_scalar_t connect
; /* max data for connection primitives */
266 t_scalar_t discon
; /* max data for disconnect primitives */
267 t_scalar_t servtype
; /* provider service type */
268 t_scalar_t flags
; /* other info about transport providers */
272 * Flags definitions for the t_info structure
274 #define T_SENDZERO 0x001 /* supports 0-length TSDUs */
275 #define T_ORDRELDATA 0x002 /* supports orderly release data */
294 t_uscalar_t len
; /* total length of option */
295 t_uscalar_t level
; /* protocol level */
296 t_uscalar_t name
; /* option name */
297 t_uscalar_t status
; /* status value */
298 /* followed by option value */
302 * t_bind - format of the addres and options arguments of bind
319 * disconnect structure
322 struct netbuf udata
; /* user data */
323 int reason
; /* reason code */
324 int sequence
; /* sequence number */
331 struct netbuf addr
; /* address */
332 struct netbuf opt
; /* options */
333 struct netbuf udata
; /* user data */
334 int sequence
; /* sequence number */
338 * data gram structure
341 struct netbuf addr
; /* address */
342 struct netbuf opt
; /* options */
343 struct netbuf udata
; /* user data */
350 struct netbuf addr
; /* address */
351 struct netbuf opt
; /* options */
352 t_scalar_t error
; /* error code */
356 * The following are structure types used when dynamically
357 * allocating the above structures via t_structalloc().
359 #define T_BIND 1 /* struct t_bind */
360 #define T_OPTMGMT 2 /* struct t_optmgmt */
361 #define T_CALL 3 /* struct t_call */
362 #define T_DIS 4 /* struct t_discon */
363 #define T_UNITDATA 5 /* struct t_unitdata */
364 #define T_UDERROR 6 /* struct t_uderr */
365 #define T_INFO 7 /* struct t_info */
368 * The following bits specify which fields of the above
369 * structures should be allocated by t_alloc().
371 #define T_ADDR 0x01 /* address */
372 #define T_OPT 0x02 /* options */
373 #define T_UDATA 0x04 /* user data */
374 #define T_ALL 0xffff /* all the above fields */
378 * the following are the states for the user
381 #define T_UNINIT 0 /* uninitialized */
382 #define T_UNBND 1 /* unbound */
383 #define T_IDLE 2 /* idle */
384 #define T_OUTCON 3 /* outgoing connection pending */
385 #define T_INCON 4 /* incoming connection pending */
386 #define T_DATAXFER 5 /* data transfer */
387 #define T_OUTREL 6 /* outgoing release pending */
388 #define T_INREL 7 /* incoming release pending */
396 * Allegedly general purpose constant. Used with (and needs to be bitwise
397 * distinct from) T_NOPROTECT, T_PASSIVEPROTECT and T_ACTIVEPROTECT
398 * which are OSI specific constants but part of this header (defined
399 * in <xti_osi.h> which is included in this header for historical
400 * XTI specification reasons)
402 #define T_ABSREQ 0x8000
405 * General definitions for option management
407 * Multiple variable length options may be packed into a single option buffer.
408 * Each option consists of a fixed length header followed by variable length
409 * data. The header and data will have to be aligned at appropriate
410 * boundaries. The following macros are used to manipulate the options.
412 * Helper Macros: Macros beginning with a "_T" prefix are helper macros.
413 * They are private, not meant for public use and may
414 * change without notice. Users should use the standard
415 * XTI macros beginning with "T_" prefix
418 #define _T_OPT_HALIGN_SZ (sizeof (t_scalar_t)) /* Hdr Alignment size */
419 #define _T_OPT_DALIGN_SZ (sizeof (int32_t)) /* Data Alignment size */
420 #define _T_OPTHDR_SZ (sizeof (struct t_opthdr))
422 /* Align 'x' to the next 'asize' alignment boundary */
423 #define _T_OPT_ALIGN(x, asize) \
424 (((uintptr_t)(x) + ((asize) - 1L)) & ~((asize) - 1L))
426 /* Align 'x' to the next header alignment boundary */
427 #define _T_OPTHDR_ALIGN(x) \
428 (_T_OPT_ALIGN((x), _T_OPT_HALIGN_SZ))
430 /* Align 'x' to the next data alignment boundary */
431 #define _T_OPTDATA_ALIGN(x) \
432 (_T_OPT_ALIGN((x), _T_OPT_DALIGN_SZ))
435 * struct t_opthdr *T_OPT_FIRSTHDR(struct netbuf *nbp):
436 * Get aligned start of first option header
438 * unsigned char *T_OPT_DATA(struct t_opthdr *tohp):
439 * Get aligned start of data part after option header
441 * struct t_opthdr *T_OPT_NEXTHDR(struct netbuf *nbp, struct t_opthdr *tohp):
442 * Skip to next option header
445 #define T_OPT_FIRSTHDR(nbp) \
446 ((nbp)->len >= _T_OPTHDR_SZ ? (struct t_opthdr *)(nbp)->buf : \
447 (struct t_opthdr *)0)
449 #define T_OPT_DATA(tohp) \
450 ((unsigned char *)_T_OPTDATA_ALIGN((char *)(tohp) + _T_OPTHDR_SZ))
452 #define _T_NEXTHDR(pbuf, buflen, popt) \
453 (((char *)_T_OPTHDR_ALIGN((char *)(popt) + (popt)->len) + \
454 _T_OPTHDR_SZ <= ((char *)(pbuf) + (buflen))) ? \
455 (struct t_opthdr *)((char *)_T_OPTHDR_ALIGN((char *)(popt) + \
456 (popt)->len)) : (struct t_opthdr *)0)
458 #define T_OPT_NEXTHDR(nbp, tohp) (_T_NEXTHDR((nbp)->buf, (nbp)->len, (tohp)))
462 * The macros below are meant for older applications for compatibility.
463 * New applications should use the T_OPT_* macros, obviating the need
464 * to explicitly use the T_ALIGN macro
466 * struct t_opthdr *OPT_NEXTHDR(char *pbuf, unsigned int buflen,
467 * struct t_opthdr *popt):
468 * Skip to next option header
470 #define T_ALIGN(p) (((uintptr_t)(p) + (sizeof (t_scalar_t) - 1))\
471 & ~(sizeof (t_scalar_t) - 1))
472 #define OPT_NEXTHDR(pbuf, buflen, popt) (_T_NEXTHDR((pbuf), (buflen), (popt)))
476 * XTI LIBRARY FUNCTIONS
479 #if defined(_XOPEN_SOURCE) && !defined(_XPG5)
480 extern int t_accept(int, int, struct t_call
*);
481 extern char *t_alloc(int, int, int);
482 extern int t_bind(int, struct t_bind
*, struct t_bind
*);
483 extern int t_connect(int, struct t_call
*, struct t_call
*);
484 extern int t_error(char *);
485 extern int t_free(char *, int);
486 extern int t_open(char *, int, struct t_info
*);
487 extern int t_optmgmt(int, struct t_optmgmt
*, struct t_optmgmt
*);
488 extern int t_rcv(int, char *, unsigned int, int *);
489 extern int t_snd(int, char *, unsigned int, int);
490 extern int t_snddis(int, struct t_call
*);
491 extern int t_sndudata(int, struct t_unitdata
*);
492 extern char *t_strerror(int);
494 extern int t_accept(int, int, const struct t_call
*);
495 extern void *t_alloc(int, int, int);
496 extern int t_bind(int, const struct t_bind
*, struct t_bind
*);
497 extern int t_connect(int, const struct t_call
*, struct t_call
*);
498 extern int t_error(const char *);
499 extern int t_free(void *, int);
500 extern int t_open(const char *, int, struct t_info
*);
501 extern int t_optmgmt(int, const struct t_optmgmt
*, struct t_optmgmt
*);
502 extern int t_rcv(int, void *, unsigned int, int *);
503 extern int t_snd(int, void *, unsigned int, int);
504 extern int t_snddis(int, const struct t_call
*);
505 extern int t_sndudata(int, const struct t_unitdata
*);
506 extern const char *t_strerror(int);
508 extern int t_close(int);
509 extern int t_getinfo(int, struct t_info
*);
510 extern int t_getstate(int);
511 extern int t_getprotaddr(int, struct t_bind
*, struct t_bind
*);
512 extern int t_listen(int, struct t_call
*);
513 extern int t_look(int);
514 extern int t_rcvconnect(int, struct t_call
*);
515 extern int t_rcvdis(int, struct t_discon
*);
516 extern int t_rcvrel(int);
517 extern int t_rcvreldata(int, struct t_discon
*);
518 extern int t_rcvudata(int, struct t_unitdata
*, int *);
519 extern int t_rcvuderr(int, struct t_uderr
*);
520 extern int t_rcvv(int, struct t_iovec
*, unsigned int, int *);
521 extern int t_rcvvudata(int, struct t_unitdata
*, struct t_iovec
*,
522 unsigned int, int *);
523 extern int t_sndrel(int);
524 extern int t_sndreldata(int, struct t_discon
*);
525 extern int t_sndv(int, const struct t_iovec
*, unsigned int, int);
526 extern int t_sndvudata(int, struct t_unitdata
*, struct t_iovec
*,
528 extern int t_sync(int);
529 extern int t_sysconf(int);
530 extern int t_unbind(int);