ISID: Add helper functions to set any type of ISID value for the iscsi context.
Let default be to create a 'random' ISID during context creation.
This commit is contained in:
@@ -15,12 +15,13 @@
|
|||||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
struct iscsi_context;
|
struct iscsi_context;
|
||||||
struct sockaddr;
|
struct sockaddr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following three functions are used to integrate libiscsi in an event
|
* The following three functions are used to integrate libiscsi in an event
|
||||||
* system.
|
* system.
|
||||||
@@ -147,8 +148,8 @@ enum iscsi_session_type {
|
|||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* Set the session type for a scsi context.
|
* Set the session type for a scsi context.
|
||||||
* Session type can only be set/changed while the iscsi context is not
|
* Session type can only be set/changed before the context
|
||||||
* logged in to a target.
|
* is logged in to the target.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0: success
|
* 0: success
|
||||||
@@ -170,8 +171,8 @@ enum iscsi_header_digest {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the desired header digest for a scsi context.
|
* Set the desired header digest for a scsi context.
|
||||||
* Header digest can only be set/changed while the iscsi context is not
|
* Header digest can only be set/changed before the context
|
||||||
* logged in to a target.
|
* is logged in to the target.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0: success
|
* 0: success
|
||||||
@@ -429,6 +430,24 @@ struct iscsi_data {
|
|||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These functions will set the ISID type and value.
|
||||||
|
* By default, contexts will automatically be assigned a 'random'
|
||||||
|
* type and value on creation, but this can be overridden
|
||||||
|
* by an appplication using these functions.
|
||||||
|
*
|
||||||
|
* Setting the ISID can only be done before loggin in to the target.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
iscsi_set_isid_oui(struct iscsi_context *iscsi, uint32_t oui, uint32_t qualifier);
|
||||||
|
int
|
||||||
|
iscsi_set_isid_en(struct iscsi_context *iscsi, uint32_t en, uint32_t qualifier);
|
||||||
|
int
|
||||||
|
iscsi_set_isid_random(struct iscsi_context *iscsi, uint32_t rnd, uint32_t qualifier);
|
||||||
|
int
|
||||||
|
iscsi_set_isid_reserved(struct iscsi_context *iscsi);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Async commands for SCSI
|
* Async commands for SCSI
|
||||||
*/
|
*/
|
||||||
@@ -494,5 +513,3 @@ struct scsi_task *
|
|||||||
iscsi_synchronizecache10_sync(struct iscsi_context *iscsi, int lun, int lba,
|
iscsi_synchronizecache10_sync(struct iscsi_context *iscsi, int lun, int lba,
|
||||||
int num_blocks, int syncnv, int immed);
|
int num_blocks, int syncnv, int immed);
|
||||||
|
|
||||||
int
|
|
||||||
iscsi_set_isid_random(struct iscsi_context *iscsi, int rnd);
|
|
||||||
|
|||||||
60
lib/init.c
60
lib/init.c
@@ -55,7 +55,7 @@ iscsi_create_context(const char *initiator_name)
|
|||||||
iscsi->fd = -1;
|
iscsi->fd = -1;
|
||||||
|
|
||||||
/* initialize to a "random" isid */
|
/* initialize to a "random" isid */
|
||||||
iscsi_set_isid_random(iscsi, getpid() ^ time(NULL));
|
iscsi_set_isid_random(iscsi, getpid() ^ time(NULL), 0);
|
||||||
|
|
||||||
/* assume we start in security negotiation phase */
|
/* assume we start in security negotiation phase */
|
||||||
iscsi->current_phase = ISCSI_PDU_LOGIN_CSG_SECNEG;
|
iscsi->current_phase = ISCSI_PDU_LOGIN_CSG_SECNEG;
|
||||||
@@ -76,14 +76,60 @@ iscsi_create_context(const char *initiator_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
iscsi_set_isid_random(struct iscsi_context *iscsi, int rnd)
|
iscsi_set_isid_oui(struct iscsi_context *iscsi, uint32_t oui, uint32_t qualifier)
|
||||||
|
{
|
||||||
|
iscsi->isid[0] = (oui >> 16) & 0x3f;
|
||||||
|
iscsi->isid[1] = (oui >> 8) & 0xff;
|
||||||
|
iscsi->isid[2] = (oui ) & 0xff;
|
||||||
|
|
||||||
|
iscsi->isid[3] = (qualifier >> 16) & 0xff;
|
||||||
|
iscsi->isid[4] = (qualifier >> 8) & 0xff;
|
||||||
|
iscsi->isid[5] = (qualifier ) & 0xff;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
iscsi_set_isid_en(struct iscsi_context *iscsi, uint32_t en, uint32_t qualifier)
|
||||||
|
{
|
||||||
|
iscsi->isid[0] = 0x40;
|
||||||
|
|
||||||
|
iscsi->isid[1] = (en >> 16) & 0xff;
|
||||||
|
iscsi->isid[2] = (en >> 8) & 0xff;
|
||||||
|
iscsi->isid[3] = (en ) & 0xff;
|
||||||
|
|
||||||
|
iscsi->isid[4] = (qualifier >> 8) & 0xff;
|
||||||
|
iscsi->isid[5] = (qualifier ) & 0xff;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
iscsi_set_isid_random(struct iscsi_context *iscsi, uint32_t rnd, uint32_t qualifier)
|
||||||
{
|
{
|
||||||
iscsi->isid[0] = 0x80;
|
iscsi->isid[0] = 0x80;
|
||||||
iscsi->isid[1] = rnd&0xff;
|
|
||||||
iscsi->isid[2] = rnd&0xff;
|
iscsi->isid[1] = (rnd >> 16) & 0xff;
|
||||||
iscsi->isid[3] = rnd&0xff;
|
iscsi->isid[2] = (rnd >> 8) & 0xff;
|
||||||
iscsi->isid[4] = 0;
|
iscsi->isid[3] = (rnd ) & 0xff;
|
||||||
iscsi->isid[5] = 0;
|
|
||||||
|
iscsi->isid[4] = (qualifier >> 8) & 0xff;
|
||||||
|
iscsi->isid[5] = (qualifier ) & 0xff;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
iscsi_set_isid_reserved(struct iscsi_context *iscsi)
|
||||||
|
{
|
||||||
|
iscsi->isid[0] = 0xc0;
|
||||||
|
|
||||||
|
iscsi->isid[1] = 0x00;
|
||||||
|
iscsi->isid[2] = 0x00;
|
||||||
|
iscsi->isid[3] = 0x00;
|
||||||
|
iscsi->isid[4] = 0x00;
|
||||||
|
iscsi->isid[5] = 0x00;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user