4 * Copyright (C) 2004 Dmitry Yusupov, Alex Aizman
5 * maintained by open-iscsi@googlegroups.com
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * See the file COPYING included with this distribution for more details.
28 #include "iscsi_proto.h"
36 #define ISCSI_CONFIG_ROOT "/etc/iscsi/"
38 #define CONFIG_FILE ISCSI_CONFIG_ROOT"iscsid.conf"
39 #define INITIATOR_NAME_FILE ISCSI_CONFIG_ROOT"initiatorname.iscsi"
41 #define PID_FILE "/var/run/iscsid.pid"
43 #define LOCK_DIR "/var/lock/iscsi"
45 #define LOCK_FILE LOCK_DIR"/lock"
46 #define LOCK_WRITE_FILE LOCK_DIR"/lock.write"
48 typedef enum iscsi_session_r_stage_e
{
50 R_STAGE_SESSION_CLEANUP
,
51 R_STAGE_SESSION_REOPEN
,
52 R_STAGE_SESSION_REDIRECT
,
53 R_STAGE_SESSION_DESTOYED
,
54 } iscsi_session_r_stage_e
;
56 typedef enum conn_login_status_e
{
57 CONN_LOGIN_SUCCESS
= 0,
58 CONN_LOGIN_FAILED
= 1,
59 CONN_LOGIN_IO_ERR
= 2,
61 CONN_LOGIN_IMM_RETRY
= 4,
62 CONN_LOGIN_IMM_REDIRECT_RETRY
= 5,
63 CONN_LOGIN_AUTH_FAILED
= 6,
64 } conn_login_status_e
;
66 enum iscsi_login_status
{
70 LOGIN_VERSION_MISMATCH
= 3,
71 LOGIN_NEGOTIATION_FAILED
= 4,
72 LOGIN_AUTHENTICATION_FAILED
= 5,
73 LOGIN_REDIRECTION_FAILED
= 6,
74 LOGIN_INVALID_PDU
= 7,
78 typedef enum iscsi_event_e
{
90 typedef struct iscsi_login_context
{
95 uint8_t status_detail
;
96 struct iscsi_acl
*auth_client
;
98 struct iscsi_login_rsp
*login_rsp
;
104 enum iscsi_login_status ret
;
105 struct queue_task
*qtask
;
106 } iscsi_login_context_t
;
108 struct iscsi_session
;
110 struct iscsi_ev_context
;
112 /* daemon's connection structure */
113 typedef struct iscsi_conn
{
115 struct iscsi_session
*session
;
116 iscsi_login_context_t login_context
;
117 struct iscsi_ev_context
*recv_context
;
118 struct queue_task
*logout_qtask
;
119 char data
[ISCSI_DEF_MAX_RECV_SEG_LEN
];
120 char host
[NI_MAXHOST
]; /* scratch */
121 enum iscsi_conn_state state
;
124 struct timeval initial_connect_time
;
126 actor_t nop_out_timer
;
128 #define CONTEXT_POOL_MAX 32
129 struct iscsi_ev_context
*context_pool
[CONTEXT_POOL_MAX
];
131 /* login state machine */
134 int partial_response
;
135 conn_login_status_e status
;
137 /* tcp/socket settings */
140 * Either a tcp/ip or a netlink socket to do
144 /* address being used for normal session connection */
145 struct sockaddr_storage saddr
;
146 /* address received during login */
147 struct sockaddr_storage failback_saddr
;
151 /* used for the IPC of bind and for connect/poll/disconnect by
152 * transports (eg iser) which does these ops from the kernel.
153 * In the case of TCP, it is just the transport_fd casted to u64. */
154 uint64_t transport_ep_handle
;
163 int noop_out_interval
;
164 int noop_out_timeout
;
169 /* negotiated parameters */
171 uint32_t datadgst_en
;
172 uint32_t max_recv_dlength
; /* the value we declare */
173 uint32_t max_xmit_dlength
; /* the value declared by the target */
176 struct iscsi_ev_context
{
178 struct iscsi_conn
*conn
;
183 typedef struct queue_task
{
189 /* Newer request types include a
190 * variable-length payload */
194 struct iscsi_transport_template
;
195 struct iscsi_transport
;
197 /* daemon's session structure */
198 typedef struct iscsi_session
{
199 struct list_head list
;
202 char netdev
[IFNAMSIZ
];
203 struct iscsi_transport
*t
;
205 node_rec_t nrec
; /* copy of original Node record in database */
206 unsigned int irrelevant_keys_bitmap
;
213 uint32_t imm_data_en
;
214 uint32_t initial_r2t_en
;
216 uint32_t first_burst
;
218 uint32_t pdu_inorder_en
;
219 uint32_t dataseq_inorder_en
;
220 uint32_t def_time2wait
;
221 uint32_t def_time2retain
;
223 int portal_group_tag
;
226 char target_name
[TARGET_NAME_MAXLEN
+ 1];
228 char *initiator_name
;
229 char *initiator_alias
;
230 struct auth_str_block auth_recv_string_block
;
231 struct auth_str_block auth_send_string_block
;
232 struct auth_large_binary auth_recv_binary_block
;
233 struct auth_large_binary auth_send_binary_block
;
234 struct iscsi_acl auth_client_block
;
235 struct iscsi_acl
*auth_client
;
236 int num_auth_buffers
;
237 struct auth_buffer_desc auth_buffers
[5];
238 int bidirectional_auth
;
239 char username
[AUTH_STR_MAX_LEN
];
240 uint8_t password
[AUTH_STR_MAX_LEN
];
242 char username_in
[AUTH_STR_MAX_LEN
];
243 uint8_t password_in
[AUTH_STR_MAX_LEN
];
244 int password_in_length
;
245 iscsi_conn_t conn
[ISCSI_CONN_MAX
];
248 /* connection reopens during recovery */
250 queue_task_t reopen_qtask
;
251 iscsi_session_r_stage_e r_stage
;
252 uint32_t replacement_timeout
;
254 int host_reset_timeout
;
255 int tgt_reset_timeout
;
256 int lu_reset_timeout
;
260 * used for hw and sync up to notify caller that the operation
263 queue_task_t
*notify_qtask
;
268 #define ISCSI_SESSION_TYPE_NORMAL 0
269 #define ISCSI_SESSION_TYPE_DISCOVERY 1
271 /* not defined by iSCSI, but used in the login code to determine
272 * when to send the initial Login PDU
274 #define ISCSI_INITIAL_LOGIN_STAGE -1
276 #define ISCSI_TEXT_SEPARATOR '='
278 /* implemented in iscsi-login.c for use on all platforms */
279 extern int iscsi_add_text(struct iscsi_hdr
*hdr
, char *data
, int max_data_length
,
280 char *param
, char *value
);
281 extern enum iscsi_login_status
iscsi_login(iscsi_session_t
*session
, int cid
,
282 char *buffer
, size_t bufsize
, uint8_t * status_class
,
283 uint8_t * status_detail
);
284 extern int iscsi_update_address(iscsi_conn_t
*conn
, char *address
);
285 extern int iscsi_login_begin(iscsi_session_t
*session
,
286 iscsi_login_context_t
*c
);
287 extern int iscsi_login_req(iscsi_session_t
*session
, iscsi_login_context_t
*c
);
288 extern int iscsi_login_rsp(iscsi_session_t
*session
, iscsi_login_context_t
*c
);
289 extern int resolve_address(char *host
, char *port
, struct sockaddr_storage
*ss
);
292 #define ISCSI_DIGEST_NONE 0
293 #define ISCSI_DIGEST_CRC32C 1
294 #define ISCSI_DIGEST_CRC32C_NONE 2 /* offer both, prefer CRC32C */
295 #define ISCSI_DIGEST_NONE_CRC32C 3 /* offer both, prefer None */
297 #define IRRELEVANT_MAXCONNECTIONS 0x01
298 #define IRRELEVANT_INITIALR2T 0x02
299 #define IRRELEVANT_IMMEDIATEDATA 0x04
300 #define IRRELEVANT_MAXBURSTLENGTH 0x08
301 #define IRRELEVANT_FIRSTBURSTLENGTH 0x10
302 #define IRRELEVANT_MAXOUTSTANDINGR2T 0x20
303 #define IRRELEVANT_DATAPDUINORDER 0x40
304 #define IRRELEVANT_DATASEQUENCEINORDER 0x80
308 * These user/kernel IPC calls are used by transports (eg iSER) that have their
309 * native connection managed from the kernel. The IPC for having the user space
310 * code being able to do it, is implemented as an enhancement of the open iscsi
311 * netlink IPC scheme, currently with the ability to connect/poll-for-establish
312 * ment/disconnect an opaque transport dependent 64 bit ep (endpoint) handle.
313 * The exact IPC ABI for that matter is defined in iscsi_if.h
316 extern int ktransport_ep_connect(iscsi_conn_t
*conn
, int non_blocking
);
317 extern int ktransport_ep_poll(iscsi_conn_t
*conn
, int timeout_ms
);
318 extern void ktransport_ep_disconnect(iscsi_conn_t
*conn
);
321 extern int iscsi_io_tcp_poll(iscsi_conn_t
*conn
, int timeout_ms
);
322 extern int iscsi_io_tcp_connect(iscsi_conn_t
*conn
, int non_blocking
);
323 extern void iscsi_io_tcp_disconnect(iscsi_conn_t
*conn
);
325 extern int iscsi_io_connect(iscsi_conn_t
*conn
);
326 extern void iscsi_io_disconnect(iscsi_conn_t
*conn
);
327 extern int iscsi_io_send_pdu(iscsi_conn_t
*conn
, struct iscsi_hdr
*hdr
,
328 int hdr_digest
, char *data
, int data_digest
, int timeout
);
329 extern int iscsi_io_recv_pdu(iscsi_conn_t
*conn
, struct iscsi_hdr
*hdr
,
330 int hdr_digest
, char *data
, int max_data_length
, int data_digest
,
334 extern int session_login_task(node_rec_t
*rec
, queue_task_t
*qtask
);
335 extern int session_logout_task(int sid
, queue_task_t
*qtask
);
336 extern iscsi_session_t
*session_find_by_sid(uint32_t sid
);
337 extern int iscsi_sync_session(node_rec_t
*rec
, queue_task_t
339 extern int iscsi_host_send_targets(queue_task_t
*qtask
,
340 int host_no
, int do_login
, struct sockaddr_storage
*ss
);
342 extern void free_initiator(void);
343 extern void iscsi_initiator_init(void);
345 /* initiator code common to discovery and normal sessions */
346 extern int iscsi_session_set_params(struct iscsi_conn
*conn
);
347 extern int iscsi_host_set_params(struct iscsi_session
*session
);
348 extern int iscsi_host_set_net_params(struct iface_rec
*iface
,
349 struct iscsi_session
*session
);
350 extern void iscsi_copy_operational_params(struct iscsi_conn
*conn
,
351 struct iscsi_session_operational_config
*session_conf
,
352 struct iscsi_conn_operational_config
*conn_conf
);
353 extern int iscsi_setup_authentication(struct iscsi_session
*session
,
354 struct iscsi_auth_config
*auth_cfg
);
355 extern int iscsi_setup_portal(struct iscsi_conn
*conn
, char *address
, int port
);
357 #endif /* INITIATOR_H */