1nbd_connect_uri(3) LIBNBD nbd_connect_uri(3)
2
3
4
6 nbd_connect_uri - connect to NBD URI
7
9 #include <libnbd.h>
10
11 int nbd_connect_uri (struct nbd_handle *h, const char *uri);
12
14 Connect (synchronously) to an NBD server and export by specifying the
15 NBD URI. This call parses the URI and calls nbd_set_export_name(3) and
16 nbd_set_tls(3) and other calls as needed, followed by
17 nbd_connect_tcp(3) or nbd_connect_unix(3).
18
19 This call returns when the connection has been made.
20
21 Example URIs supported
22 "nbd://example.com"
23 Connect over TCP, unencrypted, to "example.com" port 10809.
24
25 "nbds://example.com"
26 Connect over TCP with TLS, to "example.com" port 10809. If the
27 server does not support TLS then this will fail.
28
29 "nbd+unix:///foo?socket=/tmp/nbd.sock"
30 Connect over the Unix domain socket /tmp/nbd.sock to an NBD server
31 running locally. The export name is set to "foo" (note without any
32 leading "/" character).
33
34 "nbds+unix://alice@/?socket=/tmp/nbd.sock&tls-certificates=certs"
35 Connect over a Unix domain socket, enabling TLS and setting the
36 path to a directory containing certificates and keys.
37
38 "nbd+vsock:///"
39 In this scenario libnbd is running in a virtual machine. Connect
40 over "AF_VSOCK" to an NBD server running on the hypervisor.
41
42 Supported URI formats
43 The following schemes are supported in the current version of libnbd:
44
45 "nbd:"
46 Connect over TCP without using TLS.
47
48 "nbds:"
49 Connect over TCP. TLS is required and the connection will fail if
50 the server does not support TLS.
51
52 "nbd+unix:"
53 "nbds+unix:"
54 Connect over a Unix domain socket, without or with TLS
55 respectively. The "socket" parameter is required.
56
57 "nbd+vsock:"
58 "nbds+vsock:"
59 Connect over the "AF_VSOCK" transport, without or with TLS
60 respectively.
61
62 The authority part of the URI ("[username@][servername][:port]") is
63 parsed depending on the transport. For TCP it specifies the server to
64 connect to and optional port number. For "+unix" it should not be
65 present. For "+vsock" the server name is the numeric CID (eg. 2 to
66 connect to the host), and the optional port number may be present. If
67 the "username" is present it is used for TLS authentication.
68
69 For all transports, an export name may be present, parsed in accordance
70 with the NBD URI specification.
71
72 Finally the query part of the URI can contain:
73
74 socket=SOCKET
75 Specifies the Unix domain socket to connect on. Must be present
76 for the "+unix" transport and must not be present for the other
77 transports.
78
79 tls-certificates=DIR
80 Set the certificates directory. See nbd_set_tls_certificates(3).
81 Note this is not allowed by default - see next section.
82
83 tls-psk-file=PSKFILE
84 Set the PSK file. See nbd_set_tls_psk_file(3). Note this is not
85 allowed by default - see next section.
86
87 Disable URI features
88 For security reasons you might want to disable certain URI features.
89 Pre-filtering URIs is error-prone and should not be attempted. Instead
90 use the libnbd APIs below to control what can appear in URIs. Note you
91 must call these functions on the same handle before calling
92 nbd_connect_uri(3) or nbd_aio_connect_uri(3).
93
94 TCP, Unix domain socket or "AF_VSOCK" transports
95 Default: all allowed
96
97 To select which transports are allowed call
98 nbd_set_uri_allow_transports(3).
99
100 TLS Default: both non-TLS and TLS connections allowed
101
102 To force TLS off or on in URIs call nbd_set_uri_allow_tls(3).
103
104 Connect to Unix domain socket in the local filesystem
105 Default: allowed
106
107 To prevent this you must disable the "+unix" transport using
108 nbd_set_uri_allow_transports(3).
109
110 Read from local files
111 Default: denied
112
113 To allow URIs to contain references to local files (eg. for
114 parameters like "tls-psk-file") call
115 nbd_set_uri_allow_local_file(3).
116
117 Overriding the export name
118 It is possible to override the export name portion of a URI by using
119 nbd_set_opt_mode(3) to enable option mode, then using
120 nbd_set_export_name(3) and nbd_opt_go(3) as part of subsequent
121 negotiation.
122
123 Optional features
124 This call will fail if libnbd was not compiled with libxml2; you can
125 test whether this is the case with nbd_supports_uri(3).
126
127 Support for URIs that require TLS will fail if libnbd was not compiled
128 with gnutls; you can test whether this is the case with
129 nbd_supports_tls(3).
130
131 Constructing a URI from an existing connection
132 See nbd_get_uri(3).
133
135 If the call is successful the function returns 0.
136
138 On error "-1" is returned.
139
140 Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
141 of the error.
142
144 The handle must be newly created, otherwise this call will return an
145 error.
146
148 This function first appeared in libnbd 1.0.
149
150 If you need to test if this function is available at compile time check
151 if the following macro is defined:
152
153 #define LIBNBD_HAVE_NBD_CONNECT_URI 1
154
156 nbd_aio_connect_uri(3), nbd_connect_tcp(3), nbd_connect_unix(3),
157 nbd_connect_uri(3), nbd_create(3), nbd_get_uri(3), nbd_opt_go(3),
158 nbd_set_export_name(3), nbd_set_opt_mode(3), nbd_set_tls(3),
159 nbd_set_tls_certificates(3), nbd_set_tls_psk_file(3),
160 nbd_set_uri_allow_local_file(3), nbd_set_uri_allow_tls(3),
161 nbd_set_uri_allow_transports(3), nbd_supports_tls(3),
162 nbd_supports_uri(3), libnbd(3),
163 https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md.
164
166 Eric Blake
167
168 Richard W.M. Jones
169
171 Copyright (C) 2019-2021 Red Hat Inc.
172
174 This library is free software; you can redistribute it and/or modify it
175 under the terms of the GNU Lesser General Public License as published
176 by the Free Software Foundation; either version 2 of the License, or
177 (at your option) any later version.
178
179 This library is distributed in the hope that it will be useful, but
180 WITHOUT ANY WARRANTY; without even the implied warranty of
181 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
182 Lesser General Public License for more details.
183
184 You should have received a copy of the GNU Lesser General Public
185 License along with this library; if not, write to the Free Software
186 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
187 02110-1301 USA
188
189
190
191libnbd-1.12.5 2022-07-10 nbd_connect_uri(3)