0001
0002
0003
0004
0005
0006 #ifndef __KSMBD_CONNECTION_H__
0007 #define __KSMBD_CONNECTION_H__
0008
0009 #include <linux/list.h>
0010 #include <linux/ip.h>
0011 #include <net/sock.h>
0012 #include <net/tcp.h>
0013 #include <net/inet_connection_sock.h>
0014 #include <net/request_sock.h>
0015 #include <linux/kthread.h>
0016 #include <linux/nls.h>
0017
0018 #include "smb_common.h"
0019 #include "ksmbd_work.h"
0020
0021 #define KSMBD_SOCKET_BACKLOG 16
0022
0023 enum {
0024 KSMBD_SESS_NEW = 0,
0025 KSMBD_SESS_GOOD,
0026 KSMBD_SESS_EXITING,
0027 KSMBD_SESS_NEED_RECONNECT,
0028 KSMBD_SESS_NEED_NEGOTIATE
0029 };
0030
0031 struct ksmbd_stats {
0032 atomic_t open_files_count;
0033 atomic64_t request_served;
0034 };
0035
0036 struct ksmbd_transport;
0037
0038 struct ksmbd_conn {
0039 struct smb_version_values *vals;
0040 struct smb_version_ops *ops;
0041 struct smb_version_cmds *cmds;
0042 unsigned int max_cmds;
0043 struct mutex srv_mutex;
0044 int status;
0045 unsigned int cli_cap;
0046 char *request_buf;
0047 struct ksmbd_transport *transport;
0048 struct nls_table *local_nls;
0049 struct list_head conns_list;
0050
0051 struct xarray sessions;
0052 unsigned long last_active;
0053
0054 atomic_t req_running;
0055
0056 atomic_t r_count;
0057 unsigned int total_credits;
0058 unsigned int outstanding_credits;
0059 spinlock_t credits_lock;
0060 wait_queue_head_t req_running_q;
0061 wait_queue_head_t r_count_q;
0062
0063 spinlock_t request_lock;
0064 struct list_head requests;
0065 struct list_head async_requests;
0066 int connection_type;
0067 struct ksmbd_stats stats;
0068 char ClientGUID[SMB2_CLIENT_GUID_SIZE];
0069 struct ntlmssp_auth ntlmssp;
0070
0071 spinlock_t llist_lock;
0072 struct list_head lock_list;
0073
0074 struct preauth_integrity_info *preauth_info;
0075
0076 bool need_neg;
0077 unsigned int auth_mechs;
0078 unsigned int preferred_auth_mech;
0079 bool sign;
0080 bool use_spnego:1;
0081 __u16 cli_sec_mode;
0082 __u16 srv_sec_mode;
0083
0084 __u16 dialect;
0085
0086 char *mechToken;
0087
0088 struct ksmbd_conn_ops *conn_ops;
0089
0090
0091 struct list_head preauth_sess_table;
0092
0093 struct sockaddr_storage peer_addr;
0094
0095
0096 struct ida async_ida;
0097
0098 __le16 cipher_type;
0099 __le16 compress_algorithm;
0100 bool posix_ext_supported;
0101 bool signing_negotiated;
0102 __le16 signing_algorithm;
0103 bool binding;
0104 };
0105
0106 struct ksmbd_conn_ops {
0107 int (*process_fn)(struct ksmbd_conn *conn);
0108 int (*terminate_fn)(struct ksmbd_conn *conn);
0109 };
0110
0111 struct ksmbd_transport_ops {
0112 int (*prepare)(struct ksmbd_transport *t);
0113 void (*disconnect)(struct ksmbd_transport *t);
0114 void (*shutdown)(struct ksmbd_transport *t);
0115 int (*read)(struct ksmbd_transport *t, char *buf, unsigned int size);
0116 int (*writev)(struct ksmbd_transport *t, struct kvec *iovs, int niov,
0117 int size, bool need_invalidate_rkey,
0118 unsigned int remote_key);
0119 int (*rdma_read)(struct ksmbd_transport *t,
0120 void *buf, unsigned int len,
0121 struct smb2_buffer_desc_v1 *desc,
0122 unsigned int desc_len);
0123 int (*rdma_write)(struct ksmbd_transport *t,
0124 void *buf, unsigned int len,
0125 struct smb2_buffer_desc_v1 *desc,
0126 unsigned int desc_len);
0127 };
0128
0129 struct ksmbd_transport {
0130 struct ksmbd_conn *conn;
0131 struct ksmbd_transport_ops *ops;
0132 struct task_struct *handler;
0133 };
0134
0135 #define KSMBD_TCP_RECV_TIMEOUT (7 * HZ)
0136 #define KSMBD_TCP_SEND_TIMEOUT (5 * HZ)
0137 #define KSMBD_TCP_PEER_SOCKADDR(c) ((struct sockaddr *)&((c)->peer_addr))
0138
0139 extern struct list_head conn_list;
0140 extern rwlock_t conn_list_lock;
0141
0142 bool ksmbd_conn_alive(struct ksmbd_conn *conn);
0143 void ksmbd_conn_wait_idle(struct ksmbd_conn *conn);
0144 struct ksmbd_conn *ksmbd_conn_alloc(void);
0145 void ksmbd_conn_free(struct ksmbd_conn *conn);
0146 bool ksmbd_conn_lookup_dialect(struct ksmbd_conn *c);
0147 int ksmbd_conn_write(struct ksmbd_work *work);
0148 int ksmbd_conn_rdma_read(struct ksmbd_conn *conn,
0149 void *buf, unsigned int buflen,
0150 struct smb2_buffer_desc_v1 *desc,
0151 unsigned int desc_len);
0152 int ksmbd_conn_rdma_write(struct ksmbd_conn *conn,
0153 void *buf, unsigned int buflen,
0154 struct smb2_buffer_desc_v1 *desc,
0155 unsigned int desc_len);
0156 void ksmbd_conn_enqueue_request(struct ksmbd_work *work);
0157 int ksmbd_conn_try_dequeue_request(struct ksmbd_work *work);
0158 void ksmbd_conn_init_server_callbacks(struct ksmbd_conn_ops *ops);
0159 int ksmbd_conn_handler_loop(void *p);
0160 int ksmbd_conn_transport_init(void);
0161 void ksmbd_conn_transport_destroy(void);
0162
0163
0164
0165
0166
0167
0168
0169 static inline bool ksmbd_conn_good(struct ksmbd_work *work)
0170 {
0171 return work->conn->status == KSMBD_SESS_GOOD;
0172 }
0173
0174 static inline bool ksmbd_conn_need_negotiate(struct ksmbd_work *work)
0175 {
0176 return work->conn->status == KSMBD_SESS_NEED_NEGOTIATE;
0177 }
0178
0179 static inline bool ksmbd_conn_need_reconnect(struct ksmbd_work *work)
0180 {
0181 return work->conn->status == KSMBD_SESS_NEED_RECONNECT;
0182 }
0183
0184 static inline bool ksmbd_conn_exiting(struct ksmbd_work *work)
0185 {
0186 return work->conn->status == KSMBD_SESS_EXITING;
0187 }
0188
0189 static inline void ksmbd_conn_set_good(struct ksmbd_work *work)
0190 {
0191 work->conn->status = KSMBD_SESS_GOOD;
0192 }
0193
0194 static inline void ksmbd_conn_set_need_negotiate(struct ksmbd_work *work)
0195 {
0196 work->conn->status = KSMBD_SESS_NEED_NEGOTIATE;
0197 }
0198
0199 static inline void ksmbd_conn_set_need_reconnect(struct ksmbd_work *work)
0200 {
0201 work->conn->status = KSMBD_SESS_NEED_RECONNECT;
0202 }
0203
0204 static inline void ksmbd_conn_set_exiting(struct ksmbd_work *work)
0205 {
0206 work->conn->status = KSMBD_SESS_EXITING;
0207 }
0208 #endif