xref: /freebsd/usr.sbin/ctld/iscsi.hh (revision 7e844dcad22bdbbdfa9c73271fe46b9ef963d34c)
1*7e844dcaSJohn Baldwin /*-
2*7e844dcaSJohn Baldwin  * SPDX-License-Identifier: BSD-2-Clause
3*7e844dcaSJohn Baldwin  *
4*7e844dcaSJohn Baldwin  * Copyright (c) 2012 The FreeBSD Foundation
5*7e844dcaSJohn Baldwin  *
6*7e844dcaSJohn Baldwin  * This software was developed by Edward Tomasz Napierala under sponsorship
7*7e844dcaSJohn Baldwin  * from the FreeBSD Foundation.
8*7e844dcaSJohn Baldwin  *
9*7e844dcaSJohn Baldwin  * Redistribution and use in source and binary forms, with or without
10*7e844dcaSJohn Baldwin  * modification, are permitted provided that the following conditions
11*7e844dcaSJohn Baldwin  * are met:
12*7e844dcaSJohn Baldwin  * 1. Redistributions of source code must retain the above copyright
13*7e844dcaSJohn Baldwin  *    notice, this list of conditions and the following disclaimer.
14*7e844dcaSJohn Baldwin  * 2. Redistributions in binary form must reproduce the above copyright
15*7e844dcaSJohn Baldwin  *    notice, this list of conditions and the following disclaimer in the
16*7e844dcaSJohn Baldwin  *    documentation and/or other materials provided with the distribution.
17*7e844dcaSJohn Baldwin  *
18*7e844dcaSJohn Baldwin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19*7e844dcaSJohn Baldwin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*7e844dcaSJohn Baldwin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*7e844dcaSJohn Baldwin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22*7e844dcaSJohn Baldwin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*7e844dcaSJohn Baldwin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*7e844dcaSJohn Baldwin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*7e844dcaSJohn Baldwin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*7e844dcaSJohn Baldwin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*7e844dcaSJohn Baldwin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*7e844dcaSJohn Baldwin  * SUCH DAMAGE.
29*7e844dcaSJohn Baldwin  */
30*7e844dcaSJohn Baldwin 
31*7e844dcaSJohn Baldwin #ifndef __ISCSI_HH__
32*7e844dcaSJohn Baldwin #define	__ISCSI_HH__
33*7e844dcaSJohn Baldwin 
34*7e844dcaSJohn Baldwin #define	CONN_SESSION_TYPE_NONE		0
35*7e844dcaSJohn Baldwin #define	CONN_SESSION_TYPE_DISCOVERY	1
36*7e844dcaSJohn Baldwin #define	CONN_SESSION_TYPE_NORMAL	2
37*7e844dcaSJohn Baldwin 
38*7e844dcaSJohn Baldwin struct iscsi_connection {
39*7e844dcaSJohn Baldwin 	iscsi_connection(struct portal *portal, int fd, const char *host,
40*7e844dcaSJohn Baldwin 	    const struct sockaddr *client_sa);
41*7e844dcaSJohn Baldwin 	~iscsi_connection();
42*7e844dcaSJohn Baldwin 
43*7e844dcaSJohn Baldwin 	void handle();
44*7e844dcaSJohn Baldwin private:
45*7e844dcaSJohn Baldwin 	void login();
46*7e844dcaSJohn Baldwin 	void login_chap(struct auth_group *ag);
47*7e844dcaSJohn Baldwin 	void login_negotiate_key(struct pdu *request, const char *name,
48*7e844dcaSJohn Baldwin 	    const char *value, bool skipped_security,
49*7e844dcaSJohn Baldwin 	    struct keys *response_keys);
50*7e844dcaSJohn Baldwin 	bool login_portal_redirect(struct pdu *request);
51*7e844dcaSJohn Baldwin 	bool login_target_redirect(struct pdu *request);
52*7e844dcaSJohn Baldwin 	void login_negotiate(struct pdu *request);
53*7e844dcaSJohn Baldwin 	void login_wait_transition();
54*7e844dcaSJohn Baldwin 
55*7e844dcaSJohn Baldwin 	void discovery();
56*7e844dcaSJohn Baldwin 	bool discovery_target_filtered_out(const struct port *port) const;
57*7e844dcaSJohn Baldwin 
58*7e844dcaSJohn Baldwin 	void kernel_handoff();
59*7e844dcaSJohn Baldwin 
60*7e844dcaSJohn Baldwin 	struct connection	conn;
61*7e844dcaSJohn Baldwin 	struct portal		*conn_portal = nullptr;
62*7e844dcaSJohn Baldwin 	const struct port	*conn_port = nullptr;
63*7e844dcaSJohn Baldwin 	struct target		*conn_target = nullptr;
64*7e844dcaSJohn Baldwin 	int			conn_session_type = CONN_SESSION_TYPE_NONE;
65*7e844dcaSJohn Baldwin 	std::string		conn_initiator_name;
66*7e844dcaSJohn Baldwin 	std::string		conn_initiator_addr;
67*7e844dcaSJohn Baldwin 	std::string		conn_initiator_alias;
68*7e844dcaSJohn Baldwin 	uint8_t			conn_initiator_isid[6];
69*7e844dcaSJohn Baldwin 	const struct sockaddr	*conn_initiator_sa = nullptr;
70*7e844dcaSJohn Baldwin 	int			conn_max_recv_data_segment_limit = 0;
71*7e844dcaSJohn Baldwin 	int			conn_max_send_data_segment_limit = 0;
72*7e844dcaSJohn Baldwin 	int			conn_max_burst_limit = 0;
73*7e844dcaSJohn Baldwin 	int			conn_first_burst_limit = 0;
74*7e844dcaSJohn Baldwin 	std::string		conn_user;
75*7e844dcaSJohn Baldwin 	struct chap		*conn_chap = nullptr;
76*7e844dcaSJohn Baldwin };
77*7e844dcaSJohn Baldwin 
78*7e844dcaSJohn Baldwin #endif /* !__ISCSI_HH__ */
79