1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 *
| 1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 *
|
72 73struct auth_group { 74 TAILQ_ENTRY(auth_group) ag_next; 75 struct conf *ag_conf; 76 char *ag_name; 77 struct target *ag_target; 78 int ag_type; 79 TAILQ_HEAD(, auth) ag_auths; 80 TAILQ_HEAD(, auth_name) ag_names; 81 TAILQ_HEAD(, auth_portal) ag_portals; 82}; 83 84struct portal { 85 TAILQ_ENTRY(portal) p_next; 86 struct portal_group *p_portal_group; 87 bool p_iser; 88 char *p_listen; 89 struct addrinfo *p_ai; 90 91 TAILQ_HEAD(, target) p_targets; 92 int p_socket; 93}; 94 95struct portal_group { 96 TAILQ_ENTRY(portal_group) pg_next; 97 struct conf *pg_conf; 98 char *pg_name; 99 struct auth_group *pg_discovery_auth_group; 100 bool pg_unassigned; 101 TAILQ_HEAD(, portal) pg_portals; 102 103 uint16_t pg_tag; 104}; 105 106struct lun_option { 107 TAILQ_ENTRY(lun_option) lo_next; 108 struct lun *lo_lun; 109 char *lo_name; 110 char *lo_value; 111}; 112 113struct lun { 114 TAILQ_ENTRY(lun) l_next; 115 TAILQ_HEAD(, lun_option) l_options; 116 struct target *l_target; 117 int l_lun; 118 char *l_backend; 119 int l_blocksize; 120 char *l_device_id; 121 char *l_path; 122 char *l_serial; 123 int64_t l_size; 124 125 int l_ctl_lun; 126}; 127 128struct target { 129 TAILQ_ENTRY(target) t_next; 130 TAILQ_HEAD(, lun) t_luns; 131 struct conf *t_conf; 132 struct auth_group *t_auth_group; 133 struct portal_group *t_portal_group; 134 char *t_name; 135 char *t_alias; 136}; 137 138struct conf { 139 char *conf_pidfile_path; 140 TAILQ_HEAD(, target) conf_targets; 141 TAILQ_HEAD(, auth_group) conf_auth_groups; 142 TAILQ_HEAD(, portal_group) conf_portal_groups; 143 int conf_debug; 144 int conf_timeout; 145 int conf_maxproc; 146 147 uint16_t conf_last_portal_group_tag; 148 struct pidfh *conf_pidfh; 149 150 bool conf_default_pg_defined; 151 bool conf_default_ag_defined; 152}; 153 154#define CONN_SESSION_TYPE_NONE 0 155#define CONN_SESSION_TYPE_DISCOVERY 1 156#define CONN_SESSION_TYPE_NORMAL 2 157 158#define CONN_DIGEST_NONE 0 159#define CONN_DIGEST_CRC32C 1 160 161struct connection { 162 struct portal *conn_portal; 163 struct target *conn_target; 164 int conn_socket; 165 int conn_session_type; 166 char *conn_initiator_name; 167 char *conn_initiator_addr; 168 char *conn_initiator_alias; 169 uint32_t conn_cmdsn; 170 uint32_t conn_statsn; 171 size_t conn_max_data_segment_length; 172 size_t conn_max_burst_length; 173 int conn_immediate_data; 174 int conn_header_digest; 175 int conn_data_digest; 176}; 177 178struct pdu { 179 struct connection *pdu_connection; 180 struct iscsi_bhs *pdu_bhs; 181 char *pdu_data; 182 size_t pdu_data_len; 183}; 184 185#define KEYS_MAX 1024 186 187struct keys { 188 char *keys_names[KEYS_MAX]; 189 char *keys_values[KEYS_MAX]; 190 char *keys_data; 191 size_t keys_data_len; 192}; 193 194struct conf *conf_new(void); 195struct conf *conf_new_from_file(const char *path); 196struct conf *conf_new_from_kernel(void); 197void conf_delete(struct conf *conf); 198int conf_verify(struct conf *conf); 199 200struct auth_group *auth_group_new(struct conf *conf, const char *name); 201void auth_group_delete(struct auth_group *ag); 202struct auth_group *auth_group_find(struct conf *conf, const char *name); 203int auth_group_set_type_str(struct auth_group *ag, 204 const char *type); 205 206const struct auth *auth_new_chap(struct auth_group *ag, 207 const char *user, const char *secret); 208const struct auth *auth_new_chap_mutual(struct auth_group *ag, 209 const char *user, const char *secret, 210 const char *user2, const char *secret2); 211const struct auth *auth_find(struct auth_group *ag, 212 const char *user); 213 214const struct auth_name *auth_name_new(struct auth_group *ag, 215 const char *initiator_name); 216bool auth_name_defined(const struct auth_group *ag); 217const struct auth_name *auth_name_find(const struct auth_group *ag, 218 const char *initiator_name); 219 220const struct auth_portal *auth_portal_new(struct auth_group *ag, 221 const char *initiator_portal); 222bool auth_portal_defined(const struct auth_group *ag); 223const struct auth_portal *auth_portal_find(const struct auth_group *ag, 224 const char *initiator_portal); 225 226struct portal_group *portal_group_new(struct conf *conf, const char *name); 227void portal_group_delete(struct portal_group *pg); 228struct portal_group *portal_group_find(struct conf *conf, const char *name); 229int portal_group_add_listen(struct portal_group *pg, 230 const char *listen, bool iser); 231 232struct target *target_new(struct conf *conf, const char *name); 233void target_delete(struct target *target); 234struct target *target_find(struct conf *conf, 235 const char *name); 236 237struct lun *lun_new(struct target *target, int lun_id); 238void lun_delete(struct lun *lun); 239struct lun *lun_find(struct target *target, int lun_id); 240void lun_set_backend(struct lun *lun, const char *value); 241void lun_set_blocksize(struct lun *lun, size_t value); 242void lun_set_device_id(struct lun *lun, const char *value); 243void lun_set_path(struct lun *lun, const char *value); 244void lun_set_serial(struct lun *lun, const char *value); 245void lun_set_size(struct lun *lun, size_t value); 246void lun_set_ctl_lun(struct lun *lun, uint32_t value); 247 248struct lun_option *lun_option_new(struct lun *lun, 249 const char *name, const char *value); 250void lun_option_delete(struct lun_option *clo); 251struct lun_option *lun_option_find(struct lun *lun, const char *name); 252void lun_option_set(struct lun_option *clo, 253 const char *value); 254 255void kernel_init(void); 256int kernel_lun_add(struct lun *lun); 257int kernel_lun_resize(struct lun *lun); 258int kernel_lun_remove(struct lun *lun); 259void kernel_handoff(struct connection *conn); 260int kernel_port_on(void); 261int kernel_port_off(void); 262void kernel_capsicate(void); 263 264/* 265 * ICL_KERNEL_PROXY 266 */ 267void kernel_listen(struct addrinfo *ai, bool iser); 268int kernel_accept(void); 269void kernel_send(struct pdu *pdu); 270void kernel_receive(struct pdu *pdu); 271 272struct keys *keys_new(void); 273void keys_delete(struct keys *keys); 274void keys_load(struct keys *keys, const struct pdu *pdu); 275void keys_save(struct keys *keys, struct pdu *pdu); 276const char *keys_find(struct keys *keys, const char *name); 277int keys_find_int(struct keys *keys, const char *name); 278void keys_add(struct keys *keys, 279 const char *name, const char *value); 280void keys_add_int(struct keys *keys, 281 const char *name, int value); 282 283struct pdu *pdu_new(struct connection *conn); 284struct pdu *pdu_new_response(struct pdu *request); 285void pdu_delete(struct pdu *pdu); 286void pdu_receive(struct pdu *request); 287void pdu_send(struct pdu *response); 288 289void login(struct connection *conn); 290 291void discovery(struct connection *conn); 292 293void log_init(int level); 294void log_set_peer_name(const char *name); 295void log_set_peer_addr(const char *addr); 296void log_err(int, const char *, ...) 297 __dead2 __printf0like(2, 3); 298void log_errx(int, const char *, ...) 299 __dead2 __printf0like(2, 3); 300void log_warn(const char *, ...) __printf0like(1, 2); 301void log_warnx(const char *, ...) __printflike(1, 2); 302void log_debugx(const char *, ...) __printf0like(1, 2); 303 304char *checked_strdup(const char *); 305bool valid_iscsi_name(const char *name); 306bool timed_out(void); 307 308#endif /* !CTLD_H */
| 73 74struct auth_group { 75 TAILQ_ENTRY(auth_group) ag_next; 76 struct conf *ag_conf; 77 char *ag_name; 78 struct target *ag_target; 79 int ag_type; 80 TAILQ_HEAD(, auth) ag_auths; 81 TAILQ_HEAD(, auth_name) ag_names; 82 TAILQ_HEAD(, auth_portal) ag_portals; 83}; 84 85struct portal { 86 TAILQ_ENTRY(portal) p_next; 87 struct portal_group *p_portal_group; 88 bool p_iser; 89 char *p_listen; 90 struct addrinfo *p_ai; 91 92 TAILQ_HEAD(, target) p_targets; 93 int p_socket; 94}; 95 96struct portal_group { 97 TAILQ_ENTRY(portal_group) pg_next; 98 struct conf *pg_conf; 99 char *pg_name; 100 struct auth_group *pg_discovery_auth_group; 101 bool pg_unassigned; 102 TAILQ_HEAD(, portal) pg_portals; 103 104 uint16_t pg_tag; 105}; 106 107struct lun_option { 108 TAILQ_ENTRY(lun_option) lo_next; 109 struct lun *lo_lun; 110 char *lo_name; 111 char *lo_value; 112}; 113 114struct lun { 115 TAILQ_ENTRY(lun) l_next; 116 TAILQ_HEAD(, lun_option) l_options; 117 struct target *l_target; 118 int l_lun; 119 char *l_backend; 120 int l_blocksize; 121 char *l_device_id; 122 char *l_path; 123 char *l_serial; 124 int64_t l_size; 125 126 int l_ctl_lun; 127}; 128 129struct target { 130 TAILQ_ENTRY(target) t_next; 131 TAILQ_HEAD(, lun) t_luns; 132 struct conf *t_conf; 133 struct auth_group *t_auth_group; 134 struct portal_group *t_portal_group; 135 char *t_name; 136 char *t_alias; 137}; 138 139struct conf { 140 char *conf_pidfile_path; 141 TAILQ_HEAD(, target) conf_targets; 142 TAILQ_HEAD(, auth_group) conf_auth_groups; 143 TAILQ_HEAD(, portal_group) conf_portal_groups; 144 int conf_debug; 145 int conf_timeout; 146 int conf_maxproc; 147 148 uint16_t conf_last_portal_group_tag; 149 struct pidfh *conf_pidfh; 150 151 bool conf_default_pg_defined; 152 bool conf_default_ag_defined; 153}; 154 155#define CONN_SESSION_TYPE_NONE 0 156#define CONN_SESSION_TYPE_DISCOVERY 1 157#define CONN_SESSION_TYPE_NORMAL 2 158 159#define CONN_DIGEST_NONE 0 160#define CONN_DIGEST_CRC32C 1 161 162struct connection { 163 struct portal *conn_portal; 164 struct target *conn_target; 165 int conn_socket; 166 int conn_session_type; 167 char *conn_initiator_name; 168 char *conn_initiator_addr; 169 char *conn_initiator_alias; 170 uint32_t conn_cmdsn; 171 uint32_t conn_statsn; 172 size_t conn_max_data_segment_length; 173 size_t conn_max_burst_length; 174 int conn_immediate_data; 175 int conn_header_digest; 176 int conn_data_digest; 177}; 178 179struct pdu { 180 struct connection *pdu_connection; 181 struct iscsi_bhs *pdu_bhs; 182 char *pdu_data; 183 size_t pdu_data_len; 184}; 185 186#define KEYS_MAX 1024 187 188struct keys { 189 char *keys_names[KEYS_MAX]; 190 char *keys_values[KEYS_MAX]; 191 char *keys_data; 192 size_t keys_data_len; 193}; 194 195struct conf *conf_new(void); 196struct conf *conf_new_from_file(const char *path); 197struct conf *conf_new_from_kernel(void); 198void conf_delete(struct conf *conf); 199int conf_verify(struct conf *conf); 200 201struct auth_group *auth_group_new(struct conf *conf, const char *name); 202void auth_group_delete(struct auth_group *ag); 203struct auth_group *auth_group_find(struct conf *conf, const char *name); 204int auth_group_set_type_str(struct auth_group *ag, 205 const char *type); 206 207const struct auth *auth_new_chap(struct auth_group *ag, 208 const char *user, const char *secret); 209const struct auth *auth_new_chap_mutual(struct auth_group *ag, 210 const char *user, const char *secret, 211 const char *user2, const char *secret2); 212const struct auth *auth_find(struct auth_group *ag, 213 const char *user); 214 215const struct auth_name *auth_name_new(struct auth_group *ag, 216 const char *initiator_name); 217bool auth_name_defined(const struct auth_group *ag); 218const struct auth_name *auth_name_find(const struct auth_group *ag, 219 const char *initiator_name); 220 221const struct auth_portal *auth_portal_new(struct auth_group *ag, 222 const char *initiator_portal); 223bool auth_portal_defined(const struct auth_group *ag); 224const struct auth_portal *auth_portal_find(const struct auth_group *ag, 225 const char *initiator_portal); 226 227struct portal_group *portal_group_new(struct conf *conf, const char *name); 228void portal_group_delete(struct portal_group *pg); 229struct portal_group *portal_group_find(struct conf *conf, const char *name); 230int portal_group_add_listen(struct portal_group *pg, 231 const char *listen, bool iser); 232 233struct target *target_new(struct conf *conf, const char *name); 234void target_delete(struct target *target); 235struct target *target_find(struct conf *conf, 236 const char *name); 237 238struct lun *lun_new(struct target *target, int lun_id); 239void lun_delete(struct lun *lun); 240struct lun *lun_find(struct target *target, int lun_id); 241void lun_set_backend(struct lun *lun, const char *value); 242void lun_set_blocksize(struct lun *lun, size_t value); 243void lun_set_device_id(struct lun *lun, const char *value); 244void lun_set_path(struct lun *lun, const char *value); 245void lun_set_serial(struct lun *lun, const char *value); 246void lun_set_size(struct lun *lun, size_t value); 247void lun_set_ctl_lun(struct lun *lun, uint32_t value); 248 249struct lun_option *lun_option_new(struct lun *lun, 250 const char *name, const char *value); 251void lun_option_delete(struct lun_option *clo); 252struct lun_option *lun_option_find(struct lun *lun, const char *name); 253void lun_option_set(struct lun_option *clo, 254 const char *value); 255 256void kernel_init(void); 257int kernel_lun_add(struct lun *lun); 258int kernel_lun_resize(struct lun *lun); 259int kernel_lun_remove(struct lun *lun); 260void kernel_handoff(struct connection *conn); 261int kernel_port_on(void); 262int kernel_port_off(void); 263void kernel_capsicate(void); 264 265/* 266 * ICL_KERNEL_PROXY 267 */ 268void kernel_listen(struct addrinfo *ai, bool iser); 269int kernel_accept(void); 270void kernel_send(struct pdu *pdu); 271void kernel_receive(struct pdu *pdu); 272 273struct keys *keys_new(void); 274void keys_delete(struct keys *keys); 275void keys_load(struct keys *keys, const struct pdu *pdu); 276void keys_save(struct keys *keys, struct pdu *pdu); 277const char *keys_find(struct keys *keys, const char *name); 278int keys_find_int(struct keys *keys, const char *name); 279void keys_add(struct keys *keys, 280 const char *name, const char *value); 281void keys_add_int(struct keys *keys, 282 const char *name, int value); 283 284struct pdu *pdu_new(struct connection *conn); 285struct pdu *pdu_new_response(struct pdu *request); 286void pdu_delete(struct pdu *pdu); 287void pdu_receive(struct pdu *request); 288void pdu_send(struct pdu *response); 289 290void login(struct connection *conn); 291 292void discovery(struct connection *conn); 293 294void log_init(int level); 295void log_set_peer_name(const char *name); 296void log_set_peer_addr(const char *addr); 297void log_err(int, const char *, ...) 298 __dead2 __printf0like(2, 3); 299void log_errx(int, const char *, ...) 300 __dead2 __printf0like(2, 3); 301void log_warn(const char *, ...) __printf0like(1, 2); 302void log_warnx(const char *, ...) __printflike(1, 2); 303void log_debugx(const char *, ...) __printf0like(1, 2); 304 305char *checked_strdup(const char *); 306bool valid_iscsi_name(const char *name); 307bool timed_out(void); 308 309#endif /* !CTLD_H */
|