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