xref: /freebsd/usr.sbin/iscsid/iscsid.h (revision 3fa953a0712e5857be74648360cfb2a584522071)
1009ea47eSEdward Tomasz Napierala /*-
2009ea47eSEdward Tomasz Napierala  * Copyright (c) 2012 The FreeBSD Foundation
3009ea47eSEdward Tomasz Napierala  * All rights reserved.
4009ea47eSEdward Tomasz Napierala  *
5009ea47eSEdward Tomasz Napierala  * This software was developed by Edward Tomasz Napierala under sponsorship
6009ea47eSEdward Tomasz Napierala  * from the FreeBSD Foundation.
7009ea47eSEdward Tomasz Napierala  *
8009ea47eSEdward Tomasz Napierala  * Redistribution and use in source and binary forms, with or without
9009ea47eSEdward Tomasz Napierala  * modification, are permitted provided that the following conditions
10009ea47eSEdward Tomasz Napierala  * are met:
11009ea47eSEdward Tomasz Napierala  * 1. Redistributions of source code must retain the above copyright
12009ea47eSEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer.
13009ea47eSEdward Tomasz Napierala  * 2. Redistributions in binary form must reproduce the above copyright
14009ea47eSEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer in the
15009ea47eSEdward Tomasz Napierala  *    documentation and/or other materials provided with the distribution.
16009ea47eSEdward Tomasz Napierala  *
17009ea47eSEdward Tomasz Napierala  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18009ea47eSEdward Tomasz Napierala  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19009ea47eSEdward Tomasz Napierala  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20009ea47eSEdward Tomasz Napierala  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21009ea47eSEdward Tomasz Napierala  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22009ea47eSEdward Tomasz Napierala  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23009ea47eSEdward Tomasz Napierala  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24009ea47eSEdward Tomasz Napierala  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25009ea47eSEdward Tomasz Napierala  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26009ea47eSEdward Tomasz Napierala  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27009ea47eSEdward Tomasz Napierala  * SUCH DAMAGE.
28009ea47eSEdward Tomasz Napierala  *
29009ea47eSEdward Tomasz Napierala  * $FreeBSD$
30009ea47eSEdward Tomasz Napierala  */
31009ea47eSEdward Tomasz Napierala 
32009ea47eSEdward Tomasz Napierala #ifndef ISCSID_H
33009ea47eSEdward Tomasz Napierala #define	ISCSID_H
34009ea47eSEdward Tomasz Napierala 
35009ea47eSEdward Tomasz Napierala #include <stdbool.h>
36009ea47eSEdward Tomasz Napierala #include <stdint.h>
37009ea47eSEdward Tomasz Napierala 
38009ea47eSEdward Tomasz Napierala #include <iscsi_ioctl.h>
39009ea47eSEdward Tomasz Napierala 
40009ea47eSEdward Tomasz Napierala #define	DEFAULT_PIDFILE			"/var/run/iscsid.pid"
41009ea47eSEdward Tomasz Napierala 
42009ea47eSEdward Tomasz Napierala #define	CONN_DIGEST_NONE		0
43009ea47eSEdward Tomasz Napierala #define	CONN_DIGEST_CRC32C		1
44009ea47eSEdward Tomasz Napierala 
45009ea47eSEdward Tomasz Napierala #define CONN_MUTUAL_CHALLENGE_LEN	1024
46009ea47eSEdward Tomasz Napierala 
47009ea47eSEdward Tomasz Napierala struct connection {
48009ea47eSEdward Tomasz Napierala 	int			conn_iscsi_fd;
49009ea47eSEdward Tomasz Napierala #ifndef ICL_KERNEL_PROXY
50009ea47eSEdward Tomasz Napierala 	int			conn_socket;
51009ea47eSEdward Tomasz Napierala #endif
52009ea47eSEdward Tomasz Napierala 	unsigned int		conn_session_id;
53009ea47eSEdward Tomasz Napierala 	struct iscsi_session_conf	conn_conf;
54009ea47eSEdward Tomasz Napierala 	char			conn_target_alias[ISCSI_ADDR_LEN];
55009ea47eSEdward Tomasz Napierala 	uint8_t			conn_isid[6];
56009ea47eSEdward Tomasz Napierala 	uint32_t		conn_statsn;
57009ea47eSEdward Tomasz Napierala 	int			conn_header_digest;
58009ea47eSEdward Tomasz Napierala 	int			conn_data_digest;
59009ea47eSEdward Tomasz Napierala 	bool			conn_initial_r2t;
60009ea47eSEdward Tomasz Napierala 	bool			conn_immediate_data;
61009ea47eSEdward Tomasz Napierala 	size_t			conn_max_data_segment_length;
62009ea47eSEdward Tomasz Napierala 	size_t			conn_max_burst_length;
63009ea47eSEdward Tomasz Napierala 	size_t			conn_first_burst_length;
64009ea47eSEdward Tomasz Napierala 	char			conn_mutual_challenge[CONN_MUTUAL_CHALLENGE_LEN];
65009ea47eSEdward Tomasz Napierala 	unsigned char		conn_mutual_id;
66009ea47eSEdward Tomasz Napierala };
67009ea47eSEdward Tomasz Napierala 
68009ea47eSEdward Tomasz Napierala struct pdu {
69009ea47eSEdward Tomasz Napierala 	struct connection	*pdu_connection;
70009ea47eSEdward Tomasz Napierala 	struct iscsi_bhs	*pdu_bhs;
71009ea47eSEdward Tomasz Napierala 	char			*pdu_data;
72009ea47eSEdward Tomasz Napierala 	size_t			pdu_data_len;
73009ea47eSEdward Tomasz Napierala };
74009ea47eSEdward Tomasz Napierala 
75009ea47eSEdward Tomasz Napierala #define	KEYS_MAX		1024
76009ea47eSEdward Tomasz Napierala 
77009ea47eSEdward Tomasz Napierala struct keys {
78009ea47eSEdward Tomasz Napierala 	char			*keys_names[KEYS_MAX];
79009ea47eSEdward Tomasz Napierala 	char			*keys_values[KEYS_MAX];
80009ea47eSEdward Tomasz Napierala 	char			*keys_data;
81009ea47eSEdward Tomasz Napierala 	size_t			keys_data_len;
82009ea47eSEdward Tomasz Napierala };
83009ea47eSEdward Tomasz Napierala 
84009ea47eSEdward Tomasz Napierala struct keys		*keys_new(void);
85009ea47eSEdward Tomasz Napierala void			keys_delete(struct keys *key);
86009ea47eSEdward Tomasz Napierala void			keys_load(struct keys *keys, const struct pdu *pdu);
87009ea47eSEdward Tomasz Napierala void			keys_save(struct keys *keys, struct pdu *pdu);
88009ea47eSEdward Tomasz Napierala const char		*keys_find(struct keys *keys, const char *name);
89009ea47eSEdward Tomasz Napierala int			keys_find_int(struct keys *keys, const char *name);
90009ea47eSEdward Tomasz Napierala void			keys_add(struct keys *keys,
91009ea47eSEdward Tomasz Napierala 			    const char *name, const char *value);
92009ea47eSEdward Tomasz Napierala void			keys_add_int(struct keys *keys,
93009ea47eSEdward Tomasz Napierala 			    const char *name, int value);
94009ea47eSEdward Tomasz Napierala 
95009ea47eSEdward Tomasz Napierala struct pdu		*pdu_new(struct connection *ic);
96009ea47eSEdward Tomasz Napierala struct pdu		*pdu_new_response(struct pdu *request);
97009ea47eSEdward Tomasz Napierala void			pdu_receive(struct pdu *request);
98009ea47eSEdward Tomasz Napierala void			pdu_send(struct pdu *response);
99009ea47eSEdward Tomasz Napierala void			pdu_delete(struct pdu *ip);
100009ea47eSEdward Tomasz Napierala 
101009ea47eSEdward Tomasz Napierala void			login(struct connection *ic);
102009ea47eSEdward Tomasz Napierala 
103009ea47eSEdward Tomasz Napierala void			discovery(struct connection *ic);
104009ea47eSEdward Tomasz Napierala 
105009ea47eSEdward Tomasz Napierala void			log_init(int level);
106009ea47eSEdward Tomasz Napierala void			log_set_peer_name(const char *name);
107009ea47eSEdward Tomasz Napierala void			log_set_peer_addr(const char *addr);
108009ea47eSEdward Tomasz Napierala void			log_err(int, const char *, ...)
109*3fa953a0SEdward Tomasz Napierala 			    __dead2 __printflike(2, 3);
110009ea47eSEdward Tomasz Napierala void			log_errx(int, const char *, ...)
111*3fa953a0SEdward Tomasz Napierala 			    __dead2 __printflike(2, 3);
112*3fa953a0SEdward Tomasz Napierala void			log_warn(const char *, ...) __printflike(1, 2);
113009ea47eSEdward Tomasz Napierala void			log_warnx(const char *, ...) __printflike(1, 2);
114*3fa953a0SEdward Tomasz Napierala void			log_debugx(const char *, ...) __printflike(1, 2);
115009ea47eSEdward Tomasz Napierala 
116009ea47eSEdward Tomasz Napierala char			*checked_strdup(const char *);
117009ea47eSEdward Tomasz Napierala bool			timed_out(void);
118009ea47eSEdward Tomasz Napierala void			fail(const struct connection *, const char *);
119009ea47eSEdward Tomasz Napierala 
120009ea47eSEdward Tomasz Napierala #endif /* !ISCSID_H */
121