a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER START
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The contents of this file are subject to the terms of the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Common Development and Distribution License (the "License").
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You may not use this file except in compliance with the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * See the License for the specific language governing permissions
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * and limitations under the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * When distributing Covered Code, include this CDDL HEADER in each
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If applicable, add the following below this CDDL HEADER, with the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * fields enclosed by brackets "[]" replaced with your own identifying
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * information: Portions Copyright [yyyy] [name of copyright owner]
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER END
42bf653b44c42fc6b637ae50e590489d69399241Peter Gill * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fd76205d7372b305e64b7cfcd27939a39c743cb4Saso Kiselkov * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* From iscsitgtd */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* this should be defined someplace central... */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* max length of a base64 encoded secret */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* Default RADIUS server port */
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson/* The iscsit SMF service FMRI */
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson#define ISCSIT_FMRI "svc:/network/iscsi/target:default"
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The kernel reserves target portal group tag value 1 as the default.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* helper for property list validation */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* helper function declarations */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_iqn_generate(char *iqn_buf, int iqn_buf_len, char *opt_iqn_suffix);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_val_pass(char *name, char *val, nvlist_t *e);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* consider making validate funcs public */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_validate_configprops(nvlist_t *nvl, nvlist_t *errs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_validate_tgtprops(nvlist_t *nvl, nvlist_t *errs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_validate_iniprops(nvlist_t *nvl, nvlist_t *errs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Allocate and create an it_config_t structure representing the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * current iSCSI configuration. This structure is compiled using
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the 'provider' data returned by stmfGetProviderData(). If there
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is no provider data associated with iscsit, the it_config_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * structure will be set to a default configuration.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg A C representation of the current iSCSI configuration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ENOMEM Could not allocate resources
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid parameter
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = stmfGetProviderDataProt(ISCSIT_MODNAME, &cfg_nv,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If not initialized yet, return empty it_config_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Else, convert nvlist to struct
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_config_commit()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Informs the iscsit service that the configuration has changed and
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * commits the new configuration to persistent store by calling
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * stmfSetProviderData. This function can be called multiple times
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * during a configuration sequence if necessary.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg A C representation of the current iSCSI configuration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ENOMEM Could not allocate resources
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid it_config_t structure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * TBD ioctl() failed
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * TBD could not save config to STMF
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_size(cfgnv, &pnv_size, NV_ENCODE_NATIVE);
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson * If the iscsit service is enabled, send the changes to the
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson * kernel first. Kernel will be the final sanity check before
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson * the config is saved persistently.
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson * This somewhat leaves open the simultaneous-change hole
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson * that STMF was trying to solve, but is a better sanity
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson * check and allows for graceful handling of target renames.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Before saving the config persistently, remove any
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * PROP_OLD_TARGET_NAME entries. This is only interesting to
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the active service.
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson /* rebuild the config nvlist */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * stmfGetProviderDataProt() checks to ensure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * that the config data hasn't changed since we fetched it.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The kernel now has a version we need to save persistently.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CLI will 'do the right thing' and warn the user if it
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * gets STMF_ERROR_PROV_DATA_STALE. We'll try once to revert
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the kernel to the persistently saved data, but ultimately,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it's up to the administrator to validate things are as they
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * want them to be.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = stmfSetProviderDataProt(ISCSIT_MODNAME, cfgnv,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (ret == STMF_ERROR_PROV_DATA_STALE) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_config_setprop()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Validate the provided property list and set the global properties
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * for iSCSI Target. If errlist is not NULL, returns detailed
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * errors for each property that failed. The format for errorlist
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is key = property, value = error string.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * proplist nvlist_t containing properties for this target.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * errlist (optional) nvlist_t of errors encountered when
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * validating the properties.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid property
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_config_setprop(it_config_t *cfg, nvlist_t *proplist, nvlist_t **errlist)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * copy the existing properties, merge, then validate
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the merged properties before committing them.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_dup(cfg->config_global_properties, &cprops, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_alloc(&cprops, NV_UNIQUE_NAME, 0);
7f6f3ee7534143c5c719c28315b305ffa5e252b1Peter Gill * base64 encode the radius secret, if it's changed.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_lookup_string(proplist, PROP_RADIUS_SECRET, &val);
8175704f100a4d28687a2b2df9563d67194962bdPeter Gill ret = it_val_pass(PROP_RADIUS_SECRET, val, errs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = iscsi_binary_to_base64_str((uint8_t *)val,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* replace the value in the nvlist */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* see if we need to remove the radius server setting */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_lookup_string(cprops, PROP_RADIUS_SERVER, &val);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_remove_all(cprops, PROP_RADIUS_SERVER);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* and/or remove the alias */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_lookup_string(cprops, PROP_ALIAS, &val);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Update iSNS server list, if exists in provided property list.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_lookup_string_array(proplist, PROP_ISNS_SERVER,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* special case: if "none", remove all defined */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_DEFAULT_SERVER_PORT, &newisnslist, &newcount);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_remove_all(cprops, PROP_ISNS_SERVER);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Replace the array in the nvlist to ensure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * duplicates are properly removed & port numbers
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * are added.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap for (i = 0; i < newcount; i++) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* not an error */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* replace the global properties list */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_config_free()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Free any resources associated with the it_config_t structure.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg A C representation of the current iSCSI configuration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tgt_create()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Allocate and create an it_tgt_t structure representing a new iSCSI
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target node. If tgt_name is NULL, then a unique target node name will
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * be generated automatically. Otherwise, the value of tgt_name will be
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * used as the target node name. The new it_tgt_t structure is added to
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the target list (cfg_tgt_list) in the configuration structure, and the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * new target will not be instantiated until the modified configuration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tgt Pointer to an iSCSI target structure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tgt_name The target node name for the target to be created.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The name must be in either IQN or EUI format. If
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * this value is NULL, a node name will be generated
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * automatically in IQN format.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ENOMEM Could not allocated resources
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid parameter
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EFAULT Invalid iSCSI name specified
836fc322d4b4884a4c64c7b5d172a4a3bb6a5772Sam Cramer * E2BIG Too many already exist
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_tgt_create(it_config_t *cfg, it_tgt_t **tgt, char *tgt_name)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* generate a name */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = it_iqn_generate(buf, sizeof (buf), NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* validate the passed-in name */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* make sure this name isn't already on the list */
fcc214c383d20beb968b623b83d851672e174702Charles Ting if (strcasecmp(namep, cfgtgt->tgt_name) == 0) {
ade94d8b38f784d25f7d2abc544ef161399e22bbCharles Ting /* Too many targets? */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) strlcpy(ptr->tgt_name, namep, sizeof (ptr->tgt_name));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tgt_setprop()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Validate the provided property list and set the properties for
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the specified target. If errlist is not NULL, returns detailed
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * errors for each property that failed. The format for errorlist
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is key = property, value = error string.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tgt Pointer to an iSCSI target structure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * proplist nvlist_t containing properties for this target.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * errlist (optional) nvlist_t of errors encountered when
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * validating the properties.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid property
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_tgt_setprop(it_config_t *cfg, it_tgt_t *tgt, nvlist_t *proplist,
fcc214c383d20beb968b623b83d851672e174702Charles Ting /* verify the target name in case the target node is renamed */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * copy the existing properties, merge, then validate
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the merged properties before committing them.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_dup(tgt->tgt_properties, &tprops, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_alloc(&tprops, NV_UNIQUE_NAME, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* unset chap username or alias if requested */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_lookup_string(proplist, PROP_TARGET_CHAP_USER, &val);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_remove_all(tprops, PROP_TARGET_CHAP_USER);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_lookup_string(proplist, PROP_ALIAS, &val);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* base64 encode the CHAP secret, if it's changed */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_lookup_string(proplist, PROP_TARGET_CHAP_SECRET, &val);
8175704f100a4d28687a2b2df9563d67194962bdPeter Gill ret = it_val_pass(PROP_TARGET_CHAP_SECRET, val, errs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = iscsi_binary_to_base64_str((uint8_t *)val,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* replace the value in the nvlist */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tgt_delete()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Delete target represented by 'tgt', where 'tgt' is an existing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_tgt_structure within the configuration 'cfg'. The target removal
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * will not take effect until the modified configuration is committed
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tgt Pointer to an iSCSI target structure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * force Set the target to offline before removing it from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the config. If not specified, the operation will
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * fail if the target is determined to be online.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EBUSY Target is online
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_tgt_delete(it_config_t *cfg, it_tgt_t *tgt, boolean_t force)
fcc214c383d20beb968b623b83d851672e174702Charles Ting if (strcasecmp(tgt->tgt_name, ptgt->tgt_name) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * check to see if this target is offline. If it is not,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * and the 'force' flag is TRUE, tell STMF to offline it
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * before removing from the configuration.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = stmfDevidFromIscsiName(ptgt->tgt_name, &devid);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* can't happen? */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * only other return is STMF_ERROR_NOT_FOUND, which
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * means we don't have to offline it.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* first one on the list */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ptgt->tgt_next = NULL; /* Only free this target */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tgt_free()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Frees an it_tgt_t structure. If tgt_next is not NULL, frees
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * all structures in the list.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tpgt_create()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Allocate and create an it_tpgt_t structure representing a new iSCSI
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target portal group tag. The new it_tpgt_t structure is added to the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target tpgt list (tgt_tpgt_list) in the it_tgt_t structure. The new
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target portal group tag will not be instantiated until the modified
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * configuration is committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tgt Pointer to the iSCSI target structure associated
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * with the target portal group tag
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpgt Pointer to a target portal group tag structure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpg_name The name of the TPG to be associated with this TPGT
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpgt_tag 16-bit numerical identifier for this TPGT. If
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpgt_tag is '0', this function will choose the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tag number. If tpgt_tag is >0, and the requested
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tag is determined to be in use, another value
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * will be chosen.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ENOMEM Could not allocate resources
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid parameter
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EEXIST Specified tag name is already used.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * E2BIG No available tag numbers
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_tpgt_create(it_config_t *cfg, it_tgt_t *tgt, it_tpgt_t **tpgt,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) memset(&(tagid_used[0]), 0, sizeof (tagid_used));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Make sure this name and/or tag isn't already on the list
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * At the same time, capture all tag ids in use for this target
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * About tag numbering -- since tag numbers are used by
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the iSCSI protocol, we should be careful about reusing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * them too quickly. Start with a value greater than the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * highest one currently defined. If current == MAXTAG,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * just find an unused tag.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (strcmp(tpg_name, cfgt->tpgt_tpg_name) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((tpgt_tag > ISCSIT_DEFAULT_TPGT) && (tpgt_tag < MAXTAG) &&
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* ok to use requested */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The highest value is used, find an available id.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* next available ID */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tpgt_delete()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Delete the target portal group tag represented by 'tpgt', where
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * 'tpgt' is an existing is_tpgt_t structure within the target 'tgt'.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The target portal group tag removal will not take effect until the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * modified configuration is committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tgt Pointer to the iSCSI target structure associated
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * with the target portal group tag
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpgt Pointer to a target portal group tag structure
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_tpgt_delete(it_config_t *cfg, it_tgt_t *tgt, it_tpgt_t *tpgt)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tpgt_free()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Deallocates resources of an it_tpgt_t structure. If tpgt->next
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is not NULL, frees all members of the list.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tpg_create()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Allocate and create an it_tpg_t structure representing a new iSCSI
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target portal group. The new it_tpg_t structure is added to the global
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpg list (cfg_tgt_list) in the it_config_t structure. The new target
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * portal group will not be instantiated until the modified configuration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpg Pointer to the it_tpg_t structure representing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the target portal group
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpg_name Identifier for the target portal group
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * portal_ip_port A string containing an appropriatedly formatted
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * IP address:port. Both IPv4 and IPv6 addresses are
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * permitted. This value becomes the first portal in
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the TPG -- applications can add additional values
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * using it_portal_create() before committing the TPG.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ENOMEM Cannot allocate resources
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid parameter
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EEXIST Requested portal in use by another target portal
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_tpg_create(it_config_t *cfg, it_tpg_t **tpg, char *tpg_name,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (!cfg || !tpg || !tpg_name || !portal_ip_port) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) strlcpy(ptr->tpg_name, tpg_name, sizeof (ptr->tpg_name));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* create the portal */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = it_portal_create(cfg, ptr, &portal, portal_ip_port);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tpg_delete()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Delete target portal group represented by 'tpg', where 'tpg' is an
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * existing it_tpg_t structure within the global configuration 'cfg'.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The target portal group removal will not take effect until the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * modified configuration is committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configuration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpg Pointer to the it_tpg_t structure representing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the target portal group
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * force Remove this target portal group even if it's
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * associated with one or more targets.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid parameter
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EBUSY Portal group associated with one or more targets.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_tpg_delete(it_config_t *cfg, it_tpg_t *tpg, boolean_t force)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (strcmp(ptr->tpg_name, tpg->tpg_name) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * See if any targets are using this portal group.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If there are, and the force flag is not set, fail.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Now that it's not in use anywhere, remove the TPG */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_tpg_free()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Deallocates resources associated with an it_tpg_t structure.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If tpg->next is not NULL, frees all members of the list.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_portal_create()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Add an it_portal_t structure presenting a new portal to the specified
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target portal group. The change to the target portal group will not take
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * effect until the modified configuration is committed by calling
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpg Pointer to the it_tpg_t structure representing the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target portal group
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * portal Pointer to the it_portal_t structure representing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the portal
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * portal_ip_port A string containing an appropriately formatted
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * IP address or IP address:port in either IPv4 or
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * IPv6 format.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ENOMEM Could not allocate resources
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid parameter
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EEXIST Portal already configured for another portal group
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_portal_create(it_config_t *cfg, it_tpg_t *tpg, it_portal_t **portal,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (!cfg || !tpg || !portal || !portal_ip_port) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((it_common_convert_sa(portal_ip_port, &sa, ISCSI_LISTEN_PORT))
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Check that this portal doesn't appear in any other tag */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (it_sa_compare(&(ptr->portal_addr), &sa) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Existing in the same group is not an error,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * but don't add it again.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (strcmp(ctpg->tpg_name, tpg->tpg_name) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Not allowed */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sizeof (struct sockaddr_storage));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_portal_delete()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Remove the specified portal from the specified target portal group.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The portal removal will not take effect until the modified configuration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * is committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * tpg Pointer to the it_tpg_t structure representing the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * target portal group
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * portal Pointer to the it_portal_t structure representing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the portal
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_portal_delete(it_config_t *cfg, it_tpg_t *tpg, it_portal_t *portal)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (memcmp(&(ptr->portal_addr), &(portal->portal_addr),
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_ini_create()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Add an initiator context to the global configuration. The new
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * initiator context will not be instantiated until the modified
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * configuration is committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ini Pointer to the it_ini_t structure representing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the initiator context.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ini_node_name The iSCSI node name of the remote initiator.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ENOMEM Could not allocate resources
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid parameter.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EFAULT Invalid initiator name
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_ini_create(it_config_t *cfg, it_ini_t **ini, char *ini_node_name)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Ensure this is a valid ini name
e20dd2eed1abc2cdf00090cf24a23a2c33f9b868Charles Ting if (strcasecmp(ptr->ini_name, ini_node_name) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) strlcpy(ptr->ini_name, ini_node_name, sizeof (ptr->ini_name));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* nvlist for props? */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_ini_setprop()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Validate the provided property list and set the initiator properties.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If errlist is not NULL, returns detailed errors for each property
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * that failed. The format for errorlist is key = property,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * value = error string.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ini The initiator being updated.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * proplist nvlist_t containing properties for this target.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * errlist (optional) nvlist_t of errors encountered when
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * validating the properties.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Return Values:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EINVAL Invalid property
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_ini_setprop(it_ini_t *ini, nvlist_t *proplist, nvlist_t **errlist)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * copy the existing properties, merge, then validate
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the merged properties before committing them.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_dup(ini->ini_properties, &iprops, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = nvlist_alloc(&iprops, NV_UNIQUE_NAME, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* unset chap username if requested */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((nvlist_lookup_string(proplist, PROP_CHAP_USER, &val)) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_remove_all(iprops, PROP_CHAP_USER);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* base64 encode the CHAP secret, if it's changed */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((nvlist_lookup_string(proplist, PROP_CHAP_SECRET, &val)) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ret = iscsi_binary_to_base64_str((uint8_t *)val,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* replace the value in the nvlist */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_ini_delete()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Remove the specified initiator context from the global configuration.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The removal will not take effect until the modified configuration is
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * committed by calling it_config_commit().
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Parameters:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * cfg The current iSCSI configration obtained from
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * it_config_load()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ini Pointer to the it_ini_t structure representing
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * the initiator context.
e20dd2eed1abc2cdf00090cf24a23a2c33f9b868Charles Ting if (strcasecmp(ptr->ini_name, ini->ini_name) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ptr->ini_next = NULL; /* Only free this initiator */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: it_ini_free()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Deallocates resources of an it_ini_t structure. If ini->next is
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * not NULL, frees all members of the list.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Goes through the target property list and validates
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * each entry. If errs is non-NULL, will return explicit errors
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * for each property that fails validation.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_validate_tgtprops(nvlist_t *nvl, nvlist_t *errs)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (strcmp(name, PROP_TARGET_CHAP_USER) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (strcmp(name, PROP_TARGET_CHAP_SECRET) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * must be between 12 and 255 chars in cleartext.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * will be base64 encoded when it's set.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap "must be none, chap, radius or default"));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (strcmp(name, PROP_OLD_TARGET_NAME) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* unrecognized property */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap PROPERR(errs, name, gettext("unrecognized property"));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* if auth is being set to default, remove from this nvlist */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Goes through the config property list and validates
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * each entry. If errs is non-NULL, will return explicit errors
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * for each property that fails validation.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_validate_configprops(nvlist_t *nvl, nvlist_t *errs)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* prefetch string value as we mostly need it */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (strcmp(name, PROP_ISNS_ENABLED) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (strcmp(name, PROP_ISNS_SERVER) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap while (acount > 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (strcasecmp(arr[acount - 1], "none") == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (strcmp(name, PROP_RADIUS_SECRET) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (strcmp(name, PROP_RADIUS_SERVER) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * rewrite this property to ensure port
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * number is added.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* unrecognized property */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap PROPERR(errs, name, gettext("unrecognized property"));
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap * If we successfully reformatted the radius server to add the port
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap * number then update the nvlist
6ced70a9f1bd8e73f1cd6804344bf85abe6b6c43Priya Krishnan (void) nvlist_add_string(nvl, PROP_RADIUS_SERVER, rad_server);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * if auth = radius, ensure radius server & secret are set.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* need server & secret for radius */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Goes through the ini property list and validates
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * each entry. If errs is non-NULL, will return explicit errors
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * for each property that fails validation.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_validate_iniprops(nvlist_t *nvl, nvlist_t *errs)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (strcmp(name, PROP_CHAP_SECRET) == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * must be between 12 and 255 chars in cleartext.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * will be base64 encoded when it's set.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* unrecognized property */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap PROPERR(errs, name, gettext("unrecognized property"));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_iqn_generate(char *iqn_buf, int iqn_buf_len, char *opt_iqn_suffix)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap "%02d:%s.%s", TARGET_NAME_VERS, id_str, opt_iqn_suffix);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * must be at least 12 chars and less than 256 chars cleartext.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Since we will be automatically encoding secrets we don't really
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * need the prefix anymore.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* all is well */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Function: validate_iscsi_name()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Ensures the passed-in string is a valid IQN or EUI iSCSI name
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * IQN names are iqn.yyyy-mm.<xxx>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((i < 0) || (i > 12)) {
836fc322d4b4884a4c64c7b5d172a4a3bb6a5772Sam Cramer * RFC 3722: if using only ASCII chars, only the following
836fc322d4b4884a4c64c7b5d172a4a3bb6a5772Sam Cramer * chars are allowed: dash, dot, colon, lower case a-z, 0-9.
836fc322d4b4884a4c64c7b5d172a4a3bb6a5772Sam Cramer * We allow upper case names, which should be folded
836fc322d4b4884a4c64c7b5d172a4a3bb6a5772Sam Cramer * to lower case names later.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Finally, validate the overall length, in wide chars */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * EUI names are "eui." + 16 hex chars
5de03f841f1da359071f4d303d88b50ec0e2093aSue Gleeson if (strcmp(state, SCF_STATE_STRING_ONLINE) == 0) {
fcc214c383d20beb968b623b83d851672e174702Charles Ting * Function: canonical_iscsi_name()
fcc214c383d20beb968b623b83d851672e174702Charles Ting * Fold the iqn iscsi name to lower-case and the EUI-64 identifier of
fcc214c383d20beb968b623b83d851672e174702Charles Ting * the eui iscsi name to upper-case.
fcc214c383d20beb968b623b83d851672e174702Charles Ting * Ensures the passed-in string is a valid IQN or EUI iSCSI name
fcc214c383d20beb968b623b83d851672e174702Charles Ting /* lowercase iqn names */
fcc214c383d20beb968b623b83d851672e174702Charles Ting /* uppercase EUI-64 identifier */
fcc214c383d20beb968b623b83d851672e174702Charles Ting * Fold an iqn name to lower-case.
fcc214c383d20beb968b623b83d851672e174702Charles Ting while (*s) {
fcc214c383d20beb968b623b83d851672e174702Charles Ting * Fold the EUI-64 identifier of a eui name to upper-case.
fcc214c383d20beb968b623b83d851672e174702Charles Ting char *l = s + 4;
fcc214c383d20beb968b623b83d851672e174702Charles Ting while (*l) {