fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/socket.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sunddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/in.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/utsname.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NOTE: This routine is found in libnsl. There's apparently no prototype to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be found in any of the header files in /usr/include so defining a prototype
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * here to keep the compiler happy.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint getdomainname(char *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic const char *iqn_template = "iqn.2004-02.%s";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/adapters/iscsi_if.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct utils_val_name {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int u_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *u_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} utils_val_name_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteutils_val_name_t param_names[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER, "Sequence In Order"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_IMMEDIATE_DATA, "Immediate Data"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_INITIAL_R2T, "Inital R2T"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER, "Data PDU In Order"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_HEADER_DIGEST, "Header Digest"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_DATA_DIGEST, "Data Digest"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN, "Default Time To Retain"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT, "Default Time To Wait"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Max Recv Data Segment Length"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH, "First Burst Length"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH, "Max Burst Length"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_MAX_CONNECTIONS, "Max Connections"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_OUTSTANDING_R2T, "Outstanding R2T"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL, "Error Recovery Level"},
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { 0, NULL }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * utils_map_param -- Given a parameter return it's ascii name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine was created because previously an array contained in order
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the parameter names. Once or twice the parameters value changed which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * changed the order, but not the array. To avoid further confusion we'll
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * do a simple lookup. This code is rarely called so it shouldn't be an
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * issue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteutils_map_param(int p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utils_val_name_t *pn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pn = param_names; pn->u_name != NULL; pn++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pn->u_val == p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pn->u_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * prt_bitmap -- print out ascii strings associated with bit numbers.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechar *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprt_bitmap(int bitmap, char *str, char *buf, int size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *start = buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int do_put = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The maximum space required will if the bitmap was all 1's which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * would cause the octal characters to be replaced by '|'. So make
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sure the buffer has enough space.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (size < strlen(str))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ("No room");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = str; size--; p++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*p < 0x20) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we have been putting out stuff add separator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (do_put)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *buf++ = '|';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do_put = ((1 << *p) & bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bitmap &= ~(1 << *p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (do_put)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *buf++ = *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- remove the last separator if it was added ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((buf > start) && (*(buf - 1) == '|'))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *buf = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parse_addr_port_tpgt - Used to parse addr, port and tpgt from string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is used to parse addr, port and tpgt from a string. Callers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of this function are the sendtargets and login redirection code. The
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * caller must be aware that this function will modify the callers string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to insert NULL terminators if required. Port and TPGT are optional.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteparse_addr_port_tpgt(char *in, char **addr, int *type, char **port, char **tpgt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *t_port, *t_tpgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* default return values if requested */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (addr == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *addr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *port = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tpgt != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *tpgt = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* extract ip or domain name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*in == '[') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPV6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *type = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *addr = ++in;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in = strchr(*addr, ']');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (in == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *in++ = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* IPV4 or domainname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *type = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *addr = in;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* extract port */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_port = strchr(in, ':');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_port != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *t_port++ = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *port = in = t_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* exact tpgt */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tpgt != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_tpgt = strchr(in, ',');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_tpgt != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *t_tpgt++ = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *tpgt = in = t_tpgt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _KERNEL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * []--------------------------------------------------------------[]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | reverse_fqdn -- given a fully qualified domain name reverse it |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | The routine has the obvious problem that it can only handle a |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | name with 5 or less dots. This needs to be fixed by counting |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | the number of dots in the incoming name, calloc'ing an array |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | of the appropriate size and then handling the pointers. |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * []--------------------------------------------------------------[]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic boolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* LINTED E_FUNC_ARG_UNUSED for 3rd arg size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortereverse_fqdn(const char *domain, char *buf, int size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *ptrs[5];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *dp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *dp1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int v = 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dp = dp1 = malloc(strlen(domain) + 1)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(dp, domain);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((p = (char *)strchr(dp, '.')) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (v < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(dp1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ptrs[v--] = dp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dp = p + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(buf, dp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (v++; v < 5; v++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(buf, ".");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcat(buf, ptrs[v]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(dp1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * []------------------------------------------------------------------[]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | utils_iqn_create -- returns an iqn name for the machine |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | The information found in the iqn is not correct. The year and |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | date should be flexible. Currently this is hardwired to the |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | current year and month of this project. |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * []------------------------------------------------------------------[]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteutils_iqn_create(char *iqn_buf, int size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct utsname uts_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char domainname[256];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *temp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *pmet = NULL; /* temp reversed .. get it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rval = B_FALSE; /* Default */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uname(&uts_info) == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (getdomainname(domainname, sizeof (domainname))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((temp = malloc(strlen(uts_info.nodename) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(domainname) + 2)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * getdomainname always returns something in the order of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host.domainname so we need to skip over that portion of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host name because we don't care about it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((p = strchr(domainname, '.')) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = domainname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- Create Fully Qualified Domain Name ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf(temp, strlen(p), "%s.%s", uts_info.nodename, p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ---- According to the spec, names must be lower case ---- */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = temp; *p; p++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isupper(*p))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *p = tolower(*p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = strlen(temp) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((pmet = malloc(len)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reverse_fqdn(temp, pmet, len) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now use the template with the reversed domainname to create
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an iSCSI name using the IQN format. Only count it a success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the number of characters formated is less than the buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * size.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(iqn_buf, size, iqn_template, pmet) <= size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (temp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(temp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pmet)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(pmet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* !_KERNEL */