iscsid.h revision 262844
11573Srgrimes/*-
21573Srgrimes * Copyright (c) 2012 The FreeBSD Foundation
31573Srgrimes * All rights reserved.
41573Srgrimes *
51573Srgrimes * This software was developed by Edward Tomasz Napierala under sponsorship
61573Srgrimes * from the FreeBSD Foundation.
71573Srgrimes *
81573Srgrimes * Redistribution and use in source and binary forms, with or without
91573Srgrimes * modification, are permitted provided that the following conditions
101573Srgrimes * are met:
111573Srgrimes * 1. Redistributions of source code must retain the above copyright
121573Srgrimes *    notice, this list of conditions and the following disclaimer.
131573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141573Srgrimes *    notice, this list of conditions and the following disclaimer in the
151573Srgrimes *    documentation and/or other materials provided with the distribution.
16148834Sstefanf *
171573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
181573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
211573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271573Srgrimes * SUCH DAMAGE.
281573Srgrimes *
291573Srgrimes * $FreeBSD: stable/10/usr.sbin/iscsid/iscsid.h 262844 2014-03-06 11:13:26Z trasz $
301573Srgrimes */
311573Srgrimes
321573Srgrimes#ifndef ISCSID_H
33238378Spfg#define	ISCSID_H
3484260Sobrien
351573Srgrimes#include <stdbool.h>
361573Srgrimes#include <stdint.h>
371573Srgrimes
381573Srgrimes#include <iscsi_ioctl.h>
391573Srgrimes
401573Srgrimes#define	DEFAULT_PIDFILE			"/var/run/iscsid.pid"
4184260Sobrien
421573Srgrimes#define	CONN_DIGEST_NONE		0
431573Srgrimes#define	CONN_DIGEST_CRC32C		1
441573Srgrimes
451573Srgrimes#define CONN_MUTUAL_CHALLENGE_LEN	1024
461573Srgrimes
471573Srgrimesstruct connection {
481573Srgrimes	int			conn_iscsi_fd;
491573Srgrimes#ifndef ICL_KERNEL_PROXY
501573Srgrimes	int			conn_socket;
5184260Sobrien#endif
5284260Sobrien	unsigned int		conn_session_id;
5384260Sobrien	struct iscsi_session_conf	conn_conf;
5484260Sobrien	char			conn_target_alias[ISCSI_ADDR_LEN];
5584260Sobrien	uint8_t			conn_isid[6];
5684260Sobrien	uint32_t		conn_statsn;
5784260Sobrien	int			conn_header_digest;
5884260Sobrien	int			conn_data_digest;
59237448Spfg	bool			conn_initial_r2t;
601573Srgrimes	bool			conn_immediate_data;
61237448Spfg	size_t			conn_max_data_segment_length;
62237448Spfg	size_t			conn_max_burst_length;
63237448Spfg	size_t			conn_first_burst_length;
64238378Spfg	char			conn_mutual_challenge[CONN_MUTUAL_CHALLENGE_LEN];
65237448Spfg	unsigned char		conn_mutual_id;
661573Srgrimes};
6784260Sobrien
6884260Sobrienstruct pdu {
6984260Sobrien	struct connection	*pdu_connection;
7084260Sobrien	struct iscsi_bhs	*pdu_bhs;
711573Srgrimes	char			*pdu_data;
721573Srgrimes	size_t			pdu_data_len;
73};
74
75#define	KEYS_MAX		1024
76
77struct keys {
78	char			*keys_names[KEYS_MAX];
79	char			*keys_values[KEYS_MAX];
80	char			*keys_data;
81	size_t			keys_data_len;
82};
83
84struct keys		*keys_new(void);
85void			keys_delete(struct keys *key);
86void			keys_load(struct keys *keys, const struct pdu *pdu);
87void			keys_save(struct keys *keys, struct pdu *pdu);
88const char		*keys_find(struct keys *keys, const char *name);
89int			keys_find_int(struct keys *keys, const char *name);
90void			keys_add(struct keys *keys,
91			    const char *name, const char *value);
92void			keys_add_int(struct keys *keys,
93			    const char *name, int value);
94
95struct pdu		*pdu_new(struct connection *ic);
96struct pdu		*pdu_new_response(struct pdu *request);
97void			pdu_receive(struct pdu *request);
98void			pdu_send(struct pdu *response);
99void			pdu_delete(struct pdu *ip);
100
101void			login(struct connection *ic);
102
103void			discovery(struct connection *ic);
104
105void			log_init(int level);
106void			log_set_peer_name(const char *name);
107void			log_set_peer_addr(const char *addr);
108void			log_err(int, const char *, ...)
109			    __dead2 __printflike(2, 3);
110void			log_errx(int, const char *, ...)
111			    __dead2 __printflike(2, 3);
112void			log_warn(const char *, ...) __printflike(1, 2);
113void			log_warnx(const char *, ...) __printflike(1, 2);
114void			log_debugx(const char *, ...) __printflike(1, 2);
115
116char			*checked_strdup(const char *);
117bool			timed_out(void);
118void			fail(const struct connection *, const char *);
119
120#endif /* !ISCSID_H */
121