2007-07-24 15:35:02 +00:00
|
|
|
/*-
|
2010-08-09 12:36:36 +00:00
|
|
|
* Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
|
2007-07-24 15:35:02 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
| iSCSI
|
2010-08-09 12:36:36 +00:00
|
|
|
| $Id: isc_subr.c 560 2009-05-07 07:37:49Z danny $
|
2007-07-24 15:35:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_iscsi_initiator.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ctype.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/kthread.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/libkern.h>
|
|
|
|
|
|
|
|
#include <dev/iscsi/initiator/iscsi.h>
|
|
|
|
#include <dev/iscsi/initiator/iscsivar.h>
|
|
|
|
|
2010-08-09 12:36:36 +00:00
|
|
|
MALLOC_DEFINE(M_ISC, "iSC", "iSCSI driver options");
|
|
|
|
|
2007-07-24 15:35:02 +00:00
|
|
|
static char *
|
|
|
|
i_strdupin(char *s, size_t maxlen)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
char *p, *q;
|
|
|
|
|
2010-08-09 12:36:36 +00:00
|
|
|
p = malloc(maxlen, M_ISC, M_WAITOK);
|
2007-07-24 15:35:02 +00:00
|
|
|
if(copyinstr(s, p, maxlen, &len)) {
|
2010-08-09 12:36:36 +00:00
|
|
|
free(p, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-08-09 12:36:36 +00:00
|
|
|
q = malloc(len, M_ISC, M_WAITOK);
|
2007-07-24 15:35:02 +00:00
|
|
|
bcopy(p, q, len);
|
2010-08-09 12:36:36 +00:00
|
|
|
free(p, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
i_crc32c(const void *buf, size_t size, uint32_t crc)
|
|
|
|
{
|
|
|
|
crc = crc ^ 0xffffffff;
|
2009-02-14 11:34:57 +00:00
|
|
|
crc = calculate_crc32c(crc, buf, size);
|
2007-07-24 15:35:02 +00:00
|
|
|
crc = crc ^ 0xffffffff;
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
| XXX: not finished coding
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
i_setopt(isc_session_t *sp, isc_opt_t *opt)
|
|
|
|
{
|
|
|
|
if(opt->maxRecvDataSegmentLength > 0) {
|
|
|
|
sp->opt.maxRecvDataSegmentLength = opt->maxRecvDataSegmentLength;
|
|
|
|
sdebug(2, "maxRecvDataSegmentLength=%d", sp->opt.maxRecvDataSegmentLength);
|
|
|
|
}
|
|
|
|
if(opt->maxXmitDataSegmentLength > 0) {
|
|
|
|
// danny's RFC
|
|
|
|
sp->opt.maxXmitDataSegmentLength = opt->maxXmitDataSegmentLength;
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.maXmitDataSegmentLength=%d", sp->opt.maxXmitDataSegmentLength);
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
if(opt->maxBurstLength != 0) {
|
|
|
|
sp->opt.maxBurstLength = opt->maxBurstLength;
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.maxBurstLength=%d", sp->opt.maxBurstLength);
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(opt->targetAddress != NULL) {
|
|
|
|
if(sp->opt.targetAddress != NULL)
|
2010-08-09 12:36:36 +00:00
|
|
|
free(sp->opt.targetAddress, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
sp->opt.targetAddress = i_strdupin(opt->targetAddress, 128);
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.targetAddress='%s'", sp->opt.targetAddress);
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
if(opt->targetName != NULL) {
|
|
|
|
if(sp->opt.targetName != NULL)
|
2010-08-09 12:36:36 +00:00
|
|
|
free(sp->opt.targetName, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
sp->opt.targetName = i_strdupin(opt->targetName, 128);
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.targetName='%s'", sp->opt.targetName);
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
if(opt->initiatorName != NULL) {
|
|
|
|
if(sp->opt.initiatorName != NULL)
|
2010-08-09 12:36:36 +00:00
|
|
|
free(sp->opt.initiatorName, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
sp->opt.initiatorName = i_strdupin(opt->initiatorName, 128);
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.initiatorName='%s'", sp->opt.initiatorName);
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(opt->maxluns > 0) {
|
|
|
|
if(opt->maxluns > ISCSI_MAX_LUNS)
|
|
|
|
sp->opt.maxluns = ISCSI_MAX_LUNS; // silently chop it down ...
|
|
|
|
sp->opt.maxluns = opt->maxluns;
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.maxluns=%d", sp->opt.maxluns);
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(opt->headerDigest != NULL) {
|
|
|
|
sdebug(2, "opt.headerDigest='%s'", opt->headerDigest);
|
|
|
|
if(strcmp(opt->headerDigest, "CRC32C") == 0) {
|
|
|
|
sp->hdrDigest = (digest_t *)i_crc32c;
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.headerDigest set");
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(opt->dataDigest != NULL) {
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.dataDigest='%s'", opt->headerDigest);
|
2007-07-24 15:35:02 +00:00
|
|
|
if(strcmp(opt->dataDigest, "CRC32C") == 0) {
|
|
|
|
sp->dataDigest = (digest_t *)i_crc32c;
|
2010-08-09 12:36:36 +00:00
|
|
|
sdebug(2, "opt.dataDigest set");
|
2007-07-24 15:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
i_freeopt(isc_opt_t *opt)
|
|
|
|
{
|
2010-08-09 12:36:36 +00:00
|
|
|
debug_called(8);
|
|
|
|
|
2007-07-24 15:35:02 +00:00
|
|
|
if(opt->targetAddress != NULL) {
|
2010-08-09 12:36:36 +00:00
|
|
|
free(opt->targetAddress, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
opt->targetAddress = NULL;
|
|
|
|
}
|
|
|
|
if(opt->targetName != NULL) {
|
2010-08-09 12:36:36 +00:00
|
|
|
free(opt->targetName, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
opt->targetName = NULL;
|
|
|
|
}
|
|
|
|
if(opt->initiatorName != NULL) {
|
2010-08-09 12:36:36 +00:00
|
|
|
free(opt->initiatorName, M_ISC);
|
2007-07-24 15:35:02 +00:00
|
|
|
opt->initiatorName = NULL;
|
|
|
|
}
|
|
|
|
}
|