1From b23520dcddbdf088ededeac7a0a1611db73db191 Mon Sep 17 00:00:00 2001 2From: kircher <majun65@huawei.com> 3Date: Mon, 19 Dec 2022 19:23:42 +0800 4Subject: [PATCH] skip unnecessary tcp_route 5 6--- 7 src/core/tcp.c | 1 + 8 src/core/tcp_out.c | 20 ++++++++++++++++---- 9 src/include/lwip/tcp.h | 1 + 10 src/include/lwipsock.h | 1 + 11 4 files changed, 19 insertions(+), 4 deletions(-) 12 13diff --git a/src/core/tcp.c b/src/core/tcp.c 14index 252f27f..abfcc00 100644 15--- a/src/core/tcp.c 16+++ b/src/core/tcp.c 17@@ -2294,6 +2294,7 @@ tcp_pcb_purge(struct tcp_pcb *pcb) 18 tcp_segs_free(pcb->unacked); 19 pcb->unacked = pcb->unsent = NULL; 20 pcb->last_unacked = pcb->last_unsent = NULL; 21+ pcb->pcb_if = NULL; 22 #if TCP_OVERSIZE 23 pcb->unsent_oversize = 0; 24 #endif /* TCP_OVERSIZE */ 25diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c 26index 25aeb23..1c5734b 100644 27--- a/src/core/tcp_out.c 28+++ b/src/core/tcp_out.c 29@@ -1425,7 +1425,12 @@ tcp_output(struct tcp_pcb *pcb) 30 lwip_ntohl(seg->tcphdr->seqno), pcb->lastack)); 31 } 32 33- netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip); 34+ if (pcb->pcb_if == NULL) { 35+ netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip); 36+ pcb->pcb_if = netif; 37+ } else { 38+ netif = pcb->pcb_if; 39+ } 40 if (netif == NULL) { 41 return ERR_RTE; 42 } 43@@ -2220,7 +2225,7 @@ tcp_output_fill_options(const struct tcp_pcb *pcb, struct pbuf *p, u8_t optflags 44 * header checksum and calling ip_output_if while handling netif hints and stats. 45 */ 46 static err_t 47-tcp_output_control_segment(const struct tcp_pcb *pcb, struct pbuf *p, 48+tcp_output_control_segment(struct tcp_pcb *pcb, struct pbuf *p, 49 const ip_addr_t *src, const ip_addr_t *dst) 50 { 51 err_t err; 52@@ -2228,7 +2233,14 @@ tcp_output_control_segment(const struct tcp_pcb *pcb, struct pbuf *p, 53 54 LWIP_ASSERT("tcp_output_control_segment: invalid pbuf", p != NULL); 55 56- netif = tcp_route(pcb, src, dst); 57+ if (pcb == NULL || pcb->pcb_if == NULL) { 58+ netif = tcp_route(pcb, src, dst); 59+ if (pcb) { 60+ pcb->pcb_if = netif; 61+ } 62+ } else { 63+ netif = pcb->pcb_if; 64+ } 65 if (netif == NULL) { 66 err = ERR_RTE; 67 } else { 68@@ -2318,7 +2330,7 @@ tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno, 69 70 MIB2_STATS_INC(mib2.tcpoutrsts); 71 72- tcp_output_control_segment(pcb, p, local_ip, remote_ip); 73+ tcp_output_control_segment((struct tcp_pcb*)pcb, p, local_ip, remote_ip); 74 LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_rst: seqno %"U32_F" ackno %"U32_F".\n", seqno, ackno)); 75 } 76 77diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h 78index b0ae02c..2a61776 100644 79--- a/src/include/lwip/tcp.h 80+++ b/src/include/lwip/tcp.h 81@@ -408,6 +408,7 @@ struct tcp_pcb { 82 u8_t snd_scale; 83 u8_t rcv_scale; 84 #endif 85+ struct netif* pcb_if; 86 }; 87 88 #if TCP_PCB_HASH 89diff --git a/src/include/lwipsock.h b/src/include/lwipsock.h 90index 62e5bf1..ec4d78c 100644 91--- a/src/include/lwipsock.h 92+++ b/src/include/lwipsock.h 93@@ -111,6 +111,7 @@ struct lwip_sock { 94 /* stack thread all use */ 95 struct list_node recv_list; 96 struct list_node send_list; 97+ struct pbuf *lwip_lastdata; 98 struct pbuf *send_lastdata; 99 struct pbuf *send_pre_del; 100 101-- 1022.33.0 103 104