1195972f6Sopenharmony_ciFrom b23520dcddbdf088ededeac7a0a1611db73db191 Mon Sep 17 00:00:00 2001
2195972f6Sopenharmony_ciFrom: kircher <majun65@huawei.com>
3195972f6Sopenharmony_ciDate: Mon, 19 Dec 2022 19:23:42 +0800
4195972f6Sopenharmony_ciSubject: [PATCH] skip unnecessary tcp_route
5195972f6Sopenharmony_ci
6195972f6Sopenharmony_ci---
7195972f6Sopenharmony_ci src/core/tcp.c         |  1 +
8195972f6Sopenharmony_ci src/core/tcp_out.c     | 20 ++++++++++++++++----
9195972f6Sopenharmony_ci src/include/lwip/tcp.h |  1 +
10195972f6Sopenharmony_ci src/include/lwipsock.h |  1 +
11195972f6Sopenharmony_ci 4 files changed, 19 insertions(+), 4 deletions(-)
12195972f6Sopenharmony_ci
13195972f6Sopenharmony_cidiff --git a/src/core/tcp.c b/src/core/tcp.c
14195972f6Sopenharmony_ciindex 252f27f..abfcc00 100644
15195972f6Sopenharmony_ci--- a/src/core/tcp.c
16195972f6Sopenharmony_ci+++ b/src/core/tcp.c
17195972f6Sopenharmony_ci@@ -2294,6 +2294,7 @@ tcp_pcb_purge(struct tcp_pcb *pcb)
18195972f6Sopenharmony_ci     tcp_segs_free(pcb->unacked);
19195972f6Sopenharmony_ci     pcb->unacked = pcb->unsent = NULL;
20195972f6Sopenharmony_ci     pcb->last_unacked = pcb->last_unsent = NULL;
21195972f6Sopenharmony_ci+    pcb->pcb_if = NULL;
22195972f6Sopenharmony_ci #if TCP_OVERSIZE
23195972f6Sopenharmony_ci     pcb->unsent_oversize = 0;
24195972f6Sopenharmony_ci #endif /* TCP_OVERSIZE */
25195972f6Sopenharmony_cidiff --git a/src/core/tcp_out.c b/src/core/tcp_out.c
26195972f6Sopenharmony_ciindex 25aeb23..1c5734b 100644
27195972f6Sopenharmony_ci--- a/src/core/tcp_out.c
28195972f6Sopenharmony_ci+++ b/src/core/tcp_out.c
29195972f6Sopenharmony_ci@@ -1425,7 +1425,12 @@ tcp_output(struct tcp_pcb *pcb)
30195972f6Sopenharmony_ci                  lwip_ntohl(seg->tcphdr->seqno), pcb->lastack));
31195972f6Sopenharmony_ci   }
32195972f6Sopenharmony_ci 
33195972f6Sopenharmony_ci-  netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip);
34195972f6Sopenharmony_ci+  if (pcb->pcb_if == NULL) {
35195972f6Sopenharmony_ci+    netif = tcp_route(pcb, &pcb->local_ip, &pcb->remote_ip);
36195972f6Sopenharmony_ci+    pcb->pcb_if = netif;
37195972f6Sopenharmony_ci+  } else {
38195972f6Sopenharmony_ci+    netif = pcb->pcb_if;
39195972f6Sopenharmony_ci+  }
40195972f6Sopenharmony_ci   if (netif == NULL) {
41195972f6Sopenharmony_ci     return ERR_RTE;
42195972f6Sopenharmony_ci   }
43195972f6Sopenharmony_ci@@ -2220,7 +2225,7 @@ tcp_output_fill_options(const struct tcp_pcb *pcb, struct pbuf *p, u8_t optflags
44195972f6Sopenharmony_ci  * header checksum and calling ip_output_if while handling netif hints and stats.
45195972f6Sopenharmony_ci  */
46195972f6Sopenharmony_ci static err_t
47195972f6Sopenharmony_ci-tcp_output_control_segment(const struct tcp_pcb *pcb, struct pbuf *p,
48195972f6Sopenharmony_ci+tcp_output_control_segment(struct tcp_pcb *pcb, struct pbuf *p,
49195972f6Sopenharmony_ci                            const ip_addr_t *src, const ip_addr_t *dst)
50195972f6Sopenharmony_ci {
51195972f6Sopenharmony_ci   err_t err;
52195972f6Sopenharmony_ci@@ -2228,7 +2233,14 @@ tcp_output_control_segment(const struct tcp_pcb *pcb, struct pbuf *p,
53195972f6Sopenharmony_ci 
54195972f6Sopenharmony_ci   LWIP_ASSERT("tcp_output_control_segment: invalid pbuf", p != NULL);
55195972f6Sopenharmony_ci 
56195972f6Sopenharmony_ci-  netif = tcp_route(pcb, src, dst);
57195972f6Sopenharmony_ci+  if (pcb == NULL || pcb->pcb_if == NULL) {
58195972f6Sopenharmony_ci+    netif = tcp_route(pcb, src, dst);
59195972f6Sopenharmony_ci+    if (pcb) {
60195972f6Sopenharmony_ci+      pcb->pcb_if = netif;
61195972f6Sopenharmony_ci+    }
62195972f6Sopenharmony_ci+  } else {
63195972f6Sopenharmony_ci+    netif = pcb->pcb_if;
64195972f6Sopenharmony_ci+  }
65195972f6Sopenharmony_ci   if (netif == NULL) {
66195972f6Sopenharmony_ci     err = ERR_RTE;
67195972f6Sopenharmony_ci   } else {
68195972f6Sopenharmony_ci@@ -2318,7 +2330,7 @@ tcp_rst(const struct tcp_pcb *pcb, u32_t seqno, u32_t ackno,
69195972f6Sopenharmony_ci 
70195972f6Sopenharmony_ci   MIB2_STATS_INC(mib2.tcpoutrsts);
71195972f6Sopenharmony_ci 
72195972f6Sopenharmony_ci-  tcp_output_control_segment(pcb, p, local_ip, remote_ip);
73195972f6Sopenharmony_ci+  tcp_output_control_segment((struct tcp_pcb*)pcb, p, local_ip, remote_ip);
74195972f6Sopenharmony_ci   LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_rst: seqno %"U32_F" ackno %"U32_F".\n", seqno, ackno));
75195972f6Sopenharmony_ci }
76195972f6Sopenharmony_ci 
77195972f6Sopenharmony_cidiff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h
78195972f6Sopenharmony_ciindex b0ae02c..2a61776 100644
79195972f6Sopenharmony_ci--- a/src/include/lwip/tcp.h
80195972f6Sopenharmony_ci+++ b/src/include/lwip/tcp.h
81195972f6Sopenharmony_ci@@ -408,6 +408,7 @@ struct tcp_pcb {
82195972f6Sopenharmony_ci   u8_t snd_scale;
83195972f6Sopenharmony_ci   u8_t rcv_scale;
84195972f6Sopenharmony_ci #endif
85195972f6Sopenharmony_ci+  struct netif* pcb_if;
86195972f6Sopenharmony_ci };
87195972f6Sopenharmony_ci 
88195972f6Sopenharmony_ci #if TCP_PCB_HASH
89195972f6Sopenharmony_cidiff --git a/src/include/lwipsock.h b/src/include/lwipsock.h
90195972f6Sopenharmony_ciindex 62e5bf1..ec4d78c 100644
91195972f6Sopenharmony_ci--- a/src/include/lwipsock.h
92195972f6Sopenharmony_ci+++ b/src/include/lwipsock.h
93195972f6Sopenharmony_ci@@ -111,6 +111,7 @@ struct lwip_sock {
94195972f6Sopenharmony_ci   /* stack thread all use */
95195972f6Sopenharmony_ci   struct list_node recv_list;
96195972f6Sopenharmony_ci   struct list_node send_list;
97195972f6Sopenharmony_ci+  struct pbuf *lwip_lastdata;
98195972f6Sopenharmony_ci   struct pbuf *send_lastdata;
99195972f6Sopenharmony_ci   struct pbuf *send_pre_del;
100195972f6Sopenharmony_ci 
101195972f6Sopenharmony_ci-- 
102195972f6Sopenharmony_ci2.33.0
103195972f6Sopenharmony_ci
104