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