xref: /titanic_52/usr/src/uts/common/sys/tihdr.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	All Rights Reserved	*/
24 
25 
26 /*
27  * Copyright (c) 1995,1996 by Sun Microsystems, Inc.
28  * All rights reserved.
29  */
30 
31 #ifndef _SYS_TIHDR_H
32 #define	_SYS_TIHDR_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* from SVr4.0 11.4 */
35 
36 #include <sys/types.h>
37 /*
38  * Include declarations implicit to TPI and shared with user level code
39  */
40 #include <sys/tpicommon.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * The feature test macro, _SUN_TPI_VERSION makes some of additional
48  * declarations available and changes some existing ones. There was
49  * some changes done to this interface and this feature test macro
50  * enables transitioning to those changes while maintaining retaining
51  * backward compatibility.
52  *
53  * The following is all the information
54  * needed by the Transport Service Interface.
55  */
56 
57 /*
58  * The following are the definitions of the Transport
59  * Service Interface primitives.
60  */
61 
62 /*
63  * Primitives that are initiated by the transport user.
64  */
65 #define	T_CONN_REQ	0	/* connection request		*/
66 #if _SUN_TPI_VERSION > 1
67 #define	O_T_CONN_RES	1	/* old connection response	*/
68 #else
69 #define	T_CONN_RES	1	/* connection response		*/
70 #endif /* _SUN_TPI_VERSION > 1 */
71 #define	T_DISCON_REQ	2	/* disconnect request		*/
72 #define	T_DATA_REQ	3	/* data request			*/
73 #define	T_EXDATA_REQ	4	/* expedited data request	*/
74 #define	T_INFO_REQ	5	/* information request		*/
75 /*
76  * Bind Request primitive (TLI inspired
77  * address binding semantics). If requested address is
78  * found to be busy, an alternative free address is
79  * returned. (Requires comparison of requested address to
80  * returned address to verify if the requested address was
81  * bound)
82  *
83  */
84 #if _SUN_TPI_VERSION > 0
85 #define	O_T_BIND_REQ	6
86 #else
87 #define	T_BIND_REQ	6
88 #endif /* _SUN_TPI_VERSION > 0 */
89 
90 #define	T_UNBIND_REQ	7	/* unbind request		*/
91 #define	T_UNITDATA_REQ	8	/* unitdata request		*/
92 
93 /*
94  * Option management request (with TLI inspired semantics )
95  * The preferred name for this primitive in new code is T_SVR4_OPTMGMT_REQ.
96  * This primitive had the name T_OPTMGMT_REQ in old SVR4 derived TPI.
97  * This primitive is used for TLI and Socket API support.
98  * The packing of options in option buffer is private contract
99  * between transport provider and its users and can differ
100  * between different transports.
101  * (The name O_T_OPTMGMT_REQ continues to exist for Solaris 2.6
102  *  compilation environment compatibility only)
103  *
104  */
105 #define	T_SVR4_OPTMGMT_REQ	9
106 #if _SUN_TPI_VERSION > 0
107 #define	O_T_OPTMGMT_REQ	T_SVR4_OPTMGMT_REQ
108 #else
109 #define	T_OPTMGMT_REQ	T_SVR4_OPTMGMT_REQ
110 #endif	/* _SUN_TPI_VERSION > 0 */
111 
112 #define	T_ORDREL_REQ	10	/* orderly release req		*/
113 
114 /*
115  * Primitives that are initiated by the transport provider.
116  */
117 #define	T_CONN_IND	11	/* connection indication	*/
118 #define	T_CONN_CON	12	/* connection confirmation	*/
119 #define	T_DISCON_IND	13	/* disconnect indication	*/
120 #define	T_DATA_IND	14	/* data indication		*/
121 #define	T_EXDATA_IND	15	/* expeditied data indication	*/
122 #define	T_INFO_ACK	16	/* information acknowledgment	*/
123 #define	T_BIND_ACK	17	/* bind acknowledment		*/
124 #define	T_ERROR_ACK	18	/* error acknowledgment		*/
125 #define	T_OK_ACK	19	/* ok acknowledgment		*/
126 #define	T_UNITDATA_IND	20	/* unitdata indication		*/
127 #define	T_UDERROR_IND	21	/* unitdata error indication	*/
128 #define	T_OPTMGMT_ACK	22	/* manage options ack		*/
129 #define	T_ORDREL_IND	23	/* orderly release ind		*/
130 /*
131  * Primitives added to namespace and contain a mix of ones
132  * initiated by transport user or provider.
133  */
134 #define	T_ADDR_REQ	24	/* address request		*/
135 #define	T_ADDR_ACK	25	/* address acknowledgement	*/
136 
137 #if _SUN_TPI_VERSION > 0
138 /*
139  * Bind request primitive with better address
140  * binding semantics. (XTI inspired)
141  * If the requested address is found to be busy,
142  * an error is returned. (No need to compare addresses on successful
143  * bind acknowledgement).
144  */
145 #define	T_BIND_REQ	26	/* bind request			*/
146 
147 /*
148  * Option management request (with XTI inspired semantics)
149  * The packing of options in option buffer is required to
150  * be with 'struct T_opthdr' data structure defined later in
151  * this header.
152  */
153 #define	T_OPTMGMT_REQ	27 /* manage options req - T_opthdr option header */
154 #endif /* _SUN_TPI_VERSION > 0 */
155 
156 #if _SUN_TPI_VERSION > 1
157 /*
158  * The connection response that expects its ACCEPTOR_id to have been
159  * filled in from the value supplied via a T_CAPABILITY_ACK.
160  */
161 #define	T_CONN_RES	28	/* connection response		*/
162 
163 /*
164  * Capability request and ack.  These primitives are optional and
165  * subsume the functionality of T_INFO_{REQ,ACK}.
166  */
167 #define	T_CAPABILITY_REQ	30
168 #define	T_CAPABILITY_ACK	31
169 #endif /* _SUN_TPI_VERSION > 1 */
170 
171 #ifdef _KERNEL
172 /*
173  * Sun private TPI extensions. They are currently used for transparently
174  * passing options through the connection-oriented loopback transport.
175  * Values assigned to them may change.
176  *
177  * T_EXTCONN_IND (extended T_CONN_IND) is used to return dst as well as
178  * src addr/port.
179  */
180 #define	T_OPTDATA_REQ	0x1001	/* data (with options) request	*/
181 #define	T_OPTDATA_IND	0x1002	/* data (with options) indication */
182 #define	T_EXTCONN_IND	0x1003	/* extended T_CONN_IND to return dst as well */
183 #endif /* _KERNEL */
184 
185 /*
186  * The following are the events that drive the state machine
187  */
188 /* Initialization events */
189 #define	TE_BIND_REQ	0	/* bind request				*/
190 #define	TE_UNBIND_REQ	1	/* unbind request			*/
191 #define	TE_OPTMGMT_REQ	2	/* manage options req			*/
192 #define	TE_BIND_ACK	3	/* bind acknowledment			*/
193 #define	TE_OPTMGMT_ACK	4	/* manage options ack			*/
194 #define	TE_ERROR_ACK	5	/* error acknowledgment			*/
195 #define	TE_OK_ACK1	6	/* ok ack  seqcnt == 0			*/
196 #define	TE_OK_ACK2	7	/* ok ack  seqcnt == 1, q == resq	*/
197 #define	TE_OK_ACK3	8	/* ok ack  seqcnt == 1, q != resq	*/
198 #define	TE_OK_ACK4	9	/* ok ack  seqcnt > 1			*/
199 
200 /* Connection oriented events */
201 #define	TE_CONN_REQ	10	/* connection request			*/
202 #define	TE_CONN_RES	11	/* connection response			*/
203 #define	TE_DISCON_REQ	12	/* disconnect request			*/
204 #define	TE_DATA_REQ	13	/* data request				*/
205 #define	TE_EXDATA_REQ	14	/* expedited data request		*/
206 #define	TE_ORDREL_REQ	15	/* orderly release req			*/
207 #define	TE_CONN_IND	16	/* connection indication		*/
208 #define	TE_CONN_CON	17	/* connection confirmation		*/
209 #define	TE_DATA_IND	18	/* data indication			*/
210 #define	TE_EXDATA_IND	19	/* expedited data indication		*/
211 #define	TE_ORDREL_IND	20	/* orderly release ind			*/
212 #define	TE_DISCON_IND1	21	/* disconnect indication seq == 0	*/
213 #define	TE_DISCON_IND2	22	/* disconnect indication seq == 1	*/
214 #define	TE_DISCON_IND3	23	/* disconnect indication seq > 1	*/
215 #define	TE_PASS_CONN	24	/* pass connection			*/
216 
217 /* Unit data events */
218 #define	TE_UNITDATA_REQ	25	/* unitdata request			*/
219 #define	TE_UNITDATA_IND	26	/* unitdata indication			*/
220 #define	TE_UDERROR_IND	27	/* unitdata error indication		*/
221 
222 #define	TE_NOEVENTS	28
223 /*
224  * The following are the possible states of the Transport
225  * Service Interface
226  */
227 
228 #define	TS_UNBND		0	/* unbound			*/
229 #define	TS_WACK_BREQ		1	/* waiting ack of BIND_REQ	*/
230 #define	TS_WACK_UREQ		2	/* waiting ack of UNBIND_REQ	*/
231 #define	TS_IDLE			3	/* idle				*/
232 #define	TS_WACK_OPTREQ		4	/* wait ack options request	*/
233 #define	TS_WACK_CREQ		5	/* waiting ack of CONN_REQ	*/
234 #define	TS_WCON_CREQ		6	/* waiting confirm of CONN_REQ	*/
235 #define	TS_WRES_CIND		7	/* waiting response of CONN_IND	*/
236 #define	TS_WACK_CRES		8	/* waiting ack of CONN_RES	*/
237 #define	TS_DATA_XFER		9	/* data transfer		*/
238 #define	TS_WIND_ORDREL		10	/* releasing rd but not wr	*/
239 #define	TS_WREQ_ORDREL		11	/* wait to release wr but not rd */
240 #define	TS_WACK_DREQ6		12	/* waiting ack of DISCON_REQ	*/
241 #define	TS_WACK_DREQ7		13	/* waiting ack of DISCON_REQ	*/
242 #define	TS_WACK_DREQ9		14	/* waiting ack of DISCON_REQ	*/
243 #define	TS_WACK_DREQ10		15	/* waiting ack of DISCON_REQ	*/
244 #define	TS_WACK_DREQ11		16	/* waiting ack of DISCON_REQ	*/
245 
246 #define	TS_NOSTATES		17
247 
248 
249 /*
250  * The following structure definitions define the format of the
251  * stream message block of the above primitives.
252  * (everything is declared t_scalar_t to ensure proper alignment
253  * across different machines)
254  */
255 
256 /* connection request */
257 
258 struct T_conn_req {
259 	t_scalar_t	PRIM_type;	/* always T_CONN_REQ		*/
260 	t_scalar_t	DEST_length;	/* dest addr length		*/
261 	t_scalar_t	DEST_offset;	/* dest addr offset		*/
262 	t_scalar_t	OPT_length;	/* options length		*/
263 	t_scalar_t	OPT_offset;	/* options offset		*/
264 };
265 
266 /* connect response */
267 
268 /*
269  * Historical compatibility note for "struct T_conn_res" usage.
270  *        "QUEUE_ptr" field of type "queue_t" is obsolete to support
271  *        code portability  and application binary compatibility
272  *        between ILP32(32-bit) and LP64 (64-bit) environments.
273  *        Use field "ACCEPTOR_id" instead.
274  *        For compatibility, drivers using (_SUN_TPI_VERSION >= 2) interface
275  *        can support treating ACCEPTOR_id content as queue pointer
276  *        only when PRIM_type is O_T_CONN_RES.
277  */
278 struct T_conn_res {
279 	t_scalar_t	PRIM_type;	/* T_CONN_RES (or O_T_CONN_RES) */
280 	t_uscalar_t	ACCEPTOR_id;	/* id of accepting endpoint	*/
281 	t_scalar_t	OPT_length;	/* options length		*/
282 	t_scalar_t	OPT_offset;	/* options offset		*/
283 	t_scalar_t	SEQ_number;	/* sequence number		*/
284 };
285 
286 /* disconnect request */
287 
288 struct T_discon_req {
289 	t_scalar_t	PRIM_type;	/* always T_DISCON_REQ		*/
290 	t_scalar_t	SEQ_number;	/* sequnce number		*/
291 };
292 
293 /* data request */
294 
295 struct T_data_req {
296 	t_scalar_t	PRIM_type;	/* always T_DATA_REQ		*/
297 	t_scalar_t	MORE_flag;	/* more data			*/
298 };
299 
300 /* expedited data request */
301 
302 struct T_exdata_req {
303 	t_scalar_t	PRIM_type;	/* always T_EXDATA_REQ		*/
304 	t_scalar_t	MORE_flag;	/* more data			*/
305 };
306 
307 /* information request */
308 
309 struct T_info_req {
310 	t_scalar_t	PRIM_type;	/* always T_INFO_REQ		*/
311 };
312 
313 /* bind request */
314 
315 struct T_bind_req {
316 	t_scalar_t	PRIM_type;	/* T_BIND_REQ (or O_T_BIND_REQ)	*/
317 	t_scalar_t	ADDR_length;	/* addr length			*/
318 	t_scalar_t	ADDR_offset;	/* addr offset			*/
319 	t_uscalar_t	CONIND_number;	/* connect indications requested */
320 };
321 
322 /* unbind request */
323 
324 struct T_unbind_req {
325 	t_scalar_t	PRIM_type;	/* always T_UNBIND_REQ		*/
326 };
327 
328 /* unitdata request */
329 
330 struct T_unitdata_req {
331 	t_scalar_t	PRIM_type;	/* always T_UNITDATA_REQ	*/
332 	t_scalar_t	DEST_length;	/* dest addr length		*/
333 	t_scalar_t	DEST_offset;	/* dest addr offset		*/
334 	t_scalar_t	OPT_length;	/* options length		*/
335 	t_scalar_t	OPT_offset;	/* options offset		*/
336 };
337 
338 /* manage options request */
339 
340 struct T_optmgmt_req {
341 	t_scalar_t	PRIM_type;	/* T_OPTMGMT_REQ or		*/
342 					/* T_SVR4_OPTMGMT_REQ		*/
343 	t_scalar_t	OPT_length;	/* options length		*/
344 	t_scalar_t	OPT_offset;	/* options offset		*/
345 	t_scalar_t	MGMT_flags;	/* options flags		*/
346 };
347 
348 /* orderly release request */
349 
350 struct T_ordrel_req {
351 	t_scalar_t	PRIM_type;	/* always T_ORDREL_REQ		*/
352 };
353 
354 /* protocol address request */
355 
356 struct T_addr_req {
357 	t_scalar_t	PRIM_type;	/* always T_ADDR_REQ		*/
358 };
359 
360 /* connect indication */
361 
362 struct T_conn_ind {
363 	t_scalar_t	PRIM_type;	/* always T_CONN_IND		*/
364 	t_scalar_t	SRC_length;	/* src addr length		*/
365 	t_scalar_t	SRC_offset;	/* src addr offset		*/
366 	t_scalar_t	OPT_length;	/* option length		*/
367 	t_scalar_t	OPT_offset;	/* option offset		*/
368 	t_scalar_t	SEQ_number;	/* sequnce number		*/
369 };
370 
371 /* connect confirmation */
372 
373 struct T_conn_con {
374 	t_scalar_t	PRIM_type;	/* always T_CONN_CON		*/
375 	t_scalar_t	RES_length;	/* responding addr length	*/
376 	t_scalar_t	RES_offset;	/* responding addr offset	*/
377 	t_scalar_t	OPT_length;	/* option length		*/
378 	t_scalar_t	OPT_offset;	/* option offset		*/
379 };
380 
381 /* disconnect indication */
382 
383 struct T_discon_ind {
384 	t_scalar_t	PRIM_type;	/* always T_DISCON_IND		*/
385 	t_scalar_t	DISCON_reason;	/* disconnect reason		*/
386 	t_scalar_t	SEQ_number;	/* sequnce number		*/
387 };
388 
389 /* data indication */
390 
391 struct T_data_ind {
392 	t_scalar_t	PRIM_type;	/* always T_DATA_IND		*/
393 	t_scalar_t	MORE_flag;	/* more data			*/
394 };
395 
396 /* expedited data indication */
397 
398 struct T_exdata_ind {
399 	t_scalar_t	PRIM_type;	/* always T_EXDATA_IND		*/
400 	t_scalar_t	MORE_flag;	/* more data			*/
401 };
402 
403 /* information acknowledgment */
404 
405 struct T_info_ack {
406 	t_scalar_t	PRIM_type;	/* always T_INFO_ACK		*/
407 	t_scalar_t	TSDU_size;	/* max TSDU size		*/
408 	t_scalar_t	ETSDU_size;	/* max ETSDU size		*/
409 	t_scalar_t	CDATA_size;	/* max connect data size	*/
410 	t_scalar_t	DDATA_size;	/* max discon data size		*/
411 	t_scalar_t	ADDR_size;	/* address size			*/
412 	t_scalar_t	OPT_size;	/* options size			*/
413 	t_scalar_t	TIDU_size;	/* max TIDU size		*/
414 	t_scalar_t	SERV_type;	/* provider service type	*/
415 	t_scalar_t	CURRENT_state;	/* current state		*/
416 	t_scalar_t	PROVIDER_flag;	/* provider flags		*/
417 };
418 
419 /*
420  * The following are definitions of flags available to the transport
421  * provider to set in the PROVIDER_flag field of the T_info_ack
422  * structure.
423  */
424 
425 #if _SUN_TPI_VERSION > 0
426 #define	SENDZERO	0x0001	/* provider can handle --length TSDUs */
427 
428 #define	OLD_SENDZERO	0x1000	/* reserved for compatibility with */
429 				/* old providers- old value of */
430 				/* SENDZERO defined in <sys/timod.h> */
431 #else
432 #define	SENDZERO	0x1000	/* old SENDZERO value */
433 #endif /* _SUN_TPI_VERSION > 0 */
434 
435 #define	EXPINLINE	0x0002	/* provider wants ETSDUs in band 0 */
436 /*
437  * Flag XPG4_1:
438  *		transport provider supports TPI modifications motivated by and
439  *		in conjunction with XTI inspired TPI support and all the
440  * 		compatibility baggage that implies.
441  *    It implies, - primitives T_ADDR_REQ & T_ADDR_ACK supported
442  *		  - primitives O_T_BIND_REQ & T_BIND_REQ separately supported
443  *		  - primitives T_SVR4_OPTMGMT_REQ & T_OPTMGMT_REQ separately
444  *		    supported.
445  */
446 #define	XPG4_1		0x0004
447 
448 /* bind acknowledgment */
449 
450 struct T_bind_ack {
451 	t_scalar_t	PRIM_type;	/* always T_BIND_ACK		*/
452 	t_scalar_t	ADDR_length;	/* addr length			*/
453 	t_scalar_t	ADDR_offset;	/* addr offset			*/
454 	t_uscalar_t	CONIND_number;	/* connect ind to be queued	*/
455 };
456 
457 /* error acknowledgment */
458 
459 struct T_error_ack {
460 	t_scalar_t	PRIM_type;	/* always T_ERROR_ACK		*/
461 	t_scalar_t	ERROR_prim;	/* primitive in error		*/
462 	t_scalar_t	TLI_error;	/* TLI error code		*/
463 	t_scalar_t	UNIX_error;	/* UNIX error code		*/
464 };
465 
466 /* ok acknowledgment */
467 
468 struct T_ok_ack {
469 	t_scalar_t	PRIM_type;	/* always T_OK_ACK		*/
470 	t_scalar_t	CORRECT_prim;	/* correct primitive		*/
471 };
472 
473 /* unitdata indication */
474 
475 struct T_unitdata_ind {
476 	t_scalar_t	PRIM_type;	/* always T_UNITDATA_IND	*/
477 	t_scalar_t	SRC_length;	/* source addr length		*/
478 	t_scalar_t	SRC_offset;	/* source addr offset		*/
479 	t_scalar_t	OPT_length;	/* options length		*/
480 	t_scalar_t	OPT_offset;	/* options offset		*/
481 };
482 
483 /* unitdata error indication */
484 
485 struct T_uderror_ind {
486 	t_scalar_t	PRIM_type;	/* always T_UDERROR_IND		*/
487 	t_scalar_t	DEST_length;	/* dest addr length		*/
488 	t_scalar_t	DEST_offset;	/* dest addr offset		*/
489 	t_scalar_t	OPT_length;	/* options length		*/
490 	t_scalar_t	OPT_offset;	/* options offset		*/
491 	t_scalar_t	ERROR_type;	/* error type			*/
492 };
493 
494 /* manage options ack */
495 
496 struct T_optmgmt_ack {
497 	t_scalar_t	PRIM_type;	/* always T_OPTMGMT_ACK		*/
498 	t_scalar_t	OPT_length;	/* options length		*/
499 	t_scalar_t	OPT_offset;	/* options offset		*/
500 	t_scalar_t	MGMT_flags;	/* managment flags		*/
501 };
502 
503 /* orderly release indication */
504 
505 struct T_ordrel_ind {
506 	t_scalar_t	PRIM_type;	/* always T_ORDREL_IND		*/
507 };
508 
509 
510 /* protocol address acknowledgment */
511 
512 struct T_addr_ack {
513 	t_scalar_t	PRIM_type;	/* always T_ADDR_ACK		*/
514 	t_scalar_t	LOCADDR_length;	/* length of local address	*/
515 	t_scalar_t	LOCADDR_offset;	/* offset of local address	*/
516 	t_scalar_t	REMADDR_length;	/* length of remote address	*/
517 	t_scalar_t	REMADDR_offset;	/* offset of remote address	*/
518 };
519 
520 #if _SUN_TPI_VERSION > 1
521 /*
522  * Capability request and ack.  These primitives are optional and
523  * subsume the functionality of T_INFO_{REQ,ACK}.
524  */
525 struct T_capability_req {
526 	t_scalar_t	PRIM_type;	/* always T_CAPABILITY_REQ 	*/
527 	t_uscalar_t	CAP_bits1;	/* capability bits #1		*/
528 };
529 
530 struct T_capability_ack {
531 	t_scalar_t	PRIM_type;	/* always T_CAPABILITY_ACK 	*/
532 	t_uscalar_t	CAP_bits1;	/* capability bits #1		*/
533 	struct T_info_ack
534 			INFO_ack;	/* info acknowledgement		*/
535 	t_uscalar_t	ACCEPTOR_id;	/* accepting endpoint id	*/
536 };
537 
538 #define	TC1_INFO	(1u << 0)	/* Info request/ack		*/
539 #define	TC1_ACCEPTOR_ID	(1u << 1)	/* Acceptor_id request/ack	*/
540 #define	TC1_CAP_BITS2	(1u << 31)	/* Reserved for future use	*/
541 
542 #endif /* _SUN_TPI_VERSION > 1 */
543 
544 #ifdef _KERNEL
545 /*
546  * Private Sun TPI extensions.
547  */
548 
549 /* data (with options) request */
550 struct T_optdata_req {
551 	t_scalar_t	PRIM_type;	/* always T_OPTDATA_REQ		*/
552 	t_scalar_t	DATA_flag;	/* flags like "more data"	*/
553 	t_scalar_t	OPT_length;	/* options length		*/
554 	t_scalar_t	OPT_offset;	/* options offset		*/
555 };
556 
557 /* data (with options) indication */
558 struct T_optdata_ind {
559 	t_scalar_t	PRIM_type;	/* always T_OPTDATA_IND		*/
560 	t_scalar_t	DATA_flag;	/* flags like "more data"	*/
561 	t_scalar_t	OPT_length;	/* options length		*/
562 	t_scalar_t	OPT_offset;	/* options offset		*/
563 };
564 
565 /* extended connect indication to return dst addr/port as well as src */
566 struct T_extconn_ind {
567 	t_scalar_t	PRIM_type;	/* always T_EXTCONN_IND		*/
568 	t_scalar_t	SRC_length;	/* src addr length		*/
569 	t_scalar_t	SRC_offset;	/* src addr offset		*/
570 	t_scalar_t	OPT_length;	/* option length		*/
571 	t_scalar_t	OPT_offset;	/* option offset		*/
572 	t_scalar_t	SEQ_number;	/* sequnce number		*/
573 	t_scalar_t	DEST_length;	/* dest addr length		*/
574 	t_scalar_t	DEST_offset;	/* dest addr offset		*/
575 };
576 #endif /* _KERNEL */
577 
578 /*
579  * The following is a union of the primitives
580  */
581 union T_primitives {
582 	t_scalar_t		type;		/* primitive type	*/
583 	struct T_conn_req	conn_req;	/* connect request	*/
584 	struct T_conn_res	conn_res;	/* connect response	*/
585 	struct T_discon_req	discon_req;	/* disconnect request	*/
586 	struct T_data_req	data_req;	/* data request		*/
587 	struct T_exdata_req	exdata_req;	/* expedited data req	*/
588 	struct T_info_req	info_req;	/* information req	*/
589 	struct T_bind_req	bind_req;	/* bind request		*/
590 	struct T_unbind_req	unbind_req;	/* unbind request	*/
591 	struct T_unitdata_req	unitdata_req;	/* unitdata requset	*/
592 	struct T_optmgmt_req	optmgmt_req;	/* manage opt req	*/
593 	struct T_ordrel_req	ordrel_req;	/* orderly rel req	*/
594 	struct T_addr_req	addr_req;	/* address request	*/
595 	struct T_conn_ind	conn_ind;	/* connect indication	*/
596 	struct T_conn_con	conn_con;	/* connect corfirm	*/
597 	struct T_discon_ind	discon_ind;	/* discon indication	*/
598 	struct T_data_ind	data_ind;	/* data indication	*/
599 	struct T_exdata_ind	exdata_ind;	/* expedited data ind	*/
600 	struct T_info_ack	info_ack;	/* info ack		*/
601 	struct T_bind_ack	bind_ack;	/* bind ack		*/
602 	struct T_error_ack	error_ack;	/* error ack		*/
603 	struct T_ok_ack		ok_ack;		/* ok ack		*/
604 	struct T_unitdata_ind	unitdata_ind;	/* unitdata ind		*/
605 	struct T_uderror_ind	uderror_ind;	/* unitdata error ind	*/
606 	struct T_optmgmt_ack	optmgmt_ack;	/* manage opt ack	*/
607 	struct T_ordrel_ind	ordrel_ind;	/* orderly rel ind	*/
608 	struct T_addr_ack	addr_ack;	/* address ack		*/
609 #if _SUN_TPI_VERSION > 1
610 	struct T_capability_req	capability_req;	/* capability req	*/
611 	struct T_capability_ack	capability_ack;	/* capability ack	*/
612 #endif /* _SUN_TPI_VERSION > 1 */
613 #ifdef _KERNEL
614 	struct T_optdata_req	optdata_req;	/* option data request	*/
615 	struct T_optdata_ind	optdata_ind;	/* option data ind	*/
616 	struct T_extconn_ind	extconn_ind;	/* above plus dst addr	*/
617 #endif /* _KERNEL */
618 };
619 
620 /*
621  * TPI specification is not clear on how to pack options in option
622  * buffers. What follows is the Solaris TPI interpretation of it.
623  *
624  * struct T_opthdr data structure is used to pack options in T_OPTMGMT_{REQ,ACK}
625  * message primitives in buffer delimited by [OPT_offset, OPT_length] fields in
626  * struct T_optmgmt_req/T_optmgmt_ack data structures.
627  *
628  * It is also used to pack options in similar buffers for data structures in
629  * T_CONN_{REQ,IND,RES,CONN} primitives and T_UNITDATA_{REQ,IND} primitives
630  * Needs to be on t_uscalar_t (32-bit word) aligned boundary.
631  *
632  * Note: T_SVR4_OPTMGMT_REQ primitive can, but need not, use this data
633  *       structure for packing options. The format of option buffer for
634  *       T_SVR4_OPTMGMT_REQ primitive is undefined and is a private contract
635  *       between transport provider and its users.
636  *
637  * |<--------------first option---------------->|     |<--second option--...
638  * ______________________________________ _ _ _ ____________________________
639  * | len | level | name | status |  value.......| / / | len ...
640  * -------------------------------------- - - - ----------------------------
641  * |32bit| 32bit |32bit |  32bit |                 ^  | 32bit...
642  *                                                 |
643  *                                                 |
644  *                                        alignment characters
645  */
646 struct T_opthdr {
647 	t_uscalar_t	len;	/* total length of option (header+value) */
648 	t_uscalar_t	level;	/* protocol level */
649 	t_uscalar_t	name;	/* option name */
650 	t_uscalar_t	status;	/* status value */
651 	/* option value aligned on t_uscalar_t (32-bit) alignment boundary */
652 };
653 
654 /*
655  * ------------------------------------------------------------------------
656  * Common experimental private TPI alignment related macros. Not for
657  * use outside Solaris bundled code and can change in any release.
658  * The alignment boundary _TPI_ALIGN_SIZE represents an implementation
659  * choice for aligning many data objects which are directly or indirectly
660  * associated with Solaris TPI implementation.
661  * ------------------------------------------------------------------------
662  */
663 
664 #define	__TPI_ALIGN_SIZE		(sizeof (t_scalar_t))
665 #define	__TPI_ALIGN(x) \
666 	(((uintptr_t)(x) + __TPI_ALIGN_SIZE - 1) & ~(__TPI_ALIGN_SIZE - 1))
667 #define	__TPI_SIZE_ISALIGNED(x) \
668 		(((uintptr_t)(x) & (__TPI_ALIGN_SIZE - 1)) == 0)
669 
670 /*
671  * TPI primitive in message must be aligned at _TPI_ALIGN_SIZE boundary
672  */
673 #define	__TPI_PRIM_ISALIGNED(x)	__TPI_SIZE_ISALIGNED(x)
674 
675 /*
676  * TPI option header "struct opthdr" objects must be aligned
677  * at __TPI_ALIGN_SIZE boundary.
678  */
679 #define	__TPI_OPT_ISALIGNED(x)	__TPI_SIZE_ISALIGNED(x)
680 #define	_TPI_ALIGN_OPT(x)	__TPI_ALIGN(x)
681 
682 /*
683  * TPI option header "struct T_opthdr" objects must be aligned
684  * at __TPI_ALIGN_SIZE boundary.
685  */
686 #define	__TPI_TOPT_ISALIGNED(x)	__TPI_SIZE_ISALIGNED(x)
687 #define	_TPI_ALIGN_TOPT(x)	__TPI_ALIGN(x)
688 
689 /*
690  * --------------------------------------------------------------------
691  * Private experimental macros. Not for use outside Solaris bundled
692  * source code and can change in any release.
693  * Macros that operate on struct T_opthdr. These are roughly modelled
694  * after the corresponding Socket CMSG_*() and XTI T_OPT_*() macros, but
695  * are applied to TPI option buffers.
696  * --------------------------------------------------------------------
697  *
698  * unsigned char *
699  * _TPI_TOPT_DATA(struct T_opthdr *tohp):
700  *      Get start of data part after option header
701  */
702 #define	_TPI_TOPT_DATA(tohp)	\
703 	((unsigned char *)((char *)(tohp) + sizeof (struct T_opthdr)))
704 
705 /*
706  * t_uscalar_t
707  * _TPI_TOPT_DATALEN(tohp)
708  *	Get length of contents of option data excluding header (and
709  *	padding etc if any).
710  */
711 #define	_TPI_TOPT_DATALEN(tohp)	((tohp)->len - sizeof (struct T_opthdr))
712 
713 /*
714  * struct T_opthdr *
715  * _TPI_TOPT_FIRSTHDR(char *pbuf, t_scalar_t buflen):
716  *	Get pointer to the first option header in buffer 'pbuf'
717  *	Return NULL if there is not enough room for the header
718  *
719  * struct T_opthdr *
720  * _TPI_TOPT_NEXTHDR(char *pbuf, t_scalar_t buflen,
721  *					struct T_opthdr *popt):
722  *	Skip to next option header
723  *
724  * Notes:  _TPI_TOPT_NEXTHDR performs the roundup of the length.
725  *
726  *	If _TPI_TOPT_{FIRST,NEXT}HDR returns a non-null value, the user of
727  *      _TPI_TOPT_{FIRST,NEXT}HDR must still verify that the resulting pointer
728  *	is valid, by making a call to _TPI_TOPT_VALID. The _TPI_TOPT_VALID
729  *	macro does not assume that the last option buffer is padded.
730  */
731 #define	_TPI_TOPT_FIRSTHDR(pbuf, buflen) \
732 	((((buflen) >= (unsigned int) sizeof (struct T_opthdr)) && \
733 		__TPI_TOPT_ISALIGNED(pbuf)) ? \
734 	    (struct T_opthdr *)(pbuf) : (struct T_opthdr *)0)
735 
736 #define	_TPI_TOPT_NEXTHDR(pbuf, buflen, popt) \
737 	(((char *)(popt) + _TPI_ALIGN_TOPT((popt)->len)) < \
738 	    ((char *)(pbuf) + (buflen)) ?  \
739 	(struct T_opthdr *)((char *)(popt) + _TPI_ALIGN_TOPT((popt)->len)) : \
740 	    (struct T_opthdr *)0)
741 
742 /*
743  * bool_t
744  * _TPI_TOPT_VALID(struct T_opthdr *tohp, char *start, char *end)
745  *	Validate the option header at tohp, for its alignment and length.
746  *	1. check that tohp is aligned at t_scalar_t boundary
747  *	2. check that start <= tohp < end
748  *	3. validate the length, should be >= sizeof(T_opthdr) and
749  *	   check that there is no pointer arithmetic overflow.
750  *	   (could be caused by a very large value for tohp->len)
751  */
752 
753 #define	_TPI_TOPT_VALID(tohp, start, end)			\
754 	(__TPI_TOPT_ISALIGNED(tohp) &&				\
755 	((uintptr_t)(tohp) >= (uintptr_t)(start)) &&		\
756 	((uintptr_t)(tohp) < (uintptr_t)(end)) &&		\
757 	((ssize_t)(tohp)->len >= sizeof (struct T_opthdr)) &&	\
758 	((uintptr_t)(tohp) + (tohp)->len <= (uintptr_t)(end)) && \
759 	((uintptr_t)(tohp) + (tohp)->len >= (uintptr_t)(tohp) +	\
760 	    sizeof (struct T_opthdr)))
761 
762 #ifdef __cplusplus
763 }
764 #endif
765 
766 #endif /* _SYS_TIHDR_H */
767