iscsi tools: manage qla4xxx iscsi sessions with iscsiadm
[open-iscsi.git] / usr / initiator.h
blobb45caab7efc88362f1b8679a07917f92b31e9e24
1 /*
2 * iSCSI Initiator
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.
20 #ifndef INITIATOR_H
21 #define INITIATOR_H
23 #include <stdint.h>
24 #include <net/if.h>
25 #include <sys/time.h>
27 #include "types.h"
28 #include "iscsi_proto.h"
29 #include "iscsi_if.h"
30 #include "auth.h"
31 #include "mgmt_ipc.h"
32 #include "config.h"
33 #include "actor.h"
34 #include "list.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"
42 #ifndef LOCK_DIR
43 #define LOCK_DIR "/var/lock/iscsi"
44 #endif
45 #define LOCK_FILE LOCK_DIR"/lock"
46 #define LOCK_WRITE_FILE LOCK_DIR"/lock.write"
48 typedef enum iscsi_session_r_stage_e {
49 R_STAGE_NO_CHANGE,
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,
60 CONN_LOGIN_RETRY = 3,
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 {
67 LOGIN_OK = 0,
68 LOGIN_IO_ERROR = 1,
69 LOGIN_FAILED = 2,
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,
75 LOGIN_REDIRECT = 8,
78 typedef enum iscsi_event_e {
79 EV_UNKNOWN,
80 EV_CONN_RECV_PDU,
81 EV_CONN_POLL,
82 EV_CONN_ERROR,
83 EV_CONN_LOGOUT_TIMER,
84 EV_CONN_STOP,
85 EV_CONN_LOGIN,
86 } iscsi_event_e;
88 struct queue_task;
90 typedef struct iscsi_login_context {
91 int cid;
92 char *buffer;
93 size_t bufsize;
94 uint8_t status_class;
95 uint8_t status_detail;
96 struct iscsi_acl *auth_client;
97 struct iscsi_hdr pdu;
98 struct iscsi_login_rsp *login_rsp;
99 char *data;
100 int received_pdu;
101 int max_data_length;
102 int timeout;
103 int final;
104 enum iscsi_login_status ret;
105 struct queue_task *qtask;
106 } iscsi_login_context_t;
108 struct iscsi_session;
109 struct iscsi_conn;
110 struct iscsi_ev_context;
112 /* daemon's connection structure */
113 typedef struct iscsi_conn {
114 uint32_t id;
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;
122 int userspace_nop;
124 struct timeval initial_connect_time;
125 actor_t login_timer;
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 */
132 int current_stage;
133 int next_stage;
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
141 * IO through.
143 int socket_fd;
144 /* address being used for normal session connection */
145 struct sockaddr_storage saddr;
146 /* address received during login */
147 struct sockaddr_storage failback_saddr;
148 int tcp_window_size;
149 int type_of_service;
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;
155 int bind_ep;
157 /* timeouts */
158 int login_timeout;
159 int logout_timeout;
160 int auth_timeout;
161 int active_timeout;
163 int noop_out_interval;
164 int noop_out_timeout;
166 /* sequencing */
167 uint32_t exp_statsn;
169 /* negotiated parameters */
170 uint32_t hdrdgst_en;
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 */
174 } iscsi_conn_t;
176 struct iscsi_ev_context {
177 struct actor actor;
178 struct iscsi_conn *conn;
179 int allocated;
180 void *data;
183 typedef struct queue_task {
184 iscsi_conn_t *conn;
185 iscsiadm_req_t req;
186 iscsiadm_rsp_t rsp;
187 int mgmt_ipc_fd;
188 int allocated : 1;
189 /* Newer request types include a
190 * variable-length payload */
191 void *payload;
192 } queue_task_t;
194 struct iscsi_transport_template;
195 struct iscsi_transport;
197 /* daemon's session structure */
198 typedef struct iscsi_session {
199 struct list_head list;
200 uint32_t id;
201 uint32_t hostno;
202 char netdev[IFNAMSIZ];
203 struct iscsi_transport *t;
204 uint8_t use_ipc;
205 node_rec_t nrec; /* copy of original Node record in database */
206 unsigned int irrelevant_keys_bitmap;
207 int send_async_text;
208 uint32_t itt;
209 uint32_t cmdsn;
210 uint32_t exp_cmdsn;
211 uint32_t max_cmdsn;
212 int erl;
213 uint32_t imm_data_en;
214 uint32_t initial_r2t_en;
215 uint32_t fast_abort;
216 uint32_t first_burst;
217 uint32_t max_burst;
218 uint32_t pdu_inorder_en;
219 uint32_t dataseq_inorder_en;
220 uint32_t def_time2wait;
221 uint32_t def_time2retain;
222 int type;
223 int portal_group_tag;
224 uint8_t isid[6];
225 uint16_t tsih;
226 char target_name[TARGET_NAME_MAXLEN + 1];
227 char *target_alias;
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];
241 int password_length;
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];
246 uint64_t param_mask;
248 /* connection reopens during recovery */
249 int reopen_cnt;
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;
257 int abort_timeout;
260 * used for hw and sync up to notify caller that the operation
261 * is complete
263 queue_task_t *notify_qtask;
264 } iscsi_session_t;
266 /* login.c */
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);
291 /* Digest types */
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
315 /* netlink.c */
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);
320 /* io.c */
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,
331 int timeout);
333 /* initiator.c */
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
338 *tsk, uint32_t sid);
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 */