vsock-udp (VM Socket UDP | WIP)

Header: udo/vsock-udp.h

Table of contents (click to go)

Macros

Enums

Unions

Structs

  1. udo_vsock_udp

  2. udo_vsock_udp_server_create_info

  3. udo_vsock_udp_client_create_info

Functions

  1. udo_vsock_udp_server_create()

  2. udo_vsock_udp_server_accept()

  3. udo_vsock_udp_server_recv_data()

  4. udo_vsock_udp_client_create()

  5. udo_vsock_udp_client_connect()

  6. udo_vsock_udp_client_send_data()

  7. udo_vsock_udp_get_fd()

  8. udo_vsock_udp_get_vcid()

  9. udo_vsock_udp_get_port()

  10. udo_vsock_udp_destroy()

  11. udo_vsock_udp_get_sizeof()

  12. udo_vsock_udp_get_local_vcid()

  13. udo_vsock_udp_recv_data()

  14. udo_vsock_udp_send_data()

API Documentation

Kernel Modules

On Host Machine

sudo modprobe -a vhost_vsock vsock_loopback

Guest Machine Kernel Config Symbols

CONFIG_PCI=Y
CONFIG_VIRTIO_MENU=y
CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_BALLON=y
CONFIG_VSOCKETS_DIAG=y

CONFIG_NET=y
CONFIG_VSOCKETS=y
CONFIG_VIRTIO_VSOCKETS=y

udo_vsock_udp (private)

Structure defining UDO VM Socket UDP context.
struct udo_vsock_udp
struct udo_log_error_struct err;
bool free;
int fd;
uint32_t vcid;
int port;
struct sockaddr_vm addr;
err
Stores information about the error that occured
for the given context and may later be retrieved
by caller.
free
If structure allocated with calloc(3) member will be
set to true so that, we know to call free(3) when
destroying the context.
fd
File descriptor to the open VM socket.
vcid
VM Context Identifier.
port
Network port number to recvfrom(2)/sendto(2) with.
addr
Stores byte information about the VM socket context.
Is used for client connect(2) and server bind(2)/connect(2).

udo_vsock_udp_server_create_info

Structure passed to udo_vsock_udp_server_create()
used to define how to create the server.
struct udo_vsock_udp_server_create_info
uint32_t vcid;
int port;
vcid
VM Context Identifier to recvfrom(2)/sendto(2) data with.
port
Network port to recvfrom(2)/sendto(2) data with.

udo_vsock_udp_server_create

struct udo_vsock_udp *udo_vsock_udp_server_create(struct udo_vsock_udp *vsock, const void *vsock_info);
Creates a VM socket that may be utilized for server socket operations.

Param

Decription

vsock

May be NULL or a pointer to a struct udo_vsock_udp.
If NULL memory will be allocated and return to
caller. If not NULL address passed will be used
to store the newly created struct udo_vsock_udp
context.

vsock_info

Implementation uses a pointer to a
Returns:
on success: Pointer to a struct udo_vsock_udp
on failure: NULL

udo_vsock_udp_server_accept

int udo_vsock_udp_server_accept(struct udo_vsock_udp *vsock, const struct sockaddr_vm *addr);
Creates file descriptor that can filter for
addr data comming to server file descriptor.
Useful to utilize in an epoll(2) event loop
if caller wants to implement tcp like event
handling with UDP sockets.

Param

Decription

vsock

Must pass a pointer to a struct udo_vsock_udp.

addr

Must pass a pointer to a populated struct sockaddr_vm.
Returns:
on success: Open file descriptor to filtered socket
on failure: -1

udo_vsock_udp_server_recv_data

ssize_t udo_vsock_udp_server_recv_data(struct udo_vsock_udp *vsock, void *data, const size_t size, struct sockaddr_vm *addr, const void *vsock_info);
Receive data from server socket file descriptor.

Param

Decription

vsock

Pointer to a struct udo_vsock_udp context.

data

Pointer to buffer to store data received from a socket.

size

Size of data to receive from a socket.

addr

Pointer to struct sockaddr_vm which stores the
address information of the socket that data
was received from.

vsock_info

Reserved for future usage. For now used
to set the flag argument of recvfrom(2).
Returns:
on success: Amount of bytes received
on failure: # < 0

udo_vsock_udp_client_create_info

Structure passed to udo_vsock_udp_client_create()
used to define how to create the client.
struct udo_vsock_udp_client_create_info
uint32_t vcid;
int port;
vcid
VM Context Identifier to sendto(2)/recvfrom(2) data with.
port
Network port to sendto(2)/recvfrom(2) data with.

udo_vsock_udp_client_create

