1255570Strasz/*-
2255570Strasz * Copyright (c) 2012 The FreeBSD Foundation
3255570Strasz * All rights reserved.
4255570Strasz *
5255570Strasz * This software was developed by Edward Tomasz Napierala under sponsorship
6255570Strasz * from the FreeBSD Foundation.
7255570Strasz *
8255570Strasz * Redistribution and use in source and binary forms, with or without
9255570Strasz * modification, are permitted provided that the following conditions
10255570Strasz * are met:
11255570Strasz * 1. Redistributions of source code must retain the above copyright
12255570Strasz *    notice, this list of conditions and the following disclaimer.
13255570Strasz * 2. Redistributions in binary form must reproduce the above copyright
14255570Strasz *    notice, this list of conditions and the following disclaimer in the
15255570Strasz *    documentation and/or other materials provided with the distribution.
16255570Strasz *
17255570Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18255570Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19255570Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20255570Strasz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21255570Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22255570Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23255570Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24255570Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25255570Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26255570Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27255570Strasz * SUCH DAMAGE.
28255570Strasz *
29255570Strasz * $FreeBSD$
30255570Strasz */
31255570Strasz
32255570Strasz#ifndef ISCSICTL_H
33255570Strasz#define	ISCSICTL_H
34255570Strasz
35255570Strasz#include <sys/queue.h>
36255570Strasz#include <stdbool.h>
37255570Strasz#include <libutil.h>
38255570Strasz
39255570Strasz#define	DEFAULT_CONFIG_PATH		"/etc/iscsi.conf"
40255570Strasz#define	DEFAULT_IQN			"iqn.1994-09.org.freebsd:"
41255570Strasz
42255570Strasz#define	MAX_NAME_LEN			223
43255570Strasz#define	MAX_DATA_SEGMENT_LENGTH		65536
44255570Strasz
45255570Strasz#define	AUTH_METHOD_UNSPECIFIED		0
46255570Strasz#define	AUTH_METHOD_NONE		1
47255570Strasz#define	AUTH_METHOD_CHAP		2
48255570Strasz
49255570Strasz#define	DIGEST_UNSPECIFIED		0
50255570Strasz#define	DIGEST_NONE			1
51255570Strasz#define	DIGEST_CRC32C			2
52255570Strasz
53255570Strasz#define	SESSION_TYPE_UNSPECIFIED	0
54255570Strasz#define	SESSION_TYPE_NORMAL		1
55255570Strasz#define	SESSION_TYPE_DISCOVERY		2
56255570Strasz
57255570Strasz#define	PROTOCOL_UNSPECIFIED		0
58255570Strasz#define	PROTOCOL_ISCSI			1
59255570Strasz#define	PROTOCOL_ISER			2
60255570Strasz
61255570Straszstruct target {
62255570Strasz	TAILQ_ENTRY(target)	t_next;
63255570Strasz	struct conf		*t_conf;
64255570Strasz	char			*t_nickname;
65255570Strasz	char			*t_name;
66255570Strasz	char			*t_address;
67255570Strasz	char			*t_initiator_name;
68255570Strasz	char			*t_initiator_address;
69255570Strasz	char			*t_initiator_alias;
70255570Strasz	int			t_header_digest;
71255570Strasz	int			t_data_digest;
72255570Strasz	int			t_auth_method;
73255570Strasz	int			t_session_type;
74255570Strasz	int			t_protocol;
75255570Strasz	char			*t_user;
76255570Strasz	char			*t_secret;
77255570Strasz	char			*t_mutual_user;
78255570Strasz	char			*t_mutual_secret;
79255570Strasz};
80255570Strasz
81255570Straszstruct conf {
82255570Strasz	TAILQ_HEAD(, target)	conf_targets;
83255570Strasz};
84255570Strasz
85255570Strasz#define	CONN_SESSION_TYPE_NONE		0
86255570Strasz#define	CONN_SESSION_TYPE_DISCOVERY	1
87255570Strasz#define	CONN_SESSION_TYPE_NORMAL	2
88255570Strasz
89255570Straszstruct connection {
90255570Strasz	struct target		*conn_target;
91255570Strasz	int			conn_socket;
92255570Strasz	int			conn_session_type;
93255570Strasz	uint32_t		conn_cmdsn;
94255570Strasz	uint32_t		conn_statsn;
95255570Strasz	size_t			conn_max_data_segment_length;
96255570Strasz	size_t			conn_max_burst_length;
97255570Strasz	size_t			conn_max_outstanding_r2t;
98255570Strasz	int			conn_header_digest;
99255570Strasz	int			conn_data_digest;
100255570Strasz};
101255570Strasz
102255570Straszstruct conf	*conf_new(void);
103255570Straszstruct conf	*conf_new_from_file(const char *path);
104255570Straszvoid		conf_delete(struct conf *conf);
105255570Straszvoid		conf_verify(struct conf *conf);
106255570Strasz
107255570Straszstruct target	*target_new(struct conf *conf);
108255570Straszstruct target	*target_find(struct conf *conf, const char *nickname);
109255570Straszvoid		target_delete(struct target *ic);
110255570Strasz
111255570Straszvoid		print_periphs(int session_id);
112255570Strasz
113255570Straszchar		*checked_strdup(const char *);
114255570Straszbool		valid_iscsi_name(const char *name);
115255570Strasz
116255570Strasz#endif /* !ISCSICTL_H */
117