]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sbin/iscontrol/iscontrol.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sbin / iscontrol / iscontrol.h
1 /*-
2  * Copyright (c) 2005 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$
27  */
28 /*
29  | $Id: iscontrol.h,v 2.3 2007/04/27 08:36:49 danny Exp danny $
30  */
31 #ifdef DEBUG
32 int 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
46 typedef int auth_t(void *sess);
47
48 typedef struct isess {
49      int        flags;
50 #define SESS_CONNECTED          BIT(0)
51 #define SESS_DISCONNECT         BIT(1)
52 #define SESS_LOGGEDIN           BIT(2)
53 #define SESS_RECONNECT          BIT(3)
54 #define SESS_REDIRECT           BIT(4)
55
56 #define SESS_NEGODONE           BIT(10) // XXX: kludge
57
58 #define SESS_FULLFEATURE        BIT(29)
59 #define SESS_INITIALLOGIN1      BIT(30)
60 #define SESS_INITIALLOGIN       BIT(31)
61
62
63      isc_opt_t  *op;            // operational values
64      int        fd;             // the session fd
65      int        soc;            // the socket
66      iscsi_cam_t        cam;
67      struct cam_device  *camdev;
68
69      time_t     open_time;
70      int        redirect_cnt;
71      time_t     redirect_time;
72      int        reconnect_cnt;
73      int        reconnect_cnt1;
74      time_t     reconnect_time;
75      char       isid[6+1];
76      int        csg;            // current stage
77      int        nsg;            // next stage
78      // Phases/Stages   
79 #define SN_PHASE        0       // Security Negotiation
80 #define LON_PHASE       1       // Login Operational Negotiation
81 #define FF_PHASE        3       // FuLL-Feature
82      uint       tsih;
83      sn_t       sn;
84 } isess_t;
85
86 typedef struct token {
87      char       *name;
88      int        val;
89 } token_t;
90
91 typedef enum {
92      NONE       = 0,
93      KRB5,
94      SPKM1,
95      SPKM2,
96      SRP,
97      CHAP
98 } authm_t;
99
100 extern token_t AuthMethods[];
101 extern token_t DigestMethods[];
102
103 typedef enum {
104      SET,
105      GET
106 } oper_t;
107
108 typedef enum {
109      U_PR,      // private
110      U_IO,      // Initialize Only -- during login
111      U_LO,      // Leading Only -- when TSIH is zero
112      U_FFPO,    // Full Feature Phase Only
113      U_ALL      // in any phase
114 } usage_t;
115
116 typedef enum {
117      S_PR,
118      S_CO,      // Connect only
119      S_SW       // Session Wide
120 } scope_t;
121
122 typedef void keyfun_t(isess_t *, oper_t);
123
124 typedef struct {
125      usage_t    usage;
126      scope_t    scope;
127      char       *name;
128      int        tokenID;
129 } textkey_t;
130
131 typedef int handler_t(isess_t *sess, pdu_t *pp);
132
133 int     authenticateLogin(isess_t *sess);
134 int     fsm(isc_opt_t *op);
135 int     sendPDU(isess_t *sess, pdu_t *pp, handler_t *hdlr);
136 int     addText(pdu_t *pp, char *fmt, ...);
137 void    freePDU(pdu_t *pp);
138 int     xmitpdu(isess_t *sess, pdu_t *pp);
139 int     recvpdu(isess_t *sess, pdu_t *pp);
140 void    pukeText(char *it, pdu_t *pp);
141
142 int     lookup(token_t *tbl, char *m);
143
144 int     vflag;
145 char    *iscsidev;
146
147 void    parseArgs(int nargs, char **args, isc_opt_t *op);
148 void    parseConfig(FILE *fd, char *key, isc_opt_t *op);
149
150 char    *chapDigest(char *ap, char id, char *cp, char *chapSecret);
151 char    *genChapChallenge(char *encoding, int len);
152
153 int     str2bin(char *str, char **rsp);
154 char    *bin2str(char *fmt, unsigned char *md, int blen);
155
156 int     negotiateOPV(isess_t *sess);
157 int     setOptions(isess_t *sess, int flag);
158
159 int     loginPhase(isess_t *sess);