Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Philip Kovacs
Pieter Hintjens
Piotr Trojanek
Reza Ebrahimi
Remi Jouannet
Richard Newton
Rik van der Heijden
Robert G. Jakabosky
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,9 @@ set(cxx-sources
vmci_address.hpp
vmci_connecter.hpp
vmci_listener.hpp
vsock_address.hpp
vsock_connecter.hpp
vsock_listener.hpp
windows.hpp
wire.hpp
xpub.hpp
Expand Down Expand Up @@ -1233,6 +1236,10 @@ message(STATUS "Building with VMCI")
list(APPEND cxx-sources vmci_address.cpp vmci_connecter.cpp vmci_listener.cpp vmci.cpp)
endif()

if(ZMQ_HAVE_VSOCK)
list(APPEND cxx-sources vsock_address.cpp vsock_connecter.cpp vsock_listener.cpp)
endif()

if(ZMQ_HAVE_TIPC)
list(APPEND cxx-sources tipc_address.cpp tipc_connecter.cpp tipc_listener.cpp)
endif()
Expand Down
19 changes: 19 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ src_libzmq_la_SOURCES = \
src/vmci_connecter.hpp \
src/vmci_listener.cpp \
src/vmci_listener.hpp \
src/vsock_address.cpp \
src/vsock_address.hpp \
src/vsock_connecter.cpp \
src/vsock_connecter.hpp \
src/vsock_listener.cpp \
src/vsock_listener.hpp \
src/windows.hpp \
src/wire.hpp \
src/xpub.cpp \
Expand Down Expand Up @@ -1047,6 +1053,19 @@ tests_test_reqrep_vmci_CXXFLAGS = @LIBZMQ_VMCI_CXXFLAGS@

endif

if BUILD_VSOCK
test_apps += tests/test_pair_vsock tests/test_reqrep_vsock

tests_test_pair_vsock_SOURCES = tests/test_pair_vsock.cpp
tests_test_pair_vsock_LDADD = ${TESTUTIL_LIBS} src/libzmq.la
tests_test_pair_vsock_CPPFLAGS = ${TESTUTIL_CPPFLAGS}

tests_test_reqrep_vsock_SOURCES = tests/test_reqrep_vsock.cpp
tests_test_reqrep_vsock_LDADD = ${TESTUTIL_LIBS} src/libzmq.la
tests_test_reqrep_vsock_CPPFLAGS = ${TESTUTIL_CPPFLAGS}

endif

if ENABLE_DRAFTS
test_apps += tests/test_poller \
tests/test_client_server \
Expand Down
1 change: 1 addition & 0 deletions builds/cmake/platform.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#cmakedefine ZMQ_HAVE_OPENPGM
#cmakedefine ZMQ_HAVE_NORM
#cmakedefine ZMQ_HAVE_VMCI
#cmakedefine ZMQ_HAVE_VSOCK

#cmakedefine ZMQ_MAKE_VALGRIND_HAPPY

Expand Down
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ AC_RUN_IFELSE(

AC_MSG_RESULT([$libzmq_tipc_support])


# check vsock support
AC_MSG_CHECKING([if vsock is available ])

AC_CHECK_HEADERS([linux/vm_sockets.h],
[libzmq_vsock_support=yes],
[libzmq_vsock_support=no],
[
#include <sys/socket.h>
#include <linux/vm_sockets.h>
]
)


AC_ARG_ENABLE([pedantic],
[AS_HELP_STRING([--disable-pedantic], [disable pedantic compiler checks [default=enabled]])],
[libzmq_pedantic=$enableval], [libzmq_pedantic=yes])
Expand Down Expand Up @@ -235,6 +249,10 @@ case "${host_os}" in
if test "x$libzmq_tipc_support" = "xyes"; then
AC_DEFINE(ZMQ_HAVE_TIPC, 1, [Have TIPC support])
fi

if test "x$libzmq_vsock_support" = "xyes"; then
AC_DEFINE(ZMQ_HAVE_VSOCK, 1, [Have vsock support])
fi
case "${host_os}" in
*android*)
AC_DEFINE(ZMQ_HAVE_ANDROID, 1, [Have Android OS])
Expand Down Expand Up @@ -774,6 +792,7 @@ fi

AM_CONDITIONAL(HAVE_VMCI, test "x$have_vmci_ext" != "xno")


# Set -Wall, -Werror and -pedantic
AC_LANG_PUSH([C++])

Expand All @@ -789,6 +808,7 @@ if test "x$libzmq_pedantic" = "xyes"; then
fi
AC_LANG_POP([C++])

AM_CONDITIONAL(BUILD_VSOCK, test "x$libzmq_vsock_support" = "xyes")
AM_CONDITIONAL(BUILD_TIPC, test "x$libzmq_tipc_support" = "xyes")
AM_CONDITIONAL(ON_MINGW, test "x$libzmq_on_mingw" = "xyes")
AM_CONDITIONAL(ON_CYGWIN, test "x$libzmq_on_cygwin" = "xyes")
Expand Down
2 changes: 1 addition & 1 deletion doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MAN3 = \
MAN7 = \
zmq.7 zmq_tcp.7 zmq_pgm.7 zmq_inproc.7 zmq_ipc.7 \
zmq_null.7 zmq_plain.7 zmq_curve.7 zmq_tipc.7 zmq_vmci.7 zmq_udp.7 \
zmq_gssapi.7
zmq_gssapi.7 zmq_vsock.7

# ASCIIDOC_DOC_WITHOUT_INDEX contains all the Asciidoc files checked into the git repo, except for index.adoc
ASCIIDOC_DOC_WITHOUT_INDEX = $(MAN3:%.3=%.adoc) $(MAN7:%.7=%.adoc)
Expand Down
4 changes: 3 additions & 1 deletion doc/zmq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ Local inter-process communication transport::
Local in-process (inter-thread) communication transport::
* xref:zmq_inproc.adoc[zmq_inproc]

Virtual Machine Communications Interface (VMC) transport::
Virtual Machine Communications Interface (VMCI) transport::
* xref:zmq_vmci.adoc[zmq_vmci]

Unreliable unicast and multicast using UDP::
* xref:zmq_udp.adoc[zmq_udp]

Linux VSOCK (AF_VSOCK) transport::
* xref:zmq_vsock.adoc[zmq_vsock]

Proxies
~~~~~~~
Expand Down
7 changes: 4 additions & 3 deletions doc/zmq_bind.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ The 'endpoint' is a string consisting of a 'transport'`://` followed by an
'pgm', 'epgm':: reliable multicast transport using PGM, see xref:zmq_pgm.adoc[zmq_pgm]
'vmci':: virtual machine communications interface (VMCI), see xref:zmq_vmci.adoc[zmq_vmci]
'udp':: unreliable unicast and multicast using UDP, see xref:zmq_udp.adoc[zmq_udp]
'vsock':: Linux VSOCK, see xref:zmq_vsock.adoc[zmq_vsock]

Every 0MQ socket type except 'ZMQ_PAIR' and 'ZMQ_CHANNEL' supports one-to-many and many-to-one
semantics. The precise semantics depend on the socket type and are defined in
xref:zmq_socket.adoc[zmq_socket]

The 'ipc', 'tcp', 'vmci' and 'udp' transports accept wildcard addresses: see
xref:zmq_ipc.adoc[zmq_ipc], xref:zmq_tcp.adoc[zmq_tcp], xref:zmq_vmci.adoc[zmq_vmci] and
xref:zmq_udp.adoc[zmq_udp] for details.
The 'ipc', 'tcp', 'vmci', 'udp' and 'vsock' transports accept wildcard addresses: see
xref:zmq_ipc.adoc[zmq_ipc], xref:zmq_tcp.adoc[zmq_tcp], xref:zmq_vmci.adoc[zmq_vmci],
xref:zmq_udp.adoc[zmq_udp] and xref:zmq_vsock.adoc[zmq_vsock] for details.

NOTE: the address syntax may be different for _zmq_bind()_ and _zmq_connect()_
especially for the 'tcp', 'pgm' and 'epgm' transports.
Expand Down
1 change: 1 addition & 0 deletions doc/zmq_connect.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The 'endpoint' is a string consisting of a 'transport'`://` followed by an
'pgm', 'epgm':: reliable multicast transport using PGM, see xref:zmq_pgm.adoc[zmq_pgm]
'vmci':: virtual machine communications interface (VMCI), see xref:zmq_vmci.adoc[zmq_vmci]
'udp':: unreliable unicast and multicast using UDP, see xref:zmq_udp.adoc[zmq_udp]
'vsock':: Linux VSOCK, see xref:zmq_vsock.adoc[zmq_vsock]

Every 0MQ socket type except 'ZMQ_PAIR' and 'ZMQ_CHANNEL' supports one-to-many and many-to-one
semantics. The precise semantics depend on the socket type and are defined in
Expand Down
1 change: 1 addition & 0 deletions doc/zmq_inproc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ assert (rc == 0);
* xref:zmq_tcp.adoc[zmq_tcp]
* xref:zmq_pgm.adoc[zmq_pgm]
* xref:zmq_vmci.adoc[zmq_vmci]
* xref:zmq_vsock.adoc[zmq_vsock]
* xref:zmq.adoc[zmq]


Expand Down
1 change: 1 addition & 0 deletions doc/zmq_ipc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ assert (rc == 0);
* xref:zmq_tcp.adoc[zmq_tcp]
* xref:zmq_pgm.adoc[zmq_pgm]
* xref:zmq_vmci.adoc[zmq_vmci]
* xref:zmq_vsock.adoc[zmq_vsock]
* xref:zmq_getsockopt.adoc[zmq_getsockopt]
* xref:zmq.adoc[zmq]

Expand Down
1 change: 1 addition & 0 deletions doc/zmq_pgm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ assert (rc == 0);
* xref:zmq_ipc.adoc[zmq_ipc]
* xref:zmq_inproc.adoc[zmq_inproc]
* xref:zmq_vmci.adoc[zmq_vmci]
* xref:zmq_vsock.adoc[zmq_vsock]
* xref:zmq.adoc[zmq]


Expand Down
1 change: 1 addition & 0 deletions doc/zmq_tcp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ assert (rc == 0);
* xref:zmq_ipc.adoc[zmq_ipc]
* xref:zmq_inproc.adoc[zmq_inproc]
* xref:zmq_vmci.adoc[zmq_vmci]
* xref:zmq_vsock.adoc[zmq_vsock]
* xref:zmq.adoc[zmq]


Expand Down
1 change: 1 addition & 0 deletions doc/zmq_tipc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ assert (rc == 0);
* xref:zmq_ipc.adoc[zmq_ipc]
* xref:zmq_inproc.adoc[zmq_inproc]
* xref:zmq_vmci.adoc[zmq_vmci]
* xref:zmq_vsock.adoc[zmq_vsock]
* xref:zmq.adoc[zmq]


Expand Down
1 change: 1 addition & 0 deletions doc/zmq_udp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ assert (rc == 0);
* xref:zmq_ipc.adoc[zmq_ipc]
* xref:zmq_inproc.adoc[zmq_inproc]
* xref:zmq_vmci.adoc[zmq_vmci]
* xref:zmq_vsock.adoc[zmq_vsock]
* xref:zmq.adoc[zmq]


Expand Down
3 changes: 2 additions & 1 deletion doc/zmq_unbind.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ The 'endpoint' argument is as described in xref:zmq_bind.adoc[zmq_bind]
Unbinding wild-card address from a socket
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When wild-card `*` 'endpoint' (described in xref:zmq_tcp.adoc[zmq_tcp],
xref:zmq_ipc.adoc[zmq_ipc], xref:zmq_udp.adoc[zmq_udp] and xref:zmq_vmci.adoc[zmq_vmci]) was used in
xref:zmq_ipc.adoc[zmq_ipc], xref:zmq_udp.adoc[zmq_udp],
xref:zmq_vmci.adoc[zmq_vmci] and xref:zmq_vsock.adoc[zmq_vsock]) was used in
_zmq_bind()_, the caller should use real 'endpoint' obtained from the
ZMQ_LAST_ENDPOINT socket option to unbind this 'endpoint' from a socket.

