xref: /titanic_50/usr/src/uts/common/inet/optcom.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1990 Mentat Inc. */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #ifndef	_INET_OPTCOM_H
29*7c478bd9Sstevel@tonic-gate #define	_INET_OPTCOM_H
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
34*7c478bd9Sstevel@tonic-gate extern "C" {
35*7c478bd9Sstevel@tonic-gate #endif
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && defined(__STDC__)
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /* Options Description Structure */
40*7c478bd9Sstevel@tonic-gate typedef struct opdes_s {
41*7c478bd9Sstevel@tonic-gate 	t_uscalar_t	opdes_name;	/* option name */
42*7c478bd9Sstevel@tonic-gate 	t_uscalar_t	opdes_level;	/* option "level" */
43*7c478bd9Sstevel@tonic-gate 	int	opdes_access_nopriv;	/* permissions for non-privileged */
44*7c478bd9Sstevel@tonic-gate 	int	opdes_access_priv;	/* permissions for privileged */
45*7c478bd9Sstevel@tonic-gate 	int	opdes_access_req_priv;	/* required privilege, OP_NP if none */
46*7c478bd9Sstevel@tonic-gate 	int	opdes_props;	/* properties of associated with option */
47*7c478bd9Sstevel@tonic-gate 	t_uscalar_t	opdes_size;	/* length of option */
48*7c478bd9Sstevel@tonic-gate 					/* [ or maxlen if variable */
49*7c478bd9Sstevel@tonic-gate 			/* length(OP_VARLEN) property set for option] */
50*7c478bd9Sstevel@tonic-gate 	union {
51*7c478bd9Sstevel@tonic-gate 		/*
52*7c478bd9Sstevel@tonic-gate 		 *
53*7c478bd9Sstevel@tonic-gate 		 * Note: C semantics:
54*7c478bd9Sstevel@tonic-gate 		 * static initializer of "union" type assume
55*7c478bd9Sstevel@tonic-gate 		 * the constant on RHS is of the type of the
56*7c478bd9Sstevel@tonic-gate 		 * first member of the union. So what comes first
57*7c478bd9Sstevel@tonic-gate 		 * is important.
58*7c478bd9Sstevel@tonic-gate 		 */
59*7c478bd9Sstevel@tonic-gate #define	OPDES_DEFSZ_MAX		64
60*7c478bd9Sstevel@tonic-gate 		int64_t  opdes_def_int64;
61*7c478bd9Sstevel@tonic-gate 		char	opdes_def_charbuf[OPDES_DEFSZ_MAX];
62*7c478bd9Sstevel@tonic-gate 	} opdes_def;
63*7c478bd9Sstevel@tonic-gate } opdes_t;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #define	opdes_default	opdes_def.opdes_def_int64
66*7c478bd9Sstevel@tonic-gate #define	opdes_defbuf	opdes_def.opdes_def_charbuf
67*7c478bd9Sstevel@tonic-gate /*
68*7c478bd9Sstevel@tonic-gate  * Flags to set in opdes_acces_{all,priv} fields in opdes_t
69*7c478bd9Sstevel@tonic-gate  *
70*7c478bd9Sstevel@tonic-gate  *	OA_R	read access
71*7c478bd9Sstevel@tonic-gate  *	OA_W	write access
72*7c478bd9Sstevel@tonic-gate  *	OA_RW	read-write access
73*7c478bd9Sstevel@tonic-gate  *	OA_X	execute access
74*7c478bd9Sstevel@tonic-gate  *
75*7c478bd9Sstevel@tonic-gate  * Note: - semantics "execute" access used for operations excuted using
76*7c478bd9Sstevel@tonic-gate  *		option management interface
77*7c478bd9Sstevel@tonic-gate  *	- no bits set means this option is not visible. Some options may not
78*7c478bd9Sstevel@tonic-gate  *	  even be visible to all but priviliged users.
79*7c478bd9Sstevel@tonic-gate  */
80*7c478bd9Sstevel@tonic-gate #define	OA_R	0x1
81*7c478bd9Sstevel@tonic-gate #define	OA_W	0x2
82*7c478bd9Sstevel@tonic-gate #define	OA_X	0x4
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate /*
85*7c478bd9Sstevel@tonic-gate  * Utility macros to test permissions needed to compose more
86*7c478bd9Sstevel@tonic-gate  * complex ones. (Only a few really used directly in code).
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate #define	OA_RW	(OA_R|OA_W)
89*7c478bd9Sstevel@tonic-gate #define	OA_WX	(OA_W|OA_X)
90*7c478bd9Sstevel@tonic-gate #define	OA_RX	(OA_R|OA_X)
91*7c478bd9Sstevel@tonic-gate #define	OA_RWX	(OA_R|OA_W|OA_X)
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate #define	OA_ANY_ACCESS(x) ((x)->opdes_access_nopriv|(x)->opdes_access_priv)
94*7c478bd9Sstevel@tonic-gate #define	OA_R_NOPRIV(x)	((x)->opdes_access_nopriv & OA_R)
95*7c478bd9Sstevel@tonic-gate #define	OA_R_ANYPRIV(x)	(OA_ANY_ACCESS(x) & OA_R)
96*7c478bd9Sstevel@tonic-gate #define	OA_W_NOPRIV(x)	((x)->opdes_access_nopriv & OA_W)
97*7c478bd9Sstevel@tonic-gate #define	OA_X_ANYPRIV(x)	(OA_ANY_ACCESS(x) & OA_X)
98*7c478bd9Sstevel@tonic-gate #define	OA_X_NOPRIV(x)	((x)->opdes_access_nopriv & OA_X)
99*7c478bd9Sstevel@tonic-gate #define	OA_W_ANYPRIV(x)	(OA_ANY_ACCESS(x) & OA_W)
100*7c478bd9Sstevel@tonic-gate #define	OA_WX_NOPRIV(x)	((x)->opdes_access_nopriv & OA_WX)
101*7c478bd9Sstevel@tonic-gate #define	OA_WX_ANYPRIV(x)	(OA_ANY_ACCESS(x) & OA_WX)
102*7c478bd9Sstevel@tonic-gate #define	OA_RWX_ANYPRIV(x)	(OA_ANY_ACCESS(x) & OA_RWX)
103*7c478bd9Sstevel@tonic-gate #define	OA_RONLY_NOPRIV(x)	(((x)->opdes_access_nopriv & OA_RWX) == OA_R)
104*7c478bd9Sstevel@tonic-gate #define	OA_RONLY_ANYPRIV(x)	((OA_ANY_ACCESS(x) & OA_RWX) == OA_R)
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate #define	OP_NP		(-1)			/* No privilege required */
107*7c478bd9Sstevel@tonic-gate #define	OP_CONFIG	(0)			/* Network configuration */
108*7c478bd9Sstevel@tonic-gate #define	OP_RAW		(1)			/* Raw packets */
109*7c478bd9Sstevel@tonic-gate #define	OP_PRIVPORT	(2)			/* Privileged ports */
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate /*
113*7c478bd9Sstevel@tonic-gate  * Following macros supply the option and their privilege and
114*7c478bd9Sstevel@tonic-gate  * are used to determine permissions.
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate #define	OA_POLICY_OK(x, c) \
117*7c478bd9Sstevel@tonic-gate 		(secpolicy_net((c), (x)->opdes_access_req_priv, B_FALSE) == 0)
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate #define	OA_POLICY_ONLY_OK(x, c) \
120*7c478bd9Sstevel@tonic-gate 		(secpolicy_net((c), (x)->opdes_access_req_priv, B_TRUE) == 0)
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate #define	OA_MATCHED_PRIV(x, c)	((x)->opdes_access_req_priv != OP_NP && \
123*7c478bd9Sstevel@tonic-gate 		OA_POLICY_ONLY_OK((x), (c)))
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate #define	OA_READ_PERMISSION(x, c)	(OA_R_NOPRIV(x) || \
126*7c478bd9Sstevel@tonic-gate 		(OA_R_ANYPRIV(x) && OA_POLICY_OK((x), (c))))
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate #define	OA_WRITE_OR_EXECUTE(x, c)	(OA_WX_NOPRIV(x) || \
129*7c478bd9Sstevel@tonic-gate 		(OA_WX_ANYPRIV(x) && OA_POLICY_OK((x), (c))))
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate #define	OA_READONLY_PERMISSION(x, c)	(OA_RONLY_NOPRIV(x) || \
132*7c478bd9Sstevel@tonic-gate 		(OA_RONLY_ANYPRIV(x) && OA_POLICY_OK((x), (c))))
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate #define	OA_WRITE_PERMISSION(x, c)	(OA_W_NOPRIV(x) || \
135*7c478bd9Sstevel@tonic-gate 		(OA_W_ANYPRIV(x) && OA_POLICY_ONLY_OK((x), (c))))
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate #define	OA_EXECUTE_PERMISSION(x, c)	(OA_X_NOPRIV(x) || \
138*7c478bd9Sstevel@tonic-gate 		(OA_X_ANYPRIV(x) && OA_POLICY_ONLY_OK((x), (c))))
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate #define	OA_NO_PERMISSION(x, c)		(OA_MATCHED_PRIV((x), (c)) ? \
141*7c478bd9Sstevel@tonic-gate 		((x)->opdes_access_priv == 0) : ((x)->opdes_access_nopriv == 0))
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate  * Other properties set in opdes_props field.
145*7c478bd9Sstevel@tonic-gate  */
146*7c478bd9Sstevel@tonic-gate #define	OP_PASSNEXT	0x1	/* to pass option to next module or not */
147*7c478bd9Sstevel@tonic-gate #define	OP_VARLEN	0x2	/* option is varible length  */
148*7c478bd9Sstevel@tonic-gate #define	OP_NOT_ABSREQ	0x4	/* option is not a "absolute requirement" */
149*7c478bd9Sstevel@tonic-gate 				/* i.e. failure to negotiate does not */
150*7c478bd9Sstevel@tonic-gate 				/* abort primitive ("ignore" semantics ok) */
151*7c478bd9Sstevel@tonic-gate #define	OP_NODEFAULT	0x8	/* no concept of "default value"  */
152*7c478bd9Sstevel@tonic-gate #define	OP_DEF_FN	0x10	/* call a "default function" to get default */
153*7c478bd9Sstevel@tonic-gate 				/* value, not from static table  */
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate /*
157*7c478bd9Sstevel@tonic-gate  * Structure to represent attributed of option management specific
158*7c478bd9Sstevel@tonic-gate  * to one particular layer of "transport".
159*7c478bd9Sstevel@tonic-gate  */
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate typedef	t_uscalar_t optlevel_t;
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate typedef int (*opt_def_fn)(queue_t *, int, int, uchar_t *);
164*7c478bd9Sstevel@tonic-gate typedef int (*opt_get_fn)(queue_t *, int, int, uchar_t *);
165*7c478bd9Sstevel@tonic-gate typedef int (*opt_set_fn)(queue_t *, uint_t, int, int, uint_t, uchar_t *,
166*7c478bd9Sstevel@tonic-gate     uint_t *, uchar_t *, void *, cred_t *, mblk_t *);
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate typedef struct optdb_obj {
169*7c478bd9Sstevel@tonic-gate 	opt_def_fn	odb_deffn;	/* default value function */
170*7c478bd9Sstevel@tonic-gate 	opt_get_fn	odb_getfn;	/* get function */
171*7c478bd9Sstevel@tonic-gate 	opt_set_fn	odb_setfn;	/* set function */
172*7c478bd9Sstevel@tonic-gate 	boolean_t	odb_topmost_tpiprovider; /* whether topmost tpi */
173*7c478bd9Sstevel@tonic-gate 					/* provider or downstream */
174*7c478bd9Sstevel@tonic-gate 	uint_t		odb_opt_arr_cnt; /* count of number of options in db */
175*7c478bd9Sstevel@tonic-gate 	opdes_t		*odb_opt_des_arr; /* option descriptors in db */
176*7c478bd9Sstevel@tonic-gate 	uint_t		odb_valid_levels_arr_cnt;
177*7c478bd9Sstevel@tonic-gate 					/* count of option levels supported */
178*7c478bd9Sstevel@tonic-gate 	optlevel_t	*odb_valid_levels_arr;
179*7c478bd9Sstevel@tonic-gate 					/* array of option levels supported */
180*7c478bd9Sstevel@tonic-gate } optdb_obj_t;
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate /*
183*7c478bd9Sstevel@tonic-gate  * This is used to restart option processing. This goes inside an M_CTL
184*7c478bd9Sstevel@tonic-gate  * which is prepended to the packet. IP may need to become exclusive on
185*7c478bd9Sstevel@tonic-gate  * an ill for setting some options. For dg. IP_ADD_MEMBERSHIP. Since
186*7c478bd9Sstevel@tonic-gate  * there can be more than 1 option packed in an option buffer, we need to
187*7c478bd9Sstevel@tonic-gate  * remember where to restart option processing after resuming from a wait
188*7c478bd9Sstevel@tonic-gate  * for exclusive condition in IP.
189*7c478bd9Sstevel@tonic-gate  */
190*7c478bd9Sstevel@tonic-gate typedef struct opt_restart_s {
191*7c478bd9Sstevel@tonic-gate 	struct	opthdr	*or_start;		/* start of option buffer */
192*7c478bd9Sstevel@tonic-gate 	struct	opthdr	*or_end;		/* end of option buffer */
193*7c478bd9Sstevel@tonic-gate 	struct	opthdr	*or_ropt;		/* restart option here */
194*7c478bd9Sstevel@tonic-gate 	t_uscalar_t	or_worst_status;	/* Used by tpi_optcom_req */
195*7c478bd9Sstevel@tonic-gate 	t_uscalar_t	or_type;		/* svr4 or tpi optcom variant */
196*7c478bd9Sstevel@tonic-gate 	int		or_private;		/* currently used by CGTP */
197*7c478bd9Sstevel@tonic-gate } opt_restart_t;
198*7c478bd9Sstevel@tonic-gate /*
199*7c478bd9Sstevel@tonic-gate  * Values for "optset_context" parameter passed to
200*7c478bd9Sstevel@tonic-gate  * transport specific "setfn()" routines
201*7c478bd9Sstevel@tonic-gate  */
202*7c478bd9Sstevel@tonic-gate #define	SETFN_OPTCOM_CHECKONLY		1 /* "checkonly" semantics T_CHECK */
203*7c478bd9Sstevel@tonic-gate #define	SETFN_OPTCOM_NEGOTIATE		2 /* semantics for T_*_OPTCOM_REQ */
204*7c478bd9Sstevel@tonic-gate #define	SETFN_UD_NEGOTIATE		3 /* semantics for T_UNITDATA_REQ */
205*7c478bd9Sstevel@tonic-gate #define	SETFN_CONN_NEGOTIATE		4 /* semantics for T_CONN_*_REQ */
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate /*
208*7c478bd9Sstevel@tonic-gate  * Function prototypes
209*7c478bd9Sstevel@tonic-gate  */
210*7c478bd9Sstevel@tonic-gate extern void optcom_err_ack(queue_t *, mblk_t *, t_scalar_t, int);
211*7c478bd9Sstevel@tonic-gate extern int svr4_optcom_req(queue_t *, mblk_t *, cred_t *, optdb_obj_t *);
212*7c478bd9Sstevel@tonic-gate extern int tpi_optcom_req(queue_t *, mblk_t *, cred_t *, optdb_obj_t *);
213*7c478bd9Sstevel@tonic-gate extern int  tpi_optcom_buf(queue_t *, mblk_t *, t_scalar_t *, t_scalar_t,
214*7c478bd9Sstevel@tonic-gate     cred_t *, optdb_obj_t *, void *, int *);
215*7c478bd9Sstevel@tonic-gate extern t_uscalar_t optcom_max_optsize(opdes_t *, uint_t);
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) && defined(__STDC__) */
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
220*7c478bd9Sstevel@tonic-gate }
221*7c478bd9Sstevel@tonic-gate #endif
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate #endif	/* _INET_OPTCOM_H */
224