Commit a93779b0 authored by Andy Ross's avatar Andy Ross Committed by Jukka Rissanen
Browse files

net: tcp: Refactor "finalize" step from "prepare"



The ACK field of a packet depends on the received sequence number from
the other side of a connection, which can change long after a packet
is prepared/queued.  The IP finalize step (which computes things like
the TCP checksum) needs to be invoked just before a packet is sent,
not from prepare.

Split it out to a separate function.

Change-Id: Ibdae0c9b6833bdfb130cc381f823150dceab6637
Signed-off-by: default avatarAndy Ross <andrew.j.ross@intel.com>
parent 094c6505
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -183,10 +183,30 @@ static inline int net_tcp_add_options(struct net_buf *header, size_t len,
	return 0;
}

static int finalize_segment(struct net_context *context, struct net_buf *buf)
{
	int ret = 0;
#if defined(CONFIG_NET_IPV4)
	if (net_nbuf_family(buf) == AF_INET) {
		net_ipv4_finalize(context, buf);
	} else
#endif
#if defined(CONFIG_NET_IPV6)
	if (net_nbuf_family(buf) == AF_INET6) {
		net_ipv6_finalize(context, buf);
	} else
#endif
	{
		ret = -EPROTOTYPE;
	}
	return ret;
}

static struct net_buf *prepare_segment(struct net_tcp *tcp,
				       struct tcp_segment *segment,
				       struct net_buf *buf)
{
	int err;
	struct net_buf *header, *tail = NULL;
	struct net_tcp_hdr *tcphdr;
	struct net_context *context = tcp->context;
@@ -260,17 +280,8 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp,
		net_buf_frag_add(buf, tail);
	}

#if defined(CONFIG_NET_IPV4)
	if (net_nbuf_family(buf) == AF_INET) {
		net_ipv4_finalize(context, buf);
	} else
#endif
#if defined(CONFIG_NET_IPV6)
	if (net_nbuf_family(buf) == AF_INET6) {
		net_ipv6_finalize(context, buf);
	} else
#endif
	{
	err = finalize_segment(context, buf);
	if (err) {
	proto_err:
		NET_DBG("Protocol family %d not supported",
			net_nbuf_family(buf));