xref: /titanic_51/usr/src/uts/common/fs/smbsrv/smb_echo.c (revision a90cf9f29973990687fa61de9f1f6ea22e924e40)
1da6c28aaSamw /*
2da6c28aaSamw  * CDDL HEADER START
3da6c28aaSamw  *
4da6c28aaSamw  * The contents of this file are subject to the terms of the
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * You may not use this file except in compliance with the License.
7da6c28aaSamw  *
8da6c28aaSamw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da6c28aaSamw  * or http://www.opensolaris.org/os/licensing.
10da6c28aaSamw  * See the License for the specific language governing permissions
11da6c28aaSamw  * and limitations under the License.
12da6c28aaSamw  *
13da6c28aaSamw  * When distributing Covered Code, include this CDDL HEADER in each
14da6c28aaSamw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da6c28aaSamw  * If applicable, add the following below this CDDL HEADER, with the
16da6c28aaSamw  * fields enclosed by brackets "[]" replaced with your own identifying
17da6c28aaSamw  * information: Portions Copyright [yyyy] [name of copyright owner]
18da6c28aaSamw  *
19da6c28aaSamw  * CDDL HEADER END
20da6c28aaSamw  */
21da6c28aaSamw /*
229fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da6c28aaSamw  * Use is subject to license terms.
24*a90cf9f2SGordon Ross  *
25*a90cf9f2SGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
26da6c28aaSamw  */
27da6c28aaSamw 
28bbf6f00cSJordan Brown #include <smbsrv/smb_kproto.h>
29da6c28aaSamw 
30da6c28aaSamw /*
31da6c28aaSamw  * The echo request is used to test the connection to the server,
32da6c28aaSamw  * and to see if the server is still responding.  The tid is ignored,
33da6c28aaSamw  * so this request may be sent to the server even if there are no
34da6c28aaSamw  * tree connections to the server.
35da6c28aaSamw  *
36da6c28aaSamw  * Each response echoes the data sent, though ByteCount may indicate
37da6c28aaSamw  * no data. If echo-count is zero, no response is sent.
38da6c28aaSamw  */
397b59d02dSjb150015 smb_sdrc_t
40faa1795aSjb150015 smb_pre_echo(smb_request_t *sr)
41faa1795aSjb150015 {
42faa1795aSjb150015 	DTRACE_SMB_1(op__Echo__start, smb_request_t *, sr);
43faa1795aSjb150015 	return (SDRC_SUCCESS);
44faa1795aSjb150015 }
45faa1795aSjb150015 
46faa1795aSjb150015 void
47faa1795aSjb150015 smb_post_echo(smb_request_t *sr)
48faa1795aSjb150015 {
49faa1795aSjb150015 	DTRACE_SMB_1(op__Echo__done, smb_request_t *, sr);
50faa1795aSjb150015 }
51faa1795aSjb150015 
527f3ef643SGordon Ross static unsigned short smb_max_echo = 10;
537f3ef643SGordon Ross 
54faa1795aSjb150015 smb_sdrc_t
55da6c28aaSamw smb_com_echo(struct smb_request *sr)
56da6c28aaSamw {
57da6c28aaSamw 	unsigned short necho;
58da6c28aaSamw 	unsigned short nbytes;
59da6c28aaSamw 	unsigned short i;
60da6c28aaSamw 	struct mbuf_chain reply;
61da6c28aaSamw 	char *data;
62*a90cf9f2SGordon Ross 	uint16_t	pid_hi, pid_lo;
63*a90cf9f2SGordon Ross 
64*a90cf9f2SGordon Ross 	pid_hi = sr->smb_pid >> 16;
65*a90cf9f2SGordon Ross 	pid_lo = (uint16_t)sr->smb_pid;
66da6c28aaSamw 
677b59d02dSjb150015 	if (smbsr_decode_vwv(sr, "w", &necho) != 0)
68faa1795aSjb150015 		return (SDRC_ERROR);
69da6c28aaSamw 
707f3ef643SGordon Ross 	/*
717f3ef643SGordon Ross 	 * Don't let the client fool us into doing
727f3ef643SGordon Ross 	 * more work than is "reasonable".
737f3ef643SGordon Ross 	 */
747f3ef643SGordon Ross 	if (necho > smb_max_echo)
757f3ef643SGordon Ross 		necho = smb_max_echo;
767f3ef643SGordon Ross 
77da6c28aaSamw 	nbytes = sr->smb_bcc;
789fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 	data = smb_srm_zalloc(sr, nbytes);
79da6c28aaSamw 
803db3f65cSamw 	if (smb_mbc_decodef(&sr->smb_data, "#c", nbytes, data))
81faa1795aSjb150015 		return (SDRC_ERROR);
82da6c28aaSamw 
83da6c28aaSamw 	for (i = 1; i <= necho; ++i) {
847f3ef643SGordon Ross 
857f3ef643SGordon Ross 		/*
867f3ef643SGordon Ross 		 * According to [MS-CIFS] 3.3.5.32 echo is
877f3ef643SGordon Ross 		 * subject to cancellation.
887f3ef643SGordon Ross 		 */
897f3ef643SGordon Ross 		if (sr->sr_state != SMB_REQ_STATE_ACTIVE)
907f3ef643SGordon Ross 			break;
917f3ef643SGordon Ross 
92da6c28aaSamw 		MBC_INIT(&reply, SMB_HEADER_ED_LEN + 10 + nbytes);
93da6c28aaSamw 
943db3f65cSamw 		(void) smb_mbc_encodef(&reply, SMB_HEADER_ED_FMT,
95da6c28aaSamw 		    sr->first_smb_com,
96da6c28aaSamw 		    sr->smb_rcls,
97da6c28aaSamw 		    sr->smb_reh,
98da6c28aaSamw 		    sr->smb_err,
99da6c28aaSamw 		    sr->smb_flg | SMB_FLAGS_REPLY,
100da6c28aaSamw 		    sr->smb_flg2,
101*a90cf9f2SGordon Ross 		    pid_hi,
102da6c28aaSamw 		    sr->smb_sig,
103da6c28aaSamw 		    sr->smb_tid,
104*a90cf9f2SGordon Ross 		    pid_lo,
105da6c28aaSamw 		    sr->smb_uid,
106da6c28aaSamw 		    sr->smb_mid);
107da6c28aaSamw 
1083db3f65cSamw 		(void) smb_mbc_encodef(&reply, "bww#c", 1, i,
109da6c28aaSamw 		    nbytes, nbytes, data);
110da6c28aaSamw 
111da6c28aaSamw 		if (sr->session->signing.flags & SMB_SIGNING_ENABLED)
112da6c28aaSamw 			smb_sign_reply(sr, &reply);
113da6c28aaSamw 
114da6c28aaSamw 		(void) smb_session_send(sr->session, 0, &reply);
1157f3ef643SGordon Ross 
1167f3ef643SGordon Ross 		delay(MSEC_TO_TICK(100));
117da6c28aaSamw 	}
118da6c28aaSamw 
119da6c28aaSamw 	return (SDRC_NO_REPLY);
120da6c28aaSamw }
121