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 (struct nbd_handle *h, const char *uri);
12

DESCRIPTION

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

RETURN VALUE

121       If the call is successful the function returns 0.
122

ERRORS

124       On error "-1" is returned.
125
126       Refer to "ERROR HANDLING" in libnbd(3) for how to get further details
127       of the error.
128

HANDLE STATE

130       The handle must be newly created, otherwise this call will return an
131       error.
132

VERSION

134       This function first appeared in libnbd 1.0.
135
136       If you need to test if this function is available at compile time check
137       if the following macro is defined:
138
139        #define LIBNBD_HAVE_NBD_CONNECT_URI 1
140

SEE ALSO

142       nbd_aio_connect_uri(3), nbd_connect_tcp(3), nbd_connect_unix(3),
143       nbd_connect_uri(3), nbd_create(3), nbd_opt_go(3),
144       nbd_set_export_name(3), nbd_set_opt_mode(3), nbd_set_tls(3),
145       nbd_set_tls_psk_file(3), nbd_set_uri_allow_local_file(3),
146       nbd_set_uri_allow_tls(3), nbd_set_uri_allow_transports(3),
147       nbd_supports_tls(3), nbd_supports_uri(3), libnbd(3),
148       https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md.
149

AUTHORS

151       Eric Blake
152
153       Richard W.M. Jones
154
156       Copyright (C) 2019-2020 Red Hat Inc.
157

LICENSE

159       This library is free software; you can redistribute it and/or modify it
160       under the terms of the GNU Lesser General Public License as published
161       by the Free Software Foundation; either version 2 of the License, or
162       (at your option) any later version.
163
164       This library is distributed in the hope that it will be useful, but
165       WITHOUT ANY WARRANTY; without even the implied warranty of
166       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
167       Lesser General Public License for more details.
168
169       You should have received a copy of the GNU Lesser General Public
170       License along with this library; if not, write to the Free Software
171       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
172       02110-1301 USA
173
174
175
176libnbd-1.6.2                      2021-03-02                nbd_connect_uri(3)
Impressum