struct udo_vsock_udp *udo_vsock_udp_client_create(struct udo_vsock_udp *vsock, const void *vsock_info);
Creates a VM socket that may be utilized for client socket operations.

Param

Decription

vsock

May be NULL or a pointer to a struct udo_vsock_udp.
If NULL memory will be allocated and return to
caller. If not NULL address passed will be used
to store the newly created struct udo_vsock_udp
context.

vsock_info

Implementation uses a pointer to a
Returns:
on success: Pointer to a struct udo_vsock_udp
on failure: NULL

udo_vsock_udp_client_connect

int udo_vsock_udp_client_connect(struct udo_vsock_udp *vsock);
Fliters client socket to allow sending data
without passing a struct sockaddr_vm to sendto(2).
Address is populated with a call to udo_sock_udp_client_create().

Param

Decription

vsock

Must pass a pointer to a struct udo_vsock_udp.
Returns:
on success: 0
on failure: -1

udo_vsock_udp_client_send_data

ssize_t udo_vsock_udp_client_send_data(struct udo_vsock_udp *vsock, const void *data, const size_t size, const void *vsock_info);
Send data to client socket address provided via

Param

Decription

vsock

Must pass a pointer to a struct udo_vsock_udp.

data

Pointer to buffer to send through socket.

size

Size of data to send through socket.

vsock_info

Reserved for future usage. For now used
to set the flag argument of sendto(2).
Returns:
on success: Amount of bytes sent
on failure: # < 0

udo_vsock_udp_get_fd

int udo_vsock_udp_get_fd(struct udo_vsock_udp *vsock);
Acquire VM socket file descriptor associated with
struct udo_vsock_udp context.

Param

Decription

vsock

Must pass a pointer to a struct udo_vsock_udp.
Returns:
on success: VM socket file descriptor
on failure: -1

udo_vsock_udp_get_vcid

uint32_t udo_vsock_udp_get_vcid(struct udo_vsock_udp *vsock);
Acquire VM socket context identifier associated with
struct udo_vsock_udp context.

Param

Decription

vsock

Must pass a pointer to a struct udo_vsock_udp.
Returns:
on success: VM socket context identifier
on failure: UINT32_MAX

udo_vsock_udp_get_port

int udo_vsock_udp_get_port(struct udo_vsock_udp *vsock);
Acquire network port associated with
struct udo_vsock_udp context.

Param

Decription

vsock

Must pass a pointer to a struct udo_vsock_udp.
Returns:
on success: Network port connected to context
on failure: -1

udo_vsock_udp_destroy

void udo_vsock_udp_destroy(struct udo_vsock_udp *vsock);
Frees any allocated memory and closes FD’s (if open) created after

Param

Decription

vsock

Pointer to a valid struct udo_vsock_udp.

udo_vsock_udp_get_sizeof

int udo_vsock_udp_get_sizeof(void);
Returns size of the internal structure. So,
if caller decides to allocate memory outside
of API interface they know the exact amount
of bytes.
Returns:
on success: sizeof(struct udo_vsock_udp)
on failure: sizeof(struct udo_vsock_udp)

udo_vsock_udp_get_local_vcid

uint32_t udo_vsock_udp_get_local_vcid(void);
Returns the local CID of the VM/Hypervisor after
acquiring it from /dev/vsock.
Returns:
on success: Local VM context identifer
on failure: UINT32_MAX

udo_vsock_udp_recv_data

ssize_t udo_vsock_udp_recv_data(const int sock_fd, void *data, const size_t size, struct sockaddr_vm *addr, const void *vsock_info);
Receive data from socket file descriptor.

Param

Decription

sock_fd

Socket file descriptor to receive data from.

data

Pointer to buffer to store data received from a socket.

size

Size of data to receive from a socket.

addr

Pointer to struct sockaddr_vm which stores the
address information of the socket that data
was received from.

vsock_info

Reserved for future usage. For now used
to set the flag argument of recvfrom(2).
Returns:
on success: Amount of bytes received
on failure: # < 0

udo_vsock_udp_send_data

ssize_t udo_vsock_udp_send_data(const int sock_fd, const void *data, const size_t size, const struct sockaddr_vm *addr, const void *vsock_info);
Send data to socket file descriptor.

Param

Decription

sock_fd

Socket file descriptor to send data to.

data

Pointer to buffer to send through socket.

size

Size of data to send through socket.

addr

Pointer to struct sockaddr_vm which stores the
address information of a socket that data
will be sent to.

vsock_info

Reserved for future usage. For now used
to set the flag argument of sendto(2).
Returns:
on success: Amount of bytes sent
on failure: # < 0