mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-29 22:20:12 +00:00
patch #6537/#7858: TCP window scaling support (OOS queueing still needs special handling)
This commit is contained in:
parent
33086e6db0
commit
d2a89b424b
@ -6,6 +6,9 @@ HISTORY
|
|||||||
|
|
||||||
++ New features:
|
++ New features:
|
||||||
|
|
||||||
|
2014-02-05: Simon Goldschmidt (patch by "xtian" and "alex_ab")
|
||||||
|
* patch #6537/#7858: TCP window scaling support
|
||||||
|
|
||||||
2014-01-17: Jiri Engelthaler
|
2014-01-17: Jiri Engelthaler
|
||||||
* icmp, icmp6, opt.h: patch #8027: Completed HW checksuming for IPv4 and
|
* icmp, icmp6, opt.h: patch #8027: Completed HW checksuming for IPv4 and
|
||||||
IPv6 ICMP's
|
IPv6 ICMP's
|
||||||
|
@ -115,9 +115,24 @@
|
|||||||
#error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!"
|
#error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!"
|
||||||
#endif
|
#endif
|
||||||
#endif /* !MEMP_MEM_MALLOC */
|
#endif /* !MEMP_MEM_MALLOC */
|
||||||
#if (LWIP_TCP && (TCP_WND > 0xffff))
|
#if LWIP_WND_SCALE
|
||||||
#error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
|
#if (LWIP_TCP && (TCP_WND > 0xffffffff))
|
||||||
|
#error "If you want to use TCP, TCP_WND must fit in an u32_t, so, you have to reduce it in your lwipopts.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if (LWIP_TCP && LWIP_WND_SCALE > 14)
|
||||||
|
#error "The maximum valid window scale value is 14!"
|
||||||
|
#endif
|
||||||
|
#if (LWIP_TCP && (TCP_WND > (0xFFFFU << TCP_RCV_SCALE)))
|
||||||
|
#error "TCP_WND is bigger than the configured LWIP_WND_SCALE allows!"
|
||||||
|
#endif
|
||||||
|
#if (LWIP_TCP && ((TCP_WND >> TCP_RCV_SCALE) == 0))
|
||||||
|
#error "TCP_WND is too small for the configured LWIP_WND_SCALE (results in zero window)!"
|
||||||
|
#endif
|
||||||
|
#else /* LWIP_WND_SCALE */
|
||||||
|
#if (LWIP_TCP && (TCP_WND > 0xffff))
|
||||||
|
#error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)"
|
||||||
|
#endif
|
||||||
|
#endif /* LWIP_WND_SCALE */
|
||||||
#if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
|
#if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
|
||||||
#error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
|
#error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -625,8 +625,10 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)
|
|||||||
} else {
|
} else {
|
||||||
/* keep the right edge of window constant */
|
/* keep the right edge of window constant */
|
||||||
u32_t new_rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt;
|
u32_t new_rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt;
|
||||||
|
#if !LWIP_WND_SCALE
|
||||||
LWIP_ASSERT("new_rcv_ann_wnd <= 0xffff", new_rcv_ann_wnd <= 0xffff);
|
LWIP_ASSERT("new_rcv_ann_wnd <= 0xffff", new_rcv_ann_wnd <= 0xffff);
|
||||||
pcb->rcv_ann_wnd = (u16_t)new_rcv_ann_wnd;
|
#endif
|
||||||
|
pcb->rcv_ann_wnd = (tcpwnd_size_t)new_rcv_ann_wnd;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -649,7 +651,7 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len)
|
|||||||
LWIP_ASSERT("don't call tcp_recved for listen-pcbs",
|
LWIP_ASSERT("don't call tcp_recved for listen-pcbs",
|
||||||
pcb->state != LISTEN);
|
pcb->state != LISTEN);
|
||||||
LWIP_ASSERT("tcp_recved: len would wrap rcv_wnd\n",
|
LWIP_ASSERT("tcp_recved: len would wrap rcv_wnd\n",
|
||||||
len <= 0xffff - pcb->rcv_wnd );
|
len <= TCPWND_MAX - pcb->rcv_wnd);
|
||||||
|
|
||||||
pcb->rcv_wnd += len;
|
pcb->rcv_wnd += len;
|
||||||
if (pcb->rcv_wnd > TCP_WND) {
|
if (pcb->rcv_wnd > TCP_WND) {
|
||||||
@ -824,7 +826,7 @@ void
|
|||||||
tcp_slowtmr(void)
|
tcp_slowtmr(void)
|
||||||
{
|
{
|
||||||
struct tcp_pcb *pcb, *prev;
|
struct tcp_pcb *pcb, *prev;
|
||||||
u16_t eff_wnd;
|
tcpwnd_size_t eff_wnd;
|
||||||
u8_t pcb_remove; /* flag if a PCB should be removed */
|
u8_t pcb_remove; /* flag if a PCB should be removed */
|
||||||
u8_t pcb_reset; /* flag if a RST should be sent when removing */
|
u8_t pcb_reset; /* flag if a RST should be sent when removing */
|
||||||
err_t err;
|
err_t err;
|
||||||
@ -899,12 +901,12 @@ tcp_slowtmr_start:
|
|||||||
/* Reduce congestion window and ssthresh. */
|
/* Reduce congestion window and ssthresh. */
|
||||||
eff_wnd = LWIP_MIN(pcb->cwnd, pcb->snd_wnd);
|
eff_wnd = LWIP_MIN(pcb->cwnd, pcb->snd_wnd);
|
||||||
pcb->ssthresh = eff_wnd >> 1;
|
pcb->ssthresh = eff_wnd >> 1;
|
||||||
if (pcb->ssthresh < (pcb->mss << 1)) {
|
if (pcb->ssthresh < (tcpwnd_size_t)(pcb->mss << 1)) {
|
||||||
pcb->ssthresh = (pcb->mss << 1);
|
pcb->ssthresh = (pcb->mss << 1);
|
||||||
}
|
}
|
||||||
pcb->cwnd = pcb->mss;
|
pcb->cwnd = pcb->mss;
|
||||||
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: cwnd %"U16_F
|
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: cwnd %"TCPWNDSIZE_F
|
||||||
" ssthresh %"U16_F"\n",
|
" ssthresh %"TCPWNDSIZE_F"\n",
|
||||||
pcb->cwnd, pcb->ssthresh));
|
pcb->cwnd, pcb->ssthresh));
|
||||||
|
|
||||||
/* The following needs to be called AFTER cwnd is set to one
|
/* The following needs to be called AFTER cwnd is set to one
|
||||||
@ -1348,6 +1350,11 @@ tcp_alloc(u8_t prio)
|
|||||||
pcb->snd_queuelen = 0;
|
pcb->snd_queuelen = 0;
|
||||||
pcb->rcv_wnd = TCP_WND;
|
pcb->rcv_wnd = TCP_WND;
|
||||||
pcb->rcv_ann_wnd = TCP_WND;
|
pcb->rcv_ann_wnd = TCP_WND;
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
/* snd_scale and rcv_scale are zero unless both sides agree to use scaling */
|
||||||
|
pcb->snd_scale = 0;
|
||||||
|
pcb->rcv_scale = 0;
|
||||||
|
#endif
|
||||||
pcb->tos = 0;
|
pcb->tos = 0;
|
||||||
pcb->ttl = TCP_TTL;
|
pcb->ttl = TCP_TTL;
|
||||||
/* As initial send MSS, we use TCP_MSS but limit it to 536.
|
/* As initial send MSS, we use TCP_MSS but limit it to 536.
|
||||||
|
@ -500,9 +500,6 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
|
|||||||
npcb->state = SYN_RCVD;
|
npcb->state = SYN_RCVD;
|
||||||
npcb->rcv_nxt = seqno + 1;
|
npcb->rcv_nxt = seqno + 1;
|
||||||
npcb->rcv_ann_right_edge = npcb->rcv_nxt;
|
npcb->rcv_ann_right_edge = npcb->rcv_nxt;
|
||||||
npcb->snd_wnd = tcphdr->wnd;
|
|
||||||
npcb->snd_wnd_max = tcphdr->wnd;
|
|
||||||
npcb->ssthresh = npcb->snd_wnd;
|
|
||||||
npcb->snd_wl1 = seqno - 1;/* initialise to seqno-1 to force window update */
|
npcb->snd_wl1 = seqno - 1;/* initialise to seqno-1 to force window update */
|
||||||
npcb->callback_arg = pcb->callback_arg;
|
npcb->callback_arg = pcb->callback_arg;
|
||||||
#if LWIP_CALLBACK_API
|
#if LWIP_CALLBACK_API
|
||||||
@ -516,6 +513,10 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
|
|||||||
|
|
||||||
/* Parse any options in the SYN. */
|
/* Parse any options in the SYN. */
|
||||||
tcp_parseopt(npcb);
|
tcp_parseopt(npcb);
|
||||||
|
npcb->snd_wnd = SND_WND_SCALE(npcb, tcphdr->wnd);
|
||||||
|
npcb->snd_wnd_max = npcb->snd_wnd;
|
||||||
|
npcb->ssthresh = npcb->snd_wnd;
|
||||||
|
|
||||||
#if TCP_CALCULATE_EFF_SEND_MSS
|
#if TCP_CALCULATE_EFF_SEND_MSS
|
||||||
npcb->mss = tcp_eff_send_mss(npcb->mss, &npcb->local_ip,
|
npcb->mss = tcp_eff_send_mss(npcb->mss, &npcb->local_ip,
|
||||||
&npcb->remote_ip, PCB_ISIPV6(npcb));
|
&npcb->remote_ip, PCB_ISIPV6(npcb));
|
||||||
@ -653,8 +654,8 @@ tcp_process(struct tcp_pcb *pcb)
|
|||||||
pcb->rcv_nxt = seqno + 1;
|
pcb->rcv_nxt = seqno + 1;
|
||||||
pcb->rcv_ann_right_edge = pcb->rcv_nxt;
|
pcb->rcv_ann_right_edge = pcb->rcv_nxt;
|
||||||
pcb->lastack = ackno;
|
pcb->lastack = ackno;
|
||||||
pcb->snd_wnd = tcphdr->wnd;
|
pcb->snd_wnd = SND_WND_SCALE(pcb, tcphdr->wnd);
|
||||||
pcb->snd_wnd_max = tcphdr->wnd;
|
pcb->snd_wnd_max = pcb->snd_wnd;
|
||||||
pcb->snd_wl1 = seqno - 1; /* initialise to seqno - 1 to force window update */
|
pcb->snd_wl1 = seqno - 1; /* initialise to seqno - 1 to force window update */
|
||||||
pcb->state = ESTABLISHED;
|
pcb->state = ESTABLISHED;
|
||||||
|
|
||||||
@ -670,7 +671,7 @@ tcp_process(struct tcp_pcb *pcb)
|
|||||||
pcb->cwnd = ((pcb->cwnd == 1) ? (pcb->mss * 2) : pcb->mss);
|
pcb->cwnd = ((pcb->cwnd == 1) ? (pcb->mss * 2) : pcb->mss);
|
||||||
LWIP_ASSERT("pcb->snd_queuelen > 0", (pcb->snd_queuelen > 0));
|
LWIP_ASSERT("pcb->snd_queuelen > 0", (pcb->snd_queuelen > 0));
|
||||||
--pcb->snd_queuelen;
|
--pcb->snd_queuelen;
|
||||||
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_process: SYN-SENT --queuelen %"U16_F"\n", (u16_t)pcb->snd_queuelen));
|
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_process: SYN-SENT --queuelen %"TCPWNDSIZE_F"\n", (tcpwnd_size_t)pcb->snd_queuelen));
|
||||||
rseg = pcb->unacked;
|
rseg = pcb->unacked;
|
||||||
pcb->unacked = rseg->next;
|
pcb->unacked = rseg->next;
|
||||||
tcp_seg_free(rseg);
|
tcp_seg_free(rseg);
|
||||||
@ -703,7 +704,7 @@ tcp_process(struct tcp_pcb *pcb)
|
|||||||
if (flags & TCP_ACK) {
|
if (flags & TCP_ACK) {
|
||||||
/* expected ACK number? */
|
/* expected ACK number? */
|
||||||
if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)) {
|
if (TCP_SEQ_BETWEEN(ackno, pcb->lastack+1, pcb->snd_nxt)) {
|
||||||
u16_t old_cwnd;
|
tcpwnd_size_t old_cwnd;
|
||||||
pcb->state = ESTABLISHED;
|
pcb->state = ESTABLISHED;
|
||||||
LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest));
|
LWIP_DEBUGF(TCP_DEBUG, ("TCP connection established %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest));
|
||||||
#if LWIP_CALLBACK_API
|
#if LWIP_CALLBACK_API
|
||||||
@ -889,11 +890,11 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
if (TCP_SEQ_LT(pcb->snd_wl1, seqno) ||
|
if (TCP_SEQ_LT(pcb->snd_wl1, seqno) ||
|
||||||
(pcb->snd_wl1 == seqno && TCP_SEQ_LT(pcb->snd_wl2, ackno)) ||
|
(pcb->snd_wl1 == seqno && TCP_SEQ_LT(pcb->snd_wl2, ackno)) ||
|
||||||
(pcb->snd_wl2 == ackno && tcphdr->wnd > pcb->snd_wnd)) {
|
(pcb->snd_wl2 == ackno && tcphdr->wnd > pcb->snd_wnd)) {
|
||||||
pcb->snd_wnd = tcphdr->wnd;
|
pcb->snd_wnd = SND_WND_SCALE(pcb, tcphdr->wnd);
|
||||||
/* keep track of the biggest window announced by the remote host to calculate
|
/* keep track of the biggest window announced by the remote host to calculate
|
||||||
the maximum segment size */
|
the maximum segment size */
|
||||||
if (pcb->snd_wnd_max < tcphdr->wnd) {
|
if (pcb->snd_wnd_max < pcb->snd_wnd) {
|
||||||
pcb->snd_wnd_max = tcphdr->wnd;
|
pcb->snd_wnd_max = pcb->snd_wnd;
|
||||||
}
|
}
|
||||||
pcb->snd_wl1 = seqno;
|
pcb->snd_wl1 = seqno;
|
||||||
pcb->snd_wl2 = ackno;
|
pcb->snd_wl2 = ackno;
|
||||||
@ -957,7 +958,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
if (pcb->dupacks > 3) {
|
if (pcb->dupacks > 3) {
|
||||||
/* Inflate the congestion window, but not if it means that
|
/* Inflate the congestion window, but not if it means that
|
||||||
the value overflows. */
|
the value overflows. */
|
||||||
if ((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
|
if ((tcpwnd_size_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
|
||||||
pcb->cwnd += pcb->mss;
|
pcb->cwnd += pcb->mss;
|
||||||
}
|
}
|
||||||
} else if (pcb->dupacks == 3) {
|
} else if (pcb->dupacks == 3) {
|
||||||
@ -1003,16 +1004,16 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
ssthresh). */
|
ssthresh). */
|
||||||
if (pcb->state >= ESTABLISHED) {
|
if (pcb->state >= ESTABLISHED) {
|
||||||
if (pcb->cwnd < pcb->ssthresh) {
|
if (pcb->cwnd < pcb->ssthresh) {
|
||||||
if ((u16_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
|
if ((tcpwnd_size_t)(pcb->cwnd + pcb->mss) > pcb->cwnd) {
|
||||||
pcb->cwnd += pcb->mss;
|
pcb->cwnd += pcb->mss;
|
||||||
}
|
}
|
||||||
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: slow start cwnd %"U16_F"\n", pcb->cwnd));
|
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: slow start cwnd %"TCPWNDSIZE_F"\n", pcb->cwnd));
|
||||||
} else {
|
} else {
|
||||||
u16_t new_cwnd = (pcb->cwnd + pcb->mss * pcb->mss / pcb->cwnd);
|
tcpwnd_size_t new_cwnd = (pcb->cwnd + pcb->mss * pcb->mss / pcb->cwnd);
|
||||||
if (new_cwnd > pcb->cwnd) {
|
if (new_cwnd > pcb->cwnd) {
|
||||||
pcb->cwnd = new_cwnd;
|
pcb->cwnd = new_cwnd;
|
||||||
}
|
}
|
||||||
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %"U16_F"\n", pcb->cwnd));
|
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_receive: congestion avoidance cwnd %"TCPWNDSIZE_F"\n", pcb->cwnd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: ACK for %"U32_F", unacked->seqno %"U32_F":%"U32_F"\n",
|
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: ACK for %"U32_F", unacked->seqno %"U32_F":%"U32_F"\n",
|
||||||
@ -1035,7 +1036,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
next = pcb->unacked;
|
next = pcb->unacked;
|
||||||
pcb->unacked = pcb->unacked->next;
|
pcb->unacked = pcb->unacked->next;
|
||||||
|
|
||||||
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"U16_F" ... ", (u16_t)pcb->snd_queuelen));
|
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"TCPWNDSIZE_F" ... ", (tcpwnd_size_t)pcb->snd_queuelen));
|
||||||
LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
|
LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
|
||||||
/* Prevent ACK for FIN to generate a sent event */
|
/* Prevent ACK for FIN to generate a sent event */
|
||||||
if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
|
if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
|
||||||
@ -1045,7 +1046,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
pcb->snd_queuelen -= pbuf_clen(next->p);
|
pcb->snd_queuelen -= pbuf_clen(next->p);
|
||||||
tcp_seg_free(next);
|
tcp_seg_free(next);
|
||||||
|
|
||||||
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"U16_F" (after freeing unacked)\n", (u16_t)pcb->snd_queuelen));
|
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"TCPWNDSIZE_F" (after freeing unacked)\n", (tcpwnd_size_t)pcb->snd_queuelen));
|
||||||
if (pcb->snd_queuelen != 0) {
|
if (pcb->snd_queuelen != 0) {
|
||||||
LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
|
LWIP_ASSERT("tcp_receive: valid queue length", pcb->unacked != NULL ||
|
||||||
pcb->unsent != NULL);
|
pcb->unsent != NULL);
|
||||||
@ -1054,10 +1055,11 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
/* If there's nothing left to acknowledge, stop the retransmit
|
/* If there's nothing left to acknowledge, stop the retransmit
|
||||||
timer, otherwise reset it to start again */
|
timer, otherwise reset it to start again */
|
||||||
if(pcb->unacked == NULL)
|
if (pcb->unacked == NULL) {
|
||||||
pcb->rtime = -1;
|
pcb->rtime = -1;
|
||||||
else
|
} else {
|
||||||
pcb->rtime = 0;
|
pcb->rtime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
pcb->polltmr = 0;
|
pcb->polltmr = 0;
|
||||||
|
|
||||||
@ -1092,7 +1094,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
pcb->unsent_oversize = 0;
|
pcb->unsent_oversize = 0;
|
||||||
}
|
}
|
||||||
#endif /* TCP_OVERSIZE */
|
#endif /* TCP_OVERSIZE */
|
||||||
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"U16_F" ... ", (u16_t)pcb->snd_queuelen));
|
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_receive: queuelen %"TCPWNDSIZE_F" ... ", (tcpwnd_size_t)pcb->snd_queuelen));
|
||||||
LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
|
LWIP_ASSERT("pcb->snd_queuelen >= pbuf_clen(next->p)", (pcb->snd_queuelen >= pbuf_clen(next->p)));
|
||||||
/* Prevent ACK for FIN to generate a sent event */
|
/* Prevent ACK for FIN to generate a sent event */
|
||||||
if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
|
if ((pcb->acked != 0) && ((TCPH_FLAGS(next->tcphdr) & TCP_FIN) != 0)) {
|
||||||
@ -1100,7 +1102,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
}
|
}
|
||||||
pcb->snd_queuelen -= pbuf_clen(next->p);
|
pcb->snd_queuelen -= pbuf_clen(next->p);
|
||||||
tcp_seg_free(next);
|
tcp_seg_free(next);
|
||||||
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"U16_F" (after freeing unsent)\n", (u16_t)pcb->snd_queuelen));
|
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("%"TCPWNDSIZE_F" (after freeing unsent)\n", (tcpwnd_size_t)pcb->snd_queuelen));
|
||||||
if (pcb->snd_queuelen != 0) {
|
if (pcb->snd_queuelen != 0) {
|
||||||
LWIP_ASSERT("tcp_receive: valid queue length",
|
LWIP_ASSERT("tcp_receive: valid queue length",
|
||||||
pcb->unacked != NULL || pcb->unsent != NULL);
|
pcb->unacked != NULL || pcb->unsent != NULL);
|
||||||
@ -1584,7 +1586,7 @@ tcp_parseopt(struct tcp_pcb *pcb)
|
|||||||
opts = (u8_t *)tcphdr + TCP_HLEN;
|
opts = (u8_t *)tcphdr + TCP_HLEN;
|
||||||
|
|
||||||
/* Parse the TCP MSS option, if present. */
|
/* Parse the TCP MSS option, if present. */
|
||||||
if(TCPH_HDRLEN(tcphdr) > 0x5) {
|
if (TCPH_HDRLEN(tcphdr) > 0x5) {
|
||||||
max_c = (TCPH_HDRLEN(tcphdr) - 5) << 2;
|
max_c = (TCPH_HDRLEN(tcphdr) - 5) << 2;
|
||||||
for (c = 0; c < max_c; ) {
|
for (c = 0; c < max_c; ) {
|
||||||
opt = opts[c];
|
opt = opts[c];
|
||||||
@ -1612,6 +1614,29 @@ tcp_parseopt(struct tcp_pcb *pcb)
|
|||||||
/* Advance to next option */
|
/* Advance to next option */
|
||||||
c += 0x04;
|
c += 0x04;
|
||||||
break;
|
break;
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
case 0x03:
|
||||||
|
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: WND_SCALE\n"));
|
||||||
|
if (opts[c + 1] != 0x03 || c + 0x03 > max_c) {
|
||||||
|
/* Bad length */
|
||||||
|
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: bad length\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* If syn was received with wnd scale option,
|
||||||
|
activate wnd scale opt */
|
||||||
|
if (flags & TCP_SYN) {
|
||||||
|
/* An WND_SCALE option with the right option length. */
|
||||||
|
pcb->snd_scale = opts[c + 2];
|
||||||
|
if (pcb->snd_scale > 14U) {
|
||||||
|
pcb->snd_scale = 14U;
|
||||||
|
}
|
||||||
|
pcb->rcv_scale = TCP_RCV_SCALE;
|
||||||
|
pcb->flags |= TF_WND_SCALE;
|
||||||
|
}
|
||||||
|
/* Advance to next option */
|
||||||
|
c += 0x03;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
#if LWIP_TCP_TIMESTAMPS
|
#if LWIP_TCP_TIMESTAMPS
|
||||||
case 0x08:
|
case 0x08:
|
||||||
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: TS\n"));
|
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_parseopt: TS\n"));
|
||||||
|
@ -108,7 +108,7 @@ tcp_output_alloc_header(struct tcp_pcb *pcb, u16_t optlen, u16_t datalen,
|
|||||||
tcphdr->seqno = seqno_be;
|
tcphdr->seqno = seqno_be;
|
||||||
tcphdr->ackno = htonl(pcb->rcv_nxt);
|
tcphdr->ackno = htonl(pcb->rcv_nxt);
|
||||||
TCPH_HDRLEN_FLAGS_SET(tcphdr, (5 + optlen / 4), TCP_ACK);
|
TCPH_HDRLEN_FLAGS_SET(tcphdr, (5 + optlen / 4), TCP_ACK);
|
||||||
tcphdr->wnd = htons(pcb->rcv_ann_wnd);
|
tcphdr->wnd = htons(RCV_WND_SCALE(pcb, pcb->rcv_ann_wnd));
|
||||||
tcphdr->chksum = 0;
|
tcphdr->chksum = 0;
|
||||||
tcphdr->urgp = 0;
|
tcphdr->urgp = 0;
|
||||||
|
|
||||||
@ -315,13 +315,13 @@ tcp_write_checks(struct tcp_pcb *pcb, u16_t len)
|
|||||||
return ERR_MEM;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_write: queuelen: %"U16_F"\n", (u16_t)pcb->snd_queuelen));
|
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_write: queuelen: %"TCPWNDSIZE_F"\n", (tcpwnd_size_t)pcb->snd_queuelen));
|
||||||
|
|
||||||
/* If total number of pbufs on the unsent/unacked queues exceeds the
|
/* If total number of pbufs on the unsent/unacked queues exceeds the
|
||||||
* configured maximum, return an error */
|
* configured maximum, return an error */
|
||||||
/* check for configured max queuelen and possible overflow */
|
/* check for configured max queuelen and possible overflow */
|
||||||
if ((pcb->snd_queuelen >= TCP_SND_QUEUELEN) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
|
if ((pcb->snd_queuelen >= TCP_SND_QUEUELEN) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
|
||||||
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_write: too long queue %"U16_F" (max %"U16_F")\n",
|
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 3, ("tcp_write: too long queue %"TCPWNDSIZE_F" (max %"TCPWNDSIZE_F")\n",
|
||||||
pcb->snd_queuelen, TCP_SND_QUEUELEN));
|
pcb->snd_queuelen, TCP_SND_QUEUELEN));
|
||||||
TCP_STATS_INC(tcp.memerr);
|
TCP_STATS_INC(tcp.memerr);
|
||||||
pcb->flags |= TF_NAGLEMEMERR;
|
pcb->flags |= TF_NAGLEMEMERR;
|
||||||
@ -581,7 +581,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
|
|||||||
* length of the queue exceeds the configured maximum or
|
* length of the queue exceeds the configured maximum or
|
||||||
* overflows. */
|
* overflows. */
|
||||||
if ((queuelen > TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
|
if ((queuelen > TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
|
||||||
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_write: queue too long %"U16_F" (%"U16_F")\n", queuelen, TCP_SND_QUEUELEN));
|
LWIP_DEBUGF(TCP_OUTPUT_DEBUG | 2, ("tcp_write: queue too long %"TCPWNDSIZE_F" (%"TCPWNDSIZE_F")\n", queuelen, TCP_SND_QUEUELEN));
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
goto memerr;
|
goto memerr;
|
||||||
}
|
}
|
||||||
@ -745,6 +745,13 @@ tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)
|
|||||||
|
|
||||||
if (flags & TCP_SYN) {
|
if (flags & TCP_SYN) {
|
||||||
optflags = TF_SEG_OPTS_MSS;
|
optflags = TF_SEG_OPTS_MSS;
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
if ((pcb->state != SYN_RCVD) || (pcb->flags & TF_WND_SCALE)) {
|
||||||
|
/* In a <SYN,ACK> (sent in state SYN_RCVD), the window scale option may only
|
||||||
|
be sent if we received a window scale option from the remote host. */
|
||||||
|
optflags |= TF_SEG_OPTS_WND_SCALE;
|
||||||
|
}
|
||||||
|
#endif /* LWIP_WND_SCALE */
|
||||||
}
|
}
|
||||||
#if LWIP_TCP_TIMESTAMPS
|
#if LWIP_TCP_TIMESTAMPS
|
||||||
if ((pcb->flags & TF_TIMESTAMP)) {
|
if ((pcb->flags & TF_TIMESTAMP)) {
|
||||||
@ -837,6 +844,19 @@ tcp_build_timestamp_option(struct tcp_pcb *pcb, u32_t *opts)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
/** Build a window scale option (3 bytes long) at the specified options pointer)
|
||||||
|
*
|
||||||
|
* @param opts option pointer where to store the window scale option
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
tcp_build_wnd_scale_option(u32_t *opts)
|
||||||
|
{
|
||||||
|
/* Pad with one NOP option to make everything nicely aligned */
|
||||||
|
opts[0] = PP_HTONL(0x01030300 | TCP_RCV_SCALE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Send an ACK without data.
|
/** Send an ACK without data.
|
||||||
*
|
*
|
||||||
* @param pcb Protocol control block for the TCP connection to send the ACK
|
* @param pcb Protocol control block for the TCP connection to send the ACK
|
||||||
@ -869,7 +889,7 @@ tcp_send_empty_ack(struct tcp_pcb *pcb)
|
|||||||
/* remove ACK flags from the PCB, as we send an empty ACK now */
|
/* remove ACK flags from the PCB, as we send an empty ACK now */
|
||||||
pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
|
pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
|
||||||
|
|
||||||
/* NB. MSS option is only sent on SYNs, so ignore it here */
|
/* NB. MSS and window scale options are only sent on SYNs, so ignore them here */
|
||||||
#if LWIP_TCP_TIMESTAMPS
|
#if LWIP_TCP_TIMESTAMPS
|
||||||
pcb->ts_lastacksent = pcb->rcv_nxt;
|
pcb->ts_lastacksent = pcb->rcv_nxt;
|
||||||
|
|
||||||
@ -952,13 +972,13 @@ tcp_output(struct tcp_pcb *pcb)
|
|||||||
#endif /* TCP_OUTPUT_DEBUG */
|
#endif /* TCP_OUTPUT_DEBUG */
|
||||||
#if TCP_CWND_DEBUG
|
#if TCP_CWND_DEBUG
|
||||||
if (seg == NULL) {
|
if (seg == NULL) {
|
||||||
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U16_F
|
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"TCPWNDSIZE_F
|
||||||
", cwnd %"U16_F", wnd %"U32_F
|
", cwnd %"TCPWNDSIZE_F", wnd %"U32_F
|
||||||
", seg == NULL, ack %"U32_F"\n",
|
", seg == NULL, ack %"U32_F"\n",
|
||||||
pcb->snd_wnd, pcb->cwnd, wnd, pcb->lastack));
|
pcb->snd_wnd, pcb->cwnd, wnd, pcb->lastack));
|
||||||
} else {
|
} else {
|
||||||
LWIP_DEBUGF(TCP_CWND_DEBUG,
|
LWIP_DEBUGF(TCP_CWND_DEBUG,
|
||||||
("tcp_output: snd_wnd %"U16_F", cwnd %"U16_F", wnd %"U32_F
|
("tcp_output: snd_wnd %"TCPWNDSIZE_F", cwnd %"TCPWNDSIZE_F", wnd %"U32_F
|
||||||
", effwnd %"U32_F", seq %"U32_F", ack %"U32_F"\n",
|
", effwnd %"U32_F", seq %"U32_F", ack %"U32_F"\n",
|
||||||
pcb->snd_wnd, pcb->cwnd, wnd,
|
pcb->snd_wnd, pcb->cwnd, wnd,
|
||||||
ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len,
|
ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len,
|
||||||
@ -982,7 +1002,7 @@ tcp_output(struct tcp_pcb *pcb)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if TCP_CWND_DEBUG
|
#if TCP_CWND_DEBUG
|
||||||
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"U16_F", cwnd %"U16_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F", i %"S16_F"\n",
|
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"TCPWNDSIZE_F", cwnd %"TCPWNDSIZE_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F", i %"S16_F"\n",
|
||||||
pcb->snd_wnd, pcb->cwnd, wnd,
|
pcb->snd_wnd, pcb->cwnd, wnd,
|
||||||
ntohl(seg->tcphdr->seqno) + seg->len -
|
ntohl(seg->tcphdr->seqno) + seg->len -
|
||||||
pcb->lastack,
|
pcb->lastack,
|
||||||
@ -1069,7 +1089,16 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
|||||||
seg->tcphdr->ackno = htonl(pcb->rcv_nxt);
|
seg->tcphdr->ackno = htonl(pcb->rcv_nxt);
|
||||||
|
|
||||||
/* advertise our receive window size in this TCP segment */
|
/* advertise our receive window size in this TCP segment */
|
||||||
seg->tcphdr->wnd = htons(pcb->rcv_ann_wnd);
|
#if LWIP_WND_SCALE
|
||||||
|
if (seg->flags & TF_SEG_OPTS_WND_SCALE) {
|
||||||
|
/* The Window field in a SYN segment itself (the only type where we send
|
||||||
|
the window scale option) is never scaled. */
|
||||||
|
seg->tcphdr->wnd = htons(pcb->rcv_ann_wnd);
|
||||||
|
} else
|
||||||
|
#endif /* LWIP_WND_SCALE */
|
||||||
|
{
|
||||||
|
seg->tcphdr->wnd = htons(RCV_WND_SCALE(pcb, pcb->rcv_ann_wnd));
|
||||||
|
}
|
||||||
|
|
||||||
pcb->rcv_ann_right_edge = pcb->rcv_nxt + pcb->rcv_ann_wnd;
|
pcb->rcv_ann_right_edge = pcb->rcv_nxt + pcb->rcv_ann_wnd;
|
||||||
|
|
||||||
@ -1094,6 +1123,12 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb)
|
|||||||
opts += 3;
|
opts += 3;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
if (seg->flags & TF_SEG_OPTS_WND_SCALE) {
|
||||||
|
tcp_build_wnd_scale_option(opts);
|
||||||
|
opts += 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Set retransmission timer running if it is not currently enabled
|
/* Set retransmission timer running if it is not currently enabled
|
||||||
This must be set before checking the route. */
|
This must be set before checking the route. */
|
||||||
@ -1224,7 +1259,11 @@ tcp_rst_impl(u32_t seqno, u32_t ackno,
|
|||||||
tcphdr->seqno = htonl(seqno);
|
tcphdr->seqno = htonl(seqno);
|
||||||
tcphdr->ackno = htonl(ackno);
|
tcphdr->ackno = htonl(ackno);
|
||||||
TCPH_HDRLEN_FLAGS_SET(tcphdr, TCP_HLEN/4, TCP_RST | TCP_ACK);
|
TCPH_HDRLEN_FLAGS_SET(tcphdr, TCP_HLEN/4, TCP_RST | TCP_ACK);
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
tcphdr->wnd = PP_HTONS(((TCP_WND >> TCP_RCV_SCALE) & 0xFFFF));
|
||||||
|
#else
|
||||||
tcphdr->wnd = PP_HTONS(TCP_WND);
|
tcphdr->wnd = PP_HTONS(TCP_WND);
|
||||||
|
#endif
|
||||||
tcphdr->chksum = 0;
|
tcphdr->chksum = 0;
|
||||||
tcphdr->urgp = 0;
|
tcphdr->urgp = 0;
|
||||||
|
|
||||||
@ -1356,7 +1395,7 @@ tcp_rexmit_fast(struct tcp_pcb *pcb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* The minimum value for ssthresh should be 2 MSS */
|
/* The minimum value for ssthresh should be 2 MSS */
|
||||||
if (pcb->ssthresh < 2*pcb->mss) {
|
if (pcb->ssthresh < (2U * pcb->mss)) {
|
||||||
LWIP_DEBUGF(TCP_FR_DEBUG,
|
LWIP_DEBUGF(TCP_FR_DEBUG,
|
||||||
("tcp_receive: The minimum value for ssthresh %"U16_F
|
("tcp_receive: The minimum value for ssthresh %"U16_F
|
||||||
" should be min 2 mss %"U16_F"...\n",
|
" should be min 2 mss %"U16_F"...\n",
|
||||||
|
@ -1080,6 +1080,19 @@
|
|||||||
#define LWIP_CALLBACK_API 1
|
#define LWIP_CALLBACK_API 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LWIP_WND_SCALE and TCP_RCV_SCALE:
|
||||||
|
* Set LWIP_WND_SCALE to 1 to enable window scaling.
|
||||||
|
* Set TCP_RCV_SCALE to the desired scaling factor (shift count in the
|
||||||
|
* range of [0..14]).
|
||||||
|
* When LWIP_WND_SCALE is enabled but TCP_RCV_SCALE is 0, we can use a large
|
||||||
|
* send window while having a small receive window only.
|
||||||
|
*/
|
||||||
|
#ifndef LWIP_WND_SCALE
|
||||||
|
#define LWIP_WND_SCALE 0
|
||||||
|
#define TCP_RCV_SCALE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
@ -125,6 +125,18 @@ typedef void (*tcp_err_fn)(void *arg, err_t err);
|
|||||||
*/
|
*/
|
||||||
typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err);
|
typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err);
|
||||||
|
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
#define RCV_WND_SCALE(pcb, wnd) (((wnd) >> (pcb)->rcv_scale))
|
||||||
|
#define SND_WND_SCALE(pcb, wnd) (((wnd) << (pcb)->snd_scale))
|
||||||
|
typedef u32_t tcpwnd_size_t;
|
||||||
|
typedef u16_t tcpflags_t;
|
||||||
|
#else
|
||||||
|
#define RCV_WND_SCALE(pcb, wnd) (wnd)
|
||||||
|
#define SND_WND_SCALE(pcb, wnd) (wnd)
|
||||||
|
typedef u16_t tcpwnd_size_t;
|
||||||
|
typedef u8_t tcpflags_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
enum tcp_state {
|
enum tcp_state {
|
||||||
CLOSED = 0,
|
CLOSED = 0,
|
||||||
LISTEN = 1,
|
LISTEN = 1,
|
||||||
@ -176,15 +188,18 @@ struct tcp_pcb {
|
|||||||
/* ports are in host byte order */
|
/* ports are in host byte order */
|
||||||
u16_t remote_port;
|
u16_t remote_port;
|
||||||
|
|
||||||
u8_t flags;
|
tcpflags_t flags;
|
||||||
#define TF_ACK_DELAY ((u8_t)0x01U) /* Delayed ACK. */
|
#define TF_ACK_DELAY ((tcpflags_t)0x0001U) /* Delayed ACK. */
|
||||||
#define TF_ACK_NOW ((u8_t)0x02U) /* Immediate ACK. */
|
#define TF_ACK_NOW ((tcpflags_t)0x0002U) /* Immediate ACK. */
|
||||||
#define TF_INFR ((u8_t)0x04U) /* In fast recovery. */
|
#define TF_INFR ((tcpflags_t)0x0004U) /* In fast recovery. */
|
||||||
#define TF_TIMESTAMP ((u8_t)0x08U) /* Timestamp option enabled */
|
#define TF_TIMESTAMP ((tcpflags_t)0x0008U) /* Timestamp option enabled */
|
||||||
#define TF_RXCLOSED ((u8_t)0x10U) /* rx closed by tcp_shutdown */
|
#define TF_RXCLOSED ((tcpflags_t)0x0010U) /* rx closed by tcp_shutdown */
|
||||||
#define TF_FIN ((u8_t)0x20U) /* Connection was closed locally (FIN segment enqueued). */
|
#define TF_FIN ((tcpflags_t)0x0020U) /* Connection was closed locally (FIN segment enqueued). */
|
||||||
#define TF_NODELAY ((u8_t)0x40U) /* Disable Nagle algorithm */
|
#define TF_NODELAY ((tcpflags_t)0x0040U) /* Disable Nagle algorithm */
|
||||||
#define TF_NAGLEMEMERR ((u8_t)0x80U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */
|
#define TF_NAGLEMEMERR ((tcpflags_t)0x0080U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
#define TF_WND_SCALE ((tcpflags_t)0x0100U) /* Window Scale option enabled */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* the rest of the fields are in host byte order
|
/* the rest of the fields are in host byte order
|
||||||
as we have to do some math with them */
|
as we have to do some math with them */
|
||||||
@ -196,8 +211,8 @@ struct tcp_pcb {
|
|||||||
|
|
||||||
/* receiver variables */
|
/* receiver variables */
|
||||||
u32_t rcv_nxt; /* next seqno expected */
|
u32_t rcv_nxt; /* next seqno expected */
|
||||||
u16_t rcv_wnd; /* receiver window available */
|
tcpwnd_size_t rcv_wnd; /* receiver window available */
|
||||||
u16_t rcv_ann_wnd; /* receiver window to announce */
|
tcpwnd_size_t rcv_ann_wnd; /* receiver window to announce */
|
||||||
u32_t rcv_ann_right_edge; /* announced right edge of window */
|
u32_t rcv_ann_right_edge; /* announced right edge of window */
|
||||||
|
|
||||||
/* Retransmission timer. */
|
/* Retransmission timer. */
|
||||||
@ -218,20 +233,20 @@ struct tcp_pcb {
|
|||||||
u32_t lastack; /* Highest acknowledged seqno. */
|
u32_t lastack; /* Highest acknowledged seqno. */
|
||||||
|
|
||||||
/* congestion avoidance/control variables */
|
/* congestion avoidance/control variables */
|
||||||
u16_t cwnd;
|
tcpwnd_size_t cwnd;
|
||||||
u16_t ssthresh;
|
tcpwnd_size_t ssthresh;
|
||||||
|
|
||||||
/* sender variables */
|
/* sender variables */
|
||||||
u32_t snd_nxt; /* next new seqno to be sent */
|
u32_t snd_nxt; /* next new seqno to be sent */
|
||||||
u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last
|
u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last
|
||||||
window update. */
|
window update. */
|
||||||
u32_t snd_lbb; /* Sequence number of next byte to be buffered. */
|
u32_t snd_lbb; /* Sequence number of next byte to be buffered. */
|
||||||
u16_t snd_wnd; /* sender window */
|
tcpwnd_size_t snd_wnd; /* sender window */
|
||||||
u16_t snd_wnd_max; /* the maximum sender window announced by the remote host */
|
tcpwnd_size_t snd_wnd_max; /* the maximum sender window announced by the remote host */
|
||||||
|
|
||||||
u16_t acked;
|
u16_t acked;
|
||||||
|
|
||||||
u16_t snd_buf; /* Available buffer space for sending (in bytes). */
|
tcpwnd_size_t snd_buf; /* Available buffer space for sending (in bytes). */
|
||||||
#define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3)
|
#define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3)
|
||||||
u16_t snd_queuelen; /* Available buffer space for sending (in pbufs). */
|
u16_t snd_queuelen; /* Available buffer space for sending (in pbufs). */
|
||||||
|
|
||||||
@ -281,6 +296,11 @@ struct tcp_pcb {
|
|||||||
|
|
||||||
/* KEEPALIVE counter */
|
/* KEEPALIVE counter */
|
||||||
u8_t keep_cnt_sent;
|
u8_t keep_cnt_sent;
|
||||||
|
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
u8_t snd_scale;
|
||||||
|
u8_t rcv_scale;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tcp_pcb_listen {
|
struct tcp_pcb_listen {
|
||||||
|
@ -183,7 +183,7 @@ PACK_STRUCT_END
|
|||||||
#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
|
#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
|
||||||
#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
|
#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
|
||||||
|
|
||||||
#define TCP_TCPLEN(seg) ((seg)->len + ((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0))
|
#define TCP_TCPLEN(seg) ((seg)->len + (((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0) ? 1U : 0U))
|
||||||
|
|
||||||
/** Flags used on input processing, not on pcb->flags
|
/** Flags used on input processing, not on pcb->flags
|
||||||
*/
|
*/
|
||||||
@ -294,16 +294,38 @@ struct tcp_seg {
|
|||||||
#define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
|
#define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */
|
||||||
#define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is
|
#define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is
|
||||||
checksummed into 'chksum' */
|
checksummed into 'chksum' */
|
||||||
|
#define TF_SEG_OPTS_WND_SCALE (u8_t)0x08U /* Include WND SCALE option */
|
||||||
struct tcp_hdr *tcphdr; /* the TCP header */
|
struct tcp_hdr *tcphdr; /* the TCP header */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LWIP_TCP_OPT_LENGTH(flags) \
|
#define LWIP_TCP_OPT_LEN_MSS 4
|
||||||
(flags & TF_SEG_OPTS_MSS ? 4 : 0) + \
|
#if LWIP_TCP_TIMESTAMPS
|
||||||
(flags & TF_SEG_OPTS_TS ? 12 : 0)
|
#define LWIP_TCP_OPT_LEN_TS 12
|
||||||
|
#else
|
||||||
|
#define LWIP_TCP_OPT_LEN_TS 0
|
||||||
|
#endif
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
#define LWIP_TCP_OPT_LEN_WS 4
|
||||||
|
#else
|
||||||
|
#define LWIP_TCP_OPT_LEN_WS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LWIP_TCP_OPT_LENGTH(flags) \
|
||||||
|
(flags & TF_SEG_OPTS_MSS ? LWIP_TCP_OPT_LEN_MSS : 0) + \
|
||||||
|
(flags & TF_SEG_OPTS_TS ? LWIP_TCP_OPT_LEN_TS : 0) + \
|
||||||
|
(flags & TF_SEG_OPTS_WND_SCALE ? LWIP_TCP_OPT_LEN_WS : 0)
|
||||||
|
|
||||||
/** This returns a TCP header option for MSS in an u32_t */
|
/** This returns a TCP header option for MSS in an u32_t */
|
||||||
#define TCP_BUILD_MSS_OPTION(mss) htonl(0x02040000 | ((mss) & 0xFFFF))
|
#define TCP_BUILD_MSS_OPTION(mss) htonl(0x02040000 | ((mss) & 0xFFFF))
|
||||||
|
|
||||||
|
#if LWIP_WND_SCALE
|
||||||
|
#define TCPWNDSIZE_F U32_F
|
||||||
|
#define TCPWND_MAX 0xFFFFFFFFU
|
||||||
|
#else /* LWIP_WND_SCALE */
|
||||||
|
#define TCPWNDSIZE_F U16_F
|
||||||
|
#define TCPWND_MAX 0xFFFFU
|
||||||
|
#endif /* LWIP_WND_SCALE */
|
||||||
|
|
||||||
/* Global variables: */
|
/* Global variables: */
|
||||||
extern struct tcp_pcb *tcp_input_pcb;
|
extern struct tcp_pcb *tcp_input_pcb;
|
||||||
extern u32_t tcp_ticks;
|
extern u32_t tcp_ticks;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user