1nbd_set_strict_mode(3)              LIBNBD              nbd_set_strict_mode(3)
2
3
4

NAME

6       nbd_set_strict_mode - control how strictly to follow NBD protocol
7

SYNOPSIS

9        #include <libnbd.h>
10
11        int nbd_set_strict_mode (
12              struct nbd_handle *h, uint32_t flags
13            );
14

DESCRIPTION

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
47           Note that the NBD protocol only supports 16 bits of command flags,
48           even though the libnbd API uses "uint32_t"; bits outside of the
49           range permitted by the protocol are always a client-side error.
50
51       "LIBNBD_STRICT_BOUNDS" = 0x4
52           If set, this flag rejects client requests that would exceed the
53           export bounds without sending any traffic to the server.  If clear,
54           this flag relies on the server to detect out-of-bounds requests.
55
56       "LIBNBD_STRICT_ZERO_SIZE" = 0x8
57           If set, this flag rejects client requests with length 0.  If clear,
58           this permits zero-length requests to the server, which may produce
59           undefined results.
60
61       "LIBNBD_STRICT_ALIGN" = 0x10
62           If set, and the server provided minimum block sizes (see
63           "LIBNBD_SIZE_MINIMUM" for nbd_get_block_size(3)), this flag rejects
64           client requests that do not have length and offset aligned to the
65           server's minimum requirements.  If clear, unaligned requests are
66           sent to the server, where it is up to the server whether to honor
67           or reject the request.
68
69       "LIBNBD_STRICT_PAYLOAD" = 0x20
70           If set, the client refuses to send a command to the server with
71           more than libnbd's outgoing payload maximum (see
72           "LIBNBD_SIZE_PAYLOAD" for nbd_get_block_size(3)), whether or not
73           the server advertised a block size maximum.  If clear, oversize
74           requests up to 64MiB may be attempted, although requests larger
75           than 32MiB are liable to cause some servers to disconnect.
76
77       For convenience, the constant "LIBNBD_STRICT_MASK" is available to
78       describe all strictness flags supported by this build of libnbd.
79       Future versions of libnbd may add further flags, which are likely to be
80       enabled by default for additional client-side filtering.  As such, when
81       attempting to relax only one specific bit while keeping remaining
82       checks at the client side, it is wiser to first call
83       nbd_get_strict_mode(3) and modify that value, rather than blindly
84       setting a constant value.
85

RETURN VALUE

87       If the call is successful the function returns 0.
88

ERRORS

90       On error -1 is returned.
91
92       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
93       of the error.
94
95       The following parameters must not be NULL: "h".  For more information
96       see "Non-NULL parameters" in libnbd(3).
97

VERSION

99       This function first appeared in libnbd 1.6.
100
101       If you need to test if this function is available at compile time check
102       if the following macro is defined:
103
104        #define LIBNBD_HAVE_NBD_SET_STRICT_MODE 1
105

SEE ALSO

107       nbd_can_df(3), nbd_can_fua(3), nbd_create(3), nbd_get_block_size(3),
108       nbd_get_strict_mode(3), nbd_pread_structured(3),
109       nbd_set_handshake_flags(3), nbd_stats_bytes_received(3),
110       nbd_stats_bytes_sent(3), libnbd(3).
111

AUTHORS

113       Eric Blake
114
115       Richard W.M. Jones
116
118       Copyright Red Hat
119

LICENSE

121       This library is free software; you can redistribute it and/or modify it
122       under the terms of the GNU Lesser General Public License as published
123       by the Free Software Foundation; either version 2 of the License, or
124       (at your option) any later version.
125
126       This library is distributed in the hope that it will be useful, but
127       WITHOUT ANY WARRANTY; without even the implied warranty of
128       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
129       Lesser General Public License for more details.
130
131       You should have received a copy of the GNU Lesser General Public
132       License along with this library; if not, write to the Free Software
133       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
134       02110-1301 USA
135
136
137
138libnbd-1.16.5                     2023-09-26            nbd_set_strict_mode(3)
Impressum