From c1f278f3857ce1f9aff688a80871338bd476821f Mon Sep 17 00:00:00 2001 From: compile_success <980965867@qq.com> Date: Sat, 20 Jan 2024 11:33:00 +0000 Subject: [PATCH] add set tcp windows option --- 0106-add-tcp-wnd-set-option.patch | 173 ++++++++++++++++++++++++++++++ lwip.spec | 6 +- 2 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 0106-add-tcp-wnd-set-option.patch diff --git a/0106-add-tcp-wnd-set-option.patch b/0106-add-tcp-wnd-set-option.patch new file mode 100644 index 0000000..802184a --- /dev/null +++ b/0106-add-tcp-wnd-set-option.patch @@ -0,0 +1,173 @@ +From d101a2e798f66298c3e3b08ddd1ab4809f54de72 Mon Sep 17 00:00:00 2001 +From: compile_success <980965867@qq.com> +Date: Sat, 20 Jan 2024 11:28:45 +0000 +Subject: [PATCH] add tcp wnd set option + +--- + src/core/tcp.c | 21 +++++++++++++++++++-- + src/core/tcp_in.c | 6 ++++++ + src/core/tcp_out.c | 8 ++++++++ + src/include/lwip/tcp.h | 13 +++++++++++++ + src/include/lwipsock.h | 1 + + 5 files changed, 47 insertions(+), 2 deletions(-) + +diff --git a/src/core/tcp.c b/src/core/tcp.c +index 76f0ffd..f03c85f 100644 +--- a/src/core/tcp.c ++++ b/src/core/tcp.c +@@ -1067,8 +1067,11 @@ tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb) + + LWIP_ASSERT("tcp_update_rcv_ann_wnd: invalid pcb", pcb != NULL); + new_right_edge = pcb->rcv_nxt + pcb->rcv_wnd; +- ++#if GAZELLE_ENABLE ++ if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((pcb->default_wnd / 2), pcb->mss))) { ++#else + if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND / 2), pcb->mss))) { ++#endif + /* we can advertise more window */ + pcb->rcv_ann_wnd = pcb->rcv_wnd; + return new_right_edge - pcb->rcv_ann_right_edge; +@@ -1127,7 +1130,11 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len) + * watermark is TCP_WND/4), then send an explicit update now. + * Otherwise wait for a packet to be sent in the normal course of + * events (or more window to be available later) */ ++#if GAZELLE_ENABLE ++ if (wnd_inflation >= LWIP_MIN((pcb->default_wnd / 4), (TCP_MSS * 4))) { ++#else + if (wnd_inflation >= TCP_WND_UPDATE_THRESHOLD) { ++#endif + tcp_ack_now(pcb); + tcp_output(pcb); + } +@@ -1312,9 +1319,14 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, + pcb->snd_lbb = iss - 1; + /* 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. */ ++#if GAZELLE_ENABLE ++ pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(pcb->default_wnd); ++ pcb->snd_wnd = pcb->default_wnd; ++#else + pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND); +- pcb->rcv_ann_right_edge = pcb->rcv_nxt; + pcb->snd_wnd = TCP_WND; ++#endif ++ pcb->rcv_ann_right_edge = pcb->rcv_nxt; + /* As initial send MSS, we use TCP_MSS but limit it to 536. + The send MSS is updated when an MSS option is received. */ + pcb->mss = INITIAL_MSS; +@@ -2108,7 +2120,12 @@ tcp_alloc(u8_t prio) + pcb->snd_buf = TCP_SND_BUF; + /* 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. */ ++#if GAZELLE_ENABLE ++ pcb->default_wnd = default_wnd_value; ++ pcb->rcv_wnd = pcb->rcv_ann_wnd = default_wnd_value; ++#else + pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND); ++#endif + pcb->ttl = TCP_TTL; + /* As initial send MSS, we use TCP_MSS but limit it to 536. + The send MSS is updated when an MSS option is received. */ +diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c +index ec1905f..325be57 100644 +--- a/src/core/tcp_in.c ++++ b/src/core/tcp_in.c +@@ -2194,9 +2194,15 @@ tcp_parseopt(struct tcp_pcb *pcb) + pcb->rcv_scale = TCP_RCV_SCALE; + tcp_set_flags(pcb, TF_WND_SCALE); + /* window scaling is enabled, we can use the full receive window */ ++#if GAZELLE_ENABLE ++ LWIP_ASSERT("window not at default value", pcb->rcv_wnd == TCPWND_MIN16(pcb->default_wnd)); ++ LWIP_ASSERT("window not at default value", pcb->rcv_ann_wnd == TCPWND_MIN16(pcb->default_wnd)); ++ pcb->rcv_wnd = pcb->rcv_ann_wnd = pcb->default_wnd; ++#else + LWIP_ASSERT("window not at default value", pcb->rcv_wnd == TCPWND_MIN16(TCP_WND)); + LWIP_ASSERT("window not at default value", pcb->rcv_ann_wnd == TCPWND_MIN16(TCP_WND)); + pcb->rcv_wnd = pcb->rcv_ann_wnd = TCP_WND; ++#endif /* GAZELLE_ENABLE */ + } + break; + #endif /* LWIP_WND_SCALE */ +diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c +index bb03aae..137db4c 100644 +--- a/src/core/tcp_out.c ++++ b/src/core/tcp_out.c +@@ -2455,9 +2455,17 @@ tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno, + optlen = LWIP_TCP_OPT_LENGTH_SEGMENT(0, pcb); + + #if LWIP_WND_SCALE ++#if GAZELLE_ENABLE ++ wnd = PP_HTONS(((default_wnd_value >> TCP_RCV_SCALE) & 0xFFFF)); ++#else + wnd = PP_HTONS(((TCP_WND >> TCP_RCV_SCALE) & 0xFFFF)); ++#endif /* GAZELLE_ENABLE*/ ++#else ++#if GAZELLE_ENABLE ++ wnd = PP_HTONS(pcb->default_wnd); + #else + wnd = PP_HTONS(TCP_WND); ++#endif + #endif + + p = tcp_output_alloc_header_common(ackno, optlen, 0, lwip_htonl(seqno), local_port, +diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h +index 741e58f..7dcb349 100644 +--- a/src/include/lwip/tcp.h ++++ b/src/include/lwip/tcp.h +@@ -56,6 +56,10 @@ + #include "hlist.h" + #endif + ++#if GAZELLE_ENABLE ++#include "lwipsock.h" ++#endif ++ + #ifdef __cplusplus + extern "C" { + #endif +@@ -142,13 +146,21 @@ typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err); + #define RCV_WND_SCALE(pcb, wnd) (((wnd) >> (pcb)->rcv_scale)) + #define SND_WND_SCALE(pcb, wnd) (((wnd) << (pcb)->snd_scale)) + #define TCPWND16(x) ((u16_t)LWIP_MIN((x), 0xFFFF)) ++#if GAZELLE_ENABLE ++#define TCP_WND_MAX(pcb) ((tcpwnd_size_t)(((pcb)->flags & TF_WND_SCALE) ? pcb->default_wnd : TCPWND16(pcb->default_wnd))) ++#else + #define TCP_WND_MAX(pcb) ((tcpwnd_size_t)(((pcb)->flags & TF_WND_SCALE) ? TCP_WND : TCPWND16(TCP_WND))) ++#endif + #else + #define RCV_WND_SCALE(pcb, wnd) (wnd) + #define SND_WND_SCALE(pcb, wnd) (wnd) + #define TCPWND16(x) (x) ++#if GAZELLE_ENABLE ++#define TCP_WND_MAX(pcb) pcb->default_wnd ++#else + #define TCP_WND_MAX(pcb) TCP_WND + #endif ++#endif + /* Increments a tcpwnd_size_t and holds at max value rather than rollover */ + #define TCP_WND_INC(wnd, inc) do { \ + if ((tcpwnd_size_t)(wnd + inc) >= wnd) { \ +@@ -356,6 +368,7 @@ 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). */ ++ tcpwnd_size_t default_wnd; /* tcp windows size */ + #define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3) + u16_t snd_queuelen; /* Number of pbufs currently in the send buffer. */ + +diff --git a/src/include/lwipsock.h b/src/include/lwipsock.h +index ccc8c43..d1f12c5 100644 +--- a/src/include/lwipsock.h ++++ b/src/include/lwipsock.h +@@ -163,6 +163,7 @@ static inline unsigned same_node_ring_count(struct lwip_sock *sock) + */ + #if GAZELLE_ENABLE + extern uint32_t sockets_num; ++extern uint32_t default_wnd_value; + extern struct lwip_sock *sockets; + + extern void do_lwip_init_sock(int32_t fd); +-- +2.33.0 + diff --git a/lwip.spec b/lwip.spec index 8ee9ddb..149ffe1 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: 110 +Release: 111 License: BSD URL: http://savannah.nongnu.org/projects/lwip/ Source0: http://download.savannah.nongnu.org/releases/lwip/%{name}-%{version}.zip @@ -122,6 +122,7 @@ Patch6005: backport-tcp_in-fix-ooseq-update-error.patch Patch9102: 0103-adapt-for-dpdk-23.11.patch Patch9103: 0104-optimize-enqueue-for-unacked-and-unsent-queue.patch Patch9104: 0105-delete-redundant-logs-in-lwip.patch +Patch9105: 0106-add-tcp-wnd-set-option.patch BuildRequires: gcc-c++ dos2unix dpdk-devel @@ -151,6 +152,9 @@ cd %{_builddir}/%{name}-%{version}/src %{_libdir}/liblwip.a %changelog +* Sat Jan 20 2024 zhujunhao - 2.1.3-111 +- add tcp wnd set option + * Wed Jan 10 2024 hankangkang - 2.1.3-110 - delete redundant logs in lwip -- Gitee