nbd_connect_uri(3) | LIBNBD | nbd_connect_uri(3) |
nbd_connect_uri - connect to NBD URI
#include <libnbd.h> int nbd_connect_uri (struct nbd_handle *h, const char *uri);
Connect (synchronously) to an NBD server and export by specifying the NBD URI. This call parses the URI and calls nbd_set_export_name(3) and nbd_set_tls(3) and other calls as needed, followed by nbd_connect_tcp(3) or nbd_connect_unix(3).
This call returns when the connection has been made.
The following schemes are supported in the current version of libnbd:
The authority part of the URI ("[username@][servername][:port]") is parsed depending on the transport. For TCP it specifies the server to connect to and optional port number. For "+unix" it should not be present. For "+vsock" the server name is the numeric CID (eg. 2 to connect to the host), and the optional port number may be present. If the "username" is present it is used for TLS authentication.
For all transports, an export name may be present, parsed in accordance with the NBD URI specification.
Finally the query part of the URI can contain:
For security reasons you might want to disable certain URI features. Pre-filtering URIs is error-prone and should not be attempted. Instead use the libnbd APIs below to control what can appear in URIs. Note you must call these functions on the same handle before calling nbd_connect_uri(3) or nbd_aio_connect_uri(3).
To select which transports are allowed call nbd_set_uri_allow_transports(3).
To force TLS off or on in URIs call nbd_set_uri_allow_tls(3).
To prevent this you must disable the "+unix" transport using nbd_set_uri_allow_transports(3).
To allow URIs to contain references to local files (eg. for parameters like "tls-psk-file") call nbd_set_uri_allow_local_file(3).
It is possible to override the export name portion of a URI by using nbd_set_opt_mode(3) to enable option mode, then using nbd_set_export_name(3) and nbd_opt_go(3) as part of subsequent negotiation.
This call will fail if libnbd was not compiled with libxml2; you can test whether this is the case with nbd_supports_uri(3).
Support for URIs that require TLS will fail if libnbd was not compiled with gnutls; you can test whether this is the case with nbd_supports_tls(3).
See nbd_get_uri(3).
If the call is successful the function returns 0.
On error "-1" is returned.
Refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error.
The following parameters must not be NULL: "h", "uri". For more information see "Non-NULL parameters" in libnbd(3).
The handle must be newly created, otherwise this call will return an error.
This function first appeared in libnbd 1.0.
If you need to test if this function is available at compile time check if the following macro is defined:
#define LIBNBD_HAVE_NBD_CONNECT_URI 1
nbd_aio_connect_uri(3), nbd_connect_tcp(3), nbd_connect_unix(3), nbd_connect_uri(3), nbd_create(3), nbd_get_uri(3), nbd_opt_go(3), nbd_set_export_name(3), nbd_set_opt_mode(3), nbd_set_tls(3), nbd_set_tls_certificates(3), nbd_set_tls_psk_file(3), nbd_set_uri_allow_local_file(3), nbd_set_uri_allow_tls(3), nbd_set_uri_allow_transports(3), nbd_supports_tls(3), nbd_supports_uri(3), libnbd(3), https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md.
Eric Blake
Richard W.M. Jones
Copyright (C) 2019-2021 Red Hat Inc.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2023-01-04 | libnbd-1.14.2 |