1e25c779eSMatthew Dillon /*- 2e25c779eSMatthew Dillon * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il> 3e25c779eSMatthew Dillon * All rights reserved. 4e25c779eSMatthew Dillon * 5e25c779eSMatthew Dillon * Redistribution and use in source and binary forms, with or without 6e25c779eSMatthew Dillon * modification, are permitted provided that the following conditions 7e25c779eSMatthew Dillon * are met: 8e25c779eSMatthew Dillon * 1. Redistributions of source code must retain the above copyright 9e25c779eSMatthew Dillon * notice, this list of conditions and the following disclaimer. 10e25c779eSMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 11e25c779eSMatthew Dillon * notice, this list of conditions and the following disclaimer in the 12e25c779eSMatthew Dillon * documentation and/or other materials provided with the distribution. 13e25c779eSMatthew Dillon * 14e25c779eSMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15e25c779eSMatthew Dillon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16e25c779eSMatthew Dillon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17e25c779eSMatthew Dillon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18e25c779eSMatthew Dillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19e25c779eSMatthew Dillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20e25c779eSMatthew Dillon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21e25c779eSMatthew Dillon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22e25c779eSMatthew Dillon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23e25c779eSMatthew Dillon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24e25c779eSMatthew Dillon * SUCH DAMAGE. 25e25c779eSMatthew Dillon * 26e25c779eSMatthew Dillon * $FreeBSD$ 27e25c779eSMatthew Dillon */ 28e25c779eSMatthew Dillon /* 29e25c779eSMatthew Dillon | $Id: iscontrol.h,v 2.3 2007/04/27 08:36:49 danny Exp danny $ 30e25c779eSMatthew Dillon */ 311cdc323aSAntonio Huete #define INITIATORMOD "iscsi_initiator" 321cdc323aSAntonio Huete 33e25c779eSMatthew Dillon #ifdef DEBUG 34e25c779eSMatthew Dillon # define debug(level, fmt, args...) do {if (level <= vflag) printf("%s: " fmt "\n", __func__ , ##args);} while(0) 35e25c779eSMatthew Dillon # define debug_called(level) do {if (level <= vflag) printf("%s: called\n", __func__);} while(0) 36e25c779eSMatthew Dillon #else 37e25c779eSMatthew Dillon # define debug(level, fmt, args...) 38e25c779eSMatthew Dillon # define debug_called(level) 39e25c779eSMatthew Dillon #endif // DEBUG 40e25c779eSMatthew Dillon #define xdebug(fmt, args...) printf("%s: " fmt "\n", __func__ , ##args) 41e25c779eSMatthew Dillon 42e25c779eSMatthew Dillon #define BIT(n) (1 <<(n)) 43e25c779eSMatthew Dillon 44e25c779eSMatthew Dillon #define MAXREDIRECTS 2 45e25c779eSMatthew Dillon 46e25c779eSMatthew Dillon typedef int auth_t(void *sess); 47e25c779eSMatthew Dillon 48e25c779eSMatthew Dillon typedef struct { 49e25c779eSMatthew Dillon char *address; 50e25c779eSMatthew Dillon int port; 51e25c779eSMatthew Dillon int pgt; 52e25c779eSMatthew Dillon } target_t; 53e25c779eSMatthew Dillon 54e25c779eSMatthew Dillon typedef struct isess { 55e25c779eSMatthew Dillon int flags; 56e25c779eSMatthew Dillon #define SESS_CONNECTED BIT(0) 57e25c779eSMatthew Dillon #define SESS_DISCONNECT BIT(1) 58e25c779eSMatthew Dillon #define SESS_LOGGEDIN BIT(2) 59e25c779eSMatthew Dillon #define SESS_RECONNECT BIT(3) 60e25c779eSMatthew Dillon #define SESS_REDIRECT BIT(4) 61e25c779eSMatthew Dillon 62e25c779eSMatthew Dillon #define SESS_NEGODONE BIT(10) // XXX: kludge 63e25c779eSMatthew Dillon 64e25c779eSMatthew Dillon #define SESS_FULLFEATURE BIT(29) 65e25c779eSMatthew Dillon #define SESS_INITIALLOGIN1 BIT(30) 66e25c779eSMatthew Dillon #define SESS_INITIALLOGIN BIT(31) 67e25c779eSMatthew Dillon 68e25c779eSMatthew Dillon 69e25c779eSMatthew Dillon isc_opt_t *op; // operational values 70e25c779eSMatthew Dillon target_t target; // the Original target address 71e25c779eSMatthew Dillon int fd; // the session fd 72e25c779eSMatthew Dillon int soc; // the socket 73e25c779eSMatthew Dillon iscsi_cam_t cam; 74e25c779eSMatthew Dillon struct cam_device *camdev; 75e25c779eSMatthew Dillon 76e25c779eSMatthew Dillon time_t open_time; 77e25c779eSMatthew Dillon int redirect_cnt; 78e25c779eSMatthew Dillon time_t redirect_time; 79e25c779eSMatthew Dillon int reconnect_cnt; 80e25c779eSMatthew Dillon int reconnect_cnt1; 81e25c779eSMatthew Dillon time_t reconnect_time; 82e25c779eSMatthew Dillon char isid[6+1]; 83e25c779eSMatthew Dillon int csg; // current stage 84e25c779eSMatthew Dillon int nsg; // next stage 85e25c779eSMatthew Dillon // Phases/Stages 86e25c779eSMatthew Dillon #define SN_PHASE 0 // Security Negotiation 87e25c779eSMatthew Dillon #define LON_PHASE 1 // Login Operational Negotiation 88e25c779eSMatthew Dillon #define FF_PHASE 3 // FuLL-Feature 89e25c779eSMatthew Dillon uint tsih; 90e25c779eSMatthew Dillon sn_t sn; 91e25c779eSMatthew Dillon } isess_t; 92e25c779eSMatthew Dillon 93e25c779eSMatthew Dillon typedef struct token { 94e25c779eSMatthew Dillon char *name; 95e25c779eSMatthew Dillon int val; 96e25c779eSMatthew Dillon } token_t; 97e25c779eSMatthew Dillon 98e25c779eSMatthew Dillon typedef enum { 99e25c779eSMatthew Dillon NONE = 0, 100e25c779eSMatthew Dillon KRB5, 101e25c779eSMatthew Dillon SPKM1, 102e25c779eSMatthew Dillon SPKM2, 103e25c779eSMatthew Dillon SRP, 104e25c779eSMatthew Dillon CHAP 105e25c779eSMatthew Dillon } authm_t; 106e25c779eSMatthew Dillon 107e25c779eSMatthew Dillon extern token_t AuthMethods[]; 108e25c779eSMatthew Dillon extern token_t DigestMethods[]; 109e25c779eSMatthew Dillon 110e25c779eSMatthew Dillon typedef enum { 111e25c779eSMatthew Dillon SET, 112e25c779eSMatthew Dillon GET 113e25c779eSMatthew Dillon } oper_t; 114e25c779eSMatthew Dillon 115e25c779eSMatthew Dillon typedef enum { 116e25c779eSMatthew Dillon U_PR, // private 117e25c779eSMatthew Dillon U_IO, // Initialize Only -- during login 118e25c779eSMatthew Dillon U_LO, // Leading Only -- when TSIH is zero 119e25c779eSMatthew Dillon U_FFPO, // Full Feature Phase Only 120e25c779eSMatthew Dillon U_ALL // in any phase 121e25c779eSMatthew Dillon } usage_t; 122e25c779eSMatthew Dillon 123e25c779eSMatthew Dillon typedef enum { 124e25c779eSMatthew Dillon S_PR, 125e25c779eSMatthew Dillon S_CO, // Connect only 126e25c779eSMatthew Dillon S_SW // Session Wide 127e25c779eSMatthew Dillon } scope_t; 128e25c779eSMatthew Dillon 129e25c779eSMatthew Dillon typedef void keyfun_t(isess_t *, oper_t); 130e25c779eSMatthew Dillon 131e25c779eSMatthew Dillon typedef struct { 132e25c779eSMatthew Dillon usage_t usage; 133e25c779eSMatthew Dillon scope_t scope; 134e25c779eSMatthew Dillon char *name; 135e25c779eSMatthew Dillon int tokenID; 136e25c779eSMatthew Dillon } textkey_t; 137e25c779eSMatthew Dillon 138e25c779eSMatthew Dillon typedef int handler_t(isess_t *sess, pdu_t *pp); 139e25c779eSMatthew Dillon 140e25c779eSMatthew Dillon int authenticateLogin(isess_t *sess); 141e25c779eSMatthew Dillon int fsm(isc_opt_t *op); 142e25c779eSMatthew Dillon int sendPDU(isess_t *sess, pdu_t *pp, handler_t *hdlr); 143b58f1e66SSascha Wildner int addText(pdu_t *pp, char *fmt, ...) __printflike(2, 3); 144e25c779eSMatthew Dillon void freePDU(pdu_t *pp); 145e25c779eSMatthew Dillon int xmitpdu(isess_t *sess, pdu_t *pp); 146e25c779eSMatthew Dillon int recvpdu(isess_t *sess, pdu_t *pp); 147e25c779eSMatthew Dillon void pukeText(char *it, pdu_t *pp); 148e25c779eSMatthew Dillon 149e25c779eSMatthew Dillon int lookup(token_t *tbl, char *m); 150e25c779eSMatthew Dillon 151*760270c4SSascha Wildner extern int vflag; 152*760270c4SSascha Wildner extern char *iscsidev; 153e25c779eSMatthew Dillon 154e25c779eSMatthew Dillon void parseArgs(int nargs, char **args, isc_opt_t *op); 155e25c779eSMatthew Dillon void parseConfig(FILE *fd, char *key, isc_opt_t *op); 156e25c779eSMatthew Dillon 157e25c779eSMatthew Dillon char *chapDigest(char *ap, char id, char *cp, char *chapSecret); 158e25c779eSMatthew Dillon char *genChapChallenge(char *encoding, size_t len); 159e25c779eSMatthew Dillon 160e25c779eSMatthew Dillon int str2bin(char *str, char **rsp); 161e25c779eSMatthew Dillon char *bin2str(char *fmt, unsigned char *md, int blen); 162e25c779eSMatthew Dillon 163e25c779eSMatthew Dillon int negotiateOPV(isess_t *sess); 164e25c779eSMatthew Dillon int setOptions(isess_t *sess, int flag); 165e25c779eSMatthew Dillon 166e25c779eSMatthew Dillon int loginPhase(isess_t *sess); 167