2 * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 | $Id: isc_subr.c 560 2009-05-07 07:37:49Z danny $
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_iscsi_initiator.h"
37 #include <sys/param.h>
38 #include <sys/kernel.h>
40 #include <sys/systm.h>
41 #include <sys/malloc.h>
42 #include <sys/ctype.h>
43 #include <sys/errno.h>
44 #include <sys/sysctl.h>
47 #include <sys/socketvar.h>
48 #include <sys/socket.h>
49 #include <sys/protosw.h>
51 #include <sys/ioccom.h>
52 #include <sys/queue.h>
53 #include <sys/kthread.h>
54 #include <sys/syslog.h>
56 #include <sys/libkern.h>
58 #include <dev/iscsi/initiator/iscsi.h>
59 #include <dev/iscsi/initiator/iscsivar.h>
61 MALLOC_DEFINE(M_ISC, "iSC", "iSCSI driver options");
64 i_strdupin(char *s, size_t maxlen)
69 p = malloc(maxlen, M_ISC, M_WAITOK);
70 if(copyinstr(s, p, maxlen, &len)) {
74 q = malloc(len, M_ISC, M_WAITOK);
82 i_crc32c(const void *buf, size_t size, uint32_t crc)
84 crc = crc ^ 0xffffffff;
85 crc = calculate_crc32c(crc, buf, size);
86 crc = crc ^ 0xffffffff;
91 | XXX: not finished coding
94 i_setopt(isc_session_t *sp, isc_opt_t *opt)
96 if(opt->maxRecvDataSegmentLength > 0) {
97 sp->opt.maxRecvDataSegmentLength = opt->maxRecvDataSegmentLength;
98 sdebug(2, "maxRecvDataSegmentLength=%d", sp->opt.maxRecvDataSegmentLength);
100 if(opt->maxXmitDataSegmentLength > 0) {
102 sp->opt.maxXmitDataSegmentLength = opt->maxXmitDataSegmentLength;
103 sdebug(2, "opt.maXmitDataSegmentLength=%d", sp->opt.maxXmitDataSegmentLength);
105 if(opt->maxBurstLength != 0) {
106 sp->opt.maxBurstLength = opt->maxBurstLength;
107 sdebug(2, "opt.maxBurstLength=%d", sp->opt.maxBurstLength);
110 if(opt->targetAddress != NULL) {
111 if(sp->opt.targetAddress != NULL)
112 free(sp->opt.targetAddress, M_ISC);
113 sp->opt.targetAddress = i_strdupin(opt->targetAddress, 128);
114 sdebug(2, "opt.targetAddress='%s'", sp->opt.targetAddress);
116 if(opt->targetName != NULL) {
117 if(sp->opt.targetName != NULL)
118 free(sp->opt.targetName, M_ISC);
119 sp->opt.targetName = i_strdupin(opt->targetName, 128);
120 sdebug(2, "opt.targetName='%s'", sp->opt.targetName);
122 if(opt->initiatorName != NULL) {
123 if(sp->opt.initiatorName != NULL)
124 free(sp->opt.initiatorName, M_ISC);
125 sp->opt.initiatorName = i_strdupin(opt->initiatorName, 128);
126 sdebug(2, "opt.initiatorName='%s'", sp->opt.initiatorName);
129 if(opt->maxluns > 0) {
130 if(opt->maxluns > ISCSI_MAX_LUNS)
131 sp->opt.maxluns = ISCSI_MAX_LUNS; // silently chop it down ...
132 sp->opt.maxluns = opt->maxluns;
133 sdebug(2, "opt.maxluns=%d", sp->opt.maxluns);
136 if(opt->headerDigest != NULL) {
137 sdebug(2, "opt.headerDigest='%s'", opt->headerDigest);
138 if(strcmp(opt->headerDigest, "CRC32C") == 0) {
139 sp->hdrDigest = (digest_t *)i_crc32c;
140 sdebug(2, "opt.headerDigest set");
143 if(opt->dataDigest != NULL) {
144 sdebug(2, "opt.dataDigest='%s'", opt->headerDigest);
145 if(strcmp(opt->dataDigest, "CRC32C") == 0) {
146 sp->dataDigest = (digest_t *)i_crc32c;
147 sdebug(2, "opt.dataDigest set");
155 i_freeopt(isc_opt_t *opt)
159 if(opt->targetAddress != NULL) {
160 free(opt->targetAddress, M_ISC);
161 opt->targetAddress = NULL;
163 if(opt->targetName != NULL) {
164 free(opt->targetName, M_ISC);
165 opt->targetName = NULL;
167 if(opt->initiatorName != NULL) {
168 free(opt->initiatorName, M_ISC);
169 opt->initiatorName = NULL;