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