ctld.h revision 263732
1139743Simp/*- 239212Sgibbs * Copyright (c) 2012 The FreeBSD Foundation 339212Sgibbs * All rights reserved. 439212Sgibbs * 539212Sgibbs * This software was developed by Edward Tomasz Napierala under sponsorship 639212Sgibbs * from the FreeBSD Foundation. 739212Sgibbs * 839212Sgibbs * Redistribution and use in source and binary forms, with or without 939212Sgibbs * modification, are permitted provided that the following conditions 1039212Sgibbs * are met: 1139212Sgibbs * 1. Redistributions of source code must retain the above copyright 1239212Sgibbs * notice, this list of conditions and the following disclaimer. 1339212Sgibbs * 2. Redistributions in binary form must reproduce the above copyright 1439212Sgibbs * notice, this list of conditions and the following disclaimer in the 1539212Sgibbs * documentation and/or other materials provided with the distribution. 1639212Sgibbs * 1739212Sgibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1839212Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1939212Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2039212Sgibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2139212Sgibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2239212Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2339212Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2439212Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2539212Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2639212Sgibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2739212Sgibbs * SUCH DAMAGE. 2850477Speter * 2939212Sgibbs * $FreeBSD: stable/10/usr.sbin/ctld/ctld.h 263732 2014-03-25 12:31:08Z trasz $ 3039212Sgibbs */ 3139212Sgibbs 3239212Sgibbs#ifndef CTLD_H 3339212Sgibbs#define CTLD_H 3455206Speter 3539212Sgibbs#include <sys/queue.h> 3655206Speter#include <stdbool.h> 3739212Sgibbs#include <libutil.h> 3839212Sgibbs 3939212Sgibbs#define DEFAULT_CONFIG_PATH "/etc/ctl.conf" 4039212Sgibbs#define DEFAULT_PIDFILE "/var/run/ctld.pid" 4139212Sgibbs#define DEFAULT_BLOCKSIZE 512 4239212Sgibbs 43255870Sscottl#define MAX_NAME_LEN 223 44255870Sscottl#define MAX_DATA_SEGMENT_LENGTH (128 * 1024) 45255870Sscottl#define MAX_BURST_LENGTH 16776192 46255870Sscottl 4739212Sgibbsstruct auth { 4839212Sgibbs TAILQ_ENTRY(auth) a_next; 4939212Sgibbs struct auth_group *a_auth_group; 5039212Sgibbs char *a_user; 5139212Sgibbs char *a_secret; 5239212Sgibbs char *a_mutual_user; 53259204Snwhitehorn char *a_mutual_secret; 54259204Snwhitehorn}; 55259204Snwhitehorn 56259204Snwhitehornstruct auth_name { 57259204Snwhitehorn TAILQ_ENTRY(auth_name) an_next; 58259204Snwhitehorn struct auth_group *an_auth_group; 5939212Sgibbs char *an_initator_name; 6039212Sgibbs}; 6139212Sgibbs 6239212Sgibbsstruct auth_portal { 6339212Sgibbs TAILQ_ENTRY(auth_portal) ap_next; 6439212Sgibbs struct auth_group *ap_auth_group; 6539212Sgibbs char *ap_initator_portal; 6639212Sgibbs}; 6739212Sgibbs 6858111Sn_hibma#define AG_TYPE_UNKNOWN 0 6939212Sgibbs#define AG_TYPE_DENY 1 7039212Sgibbs#define AG_TYPE_NO_AUTHENTICATION 2 7139212Sgibbs#define AG_TYPE_CHAP 3 7239212Sgibbs#define AG_TYPE_CHAP_MUTUAL 4 73203108Smav 7439212Sgibbsstruct auth_group { 75203108Smav TAILQ_ENTRY(auth_group) ag_next; 76203108Smav struct conf *ag_conf; 77203108Smav char *ag_name; 78203108Smav struct target *ag_target; 79203108Smav int ag_type; 80203108Smav TAILQ_HEAD(, auth) ag_auths; 81203108Smav TAILQ_HEAD(, auth_name) ag_names; 82203108Smav TAILQ_HEAD(, auth_portal) ag_portals; 83203108Smav}; 84311402Smav 85203108Smavstruct portal { 86203108Smav TAILQ_ENTRY(portal) p_next; 8739212Sgibbs struct portal_group *p_portal_group; 8839212Sgibbs bool p_iser; 89203108Smav char *p_listen; 90203108Smav struct addrinfo *p_ai; 91203108Smav 92203108Smav TAILQ_HEAD(, target) p_targets; 93249466Smav int p_socket; 94203108Smav}; 9539212Sgibbs 9639212Sgibbsstruct portal_group { 9739212Sgibbs TAILQ_ENTRY(portal_group) pg_next; 9839212Sgibbs struct conf *pg_conf; 9939212Sgibbs char *pg_name; 10039212Sgibbs struct auth_group *pg_discovery_auth_group; 101253958Smav bool pg_unassigned; 10239212Sgibbs TAILQ_HEAD(, portal) pg_portals; 10339212Sgibbs 10445441Sgibbs uint16_t pg_tag; 10545441Sgibbs}; 10645441Sgibbs 10745441Sgibbsstruct lun_option { 10845441Sgibbs TAILQ_ENTRY(lun_option) lo_next; 10945441Sgibbs struct lun *lo_lun; 11045441Sgibbs char *lo_name; 11145441Sgibbs char *lo_value; 11245441Sgibbs}; 11345441Sgibbs 11445441Sgibbsstruct lun { 11574840Sken TAILQ_ENTRY(lun) l_next; 11639212Sgibbs TAILQ_HEAD(, lun_option) l_options; 11739212Sgibbs struct target *l_target; 11874840Sken int l_lun; 11974840Sken char *l_backend; 12039212Sgibbs int l_blocksize; 12139212Sgibbs char *l_device_id; 122236814Smav char *l_path; 123236814Smav char *l_serial; 124236814Smav int64_t l_size; 125311402Smav 126236814Smav int l_ctl_lun; 127236814Smav}; 128278440Smav 129278440Smavstruct target { 130236814Smav TAILQ_ENTRY(target) t_next; 131236814Smav TAILQ_HEAD(, lun) t_luns; 13239212Sgibbs struct conf *t_conf; 13339212Sgibbs struct auth_group *t_auth_group; 134255870Sscottl struct portal_group *t_portal_group; 135255870Sscottl char *t_name; 13639212Sgibbs char *t_alias; 137255870Sscottl}; 138255870Sscottl 13939212Sgibbsstruct conf { 140255870Sscottl char *conf_pidfile_path; 141255870Sscottl TAILQ_HEAD(, target) conf_targets; 14239212Sgibbs TAILQ_HEAD(, auth_group) conf_auth_groups; 143255870Sscottl TAILQ_HEAD(, portal_group) conf_portal_groups; 144255870Sscottl int conf_debug; 14556143Smjacob int conf_timeout; 146255870Sscottl int conf_maxproc; 147255870Sscottl 148255870Sscottl uint16_t conf_last_portal_group_tag; 149255870Sscottl struct pidfh *conf_pidfh; 150255870Sscottl 151255870Sscottl bool conf_default_pg_defined; 152255870Sscottl bool conf_default_ag_defined; 153255870Sscottl}; 154255870Sscottl 155255870Sscottl#define CONN_SESSION_TYPE_NONE 0 156255870Sscottl#define CONN_SESSION_TYPE_DISCOVERY 1 157255870Sscottl#define CONN_SESSION_TYPE_NORMAL 2 158255870Sscottl 159255870Sscottl#define CONN_DIGEST_NONE 0 160255870Sscottl#define CONN_DIGEST_CRC32C 1 161255870Sscottl 162255870Sscottlstruct connection { 163255870Sscottl struct portal *conn_portal; 164255870Sscottl struct target *conn_target; 165255870Sscottl int conn_socket; 166255870Sscottl int conn_session_type; 167255870Sscottl char *conn_initiator_name; 168255870Sscottl char *conn_initiator_addr; 169255870Sscottl char *conn_initiator_alias; 170255870Sscottl uint32_t conn_cmdsn; 171255870Sscottl uint32_t conn_statsn; 172255870Sscottl size_t conn_max_data_segment_length; 173255870Sscottl size_t conn_max_burst_length; 174255870Sscottl int conn_immediate_data; 175255870Sscottl int conn_header_digest; 176255870Sscottl int conn_data_digest; 177255870Sscottl}; 178255870Sscottl 179255870Sscottlstruct pdu { 180255870Sscottl struct connection *pdu_connection; 181255870Sscottl struct iscsi_bhs *pdu_bhs; 182255870Sscottl char *pdu_data; 183255870Sscottl size_t pdu_data_len; 184255870Sscottl}; 185255870Sscottl 186255870Sscottl#define KEYS_MAX 1024 187255870Sscottl 188255870Sscottlstruct keys { 189255870Sscottl char *keys_names[KEYS_MAX]; 190255870Sscottl char *keys_values[KEYS_MAX]; 191255870Sscottl char *keys_data; 192255870Sscottl size_t keys_data_len; 193255870Sscottl}; 194255870Sscottl 195255870Sscottlstruct conf *conf_new(void); 196255870Sscottlstruct conf *conf_new_from_file(const char *path); 197255870Sscottlstruct conf *conf_new_from_kernel(void); 198255870Sscottlvoid conf_delete(struct conf *conf); 199255870Sscottlint conf_verify(struct conf *conf); 200255870Sscottl 201255870Sscottlstruct auth_group *auth_group_new(struct conf *conf, const char *name); 202255870Sscottlvoid auth_group_delete(struct auth_group *ag); 203255870Sscottlstruct auth_group *auth_group_find(struct conf *conf, const char *name); 204255870Sscottlint auth_group_set_type_str(struct auth_group *ag, 205255870Sscottl const char *type); 206255870Sscottl 207255870Sscottlconst struct auth *auth_new_chap(struct auth_group *ag, 208255870Sscottl const char *user, const char *secret); 209255870Sscottlconst struct auth *auth_new_chap_mutual(struct auth_group *ag, 210255870Sscottl const char *user, const char *secret, 211255870Sscottl const char *user2, const char *secret2); 212255870Sscottlconst struct auth *auth_find(struct auth_group *ag, 213255870Sscottl const char *user); 214255870Sscottl 215255870Sscottlconst struct auth_name *auth_name_new(struct auth_group *ag, 216255870Sscottl const char *initiator_name); 217255870Sscottlbool auth_name_defined(const struct auth_group *ag); 218255870Sscottlconst struct auth_name *auth_name_find(const struct auth_group *ag, 219255870Sscottl const char *initiator_name); 220255870Sscottl 221255870Sscottlconst struct auth_portal *auth_portal_new(struct auth_group *ag, 222255870Sscottl const char *initiator_portal); 223255870Sscottlbool auth_portal_defined(const struct auth_group *ag); 224255870Sscottlconst struct auth_portal *auth_portal_find(const struct auth_group *ag, 225255870Sscottl const char *initiator_portal); 226255870Sscottl 227255870Sscottlstruct portal_group *portal_group_new(struct conf *conf, const char *name); 228255870Sscottlvoid portal_group_delete(struct portal_group *pg); 229255870Sscottlstruct portal_group *portal_group_find(struct conf *conf, const char *name); 230255870Sscottlint portal_group_add_listen(struct portal_group *pg, 231255870Sscottl const char *listen, bool iser); 232255870Sscottl 233255870Sscottlstruct target *target_new(struct conf *conf, const char *name); 234255870Sscottlvoid target_delete(struct target *target); 235255870Sscottlstruct target *target_find(struct conf *conf, 236255870Sscottl const char *name); 237255870Sscottl 238255870Sscottlstruct lun *lun_new(struct target *target, int lun_id); 239255870Sscottlvoid lun_delete(struct lun *lun); 240255870Sscottlstruct lun *lun_find(struct target *target, int lun_id); 241255870Sscottlvoid lun_set_backend(struct lun *lun, const char *value); 242255870Sscottlvoid lun_set_blocksize(struct lun *lun, size_t value); 243255870Sscottlvoid lun_set_device_id(struct lun *lun, const char *value); 244255870Sscottlvoid lun_set_path(struct lun *lun, const char *value); 245255870Sscottlvoid lun_set_serial(struct lun *lun, const char *value); 246255870Sscottlvoid lun_set_size(struct lun *lun, size_t value); 247255870Sscottlvoid lun_set_ctl_lun(struct lun *lun, uint32_t value); 248255870Sscottl 249255870Sscottlstruct lun_option *lun_option_new(struct lun *lun, 250255870Sscottl const char *name, const char *value); 251255870Sscottlvoid lun_option_delete(struct lun_option *clo); 252255870Sscottlstruct lun_option *lun_option_find(struct lun *lun, const char *name); 253255870Sscottlvoid lun_option_set(struct lun_option *clo, 254255870Sscottl const char *value); 255255870Sscottl 256255870Sscottlvoid kernel_init(void); 257255870Sscottlint kernel_lun_add(struct lun *lun); 258255870Sscottlint kernel_lun_resize(struct lun *lun); 259255870Sscottlint kernel_lun_remove(struct lun *lun); 260255870Sscottlvoid kernel_handoff(struct connection *conn); 261255870Sscottlint kernel_port_on(void); 262255870Sscottlint kernel_port_off(void); 263255870Sscottlvoid kernel_capsicate(void); 264255870Sscottl 265255870Sscottl/* 266255870Sscottl * ICL_KERNEL_PROXY 267255870Sscottl */ 268255870Sscottlvoid kernel_listen(struct addrinfo *ai, bool iser); 269255870Sscottlint kernel_accept(void); 270255870Sscottlvoid kernel_send(struct pdu *pdu); 271255870Sscottlvoid kernel_receive(struct pdu *pdu); 272255870Sscottl 273255870Sscottlstruct keys *keys_new(void); 274255870Sscottlvoid keys_delete(struct keys *keys); 275255870Sscottlvoid keys_load(struct keys *keys, const struct pdu *pdu); 276255870Sscottlvoid keys_save(struct keys *keys, struct pdu *pdu); 277255870Sscottlconst char *keys_find(struct keys *keys, const char *name); 278255870Sscottlint keys_find_int(struct keys *keys, const char *name); 279255870Sscottlvoid keys_add(struct keys *keys, 280255870Sscottl const char *name, const char *value); 281255870Sscottlvoid keys_add_int(struct keys *keys, 282255870Sscottl const char *name, int value); 283255870Sscottl 284255870Sscottlstruct pdu *pdu_new(struct connection *conn); 285255870Sscottlstruct pdu *pdu_new_response(struct pdu *request); 286255870Sscottlvoid pdu_delete(struct pdu *pdu); 287255870Sscottlvoid pdu_receive(struct pdu *request); 288255870Sscottlvoid pdu_send(struct pdu *response); 289255870Sscottl 290255870Sscottlvoid login(struct connection *conn); 291255870Sscottl 292255870Sscottlvoid discovery(struct connection *conn); 293255870Sscottl 294255870Sscottlvoid log_init(int level); 295255870Sscottlvoid log_set_peer_name(const char *name); 296255870Sscottlvoid log_set_peer_addr(const char *addr); 297255870Sscottlvoid log_err(int, const char *, ...) 298255870Sscottl __dead2 __printflike(2, 3); 299255870Sscottlvoid log_errx(int, const char *, ...) 300255870Sscottl __dead2 __printflike(2, 3); 301255870Sscottlvoid log_warn(const char *, ...) __printflike(1, 2); 302255870Sscottlvoid log_warnx(const char *, ...) __printflike(1, 2); 303255870Sscottlvoid log_debugx(const char *, ...) __printflike(1, 2); 304255870Sscottl 305255870Sscottlchar *checked_strdup(const char *); 306255870Sscottlbool valid_iscsi_name(const char *name); 307255870Sscottlbool timed_out(void); 308255870Sscottl 309255870Sscottl#endif /* !CTLD_H */ 310255870Sscottl