iscontrol.h revision 211095
170856Sjhb/*-
270856Sjhb * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il>
370856Sjhb * All rights reserved.
470856Sjhb *
570856Sjhb * Redistribution and use in source and binary forms, with or without
670856Sjhb * modification, are permitted provided that the following conditions
770856Sjhb * are met:
870856Sjhb * 1. Redistributions of source code must retain the above copyright
970856Sjhb *    notice, this list of conditions and the following disclaimer.
1070856Sjhb * 2. Redistributions in binary form must reproduce the above copyright
1170856Sjhb *    notice, this list of conditions and the following disclaimer in the
1270856Sjhb *    documentation and/or other materials provided with the distribution.
1370856Sjhb *
1470856Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1570856Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1670856Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1770856Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1870856Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1970856Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2070856Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2170856Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2270856Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2370856Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2470856Sjhb * SUCH DAMAGE.
2570856Sjhb *
2670856Sjhb * $FreeBSD: head/sbin/iscontrol/iscontrol.h 211095 2010-08-09 12:36:36Z des $
2770856Sjhb */
2870856Sjhb/*
2970856Sjhb | $Id: iscontrol.h,v 2.3 2007/04/27 08:36:49 danny Exp danny $
3070856Sjhb */
3170856Sjhb#ifdef DEBUG
3270856Sjhbint vflag;
3370856Sjhb
3470856Sjhb# define debug(level, fmt, args...)	do {if (level <= vflag) printf("%s: " fmt "\n", __func__ , ##args);} while(0)
3570856Sjhb# define debug_called(level)		do {if (level <= vflag) printf("%s: called\n", __func__);} while(0)
3670856Sjhb#else
3770856Sjhb# define debug(level, fmt, args...)
3870856Sjhb# define debug_called(level)
3970856Sjhb#endif // DEBUG
4070856Sjhb#define xdebug(fmt, args...)	printf("%s: " fmt "\n", __func__ , ##args)
4170856Sjhb
4270856Sjhb#define BIT(n)	(1 <<(n))
4370856Sjhb
4470856Sjhb#define MAXREDIRECTS	2
4570856Sjhb
4670856Sjhbtypedef int auth_t(void *sess);
4770856Sjhb
4870856Sjhbtypedef struct {
4970856Sjhb     char      *address;
5070856Sjhb     int       port;
5170856Sjhb     int       pgt;
5270856Sjhb} target_t;
5370856Sjhb
5470856Sjhbtypedef struct isess {
5570856Sjhb     int	flags;
5670856Sjhb#define SESS_CONNECTED		BIT(0)
5770856Sjhb#define SESS_DISCONNECT		BIT(1)
5870856Sjhb#define SESS_LOGGEDIN		BIT(2)
5970856Sjhb#define SESS_RECONNECT		BIT(3)
6070856Sjhb#define SESS_REDIRECT		BIT(4)
6170856Sjhb
6270856Sjhb#define SESS_NEGODONE		BIT(10)	// XXX: kludge
6370856Sjhb
6470856Sjhb#define SESS_FULLFEATURE	BIT(29)
6570856Sjhb#define SESS_INITIALLOGIN1	BIT(30)
6670856Sjhb#define SESS_INITIALLOGIN	BIT(31)
6770856Sjhb
6870856Sjhb
6970856Sjhb     isc_opt_t	*op;		// operational values
7070856Sjhb     target_t  target;         // the Original target address
7170856Sjhb     int	fd;		// the session fd
7270856Sjhb     int	soc;		// the socket
7370856Sjhb     iscsi_cam_t	cam;
7470856Sjhb     struct cam_device	*camdev;
7570856Sjhb
7670856Sjhb     time_t	open_time;
7770856Sjhb     int	redirect_cnt;
7870856Sjhb     time_t	redirect_time;
7970856Sjhb     int	reconnect_cnt;
8070856Sjhb     int	reconnect_cnt1;
8170856Sjhb     time_t	reconnect_time;
8270856Sjhb     char	isid[6+1];
8370856Sjhb     int	csg;		// current stage
8470856Sjhb     int	nsg;		// next stage
8570856Sjhb     // Phases/Stages
8670856Sjhb#define	SN_PHASE	0	// Security Negotiation
8770856Sjhb#define LON_PHASE	1	// Login Operational Negotiation
8870856Sjhb#define FF_PHASE	3	// FuLL-Feature
8970856Sjhb     uint	tsih;
9070856Sjhb     sn_t	sn;
9170856Sjhb} isess_t;
9270856Sjhb
9370856Sjhbtypedef struct token {
9470856Sjhb     char	*name;
9570856Sjhb     int	val;
9670856Sjhb} token_t;
9770856Sjhb
9870856Sjhbtypedef enum {
9970856Sjhb     NONE	= 0,
10070856Sjhb     KRB5,
10170856Sjhb     SPKM1,
10270856Sjhb     SPKM2,
10370856Sjhb     SRP,
10470856Sjhb     CHAP
10570856Sjhb} authm_t;
10670856Sjhb
10770856Sjhbextern token_t AuthMethods[];
10870856Sjhbextern token_t DigestMethods[];
10970856Sjhb
11070856Sjhbtypedef enum {
11170856Sjhb     SET,
11270856Sjhb     GET
11370856Sjhb} oper_t;
11470856Sjhb
11570856Sjhbtypedef enum {
11670856Sjhb     U_PR,	// private
11770856Sjhb     U_IO,	// Initialize Only -- during login
11870856Sjhb     U_LO,	// Leading Only -- when TSIH is zero
11970856Sjhb     U_FFPO,	// Full Feature Phase Only
12070856Sjhb     U_ALL	// in any phase
12170856Sjhb} usage_t;
12270856Sjhb
12370856Sjhbtypedef enum {
12470856Sjhb     S_PR,
12570856Sjhb     S_CO,	// Connect only
12670856Sjhb     S_SW	// Session Wide
12770856Sjhb} scope_t;
12870856Sjhb
12970856Sjhbtypedef void keyfun_t(isess_t *, oper_t);
13070856Sjhb
13170856Sjhbtypedef struct {
13270856Sjhb     usage_t	usage;
13370856Sjhb     scope_t	scope;
13470856Sjhb     char	*name;
13570856Sjhb     int	tokenID;
13670856Sjhb} textkey_t;
13770856Sjhb
13870856Sjhbtypedef int handler_t(isess_t *sess, pdu_t *pp);
13970856Sjhb
14070856Sjhbint	authenticateLogin(isess_t *sess);
14170856Sjhbint	fsm(isc_opt_t *op);
14270856Sjhbint	sendPDU(isess_t *sess, pdu_t *pp, handler_t *hdlr);
14370856Sjhbint	addText(pdu_t *pp, char *fmt, ...);
14470856Sjhbvoid	freePDU(pdu_t *pp);
14570856Sjhbint	xmitpdu(isess_t *sess, pdu_t *pp);
14670856Sjhbint	recvpdu(isess_t *sess, pdu_t *pp);
14770856Sjhb
14870856Sjhbint	lookup(token_t *tbl, char *m);
14970856Sjhb
15070856Sjhbint	vflag;
15170856Sjhbchar	*iscsidev;
15270856Sjhb
15370856Sjhbvoid	parseArgs(int nargs, char **args, isc_opt_t *op);
15470856Sjhbvoid	parseConfig(FILE *fd, char *key, isc_opt_t *op);
15570856Sjhb
15670856Sjhbchar	*chapDigest(char *ap, char id, char *cp, char *chapSecret);
15770856Sjhbchar	*genChapChallenge(char *encoding, uint len);
15870856Sjhb
15970856Sjhbint	str2bin(char *str, char **rsp);
16070856Sjhbchar	*bin2str(char *fmt, unsigned char *md, int blen);
16170856Sjhb
16270856Sjhbint	negotiateOPV(isess_t *sess);
16370856Sjhbint	setOptions(isess_t *sess, int flag);
16470856Sjhb
16570856Sjhbint	loginPhase(isess_t *sess);
16670856Sjhb