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 (
12 struct nbd_handle *h, uint32_t flags
13 );
14
16 By default, libnbd tries to detect requests that would trigger
17 undefined behavior in the NBD protocol, and rejects them client side
18 without causing any network traffic, rather than risking undefined
19 server behavior. However, for integration testing, it can be handy to
20 relax the strictness of libnbd, to coerce it into sending such requests
21 over the network for testing the robustness of the server in dealing
22 with such traffic.
23
24 The "flags" argument is a bitmask, including zero or more of the
25 following strictness flags:
26
27 "LIBNBD_STRICT_COMMANDS" = 0x1
28 If set, this flag rejects client requests that do not comply with
29 the set of advertised server flags (for example, attempting a write
30 on a read-only server, or attempting to use "LIBNBD_CMD_FLAG_FUA"
31 when nbd_can_fua(3) returned false). If clear, this flag relies on
32 the server to reject unexpected commands.
33
34 "LIBNBD_STRICT_FLAGS" = 0x2
35 If set, this flag rejects client requests that attempt to set a
36 command flag not recognized by libnbd (those outside of
37 "LIBNBD_CMD_FLAG_MASK"), or a flag not normally associated with a
38 command (such as using "LIBNBD_CMD_FLAG_FUA" on a read command).
39 If clear, all flags are sent on to the server, even if sending such
40 a flag may cause the server to change its reply in a manner that
41 confuses libnbd, perhaps causing deadlock or ending the connection.
42
43 Flags that are known by libnbd as associated with a given command
44 (such as "LIBNBD_CMD_FLAG_DF" for nbd_pread_structured(3) gated by
45 nbd_can_df(3)) are controlled by "LIBNBD_STRICT_COMMANDS" instead;
46 and "LIBNBD_CMD_FLAG_PAYLOAD_LEN" is managed automatically by
47 libnbd unless "LIBNBD_STRICT_AUTO_FLAG" is disabled.
48
49 Note that the NBD protocol only supports 16 bits of command flags,
50 even though the libnbd API uses "uint32_t"; bits outside of the
51 range permitted by the protocol are always a client-side error.
52
53 "LIBNBD_STRICT_BOUNDS" = 0x4
54 If set, this flag rejects client requests that would exceed the
55 export bounds without sending any traffic to the server. If clear,
56 this flag relies on the server to detect out-of-bounds requests.
57
58 "LIBNBD_STRICT_ZERO_SIZE" = 0x8
59 If set, this flag rejects client requests with length 0. If clear,
60 this permits zero-length requests to the server, which may produce
61 undefined results.
62
63 "LIBNBD_STRICT_ALIGN" = 0x10
64 If set, and the server provided minimum block sizes (see
65 "LIBNBD_SIZE_MINIMUM" for nbd_get_block_size(3)), this flag rejects
66 client requests that do not have length and offset aligned to the
67 server's minimum requirements. If clear, unaligned requests are
68 sent to the server, where it is up to the server whether to honor
69 or reject the request.
70
71 "LIBNBD_STRICT_PAYLOAD" = 0x20
72 If set, the client refuses to send a command to the server with
73 more than libnbd's outgoing payload maximum (see
74 "LIBNBD_SIZE_PAYLOAD" for nbd_get_block_size(3)), whether or not
75 the server advertised a block size maximum. If clear, oversize
76 requests up to 64MiB may be attempted, although requests larger
77 than 32MiB are liable to cause some servers to disconnect.
78
79 "LIBNBD_STRICT_AUTO_FLAG" = 0x40
80 If set, commands that accept the "LIBNBD_CMD_FLAG_PAYLOAD_LEN" flag
81 (such as nbd_pwrite(3) and nbd_block_status_filter(3)) ignore the
82 presence or absence of that flag from the caller, instead sending
83 the value over the wire that matches the server's expectations
84 based on whether extended headers were negotiated when the
85 connection was made. If clear, the caller takes on the
86 responsibility for whether the payload length flag is set or clear
87 during the affected command, which can be useful during integration
88 testing but is more likely to lead to undefined behavior.
89
90 For convenience, the constant "LIBNBD_STRICT_MASK" is available to
91 describe all strictness flags supported by this build of libnbd.
92 Future versions of libnbd may add further flags, which are likely to be
93 enabled by default for additional client-side filtering. As such, when
94 attempting to relax only one specific bit while keeping remaining
95 checks at the client side, it is wiser to first call
96 nbd_get_strict_mode(3) and modify that value, rather than blindly
97 setting a constant value.
98
100 If the call is successful the function returns 0.
101
103 On error -1 is returned.
104
105 Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
106 of the error.
107
108 The following parameters must not be NULL: "h". For more information
109 see "Non-NULL parameters" in libnbd(3).
110
112 This function first appeared in libnbd 1.6.
113
114 If you need to test if this function is available at compile time check
115 if the following macro is defined:
116
117 #define LIBNBD_HAVE_NBD_SET_STRICT_MODE 1
118
120 nbd_can_df(3), nbd_can_fua(3), nbd_create(3), nbd_get_block_size(3),
121 nbd_get_strict_mode(3), nbd_pread_structured(3), nbd_pwrite(3),
122 nbd_set_handshake_flags(3), nbd_stats_bytes_received(3),
123 nbd_stats_bytes_sent(3), libnbd(3).
124
126 Eric Blake
127
128 Richard W.M. Jones
129
131 Copyright Red Hat
132
134 This library is free software; you can redistribute it and/or modify it
135 under the terms of the GNU Lesser General Public License as published
136 by the Free Software Foundation; either version 2 of the License, or
137 (at your option) any later version.
138
139 This library is distributed in the hope that it will be useful, but
140 WITHOUT ANY WARRANTY; without even the implied warranty of
141 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
142 Lesser General Public License for more details.
143
144 You should have received a copy of the GNU Lesser General Public
145 License along with this library; if not, write to the Free Software
146 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
147 02110-1301 USA
148
149
150
151libnbd-1.18.1 2023-10-31 nbd_set_strict_mode(3)