From f6320b17ef84ea6f0d41caf85785f58e10cc6333 Mon Sep 17 00:00:00 2001 From: Dmytro Podgornyi Date: Wed, 22 Jul 2020 16:09:23 +0300 Subject: [PATCH 1/2] lwip/tcp.c: remove unused and duplicated code tcp_abandon() calls tcp_pcb_remove() which calls tcp_pcb_purge(). Since we can abandon only non LISTEN sockets, all segments lists are guaranteed to be empty after tcp_pcb_remove(). Checking them is an extra code. external_ip_output() is not used anywhere and the code around this function is dead. Signed-off-by: Dmytro Podgornyi --- src/vma/lwip/tcp.c | 18 ------------------ src/vma/lwip/tcp.h | 1 - src/vma/lwip/tcp_out.c | 10 +--------- src/vma/proto/vma_lwip.cpp | 1 - 4 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/vma/lwip/tcp.c b/src/vma/lwip/tcp.c index 43e343f92..ac7d67b44 100644 --- a/src/vma/lwip/tcp.c +++ b/src/vma/lwip/tcp.c @@ -329,7 +329,6 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) { u32_t seqno, ackno; u16_t remote_port, local_port; - ip_addr_t remote_ip, local_ip; #if LWIP_CALLBACK_API tcp_err_fn errf; #endif /* LWIP_CALLBACK_API */ @@ -347,8 +346,6 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) int send_rst = reset && (get_tcp_state(pcb) != CLOSED); seqno = pcb->snd_nxt; ackno = pcb->rcv_nxt; - ip_addr_copy(local_ip, pcb->local_ip); - ip_addr_copy(remote_ip, pcb->remote_ip); local_port = pcb->local_port; remote_port = pcb->remote_port; #if LWIP_CALLBACK_API @@ -356,27 +353,12 @@ tcp_abandon(struct tcp_pcb *pcb, int reset) #endif /* LWIP_CALLBACK_API */ errf_arg = pcb->my_container; tcp_pcb_remove(pcb); - if (pcb->unacked != NULL) { - tcp_tx_segs_free(pcb, pcb->unacked); - pcb->unacked = NULL; - } - if (pcb->unsent != NULL) { - tcp_tx_segs_free(pcb, pcb->unsent); - pcb->unsent = NULL; - } -#if TCP_QUEUE_OOSEQ - if (pcb->ooseq != NULL) { - tcp_segs_free(pcb, pcb->ooseq); - } -#endif /* TCP_QUEUE_OOSEQ */ TCP_EVENT_ERR(errf, errf_arg, ERR_ABRT); if (send_rst) { LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abandon: sending RST\n")); tcp_rst(seqno, ackno, local_port, remote_port, pcb); } } - (void)local_ip; /* Fix warning -Wunused-but-set-variable */ - (void)remote_ip; /* Fix warning -Wunused-but-set-variable */ } /** diff --git a/src/vma/lwip/tcp.h b/src/vma/lwip/tcp.h index 22d8bb79a..e783904d0 100644 --- a/src/vma/lwip/tcp.h +++ b/src/vma/lwip/tcp.h @@ -58,7 +58,6 @@ typedef err_t (*ip_output_fn)(struct pbuf *p, void* p_conn, u16_t flags); #else typedef err_t (*ip_output_fn)(struct pbuf *p, void* p_conn, int is_rexmit, u8_t is_dummy); #endif /* LWIP_TSO */ -void register_ip_output(ip_output_fn fn); typedef ssize_t (*sys_readv_fn)(int __fd, const struct iovec *iov, int iovcnt); void register_sys_readv(sys_readv_fn fn); diff --git a/src/vma/lwip/tcp_out.c b/src/vma/lwip/tcp_out.c index efe944fd3..482dae705 100644 --- a/src/vma/lwip/tcp_out.c +++ b/src/vma/lwip/tcp_out.c @@ -106,13 +106,6 @@ void register_sys_now(sys_now_fn fn) } #if LWIP_3RD_PARTY_L3 -ip_output_fn external_ip_output; - -void register_ip_output(ip_output_fn fn) -{ - external_ip_output = fn; -} - ip_route_mtu_fn external_ip_route_mtu; void register_ip_route_mtu(ip_route_mtu_fn fn) @@ -1785,7 +1778,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb) * most other segment output functions. * * The pcb is given only when its valid and from an output context. - * It is used with the external_ip_output function. + * It is used with the pcb->ip_output() function. * * @param seqno the sequence number to use for the outgoing segment * @param ackno the acknowledge number to use for the outgoing segment @@ -1828,7 +1821,6 @@ tcp_rst(u32_t seqno, u32_t ackno, u16_t local_port, u16_t remote_port, struct tc #else if(pcb) pcb->ip_output(p, pcb, 0, 0); #endif /* LWIP_TSO */ - /* external_ip_output(p, NULL, local_ip, remote_ip, TCP_TTL, 0, IP_PROTO_TCP) */; tcp_tx_pbuf_free(pcb, p); LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_rst: seqno %"U32_F" ackno %"U32_F".\n", seqno, ackno)); } diff --git a/src/vma/proto/vma_lwip.cpp b/src/vma/proto/vma_lwip.cpp index 42ce85c2c..2e42449e3 100644 --- a/src/vma/proto/vma_lwip.cpp +++ b/src/vma/proto/vma_lwip.cpp @@ -120,7 +120,6 @@ vma_lwip::vma_lwip() register_tcp_tx_pbuf_free(sockinfo_tcp::tcp_tx_pbuf_free); register_tcp_seg_alloc(sockinfo_tcp::tcp_seg_alloc); register_tcp_seg_free(sockinfo_tcp::tcp_seg_free); - register_ip_output(sockinfo_tcp::ip_output); register_tcp_state_observer(sockinfo_tcp::tcp_state_observer); register_ip_route_mtu(sockinfo_tcp::get_route_mtu); register_sys_now(sys_now); From f25e5eadbbff61931d6c60e2842f8fbf19e43566 Mon Sep 17 00:00:00 2001 From: Dmytro Podgornyi Date: Sun, 26 Jul 2020 00:05:45 +0300 Subject: [PATCH 2/2] lwip/tcp_in: remove dead assignments snd_wnd and ssthresh are reassigned later unconditionally. Also, fix coding style of the code. Signed-off-by: Dmytro Podgornyi --- src/vma/lwip/tcp_in.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/vma/lwip/tcp_in.c b/src/vma/lwip/tcp_in.c index 1f8b693ab..b8469f221 100644 --- a/src/vma/lwip/tcp_in.c +++ b/src/vma/lwip/tcp_in.c @@ -379,8 +379,6 @@ tcp_listen_input(struct tcp_pcb_listen *pcb, tcp_in_data* in_data) set_tcp_state(npcb, SYN_RCVD); npcb->rcv_nxt = in_data->seqno + 1; npcb->rcv_ann_right_edge = npcb->rcv_nxt; - npcb->snd_wnd = in_data->tcphdr->wnd; - npcb->ssthresh = npcb->snd_wnd; npcb->snd_wl1 = in_data->seqno - 1;/* initialise to seqno-1 to force window update */ npcb->callback_arg = pcb->callback_arg; #if LWIP_CALLBACK_API @@ -398,14 +396,14 @@ tcp_listen_input(struct tcp_pcb_listen *pcb, tcp_in_data* in_data) /* Parse any options in the SYN. */ tcp_parseopt(npcb, in_data); - npcb->rcv_wnd = TCP_WND_SCALED(npcb); - npcb->rcv_ann_wnd = TCP_WND_SCALED(npcb); - npcb->rcv_wnd_max = TCP_WND_SCALED(npcb); - npcb->rcv_wnd_max_desired = TCP_WND_SCALED(npcb); + npcb->rcv_wnd = TCP_WND_SCALED(npcb); + npcb->rcv_ann_wnd = TCP_WND_SCALED(npcb); + npcb->rcv_wnd_max = TCP_WND_SCALED(npcb); + npcb->rcv_wnd_max_desired = TCP_WND_SCALED(npcb); - npcb->snd_wnd = SND_WND_SCALE(npcb, in_data->tcphdr->wnd); - npcb->snd_wnd_max = npcb->snd_wnd; - npcb->ssthresh = npcb->snd_wnd; + npcb->snd_wnd = SND_WND_SCALE(npcb, in_data->tcphdr->wnd); + npcb->snd_wnd_max = npcb->snd_wnd; + npcb->ssthresh = npcb->snd_wnd; #if TCP_CALCULATE_EFF_SEND_MSS u16_t snd_mss = tcp_eff_send_mss(npcb->mss, npcb); UPDATE_PCB_BY_MSS(npcb, snd_mss);