/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _CHAP_H #define _CHAP_H #ifdef __cplusplus extern "C" { #endif #include #include #include #include typedef enum chap_validation_status_type { CHAP_VALIDATION_PASSED, /* CHAP validation passed */ CHAP_VALIDATION_INVALID_RESPONSE, /* Invalid CHAP response */ CHAP_VALIDATION_DUP_SECRET, /* Same CHAP secret used */ /* for authentication in the */ /* other direction */ CHAP_VALIDATION_UNKNOWN_AUTH_METHOD, /* Unknown authentication */ /* method */ CHAP_VALIDATION_INTERNAL_ERROR, /* MISC internal error */ CHAP_VALIDATION_RADIUS_ACCESS_ERROR, /* Problem accessing RADIUS */ CHAP_VALIDATION_BAD_RADIUS_SECRET, /* Invalid RADIUS shared */ /* secret */ CHAP_VALIDATION_UNKNOWN_RADIUS_CODE /* Irrelevant or unknown */ /* RADIUS packet code */ /* returned */ } chap_validation_status_type; typedef enum authentication_method_type { RADIUS_AUTHENTICATION, DIRECT_AUTHENTICATION } authentication_method_type; typedef struct radius_config { iscsi_ipaddr_t rad_svr_addr; /* IPv6 enabled */ uint32_t rad_svr_port; uint8_t rad_svr_shared_secret[MAX_RAD_SHARED_SECRET_LEN]; uint32_t rad_svr_shared_secret_len; } RADIUS_CONFIG; /* * To validate a target CHAP response given the associated challenge. * * target_chap_name - The CHAP name of the target being authenticated. * initiator_chap_name - The CHAP name of the authenticating initiator. * challenge - The CHAP challenge to which the target responded. * target_response - The target's CHAP response to be validated. * identifier - The identifier associated with the CHAP challenge. * auth_method - The authentication method to be used. * auth_config_data - Any required configuration data to support the * specified authentication method. */ chap_validation_status_type chap_validate( char *target_chap_name, char *initiator_chap_name, uint8_t *challenge, uint8_t *target_response, uint8_t identifier, authentication_method_type auth_method, void *auth_config_data); #ifdef __cplusplus } #endif #endif /* _CHAP_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _ISCSI_IF_H #define _ISCSI_IF_H #ifdef __cplusplus extern "C" { #endif #ifdef _KERNEL #include #include /* for prototype of kstrgetmsg */ #include #include /* for struct sonode */ #endif #include #include #include /* * Each of the top level structures have a version field as * the first member. That version value will be set by the * caller. The consumer of the structure will check to see * if the version is correct. */ #define ISCSI_INTERFACE_VERSION 3 /* * The maximum length of an iSCSI name is 223. 224 is used * to provide space for a null character. */ #define ISCSI_MAX_NAME_LEN 224 /* * Login parameter values are used instead of ascii text * between the IMA plug-in and kernel. */ #define ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER 0x0000 /* bool */ #define ISCSI_LOGIN_PARAM_IMMEDIATE_DATA 0x0001 /* bool */ #define ISCSI_LOGIN_PARAM_INITIAL_R2T 0x0002 /* bool */ #define ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER 0x0003 /* bool */ #define ISCSI_LOGIN_PARAM_HEADER_DIGEST 0x0004 /* int */ #define ISCSI_LOGIN_PARAM_DATA_DIGEST 0x0005 /* int */ #define ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN 0x0006 /* int */ #define ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT 0x0007 /* int */ #define ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH 0x0008 /* int */ #define ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH 0x0009 /* int */ #define ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH 0x000A /* int */ #define ISCSI_LOGIN_PARAM_MAX_CONNECTIONS 0x000B /* int */ #define ISCSI_LOGIN_PARAM_OUTSTANDING_R2T 0x000C /* int */ #define ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL 0x000D /* int */ /* * number of login parameters - needs to be updated when new parameter added */ #define ISCSI_NUM_LOGIN_PARAM 0x000E /* * Used internally by the persistent store code. Currently a bitmap is kept of * which params are currently set. This allows for quick a look up instead of * cycling through the possible entries. Using an unsigned int as the bitmap we * can have parameter numbers up through 31. Since the current only has 22 * we're okay. */ #define ISCSI_LOGIN_PARAM_DB_ENTRY 0x0020 /* * Special case. When this parameter value is set in iscsi_param_set_t * the member s_value (type iscsi_param_set_t) is not used. * The name field contains the InitiatorName for the system which * should be used for all future sessions. */ #define ISCSI_LOGIN_PARAM_INITIATOR_NAME 0x0021 #define ISCSI_LOGIN_PARAM_INITIATOR_ALIAS 0x0022 #define ISCSI_DEVCTL "devctl" #define ISCSI_DRIVER_DEVCTL "/devices/iscsi:" ISCSI_DEVCTL /* * ioctls supported by the driver. */ #define ISCSI_IOCTL (('i' << 24) | ('S' << 16) | ('C' << 8)) #define ISCSI_CREATE_OID (ISCSI_IOCTL | 2) #define ISCSI_LOGIN (ISCSI_IOCTL | 3) #define ISCSI_LOGOUT (ISCSI_IOCTL | 4) #define ISCSI_PARAM_GET (ISCSI_IOCTL | 5) #define ISCSI_PARAM_SET (ISCSI_IOCTL | 6) #define ISCSI_TARGET_PARAM_CLEAR (ISCSI_IOCTL | 8) #define ISCSI_TARGET_OID_LIST_GET (ISCSI_IOCTL | 9) #define ISCSI_TARGET_PROPS_GET (ISCSI_IOCTL | 10) #define ISCSI_TARGET_PROPS_SET (ISCSI_IOCTL | 11) #define ISCSI_TARGET_ADDRESS_GET (ISCSI_IOCTL | 12) #define ISCSI_CHAP_SET (ISCSI_IOCTL | 13) #define ISCSI_CHAP_GET (ISCSI_IOCTL | 14) #define ISCSI_CHAP_CLEAR (ISCSI_IOCTL | 15) #define ISCSI_STATIC_GET (ISCSI_IOCTL | 16) #define ISCSI_STATIC_SET (ISCSI_IOCTL | 17) #define ISCSI_STATIC_CLEAR (ISCSI_IOCTL | 18) #define ISCSI_DISCOVERY_SET (ISCSI_IOCTL | 19) #define ISCSI_DISCOVERY_GET (ISCSI_IOCTL | 20) #define ISCSI_DISCOVERY_CLEAR (ISCSI_IOCTL | 21) #define ISCSI_DISCOVERY_PROPS (ISCSI_IOCTL | 22) #define ISCSI_DISCOVERY_ADDR_SET (ISCSI_IOCTL | 23) #define ISCSI_DISCOVERY_ADDR_LIST_GET (ISCSI_IOCTL | 24) #define ISCSI_DISCOVERY_ADDR_CLEAR (ISCSI_IOCTL | 25) #define ISCSI_RADIUS_SET (ISCSI_IOCTL | 26) #define ISCSI_RADIUS_GET (ISCSI_IOCTL | 27) #define ISCSI_DB_RELOAD (ISCSI_IOCTL | 28) #define ISCSI_LUN_OID_LIST_GET (ISCSI_IOCTL | 29) #define ISCSI_LUN_PROPS_GET (ISCSI_IOCTL | 30) #define ISCSI_CONN_OID_LIST_GET (ISCSI_IOCTL | 31) #define ISCSI_CONN_PROPS_GET (ISCSI_IOCTL | 32) #define ISCSI_USCSI (ISCSI_IOCTL | 33) #define ISCSI_DOOR_HANDLE_SET (ISCSI_IOCTL | 34) #define ISCSI_DISCOVERY_EVENTS (ISCSI_IOCTL | 35) #define ISCSI_AUTH_SET (ISCSI_IOCTL | 36) #define ISCSI_AUTH_GET (ISCSI_IOCTL | 37) #define ISCSI_AUTH_CLEAR (ISCSI_IOCTL | 38) #define ISCSI_SENDTGTS_GET (ISCSI_IOCTL | 39) #define ISCSI_ISNS_SERVER_ADDR_SET (ISCSI_IOCTL | 40) #define ISCSI_ISNS_SERVER_ADDR_LIST_GET (ISCSI_IOCTL | 41) #define ISCSI_ISNS_SERVER_ADDR_CLEAR (ISCSI_IOCTL | 42) #define ISCSI_ISNS_SERVER_GET (ISCSI_IOCTL | 43) #define ISCSI_GET_CONFIG_SESSIONS (ISCSI_IOCTL | 44) #define ISCSI_SET_CONFIG_SESSIONS (ISCSI_IOCTL | 45) #define ISCSI_INIT_NODE_NAME_SET (ISCSI_IOCTL | 46) #define ISCSI_DB_DUMP (ISCSI_IOCTL | 100) /* DBG */ /* * Misc. defines */ #define ISCSI_CHAP_NAME_LEN 512 #define ISCSI_CHAP_SECRET_LEN 16 #define ISCSI_TGT_OID_LIST 0x0001 #define ISCSI_STATIC_TGT_OID_LIST 0x0002 #define ISCSI_TGT_PARAM_OID_LIST 0x0004 #define ISCSI_SESS_PARAM 0x0001 #define ISCSI_CONN_PARAM 0x0002 /* digest level defines */ #define ISCSI_DIGEST_NONE 0 #define ISCSI_DIGEST_CRC32C 1 #define ISCSI_DIGEST_CRC32C_NONE 2 /* offer both, prefer CRC32C */ #define ISCSI_DIGEST_NONE_CRC32C 3 /* offer both, prefer None */ /* * A last error associated with each target session is returned in the * iscsi_target_t structure. */ typedef enum iscsi_error { NoError, AuthenticationError, LoginParamError, ConnectionReset } iscsi_error_t; /* * The values associated with each enum is based on the IMA specification. */ typedef enum iSCSIDiscoveryMethod { iSCSIDiscoveryMethodUnknown = 0, iSCSIDiscoveryMethodStatic = 1, iSCSIDiscoveryMethodSLP = 2, iSCSIDiscoveryMethodISNS = 4, iSCSIDiscoveryMethodSendTargets = 8 } iSCSIDiscoveryMethod_t; #define ISCSI_ALL_DISCOVERY_METHODS (iSCSIDiscoveryMethodStatic | \ iSCSIDiscoveryMethodSLP | \ iSCSIDiscoveryMethodISNS | \ iSCSIDiscoveryMethodSendTargets) /* * Before anything can be done to a target it must have an OID. */ typedef struct iscsi_oid { uint32_t o_vers; /* In */ uchar_t o_name[ISCSI_MAX_NAME_LEN]; /* In */ /* * tpgt is only 16 bits per spec. use 32 in ioctl to reduce * packing issue. Also -1 tpgt denotes default value. iSCSI * stack will detemermine tpgt during login. */ int o_tpgt; /* In */ uint32_t o_oid; /* Out */ } iscsi_oid_t; #define ISCSI_OID_NOTSET 0 #define ISCSI_INITIATOR_OID 1 /* Other OIDs follow > 1 */ #define ISCSI_DEFAULT_TPGT -1 /* * iSCSI Login Parameters - Reference iscsi draft for * definitions of the below login params. */ typedef struct iscsi_login_params { boolean_t immediate_data; boolean_t initial_r2t; int first_burst_length; /* range: 512 - 2**24-1 */ int max_burst_length; /* range: 512 - 2**24-1 */ boolean_t data_pdu_in_order; boolean_t data_sequence_in_order; int default_time_to_wait; int default_time_to_retain; int header_digest; int data_digest; int max_recv_data_seg_len; /* range: 512 - 2**24-1 */ int max_xmit_data_seg_len; /* range: 512 - 2**24-1 */ int max_connections; int max_outstanding_r2t; int error_recovery_level; boolean_t ifmarker; boolean_t ofmarker; } iscsi_login_params_t; /* * Once parameters have been set via ISCSI_SET_PARAM the login is initiated * by sending an ISCSI_LOGIN ioctl with the following structure filled in. */ typedef struct entry { int e_vers; uint32_t e_oid; union { struct in_addr u_in4; struct in6_addr u_in6; } e_u; /* * e_insize indicates which of the previous structs is valid. */ int e_insize; int e_port; int e_tpgt; } entry_t; /* * Used when setting or gettnig the Initiator Name or Alias. */ typedef struct node_name { unsigned char n_name[ISCSI_MAX_NAME_LEN]; int n_len; } node_name_t; typedef struct _iSCSIMinMaxValue { uint32_t i_current, i_default, i_min, i_max, i_incr; } iscsi_int_info_t; typedef struct _iSCSIBoolValue { boolean_t b_current, b_default; } iscsi_bool_info_t; typedef struct _iSCSIParamValueGet { boolean_t v_valid, v_settable; iscsi_int_info_t v_integer; iscsi_bool_info_t v_bool; uchar_t v_name[ISCSI_MAX_NAME_LEN]; } iscsi_get_value_t; typedef struct _iSCSILoginParamGet { uint32_t g_vers; /* In */ uint32_t g_oid; /* In */ uint32_t g_param; /* Out */ iscsi_get_value_t g_value; /* Out */ uint32_t g_conn_cid; /* In */ /* * To indicate whether session or connection related param is * being requested. */ uint32_t g_param_type; /* In */ } iscsi_param_get_t; typedef struct iscsi_set_value { uint32_t v_integer; boolean_t v_bool; uchar_t v_name[ISCSI_MAX_NAME_LEN]; } iscsi_set_value_t; /* * All of the members of this structure are set by the user agent and * consumed by the driver. */ typedef struct iSCSILoginParamSet { uint32_t s_vers, s_oid; uint32_t s_param; iscsi_set_value_t s_value; } iscsi_param_set_t; /* * Data in this structure is set by the user agent and consumed by * the driver. */ typedef struct chap_props { uint32_t c_vers, c_retries, c_oid; unsigned char c_user[128]; uint32_t c_user_len; unsigned char c_secret[16]; uint32_t c_secret_len; } iscsi_chap_props_t; typedef enum authMethod { authMethodNone = 0x00, authMethodCHAP = 0x01, authMethodSRP = 0x02, authMethodKRB5 = 0x04, authMethodSPKM1 = 0x08, authMethodSPKM2 = 0x10 } authMethod_t; /* * Data in this structure is set by the user agent and consumed by * the driver. */ typedef struct auth_props { uint32_t a_vers; uint32_t a_oid; boolean_t a_bi_auth; authMethod_t a_auth_method; } iscsi_auth_props_t; /* * Data in this structure is set by the user agent and consumed by * the driver. */ #define MAX_RAD_SHARED_SECRET_LEN 128 typedef struct radius_props { uint32_t r_vers; uint32_t r_oid; union { struct in_addr u_in4; struct in6_addr u_in6; } r_addr; /* * r_insize indicates which of the previous structs is valid. */ int r_insize; uint32_t r_port; uint8_t r_shared_secret[MAX_RAD_SHARED_SECRET_LEN]; boolean_t r_radius_access; boolean_t r_radius_config_valid; uint32_t r_shared_secret_len; } iscsi_radius_props_t; typedef struct _IPAddress { union { struct in_addr in4; struct in6_addr in6; } i_addr; /* i_insize determines which is valid in the union above */ int i_insize; } iscsi_ipaddr_t; typedef struct _iSCSITargetAddressKey { iscsi_ipaddr_t a_addr; uint32_t a_port, a_oid; } iscsi_addr_t; typedef struct _iSCSITargetAddressKeyProperties { uint32_t al_vers, /* In */ al_oid; /* In */ uint32_t al_in_cnt; /* In */ uint32_t al_out_cnt; /* Out */ uint32_t al_tpgt; /* Out */ iscsi_addr_t al_addrs[1]; /* Out */ } iscsi_addr_list_t; typedef struct _iSCSITargetProperties { uint32_t p_vers, /* In */ p_oid; /* In */ uchar_t p_name[ISCSI_MAX_NAME_LEN]; /* Out */ uint_t p_name_len; /* Out */ uchar_t p_alias[ISCSI_MAX_NAME_LEN]; /* Out */ uint_t p_alias_len; /* Out */ iSCSIDiscoveryMethod_t p_discovery; /* Out */ boolean_t p_connected; /* Out */ uint32_t p_num_of_connections; /* Out */ /* ---- If connected == B_TRUE then lastErr has no meaning. ---- */ iscsi_error_t p_last_err; /* Out */ /* * Target portal group tag = -1 value means default. */ int p_tpgt_conf; /* Out */ int p_tpgt_nego; /* Out */ uchar_t p_isid[ISCSI_ISID_LEN]; /* Out */ uchar_t p_reserved[128]; } iscsi_property_t; typedef struct _iSCSITargetDeviceList { uint32_t tl_vers, /* In */ tl_in_cnt, /* In */ tl_tgt_list_type, /* In */ tl_out_cnt, /* Out */ tl_oid_list[1]; /* Out */ } iscsi_target_list_t; typedef struct _iSCSIStaticTargetProperties { uint32_t p_vers, /* In */ p_oid; /* In */ uchar_t p_name[ISCSI_MAX_NAME_LEN]; /* Out */ uint_t p_name_len; /* Out */ iscsi_addr_list_t p_addr_list; /* Out */ } iscsi_static_property_t; typedef enum iscsi_lun_status { LunValid, LunDoesNotExist } iscsi_lun_status_t; /* * SCSI inquiry vendor and product identifier buffer length - these values are * defined by the identifier length plus 1 byte for the * null termination. */ #define ISCSI_INQ_VID_BUF_LEN 9 /* 8 byte ID */ #define ISCSI_INQ_PID_BUF_LEN 17 /* 16 byte ID */ typedef struct iscsi_lun_props { uint32_t lp_vers, /* In */ lp_tgt_oid, /* In */ lp_oid, /* In */ lp_num, /* Out */ lp_status; /* Out */ char lp_pathname[MAXPATHLEN], /* Out */ lp_vid[ISCSI_INQ_VID_BUF_LEN], /* Out */ lp_pid[ISCSI_INQ_PID_BUF_LEN]; /* Out */ time_t lp_time_online; /* Out */ } iscsi_lun_props_t; typedef struct iscsi_if_lun { uint32_t l_tgt_oid, l_oid, l_num; } iscsi_if_lun_t; typedef struct iscsi_lun_list { uint32_t ll_vers; /* In */ boolean_t ll_all_tgts; /* In */ uint32_t ll_tgt_oid, /* In */ ll_in_cnt, /* In */ ll_out_cnt; /* Out */ iscsi_if_lun_t ll_luns[1]; /* Out */ } iscsi_lun_list_t; typedef struct iscsi_conn_props { uint32_t cp_vers, /* In */ cp_oid, /* In */ cp_cid, /* In */ cp_sess_oid; /* In */ union { struct sockaddr_in soa4; struct sockaddr_in6 soa6; } cp_local; /* Out */ union { struct sockaddr_in soa4; struct sockaddr_in6 soa6; } cp_peer; /* Out */ iscsi_login_params_t cp_params; boolean_t cp_params_valid; } iscsi_conn_props_t; typedef struct iscsi_if_conn { uint32_t c_sess_oid, c_oid, c_cid; } iscsi_if_conn_t; typedef struct iscsi_conn_list { uint32_t cl_vers; /* In */ boolean_t cl_all_sess; /* In */ uint32_t cl_sess_oid, /* In */ cl_in_cnt, /* In */ cl_out_cnt; /* Out */ iscsi_if_conn_t cl_list[1]; /* Out */ } iscsi_conn_list_t; typedef enum iSNSDiscoveryMethod { iSNSDiscoveryMethodStatic = 0, iSNSDiscoveryMethodDHCP = 1, iSNSDiscoveryMethodSLP = 2 } isns_method_t; typedef struct iSCSIDiscoveryProperties { uint32_t vers; boolean_t iSNSDiscoverySettable; boolean_t iSNSDiscoveryEnabled; isns_method_t iSNSDiscoveryMethod; unsigned char iSNSDomainName[256]; boolean_t SLPDiscoverySettable; boolean_t SLPDiscoveryEnabled; boolean_t StaticDiscoverySettable; boolean_t StaticDiscoveryEnabled; boolean_t SendTargetsDiscoverySettable; boolean_t SendTargetsDiscoveryEnabled; } iSCSIDiscoveryProperties_t; typedef struct iscsi_uscsi { uint32_t iu_vers; uint32_t iu_oid; int iu_tpgt; uint32_t iu_len; uint32_t iu_lun; struct uscsi_cmd iu_ucmd; } iscsi_uscsi_t; #if defined(_SYSCALL32) typedef struct iscsi_uscsi32 { uint32_t iu_vers; uint32_t iu_oid; int iu_tpgt; uint32_t iu_len; uint32_t iu_lun; struct uscsi_cmd32 iu_ucmd; } iscsi_uscsi32_t; #endif /* _SYSCALL32 */ typedef struct iscsi_sendtgts_entry { /* ---- Node name, NULL terminated UTF-8 string ---- */ uchar_t ste_name[ISCSI_MAX_NAME_LEN]; iscsi_addr_t ste_ipaddr; int ste_tpgt; } iscsi_sendtgts_entry_t; typedef struct iscsi_sendtgts_list { entry_t stl_entry; /* In */ uint32_t stl_in_cnt, /* In */ stl_out_cnt; /* Out */ iscsi_sendtgts_entry_t stl_list[1]; /* Out */ } iscsi_sendtgts_list_t; typedef struct iscsi_statictgt_entry { entry_t te_entry; /* In */ uchar_t te_name[ISCSI_MAX_NAME_LEN]; /* In */ } iscsi_target_entry_t; /* iSNS Draft - section 4.1.1. */ typedef struct isns_portal_group { uint8_t pg_iscsi_name[ISCSI_MAX_NAME_LEN]; union { in_addr_t u_ip4; in6_addr_t u_ip6; } pg_ip_addr; int insize; in_port_t pg_port; uint16_t pg_tag; iscsi_ipaddr_t isns_server_ip; uint32_t isns_server_port; } isns_portal_group_t; typedef struct isns_portal_group_list { uint32_t pg_in_cnt, pg_out_cnt; isns_portal_group_t pg_list[1]; } isns_portal_group_list_t; typedef struct isns_server_portal_group_list { iscsi_addr_t addr; isns_portal_group_list_t addr_port_list; } isns_server_portal_group_list_t; #define ISCSI_MIN_CONFIG_SESSIONS 1 /* lowered max config sessions due to ct_power_cnt >= 0 assert */ #define ISCSI_MAX_CONFIG_SESSIONS 4 typedef struct iscsi_config_sess { uint32_t ics_ver; uint32_t ics_oid; boolean_t ics_bound; uint_t ics_in; uint_t ics_out; iscsi_ipaddr_t ics_bindings[1]; } iscsi_config_sess_t; #define ISCSI_SESSION_CONFIG_SIZE(SIZE) \ (sizeof (iscsi_config_sess_t) + \ ((SIZE - 1) * sizeof (iscsi_ipaddr_t))) /* * Event class and subclass information */ #define EC_ISCSI "EC_iSCSI" #define ESC_ISCSI_STATIC_START "ESC_static_start" #define ESC_ISCSI_STATIC_END "ESC_static_end" #define ESC_ISCSI_SEND_TARGETS_START "ESC_send_targets_start" #define ESC_ISCSI_SEND_TARGETS_END "ESC_send_targets_end" #define ESC_ISCSI_SLP_START "ESC_slp_start" #define ESC_ISCSI_SLP_END "ESC_slp_end" #define ESC_ISCSI_ISNS_START "ESC_isns_start" #define ESC_ISCSI_ISNS_END "ESC_isns_end" #define ESC_ISCSI_PROP_CHANGE "ESC_prop_change" #ifdef _KERNEL /* ---- iscsi_utils.c ---- */ extern int iscsid_open(char *, int, int); extern int iscsid_close(int); extern int iscsid_remove(char *filename); extern int iscsid_rename(char *oldname, char *newname); extern ssize_t iscsid_write(int, void *, ssize_t); extern ssize_t iscsid_read(int, void *, ssize_t); extern ssize_t iscsid_sendto(struct sonode *, void *, size_t, struct sockaddr *, socklen_t); extern ssize_t iscsid_recvfrom(struct sonode *, void *buffer, size_t len); extern int iscsid_errno; #endif /* * Function prototypes for those routines found in the common code */ /* ---- utils.c ---- */ extern boolean_t utils_iqn_create(char *, int); extern char *prt_bitmap(int, char *, char *, int); extern char *utils_map_param(int); extern boolean_t parse_addr_port_tpgt(char *in, char **addr, int *type, char **port, char **tpgt); #ifdef __cplusplus } #endif #endif /* _ISCSI_IF_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. */ #ifndef _ISCSIT_COMMON_H_ #define _ISCSIT_COMMON_H_ #ifdef _KERNEL #include #else #include #endif #ifdef __cplusplus extern "C" { #endif #define ISCSIT_API_VERS0 0 #define ISCSIT_MODNAME "iscsit" #define ISCSIT_NODE "/devices/pseudo/iscsit@0:iscsit" typedef enum { ITCFG_SUCCESS = 0, ITCFG_INVALID, ITCFG_TGT_CREATE_ERR, ITCFG_MISC_ERR } it_cfg_status_t; /* * This structure is passed back to the driver during ISCSIT_IOC_ENABLE_SVC * in order to provide the fully qualified hostname for use as the EID * by iSNS. */ #define ISCSIT_MAX_HOSTNAME_LEN 256 typedef struct iscsit_hostinfo_s { uint32_t length; char fqhn[ISCSIT_MAX_HOSTNAME_LEN]; } iscsit_hostinfo_t; #define ISCSIT_IOC_SET_CONFIG 1 #define ISCSIT_IOC_GET_STATE 2 #define ISCSIT_IOC_ENABLE_SVC 101 #define ISCSIT_IOC_DISABLE_SVC 102 /* XXX Rationalize these with other error values (used in it_smf.c */ #define ITADM_SUCCESS 0 #define ITADM_FATAL_ERROR 0x1 #define ITADM_NO_MEM 0x2 #define ITADM_INVALID 0x4 #define ITADM_NODATA 0x8 #define ITADM_PERM 0x10 #define PROP_AUTH "auth" #define PROP_ALIAS "alias" #define PROP_CHAP_USER "chapuser" #define PROP_CHAP_SECRET "chapsecret" #define PROP_TARGET_CHAP_USER "targetchapuser" #define PROP_TARGET_CHAP_SECRET "targetchapsecret" #define PROP_RADIUS_SERVER "radiusserver" #define PROP_RADIUS_SECRET "radiussecret" #define PROP_ISNS_ENABLED "isns" #define PROP_ISNS_SERVER "isnsserver" #define PROP_OLD_TARGET_NAME "oldtargetname" #define PA_AUTH_RADIUS "radius" #define PA_AUTH_CHAP "chap" #define PA_AUTH_NONE "none" typedef struct { int set_cfg_vers; int set_cfg_pnvlist_len; caddr_t set_cfg_pnvlist; } iscsit_ioc_set_config_t; typedef struct { int getst_vers; int getst_pnvlist_len; char *getst_pnvlist; } iscsit_ioc_getstate_t; #ifdef _SYSCALL32 typedef struct { int set_cfg_vers; int set_cfg_pnvlist_len; caddr32_t set_cfg_pnvlist; } iscsit_ioc_set_config32_t; typedef struct { int getst_vers; int getst_pnvlist_len; caddr32_t getst_pnvlist; } iscsit_ioc_getstate32_t; #endif /* _SYSCALL32 */ /* Shared user/kernel structures */ /* Maximum size of a Target Portal Group name */ #define MAX_TPG_NAMELEN 256 /* XXX */ /* Maximum size of an iSCSI Target Node name */ #define MAX_ISCSI_NODENAMELEN 256 /* XXX */ /* * A target portal group tag is a binding between a target and a target * portal group along with a numerical value associated with that binding. * The numerical identifier is used as the 'target portal group tag' defined * in RFC3720. * * tpgt_tpg_name The name of the target portal group associated with * this target portal group tag. * tpgt_generation Generation number which is incremented each time the * structure changes. * tpgt_next Next target portal group tag in th list of target portal * group tags. If tpgt_next is NUL, then this is the last * target portal group in the list. * tpgt_tag A numerical identifier that uniquely identifies a * target portal group within the associated target node. */ typedef struct it_tpgt_s { char tpgt_tpg_name[MAX_TPG_NAMELEN]; uint64_t tpgt_generation; struct it_tpgt_s *tpgt_next; uint16_t tpgt_tag; } it_tpgt_t; /* * An iSCSI target node is represented by an it_tgt_structure. Each * target node includes a list of associated target portal group tags * and a list of properties. * * tgt_name The iSCSI target node name in either IQN or EUI * format (see RFC3720). * tgt_generation Generation number which is incremented each time * the structure changes. * tgt_next Next target in the list of targets. If tgt_next * is NULL, then this is the last target in the list. * tgt_tpgt_list A linked list representing the current target * portal group tags associated with this target. * tgt_tpgt_count The number of currently defined target portal * group tags. * tgt_properties An nvlist representation of the properties * associated with this target. This list can be * manipulated using libnvpair(3lib), and should be * validated and stored using it_tgt_setprop(). * * Target nvlist Properties: * * nvlist Key Type Valid Values * -------------------------------------------------------------------- * targetchapuser string any string or "none" to remove * targetchapsecret string string of at least 12 characters * but not more than 255 characters. * secret will be base64 encoded when * stored. * alias string any string or "none" to remove * auth string "radius", "chap", or "none" * */ typedef struct it_tgt_s { char tgt_name[MAX_ISCSI_NODENAMELEN]; uint64_t tgt_generation; struct it_tgt_s *tgt_next; it_tpgt_t *tgt_tpgt_list; uint32_t tgt_tpgt_count; nvlist_t *tgt_properties; } it_tgt_t; /* * A target portal is represented by an IP address and a listening * TCP port. * * portal_addr sockaddr_storage structure representing the * IPv4 or IPv6 address and TCP port associated * with the portal. * portal_next Next portal in the list of portals. If * portal_next is NULL, this is the last portal * in the list. */ typedef struct it_portal_s { struct sockaddr_storage portal_addr; struct it_portal_s *portal_next; } it_portal_t; /* * A portal is an IP address and TCP port and a portal group is a set * of portals. Each defined portal belongs to exactly one portal group. * Applications can associate a target portal group with a particular * target using a target portal group name. Initiators can only connect * to targets through the portals associated with the target's target * portal group tags. * * tpg_name Identifier for the target portal group. * tpg_generation Generation number which is incremented each * time this structure changes. * tpg_next Next target portal group in the list of target * portal groups. If tpg_next is NULL, this is the * last target portal group in the list. * tpg_portal_count Number of it_portal_t structures in the list. * tpg_portal_list Linked list of it_portal_t structures. */ typedef struct it_tpg_s { char tpg_name[MAX_TPG_NAMELEN]; uint64_t tpg_generation; struct it_tpg_s *tpg_next; uint32_t tpg_portal_count; it_portal_t *tpg_portal_list; } it_tpg_t; /* * A context representing a remote iSCSI initiator node. The purpose * of this structure is to maintain information specific to a remote * initiator such as the CHAP username and CHAP secret. * * ini_name the iSCSI node name of the remote initiator. * ini_generation Generation number which is incremented each * time this structure changes. * ini_next Next initiator in the list of initiators. * If ini_next is NULL, this is the last initiator * in the list. * ini_properties Name/Value list containing the properties * associated with the initiator context. This list * can be manipulated using libnvpair(3lib), and should * be validated and stored using it_ini_setprop(). * * Initiator nvlist Properties: * * nvlist Key Type Valid Values * -------------------------------------------------------------------- * chapuser string any string * chapsecret string string of at least 12 characters * but not more than 255 characters. * secret will be base64 encoded when * stored. */ typedef struct it_ini_s { char ini_name[MAX_ISCSI_NODENAMELEN]; uint64_t ini_generation; struct it_ini_s *ini_next; nvlist_t *ini_properties; } it_ini_t; /* * This structure represents a complete configuration for the iscsit * port provider. In addition to the global configuration, it_config_t * includes lists of child objects including targets, target portal * groups and initiator contexts. Each object includes a "generation" * value which is used by the iscsit kernel driver to identify changes * from one configuration update to the next. * * stmf_token A uint64_t that contains the value returned from a * successful call to stmfGetProviderDataProt(3STMF). * This token is used to verify that the configuration * data persistently stored in COMSTAR has not been * modified since this version was loaded. * config_version Version number for this configuration structure * config_tgt_list Linked list of target contexts representing the * currently defined targets. Applications can add * targets to or remove targets from this list using * the it_tgt_create and it_tgt_delete functions. * config_tgt_count The number of currently defined targets. * config_tpg_list Linked list of target portal group contexts. * Applications can add or remove target portal groups * to/from this list using the it_tpg_create and * it_tpg_delete functions. * config_tpg_count The number of currently defined target portal groups * config_ini_list Linked list of initiator contexts. Applications * can add initiator contexts or remove initiator * contexts from this list using the it_ini_create * and it_ini_delete functions. * config_ini_count The number of currently defined initiator contexts. * config_global_properties * Name/Value list representing the current global * property settings. This list can be manipulated * using libnvpair(3lib), and should be validated * and stored using it_config_setprop(). * config_isns_svr_list * Linked list of currently defined iSNS servers. * Applications can add or remove iSNS servers by * using the it_config_setprop() function and changing * the array of iSNS servers stored in the "isnsserver" * property. * config_isns_svr_count * The number of currently defined iSNS servers. * * Global nvlist Properties: * * nvlist Key Type Valid Values * -------------------------------------------------------------------- * alias string any string * auth string "radius", "chap", or "none" * isns boolean B_TRUE, B_FALSE * isnsserver string array Array of portal specifications of * the form IPaddress:port. Port * is optional; if not specified, the * default iSNS port number of 3205 will * be used. IPv6 addresses should * be enclosed in square brackets '[' ']'. * If "none" is specified, all defined * iSNS servers will be removed from the * configuration. * radiusserver string IPaddress:port specification as * described for 'isnsserver'. * radiussecret string string of at least 12 characters * but not more than 255 characters. * secret will be base64 encoded when * stored. */ typedef struct it_config_s { uint64_t stmf_token; uint32_t config_version; it_tgt_t *config_tgt_list; uint32_t config_tgt_count; it_tpg_t *config_tpg_list; uint32_t config_tpg_count; it_ini_t *config_ini_list; uint32_t config_ini_count; it_portal_t *config_isns_svr_list; uint32_t config_isns_svr_count; nvlist_t *config_global_properties; } it_config_t; /* Functions to convert iSCSI target structures to/from nvlists. */ int it_config_to_nv(it_config_t *cfg, nvlist_t **nvl); /* * nvlist version of config is 3 list-of-list, + 1 proplist. arrays * are interesting, but lists-of-lists are more useful when doing * individual lookups when we later add support for it. Also, no * need to store name in individual struct representation. */ int it_nv_to_config(nvlist_t *nvl, it_config_t **cfg); int it_nv_to_tgtlist(nvlist_t *nvl, uint32_t *count, it_tgt_t **tgtlist); int it_tgtlist_to_nv(it_tgt_t *tgtlist, nvlist_t **nvl); int it_tgt_to_nv(it_tgt_t *tgt, nvlist_t **nvl); int it_nv_to_tgt(nvlist_t *nvl, char *name, it_tgt_t **tgt); int it_tpgt_to_nv(it_tpgt_t *tpgt, nvlist_t **nvl); int it_nv_to_tpgt(nvlist_t *nvl, char *name, it_tpgt_t **tpgt); int it_tpgtlist_to_nv(it_tpgt_t *tpgtlist, nvlist_t **nvl); int it_nv_to_tpgtlist(nvlist_t *nvl, uint32_t *count, it_tpgt_t **tpgtlist); int it_tpg_to_nv(it_tpg_t *tpg, nvlist_t **nvl); int it_nv_to_tpg(nvlist_t *nvl, char *name, it_tpg_t **tpg); int it_tpglist_to_nv(it_tpg_t *tpglist, nvlist_t **nvl); int it_nv_to_tpglist(nvlist_t *nvl, uint32_t *count, it_tpg_t **tpglist); int it_ini_to_nv(it_ini_t *ini, nvlist_t **nvl); int it_nv_to_ini(nvlist_t *nvl, char *name, it_ini_t **ini); int it_inilist_to_nv(it_ini_t *inilist, nvlist_t **nvl); int it_nv_to_inilist(nvlist_t *nvl, uint32_t *count, it_ini_t **inilist); it_tgt_t * it_tgt_lookup(it_config_t *cfg, char *tgt_name); it_tpg_t * it_tpg_lookup(it_config_t *cfg, char *tpg_name); it_portal_t * it_sns_svr_lookup(it_config_t *cfg, struct sockaddr_storage *sa); it_portal_t * it_portal_lookup(it_tpg_t *cfg_tpg, struct sockaddr_storage *sa); int it_sa_compare(struct sockaddr_storage *sa1, struct sockaddr_storage *sa2); /* * Convert a sockaddr to the string representation, suitable for * storing in an nvlist or printing out in a list. */ int sockaddr_to_str(struct sockaddr_storage *sa, char **addr); /* * Convert a char string to a sockaddr structure * * default_port should be the port to be used, if not specified * as part of the supplied string 'arg'. */ struct sockaddr_storage * it_common_convert_sa(char *arg, struct sockaddr_storage *buf, uint32_t default_port); /* * Convert an string array of IP-addr:port to a portal list */ int it_array_to_portallist(char **arr, uint32_t count, uint32_t default_port, it_portal_t **portallist, uint32_t *list_count); /* * Function: it_config_free_cmn() * * Free any resources associated with the it_config_t structure. * * Parameters: * cfg A C representation of the current iSCSI configuration */ void it_config_free_cmn(it_config_t *cfg); /* * Function: it_tgt_free_cmn() * * Frees an it_tgt_t structure. If tgt_next is not NULL, frees * all structures in the list. */ void it_tgt_free_cmn(it_tgt_t *tgt); /* * Function: it_tpgt_free_cmn() * * Deallocates resources of an it_tpgt_t structure. If tpgt->next * is not NULL, frees all members of the list. */ void it_tpgt_free_cmn(it_tpgt_t *tpgt); /* * Function: it_tpg_free_cmn() * * Deallocates resources associated with an it_tpg_t structure. * If tpg->next is not NULL, frees all members of the list. */ void it_tpg_free_cmn(it_tpg_t *tpg); /* * Function: it_ini_free_cmn() * * Deallocates resources of an it_ini_t structure. If ini->next is * not NULL, frees all members of the list. */ void it_ini_free_cmn(it_ini_t *ini); /* * Function: iscsi_binary_to_base64_str() * * Encodes a byte array into a base64 string. */ int iscsi_binary_to_base64_str(uint8_t *in_buf, int in_buf_len, char *base64_str_buf, int base64_buf_len); /* * Function: iscsi_base64_str_to_binary() * * Decodes a base64 string into a byte array */ int iscsi_base64_str_to_binary(char *hstr, int hstr_len, uint8_t *binary, int binary_buf_len, int *out_len); #ifdef __cplusplus } #endif #endif /* _ISCSIT_COMMON_H_ */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _ISNS_PROTOCOL_H #define _ISNS_PROTOCOL_H #ifdef __cplusplus extern "C" { #endif #include #include #include #define ISNSP_VERSION (0x01) #define ISNS_DEFAULT_SERVER_PORT (3205) #define ISNSP_HEADER_SIZE (12) #define ISNSP_RSP_CODE_SIZE (4) #define ISNSP_MAX_PAYLOAD_SIZE (65532) #define ISNSP_MAX_PDU_SIZE (ISNSP_HEADER_SIZE + \ ISNSP_MAX_PAYLOAD_SIZE) #define ISNS_TLV_ATTR_ID_LEN (4) #define ISNS_TLV_ATTR_LEN_LEN (4) #define MAX_ISNS_MESG_ATTR_ENTRIES (8) #define MAX_ISNS_OPER_ATTR_ENTRIES (32) /* iSNS Entity Protocol, iSNS Draft - section 6.2.2. */ #define ISNS_ENTITY_PROTOCOL_NO (1) #define ISNS_ENTITY_PROTOCOL_ISCSI (2) #define ISNS_ENTITY_PROTOCOL_FCP (3) /* iSNS Function IDs, iSNS Draft - section 4.1.3. */ #define ISNS_DEV_ATTR_REG (0x0001) #define ISNS_DEV_ATTR_QRY (0x0002) #define ISNS_DEV_GET_NEXT (0x0003) #define ISNS_DEV_DEREG (0x0004) #define ISNS_SCN_REG (0x0005) #define ISNS_SCN_DEREG (0x0006) #define ISNS_SCN_EVENT (0x0007) #define ISNS_SCN (0x0008) #define ISNS_DD_REG (0x0009) #define ISNS_DD_DEREG (0x000A) #define ISNS_DDS_REG (0x000B) #define ISNS_DDS_DEREG (0x000C) #define ISNS_ESI (0x000D) #define ISNS_HEARTBEAT (0x000E) #define ISNS_DEV_ATTR_REG_RSP (0x8001) #define ISNS_DEV_ATTR_QRY_RSP (0x8002) #define ISNS_DEV_GET_NEXT_RSP (0x8003) #define ISNS_DEV_DEREG_RSP (0x8004) #define ISNS_SCN_REG_RSP (0x8005) #define ISNS_SCN_DEREG_RSP (0x8006) #define ISNS_SCN_EVENT_RSP (0x8007) #define ISNS_SCN_RSP (0x8008) #define ISNS_DD_REG_RSP (0x8009) #define ISNS_DD_DEREG_RSP (0x800A) #define ISNS_DDS_REG_RSP (0x800B) #define ISNS_DDS_DEREG_RSP (0x800C) #define ISNS_ESI_RSP (0x800D) /* iSNS Flags, iSNS Draft - section 5.1.4. */ #define ISNS_FLAG_FIRST_PDU (0x0400) #define ISNS_FLAG_LAST_PDU (0x0800) #define ISNS_FLAG_REPLACE_REG (0x1000) #define ISNS_FLAG_AUTH_BLK_PRESENTED (0x2000) #define ISNS_FLAG_SERVER (0x4000) #define ISNS_FLAG_CLIENT (0x8000) /* iSNS Response Status, iSNS Draft - section 5.4 */ #define ISNS_RSP_SUCCESSFUL (0) #define ISNS_RSP_UNKNOWN_ERROR (1) #define ISNS_RSP_MSG_FORMAT_ERROR (2) #define ISNS_RSP_INVALID_REGIS (3) #define ISNS_RSP_INVALID_QRY (5) #define ISNS_RSP_SRC_UNKNOWN (6) #define ISNS_RSP_SRC_ABSENT (7) #define ISNS_RSP_SRC_UNAUTHORIZED (8) #define ISNS_RSP_NO_SUCH_ENTRY (9) #define ISNS_RSP_VER_NOT_SUPPORTED (10) #define ISNS_RSP_INTERNAL_ERROR (11) #define ISNS_RSP_BUSY (12) #define ISNS_RSP_OPTION_NOT_UNDERSTOOD (13) #define ISNS_RSP_INVALID_UPDATE (14) #define ISNS_RSP_MSG_NOT_SUPPORTED (15) #define ISNS_RSP_SCN_EVENT_REJECTED (16) #define ISNS_RSP_SCN_REGIS_REJECTED (17) #define ISNS_RSP_ATTR_NOT_IMPL (18) #define ISNS_RSP_ESI_NOT_AVAILABLE (21) #define ISNS_RSP_INVALID_DEREGIS (22) #define ISNS_RSP_REGIS_NOT_SUPPORTED (23) /* iSNS Attribute IDs, iSNS Draft - section 6.1. */ #define ISNS_DELIMITER_ATTR_ID (0) #define ISNS_EID_ATTR_ID (1) #define ISNS_ENTITY_PROTOCOL_ATTR_ID (2) #define ISNS_MGMT_IP_ADDR_ATTR_ID (3) #define ISNS_TIMESTAMP_ATTR_ID (4) #define ISNS_VERSION_RANGE_ATTR_ID (5) #define ISNS_ENTITY_REG_PERIOD_ATTR_ID (6) #define ISNS_ENTITY_INDEX_ATTR_ID (7) #define ISNS_ENTITY_NEXT_INDEX_ATTR_ID (8) #define ISNS_ENTITY_ISAKMP_P1_ATTR_ID (11) #define ISNS_ENTITY_CERT_ATTR_ID (12) #define ISNS_PORTAL_IP_ADDR_ATTR_ID (16) #define ISNS_PORTAL_PORT_ATTR_ID (17) #define ISNS_PORTAL_NAME_ATTR_ID (18) #define ISNS_ESI_INTERVAL_ATTR_ID (19) #define ISNS_ESI_PORT_ATTR_ID (20) #define ISNS_PORTAL_INDEX_ATTR_ID (22) #define ISNS_SCN_PORT_ATTR_ID (23) #define ISNS_PORTAL_NEXT_INDEX_ATTR_ID (24) #define ISNS_PORTAL_SEC_BMP_ATTR_ID (27) #define ISNS_PORTAL_ISAKMP_P1_ATTR_ID (28) #define ISNS_PORTAL_ISAKMP_P2_ATTR_ID (29) #define ISNS_PORTAL_CERT_ATTR_ID (31) #define ISNS_ISCSI_NAME_ATTR_ID (32) #define ISNS_ISCSI_NODE_TYPE_ATTR_ID (33) #define ISNS_ISCSI_ALIAS_ATTR_ID (34) #define ISNS_ISCSI_SCN_BITMAP_ATTR_ID (35) #define ISNS_ISCSI_NODE_INDEX_ATTR_ID (36) #define ISNS_WWNN_TOKEN_ATTR_ID (37) #define ISNS_NODE_NEXT_INDEX_ATTR_ID (38) #define ISNS_ISCSI_AUTH_METHOD_ATTR_ID (42) #define ISNS_PG_ISCSI_NAME_ATTR_ID (48) #define ISNS_PG_PORTAL_IP_ADDR_ATTR_ID (49) #define ISNS_PG_PORTAL_PORT_ATTR_ID (50) #define ISNS_PG_TAG_ATTR_ID (51) #define ISNS_PG_INDEX_ATTR_ID (52) #define ISNS_PG_NEXT_ID_ATTR_ID (53) #define ISNS_DD_SET_ID_ATTR_ID (2049) #define ISNS_DD_SET_NAME_ATTR_ID (2050) #define ISNS_DD_SET_STATUS_ATTR_ID (2051) #define ISNS_DD_ID_ATTR_ID (2065) #define ISNS_DD_NAME_ATTR_ID (2066) #define ISNS_DD_ISCSI_INDEX_ATTR_ID (2067) #define ISNS_DD_ISCSI_NAME_ATTR_ID (2068) #define ISNS_DD_FC_PORT_NAME_ATTR_ID (2069) #define ISNS_DD_PORTAL_INDEX_ATTR_ID (2070) #define ISNS_DD_PORTAL_IP_ADDR_ATTR_ID (2071) #define ISNS_DD_PORTAL_PORT_ATTR_ID (2072) #define ISNS_DD_FEATURES_ATTR_ID (2078) /* Entity Protocol, RFC 4171 - section 6.2.2. */ #define ISNS_ENTITY_NO_PROTOCOL (1) #define ISNS_ENTITY_ISCSI (2) #define ISNS_ENTITY_IFCP (3) /* Protocol Version Range, RFC 4171 - section 6.2.5. */ #define ISNS_VER_SHIFT (16) #define ISNS_VERSION (0x0000FFFF) /* Portal Port, RFC 4171 - section 6.3.2. */ #define ISNS_PORT_BITS (0x0000FFFF) /* Bits 16 - 31 */ #define ISNS_PORT_TYPE (0x00010000) /* Bit 15 */ /* Portal Security Bitmap, RFC 4171 - section 6.3.9. */ #define ISNS_TUNNEL_MODE_PREFERRED (0x0040) /* Bit 25 */ #define ISNS_TRANS_MODE_PREFERRED (0x0020) /* Bit 26 */ #define ISNS_PFS_ENABLED (0x0010) /* Bit 27 */ #define ISNS_AGGR_MODE_ENABLED (0x0008) /* Bit 28 */ #define ISNS_MAIN_MODE_ENABLED (0x0004) /* Bit 29 */ #define ISNS_IKE_IPSEC_ENABLED (0x0002) /* Bit 30 */ #define ISNS_BITMAP_VALID (0x0001) /* Bit 31 */ /* iSCSI Node Type, RFC 4171 - section 6.4.2. */ #define ISNS_TARGET_NODE_TYPE (0x0001) #define ISNS_INITIATOR_NODE_TYPE (0x0002) #define ISNS_CONTROL_NODE_TYPE (0x0004) /* iSCSI Node SCN Bitmap, RFC 4171 - section 6.4.4. */ #define ISNS_INIT_SELF_INFO_ONLY (0x0080) /* Bit 24 */ #define ISNS_TARGET_SELF_INFO_ONLY (0x0040) /* Bit 25 */ #define ISNS_MGMT_REG (0x0020) /* Bit 26 */ #define ISNS_OBJECT_REMOVED (0x0010) /* Bit 27 */ #define ISNS_OBJECT_ADDED (0x0008) /* Bit 28 */ #define ISNS_OBJECT_UPDATED (0x0004) /* Bit 29 */ #define ISNS_MEMBER_REMOVED (0x0002) /* Bit 30 */ #define ISNS_MEMBER_ADDED (0x0001) /* Bit 31 */ /* Portal Group Tag, RFC 4171 - section 6.5.4. */ #define ISNS_PG_TAG (0x0000FFFF) /* Bits 16 - 31 */ /* DDS Status, RFC 4171 - section 6.11.1.3. */ #define ISNS_DDS_STATUS (0x0001) /* Bit 31 */ /* DD Feature, RFC 4171 - section 6.11.2.9. */ #define ISNS_DD_BOOTLIST (0x0001) /* Bit 31 */ /* iSNS Defaults */ #define ISNS_DEFAULT_PGT (0x00000001) #define ISNS_DEFAULT_DD_SET_ID (1) #define ISNS_DEFAULT_DD_ID (1) /* Min/Max length of names */ #define ISNS_DDS_MAX_NAME_LEN (256) #define ISNS_DD_MAX_NAME_LEN (256) #define ISNS_ISCSI_MAX_NAME_LEN (224) #define ISNS_ISCSI_MAX_ALIAS_LEN (256) #define ISNS_ENTITY_MIN_EID_LEN (3) #define ISNS_ENTITY_MAX_EID_LEN (255) typedef struct isns_tlv { uint32_t attr_id; uint32_t attr_len; uint8_t attr_value[1]; } isns_tlv_t; typedef struct isns_packet_data { uint16_t version; uint16_t func_id; uint16_t payload_len; uint16_t flags; uint16_t xid; uint16_t seq; int num_of_tlvs; isns_tlv_t tlvs[MAX_ISNS_OPER_ATTR_ENTRIES]; } isns_packet_data_t; typedef struct isns_reg_mesg { isns_tlv_t src_attr; int num_of_mesg_attrs; isns_tlv_t *mesg_attrs[MAX_ISNS_MESG_ATTR_ENTRIES]; isns_tlv_t delimiter_attr; isns_tlv_t *operating_attrs[MAX_ISNS_OPER_ATTR_ENTRIES]; } isns_reg_mesg_t; typedef struct isns_resp_mesg { uint8_t status[4]; isns_tlv_t messages_attrs[MAX_ISNS_MESG_ATTR_ENTRIES]; isns_tlv_t delimiter_attr; isns_tlv_t operating_attrs[MAX_ISNS_OPER_ATTR_ENTRIES]; } isns_resp_mesg_t; typedef struct isns_pdu { uint16_t version; uint16_t func_id; uint16_t payload_len; uint16_t flags; uint16_t xid; uint16_t seq; uint8_t payload[1]; } isns_pdu_t; typedef struct isns_resp { uint32_t status; uint8_t data[1]; } isns_resp_t; #ifdef __cplusplus } #endif #endif /* _ISNS_PROTOCOL_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _RADIUS_PACKET_H #define _RADIUS_PACKET_H #ifdef __cplusplus extern "C" { #endif #include #include #include #include /* A total of RAD_RCV_TIMEOUT * RAD_RETRY_MAX seconds timeout. */ #define RAD_RCV_TIMEOUT 5 /* Timeout for receiving RADIUS packet in */ /* sec. */ #define RAD_RETRY_MAX 2 /* Max. # of times to retry receiving */ /* packet. */ /* Describes a RADIUS attribute */ typedef struct radius_attr { int attr_type_code; /* RADIUS attribute type code, */ /* e.g. RAD_USER_PASSWORD, etc. */ int attr_value_len; uint8_t attr_value[MAX_RAD_ATTR_VALUE_LEN]; } radius_attr_t; /* Describes data fields of a RADIUS packet. */ typedef struct radius_packet_data { uint8_t code; /* RADIUS code, section 3, RFC 2865. */ uint8_t identifier; uint8_t authenticator[RAD_AUTHENTICATOR_LEN]; int num_of_attrs; radius_attr_t attrs[4]; /* For this implementation each */ /* outbound RADIUS packet will only */ /* have 3 attributes associated with */ /* it thus the chosen size should be */ /* good enough. */ } radius_packet_data_t; /* * Send a request to a RADIUS server. * * Returns > 0 on success, <= 0 on failure . * */ int iscsit_snd_radius_request(ksocket_t socket, iscsi_ipaddr_t rsvr_ip_addr, uint32_t rsvr_port, radius_packet_data_t *packet_data); #define RAD_RSP_RCVD_SUCCESS 0 #define RAD_RSP_RCVD_NO_DATA 1 #define RAD_RSP_RCVD_TIMEOUT 2 #define RAD_RSP_RCVD_PROTOCOL_ERR 3 #define RAD_RSP_RCVD_AUTH_FAILED 4 /* * Receives a response from a RADIUS server. * * Return receive status. */ int iscsit_rcv_radius_response(ksocket_t socket, uint8_t *shared_secret, uint32_t shared_secret_len, uint8_t *req_authenticator, radius_packet_data_t *resp_data); #ifdef __cplusplus } #endif #endif /* _RADIUS_PACKET_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _RADIUS_PROTOCOL_H #define _RADIUS_PROTOCOL_H #ifdef __cplusplus extern "C" { #endif /* Packet type. RFC 2865 section 4. */ #define RAD_ACCESS_REQ 1 /* Authentication Request */ #define RAD_ACCESS_ACPT 2 /* Authentication Accepted */ #define RAD_ACCESS_REJ 3 /* Authentication Rejected */ /* RADIUS Attribute Types. RFC 2865 section 5. */ #define RAD_USER_NAME 1 #define RAD_CHAP_PASSWORD 3 #define RAD_CHAP_CHALLENGE 60 /* RFC 2865 Section 3. The Identifier field is one octet. */ #define RAD_IDENTIFIER_LEN 1 /* RFC 2865 Section 5.3. The String field is 16 octets. */ #define RAD_CHAP_PASSWD_STR_LEN 16 /* RFC 2865 Section 3. Authenticator field is 16 octets. */ #define RAD_AUTHENTICATOR_LEN 16 /* RFC 2865 Section 5: 1-253 octets */ #define MAX_RAD_ATTR_VALUE_LEN 253 /* RFC 2865 Section 3. Minimum length 20 octets. */ #define MIN_RAD_PACKET_LEN 20 /* RFC 2865 Section 3. Maximum length 4096 octets. */ #define MAX_RAD_PACKET_LEN 4096 /* Maximum RADIUS shared secret length (in fact there is no defined limit) */ #define MAX_RAD_SHARED_SECRET_LEN 128 /* RFC 2865 Section 3. Minimum RADIUS shared secret length */ #define MIN_RAD_SHARED_SECRET_LEN 16 /* Raw RADIUS packet. RFC 2865 section 3. */ typedef struct radius_packet { uint8_t code; /* RADIUS code, section 3, RFC 2865 */ uint8_t identifier; /* 1 octet in length. RFC 2865 section 3 */ uint8_t length[2]; /* 2 octets, or sizeof (u_short) */ uint8_t authenticator[RAD_AUTHENTICATOR_LEN]; uint8_t data[1]; } radius_packet_t; /* Length of a RADIUS packet minus the payload */ #define RAD_PACKET_HDR_LEN 20 #ifdef __cplusplus } #endif #endif /* _RADIUS_PROTOCOL_H */