Supporting VSOCK address family
Raimo Niskanen
raimo+erlang-questions@REDACTED
Wed Nov 17 11:47:29 CET 2021
On Wed, Oct 27, 2021 at 02:54:30AM +0000, Ali Shirvani wrote:
> Hello everyone,
> As I found, current socket NIF does not support Linux VSOCK[1] address family.
> Regarding the recommendation in the Erlang/OTP contribution guide, I am writing to discuss adding the VSOCK address family to the socket NIF.
>
> I will be happy to implement this feature, and it would be great if you could give me some advice.
Sorry about the delay! We are currently working on adding IOCtl:s
and rewriting the error handling in socket completely, so it is
a somewhat awkward question what would be the best advice to you...
I see no problem about adding AF_VSOCK on platforms where it is
supported, i.e Linux.
This would be a feature addition for the 'master' branch to be
released at the earliest in OTP-25.0. Hopefully the needed
changes does not collide too much with our ongoing work,
so you might get away with creating a topic branch from
OTP-24.1, or wait for OTP-24.2. Should merge conflicts
emerge you may need to rebase to a fresh 'master'.
The changes I foresee
---------------------
lib/kernel/socket.erl:
* Add 'vsock' to the type domain().
* Add a record type sockaddr_vm() with mandatory field
family := 'vsock', and optional fields
cid => any | hypervisor | reserved | host | 0..16#FFFFFFFF
port => any | 0..16#FFFFFFFF
* I do not know if it would be desired to have translations in
bind/2 for 'any' -> #{family => vsock, cid => any, port => any}
and 'loopback' -> #{family => vsock, cid => host, port => any}
for domain vsock?
erts/preloaded/src/prim_socket.erl:
* Add a macro ESOCK_SOCKADDR_VSOCK_DEFAULTS:
#{family => vsock, port => any, cid => any}
* Add handling of the defaults in enc_sockaddr/1 like for e.g 'unspec'.
erts/emulator/nifs/common/socket_int.h:
* Add struct sockaddr_vm to typedef union ESockAddress
erts/emulator/nifs/common/socket_util.c:
* Add 'vsock' to esock_decode_domain() and esock_encode_domain()
* Add functions esock_decode_sockaddr_vsock()
and esock_encode_sockaddr_vsock(). These need to handle
'any', 'hypervisor', 'reserved' and 'host' and translate to/from
VMADDR_CID_* and VMADDR_PORT_ANY.
* Add those functions to esock_decode_sockaddr()
and esock_encode_sockaddr()
In general: search for AF_INET, AF_INET6 and AF_LOCAL in the C files
for socket to see where something equivalent should be added for AF_VSOCK.
Good luck!
/ Raimo
>
> Regards,
> Ali
>
> [1] https://man7.org/linux/man-pages/man7/vsock.7.html
>
> Sent with [ProtonMail](https://protonmail.com/) Secure Email.
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list