xref: /freebsd/usr.sbin/ctld/iscsi.hh (revision 16459743927068abbee34ce3f266b38c71968232)
17e844dcaSJohn Baldwin /*-
27e844dcaSJohn Baldwin  * SPDX-License-Identifier: BSD-2-Clause
37e844dcaSJohn Baldwin  *
47e844dcaSJohn Baldwin  * Copyright (c) 2012 The FreeBSD Foundation
57e844dcaSJohn Baldwin  *
67e844dcaSJohn Baldwin  * This software was developed by Edward Tomasz Napierala under sponsorship
77e844dcaSJohn Baldwin  * from the FreeBSD Foundation.
87e844dcaSJohn Baldwin  *
97e844dcaSJohn Baldwin  * Redistribution and use in source and binary forms, with or without
107e844dcaSJohn Baldwin  * modification, are permitted provided that the following conditions
117e844dcaSJohn Baldwin  * are met:
127e844dcaSJohn Baldwin  * 1. Redistributions of source code must retain the above copyright
137e844dcaSJohn Baldwin  *    notice, this list of conditions and the following disclaimer.
147e844dcaSJohn Baldwin  * 2. Redistributions in binary form must reproduce the above copyright
157e844dcaSJohn Baldwin  *    notice, this list of conditions and the following disclaimer in the
167e844dcaSJohn Baldwin  *    documentation and/or other materials provided with the distribution.
177e844dcaSJohn Baldwin  *
187e844dcaSJohn Baldwin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
197e844dcaSJohn Baldwin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
207e844dcaSJohn Baldwin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
217e844dcaSJohn Baldwin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
227e844dcaSJohn Baldwin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
237e844dcaSJohn Baldwin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
247e844dcaSJohn Baldwin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
257e844dcaSJohn Baldwin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
267e844dcaSJohn Baldwin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
277e844dcaSJohn Baldwin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
287e844dcaSJohn Baldwin  * SUCH DAMAGE.
297e844dcaSJohn Baldwin  */
307e844dcaSJohn Baldwin 
317e844dcaSJohn Baldwin #ifndef __ISCSI_HH__
327e844dcaSJohn Baldwin #define	__ISCSI_HH__
337e844dcaSJohn Baldwin 
347e844dcaSJohn Baldwin #define	CONN_SESSION_TYPE_NONE		0
357e844dcaSJohn Baldwin #define	CONN_SESSION_TYPE_DISCOVERY	1
367e844dcaSJohn Baldwin #define	CONN_SESSION_TYPE_NORMAL	2
377e844dcaSJohn Baldwin 
387e844dcaSJohn Baldwin struct iscsi_connection {
3940484d31SJohn Baldwin 	iscsi_connection(struct portal *portal, freebsd::fd_up fd,
4040484d31SJohn Baldwin 	    const char *host, const struct sockaddr *client_sa);
417e844dcaSJohn Baldwin 	~iscsi_connection();
427e844dcaSJohn Baldwin 
437e844dcaSJohn Baldwin 	void handle();
447e844dcaSJohn Baldwin private:
457e844dcaSJohn Baldwin 	void login();
467e844dcaSJohn Baldwin 	void login_chap(struct auth_group *ag);
477e844dcaSJohn Baldwin 	void login_negotiate_key(struct pdu *request, const char *name,
487e844dcaSJohn Baldwin 	    const char *value, bool skipped_security,
497e844dcaSJohn Baldwin 	    struct keys *response_keys);
507e844dcaSJohn Baldwin 	bool login_portal_redirect(struct pdu *request);
517e844dcaSJohn Baldwin 	bool login_target_redirect(struct pdu *request);
527e844dcaSJohn Baldwin 	void login_negotiate(struct pdu *request);
537e844dcaSJohn Baldwin 	void login_wait_transition();
547e844dcaSJohn Baldwin 
557e844dcaSJohn Baldwin 	void discovery();
567e844dcaSJohn Baldwin 	bool discovery_target_filtered_out(const struct port *port) const;
577e844dcaSJohn Baldwin 
587e844dcaSJohn Baldwin 	void kernel_handoff();
597e844dcaSJohn Baldwin 
607e844dcaSJohn Baldwin 	struct connection	conn;
617e844dcaSJohn Baldwin 	struct portal		*conn_portal = nullptr;
627e844dcaSJohn Baldwin 	const struct port	*conn_port = nullptr;
637e844dcaSJohn Baldwin 	struct target		*conn_target = nullptr;
6440484d31SJohn Baldwin 	freebsd::fd_up		conn_fd;
657e844dcaSJohn Baldwin 	int			conn_session_type = CONN_SESSION_TYPE_NONE;
667e844dcaSJohn Baldwin 	std::string		conn_initiator_name;
677e844dcaSJohn Baldwin 	std::string		conn_initiator_addr;
687e844dcaSJohn Baldwin 	std::string		conn_initiator_alias;
69*16459743SJohn Baldwin 	uint8_t			conn_initiator_isid[6] = {};
707e844dcaSJohn Baldwin 	const struct sockaddr	*conn_initiator_sa = nullptr;
717e844dcaSJohn Baldwin 	int			conn_max_recv_data_segment_limit = 0;
727e844dcaSJohn Baldwin 	int			conn_max_send_data_segment_limit = 0;
737e844dcaSJohn Baldwin 	int			conn_max_burst_limit = 0;
747e844dcaSJohn Baldwin 	int			conn_first_burst_limit = 0;
757e844dcaSJohn Baldwin 	std::string		conn_user;
767e844dcaSJohn Baldwin 	struct chap		*conn_chap = nullptr;
777e844dcaSJohn Baldwin };
787e844dcaSJohn Baldwin 
797e844dcaSJohn Baldwin #endif /* !__ISCSI_HH__ */
80