1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12/*
13 * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
14 * Copyright 2020 RackTop Systems, Inc.
15 */
16
17#ifndef _SMB2_KPROTO_H_
18#define	_SMB2_KPROTO_H_
19
20#include <smbsrv/smb_kproto.h>
21#include <smbsrv/smb2.h>
22
23#ifdef	__cplusplus
24extern "C" {
25#endif
26
27extern uint32_t smb2_tcp_rcvbuf;
28extern uint32_t smb2_max_rwsize;
29extern uint32_t smb2_max_trans;
30
31extern int smb2_aapl_use_file_ids;
32extern uint32_t smb2_dh_def_timeout;
33extern uint32_t smb2_dh_max_timeout;
34extern uint32_t smb2_res_def_timeout;
35extern uint32_t smb2_res_max_timeout;
36extern uint32_t smb2_persist_timeout;
37extern int smb2_enable_dh;
38
39#define	SMB3_CLIENT_ENCRYPTS(sr) \
40	((sr->session->capabilities & SMB2_CAP_ENCRYPTION) != 0)
41
42void	smb2_dispatch_stats_init(smb_server_t *);
43void	smb2_dispatch_stats_fini(smb_server_t *);
44void	smb2_dispatch_stats_update(smb_server_t *,
45		smb_kstat_req_t *, int, int);
46
47int	smb2sr_newrq(smb_request_t *);
48void	smb2sr_work(smb_request_t *);
49uint32_t smb2sr_go_async(smb_request_t *);
50void smb2sr_append_postwork(smb_request_t *, smb_request_t *);
51
52int smb2_decode_header(smb_request_t *);
53int smb2_encode_header(smb_request_t *, boolean_t);
54int smb3_decode_tform_header(smb_request_t *);
55int smb3_encode_tform_header(smb_request_t *, struct mbuf_chain *mbc);
56
57void smb2_send_reply(smb_request_t *);
58void smb2sr_put_error(smb_request_t *, uint32_t);
59void smb2sr_put_error_data(smb_request_t *, uint32_t, mbuf_chain_t *);
60void smb2sr_put_error_ctx(smb_request_t *, uint32_t, uint32_t, mbuf_chain_t *);
61void smb2sr_put_error_ctx0(smb_request_t *, uint32_t, mbuf_chain_t *);
62void smb2sr_put_errno(struct smb_request *, int);
63uint32_t smb2sr_lookup_fid(smb_request_t *, smb2fid_t *);
64
65/* SMB2 signing routines - smb2_signing.c */
66int smb2_sign_check_request(smb_request_t *);
67void smb2_sign_reply(smb_request_t *);
68void smb2_sign_init_mech(smb_session_t *);
69void smb31_preauth_init_mech(smb_session_t *);
70void smb31_preauth_fini(smb_session_t *s);
71int smb31_preauth_sha512_calc(smb_request_t *, struct mbuf_chain *,
72    uint8_t *, uint8_t *);
73
74int smb3_encrypt_sr(smb_request_t *, struct mbuf_chain *, struct mbuf_chain *);
75int smb3_decrypt_sr(smb_request_t *);
76int smb3_encrypt_init_mech(smb_session_t *s);
77
78uint32_t smb2_fsctl_fs(smb_request_t *, smb_fsctl_t *);
79uint32_t smb2_fsctl_netfs(smb_request_t *, smb_fsctl_t *);
80uint32_t smb2_fsctl_copychunk(smb_request_t *, smb_fsctl_t *);
81uint32_t smb2_fsctl_odx_read(smb_request_t *, smb_fsctl_t *);
82uint32_t smb2_fsctl_odx_write(smb_request_t *, smb_fsctl_t *);
83uint32_t smb2_fsctl_set_resilient(smb_request_t *, smb_fsctl_t *);
84
85/* smb2_fsctl_sparse.c */
86uint32_t smb2_fsctl_set_sparse(smb_request_t *, smb_fsctl_t *);
87uint32_t smb2_fsctl_set_zero_data(smb_request_t *, smb_fsctl_t *);
88uint32_t smb2_fsctl_query_alloc_ranges(smb_request_t *, smb_fsctl_t *);
89uint32_t smb2_fsctl_query_file_regions(smb_request_t *, smb_fsctl_t *);
90uint32_t smb2_sparse_copy(smb_request_t *sr,
91    smb_ofile_t *src_ofile, smb_ofile_t *dst_ofile,
92    off64_t src_off, off64_t dst_off, uint32_t *residp,
93    void *buffer, size_t bufsize);
94
95uint32_t smb2_nego_validate(smb_request_t *, smb_fsctl_t *);
96
97smb_sdrc_t smb2_negotiate(smb_request_t *);
98smb_sdrc_t smb2_session_setup(smb_request_t *);
99smb_sdrc_t smb2_logoff(smb_request_t *);
100smb_sdrc_t smb2_tree_connect(smb_request_t *);
101smb_sdrc_t smb2_tree_disconn(smb_request_t *);
102smb_sdrc_t smb2_create(smb_request_t *);
103smb_sdrc_t smb2_close(smb_request_t *);
104smb_sdrc_t smb2_flush(smb_request_t *);
105smb_sdrc_t smb2_read(smb_request_t *);
106smb_sdrc_t smb2_write(smb_request_t *);
107smb_sdrc_t smb2_lock(smb_request_t *);
108smb_sdrc_t smb2_ioctl(smb_request_t *);
109smb_sdrc_t smb2_cancel(smb_request_t *);
110smb_sdrc_t smb2_echo(smb_request_t *);
111smb_sdrc_t smb2_query_dir(smb_request_t *);
112smb_sdrc_t smb2_change_notify(smb_request_t *);
113smb_sdrc_t smb2_query_info(smb_request_t *);
114smb_sdrc_t smb2_set_info(smb_request_t *);
115smb_sdrc_t smb2_oplock_break_ack(smb_request_t *);
116smb_sdrc_t smb2_lease_break_ack(smb_request_t *);
117
118int smb2_newrq_negotiate(smb_request_t *);
119int smb2_newrq_cancel(smb_request_t *);
120
121uint32_t smb2_aapl_crctx(smb_request_t *,
122	mbuf_chain_t *, mbuf_chain_t *);
123
124uint32_t smb2_ofile_getattr(smb_request_t *, smb_ofile_t *, smb_attr_t *);
125uint32_t smb2_ofile_getstd(smb_ofile_t *, smb_queryinfo_t *);
126uint32_t smb2_ofile_getname(smb_ofile_t *, smb_queryinfo_t *);
127
128uint32_t smb2_qinfo_file(smb_request_t *, smb_queryinfo_t *);
129uint32_t smb2_qinfo_fs(smb_request_t *, smb_queryinfo_t *);
130uint32_t smb2_qinfo_sec(smb_request_t *, smb_queryinfo_t *);
131uint32_t smb2_qinfo_quota(smb_request_t *, smb_queryinfo_t *);
132uint32_t smb2_qinfo_stream(smb_request_t *, smb_queryinfo_t *);
133
134uint32_t smb2_setinfo_file(smb_request_t *, smb_setinfo_t *, int);
135uint32_t smb2_setinfo_fs(smb_request_t *, smb_setinfo_t *, int);
136uint32_t smb2_setinfo_sec(smb_request_t *, smb_setinfo_t *, uint32_t);
137uint32_t smb2_setinfo_quota(smb_request_t *, smb_setinfo_t *);
138
139void smb2_oplock_acquire(smb_request_t *sr);
140void smb2_oplock_reconnect(smb_request_t *sr);
141void smb2_lease_acquire(smb_request_t *sr);
142uint32_t smb2_lease_create(smb_request_t *sr, uint8_t *);
143void smb2_lease_rele(smb_lease_t *);
144void smb2_lease_init(void);
145void smb2_lease_fini(void);
146void smb2_lease_ofile_close(smb_ofile_t *);
147
148void smb2_durable_timers(smb_server_t *);
149
150uint32_t smb2_dh_reconnect(smb_request_t *);
151boolean_t smb_dh_should_save(smb_ofile_t *);
152extern void smb2_dh_shutdown(smb_server_t *);
153int smb2_dh_new_ca_share(smb_server_t *, smb_kshare_t *);
154void smb2_dh_close_persistent(smb_ofile_t *);
155void smb2_dh_close_my_orphans(smb_request_t *, smb_ofile_t *);
156int smb2_dh_make_persistent(smb_request_t *, smb_ofile_t *);
157void smb2_dh_setdoc_persistent(smb_ofile_t *);
158void smb2_dh_update_nvfile(smb_request_t *);
159void smb2_dh_update_oplock(smb_request_t *, smb_ofile_t *);
160void smb2_dh_update_locks(smb_request_t *, smb_ofile_t *);
161void smb2_dh_update_times(smb_request_t *, smb_ofile_t *, smb_attr_t *);
162
163#ifdef	__cplusplus
164}
165#endif
166
167#endif /* _SMB2_KPROTO_H_ */
168