summaryrefslogtreecommitdiffstats
path: root/sbin/iscontrol
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2010-08-09 12:36:36 +0000
committerdes <des@FreeBSD.org>2010-08-09 12:36:36 +0000
commit9f1a6fc5a691fe47d9f9667fa2a112ee7e4bbdf0 (patch)
tree43342de6f254d6434829cb76dee008ac438a8d6d /sbin/iscontrol
parent855b4d34cabdc84251dc2751ba1a4d13588bc04e (diff)
downloadFreeBSD-src-9f1a6fc5a691fe47d9f9667fa2a112ee7e4bbdf0.zip
FreeBSD-src-9f1a6fc5a691fe47d9f9667fa2a112ee7e4bbdf0.tar.gz
- Add full support for header / data digests.
- Increase target limit from 4 to 64; this limit will be removed entirely at a later time. - Improve recovery from lost network connections. - Fix some potential deadlocks and a serious memory leak. - Fix incorrect use of MH_ALIGN (instead of M_ALIGN), which makes no practical difference, but triggers a KASSERT with INVARIANTS. - Fix some warnings in iscontrol(8) and improve the man page somewhat. Submitted by: Daniel Braniss <danny@cs.huji.ac.il> Sponsored by: Dansk Scanning A/S, Data Robotics Inc.
Diffstat (limited to 'sbin/iscontrol')
-rw-r--r--sbin/iscontrol/Makefile5
-rw-r--r--sbin/iscontrol/auth_subr.c6
-rw-r--r--sbin/iscontrol/config.c23
-rw-r--r--sbin/iscontrol/fsm.c117
-rw-r--r--sbin/iscontrol/iscontrol.832
-rw-r--r--sbin/iscontrol/iscontrol.c24
-rw-r--r--sbin/iscontrol/iscontrol.h4
-rw-r--r--sbin/iscontrol/iscsi.conf.53
-rw-r--r--sbin/iscontrol/login.c10
-rw-r--r--sbin/iscontrol/misc.c5
-rw-r--r--sbin/iscontrol/pdu.c22
-rw-r--r--sbin/iscontrol/pdu.h134
12 files changed, 142 insertions, 243 deletions
diff --git a/sbin/iscontrol/Makefile b/sbin/iscontrol/Makefile
index 446a5f4..1830ad9 100644
--- a/sbin/iscontrol/Makefile
+++ b/sbin/iscontrol/Makefile
@@ -4,9 +4,10 @@ SRCS= iscontrol.c pdu.c fsm.c config.c login.c auth_subr.c misc.c
PROG= iscontrol
DPADD= ${LIBCAM} ${LIBMD}
LDADD= -lcam -lmd
+S= ${.CURDIR}/../../sys
-WARNS?= 2
-CFLAGS += -I${.CURDIR}/../../sys/dev/iscsi/initiator
+WARNS?= 3
+CFLAGS += -I$S
#CFLAGS += -g -DDEBUG
MAN= iscsi.conf.5 iscontrol.8
diff --git a/sbin/iscontrol/auth_subr.c b/sbin/iscontrol/auth_subr.c
index 06c0ee5..375d06d 100644
--- a/sbin/iscontrol/auth_subr.c
+++ b/sbin/iscontrol/auth_subr.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$");
#include <md5.h>
#include <sha.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
static int
@@ -152,7 +152,7 @@ chapDigest(char *ap, char id, char *cp, char *chapSecret)
}
char *
-genChapChallenge(char *encoding, int len)
+genChapChallenge(char *encoding, uint len)
{
int fd;
unsigned char tmp[1024];
diff --git a/sbin/iscontrol/config.c b/sbin/iscontrol/config.c
index df3a490..197f178 100644
--- a/sbin/iscontrol/config.c
+++ b/sbin/iscontrol/config.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2009 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
/*
@@ -94,6 +94,11 @@ __FBSDID("$FreeBSD$");
#define OPT_iqn 34
#define OPT_sockbufsize 35
+/*
+ | sentinel
+ */
+#define OPT_end 0
+
#define _OFF(v) ((int)&((isc_opt_t *)NULL)->v)
#define _E(u, s, v) {.usage=u, .scope=s, .name=#v, .tokenID=OPT_##v}
@@ -145,7 +150,7 @@ textkey_t keyMap[] = {
_E(U_LO, S_SW, sessionType),
- {0}
+ _E(0, 0, end)
};
#define _OPT_INT(w) strtol((char *)w, NULL, 0)
@@ -154,7 +159,7 @@ textkey_t keyMap[] = {
static __inline int
_OPT_BOOL(char *w)
{
- if(isalpha(*w))
+ if(isalpha((unsigned char)*w))
return strcasecmp(w, "TRUE") == 0;
else
return _OPT_INT(w);
@@ -244,12 +249,12 @@ getConfig(FILE *fd, char *key, char **Ar, int *nargs)
len = 0;
state = 0;
while((lp = getline(fd)) != NULL) {
- for(; isspace(*lp); lp++)
+ for(; isspace((unsigned char)*lp); lp++)
;
switch(state) {
case 0:
if((p = strchr(lp, '{')) != NULL) {
- while((--p > lp) && *p && isspace(*p));
+ while((--p > lp) && *p && isspace((unsigned char)*p));
n = p - lp;
if(len && strncmp(lp, key, MAX(n, len)) == 0)
state = 2;
@@ -272,7 +277,7 @@ getConfig(FILE *fd, char *key, char **Ar, int *nargs)
}
- for(p = &lp[strlen(lp)-1]; isspace(*p); p--)
+ for(p = &lp[strlen(lp)-1]; isspace((unsigned char)*p); p--)
*p = 0;
if((*nargs)-- > 0)
*ar++ = strdup(lp);
@@ -351,9 +356,9 @@ parseArgs(int nargs, char **args, isc_opt_t *op)
continue;
*p = 0;
v = p + 1;
- while(isspace(*--p))
+ while(isspace((unsigned char)*--p))
*p = 0;
- while(isspace(*v))
+ while(isspace((unsigned char)*v))
v++;
if((tk = keyLookup(*ar)) == NULL)
continue;
diff --git a/sbin/iscontrol/fsm.c b/sbin/iscontrol/fsm.c
index 443ebca..ec71931 100644
--- a/sbin/iscontrol/fsm.c
+++ b/sbin/iscontrol/fsm.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$");
#include <stdarg.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
typedef enum {
@@ -99,26 +99,26 @@ tcpConnect(isess_t *sess)
#ifdef notyet
{
time_t sec;
- // make sure we are not in a loop
- // XXX: this code has to be tested
- sec = time(0) - sess->reconnect_time;
- if(sec > (5*60)) {
- // if we've been connected for more that 5 minutes
- // then just reconnect
- sess->reconnect_time = sec;
- sess->reconnect_cnt1 = 0;
- }
- else {
- //
- sess->reconnect_cnt1++;
- if((sec / sess->reconnect_cnt1) < 2) {
- // if less that 2 seconds from the last reconnect
- // we are most probably looping
- syslog(LOG_CRIT, "too many reconnects %d", sess->reconnect_cnt1);
- return 0;
+ // make sure we are not in a loop
+ // XXX: this code has to be tested
+ sec = time(0) - sess->reconnect_time;
+ if(sec > (5*60)) {
+ // if we've been connected for more that 5 minutes
+ // then just reconnect
+ sess->reconnect_time = sec;
+ sess->reconnect_cnt1 = 0;
+ }
+ else {
+ //
+ sess->reconnect_cnt1++;
+ if((sec / sess->reconnect_cnt1) < 2) {
+ // if less that 2 seconds from the last reconnect
+ // we are most probably looping
+ syslog(LOG_CRIT, "too many reconnects %d", sess->reconnect_cnt1);
+ return 0;
+ }
}
}
- }
#endif
sess->reconnect_cnt++;
}
@@ -140,13 +140,13 @@ tcpConnect(isess_t *sess)
if (soc == -1)
continue;
- // from Patrick.Guelat@imp.ch:
- // iscontrol can be called without waiting for the socket entry to time out
- val = 1;
+ // from Patrick.Guelat@imp.ch:
+ // iscontrol can be called without waiting for the socket entry to time out
+ val = 1;
if(setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, &val, (socklen_t)sizeof(val)) < 0) {
- fprintf(stderr, "Cannot set socket SO_REUSEADDR %d: %s\n\n",
- errno, strerror(errno));
- }
+ fprintf(stderr, "Cannot set socket SO_REUSEADDR %d: %s\n\n",
+ errno, strerror(errno));
+ }
if(connect(soc, res->ai_addr, res->ai_addrlen) == 0)
break;
@@ -196,7 +196,7 @@ tcpConnect(isess_t *sess)
}
sess->flags |= SESS_CONNECTED;
return T1;
- }
+ }
fprintf(stderr, "errno=%d\n", sv_errno);
perror("connect");
@@ -289,7 +289,7 @@ startSession(isess_t *sess)
// XXX: this has to go
size_t n;
n = sizeof(sess->isid);
- if(sysctlbyname("net.iscsi.isid", (void *)sess->isid, (size_t *)&n, 0, 0) != 0)
+ if(sysctlbyname("net.iscsi_initiator.isid", (void *)sess->isid, (size_t *)&n, 0, 0) != 0)
perror("sysctlbyname");
}
if(ioctl(fd, ISCSISETSES, &n)) {
@@ -343,29 +343,29 @@ trap(int sig)
}
}
-static void
+static int
doCAM(isess_t *sess)
{
char pathstr[1024];
union ccb *ccb;
- int i;
+ int i, n;
if(ioctl(sess->fd, ISCSIGETCAM, &sess->cam) != 0) {
syslog(LOG_WARNING, "ISCSIGETCAM failed: %d", errno);
- return;
+ return 0;
}
- debug(2, "nluns=%d", sess->cam.target_nluns);
+ debug(1, "nluns=%d", sess->cam.target_nluns);
/*
| for now will do this for each lun ...
*/
- for(i = 0; i < sess->cam.target_nluns; i++) {
+ for(n = i = 0; i < sess->cam.target_nluns; i++) {
debug(2, "CAM path_id=%d target_id=%d target_lun=%d",
sess->cam.path_id, sess->cam.target_id, sess->cam.target_lun[i]);
sess->camdev = cam_open_btl(sess->cam.path_id, sess->cam.target_id,
- sess->cam.target_lun[i], O_RDWR, NULL);
+ i, O_RDWR, NULL);
if(sess->camdev == NULL) {
- syslog(LOG_WARNING, "%s", cam_errbuf);
+ //syslog(LOG_WARNING, "%s", cam_errbuf);
debug(3, "%s", cam_errbuf);
continue;
}
@@ -378,20 +378,21 @@ doCAM(isess_t *sess)
ccb->ccb_h.func_code = XPT_REL_SIMQ;
ccb->crs.release_flags = RELSIM_ADJUST_OPENINGS;
ccb->crs.openings = sess->op->tags;
-
if(cam_send_ccb(sess->camdev, ccb) < 0)
- syslog(LOG_WARNING, "%s", cam_errbuf);
+ debug(2, "%s", cam_errbuf);
else
if((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
syslog(LOG_WARNING, "XPT_REL_SIMQ CCB failed");
// cam_error_print(sess->camdev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr);
}
- else
+ else {
+ n++;
syslog(LOG_INFO, "%s tagged openings now %d\n", pathstr, ccb->crs.openings);
-
+ }
cam_freeccb(ccb);
cam_close_device(sess->camdev);
}
+ return n;
}
static trans_t
@@ -417,7 +418,15 @@ supervise(isess_t *sess)
perror("daemon");
exit(1);
}
+ if(sess->op->pidfile != NULL) {
+ FILE *pidf;
+ pidf = fopen(sess->op->pidfile, "w");
+ if(pidf != NULL) {
+ fprintf(pidf, "%d\n", getpid());
+ fclose(pidf);
+ }
+ }
openlog("iscontrol", LOG_CONS|LOG_PERROR|LOG_PID|LOG_NDELAY, LOG_KERN);
syslog(LOG_INFO, "running");
@@ -426,7 +435,11 @@ supervise(isess_t *sess)
perror("ISCSISTART");
return -1;
}
- doCAM(sess);
+ if(doCAM(sess) == 0) {
+ syslog(LOG_WARNING, "no device found");
+ ioctl(sess->fd, ISCSISTOP);
+ return T15;
+ }
}
else {
@@ -449,7 +462,8 @@ supervise(isess_t *sess)
sess->flags |= SESS_FULLFEATURE;
sess->flags &= ~(SESS_REDIRECT | SESS_RECONNECT);
- printf("iscontrol: supervise starting main loop\n");
+ if(vflag)
+ printf("iscontrol: supervise starting main loop\n");
/*
| the main loop - actually do nothing
| all the work is done inside the kernel
@@ -468,14 +482,14 @@ supervise(isess_t *sess)
}
if(sess->flags & SESS_DISCONNECT) {
- val = 0;
- if(ioctl(sess->fd, ISCSISTOP, &val)) {
- perror("ISCSISTOP");
- }
sess->flags &= ~SESS_FULLFEATURE;
return T9;
}
else {
+ val = 0;
+ if(ioctl(sess->fd, ISCSISTOP, &val)) {
+ perror("ISCSISTOP");
+ }
sess->flags |= SESS_INITIALLOGIN1;
}
return T8;
@@ -490,7 +504,7 @@ handledDiscoveryResp(isess_t *sess, pdu_t *pp)
debug_called(3);
len = pp->ds_len;
- ptr = pp->ds;
+ ptr = pp->ds_addr;
while(len > 0) {
if(*ptr != 0)
printf("%s\n", ptr);
@@ -579,8 +593,13 @@ doLogin(isess_t *sess)
static int
handleLogoutResp(isess_t *sess, pdu_t *pp)
{
- if(sess->flags & SESS_DISCONNECT)
+ if(sess->flags & SESS_DISCONNECT) {
+ int val = 0;
+ if(ioctl(sess->fd, ISCSISTOP, &val)) {
+ perror("ISCSISTOP");
+ }
return 0;
+ }
return T13;
}
@@ -610,7 +629,7 @@ typedef enum {
S1, S2, /*S3,*/ S4, S5, S6, S7, S8
} state_t;
-#if 0
+/**
S1: FREE
S2: XPT_WAIT
S4: IN_LOGIN
@@ -652,7 +671,7 @@ typedef enum {
| +-----\ /--->\ / T14 |
| ------- --+----+------+T17
+---------------------------+
-#endif
+*/
int
fsm(isc_opt_t *op)
diff --git a/sbin/iscontrol/iscontrol.8 b/sbin/iscontrol/iscontrol.8
index 71595db..d2e8bdd 100644
--- a/sbin/iscontrol/iscontrol.8
+++ b/sbin/iscontrol/iscontrol.8
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2007-2008 Daniel Braniss <danny@cs.huji.ac.il>
+.\" Copyright (c) 2007-2010 Daniel Braniss <danny@cs.huji.ac.il>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -32,11 +32,12 @@
.Nd login/negotiator/control for an iSCSI initiator session
.Sh SYNOPSIS
.Nm
-.Op Fl vd
+.Op Fl dv
.Oo
-.Op Fl c Ar file
+.Fl c Ar file
.Op Fl n Ar nickname
.Oc
+.Op Fl p Ar pidfile
.Op Fl t Ar target
.Op Ar variable Ns = Ns Ar value
.Sh DESCRIPTION
@@ -57,26 +58,29 @@ It will terminate/logout the session
when a SIGHUP signal is received.
The flags are as follows:
.Bl -tag -width variable=value
-.It Fl v
-verbose mode.
-.It Fl d
-do a
-.Em discovery session
-and exit.
.It Fl c Ar file
a file containing configuration
.Em key-options ,
see
-.Xr iscsi.conf 5
+.Xr iscsi.conf 5 .
+.It Fl d
+do a
+.Em discovery session
+and exit.
.It Fl n Ar nickname
if
.Sy -c file
is specified, then search for the block named
.Em nickname
in that file, see
-.Xr iscsi.conf 5
+.Xr iscsi.conf 5 .
+.It Fl p Ar pidfile
+will write the process ID of the session to the specified
+.Em pidfile
.It Fl t Ar target
-is the target's IP address or name
+the target's IP address or name.
+.It Fl v
+verbose mode.
.It Ar variable Ns = Ns Ar value
see
.Xr iscsi.conf 5
@@ -86,13 +90,13 @@ possible values.
.Sh EXAMPLES
.Dl iscontrol -dt myiscsitarget
.Pp
-will start a
+will start a
.Em discovery session
with the target and
print to stdout the list of available targetnames/targetadresses.
Note: this listing does not necessarily mean availability, since
depending on the target configuration, a discovery session might
-not need login/access permission, but a
+not need login/access permission, but a
.Em full session
certainly does.
.sp
diff --git a/sbin/iscontrol/iscontrol.c b/sbin/iscontrol/iscontrol.c
index 8cfa5fa..c7bda0e 100644
--- a/sbin/iscontrol/iscontrol.c
+++ b/sbin/iscontrol/iscontrol.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,15 +53,11 @@ __FBSDID("$FreeBSD$");
#include <time.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
-#define USAGE "[-v] [-d] [-c config] [-n name] [-t target] "
-#define OPTIONS "vdc:t:n:"
-
-#ifndef DEBUG
-//int vflag;
-#endif
+#define USAGE "[-v] [-d] [-c config] [-n name] [-t target] [-p pidfile]"
+#define OPTIONS "vdc:t:n:p:"
token_t AuthMethods[] = {
{"None", NONE},
@@ -70,14 +66,14 @@ token_t AuthMethods[] = {
{"SPKM2", SPKM2},
{"SRP", SRP},
{"CHAP", CHAP},
- {0}
+ {0, 0}
};
token_t DigestMethods[] = {
{"None", 0},
{"CRC32", 1},
{"CRC32C", 1},
- {0}
+ {0, 0}
};
u_char isid[6 + 6];
@@ -128,7 +124,7 @@ int
main(int cc, char **vv)
{
int ch, disco;
- char *pname, *p, *q, *ta, *kw;
+ char *pname, *pidfile, *p, *q, *ta, *kw;
isc_opt_t *op;
FILE *fd;
@@ -141,6 +137,7 @@ main(int cc, char **vv)
kw = ta = 0;
disco = 0;
+ pidfile = NULL;
while((ch = getopt(cc, vv, OPTIONS)) != -1) {
switch(ch) {
@@ -163,6 +160,9 @@ main(int cc, char **vv)
case 'n':
kw = optarg;
break;
+ case 'p':
+ pidfile = optarg;
+ break;
default:
badu:
fprintf(stderr, "Usage: %s %s\n", pname, USAGE);
@@ -225,7 +225,7 @@ main(int cc, char **vv)
op->sessionType = "Discovery";
op->targetName = 0;
}
-
+ op->pidfile = pidfile;
fsm(op);
exit(0);
diff --git a/sbin/iscontrol/iscontrol.h b/sbin/iscontrol/iscontrol.h
index 5ab296d..6aa5612 100644
--- a/sbin/iscontrol/iscontrol.h
+++ b/sbin/iscontrol/iscontrol.h
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -154,7 +154,7 @@ void parseArgs(int nargs, char **args, isc_opt_t *op);
void parseConfig(FILE *fd, char *key, isc_opt_t *op);
char *chapDigest(char *ap, char id, char *cp, char *chapSecret);
-char *genChapChallenge(char *encoding, int len);
+char *genChapChallenge(char *encoding, uint len);
int str2bin(char *str, char **rsp);
char *bin2str(char *fmt, unsigned char *md, int blen);
diff --git a/sbin/iscontrol/iscsi.conf.5 b/sbin/iscontrol/iscsi.conf.5
index 299fa16..84f0f01 100644
--- a/sbin/iscontrol/iscsi.conf.5
+++ b/sbin/iscontrol/iscsi.conf.5
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2007-2008 Daniel Braniss <danny@cs.huji.ac.il>
+.\" Copyright (c) 2007-2010 Daniel Braniss <danny@cs.huji.ac.il>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -68,6 +68,7 @@ Only CRC32C is implemented.
Default is none.
.It Cm DataDigest
same as for HeaderDigest, but on the data part of the iSCSI PDU.
+(not yet tested)
.It Cm MaxConnections
is the number of simultaneous connections per session,
currently only 1.
diff --git a/sbin/iscontrol/login.c b/sbin/iscontrol/login.c
index ec17f21..e2a9e5f 100644
--- a/sbin/iscontrol/login.c
+++ b/sbin/iscontrol/login.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
static char *status_class1[] = {
@@ -107,7 +107,7 @@ getkeyval(char *key, pdu_t *pp)
debug_called(3);
len = pp->ds_len;
- ptr = (char *)pp->ds;
+ ptr = (char *)pp->ds_addr;
klen = strlen(key);
while(len > klen) {
if(strncmp(key, ptr, klen) == 0)
@@ -163,7 +163,7 @@ processParams(isess_t *sess, pdu_t *pp)
debug_called(3);
len = pp->ds_len;
- ptr = (char *)pp->ds;
+ ptr = (char *)pp->ds_addr;
while(len > 0) {
if(vflag > 1)
printf("got: len=%d %s\n", len, ptr);
@@ -233,7 +233,7 @@ handleLoginResp(isess_t *sess, pdu_t *pp)
st_class = status >> 8;
if(status) {
- int st_detail = status & 0xff;
+ uint st_detail = status & 0xff;
switch(st_class) {
case 1: // Redirect
diff --git a/sbin/iscontrol/misc.c b/sbin/iscontrol/misc.c
index 9634a1b..1c7a1ad 100644
--- a/sbin/iscontrol/misc.c
+++ b/sbin/iscontrol/misc.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,9 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <string.h>
+#include <dev/iscsi/initiator/iscsi.h>
+#include "iscontrol.h"
+
static inline char
c2b(unsigned char c)
{
diff --git a/sbin/iscontrol/pdu.c b/sbin/iscontrol/pdu.c
index 444c1f1..c4d3a2a 100644
--- a/sbin/iscontrol/pdu.c
+++ b/sbin/iscontrol/pdu.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$");
#include <stdarg.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
static void pukeText(char *it, pdu_t *pp);
@@ -85,7 +85,7 @@ sendPDU(isess_t *sess, pdu_t *pp, handler_t *hdlr)
int res;
pp->ahs_size = 8 * 1024;
- if((pp->ahs = malloc(pp->ahs_size)) == NULL) {
+ if((pp->ahs_addr = malloc(pp->ahs_size)) == NULL) {
fprintf(stderr, "out of mem!");
return -1;
}
@@ -126,16 +126,16 @@ addText(pdu_t *pp, char *fmt, ...)
if((pp->ds_len + len) > pp->ds_size) {
u_char *np;
- np = realloc(pp->ds, pp->ds_size + len + FUDGE);
+ np = realloc(pp->ds_addr, pp->ds_size + len + FUDGE);
if(np == NULL) {
free(str);
//XXX: out of memory!
return -1;
}
- pp->ds = np;
+ pp->ds_addr = np;
pp->ds_size += len + FUDGE;
}
- memcpy(pp->ds + pp->ds_len, str, len);
+ memcpy(pp->ds_addr + pp->ds_len, str, len);
pp->ds_len += len;
free(str);
return len;
@@ -145,12 +145,12 @@ void
freePDU(pdu_t *pp)
{
if(pp->ahs_size)
- free(pp->ahs);
+ free(pp->ahs_addr);
if(pp->ds_size)
- free(pp->ds);
+ free(pp->ds_addr);
bzero(&pp->ipdu, sizeof(union ipdu_u));
- pp->ahs = NULL;
- pp->ds = NULL;
+ pp->ahs_addr = NULL;
+ pp->ds_addr = NULL;
pp->ahs_size = 0;
pp->ds_size = pp->ds_len = 0;
}
@@ -163,7 +163,7 @@ pukeText(char *it, pdu_t *pp)
size_t len, n;
len = pp->ds_len;
- ptr = (char *)pp->ds;
+ ptr = (char *)pp->ds_addr;
cmd = pp->ipdu.bhs.opcode;
printf("%s: cmd=0x%x len=%d\n", it, cmd, (int)len);
diff --git a/sbin/iscontrol/pdu.h b/sbin/iscontrol/pdu.h
deleted file mode 100644
index 0154f9e..0000000
--- a/sbin/iscontrol/pdu.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*-
- * Copyright (c) 2005 Daniel Braniss <danny@cs.huji.ac.il>
- * 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.
- *
- * $FreeBSD$
- */
-/*
- | $Id: pdu.h,v 2.1 2006/11/12 08:06:51 danny Exp $
- */
-
-/*
- | keep in BIG endian order (network byte order).
- */
-
-typedef struct login_req {
- char cmd; // 0x03
-
- u_char NSG:2;
- u_char CSG:2;
- u_char _:2;
- u_char C:1;
- u_char T:1;
-
- char v_max;
- char v_min;
-
- int len; // remapped via standard bhs
- char isid[6];
- short tsih;
- int itt; // Initiator Task Tag;
-
- int CID:16;
- int rsv:16;
-
- int cmdSN;
- int expStatSN;
- int unused[4];
-} login_req_t;
-
-typedef struct login_rsp {
- char cmd; // 0x23
- u_char NSG:2;
- u_char CSG:2;
- u_char _1:2;
- u_char C:1;
- u_char T:1;
-
- char v_max;
- char v_act;
-
- int len; // remapped via standard bhs
- char isid[6];
- short tsih;
- int itt; // Initiator Task Tag;
- int _2;
- rsp_sn_t sn;
- int status:16;
- int _3:16;
- int _4[2];
-} login_rsp_t;
-
-typedef struct text_req {
- char cmd; // 0x04
-
- u_char _1:6;
- u_char C:1; // Continuation
- u_char F:1; // Final
- char _2[2];
-
- int len;
- int itt; // Initiator Task Tag
- int LUN[2];
- int ttt; // Target Transfer Tag
- int cmdSN;
- int expStatSN;
- int unused[4];
-} text_req_t;
-
-/*
- | Responses
- */
-typedef struct logout_req {
- char cmd; // 0x06
- char reason; // 0 - close session
- // 1 - close connection
- // 2 - remove the connection for recovery
- char _2[2];
-
- int len;
- int _r[2];
- int itt; // Initiator Task Tag;
-
- u_int CID:16;
- u_int rsv:16;
-
- int cmdSN;
- int expStatSN;
- int unused[4];
-} logout_req_t;
-
-typedef struct logout_rsp {
- char cmd; // 0x26
- char cbits;
- char _1[2];
- int len;
- int _2[2];
- int itt;
- int _3;
- rsp_sn_t sn;
- short time2wait;
- short time2retain;
- int _4;
-} logout_rsp_t;
OpenPOWER on IntegriCloud