|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [UNIKRAFT PATCH 0/3] Introduce posix-socket
From: Alexander Jung <alexander.jung@xxxxxxxxx>
This patch series introduces the posix-socket microlibrary within the
Unikraft core in order to facilitate the use of multiple POSIX-
compliant socket implementations which target specific AF family
numbers.
This library allows for the registration of socket interfaces, listed
within `struct posix_socket_ops`, and exposes unikernel-wide
prototypes for socket(), accept(), bind(), listen(), connect(),
send(), recv() and friends in order to access them via a
corresponding AF family number. The implementing library simply needs
to register against the desired interfaces with a glue function:
#include <uk/socket.h>
#include "my_socket.h"
static struct posix_socket_ops mysock_socket_ops = {
/* The initialization function on socket registration. */
.init = mysock_lib_init,
/* POSIX interfaces */
.create = mysock_glue_create,
.accept = mysock_glue_accept,
.bind = mysock_glue_bind,
.shutdown = mysock_glue_shutdown,
.getpeername = mysock_glue_getpeername,
.getsockname = mysock_glue_getsockname,
.getsockopt = mysock_glue_getsockopt,
.setsockopt = mysock_glue_setsockopt,
.connect = mysock_glue_connect,
.listen = mysock_glue_listen,
.recv = mysock_glue_recv,
.recvfrom = mysock_glue_recvfrom,
.recvmsg = mysock_glue_recvmsg,
.send = mysock_glue_send,
.sendmsg = mysock_glue_sendmsg,
.sendto = mysock_glue_sendto,
/* vfscore ops */
.read = mysock_glue_read,
.write = mysock_glue_write,
.close = mysock_glue_close,
.ioctl = mysock_glue_ioctl,
};
Each glue function accepts traditional parameters for the POSIX
interface as side from the file descriptor, traditionally `int fd` or
`int sock`, which has instead been cast as `void *`. This allows the
implementing library to use internal socket file descriptor or
reference. The creation of a socket via socket() and accept() have
also been cast to return `void *` in line with internal needs of the
implementing library. This makes sense for implementing libraries
which use a structure instead of a file descriptor identification
integer. An additional parameter, `struct posix_socket_driver`, is
passed to each interface which can store private data as well as a
preferred memory allocator. The glue for each interface simply needs
to call the appropriate method internally, for example:
static int
mysock_glue_bind(struct posix_socket_driver *d,
void *sock, const struct sockaddr *addr, socklen_t addr_len)
{
int ret = 0;
struct my_socket *mysock;
/* Transform the socket descriptor to the my_socket pointer. */
mysock = (struct my_socket *)sock;
if (mysock->mysock_fd < 0) {
ret = -1;
SOCKET_LIB_ERR(d, ret, "failed to identify socket descriptor");
goto EXIT;
}
/* Bind to my socket */
ret = mysock_bind(mysock->mysock_fd, addr, addr_len);
if (ret < 0)
ret = -1;
EXIT:
return ret;
}
The library selects the appropriate implementation based on the AF
family number and registers the required interfaces using a newly
exposed macro:
POSIX_SOCKET_FAMILY_REGISTER(AF_INET, &mysock_socket_ops, NULL);
Implementing libraries can register as many AF numbers as desired
or specify new families which are not listed in the <sys/socket.h>
header. To access the relevant implementation, the application
simply needs to call the socket() method with the relevant AF family
number.
Alexander Jung (3):
lib/posix-socket: Introduce abstraction for communication sockets
lib/nolibc: Provide sys/socket.h
lib/posix-socket: Register library within Unikraft.
lib/Makefile.uk | 1 +
lib/nolibc/include/sys/socket.h | 258 +++++
lib/posix-socket/Config.uk | 18 +
lib/posix-socket/Makefile.uk | 10 +
lib/posix-socket/driver.c | 154 +++
lib/posix-socket/exportsyms.uk | 26 +
lib/posix-socket/extra.ld | 9 +
lib/posix-socket/include/uk/socket.h | 45 +
lib/posix-socket/include/uk/socket_driver.h | 1018 +++++++++++++++++++
lib/posix-socket/include/uk/socket_vnops.h | 97 ++
lib/posix-socket/socket.c | 722 +++++++++++++
lib/posix-socket/socket_vnops.c | 323 ++++++
12 files changed, 2681 insertions(+)
create mode 100644 lib/nolibc/include/sys/socket.h
create mode 100644 lib/posix-socket/Config.uk
create mode 100644 lib/posix-socket/Makefile.uk
create mode 100644 lib/posix-socket/driver.c
create mode 100644 lib/posix-socket/exportsyms.uk
create mode 100644 lib/posix-socket/extra.ld
create mode 100644 lib/posix-socket/include/uk/socket.h
create mode 100644 lib/posix-socket/include/uk/socket_driver.h
create mode 100644 lib/posix-socket/include/uk/socket_vnops.h
create mode 100644 lib/posix-socket/socket.c
create mode 100644 lib/posix-socket/socket_vnops.c
--
2.20.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |