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.
This commit is contained in:
David van Moolenbroek 2017-01-26 23:33:57 +00:00 committed by sg
parent 29ddfd1d71
commit 3d80e51b2a
3 changed files with 9 additions and 21 deletions

View File

@ -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))

View File

@ -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 */

View File

@ -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