1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte * CDDL HEADER START
3fcf3ce44SJohn Forte *
4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte *
8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing.
10fcf3ce44SJohn Forte * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte * and limitations under the License.
12fcf3ce44SJohn Forte *
13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte *
19fcf3ce44SJohn Forte * CDDL HEADER END
20fcf3ce44SJohn Forte */
21fcf3ce44SJohn Forte
22fcf3ce44SJohn Forte /*
23*530e2b59Swl202157@icefox * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24fcf3ce44SJohn Forte * Use is subject to license terms.
25fcf3ce44SJohn Forte */
26fcf3ce44SJohn Forte
27fcf3ce44SJohn Forte #include <stdio.h>
28fcf3ce44SJohn Forte #include <stdlib.h>
29fcf3ce44SJohn Forte #include <string.h>
30fcf3ce44SJohn Forte #include <pthread.h>
31fcf3ce44SJohn Forte #include <sys/types.h>
32fcf3ce44SJohn Forte #include <sys/socket.h>
33fcf3ce44SJohn Forte #include <netinet/in.h>
34fcf3ce44SJohn Forte #include <arpa/inet.h>
35fcf3ce44SJohn Forte
36fcf3ce44SJohn Forte #include "isns_server.h"
37fcf3ce44SJohn Forte #include "isns_msgq.h"
38fcf3ce44SJohn Forte #include "isns_htab.h"
39fcf3ce44SJohn Forte #include "isns_cache.h"
40fcf3ce44SJohn Forte #include "isns_pdu.h"
41fcf3ce44SJohn Forte #include "isns_obj.h"
42fcf3ce44SJohn Forte #include "isns_dd.h"
43fcf3ce44SJohn Forte #include "isns_func.h"
44fcf3ce44SJohn Forte #include "isns_dseng.h"
45fcf3ce44SJohn Forte #include "isns_log.h"
46fcf3ce44SJohn Forte #include "isns_scn.h"
47fcf3ce44SJohn Forte #include "isns_utils.h"
48fcf3ce44SJohn Forte #include "isns_esi.h"
49fcf3ce44SJohn Forte
50fcf3ce44SJohn Forte /*
51fcf3ce44SJohn Forte * external variables
52fcf3ce44SJohn Forte */
53fcf3ce44SJohn Forte #ifdef DEBUG
54fcf3ce44SJohn Forte extern int verbose_mc;
55fcf3ce44SJohn Forte extern void print_object(char *, isns_obj_t *);
56fcf3ce44SJohn Forte #endif
57fcf3ce44SJohn Forte
58fcf3ce44SJohn Forte extern msg_queue_t *sys_q;
59fcf3ce44SJohn Forte extern msg_queue_t *scn_q;
60fcf3ce44SJohn Forte
61fcf3ce44SJohn Forte extern pthread_mutex_t el_mtx;
62fcf3ce44SJohn Forte
63fcf3ce44SJohn Forte extern int cache_flag;
64fcf3ce44SJohn Forte
65fcf3ce44SJohn Forte /*
66fcf3ce44SJohn Forte * global data
67fcf3ce44SJohn Forte */
68fcf3ce44SJohn Forte
69fcf3ce44SJohn Forte /*
70fcf3ce44SJohn Forte * local variables
71fcf3ce44SJohn Forte */
72fcf3ce44SJohn Forte /* type of parent object */
73fcf3ce44SJohn Forte const int TYPE_OF_PARENT[MAX_OBJ_TYPE_FOR_SIZE] = {
74fcf3ce44SJohn Forte 0,
75fcf3ce44SJohn Forte 0,
76fcf3ce44SJohn Forte ISCSI_PARENT_TYPE,
77fcf3ce44SJohn Forte PORTAL_PARENT_TYPE,
78fcf3ce44SJohn Forte PG_PARENT_TYPE,
79fcf3ce44SJohn Forte 0, /* OBJ_DD */
80fcf3ce44SJohn Forte 0, /* OBJ_DDS */
81fcf3ce44SJohn Forte 0, /* MAX_OBJ_TYPE */
82fcf3ce44SJohn Forte 0, /* OBJ_DUMMY1 */
83fcf3ce44SJohn Forte 0, /* OBJ_DUMMY2 */
84fcf3ce44SJohn Forte 0, /* OBJ_DUMMY3 */
85fcf3ce44SJohn Forte 0, /* OBJ_DUMMY4 */
86fcf3ce44SJohn Forte ASSOC_ISCSI_PARENT_TYPE,
87fcf3ce44SJohn Forte ASSOC_DD_PARENT_TYPE
88fcf3ce44SJohn Forte };
89fcf3ce44SJohn Forte
90fcf3ce44SJohn Forte /* number of children object type */
91fcf3ce44SJohn Forte const int NUM_OF_CHILD[MAX_OBJ_TYPE] = {
92fcf3ce44SJohn Forte 0,
93fcf3ce44SJohn Forte MAX_ENTITY_CHILD,
94fcf3ce44SJohn Forte MAX_ISCSI_CHILD,
95fcf3ce44SJohn Forte MAX_PORTAL_CHILD,
96fcf3ce44SJohn Forte MAX_PG_CHILD,
97fcf3ce44SJohn Forte 0,
98fcf3ce44SJohn Forte 0
99fcf3ce44SJohn Forte };
100fcf3ce44SJohn Forte
101fcf3ce44SJohn Forte /* type of a child object */
102fcf3ce44SJohn Forte const int TYPE_OF_CHILD[MAX_OBJ_TYPE][MAX_CHILD_TYPE] = {
103fcf3ce44SJohn Forte { 0, 0 },
104fcf3ce44SJohn Forte { OBJ_ISCSI, OBJ_PORTAL },
105fcf3ce44SJohn Forte { 0, 0 },
106fcf3ce44SJohn Forte { 0, 0 },
107fcf3ce44SJohn Forte { 0, 0 },
108fcf3ce44SJohn Forte { 0, 0 },
109fcf3ce44SJohn Forte { 0, 0 }
110fcf3ce44SJohn Forte };
111fcf3ce44SJohn Forte
112fcf3ce44SJohn Forte /* number of attributes of certain type of object */
113fcf3ce44SJohn Forte const int NUM_OF_ATTRS[MAX_OBJ_TYPE_FOR_SIZE] = {
114fcf3ce44SJohn Forte 0,
115fcf3ce44SJohn Forte NUM_OF_ENTITY_ATTRS,
116fcf3ce44SJohn Forte NUM_OF_ISCSI_ATTRS,
117fcf3ce44SJohn Forte NUM_OF_PORTAL_ATTRS,
118fcf3ce44SJohn Forte NUM_OF_PG_ATTRS,
119fcf3ce44SJohn Forte NUM_OF_DD_ATTRS,
120fcf3ce44SJohn Forte NUM_OF_DDS_ATTRS,
121fcf3ce44SJohn Forte 0, /* MAX_OBJ_TYPE */
122fcf3ce44SJohn Forte 0, /* OBJ_DUMMY1 */
123fcf3ce44SJohn Forte 0, /* OBJ_DUMMY2 */
124fcf3ce44SJohn Forte 0, /* OBJ_DUMMY3 */
125fcf3ce44SJohn Forte 0, /* OBJ_DUMMY4 */
126fcf3ce44SJohn Forte NUM_OF_ASSOC_ISCSI_ATTRS,
127fcf3ce44SJohn Forte NUM_OF_ASSOC_DD_ATTRS
128fcf3ce44SJohn Forte };
129fcf3ce44SJohn Forte
130fcf3ce44SJohn Forte /* the tag of UID of each type of object */
131fcf3ce44SJohn Forte static const int UID_TAG[MAX_OBJ_TYPE_FOR_SIZE] = {
132fcf3ce44SJohn Forte 0,
133fcf3ce44SJohn Forte ISNS_ENTITY_INDEX_ATTR_ID,
134fcf3ce44SJohn Forte ISNS_ISCSI_NODE_INDEX_ATTR_ID,
135fcf3ce44SJohn Forte ISNS_PORTAL_INDEX_ATTR_ID,
136fcf3ce44SJohn Forte ISNS_PG_INDEX_ATTR_ID,
137fcf3ce44SJohn Forte ISNS_DD_ID_ATTR_ID,
138fcf3ce44SJohn Forte ISNS_DD_SET_ID_ATTR_ID,
139fcf3ce44SJohn Forte 0, /* MAX_OBJ_TYPE */
140fcf3ce44SJohn Forte 0, /* OBJ_DUMMY1 */
141fcf3ce44SJohn Forte 0, /* OBJ_DUMMY2 */
142fcf3ce44SJohn Forte 0, /* OBJ_DUMMY3 */
143fcf3ce44SJohn Forte 0, /* OBJ_DUMMY4 */
144fcf3ce44SJohn Forte ISNS_DD_ISCSI_INDEX_ATTR_ID,
145fcf3ce44SJohn Forte ISNS_DD_ID_ATTR_ID
146fcf3ce44SJohn Forte };
147fcf3ce44SJohn Forte
148fcf3ce44SJohn Forte /* the index of UID of each type of object */
149fcf3ce44SJohn Forte const int UID_ATTR_INDEX[MAX_OBJ_TYPE_FOR_SIZE] = {
150fcf3ce44SJohn Forte 0,
151fcf3ce44SJohn Forte ATTR_INDEX_ENTITY(ISNS_ENTITY_INDEX_ATTR_ID),
152fcf3ce44SJohn Forte ATTR_INDEX_ISCSI(ISNS_ISCSI_NODE_INDEX_ATTR_ID),
153fcf3ce44SJohn Forte ATTR_INDEX_PORTAL(ISNS_PORTAL_INDEX_ATTR_ID),
154fcf3ce44SJohn Forte ATTR_INDEX_PG(ISNS_PG_INDEX_ATTR_ID),
155fcf3ce44SJohn Forte ATTR_INDEX_DD(ISNS_DD_ID_ATTR_ID),
156fcf3ce44SJohn Forte ATTR_INDEX_DDS(ISNS_DD_SET_ID_ATTR_ID),
157fcf3ce44SJohn Forte 0, /* MAX_OBJ_TYPE */
158fcf3ce44SJohn Forte 0, /* OBJ_DUMMY1 */
159fcf3ce44SJohn Forte 0, /* OBJ_DUMMY2 */
160fcf3ce44SJohn Forte 0, /* OBJ_DUMMY3 */
161fcf3ce44SJohn Forte 0, /* OBJ_DUMMY4 */
162fcf3ce44SJohn Forte ATTR_INDEX_ASSOC_ISCSI(ISNS_DD_ISCSI_INDEX_ATTR_ID),
163fcf3ce44SJohn Forte ATTR_INDEX_ASSOC_DD(ISNS_DD_ID_ATTR_ID)
164fcf3ce44SJohn Forte };
165fcf3ce44SJohn Forte
166fcf3ce44SJohn Forte /* the index of the key attributes of each type of object */
167fcf3ce44SJohn Forte static const int KEY_ATTR_INDEX[MAX_OBJ_TYPE][MAX_KEY_ATTRS] = {
168fcf3ce44SJohn Forte { 0 },
169fcf3ce44SJohn Forte { ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID), 0 },
170fcf3ce44SJohn Forte { ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID),
171fcf3ce44SJohn Forte 0 },
172fcf3ce44SJohn Forte { ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID),
173fcf3ce44SJohn Forte ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID),
174fcf3ce44SJohn Forte 0 },
175fcf3ce44SJohn Forte { ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID),
176fcf3ce44SJohn Forte ATTR_INDEX_PG(ISNS_PG_PORTAL_IP_ADDR_ATTR_ID),
177fcf3ce44SJohn Forte ATTR_INDEX_PG(ISNS_PG_PORTAL_PORT_ATTR_ID) },
178fcf3ce44SJohn Forte { ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID), 0 },
179fcf3ce44SJohn Forte { ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID), 0 }
180fcf3ce44SJohn Forte };
181fcf3ce44SJohn Forte
182fcf3ce44SJohn Forte /* the operating methods for key attributes of each type of object */
183fcf3ce44SJohn Forte static const int KEY_ATTR_OP[MAX_OBJ_TYPE][MAX_KEY_ATTRS] = {
184fcf3ce44SJohn Forte { 0 },
185fcf3ce44SJohn Forte { OP_STRING, 0 },
186fcf3ce44SJohn Forte { OP_STRING, 0 },
187fcf3ce44SJohn Forte { OP_MEMORY_IP6, OP_INTEGER, 0 },
188fcf3ce44SJohn Forte { OP_STRING, OP_MEMORY_IP6, OP_INTEGER },
189fcf3ce44SJohn Forte { OP_STRING, 0 },
190fcf3ce44SJohn Forte { OP_STRING, 0 }
191fcf3ce44SJohn Forte };
192fcf3ce44SJohn Forte
193fcf3ce44SJohn Forte /* the size of each type of object */
194fcf3ce44SJohn Forte static const int SIZEOF_OBJ[MAX_OBJ_TYPE_FOR_SIZE] = {
195fcf3ce44SJohn Forte 0,
196fcf3ce44SJohn Forte sizeof (isns_entity_t),
197fcf3ce44SJohn Forte sizeof (isns_iscsi_t),
198fcf3ce44SJohn Forte sizeof (isns_portal_t),
199fcf3ce44SJohn Forte sizeof (isns_pg_t),
200fcf3ce44SJohn Forte sizeof (isns_dd_t),
201fcf3ce44SJohn Forte sizeof (isns_dds_t),
202fcf3ce44SJohn Forte 0,
203fcf3ce44SJohn Forte 0,
204fcf3ce44SJohn Forte 0,
205fcf3ce44SJohn Forte 0,
206fcf3ce44SJohn Forte 0,
207fcf3ce44SJohn Forte sizeof (isns_assoc_iscsi_t),
208fcf3ce44SJohn Forte sizeof (isns_assoc_dd_t)
209fcf3ce44SJohn Forte };
210fcf3ce44SJohn Forte
211fcf3ce44SJohn Forte #ifdef DEBUG
212fcf3ce44SJohn Forte const int NUM_OF_REF[MAX_OBJ_TYPE_FOR_SIZE] = {
213fcf3ce44SJohn Forte #else
214fcf3ce44SJohn Forte static const int NUM_OF_REF[MAX_OBJ_TYPE_FOR_SIZE] = {
215fcf3ce44SJohn Forte #endif
216fcf3ce44SJohn Forte 0,
217fcf3ce44SJohn Forte 0,
218fcf3ce44SJohn Forte 0,
219fcf3ce44SJohn Forte 0,
220fcf3ce44SJohn Forte PG_REF_COUNT,
221fcf3ce44SJohn Forte 0,
222fcf3ce44SJohn Forte 0,
223fcf3ce44SJohn Forte 0,
224fcf3ce44SJohn Forte 0,
225fcf3ce44SJohn Forte 0,
226fcf3ce44SJohn Forte 0,
227fcf3ce44SJohn Forte 0,
228fcf3ce44SJohn Forte 0,
229fcf3ce44SJohn Forte 0
230fcf3ce44SJohn Forte };
231fcf3ce44SJohn Forte
232fcf3ce44SJohn Forte /* the type of the reference object */
233fcf3ce44SJohn Forte static const int TYPE_OF_REF[MAX_OBJ_TYPE][MAX_REF_COUNT + 1] = {
234fcf3ce44SJohn Forte { 0 },
235fcf3ce44SJohn Forte { 0 },
236fcf3ce44SJohn Forte { OBJ_PG, OBJ_PORTAL, 0 },
237fcf3ce44SJohn Forte { OBJ_PG, OBJ_ISCSI, 0 },
238fcf3ce44SJohn Forte { 0, OBJ_ISCSI, OBJ_PORTAL },
239fcf3ce44SJohn Forte { 0 },
240fcf3ce44SJohn Forte { 0 }
241fcf3ce44SJohn Forte };
242fcf3ce44SJohn Forte
243fcf3ce44SJohn Forte /* the operating method for match operation of the reference object */
244fcf3ce44SJohn Forte #define MAX_REF_MATCH (2)
245fcf3ce44SJohn Forte static const int REF_MATCH_OPS[MAX_OBJ_TYPE][MAX_REF_MATCH] = {
246fcf3ce44SJohn Forte { 0, 0 },
247fcf3ce44SJohn Forte { 0, 0 },
248fcf3ce44SJohn Forte { OP_STRING, 0 },
249fcf3ce44SJohn Forte { OP_MEMORY_IP6, OP_INTEGER },
250fcf3ce44SJohn Forte { 0, 0 },
251fcf3ce44SJohn Forte { 0, 0 },
252fcf3ce44SJohn Forte { 0, 0 }
253fcf3ce44SJohn Forte };
254fcf3ce44SJohn Forte
255fcf3ce44SJohn Forte /* the index of the attribute of being matched object */
256fcf3ce44SJohn Forte static const int REF_MATCH_ID1[MAX_OBJ_TYPE][MAX_REF_MATCH] = {
257fcf3ce44SJohn Forte { 0, 0 },
258fcf3ce44SJohn Forte { 0, 0 },
259fcf3ce44SJohn Forte { ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID), 0 },
260fcf3ce44SJohn Forte { ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID),
261fcf3ce44SJohn Forte ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID) },
262fcf3ce44SJohn Forte { 0, 0 },
263fcf3ce44SJohn Forte { 0, 0 },
264fcf3ce44SJohn Forte { 0, 0 }
265fcf3ce44SJohn Forte };
266fcf3ce44SJohn Forte
267fcf3ce44SJohn Forte /* the index of the attribute of matching object */
268fcf3ce44SJohn Forte static const int REF_MATCH_ID2[MAX_OBJ_TYPE][MAX_REF_MATCH] = {
269fcf3ce44SJohn Forte { 0, 0 },
270fcf3ce44SJohn Forte { 0, 0 },
271fcf3ce44SJohn Forte { ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID), 0 },
272fcf3ce44SJohn Forte { ATTR_INDEX_PG(ISNS_PG_PORTAL_IP_ADDR_ATTR_ID),
273fcf3ce44SJohn Forte ATTR_INDEX_PG(ISNS_PG_PORTAL_PORT_ATTR_ID) },
274fcf3ce44SJohn Forte { 0, 0 },
275fcf3ce44SJohn Forte { 0, 0 },
276fcf3ce44SJohn Forte { 0, 0 }
277fcf3ce44SJohn Forte };
278fcf3ce44SJohn Forte
279fcf3ce44SJohn Forte /*
280fcf3ce44SJohn Forte * local functions.
281fcf3ce44SJohn Forte */
282fcf3ce44SJohn Forte static uint32_t get_reg_period();
283fcf3ce44SJohn Forte static char *make_unique_name(int *, uint32_t);
284fcf3ce44SJohn Forte static lookup_ctrl_t *set_lookup_ctrl(lookup_ctrl_t *, isns_obj_t *);
285fcf3ce44SJohn Forte static int setup_ref_lcp(lookup_ctrl_t *,
286fcf3ce44SJohn Forte const isns_obj_t *, const isns_obj_t *);
287fcf3ce44SJohn Forte static int setup_deref_lcp(lookup_ctrl_t *,
288fcf3ce44SJohn Forte const isns_obj_t *, isns_type_t);
289fcf3ce44SJohn Forte static int cb_get_parent(void *, void *);
290fcf3ce44SJohn Forte static int cb_node_child(void *, void *);
291fcf3ce44SJohn Forte static int cb_set_ref(void *, void *);
292fcf3ce44SJohn Forte static int cb_clear_ref(void *, void *);
293fcf3ce44SJohn Forte static int cb_add_child(void *, void *);
294fcf3ce44SJohn Forte static int cb_remove_child(void *, void *);
295fcf3ce44SJohn Forte static int cb_verify_ref(void *, void *);
296fcf3ce44SJohn Forte static int cb_ref_new2old(void *, void *);
297fcf3ce44SJohn Forte static int cb_new_ref(void *, void *);
298fcf3ce44SJohn Forte static int ref_new2old(
299fcf3ce44SJohn Forte lookup_ctrl_t *, isns_type_t, uint32_t, const isns_obj_t *);
300fcf3ce44SJohn Forte static int ref_new2new(
301fcf3ce44SJohn Forte lookup_ctrl_t *, const isns_obj_t *, const isns_obj_t *);
302fcf3ce44SJohn Forte static int new_ref(const isns_obj_t *, const isns_obj_t *);
303fcf3ce44SJohn Forte static uint32_t setup_parent_lcp(lookup_ctrl_t *, isns_obj_t *);
304fcf3ce44SJohn Forte static int set_obj_offline(isns_obj_t *);
305fcf3ce44SJohn Forte static int copy_attrs(isns_obj_t *, const isns_obj_t *);
306fcf3ce44SJohn Forte
307fcf3ce44SJohn Forte static isns_obj_t *make_default_pg(const isns_obj_t *, const isns_obj_t *);
308fcf3ce44SJohn Forte static isns_obj_t *(*const make_ref[MAX_OBJ_TYPE])
309fcf3ce44SJohn Forte (const isns_obj_t *, const isns_obj_t *) = {
310fcf3ce44SJohn Forte NULL,
311fcf3ce44SJohn Forte NULL,
312fcf3ce44SJohn Forte &make_default_pg,
313fcf3ce44SJohn Forte &make_default_pg,
314fcf3ce44SJohn Forte NULL,
315fcf3ce44SJohn Forte NULL,
316fcf3ce44SJohn Forte NULL
317fcf3ce44SJohn Forte };
318fcf3ce44SJohn Forte
319fcf3ce44SJohn Forte static uint32_t entity_hval(void *, uint16_t, uint32_t *);
320fcf3ce44SJohn Forte static uint32_t iscsi_hval(void *, uint16_t, uint32_t *);
321fcf3ce44SJohn Forte static uint32_t portal_hval(void *, uint16_t, uint32_t *);
322fcf3ce44SJohn Forte static uint32_t pg_hval(void *, uint16_t, uint32_t *);
323fcf3ce44SJohn Forte static uint32_t dd_hval(void *, uint16_t, uint32_t *);
324fcf3ce44SJohn Forte static uint32_t dds_hval(void *, uint16_t, uint32_t *);
325fcf3ce44SJohn Forte static uint32_t (*const hval_func[MAX_OBJ_TYPE])
326fcf3ce44SJohn Forte (void *, uint16_t, uint32_t *) = {
327fcf3ce44SJohn Forte NULL,
328fcf3ce44SJohn Forte &entity_hval,
329fcf3ce44SJohn Forte &iscsi_hval,
330fcf3ce44SJohn Forte &portal_hval,
331fcf3ce44SJohn Forte &pg_hval,
332fcf3ce44SJohn Forte &dd_hval,
333fcf3ce44SJohn Forte &dds_hval
334fcf3ce44SJohn Forte };
335fcf3ce44SJohn Forte
336fcf3ce44SJohn Forte /*
337fcf3ce44SJohn Forte * ****************************************************************************
338fcf3ce44SJohn Forte *
339fcf3ce44SJohn Forte * entity_hval:
340fcf3ce44SJohn Forte * caculate the hash value of a network entity object.
341fcf3ce44SJohn Forte *
342fcf3ce44SJohn Forte * p - the pointer pointers to network entity object or
343fcf3ce44SJohn Forte * the lookup control data, both have the key attribute
344fcf3ce44SJohn Forte * of a network entity object.
345fcf3ce44SJohn Forte * chunk- which chunk of the hash table.
346fcf3ce44SJohn Forte * flags- pointer to flags.
347fcf3ce44SJohn Forte * return - the hash value.
348fcf3ce44SJohn Forte *
349fcf3ce44SJohn Forte * ****************************************************************************
350fcf3ce44SJohn Forte */
351fcf3ce44SJohn Forte static uint32_t
entity_hval(void * p,uint16_t chunk,uint32_t * flags)352fcf3ce44SJohn Forte entity_hval(
353fcf3ce44SJohn Forte void *p,
354fcf3ce44SJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
355fcf3ce44SJohn Forte uint16_t chunk,
356fcf3ce44SJohn Forte uint32_t *flags
357fcf3ce44SJohn Forte )
358fcf3ce44SJohn Forte {
359fcf3ce44SJohn Forte uchar_t *key;
360fcf3ce44SJohn Forte isns_obj_t *obj;
361fcf3ce44SJohn Forte lookup_ctrl_t *lcp;
362fcf3ce44SJohn Forte
363fcf3ce44SJohn Forte if ((*flags & FLAGS_CTRL_MASK) == 0) {
364fcf3ce44SJohn Forte /* p pointers to a network entity object */
365fcf3ce44SJohn Forte obj = (isns_obj_t *)p;
366fcf3ce44SJohn Forte key = obj->attrs[ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID)].
367fcf3ce44SJohn Forte value.ptr;
368fcf3ce44SJohn Forte } else {
369fcf3ce44SJohn Forte /* p is lookup control data */
370fcf3ce44SJohn Forte lcp = (lookup_ctrl_t *)p;
371fcf3ce44SJohn Forte key = lcp->data[0].ptr;
372fcf3ce44SJohn Forte }
373fcf3ce44SJohn Forte
374fcf3ce44SJohn Forte return (htab_compute_hval(key));
375fcf3ce44SJohn Forte }
376fcf3ce44SJohn Forte
377fcf3ce44SJohn Forte /*
378fcf3ce44SJohn Forte * ****************************************************************************
379fcf3ce44SJohn Forte *
380fcf3ce44SJohn Forte * iscsi_hval:
381fcf3ce44SJohn Forte * caculate the hash value of an iscsi storage node object.
382fcf3ce44SJohn Forte *
383fcf3ce44SJohn Forte * p - the pointer pointers to iscsi storage node object or
384fcf3ce44SJohn Forte * the lookup control data, both have the key attribute
385fcf3ce44SJohn Forte * of an iscsi storage node object.
386fcf3ce44SJohn Forte * chunk- which chunk of the hash table.
387fcf3ce44SJohn Forte * flags- pointer to flags.
388fcf3ce44SJohn Forte * return - the hash value.
389fcf3ce44SJohn Forte *
390fcf3ce44SJohn Forte * ****************************************************************************
391fcf3ce44SJohn Forte */
392fcf3ce44SJohn Forte static uint32_t
iscsi_hval(void * p,uint16_t chunk,uint32_t * flags)393fcf3ce44SJohn Forte iscsi_hval(
394fcf3ce44SJohn Forte void *p,
395fcf3ce44SJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
396fcf3ce44SJohn Forte uint16_t chunk,
397fcf3ce44SJohn Forte uint32_t *flags
398fcf3ce44SJohn Forte )
399fcf3ce44SJohn Forte {
400fcf3ce44SJohn Forte uchar_t *key;
401fcf3ce44SJohn Forte isns_obj_t *obj;
402fcf3ce44SJohn Forte lookup_ctrl_t *lcp;
403fcf3ce44SJohn Forte
404fcf3ce44SJohn Forte if ((*flags & FLAGS_CTRL_MASK) == 0) {
405fcf3ce44SJohn Forte /* p pointers to an iscsi storage node object */
406fcf3ce44SJohn Forte obj = (isns_obj_t *)p;
407fcf3ce44SJohn Forte key = obj->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID)].
408fcf3ce44SJohn Forte value.ptr;
409fcf3ce44SJohn Forte } else {
410fcf3ce44SJohn Forte /* p is lookup control data */
411fcf3ce44SJohn Forte lcp = (lookup_ctrl_t *)p;
412fcf3ce44SJohn Forte key = lcp->data[0].ptr;
413fcf3ce44SJohn Forte }
414fcf3ce44SJohn Forte
415fcf3ce44SJohn Forte return (htab_compute_hval(key));
416fcf3ce44SJohn Forte }
417fcf3ce44SJohn Forte
418fcf3ce44SJohn Forte /*
419fcf3ce44SJohn Forte * ****************************************************************************
420fcf3ce44SJohn Forte *
421fcf3ce44SJohn Forte * portal_hval:
422fcf3ce44SJohn Forte * caculate the hash value of a portal object.
423fcf3ce44SJohn Forte *
424fcf3ce44SJohn Forte * p - the pointer pointers to a portal object or the lookup control
425fcf3ce44SJohn Forte * data, both have the key attributes of a portal object.
426fcf3ce44SJohn Forte * chunk- which chunk of the hash table.
427fcf3ce44SJohn Forte * flags- pointer to flags.
428fcf3ce44SJohn Forte * return - the hash value.
429fcf3ce44SJohn Forte *
430fcf3ce44SJohn Forte * ****************************************************************************
431fcf3ce44SJohn Forte */
432fcf3ce44SJohn Forte static uint32_t
portal_hval(void * p,uint16_t chunk,uint32_t * flags)433fcf3ce44SJohn Forte portal_hval(
434fcf3ce44SJohn Forte void *p,
435fcf3ce44SJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
436fcf3ce44SJohn Forte uint16_t chunk,
437fcf3ce44SJohn Forte uint32_t *flags
438fcf3ce44SJohn Forte )
439fcf3ce44SJohn Forte {
440fcf3ce44SJohn Forte char buff[INET6_ADDRSTRLEN + 8] = { 0 };
441fcf3ce44SJohn Forte char buff2[8] = { 0 };
442fcf3ce44SJohn Forte uchar_t *key;
443fcf3ce44SJohn Forte isns_obj_t *obj;
444fcf3ce44SJohn Forte lookup_ctrl_t *lcp;
445fcf3ce44SJohn Forte
446fcf3ce44SJohn Forte in6_addr_t *ip;
447fcf3ce44SJohn Forte uint32_t port;
448fcf3ce44SJohn Forte
449fcf3ce44SJohn Forte if ((*flags & FLAGS_CTRL_MASK) == 0) {
450fcf3ce44SJohn Forte /* p pointers to a portal object */
451fcf3ce44SJohn Forte obj = (isns_obj_t *)p;
452fcf3ce44SJohn Forte ip = obj->attrs[ATTR_INDEX_PORTAL
453fcf3ce44SJohn Forte (ISNS_PORTAL_IP_ADDR_ATTR_ID)].value.ip;
454fcf3ce44SJohn Forte port = obj->attrs[ATTR_INDEX_PORTAL
455fcf3ce44SJohn Forte (ISNS_PORTAL_PORT_ATTR_ID)].value.ui;
456fcf3ce44SJohn Forte } else {
457fcf3ce44SJohn Forte /* p is lookup control data */
458fcf3ce44SJohn Forte lcp = (lookup_ctrl_t *)p;
459fcf3ce44SJohn Forte ip = lcp->data[0].ip;
460fcf3ce44SJohn Forte port = lcp->data[1].ui;
461fcf3ce44SJohn Forte }
462fcf3ce44SJohn Forte
463fcf3ce44SJohn Forte key = (uchar_t *)inet_ntop(AF_INET6, (void *)ip,
464fcf3ce44SJohn Forte buff, sizeof (buff));
465fcf3ce44SJohn Forte (void) snprintf(buff2, sizeof (buff2), "%d", port);
466fcf3ce44SJohn Forte (void) strcat((char *)key, buff2);
467fcf3ce44SJohn Forte
468fcf3ce44SJohn Forte return (htab_compute_hval(key));
469fcf3ce44SJohn Forte }
470fcf3ce44SJohn Forte
471fcf3ce44SJohn Forte /*
472fcf3ce44SJohn Forte * ****************************************************************************
473fcf3ce44SJohn Forte *
474fcf3ce44SJohn Forte * pg_hval:
475fcf3ce44SJohn Forte * caculate the hash value of a portal group object.
476fcf3ce44SJohn Forte *
477fcf3ce44SJohn Forte * p - the pointer pointers to a portal group object or the lookup
478fcf3ce44SJohn Forte * control data, both have the key attributes of a portal object.
479fcf3ce44SJohn Forte * chunk- which chunk of the hash table.
480fcf3ce44SJohn Forte * flags- pointer to flags.
481fcf3ce44SJohn Forte * return - the hash value.
482fcf3ce44SJohn Forte *
483fcf3ce44SJohn Forte * ****************************************************************************
484fcf3ce44SJohn Forte */
485fcf3ce44SJohn Forte static uint32_t
pg_hval(void * p,uint16_t chunk,uint32_t * flags)486fcf3ce44SJohn Forte pg_hval(
487fcf3ce44SJohn Forte void *p,
488fcf3ce44SJohn Forte uint16_t chunk,
489fcf3ce44SJohn Forte uint32_t *flags
490fcf3ce44SJohn Forte )
491fcf3ce44SJohn Forte {
492fcf3ce44SJohn Forte char buff[INET6_ADDRSTRLEN + 8] = { 0 };
493fcf3ce44SJohn Forte char buff2[8] = { 0 };
494fcf3ce44SJohn Forte uchar_t *key = NULL;
495fcf3ce44SJohn Forte isns_obj_t *obj;
496fcf3ce44SJohn Forte lookup_ctrl_t *lcp;
497fcf3ce44SJohn Forte
498fcf3ce44SJohn Forte in6_addr_t *ip = NULL;
499fcf3ce44SJohn Forte uint32_t port;
500fcf3ce44SJohn Forte
501fcf3ce44SJohn Forte if ((*flags & FLAGS_CTRL_MASK) == 0) {
502fcf3ce44SJohn Forte /* p is a portal group object */
503fcf3ce44SJohn Forte obj = (isns_obj_t *)p;
504fcf3ce44SJohn Forte if (chunk == 0) {
505fcf3ce44SJohn Forte /* the first chunk */
506fcf3ce44SJohn Forte key = obj->attrs[ATTR_INDEX_PG
507fcf3ce44SJohn Forte (ISNS_PG_ISCSI_NAME_ATTR_ID)].value.ptr;
508fcf3ce44SJohn Forte } else {
509fcf3ce44SJohn Forte /* another chunk */
510fcf3ce44SJohn Forte ip = obj->attrs[ATTR_INDEX_PG
511fcf3ce44SJohn Forte (ISNS_PG_PORTAL_IP_ADDR_ATTR_ID)].value.ip;
512fcf3ce44SJohn Forte port = obj->attrs[ATTR_INDEX_PG
513fcf3ce44SJohn Forte (ISNS_PG_PORTAL_PORT_ATTR_ID)].value.ui;
514fcf3ce44SJohn Forte }
515fcf3ce44SJohn Forte } else {
516fcf3ce44SJohn Forte /* p is a lookup control data */
517fcf3ce44SJohn Forte lcp = (lookup_ctrl_t *)p;
518fcf3ce44SJohn Forte /* clear the chunk flags */
519fcf3ce44SJohn Forte *flags &= ~FLAGS_CHUNK_MASK;
520fcf3ce44SJohn Forte if (lcp->op[0] == OP_STRING) {
521fcf3ce44SJohn Forte /* the first chunk */
522fcf3ce44SJohn Forte key = lcp->data[0].ptr;
523fcf3ce44SJohn Forte } else {
524fcf3ce44SJohn Forte /* another chunk */
525fcf3ce44SJohn Forte ip = lcp->data[0].ip;
526fcf3ce44SJohn Forte port = lcp->data[1].ui;
527fcf3ce44SJohn Forte *flags |= 1;
528fcf3ce44SJohn Forte }
529fcf3ce44SJohn Forte }
530fcf3ce44SJohn Forte
531fcf3ce44SJohn Forte if (key == NULL) {
532fcf3ce44SJohn Forte key = (uchar_t *)inet_ntop(AF_INET6, (void *)ip,
533fcf3ce44SJohn Forte buff, sizeof (buff));
534fcf3ce44SJohn Forte (void) snprintf(buff2, sizeof (buff2), "%d", port);
535fcf3ce44SJohn Forte (void) strcat((char *)key, buff2);
536fcf3ce44SJohn Forte }
537fcf3ce44SJohn Forte
538fcf3ce44SJohn Forte return (htab_compute_hval(key));
539fcf3ce44SJohn Forte }
540fcf3ce44SJohn Forte
541fcf3ce44SJohn Forte /*
542fcf3ce44SJohn Forte * ****************************************************************************
543fcf3ce44SJohn Forte *
544fcf3ce44SJohn Forte * dd_hval:
545fcf3ce44SJohn Forte * caculate the hash value of a DD object.
546fcf3ce44SJohn Forte *
547fcf3ce44SJohn Forte * p - the pointer pointers to a DD object or the lookup control data,
548fcf3ce44SJohn Forte * both have the key attributes of a DD object.
549fcf3ce44SJohn Forte * chunk- which chunk of the hash table.
550fcf3ce44SJohn Forte * flags- pointer to flags.
551fcf3ce44SJohn Forte * return - the hash value.
552fcf3ce44SJohn Forte *
553fcf3ce44SJohn Forte * ****************************************************************************
554fcf3ce44SJohn Forte */
555fcf3ce44SJohn Forte static uint32_t
dd_hval(void * p,uint16_t chunk,uint32_t * flags)556fcf3ce44SJohn Forte dd_hval(
557fcf3ce44SJohn Forte void *p,
558fcf3ce44SJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
559fcf3ce44SJohn Forte uint16_t chunk,
560fcf3ce44SJohn Forte uint32_t *flags
561fcf3ce44SJohn Forte )
562fcf3ce44SJohn Forte {
563fcf3ce44SJohn Forte uchar_t *key;
564fcf3ce44SJohn Forte isns_obj_t *obj;
565fcf3ce44SJohn Forte lookup_ctrl_t *lcp;
566fcf3ce44SJohn Forte
567fcf3ce44SJohn Forte if ((*flags & FLAGS_CTRL_MASK) == 0) {
568fcf3ce44SJohn Forte /* p is a DD object */
569fcf3ce44SJohn Forte obj = (isns_obj_t *)p;
570fcf3ce44SJohn Forte key = obj->attrs[ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID)].
571fcf3ce44SJohn Forte value.ptr;
572fcf3ce44SJohn Forte } else {
573fcf3ce44SJohn Forte /* p is a lookup control data */
574fcf3ce44SJohn Forte lcp = (lookup_ctrl_t *)p;
575fcf3ce44SJohn Forte key = lcp->data[0].ptr;
576fcf3ce44SJohn Forte }
577fcf3ce44SJohn Forte
578fcf3ce44SJohn Forte return (htab_compute_hval(key));
579fcf3ce44SJohn Forte }
580fcf3ce44SJohn Forte
581fcf3ce44SJohn Forte /*
582fcf3ce44SJohn Forte * ****************************************************************************
583fcf3ce44SJohn Forte *
584fcf3ce44SJohn Forte * dds_hval:
585fcf3ce44SJohn Forte * caculate the hash value of a DD-set object.
586fcf3ce44SJohn Forte *
587fcf3ce44SJohn Forte * p - the pointer pointers to a DD-set object or the lookup control data,
588fcf3ce44SJohn Forte * both have the key attributes of a DD-set object.
589fcf3ce44SJohn Forte * chunk- which chunk of the hash table.
590fcf3ce44SJohn Forte * flags- pointer to flags.
591fcf3ce44SJohn Forte * return - the hash value.
592fcf3ce44SJohn Forte *
593fcf3ce44SJohn Forte * ****************************************************************************
594fcf3ce44SJohn Forte */
595fcf3ce44SJohn Forte static uint32_t
dds_hval(void * p,uint16_t chunk,uint32_t * flags)596fcf3ce44SJohn Forte dds_hval(
597fcf3ce44SJohn Forte void *p,
598fcf3ce44SJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
599fcf3ce44SJohn Forte uint16_t chunk,
600fcf3ce44SJohn Forte uint32_t *flags
601fcf3ce44SJohn Forte )
602fcf3ce44SJohn Forte {
603fcf3ce44SJohn Forte uchar_t *key;
604fcf3ce44SJohn Forte isns_obj_t *obj;
605fcf3ce44SJohn Forte lookup_ctrl_t *lcp;
606fcf3ce44SJohn Forte
607fcf3ce44SJohn Forte if ((*flags & FLAGS_CTRL_MASK) == 0) {
608fcf3ce44SJohn Forte /* p is a DD-set object */
609fcf3ce44SJohn Forte obj = (isns_obj_t *)p;
610fcf3ce44SJohn Forte key = obj->attrs[ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID)].
611fcf3ce44SJohn Forte value.ptr;
612fcf3ce44SJohn Forte } else {
613fcf3ce44SJohn Forte /* p is lookup control data */
614fcf3ce44SJohn Forte lcp = (lookup_ctrl_t *)p;
615fcf3ce44SJohn Forte key = lcp->data[0].ptr;
616fcf3ce44SJohn Forte }
617fcf3ce44SJohn Forte
618fcf3ce44SJohn Forte return (htab_compute_hval(key));
619fcf3ce44SJohn Forte }
620fcf3ce44SJohn Forte
621fcf3ce44SJohn Forte /*
622fcf3ce44SJohn Forte * ****************************************************************************
623fcf3ce44SJohn Forte *
624fcf3ce44SJohn Forte * obj_hval:
625fcf3ce44SJohn Forte * caculate the hash value of an object.
626fcf3ce44SJohn Forte *
627fcf3ce44SJohn Forte * p - the pointer pointers to an object or lookup control data,
628fcf3ce44SJohn Forte * both has the object type and the key attributes of an object.
629fcf3ce44SJohn Forte * chunk- which chunk of the hash table.
630fcf3ce44SJohn Forte * flags- pointer to flags.
631fcf3ce44SJohn Forte * return - the hash value.
632fcf3ce44SJohn Forte *
633fcf3ce44SJohn Forte * ****************************************************************************
634fcf3ce44SJohn Forte */
635fcf3ce44SJohn Forte uint32_t
obj_hval(void * p,uint16_t chunk,uint32_t * flags)636fcf3ce44SJohn Forte obj_hval(
637fcf3ce44SJohn Forte void *p,
638fcf3ce44SJohn Forte uint16_t chunk,
639fcf3ce44SJohn Forte uint32_t *flags
640fcf3ce44SJohn Forte )
641fcf3ce44SJohn Forte {
642fcf3ce44SJohn Forte isns_type_t type = ((isns_obj_t *)p)->type;
643fcf3ce44SJohn Forte
644fcf3ce44SJohn Forte return (hval_func[type](p, chunk, flags));
645fcf3ce44SJohn Forte }
646fcf3ce44SJohn Forte
647fcf3ce44SJohn Forte /*
648fcf3ce44SJohn Forte * ****************************************************************************
649fcf3ce44SJohn Forte *
650fcf3ce44SJohn Forte * get_obj_uid:
651fcf3ce44SJohn Forte * get the UID of an object.
652fcf3ce44SJohn Forte *
653fcf3ce44SJohn Forte * p - the pointer pointers to an object.
654fcf3ce44SJohn Forte * return - the UID.
655fcf3ce44SJohn Forte *
656fcf3ce44SJohn Forte * ****************************************************************************
657fcf3ce44SJohn Forte */
658fcf3ce44SJohn Forte uint32_t
get_obj_uid(const void * p)659fcf3ce44SJohn Forte get_obj_uid(
660fcf3ce44SJohn Forte const void *p
661fcf3ce44SJohn Forte )
662fcf3ce44SJohn Forte {
663fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p;
664fcf3ce44SJohn Forte isns_attr_t *attr = &obj->attrs[UID_ATTR_INDEX[obj->type]];
665fcf3ce44SJohn Forte uint32_t uid = attr->value.ui;
666fcf3ce44SJohn Forte return (uid);
667fcf3ce44SJohn Forte }
668fcf3ce44SJohn Forte
669fcf3ce44SJohn Forte /*
670fcf3ce44SJohn Forte * ****************************************************************************
671fcf3ce44SJohn Forte *
672fcf3ce44SJohn Forte * set_obj_uid:
673fcf3ce44SJohn Forte * set the UID of an object.
674fcf3ce44SJohn Forte *
675fcf3ce44SJohn Forte * p - the pointer pointers to an object.
676fcf3ce44SJohn Forte * uid - the UID.
677fcf3ce44SJohn Forte * return - the UID.
678fcf3ce44SJohn Forte *
679fcf3ce44SJohn Forte * ****************************************************************************
680fcf3ce44SJohn Forte */
681fcf3ce44SJohn Forte uint32_t
set_obj_uid(void * p,uint32_t uid)682fcf3ce44SJohn Forte set_obj_uid(
683fcf3ce44SJohn Forte void *p,
684fcf3ce44SJohn Forte uint32_t uid
685fcf3ce44SJohn Forte )
686fcf3ce44SJohn Forte {
687fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p;
688fcf3ce44SJohn Forte isns_attr_t *attr = &obj->attrs[UID_ATTR_INDEX[obj->type]];
689fcf3ce44SJohn Forte
690fcf3ce44SJohn Forte /* set the tag, len and value */
691fcf3ce44SJohn Forte attr->tag = UID_TAG[obj->type];
692fcf3ce44SJohn Forte attr->len = 4;
693fcf3ce44SJohn Forte attr->value.ui = uid;
694fcf3ce44SJohn Forte
695fcf3ce44SJohn Forte return (uid);
696fcf3ce44SJohn Forte }
697fcf3ce44SJohn Forte
698fcf3ce44SJohn Forte /*
699fcf3ce44SJohn Forte * ****************************************************************************
700fcf3ce44SJohn Forte *
701fcf3ce44SJohn Forte * obj_cmp:
702fcf3ce44SJohn Forte * compare between two objects or an object with a lookup control data.
703fcf3ce44SJohn Forte *
704fcf3ce44SJohn Forte * p1 - the pointer points to an object.
705fcf3ce44SJohn Forte * p2 - the pointer points to an object or a lookup control data.
706fcf3ce44SJohn Forte * flags- 0: p2 is an object; otherwise p2 is a lookup control data.
707fcf3ce44SJohn Forte * return - the comparsion result.
708fcf3ce44SJohn Forte *
709fcf3ce44SJohn Forte * ****************************************************************************
710fcf3ce44SJohn Forte */
711fcf3ce44SJohn Forte int
obj_cmp(void * p1,void * p2,int flags)712fcf3ce44SJohn Forte obj_cmp(
713fcf3ce44SJohn Forte void *p1,
714fcf3ce44SJohn Forte void *p2,
715fcf3ce44SJohn Forte int flags
716fcf3ce44SJohn Forte )
717fcf3ce44SJohn Forte {
718fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p1;
719fcf3ce44SJohn Forte lookup_ctrl_t buff = { 0 };
720fcf3ce44SJohn Forte lookup_ctrl_t *lcp;
721fcf3ce44SJohn Forte uint32_t uid;
722fcf3ce44SJohn Forte
723fcf3ce44SJohn Forte if (flags == 0) {
724fcf3ce44SJohn Forte lcp = set_lookup_ctrl(&buff, (isns_obj_t *)p2);
725fcf3ce44SJohn Forte } else {
726fcf3ce44SJohn Forte lcp = (lookup_ctrl_t *)p2;
727fcf3ce44SJohn Forte uid = get_obj_uid(obj);
728fcf3ce44SJohn Forte /* the object are linked with decending order by */
729fcf3ce44SJohn Forte /* the object UID, if the object UID is greater than */
730fcf3ce44SJohn Forte /* or equal to the current UID, it needs to compare */
731fcf3ce44SJohn Forte /* for the next one. */
732fcf3ce44SJohn Forte if (lcp->curr_uid != 0 && uid >= lcp->curr_uid) {
733fcf3ce44SJohn Forte return (-1);
734fcf3ce44SJohn Forte }
735fcf3ce44SJohn Forte }
736fcf3ce44SJohn Forte
737fcf3ce44SJohn Forte return (key_cmp(lcp, obj));
738fcf3ce44SJohn Forte }
739fcf3ce44SJohn Forte
740fcf3ce44SJohn Forte /*
741fcf3ce44SJohn Forte * ****************************************************************************
742fcf3ce44SJohn Forte *
743fcf3ce44SJohn Forte * replace_object:
744fcf3ce44SJohn Forte * replace an existing object with the new one.
745fcf3ce44SJohn Forte *
746fcf3ce44SJohn Forte * p1 - the pointer points to an object being replaced.
747fcf3ce44SJohn Forte * p2 - the pointer points to a new object.
748fcf3ce44SJohn Forte * uid_p- points to uid for returning.
749fcf3ce44SJohn Forte * flag - 0: do not free the source object, otherwise free it.
750fcf3ce44SJohn Forte * return - error code.
751fcf3ce44SJohn Forte *
752fcf3ce44SJohn Forte * ****************************************************************************
753fcf3ce44SJohn Forte */
754fcf3ce44SJohn Forte int
replace_object(void * p1,void * p2,uint32_t * uid_p,int flag)755fcf3ce44SJohn Forte replace_object(
756fcf3ce44SJohn Forte void *p1,
757fcf3ce44SJohn Forte void *p2,
758fcf3ce44SJohn Forte uint32_t *uid_p,
759fcf3ce44SJohn Forte int flag
760fcf3ce44SJohn Forte )
761fcf3ce44SJohn Forte {
762fcf3ce44SJohn Forte int ec = 0;
763fcf3ce44SJohn Forte
764fcf3ce44SJohn Forte #ifndef SKIP_SRC_AUTH
765fcf3ce44SJohn Forte uint32_t *pp_dst, *pp_src, swap;
766fcf3ce44SJohn Forte #endif
767fcf3ce44SJohn Forte int online;
768fcf3ce44SJohn Forte
769fcf3ce44SJohn Forte isns_obj_t *dst = (isns_obj_t *)p1;
770fcf3ce44SJohn Forte isns_obj_t *src = (isns_obj_t *)p2;
771fcf3ce44SJohn Forte
772fcf3ce44SJohn Forte if (src->type == OBJ_DD || src->type == OBJ_DDS) {
773fcf3ce44SJohn Forte /* replace not allowed */
774fcf3ce44SJohn Forte return (ERR_NAME_IN_USE);
775fcf3ce44SJohn Forte }
776fcf3ce44SJohn Forte
777fcf3ce44SJohn Forte online = is_obj_online(dst);
778fcf3ce44SJohn Forte
779fcf3ce44SJohn Forte /* set cache update flag */
780fcf3ce44SJohn Forte SET_CACHE_UPDATED();
781fcf3ce44SJohn Forte
782fcf3ce44SJohn Forte /* update parent uid */
783fcf3ce44SJohn Forte #ifndef SKIP_SRC_AUTH
784fcf3ce44SJohn Forte pp_dst = get_parent_p(dst);
785fcf3ce44SJohn Forte if (pp_dst != NULL) {
786fcf3ce44SJohn Forte pp_src = get_parent_p(src);
787fcf3ce44SJohn Forte swap = *pp_dst;
788fcf3ce44SJohn Forte *pp_dst = *pp_src;
789fcf3ce44SJohn Forte if (swap != 0) {
790fcf3ce44SJohn Forte *pp_src = swap;
791fcf3ce44SJohn Forte }
792fcf3ce44SJohn Forte }
793fcf3ce44SJohn Forte #endif
794fcf3ce44SJohn Forte
795fcf3ce44SJohn Forte /* update all of attributes */
796fcf3ce44SJohn Forte if (copy_attrs(dst, src) != 0) {
797fcf3ce44SJohn Forte return (ISNS_RSP_INTERNAL_ERROR);
798fcf3ce44SJohn Forte }
799fcf3ce44SJohn Forte
800fcf3ce44SJohn Forte /* free up the src object */
801fcf3ce44SJohn Forte if (flag != 0) {
802fcf3ce44SJohn Forte (void) free_object(src);
803fcf3ce44SJohn Forte } else if (online == 0) {
804fcf3ce44SJohn Forte (void) set_obj_uid(src, get_obj_uid(dst));
805fcf3ce44SJohn Forte (void) set_obj_offline(src);
806fcf3ce44SJohn Forte }
807fcf3ce44SJohn Forte
808fcf3ce44SJohn Forte /* update data store */
809fcf3ce44SJohn Forte if (sys_q != NULL) {
810fcf3ce44SJohn Forte ec = write_data(DATA_UPDATE, dst);
811fcf3ce44SJohn Forte } else {
812fcf3ce44SJohn Forte /* we should never have duplicated entry in data store */
813fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
814fcf3ce44SJohn Forte }
815fcf3ce44SJohn Forte
816fcf3ce44SJohn Forte /* trigger a scn */
817fcf3ce44SJohn Forte if (ec == 0) {
818fcf3ce44SJohn Forte if (scn_q != NULL) {
819fcf3ce44SJohn Forte (void) make_scn((online == 0) ?
820fcf3ce44SJohn Forte ISNS_OBJECT_ADDED :
821fcf3ce44SJohn Forte ISNS_OBJECT_UPDATED,
822fcf3ce44SJohn Forte dst);
823fcf3ce44SJohn Forte }
824fcf3ce44SJohn Forte if (uid_p != NULL) {
825fcf3ce44SJohn Forte *uid_p = get_obj_uid(dst);
826fcf3ce44SJohn Forte }
827fcf3ce44SJohn Forte }
828fcf3ce44SJohn Forte
829fcf3ce44SJohn Forte return (ec);
830fcf3ce44SJohn Forte }
831fcf3ce44SJohn Forte
832fcf3ce44SJohn Forte /*
833fcf3ce44SJohn Forte * ****************************************************************************
834fcf3ce44SJohn Forte *
835fcf3ce44SJohn Forte * add_object:
836fcf3ce44SJohn Forte * post function after adding a new object.
837fcf3ce44SJohn Forte *
838fcf3ce44SJohn Forte * p - object which has been added.
839fcf3ce44SJohn Forte * return - error code.
840fcf3ce44SJohn Forte *
841fcf3ce44SJohn Forte * ****************************************************************************
842fcf3ce44SJohn Forte */
843fcf3ce44SJohn Forte int
add_object(void * p)844fcf3ce44SJohn Forte add_object(
845fcf3ce44SJohn Forte void *p
846fcf3ce44SJohn Forte )
847fcf3ce44SJohn Forte {
848fcf3ce44SJohn Forte int ec = 0;
849fcf3ce44SJohn Forte
850fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p;
851fcf3ce44SJohn Forte
852fcf3ce44SJohn Forte /* add the new object to data store */
853fcf3ce44SJohn Forte if (sys_q != NULL) {
854fcf3ce44SJohn Forte ec = write_data(DATA_ADD, obj);
855fcf3ce44SJohn Forte }
856fcf3ce44SJohn Forte
857fcf3ce44SJohn Forte /* trigger a scn */
858fcf3ce44SJohn Forte if (ec == 0 && scn_q != NULL) {
859fcf3ce44SJohn Forte (void) make_scn(ISNS_OBJECT_ADDED, obj);
860fcf3ce44SJohn Forte }
861fcf3ce44SJohn Forte
862fcf3ce44SJohn Forte return (ec);
863fcf3ce44SJohn Forte }
864fcf3ce44SJohn Forte
865fcf3ce44SJohn Forte /*
866fcf3ce44SJohn Forte * ****************************************************************************
867fcf3ce44SJohn Forte *
868fcf3ce44SJohn Forte * obj_tab_init:
869fcf3ce44SJohn Forte * initialize the object hash tables.
870fcf3ce44SJohn Forte *
871fcf3ce44SJohn Forte * c - points to the cache.
872fcf3ce44SJohn Forte * return - error code.
873fcf3ce44SJohn Forte *
874fcf3ce44SJohn Forte * ****************************************************************************
875fcf3ce44SJohn Forte */
876fcf3ce44SJohn Forte int
obj_tab_init(struct cache * c)877fcf3ce44SJohn Forte obj_tab_init(
878fcf3ce44SJohn Forte struct cache *c
879fcf3ce44SJohn Forte )
880fcf3ce44SJohn Forte {
881fcf3ce44SJohn Forte htab_t *t;
882fcf3ce44SJohn Forte
883fcf3ce44SJohn Forte htab_init();
884fcf3ce44SJohn Forte
885fcf3ce44SJohn Forte /*
886fcf3ce44SJohn Forte * allocate an array of pointer for the object hash tables.
887fcf3ce44SJohn Forte */
888fcf3ce44SJohn Forte c->t = (struct htab **)calloc(sizeof (struct htab *), MAX_OBJ_TYPE);
889fcf3ce44SJohn Forte if (c->t == NULL) {
890fcf3ce44SJohn Forte return (1);
891fcf3ce44SJohn Forte }
892fcf3ce44SJohn Forte
893fcf3ce44SJohn Forte /*
894fcf3ce44SJohn Forte * hash table for network entity objects.
895fcf3ce44SJohn Forte */
896fcf3ce44SJohn Forte t = htab_create(UID_FLAGS_SEQ, 8, 1);
897fcf3ce44SJohn Forte if (t != NULL) {
898fcf3ce44SJohn Forte t->c = c;
899fcf3ce44SJohn Forte c->t[OBJ_ENTITY] = t;
900fcf3ce44SJohn Forte } else {
901fcf3ce44SJohn Forte return (1);
902fcf3ce44SJohn Forte }
903fcf3ce44SJohn Forte
904fcf3ce44SJohn Forte /*
905fcf3ce44SJohn Forte * hash table for iscsi storage node objects.
906fcf3ce44SJohn Forte */
907fcf3ce44SJohn Forte t = htab_create(UID_FLAGS_SEQ, 8, 1);
908fcf3ce44SJohn Forte if (t != NULL) {
909fcf3ce44SJohn Forte t->c = c;
910fcf3ce44SJohn Forte c->t[OBJ_ISCSI] = t;
911fcf3ce44SJohn Forte } else {
912fcf3ce44SJohn Forte return (1);
913fcf3ce44SJohn Forte }
914fcf3ce44SJohn Forte
915fcf3ce44SJohn Forte /*
916fcf3ce44SJohn Forte * hash table for portal objects.
917fcf3ce44SJohn Forte */
918fcf3ce44SJohn Forte t = htab_create(UID_FLAGS_SEQ, 8, 1);
919fcf3ce44SJohn Forte if (t != NULL) {
920fcf3ce44SJohn Forte t->c = c;
921fcf3ce44SJohn Forte c->t[OBJ_PORTAL] = t;
922fcf3ce44SJohn Forte } else {
923fcf3ce44SJohn Forte return (1);
924fcf3ce44SJohn Forte }
925fcf3ce44SJohn Forte
926fcf3ce44SJohn Forte /*
927fcf3ce44SJohn Forte * hash table for portal group objects.
928fcf3ce44SJohn Forte */
929fcf3ce44SJohn Forte t = htab_create(UID_FLAGS_SEQ, 8, 2);
930fcf3ce44SJohn Forte if (t != NULL) {
931fcf3ce44SJohn Forte t->c = c;
932fcf3ce44SJohn Forte c->t[OBJ_PG] = t;
933fcf3ce44SJohn Forte } else {
934fcf3ce44SJohn Forte return (1);
935fcf3ce44SJohn Forte }
936fcf3ce44SJohn Forte
937fcf3ce44SJohn Forte /*
938fcf3ce44SJohn Forte * hash table for discovery domain objects.
939fcf3ce44SJohn Forte */
940fcf3ce44SJohn Forte t = htab_create(0, 6, 1);
941fcf3ce44SJohn Forte if (t != NULL) {
942fcf3ce44SJohn Forte t->c = c;
943fcf3ce44SJohn Forte c->t[OBJ_DD] = t;
944fcf3ce44SJohn Forte } else {
945fcf3ce44SJohn Forte return (1);
946fcf3ce44SJohn Forte }
947fcf3ce44SJohn Forte
948fcf3ce44SJohn Forte /*
949fcf3ce44SJohn Forte * hash table for discovery domain set objects.
950fcf3ce44SJohn Forte */
951fcf3ce44SJohn Forte t = htab_create(0, 4, 1);
952fcf3ce44SJohn Forte if (t != NULL) {
953fcf3ce44SJohn Forte t->c = c;
954fcf3ce44SJohn Forte c->t[OBJ_DDS] = t;
955fcf3ce44SJohn Forte } else {
956fcf3ce44SJohn Forte return (1);
957fcf3ce44SJohn Forte }
958fcf3ce44SJohn Forte
959fcf3ce44SJohn Forte return (0);
960fcf3ce44SJohn Forte }
961fcf3ce44SJohn Forte
962fcf3ce44SJohn Forte /*
963fcf3ce44SJohn Forte * ****************************************************************************
964fcf3ce44SJohn Forte *
965fcf3ce44SJohn Forte * get_ref_np:
966fcf3ce44SJohn Forte * get the ref pointer of the portal group object.
967fcf3ce44SJohn Forte *
968fcf3ce44SJohn Forte * obj - portal group object.
969fcf3ce44SJohn Forte * return - ref pointer.
970fcf3ce44SJohn Forte *
971fcf3ce44SJohn Forte * ****************************************************************************
972fcf3ce44SJohn Forte */
973fcf3ce44SJohn Forte static uint32_t *
get_ref_np(isns_obj_t * obj,int n)974fcf3ce44SJohn Forte get_ref_np(
975fcf3ce44SJohn Forte isns_obj_t *obj,
976fcf3ce44SJohn Forte int n
977fcf3ce44SJohn Forte )
978fcf3ce44SJohn Forte {
979fcf3ce44SJohn Forte uint32_t *refp =
980fcf3ce44SJohn Forte obj->type == OBJ_PG ? &((isns_pg_t *)obj)->ref[n] : NULL;
981fcf3ce44SJohn Forte
982fcf3ce44SJohn Forte return (refp);
983fcf3ce44SJohn Forte }
984fcf3ce44SJohn Forte
985fcf3ce44SJohn Forte #ifdef DEBUG
986fcf3ce44SJohn Forte uint32_t
987fcf3ce44SJohn Forte #else
988fcf3ce44SJohn Forte static uint32_t
989fcf3ce44SJohn Forte #endif
get_ref_n(isns_obj_t * obj,int n)990fcf3ce44SJohn Forte get_ref_n(
991fcf3ce44SJohn Forte isns_obj_t *obj,
992fcf3ce44SJohn Forte int n
993fcf3ce44SJohn Forte )
994fcf3ce44SJohn Forte {
995fcf3ce44SJohn Forte return (*get_ref_np(obj, n));
996fcf3ce44SJohn Forte }
997fcf3ce44SJohn Forte
998fcf3ce44SJohn Forte static uint32_t *
get_ref_p(isns_obj_t * obj,isns_type_t rt)999fcf3ce44SJohn Forte get_ref_p(
1000fcf3ce44SJohn Forte isns_obj_t *obj,
1001fcf3ce44SJohn Forte isns_type_t rt
1002fcf3ce44SJohn Forte )
1003fcf3ce44SJohn Forte {
1004fcf3ce44SJohn Forte isns_type_t t = obj->type;
1005fcf3ce44SJohn Forte
1006fcf3ce44SJohn Forte int i = 0;
1007fcf3ce44SJohn Forte while (i < NUM_OF_REF[t]) {
1008fcf3ce44SJohn Forte if (rt == TYPE_OF_REF[t][i + 1]) {
1009fcf3ce44SJohn Forte return (get_ref_np(obj, i));
1010fcf3ce44SJohn Forte }
1011fcf3ce44SJohn Forte i ++;
1012fcf3ce44SJohn Forte }
1013fcf3ce44SJohn Forte
1014fcf3ce44SJohn Forte return (NULL);
1015fcf3ce44SJohn Forte }
1016fcf3ce44SJohn Forte
1017fcf3ce44SJohn Forte uint32_t
get_ref_t(isns_obj_t * obj,isns_type_t type)1018fcf3ce44SJohn Forte get_ref_t(
1019fcf3ce44SJohn Forte isns_obj_t *obj,
1020fcf3ce44SJohn Forte isns_type_t type
1021fcf3ce44SJohn Forte )
1022fcf3ce44SJohn Forte {
1023fcf3ce44SJohn Forte uint32_t *refp = get_ref_p(obj, type);
1024fcf3ce44SJohn Forte
1025fcf3ce44SJohn Forte if (refp != NULL) {
1026fcf3ce44SJohn Forte return (*refp);
1027fcf3ce44SJohn Forte /* LINTED E_NOP_ELSE_STMT */
1028fcf3ce44SJohn Forte } else {
1029fcf3ce44SJohn Forte ASSERT(0);
1030fcf3ce44SJohn Forte }
1031fcf3ce44SJohn Forte
1032fcf3ce44SJohn Forte return (0);
1033fcf3ce44SJohn Forte }
1034fcf3ce44SJohn Forte
1035fcf3ce44SJohn Forte /*
1036fcf3ce44SJohn Forte * ****************************************************************************
1037fcf3ce44SJohn Forte *
1038fcf3ce44SJohn Forte * get_parent_p:
1039fcf3ce44SJohn Forte * get the pointer of the parent object.
1040fcf3ce44SJohn Forte *
1041fcf3ce44SJohn Forte * obj - an object.
1042fcf3ce44SJohn Forte * return - parent object pointer.
1043fcf3ce44SJohn Forte *
1044fcf3ce44SJohn Forte * ****************************************************************************
1045fcf3ce44SJohn Forte */
1046fcf3ce44SJohn Forte uint32_t *const
get_parent_p(const isns_obj_t * obj)1047fcf3ce44SJohn Forte get_parent_p(
1048fcf3ce44SJohn Forte const isns_obj_t *obj
1049fcf3ce44SJohn Forte )
1050fcf3ce44SJohn Forte {
1051fcf3ce44SJohn Forte uint32_t *pp;
1052fcf3ce44SJohn Forte switch (obj->type) {
1053fcf3ce44SJohn Forte case OBJ_ISCSI:
1054fcf3ce44SJohn Forte pp = &((isns_iscsi_t *)obj)->puid;
1055fcf3ce44SJohn Forte break;
1056fcf3ce44SJohn Forte case OBJ_PORTAL:
1057fcf3ce44SJohn Forte pp = &((isns_portal_t *)obj)->puid;
1058fcf3ce44SJohn Forte break;
1059fcf3ce44SJohn Forte case OBJ_PG:
1060fcf3ce44SJohn Forte pp = &((isns_pg_t *)obj)->puid;
1061fcf3ce44SJohn Forte break;
1062fcf3ce44SJohn Forte case OBJ_ASSOC_ISCSI:
1063fcf3ce44SJohn Forte pp = &((isns_assoc_iscsi_t *)obj)->puid;
1064fcf3ce44SJohn Forte break;
1065fcf3ce44SJohn Forte case OBJ_ASSOC_DD:
1066fcf3ce44SJohn Forte pp = &((isns_assoc_dd_t *)obj)->puid;
1067fcf3ce44SJohn Forte break;
1068fcf3ce44SJohn Forte default:
1069fcf3ce44SJohn Forte pp = NULL;
1070fcf3ce44SJohn Forte break;
1071fcf3ce44SJohn Forte }
1072fcf3ce44SJohn Forte
1073fcf3ce44SJohn Forte return (pp);
1074fcf3ce44SJohn Forte }
1075fcf3ce44SJohn Forte
1076fcf3ce44SJohn Forte uint32_t
get_parent_uid(const isns_obj_t * obj)1077fcf3ce44SJohn Forte get_parent_uid(
1078fcf3ce44SJohn Forte const isns_obj_t *obj
1079fcf3ce44SJohn Forte )
1080fcf3ce44SJohn Forte {
1081fcf3ce44SJohn Forte uint32_t *pp = get_parent_p(obj);
1082fcf3ce44SJohn Forte if (pp != NULL) {
1083fcf3ce44SJohn Forte return (*pp);
1084fcf3ce44SJohn Forte }
1085fcf3ce44SJohn Forte
1086fcf3ce44SJohn Forte return (0);
1087fcf3ce44SJohn Forte }
1088fcf3ce44SJohn Forte
1089fcf3ce44SJohn Forte /*
1090fcf3ce44SJohn Forte * ****************************************************************************
1091fcf3ce44SJohn Forte *
1092fcf3ce44SJohn Forte * get_child_np:
1093fcf3ce44SJohn Forte * get the pointer of the UID array of the n'th child of an object.
1094fcf3ce44SJohn Forte *
1095fcf3ce44SJohn Forte * obj - an object.
1096fcf3ce44SJohn Forte * n - the child index.
1097fcf3ce44SJohn Forte * return - the pointer of the UID array.
1098fcf3ce44SJohn Forte *
1099fcf3ce44SJohn Forte * ****************************************************************************
1100fcf3ce44SJohn Forte */
1101fcf3ce44SJohn Forte static uint32_t **
get_child_np(isns_obj_t * obj,int n)1102fcf3ce44SJohn Forte get_child_np(
1103fcf3ce44SJohn Forte isns_obj_t *obj,
1104fcf3ce44SJohn Forte int n
1105fcf3ce44SJohn Forte )
1106fcf3ce44SJohn Forte {
1107fcf3ce44SJohn Forte uint32_t **pp =
1108fcf3ce44SJohn Forte obj->type == OBJ_ENTITY ? &((isns_entity_t *)obj)->cuid[n] : NULL;
1109fcf3ce44SJohn Forte
1110fcf3ce44SJohn Forte return (pp);
1111fcf3ce44SJohn Forte }
1112fcf3ce44SJohn Forte
1113fcf3ce44SJohn Forte /*
1114fcf3ce44SJohn Forte * ****************************************************************************
1115fcf3ce44SJohn Forte *
1116fcf3ce44SJohn Forte * get_child_n:
1117fcf3ce44SJohn Forte * get the UID array of the n'th child of an object.
1118fcf3ce44SJohn Forte *
1119fcf3ce44SJohn Forte * obj - an object.
1120fcf3ce44SJohn Forte * n - the child index.
1121fcf3ce44SJohn Forte * return - the UID array.
1122fcf3ce44SJohn Forte *
1123fcf3ce44SJohn Forte * ****************************************************************************
1124fcf3ce44SJohn Forte */
1125fcf3ce44SJohn Forte #ifdef DEBUG
1126fcf3ce44SJohn Forte uint32_t *
1127fcf3ce44SJohn Forte #else
1128fcf3ce44SJohn Forte static uint32_t *
1129fcf3ce44SJohn Forte #endif
get_child_n(isns_obj_t * obj,int n)1130fcf3ce44SJohn Forte get_child_n(
1131fcf3ce44SJohn Forte isns_obj_t *obj,
1132fcf3ce44SJohn Forte int n
1133fcf3ce44SJohn Forte )
1134fcf3ce44SJohn Forte {
1135fcf3ce44SJohn Forte uint32_t **pp = get_child_np(obj, n);
1136fcf3ce44SJohn Forte
1137fcf3ce44SJohn Forte if (pp != NULL) {
1138fcf3ce44SJohn Forte return (*pp);
1139fcf3ce44SJohn Forte }
1140fcf3ce44SJohn Forte
1141fcf3ce44SJohn Forte ASSERT(0);
1142fcf3ce44SJohn Forte return (NULL);
1143fcf3ce44SJohn Forte }
1144fcf3ce44SJohn Forte
1145fcf3ce44SJohn Forte /*
1146fcf3ce44SJohn Forte * ****************************************************************************
1147fcf3ce44SJohn Forte *
1148fcf3ce44SJohn Forte * get_child_p:
1149fcf3ce44SJohn Forte * get the pointer of the UID array of the child matching the type.
1150fcf3ce44SJohn Forte *
1151fcf3ce44SJohn Forte * base - an object.
1152fcf3ce44SJohn Forte * child_type - the child object type.
1153fcf3ce44SJohn Forte * return - the pointer of the UID array.
1154fcf3ce44SJohn Forte *
1155fcf3ce44SJohn Forte * ****************************************************************************
1156fcf3ce44SJohn Forte */
1157fcf3ce44SJohn Forte static uint32_t **
get_child_p(isns_obj_t * base,int child_type)1158fcf3ce44SJohn Forte get_child_p(
1159fcf3ce44SJohn Forte isns_obj_t *base,
1160fcf3ce44SJohn Forte int child_type
1161fcf3ce44SJohn Forte )
1162fcf3ce44SJohn Forte {
1163fcf3ce44SJohn Forte uint32_t **pp = NULL;
1164fcf3ce44SJohn Forte int i = 0;
1165fcf3ce44SJohn Forte while (i < NUM_OF_CHILD[base->type]) {
1166fcf3ce44SJohn Forte if (child_type == TYPE_OF_CHILD[base->type][i]) {
1167fcf3ce44SJohn Forte pp = get_child_np(base, i);
1168fcf3ce44SJohn Forte break;
1169fcf3ce44SJohn Forte }
1170fcf3ce44SJohn Forte i ++;
1171fcf3ce44SJohn Forte }
1172fcf3ce44SJohn Forte
1173fcf3ce44SJohn Forte return (pp);
1174fcf3ce44SJohn Forte }
1175fcf3ce44SJohn Forte
1176fcf3ce44SJohn Forte /*
1177fcf3ce44SJohn Forte * ****************************************************************************
1178fcf3ce44SJohn Forte *
1179fcf3ce44SJohn Forte * get_child_t:
1180fcf3ce44SJohn Forte * get the UID array of the child object matching the type.
1181fcf3ce44SJohn Forte *
1182fcf3ce44SJohn Forte * base - an object.
1183fcf3ce44SJohn Forte * child_type - the child object type.
1184fcf3ce44SJohn Forte * return - the UID array.
1185fcf3ce44SJohn Forte *
1186fcf3ce44SJohn Forte * ****************************************************************************
1187fcf3ce44SJohn Forte */
1188fcf3ce44SJohn Forte uint32_t *
get_child_t(isns_obj_t * base,int child_type)1189fcf3ce44SJohn Forte get_child_t(
1190fcf3ce44SJohn Forte isns_obj_t *base,
1191fcf3ce44SJohn Forte int child_type
1192fcf3ce44SJohn Forte )
1193fcf3ce44SJohn Forte {
1194fcf3ce44SJohn Forte uint32_t **pp = get_child_p(base, child_type);
1195fcf3ce44SJohn Forte
1196fcf3ce44SJohn Forte if (pp != NULL) {
1197fcf3ce44SJohn Forte return (*pp);
1198fcf3ce44SJohn Forte } else {
1199fcf3ce44SJohn Forte return (NULL);
1200fcf3ce44SJohn Forte }
1201fcf3ce44SJohn Forte }
1202fcf3ce44SJohn Forte
1203fcf3ce44SJohn Forte /*
1204fcf3ce44SJohn Forte * ****************************************************************************
1205fcf3ce44SJohn Forte *
1206fcf3ce44SJohn Forte * key_cmp:
1207fcf3ce44SJohn Forte * compare the object against the lookup control data.
1208fcf3ce44SJohn Forte *
1209fcf3ce44SJohn Forte * lcp - the lookup control data.
1210fcf3ce44SJohn Forte * obj - an object.
1211fcf3ce44SJohn Forte * return - comparison result.
1212fcf3ce44SJohn Forte *
1213fcf3ce44SJohn Forte * ****************************************************************************
1214fcf3ce44SJohn Forte */
1215fcf3ce44SJohn Forte int
key_cmp(lookup_ctrl_t * lcp,isns_obj_t * obj)1216fcf3ce44SJohn Forte key_cmp(
1217fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
1218fcf3ce44SJohn Forte isns_obj_t *obj
1219fcf3ce44SJohn Forte )
1220fcf3ce44SJohn Forte {
1221fcf3ce44SJohn Forte int i = 0;
1222fcf3ce44SJohn Forte int match = 1;
1223fcf3ce44SJohn Forte while (i < MAX_LOOKUP_CTRL && lcp->op[i] > 0 && match) {
1224fcf3ce44SJohn Forte isns_attr_t *attr = &obj->attrs[lcp->id[i]];
1225fcf3ce44SJohn Forte switch (lcp->op[i]) {
1226fcf3ce44SJohn Forte case OP_STRING:
1227fcf3ce44SJohn Forte match = (strcmp((const char *)lcp->data[i].ptr,
1228fcf3ce44SJohn Forte (const char *)attr->value.ptr) == 0);
1229fcf3ce44SJohn Forte break;
1230fcf3ce44SJohn Forte case OP_INTEGER:
1231fcf3ce44SJohn Forte match = (lcp->data[i].ui == attr->value.ui);
1232fcf3ce44SJohn Forte break;
1233fcf3ce44SJohn Forte case OP_MEMORY_IP6:
1234fcf3ce44SJohn Forte match = !memcmp((void *)lcp->data[i].ip,
1235fcf3ce44SJohn Forte (void *)attr->value.ip,
1236fcf3ce44SJohn Forte sizeof (in6_addr_t));
1237fcf3ce44SJohn Forte break;
1238fcf3ce44SJohn Forte default:
1239fcf3ce44SJohn Forte ASSERT(0);
1240fcf3ce44SJohn Forte match = 0;
1241fcf3ce44SJohn Forte break;
1242fcf3ce44SJohn Forte }
1243fcf3ce44SJohn Forte i ++;
1244fcf3ce44SJohn Forte }
1245fcf3ce44SJohn Forte
1246fcf3ce44SJohn Forte if (i && match) {
1247fcf3ce44SJohn Forte return (0);
1248fcf3ce44SJohn Forte } else {
1249fcf3ce44SJohn Forte return (1);
1250fcf3ce44SJohn Forte }
1251fcf3ce44SJohn Forte }
1252fcf3ce44SJohn Forte
1253fcf3ce44SJohn Forte /*
1254fcf3ce44SJohn Forte * ****************************************************************************
1255fcf3ce44SJohn Forte *
1256fcf3ce44SJohn Forte * set_lookup_ctrl:
1257fcf3ce44SJohn Forte * fill in the lookup control data for an object.
1258fcf3ce44SJohn Forte *
1259fcf3ce44SJohn Forte * lcp - the lookup control data.
1260fcf3ce44SJohn Forte * obj - an object.
1261fcf3ce44SJohn Forte * return - the lookup control data.
1262fcf3ce44SJohn Forte *
1263fcf3ce44SJohn Forte * ****************************************************************************
1264fcf3ce44SJohn Forte */
1265fcf3ce44SJohn Forte static lookup_ctrl_t *
set_lookup_ctrl(lookup_ctrl_t * lcp,isns_obj_t * obj)1266fcf3ce44SJohn Forte set_lookup_ctrl(
1267fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
1268fcf3ce44SJohn Forte isns_obj_t *obj
1269fcf3ce44SJohn Forte )
1270fcf3ce44SJohn Forte {
1271fcf3ce44SJohn Forte isns_type_t type = obj->type;
1272fcf3ce44SJohn Forte uint32_t id, op;
1273fcf3ce44SJohn Forte int i = 0;
1274fcf3ce44SJohn Forte
1275fcf3ce44SJohn Forte lcp->type = type;
1276fcf3ce44SJohn Forte while (i < MAX_KEY_ATTRS) {
1277fcf3ce44SJohn Forte op = KEY_ATTR_OP[type][i];
1278fcf3ce44SJohn Forte if (op != 0) {
1279fcf3ce44SJohn Forte id = KEY_ATTR_INDEX[type][i];
1280fcf3ce44SJohn Forte lcp->id[i] = id;
1281fcf3ce44SJohn Forte lcp->op[i] = op;
1282fcf3ce44SJohn Forte lcp->data[i].ui = obj->attrs[id].value.ui;
1283fcf3ce44SJohn Forte } else {
1284fcf3ce44SJohn Forte break;
1285fcf3ce44SJohn Forte }
1286fcf3ce44SJohn Forte i ++;
1287fcf3ce44SJohn Forte }
1288fcf3ce44SJohn Forte
1289fcf3ce44SJohn Forte return (lcp);
1290fcf3ce44SJohn Forte }
1291fcf3ce44SJohn Forte
1292fcf3ce44SJohn Forte /*
1293fcf3ce44SJohn Forte * ****************************************************************************
1294fcf3ce44SJohn Forte *
1295fcf3ce44SJohn Forte * assign_attr:
1296fcf3ce44SJohn Forte * assign an attribute.
1297fcf3ce44SJohn Forte *
1298fcf3ce44SJohn Forte * attr - the attribute being assigned.
1299fcf3ce44SJohn Forte * tmp - the attribute.
1300fcf3ce44SJohn Forte * return - error code.
1301fcf3ce44SJohn Forte *
1302fcf3ce44SJohn Forte * ****************************************************************************
1303fcf3ce44SJohn Forte */
1304fcf3ce44SJohn Forte int
assign_attr(isns_attr_t * attr,const isns_attr_t * tmp)1305fcf3ce44SJohn Forte assign_attr(
1306fcf3ce44SJohn Forte isns_attr_t *attr,
1307fcf3ce44SJohn Forte const isns_attr_t *tmp
1308fcf3ce44SJohn Forte )
1309fcf3ce44SJohn Forte {
1310fcf3ce44SJohn Forte uint32_t t;
1311fcf3ce44SJohn Forte
1312fcf3ce44SJohn Forte switch (tmp->tag) {
1313fcf3ce44SJohn Forte case ISNS_EID_ATTR_ID:
1314fcf3ce44SJohn Forte case ISNS_DD_SET_NAME_ATTR_ID:
1315fcf3ce44SJohn Forte case ISNS_DD_NAME_ATTR_ID:
1316fcf3ce44SJohn Forte if (tmp->len == 0 && attr->len == 0) {
1317fcf3ce44SJohn Forte int len;
1318fcf3ce44SJohn Forte char *name = make_unique_name(&len, tmp->tag);
1319fcf3ce44SJohn Forte if (name != NULL) {
1320fcf3ce44SJohn Forte attr->value.ptr = (uchar_t *)name;
1321fcf3ce44SJohn Forte attr->tag = tmp->tag;
1322fcf3ce44SJohn Forte attr->len = len;
1323fcf3ce44SJohn Forte } else {
1324fcf3ce44SJohn Forte /* memory exhausted */
1325fcf3ce44SJohn Forte return (1);
1326fcf3ce44SJohn Forte }
1327fcf3ce44SJohn Forte }
1328fcf3ce44SJohn Forte case ISNS_PORTAL_NAME_ATTR_ID:
1329fcf3ce44SJohn Forte case ISNS_ISCSI_NAME_ATTR_ID:
1330fcf3ce44SJohn Forte case ISNS_ISCSI_ALIAS_ATTR_ID:
1331fcf3ce44SJohn Forte case ISNS_ISCSI_AUTH_METHOD_ATTR_ID:
1332fcf3ce44SJohn Forte case ISNS_PG_ISCSI_NAME_ATTR_ID:
1333fcf3ce44SJohn Forte case ISNS_DD_ISCSI_NAME_ATTR_ID:
1334fcf3ce44SJohn Forte if (tmp->len == 0) {
1335fcf3ce44SJohn Forte return (0);
1336*530e2b59Swl202157@icefox } else if (tmp->len >= attr->len) {
1337*530e2b59Swl202157@icefox attr->value.ptr = realloc(
1338*530e2b59Swl202157@icefox attr->value.ptr, tmp->len + 1);
1339fcf3ce44SJohn Forte }
1340fcf3ce44SJohn Forte if (attr->value.ptr != NULL) {
1341*530e2b59Swl202157@icefox (void) strncpy((char *)attr->value.ptr,
1342*530e2b59Swl202157@icefox (char *)tmp->value.ptr, tmp->len);
1343*530e2b59Swl202157@icefox attr->value.ptr[tmp->len] = 0;
1344fcf3ce44SJohn Forte attr->tag = tmp->tag;
1345fcf3ce44SJohn Forte attr->len = tmp->len;
1346fcf3ce44SJohn Forte } else {
1347fcf3ce44SJohn Forte /* memory exhausted */
1348fcf3ce44SJohn Forte return (1);
1349fcf3ce44SJohn Forte }
1350fcf3ce44SJohn Forte break;
1351fcf3ce44SJohn Forte case ISNS_MGMT_IP_ADDR_ATTR_ID:
1352fcf3ce44SJohn Forte case ISNS_PORTAL_IP_ADDR_ATTR_ID:
1353fcf3ce44SJohn Forte case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
1354fcf3ce44SJohn Forte if (attr->value.ip == NULL) {
1355fcf3ce44SJohn Forte attr->value.ip = (in6_addr_t *)calloc(1, tmp->len);
1356fcf3ce44SJohn Forte }
1357fcf3ce44SJohn Forte if (attr->value.ip != NULL) {
1358fcf3ce44SJohn Forte (void) memcpy((void *)attr->value.ip,
1359fcf3ce44SJohn Forte (void *)tmp->value.ip, tmp->len);
1360fcf3ce44SJohn Forte attr->tag = tmp->tag;
1361fcf3ce44SJohn Forte attr->len = tmp->len;
1362fcf3ce44SJohn Forte } else {
1363fcf3ce44SJohn Forte /* memory exhausted */
1364fcf3ce44SJohn Forte return (1);
1365fcf3ce44SJohn Forte }
1366fcf3ce44SJohn Forte break;
1367fcf3ce44SJohn Forte case ISNS_ENTITY_INDEX_ATTR_ID:
1368fcf3ce44SJohn Forte case ISNS_PORTAL_INDEX_ATTR_ID:
1369fcf3ce44SJohn Forte case ISNS_ISCSI_NODE_INDEX_ATTR_ID:
1370fcf3ce44SJohn Forte case ISNS_PG_INDEX_ATTR_ID:
1371fcf3ce44SJohn Forte case ISNS_DD_SET_ID_ATTR_ID:
1372fcf3ce44SJohn Forte case ISNS_DD_ID_ATTR_ID:
1373fcf3ce44SJohn Forte if (attr->value.ui != 0) {
1374fcf3ce44SJohn Forte break;
1375fcf3ce44SJohn Forte }
1376fcf3ce44SJohn Forte case ISNS_ENTITY_PROTOCOL_ATTR_ID:
1377fcf3ce44SJohn Forte case ISNS_VERSION_RANGE_ATTR_ID:
1378fcf3ce44SJohn Forte
1379fcf3ce44SJohn Forte case ISNS_PORTAL_PORT_ATTR_ID:
1380fcf3ce44SJohn Forte case ISNS_ESI_PORT_ATTR_ID:
1381fcf3ce44SJohn Forte case ISNS_SCN_PORT_ATTR_ID:
1382fcf3ce44SJohn Forte
1383fcf3ce44SJohn Forte case ISNS_ISCSI_NODE_TYPE_ATTR_ID:
1384fcf3ce44SJohn Forte case ISNS_ISCSI_SCN_BITMAP_ATTR_ID:
1385fcf3ce44SJohn Forte
1386fcf3ce44SJohn Forte case ISNS_PG_PORTAL_PORT_ATTR_ID:
1387fcf3ce44SJohn Forte case ISNS_PG_TAG_ATTR_ID:
1388fcf3ce44SJohn Forte
1389fcf3ce44SJohn Forte case ISNS_DD_SET_STATUS_ATTR_ID:
1390fcf3ce44SJohn Forte case ISNS_DD_ISCSI_INDEX_ATTR_ID:
1391fcf3ce44SJohn Forte attr->tag = tmp->tag;
1392fcf3ce44SJohn Forte attr->len = tmp->len;
1393fcf3ce44SJohn Forte attr->value.ui = tmp->value.ui;
1394fcf3ce44SJohn Forte break;
1395fcf3ce44SJohn Forte case ISNS_ENTITY_REG_PERIOD_ATTR_ID:
1396fcf3ce44SJohn Forte attr->tag = tmp->tag;
1397fcf3ce44SJohn Forte attr->len = tmp->len;
1398fcf3ce44SJohn Forte attr->value.ui = tmp->value.ui;
1399fcf3ce44SJohn Forte t = get_reg_period();
1400fcf3ce44SJohn Forte if (attr->value.ui > t) {
1401fcf3ce44SJohn Forte attr->value.ui = t;
1402fcf3ce44SJohn Forte } else if (attr->value.ui < ONE_DAY) {
1403fcf3ce44SJohn Forte attr->value.ui = ONE_DAY;
1404fcf3ce44SJohn Forte }
1405fcf3ce44SJohn Forte break;
1406fcf3ce44SJohn Forte case ISNS_ESI_INTERVAL_ATTR_ID:
1407fcf3ce44SJohn Forte attr->tag = tmp->tag;
1408fcf3ce44SJohn Forte attr->len = tmp->len;
1409fcf3ce44SJohn Forte attr->value.ui = tmp->value.ui;
1410fcf3ce44SJohn Forte if (attr->value.ui > ONE_DAY) {
1411fcf3ce44SJohn Forte attr->value.ui = ONE_DAY;
1412fcf3ce44SJohn Forte } else if (attr->value.ui < MIN_ESI_INTVAL) {
1413fcf3ce44SJohn Forte attr->value.ui = MIN_ESI_INTVAL; /* 20 seconds */
1414fcf3ce44SJohn Forte }
1415fcf3ce44SJohn Forte break;
1416fcf3ce44SJohn Forte default:
1417fcf3ce44SJohn Forte ASSERT(0);
1418fcf3ce44SJohn Forte /* don't assign the attribute */
1419fcf3ce44SJohn Forte break;
1420fcf3ce44SJohn Forte }
1421fcf3ce44SJohn Forte return (0);
1422fcf3ce44SJohn Forte }
1423fcf3ce44SJohn Forte
1424fcf3ce44SJohn Forte /*
1425fcf3ce44SJohn Forte * ****************************************************************************
1426fcf3ce44SJohn Forte *
1427fcf3ce44SJohn Forte * copy_attrs:
1428fcf3ce44SJohn Forte * copy all of attributes from one object to another.
1429fcf3ce44SJohn Forte *
1430fcf3ce44SJohn Forte * dst - the destination object.
1431fcf3ce44SJohn Forte * tmp - the source object.
1432fcf3ce44SJohn Forte * return - error code.
1433fcf3ce44SJohn Forte *
1434fcf3ce44SJohn Forte * ****************************************************************************
1435fcf3ce44SJohn Forte */
1436fcf3ce44SJohn Forte static int
copy_attrs(isns_obj_t * dst,const isns_obj_t * src)1437fcf3ce44SJohn Forte copy_attrs(
1438fcf3ce44SJohn Forte isns_obj_t *dst,
1439fcf3ce44SJohn Forte const isns_obj_t *src
1440fcf3ce44SJohn Forte )
1441fcf3ce44SJohn Forte {
1442fcf3ce44SJohn Forte int i = 0;
1443fcf3ce44SJohn Forte int n = NUM_OF_ATTRS[dst->type];
1444fcf3ce44SJohn Forte
1445fcf3ce44SJohn Forte isns_attr_t *dst_attr;
1446fcf3ce44SJohn Forte const isns_attr_t *src_attr;
1447fcf3ce44SJohn Forte
1448fcf3ce44SJohn Forte while (i < n) {
1449fcf3ce44SJohn Forte src_attr = &(src->attrs[i]);
1450fcf3ce44SJohn Forte if (src_attr->tag != 0) {
1451fcf3ce44SJohn Forte dst_attr = &(dst->attrs[i]);
1452fcf3ce44SJohn Forte if (assign_attr(dst_attr, src_attr) != 0) {
1453fcf3ce44SJohn Forte return (1);
1454fcf3ce44SJohn Forte }
1455fcf3ce44SJohn Forte }
1456fcf3ce44SJohn Forte i ++;
1457fcf3ce44SJohn Forte }
1458fcf3ce44SJohn Forte
1459fcf3ce44SJohn Forte return (0);
1460fcf3ce44SJohn Forte }
1461fcf3ce44SJohn Forte
1462fcf3ce44SJohn Forte /*
1463fcf3ce44SJohn Forte * ****************************************************************************
1464fcf3ce44SJohn Forte *
1465fcf3ce44SJohn Forte * extract_attr:
1466fcf3ce44SJohn Forte * extract an attribute from a TLV format data.
1467fcf3ce44SJohn Forte *
1468fcf3ce44SJohn Forte * attr - the attribute.
1469fcf3ce44SJohn Forte * tlv - the TLV format data.
1470fcf3ce44SJohn Forte * return - error code.
1471fcf3ce44SJohn Forte *
1472fcf3ce44SJohn Forte * ****************************************************************************
1473fcf3ce44SJohn Forte */
1474fcf3ce44SJohn Forte int
extract_attr(isns_attr_t * attr,const isns_tlv_t * tlv,int flag)1475fcf3ce44SJohn Forte extract_attr(
1476fcf3ce44SJohn Forte isns_attr_t *attr,
1477fcf3ce44SJohn Forte const isns_tlv_t *tlv,
1478fcf3ce44SJohn Forte int flag
1479fcf3ce44SJohn Forte )
1480fcf3ce44SJohn Forte {
1481fcf3ce44SJohn Forte int ec = 0;
1482fcf3ce44SJohn Forte
1483fcf3ce44SJohn Forte uint32_t min_len = 4, max_len = 224;
1484fcf3ce44SJohn Forte
1485fcf3ce44SJohn Forte switch (tlv->attr_id) {
1486fcf3ce44SJohn Forte case ISNS_EID_ATTR_ID:
1487fcf3ce44SJohn Forte min_len = 0;
1488fcf3ce44SJohn Forte case ISNS_PORTAL_NAME_ATTR_ID:
1489fcf3ce44SJohn Forte case ISNS_ISCSI_ALIAS_ATTR_ID:
1490fcf3ce44SJohn Forte case ISNS_DD_SET_NAME_ATTR_ID:
1491fcf3ce44SJohn Forte case ISNS_DD_NAME_ATTR_ID:
1492fcf3ce44SJohn Forte max_len = 256;
1493fcf3ce44SJohn Forte case ISNS_ISCSI_NAME_ATTR_ID:
1494fcf3ce44SJohn Forte case ISNS_PG_ISCSI_NAME_ATTR_ID:
1495fcf3ce44SJohn Forte if (tlv->attr_len < min_len || tlv->attr_len > max_len) {
1496fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
1497fcf3ce44SJohn Forte } else {
1498fcf3ce44SJohn Forte attr->tag = tlv->attr_id;
1499fcf3ce44SJohn Forte attr->len = tlv->attr_len;
1500fcf3ce44SJohn Forte attr->value.ptr = (uchar_t *)&(tlv->attr_value[0]);
1501fcf3ce44SJohn Forte }
1502fcf3ce44SJohn Forte break;
1503fcf3ce44SJohn Forte case ISNS_ISCSI_AUTH_METHOD_ATTR_ID:
1504fcf3ce44SJohn Forte attr->tag = tlv->attr_id;
1505fcf3ce44SJohn Forte attr->len = tlv->attr_len;
1506fcf3ce44SJohn Forte attr->value.ptr = (uchar_t *)&(tlv->attr_value[0]);
1507fcf3ce44SJohn Forte break;
1508fcf3ce44SJohn Forte case ISNS_MGMT_IP_ADDR_ATTR_ID:
1509fcf3ce44SJohn Forte case ISNS_PORTAL_IP_ADDR_ATTR_ID:
1510fcf3ce44SJohn Forte case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
1511fcf3ce44SJohn Forte if (tlv->attr_len != 16) {
1512fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
1513fcf3ce44SJohn Forte } else {
1514fcf3ce44SJohn Forte attr->tag = tlv->attr_id;
1515fcf3ce44SJohn Forte attr->len = tlv->attr_len;
1516fcf3ce44SJohn Forte attr->value.ip = (void *)&(tlv->attr_value[0]);
1517fcf3ce44SJohn Forte }
1518fcf3ce44SJohn Forte break;
1519fcf3ce44SJohn Forte case ISNS_ENTITY_PROTOCOL_ATTR_ID:
1520fcf3ce44SJohn Forte case ISNS_VERSION_RANGE_ATTR_ID:
1521fcf3ce44SJohn Forte case ISNS_ENTITY_REG_PERIOD_ATTR_ID:
1522fcf3ce44SJohn Forte /* fall throught */
1523fcf3ce44SJohn Forte case ISNS_PORTAL_PORT_ATTR_ID:
1524fcf3ce44SJohn Forte case ISNS_ESI_INTERVAL_ATTR_ID:
1525fcf3ce44SJohn Forte case ISNS_ESI_PORT_ATTR_ID:
1526fcf3ce44SJohn Forte case ISNS_SCN_PORT_ATTR_ID:
1527fcf3ce44SJohn Forte /* fall throught */
1528fcf3ce44SJohn Forte case ISNS_ISCSI_NODE_TYPE_ATTR_ID:
1529fcf3ce44SJohn Forte /* fall throught */
1530fcf3ce44SJohn Forte case ISNS_PG_PORTAL_PORT_ATTR_ID:
1531fcf3ce44SJohn Forte /* fall throught */
1532fcf3ce44SJohn Forte case ISNS_DD_SET_ID_ATTR_ID:
1533fcf3ce44SJohn Forte case ISNS_DD_SET_STATUS_ATTR_ID:
1534fcf3ce44SJohn Forte /* fall throught */
1535fcf3ce44SJohn Forte case ISNS_DD_ID_ATTR_ID:
1536fcf3ce44SJohn Forte if (tlv->attr_len != 4) {
1537fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
1538fcf3ce44SJohn Forte break;
1539fcf3ce44SJohn Forte }
1540fcf3ce44SJohn Forte case ISNS_PG_TAG_ATTR_ID:
1541fcf3ce44SJohn Forte attr->tag = tlv->attr_id;
1542fcf3ce44SJohn Forte attr->len = tlv->attr_len;
1543fcf3ce44SJohn Forte if (tlv->attr_len == 4) {
1544fcf3ce44SJohn Forte attr->value.ui = ntohl(*(uint32_t *)
1545fcf3ce44SJohn Forte &(tlv->attr_value[0]));
1546fcf3ce44SJohn Forte } else {
1547fcf3ce44SJohn Forte attr->value.ui = 0;
1548fcf3ce44SJohn Forte }
1549fcf3ce44SJohn Forte break;
1550fcf3ce44SJohn Forte case ISNS_ISCSI_SCN_BITMAP_ATTR_ID:
1551fcf3ce44SJohn Forte /* ignore scn bitmap attribute during object registration, */
1552fcf3ce44SJohn Forte /* it is registered by scn_reg message. */
1553fcf3ce44SJohn Forte case ISNS_ENTITY_ISAKMP_P1_ATTR_ID:
1554fcf3ce44SJohn Forte case ISNS_ENTITY_CERT_ATTR_ID:
1555fcf3ce44SJohn Forte case ISNS_PORTAL_SEC_BMP_ATTR_ID:
1556fcf3ce44SJohn Forte case ISNS_PORTAL_ISAKMP_P1_ATTR_ID:
1557fcf3ce44SJohn Forte case ISNS_PORTAL_ISAKMP_P2_ATTR_ID:
1558fcf3ce44SJohn Forte case ISNS_PORTAL_CERT_ATTR_ID:
1559fcf3ce44SJohn Forte break;
1560fcf3ce44SJohn Forte case ISNS_PORTAL_INDEX_ATTR_ID:
1561fcf3ce44SJohn Forte case ISNS_ISCSI_NODE_INDEX_ATTR_ID:
1562fcf3ce44SJohn Forte case ISNS_PG_INDEX_ATTR_ID:
1563fcf3ce44SJohn Forte if (flag == 0) {
1564fcf3ce44SJohn Forte if (tlv->attr_len != 4) {
1565fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
1566fcf3ce44SJohn Forte } else {
1567fcf3ce44SJohn Forte attr->tag = tlv->attr_id;
1568fcf3ce44SJohn Forte attr->len = tlv->attr_len;
1569fcf3ce44SJohn Forte attr->value.ui = ntohl(*(uint32_t *)
1570fcf3ce44SJohn Forte &(tlv->attr_value[0]));
1571fcf3ce44SJohn Forte }
1572fcf3ce44SJohn Forte break;
1573fcf3ce44SJohn Forte }
1574fcf3ce44SJohn Forte case ISNS_ENTITY_INDEX_ATTR_ID:
1575fcf3ce44SJohn Forte case ISNS_TIMESTAMP_ATTR_ID:
1576fcf3ce44SJohn Forte default:
1577fcf3ce44SJohn Forte if (flag == 0) {
1578fcf3ce44SJohn Forte ec = ISNS_RSP_INVALID_QRY;
1579fcf3ce44SJohn Forte } else {
1580fcf3ce44SJohn Forte ec = ISNS_RSP_INVALID_REGIS;
1581fcf3ce44SJohn Forte }
1582fcf3ce44SJohn Forte break;
1583fcf3ce44SJohn Forte }
1584fcf3ce44SJohn Forte
1585fcf3ce44SJohn Forte return (ec);
1586fcf3ce44SJohn Forte }
1587fcf3ce44SJohn Forte
1588fcf3ce44SJohn Forte /*
1589fcf3ce44SJohn Forte * ****************************************************************************
1590fcf3ce44SJohn Forte *
1591fcf3ce44SJohn Forte * copy_attr:
1592fcf3ce44SJohn Forte * copy an attribute from a TLV format data.
1593fcf3ce44SJohn Forte *
1594fcf3ce44SJohn Forte * attr - the attribute.
1595fcf3ce44SJohn Forte * tlv - the TLV format data.
1596fcf3ce44SJohn Forte * return - error code.
1597fcf3ce44SJohn Forte *
1598fcf3ce44SJohn Forte * ****************************************************************************
1599fcf3ce44SJohn Forte */
1600fcf3ce44SJohn Forte static int
copy_attr(isns_attr_t * attr,const isns_tlv_t * tlv)1601fcf3ce44SJohn Forte copy_attr(
1602fcf3ce44SJohn Forte isns_attr_t *attr,
1603fcf3ce44SJohn Forte const isns_tlv_t *tlv
1604fcf3ce44SJohn Forte )
1605fcf3ce44SJohn Forte {
1606fcf3ce44SJohn Forte int ec = 0;
1607fcf3ce44SJohn Forte
1608fcf3ce44SJohn Forte isns_attr_t tmp = { 0 };
1609fcf3ce44SJohn Forte
1610fcf3ce44SJohn Forte /* extract the attribute first */
1611fcf3ce44SJohn Forte ec = extract_attr(&tmp, tlv, 1);
1612fcf3ce44SJohn Forte
1613fcf3ce44SJohn Forte /* assign the attribute */
1614fcf3ce44SJohn Forte if (ec == 0 && tmp.tag != 0) {
1615fcf3ce44SJohn Forte if (assign_attr(attr, &tmp) != 0) {
1616fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
1617fcf3ce44SJohn Forte }
1618fcf3ce44SJohn Forte }
1619fcf3ce44SJohn Forte
1620fcf3ce44SJohn Forte return (ec);
1621fcf3ce44SJohn Forte }
1622fcf3ce44SJohn Forte
1623fcf3ce44SJohn Forte /*
1624fcf3ce44SJohn Forte * ****************************************************************************
1625fcf3ce44SJohn Forte *
1626fcf3ce44SJohn Forte * get_timestamp:
1627fcf3ce44SJohn Forte * get current timestamp.
1628fcf3ce44SJohn Forte *
1629fcf3ce44SJohn Forte * return - current timestamp.
1630fcf3ce44SJohn Forte *
1631fcf3ce44SJohn Forte * ****************************************************************************
1632fcf3ce44SJohn Forte */
1633fcf3ce44SJohn Forte uint32_t
get_timestamp()1634fcf3ce44SJohn Forte get_timestamp(
1635fcf3ce44SJohn Forte )
1636fcf3ce44SJohn Forte {
1637fcf3ce44SJohn Forte uint32_t t;
1638fcf3ce44SJohn Forte int flag;
1639fcf3ce44SJohn Forte
1640fcf3ce44SJohn Forte /* block the scheduler */
1641fcf3ce44SJohn Forte (void) pthread_mutex_lock(&el_mtx);
1642fcf3ce44SJohn Forte
1643fcf3ce44SJohn Forte /* get most current time */
1644fcf3ce44SJohn Forte if (sys_q != NULL) {
1645fcf3ce44SJohn Forte /* need to wakeup idle */
1646fcf3ce44SJohn Forte flag = 1;
1647fcf3ce44SJohn Forte } else {
1648fcf3ce44SJohn Forte flag = 0;
1649fcf3ce44SJohn Forte }
1650fcf3ce44SJohn Forte t = get_stopwatch(flag);
1651fcf3ce44SJohn Forte
1652fcf3ce44SJohn Forte /* unblock it */
1653fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&el_mtx);
1654fcf3ce44SJohn Forte
1655fcf3ce44SJohn Forte return (t);
1656fcf3ce44SJohn Forte }
1657fcf3ce44SJohn Forte
1658fcf3ce44SJohn Forte /*
1659fcf3ce44SJohn Forte * ****************************************************************************
1660fcf3ce44SJohn Forte *
1661fcf3ce44SJohn Forte * get_reg_period:
1662fcf3ce44SJohn Forte * get the longest registration period.
1663fcf3ce44SJohn Forte *
1664fcf3ce44SJohn Forte * return - the longest registration period.
1665fcf3ce44SJohn Forte *
1666fcf3ce44SJohn Forte * ****************************************************************************
1667fcf3ce44SJohn Forte */
1668fcf3ce44SJohn Forte static uint32_t
get_reg_period()1669fcf3ce44SJohn Forte get_reg_period(
1670fcf3ce44SJohn Forte )
1671fcf3ce44SJohn Forte {
1672fcf3ce44SJohn Forte uint32_t t;
1673fcf3ce44SJohn Forte uint32_t period;
1674fcf3ce44SJohn Forte
1675fcf3ce44SJohn Forte /* get most current time */
1676fcf3ce44SJohn Forte t = get_timestamp();
1677fcf3ce44SJohn Forte
1678fcf3ce44SJohn Forte /* just one second before the end of the world */
1679fcf3ce44SJohn Forte period = INFINITY - t - 1;
1680fcf3ce44SJohn Forte
1681fcf3ce44SJohn Forte return (period);
1682fcf3ce44SJohn Forte }
1683fcf3ce44SJohn Forte
1684fcf3ce44SJohn Forte /*
1685fcf3ce44SJohn Forte * ****************************************************************************
1686fcf3ce44SJohn Forte *
1687fcf3ce44SJohn Forte * obj_calloc:
1688fcf3ce44SJohn Forte * allocate memory space for an object.
1689fcf3ce44SJohn Forte *
1690fcf3ce44SJohn Forte * type - the object type.
1691fcf3ce44SJohn Forte * return - pointer of the object being allocated.
1692fcf3ce44SJohn Forte *
1693fcf3ce44SJohn Forte * ****************************************************************************
1694fcf3ce44SJohn Forte */
1695fcf3ce44SJohn Forte isns_obj_t *
obj_calloc(int type)1696fcf3ce44SJohn Forte obj_calloc(
1697fcf3ce44SJohn Forte int type
1698fcf3ce44SJohn Forte )
1699fcf3ce44SJohn Forte {
1700fcf3ce44SJohn Forte isns_obj_t *obj = NULL;
1701fcf3ce44SJohn Forte
1702fcf3ce44SJohn Forte obj = (isns_obj_t *)calloc(1, SIZEOF_OBJ[type]);
1703fcf3ce44SJohn Forte if (obj != NULL) {
1704fcf3ce44SJohn Forte obj->type = type;
1705fcf3ce44SJohn Forte #ifdef DEBUG
1706fcf3ce44SJohn Forte if (verbose_mc) {
1707fcf3ce44SJohn Forte printf("object(%d) allocated\n", type);
1708fcf3ce44SJohn Forte }
1709fcf3ce44SJohn Forte #endif
1710fcf3ce44SJohn Forte }
1711fcf3ce44SJohn Forte
1712fcf3ce44SJohn Forte return (obj);
1713fcf3ce44SJohn Forte }
1714fcf3ce44SJohn Forte
1715fcf3ce44SJohn Forte /*
1716fcf3ce44SJohn Forte * ****************************************************************************
1717fcf3ce44SJohn Forte *
1718fcf3ce44SJohn Forte * make_default_entity:
1719fcf3ce44SJohn Forte * generate a default network entity object.
1720fcf3ce44SJohn Forte *
1721fcf3ce44SJohn Forte * return - pointer of the default network entity object.
1722fcf3ce44SJohn Forte *
1723fcf3ce44SJohn Forte * ****************************************************************************
1724fcf3ce44SJohn Forte */
1725fcf3ce44SJohn Forte isns_obj_t *
make_default_entity()1726fcf3ce44SJohn Forte make_default_entity(
1727fcf3ce44SJohn Forte )
1728fcf3ce44SJohn Forte {
1729fcf3ce44SJohn Forte uint32_t t;
1730fcf3ce44SJohn Forte
1731fcf3ce44SJohn Forte isns_obj_t *obj = obj_calloc(OBJ_ENTITY);
1732fcf3ce44SJohn Forte isns_attr_t *attr;
1733fcf3ce44SJohn Forte if (obj != NULL) {
1734fcf3ce44SJohn Forte int len;
1735fcf3ce44SJohn Forte char *eid = make_unique_name(&len, ISNS_EID_ATTR_ID);
1736fcf3ce44SJohn Forte if (!eid) {
1737fcf3ce44SJohn Forte free(obj);
1738fcf3ce44SJohn Forte return (NULL);
1739fcf3ce44SJohn Forte }
1740fcf3ce44SJohn Forte attr = &obj->attrs[ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID)];
1741fcf3ce44SJohn Forte
1742fcf3ce44SJohn Forte /* set default entity name */
1743fcf3ce44SJohn Forte attr->tag = ISNS_EID_ATTR_ID;
1744fcf3ce44SJohn Forte attr->len = len;
1745fcf3ce44SJohn Forte attr->value.ptr = (uchar_t *)eid;
1746fcf3ce44SJohn Forte
1747fcf3ce44SJohn Forte /* set default registration period */
1748fcf3ce44SJohn Forte attr = &obj->attrs[
1749fcf3ce44SJohn Forte ATTR_INDEX_ENTITY(ISNS_ENTITY_REG_PERIOD_ATTR_ID)];
1750fcf3ce44SJohn Forte if (attr->tag == 0) {
1751fcf3ce44SJohn Forte attr->tag = ISNS_ENTITY_REG_PERIOD_ATTR_ID;
1752fcf3ce44SJohn Forte attr->len = 4;
1753fcf3ce44SJohn Forte t = get_reg_period();
1754fcf3ce44SJohn Forte attr->value.ui = t;
1755fcf3ce44SJohn Forte }
1756fcf3ce44SJohn Forte }
1757fcf3ce44SJohn Forte
1758fcf3ce44SJohn Forte return (obj);
1759fcf3ce44SJohn Forte }
1760fcf3ce44SJohn Forte
1761fcf3ce44SJohn Forte /*
1762fcf3ce44SJohn Forte * ****************************************************************************
1763fcf3ce44SJohn Forte *
1764fcf3ce44SJohn Forte * make_default_pg:
1765fcf3ce44SJohn Forte * generate a default portal group object.
1766fcf3ce44SJohn Forte *
1767fcf3ce44SJohn Forte * iscsi - the iscsi storage node object.
1768fcf3ce44SJohn Forte * portal - the portal object.
1769fcf3ce44SJohn Forte * return - pointer of the default portal group object.
1770fcf3ce44SJohn Forte *
1771fcf3ce44SJohn Forte * ****************************************************************************
1772fcf3ce44SJohn Forte */
1773fcf3ce44SJohn Forte static isns_obj_t *
make_default_pg(const isns_obj_t * p1,const isns_obj_t * p2)1774fcf3ce44SJohn Forte make_default_pg(
1775fcf3ce44SJohn Forte const isns_obj_t *p1,
1776fcf3ce44SJohn Forte const isns_obj_t *p2
1777fcf3ce44SJohn Forte )
1778fcf3ce44SJohn Forte {
1779fcf3ce44SJohn Forte const isns_obj_t *iscsi, *portal;
1780fcf3ce44SJohn Forte const isns_attr_t *name, *addr, *port;
1781fcf3ce44SJohn Forte isns_obj_t *pg;
1782fcf3ce44SJohn Forte
1783fcf3ce44SJohn Forte uchar_t *pg_name;
1784fcf3ce44SJohn Forte in6_addr_t *pg_addr;
1785fcf3ce44SJohn Forte
1786fcf3ce44SJohn Forte isns_attr_t *attr;
1787fcf3ce44SJohn Forte
1788fcf3ce44SJohn Forte uint32_t *refp;
1789fcf3ce44SJohn Forte
1790fcf3ce44SJohn Forte if (p1->type == OBJ_ISCSI) {
1791fcf3ce44SJohn Forte iscsi = p1;
1792fcf3ce44SJohn Forte portal = p2;
1793fcf3ce44SJohn Forte } else {
1794fcf3ce44SJohn Forte iscsi = p2;
1795fcf3ce44SJohn Forte portal = p1;
1796fcf3ce44SJohn Forte }
1797fcf3ce44SJohn Forte name = &iscsi->attrs[ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID)];
1798fcf3ce44SJohn Forte addr = &portal->attrs[ATTR_INDEX_PORTAL(ISNS_PORTAL_IP_ADDR_ATTR_ID)];
1799fcf3ce44SJohn Forte port = &portal->attrs[ATTR_INDEX_PORTAL(ISNS_PORTAL_PORT_ATTR_ID)];
1800fcf3ce44SJohn Forte
1801fcf3ce44SJohn Forte pg = obj_calloc(OBJ_PG);
1802fcf3ce44SJohn Forte pg_name = (uchar_t *)malloc(name->len);
1803fcf3ce44SJohn Forte pg_addr = (in6_addr_t *)malloc(addr->len);
1804fcf3ce44SJohn Forte if (pg != NULL && pg_name != NULL && pg_addr != NULL) {
1805fcf3ce44SJohn Forte (void) strcpy((char *)pg_name, (char *)name->value.ptr);
1806fcf3ce44SJohn Forte attr = &pg->attrs[ATTR_INDEX_PG(ISNS_PG_ISCSI_NAME_ATTR_ID)];
1807fcf3ce44SJohn Forte attr->tag = ISNS_PG_ISCSI_NAME_ATTR_ID;
1808fcf3ce44SJohn Forte attr->len = name->len;
1809fcf3ce44SJohn Forte attr->value.ptr = pg_name;
1810fcf3ce44SJohn Forte
1811fcf3ce44SJohn Forte (void) memcpy((void *)pg_addr,
1812fcf3ce44SJohn Forte (void *)addr->value.ip, addr->len);
1813fcf3ce44SJohn Forte attr = &pg->attrs[ATTR_INDEX_PG(
1814fcf3ce44SJohn Forte ISNS_PG_PORTAL_IP_ADDR_ATTR_ID)];
1815fcf3ce44SJohn Forte attr->tag = ISNS_PG_PORTAL_IP_ADDR_ATTR_ID;
1816fcf3ce44SJohn Forte attr->len = addr->len;
1817fcf3ce44SJohn Forte attr->value.ip = pg_addr;
1818fcf3ce44SJohn Forte
1819fcf3ce44SJohn Forte attr = &pg->attrs[ATTR_INDEX_PG(
1820fcf3ce44SJohn Forte ISNS_PG_PORTAL_PORT_ATTR_ID)];
1821fcf3ce44SJohn Forte attr->tag = ISNS_PG_PORTAL_PORT_ATTR_ID;
1822fcf3ce44SJohn Forte attr->len = port->len;
1823fcf3ce44SJohn Forte attr->value.ui = port->value.ui;
1824fcf3ce44SJohn Forte
1825fcf3ce44SJohn Forte attr = &pg->attrs[ATTR_INDEX_PG(
1826fcf3ce44SJohn Forte ISNS_PG_TAG_ATTR_ID)];
1827fcf3ce44SJohn Forte attr->tag = ISNS_PG_TAG_ATTR_ID;
1828fcf3ce44SJohn Forte attr->len = 4;
1829fcf3ce44SJohn Forte attr->value.ui = ISNS_DEFAULT_PGT;
1830fcf3ce44SJohn Forte
1831fcf3ce44SJohn Forte refp = get_ref_p(pg, OBJ_ISCSI);
1832fcf3ce44SJohn Forte *refp = get_obj_uid(iscsi);
1833fcf3ce44SJohn Forte
1834fcf3ce44SJohn Forte refp = get_ref_p(pg, OBJ_PORTAL);
1835fcf3ce44SJohn Forte *refp = get_obj_uid(portal);
1836fcf3ce44SJohn Forte
1837fcf3ce44SJohn Forte (void) set_parent_obj(pg, get_parent_uid(iscsi));
1838fcf3ce44SJohn Forte } else {
1839fcf3ce44SJohn Forte free(pg);
1840fcf3ce44SJohn Forte free(pg_name);
1841fcf3ce44SJohn Forte free(pg_addr);
1842fcf3ce44SJohn Forte pg = NULL;
1843fcf3ce44SJohn Forte }
1844fcf3ce44SJohn Forte
1845fcf3ce44SJohn Forte return (pg);
1846fcf3ce44SJohn Forte }
1847fcf3ce44SJohn Forte
1848fcf3ce44SJohn Forte /*
1849fcf3ce44SJohn Forte * ****************************************************************************
1850fcf3ce44SJohn Forte *
1851fcf3ce44SJohn Forte * reg_get_entity:
1852fcf3ce44SJohn Forte * parse the Operating Attributes of the DevAttrReg message and
1853fcf3ce44SJohn Forte * create the Network Entity object if it has one.
1854fcf3ce44SJohn Forte *
1855fcf3ce44SJohn Forte * p - the pointer of the object for returning.
1856fcf3ce44SJohn Forte * op - the operating attributes.
1857fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
1858fcf3ce44SJohn Forte * return - error code.
1859fcf3ce44SJohn Forte *
1860fcf3ce44SJohn Forte * ****************************************************************************
1861fcf3ce44SJohn Forte */
1862fcf3ce44SJohn Forte int
reg_get_entity(isns_obj_t ** p,isns_tlv_t ** op,uint16_t * op_len)1863fcf3ce44SJohn Forte reg_get_entity(
1864fcf3ce44SJohn Forte isns_obj_t **p,
1865fcf3ce44SJohn Forte isns_tlv_t **op,
1866fcf3ce44SJohn Forte uint16_t *op_len
1867fcf3ce44SJohn Forte )
1868fcf3ce44SJohn Forte {
1869fcf3ce44SJohn Forte int ec = 0;
1870fcf3ce44SJohn Forte
1871fcf3ce44SJohn Forte isns_tlv_t *tmp;
1872fcf3ce44SJohn Forte uint16_t tmp_len;
1873fcf3ce44SJohn Forte isns_attr_t *attr;
1874fcf3ce44SJohn Forte
1875fcf3ce44SJohn Forte isns_obj_t *entity = NULL;
1876fcf3ce44SJohn Forte
1877fcf3ce44SJohn Forte tmp = *op;
1878fcf3ce44SJohn Forte tmp_len = *op_len;
1879fcf3ce44SJohn Forte
1880fcf3ce44SJohn Forte /* parse the entity object */
1881fcf3ce44SJohn Forte if (tmp_len >= 8 && IS_ENTITY_KEY(tmp->attr_id)) {
1882fcf3ce44SJohn Forte entity = obj_calloc(OBJ_ENTITY);
1883fcf3ce44SJohn Forte if (entity != NULL) {
1884fcf3ce44SJohn Forte do {
1885fcf3ce44SJohn Forte attr = &entity->attrs[
1886fcf3ce44SJohn Forte ATTR_INDEX_ENTITY(tmp->attr_id)];
1887fcf3ce44SJohn Forte ec = copy_attr(attr, tmp);
1888fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
1889fcf3ce44SJohn Forte } while (ec == 0 &&
1890fcf3ce44SJohn Forte tmp_len >= 8 &&
1891fcf3ce44SJohn Forte IS_ENTITY_ATTR(tmp->attr_id));
1892fcf3ce44SJohn Forte } else {
1893fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
1894fcf3ce44SJohn Forte }
1895fcf3ce44SJohn Forte
1896fcf3ce44SJohn Forte if (ec == 0) {
1897fcf3ce44SJohn Forte /* set default registration period */
1898fcf3ce44SJohn Forte attr = &entity->attrs[
1899fcf3ce44SJohn Forte ATTR_INDEX_ENTITY(ISNS_ENTITY_REG_PERIOD_ATTR_ID)];
1900fcf3ce44SJohn Forte if (attr->tag == 0) {
1901fcf3ce44SJohn Forte attr->tag = ISNS_ENTITY_REG_PERIOD_ATTR_ID;
1902fcf3ce44SJohn Forte attr->len = 4;
1903fcf3ce44SJohn Forte attr->value.ui = get_reg_period();
1904fcf3ce44SJohn Forte }
1905fcf3ce44SJohn Forte } else if (entity != NULL) {
1906fcf3ce44SJohn Forte free(entity);
1907fcf3ce44SJohn Forte entity = NULL;
1908fcf3ce44SJohn Forte }
1909fcf3ce44SJohn Forte }
1910fcf3ce44SJohn Forte
1911fcf3ce44SJohn Forte *p = entity;
1912fcf3ce44SJohn Forte *op = tmp;
1913fcf3ce44SJohn Forte *op_len = tmp_len;
1914fcf3ce44SJohn Forte
1915fcf3ce44SJohn Forte return (ec);
1916fcf3ce44SJohn Forte }
1917fcf3ce44SJohn Forte
1918fcf3ce44SJohn Forte /*
1919fcf3ce44SJohn Forte * ****************************************************************************
1920fcf3ce44SJohn Forte *
1921fcf3ce44SJohn Forte * reg_get_iscsi:
1922fcf3ce44SJohn Forte * parse the Operating Attributes of the DevAttrReg message and
1923fcf3ce44SJohn Forte * create an iSCSI Storage Node object.
1924fcf3ce44SJohn Forte *
1925fcf3ce44SJohn Forte * p - the pointer of the object for returning.
1926fcf3ce44SJohn Forte * pg_key1 - the pointer of iscsi storage node name for returning.
1927fcf3ce44SJohn Forte * op - the operating attributes.
1928fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
1929fcf3ce44SJohn Forte * return - error code.
1930fcf3ce44SJohn Forte *
1931fcf3ce44SJohn Forte * ****************************************************************************
1932fcf3ce44SJohn Forte */
1933fcf3ce44SJohn Forte static int
reg_get_iscsi(isns_obj_t ** p,isns_attr_t * pg_key1,isns_tlv_t ** op,uint16_t * op_len)1934fcf3ce44SJohn Forte reg_get_iscsi(
1935fcf3ce44SJohn Forte isns_obj_t **p,
1936fcf3ce44SJohn Forte isns_attr_t *pg_key1,
1937fcf3ce44SJohn Forte isns_tlv_t **op,
1938fcf3ce44SJohn Forte uint16_t *op_len
1939fcf3ce44SJohn Forte )
1940fcf3ce44SJohn Forte {
1941fcf3ce44SJohn Forte int ec = 0;
1942fcf3ce44SJohn Forte
1943fcf3ce44SJohn Forte isns_tlv_t *tmp;
1944fcf3ce44SJohn Forte uint16_t tmp_len;
1945fcf3ce44SJohn Forte isns_attr_t *attr;
1946fcf3ce44SJohn Forte
1947fcf3ce44SJohn Forte isns_obj_t *obj = NULL;
1948fcf3ce44SJohn Forte
1949fcf3ce44SJohn Forte tmp = *op;
1950fcf3ce44SJohn Forte tmp_len = *op_len;
1951fcf3ce44SJohn Forte
1952fcf3ce44SJohn Forte /* keep the iscsi storage node name for */
1953fcf3ce44SJohn Forte /* parsing a pg object which is immediately */
1954fcf3ce44SJohn Forte /* followed with a PGT by the iscsi storage node */
1955fcf3ce44SJohn Forte pg_key1->tag = PG_KEY1;
1956fcf3ce44SJohn Forte pg_key1->len = tmp->attr_len;
1957fcf3ce44SJohn Forte pg_key1->value.ptr = (uchar_t *)&tmp->attr_value[0];
1958fcf3ce44SJohn Forte
1959fcf3ce44SJohn Forte /* parse one iscsi storage node object */
1960fcf3ce44SJohn Forte obj = obj_calloc(OBJ_ISCSI);
1961fcf3ce44SJohn Forte if (obj != NULL) {
1962fcf3ce44SJohn Forte /* parse key & non-key attributes */
1963fcf3ce44SJohn Forte do {
1964fcf3ce44SJohn Forte attr = &obj->attrs[
1965fcf3ce44SJohn Forte ATTR_INDEX_ISCSI(tmp->attr_id)];
1966fcf3ce44SJohn Forte ec = copy_attr(attr, tmp);
1967fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
1968fcf3ce44SJohn Forte } while (ec == 0 &&
1969fcf3ce44SJohn Forte tmp_len >= 8 &&
1970fcf3ce44SJohn Forte IS_ISCSI_ATTR(tmp->attr_id));
1971fcf3ce44SJohn Forte } else {
1972fcf3ce44SJohn Forte /* no memory */
1973fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
1974fcf3ce44SJohn Forte }
1975fcf3ce44SJohn Forte
1976fcf3ce44SJohn Forte *p = obj;
1977fcf3ce44SJohn Forte *op = tmp;
1978fcf3ce44SJohn Forte *op_len = tmp_len;
1979fcf3ce44SJohn Forte
1980fcf3ce44SJohn Forte return (ec);
1981fcf3ce44SJohn Forte }
1982fcf3ce44SJohn Forte
1983fcf3ce44SJohn Forte /*
1984fcf3ce44SJohn Forte * ****************************************************************************
1985fcf3ce44SJohn Forte *
1986fcf3ce44SJohn Forte * reg_get_portal:
1987fcf3ce44SJohn Forte * parse the Operating Attributes of the DevAttrReg message and
1988fcf3ce44SJohn Forte * create a Portal object.
1989fcf3ce44SJohn Forte *
1990fcf3ce44SJohn Forte * p - the pointer of the object for returning.
1991fcf3ce44SJohn Forte * pg_key1 - the pointer of portal ip addr for returning.
1992fcf3ce44SJohn Forte * pg_key2 - the pointer of portal port for returning.
1993fcf3ce44SJohn Forte * op - the operating attributes.
1994fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
1995fcf3ce44SJohn Forte * return - error code.
1996fcf3ce44SJohn Forte *
1997fcf3ce44SJohn Forte * ****************************************************************************
1998fcf3ce44SJohn Forte */
1999fcf3ce44SJohn Forte static int
reg_get_portal(isns_obj_t ** p,isns_attr_t * pg_key1,isns_attr_t * pg_key2,isns_tlv_t ** op,uint16_t * op_len)2000fcf3ce44SJohn Forte reg_get_portal(
2001fcf3ce44SJohn Forte isns_obj_t **p,
2002fcf3ce44SJohn Forte isns_attr_t *pg_key1,
2003fcf3ce44SJohn Forte isns_attr_t *pg_key2,
2004fcf3ce44SJohn Forte isns_tlv_t **op,
2005fcf3ce44SJohn Forte uint16_t *op_len
2006fcf3ce44SJohn Forte )
2007fcf3ce44SJohn Forte {
2008fcf3ce44SJohn Forte int ec = 0;
2009fcf3ce44SJohn Forte
2010fcf3ce44SJohn Forte isns_tlv_t *tmp;
2011fcf3ce44SJohn Forte uint16_t tmp_len;
2012fcf3ce44SJohn Forte isns_attr_t *attr;
2013fcf3ce44SJohn Forte
2014fcf3ce44SJohn Forte isns_obj_t *obj = NULL;
2015fcf3ce44SJohn Forte
2016fcf3ce44SJohn Forte isns_tlv_t *ip;
2017fcf3ce44SJohn Forte
2018fcf3ce44SJohn Forte tmp = *op;
2019fcf3ce44SJohn Forte tmp_len = *op_len;
2020fcf3ce44SJohn Forte
2021fcf3ce44SJohn Forte /* keep the portal ip addr */
2022fcf3ce44SJohn Forte pg_key1->tag = PG_KEY2;
2023fcf3ce44SJohn Forte pg_key1->len = tmp->attr_len;
2024fcf3ce44SJohn Forte pg_key1->value.ip = (void *)&tmp->attr_value[0];
2025fcf3ce44SJohn Forte ip = tmp;
2026fcf3ce44SJohn Forte
2027fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
2028fcf3ce44SJohn Forte if (tmp_len > 8 &&
2029fcf3ce44SJohn Forte tmp->attr_id == PORTAL_KEY2 &&
2030fcf3ce44SJohn Forte tmp->attr_len == 4) {
2031fcf3ce44SJohn Forte /* keep the portal port */
2032fcf3ce44SJohn Forte pg_key2->tag = PG_KEY3;
2033fcf3ce44SJohn Forte pg_key2->len = tmp->attr_len;
2034fcf3ce44SJohn Forte pg_key2->value.ui = ntohl(*(uint32_t *)&tmp->attr_value[0]);
2035fcf3ce44SJohn Forte
2036fcf3ce44SJohn Forte /* parse one portal object */
2037fcf3ce44SJohn Forte obj = obj_calloc(OBJ_PORTAL);
2038fcf3ce44SJohn Forte if (obj != NULL) {
2039fcf3ce44SJohn Forte /* copy ip addr attribute */
2040fcf3ce44SJohn Forte attr = &obj->attrs[
2041fcf3ce44SJohn Forte ATTR_INDEX_PORTAL(ip->attr_id)];
2042fcf3ce44SJohn Forte ec = copy_attr(attr, ip);
2043fcf3ce44SJohn Forte /* copy port attribute */
2044fcf3ce44SJohn Forte if (ec == 0) {
2045fcf3ce44SJohn Forte attr = &obj->attrs[
2046fcf3ce44SJohn Forte ATTR_INDEX_PORTAL(tmp->attr_id)];
2047fcf3ce44SJohn Forte ec = copy_attr(attr, tmp);
2048fcf3ce44SJohn Forte }
2049fcf3ce44SJohn Forte /* parse non-key attributes */
2050fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
2051fcf3ce44SJohn Forte while (ec == 0 &&
2052fcf3ce44SJohn Forte tmp_len >= 8 &&
2053fcf3ce44SJohn Forte IS_PORTAL_ATTR(tmp->attr_id)) {
2054fcf3ce44SJohn Forte attr = &obj->attrs[
2055fcf3ce44SJohn Forte ATTR_INDEX_PORTAL(
2056fcf3ce44SJohn Forte tmp->attr_id)];
2057fcf3ce44SJohn Forte ec = copy_attr(attr, tmp);
2058fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
2059fcf3ce44SJohn Forte }
2060fcf3ce44SJohn Forte } else {
2061fcf3ce44SJohn Forte /* no memory */
2062fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
2063fcf3ce44SJohn Forte }
2064fcf3ce44SJohn Forte } else {
2065fcf3ce44SJohn Forte /* ip address is not followed by port */
2066fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
2067fcf3ce44SJohn Forte }
2068fcf3ce44SJohn Forte
2069fcf3ce44SJohn Forte *p = obj;
2070fcf3ce44SJohn Forte *op = tmp;
2071fcf3ce44SJohn Forte *op_len = tmp_len;
2072fcf3ce44SJohn Forte
2073fcf3ce44SJohn Forte return (ec);
2074fcf3ce44SJohn Forte }
2075fcf3ce44SJohn Forte
2076fcf3ce44SJohn Forte /*
2077fcf3ce44SJohn Forte * ****************************************************************************
2078fcf3ce44SJohn Forte *
2079fcf3ce44SJohn Forte * reg_get_pg:
2080fcf3ce44SJohn Forte * parse the Operating Attributes of the DevAttrReg message and
2081fcf3ce44SJohn Forte * create a Portal Group object.
2082fcf3ce44SJohn Forte *
2083fcf3ce44SJohn Forte * p - the pointer of the object for returning.
2084fcf3ce44SJohn Forte * op - the operating attributes.
2085fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
2086fcf3ce44SJohn Forte * return - error code.
2087fcf3ce44SJohn Forte *
2088fcf3ce44SJohn Forte * ****************************************************************************
2089fcf3ce44SJohn Forte */
2090fcf3ce44SJohn Forte static int
reg_get_pg(isns_obj_t ** p,isns_tlv_t ** op,uint16_t * op_len)2091fcf3ce44SJohn Forte reg_get_pg(
2092fcf3ce44SJohn Forte isns_obj_t **p,
2093fcf3ce44SJohn Forte isns_tlv_t **op,
2094fcf3ce44SJohn Forte uint16_t *op_len
2095fcf3ce44SJohn Forte )
2096fcf3ce44SJohn Forte {
2097fcf3ce44SJohn Forte int ec = 0;
2098fcf3ce44SJohn Forte
2099fcf3ce44SJohn Forte isns_tlv_t *tmp;
2100fcf3ce44SJohn Forte uint16_t tmp_len;
2101fcf3ce44SJohn Forte isns_attr_t *attr;
2102fcf3ce44SJohn Forte
2103fcf3ce44SJohn Forte isns_obj_t *obj = NULL;
2104fcf3ce44SJohn Forte
2105fcf3ce44SJohn Forte tmp = *op;
2106fcf3ce44SJohn Forte tmp_len = *op_len;
2107fcf3ce44SJohn Forte
2108fcf3ce44SJohn Forte /* parse a complete pg object */
2109fcf3ce44SJohn Forte obj = obj_calloc(OBJ_PG);
2110fcf3ce44SJohn Forte if (obj != NULL) {
2111fcf3ce44SJohn Forte /* parse attributes */
2112fcf3ce44SJohn Forte do {
2113fcf3ce44SJohn Forte attr = &obj->attrs[
2114fcf3ce44SJohn Forte ATTR_INDEX_PG(tmp->attr_id)];
2115fcf3ce44SJohn Forte ec = copy_attr(attr, tmp);
2116fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
2117fcf3ce44SJohn Forte } while (ec == 0 &&
2118fcf3ce44SJohn Forte tmp_len >= 8 &&
2119fcf3ce44SJohn Forte IS_PG_ATTR(tmp->attr_id));
2120fcf3ce44SJohn Forte } else {
2121fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
2122fcf3ce44SJohn Forte }
2123fcf3ce44SJohn Forte
2124fcf3ce44SJohn Forte *p = obj;
2125fcf3ce44SJohn Forte *op = tmp;
2126fcf3ce44SJohn Forte *op_len = tmp_len;
2127fcf3ce44SJohn Forte
2128fcf3ce44SJohn Forte return (ec);
2129fcf3ce44SJohn Forte }
2130fcf3ce44SJohn Forte
2131fcf3ce44SJohn Forte /*
2132fcf3ce44SJohn Forte * ****************************************************************************
2133fcf3ce44SJohn Forte *
2134fcf3ce44SJohn Forte * reg_get_pg1:
2135fcf3ce44SJohn Forte * parse the Operating Attributes of the DevAttrReg message and
2136fcf3ce44SJohn Forte * create a Portal Group object which is followed to a Portal object.
2137fcf3ce44SJohn Forte *
2138fcf3ce44SJohn Forte * p - the pointer of the object for returning.
2139fcf3ce44SJohn Forte * pgt - the size-3 array of pointers which have the pg portal ip addr, port
2140fcf3ce44SJohn Forte * and the pg tag attributes.
2141fcf3ce44SJohn Forte * op - the operating attributes.
2142fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
2143fcf3ce44SJohn Forte * return - error code.
2144fcf3ce44SJohn Forte *
2145fcf3ce44SJohn Forte * ****************************************************************************
2146fcf3ce44SJohn Forte */
2147fcf3ce44SJohn Forte static int
reg_get_pg1(isns_obj_t ** p,isns_attr_t const * pgt,isns_tlv_t ** op,uint16_t * op_len)2148fcf3ce44SJohn Forte reg_get_pg1(
2149fcf3ce44SJohn Forte isns_obj_t **p,
2150fcf3ce44SJohn Forte isns_attr_t const *pgt,
2151fcf3ce44SJohn Forte isns_tlv_t **op,
2152fcf3ce44SJohn Forte uint16_t *op_len
2153fcf3ce44SJohn Forte )
2154fcf3ce44SJohn Forte {
2155fcf3ce44SJohn Forte int ec = 0;
2156fcf3ce44SJohn Forte
2157fcf3ce44SJohn Forte isns_tlv_t *tmp;
2158fcf3ce44SJohn Forte uint16_t tmp_len;
2159fcf3ce44SJohn Forte isns_attr_t *attr;
2160fcf3ce44SJohn Forte
2161fcf3ce44SJohn Forte isns_obj_t *obj = NULL;
2162fcf3ce44SJohn Forte int i = 0;
2163fcf3ce44SJohn Forte
2164fcf3ce44SJohn Forte tmp = *op;
2165fcf3ce44SJohn Forte tmp_len = *op_len;
2166fcf3ce44SJohn Forte
2167fcf3ce44SJohn Forte if (pgt[0].tag == PG_KEY2 &&
2168fcf3ce44SJohn Forte pgt[1].tag == PG_KEY3) {
2169fcf3ce44SJohn Forte /* the pg iscsi storage node name is */
2170fcf3ce44SJohn Forte /* followed to a portal group tag */
2171fcf3ce44SJohn Forte obj = obj_calloc(OBJ_PG);
2172fcf3ce44SJohn Forte if (obj != NULL) {
2173fcf3ce44SJohn Forte /* copy pg iscsi storage node name */
2174fcf3ce44SJohn Forte attr = &obj->attrs[
2175fcf3ce44SJohn Forte ATTR_INDEX_PG(tmp->attr_id)];
2176fcf3ce44SJohn Forte ec = copy_attr(attr, tmp);
2177fcf3ce44SJohn Forte /* copy pg ip addr, pg port & pgt */
2178fcf3ce44SJohn Forte while (ec == 0 && i < 3) {
2179fcf3ce44SJohn Forte attr = &obj->attrs[
2180fcf3ce44SJohn Forte ATTR_INDEX_PG(pgt[i].tag)];
2181fcf3ce44SJohn Forte ec = assign_attr(attr, &pgt[i]);
2182fcf3ce44SJohn Forte i ++;
2183fcf3ce44SJohn Forte }
2184fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
2185fcf3ce44SJohn Forte } else {
2186fcf3ce44SJohn Forte /* no memory */
2187fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
2188fcf3ce44SJohn Forte }
2189fcf3ce44SJohn Forte } else {
2190fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
2191fcf3ce44SJohn Forte }
2192fcf3ce44SJohn Forte
2193fcf3ce44SJohn Forte *p = obj;
2194fcf3ce44SJohn Forte *op = tmp;
2195fcf3ce44SJohn Forte *op_len = tmp_len;
2196fcf3ce44SJohn Forte
2197fcf3ce44SJohn Forte return (ec);
2198fcf3ce44SJohn Forte }
2199fcf3ce44SJohn Forte
2200fcf3ce44SJohn Forte /*
2201fcf3ce44SJohn Forte * ****************************************************************************
2202fcf3ce44SJohn Forte *
2203fcf3ce44SJohn Forte * reg_get_pg2:
2204fcf3ce44SJohn Forte * parse the Operating Attributes of the DevAttrReg message and
2205fcf3ce44SJohn Forte * create a Portal Group object which is followed to a iSCSI
2206fcf3ce44SJohn Forte * Storage Node object.
2207fcf3ce44SJohn Forte *
2208fcf3ce44SJohn Forte * p - the pointer of the object for returning.
2209fcf3ce44SJohn Forte * pgt - the size-3 array of pointers which have the pg iscsi storage
2210fcf3ce44SJohn Forte * node name and the pg tag attributes.
2211fcf3ce44SJohn Forte * op - the operating attributes.
2212fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
2213fcf3ce44SJohn Forte * return - error code.
2214fcf3ce44SJohn Forte *
2215fcf3ce44SJohn Forte * ****************************************************************************
2216fcf3ce44SJohn Forte */
2217fcf3ce44SJohn Forte static int
reg_get_pg2(isns_obj_t ** p,isns_attr_t const * pgt,isns_tlv_t ** op,uint16_t * op_len)2218fcf3ce44SJohn Forte reg_get_pg2(
2219fcf3ce44SJohn Forte isns_obj_t **p,
2220fcf3ce44SJohn Forte isns_attr_t const *pgt,
2221fcf3ce44SJohn Forte isns_tlv_t **op,
2222fcf3ce44SJohn Forte uint16_t *op_len
2223fcf3ce44SJohn Forte )
2224fcf3ce44SJohn Forte {
2225fcf3ce44SJohn Forte int ec = 0;
2226fcf3ce44SJohn Forte
2227fcf3ce44SJohn Forte isns_tlv_t *tmp;
2228fcf3ce44SJohn Forte uint16_t tmp_len;
2229fcf3ce44SJohn Forte isns_attr_t *attr;
2230fcf3ce44SJohn Forte
2231fcf3ce44SJohn Forte isns_obj_t *obj = NULL;
2232fcf3ce44SJohn Forte int i = 0;
2233fcf3ce44SJohn Forte
2234fcf3ce44SJohn Forte isns_tlv_t *ip;
2235fcf3ce44SJohn Forte
2236fcf3ce44SJohn Forte tmp = *op;
2237fcf3ce44SJohn Forte tmp_len = *op_len;
2238fcf3ce44SJohn Forte
2239fcf3ce44SJohn Forte /* keep ip address */
2240fcf3ce44SJohn Forte ip = tmp;
2241fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
2242fcf3ce44SJohn Forte
2243fcf3ce44SJohn Forte if (tmp_len > 8 &&
2244fcf3ce44SJohn Forte /* expect pg portal port */
2245fcf3ce44SJohn Forte tmp->attr_id == PG_KEY3 &&
2246fcf3ce44SJohn Forte tmp->attr_len == 4 &&
2247fcf3ce44SJohn Forte /* expect pg tag */
2248fcf3ce44SJohn Forte pgt[2].tag == PG_PGT &&
2249fcf3ce44SJohn Forte /* expect pg iscsi storage node name only */
2250fcf3ce44SJohn Forte pgt[1].tag == 0 &&
2251fcf3ce44SJohn Forte pgt[0].tag == PG_KEY1) {
2252fcf3ce44SJohn Forte /* the pg portal ip addr & port is followed */
2253fcf3ce44SJohn Forte /* to a pg tag and we have the iscsi storage */
2254fcf3ce44SJohn Forte /* node parsed previously */
2255fcf3ce44SJohn Forte obj = obj_calloc(OBJ_PG);
2256fcf3ce44SJohn Forte if (obj != NULL) {
2257fcf3ce44SJohn Forte /* copy the pg ip addr */
2258fcf3ce44SJohn Forte attr = &obj->attrs[
2259fcf3ce44SJohn Forte ATTR_INDEX_PG(ip->attr_id)];
2260fcf3ce44SJohn Forte ec = copy_attr(attr, ip);
2261fcf3ce44SJohn Forte /* copy the pg port */
2262fcf3ce44SJohn Forte if (ec == 0) {
2263fcf3ce44SJohn Forte attr = &obj->attrs[
2264fcf3ce44SJohn Forte ATTR_INDEX_PG(tmp->attr_id)];
2265fcf3ce44SJohn Forte ec = copy_attr(attr, tmp);
2266fcf3ce44SJohn Forte }
2267fcf3ce44SJohn Forte /* copy pg iscsi storage node name & pgt */
2268fcf3ce44SJohn Forte while (ec == 0 && i < 3) {
2269fcf3ce44SJohn Forte attr = &obj->attrs[
2270fcf3ce44SJohn Forte ATTR_INDEX_PG(pgt[i].tag)];
2271fcf3ce44SJohn Forte ec = assign_attr(attr, &pgt[i]);
2272fcf3ce44SJohn Forte i += 2;
2273fcf3ce44SJohn Forte }
2274fcf3ce44SJohn Forte NEXT_TLV(tmp, tmp_len);
2275fcf3ce44SJohn Forte } else {
2276fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
2277fcf3ce44SJohn Forte }
2278fcf3ce44SJohn Forte } else {
2279fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
2280fcf3ce44SJohn Forte }
2281fcf3ce44SJohn Forte
2282fcf3ce44SJohn Forte *p = obj;
2283fcf3ce44SJohn Forte *op = tmp;
2284fcf3ce44SJohn Forte *op_len = tmp_len;
2285fcf3ce44SJohn Forte
2286fcf3ce44SJohn Forte return (ec);
2287fcf3ce44SJohn Forte }
2288fcf3ce44SJohn Forte
2289fcf3ce44SJohn Forte /*
2290fcf3ce44SJohn Forte * ****************************************************************************
2291fcf3ce44SJohn Forte *
2292fcf3ce44SJohn Forte * reg_get_obj:
2293fcf3ce44SJohn Forte * parse and create one object from the rest of Operating Attributes
2294fcf3ce44SJohn Forte * of the DevAttrReg message, the object can be iSCSI Storage Node,
2295fcf3ce44SJohn Forte * Portal or Portal Group.
2296fcf3ce44SJohn Forte *
2297fcf3ce44SJohn Forte * p - the pointer of the object for returning.
2298fcf3ce44SJohn Forte * pgt - an attribute array with size 3, the elements are:
2299fcf3ce44SJohn Forte * 0: the first pg key attribute, it is either the name of an
2300fcf3ce44SJohn Forte * iscsi storage node object or the ip addr of a portal object.
2301fcf3ce44SJohn Forte * 1: the second pg key attribute, i.e. the portal port.
2302fcf3ce44SJohn Forte * 2: the portal group tag attribute.
2303fcf3ce44SJohn Forte * op - the operating attributes.
2304fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
2305fcf3ce44SJohn Forte * return - error code.
2306fcf3ce44SJohn Forte *
2307fcf3ce44SJohn Forte * ****************************************************************************
2308fcf3ce44SJohn Forte */
2309fcf3ce44SJohn Forte int
reg_get_obj(isns_obj_t ** p,isns_attr_t * pgt,isns_tlv_t ** op,uint16_t * op_len)2310fcf3ce44SJohn Forte reg_get_obj(
2311fcf3ce44SJohn Forte isns_obj_t **p,
2312fcf3ce44SJohn Forte isns_attr_t *pgt,
2313fcf3ce44SJohn Forte isns_tlv_t **op,
2314fcf3ce44SJohn Forte uint16_t *op_len
2315fcf3ce44SJohn Forte )
2316fcf3ce44SJohn Forte {
2317fcf3ce44SJohn Forte int ec = 0;
2318fcf3ce44SJohn Forte
2319fcf3ce44SJohn Forte int derefd = 0;
2320fcf3ce44SJohn Forte
2321fcf3ce44SJohn Forte uint32_t pg_tag;
2322fcf3ce44SJohn Forte
2323fcf3ce44SJohn Forte if (*op_len == 0) {
2324fcf3ce44SJohn Forte *p = NULL;
2325fcf3ce44SJohn Forte return (0);
2326fcf3ce44SJohn Forte }
2327fcf3ce44SJohn Forte
2328fcf3ce44SJohn Forte switch ((*op)->attr_id) {
2329fcf3ce44SJohn Forte case ISCSI_KEY:
2330fcf3ce44SJohn Forte ec = reg_get_iscsi(p, &pgt[0], op, op_len);
2331fcf3ce44SJohn Forte pgt[1].tag = 0;
2332fcf3ce44SJohn Forte pgt[2].tag = 0;
2333fcf3ce44SJohn Forte break;
2334fcf3ce44SJohn Forte case PORTAL_KEY1:
2335fcf3ce44SJohn Forte ec = reg_get_portal(p, &pgt[0], &pgt[1], op, op_len);
2336fcf3ce44SJohn Forte pgt[2].tag = 0;
2337fcf3ce44SJohn Forte break;
2338fcf3ce44SJohn Forte case PG_KEY1:
2339fcf3ce44SJohn Forte if (pgt[2].tag == PG_PGT) {
2340fcf3ce44SJohn Forte /* pg iscsi storage node name is */
2341fcf3ce44SJohn Forte /* followed to a pgt */
2342fcf3ce44SJohn Forte ec = reg_get_pg1(p, pgt, op, op_len);
2343fcf3ce44SJohn Forte } else {
2344fcf3ce44SJohn Forte /* a complete pg object */
2345fcf3ce44SJohn Forte ec = reg_get_pg(p, op, op_len);
2346fcf3ce44SJohn Forte pgt[0].tag = 0;
2347fcf3ce44SJohn Forte pgt[1].tag = 0;
2348fcf3ce44SJohn Forte pgt[2].tag = 0;
2349fcf3ce44SJohn Forte }
2350fcf3ce44SJohn Forte break;
2351fcf3ce44SJohn Forte case PG_KEY2:
2352fcf3ce44SJohn Forte /* pg portal ip addr is followed to a pgt */
2353fcf3ce44SJohn Forte ec = reg_get_pg2(p, pgt, op, op_len);
2354fcf3ce44SJohn Forte break;
2355fcf3ce44SJohn Forte case PG_PGT:
2356fcf3ce44SJohn Forte switch (pgt[0].tag) {
2357fcf3ce44SJohn Forte case 0:
2358fcf3ce44SJohn Forte /* portal group tag does not follow */
2359fcf3ce44SJohn Forte /* iscsi storage node or portal object */
2360fcf3ce44SJohn Forte *p = NULL;
2361fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
2362fcf3ce44SJohn Forte break;
2363fcf3ce44SJohn Forte case PG_KEY1:
2364fcf3ce44SJohn Forte case PG_KEY2:
2365fcf3ce44SJohn Forte pgt[2].tag = PG_PGT;
2366fcf3ce44SJohn Forte pgt[2].len = (*op)->attr_len;
2367fcf3ce44SJohn Forte pg_tag = 0;
2368fcf3ce44SJohn Forte switch ((*op)->attr_len) {
2369fcf3ce44SJohn Forte case 4:
2370fcf3ce44SJohn Forte pg_tag = ntohl(*(uint32_t *)
2371fcf3ce44SJohn Forte &(*op)->attr_value[0]);
2372fcf3ce44SJohn Forte case 0:
2373fcf3ce44SJohn Forte pgt[2].value.ui = pg_tag;
2374fcf3ce44SJohn Forte break;
2375fcf3ce44SJohn Forte default:
2376fcf3ce44SJohn Forte *p = NULL;
2377fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
2378fcf3ce44SJohn Forte break;
2379fcf3ce44SJohn Forte }
2380fcf3ce44SJohn Forte if (ec == 0) {
2381fcf3ce44SJohn Forte derefd = 1;
2382fcf3ce44SJohn Forte NEXT_TLV(*op, *op_len);
2383fcf3ce44SJohn Forte ec = reg_get_obj(p, pgt, op, op_len);
2384fcf3ce44SJohn Forte }
2385fcf3ce44SJohn Forte break;
2386fcf3ce44SJohn Forte default:
2387fcf3ce44SJohn Forte /* should never happen */
2388fcf3ce44SJohn Forte ASSERT(0);
2389fcf3ce44SJohn Forte *p = NULL;
2390fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
2391fcf3ce44SJohn Forte break;
2392fcf3ce44SJohn Forte }
2393fcf3ce44SJohn Forte break;
2394fcf3ce44SJohn Forte default:
2395fcf3ce44SJohn Forte *p = NULL;
2396fcf3ce44SJohn Forte ec = ISNS_RSP_MSG_FORMAT_ERROR;
2397fcf3ce44SJohn Forte break;
2398fcf3ce44SJohn Forte }
2399fcf3ce44SJohn Forte
2400fcf3ce44SJohn Forte if (ec == 0 && derefd == 0) {
2401fcf3ce44SJohn Forte ec = update_deref_obj(*p);
2402fcf3ce44SJohn Forte }
2403fcf3ce44SJohn Forte
2404fcf3ce44SJohn Forte if (ec != 0 && *p != NULL) {
2405fcf3ce44SJohn Forte free_one_object(*p);
2406fcf3ce44SJohn Forte *p = NULL;
2407fcf3ce44SJohn Forte }
2408fcf3ce44SJohn Forte
2409fcf3ce44SJohn Forte return (ec);
2410fcf3ce44SJohn Forte }
2411fcf3ce44SJohn Forte
2412fcf3ce44SJohn Forte /*
2413fcf3ce44SJohn Forte * ****************************************************************************
2414fcf3ce44SJohn Forte *
2415fcf3ce44SJohn Forte * reg_auth_src:
2416fcf3ce44SJohn Forte * Authorize the source attribute the DevAttrReg message.
2417fcf3ce44SJohn Forte * The update can only performed by the node who has the owenership.
2418fcf3ce44SJohn Forte *
2419fcf3ce44SJohn Forte * p - the pointer of the object for returning.
2420fcf3ce44SJohn Forte * pgt - an attribute array with size 3, the elements are:
2421fcf3ce44SJohn Forte * 0: the first pg key attribute, it is either the name of an
2422fcf3ce44SJohn Forte * iscsi storage node object or the ip addr of a portal object.
2423fcf3ce44SJohn Forte * 1: the second pg key attribute, i.e. the portal port.
2424fcf3ce44SJohn Forte * 2: the portal group tag attribute.
2425fcf3ce44SJohn Forte * op - the operating attributes.
2426fcf3ce44SJohn Forte * op_len - the length of the operating attributes.
2427fcf3ce44SJohn Forte * return - error code.
2428fcf3ce44SJohn Forte *
2429fcf3ce44SJohn Forte * ****************************************************************************
2430fcf3ce44SJohn Forte */
2431fcf3ce44SJohn Forte int
reg_auth_src(isns_type_t type,uint32_t uid,uchar_t * src)2432fcf3ce44SJohn Forte reg_auth_src(
2433fcf3ce44SJohn Forte isns_type_t type,
2434fcf3ce44SJohn Forte uint32_t uid,
2435fcf3ce44SJohn Forte uchar_t *src
2436fcf3ce44SJohn Forte )
2437fcf3ce44SJohn Forte {
2438fcf3ce44SJohn Forte lookup_ctrl_t lc;
2439fcf3ce44SJohn Forte uint32_t puid;
2440fcf3ce44SJohn Forte
2441fcf3ce44SJohn Forte puid = is_parent_there(src);
2442fcf3ce44SJohn Forte
2443fcf3ce44SJohn Forte if (TYPE_OF_PARENT[type] != 0) {
2444fcf3ce44SJohn Forte SET_UID_LCP(&lc, type, uid);
2445fcf3ce44SJohn Forte uid = cache_lookup(&lc, NULL, cb_get_parent);
2446fcf3ce44SJohn Forte type = TYPE_OF_PARENT[type];
2447fcf3ce44SJohn Forte }
2448fcf3ce44SJohn Forte
2449fcf3ce44SJohn Forte if (uid != 0 && puid == 0) {
2450fcf3ce44SJohn Forte SET_UID_LCP(&lc, type, uid);
2451fcf3ce44SJohn Forte uid = cache_lookup(&lc, NULL, cb_node_child);
2452fcf3ce44SJohn Forte }
2453fcf3ce44SJohn Forte
2454fcf3ce44SJohn Forte if (puid != uid) {
2455fcf3ce44SJohn Forte return (0);
2456fcf3ce44SJohn Forte }
2457fcf3ce44SJohn Forte
2458fcf3ce44SJohn Forte return (1);
2459fcf3ce44SJohn Forte }
2460fcf3ce44SJohn Forte
2461fcf3ce44SJohn Forte /*
2462fcf3ce44SJohn Forte * ****************************************************************************
2463fcf3ce44SJohn Forte *
2464fcf3ce44SJohn Forte * is_obj_online:
2465fcf3ce44SJohn Forte * determine if the object is currently registered with the server.
2466fcf3ce44SJohn Forte *
2467fcf3ce44SJohn Forte * obj - the object being checked.
2468fcf3ce44SJohn Forte * return - 0: not registered, otherwise registered.
2469fcf3ce44SJohn Forte *
2470fcf3ce44SJohn Forte * ****************************************************************************
2471fcf3ce44SJohn Forte */
2472fcf3ce44SJohn Forte int
is_obj_online(const isns_obj_t * obj)2473fcf3ce44SJohn Forte is_obj_online(
2474fcf3ce44SJohn Forte const isns_obj_t *obj
2475fcf3ce44SJohn Forte )
2476fcf3ce44SJohn Forte {
2477fcf3ce44SJohn Forte int online = 1;
2478fcf3ce44SJohn Forte
2479fcf3ce44SJohn Forte switch (obj->type) {
2480fcf3ce44SJohn Forte case OBJ_ISCSI:
2481fcf3ce44SJohn Forte online = obj->attrs[ATTR_INDEX_ISCSI(
2482fcf3ce44SJohn Forte ISNS_ISCSI_NODE_TYPE_ATTR_ID)].value.ui == 0 ? 0 : 1;
2483fcf3ce44SJohn Forte break;
2484fcf3ce44SJohn Forte default:
2485fcf3ce44SJohn Forte break;
2486fcf3ce44SJohn Forte }
2487fcf3ce44SJohn Forte
2488fcf3ce44SJohn Forte return (online);
2489fcf3ce44SJohn Forte }
2490fcf3ce44SJohn Forte
2491fcf3ce44SJohn Forte static int
set_obj_offline(isns_obj_t * obj)2492fcf3ce44SJohn Forte set_obj_offline(
2493fcf3ce44SJohn Forte isns_obj_t *obj
2494fcf3ce44SJohn Forte )
2495fcf3ce44SJohn Forte {
2496fcf3ce44SJohn Forte switch (obj->type) {
2497fcf3ce44SJohn Forte case OBJ_ISCSI:
2498fcf3ce44SJohn Forte obj->attrs[ATTR_INDEX_ISCSI(
2499fcf3ce44SJohn Forte ISNS_ISCSI_NODE_TYPE_ATTR_ID)].value.ui = 0;
2500fcf3ce44SJohn Forte break;
2501fcf3ce44SJohn Forte default:
2502fcf3ce44SJohn Forte break;
2503fcf3ce44SJohn Forte }
2504fcf3ce44SJohn Forte
2505fcf3ce44SJohn Forte return (0);
2506fcf3ce44SJohn Forte }
2507fcf3ce44SJohn Forte
2508fcf3ce44SJohn Forte /*
2509fcf3ce44SJohn Forte * ****************************************************************************
2510fcf3ce44SJohn Forte *
2511fcf3ce44SJohn Forte * assoc_clone:
2512fcf3ce44SJohn Forte * clone the association object.
2513fcf3ce44SJohn Forte *
2514fcf3ce44SJohn Forte * p - the object being cloned.
2515fcf3ce44SJohn Forte * clone_flag - 0: the object is being removed;
2516fcf3ce44SJohn Forte * 1: only the association is being removed.
2517fcf3ce44SJohn Forte * return - the clone object.
2518fcf3ce44SJohn Forte *
2519fcf3ce44SJohn Forte * ****************************************************************************
2520fcf3ce44SJohn Forte */
2521fcf3ce44SJohn Forte void *
assoc_clone(void * p,int clone_flag)2522fcf3ce44SJohn Forte assoc_clone(
2523fcf3ce44SJohn Forte void *p,
2524fcf3ce44SJohn Forte int clone_flag
2525fcf3ce44SJohn Forte )
2526fcf3ce44SJohn Forte {
2527fcf3ce44SJohn Forte isns_type_t type;
2528fcf3ce44SJohn Forte isns_obj_t *clone;
2529fcf3ce44SJohn Forte const isns_attr_t *src_attr;
2530fcf3ce44SJohn Forte isns_attr_t *dst_attr;
2531fcf3ce44SJohn Forte uint32_t id, op;
2532fcf3ce44SJohn Forte int i = 0;
2533fcf3ce44SJohn Forte
2534fcf3ce44SJohn Forte const isns_obj_t *obj;
2535fcf3ce44SJohn Forte uint32_t dd_flag;
2536fcf3ce44SJohn Forte int online;
2537fcf3ce44SJohn Forte
2538fcf3ce44SJohn Forte int state;
2539fcf3ce44SJohn Forte
2540fcf3ce44SJohn Forte obj = (isns_obj_t *)p;
2541fcf3ce44SJohn Forte
2542fcf3ce44SJohn Forte if (obj->type != OBJ_ISCSI) {
2543fcf3ce44SJohn Forte return (NULL);
2544fcf3ce44SJohn Forte }
2545fcf3ce44SJohn Forte
2546fcf3ce44SJohn Forte dd_flag = (get_dd_id(get_obj_uid(obj), ISNS_DEFAULT_DD_ID) == 0) ?
2547fcf3ce44SJohn Forte 0 : 1;
2548fcf3ce44SJohn Forte online = is_obj_online(obj);
2549fcf3ce44SJohn Forte
2550fcf3ce44SJohn Forte state = (clone_flag << 2) | (dd_flag << 1) | online;
2551fcf3ce44SJohn Forte
2552fcf3ce44SJohn Forte /* clone_flag dd_flag online action */
2553fcf3ce44SJohn Forte /* 0 0 0 ASSERT(0) */
2554fcf3ce44SJohn Forte /* 0 0 1 NULL */
2555fcf3ce44SJohn Forte /* 0 1 0 itself */
2556fcf3ce44SJohn Forte /* 0 1 1 clone it */
2557fcf3ce44SJohn Forte /* 1 0 0 NULL */
2558fcf3ce44SJohn Forte /* 1 0 1 itself */
2559fcf3ce44SJohn Forte /* 1 1 0 itself */
2560fcf3ce44SJohn Forte /* 1 1 1 itself */
2561fcf3ce44SJohn Forte
2562fcf3ce44SJohn Forte switch (state) {
2563fcf3ce44SJohn Forte case 0:
2564fcf3ce44SJohn Forte ASSERT(0);
2565fcf3ce44SJohn Forte case 1:
2566fcf3ce44SJohn Forte case 4:
2567fcf3ce44SJohn Forte return (NULL);
2568fcf3ce44SJohn Forte case 2:
2569fcf3ce44SJohn Forte case 5:
2570fcf3ce44SJohn Forte case 6:
2571fcf3ce44SJohn Forte case 7:
2572fcf3ce44SJohn Forte return (p);
2573fcf3ce44SJohn Forte case 3:
2574fcf3ce44SJohn Forte default:
2575fcf3ce44SJohn Forte break;
2576fcf3ce44SJohn Forte }
2577fcf3ce44SJohn Forte
2578fcf3ce44SJohn Forte type = obj->type;
2579fcf3ce44SJohn Forte clone = obj_calloc(type);
2580fcf3ce44SJohn Forte
2581fcf3ce44SJohn Forte if (clone != NULL) {
2582fcf3ce44SJohn Forte id = UID_ATTR_INDEX[type];
2583fcf3ce44SJohn Forte src_attr = &(obj->attrs[id]);
2584fcf3ce44SJohn Forte dst_attr = &(clone->attrs[id]);
2585fcf3ce44SJohn Forte if (assign_attr(dst_attr, src_attr) != 0) {
2586fcf3ce44SJohn Forte free_one_object(clone);
2587fcf3ce44SJohn Forte return (NULL);
2588fcf3ce44SJohn Forte }
2589fcf3ce44SJohn Forte
2590fcf3ce44SJohn Forte while (i < MAX_KEY_ATTRS) {
2591fcf3ce44SJohn Forte op = KEY_ATTR_OP[type][i];
2592fcf3ce44SJohn Forte if (op != 0) {
2593fcf3ce44SJohn Forte id = KEY_ATTR_INDEX[type][i];
2594fcf3ce44SJohn Forte src_attr = &(obj->attrs[id]);
2595fcf3ce44SJohn Forte dst_attr = &(clone->attrs[id]);
2596fcf3ce44SJohn Forte if (assign_attr(dst_attr, src_attr) != 0) {
2597fcf3ce44SJohn Forte free_one_object(clone);
2598fcf3ce44SJohn Forte return (NULL);
2599fcf3ce44SJohn Forte }
2600fcf3ce44SJohn Forte } else {
2601fcf3ce44SJohn Forte break;
2602fcf3ce44SJohn Forte }
2603fcf3ce44SJohn Forte i ++;
2604fcf3ce44SJohn Forte }
2605fcf3ce44SJohn Forte }
2606fcf3ce44SJohn Forte
2607fcf3ce44SJohn Forte return ((void *)clone);
2608fcf3ce44SJohn Forte }
2609fcf3ce44SJohn Forte
2610fcf3ce44SJohn Forte /*
2611fcf3ce44SJohn Forte * ****************************************************************************
2612fcf3ce44SJohn Forte *
2613fcf3ce44SJohn Forte * free_one_object:
2614fcf3ce44SJohn Forte * free up one object.
2615fcf3ce44SJohn Forte *
2616fcf3ce44SJohn Forte * obj - the object being freed.
2617fcf3ce44SJohn Forte *
2618fcf3ce44SJohn Forte * ****************************************************************************
2619fcf3ce44SJohn Forte */
2620fcf3ce44SJohn Forte void
free_one_object(isns_obj_t * obj)2621fcf3ce44SJohn Forte free_one_object(
2622fcf3ce44SJohn Forte isns_obj_t *obj
2623fcf3ce44SJohn Forte )
2624fcf3ce44SJohn Forte {
2625fcf3ce44SJohn Forte int i;
2626fcf3ce44SJohn Forte uint32_t *cuid;
2627fcf3ce44SJohn Forte if (obj == NULL) {
2628fcf3ce44SJohn Forte return;
2629fcf3ce44SJohn Forte }
2630fcf3ce44SJohn Forte for (i = 0; i < NUM_OF_ATTRS[obj->type]; i++) {
2631fcf3ce44SJohn Forte isns_attr_t *attr = &obj->attrs[i];
2632fcf3ce44SJohn Forte switch (attr->tag) {
2633fcf3ce44SJohn Forte case ISNS_EID_ATTR_ID:
2634fcf3ce44SJohn Forte case ISNS_ISCSI_NAME_ATTR_ID:
2635fcf3ce44SJohn Forte case ISNS_ISCSI_ALIAS_ATTR_ID:
2636fcf3ce44SJohn Forte case ISNS_ISCSI_AUTH_METHOD_ATTR_ID:
2637fcf3ce44SJohn Forte case ISNS_PG_ISCSI_NAME_ATTR_ID:
2638fcf3ce44SJohn Forte case ISNS_PORTAL_IP_ADDR_ATTR_ID:
2639fcf3ce44SJohn Forte case ISNS_PORTAL_NAME_ATTR_ID:
2640fcf3ce44SJohn Forte case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
2641fcf3ce44SJohn Forte case ISNS_DD_SET_NAME_ATTR_ID:
2642fcf3ce44SJohn Forte case ISNS_DD_NAME_ATTR_ID:
2643fcf3ce44SJohn Forte case ISNS_DD_ISCSI_NAME_ATTR_ID:
2644fcf3ce44SJohn Forte case ISNS_DD_FC_PORT_NAME_ATTR_ID:
2645fcf3ce44SJohn Forte case ISNS_DD_PORTAL_IP_ADDR_ATTR_ID:
2646fcf3ce44SJohn Forte #ifdef DEBUG
2647fcf3ce44SJohn Forte if (verbose_mc) {
2648fcf3ce44SJohn Forte printf("memory(%d) deallocated\n",
2649fcf3ce44SJohn Forte attr->len);
2650fcf3ce44SJohn Forte }
2651fcf3ce44SJohn Forte #endif
2652fcf3ce44SJohn Forte free(attr->value.ptr);
2653fcf3ce44SJohn Forte attr->value.ptr = NULL;
2654fcf3ce44SJohn Forte break;
2655fcf3ce44SJohn Forte default:
2656fcf3ce44SJohn Forte break;
2657fcf3ce44SJohn Forte }
2658fcf3ce44SJohn Forte }
2659fcf3ce44SJohn Forte
2660fcf3ce44SJohn Forte /* free child uids */
2661fcf3ce44SJohn Forte i = 0;
2662fcf3ce44SJohn Forte while (i < NUM_OF_CHILD[obj->type]) {
2663fcf3ce44SJohn Forte cuid = get_child_n(obj, i);
2664fcf3ce44SJohn Forte free(cuid);
2665fcf3ce44SJohn Forte i ++;
2666fcf3ce44SJohn Forte }
2667fcf3ce44SJohn Forte
2668fcf3ce44SJohn Forte /* at last, free the object itself */
2669fcf3ce44SJohn Forte #ifdef DEBUG
2670fcf3ce44SJohn Forte if (verbose_mc) {
2671fcf3ce44SJohn Forte printf("object(%d) deallocated\n", obj->type);
2672fcf3ce44SJohn Forte }
2673fcf3ce44SJohn Forte #endif
2674fcf3ce44SJohn Forte free(obj);
2675fcf3ce44SJohn Forte }
2676fcf3ce44SJohn Forte
2677fcf3ce44SJohn Forte /*
2678fcf3ce44SJohn Forte * ****************************************************************************
2679fcf3ce44SJohn Forte *
2680fcf3ce44SJohn Forte * free_object:
2681fcf3ce44SJohn Forte * free up one object.
2682fcf3ce44SJohn Forte *
2683fcf3ce44SJohn Forte * obj - the object being freed.
2684fcf3ce44SJohn Forte *
2685fcf3ce44SJohn Forte * ****************************************************************************
2686fcf3ce44SJohn Forte */
2687fcf3ce44SJohn Forte void
free_object(isns_obj_t * obj)2688fcf3ce44SJohn Forte free_object(
2689fcf3ce44SJohn Forte isns_obj_t *obj
2690fcf3ce44SJohn Forte )
2691fcf3ce44SJohn Forte {
2692fcf3ce44SJohn Forte free_one_object(obj);
2693fcf3ce44SJohn Forte }
2694fcf3ce44SJohn Forte
2695fcf3ce44SJohn Forte /*
2696fcf3ce44SJohn Forte * ****************************************************************************
2697fcf3ce44SJohn Forte *
2698fcf3ce44SJohn Forte * set_parent_obj:
2699fcf3ce44SJohn Forte * set the parent object UID.
2700fcf3ce44SJohn Forte *
2701fcf3ce44SJohn Forte * obj - the child object.
2702fcf3ce44SJohn Forte * puid- the parent object UID.
2703fcf3ce44SJohn Forte * return - error code.
2704fcf3ce44SJohn Forte *
2705fcf3ce44SJohn Forte * ****************************************************************************
2706fcf3ce44SJohn Forte */
2707fcf3ce44SJohn Forte int
set_parent_obj(isns_obj_t * obj,uint32_t puid)2708fcf3ce44SJohn Forte set_parent_obj(
2709fcf3ce44SJohn Forte isns_obj_t *obj,
2710fcf3ce44SJohn Forte uint32_t puid
2711fcf3ce44SJohn Forte )
2712fcf3ce44SJohn Forte {
2713fcf3ce44SJohn Forte uint32_t *const p = get_parent_p(obj);
2714fcf3ce44SJohn Forte if (p != NULL) {
2715fcf3ce44SJohn Forte *p = puid;
2716fcf3ce44SJohn Forte }
2717fcf3ce44SJohn Forte
2718fcf3ce44SJohn Forte return (0);
2719fcf3ce44SJohn Forte }
2720fcf3ce44SJohn Forte
2721fcf3ce44SJohn Forte /*
2722fcf3ce44SJohn Forte * ****************************************************************************
2723fcf3ce44SJohn Forte *
2724fcf3ce44SJohn Forte * buff_child_obj:
2725fcf3ce44SJohn Forte * add a child object UID to the child object array.
2726fcf3ce44SJohn Forte *
2727fcf3ce44SJohn Forte * obj - the parent object.
2728fcf3ce44SJohn Forte * child_type - the type of the child object.
2729fcf3ce44SJohn Forte * number - the number of the child object.
2730fcf3ce44SJohn Forte * return - the length of the child object UID array.
2731fcf3ce44SJohn Forte *
2732fcf3ce44SJohn Forte * ****************************************************************************
2733fcf3ce44SJohn Forte */
2734fcf3ce44SJohn Forte int
buff_child_obj(const isns_type_t ptype,const isns_type_t ctype,const void * c,void const *** child)2735fcf3ce44SJohn Forte buff_child_obj(
2736fcf3ce44SJohn Forte const isns_type_t ptype,
2737fcf3ce44SJohn Forte const isns_type_t ctype,
2738fcf3ce44SJohn Forte const void *c,
2739fcf3ce44SJohn Forte void const ***child
2740fcf3ce44SJohn Forte )
2741fcf3ce44SJohn Forte {
2742fcf3ce44SJohn Forte int ec = 0;
2743fcf3ce44SJohn Forte
2744fcf3ce44SJohn Forte int i = 0;
2745fcf3ce44SJohn Forte void const ***pp, **p;
2746fcf3ce44SJohn Forte uint32_t num, new_num;
2747fcf3ce44SJohn Forte
2748fcf3ce44SJohn Forte pp = NULL;
2749fcf3ce44SJohn Forte /* get the pointer of the array which the child belongs to */
2750fcf3ce44SJohn Forte while (i < NUM_OF_CHILD[ptype]) {
2751fcf3ce44SJohn Forte if (TYPE_OF_CHILD[ptype][i] == ctype) {
2752fcf3ce44SJohn Forte pp = &child[i];
2753fcf3ce44SJohn Forte break;
2754fcf3ce44SJohn Forte }
2755fcf3ce44SJohn Forte i ++;
2756fcf3ce44SJohn Forte }
2757fcf3ce44SJohn Forte
2758fcf3ce44SJohn Forte /* the child type is not applicable */
2759fcf3ce44SJohn Forte if (pp == NULL) {
2760fcf3ce44SJohn Forte return (ec);
2761fcf3ce44SJohn Forte }
2762fcf3ce44SJohn Forte
2763fcf3ce44SJohn Forte p = *pp;
2764fcf3ce44SJohn Forte /* get an empty slot from the uid array for this child */
2765fcf3ce44SJohn Forte if (p != NULL) {
2766fcf3ce44SJohn Forte num = (uint32_t)*p;
2767fcf3ce44SJohn Forte i = 0;
2768fcf3ce44SJohn Forte while (i < num) {
2769fcf3ce44SJohn Forte if (p[++i] == NULL) {
2770fcf3ce44SJohn Forte /* found it */
2771fcf3ce44SJohn Forte p[i] = c;
2772fcf3ce44SJohn Forte return (ec);
2773fcf3ce44SJohn Forte }
2774fcf3ce44SJohn Forte }
2775fcf3ce44SJohn Forte p = *pp;
2776fcf3ce44SJohn Forte new_num = num + 1;
2777fcf3ce44SJohn Forte } else {
2778fcf3ce44SJohn Forte num = 0;
2779fcf3ce44SJohn Forte new_num = 1;
2780fcf3ce44SJohn Forte }
2781fcf3ce44SJohn Forte
2782fcf3ce44SJohn Forte /* the array is full, enlarge the child uid array */
2783fcf3ce44SJohn Forte p = (void const **)realloc(p, (new_num + 1) * sizeof (void *));
2784fcf3ce44SJohn Forte if (p != NULL) {
2785fcf3ce44SJohn Forte *pp = p;
2786fcf3ce44SJohn Forte *p = (void *)new_num;
2787fcf3ce44SJohn Forte p[new_num] = c;
2788fcf3ce44SJohn Forte } else {
2789fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
2790fcf3ce44SJohn Forte }
2791fcf3ce44SJohn Forte
2792fcf3ce44SJohn Forte return (ec);
2793fcf3ce44SJohn Forte }
2794fcf3ce44SJohn Forte
2795fcf3ce44SJohn Forte /*
2796fcf3ce44SJohn Forte * ****************************************************************************
2797fcf3ce44SJohn Forte *
2798fcf3ce44SJohn Forte * update_child_object:
2799fcf3ce44SJohn Forte * update the child object of a network entity object.
2800fcf3ce44SJohn Forte *
2801fcf3ce44SJohn Forte * puid - the UID of the parent object, i.e. the network entity object.
2802fcf3ce44SJohn Forte * child_type - the type of the child object.
2803fcf3ce44SJohn Forte * child_uid - the uid of the child object.
2804fcf3ce44SJohn Forte * return - error code.
2805fcf3ce44SJohn Forte *
2806fcf3ce44SJohn Forte * ****************************************************************************
2807fcf3ce44SJohn Forte */
2808fcf3ce44SJohn Forte int
update_child_obj(const isns_type_t ptype,const uint32_t puid,void const *** child,int child_flag)2809fcf3ce44SJohn Forte update_child_obj(
2810fcf3ce44SJohn Forte const isns_type_t ptype,
2811fcf3ce44SJohn Forte const uint32_t puid,
2812fcf3ce44SJohn Forte void const ***child,
2813fcf3ce44SJohn Forte int child_flag
2814fcf3ce44SJohn Forte )
2815fcf3ce44SJohn Forte {
2816fcf3ce44SJohn Forte int ec = 0;
2817fcf3ce44SJohn Forte
2818fcf3ce44SJohn Forte lookup_ctrl_t lc;
2819fcf3ce44SJohn Forte
2820fcf3ce44SJohn Forte SET_UID_LCP(&lc, ptype, puid);
2821fcf3ce44SJohn Forte
2822fcf3ce44SJohn Forte lc.data[1].ptr = (uchar_t *)child;
2823fcf3ce44SJohn Forte lc.data[2].ui = child_flag;
2824fcf3ce44SJohn Forte
2825fcf3ce44SJohn Forte ec = cache_lookup(&lc, NULL, cb_add_child);
2826fcf3ce44SJohn Forte
2827fcf3ce44SJohn Forte return (ec);
2828fcf3ce44SJohn Forte }
2829fcf3ce44SJohn Forte
2830fcf3ce44SJohn Forte int
update_ref_obj(const isns_obj_t * obj)2831fcf3ce44SJohn Forte update_ref_obj(
2832fcf3ce44SJohn Forte const isns_obj_t *obj
2833fcf3ce44SJohn Forte )
2834fcf3ce44SJohn Forte {
2835fcf3ce44SJohn Forte uint32_t uid;
2836fcf3ce44SJohn Forte lookup_ctrl_t lc;
2837fcf3ce44SJohn Forte isns_type_t t;
2838fcf3ce44SJohn Forte
2839fcf3ce44SJohn Forte t = obj->type;
2840fcf3ce44SJohn Forte
2841fcf3ce44SJohn Forte if (TYPE_OF_REF[t][0] != 0) {
2842fcf3ce44SJohn Forte (void) setup_ref_lcp(&lc, obj, NULL);
2843fcf3ce44SJohn Forte
2844fcf3ce44SJohn Forte lc.id[2] = t;
2845fcf3ce44SJohn Forte lc.data[2].ui = get_obj_uid(obj);
2846fcf3ce44SJohn Forte
2847fcf3ce44SJohn Forte uid = 0;
2848fcf3ce44SJohn Forte do {
2849fcf3ce44SJohn Forte lc.curr_uid = uid;
2850fcf3ce44SJohn Forte (void) cache_lookup(&lc, &uid, cb_set_ref);
2851fcf3ce44SJohn Forte } while (uid != 0);
2852fcf3ce44SJohn Forte }
2853fcf3ce44SJohn Forte
2854fcf3ce44SJohn Forte return (0);
2855fcf3ce44SJohn Forte }
2856fcf3ce44SJohn Forte
2857fcf3ce44SJohn Forte /*
2858fcf3ce44SJohn Forte * ****************************************************************************
2859fcf3ce44SJohn Forte *
2860fcf3ce44SJohn Forte * verify_ref_obj:
2861fcf3ce44SJohn Forte * update the reference bit of a portal group object.
2862fcf3ce44SJohn Forte *
2863fcf3ce44SJohn Forte * obj - the object being ref'ed.
2864fcf3ce44SJohn Forte * return - error code.
2865fcf3ce44SJohn Forte *
2866fcf3ce44SJohn Forte * ****************************************************************************
2867fcf3ce44SJohn Forte */
2868fcf3ce44SJohn Forte int
verify_ref_obj(const isns_type_t ptype,const uint32_t puid,void const *** child)2869fcf3ce44SJohn Forte verify_ref_obj(
2870fcf3ce44SJohn Forte const isns_type_t ptype,
2871fcf3ce44SJohn Forte const uint32_t puid,
2872fcf3ce44SJohn Forte void const ***child
2873fcf3ce44SJohn Forte )
2874fcf3ce44SJohn Forte {
2875fcf3ce44SJohn Forte int ec = 0;
2876fcf3ce44SJohn Forte
2877fcf3ce44SJohn Forte lookup_ctrl_t lc;
2878fcf3ce44SJohn Forte
2879fcf3ce44SJohn Forte SET_UID_LCP(&lc, ptype, puid);
2880fcf3ce44SJohn Forte
2881fcf3ce44SJohn Forte lc.data[1].ptr = (uchar_t *)child;
2882fcf3ce44SJohn Forte
2883fcf3ce44SJohn Forte ec = cache_lookup(&lc, NULL, cb_verify_ref);
2884fcf3ce44SJohn Forte
2885fcf3ce44SJohn Forte return (ec);
2886fcf3ce44SJohn Forte }
2887fcf3ce44SJohn Forte
2888fcf3ce44SJohn Forte int
update_deref_obj(isns_obj_t * obj)2889fcf3ce44SJohn Forte update_deref_obj(
2890fcf3ce44SJohn Forte isns_obj_t *obj
2891fcf3ce44SJohn Forte )
2892fcf3ce44SJohn Forte {
2893fcf3ce44SJohn Forte int ec = 0;
2894fcf3ce44SJohn Forte
2895fcf3ce44SJohn Forte isns_type_t t, rt;
2896fcf3ce44SJohn Forte lookup_ctrl_t lc;
2897fcf3ce44SJohn Forte int i, ref_count;
2898fcf3ce44SJohn Forte
2899fcf3ce44SJohn Forte uint32_t uid, *refp;
2900fcf3ce44SJohn Forte
2901fcf3ce44SJohn Forte t = obj->type;
2902fcf3ce44SJohn Forte i = ref_count = 0;
2903fcf3ce44SJohn Forte while (i < NUM_OF_REF[t]) {
2904fcf3ce44SJohn Forte rt = TYPE_OF_REF[t][i + 1];
2905fcf3ce44SJohn Forte (void) setup_deref_lcp(&lc, obj, rt);
2906fcf3ce44SJohn Forte uid = is_obj_there(&lc);
2907fcf3ce44SJohn Forte if (uid != 0) {
2908fcf3ce44SJohn Forte refp = get_ref_p(obj, lc.type);
2909fcf3ce44SJohn Forte *refp = uid;
2910fcf3ce44SJohn Forte ref_count ++;
2911fcf3ce44SJohn Forte }
2912fcf3ce44SJohn Forte i ++;
2913fcf3ce44SJohn Forte }
2914fcf3ce44SJohn Forte
2915fcf3ce44SJohn Forte if (i > 0 && ref_count == 0) {
2916fcf3ce44SJohn Forte ec = ISNS_RSP_INVALID_REGIS;
2917fcf3ce44SJohn Forte }
2918fcf3ce44SJohn Forte
2919fcf3ce44SJohn Forte return (ec);
2920fcf3ce44SJohn Forte }
2921fcf3ce44SJohn Forte
2922fcf3ce44SJohn Forte /*
2923fcf3ce44SJohn Forte * ****************************************************************************
2924fcf3ce44SJohn Forte *
2925fcf3ce44SJohn Forte * register_object:
2926fcf3ce44SJohn Forte * add one object to the object container.
2927fcf3ce44SJohn Forte *
2928fcf3ce44SJohn Forte * obj - the object being added.
2929fcf3ce44SJohn Forte * uid_p- the pointer for returning object UID.
2930fcf3ce44SJohn Forte * update_p- the pointer for returning flag which indicates if the object
2931fcf3ce44SJohn Forte * is newly registered or updated with an existing one.
2932fcf3ce44SJohn Forte * return - error code.
2933fcf3ce44SJohn Forte *
2934fcf3ce44SJohn Forte * ****************************************************************************
2935fcf3ce44SJohn Forte */
2936fcf3ce44SJohn Forte int
register_object(isns_obj_t * obj,uint32_t * uid_p,int * update_p)2937fcf3ce44SJohn Forte register_object(
2938fcf3ce44SJohn Forte isns_obj_t *obj,
2939fcf3ce44SJohn Forte uint32_t *uid_p,
2940fcf3ce44SJohn Forte int *update_p
2941fcf3ce44SJohn Forte )
2942fcf3ce44SJohn Forte {
2943fcf3ce44SJohn Forte return (cache_add(obj, 0, uid_p, update_p));
2944fcf3ce44SJohn Forte }
2945fcf3ce44SJohn Forte
2946fcf3ce44SJohn Forte /*
2947fcf3ce44SJohn Forte * ****************************************************************************
2948fcf3ce44SJohn Forte *
2949fcf3ce44SJohn Forte * register_assoc:
2950fcf3ce44SJohn Forte * add one association object to the object container, the association
2951fcf3ce44SJohn Forte * object has only the information for discovery domain membership, i.e.
2952fcf3ce44SJohn Forte * a name and UID only.
2953fcf3ce44SJohn Forte *
2954fcf3ce44SJohn Forte * obj - the association object being added.
2955fcf3ce44SJohn Forte * uid_p- the pointer for returning object UID.
2956fcf3ce44SJohn Forte * return - error code.
2957fcf3ce44SJohn Forte *
2958fcf3ce44SJohn Forte * ****************************************************************************
2959fcf3ce44SJohn Forte */
2960fcf3ce44SJohn Forte int
register_assoc(isns_obj_t * obj,uint32_t * uid_p)2961fcf3ce44SJohn Forte register_assoc(
2962fcf3ce44SJohn Forte isns_obj_t *obj,
2963fcf3ce44SJohn Forte uint32_t *uid_p
2964fcf3ce44SJohn Forte )
2965fcf3ce44SJohn Forte {
2966fcf3ce44SJohn Forte return (cache_add(obj, 1, uid_p, NULL));
2967fcf3ce44SJohn Forte }
2968fcf3ce44SJohn Forte
2969fcf3ce44SJohn Forte /*
2970fcf3ce44SJohn Forte * ****************************************************************************
2971fcf3ce44SJohn Forte *
2972fcf3ce44SJohn Forte * is_obj_there:
2973fcf3ce44SJohn Forte * check if the object is registered or not.
2974fcf3ce44SJohn Forte *
2975fcf3ce44SJohn Forte * lcp - the lookup control data.
2976fcf3ce44SJohn Forte * return - the object UID.
2977fcf3ce44SJohn Forte *
2978fcf3ce44SJohn Forte * ****************************************************************************
2979fcf3ce44SJohn Forte */
2980fcf3ce44SJohn Forte uint32_t
is_obj_there(lookup_ctrl_t * lcp)2981fcf3ce44SJohn Forte is_obj_there(
2982fcf3ce44SJohn Forte lookup_ctrl_t *lcp
2983fcf3ce44SJohn Forte )
2984fcf3ce44SJohn Forte {
2985fcf3ce44SJohn Forte uint32_t uid;
2986fcf3ce44SJohn Forte
2987fcf3ce44SJohn Forte (void) cache_lookup(lcp, &uid, NULL);
2988fcf3ce44SJohn Forte
2989fcf3ce44SJohn Forte return (uid);
2990fcf3ce44SJohn Forte }
2991fcf3ce44SJohn Forte
2992fcf3ce44SJohn Forte uint32_t
is_parent_there(uchar_t * src)2993fcf3ce44SJohn Forte is_parent_there(
2994fcf3ce44SJohn Forte uchar_t *src
2995fcf3ce44SJohn Forte )
2996fcf3ce44SJohn Forte {
2997fcf3ce44SJohn Forte lookup_ctrl_t lc;
2998fcf3ce44SJohn Forte
2999fcf3ce44SJohn Forte lc.curr_uid = 0;
3000fcf3ce44SJohn Forte lc.type = OBJ_ISCSI;
3001fcf3ce44SJohn Forte lc.id[0] = ATTR_INDEX_ISCSI(ISNS_ISCSI_NAME_ATTR_ID);
3002fcf3ce44SJohn Forte lc.op[0] = OP_STRING;
3003fcf3ce44SJohn Forte lc.data[0].ptr = src;
3004fcf3ce44SJohn Forte lc.op[1] = 0;
3005fcf3ce44SJohn Forte
3006fcf3ce44SJohn Forte return (cache_lookup(&lc, NULL, cb_get_parent));
3007fcf3ce44SJohn Forte }
3008fcf3ce44SJohn Forte
3009fcf3ce44SJohn Forte /*
3010fcf3ce44SJohn Forte * ****************************************************************************
3011fcf3ce44SJohn Forte *
3012fcf3ce44SJohn Forte * setup_ref_lcp:
3013fcf3ce44SJohn Forte * prepare the lookup control data for looking up a portal group
3014fcf3ce44SJohn Forte * object which references to a iscsi stroage node and/or a portal
3015fcf3ce44SJohn Forte * object.
3016fcf3ce44SJohn Forte *
3017fcf3ce44SJohn Forte * lcp - the lookup control data.
3018fcf3ce44SJohn Forte * iscsi- the ref'ed iscsi storage node object.
3019fcf3ce44SJohn Forte * portal- the ref'ed portal object.
3020fcf3ce44SJohn Forte * return - error code.
3021fcf3ce44SJohn Forte *
3022fcf3ce44SJohn Forte * ****************************************************************************
3023fcf3ce44SJohn Forte */
3024fcf3ce44SJohn Forte static int
setup_ref_lcp(lookup_ctrl_t * lcp,const isns_obj_t * iscsi,const isns_obj_t * portal)3025fcf3ce44SJohn Forte setup_ref_lcp(
3026fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
3027fcf3ce44SJohn Forte const isns_obj_t *iscsi,
3028fcf3ce44SJohn Forte const isns_obj_t *portal
3029fcf3ce44SJohn Forte )
3030fcf3ce44SJohn Forte {
3031fcf3ce44SJohn Forte int i = 0, j = 0;
3032fcf3ce44SJohn Forte
3033fcf3ce44SJohn Forte lcp->curr_uid = 0;
3034fcf3ce44SJohn Forte lcp->type = TYPE_OF_REF[iscsi->type][0];
3035fcf3ce44SJohn Forte
3036fcf3ce44SJohn Forte /* extrace the matching attributes from iscsi storage node object */
3037fcf3ce44SJohn Forte while (iscsi != NULL &&
3038fcf3ce44SJohn Forte i < MAX_REF_MATCH &&
3039fcf3ce44SJohn Forte REF_MATCH_OPS[iscsi->type][i] > 0) {
3040fcf3ce44SJohn Forte lcp->id[i] = REF_MATCH_ID2[iscsi->type][i];
3041fcf3ce44SJohn Forte lcp->op[i] = REF_MATCH_OPS[iscsi->type][i];
3042fcf3ce44SJohn Forte lcp->data[i].ptr = iscsi->attrs[
3043fcf3ce44SJohn Forte REF_MATCH_ID1[iscsi->type][i]].value.ptr;
3044fcf3ce44SJohn Forte i ++;
3045fcf3ce44SJohn Forte }
3046fcf3ce44SJohn Forte
3047fcf3ce44SJohn Forte /* extrace the matching attributes from portal object */
3048fcf3ce44SJohn Forte while (portal != NULL &&
3049fcf3ce44SJohn Forte i < MAX_LOOKUP_CTRL &&
3050fcf3ce44SJohn Forte j < MAX_REF_MATCH &&
3051fcf3ce44SJohn Forte REF_MATCH_OPS[portal->type][j] > 0) {
3052fcf3ce44SJohn Forte lcp->id[i] = REF_MATCH_ID2[portal->type][j];
3053fcf3ce44SJohn Forte lcp->op[i] = REF_MATCH_OPS[portal->type][j];
3054fcf3ce44SJohn Forte lcp->data[i].ptr = portal->attrs[
3055fcf3ce44SJohn Forte REF_MATCH_ID1[portal->type][j]].value.ptr;
3056fcf3ce44SJohn Forte j ++;
3057fcf3ce44SJohn Forte i ++;
3058fcf3ce44SJohn Forte }
3059fcf3ce44SJohn Forte
3060fcf3ce44SJohn Forte if (i < MAX_LOOKUP_CTRL) {
3061fcf3ce44SJohn Forte lcp->op[i] = 0;
3062fcf3ce44SJohn Forte }
3063fcf3ce44SJohn Forte
3064fcf3ce44SJohn Forte return (0);
3065fcf3ce44SJohn Forte }
3066fcf3ce44SJohn Forte
3067fcf3ce44SJohn Forte static int
setup_deref_lcp(lookup_ctrl_t * lcp,const isns_obj_t * pg,isns_type_t t)3068fcf3ce44SJohn Forte setup_deref_lcp(
3069fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
3070fcf3ce44SJohn Forte const isns_obj_t *pg,
3071fcf3ce44SJohn Forte isns_type_t t
3072fcf3ce44SJohn Forte )
3073fcf3ce44SJohn Forte {
3074fcf3ce44SJohn Forte int i = 0;
3075fcf3ce44SJohn Forte
3076fcf3ce44SJohn Forte lcp->curr_uid = 0;
3077fcf3ce44SJohn Forte lcp->type = t;
3078fcf3ce44SJohn Forte
3079fcf3ce44SJohn Forte /* extrace the matching attributes from iscsi storage node object */
3080fcf3ce44SJohn Forte while (i < MAX_REF_MATCH &&
3081fcf3ce44SJohn Forte REF_MATCH_OPS[t][i] > 0) {
3082fcf3ce44SJohn Forte lcp->id[i] = REF_MATCH_ID1[t][i];
3083fcf3ce44SJohn Forte lcp->op[i] = REF_MATCH_OPS[t][i];
3084fcf3ce44SJohn Forte lcp->data[i].ptr = pg->attrs[
3085fcf3ce44SJohn Forte REF_MATCH_ID2[t][i]].value.ptr;
3086fcf3ce44SJohn Forte i ++;
3087fcf3ce44SJohn Forte }
3088fcf3ce44SJohn Forte
3089fcf3ce44SJohn Forte if (i < MAX_LOOKUP_CTRL) {
3090fcf3ce44SJohn Forte lcp->op[i] = 0;
3091fcf3ce44SJohn Forte }
3092fcf3ce44SJohn Forte
3093fcf3ce44SJohn Forte return (0);
3094fcf3ce44SJohn Forte }
3095fcf3ce44SJohn Forte
3096fcf3ce44SJohn Forte /*
3097fcf3ce44SJohn Forte * ****************************************************************************
3098fcf3ce44SJohn Forte *
3099fcf3ce44SJohn Forte * setup_parent_lcp:
3100fcf3ce44SJohn Forte * prepare the lookup control data for looking up parent object
3101fcf3ce44SJohn Forte * with a child object.
3102fcf3ce44SJohn Forte *
3103fcf3ce44SJohn Forte * lcp - the lookup control data.
3104fcf3ce44SJohn Forte * obj - the child object.
3105fcf3ce44SJohn Forte * return - parent object UID.
3106fcf3ce44SJohn Forte *
3107fcf3ce44SJohn Forte * ****************************************************************************
3108fcf3ce44SJohn Forte */
3109fcf3ce44SJohn Forte static uint32_t
setup_parent_lcp(lookup_ctrl_t * lcp,isns_obj_t * obj)3110fcf3ce44SJohn Forte setup_parent_lcp(
3111fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
3112fcf3ce44SJohn Forte isns_obj_t *obj
3113fcf3ce44SJohn Forte )
3114fcf3ce44SJohn Forte {
3115fcf3ce44SJohn Forte isns_type_t ptype;
3116fcf3ce44SJohn Forte uint32_t puid;
3117fcf3ce44SJohn Forte
3118fcf3ce44SJohn Forte puid = get_parent_uid(obj);
3119fcf3ce44SJohn Forte if (puid != 0) {
3120fcf3ce44SJohn Forte ptype = TYPE_OF_PARENT[obj->type];
3121fcf3ce44SJohn Forte SET_UID_LCP(lcp, ptype, puid);
3122fcf3ce44SJohn Forte lcp->data[1].ui = obj->type;
3123fcf3ce44SJohn Forte lcp->data[2].ui = get_obj_uid(obj);
3124fcf3ce44SJohn Forte }
3125fcf3ce44SJohn Forte
3126fcf3ce44SJohn Forte return (puid);
3127fcf3ce44SJohn Forte }
3128fcf3ce44SJohn Forte
3129fcf3ce44SJohn Forte static int
cb_get_parent(void * p1,void * p2)3130fcf3ce44SJohn Forte cb_get_parent(
3131fcf3ce44SJohn Forte void *p1,
3132fcf3ce44SJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
3133fcf3ce44SJohn Forte void *p2
3134fcf3ce44SJohn Forte )
3135fcf3ce44SJohn Forte {
3136fcf3ce44SJohn Forte return (get_parent_uid(p1));
3137fcf3ce44SJohn Forte }
3138fcf3ce44SJohn Forte
3139fcf3ce44SJohn Forte static int
cb_node_child(void * p1,void * p2)3140fcf3ce44SJohn Forte cb_node_child(
3141fcf3ce44SJohn Forte void *p1,
3142fcf3ce44SJohn Forte /* LINTED E_FUNC_ARG_UNUSED */
3143fcf3ce44SJohn Forte void *p2
3144fcf3ce44SJohn Forte )
3145fcf3ce44SJohn Forte {
3146fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p1;
3147fcf3ce44SJohn Forte
3148fcf3ce44SJohn Forte uint32_t num, uid;
3149fcf3ce44SJohn Forte
3150fcf3ce44SJohn Forte uint32_t *cuid = get_child_t(obj, OBJ_ISCSI);
3151fcf3ce44SJohn Forte
3152fcf3ce44SJohn Forte if (cuid != NULL) {
3153fcf3ce44SJohn Forte num = *cuid;
3154fcf3ce44SJohn Forte } else {
3155fcf3ce44SJohn Forte num = 0;
3156fcf3ce44SJohn Forte }
3157fcf3ce44SJohn Forte
3158fcf3ce44SJohn Forte while (num > 0) {
3159fcf3ce44SJohn Forte uid = *++cuid;
3160fcf3ce44SJohn Forte if (uid != 0) {
3161fcf3ce44SJohn Forte return (uid);
3162fcf3ce44SJohn Forte }
3163fcf3ce44SJohn Forte num --;
3164fcf3ce44SJohn Forte }
3165fcf3ce44SJohn Forte
3166fcf3ce44SJohn Forte return (0);
3167fcf3ce44SJohn Forte }
3168fcf3ce44SJohn Forte
3169fcf3ce44SJohn Forte /*
3170fcf3ce44SJohn Forte * ****************************************************************************
3171fcf3ce44SJohn Forte *
3172fcf3ce44SJohn Forte * cb_set_ref:
3173fcf3ce44SJohn Forte * callback function which sets the reference bit to 1 according to
3174fcf3ce44SJohn Forte * the type of object.
3175fcf3ce44SJohn Forte *
3176fcf3ce44SJohn Forte * p1 - the object.
3177fcf3ce44SJohn Forte * p2 - the lcp.
3178fcf3ce44SJohn Forte * return - error code.
3179fcf3ce44SJohn Forte *
3180fcf3ce44SJohn Forte * ****************************************************************************
3181fcf3ce44SJohn Forte */
3182fcf3ce44SJohn Forte static int
cb_set_ref(void * p1,void * p2)3183fcf3ce44SJohn Forte cb_set_ref(
3184fcf3ce44SJohn Forte void *p1,
3185fcf3ce44SJohn Forte void *p2
3186fcf3ce44SJohn Forte )
3187fcf3ce44SJohn Forte {
3188fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p1;
3189fcf3ce44SJohn Forte lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
3190fcf3ce44SJohn Forte
3191fcf3ce44SJohn Forte isns_type_t t;
3192fcf3ce44SJohn Forte uint32_t u;
3193fcf3ce44SJohn Forte
3194fcf3ce44SJohn Forte uint32_t *refp;
3195fcf3ce44SJohn Forte
3196fcf3ce44SJohn Forte t = lcp->id[2];
3197fcf3ce44SJohn Forte u = lcp->data[2].ui;
3198fcf3ce44SJohn Forte refp = get_ref_p(obj, t);
3199fcf3ce44SJohn Forte *refp = u;
3200fcf3ce44SJohn Forte
3201fcf3ce44SJohn Forte /* successful */
3202fcf3ce44SJohn Forte return (0);
3203fcf3ce44SJohn Forte }
3204fcf3ce44SJohn Forte
3205fcf3ce44SJohn Forte /*
3206fcf3ce44SJohn Forte * ****************************************************************************
3207fcf3ce44SJohn Forte *
3208fcf3ce44SJohn Forte * cb_clear_ref:
3209fcf3ce44SJohn Forte * callback function which clears the reference bit according to
3210fcf3ce44SJohn Forte * the type of object.
3211fcf3ce44SJohn Forte *
3212fcf3ce44SJohn Forte * p1 - the object.
3213fcf3ce44SJohn Forte * p2 - the lcp.
3214fcf3ce44SJohn Forte * return - 1: the object is no longer ref'ed, 0: otherwise.
3215fcf3ce44SJohn Forte *
3216fcf3ce44SJohn Forte * ****************************************************************************
3217fcf3ce44SJohn Forte */
3218fcf3ce44SJohn Forte static int
cb_clear_ref(void * p1,void * p2)3219fcf3ce44SJohn Forte cb_clear_ref(
3220fcf3ce44SJohn Forte void *p1,
3221fcf3ce44SJohn Forte void *p2
3222fcf3ce44SJohn Forte )
3223fcf3ce44SJohn Forte {
3224fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p1;
3225fcf3ce44SJohn Forte lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
3226fcf3ce44SJohn Forte
3227fcf3ce44SJohn Forte isns_type_t t;
3228fcf3ce44SJohn Forte uint32_t *refp;
3229fcf3ce44SJohn Forte
3230fcf3ce44SJohn Forte int i = 0;
3231fcf3ce44SJohn Forte uint32_t ref;
3232fcf3ce44SJohn Forte
3233fcf3ce44SJohn Forte t = lcp->data[2].ui;
3234fcf3ce44SJohn Forte refp = get_ref_p(obj, t);
3235fcf3ce44SJohn Forte *refp = 0;
3236fcf3ce44SJohn Forte
3237fcf3ce44SJohn Forte while (i < NUM_OF_REF[obj->type]) {
3238fcf3ce44SJohn Forte ref = get_ref_n(obj, i);
3239fcf3ce44SJohn Forte if (ref != 0) {
3240fcf3ce44SJohn Forte return (0);
3241fcf3ce44SJohn Forte }
3242fcf3ce44SJohn Forte i ++;
3243fcf3ce44SJohn Forte }
3244fcf3ce44SJohn Forte
3245fcf3ce44SJohn Forte return (1);
3246fcf3ce44SJohn Forte }
3247fcf3ce44SJohn Forte
3248fcf3ce44SJohn Forte static int
cb_add_child(void * p1,void * p2)3249fcf3ce44SJohn Forte cb_add_child(
3250fcf3ce44SJohn Forte void *p1,
3251fcf3ce44SJohn Forte void *p2
3252fcf3ce44SJohn Forte )
3253fcf3ce44SJohn Forte {
3254fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p1;
3255fcf3ce44SJohn Forte lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
3256fcf3ce44SJohn Forte
3257fcf3ce44SJohn Forte const void ***child;
3258fcf3ce44SJohn Forte const void **vpp;
3259fcf3ce44SJohn Forte uint32_t vnum;
3260fcf3ce44SJohn Forte int child_flag;
3261fcf3ce44SJohn Forte
3262fcf3ce44SJohn Forte uint32_t **upp, *up;
3263fcf3ce44SJohn Forte uint32_t num;
3264fcf3ce44SJohn Forte
3265fcf3ce44SJohn Forte isns_obj_t *o;
3266fcf3ce44SJohn Forte
3267fcf3ce44SJohn Forte int i = 0;
3268fcf3ce44SJohn Forte
3269fcf3ce44SJohn Forte child = (const void ***)lcp->data[1].ptr;
3270fcf3ce44SJohn Forte child_flag = lcp->data[2].ui;
3271fcf3ce44SJohn Forte
3272fcf3ce44SJohn Forte while (i < NUM_OF_CHILD[obj->type]) {
3273fcf3ce44SJohn Forte vpp = child[i];
3274fcf3ce44SJohn Forte if (vpp != NULL &&
3275fcf3ce44SJohn Forte (vnum = (uint32_t)*vpp) > 0 &&
3276fcf3ce44SJohn Forte *(vpp + 1) != NULL) {
3277fcf3ce44SJohn Forte upp = get_child_np(obj, i);
3278fcf3ce44SJohn Forte if (*upp == NULL) {
3279fcf3ce44SJohn Forte if (child_flag == 0 &&
3280fcf3ce44SJohn Forte sizeof (typeof (**upp)) ==
3281fcf3ce44SJohn Forte sizeof (typeof (**child))) {
3282fcf3ce44SJohn Forte *upp = (uint32_t *)vpp;
3283fcf3ce44SJohn Forte vpp = NULL;
3284fcf3ce44SJohn Forte child[i] = NULL;
3285fcf3ce44SJohn Forte }
3286fcf3ce44SJohn Forte num = vnum;
3287fcf3ce44SJohn Forte } else {
3288fcf3ce44SJohn Forte num = **upp + vnum;
3289fcf3ce44SJohn Forte }
3290fcf3ce44SJohn Forte if (vpp != NULL) {
3291fcf3ce44SJohn Forte /* copy required */
3292fcf3ce44SJohn Forte up = (uint32_t *)realloc(*upp,
3293fcf3ce44SJohn Forte (num + 1) * sizeof (uint32_t));
3294fcf3ce44SJohn Forte if (up == NULL) {
3295fcf3ce44SJohn Forte return (ISNS_RSP_INTERNAL_ERROR);
3296fcf3ce44SJohn Forte }
3297fcf3ce44SJohn Forte *upp = up;
3298fcf3ce44SJohn Forte *up = num;
3299fcf3ce44SJohn Forte up += num;
3300fcf3ce44SJohn Forte vpp += vnum;
3301fcf3ce44SJohn Forte while (vnum > 0) {
3302fcf3ce44SJohn Forte if (*vpp == NULL) {
3303fcf3ce44SJohn Forte *up = 0;
3304fcf3ce44SJohn Forte } else if (child_flag == 0) {
3305fcf3ce44SJohn Forte *up = (uint32_t)*vpp;
3306fcf3ce44SJohn Forte *vpp = NULL;
3307fcf3ce44SJohn Forte } else {
3308fcf3ce44SJohn Forte o = (isns_obj_t *)*vpp;
3309fcf3ce44SJohn Forte *up = get_obj_uid(o);
3310fcf3ce44SJohn Forte if (is_obj_online(o) == 0) {
3311fcf3ce44SJohn Forte free_object(o);
3312fcf3ce44SJohn Forte }
3313fcf3ce44SJohn Forte *vpp = NULL;
3314fcf3ce44SJohn Forte }
3315fcf3ce44SJohn Forte up --;
3316fcf3ce44SJohn Forte vpp --;
3317fcf3ce44SJohn Forte vnum --;
3318fcf3ce44SJohn Forte }
3319fcf3ce44SJohn Forte }
3320fcf3ce44SJohn Forte }
3321fcf3ce44SJohn Forte i ++;
3322fcf3ce44SJohn Forte }
3323fcf3ce44SJohn Forte
3324fcf3ce44SJohn Forte return (0);
3325fcf3ce44SJohn Forte }
3326fcf3ce44SJohn Forte
3327fcf3ce44SJohn Forte /*
3328fcf3ce44SJohn Forte * ****************************************************************************
3329fcf3ce44SJohn Forte *
3330fcf3ce44SJohn Forte * cb_remove_child:
3331fcf3ce44SJohn Forte * callback function which removes a child object UID from the
3332fcf3ce44SJohn Forte * children objet UID array of the parent object.
3333fcf3ce44SJohn Forte *
3334fcf3ce44SJohn Forte * p1 - the object.
3335fcf3ce44SJohn Forte * p2 - the lcp.
3336fcf3ce44SJohn Forte * return - 1: no more such type of child object, 0: otherwise.
3337fcf3ce44SJohn Forte *
3338fcf3ce44SJohn Forte * ****************************************************************************
3339fcf3ce44SJohn Forte */
3340fcf3ce44SJohn Forte static int
cb_remove_child(void * p1,void * p2)3341fcf3ce44SJohn Forte cb_remove_child(
3342fcf3ce44SJohn Forte void *p1,
3343fcf3ce44SJohn Forte void *p2
3344fcf3ce44SJohn Forte )
3345fcf3ce44SJohn Forte {
3346fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p1;
3347fcf3ce44SJohn Forte lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
3348fcf3ce44SJohn Forte uint32_t child_type = lcp->data[1].ui;
3349fcf3ce44SJohn Forte uint32_t child_uid = lcp->data[2].ui;
3350fcf3ce44SJohn Forte uint32_t *cuidp, cuid, num_of_child = 0;
3351fcf3ce44SJohn Forte int i;
3352fcf3ce44SJohn Forte
3353fcf3ce44SJohn Forte /* get the children object UID array */
3354fcf3ce44SJohn Forte cuidp = get_child_t(obj, child_type);
3355fcf3ce44SJohn Forte if (cuidp != NULL) {
3356fcf3ce44SJohn Forte num_of_child = *cuidp;
3357fcf3ce44SJohn Forte }
3358fcf3ce44SJohn Forte
3359fcf3ce44SJohn Forte /* remove it */
3360fcf3ce44SJohn Forte while (num_of_child > 0) {
3361fcf3ce44SJohn Forte cuid = *++cuidp;
3362fcf3ce44SJohn Forte if (cuid == child_uid) {
3363fcf3ce44SJohn Forte *cuidp = 0;
3364fcf3ce44SJohn Forte break;
3365fcf3ce44SJohn Forte }
3366fcf3ce44SJohn Forte num_of_child --;
3367fcf3ce44SJohn Forte }
3368fcf3ce44SJohn Forte
3369fcf3ce44SJohn Forte /* check if all of child object UIDs are removed */
3370fcf3ce44SJohn Forte i = 0;
3371fcf3ce44SJohn Forte while (i < NUM_OF_CHILD[obj->type]) {
3372fcf3ce44SJohn Forte cuidp = get_child_n(obj, i);
3373fcf3ce44SJohn Forte if (cuidp != NULL) {
3374fcf3ce44SJohn Forte num_of_child = *cuidp;
3375fcf3ce44SJohn Forte while (num_of_child > 0) {
3376fcf3ce44SJohn Forte cuid = *++cuidp;
3377fcf3ce44SJohn Forte if (cuid != 0) {
3378fcf3ce44SJohn Forte return (0);
3379fcf3ce44SJohn Forte }
3380fcf3ce44SJohn Forte num_of_child --;
3381fcf3ce44SJohn Forte }
3382fcf3ce44SJohn Forte }
3383fcf3ce44SJohn Forte i ++;
3384fcf3ce44SJohn Forte }
3385fcf3ce44SJohn Forte
3386fcf3ce44SJohn Forte return (1);
3387fcf3ce44SJohn Forte }
3388fcf3ce44SJohn Forte
3389fcf3ce44SJohn Forte static int
cb_verify_ref(void * p1,void * p2)3390fcf3ce44SJohn Forte cb_verify_ref(
3391fcf3ce44SJohn Forte void *p1,
3392fcf3ce44SJohn Forte void *p2
3393fcf3ce44SJohn Forte )
3394fcf3ce44SJohn Forte {
3395fcf3ce44SJohn Forte int ec = 0;
3396fcf3ce44SJohn Forte
3397fcf3ce44SJohn Forte isns_obj_t *parent = (isns_obj_t *)p1;
3398fcf3ce44SJohn Forte lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
3399fcf3ce44SJohn Forte
3400fcf3ce44SJohn Forte const void ***child;
3401fcf3ce44SJohn Forte
3402fcf3ce44SJohn Forte const void **vpp;
3403fcf3ce44SJohn Forte const void *vp;
3404fcf3ce44SJohn Forte uint32_t vnum;
3405fcf3ce44SJohn Forte
3406fcf3ce44SJohn Forte const void **evpp;
3407fcf3ce44SJohn Forte const void *evp;
3408fcf3ce44SJohn Forte uint32_t evnum;
3409fcf3ce44SJohn Forte
3410fcf3ce44SJohn Forte isns_type_t pt; /* parent object type */
3411fcf3ce44SJohn Forte isns_type_t ct; /* child object type */
3412fcf3ce44SJohn Forte isns_type_t rt; /* ref object type */
3413fcf3ce44SJohn Forte isns_type_t et; /* peer object type */
3414fcf3ce44SJohn Forte
3415fcf3ce44SJohn Forte uint32_t *up;
3416fcf3ce44SJohn Forte uint32_t u;
3417fcf3ce44SJohn Forte uint32_t unum;
3418fcf3ce44SJohn Forte
3419fcf3ce44SJohn Forte lookup_ctrl_t lc;
3420fcf3ce44SJohn Forte uint8_t flag[MAX_OBJ_TYPE + 1] = { 0 };
3421fcf3ce44SJohn Forte
3422fcf3ce44SJohn Forte int i, j, k;
3423fcf3ce44SJohn Forte
3424fcf3ce44SJohn Forte pt = parent->type;
3425fcf3ce44SJohn Forte
3426fcf3ce44SJohn Forte child = (const void ***)lcp->data[1].ptr;
3427fcf3ce44SJohn Forte
3428fcf3ce44SJohn Forte for (i = 0; i < NUM_OF_CHILD[pt]; i++) {
3429fcf3ce44SJohn Forte ct = TYPE_OF_CHILD[pt][i];
3430fcf3ce44SJohn Forte rt = TYPE_OF_REF[ct][0];
3431fcf3ce44SJohn Forte if (rt == 0) {
3432fcf3ce44SJohn Forte continue;
3433fcf3ce44SJohn Forte }
3434fcf3ce44SJohn Forte
3435fcf3ce44SJohn Forte et = TYPE_OF_REF[ct][1];
3436fcf3ce44SJohn Forte vpp = child[i];
3437fcf3ce44SJohn Forte if (vpp != NULL) {
3438fcf3ce44SJohn Forte vnum = (uint32_t)*vpp;
3439fcf3ce44SJohn Forte up = get_child_t(parent, et);
3440fcf3ce44SJohn Forte if (up != NULL) {
3441fcf3ce44SJohn Forte unum = *up;
3442fcf3ce44SJohn Forte } else {
3443fcf3ce44SJohn Forte unum = 0;
3444fcf3ce44SJohn Forte }
3445fcf3ce44SJohn Forte } else {
3446fcf3ce44SJohn Forte vnum = 0;
3447fcf3ce44SJohn Forte }
3448fcf3ce44SJohn Forte
3449fcf3ce44SJohn Forte j = vnum;
3450fcf3ce44SJohn Forte while (j > 0) {
3451fcf3ce44SJohn Forte vp = vpp[j];
3452fcf3ce44SJohn Forte if (vp != NULL) {
3453fcf3ce44SJohn Forte (void) setup_ref_lcp(&lc, vp, NULL);
3454fcf3ce44SJohn Forte k = unum;
3455fcf3ce44SJohn Forte while (k > 0) {
3456fcf3ce44SJohn Forte u = up[k];
3457fcf3ce44SJohn Forte if (u != 0) {
3458fcf3ce44SJohn Forte ec = ref_new2old(
3459fcf3ce44SJohn Forte &lc, et, u, vp);
3460fcf3ce44SJohn Forte if (ec != 0) {
3461fcf3ce44SJohn Forte return (ec);
3462fcf3ce44SJohn Forte }
3463fcf3ce44SJohn Forte }
3464fcf3ce44SJohn Forte k --;
3465fcf3ce44SJohn Forte } /* End of while each unum */
3466fcf3ce44SJohn Forte }
3467fcf3ce44SJohn Forte j --;
3468fcf3ce44SJohn Forte } /* End of while each vnum */
3469fcf3ce44SJohn Forte
3470fcf3ce44SJohn Forte if (flag[ct] != 0) {
3471fcf3ce44SJohn Forte continue;
3472fcf3ce44SJohn Forte }
3473fcf3ce44SJohn Forte
3474fcf3ce44SJohn Forte evnum = 0;
3475fcf3ce44SJohn Forte j = 0;
3476fcf3ce44SJohn Forte while (j < NUM_OF_CHILD[pt]) {
3477fcf3ce44SJohn Forte if (TYPE_OF_CHILD[pt][j] == et) {
3478fcf3ce44SJohn Forte evpp = child[j];
3479fcf3ce44SJohn Forte if (evpp != NULL) {
3480fcf3ce44SJohn Forte evnum = (uint32_t)*evpp;
3481fcf3ce44SJohn Forte }
3482fcf3ce44SJohn Forte break;
3483fcf3ce44SJohn Forte }
3484fcf3ce44SJohn Forte j ++;
3485fcf3ce44SJohn Forte }
3486fcf3ce44SJohn Forte
3487fcf3ce44SJohn Forte j = vnum;
3488fcf3ce44SJohn Forte while (j > 0) {
3489fcf3ce44SJohn Forte vp = vpp[j];
3490fcf3ce44SJohn Forte k = evnum;
3491fcf3ce44SJohn Forte while (k > 0) {
3492fcf3ce44SJohn Forte evp = evpp[k];
3493fcf3ce44SJohn Forte if (vp != NULL && evp != NULL) {
3494fcf3ce44SJohn Forte (void) setup_ref_lcp(&lc, vp, evp);
3495fcf3ce44SJohn Forte ec = ref_new2new(&lc, vp, evp);
3496fcf3ce44SJohn Forte if (ec != 0) {
3497fcf3ce44SJohn Forte return (ec);
3498fcf3ce44SJohn Forte }
3499fcf3ce44SJohn Forte }
3500fcf3ce44SJohn Forte k --;
3501fcf3ce44SJohn Forte }
3502fcf3ce44SJohn Forte j --;
3503fcf3ce44SJohn Forte } /* End of while each vnum */
3504fcf3ce44SJohn Forte
3505fcf3ce44SJohn Forte flag[et] = 1;
3506fcf3ce44SJohn Forte } /* End of for each type of child */
3507fcf3ce44SJohn Forte
3508fcf3ce44SJohn Forte return (ec);
3509fcf3ce44SJohn Forte }
3510fcf3ce44SJohn Forte
3511fcf3ce44SJohn Forte static int
cb_ref_new2old(void * p1,void * p2)3512fcf3ce44SJohn Forte cb_ref_new2old(
3513fcf3ce44SJohn Forte void *p1,
3514fcf3ce44SJohn Forte void *p2
3515fcf3ce44SJohn Forte )
3516fcf3ce44SJohn Forte {
3517fcf3ce44SJohn Forte isns_obj_t *obj = (isns_obj_t *)p1;
3518fcf3ce44SJohn Forte lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
3519fcf3ce44SJohn Forte
3520fcf3ce44SJohn Forte isns_type_t et;
3521fcf3ce44SJohn Forte uint32_t uu;
3522fcf3ce44SJohn Forte
3523fcf3ce44SJohn Forte uint32_t ref;
3524fcf3ce44SJohn Forte
3525fcf3ce44SJohn Forte int match;
3526fcf3ce44SJohn Forte
3527fcf3ce44SJohn Forte et = lcp->id[2];
3528fcf3ce44SJohn Forte uu = lcp->data[2].ui;
3529fcf3ce44SJohn Forte
3530fcf3ce44SJohn Forte ref = get_ref_t(obj, et);
3531fcf3ce44SJohn Forte
3532fcf3ce44SJohn Forte if (ref == uu) {
3533fcf3ce44SJohn Forte match = 1;
3534fcf3ce44SJohn Forte } else {
3535fcf3ce44SJohn Forte match = 0;
3536fcf3ce44SJohn Forte }
3537fcf3ce44SJohn Forte
3538fcf3ce44SJohn Forte return (match);
3539fcf3ce44SJohn Forte }
3540fcf3ce44SJohn Forte
3541fcf3ce44SJohn Forte static int
cb_new_ref(void * p1,void * p2)3542fcf3ce44SJohn Forte cb_new_ref(
3543fcf3ce44SJohn Forte void *p1,
3544fcf3ce44SJohn Forte void *p2
3545fcf3ce44SJohn Forte )
3546fcf3ce44SJohn Forte {
3547fcf3ce44SJohn Forte int ec = 0;
3548fcf3ce44SJohn Forte
3549fcf3ce44SJohn Forte lookup_ctrl_t *lcp = (lookup_ctrl_t *)p2;
3550fcf3ce44SJohn Forte isns_obj_t *a = (isns_obj_t *)p1;
3551fcf3ce44SJohn Forte isns_obj_t *b = (isns_obj_t *)lcp->data[2].ptr;
3552fcf3ce44SJohn Forte
3553fcf3ce44SJohn Forte ec = new_ref(a, b);
3554fcf3ce44SJohn Forte
3555fcf3ce44SJohn Forte return (ec);
3556fcf3ce44SJohn Forte }
3557fcf3ce44SJohn Forte
3558fcf3ce44SJohn Forte static int
ref_new2old(lookup_ctrl_t * lcp,isns_type_t et,uint32_t uu,const isns_obj_t * vp)3559fcf3ce44SJohn Forte ref_new2old(
3560fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
3561fcf3ce44SJohn Forte isns_type_t et,
3562fcf3ce44SJohn Forte uint32_t uu,
3563fcf3ce44SJohn Forte const isns_obj_t *vp
3564fcf3ce44SJohn Forte )
3565fcf3ce44SJohn Forte {
3566fcf3ce44SJohn Forte int ec = 0;
3567fcf3ce44SJohn Forte
3568fcf3ce44SJohn Forte int match;
3569fcf3ce44SJohn Forte uint32_t uid;
3570fcf3ce44SJohn Forte
3571fcf3ce44SJohn Forte lookup_ctrl_t lc;
3572fcf3ce44SJohn Forte
3573fcf3ce44SJohn Forte lcp->id[2] = et;
3574fcf3ce44SJohn Forte lcp->data[2].ui = uu;
3575fcf3ce44SJohn Forte
3576fcf3ce44SJohn Forte uid = 0;
3577fcf3ce44SJohn Forte do {
3578fcf3ce44SJohn Forte lcp->curr_uid = uid;
3579fcf3ce44SJohn Forte match = cache_lookup(lcp, &uid, cb_ref_new2old);
3580fcf3ce44SJohn Forte } while (match == 0 && uid != 0);
3581fcf3ce44SJohn Forte
3582fcf3ce44SJohn Forte if (match == 0) {
3583fcf3ce44SJohn Forte /* no such ref, create a default one */
3584fcf3ce44SJohn Forte SET_UID_LCP(&lc, et, uu);
3585fcf3ce44SJohn Forte
3586fcf3ce44SJohn Forte lc.data[2].ptr = (uchar_t *)vp;
3587fcf3ce44SJohn Forte
3588fcf3ce44SJohn Forte ec = cache_lookup(&lc, NULL, cb_new_ref);
3589fcf3ce44SJohn Forte }
3590fcf3ce44SJohn Forte
3591fcf3ce44SJohn Forte return (ec);
3592fcf3ce44SJohn Forte }
3593fcf3ce44SJohn Forte
3594fcf3ce44SJohn Forte static int
ref_new2new(lookup_ctrl_t * lcp,const isns_obj_t * p1,const isns_obj_t * p2)3595fcf3ce44SJohn Forte ref_new2new(
3596fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
3597fcf3ce44SJohn Forte const isns_obj_t *p1,
3598fcf3ce44SJohn Forte const isns_obj_t *p2
3599fcf3ce44SJohn Forte )
3600fcf3ce44SJohn Forte {
3601fcf3ce44SJohn Forte int ec = 0;
3602fcf3ce44SJohn Forte
3603fcf3ce44SJohn Forte if (is_obj_there(lcp) != 0) {
3604fcf3ce44SJohn Forte return (0);
3605fcf3ce44SJohn Forte }
3606fcf3ce44SJohn Forte
3607fcf3ce44SJohn Forte ec = new_ref(p1, p2);
3608fcf3ce44SJohn Forte
3609fcf3ce44SJohn Forte return (ec);
3610fcf3ce44SJohn Forte }
3611fcf3ce44SJohn Forte
3612fcf3ce44SJohn Forte static int
new_ref(const isns_obj_t * p1,const isns_obj_t * p2)3613fcf3ce44SJohn Forte new_ref(
3614fcf3ce44SJohn Forte const isns_obj_t *p1,
3615fcf3ce44SJohn Forte const isns_obj_t *p2
3616fcf3ce44SJohn Forte )
3617fcf3ce44SJohn Forte {
3618fcf3ce44SJohn Forte int ec = 0;
3619fcf3ce44SJohn Forte
3620fcf3ce44SJohn Forte isns_obj_t *obj;
3621fcf3ce44SJohn Forte
3622fcf3ce44SJohn Forte obj = make_ref[p1->type](p1, p2);
3623fcf3ce44SJohn Forte if (obj != NULL) {
3624fcf3ce44SJohn Forte ec = register_object(obj, NULL, NULL);
3625fcf3ce44SJohn Forte } else {
3626fcf3ce44SJohn Forte ec = ISNS_RSP_INTERNAL_ERROR;
3627fcf3ce44SJohn Forte }
3628fcf3ce44SJohn Forte
3629fcf3ce44SJohn Forte return (ec);
3630fcf3ce44SJohn Forte }
3631fcf3ce44SJohn Forte
3632fcf3ce44SJohn Forte /*
3633fcf3ce44SJohn Forte * ****************************************************************************
3634fcf3ce44SJohn Forte *
3635fcf3ce44SJohn Forte * do_dereg:
3636fcf3ce44SJohn Forte * Physically remove an object along with the children objects,
3637fcf3ce44SJohn Forte * the reference object and the parent object recursively.
3638fcf3ce44SJohn Forte * Apporiate SCN is triggered.
3639fcf3ce44SJohn Forte *
3640fcf3ce44SJohn Forte * lcp - the lookup control for the object being removed.
3641fcf3ce44SJohn Forte * parent_flag - 1: the object being removed is the parent object;
3642fcf3ce44SJohn Forte * 0: otherwise.
3643fcf3ce44SJohn Forte * child_flag - 1: the object being removed is a child object;
3644fcf3ce44SJohn Forte * 0: otherwise.
3645fcf3ce44SJohn Forte * pending - 1: do not remove the ESI entry immediately;
3646fcf3ce44SJohn Forte * 0: remove the ESI entry without any delay.
3647fcf3ce44SJohn Forte * return - error code.
3648fcf3ce44SJohn Forte *
3649fcf3ce44SJohn Forte * ****************************************************************************
3650fcf3ce44SJohn Forte */
3651fcf3ce44SJohn Forte static int
do_dereg(lookup_ctrl_t * lcp,int parent_flag,int child_flag,int pending)3652fcf3ce44SJohn Forte do_dereg(
3653fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
3654fcf3ce44SJohn Forte int parent_flag,
3655fcf3ce44SJohn Forte int child_flag,
3656fcf3ce44SJohn Forte int pending
3657fcf3ce44SJohn Forte )
3658fcf3ce44SJohn Forte {
3659fcf3ce44SJohn Forte int ec = 0;
3660fcf3ce44SJohn Forte
3661fcf3ce44SJohn Forte isns_obj_t *obj;
3662fcf3ce44SJohn Forte uint32_t *cuidp, num;
3663fcf3ce44SJohn Forte isns_type_t type;
3664fcf3ce44SJohn Forte uint32_t uid;
3665fcf3ce44SJohn Forte int i;
3666fcf3ce44SJohn Forte
3667fcf3ce44SJohn Forte /* remove the object from object container */
3668fcf3ce44SJohn Forte obj = cache_remove(lcp, 0);
3669fcf3ce44SJohn Forte
3670fcf3ce44SJohn Forte if (obj == NULL) {
3671fcf3ce44SJohn Forte return (0);
3672fcf3ce44SJohn Forte }
3673fcf3ce44SJohn Forte
3674fcf3ce44SJohn Forte /* trigger a scn */
3675fcf3ce44SJohn Forte if (scn_q != NULL) {
3676fcf3ce44SJohn Forte (void) make_scn(ISNS_OBJECT_REMOVED, obj);
3677fcf3ce44SJohn Forte }
3678fcf3ce44SJohn Forte
3679fcf3ce44SJohn Forte /* dereg children */
3680fcf3ce44SJohn Forte i = 0;
3681fcf3ce44SJohn Forte while (ec == 0 && !parent_flag &&
3682fcf3ce44SJohn Forte i < NUM_OF_CHILD[obj->type]) {
3683fcf3ce44SJohn Forte type = TYPE_OF_CHILD[obj->type][i];
3684fcf3ce44SJohn Forte cuidp = get_child_n(obj, i);
3685fcf3ce44SJohn Forte if (cuidp != NULL) {
3686fcf3ce44SJohn Forte num = *cuidp;
3687fcf3ce44SJohn Forte } else {
3688fcf3ce44SJohn Forte num = 0;
3689fcf3ce44SJohn Forte }
3690fcf3ce44SJohn Forte while (ec == 0 && num > 0) {
3691fcf3ce44SJohn Forte uid = cuidp[num];
3692fcf3ce44SJohn Forte if (uid != 0) {
3693fcf3ce44SJohn Forte SET_UID_LCP(lcp, type, uid);
3694fcf3ce44SJohn Forte ec = do_dereg(lcp,
3695fcf3ce44SJohn Forte parent_flag,
3696fcf3ce44SJohn Forte 1,
3697fcf3ce44SJohn Forte pending);
3698fcf3ce44SJohn Forte }
3699fcf3ce44SJohn Forte num --;
3700fcf3ce44SJohn Forte }
3701fcf3ce44SJohn Forte i ++;
3702fcf3ce44SJohn Forte }
3703fcf3ce44SJohn Forte
3704fcf3ce44SJohn Forte /* clear the ref bit on the ref'd object */
3705fcf3ce44SJohn Forte if (ec == 0 && TYPE_OF_REF[obj->type][0] > 0) {
3706fcf3ce44SJohn Forte uid = 0;
3707fcf3ce44SJohn Forte do {
3708fcf3ce44SJohn Forte (void) setup_ref_lcp(lcp, obj, NULL);
3709fcf3ce44SJohn Forte lcp->curr_uid = uid;
3710fcf3ce44SJohn Forte lcp->data[2].ui = obj->type;
3711fcf3ce44SJohn Forte if (cache_lookup(lcp, &uid, cb_clear_ref) != 0) {
3712fcf3ce44SJohn Forte UPDATE_LCP_UID(lcp, uid);
3713fcf3ce44SJohn Forte ec = do_dereg(lcp,
3714fcf3ce44SJohn Forte parent_flag,
3715fcf3ce44SJohn Forte child_flag,
3716fcf3ce44SJohn Forte pending);
3717fcf3ce44SJohn Forte }
3718fcf3ce44SJohn Forte } while (uid != 0);
3719fcf3ce44SJohn Forte }
3720fcf3ce44SJohn Forte
3721fcf3ce44SJohn Forte /* remove it from the parent */
3722fcf3ce44SJohn Forte if (ec == 0 && !child_flag &&
3723fcf3ce44SJohn Forte TYPE_OF_PARENT[obj->type] > 0 &&
3724fcf3ce44SJohn Forte (uid = setup_parent_lcp(lcp, obj)) != 0) {
3725fcf3ce44SJohn Forte if (cache_lookup(lcp, NULL, cb_remove_child) != 0) {
3726fcf3ce44SJohn Forte UPDATE_LCP_UID(lcp, uid);
3727fcf3ce44SJohn Forte ec = do_dereg(lcp,
3728fcf3ce44SJohn Forte 1,
3729fcf3ce44SJohn Forte child_flag,
3730fcf3ce44SJohn Forte 0);
3731fcf3ce44SJohn Forte }
3732fcf3ce44SJohn Forte }
3733fcf3ce44SJohn Forte
3734fcf3ce44SJohn Forte if (ec == 0 && !child_flag) {
3735fcf3ce44SJohn Forte /* remove it from persistent data store */
3736fcf3ce44SJohn Forte if (sys_q) {
3737fcf3ce44SJohn Forte ec = write_data(DATA_DELETE, obj);
3738fcf3ce44SJohn Forte }
3739fcf3ce44SJohn Forte /* remove esi event entry */
3740fcf3ce44SJohn Forte if (ec == 0) {
3741fcf3ce44SJohn Forte (void) esi_remove_obj(obj, pending);
3742fcf3ce44SJohn Forte }
3743fcf3ce44SJohn Forte
3744fcf3ce44SJohn Forte /* save the parent uid for caller */
3745fcf3ce44SJohn Forte if (TYPE_OF_PARENT[obj->type] != 0) {
3746fcf3ce44SJohn Forte lcp->curr_uid = get_parent_uid(obj);
3747fcf3ce44SJohn Forte } else {
3748fcf3ce44SJohn Forte /* it's the parent itself */
3749fcf3ce44SJohn Forte lcp->curr_uid = get_obj_uid(obj);
3750fcf3ce44SJohn Forte }
3751fcf3ce44SJohn Forte }
3752fcf3ce44SJohn Forte
3753fcf3ce44SJohn Forte /* remove this portal from scn registry */
3754fcf3ce44SJohn Forte if (ec == 0 &&
3755fcf3ce44SJohn Forte obj->type == OBJ_PORTAL) {
3756fcf3ce44SJohn Forte (void) remove_scn_portal(get_obj_uid(obj));
3757fcf3ce44SJohn Forte }
3758fcf3ce44SJohn Forte
3759fcf3ce44SJohn Forte /* free the object */
3760fcf3ce44SJohn Forte (void) free_object(obj);
3761fcf3ce44SJohn Forte
3762fcf3ce44SJohn Forte return (ec);
3763fcf3ce44SJohn Forte }
3764fcf3ce44SJohn Forte
3765fcf3ce44SJohn Forte /*
3766fcf3ce44SJohn Forte * ****************************************************************************
3767fcf3ce44SJohn Forte *
3768fcf3ce44SJohn Forte * dereg_assoc:
3769fcf3ce44SJohn Forte * Remove one association object from object container.
3770fcf3ce44SJohn Forte *
3771fcf3ce44SJohn Forte * lcp - the lookup control for the object being removed.
3772fcf3ce44SJohn Forte * return - error code.
3773fcf3ce44SJohn Forte *
3774fcf3ce44SJohn Forte * ****************************************************************************
3775fcf3ce44SJohn Forte */
3776fcf3ce44SJohn Forte int
dereg_assoc(lookup_ctrl_t * lcp)3777fcf3ce44SJohn Forte dereg_assoc(
3778fcf3ce44SJohn Forte lookup_ctrl_t *lcp
3779fcf3ce44SJohn Forte )
3780fcf3ce44SJohn Forte {
3781fcf3ce44SJohn Forte isns_obj_t *obj;
3782fcf3ce44SJohn Forte
3783fcf3ce44SJohn Forte obj = cache_remove(lcp, 1);
3784fcf3ce44SJohn Forte
3785fcf3ce44SJohn Forte /* free the object */
3786fcf3ce44SJohn Forte if (obj != NULL) {
3787fcf3ce44SJohn Forte free_object(obj);
3788fcf3ce44SJohn Forte }
3789fcf3ce44SJohn Forte
3790fcf3ce44SJohn Forte return (0);
3791fcf3ce44SJohn Forte }
3792fcf3ce44SJohn Forte
3793fcf3ce44SJohn Forte /*
3794fcf3ce44SJohn Forte * ****************************************************************************
3795fcf3ce44SJohn Forte *
3796fcf3ce44SJohn Forte * dereg_object:
3797fcf3ce44SJohn Forte * Remove one object from object container.
3798fcf3ce44SJohn Forte *
3799fcf3ce44SJohn Forte * lcp - the lookup control for the object being removed.
3800fcf3ce44SJohn Forte * return - error code.
3801fcf3ce44SJohn Forte *
3802fcf3ce44SJohn Forte * ****************************************************************************
3803fcf3ce44SJohn Forte */
3804fcf3ce44SJohn Forte int
dereg_object(lookup_ctrl_t * lcp,int pending)3805fcf3ce44SJohn Forte dereg_object(
3806fcf3ce44SJohn Forte lookup_ctrl_t *lcp,
3807fcf3ce44SJohn Forte int pending
3808fcf3ce44SJohn Forte )
3809fcf3ce44SJohn Forte {
3810fcf3ce44SJohn Forte return (do_dereg(lcp, 0, 0, pending));
3811fcf3ce44SJohn Forte }
3812fcf3ce44SJohn Forte
3813fcf3ce44SJohn Forte /*
3814fcf3ce44SJohn Forte * ****************************************************************************
3815fcf3ce44SJohn Forte *
3816fcf3ce44SJohn Forte * data_sync:
3817fcf3ce44SJohn Forte * Synchronize the cache with persistent data store.
3818fcf3ce44SJohn Forte * Flush the cache data to data store if the input ec is zero,
3819fcf3ce44SJohn Forte * retreat the changes in cache and ignore data store update
3820fcf3ce44SJohn Forte * if there is an error.
3821fcf3ce44SJohn Forte *
3822fcf3ce44SJohn Forte * ec - error code.
3823fcf3ce44SJohn Forte * return - error code.
3824fcf3ce44SJohn Forte *
3825fcf3ce44SJohn Forte * ****************************************************************************
3826fcf3ce44SJohn Forte */
3827fcf3ce44SJohn Forte int
data_sync(int ec)3828fcf3ce44SJohn Forte data_sync(
3829fcf3ce44SJohn Forte int ec
3830fcf3ce44SJohn Forte )
3831fcf3ce44SJohn Forte {
3832fcf3ce44SJohn Forte /* cache is updated successfully, commit the data to data store */
3833fcf3ce44SJohn Forte if (IS_CACHE_UPDATED()) {
3834fcf3ce44SJohn Forte if (ec == 0) {
3835fcf3ce44SJohn Forte ec = write_data(DATA_COMMIT, NULL);
3836fcf3ce44SJohn Forte }
3837fcf3ce44SJohn Forte if (ec == 0) {
3838fcf3ce44SJohn Forte /* successful, trigger the SCN */
3839fcf3ce44SJohn Forte (void) queue_msg_set(scn_q, SCN_TRIGGER, (void *)NULL);
3840fcf3ce44SJohn Forte } else {
3841fcf3ce44SJohn Forte shutdown_server();
3842fcf3ce44SJohn Forte }
3843fcf3ce44SJohn Forte } else {
3844fcf3ce44SJohn Forte /* ignore all SCNs which have been generated */
3845fcf3ce44SJohn Forte (void) queue_msg_set(scn_q, SCN_IGNORE, (void *)NULL);
3846fcf3ce44SJohn Forte
3847fcf3ce44SJohn Forte (void) write_data(DATA_RETREAT, NULL);
3848fcf3ce44SJohn Forte }
3849fcf3ce44SJohn Forte
3850fcf3ce44SJohn Forte return (ec);
3851fcf3ce44SJohn Forte }
3852fcf3ce44SJohn Forte
3853fcf3ce44SJohn Forte static pthread_mutex_t name_mtx[3] = {
3854fcf3ce44SJohn Forte PTHREAD_MUTEX_INITIALIZER,
3855fcf3ce44SJohn Forte PTHREAD_MUTEX_INITIALIZER,
3856fcf3ce44SJohn Forte PTHREAD_MUTEX_INITIALIZER
3857fcf3ce44SJohn Forte };
3858fcf3ce44SJohn Forte static const char *name_pattern[3] = {
3859fcf3ce44SJohn Forte "ENTITY_ID_%d",
3860fcf3ce44SJohn Forte "DD_%d",
3861fcf3ce44SJohn Forte "DD-Set_%d"
3862fcf3ce44SJohn Forte };
3863fcf3ce44SJohn Forte static uint32_t name_count[3] = {
3864fcf3ce44SJohn Forte 0,
3865fcf3ce44SJohn Forte 0,
3866fcf3ce44SJohn Forte 0
3867fcf3ce44SJohn Forte };
3868fcf3ce44SJohn Forte
3869fcf3ce44SJohn Forte /*
3870fcf3ce44SJohn Forte * ****************************************************************************
3871fcf3ce44SJohn Forte *
3872fcf3ce44SJohn Forte * make_unique_name:
3873fcf3ce44SJohn Forte * make a default unique name for a newly registered network entity,
3874fcf3ce44SJohn Forte * discovery domain or discovery domain set object.
3875fcf3ce44SJohn Forte *
3876fcf3ce44SJohn Forte * len - pointer of the length of the new name for returning.
3877fcf3ce44SJohn Forte * tag - which attribute of the new name is for.
3878fcf3ce44SJohn Forte * return - the name being made.
3879fcf3ce44SJohn Forte *
3880fcf3ce44SJohn Forte * ****************************************************************************
3881fcf3ce44SJohn Forte */
3882fcf3ce44SJohn Forte static char *
make_unique_name(int * len,uint32_t tag)3883fcf3ce44SJohn Forte make_unique_name(
3884fcf3ce44SJohn Forte int *len,
3885fcf3ce44SJohn Forte uint32_t tag
3886fcf3ce44SJohn Forte )
3887fcf3ce44SJohn Forte {
3888fcf3ce44SJohn Forte int i;
3889fcf3ce44SJohn Forte int count;
3890fcf3ce44SJohn Forte char name[32] = { 0 };
3891fcf3ce44SJohn Forte
3892fcf3ce44SJohn Forte char *p;
3893fcf3ce44SJohn Forte
3894fcf3ce44SJohn Forte lookup_ctrl_t lc;
3895fcf3ce44SJohn Forte
3896fcf3ce44SJohn Forte lc.curr_uid = 0;
3897fcf3ce44SJohn Forte
3898fcf3ce44SJohn Forte switch (tag) {
3899fcf3ce44SJohn Forte case ISNS_EID_ATTR_ID:
3900fcf3ce44SJohn Forte i = 0;
3901fcf3ce44SJohn Forte lc.type = OBJ_ENTITY;
3902fcf3ce44SJohn Forte lc.id[0] = ATTR_INDEX_ENTITY(ISNS_EID_ATTR_ID);
3903fcf3ce44SJohn Forte break;
3904fcf3ce44SJohn Forte case ISNS_DD_NAME_ATTR_ID:
3905fcf3ce44SJohn Forte i = 1;
3906fcf3ce44SJohn Forte lc.type = OBJ_DD;
3907fcf3ce44SJohn Forte lc.id[0] = ATTR_INDEX_DD(ISNS_DD_NAME_ATTR_ID);
3908fcf3ce44SJohn Forte break;
3909fcf3ce44SJohn Forte case ISNS_DD_SET_NAME_ATTR_ID:
3910fcf3ce44SJohn Forte i = 2;
3911fcf3ce44SJohn Forte lc.type = OBJ_DDS;
3912fcf3ce44SJohn Forte lc.id[0] = ATTR_INDEX_DDS(ISNS_DD_SET_NAME_ATTR_ID);
3913fcf3ce44SJohn Forte break;
3914fcf3ce44SJohn Forte default:
3915fcf3ce44SJohn Forte ASSERT(0);
3916fcf3ce44SJohn Forte break;
3917fcf3ce44SJohn Forte }
3918fcf3ce44SJohn Forte
3919fcf3ce44SJohn Forte lc.op[0] = OP_STRING;
3920fcf3ce44SJohn Forte lc.op[1] = 0;
3921fcf3ce44SJohn Forte do {
3922fcf3ce44SJohn Forte (void) pthread_mutex_lock(&name_mtx[i]);
3923fcf3ce44SJohn Forte count = ++ name_count[i];
3924fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&name_mtx[i]);
3925fcf3ce44SJohn Forte /* no more space, failure */
3926fcf3ce44SJohn Forte if (count == 0) {
3927fcf3ce44SJohn Forte return (NULL);
3928fcf3ce44SJohn Forte }
3929fcf3ce44SJohn Forte (void) sprintf(name, name_pattern[i], count);
3930fcf3ce44SJohn Forte lc.data[0].ptr = (uchar_t *)name;
3931fcf3ce44SJohn Forte } while (is_obj_there(&lc) != 0);
3932fcf3ce44SJohn Forte
3933fcf3ce44SJohn Forte /* 4-bytes aligned length */
3934fcf3ce44SJohn Forte *len = strlen(name);
3935fcf3ce44SJohn Forte *len = *len + (4 - *len % 4);
3936fcf3ce44SJohn Forte p = (char *)malloc(*len);
3937fcf3ce44SJohn Forte if (p != NULL) {
3938fcf3ce44SJohn Forte (void) strcpy(p, name);
3939fcf3ce44SJohn Forte }
3940fcf3ce44SJohn Forte return (p);
3941fcf3ce44SJohn Forte }
3942fcf3ce44SJohn Forte
3943fcf3ce44SJohn Forte #ifdef DEBUG
3944fcf3ce44SJohn Forte void
obj_dump(void * p)3945fcf3ce44SJohn Forte obj_dump(
3946fcf3ce44SJohn Forte void *p
3947fcf3ce44SJohn Forte )
3948fcf3ce44SJohn Forte {
3949fcf3ce44SJohn Forte print_object(NULL, (isns_obj_t *)p);
3950fcf3ce44SJohn Forte }
3951fcf3ce44SJohn Forte #endif
3952