1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 /* 27 * Structures and type definitions for the SMB module. 28 */ 29 30 #ifndef _SMBSRV_SMB_SVC_SM_H 31 #define _SMBSRV_SMB_SVC_SM_H 32 33 #pragma ident "@(#)smb_svc_sm.h 1.1 07/10/25 SMI" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /* 40 * CIFS Service State Machine Definitions 41 */ 42 43 /* 44 * Events 45 * 46 * SMB_SVCEVT_UNDEFINED Invalid Event 47 * SMB_SVCEVT_OPEN Pseudo-device opened 48 * SMB_SVCEVT_CLOSE Pseudo-device closed 49 * SMB_SVCEVT_OPEN_SUCCESS Open actions completed successfully 50 * SMB_SVCEVT_OPEN_FAILED Open actions failed 51 * SMB_SVCEVT_CLOSE_SUCCESS Close actions completed successfully 52 * SMB_SVCEVT_CONNECT Connected and listening on SMB session port 53 * SMB_SVCEVT_DISCONNECT SMB connection dropped or failed to connect 54 * SMB_SVCEVT_CONFIG New config from smbd 55 * SMB_SVCEVT_CONFIG_SUCCESS Configuration updated successfully 56 * SMB_SVCEVT_CONFIG_FAILED Configuration update failed 57 * SMB_SVCEVT_SESSION_CREATE SMB port listener accepted a connection 58 * SMB_SVCEVT_SESSION_DELETE Session ended 59 * SMB_SVCEVT_MAX_EVENT Invalid Event 60 */ 61 62 typedef enum { 63 SMB_SVCEVT_UNDEFINED = 0, 64 SMB_SVCEVT_OPEN, 65 SMB_SVCEVT_CLOSE, 66 SMB_SVCEVT_OPEN_SUCCESS, 67 SMB_SVCEVT_OPEN_FAILED, 68 SMB_SVCEVT_CLOSE_SUCCESS, 69 SMB_SVCEVT_CONNECT, 70 SMB_SVCEVT_DISCONNECT, 71 SMB_SVCEVT_CONFIG, 72 SMB_SVCEVT_CONFIG_SUCCESS, 73 SMB_SVCEVT_CONFIG_FAILED, 74 SMB_SVCEVT_SESSION_CREATE, 75 SMB_SVCEVT_SESSION_DELETE, 76 SMB_SVCEVT_MAX_EVENT 77 } smb_svcevt_t; 78 79 /* 80 * States 81 * 82 * SMB_SVCSTATE_UNDEFINED Invalid state 83 * SMB_SVCSTATE_INIT Pseudo-driver loaded/idle 84 * SMB_SVCSTATE_OPENING Pseudo-driver opened, starting 85 * SMB_SVCSTATE_CONFIG_WAIT Waiting for configuration 86 * SMB_SVCSTATE_CONNECTING Waiting for socket bind to SMB 87 * SMB_SVCSTATE_ONLINE Online, accepting connections 88 * SMB_SVCSTATE_RECONFIGURING Updating config, no new connections 89 * SMB_SVCSTATE_DISCONNECTING Smbd requested shutdown, closing socket 90 * SMB_SVCSTATE_SESSION_CLOSE Shutting down, closing active sessions 91 * SMB_SVCSTATE_CLOSING Shutting down, releasing resources 92 * SMB_SVCSTATE_ERROR_SESSION_CLOSE Unexpected SMB socket error, 93 * closing active sessions 94 * SMB_SVCSTATE_ERROR_CLOSING Error, releasing resources 95 * SMB_SVCSTATE_MAX_STATE Invalid state 96 */ 97 typedef enum { 98 SMB_SVCSTATE_UNDEFINED = 0, 99 SMB_SVCSTATE_INIT, 100 SMB_SVCSTATE_OPENING, 101 SMB_SVCSTATE_CONFIG_WAIT, 102 SMB_SVCSTATE_CONNECTING, 103 SMB_SVCSTATE_ONLINE, 104 SMB_SVCSTATE_RECONFIGURING, 105 SMB_SVCSTATE_DISCONNECTING, 106 SMB_SVCSTATE_SESSION_CLOSE, 107 SMB_SVCSTATE_ERROR_SESSION_CLOSE, 108 SMB_SVCSTATE_CLOSING, 109 SMB_SVCSTATE_ERROR_CLOSING, 110 SMB_SVCSTATE_ERROR, 111 SMB_SVCSTATE_MAX_STATE 112 } smb_svcstate_t; 113 114 #ifdef _KERNEL 115 /* Event context */ 116 typedef struct { 117 smb_svcevt_t sec_event; 118 uintptr_t sec_info; 119 } smb_event_ctx_t; 120 121 /* Service state machine context */ 122 typedef struct { 123 taskq_t *ssc_taskq; 124 krwlock_t ssc_state_rwlock; 125 kmutex_t ssc_state_cv_mutex; 126 kcondvar_t ssc_state_cv; 127 int ssc_started; 128 int ssc_start_error; 129 int ssc_disconnect_error; 130 smb_svcstate_t ssc_state; 131 smb_svcstate_t ssc_last_state; /* Debug only */ 132 int ssc_session_creates_waiting; 133 int ssc_deferred_session_count; 134 list_t ssc_deferred_sessions; 135 int ssc_active_session_count; 136 list_t ssc_active_sessions; 137 uint32_t ssc_error_no_resources; 138 } smb_svc_sm_ctx_t; 139 140 /* 141 * SMB service state machine API 142 */ 143 144 extern int smb_svcstate_sm_init(smb_svc_sm_ctx_t *svc_sm); 145 extern void smb_svcstate_sm_fini(smb_svc_sm_ctx_t *svc_sm); 146 extern int smb_svcstate_sm_start(smb_svc_sm_ctx_t *svc_sm); 147 extern void smb_svcstate_sm_stop(smb_svc_sm_ctx_t *svc_sm); 148 extern boolean_t smb_svcstate_sm_busy(void); 149 extern void smb_svcstate_event(smb_svcevt_t event, uintptr_t event_info); 150 extern void smb_svcstate_lock_read(smb_svc_sm_ctx_t *svc_sm); 151 extern void smb_svcstate_unlock(smb_svc_sm_ctx_t *svc_sm); 152 extern smb_session_t *smb_svcstate_session_getnext(smb_svc_sm_ctx_t *svc_sm, 153 smb_session_t *prev); 154 extern int smb_svcstate_session_count(smb_svc_sm_ctx_t *svc_sm); 155 156 #endif /* _KERNEL */ 157 158 #ifdef __cplusplus 159 } 160 #endif 161 162 #endif /* _SMBSRV_SMB_SVC_SM_H */ 163