diff --git a/0163-LWIPOPTS-support-setsockopt-SO_SNDTIMEO.patch b/0163-LWIPOPTS-support-setsockopt-SO_SNDTIMEO.patch new file mode 100644 index 0000000000000000000000000000000000000000..e5035024fc8cc14d83200fe083624eafae528954 --- /dev/null +++ b/0163-LWIPOPTS-support-setsockopt-SO_SNDTIMEO.patch @@ -0,0 +1,25 @@ +From 1fd85c08c2995a43aacb57614bbd04745891a82e Mon Sep 17 00:00:00 2001 +From: yinbin +Date: Tue, 10 Sep 2024 20:20:25 +0800 +Subject: [PATCH 1/2] LWIPOPTS: support setsockopt SO_SNDTIMEO + +--- + src/include/lwipopts.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h +index 4483ebe..5cc7431 100644 +--- a/src/include/lwipopts.h ++++ b/src/include/lwipopts.h +@@ -251,7 +251,7 @@ + + #define LWIP_SOCKET_POLL 0 + +-#define LWIP_SO_SNDTIMEO 0 ++#define LWIP_SO_SNDTIMEO 1 + + #define LWIP_SO_LINGER 0 + +-- +2.34.1 + diff --git a/0164-LWIPOPTS-support-setsockopt-SO_SNDBUF.patch b/0164-LWIPOPTS-support-setsockopt-SO_SNDBUF.patch new file mode 100644 index 0000000000000000000000000000000000000000..7f047327cbcceea8eb4338abbf34ed11e043b3f4 --- /dev/null +++ b/0164-LWIPOPTS-support-setsockopt-SO_SNDBUF.patch @@ -0,0 +1,164 @@ +From 578c96e235937d8d769c00e656175734c3fcb5f5 Mon Sep 17 00:00:00 2001 +From: yinbin +Date: Tue, 10 Sep 2024 20:51:19 +0800 +Subject: [PATCH] LWIPOPTS: support setsockopt SO_SNDBUF + +--- + src/api/lwipgz_sock.c | 30 ++++++++++++++++++++++++++++++ + src/api/sockets.c | 16 ++++++++++++++++ + src/core/tcp.c | 3 +++ + src/include/lwip/tcp.h | 3 +++ + src/include/lwipgz_sock.h | 9 +++++++++ + src/include/lwipopts.h | 4 ++++ + 6 files changed, 65 insertions(+) + +diff --git a/src/api/lwipgz_sock.c b/src/api/lwipgz_sock.c +index 5a5a5fd..96f54bc 100644 +--- a/src/api/lwipgz_sock.c ++++ b/src/api/lwipgz_sock.c +@@ -154,3 +154,33 @@ void lwip_exit(void) + */ + return; + } ++ ++#if GAZELLE_SO_SNDBUF ++void netconn_set_sndbufsize(struct netconn *conn, tcpwnd_size_t sndbufsize) ++{ ++ struct tcp_pcb *tcp = conn->pcb.tcp; ++ ++ if (sndbufsize > TCP_SND_BUF_MAX) { ++ LWIP_DEBUGF(GAZELLE_DEBUG_WARNING, ++ ("netconn_set_sndbufsize: setting sndbufsize exceed TCP_SND_BUF_MAX. " ++ "sndbufsize=%u, snd_buf_max=%u", sndbufsize, TCP_SND_BUF_MAX)); ++ return; ++ } ++ if (sndbufsize >= tcp->snd_buf_max) { ++ tcp->snd_buf += sndbufsize - tcp->snd_buf_max; ++ tcp->snd_buf_max = sndbufsize; ++ return; ++ } ++ /* remaining snd_buf less than the mount to be reduced */ ++ if (tcp->snd_buf < tcp->snd_buf_max - sndbufsize) { ++ LWIP_DEBUGF(GAZELLE_DEBUG_WARNING, ++ ("netconn_set_sndbufsize: setting sndbufsize too small. " ++ "snd_buf available is %u, need reduce is %u\n", tcp->snd_buf, ++ tcp->snd_buf_max - sndbufsize)); ++ return; ++ } ++ tcp->snd_buf -= tcp->snd_buf_max - sndbufsize; ++ tcp->snd_buf_max = sndbufsize; ++ return; ++} ++#endif /* GAZELLE_SO_SNDBUF */ +diff --git a/src/api/sockets.c b/src/api/sockets.c +index 3e64f66..7256c76 100644 +--- a/src/api/sockets.c ++++ b/src/api/sockets.c +@@ -3145,6 +3145,14 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt + LWIP_SO_SNDRCVTIMEO_SET(optval, netconn_get_recvtimeout(sock->conn)); + break; + #endif /* LWIP_SO_RCVTIMEO */ ++#if GAZELLE_SO_SNDBUF ++ case SO_SNDBUF: ++ LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, tcpwnd_size_t); ++ if (netconn_type(sock->conn) == NETCONN_TCP) { ++ *(tcpwnd_size_t *)optval = netconn_get_sndbufsize(sock->conn); ++ } ++ break; ++#endif /* GAZELLE_SO_SNDBUF */ + #if LWIP_SO_RCVBUF + case SO_RCVBUF: + LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, int); +@@ -3546,6 +3554,14 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ + break; + } + #endif /* LWIP_SO_RCVTIMEO */ ++#if GAZELLE_SO_SNDBUF ++ case SO_SNDBUF: ++ LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, tcpwnd_size_t); ++ if (netconn_type(sock->conn) == NETCONN_TCP) { ++ netconn_set_sndbufsize(sock->conn, *(const tcpwnd_size_t *)optval); ++ } ++ break; ++#endif /* GAZELLE_SO_SNDBUF */ + #if LWIP_SO_RCVBUF + case SO_RCVBUF: + LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, int); +diff --git a/src/core/tcp.c b/src/core/tcp.c +index a35f19a..79e6310 100644 +--- a/src/core/tcp.c ++++ b/src/core/tcp.c +@@ -2108,6 +2108,9 @@ tcp_alloc(u8_t prio) + memset(pcb, 0, sizeof(struct tcp_pcb)); + pcb->prio = prio; + pcb->snd_buf = TCP_SND_BUF; ++#if GAZELLE_SO_SNDBUF ++ pcb->snd_buf_max = TCP_SND_BUF; ++#endif /* GAZELLE_SO_SNDBUF */ + /* Start with a window that does not need scaling. When window scaling is + enabled and used, the window is enlarged when both sides agree on scaling. */ + pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND); +diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h +index 9c8a2ca..72fd166 100644 +--- a/src/include/lwip/tcp.h ++++ b/src/include/lwip/tcp.h +@@ -340,6 +340,9 @@ struct tcp_pcb { + tcpwnd_size_t snd_wnd_max; /* the maximum sender window announced by the remote host */ + + tcpwnd_size_t snd_buf; /* Available buffer space for sending (in bytes). */ ++#if GAZELLE_SO_SNDBUF ++ tcpwnd_size_t snd_buf_max; /* the max size of snd_buf */ ++#endif /* GAZELLE_SO_SNDBUF */ + #define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3) + u16_t snd_queuelen; /* Number of pbufs currently in the send buffer. */ + +diff --git a/src/include/lwipgz_sock.h b/src/include/lwipgz_sock.h +index e0fe7c8..4f8e17b 100644 +--- a/src/include/lwipgz_sock.h ++++ b/src/include/lwipgz_sock.h +@@ -36,6 +36,10 @@ + #include "lwip/opt.h" + #include "lwip/api.h" + ++#if GAZELLE_SO_SNDBUF ++#include "lwip/tcp.h" ++#endif /* GAZELLE_SO_SNDBUF */ ++ + #if GAZELLE_ENABLE + #include + #include +@@ -193,4 +197,9 @@ struct lwip_sock { + #endif /* GAZELLE_ENABLE */ + }; + ++#if GAZELLE_SO_SNDBUF ++void netconn_set_sndbufsize(struct netconn *conn, tcpwnd_size_t sndbufsize); ++#define netconn_get_sndbufsize(conn) ((conn)->pcb.tcp->snd_buf_max) ++#endif /* GAZELLE_SO_SNDBUF */ ++ + #endif /* __LWIPGZ_SOCK_H__ */ +diff --git a/src/include/lwipopts.h b/src/include/lwipopts.h +index 5cc7431..ea6588a 100644 +--- a/src/include/lwipopts.h ++++ b/src/include/lwipopts.h +@@ -229,6 +229,8 @@ + + #define TCP_SND_QUEUELEN (8191) + ++#define TCP_SND_BUF_MAX (TCP_SND_QUEUELEN * TCP_MSS) ++ + #define TCP_SNDLOWAT (32768) + + #define TCP_SNDQUEUELOWAT (TCP_SND_QUEUELEN / 5) +@@ -265,6 +267,8 @@ + + #define SO_REUSE_RXTOALL 1 + ++#define GAZELLE_SO_SNDBUF 1 ++ + /* + ------------------------------------ + --------- Debug log options -------- +-- +2.34.1 + diff --git a/lwip.spec b/lwip.spec index 7321c47f52e758230859fef07e68940eeb46e4d3..190d0cfb9370b4a2caa26eb522446a3c128c6815 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.2.0 -Release: 53 +Release: 54 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -174,6 +174,8 @@ Patch9158: 0159-LOOPBACK-fix-loop-coredump.patch Patch9159: 0160-INIT-fix-lwip_init-failed-because-of-dpdk-set-errno.patch Patch9160: 0161-fix-the-definition-of-IPV6_V6ONLY.patch Patch9161: 0162-check-if-mem_init-returns-errno.patch +Patch9162: 0163-LWIPOPTS-support-setsockopt-SO_SNDTIMEO.patch +Patch9163: 0164-LWIPOPTS-support-setsockopt-SO_SNDBUF.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -203,6 +205,10 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Tue Sep 10 2024 yinbin - 2.2.0-54 +- LWIPOPTS support setsockopt SO_SNDTIMEO +- LWIPOPTS support setsockopt SO_SNDBUF + * Tue Aug 20 2024 yinbin - 2.2.0-53 - check if mem_init returns errno