Expand Down
2 changes: 1 addition & 1 deletion doc/zmq_vmci.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


== NAME
zmq_vmci - 0MQ transport over virtual machine communicatios interface (VMCI) sockets
zmq_vmci - 0MQ transport over virtual machine communications interface (VMCI) sockets


== SYNOPSIS
Expand Down
90 changes: 90 additions & 0 deletions doc/zmq_vsock.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
= zmq_vsock(7)


== NAME
zmq_vsock - 0MQ transport over Linux VSOCK (AF_VSOCK)


== SYNOPSIS
The AF_VSOCK address family facilitates communication between virtual machines and the host they are running on.
This address family is used by guest agents and hypervisor services that need a communications channel that is independent of virtual machine network configuration.

NOTE: AF_VSOCK is only supported on linux, <https://man7.org/linux/man-pages/man7/vsock.7.html>


== ADDRESSING
A 0MQ endpoint is a string consisting of a 'transport'`://` followed by an
'address'. The 'transport' specifies the underlying protocol to use. The
'address' specifies the transport-specific address to connect to.

For the VSOCK transport, the transport is `vsock`, and the meaning of
the 'address' part is defined below.


Binding a socket
~~~~~~~~~~~~~~~~
When binding a 'socket' to a local address using _zmq_bind()_ with the 'vsock'
transport, the 'endpoint' shall be interpreted as an 'interface' followed by a
colon and the port number to use.

