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