Commit | Line | Data |
---|---|---|
0626e664 NJ |
1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | /* | |
3 | * Copyright (C) 2018 Samsung Electronics Co., Ltd. | |
4 | */ | |
5 | ||
6 | #ifndef __KSMBD_CONNECTION_H__ | |
7 | #define __KSMBD_CONNECTION_H__ | |
8 | ||
9 | #include <linux/list.h> | |
10 | #include <linux/ip.h> | |
11 | #include <net/sock.h> | |
12 | #include <net/tcp.h> | |
13 | #include <net/inet_connection_sock.h> | |
14 | #include <net/request_sock.h> | |
15 | #include <linux/kthread.h> | |
16 | #include <linux/nls.h> | |
dbab80e2 | 17 | #include <linux/unicode.h> |
0626e664 NJ |
18 | |
19 | #include "smb_common.h" | |
20 | #include "ksmbd_work.h" | |
21 | ||
22 | #define KSMBD_SOCKET_BACKLOG 16 | |
23 | ||
0626e664 NJ |
24 | enum { |
25 | KSMBD_SESS_NEW = 0, | |
26 | KSMBD_SESS_GOOD, | |
27 | KSMBD_SESS_EXITING, | |
28 | KSMBD_SESS_NEED_RECONNECT, | |
29 | KSMBD_SESS_NEED_NEGOTIATE | |
30 | }; | |
31 | ||
32 | struct ksmbd_stats { | |
33 | atomic_t open_files_count; | |
34 | atomic64_t request_served; | |
35 | }; | |
36 | ||
37 | struct ksmbd_transport; | |
38 | ||
39 | struct ksmbd_conn { | |
40 | struct smb_version_values *vals; | |
41 | struct smb_version_ops *ops; | |
42 | struct smb_version_cmds *cmds; | |
43 | unsigned int max_cmds; | |
44 | struct mutex srv_mutex; | |
45 | int status; | |
46 | unsigned int cli_cap; | |
47 | char *request_buf; | |
48 | struct ksmbd_transport *transport; | |
49 | struct nls_table *local_nls; | |
16b5f54e | 50 | struct unicode_map *um; |
0626e664 NJ |
51 | struct list_head conns_list; |
52 | /* smb session 1 per user */ | |
e4d3e6b5 | 53 | struct xarray sessions; |
0626e664 NJ |
54 | unsigned long last_active; |
55 | /* How many request are running currently */ | |
56 | atomic_t req_running; | |
57 | /* References which are made for this Server object*/ | |
58 | atomic_t r_count; | |
b589f5db NJ |
59 | unsigned int total_credits; |
60 | unsigned int outstanding_credits; | |
0626e664 NJ |
61 | spinlock_t credits_lock; |
62 | wait_queue_head_t req_running_q; | |
a14c5738 | 63 | wait_queue_head_t r_count_q; |
0626e664 NJ |
64 | /* Lock to protect requests list*/ |
65 | spinlock_t request_lock; | |
66 | struct list_head requests; | |
67 | struct list_head async_requests; | |
68 | int connection_type; | |
69 | struct ksmbd_stats stats; | |
70 | char ClientGUID[SMB2_CLIENT_GUID_SIZE]; | |
ce53d365 | 71 | struct ntlmssp_auth ntlmssp; |
0626e664 | 72 | |
d63528eb HL |
73 | spinlock_t llist_lock; |
74 | struct list_head lock_list; | |
75 | ||
0626e664 NJ |
76 | struct preauth_integrity_info *preauth_info; |
77 | ||
78 | bool need_neg; | |
79 | unsigned int auth_mechs; | |
80 | unsigned int preferred_auth_mech; | |
81 | bool sign; | |
82 | bool use_spnego:1; | |
83 | __u16 cli_sec_mode; | |
84 | __u16 srv_sec_mode; | |
85 | /* dialect index that server chose */ | |
86 | __u16 dialect; | |
87 | ||
88 | char *mechToken; | |
89 | ||
90 | struct ksmbd_conn_ops *conn_ops; | |
91 | ||
92 | /* Preauth Session Table */ | |
93 | struct list_head preauth_sess_table; | |
94 | ||
95 | struct sockaddr_storage peer_addr; | |
96 | ||
97 | /* Identifier for async message */ | |
d40012a8 | 98 | struct ida async_ida; |
0626e664 NJ |
99 | |
100 | __le16 cipher_type; | |
101 | __le16 compress_algorithm; | |
102 | bool posix_ext_supported; | |
378087cd NJ |
103 | bool signing_negotiated; |
104 | __le16 signing_algorithm; | |
f5a544e3 | 105 | bool binding; |
0626e664 NJ |
106 | }; |
107 | ||
108 | struct ksmbd_conn_ops { | |
109 | int (*process_fn)(struct ksmbd_conn *conn); | |
110 | int (*terminate_fn)(struct ksmbd_conn *conn); | |
111 | }; | |
112 | ||
113 | struct ksmbd_transport_ops { | |
114 | int (*prepare)(struct ksmbd_transport *t); | |
115 | void (*disconnect)(struct ksmbd_transport *t); | |
136dff3a | 116 | void (*shutdown)(struct ksmbd_transport *t); |
be6f42fa NJ |
117 | int (*read)(struct ksmbd_transport *t, char *buf, |
118 | unsigned int size, int max_retries); | |
64b39f4a | 119 | int (*writev)(struct ksmbd_transport *t, struct kvec *iovs, int niov, |
070fb21e NJ |
120 | int size, bool need_invalidate_rkey, |
121 | unsigned int remote_key); | |
1807abcf HL |
122 | int (*rdma_read)(struct ksmbd_transport *t, |
123 | void *buf, unsigned int len, | |
124 | struct smb2_buffer_desc_v1 *desc, | |
125 | unsigned int desc_len); | |
126 | int (*rdma_write)(struct ksmbd_transport *t, | |
127 | void *buf, unsigned int len, | |
128 | struct smb2_buffer_desc_v1 *desc, | |
129 | unsigned int desc_len); | |
0626e664 NJ |
130 | }; |
131 | ||
132 | struct ksmbd_transport { | |
133 | struct ksmbd_conn *conn; | |
134 | struct ksmbd_transport_ops *ops; | |
135 | struct task_struct *handler; | |
136 | }; | |
137 | ||
138 | #define KSMBD_TCP_RECV_TIMEOUT (7 * HZ) | |
139 | #define KSMBD_TCP_SEND_TIMEOUT (5 * HZ) | |
140 | #define KSMBD_TCP_PEER_SOCKADDR(c) ((struct sockaddr *)&((c)->peer_addr)) | |
141 | ||
d63528eb HL |
142 | extern struct list_head conn_list; |
143 | extern rwlock_t conn_list_lock; | |
144 | ||
0626e664 NJ |
145 | bool ksmbd_conn_alive(struct ksmbd_conn *conn); |
146 | void ksmbd_conn_wait_idle(struct ksmbd_conn *conn); | |
0626e664 NJ |
147 | struct ksmbd_conn *ksmbd_conn_alloc(void); |
148 | void ksmbd_conn_free(struct ksmbd_conn *conn); | |
149 | bool ksmbd_conn_lookup_dialect(struct ksmbd_conn *c); | |
150 | int ksmbd_conn_write(struct ksmbd_work *work); | |
1807abcf HL |
151 | int ksmbd_conn_rdma_read(struct ksmbd_conn *conn, |
152 | void *buf, unsigned int buflen, | |
153 | struct smb2_buffer_desc_v1 *desc, | |
154 | unsigned int desc_len); | |
155 | int ksmbd_conn_rdma_write(struct ksmbd_conn *conn, | |
156 | void *buf, unsigned int buflen, | |
157 | struct smb2_buffer_desc_v1 *desc, | |
158 | unsigned int desc_len); | |
0626e664 NJ |
159 | void ksmbd_conn_enqueue_request(struct ksmbd_work *work); |
160 | int ksmbd_conn_try_dequeue_request(struct ksmbd_work *work); | |
161 | void ksmbd_conn_init_server_callbacks(struct ksmbd_conn_ops *ops); | |
0626e664 | 162 | int ksmbd_conn_handler_loop(void *p); |
0626e664 NJ |
163 | int ksmbd_conn_transport_init(void); |
164 | void ksmbd_conn_transport_destroy(void); | |
165 | ||
166 | /* | |
167 | * WARNING | |
168 | * | |
169 | * This is a hack. We will move status to a proper place once we land | |
170 | * a multi-sessions support. | |
171 | */ | |
172 | static inline bool ksmbd_conn_good(struct ksmbd_work *work) | |
173 | { | |
174 | return work->conn->status == KSMBD_SESS_GOOD; | |
175 | } | |
176 | ||
177 | static inline bool ksmbd_conn_need_negotiate(struct ksmbd_work *work) | |
178 | { | |
179 | return work->conn->status == KSMBD_SESS_NEED_NEGOTIATE; | |
180 | } | |
181 | ||
182 | static inline bool ksmbd_conn_need_reconnect(struct ksmbd_work *work) | |
183 | { | |
184 | return work->conn->status == KSMBD_SESS_NEED_RECONNECT; | |
185 | } | |
186 | ||
187 | static inline bool ksmbd_conn_exiting(struct ksmbd_work *work) | |
188 | { | |
189 | return work->conn->status == KSMBD_SESS_EXITING; | |
190 | } | |
191 | ||
192 | static inline void ksmbd_conn_set_good(struct ksmbd_work *work) | |
193 | { | |
194 | work->conn->status = KSMBD_SESS_GOOD; | |
195 | } | |
196 | ||
197 | static inline void ksmbd_conn_set_need_negotiate(struct ksmbd_work *work) | |
198 | { | |
199 | work->conn->status = KSMBD_SESS_NEED_NEGOTIATE; | |
200 | } | |
201 | ||
202 | static inline void ksmbd_conn_set_need_reconnect(struct ksmbd_work *work) | |
203 | { | |
204 | work->conn->status = KSMBD_SESS_NEED_RECONNECT; | |
205 | } | |
206 | ||
207 | static inline void ksmbd_conn_set_exiting(struct ksmbd_work *work) | |
208 | { | |
209 | work->conn->status = KSMBD_SESS_EXITING; | |
210 | } | |
211 | #endif /* __CONNECTION_H__ */ |