26 */ |
26 */ |
27 |
27 |
28 /* |
28 /* |
29 * Framework interface routines for iSCSI |
29 * Framework interface routines for iSCSI |
30 */ |
30 */ |
31 #include "iscsi.h" /* main header */ |
31 #include "iscsi.h" /* main header */ |
|
32 #include <sys/idm/idm_text.h> /* main header */ |
|
33 #include <sys/iscsi_protocol.h> /* protocol structs */ |
32 #include <sys/scsi/adapters/iscsi_if.h> /* ioctl interfaces */ |
34 #include <sys/scsi/adapters/iscsi_if.h> /* ioctl interfaces */ |
33 /* protocol structs and defines */ |
|
34 #include <sys/iscsi_protocol.h> |
|
35 #include "persistent.h" |
35 #include "persistent.h" |
36 #include <sys/scsi/adapters/iscsi_door.h> |
36 #include <sys/scsi/adapters/iscsi_door.h> |
37 #include "iscsi_targetparam.h" |
37 #include "iscsi_targetparam.h" |
38 #include <sys/strsubr.h> |
38 #include <sys/strsubr.h> |
39 #include <sys/socketvar.h> |
39 #include <sys/socketvar.h> |
235 iscsi_ioctl_conn_props_get(iscsi_hba_t *ihp, iscsi_conn_props_t *cp) |
235 iscsi_ioctl_conn_props_get(iscsi_hba_t *ihp, iscsi_conn_props_t *cp) |
236 { |
236 { |
237 iscsi_sess_t *isp; |
237 iscsi_sess_t *isp; |
238 iscsi_conn_t *icp; |
238 iscsi_conn_t *icp; |
239 boolean_t rtn; |
239 boolean_t rtn; |
240 struct sockaddr_in6 t_addr; |
240 idm_conn_t *idm_conn; |
241 socklen_t t_addrlen; |
|
242 |
241 |
243 /* Let's check the version. */ |
242 /* Let's check the version. */ |
244 if (cp->cp_vers != ISCSI_INTERFACE_VERSION) { |
243 if (cp->cp_vers != ISCSI_INTERFACE_VERSION) { |
245 return (B_FALSE); |
244 return (B_FALSE); |
246 } |
245 } |
247 |
246 |
248 bzero(&t_addr, sizeof (struct sockaddr_in6)); |
|
249 t_addrlen = sizeof (struct sockaddr_in6); |
|
250 /* Let's find the session. */ |
247 /* Let's find the session. */ |
251 rw_enter(&ihp->hba_sess_list_rwlock, RW_READER); |
248 rw_enter(&ihp->hba_sess_list_rwlock, RW_READER); |
252 if (iscsi_sess_get(cp->cp_sess_oid, ihp, &isp) != 0) { |
249 if (iscsi_sess_get(cp->cp_sess_oid, ihp, &isp) != 0) { |
253 rw_exit(&ihp->hba_sess_list_rwlock); |
250 rw_exit(&ihp->hba_sess_list_rwlock); |
254 return (B_FALSE); |
251 return (B_FALSE); |
265 while (icp != NULL) { |
262 while (icp != NULL) { |
266 |
263 |
267 ASSERT(icp->conn_sig == ISCSI_SIG_CONN); |
264 ASSERT(icp->conn_sig == ISCSI_SIG_CONN); |
268 |
265 |
269 if (icp->conn_oid == cp->cp_oid) { |
266 if (icp->conn_oid == cp->cp_oid) { |
270 iscsi_net->getsockname(icp->conn_socket, |
267 struct sockaddr_storage *sal; |
271 (struct sockaddr *)&t_addr, &t_addrlen); |
268 struct sockaddr_storage *sar; |
272 if (t_addrlen <= sizeof (cp->cp_local)) { |
269 |
273 bcopy(&t_addr, &cp->cp_local, t_addrlen); |
270 idm_conn = |
274 } |
271 (idm_conn_t *)icp->conn_ic; |
275 ksocket_getpeername((ksocket_t)(icp->conn_socket), |
272 |
276 (struct sockaddr *)&t_addr, &t_addrlen, CRED()); |
273 sal = &idm_conn->ic_laddr; |
277 if (t_addrlen <= sizeof (cp->cp_peer)) { |
274 sar = &idm_conn->ic_raddr; |
278 bcopy(&t_addr, &cp->cp_peer, t_addrlen); |
275 |
|
276 /* Local Address */ |
|
277 if (sal->ss_family == AF_INET) { |
|
278 bcopy(&idm_conn->ic_laddr, |
|
279 &cp->cp_local, |
|
280 sizeof (struct sockaddr_in)); |
|
281 } else { |
|
282 bcopy(&idm_conn->ic_laddr, |
|
283 &cp->cp_local, |
|
284 sizeof (struct sockaddr_in6)); |
|
285 } |
|
286 |
|
287 /* Peer Address */ |
|
288 if (sar->ss_family == AF_INET) { |
|
289 bcopy(&idm_conn->ic_raddr, |
|
290 &cp->cp_peer, |
|
291 sizeof (struct sockaddr_in)); |
|
292 } else { |
|
293 bcopy(&idm_conn->ic_raddr, |
|
294 &cp->cp_peer, |
|
295 sizeof (struct sockaddr_in6)); |
279 } |
296 } |
280 |
297 |
281 if (icp->conn_state == ISCSI_CONN_STATE_LOGGED_IN) { |
298 if (icp->conn_state == ISCSI_CONN_STATE_LOGGED_IN) { |
282 cp->cp_params_valid = B_TRUE; |
299 cp->cp_params_valid = B_TRUE; |
283 bcopy(&icp->conn_params, &cp->cp_params, |
300 bcopy(&icp->conn_params, &cp->cp_params, |
343 } |
360 } |
344 rw_exit(&ihp->hba_sess_list_rwlock); |
361 rw_exit(&ihp->hba_sess_list_rwlock); |
345 |
362 |
346 /* start login */ |
363 /* start login */ |
347 mutex_enter(&icp->conn_state_mutex); |
364 mutex_enter(&icp->conn_state_mutex); |
348 (void) iscsi_conn_state_machine(icp, ISCSI_CONN_EVENT_T1); |
365 status = iscsi_conn_online(icp); |
349 mutex_exit(&icp->conn_state_mutex); |
366 mutex_exit(&icp->conn_state_mutex); |
350 |
367 |
351 if (icp->conn_state == ISCSI_CONN_STATE_LOGGED_IN) { |
368 if (status == ISCSI_STATUS_SUCCESS) { |
352 data_len = icp->conn_params.max_xmit_data_seg_len; |
369 data_len = icp->conn_params.max_xmit_data_seg_len; |
353 retry_sendtgts: |
370 retry_sendtgts: |
354 /* alloc/init buffer for SendTargets req/resp */ |
371 /* alloc/init buffer for SendTargets req/resp */ |
355 data = kmem_zalloc(data_len, KM_SLEEP); |
372 data = kmem_zalloc(data_len, KM_SLEEP); |
356 bcopy(ISCSI_SENDTGTS_REQ_STR, data, |
373 bcopy(ISCSI_SENDTGTS_REQ_STR, data, |