1nbd_set_strict_mode(3) LIBNBD nbd_set_strict_mode(3)
2
3
4
6 nbd_set_strict_mode - control how strictly to follow NBD protocol
7
9 #include <libnbd.h>
10
11 int nbd_set_strict_mode (struct nbd_handle *h,
12 uint32_t flags);
13
15 By default, libnbd tries to detect requests that would trigger
16 undefined behavior in the NBD protocol, and rejects them client side
17 without causing any network traffic, rather than risking undefined
18 server behavior. However, for integration testing, it can be handy to
19 relax the strictness of libnbd, to coerce it into sending such requests
20 over the network for testing the robustness of the server in dealing
21 with such traffic.
22
23 The "flags" argument is a bitmask, including zero or more of the
24 following strictness flags:
25
26 "LIBNBD_STRICT_COMMANDS" = 1
27 If set, this flag rejects client requests that do not comply with
28 the set of advertised server flags (for example, attempting a write
29 on a read-only server, or attempting to use "LIBNBD_CMD_FLAG_FUA"
30 when nbd_can_fua(3) returned false). If clear, this flag relies on
31 the server to reject unexpected commands.
32
33 "LIBNBD_STRICT_FLAGS" = 2
34 If set, this flag rejects client requests that attempt to set a
35 command flag not recognized by libnbd (those outside of
36 "LIBNBD_CMD_FLAG_MASK"), or a flag not normally associated with a
37 command (such as using "LIBNBD_CMD_FLAG_FUA" on a read command).
38 If clear, all flags are sent on to the server, even if sending such
39 a flag may cause the server to change its reply in a manner that
40 confuses libnbd, perhaps causing deadlock or ending the connection.
41
42 Flags that are known by libnbd as associated with a given command
43 (such as "LIBNBD_CMD_FLAG_DF" for nbd_pread_structured(3) gated by
44 nbd_can_df(3)) are controlled by "LIBNBD_STRICT_COMMANDS" instead.
45
46 Note that the NBD protocol only supports 16 bits of command flags,
47 even though the libnbd API uses "uint32_t"; bits outside of the
48 range permitted by the protocol are always a client-side error.
49
50 "LIBNBD_STRICT_BOUNDS" = 3
51 If set, this flag rejects client requests that would exceed the
52 export bounds without sending any traffic to the server. If clear,
53 this flag relies on the server to detect out-of-bounds requests.
54
55 "LIBNBD_STRICT_ZERO_SIZE" = 4
56 If set, this flag rejects client requests with length 0. If clear,
57 this permits zero-length requests to the server, which may produce
58 undefined results.
59
60 "LIBNBD_STRICT_ALIGN" = 5
61 If set, and the server provided minimum block sizes (see
62 nbd_get_block_size(3), this flag rejects client requests that do
63 not have length and offset aligned to the server's minimum
64 requirements. If clear, unaligned requests are sent to the server,
65 where it is up to the server whether to honor or reject the
66 request.
67
68 For convenience, the constant "LIBNBD_STRICT_MASK" is available to
69 describe all strictness flags supported by this build of libnbd.
70 Future versions of libnbd may add further flags, which are likely to be
71 enabled by default for additional client-side filtering. As such, when
72 attempting to relax only one specific bit while keeping remaining
73 checks at the client side, it is wiser to first call
74 nbd_get_strict_mode(3) and modify that value, rather than blindly
75 setting a constant value.
76
78 If the call is successful the function returns 0.
79
81 On error "-1" is returned.
82
83 Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
84 of the error.
85
87 This function first appeared in libnbd 1.6.
88
89 If you need to test if this function is available at compile time check
90 if the following macro is defined:
91
92 #define LIBNBD_HAVE_NBD_SET_STRICT_MODE 1
93
95 nbd_can_df(3), nbd_can_fua(3), nbd_create(3), nbd_get_block_size(3),
96 nbd_get_strict_mode(3), nbd_pread_structured(3),
97 nbd_set_handshake_flags(3), libnbd(3).
98
100 Eric Blake
101
102 Richard W.M. Jones
103
105 Copyright (C) 2019-2021 Red Hat Inc.
106
108 This library is free software; you can redistribute it and/or modify it
109 under the terms of the GNU Lesser General Public License as published
110 by the Free Software Foundation; either version 2 of the License, or
111 (at your option) any later version.
112
113 This library is distributed in the hope that it will be useful, but
114 WITHOUT ANY WARRANTY; without even the implied warranty of
115 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
116 Lesser General Public License for more details.
117
118 You should have received a copy of the GNU Lesser General Public
119 License along with this library; if not, write to the Free Software
120 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
121 02110-1301 USA
122
123
124
125libnbd-1.12.5 2022-07-10 nbd_set_strict_mode(3)