1*a90cf9f2SGordon Ross /* 2*a90cf9f2SGordon Ross * This file and its contents are supplied under the terms of the 3*a90cf9f2SGordon Ross * Common Development and Distribution License ("CDDL"), version 1.0. 4*a90cf9f2SGordon Ross * You may only use this file in accordance with the terms of version 5*a90cf9f2SGordon Ross * 1.0 of the CDDL. 6*a90cf9f2SGordon Ross * 7*a90cf9f2SGordon Ross * A full copy of the text of the CDDL should have accompanied this 8*a90cf9f2SGordon Ross * source. A copy of the CDDL is also available via the Internet at 9*a90cf9f2SGordon Ross * http://www.illumos.org/license/CDDL. 10*a90cf9f2SGordon Ross */ 11*a90cf9f2SGordon Ross 12*a90cf9f2SGordon Ross /* 13*a90cf9f2SGordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 14*a90cf9f2SGordon Ross */ 15*a90cf9f2SGordon Ross 16*a90cf9f2SGordon Ross /* 17*a90cf9f2SGordon Ross * Dispatch function for SMB2_OPLOCK_BREAK 18*a90cf9f2SGordon Ross */ 19*a90cf9f2SGordon Ross 20*a90cf9f2SGordon Ross #include <smbsrv/smb2_kproto.h> 21*a90cf9f2SGordon Ross 22*a90cf9f2SGordon Ross /* 23*a90cf9f2SGordon Ross * SMB2 Oplock Break Acknowledgement 24*a90cf9f2SGordon Ross * [MS-SMB2 2.2.24] 25*a90cf9f2SGordon Ross */ 26*a90cf9f2SGordon Ross smb_sdrc_t 27*a90cf9f2SGordon Ross smb2_oplock_break_ack(smb_request_t *sr) 28*a90cf9f2SGordon Ross { 29*a90cf9f2SGordon Ross smb_node_t *node; 30*a90cf9f2SGordon Ross smb2fid_t smb2fid; 31*a90cf9f2SGordon Ross uint32_t status; 32*a90cf9f2SGordon Ross uint16_t StructSize; 33*a90cf9f2SGordon Ross uint8_t OplockLevel; 34*a90cf9f2SGordon Ross uint8_t brk; 35*a90cf9f2SGordon Ross int rc = 0; 36*a90cf9f2SGordon Ross 37*a90cf9f2SGordon Ross /* 38*a90cf9f2SGordon Ross * Decode the SMB2 Oplock Break Ack. 39*a90cf9f2SGordon Ross */ 40*a90cf9f2SGordon Ross rc = smb_mbc_decodef( 41*a90cf9f2SGordon Ross &sr->smb_data, "wb5.qq", 42*a90cf9f2SGordon Ross &StructSize, /* w */ 43*a90cf9f2SGordon Ross &OplockLevel, /* b */ 44*a90cf9f2SGordon Ross /* reserved 5. */ 45*a90cf9f2SGordon Ross &smb2fid.persistent, /* q */ 46*a90cf9f2SGordon Ross &smb2fid.temporal); /* q */ 47*a90cf9f2SGordon Ross if (rc || StructSize != 24) 48*a90cf9f2SGordon Ross return (SDRC_ERROR); 49*a90cf9f2SGordon Ross 50*a90cf9f2SGordon Ross status = smb2sr_lookup_fid(sr, &smb2fid); 51*a90cf9f2SGordon Ross if (status) 52*a90cf9f2SGordon Ross goto errout; 53*a90cf9f2SGordon Ross if ((node = sr->fid_ofile->f_node) == NULL) { 54*a90cf9f2SGordon Ross /* Not a regular file */ 55*a90cf9f2SGordon Ross status = NT_STATUS_INVALID_PARAMETER; 56*a90cf9f2SGordon Ross goto errout; 57*a90cf9f2SGordon Ross } 58*a90cf9f2SGordon Ross 59*a90cf9f2SGordon Ross /* 60*a90cf9f2SGordon Ross * Process the oplock break ack. We only expect levels 61*a90cf9f2SGordon Ross * at or below the hightest break levels we send, which is 62*a90cf9f2SGordon Ross * currently SMB2_OPLOCK_LEVEL_II. 63*a90cf9f2SGordon Ross */ 64*a90cf9f2SGordon Ross switch (OplockLevel) { 65*a90cf9f2SGordon Ross case SMB2_OPLOCK_LEVEL_NONE: /* 0x00 */ 66*a90cf9f2SGordon Ross brk = SMB_OPLOCK_BREAK_TO_NONE; 67*a90cf9f2SGordon Ross break; 68*a90cf9f2SGordon Ross 69*a90cf9f2SGordon Ross case SMB2_OPLOCK_LEVEL_II: /* 0x01 */ 70*a90cf9f2SGordon Ross brk = SMB_OPLOCK_BREAK_TO_LEVEL_II; 71*a90cf9f2SGordon Ross break; 72*a90cf9f2SGordon Ross 73*a90cf9f2SGordon Ross /* We don't break to these levels (yet). */ 74*a90cf9f2SGordon Ross case SMB2_OPLOCK_LEVEL_EXCLUSIVE: /* 0x08 */ 75*a90cf9f2SGordon Ross case SMB2_OPLOCK_LEVEL_BATCH: /* 0x09 */ 76*a90cf9f2SGordon Ross case SMB2_OPLOCK_LEVEL_LEASE: /* 0xFF */ 77*a90cf9f2SGordon Ross default: /* gcc -Wuninitialized */ 78*a90cf9f2SGordon Ross status = NT_STATUS_INVALID_PARAMETER; 79*a90cf9f2SGordon Ross goto errout; 80*a90cf9f2SGordon Ross } 81*a90cf9f2SGordon Ross 82*a90cf9f2SGordon Ross smb_oplock_ack(node, sr->fid_ofile, brk); 83*a90cf9f2SGordon Ross 84*a90cf9f2SGordon Ross /* 85*a90cf9f2SGordon Ross * Generate SMB2 Oplock Break response 86*a90cf9f2SGordon Ross * [MS-SMB2] 2.2.25 87*a90cf9f2SGordon Ross */ 88*a90cf9f2SGordon Ross StructSize = 24; 89*a90cf9f2SGordon Ross (void) smb_mbc_encodef( 90*a90cf9f2SGordon Ross &sr->reply, "wb5.qq", 91*a90cf9f2SGordon Ross StructSize, /* w */ 92*a90cf9f2SGordon Ross OplockLevel, /* b */ 93*a90cf9f2SGordon Ross /* reserved 5. */ 94*a90cf9f2SGordon Ross smb2fid.persistent, /* q */ 95*a90cf9f2SGordon Ross smb2fid.temporal); /* q */ 96*a90cf9f2SGordon Ross return (SDRC_SUCCESS); 97*a90cf9f2SGordon Ross 98*a90cf9f2SGordon Ross errout: 99*a90cf9f2SGordon Ross smb2sr_put_error(sr, status); 100*a90cf9f2SGordon Ross return (SDRC_SUCCESS); 101*a90cf9f2SGordon Ross } 102*a90cf9f2SGordon Ross 103*a90cf9f2SGordon Ross /* 104*a90cf9f2SGordon Ross * Compose an SMB2 Oplock Break Notification packet, including 105*a90cf9f2SGordon Ross * the SMB2 header and everything, in sr->reply. 106*a90cf9f2SGordon Ross * The caller will send it and free the request. 107*a90cf9f2SGordon Ross */ 108*a90cf9f2SGordon Ross void 109*a90cf9f2SGordon Ross smb2_oplock_break_notification(smb_request_t *sr, uint8_t brk) 110*a90cf9f2SGordon Ross { 111*a90cf9f2SGordon Ross smb_ofile_t *ofile = sr->fid_ofile; 112*a90cf9f2SGordon Ross smb2fid_t smb2fid; 113*a90cf9f2SGordon Ross uint16_t StructSize; 114*a90cf9f2SGordon Ross uint8_t OplockLevel; 115*a90cf9f2SGordon Ross 116*a90cf9f2SGordon Ross switch (brk) { 117*a90cf9f2SGordon Ross default: 118*a90cf9f2SGordon Ross ASSERT(0); 119*a90cf9f2SGordon Ross /* FALLTHROUGH */ 120*a90cf9f2SGordon Ross case SMB_OPLOCK_BREAK_TO_NONE: 121*a90cf9f2SGordon Ross OplockLevel = SMB2_OPLOCK_LEVEL_NONE; 122*a90cf9f2SGordon Ross break; 123*a90cf9f2SGordon Ross case SMB_OPLOCK_BREAK_TO_LEVEL_II: 124*a90cf9f2SGordon Ross OplockLevel = SMB2_OPLOCK_LEVEL_II; 125*a90cf9f2SGordon Ross break; 126*a90cf9f2SGordon Ross } 127*a90cf9f2SGordon Ross 128*a90cf9f2SGordon Ross /* 129*a90cf9f2SGordon Ross * SMB2 Header 130*a90cf9f2SGordon Ross */ 131*a90cf9f2SGordon Ross sr->smb2_cmd_code = SMB2_OPLOCK_BREAK; 132*a90cf9f2SGordon Ross sr->smb2_hdr_flags = SMB2_FLAGS_SERVER_TO_REDIR; 133*a90cf9f2SGordon Ross sr->smb_tid = ofile->f_tree->t_tid; 134*a90cf9f2SGordon Ross sr->smb_pid = 0; 135*a90cf9f2SGordon Ross sr->smb_uid = 0; 136*a90cf9f2SGordon Ross sr->smb2_messageid = UINT64_MAX; 137*a90cf9f2SGordon Ross (void) smb2_encode_header(sr, B_FALSE); 138*a90cf9f2SGordon Ross 139*a90cf9f2SGordon Ross /* 140*a90cf9f2SGordon Ross * SMB2 Oplock Break, variable part 141*a90cf9f2SGordon Ross */ 142*a90cf9f2SGordon Ross StructSize = 24; 143*a90cf9f2SGordon Ross smb2fid.persistent = 0; 144*a90cf9f2SGordon Ross smb2fid.temporal = ofile->f_fid; 145*a90cf9f2SGordon Ross (void) smb_mbc_encodef( 146*a90cf9f2SGordon Ross &sr->reply, "wb5.qq", 147*a90cf9f2SGordon Ross StructSize, /* w */ 148*a90cf9f2SGordon Ross OplockLevel, /* b */ 149*a90cf9f2SGordon Ross /* reserved 5. */ 150*a90cf9f2SGordon Ross smb2fid.persistent, /* q */ 151*a90cf9f2SGordon Ross smb2fid.temporal); /* q */ 152*a90cf9f2SGordon Ross } 153