An 'interface' may be specified by either of the following:

* The wild-card `*`, meaning all available interfaces.
* An integer returned by `VMADDR_CID_LOCAL` or `@`.

The port may be specified by:

* A numeric value, usually above 1024 on POSIX systems.
* The wild-card `*`, meaning a system-assigned ephemeral port.

Unbinding wild-card address from a socket
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When wild-card `*` 'endpoint' was used in _zmq_bind()_, the caller should use
real 'endpoint' obtained from the ZMQ_LAST_ENDPOINT socket option to unbind
this 'endpoint' from a socket using _zmq_unbind()_.

Connecting a socket
~~~~~~~~~~~~~~~~~~~
When connecting a socket to a peer address using _zmq_connect()_ with the 'vsock'
transport, the 'endpoint' shall be interpreted as a 'peer address' followed by
a colon and the port number to use.

A 'peer address' must be a CID of the peer.


== EXAMPLES
.Assigning a local address to a socket
----
// VSOCK port 5555 on all available interfaces
rc = zmq_bind(socket, "vsock://*:5555");
assert (rc == 0);
// VSOCK port 5555 on the local loop-back interface on all platforms
cid = VMADDR_CID_LOCAL;
sprintf(endpoint, "vsock://%d:5555", cid);
rc = zmq_bind(socket, endpoint);
assert (rc == 0);
----

