Home | History | Annotate | Download | only in iscsitgtd
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 
     22 /*
     23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #ifndef	_ISNS_CLIENT_H
     28 #define	_ISNS_CLIENT_H
     29 
     30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     31 
     32 #ifdef __cplusplus
     33 extern "C" {
     34 #endif
     35 
     36 #include <netdb.h>
     37 #include "queue.h"
     38 
     39 #include "isns_protocol.h"
     40 
     41 #ifndef	TRUE
     42 #define	TRUE		1
     43 #endif
     44 
     45 #ifndef	FALSE
     46 #define	FALSE		0
     47 #endif
     48 
     49 /* isns update bitmap */
     50 #define	ISNS_MOD_ALIAS	0x1
     51 #define	ISNS_MOD_TPGT	0x2
     52 
     53 /* iscsi isns protocol */
     54 
     55 /*
     56  * Attribute size
     57  */
     58 #define	ISNS_ISCSI_TYPE_SZ	(4)
     59 #define	ISNS_SCN_BITMAP_SZ	(4)
     60 #define	ISNS_PORT_SZ		(4)
     61 #define	ISNS_ESI_TICK_SZ	(4)
     62 #define	ISNS_PG_TAG_SZ		(4)
     63 #define	ISNS_ENTITY_TYP_SZ	(4)
     64 #define	ISNS_NODE_TYP_SZ	(4)
     65 
     66 /*
     67  * iSNS attribute length:  See RFC 4171 Section 6.1
     68  *	iSCSI Name = 4-224
     69  *	iSCSI Alias = 4-256
     70  */
     71 #define	ISCSI_MAX_NAME	224
     72 #define	ISCSI_MAX_ALIAS	256
     73 
     74 /*
     75  * Default pdu payload size, this is derived from a typical DevAttrReg
     76  * request, this should be sufficient for all requests.
     77  */
     78 #define	MAX_PDU_SZ		(16384)
     79 #define	MAX_PDU_PAYLOAD_SZ	(MAX_PDU_SZ - ISNSP_HEADER_SIZE)
     80 #define	TAG_LEN_SZ		(8)
     81 
     82 /* various isns data size */
     83 #define	ISNS_STATUS_SZ		(4)
     84 #define	ISNS_ATTR_SZ(attr_len)	(attr_len + TAG_LEN_SZ)
     85 
     86 /*
     87  * PDU length is 4 bytes aligned.  See RFC 4171 Section 5.1.3
     88  */
     89 #define	PAD4(a)	((a%4) ? ((4-a%4)+a) : a)
     90 
     91 /*
     92  * Macro to check 1st and last pdu
     93  */
     94 #define	IS_1ST_PDU(x)	((x & ISNS_FLAG_FIRST_PDU) ? 1 : 0)
     95 #define	IS_LAST_PDU(x)	((x & ISNS_FLAG_LAST_PDU) ? 1 : 0)
     96 
     97 /* RFC 4171 section 6 - null is included in strlen */
     98 #define	STRLEN(x)	(strlen(x) + 1)
     99 
    100 typedef struct esi_scn_arg {
    101 	char		entity[MAXHOSTNAMELEN + 1]; /* iscsi target entity */
    102 	char		server[MAXHOSTNAMELEN + 1]; /* isns server */
    103 	int		isns_port;		/* isns server port */
    104 } esi_scn_arg_t;
    105 
    106 /*
    107  * ISNS message header
    108  * See RFC 4171 Section 5.0 & 5.1
    109  */
    110 typedef	struct	isns_hdr {
    111 	uint16_t	version;
    112 	uint16_t	func_id;
    113 	uint16_t	pdu_len;
    114 	uint16_t	flags;
    115 	uint16_t	xid;
    116 	uint16_t	seqid;
    117 } isns_hdr_t;
    118 
    119 /*
    120  * ISNS attribute, the attribute is in Tag-Length_Value format
    121  * attr_len: NULLs are included in the length
    122  * attr_value: is variable size and it is 4 bytes aligned
    123  */
    124 #if 0
    125 typedef	struct	isns_attr {
    126 	uint32_t	tag;
    127 	uint32_t	len;
    128 	uint8_t		val[1];
    129 } isns_attr_t;
    130 #endif
    131 
    132 typedef struct isns_rsp {
    133 	uint16_t	version;
    134 	uint16_t	func_id;
    135 	uint16_t	pdu_len;
    136 	uint16_t	flags;
    137 	uint16_t	xid;
    138 	uint16_t	seqid;
    139 	uint32_t	status;
    140 	uint8_t		data[1];
    141 } isns_rsp_t;
    142 
    143 /* Function prototype */
    144 int		isns_init(target_queue_t *q);
    145 int		isns_update();
    146 void		isns_fini();
    147 Boolean_t	isns_qry_initiator(char *, char *);
    148 int		isns_reg(char *);
    149 int		isns_reg_all();
    150 int		isns_dereg(char *);
    151 int		isns_dereg_all();
    152 int		isns_scn_reg_all();
    153 int		isns_scn_dereg_all();
    154 int		isns_dev_update(char *, uint32_t);
    155 Boolean_t	isns_enabled();
    156 void		isns_tpgt_update();
    157 int		isns_open(char *);
    158 void		isns_close(int);
    159 int		isns_append_attr(isns_pdu_t *, uint32_t, uint32_t, void *,
    160 			uint32_t);
    161 int		isns_create_pdu(uint16_t, uint32_t, isns_pdu_t **);
    162 void		isns_free_pdu(void *);
    163 int		isns_send(int, isns_pdu_t *);
    164 int		isns_recv(int, isns_rsp_t **);
    165 void		ntoh_isns_hdr(isns_hdr_t *);
    166 void		ntoh_tlv(isns_tlv_t *);
    167 void		print_ntoh_tlv(isns_tlv_t *);
    168 void		print_attr(isns_tlv_t *attr, void *pval, uint32_t ival);
    169 void		print_isns_hdr(isns_hdr_t *);
    170 int		setsocknonblocking(int so);
    171 int		setsockblocking(int so);
    172 Boolean_t	is_socket_ready(int so,
    173 		    fd_set *rfdset, fd_set *wfdset, fd_set *errfdset);
    174 
    175 #ifdef __cplusplus
    176 }
    177 #endif
    178 
    179 #endif	/* _ISNS_CLIENT_H */
    180