From 3d80e51b2a15638b1071ef3a409ad06e42f5a390 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Thu, 26 Jan 2017 23:33:57 +0000 Subject: [PATCH] tcp: eliminate some redundant route lookups Now that tcp_connect() always determines the outgoing netif with a route lookup, we can compute the effective MSS without doing the same route lookup again. The outgoing netif is already known from one other location that computes the MSS, so we can eliminate a redundant route lookup there too. Reduce some macro clutter as a side effect. --- src/core/tcp.c | 14 ++++---------- src/core/tcp_out.c | 2 +- src/include/lwip/priv/tcp_priv.h | 14 ++++---------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index f20b44a9..8d4af978 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -960,7 +960,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, The send MSS is updated when an MSS option is received. */ pcb->mss = INITIAL_MSS; #if TCP_CALCULATE_EFF_SEND_MSS - pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip); + pcb->mss = tcp_eff_send_mss_netif(pcb->mss, netif, &pcb->remote_ip); #endif /* TCP_CALCULATE_EFF_SEND_MSS */ pcb->cwnd = 1; pcb->ssthresh = TCP_WND; @@ -1903,21 +1903,15 @@ tcp_next_iss(struct tcp_pcb *pcb) #if TCP_CALCULATE_EFF_SEND_MSS /** * Calculates the effective send mss that can be used for a specific IP address - * by using ip_route to determine the netif used to send to the address and - * calculating the minimum of TCP_MSS and that netif's mtu (if set). + * by calculating the minimum of TCP_MSS and the mtu (if set) of the target + * netif (if not NULL). */ u16_t -tcp_eff_send_mss_impl(u16_t sendmss, const ip_addr_t *dest -#if LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING - , const ip_addr_t *src -#endif /* LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING */ - ) +tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, const ip_addr_t *dest) { u16_t mss_s; - struct netif *outif; s16_t mtu; - outif = ip_route(src, dest); #if LWIP_IPV6 #if LWIP_IPV4 if (IP_IS_V6(dest)) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 108028b2..940fc9fa 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1216,7 +1216,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif if (seg->flags & TF_SEG_OPTS_MSS) { u16_t mss; #if TCP_CALCULATE_EFF_SEND_MSS - mss = tcp_eff_send_mss(TCP_MSS, &pcb->local_ip, &pcb->remote_ip); + mss = tcp_eff_send_mss_netif(TCP_MSS, netif, &pcb->remote_ip); #else /* TCP_CALCULATE_EFF_SEND_MSS */ mss = TCP_MSS; #endif /* TCP_CALCULATE_EFF_SEND_MSS */ diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h index 03ebcb63..ffffb977 100644 --- a/src/include/lwip/priv/tcp_priv.h +++ b/src/include/lwip/priv/tcp_priv.h @@ -459,16 +459,10 @@ err_t tcp_zero_window_probe(struct tcp_pcb *pcb); void tcp_trigger_input_pcb_close(void); #if TCP_CALCULATE_EFF_SEND_MSS -u16_t tcp_eff_send_mss_impl(u16_t sendmss, const ip_addr_t *dest -#if LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING - , const ip_addr_t *src -#endif /* LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING */ - ); -#if LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING -#define tcp_eff_send_mss(sendmss, src, dest) tcp_eff_send_mss_impl(sendmss, dest, src) -#else /* LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING */ -#define tcp_eff_send_mss(sendmss, src, dest) tcp_eff_send_mss_impl(sendmss, dest) -#endif /* LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING */ +u16_t tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, + const ip_addr_t *dest); +#define tcp_eff_send_mss(sendmss, src, dest) \ + tcp_eff_send_mss_netif(sendmss, ip_route(src, dest), dest) #endif /* TCP_CALCULATE_EFF_SEND_MSS */ #if LWIP_CALLBACK_API