xref: /freebsd/usr.bin/iscsictl/iscsictl.h (revision 2008043f386721d58158e37e0d7e50df8095942d)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2012 The FreeBSD Foundation
5  *
6  * This software was developed by Edward Tomasz Napierala under sponsorship
7  * from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef ISCSICTL_H
32 #define	ISCSICTL_H
33 
34 #include <sys/queue.h>
35 #include <stdbool.h>
36 #include <libutil.h>
37 
38 #define	DEFAULT_CONFIG_PATH		"/etc/iscsi.conf"
39 #define	DEFAULT_IQN			"iqn.1994-09.org.freebsd:"
40 
41 #define	MAX_NAME_LEN			223
42 
43 #define	AUTH_METHOD_UNSPECIFIED		0
44 #define	AUTH_METHOD_NONE		1
45 #define	AUTH_METHOD_CHAP		2
46 
47 #define	DIGEST_UNSPECIFIED		0
48 #define	DIGEST_NONE			1
49 #define	DIGEST_CRC32C			2
50 
51 #define	SESSION_TYPE_UNSPECIFIED	0
52 #define	SESSION_TYPE_NORMAL		1
53 #define	SESSION_TYPE_DISCOVERY		2
54 
55 #define	PROTOCOL_UNSPECIFIED		0
56 #define	PROTOCOL_ISCSI			1
57 #define	PROTOCOL_ISER			2
58 
59 #define	ENABLE_UNSPECIFIED		0
60 #define	ENABLE_ON			1
61 #define	ENABLE_OFF			2
62 
63 struct target {
64 	TAILQ_ENTRY(target)	t_next;
65 	struct conf		*t_conf;
66 	char			*t_nickname;
67 	char			*t_name;
68 	char			*t_address;
69 	char			*t_initiator_name;
70 	char			*t_initiator_address;
71 	char			*t_initiator_alias;
72 	int			t_header_digest;
73 	int			t_data_digest;
74 	int			t_auth_method;
75 	int			t_session_type;
76 	int			t_enable;
77 	int			t_protocol;
78 	int			t_dscp;
79 	int			t_pcp;
80 	int			t_pingtimeout;
81 	int			t_logintimeout;
82 	char			*t_offload;
83 	char			*t_user;
84 	char			*t_secret;
85 	char			*t_mutual_user;
86 	char			*t_mutual_secret;
87 };
88 
89 struct conf {
90 	TAILQ_HEAD(, target)	conf_targets;
91 };
92 
93 struct conf	*conf_new(void);
94 struct conf	*conf_new_from_file(const char *path);
95 void		conf_delete(struct conf *conf);
96 void		conf_verify(struct conf *conf);
97 
98 struct target	*target_new(struct conf *conf);
99 struct target	*target_find(struct conf *conf, const char *nickname);
100 void		target_delete(struct target *ic);
101 
102 void		print_periphs(int session_id);
103 
104 bool		valid_iscsi_name(const char *name);
105 int		parse_enable(const char *enable);
106 
107 #endif /* !ISCSICTL_H */
108