iscontrol.h revision 225736
1/*- 2 * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: stable/9/sbin/iscontrol/iscontrol.h 211095 2010-08-09 12:36:36Z des $ 27 */ 28/* 29 | $Id: iscontrol.h,v 2.3 2007/04/27 08:36:49 danny Exp danny $ 30 */ 31#ifdef DEBUG 32int vflag; 33 34# define debug(level, fmt, args...) do {if (level <= vflag) printf("%s: " fmt "\n", __func__ , ##args);} while(0) 35# define debug_called(level) do {if (level <= vflag) printf("%s: called\n", __func__);} while(0) 36#else 37# define debug(level, fmt, args...) 38# define debug_called(level) 39#endif // DEBUG 40#define xdebug(fmt, args...) printf("%s: " fmt "\n", __func__ , ##args) 41 42#define BIT(n) (1 <<(n)) 43 44#define MAXREDIRECTS 2 45 46typedef int auth_t(void *sess); 47 48typedef struct { 49 char *address; 50 int port; 51 int pgt; 52} target_t; 53 54typedef struct isess { 55 int flags; 56#define SESS_CONNECTED BIT(0) 57#define SESS_DISCONNECT BIT(1) 58#define SESS_LOGGEDIN BIT(2) 59#define SESS_RECONNECT BIT(3) 60#define SESS_REDIRECT BIT(4) 61 62#define SESS_NEGODONE BIT(10) // XXX: kludge 63 64#define SESS_FULLFEATURE BIT(29) 65#define SESS_INITIALLOGIN1 BIT(30) 66#define SESS_INITIALLOGIN BIT(31) 67 68 69 isc_opt_t *op; // operational values 70 target_t target; // the Original target address 71 int fd; // the session fd 72 int soc; // the socket 73 iscsi_cam_t cam; 74 struct cam_device *camdev; 75 76 time_t open_time; 77 int redirect_cnt; 78 time_t redirect_time; 79 int reconnect_cnt; 80 int reconnect_cnt1; 81 time_t reconnect_time; 82 char isid[6+1]; 83 int csg; // current stage 84 int nsg; // next stage 85 // Phases/Stages 86#define SN_PHASE 0 // Security Negotiation 87#define LON_PHASE 1 // Login Operational Negotiation 88#define FF_PHASE 3 // FuLL-Feature 89 uint tsih; 90 sn_t sn; 91} isess_t; 92 93typedef struct token { 94 char *name; 95 int val; 96} token_t; 97 98typedef enum { 99 NONE = 0, 100 KRB5, 101 SPKM1, 102 SPKM2, 103 SRP, 104 CHAP 105} authm_t; 106 107extern token_t AuthMethods[]; 108extern token_t DigestMethods[]; 109 110typedef enum { 111 SET, 112 GET 113} oper_t; 114 115typedef enum { 116 U_PR, // private 117 U_IO, // Initialize Only -- during login 118 U_LO, // Leading Only -- when TSIH is zero 119 U_FFPO, // Full Feature Phase Only 120 U_ALL // in any phase 121} usage_t; 122 123typedef enum { 124 S_PR, 125 S_CO, // Connect only 126 S_SW // Session Wide 127} scope_t; 128 129typedef void keyfun_t(isess_t *, oper_t); 130 131typedef struct { 132 usage_t usage; 133 scope_t scope; 134 char *name; 135 int tokenID; 136} textkey_t; 137 138typedef int handler_t(isess_t *sess, pdu_t *pp); 139 140int authenticateLogin(isess_t *sess); 141int fsm(isc_opt_t *op); 142int sendPDU(isess_t *sess, pdu_t *pp, handler_t *hdlr); 143int addText(pdu_t *pp, char *fmt, ...); 144void freePDU(pdu_t *pp); 145int xmitpdu(isess_t *sess, pdu_t *pp); 146int recvpdu(isess_t *sess, pdu_t *pp); 147 148int lookup(token_t *tbl, char *m); 149 150int vflag; 151char *iscsidev; 152 153void parseArgs(int nargs, char **args, isc_opt_t *op); 154void parseConfig(FILE *fd, char *key, isc_opt_t *op); 155 156char *chapDigest(char *ap, char id, char *cp, char *chapSecret); 157char *genChapChallenge(char *encoding, uint len); 158 159int str2bin(char *str, char **rsp); 160char *bin2str(char *fmt, unsigned char *md, int blen); 161 162int negotiateOPV(isess_t *sess); 163int setOptions(isess_t *sess, int flag); 164 165int loginPhase(isess_t *sess); 166