xref: /freebsd/usr.sbin/iscsid/iscsid.h (revision 45078155e3aea5ffb03d0b1d61f76a8f1dd89bf7)
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>
37*45078155SEdward Tomasz Napierala #include <openssl/md5.h>
38009ea47eSEdward Tomasz Napierala 
39009ea47eSEdward Tomasz Napierala #include <iscsi_ioctl.h>
40009ea47eSEdward Tomasz Napierala 
41009ea47eSEdward Tomasz Napierala #define	DEFAULT_PIDFILE			"/var/run/iscsid.pid"
42009ea47eSEdward Tomasz Napierala 
43009ea47eSEdward Tomasz Napierala #define	CONN_DIGEST_NONE		0
44009ea47eSEdward Tomasz Napierala #define	CONN_DIGEST_CRC32C		1
45009ea47eSEdward Tomasz Napierala 
46009ea47eSEdward Tomasz Napierala #define CONN_MUTUAL_CHALLENGE_LEN	1024
47009ea47eSEdward Tomasz Napierala 
48009ea47eSEdward Tomasz Napierala struct connection {
49009ea47eSEdward Tomasz Napierala 	int			conn_iscsi_fd;
50009ea47eSEdward Tomasz Napierala 	int			conn_socket;
51009ea47eSEdward Tomasz Napierala 	unsigned int		conn_session_id;
52009ea47eSEdward Tomasz Napierala 	struct iscsi_session_conf	conn_conf;
53009ea47eSEdward Tomasz Napierala 	char			conn_target_alias[ISCSI_ADDR_LEN];
54009ea47eSEdward Tomasz Napierala 	uint8_t			conn_isid[6];
55ffe82e05SAlexander Motin 	uint16_t		conn_tsih;
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;
64*45078155SEdward Tomasz Napierala 	struct chap		*conn_mutual_chap;
65009ea47eSEdward Tomasz Napierala };
66009ea47eSEdward Tomasz Napierala 
67009ea47eSEdward Tomasz Napierala struct pdu {
68009ea47eSEdward Tomasz Napierala 	struct connection	*pdu_connection;
69009ea47eSEdward Tomasz Napierala 	struct iscsi_bhs	*pdu_bhs;
70009ea47eSEdward Tomasz Napierala 	char			*pdu_data;
71009ea47eSEdward Tomasz Napierala 	size_t			pdu_data_len;
72009ea47eSEdward Tomasz Napierala };
73009ea47eSEdward Tomasz Napierala 
74009ea47eSEdward Tomasz Napierala #define	KEYS_MAX		1024
75009ea47eSEdward Tomasz Napierala 
76009ea47eSEdward Tomasz Napierala struct keys {
77009ea47eSEdward Tomasz Napierala 	char			*keys_names[KEYS_MAX];
78009ea47eSEdward Tomasz Napierala 	char			*keys_values[KEYS_MAX];
79009ea47eSEdward Tomasz Napierala 	char			*keys_data;
80009ea47eSEdward Tomasz Napierala 	size_t			keys_data_len;
81009ea47eSEdward Tomasz Napierala };
82009ea47eSEdward Tomasz Napierala 
83*45078155SEdward Tomasz Napierala #define	CHAP_CHALLENGE_LEN	1024
84*45078155SEdward Tomasz Napierala 
85*45078155SEdward Tomasz Napierala struct chap {
86*45078155SEdward Tomasz Napierala 	unsigned char	chap_id;
87*45078155SEdward Tomasz Napierala 	char		chap_challenge[CHAP_CHALLENGE_LEN];
88*45078155SEdward Tomasz Napierala 	char		chap_response[MD5_DIGEST_LENGTH];
89*45078155SEdward Tomasz Napierala };
90*45078155SEdward Tomasz Napierala 
91*45078155SEdward Tomasz Napierala struct rchap {
92*45078155SEdward Tomasz Napierala 	char		*rchap_secret;
93*45078155SEdward Tomasz Napierala 	unsigned char	rchap_id;
94*45078155SEdward Tomasz Napierala 	void		*rchap_challenge;
95*45078155SEdward Tomasz Napierala 	size_t		rchap_challenge_len;
96*45078155SEdward Tomasz Napierala };
97*45078155SEdward Tomasz Napierala 
98*45078155SEdward Tomasz Napierala struct chap		*chap_new(void);
99*45078155SEdward Tomasz Napierala char			*chap_get_id(const struct chap *chap);
100*45078155SEdward Tomasz Napierala char			*chap_get_challenge(const struct chap *chap);
101*45078155SEdward Tomasz Napierala int			chap_receive(struct chap *chap, const char *response);
102*45078155SEdward Tomasz Napierala int			chap_authenticate(struct chap *chap,
103*45078155SEdward Tomasz Napierala 			    const char *secret);
104*45078155SEdward Tomasz Napierala void			chap_delete(struct chap *chap);
105*45078155SEdward Tomasz Napierala 
106*45078155SEdward Tomasz Napierala struct rchap		*rchap_new(const char *secret);
107*45078155SEdward Tomasz Napierala int			rchap_receive(struct rchap *rchap,
108*45078155SEdward Tomasz Napierala 			    const char *id, const char *challenge);
109*45078155SEdward Tomasz Napierala char			*rchap_get_response(struct rchap *rchap);
110*45078155SEdward Tomasz Napierala void			rchap_delete(struct rchap *rchap);
111*45078155SEdward Tomasz Napierala 
112009ea47eSEdward Tomasz Napierala struct keys		*keys_new(void);
113009ea47eSEdward Tomasz Napierala void			keys_delete(struct keys *key);
114009ea47eSEdward Tomasz Napierala void			keys_load(struct keys *keys, const struct pdu *pdu);
115009ea47eSEdward Tomasz Napierala void			keys_save(struct keys *keys, struct pdu *pdu);
116009ea47eSEdward Tomasz Napierala const char		*keys_find(struct keys *keys, const char *name);
117009ea47eSEdward Tomasz Napierala int			keys_find_int(struct keys *keys, const char *name);
118009ea47eSEdward Tomasz Napierala void			keys_add(struct keys *keys,
119009ea47eSEdward Tomasz Napierala 			    const char *name, const char *value);
120009ea47eSEdward Tomasz Napierala void			keys_add_int(struct keys *keys,
121009ea47eSEdward Tomasz Napierala 			    const char *name, int value);
122009ea47eSEdward Tomasz Napierala 
123009ea47eSEdward Tomasz Napierala struct pdu		*pdu_new(struct connection *ic);
124009ea47eSEdward Tomasz Napierala struct pdu		*pdu_new_response(struct pdu *request);
125009ea47eSEdward Tomasz Napierala void			pdu_receive(struct pdu *request);
126009ea47eSEdward Tomasz Napierala void			pdu_send(struct pdu *response);
127009ea47eSEdward Tomasz Napierala void			pdu_delete(struct pdu *ip);
128009ea47eSEdward Tomasz Napierala 
129009ea47eSEdward Tomasz Napierala void			login(struct connection *ic);
130009ea47eSEdward Tomasz Napierala 
131009ea47eSEdward Tomasz Napierala void			discovery(struct connection *ic);
132009ea47eSEdward Tomasz Napierala 
133009ea47eSEdward Tomasz Napierala void			log_init(int level);
134009ea47eSEdward Tomasz Napierala void			log_set_peer_name(const char *name);
135009ea47eSEdward Tomasz Napierala void			log_set_peer_addr(const char *addr);
136009ea47eSEdward Tomasz Napierala void			log_err(int, const char *, ...)
1373fa953a0SEdward Tomasz Napierala 			    __dead2 __printflike(2, 3);
138009ea47eSEdward Tomasz Napierala void			log_errx(int, const char *, ...)
1393fa953a0SEdward Tomasz Napierala 			    __dead2 __printflike(2, 3);
1403fa953a0SEdward Tomasz Napierala void			log_warn(const char *, ...) __printflike(1, 2);
141009ea47eSEdward Tomasz Napierala void			log_warnx(const char *, ...) __printflike(1, 2);
1423fa953a0SEdward Tomasz Napierala void			log_debugx(const char *, ...) __printflike(1, 2);
143009ea47eSEdward Tomasz Napierala 
144009ea47eSEdward Tomasz Napierala char			*checked_strdup(const char *);
145009ea47eSEdward Tomasz Napierala bool			timed_out(void);
146009ea47eSEdward Tomasz Napierala void			fail(const struct connection *, const char *);
147009ea47eSEdward Tomasz Napierala 
148009ea47eSEdward Tomasz Napierala #endif /* !ISCSID_H */
149