xref: /freebsd/usr.sbin/iscsid/iscsid.h (revision 0572ccaa4543b0abef8ef81e384c1d04de9f3da1)
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$
30  */
31 
32 #ifndef ISCSID_H
33 #define	ISCSID_H
34 
35 #include <stdbool.h>
36 #include <stdint.h>
37 
38 #include <iscsi_ioctl.h>
39 
40 #define	DEFAULT_PIDFILE			"/var/run/iscsid.pid"
41 
42 #define	CONN_DIGEST_NONE		0
43 #define	CONN_DIGEST_CRC32C		1
44 
45 #define CONN_MUTUAL_CHALLENGE_LEN	1024
46 
47 struct connection {
48 	int			conn_iscsi_fd;
49 	int			conn_socket;
50 	unsigned int		conn_session_id;
51 	struct iscsi_session_conf	conn_conf;
52 	char			conn_target_alias[ISCSI_ADDR_LEN];
53 	uint8_t			conn_isid[6];
54 	uint32_t		conn_statsn;
55 	int			conn_header_digest;
56 	int			conn_data_digest;
57 	bool			conn_initial_r2t;
58 	bool			conn_immediate_data;
59 	size_t			conn_max_data_segment_length;
60 	size_t			conn_max_burst_length;
61 	size_t			conn_first_burst_length;
62 	char			conn_mutual_challenge[CONN_MUTUAL_CHALLENGE_LEN];
63 	unsigned char		conn_mutual_id;
64 };
65 
66 struct pdu {
67 	struct connection	*pdu_connection;
68 	struct iscsi_bhs	*pdu_bhs;
69 	char			*pdu_data;
70 	size_t			pdu_data_len;
71 };
72 
73 #define	KEYS_MAX		1024
74 
75 struct keys {
76 	char			*keys_names[KEYS_MAX];
77 	char			*keys_values[KEYS_MAX];
78 	char			*keys_data;
79 	size_t			keys_data_len;
80 };
81 
82 struct keys		*keys_new(void);
83 void			keys_delete(struct keys *key);
84 void			keys_load(struct keys *keys, const struct pdu *pdu);
85 void			keys_save(struct keys *keys, struct pdu *pdu);
86 const char		*keys_find(struct keys *keys, const char *name);
87 int			keys_find_int(struct keys *keys, const char *name);
88 void			keys_add(struct keys *keys,
89 			    const char *name, const char *value);
90 void			keys_add_int(struct keys *keys,
91 			    const char *name, int value);
92 
93 struct pdu		*pdu_new(struct connection *ic);
94 struct pdu		*pdu_new_response(struct pdu *request);
95 void			pdu_receive(struct pdu *request);
96 void			pdu_send(struct pdu *response);
97 void			pdu_delete(struct pdu *ip);
98 
99 void			login(struct connection *ic);
100 
101 void			discovery(struct connection *ic);
102 
103 void			log_init(int level);
104 void			log_set_peer_name(const char *name);
105 void			log_set_peer_addr(const char *addr);
106 void			log_err(int, const char *, ...)
107 			    __dead2 __printflike(2, 3);
108 void			log_errx(int, const char *, ...)
109 			    __dead2 __printflike(2, 3);
110 void			log_warn(const char *, ...) __printflike(1, 2);
111 void			log_warnx(const char *, ...) __printflike(1, 2);
112 void			log_debugx(const char *, ...) __printflike(1, 2);
113 
114 char			*checked_strdup(const char *);
115 bool			timed_out(void);
116 void			fail(const struct connection *, const char *);
117 
118 #endif /* !ISCSID_H */
119