1nbd_connect_uri(3)                  LIBNBD                  nbd_connect_uri(3)
2
3
4

NAME

6       nbd_connect_uri - connect to NBD URI
7

SYNOPSIS

9        #include <libnbd.h>
10
11        int nbd_connect_uri (
12              struct nbd_handle *h, const char *uri
13            );
14

DESCRIPTION

16       Connect (synchronously) to an NBD server and export by specifying the
17       NBD URI.  This call parses the URI and calls nbd_set_export_name(3) and
18       nbd_set_tls(3) and other calls as needed, followed by
19       nbd_connect_tcp(3), nbd_connect_unix(3) or nbd_connect_vsock(3).
20
21       This call returns when the connection has been made.  By default, this
22       proceeds all the way to transmission phase, but nbd_set_opt_mode(3) can
23       be used for manual control over option negotiation performed before
24       transmission phase.
25
26   Example URIs supported
27       "nbd://example.com"
28           Connect over TCP, unencrypted, to "example.com" port 10809.
29
30       "nbds://example.com"
31           Connect over TCP with TLS, to "example.com" port 10809.  If the
32           server does not support TLS then this will fail.
33
34       "nbd+unix:///foo?socket=/tmp/nbd.sock"
35           Connect over the Unix domain socket /tmp/nbd.sock to an NBD server
36           running locally.  The export name is set to "foo" (note without any
37           leading "/" character).
38
39       "nbds+unix://alice@/?socket=/tmp/nbd.sock&tls-certificates=certs"
40           Connect over a Unix domain socket, enabling TLS and setting the
41           path to a directory containing certificates and keys.
42
43       "nbd+vsock:///"
44           In this scenario libnbd is running in a virtual machine.  Connect
45           over "AF_VSOCK" to an NBD server running on the hypervisor.
46
47   Supported URI formats
48       The following schemes are supported in the current version of libnbd:
49
50       "nbd:"
51           Connect over TCP without using TLS.
52
53       "nbds:"
54           Connect over TCP.  TLS is required and the connection will fail if
55           the server does not support TLS.
56
57       "nbd+unix:"
58       "nbds+unix:"
59           Connect over a Unix domain socket, without or with TLS
60           respectively.  The "socket" parameter is required.
61
62       "nbd+vsock:"
63       "nbds+vsock:"
64           Connect over the "AF_VSOCK" transport, without or with TLS
65           respectively. You can use nbd_supports_vsock(3) to see if this
66           build of libnbd supports "AF_VSOCK".
67
68       The authority part of the URI ("[username@][servername][:port]") is
69       parsed depending on the transport.  For TCP it specifies the server to
70       connect to and optional port number.  For "+unix" it should not be
71       present.  For "+vsock" the server name is the numeric CID (eg. 2 to
72       connect to the host), and the optional port number may be present.  If
73       the "username" is present it is used for TLS authentication.
74
75       For all transports, an export name may be present, parsed in accordance
76       with the NBD URI specification.
77
78       Finally the query part of the URI can contain:
79
80       socket=SOCKET
81           Specifies the Unix domain socket to connect on.  Must be present
82           for the "+unix" transport and must not be present for the other
83           transports.
84
85       tls-certificates=DIR
86           Set the certificates directory.  See nbd_set_tls_certificates(3).
87           Note this is not allowed by default - see next section.
88
89       tls-psk-file=PSKFILE
90           Set the PSK file.  See nbd_set_tls_psk_file(3).  Note this is not
91           allowed by default - see next section.
92
93   Disable URI features
94       For security reasons you might want to disable certain URI features.
95       Pre-filtering URIs is error-prone and should not be attempted.  Instead
96       use the libnbd APIs below to control what can appear in URIs.  Note you
97       must call these functions on the same handle before calling
98       nbd_connect_uri(3) or nbd_aio_connect_uri(3).
99
100       TCP, Unix domain socket or "AF_VSOCK" transports
101           Default: all allowed
102
103           To select which transports are allowed call
104           nbd_set_uri_allow_transports(3).
105
106       TLS Default: both non-TLS and TLS connections allowed
107
108           To force TLS off or on in URIs call nbd_set_uri_allow_tls(3).
109
110       Connect to Unix domain socket in the local filesystem
111           Default: allowed
112
113           To prevent this you must disable the "+unix" transport using
114           nbd_set_uri_allow_transports(3).
115
116       Read from local files
117           Default: denied
118
119           To allow URIs to contain references to local files (eg. for
120           parameters like "tls-psk-file") call
121           nbd_set_uri_allow_local_file(3).
122
123   Overriding the export name
124       It is possible to override the export name portion of a URI by using
125       nbd_set_opt_mode(3) to enable option mode, then using
126       nbd_set_export_name(3) and nbd_opt_go(3) as part of subsequent
127       negotiation.
128
129   Optional features
130       This call will fail if libnbd was not compiled with libxml2; you can
131       test whether this is the case with nbd_supports_uri(3).
132
133       Support for URIs that require TLS will fail if libnbd was not compiled
134       with gnutls; you can test whether this is the case with
135       nbd_supports_tls(3).
136
137   Constructing a URI from an existing connection
138       See nbd_get_uri(3).
139

RETURN VALUE

141       If the call is successful the function returns 0.
142

ERRORS

144       On error -1 is returned.
145
146       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
147       of the error.
148
149       The following parameters must not be NULL: "h", "uri".  For more
150       information see "Non-NULL parameters" in libnbd(3).
151

HANDLE STATE

153       The handle must be newly created, otherwise this call will return an
154       error.
155

VERSION

157       This function first appeared in libnbd 1.0.
158
159       If you need to test if this function is available at compile time check
160       if the following macro is defined:
161
162        #define LIBNBD_HAVE_NBD_CONNECT_URI 1
163

SEE ALSO

165       nbd_aio_connect_uri(3), nbd_connect_tcp(3), nbd_connect_unix(3),
166       nbd_connect_uri(3), nbd_connect_vsock(3), nbd_create(3),
167       nbd_get_uri(3), nbd_opt_go(3), nbd_set_export_name(3),
168       nbd_set_opt_mode(3), nbd_set_tls(3), nbd_set_tls_certificates(3),
169       nbd_set_tls_psk_file(3), nbd_set_uri_allow_local_file(3),
170       nbd_set_uri_allow_tls(3), nbd_set_uri_allow_transports(3),
171       nbd_supports_tls(3), nbd_supports_uri(3), nbd_supports_vsock(3),
172       libnbd(3),
173       https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md.
174

AUTHORS

176       Eric Blake
177
178       Richard W.M. Jones
179
181       Copyright Red Hat
182

LICENSE

184       This library is free software; you can redistribute it and/or modify it
185       under the terms of the GNU Lesser General Public License as published
186       by the Free Software Foundation; either version 2 of the License, or
187       (at your option) any later version.
188
189       This library is distributed in the hope that it will be useful, but
190       WITHOUT ANY WARRANTY; without even the implied warranty of
191       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
192       Lesser General Public License for more details.
193
194       You should have received a copy of the GNU Lesser General Public
195       License along with this library; if not, write to the Free Software
196       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
197       02110-1301 USA
198
199
200
201libnbd-1.18.1                     2023-10-31                nbd_connect_uri(3)
Impressum