.Connecting a socket
----
// Connecting using a CID
sprintf(endpoint, "vsock://%d:5555", cid);
rc = zmq_connect(socket, endpoint);
assert (rc == 0);
----


== SEE ALSO
* xref:zmq_bind.adoc[zmq_bind]
* xref:zmq_connect.adoc[zmq_connect]
* xref:zmq_inproc.adoc[zmq_inproc]
* xref:zmq_tcp.adoc[zmq_tcp]
* xref:zmq_pgm.adoc[zmq_pgm]
* xref:zmq_vsock.adoc[zmq_vsock]
* xref:zmq_getsockopt.adoc[zmq_getsockopt]
* xref:zmq.adoc[zmq]


== AUTHORS
This page was written by the 0MQ community. To make a change please
read the 0MQ Contribution Policy at <https://zeromq.org/how-to-contribute/>.
20 changes: 20 additions & 0 deletions src/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
#include "tipc_address.hpp"
#include "ws_address.hpp"

#if defined ZMQ_HAVE_VSOCK
// fix header conflict with VMCI
#define sockaddr_vm linux_sockaddr_vm
#define VMADDR_PORT_ANY LINUX_VMADDR_PORT_ANY
#define VMADDR_CID_ANY LINUX_VMADDR_CID_ANY
#include "vsock_address.hpp"
#undef sockaddr_vm
#undef VMADDR_CID_ANY
#undef VMADDR_PORT_ANY
#endif

#if defined ZMQ_HAVE_VMCI
#include "vmci_address.hpp"
#endif
Expand Down Expand Up @@ -60,6 +71,11 @@ zmq::address_t::~address_t ()
LIBZMQ_DELETE (resolved.vmci_addr);
}
#endif
#if defined ZMQ_HAVE_VSOCK
else if (protocol == protocol_name::vsock) {
LIBZMQ_DELETE (resolved.vsock_addr);
}
#endif
}

int zmq::address_t::to_string (std::string &addr_) const
Expand Down Expand Up @@ -88,6 +104,10 @@ int zmq::address_t::to_string (std::string &addr_) const
if (protocol == protocol_name::vmci && resolved.vmci_addr)
return resolved.vmci_addr->to_string (addr_);
#endif
#if defined ZMQ_HAVE_VSOCK
if (protocol == protocol_name::vsock && resolved.vsock_addr)
return resolved.vsock_addr->to_string (addr_);
#endif

if (!protocol.empty () && !address.empty ()) {
std::stringstream s;
Expand Down
9 changes: 9 additions & 0 deletions src/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class tipc_address_t;
#if defined ZMQ_HAVE_VMCI
class vmci_address_t;
#endif
#if defined ZMQ_HAVE_VSOCK
class vsock_address_t;
#endif

namespace protocol_name
{
Expand Down Expand Up @@ -59,6 +62,9 @@ static const char tipc[] = "tipc";
#if defined ZMQ_HAVE_VMCI
static const char vmci[] = "vmci";
#endif
#if defined ZMQ_HAVE_VSOCK
static const char vsock[] = "vsock";
#endif
}

struct address_t
Expand Down Expand Up @@ -94,6 +100,9 @@ struct address_t
#endif
#if defined ZMQ_HAVE_VMCI
vmci_address_t *vmci_addr;
#endif
#if defined ZMQ_HAVE_VSOCK
vsock_address_t *vsock_addr;
#endif
} resolved;

Expand Down
Loading
Loading