Skip to content
Tech News
← Back to articles

Use Vsock with Libzmq

read original get ZeroMQ: Messaging for Many Applications (O'Reilly, Pieter Hintjens) → more articles
Why This Matters

VSOCK (AF_VSOCK) has been in the Linux kernel since 4.8 as a socket family for guest-to-hypervisor and guest-to-guest communication, and it now underpins features like AWS Nitro Enclaves. Until now developers had only low-level bindings, so adding support in libzmq gives them a familiar high-level messaging abstraction instead of hand-rolling socket code.

Key Takeaways
Worth a Look

ZeroMQ: Messaging for Many Applications (O'Reilly, Pieter Hintjens) — If you're wiring libzmq up to new transports like AF_VSOCK, Pieter Hintjens' ZeroMQ book is the canonical guide to socket patterns, framing and messaging architecture. It walks through the pub/sub, request/reply and pipeline patterns you'll be running over whatever transport you choose, hypervisor sockets included.

See ZeroMQ: Messaging for Many Applications (O'Reilly, Pieter Hintjens) on Amazon → Affiliate link — we may earn a commission on purchases, at no extra cost to you. Product picked by AI based on this article; it is not a tested recommendation.

Use VSOCK with libzmq

AF_VSOCK

VSOCK is not new anymore it has been around in Linux kernel since 4.8. For those who do not know what this is, it was previously developed by VMware under the name VMCI. AF_VSOCK is a socket address family like AF_INET or AF_UNIX. It’s an address family designed for communication between a VM (guest) and the underlying hypervisor (host), you can also build communication between multiple guests on the same host. Previously, this kind of communication was done with a serial port, a great example is https://pve.proxmox.com/wiki/Qemu-guest-agent.

AF_VSOCK looks and feels like a Unix socket with TCP/UDP-like features. You have addresses and ports, you also have stream and datagram.

The man page https://man7.org/linux/man-pages/man7/vsock.7.html

You have 32-bit addresses that are called “context identifier”, with reserved CID: VMADDR_CID_ANY, VMADDR_CID_HYPERVISOR, VMADDR_CID_LOCAL (new in 5.6), VMADDR_CID_HOST. Regarding port numbers, you can allocate 32-bit ports and those under 1024 need root access. just like TCP/UDP you can then have different communication with the same CID by using different port.

VSOCK has been around for some time, but the support is growing slowly. Python/C/Golang/rust support it and you have some basic tools and SDK.

https://stefano-garzarella.github.io/posts/2021-01-22-socat-vsock/

https://github.com/rust-vsock/tokio-vsock

https://mdlayher.com/blog/linux-vm-sockets-in-go/

... continue reading