lwip/0069-cleancode-refactor-options-define.patch
Lemmy Huang 858899f8d7 cleancode: refactor options define
Signed-off-by: Lemmy Huang <huangliming5@huawei.com>
2023-05-29 15:49:37 +08:00

405 lines
12 KiB
Diff

From af6f1d199a462c9097a3564070a91e9c90a7b525 Mon Sep 17 00:00:00 2001
From: Lemmy Huang <huangliming5@huawei.com>
Date: Fri, 26 May 2023 14:29:01 +0800
Subject: [PATCH 1/5] cleancode: refactor options define
Signed-off-by: Lemmy Huang <huangliming5@huawei.com>
---
src/core/stats.c | 11 ------
src/include/lwip/def.h | 2 +
src/include/lwip/ip.h | 6 ---
src/include/lwip/opt.h | 73 +++----------------------------------
src/include/lwip/prot/ip4.h | 2 +
src/include/lwip/sockets.h | 48 ++++--------------------
src/include/lwip/stats.h | 2 -
src/include/lwipopts.h | 9 +++++
8 files changed, 27 insertions(+), 126 deletions(-)
diff --git a/src/core/stats.c b/src/core/stats.c
index f7e0604..afa7012 100644
--- a/src/core/stats.c
+++ b/src/core/stats.c
@@ -59,17 +59,6 @@ stats_init(void)
#endif /* LWIP_DEBUG */
}
-int get_mib2_stats(char *buf)
-{
- int len = 0;
-#if MIB2_STATS
- len = (long)&((struct stats_mib2 *)0)->udpindatagrams;
- /* we just need the ip&tcp, others not needed. */
- memcpy(buf, &lwip_stats.mib2, len);
-#endif
- return len;
-}
-
#if LWIP_STATS_DISPLAY
void
stats_display_proto(struct stats_proto *proto, const char *name)
diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h
index fea7187..91cc6b9 100644
--- a/src/include/lwip/def.h
+++ b/src/include/lwip/def.h
@@ -117,6 +117,7 @@ u32_t lwip_htonl(u32_t x);
/* Provide usual function names as macros for users, but this can be turned off */
#ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
+#if GAZELLE_ENABLE
/* avoid conflicts with netinet/in.h */
#ifdef htons
#undef htons
@@ -130,6 +131,7 @@ u32_t lwip_htonl(u32_t x);
#ifdef ntohl
#undef ntohl
#endif
+#endif /* GAZELLE_ENABLE */
#define htons(x) lwip_htons(x)
#define ntohs(x) lwip_ntohs(x)
diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h
index 1c6988b..27bd99e 100644
--- a/src/include/lwip/ip.h
+++ b/src/include/lwip/ip.h
@@ -97,15 +97,9 @@ struct ip_pcb {
/*
* Option flags per-socket. These are the same like SO_XXX in sockets.h
*/
-#if GAZELLE_ENABLE
-#define SOF_REUSEADDR 0x02U /* allow local address reuse */
-#define SOF_KEEPALIVE 0x09U /* keep connections alive */
-#define SOF_BROADCAST 0x06U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
-#else
#define SOF_REUSEADDR 0x04U /* allow local address reuse */
#define SOF_KEEPALIVE 0x08U /* keep connections alive */
#define SOF_BROADCAST 0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
-#endif /* GAZELLE_ENABLE */
/* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */
#define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE)
diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
index 38c6e9b..d8c82d1 100644
--- a/src/include/lwip/opt.h
+++ b/src/include/lwip/opt.h
@@ -133,7 +133,6 @@
* MEMCPY: override this if you have a faster implementation at hand than the
* one included in your C library
*/
-//#include <rte_memcpy.h>
#if !defined MEMCPY || defined __DOXYGEN__
#define MEMCPY(dst,src,len) memcpy(dst,src,len)
#endif
@@ -533,22 +532,6 @@
#define MEMP_NUM_NETCONN 4
#endif
-/**
- * MEMP_NUM_SYS_SEM: the number of struct sys_sems.
- * (only needed if you use the sequential API, like api_lib.c)
- */
-#if !defined MEMP_NUM_SYS_SEM || defined __DOXYGEN__
-#define MEMP_NUM_SYS_SEM 128
-#endif
-
-/**
- * MEMP_NUM_SYS_MBOX: the number of struct sys_sems.
- * (only needed if you use the sequential API, like api_lib.c)
- */
-#if !defined MEMP_NUM_SYS_MBOX || defined __DOXYGEN__
-#define MEMP_NUM_SYS_MBOX 128
-#endif
-
/**
* MEMP_NUM_SELECT_CB: the number of struct lwip_select_cb.
* (Only needed if you have LWIP_MPU_COMPATIBLE==1 and use the socket API.
@@ -1084,7 +1067,7 @@
* LWIP_IGMP==1: Turn on IGMP module.
*/
#if !defined LWIP_IGMP || defined __DOXYGEN__
-#define LWIP_IGMP 1
+#define LWIP_IGMP 0
#endif
#if !LWIP_IPV4
#undef LWIP_IGMP
@@ -1282,7 +1265,7 @@
* LWIP_TCP_SACK_OUT==1: TCP will support sending selective acknowledgements (SACKs).
*/
#if !defined LWIP_TCP_SACK_OUT || defined __DOXYGEN__
-#define LWIP_TCP_SACK_OUT 1
+#define LWIP_TCP_SACK_OUT 0
#endif
/**
@@ -1483,8 +1466,8 @@
* send window while having a small receive window only.
*/
#if !defined LWIP_WND_SCALE || defined __DOXYGEN__
-#define LWIP_WND_SCALE 1
-#define TCP_RCV_SCALE 6
+#define LWIP_WND_SCALE 0
+#define TCP_RCV_SCALE 0
#endif
/**
@@ -2031,7 +2014,7 @@
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
*/
#if !defined LWIP_SO_RCVBUF || defined __DOXYGEN__
-#define LWIP_SO_RCVBUF 1
+#define LWIP_SO_RCVBUF 0
#endif
/**
@@ -2249,7 +2232,7 @@
* MIB2_STATS==1: Stats for SNMP MIB2.
*/
#if !defined MIB2_STATS || defined __DOXYGEN__
-#define MIB2_STATS 1
+#define MIB2_STATS 0
#endif
#else
@@ -3439,10 +3422,6 @@
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#endif
-#ifndef PERF_OUTPUT_DEBUG
- #define PERF_OUTPUT_DEBUG LWIP_DBG_OFF
-#endif
-
/**
* TCP_RST_DEBUG: Enable debugging for TCP with the RST message.
*/
@@ -3523,46 +3502,6 @@
#define LWIP_TESTMODE 0
#endif
-/**
- * EPOLL_DEBUG: Enable debugging in epoll.c.
- */
-#if !defined EPOLL_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE
-#define EPOLL_DEBUG LWIP_DBG_OFF
-#endif
-/**
- * @}
- */
-
-/**
- * ETHDEV_DEBUG: Enable debugging in ethdev.c.
- */
-#if !defined ETHDEV_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE
-#define ETHDEV_DEBUG LWIP_DBG_OFF
-#endif
-/**
- * @}
- */
-
-/**
- * ETHDEV_DEBUG: Enable debugging in ethdev.c.
- */
-#if !defined SYSCALL_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE
-#define SYSCALL_DEBUG LWIP_DBG_OFF
-#endif
-/**
- * @}
- */
-
-/**
- * CONTROL_DEBUG: Enable debugging in control_plane.c.
- */
-#if !defined CONTROL_DEBUG || defined __DOXYGEN__ && GAZELLE_ENABLE
-#define CONTROL_DEBUG LWIP_DBG_ON
-#endif
-/**
- * @}
- */
-
/*
--------------------------------------------------
---------- Performance tracking options ----------
diff --git a/src/include/lwip/prot/ip4.h b/src/include/lwip/prot/ip4.h
index c9ad89c..5f863a2 100644
--- a/src/include/lwip/prot/ip4.h
+++ b/src/include/lwip/prot/ip4.h
@@ -82,6 +82,7 @@ struct ip_hdr {
/* fragment offset field */
PACK_STRUCT_FIELD(u16_t _offset);
+#if GAZELLE_ENABLE
/* avoid conflicts with netinet/ip.h */
#ifdef IP_RF
#undef IP_RF
@@ -95,6 +96,7 @@ struct ip_hdr {
#ifdef IP_OFFMASK
#undef IP_OFFMASK
#endif
+#endif /* GAZELLE_ENABLE */
#define IP_RF 0x8000U /* reserved fragment flag */
#define IP_DF 0x4000U /* don't fragment flag */
diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h
index 36a47eb..e59fdf4 100644
--- a/src/include/lwip/sockets.h
+++ b/src/include/lwip/sockets.h
@@ -60,7 +60,7 @@ extern "C" {
to prevent this code from redefining it. */
#if GAZELLE_ENABLE
#define SA_FAMILY_T_DEFINED
- typedef u16_t sa_family_t;
+typedef u16_t sa_family_t;
#endif
#if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
@@ -200,6 +200,11 @@ struct ifreq {
#define SOCK_RAW 3
#if GAZELLE_ENABLE
+#define O_CLOEXEC 02000000 /* same as define in asm-generic/fcntl.h */
+#define SOCK_CLOEXEC O_CLOEXEC
+#define SOCK_NONBLOCK O_NONBLOCK
+#define SOCK_TYPE_MASK 0xf
+
#include <asm/socket.h>
#else
/*
@@ -298,6 +303,7 @@ struct linger {
#define TCP_KEEPINTVL 0x05 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
#define TCP_KEEPCNT 0x06 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
#else /* GAZELLE_ENABLE */
+
#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
#define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
@@ -523,24 +529,7 @@ typedef struct fd_set
#define LWIP_SELECT_MAXNFDS FD_SETSIZE
#endif /* FD_SET */
-#if GAZELLE_ENABLE
-#if !defined(POLLIN) && !defined(POLLOUT)
-/* come from bits/poll.h */
-#define POLLIN 0x001
-#define POLLOUT 0x004
-#define POLLERR 0x008
-#define POLLNVAL 0x020
-/* Below values are unimplemented */
-#define POLLRDNORM 0x040
-#define POLLRDBAND 0x080
-#define POLLPRI 0x002
-#define POLLWRNORM 0x100
-#define POLLWRBAND 0x200
-#define POLLHUP 0x010
-#endif
-#endif /* GAZELLE_ENABLE */
-
-#if LWIP_SOCKET_POLL
+#if LWIP_SOCKET_POLL && !GAZELLE_ENABLE
/* poll-related defines and types */
/* @todo: find a better way to guard the definition of these defines and types if already defined */
#if !defined(POLLIN) && !defined(POLLOUT)
@@ -585,7 +574,6 @@ void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destro
#if LWIP_COMPAT_SOCKETS == 2
/* This helps code parsers/code completion by not having the COMPAT functions as defines */
#define lwip_accept accept
-#define lwip_accept4 accept4
#define lwip_bind bind
#define lwip_shutdown shutdown
#define lwip_getpeername getpeername
@@ -627,23 +615,6 @@ int fcntl(int s, int cmd, ...);
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
#endif /* LWIP_COMPAT_SOCKETS == 2 */
-#ifndef O_CLOEXEC
-#define O_CLOEXEC 02000000
-#endif
-
-#ifndef SOCK_TYPE_MASK
-#define SOCK_TYPE_MASK 0xf
-#endif
-
-#ifndef SOCK_CLOEXEC
-#define SOCK_CLOEXEC O_CLOEXEC
-#endif
-
-#ifndef SOCK_NONBLOCK
-#define SOCK_NONBLOCK O_NONBLOCK
-#endif
-
-
int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int lwip_accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags);
int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
@@ -668,7 +639,6 @@ ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags,
int lwip_socket(int domain, int type, int protocol);
ssize_t lwip_write(int s, const void *dataptr, size_t size);
ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt);
-
#if LWIP_SOCKET_SELECT
int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout);
@@ -695,8 +665,6 @@ int lwip_inet_pton(int af, const char *src, void *dst);
/** @ingroup socket */
#define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen)
/** @ingroup socket */
-#define accept4(s,addr,addrlen,flags) lwip_accept4(s,addr,addrlen,flags)
-/** @ingroup socket */
#define bind(s,name,namelen) lwip_bind(s,name,namelen)
/** @ingroup socket */
#define shutdown(s,how) lwip_shutdown(s,how)
diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h
index 4470531..4cad603 100644
--- a/src/include/lwip/stats.h
+++ b/src/include/lwip/stats.h
@@ -467,8 +467,6 @@ void stats_init(void);
#define MIB2_STATS_INC(x)
#endif
-int get_mib2_stats(char *buf);
-
/* Display of statistics */
#if LWIP_STATS_DISPLAY
void stats_display(void);
diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h
index bc85eae..4a93923 100644
--- a/src/include/lwipopts.h
+++ b/src/include/lwipopts.h
@@ -99,6 +99,8 @@
#define LWIP_STATS_DISPLAY 1
+#define MIB2_STATS 1
+
#define LWIP_TIMERS 1
#define LWIP_TIMEVAL_PRIVATE 0
@@ -154,6 +156,7 @@
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
+#define LWIP_IGMP 1
/*
---------------------------------
@@ -209,6 +212,10 @@
#define LWIP_TCP_KEEPALIVE 1
+#define LWIP_TCP_SACK_OUT 1
+#define LWIP_WND_SCALE 1
+#define TCP_RCV_SCALE 6
+
#define GAZELLE_TCP_MAX_CONN_PER_THREAD 65535
#define GAZELLE_TCP_REUSE_IPPORT 1
@@ -226,6 +233,8 @@
#define LWIP_SO_LINGER 0
+#define LWIP_SO_RCVBUF 1
+
#define SO_REUSE 1
#define FIONBIO 0x5421 /* same as define in asm-generic/ioctls.h */
--
2.22.0.windows.1