iscsid.h revision 279001
1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: stable/10/usr.sbin/iscsid/iscsid.h 279001 2015-02-19 14:28:47Z mav $ 30 */ 31 32#ifndef ISCSID_H 33#define ISCSID_H 34 35#include <stdbool.h> 36#include <stdint.h> 37#include <openssl/md5.h> 38 39#include <iscsi_ioctl.h> 40 41#define DEFAULT_PIDFILE "/var/run/iscsid.pid" 42 43#define CONN_DIGEST_NONE 0 44#define CONN_DIGEST_CRC32C 1 45 46#define CONN_MUTUAL_CHALLENGE_LEN 1024 47#define SOCKBUF_SIZE 1048576 48 49struct connection { 50 int conn_iscsi_fd; 51 int conn_socket; 52 unsigned int conn_session_id; 53 struct iscsi_session_conf conn_conf; 54 char conn_target_alias[ISCSI_ADDR_LEN]; 55 uint8_t conn_isid[6]; 56 uint16_t conn_tsih; 57 uint32_t conn_statsn; 58 int conn_header_digest; 59 int conn_data_digest; 60 bool conn_initial_r2t; 61 bool conn_immediate_data; 62 size_t conn_max_data_segment_length; 63 size_t conn_max_burst_length; 64 size_t conn_first_burst_length; 65 struct chap *conn_mutual_chap; 66}; 67 68struct pdu { 69 struct connection *pdu_connection; 70 struct iscsi_bhs *pdu_bhs; 71 char *pdu_data; 72 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 84#define CHAP_CHALLENGE_LEN 1024 85 86struct chap { 87 unsigned char chap_id; 88 char chap_challenge[CHAP_CHALLENGE_LEN]; 89 char chap_response[MD5_DIGEST_LENGTH]; 90}; 91 92struct rchap { 93 char *rchap_secret; 94 unsigned char rchap_id; 95 void *rchap_challenge; 96 size_t rchap_challenge_len; 97}; 98 99struct chap *chap_new(void); 100char *chap_get_id(const struct chap *chap); 101char *chap_get_challenge(const struct chap *chap); 102int chap_receive(struct chap *chap, const char *response); 103int chap_authenticate(struct chap *chap, 104 const char *secret); 105void chap_delete(struct chap *chap); 106 107struct rchap *rchap_new(const char *secret); 108int rchap_receive(struct rchap *rchap, 109 const char *id, const char *challenge); 110char *rchap_get_response(struct rchap *rchap); 111void rchap_delete(struct rchap *rchap); 112 113struct keys *keys_new(void); 114void keys_delete(struct keys *key); 115void keys_load(struct keys *keys, const struct pdu *pdu); 116void keys_save(struct keys *keys, struct pdu *pdu); 117const char *keys_find(struct keys *keys, const char *name); 118int keys_find_int(struct keys *keys, const char *name); 119void keys_add(struct keys *keys, 120 const char *name, const char *value); 121void keys_add_int(struct keys *keys, 122 const char *name, int value); 123 124struct pdu *pdu_new(struct connection *ic); 125struct pdu *pdu_new_response(struct pdu *request); 126void pdu_receive(struct pdu *request); 127void pdu_send(struct pdu *response); 128void pdu_delete(struct pdu *ip); 129 130void login(struct connection *ic); 131 132void discovery(struct connection *ic); 133 134void log_init(int level); 135void log_set_peer_name(const char *name); 136void log_set_peer_addr(const char *addr); 137void log_err(int, const char *, ...) 138 __dead2 __printflike(2, 3); 139void log_errx(int, const char *, ...) 140 __dead2 __printflike(2, 3); 141void log_warn(const char *, ...) __printflike(1, 2); 142void log_warnx(const char *, ...) __printflike(1, 2); 143void log_debugx(const char *, ...) __printflike(1, 2); 144 145char *checked_strdup(const char *); 146bool timed_out(void); 147void fail(const struct connection *, const char *); 148 149#endif /* !ISCSID_H */ 150