iscsid.h revision 268703
138100Speter/*-
264567Sgshapiro * Copyright (c) 2012 The FreeBSD Foundation
338100Speter * All rights reserved.
4321267Sngie *
564567Sgshapiro * This software was developed by Edward Tomasz Napierala under sponsorship
638100Speter * from the FreeBSD Foundation.
738100Speter *
864567Sgshapiro * Redistribution and use in source and binary forms, with or without
974814Sru * modification, are permitted provided that the following conditions
1090798Sgshapiro * are met:
1138100Speter * 1. Redistributions of source code must retain the above copyright
12147225Sdes *    notice, this list of conditions and the following disclaimer.
13147225Sdes * 2. Redistributions in binary form must reproduce the above copyright
1464567Sgshapiro *    notice, this list of conditions and the following disclaimer in the
1590798Sgshapiro *    documentation and/or other materials provided with the distribution.
1690798Sgshapiro *
1764567Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18201380Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19201380Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2090798Sgshapiro * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2190798Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2290798Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2365970Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2465970Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2566961Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2666961Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2765970Sgshapiro * SUCH DAMAGE.
2865970Sgshapiro *
2990798Sgshapiro * $FreeBSD: stable/10/usr.sbin/iscsid/iscsid.h 268703 2014-07-15 18:21:26Z mav $
3090798Sgshapiro */
3190798Sgshapiro
3238100Speter#ifndef ISCSID_H
33#define	ISCSID_H
34
35#include <stdbool.h>
36#include <stdint.h>
37
38#include <iscsi_ioctl.h>
39
40#define	DEFAULT_PIDFILE			"/var/run/iscsid.pid"
41
42#define	CONN_DIGEST_NONE		0
43#define	CONN_DIGEST_CRC32C		1
44
45#define CONN_MUTUAL_CHALLENGE_LEN	1024
46
47struct connection {
48	int			conn_iscsi_fd;
49	int			conn_socket;
50	unsigned int		conn_session_id;
51	struct iscsi_session_conf	conn_conf;
52	char			conn_target_alias[ISCSI_ADDR_LEN];
53	uint8_t			conn_isid[6];
54	uint16_t		conn_tsih;
55	uint32_t		conn_statsn;
56	int			conn_header_digest;
57	int			conn_data_digest;
58	bool			conn_initial_r2t;
59	bool			conn_immediate_data;
60	size_t			conn_max_data_segment_length;
61	size_t			conn_max_burst_length;
62	size_t			conn_first_burst_length;
63	char			conn_mutual_challenge[CONN_MUTUAL_CHALLENGE_LEN];
64	unsigned char		conn_mutual_id;
65};
66
67struct pdu {
68	struct connection	*pdu_connection;
69	struct iscsi_bhs	*pdu_bhs;
70	char			*pdu_data;
71	size_t			pdu_data_len;
72};
73
74#define	KEYS_MAX		1024
75
76struct keys {
77	char			*keys_names[KEYS_MAX];
78	char			*keys_values[KEYS_MAX];
79	char			*keys_data;
80	size_t			keys_data_len;
81};
82
83struct keys		*keys_new(void);
84void			keys_delete(struct keys *key);
85void			keys_load(struct keys *keys, const struct pdu *pdu);
86void			keys_save(struct keys *keys, struct pdu *pdu);
87const char		*keys_find(struct keys *keys, const char *name);
88int			keys_find_int(struct keys *keys, const char *name);
89void			keys_add(struct keys *keys,
90			    const char *name, const char *value);
91void			keys_add_int(struct keys *keys,
92			    const char *name, int value);
93
94struct pdu		*pdu_new(struct connection *ic);
95struct pdu		*pdu_new_response(struct pdu *request);
96void			pdu_receive(struct pdu *request);
97void			pdu_send(struct pdu *response);
98void			pdu_delete(struct pdu *ip);
99
100void			login(struct connection *ic);
101
102void			discovery(struct connection *ic);
103
104void			log_init(int level);
105void			log_set_peer_name(const char *name);
106void			log_set_peer_addr(const char *addr);
107void			log_err(int, const char *, ...)
108			    __dead2 __printflike(2, 3);
109void			log_errx(int, const char *, ...)
110			    __dead2 __printflike(2, 3);
111void			log_warn(const char *, ...) __printflike(1, 2);
112void			log_warnx(const char *, ...) __printflike(1, 2);
113void			log_debugx(const char *, ...) __printflike(1, 2);
114
115char			*checked_strdup(const char *);
116bool			timed_out(void);
117void			fail(const struct connection *, const char *);
118
119#endif /* !ISCSID_H */
120