| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
test suite for SMB2 leases |
| 5 |
|
| 6 |
Copyright (C) Zachary Loafman 2009 |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3 of the License, or |
| 11 |
(at your option) any later version. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "torture/util.h" |
| 23 |
|
| 24 |
struct lease_break_info { |
| 25 |
struct torture_context *tctx; |
| 26 |
|
| 27 |
struct smb2_lease_break lease_break; |
| 28 |
struct smb2_transport *lease_transport; |
| 29 |
bool lease_skip_ack; |
| 30 |
struct smb2_lease_break_ack lease_break_ack; |
| 31 |
|
| 32 |
struct smb2_handle lease_handle; |
| 33 |
struct smb2_close close; |
| 34 |
|
| 35 |
int count; |
| 36 |
int failures; |
| 37 |
|
| 38 |
struct smb2_handle oplock_handle; |
| 39 |
uint8_t held_oplock_level; |
| 40 |
uint8_t oplock_level; |
| 41 |
int oplock_count; |
| 42 |
int oplock_failures; |
| 43 |
}; |
| 44 |
|
| 45 |
#define CHECK_LEASE_BREAK(__lb, __oldstate, __state, __key) \ |
| 46 |
do { \ |
| 47 |
uint16_t __new = smb2_util_lease_state(__state); \ |
| 48 |
uint16_t __old = smb2_util_lease_state(__oldstate); \ |
| 49 |
CHECK_VAL((__lb)->new_lease_state, __new); \ |
| 50 |
CHECK_VAL((__lb)->current_lease.lease_state, __old); \ |
| 51 |
CHECK_VAL((__lb)->current_lease.lease_key.data[0], (__key)); \ |
| 52 |
CHECK_VAL((__lb)->current_lease.lease_key.data[1], ~(__key)); \ |
| 53 |
if (__old & (SMB2_LEASE_WRITE | SMB2_LEASE_HANDLE)) { \ |
| 54 |
CHECK_VAL((__lb)->break_flags, \ |
| 55 |
SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED); \ |
| 56 |
} else { \ |
| 57 |
CHECK_VAL((__lb)->break_flags, 0); \ |
| 58 |
} \ |
| 59 |
} while(0) |
| 60 |
|
| 61 |
#define CHECK_LEASE_BREAK_ACK(__lba, __state, __key) \ |
| 62 |
do { \ |
| 63 |
CHECK_VAL((__lba)->out.reserved, 0); \ |
| 64 |
CHECK_VAL((__lba)->out.lease.lease_key.data[0], (__key)); \ |
| 65 |
CHECK_VAL((__lba)->out.lease.lease_key.data[1], ~(__key)); \ |
| 66 |
CHECK_VAL((__lba)->out.lease.lease_state, smb2_util_lease_state(__state)); \ |
| 67 |
CHECK_VAL((__lba)->out.lease.lease_flags, 0); \ |
| 68 |
CHECK_VAL((__lba)->out.lease.lease_duration, 0); \ |
| 69 |
} while(0) |
| 70 |
|
| 71 |
#define CHECK_NO_BREAK(tctx) \ |
| 72 |
do { \ |
| 73 |
torture_wait_for_lease_break(tctx); \ |
| 74 |
CHECK_VAL(lease_break_info.failures, 0); \ |
| 75 |
CHECK_VAL(lease_break_info.count, 0); \ |
| 76 |
CHECK_VAL(lease_break_info.oplock_failures, 0); \ |
| 77 |
CHECK_VAL(lease_break_info.oplock_count, 0); \ |
| 78 |
} while(0) |
| 79 |
|
| 80 |
#define CHECK_OPLOCK_BREAK(__brokento) \ |
| 81 |
do { \ |
| 82 |
torture_wait_for_lease_break(tctx); \ |
| 83 |
CHECK_VAL(lease_break_info.oplock_count, 1); \ |
| 84 |
CHECK_VAL(lease_break_info.oplock_failures, 0); \ |
| 85 |
CHECK_VAL(lease_break_info.oplock_level, \ |
| 86 |
smb2_util_oplock_level(__brokento)); \ |
| 87 |
lease_break_info.held_oplock_level = lease_break_info.oplock_level; \ |
| 88 |
} while(0) |
| 89 |
|
| 90 |
#define _CHECK_BREAK_INFO(__oldstate, __state, __key) \ |
| 91 |
do { \ |
| 92 |
torture_wait_for_lease_break(tctx); \ |
| 93 |
CHECK_VAL(lease_break_info.failures, 0); \ |
| 94 |
CHECK_VAL(lease_break_info.count, 1); \ |
| 95 |
CHECK_LEASE_BREAK(&lease_break_info.lease_break, (__oldstate), \ |
| 96 |
(__state), (__key)); \ |
| 97 |
if (!lease_break_info.lease_skip_ack && \ |
| 98 |
(lease_break_info.lease_break.break_flags & \ |
| 99 |
SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED)) \ |
| 100 |
{ \ |
| 101 |
torture_wait_for_lease_break(tctx); \ |
| 102 |
CHECK_LEASE_BREAK_ACK(&lease_break_info.lease_break_ack, \ |
| 103 |
(__state), (__key)); \ |
| 104 |
} \ |
| 105 |
} while(0) |
| 106 |
|
| 107 |
#define _CHECK_BREAK_INFO_NOWAIT(__oldstate, __state, __key) \ |
| 108 |
do { \ |
| 109 |
CHECK_VAL(lease_break_info.failures, 0); \ |
| 110 |
CHECK_VAL(lease_break_info.count, 1); \ |
| 111 |
CHECK_LEASE_BREAK(&lease_break_info.lease_break, (__oldstate), \ |
| 112 |
(__state), (__key)); \ |
| 113 |
if (!lease_break_info.lease_skip_ack && \ |
| 114 |
(lease_break_info.lease_break.break_flags & \ |
| 115 |
SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED)) \ |
| 116 |
{ \ |
| 117 |
torture_wait_for_lease_break(tctx); \ |
| 118 |
CHECK_LEASE_BREAK_ACK(&lease_break_info.lease_break_ack, \ |
| 119 |
(__state), (__key)); \ |
| 120 |
} \ |
| 121 |
} while(0) |
| 122 |
|
| 123 |
#define CHECK_BREAK_INFO(__oldstate, __state, __key) \ |
| 124 |
do { \ |
| 125 |
_CHECK_BREAK_INFO(__oldstate, __state, __key); \ |
| 126 |
CHECK_VAL(lease_break_info.lease_break.new_epoch, 0); \ |
| 127 |
} while(0) |
| 128 |
|
| 129 |
#define CHECK_BREAK_INFO_V2(__transport, __oldstate, __state, __key, __epoch) \ |
| 130 |
do { \ |
| 131 |
_CHECK_BREAK_INFO(__oldstate, __state, __key); \ |
| 132 |
CHECK_VAL(lease_break_info.lease_break.new_epoch, __epoch); \ |
| 133 |
if (!TARGET_IS_SAMBA3(tctx)) { \ |
| 134 |
CHECK_VAL((uintptr_t)lease_break_info.lease_transport, \ |
| 135 |
(uintptr_t)__transport); \ |
| 136 |
} \ |
| 137 |
} while(0) |
| 138 |
|
| 139 |
#define CHECK_BREAK_INFO_V2_NOWAIT(__transport, __oldstate, __state, __key, __epoch) \ |
| 140 |
do { \ |
| 141 |
_CHECK_BREAK_INFO_NOWAIT(__oldstate, __state, __key); \ |
| 142 |
CHECK_VAL(lease_break_info.lease_break.new_epoch, __epoch); \ |
| 143 |
if (!TARGET_IS_SAMBA3(tctx)) { \ |
| 144 |
CHECK_VAL((uintptr_t)lease_break_info.lease_transport, \ |
| 145 |
(uintptr_t)__transport); \ |
| 146 |
} \ |
| 147 |
} while(0) |
| 148 |
|
| 149 |
extern struct lease_break_info lease_break_info; |
| 150 |
|
| 151 |
bool torture_lease_handler(struct smb2_transport *transport, |
| 152 |
const struct smb2_lease_break *lb, |
| 153 |
void *private_data); |
| 154 |
void torture_wait_for_lease_break(struct torture_context *tctx); |
| 155 |
|
| 156 |
static inline void torture_reset_lease_break_info(struct torture_context *tctx, |
| 157 |
struct lease_break_info *r) |
| 158 |
{ |
| 159 |
ZERO_STRUCTP(r); |
| 160 |
r->tctx = tctx; |
| 161 |
} |