Deleted Added
full compact
ctld.h (263723) ctld.h (263724)
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 *
29 * $FreeBSD: stable/10/usr.sbin/ctld/ctld.h 263723 2014-03-25 12:10:30Z trasz $
29 * $FreeBSD: stable/10/usr.sbin/ctld/ctld.h 263724 2014-03-25 12:12:37Z trasz $
30 */
31
32#ifndef CTLD_H
33#define CTLD_H
34
35#include <sys/queue.h>
36#include <stdbool.h>
37#include <libutil.h>
38
39#define DEFAULT_CONFIG_PATH "/etc/ctl.conf"
40#define DEFAULT_PIDFILE "/var/run/ctld.pid"
41#define DEFAULT_BLOCKSIZE 512
42
43#define MAX_NAME_LEN 223
44#define MAX_DATA_SEGMENT_LENGTH (128 * 1024)
45#define MAX_BURST_LENGTH 16776192
46
47struct auth {
48 TAILQ_ENTRY(auth) a_next;
49 struct auth_group *a_auth_group;
50 char *a_user;
51 char *a_secret;
52 char *a_mutual_user;
53 char *a_mutual_secret;
54};
55
56struct auth_name {
57 TAILQ_ENTRY(auth_name) an_next;
58 struct auth_group *an_auth_group;
59 char *an_initator_name;
60};
61
62struct auth_portal {
63 TAILQ_ENTRY(auth_portal) ap_next;
64 struct auth_group *ap_auth_group;
65 char *ap_initator_portal;
66};
67
68#define AG_TYPE_UNKNOWN 0
69#define AG_TYPE_NO_AUTHENTICATION 1
70#define AG_TYPE_CHAP 2
71#define AG_TYPE_CHAP_MUTUAL 3
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
151#define CONN_SESSION_TYPE_NONE 0
152#define CONN_SESSION_TYPE_DISCOVERY 1
153#define CONN_SESSION_TYPE_NORMAL 2
154
155#define CONN_DIGEST_NONE 0
156#define CONN_DIGEST_CRC32C 1
157
158struct connection {
159 struct portal *conn_portal;
160 struct target *conn_target;
161 int conn_socket;
162 int conn_session_type;
163 char *conn_initiator_name;
164 char *conn_initiator_addr;
165 char *conn_initiator_alias;
166 uint32_t conn_cmdsn;
167 uint32_t conn_statsn;
168 size_t conn_max_data_segment_length;
169 size_t conn_max_burst_length;
170 int conn_immediate_data;
171 int conn_header_digest;
172 int conn_data_digest;
173};
174
175struct pdu {
176 struct connection *pdu_connection;
177 struct iscsi_bhs *pdu_bhs;
178 char *pdu_data;
179 size_t pdu_data_len;
180};
181
182#define KEYS_MAX 1024
183
184struct keys {
185 char *keys_names[KEYS_MAX];
186 char *keys_values[KEYS_MAX];
187 char *keys_data;
188 size_t keys_data_len;
189};
190
191struct conf *conf_new(void);
192struct conf *conf_new_from_file(const char *path);
193struct conf *conf_new_from_kernel(void);
194void conf_delete(struct conf *conf);
195int conf_verify(struct conf *conf);
196
197struct auth_group *auth_group_new(struct conf *conf, const char *name);
198void auth_group_delete(struct auth_group *ag);
199struct auth_group *auth_group_find(struct conf *conf, const char *name);
30 */
31
32#ifndef CTLD_H
33#define CTLD_H
34
35#include <sys/queue.h>
36#include <stdbool.h>
37#include <libutil.h>
38
39#define DEFAULT_CONFIG_PATH "/etc/ctl.conf"
40#define DEFAULT_PIDFILE "/var/run/ctld.pid"
41#define DEFAULT_BLOCKSIZE 512
42
43#define MAX_NAME_LEN 223
44#define MAX_DATA_SEGMENT_LENGTH (128 * 1024)
45#define MAX_BURST_LENGTH 16776192
46
47struct auth {
48 TAILQ_ENTRY(auth) a_next;
49 struct auth_group *a_auth_group;
50 char *a_user;
51 char *a_secret;
52 char *a_mutual_user;
53 char *a_mutual_secret;
54};
55
56struct auth_name {
57 TAILQ_ENTRY(auth_name) an_next;
58 struct auth_group *an_auth_group;
59 char *an_initator_name;
60};
61
62struct auth_portal {
63 TAILQ_ENTRY(auth_portal) ap_next;
64 struct auth_group *ap_auth_group;
65 char *ap_initator_portal;
66};
67
68#define AG_TYPE_UNKNOWN 0
69#define AG_TYPE_NO_AUTHENTICATION 1
70#define AG_TYPE_CHAP 2
71#define AG_TYPE_CHAP_MUTUAL 3
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
151#define CONN_SESSION_TYPE_NONE 0
152#define CONN_SESSION_TYPE_DISCOVERY 1
153#define CONN_SESSION_TYPE_NORMAL 2
154
155#define CONN_DIGEST_NONE 0
156#define CONN_DIGEST_CRC32C 1
157
158struct connection {
159 struct portal *conn_portal;
160 struct target *conn_target;
161 int conn_socket;
162 int conn_session_type;
163 char *conn_initiator_name;
164 char *conn_initiator_addr;
165 char *conn_initiator_alias;
166 uint32_t conn_cmdsn;
167 uint32_t conn_statsn;
168 size_t conn_max_data_segment_length;
169 size_t conn_max_burst_length;
170 int conn_immediate_data;
171 int conn_header_digest;
172 int conn_data_digest;
173};
174
175struct pdu {
176 struct connection *pdu_connection;
177 struct iscsi_bhs *pdu_bhs;
178 char *pdu_data;
179 size_t pdu_data_len;
180};
181
182#define KEYS_MAX 1024
183
184struct keys {
185 char *keys_names[KEYS_MAX];
186 char *keys_values[KEYS_MAX];
187 char *keys_data;
188 size_t keys_data_len;
189};
190
191struct conf *conf_new(void);
192struct conf *conf_new_from_file(const char *path);
193struct conf *conf_new_from_kernel(void);
194void conf_delete(struct conf *conf);
195int conf_verify(struct conf *conf);
196
197struct auth_group *auth_group_new(struct conf *conf, const char *name);
198void auth_group_delete(struct auth_group *ag);
199struct auth_group *auth_group_find(struct conf *conf, const char *name);
200int auth_group_set_type_str(struct auth_group *ag,
201 const char *type);
200
201const struct auth *auth_new_chap(struct auth_group *ag,
202 const char *user, const char *secret);
203const struct auth *auth_new_chap_mutual(struct auth_group *ag,
204 const char *user, const char *secret,
205 const char *user2, const char *secret2);
206const struct auth *auth_find(struct auth_group *ag,
207 const char *user);
208
209const struct auth_name *auth_name_new(struct auth_group *ag,
210 const char *initiator_name);
211bool auth_name_defined(const struct auth_group *ag);
212const struct auth_name *auth_name_find(const struct auth_group *ag,
213 const char *initiator_name);
214
215const struct auth_portal *auth_portal_new(struct auth_group *ag,
216 const char *initiator_portal);
217bool auth_portal_defined(const struct auth_group *ag);
218const struct auth_portal *auth_portal_find(const struct auth_group *ag,
219 const char *initiator_portal);
220
221struct portal_group *portal_group_new(struct conf *conf, const char *name);
222void portal_group_delete(struct portal_group *pg);
223struct portal_group *portal_group_find(struct conf *conf, const char *name);
224int portal_group_add_listen(struct portal_group *pg,
225 const char *listen, bool iser);
226
227struct target *target_new(struct conf *conf, const char *name);
228void target_delete(struct target *target);
229struct target *target_find(struct conf *conf,
230 const char *name);
231
232struct lun *lun_new(struct target *target, int lun_id);
233void lun_delete(struct lun *lun);
234struct lun *lun_find(struct target *target, int lun_id);
235void lun_set_backend(struct lun *lun, const char *value);
236void lun_set_blocksize(struct lun *lun, size_t value);
237void lun_set_device_id(struct lun *lun, const char *value);
238void lun_set_path(struct lun *lun, const char *value);
239void lun_set_serial(struct lun *lun, const char *value);
240void lun_set_size(struct lun *lun, size_t value);
241void lun_set_ctl_lun(struct lun *lun, uint32_t value);
242
243struct lun_option *lun_option_new(struct lun *lun,
244 const char *name, const char *value);
245void lun_option_delete(struct lun_option *clo);
246struct lun_option *lun_option_find(struct lun *lun, const char *name);
247void lun_option_set(struct lun_option *clo,
248 const char *value);
249
250void kernel_init(void);
251int kernel_lun_add(struct lun *lun);
252int kernel_lun_resize(struct lun *lun);
253int kernel_lun_remove(struct lun *lun);
254void kernel_handoff(struct connection *conn);
255int kernel_port_on(void);
256int kernel_port_off(void);
257void kernel_capsicate(void);
258
259/*
260 * ICL_KERNEL_PROXY
261 */
262void kernel_listen(struct addrinfo *ai, bool iser);
263int kernel_accept(void);
264void kernel_send(struct pdu *pdu);
265void kernel_receive(struct pdu *pdu);
266
267struct keys *keys_new(void);
268void keys_delete(struct keys *keys);
269void keys_load(struct keys *keys, const struct pdu *pdu);
270void keys_save(struct keys *keys, struct pdu *pdu);
271const char *keys_find(struct keys *keys, const char *name);
272int keys_find_int(struct keys *keys, const char *name);
273void keys_add(struct keys *keys,
274 const char *name, const char *value);
275void keys_add_int(struct keys *keys,
276 const char *name, int value);
277
278struct pdu *pdu_new(struct connection *conn);
279struct pdu *pdu_new_response(struct pdu *request);
280void pdu_delete(struct pdu *pdu);
281void pdu_receive(struct pdu *request);
282void pdu_send(struct pdu *response);
283
284void login(struct connection *conn);
285
286void discovery(struct connection *conn);
287
288void log_init(int level);
289void log_set_peer_name(const char *name);
290void log_set_peer_addr(const char *addr);
291void log_err(int, const char *, ...)
292 __dead2 __printf0like(2, 3);
293void log_errx(int, const char *, ...)
294 __dead2 __printf0like(2, 3);
295void log_warn(const char *, ...) __printf0like(1, 2);
296void log_warnx(const char *, ...) __printflike(1, 2);
297void log_debugx(const char *, ...) __printf0like(1, 2);
298
299char *checked_strdup(const char *);
300bool valid_iscsi_name(const char *name);
301bool timed_out(void);
302
303#endif /* !CTLD_H */
202
203const struct auth *auth_new_chap(struct auth_group *ag,
204 const char *user, const char *secret);
205const struct auth *auth_new_chap_mutual(struct auth_group *ag,
206 const char *user, const char *secret,
207 const char *user2, const char *secret2);
208const struct auth *auth_find(struct auth_group *ag,
209 const char *user);
210
211const struct auth_name *auth_name_new(struct auth_group *ag,
212 const char *initiator_name);
213bool auth_name_defined(const struct auth_group *ag);
214const struct auth_name *auth_name_find(const struct auth_group *ag,
215 const char *initiator_name);
216
217const struct auth_portal *auth_portal_new(struct auth_group *ag,
218 const char *initiator_portal);
219bool auth_portal_defined(const struct auth_group *ag);
220const struct auth_portal *auth_portal_find(const struct auth_group *ag,
221 const char *initiator_portal);
222
223struct portal_group *portal_group_new(struct conf *conf, const char *name);
224void portal_group_delete(struct portal_group *pg);
225struct portal_group *portal_group_find(struct conf *conf, const char *name);
226int portal_group_add_listen(struct portal_group *pg,
227 const char *listen, bool iser);
228
229struct target *target_new(struct conf *conf, const char *name);
230void target_delete(struct target *target);
231struct target *target_find(struct conf *conf,
232 const char *name);
233
234struct lun *lun_new(struct target *target, int lun_id);
235void lun_delete(struct lun *lun);
236struct lun *lun_find(struct target *target, int lun_id);
237void lun_set_backend(struct lun *lun, const char *value);
238void lun_set_blocksize(struct lun *lun, size_t value);
239void lun_set_device_id(struct lun *lun, const char *value);
240void lun_set_path(struct lun *lun, const char *value);
241void lun_set_serial(struct lun *lun, const char *value);
242void lun_set_size(struct lun *lun, size_t value);
243void lun_set_ctl_lun(struct lun *lun, uint32_t value);
244
245struct lun_option *lun_option_new(struct lun *lun,
246 const char *name, const char *value);
247void lun_option_delete(struct lun_option *clo);
248struct lun_option *lun_option_find(struct lun *lun, const char *name);
249void lun_option_set(struct lun_option *clo,
250 const char *value);
251
252void kernel_init(void);
253int kernel_lun_add(struct lun *lun);
254int kernel_lun_resize(struct lun *lun);
255int kernel_lun_remove(struct lun *lun);
256void kernel_handoff(struct connection *conn);
257int kernel_port_on(void);
258int kernel_port_off(void);
259void kernel_capsicate(void);
260
261/*
262 * ICL_KERNEL_PROXY
263 */
264void kernel_listen(struct addrinfo *ai, bool iser);
265int kernel_accept(void);
266void kernel_send(struct pdu *pdu);
267void kernel_receive(struct pdu *pdu);
268
269struct keys *keys_new(void);
270void keys_delete(struct keys *keys);
271void keys_load(struct keys *keys, const struct pdu *pdu);
272void keys_save(struct keys *keys, struct pdu *pdu);
273const char *keys_find(struct keys *keys, const char *name);
274int keys_find_int(struct keys *keys, const char *name);
275void keys_add(struct keys *keys,
276 const char *name, const char *value);
277void keys_add_int(struct keys *keys,
278 const char *name, int value);
279
280struct pdu *pdu_new(struct connection *conn);
281struct pdu *pdu_new_response(struct pdu *request);
282void pdu_delete(struct pdu *pdu);
283void pdu_receive(struct pdu *request);
284void pdu_send(struct pdu *response);
285
286void login(struct connection *conn);
287
288void discovery(struct connection *conn);
289
290void log_init(int level);
291void log_set_peer_name(const char *name);
292void log_set_peer_addr(const char *addr);
293void log_err(int, const char *, ...)
294 __dead2 __printf0like(2, 3);
295void log_errx(int, const char *, ...)
296 __dead2 __printf0like(2, 3);
297void log_warn(const char *, ...) __printf0like(1, 2);
298void log_warnx(const char *, ...) __printflike(1, 2);
299void log_debugx(const char *, ...) __printf0like(1, 2);
300
301char *checked_strdup(const char *);
302bool valid_iscsi_name(const char *name);
303bool timed_out(void);
304
305#endif /* !CTLD_H */