1*83a6212dSwiz.\" $NetBSD: isns.3,v 1.2 2011/01/16 08:00:01 wiz Exp $ 2dc2ecebeSagc.\" 3dc2ecebeSagc.\" Copyright (c) 2004,2009 The NetBSD Foundation, Inc. 4dc2ecebeSagc.\" All rights reserved. 5dc2ecebeSagc.\" 6dc2ecebeSagc.\" This code is derived from software contributed to The NetBSD Foundation 7dc2ecebeSagc.\" by Wasabi Systems, Inc. 8dc2ecebeSagc.\" 9dc2ecebeSagc.\" Redistribution and use in source and binary forms, with or without 10dc2ecebeSagc.\" modification, are permitted provided that the following conditions 11dc2ecebeSagc.\" are met: 12dc2ecebeSagc.\" 1. Redistributions of source code must retain the above copyright 13dc2ecebeSagc.\" notice, this list of conditions and the following disclaimer. 14dc2ecebeSagc.\" 2. Redistributions in binary form must reproduce the above copyright 15dc2ecebeSagc.\" notice, this list of conditions and the following disclaimer in the 16dc2ecebeSagc.\" documentation and/or other materials provided with the distribution. 17dc2ecebeSagc.\" 18dc2ecebeSagc.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19dc2ecebeSagc.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20dc2ecebeSagc.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21dc2ecebeSagc.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22dc2ecebeSagc.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23dc2ecebeSagc.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24dc2ecebeSagc.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25dc2ecebeSagc.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26dc2ecebeSagc.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27dc2ecebeSagc.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28dc2ecebeSagc.\" POSSIBILITY OF SUCH DAMAGE. 29dc2ecebeSagc.Dd October 1, 2009 30dc2ecebeSagc.Dt ISNS 3 31dc2ecebeSagc.Os 32dc2ecebeSagc.Sh NAME 33dc2ecebeSagc.Nm isns 34dc2ecebeSagc.Nd iSNS protocol support library 35dc2ecebeSagc.Sh LIBRARY 36dc2ecebeSagc.Lb libisns 37dc2ecebeSagc.Sh SYNOPSIS 38dc2ecebeSagc.In isns.h 39dc2ecebeSagc.Ft int 40dc2ecebeSagc.Fn isns_init "ISNS_HANDLE *h" "int is_server" 41dc2ecebeSagc.Ft void 42dc2ecebeSagc.Fn isns_stop "ISNS_HANDLE h" 43dc2ecebeSagc.Ft int 44dc2ecebeSagc.Fn isns_add_servercon "ISNS_HANDLE h" "int fd" "struct addrinfo *ai" 45dc2ecebeSagc.Ft int 46dc2ecebeSagc.Fn isns_init_reg_refresh "ISNS_HANDLE h" "const char *node" "int interval" 47dc2ecebeSagc.Ft ISNS_TRANS 48dc2ecebeSagc.Fn isns_new_trans "ISNS_HANDLE h" "uint16_t func_id" "uint16_t pdu_flags" 49dc2ecebeSagc.Ft int 50dc2ecebeSagc.Fn isns_add_tlv "ISNS_TRANS t" "uint32_t tag" "int data_len" "const void *data_p" 51dc2ecebeSagc.Ft int 52dc2ecebeSagc.Fn isns_add_string "ISNS_TRANS t" "uint32_t tag" "const char *s" 53dc2ecebeSagc.Ft int 54dc2ecebeSagc.Fn isns_send_trans "ISNS_TRANS t" "const struct timespec *timeout_p" "uint32_t *status_p" 55dc2ecebeSagc.Ft int 56dc2ecebeSagc.Fn isns_get_tlv "ISNS_TRANS t" "int which_tlv" "uint32_t *tag_p" "int data_len_p" "void **data_pp" 57dc2ecebeSagc.Ft void 58dc2ecebeSagc.Fn isns_free_trans "ISNS_TRANS t" 59dc2ecebeSagc.Sh DESCRIPTION 60dc2ecebeSagcThe 61dc2ecebeSagc.Nm 62dc2ecebeSagclibrary exports an API that simplifies Internet Storage Name 63dc2ecebeSagcService (iSNS) client implementations. 64dc2ecebeSagcThe API defines a transactional model in support of: 65dc2ecebeSagc.Pp 66dc2ecebeSagc.Bl -bullet -width 3n -offset indent -compact 67dc2ecebeSagc.It 68dc2ecebeSagcgenerating iSNS messages composed of iSNS attributes expressed in 69dc2ecebeSagcTag-Length-Value (TLV) data format 70dc2ecebeSagc.It 71dc2ecebeSagcsubmitting iSNS Protocol (iSNSP) messages 72dc2ecebeSagc.It 73dc2ecebeSagcoptionally waiting for iSNSP responses 74dc2ecebeSagc.El 75dc2ecebeSagc.Pp 76dc2ecebeSagc.Nm 77dc2ecebeSagcdoes not currently support receipt of iSNS Heartbeat messages, State Change 78dc2ecebeSagcNotification (SCN) messages, or Entity Status Inquiry (ESI) messages. 79*83a6212dSwiz.Sh INITIALIZATION 80dc2ecebeSagcAn iSNS client that uses 81dc2ecebeSagc.Nm 82dc2ecebeSagcmust call 83dc2ecebeSagc.Fn isns_init 84dc2ecebeSagcto initialize the iSNS environment. 85dc2ecebeSagcThis call will create a thread to handle client-server communication, and 86dc2ecebeSagcas such should only be called when thread creation is appropriate (such 87dc2ecebeSagcas after a daemonized program forks). 88dc2ecebeSagc.Pp 89*83a6212dSwizThe value passed as 90*83a6212dSwiz.Ar is_server 91*83a6212dSwizis used to set iSNSP message format Flags 92dc2ecebeSagc"Sender is the iSNS client" (bit position 16) and "Sender is the iSNS server" 93dc2ecebeSagc(bit position 17). 94dc2ecebeSagcFor now the value 0 (zero) should be passed for 95*83a6212dSwiz.Ar is_server . 96*83a6212dSwizThe value returned in 97*83a6212dSwiz.Ar h 98*83a6212dSwizshould be considered opaque by the caller. 99dc2ecebeSagcThis value is passed unchanged to 100dc2ecebeSagc.Fn isns_add_servercon , 101dc2ecebeSagc.Fn isns_init_reg_refresh , 102dc2ecebeSagc.Fn isns_stop , 103dc2ecebeSagcand 104dc2ecebeSagc.Fn isns_new_trans . 105dc2ecebeSagc.Pp 106dc2ecebeSagc.Fn isns_stop 107dc2ecebeSagcshould be called when the iSNS environment is no longer needed. 108dc2ecebeSagcThis call will kill any threads created by 109dc2ecebeSagc.Fn isns_init . 110dc2ecebeSagc.Sh CONFIGURATION 111dc2ecebeSagcFollowing initialization, 112dc2ecebeSagc.Fn isns_add_servercon 113dc2ecebeSagcshould be used to make the iSNS environment aware of the iSNS 114dc2ecebeSagcserver to which iSNSP queries and requests are to be sent. 115dc2ecebeSagcThis routine should not be called by a program acting as an iSNS server. 116dc2ecebeSagc.Pp 117*83a6212dSwizA connected TCP socket descriptor is passed as parameter 118*83a6212dSwiz.Ar fd . 119*83a6212dSwizParameter 120*83a6212dSwiz.Ar ai 121*83a6212dSwizis the address of the remote TCP endpoint. 122dc2ecebeSagcIt is included so that reconnection may be attempted by 123dc2ecebeSagc.Nm 124dc2ecebeSagcin the event that the TCP connection is broken. 125dc2ecebeSagc.Pp 126dc2ecebeSagcCertain iSNS servers will limit registration lifetimes, and will 127dc2ecebeSagcrefresh registrations after any request from a given iSNS entity. 128dc2ecebeSagcThe 129dc2ecebeSagc.Fn isns_init_reg_refresh 130dc2ecebeSagcfunction offers a way for 131dc2ecebeSagc.Nm 132dc2ecebeSagcto refresh registrations on behalf of the iSNS client. 133dc2ecebeSagc.Pp 134*83a6212dSwizParameter 135*83a6212dSwiz.Ar node 136*83a6212dSwizis the 137*83a6212dSwiz.Dq iSCSI Name 138*83a6212dSwizattribute used for the periodic queries. 139dc2ecebeSagcIt should be the name of an iSCSI node within the registered iSNS entity. 140*83a6212dSwizThe desired refresh interval, in seconds, is passed in parameter 141*83a6212dSwiz.Ar interval . 142dc2ecebeSagc.Sh TRANSACTIONS 143dc2ecebeSagc.Fn isns_new_trans 144dc2ecebeSagccreates new iSNS transactions. 145dc2ecebeSagc.Pp 146*83a6212dSwizParameter 147*83a6212dSwiz.Ar func_id 148*83a6212dSwizis used as the iSNSP message id. 149*83a6212dSwizParameter 150*83a6212dSwiz.Ar pdu_flags 151*83a6212dSwizis used to set iSNSP message format Flags and is 152dc2ecebeSagcexposed to allow callers to set flag "Replace flag" (bit position 19). 153dc2ecebeSagcThis provides callers with a way 154dc2ecebeSagcto specify whether a Device Attribute Registration Request is intended to 155*83a6212dSwizupdate or replace an existing registration. 156*83a6212dSwizThis is currently the only use defined for parameter 157*83a6212dSwiz.Ar pdu_flags . 158dc2ecebeSagc.Pp 159dc2ecebeSagcOnce a new transaction has been created, callers can specify iSNS attributes 160dc2ecebeSagcused for registration and query requests. 161dc2ecebeSagcTLV data may be added using either 162dc2ecebeSagc.Fn isns_add_tlv 163dc2ecebeSagcor 164dc2ecebeSagc.Fn isns_add_string . 165dc2ecebeSagc.Pp 166*83a6212dSwizParameter 167*83a6212dSwiz.Ar tag 168*83a6212dSwizis the iSNS Tag corresponding to the attribute being added. 169*83a6212dSwizParameter 170*83a6212dSwiz.Ar data_len 171*83a6212dSwizis the length of the attribute value. 172*83a6212dSwizParameter 173*83a6212dSwiz.Ar data_p 174*83a6212dSwizreferences the attribute value. 175dc2ecebeSagcThe caller does not need to handle iSNS attribute 4-byte alignment requirements. 176dc2ecebeSagcThis is handled by the iSNS environment on behalf of the caller. 177dc2ecebeSagc.Fn isns_add_string 178dc2ecebeSagcmay be used if the attribute value is a NUL terminated C string. 179dc2ecebeSagc.Pp 180dc2ecebeSagcOnce a transaction has been populated with any required TLV data, 181dc2ecebeSagc.Fn isns_send_trans 182dc2ecebeSagccan be used to submit an iSNSP registration or query message. 183dc2ecebeSagc.Pp 184dc2ecebeSagcCallers that submit iSNSP query messages may need to wait for returned data. 185dc2ecebeSagc.Fn isns_send_trans 186dc2ecebeSagcsupports bounded waits. 187dc2ecebeSagcSuccessful waits, those that do not time out, return the iSNSP response 188dc2ecebeSagcstatus code received in the iSNSP response message. 189*83a6212dSwizIf a wait does time out, the value of 190*83a6212dSwiz.Ar status_p 191*83a6212dSwizis undefined. 192dc2ecebeSagcCallers that do not need to wait for returned data can simply 193*83a6212dSwizpass 194*83a6212dSwiz.Dv NULL 195*83a6212dSwizfor parameter 196*83a6212dSwiz.Ar timeout_p . 197*83a6212dSwizCallers should set parameter 198*83a6212dSwiz.Ar status_p 199*83a6212dSwizto 200*83a6212dSwiz.Dv NULL 201*83a6212dSwizif not waiting. 202dc2ecebeSagc.Pp 203dc2ecebeSagc.Fn isns_get_tlv 204dc2ecebeSagcis used to retrieve TLV data returned in a transaction. 205dc2ecebeSagcThe first call to 206dc2ecebeSagc.Fn isns_get_tlv 207*83a6212dSwizshould pass the value 208*83a6212dSwiz.Dv ISNS_TLV_FIRST 209*83a6212dSwizfor parameter 210*83a6212dSwiz.Ar which_tlv . 211*83a6212dSwizEach subsequent TLV can be retrieved by passing in 212*83a6212dSwiz.Dv ISNS_TLV_NEXT 213*83a6212dSwizin place of 214*83a6212dSwiz.Dv ISNS_TLV_FIRST . 215dc2ecebeSagc.Pp 216dc2ecebeSagcWhen a caller is done with a transaction, having submitted either a 217dc2ecebeSagcregistration or a query message and retrieved any returned TLV data, 218*83a6212dSwiz.Fn isns_free_trans 219dc2ecebeSagcshould be used to release resources used by the transaction. 220dc2ecebeSagc.Sh RETURN VALUES 221dc2ecebeSagc.Fn isns_init , 222dc2ecebeSagc.Fn isns_add_servercon , 223dc2ecebeSagc.Fn isns_init_reg_refresh , 224dc2ecebeSagc.Fn isns_add_tlv , 225dc2ecebeSagc.Fn isns_add_string , 226dc2ecebeSagcand 227dc2ecebeSagc.Fn isns_send_trans 228*83a6212dSwizreturn 0 on success, or \-1 on failure. 229dc2ecebeSagc.Fn isns_new_trans 230*83a6212dSwizreturns 0 on success, or 231*83a6212dSwiz.Dv ISNS_INVALID_TRANS 232*83a6212dSwizon failure. 233dc2ecebeSagc.Fn isns_get_tlv 234*83a6212dSwizreturns 0 on success, or 235*83a6212dSwiz.Er ENOENT 236*83a6212dSwizif there are no TLVs to retrieve. 237dc2ecebeSagc.Sh HISTORY 238dc2ecebeSagc.Nm 239dc2ecebeSagcfirst appeared in 240dc2ecebeSagc.Nx 6.0 . 241dc2ecebeSagcThe 242dc2ecebeSagc.Nm 243*83a6212dSwizimplementation was contributed to the 244*83a6212dSwiz.Nx 245*83a6212dSwizFoundation by Wasabi Systems, Inc. 246