diff --git a/0066-cleancode-refactor-gazelle_posix_api.h.patch b/0066-cleancode-refactor-gazelle_posix_api.h.patch new file mode 100644 index 0000000..6bf1a1b --- /dev/null +++ b/0066-cleancode-refactor-gazelle_posix_api.h.patch @@ -0,0 +1,247 @@ +From fd9219c855b9f9286c2412deba3dbedd7c3e96e3 Mon Sep 17 00:00:00 2001 +From: Lemmy Huang +Date: Mon, 22 May 2023 14:37:14 +0800 +Subject: [PATCH] cleancode: refactor gazelle_posix_api.h + +Signed-off-by: Lemmy Huang +--- + src/api/gazelle_posix_api.c | 106 +++++++++++++++----------------- + src/include/gazelle_posix_api.h | 63 ++++++++++--------- + 2 files changed, 81 insertions(+), 88 deletions(-) + +diff --git a/src/api/gazelle_posix_api.c b/src/api/gazelle_posix_api.c +index 219769a..1bff6d9 100644 +--- a/src/api/gazelle_posix_api.c ++++ b/src/api/gazelle_posix_api.c +@@ -31,38 +31,24 @@ + */ + + #include +-#include +-#include ++// #include ++// #include ++// #include + #include +-#include +-#include +- +-#include +- +-#include "lwip/err.h" +-#include "lwipsock.h" + #include "gazelle_posix_api.h" + +-posix_api_t *posix_api; +-posix_api_t posix_api_val; +- +-static int chld_is_epfd(int fd) +-{ +- return 0; +-} ++posix_api_t *posix_api = NULL; ++static posix_api_t posix_api_val; + + void posix_api_fork(void) + { + /* lstack helper api */ +- posix_api->ues_posix = 1; +- posix_api->is_epfd = chld_is_epfd; ++ posix_api->use_kernel = 1; + } + +- + int posix_api_init(void) + { +-/* the symbol we use here won't be NULL, so we don't need dlerror() +- to test error */ ++/* the symbol we use here won't be NULL, so we don't need dlerror() to test error */ + #define CHECK_DLSYM_RET_RETURN(ret) do { \ + if ((ret) == NULL) \ + goto err_out; \ +@@ -73,46 +59,50 @@ int posix_api_init(void) + void *__restrict handle = RTLD_NEXT; + + /* glibc standard api */ +- CHECK_DLSYM_RET_RETURN(posix_api->socket_fn = dlsym(handle, "socket")); +- CHECK_DLSYM_RET_RETURN(posix_api->accept_fn = dlsym(handle, "accept")); +- CHECK_DLSYM_RET_RETURN(posix_api->accept4_fn = dlsym(handle, "accept4")); +- CHECK_DLSYM_RET_RETURN(posix_api->bind_fn = dlsym(handle, "bind")); +- CHECK_DLSYM_RET_RETURN(posix_api->listen_fn = dlsym(handle, "listen")); +- CHECK_DLSYM_RET_RETURN(posix_api->connect_fn = dlsym(handle, "connect")); +- CHECK_DLSYM_RET_RETURN(posix_api->setsockopt_fn = dlsym(handle, "setsockopt")); +- CHECK_DLSYM_RET_RETURN(posix_api->getsockopt_fn = dlsym(handle, "getsockopt")); +- CHECK_DLSYM_RET_RETURN(posix_api->getpeername_fn = dlsym(handle, "getpeername")); +- CHECK_DLSYM_RET_RETURN(posix_api->getsockname_fn = dlsym(handle, "getsockname")); +- CHECK_DLSYM_RET_RETURN(posix_api->shutdown_fn = dlsym(handle, "shutdown")); +- CHECK_DLSYM_RET_RETURN(posix_api->close_fn = dlsym(handle, "close")); +- CHECK_DLSYM_RET_RETURN(posix_api->read_fn = dlsym(handle, "read")); +- CHECK_DLSYM_RET_RETURN(posix_api->readv_fn = dlsym(handle, "readv")); +- CHECK_DLSYM_RET_RETURN(posix_api->write_fn = dlsym(handle, "write")); +- CHECK_DLSYM_RET_RETURN(posix_api->writev_fn = dlsym(handle, "writev")); +- CHECK_DLSYM_RET_RETURN(posix_api->recv_fn = dlsym(handle, "recv")); +- CHECK_DLSYM_RET_RETURN(posix_api->send_fn = dlsym(handle, "send")); +- CHECK_DLSYM_RET_RETURN(posix_api->recv_msg = dlsym(handle, "recvmsg")); +- CHECK_DLSYM_RET_RETURN(posix_api->send_msg = dlsym(handle, "sendmsg")); +- CHECK_DLSYM_RET_RETURN(posix_api->recv_from = dlsym(handle, "recvfrom")); +- CHECK_DLSYM_RET_RETURN(posix_api->send_to = dlsym(handle, "sendto")); +- CHECK_DLSYM_RET_RETURN(posix_api->fcntl_fn = dlsym(handle, "fcntl")); +- CHECK_DLSYM_RET_RETURN(posix_api->fcntl64_fn = dlsym(handle, "fcntl64")); +- CHECK_DLSYM_RET_RETURN(posix_api->pipe_fn = dlsym(handle, "pipe")); +- CHECK_DLSYM_RET_RETURN(posix_api->epoll_create_fn = dlsym(handle, "epoll_create")); +- CHECK_DLSYM_RET_RETURN(posix_api->epoll_create1_fn = dlsym(handle, "epoll_create1")); +- CHECK_DLSYM_RET_RETURN(posix_api->epoll_ctl_fn = dlsym(handle, "epoll_ctl")); +- CHECK_DLSYM_RET_RETURN(posix_api->epoll_wait_fn = dlsym(handle, "epoll_wait")); +- CHECK_DLSYM_RET_RETURN(posix_api->fork_fn = dlsym(handle, "fork")); +- CHECK_DLSYM_RET_RETURN(posix_api->eventfd_fn = dlsym(handle, "eventfd")); +- CHECK_DLSYM_RET_RETURN(posix_api->sigaction_fn = dlsym(handle, "sigaction")); +- CHECK_DLSYM_RET_RETURN(posix_api->poll_fn = dlsym(handle, "poll")); +- CHECK_DLSYM_RET_RETURN(posix_api->ioctl_fn = dlsym(handle, "ioctl")); ++ CHECK_DLSYM_RET_RETURN(posix_api->shutdown_fn = dlsym(handle, "shutdown")); ++ CHECK_DLSYM_RET_RETURN(posix_api->close_fn = dlsym(handle, "close")); ++ CHECK_DLSYM_RET_RETURN(posix_api->socket_fn = dlsym(handle, "socket")); ++ CHECK_DLSYM_RET_RETURN(posix_api->connect_fn = dlsym(handle, "connect")); ++ CHECK_DLSYM_RET_RETURN(posix_api->bind_fn = dlsym(handle, "bind")); ++ CHECK_DLSYM_RET_RETURN(posix_api->listen_fn = dlsym(handle, "listen")); ++ CHECK_DLSYM_RET_RETURN(posix_api->accept_fn = dlsym(handle, "accept")); ++ CHECK_DLSYM_RET_RETURN(posix_api->accept4_fn = dlsym(handle, "accept4")); ++ ++ CHECK_DLSYM_RET_RETURN(posix_api->getpeername_fn = dlsym(handle, "getpeername")); ++ CHECK_DLSYM_RET_RETURN(posix_api->getsockname_fn = dlsym(handle, "getsockname")); ++ CHECK_DLSYM_RET_RETURN(posix_api->getsockopt_fn = dlsym(handle, "getsockopt")); ++ CHECK_DLSYM_RET_RETURN(posix_api->setsockopt_fn = dlsym(handle, "setsockopt")); ++ ++ CHECK_DLSYM_RET_RETURN(posix_api->read_fn = dlsym(handle, "read")); ++ CHECK_DLSYM_RET_RETURN(posix_api->write_fn = dlsym(handle, "write")); ++ CHECK_DLSYM_RET_RETURN(posix_api->readv_fn = dlsym(handle, "readv")); ++ CHECK_DLSYM_RET_RETURN(posix_api->writev_fn = dlsym(handle, "writev")); ++ CHECK_DLSYM_RET_RETURN(posix_api->recv_fn = dlsym(handle, "recv")); ++ CHECK_DLSYM_RET_RETURN(posix_api->send_fn = dlsym(handle, "send")); ++ CHECK_DLSYM_RET_RETURN(posix_api->recvmsg_fn = dlsym(handle, "recvmsg")); ++ CHECK_DLSYM_RET_RETURN(posix_api->sendmsg_fn = dlsym(handle, "sendmsg")); ++ CHECK_DLSYM_RET_RETURN(posix_api->recvfrom_fn = dlsym(handle, "recvfrom")); ++ CHECK_DLSYM_RET_RETURN(posix_api->sendto_fn = dlsym(handle, "sendto")); ++ ++ CHECK_DLSYM_RET_RETURN(posix_api->poll_fn = dlsym(handle, "poll")); ++ CHECK_DLSYM_RET_RETURN(posix_api->epoll_create_fn = dlsym(handle, "epoll_create")); ++ CHECK_DLSYM_RET_RETURN(posix_api->epoll_create1_fn = dlsym(handle, "epoll_create1")); ++ CHECK_DLSYM_RET_RETURN(posix_api->epoll_ctl_fn = dlsym(handle, "epoll_ctl")); ++ CHECK_DLSYM_RET_RETURN(posix_api->epoll_wait_fn = dlsym(handle, "epoll_wait")); ++ CHECK_DLSYM_RET_RETURN(posix_api->eventfd_fn = dlsym(handle, "eventfd")); ++ ++ CHECK_DLSYM_RET_RETURN(posix_api->ioctl_fn = dlsym(handle, "ioctl")); ++ CHECK_DLSYM_RET_RETURN(posix_api->fcntl_fn = dlsym(handle, "fcntl")); ++ CHECK_DLSYM_RET_RETURN(posix_api->fcntl64_fn = dlsym(handle, "fcntl64")); ++ ++ CHECK_DLSYM_RET_RETURN(posix_api->sigaction_fn = dlsym(handle, "sigaction")); ++ CHECK_DLSYM_RET_RETURN(posix_api->fork_fn = dlsym(handle, "fork")); + + /* support fork */ +- posix_api->ues_posix = 1; +- return ERR_OK; ++ posix_api->use_kernel = 1; ++ return 0; + + err_out: +- return ERR_MEM; ++ return -1; + #undef CHECK_DLSYM_RET_RETURN + } +diff --git a/src/include/gazelle_posix_api.h b/src/include/gazelle_posix_api.h +index 6df414b..e9a7633 100644 +--- a/src/include/gazelle_posix_api.h ++++ b/src/include/gazelle_posix_api.h +@@ -33,57 +33,60 @@ + #ifndef _GAZELLE_POSIX_API_H_ + #define _GAZELLE_POSIX_API_H_ + ++#include + #include + #include + #include + #include ++// #include + + typedef struct { +- void *handle; +- int (*socket_fn)(int domain, int type, int protocol); +- int (*accept_fn)(int s, struct sockaddr*, socklen_t*); +- int (*accept4_fn)(int s, struct sockaddr *addr, socklen_t *addrlen, int flags); +- int (*bind_fn)(int s, const struct sockaddr*, socklen_t); +- int (*listen_fn)(int s, int backlog); +- int (*connect_fn)(int s, const struct sockaddr *name, socklen_t namelen); +- int (*getpeername_fn)(int s, struct sockaddr *name, socklen_t *namelen); +- int (*getsockname_fn)(int s, struct sockaddr *name, socklen_t *namelen); +- int (*setsockopt_fn)(int s, int level, int optname, const void *optval, socklen_t optlen); +- int (*getsockopt_fn)(int s, int level, int optname, void *optval, socklen_t *optlen); +- int (*shutdown_fn)(int s, int how); ++ int (*shutdown_fn)(int fd, int how); + int (*close_fn)(int fd); +- pid_t (*fork_fn)(void); ++ int (*socket_fn)(int domain, int type, int protocol); ++ int (*connect_fn)(int fd, const struct sockaddr *name, socklen_t namelen); ++ int (*bind_fn)(int fd, const struct sockaddr*, socklen_t); ++ int (*listen_fn)(int fd, int backlog); ++ int (*accept_fn)(int fd, struct sockaddr*, socklen_t*); ++ int (*accept4_fn)(int fd, struct sockaddr *addr, socklen_t *addrlen, int flags); ++ ++ int (*getpeername_fn)(int fd, struct sockaddr *name, socklen_t *namelen); ++ int (*getsockname_fn)(int fd, struct sockaddr *name, socklen_t *namelen); ++ int (*getsockopt_fn)(int fd, int level, int optname, void *optval, socklen_t *optlen); ++ int (*setsockopt_fn)(int fd, int level, int optname, const void *optval, socklen_t optlen); ++ + ssize_t (*read_fn)(int fd, void *mem, size_t len); +- ssize_t (*readv_fn)(int s, const struct iovec *iov, int iovcnt); + ssize_t (*write_fn)(int fd, const void *data, size_t len); +- ssize_t (*writev_fn)(int s, const struct iovec *iov, int iovcnt); +- ssize_t (*recv_fn)(int sockfd, void *buf, size_t len, int flags); +- ssize_t (*send_fn)(int sockfd, const void *buf, size_t len, int flags); +- ssize_t (*recv_msg)(int sockfd, const struct msghdr *msg, int flags); +- ssize_t (*send_msg)(int sockfd, const struct msghdr *msg, int flags); +- ssize_t (*recv_from)(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); +- ssize_t (*send_to)(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, +- socklen_t addrlen); +- int (*fcntl_fn)(int fd, int cmd, ...); +- int (*fcntl64_fn)(int fd, int cmd, ...); +- int (*pipe_fn)(int pipefd[2]); ++ ssize_t (*readv_fn)(int fd, const struct iovec *iov, int iovcnt); ++ ssize_t (*writev_fn)(int fd, const struct iovec *iov, int iovcnt); ++ ssize_t (*recv_fn)(int fd, void *buf, size_t len, int flags); ++ ssize_t (*send_fn)(int fd, const void *buf, size_t len, int flags); ++ ssize_t (*recvmsg_fn)(int fd, const struct msghdr *msg, int flags); ++ ssize_t (*sendmsg_fn)(int fd, const struct msghdr *msg, int flags); ++ ssize_t (*recvfrom_fn)(int fd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); ++ ssize_t (*sendto_fn)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); ++ ++ int (*poll_fn)(struct pollfd *fds, nfds_t nfds, int timeout); + int (*epoll_create_fn)(int size); + int (*epoll_create1_fn)(int size); + int (*epoll_ctl_fn)(int epfd, int op, int fd, struct epoll_event *event); + int (*epoll_wait_fn)(int epfd, struct epoll_event *events, int maxevents, int timeout); ++ int (*epoll_close_fn)(int epfd); + int (*eventfd_fn)(unsigned int initval, int flags); +- int (*is_epfd)(int fd); +- int (*sigaction_fn)(int signum, const struct sigaction *act, struct sigaction *oldact); +- int (*poll_fn)(struct pollfd *fds, nfds_t nfds, int timeout); ++ + int (*ioctl_fn)(int fd, int cmd, ...); ++ int (*fcntl_fn)(int fd, int cmd, ...); ++ int (*fcntl64_fn)(int fd, int cmd, ...); ++ ++ int (*sigaction_fn)(int signum, const struct sigaction *act, struct sigaction *oldact); ++ pid_t (*fork_fn)(void); + +- int ues_posix; ++ int use_kernel; + } posix_api_t; + + extern posix_api_t *posix_api; + + int posix_api_init(void); +-void posix_api_free(void); + void posix_api_fork(void); + + #endif /* _GAZELLE_POSIX_API_H_ */ +-- +2.22.0.windows.1 + diff --git a/lwip.spec b/lwip.spec index 1443d54..6d34c47 100644 --- a/lwip.spec +++ b/lwip.spec @@ -4,7 +4,7 @@ Summary: lwip is a small independent implementation of the TCP/IP protocol suite Name: lwip Version: 2.1.3 -Release: 55 +Release: 56 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -77,6 +77,7 @@ Patch9061: 0062-cleancode-improving-makefile-readability.patch Patch9062: 0063-cleancode-remove-perf.patch Patch9063: 0064-cleancode-rename-gazelle-files-in-lwip.patch Patch9064: 0065-cleancode-refactor-lwipsock.h.patch +Patch9065: 0066-cleancode-refactor-gazelle_posix_api.h.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -158,6 +159,7 @@ find %{_builddir}/%{name}-%{version} -type f -exec dos2unix -q {} \; %patch9062 -p1 %patch9063 -p1 %patch9064 -p1 +%patch9065 -p1 %build cd %{_builddir}/%{name}-%{version}/src @@ -173,6 +175,9 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Wed May 24 2023 Lemmy Huang - 2.1.3-56 +- cleancode: refactor gazelle_posix_api.h + * Tue May 23 2023 Lemmy Huang - 2.1.3-55 - cleancode: refactor lwipsock.h