From: Andrei Tatar Date: Thu, 22 Feb 2024 19:40:25 +0000 (+0100) Subject: lib/posix-socket: Remove posix-fdtab dependency X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7a7125138b333a1bccf65a133a808c88ad3c67c3;p=unikraft%2Funikraft.git lib/posix-socket: Remove posix-fdtab dependency This change makes posix-fdtab no longer a hard dependency of posix-socket, allowing socket operations using the internal API without needing a userspace-visible fdtab. Signed-off-by: Andrei Tatar Reviewed-by: Sergiu Moga Approved-by: Sergiu Moga GitHub-Closes: #1437 --- diff --git a/lib/posix-socket/include/uk/socket.h b/lib/posix-socket/include/uk/socket.h index e322803b7..8ff21f342 100644 --- a/lib/posix-socket/include/uk/socket.h +++ b/lib/posix-socket/include/uk/socket.h @@ -42,6 +42,8 @@ #include +#include + struct posix_socket_driver; struct posix_socket_node { @@ -69,11 +71,13 @@ const struct uk_file *uk_socket_accept(const struct uk_file *sock, int blocking, struct sockaddr *addr, socklen_t *addr_len, int flags); +#if CONFIG_LIBPOSIX_FDTAB int uk_sys_socket(int family, int type, int protocol); int uk_sys_socketpair(int family, int type, int protocol, int sv[2]); int uk_sys_accept(const struct uk_file *sock, int blocking, struct sockaddr *addr, socklen_t *addr_len, int flags); +#endif /* CONFIG_LIBPOSIX_FDTAB */ #endif /* __UK_SOCKET__ */ diff --git a/lib/posix-socket/socket.c b/lib/posix-socket/socket.c index 271d88744..fa95d3a1b 100644 --- a/lib/posix-socket/socket.c +++ b/lib/posix-socket/socket.c @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -53,6 +52,10 @@ #include #include +#if CONFIG_LIBPOSIX_FDTAB +#include +#endif /* CONFIG_LIBPOSIX_FDTAB */ + #include "events.h" @@ -73,7 +76,7 @@ struct socket_alloc { #endif /* CONFIG_LIBPOSIX_SOCKET_EVENTS */ }; - +#if CONFIG_LIBPOSIX_FDTAB static struct uk_ofile *socketfd_get(int fd) { struct uk_ofile *of = uk_fdtab_get(fd); @@ -86,7 +89,7 @@ static struct uk_ofile *socketfd_get(int fd) } return of; } - +#endif /* CONFIG_LIBPOSIX_FDTAB */ static ssize_t socket_read(const struct uk_file *sock, @@ -270,7 +273,7 @@ struct uk_file *uk_socket_create(int family, int type, int protocol) } /* Internal API & Syscalls */ - +#if CONFIG_LIBPOSIX_FDTAB int uk_sys_socket(int family, int type, int protocol) { int fd; @@ -309,6 +312,7 @@ UK_SYSCALL_R_DEFINE(int, socket, int, family, int, type, int, protocol) return ret; } +#endif /* CONFIG_LIBPOSIX_FDTAB */ const struct uk_file *uk_socket_accept(const struct uk_file *sock, int blocking, struct sockaddr *addr, @@ -349,6 +353,7 @@ const struct uk_file *uk_socket_accept(const struct uk_file *sock, int blocking, return &al->f; } +#if CONFIG_LIBPOSIX_FDTAB int uk_sys_accept(const struct uk_file *sock, int blocking, struct sockaddr *addr, socklen_t *addr_len, int flags) { @@ -908,6 +913,8 @@ ssize_t send(int sock, const void *buf, size_t len, int flags) } #endif /* UK_LIBC_SYSCALLS */ +#endif /* CONFIG_LIBPOSIX_FDTAB */ + int uk_socketpair_create(int family, int type, int protocol, const struct uk_file *sv[2]) @@ -952,6 +959,7 @@ err_free: return ret; } +#if CONFIG_LIBPOSIX_FDTAB int uk_sys_socketpair(int family, int type, int protocol, int sv[2]) { int ret; @@ -1009,3 +1017,4 @@ UK_SYSCALL_R_DEFINE(int, socketpair, int, family, int, type, int, protocol, trace_posix_socket_socketpair_ret(ret); return ret; } +#endif /* CONFIG_LIBPOSIX_FDTAB */