net: tcp2: Eliminate the need for a test receive window
In order to drop dependency on a heap, drop the test receive window. The receive window was needed for TTCN-3 sanity check, but it's possible to do without it. Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
This commit is contained in:
parent
71a225d76f
commit
b25faa6159
2 changed files with 2 additions and 83 deletions
|
@ -38,49 +38,6 @@ int net_tcp_finalize(struct net_pkt *pkt);
|
||||||
|
|
||||||
int (*tcp_send_cb)(struct net_pkt *pkt) = NULL;
|
int (*tcp_send_cb)(struct net_pkt *pkt) = NULL;
|
||||||
|
|
||||||
/* TODO: Add mutex/irq lock */
|
|
||||||
static bool tcp_nbufs_reserve(struct tcp *conn, size_t len)
|
|
||||||
{
|
|
||||||
size_t rsv_bytes = 0, rsv_bytes_old = conn->rsv_bytes;
|
|
||||||
bool result = false;
|
|
||||||
struct net_buf *buf;
|
|
||||||
|
|
||||||
while (rsv_bytes < len) {
|
|
||||||
|
|
||||||
buf = tcp_nbuf_alloc(conn, CONFIG_NET_BUF_DATA_SIZE);
|
|
||||||
|
|
||||||
NET_ASSERT(buf);
|
|
||||||
|
|
||||||
sys_slist_append(&conn->rsv_bufs, &buf->node);
|
|
||||||
|
|
||||||
rsv_bytes += buf->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rsv_bytes >= len) {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
conn->rsv_bytes += rsv_bytes;
|
|
||||||
|
|
||||||
NET_DBG("%zu->%zu", rsv_bytes_old, conn->rsv_bytes);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_nbufs_unreserve(struct tcp *conn)
|
|
||||||
{
|
|
||||||
size_t rsv_bytes_old = conn->rsv_bytes;
|
|
||||||
struct net_buf *buf;
|
|
||||||
|
|
||||||
while ((buf = tcp_slist(&conn->rsv_bufs, get, struct net_buf, node))) {
|
|
||||||
conn->rsv_bytes -= buf->size;
|
|
||||||
buf->frags = NULL;
|
|
||||||
tcp_nbuf_unref(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_DBG("%zu->%zu", rsv_bytes_old, conn->rsv_bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct tcphdr *th_get(struct net_pkt *pkt)
|
static struct tcphdr *th_get(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
NET_PKT_DATA_ACCESS_DEFINE(th_access, struct tcphdr);
|
NET_PKT_DATA_ACCESS_DEFINE(th_access, struct tcphdr);
|
||||||
|
@ -307,12 +264,9 @@ static int tcp_conn_unref(struct tcp *conn)
|
||||||
|
|
||||||
net_context_unref(conn->context);
|
net_context_unref(conn->context);
|
||||||
|
|
||||||
tcp_nbufs_unreserve(conn);
|
|
||||||
|
|
||||||
tcp_send_queue_flush(conn);
|
tcp_send_queue_flush(conn);
|
||||||
|
|
||||||
tcp_win_free(conn->snd, "SND");
|
tcp_win_free(conn->snd, "SND");
|
||||||
tcp_win_free(conn->rcv, "RCV");
|
|
||||||
|
|
||||||
tcp_free(conn->src);
|
tcp_free(conn->src);
|
||||||
tcp_free(conn->dst);
|
tcp_free(conn->dst);
|
||||||
|
@ -565,31 +519,9 @@ static size_t tcp_data_len(struct net_pkt *pkt)
|
||||||
|
|
||||||
static size_t tcp_data_get(struct tcp *conn, struct net_pkt *pkt)
|
static size_t tcp_data_get(struct tcp *conn, struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
struct tcphdr *th = th_get(pkt);
|
|
||||||
ssize_t len = tcp_data_len(pkt);
|
ssize_t len = tcp_data_len(pkt);
|
||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
void *buf;
|
|
||||||
|
|
||||||
if (tcp_nbufs_reserve(conn, len) == false) {
|
|
||||||
len = 0;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = tcp_malloc(len);
|
|
||||||
|
|
||||||
net_pkt_skip(pkt, th->th_off * 4);
|
|
||||||
|
|
||||||
net_pkt_read(pkt, buf, len);
|
|
||||||
|
|
||||||
tcp_win_append(conn, conn->rcv, "RCV", buf, len);
|
|
||||||
|
|
||||||
if (tcp_echo) {
|
|
||||||
tcp_win_append(conn, conn->snd, "SND", buf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
tcp_free(buf);
|
|
||||||
|
|
||||||
if (conn->context->recv_cb) {
|
if (conn->context->recv_cb) {
|
||||||
struct net_pkt *up = net_pkt_clone(pkt, K_NO_WAIT);
|
struct net_pkt *up = net_pkt_clone(pkt, K_NO_WAIT);
|
||||||
|
|
||||||
|
@ -603,7 +535,7 @@ static size_t tcp_data_get(struct tcp *conn, struct net_pkt *pkt)
|
||||||
up, NULL, NULL, conn->recv_user_data);
|
up, NULL, NULL, conn->recv_user_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -780,13 +712,10 @@ static struct tcp *tcp_conn_alloc(void)
|
||||||
|
|
||||||
conn->win = tcp_window;
|
conn->win = tcp_window;
|
||||||
|
|
||||||
conn->rcv = tcp_win_new();
|
|
||||||
conn->snd = tcp_win_new();
|
conn->snd = tcp_win_new();
|
||||||
|
|
||||||
sys_slist_init(&conn->send_queue);
|
sys_slist_init(&conn->send_queue);
|
||||||
|
|
||||||
sys_slist_init(&conn->rsv_bufs);
|
|
||||||
|
|
||||||
k_delayed_work_init(&conn->send_timer, tcp_send_process);
|
k_delayed_work_init(&conn->send_timer, tcp_send_process);
|
||||||
|
|
||||||
tcp_conn_ref(conn);
|
tcp_conn_ref(conn);
|
||||||
|
|
|
@ -153,7 +153,6 @@ struct tcp { /* TCP connection */
|
||||||
union tcp_endpoint *src;
|
union tcp_endpoint *src;
|
||||||
union tcp_endpoint *dst;
|
union tcp_endpoint *dst;
|
||||||
u16_t win;
|
u16_t win;
|
||||||
struct tcp_win *rcv;
|
|
||||||
struct tcp_win *snd;
|
struct tcp_win *snd;
|
||||||
struct k_delayed_work send_timer;
|
struct k_delayed_work send_timer;
|
||||||
sys_slist_t send_queue;
|
sys_slist_t send_queue;
|
||||||
|
@ -162,8 +161,6 @@ struct tcp { /* TCP connection */
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
net_tcp_accept_cb_t accept_cb;
|
net_tcp_accept_cb_t accept_cb;
|
||||||
atomic_t ref_count;
|
atomic_t ref_count;
|
||||||
sys_slist_t rsv_bufs;
|
|
||||||
size_t rsv_bytes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define _flags(_fl, _op, _mask, _cond) \
|
#define _flags(_fl, _op, _mask, _cond) \
|
||||||
|
@ -197,14 +194,7 @@ extern struct net_buf_pool tcp_nbufs;
|
||||||
#else
|
#else
|
||||||
static struct net_buf *tcp_nbuf_alloc(struct tcp *conn, size_t len)
|
static struct net_buf *tcp_nbuf_alloc(struct tcp *conn, size_t len)
|
||||||
{
|
{
|
||||||
struct net_buf *buf;
|
struct net_buf *buf = net_buf_alloc_len(&tcp_nbufs, len, K_NO_WAIT);
|
||||||
|
|
||||||
if (conn->rsv_bytes >= len) {
|
|
||||||
buf = tcp_slist(&conn->rsv_bufs, get, struct net_buf, node);
|
|
||||||
conn->rsv_bytes -= buf->size;
|
|
||||||
} else {
|
|
||||||
buf = net_buf_alloc_len(&tcp_nbufs, len, K_NO_WAIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_ASSERT(buf && buf->size >= len);
|
NET_ASSERT(buf && buf->size >= len);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue