xref: /titanic_52/usr/src/cmd/isns/isnsd/isns_server.h (revision 5c51f1241dbbdf2656d0e10011981411ed0c9673)
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 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 
28 #ifndef _ISNS_SERVER_H
29 #define	_ISNS_SERVER_H
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <assert.h>
36 #include <sys/param.h>
37 #include <isns_protocol.h>
38 
39 #ifdef DEBUG
40 #define	ASSERT(EXP)	assert(EXP)
41 #else
42 #define	ASSERT(EXP)
43 #endif
44 
45 #define	ISNS_RSP_MASK	(0x8000)
46 
47 /*
48  * definitions for SMF.
49  */
50 #define	ISNS_SERVER_SVC_NAME	"network/isns_server"
51 #define	ISNS_SERVER_CONFIG	"config"
52 #define	CONFIG_DATA_STORE	"data_store_location"
53 #define	CONFIG_ESI_THRESHOLD	"ESI_retry_threshold_count"
54 #define	CONFIG_MGMT_SCN		"Management_SCN_Enabled"
55 #define	CONFIG_CONTROL_NODES	"Authorized_Control_Nodes"
56 #ifdef DEBUG
57 #define	OPT_DAEMONLIZE		"daemonlize"
58 #endif
59 
60 #define	ISNS_DAEMON_SYSLOG_PP "isns"
61 
62 #define	FIRST_TAG_ENTITY	ISNS_EID_ATTR_ID
63 #define	FIRST_TAG_ISCSI		ISNS_ISCSI_NAME_ATTR_ID
64 #define	FIRST_TAG_PORTAL	ISNS_PORTAL_IP_ADDR_ATTR_ID
65 #define	FIRST_TAG_PG		ISNS_PG_ISCSI_NAME_ATTR_ID
66 #define	FIRST_TAG_DD		ISNS_DD_ID_ATTR_ID
67 #define	FIRST_TAG_DDS		ISNS_DD_SET_ID_ATTR_ID
68 #define	FIRST_TAG_ASSOC_ISCSI	ISNS_DD_ISCSI_INDEX_ATTR_ID
69 #define	FIRST_TAG_ASSOC_DD	ISNS_DD_ID_ATTR_ID
70 
71 #define	LAST_TAG_ENTITY		ISNS_ENTITY_INDEX_ATTR_ID
72 #define	LAST_TAG_ISCSI		ISNS_ISCSI_AUTH_METHOD_ATTR_ID
73 #define	LAST_TAG_PORTAL		ISNS_SCN_PORT_ATTR_ID
74 #define	LAST_TAG_PG		ISNS_PG_INDEX_ATTR_ID
75 #define	LAST_TAG_DD		ISNS_DD_FEATURES_ATTR_ID
76 #define	LAST_TAG_DDS		ISNS_DD_SET_STATUS_ATTR_ID
77 #define	LAST_TAG_ASSOC_ISCSI	ISNS_DD_ISCSI_NAME_ATTR_ID
78 #define	LAST_TAG_ASSOC_DD	ISNS_DD_ID_ATTR_ID
79 
80 #define	NUM_OF_ENTITY_ATTRS \
81 	(LAST_TAG_ENTITY - FIRST_TAG_ENTITY + 1)
82 #define	NUM_OF_ISCSI_ATTRS \
83 	(LAST_TAG_ISCSI - FIRST_TAG_ISCSI + 1)
84 #define	NUM_OF_PORTAL_ATTRS \
85 	(LAST_TAG_PORTAL - FIRST_TAG_PORTAL + 1)
86 #define	NUM_OF_PG_ATTRS \
87 	(LAST_TAG_PG - FIRST_TAG_PG + 1)
88 #define	NUM_OF_DD_ATTRS \
89 	(LAST_TAG_DD - FIRST_TAG_DD + 1)
90 #define	NUM_OF_DDS_ATTRS \
91 	(LAST_TAG_DDS - FIRST_TAG_DDS + 1)
92 #define	NUM_OF_ASSOC_ISCSI_ATTRS \
93 	(LAST_TAG_ASSOC_ISCSI - FIRST_TAG_ASSOC_ISCSI + 1)
94 #define	NUM_OF_ASSOC_DD_ATTRS \
95 	(LAST_TAG_ASSOC_DD - FIRST_TAG_ASSOC_DD + 1)
96 
97 #define	ATTR_INDEX_ENTITY(TAG)	((TAG) - FIRST_TAG_ENTITY)
98 #define	ATTR_INDEX_ISCSI(TAG)	((TAG) - FIRST_TAG_ISCSI)
99 #define	ATTR_INDEX_PORTAL(TAG)	((TAG) - FIRST_TAG_PORTAL)
100 #define	ATTR_INDEX_PG(TAG)	((TAG) - FIRST_TAG_PG)
101 #define	ATTR_INDEX_DD(TAG)	((TAG) - FIRST_TAG_DD)
102 #define	ATTR_INDEX_DDS(TAG)	((TAG) - FIRST_TAG_DDS)
103 #define	ATTR_INDEX_ASSOC_ISCSI(TAG)	((TAG) - FIRST_TAG_ASSOC_ISCSI)
104 #define	ATTR_INDEX_ASSOC_DD(TAG)	((TAG) - FIRST_TAG_ASSOC_DD)
105 #define	ATTR_INDEX(TAG, TYPE)	((TAG) - TAG_RANGE[TYPE][0])
106 
107 #define	ISCSI_ATTR(ISCSI, TAG)	((ISCSI)->attrs[ATTR_INDEX_ISCSI(TAG)].value)
108 
109 /*
110  * isns object type.
111  */
112 typedef enum isns_otype {
113 	/*
114 	 * iSNS objects as they are defined in RFC 4171.
115 	 */
116 	OBJ_ENTITY = 0x1,
117 	OBJ_ISCSI,
118 	OBJ_PORTAL,
119 	OBJ_PG,
120 	OBJ_DD,
121 	OBJ_DDS,
122 	MAX_OBJ_TYPE,
123 	/*
124 	 * dummy object types for future extension.
125 	 */
126 	OBJ_DUMMY1,
127 	OBJ_DUMMY2,
128 	OBJ_DUMMY3,
129 	OBJ_DUMMY4,
130 	/*
131 	 * madeup object for internal implementation.
132 	 */
133 	OBJ_ASSOC_ISCSI,
134 	OBJ_ASSOC_DD,
135 	MAX_OBJ_TYPE_FOR_SIZE
136 } isns_type_t;
137 
138 #define	MAX_LOOKUP_CTRL	(3)
139 /*
140  * lookup operation.
141  */
142 typedef enum {
143 	OP_STRING = 1,
144 	OP_INTEGER,
145 	OP_MEMORY_IP6
146 } lookup_method_t;
147 
148 /*
149  * lookup control data.
150  */
151 typedef struct lookup_ctrl {
152 	isns_type_t type;
153 	uint32_t curr_uid;
154 	uint16_t id[MAX_LOOKUP_CTRL];
155 	uint8_t op[MAX_LOOKUP_CTRL];
156 	union {
157 		uchar_t *ptr;
158 		uint32_t ui;
159 		in6_addr_t *ip;
160 	} data[MAX_LOOKUP_CTRL];
161 } lookup_ctrl_t;
162 
163 #define	SET_UID_LCP(LCP, TYPE, UID)	{\
164 	(LCP)->type = TYPE;\
165 	(LCP)->curr_uid = 0;\
166 	(LCP)->id[0] = UID_ATTR_INDEX[TYPE];\
167 	(LCP)->op[0] = OP_INTEGER;\
168 	(LCP)->data[0].ui = UID;\
169 	(LCP)->op[1] = 0;\
170 }
171 
172 #define	UPDATE_LCP_UID(LCP, UID)	{\
173 	(LCP)->curr_uid = 0;\
174 	(LCP)->id[0] = UID_ATTR_INDEX[(LCP)->type];\
175 	(LCP)->op[0] = OP_INTEGER;\
176 	(LCP)->data[0].ui = UID;\
177 	(LCP)->op[1] = 0;\
178 }
179 
180 /*
181  * isns object attribute
182  */
183 typedef struct isns_attr {
184 	uint32_t tag;
185 	uint32_t len;
186 	union {
187 		int32_t i;
188 		uint32_t ui;
189 		in6_addr_t *ip;
190 		uchar_t *ptr;
191 		time_t timestamp;
192 	} value;
193 } isns_attr_t;
194 
195 #define	MAX_KEY_ATTRS	(3)
196 
197 /*
198  * isns generic object.
199  */
200 typedef struct isns_obj {
201 	isns_type_t type;
202 	isns_attr_t attrs[1];
203 } isns_obj_t;
204 
205 #define	ISCSI_PARENT_TYPE	(OBJ_ENTITY)
206 #define	PORTAL_PARENT_TYPE	(OBJ_ENTITY)
207 #define	PG_PARENT_TYPE		(OBJ_ENTITY)
208 #define	ASSOC_ISCSI_PARENT_TYPE	(OBJ_DD)
209 #define	ASSOC_DD_PARENT_TYPE	(OBJ_DDS)
210 
211 /*
212  * iSNS objects.
213  */
214 typedef struct isns_dds {
215 	isns_type_t type;
216 	isns_attr_t attrs[NUM_OF_DDS_ATTRS];
217 } isns_dds_t;
218 
219 typedef struct isns_assoc_dd {
220 	isns_type_t type;
221 	isns_attr_t attrs[NUM_OF_ASSOC_DD_ATTRS];
222 
223 	/* parent object uid */
224 #ifdef ASSOC_DD_PARENT_TYPE
225 	uint32_t puid;
226 #endif
227 } isns_assoc_dd_t;
228 
229 #define	DDS_ENABLED(UI) ((UI) & (ISNS_DDS_STATUS))
230 #define	ENABLE_DDS(DDS)  (((DDS)->status) |= (ISNS_DDS_STATUS))
231 #define	DISABLE_DDS(DDS) (((DDS)->status) &= ~(ISNS_DDS_STATUS))
232 
233 #define	DD_BOOTLIST_ENABLED(UI) ((UI) & (ISNS_DD_BOOTLIST))
234 
235 typedef struct isns_dd {
236 	isns_type_t type;
237 	isns_attr_t attrs[NUM_OF_DD_ATTRS];
238 } isns_dd_t;
239 
240 typedef struct isns_assoc_iscsi {
241 	isns_type_t type;
242 	isns_attr_t attrs[NUM_OF_ASSOC_ISCSI_ATTRS];
243 
244 	/* parent object uid */
245 #ifdef ASSOC_ISCSI_PARENT_TYPE
246 	uint32_t puid;
247 #endif
248 } isns_assoc_iscsi_t;
249 
250 #define	MAX_ISCSI_CHILD		(0)
251 #define	MAX_PORTAL_CHILD	(0)
252 #define	MAX_PG_CHILD		(0)
253 #define	MAX_ENTITY_CHILD	(2)
254 #define	MAX_CHILD_TYPE		(2)
255 
256 #define	PG_REF_COUNT		(2)
257 
258 #define	MAX_REF_COUNT		(2)
259 
260 typedef struct isns_iscsi {
261 	isns_type_t type;
262 	isns_attr_t attrs[NUM_OF_ISCSI_ATTRS];
263 
264 	/* parent object uid */
265 #ifdef ISCSI_PARENT_TYPE
266 	uint32_t puid;
267 #endif
268 	/* subordinate object uid(s) */
269 #if defined(MAX_ISCSI_CHILD) && (MAX_ISCSI_CHILD > 0)
270 	uint32_t *cuid[MAX_ISCSI_CHILD];
271 #endif
272 } isns_iscsi_t;
273 
274 #define	IS_ISCSI_TARGET(NODE)    (((NODE)->type) & ISNS_TARGET_NODE_TYPE)
275 #define	IS_ISCSI_INITIATOR(NODE) (((NODE)->type) & ISNS_INITIATOR_NODE_TYPE)
276 #define	IS_ISCSI_CONTROL(NODE)   (((NODE)->type) & ISNS_CONTROL_NODE_TYPE)
277 
278 #define	IS_TYPE_TARGET(TYPE)	((TYPE) & ISNS_TARGET_NODE_TYPE)
279 #define	IS_TYPE_INITIATOR(TYPE)	((TYPE) & ISNS_INITIATOR_NODE_TYPE)
280 #define	IS_TYPE_CONTROL(TYPE)	((TYPE) & ISNS_CONTROL_NODE_TYPE)
281 #define	IS_TYPE_UNKNOWN(TYPE)	(!IS_TYPE_TARGET(TYPE) && \
282 				!IS_TYPE_INITIATOR(TYPE) && \
283 				!IS_TYPE_CONTROL(TYPE))
284 
285 #define	IS_SCN_INIT_SELF_INFO_ONLY(UI) ((UI) & ISNS_INIT_SELF_INFO_ONLY)
286 #define	IS_SCN_TARGET_SELF_INFO_ONLY(UI) ((UI) & ISNS_TARGET_SELF_INFO_ONLY)
287 #define	IS_SCN_MGMT_REG(UI)		((UI) & ISNS_MGMT_REG)
288 #define	IS_SCN_OBJ_REMOVED(UI)	((UI) & ISNS_OBJECT_REMOVED)
289 #define	IS_SCN_OBJ_ADDED(UI)	((UI) & ISNS_OBJECT_ADDED)
290 #define	IS_SCN_OBJ_UPDATED(UI)	((UI) & ISNS_OBJECT_UPDATED)
291 #define	IS_SCN_MEMBER_REMOVED(UI)   ((UI) & ISNS_MEMBER_REMOVED)
292 #define	IS_SCN_MEMBER_ADDED(UI)	((UI) & ISNS_MEMBER_ADDED)
293 
294 typedef struct isns_portal {
295 	isns_type_t type;
296 	isns_attr_t attrs[NUM_OF_PORTAL_ATTRS];
297 
298 	/* parent object uid */
299 #ifdef PORTAL_PARENT_TYPE
300 	uint32_t puid;
301 #endif
302 	/* subordinate object uid(s) */
303 #if defined(MAX_PORTAL_CHILD) && (MAX_PORTAL_CHILD > 0)
304 	uint32_t *cuid[MAX_PORTAL_CHILD];
305 #endif
306 } isns_portal_t;
307 
308 #define	PORTAL_PORT(UI) ((UI) & ISNS_PORT_BITS)
309 #define	ESI_PORT(UI)    ((UI) & ISNS_PORT_BITS)
310 #define	IS_ESI_UDP(UI)  ((UI) & ISNS_PORT_TYPE)
311 #define	SCN_PORT(UI)    ((UI) & ISNS_PORT_BITS)
312 #define	IS_SCN_UDP(UI)  ((UI) & ISNS_PORT_TYPE)
313 
314 #define	PORT_NUMBER(UI)	((UI) & ISNS_PORT_BITS)
315 #define	IS_PORT_UDP(UI)	((UI) & ISNS_PORT_TYPE)
316 
317 typedef struct isns_pg {
318 	isns_type_t type;
319 	isns_attr_t attrs[NUM_OF_PG_ATTRS];
320 
321 	/* parent object uid */
322 #ifdef PG_PARENT_TYPE
323 	uint32_t puid;
324 #endif
325 	/* subordinate object uid(s) */
326 #if defined(MAX_PG_CHILD) && (MAX_PG_CHILD > 0)
327 	uint32_t *cuid[MAX_PG_CHILD];
328 #endif
329 	/* ref count */
330 #if defined(PG_REF_COUNT) && (PG_REF_COUNT > 0)
331 	uint32_t ref[PG_REF_COUNT];
332 #endif
333 } isns_pg_t;
334 
335 #define	PG_TAG(PGT)	(((PGT)->tag) & ISNS_PG_TAG)
336 
337 typedef struct isns_entity {
338 	isns_type_t type;
339 	isns_attr_t attrs[NUM_OF_ENTITY_ATTRS];
340 
341 	/* parent object uid */
342 #ifdef ENTITY_PARENT_TYPE
343 	uint32_t puid;
344 #endif
345 	/* subordinate object uid(s) */
346 #if defined(MAX_ENTITY_CHILD) && (MAX_ENTITY_CHILD > 0)
347 	uint32_t *cuid[MAX_ENTITY_CHILD];
348 #endif
349 } isns_entity_t;
350 
351 #define	PROTOCOL_MAX_VER(ENTITY)	((((ENTITY)->versions) >> \
352 							ISNS_VER_SHIFT) && \
353 						ISNS_VERSION)
354 #define	PROTOCOL_MIN_VER(ENTITY)	(((ENTITY)->versions) & ISNS_VERSION)
355 
356 #define	DEFAULT_EID_LEN	20
357 #define	DEFAULT_EID_PATTERN	"isns: %.6d"
358 
359 #define	DEFAULT_DD_NAME		"Default"
360 #define	DEFAULT_DD_SET_NAME	"Default"
361 
362 #define	DEFAULT_DD_FEATURES	0
363 #define	DEFAULT_DD_SET_STATUS	0
364 
365 #define	MIN_ESI_INTVAL		(20)		/* 20 seconds */
366 #define	DEFAULT_ESI_INTVAL	(3 * 60)	/* 3 mintues */
367 
368 #define	ONE_DAY		(86400)
369 #define	INFINITY	(4294967295UL)	/* >136 years, max # of uint32_t */
370 
371 /*
372  * function prototype.
373  */
374 void *
375 isns_port_watcher(
376 	void *
377 );
378 
379 uint16_t get_server_xid(void);
380 
381 void inc_thr_count(void);
382 void dec_thr_count(void);
383 void shutdown_server(void);
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 
389 #endif /* _ISNS_SERVER_H */
390