mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-26 16:12:55 +00:00
[PATCH] Replace the OOSEQ max bytes and pbufs constants with functions.
Some systems need to take into account an RX buffer pool size when advising an appropriate number of RX pbufs to queue on the ooseq list. For some systems there is a practical hard limit beyond which the rx pool becomes exhausted blocking reception of further buffers until some are freed. It also helps to be able to consider the available dynamic memory when advising an appropriate maximum number of bytes to buffer on the ooseq list. These decisions can also benefit from knowing the number already allocated on a particular pcb, so the ooseq tcp segement is passed to these functions. For example, if the system only wants to allow the total number of rx pbufs queued on all the ooseq lists to grow by one and a pcb already has two then it can return three for this call, but might return one for another call - supporting a greedy allocation strategy. Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
parent
7dcc407c53
commit
dbd726959c
@ -96,9 +96,9 @@ static int tcp_input_delayed_close(struct tcp_pcb *pcb);
|
|||||||
#if LWIP_TCP_SACK_OUT
|
#if LWIP_TCP_SACK_OUT
|
||||||
static void tcp_add_sack(struct tcp_pcb *pcb, u32_t left, u32_t right);
|
static void tcp_add_sack(struct tcp_pcb *pcb, u32_t left, u32_t right);
|
||||||
static void tcp_remove_sacks_lt(struct tcp_pcb *pcb, u32_t seq);
|
static void tcp_remove_sacks_lt(struct tcp_pcb *pcb, u32_t seq);
|
||||||
#if TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS
|
#if defined(TCP_OOSEQ_BYTES_LIMIT) || defined(TCP_OOSEQ_PBUFS_LIMIT)
|
||||||
static void tcp_remove_sacks_gt(struct tcp_pcb *pcb, u32_t seq);
|
static void tcp_remove_sacks_gt(struct tcp_pcb *pcb, u32_t seq);
|
||||||
#endif /* TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS */
|
#endif /* TCP_OOSEQ_BYTES_LIMIT || TCP_OOSEQ_PBUFS_LIMIT */
|
||||||
#endif /* LWIP_TCP_SACK_OUT */
|
#endif /* LWIP_TCP_SACK_OUT */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1772,23 +1772,35 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
}
|
}
|
||||||
#endif /* LWIP_TCP_SACK_OUT */
|
#endif /* LWIP_TCP_SACK_OUT */
|
||||||
}
|
}
|
||||||
#if TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS
|
#if defined(TCP_OOSEQ_BYTES_LIMIT) || defined(TCP_OOSEQ_PBUFS_LIMIT)
|
||||||
{
|
{
|
||||||
/* Check that the data on ooseq doesn't exceed one of the limits
|
/* Check that the data on ooseq doesn't exceed one of the limits
|
||||||
and throw away everything above that limit. */
|
and throw away everything above that limit. */
|
||||||
|
#ifdef TCP_OOSEQ_BYTES_LIMIT
|
||||||
|
const u32_t ooseq_max_blen = TCP_OOSEQ_BYTES_LIMIT(pcb);
|
||||||
u32_t ooseq_blen = 0;
|
u32_t ooseq_blen = 0;
|
||||||
|
#endif
|
||||||
|
#ifdef TCP_OOSEQ_PBUFS_LIMIT
|
||||||
|
const u16_t ooseq_max_qlen = TCP_OOSEQ_PBUFS_LIMIT(pcb);
|
||||||
u16_t ooseq_qlen = 0;
|
u16_t ooseq_qlen = 0;
|
||||||
|
#endif
|
||||||
struct tcp_seg *next, *prev = NULL;
|
struct tcp_seg *next, *prev = NULL;
|
||||||
for (next = pcb->ooseq; next != NULL; prev = next, next = next->next) {
|
for (next = pcb->ooseq; next != NULL; prev = next, next = next->next) {
|
||||||
struct pbuf *p = next->p;
|
struct pbuf *p = next->p;
|
||||||
#if TCP_OOSEQ_MAX_BYTES
|
int stop_here = 0;
|
||||||
|
#ifdef TCP_OOSEQ_BYTES_LIMIT
|
||||||
ooseq_blen += p->tot_len;
|
ooseq_blen += p->tot_len;
|
||||||
|
if (ooseq_blen > ooseq_max_blen) {
|
||||||
|
stop_here = 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if TCP_OOSEQ_MAX_PBUFS
|
#ifdef TCP_OOSEQ_PBUFS_LIMIT
|
||||||
ooseq_qlen += pbuf_clen(p);
|
ooseq_qlen += pbuf_clen(p);
|
||||||
|
if (ooseq_qlen > ooseq_max_qlen) {
|
||||||
|
stop_here = 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if ((ooseq_blen > TCP_OOSEQ_MAX_BYTES) ||
|
if (stop_here) {
|
||||||
(ooseq_qlen > TCP_OOSEQ_MAX_PBUFS)) {
|
|
||||||
#if LWIP_TCP_SACK_OUT
|
#if LWIP_TCP_SACK_OUT
|
||||||
if (pcb->flags & TF_SACK) {
|
if (pcb->flags & TF_SACK) {
|
||||||
/* Let's remove all SACKs from next's seqno up. */
|
/* Let's remove all SACKs from next's seqno up. */
|
||||||
@ -1808,7 +1820,7 @@ tcp_receive(struct tcp_pcb *pcb)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS */
|
#endif /* TCP_OOSEQ_BYTES_LIMIT || TCP_OOSEQ_PBUFS_LIMIT */
|
||||||
#endif /* TCP_QUEUE_OOSEQ */
|
#endif /* TCP_QUEUE_OOSEQ */
|
||||||
|
|
||||||
/* We send the ACK packet after we've (potentially) dealt with SACKs,
|
/* We send the ACK packet after we've (potentially) dealt with SACKs,
|
||||||
@ -2074,7 +2086,7 @@ tcp_remove_sacks_lt(struct tcp_pcb *pcb, u32_t seq)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS
|
#if defined(TCP_OOSEQ_BYTES_LIMIT) || defined(TCP_OOSEQ_PBUFS_LIMIT)
|
||||||
/**
|
/**
|
||||||
* Called to remove a range of SACKs.
|
* Called to remove a range of SACKs.
|
||||||
*
|
*
|
||||||
@ -2113,7 +2125,7 @@ tcp_remove_sacks_gt(struct tcp_pcb *pcb, u32_t seq)
|
|||||||
pcb->rcv_sacks[i].left = pcb->rcv_sacks[i].right = 0;
|
pcb->rcv_sacks[i].left = pcb->rcv_sacks[i].right = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS */
|
#endif /* TCP_OOSEQ_BYTES_LIMIT || TCP_OOSEQ_PBUFS_LIMIT */
|
||||||
|
|
||||||
#endif /* LWIP_TCP_SACK_OUT */
|
#endif /* LWIP_TCP_SACK_OUT */
|
||||||
|
|
||||||
|
@ -1300,21 +1300,51 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCP_OOSEQ_MAX_BYTES: The maximum number of bytes queued on ooseq per pcb.
|
* TCP_OOSEQ_MAX_BYTES: The default maximum number of bytes queued on ooseq per
|
||||||
* Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==1.
|
* pcb if TCP_OOSEQ_BYTES_LIMIT is not defined. Default is 0 (no limit).
|
||||||
|
* Only valid for TCP_QUEUE_OOSEQ==1.
|
||||||
*/
|
*/
|
||||||
#if !defined TCP_OOSEQ_MAX_BYTES || defined __DOXYGEN__
|
#if !defined TCP_OOSEQ_MAX_BYTES || defined __DOXYGEN__
|
||||||
#define TCP_OOSEQ_MAX_BYTES 0
|
#define TCP_OOSEQ_MAX_BYTES 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCP_OOSEQ_MAX_PBUFS: The maximum number of pbufs queued on ooseq per pcb.
|
* TCP_OOSEQ_BYTES_LIMIT(pcb): Return the maximum number of bytes to be queued
|
||||||
* Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==1.
|
* on ooseq per pcb, given the pcb. Only valid for TCP_QUEUE_OOSEQ==1 &&
|
||||||
|
* TCP_OOSEQ_MAX_BYTES==1.
|
||||||
|
* Use this to override TCP_OOSEQ_MAX_BYTES to a dynamic value per pcb.
|
||||||
|
*/
|
||||||
|
#if !defined TCP_OOSEQ_BYTES_LIMIT
|
||||||
|
#if TCP_OOSEQ_MAX_BYTES
|
||||||
|
#define TCP_OOSEQ_BYTES_LIMIT(pcb) TCP_OOSEQ_MAX_BYTES
|
||||||
|
#elif defined __DOXYGEN__
|
||||||
|
#define TCP_OOSEQ_BYTES_LIMIT(pcb)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TCP_OOSEQ_MAX_PBUFS: The default maximum number of pbufs queued on ooseq per
|
||||||
|
* pcb if TCP_OOSEQ_BYTES_LIMIT is not defined. Default is 0 (no limit).
|
||||||
|
* Only valid for TCP_QUEUE_OOSEQ==1.
|
||||||
*/
|
*/
|
||||||
#if !defined TCP_OOSEQ_MAX_PBUFS || defined __DOXYGEN__
|
#if !defined TCP_OOSEQ_MAX_PBUFS || defined __DOXYGEN__
|
||||||
#define TCP_OOSEQ_MAX_PBUFS 0
|
#define TCP_OOSEQ_MAX_PBUFS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TCP_OOSEQ_PBUFS_LIMIT(pcb): Return the maximum number of pbufs to be queued
|
||||||
|
* on ooseq per pcb, given the pcb. Only valid for TCP_QUEUE_OOSEQ==1 &&
|
||||||
|
* TCP_OOSEQ_MAX_PBUFS==1.
|
||||||
|
* Use this to override TCP_OOSEQ_MAX_PBUFS to a dynamic value per pcb.
|
||||||
|
*/
|
||||||
|
#if !defined TCP_OOSEQ_PBUFS_LIMIT
|
||||||
|
#if TCP_OOSEQ_MAX_PBUFS
|
||||||
|
#define TCP_OOSEQ_PBUFS_LIMIT(pcb) TCP_OOSEQ_MAX_PBUFS
|
||||||
|
#elif defined __DOXYGEN__
|
||||||
|
#define TCP_OOSEQ_PBUFS_LIMIT(pcb)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb.
|
* TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user