From fd1401495b9359b844a82d10de66c6ec1df50cff Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Fri, 1 Feb 2019 21:50:41 +0100 Subject: [PATCH] net/tcp: Move net_tcp_set_hdr() away from net core Only the unit test needs it now, so let's move it there. Signed-off-by: Tomasz Bursztyka --- include/net/tcp.h | 51 ----------------------------------- subsys/net/ip/connection.c | 1 - subsys/net/ip/ipv4.c | 1 - subsys/net/ip/ipv6.c | 1 - subsys/net/ip/ipv6_fragment.c | 1 - subsys/net/ip/ipv6_mld.c | 1 - subsys/net/ip/ipv6_nbr.c | 1 - subsys/net/ip/net_context.c | 1 - subsys/net/ip/net_core.c | 1 - subsys/net/ip/net_pkt.c | 1 - subsys/net/ip/net_shell.c | 1 - subsys/net/ip/tcp.c | 36 ------------------------- subsys/net/ip/tcp_internal.h | 8 ------ tests/net/tcp/src/main.c | 36 ++++++++++++++++++++++++- 14 files changed, 35 insertions(+), 106 deletions(-) delete mode 100644 include/net/tcp.h diff --git a/include/net/tcp.h b/include/net/tcp.h deleted file mode 100644 index e7f94861f2a..00000000000 --- a/include/net/tcp.h +++ /dev/null @@ -1,51 +0,0 @@ -/** @file - * @brief TCP utility functions - */ - -/* - * Copyright (c) 2018 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_INCLUDE_NET_TCP_H_ -#define ZEPHYR_INCLUDE_NET_TCP_H_ - -#include - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(CONFIG_NET_TCP) - -/** - * @brief Set TCP packet header data in net_pkt. - * - * @details The values in the header must be in network byte order. - * This function is normally called after a call to net_tcp_get_hdr(). - * The hdr parameter value should be the same that is returned by function - * net_tcp_get_hdr() call. Note that if the TCP header fits in first net_pkt - * fragment, then this function will not do anything as the returned value - * was pointing directly to net_pkt. - * - * @param pkt Network packet - * @param hdr Header data pointer that was returned by net_tcp_get_hdr(). - * - * @return Return hdr or NULL if error - */ -struct net_tcp_hdr *net_tcp_set_hdr(struct net_pkt *pkt, - struct net_tcp_hdr *hdr); - -#endif /* CONFIG_NET_TCP */ - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_NET_TCP_H_ */ diff --git a/subsys/net/ip/connection.c b/subsys/net/ip/connection.c index bdb3c94e08c..db21cf2b4ed 100644 --- a/subsys/net/ip/connection.c +++ b/subsys/net/ip/connection.c @@ -17,7 +17,6 @@ LOG_MODULE_REGISTER(net_conn, CONFIG_NET_CONN_LOG_LEVEL); #include #include #include -#include #include #include diff --git a/subsys/net/ip/ipv4.c b/subsys/net/ip/ipv4.c index 1c675105100..ba4f485a42b 100644 --- a/subsys/net/ip/ipv4.c +++ b/subsys/net/ip/ipv4.c @@ -16,7 +16,6 @@ LOG_MODULE_REGISTER(net_ipv4, CONFIG_NET_IPV4_LOG_LEVEL); #include #include #include -#include #include "net_private.h" #include "connection.h" #include "net_stats.h" diff --git a/subsys/net/ip/ipv6.c b/subsys/net/ip/ipv6.c index d596d275e39..4665cefb46c 100644 --- a/subsys/net/ip/ipv6.c +++ b/subsys/net/ip/ipv6.c @@ -23,7 +23,6 @@ LOG_MODULE_REGISTER(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL); #include #include #include -#include #include "net_private.h" #include "connection.h" #include "icmpv6.h" diff --git a/subsys/net/ip/ipv6_fragment.c b/subsys/net/ip/ipv6_fragment.c index d1a3241d593..e70e45e8eeb 100644 --- a/subsys/net/ip/ipv6_fragment.c +++ b/subsys/net/ip/ipv6_fragment.c @@ -17,7 +17,6 @@ LOG_MODULE_DECLARE(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL); #include #include #include -#include #include "net_private.h" #include "connection.h" #include "icmpv6.h" diff --git a/subsys/net/ip/ipv6_mld.c b/subsys/net/ip/ipv6_mld.c index f9850f5dc1e..4ebadf7722a 100644 --- a/subsys/net/ip/ipv6_mld.c +++ b/subsys/net/ip/ipv6_mld.c @@ -17,7 +17,6 @@ LOG_MODULE_DECLARE(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL); #include #include #include -#include #include "net_private.h" #include "connection.h" #include "icmpv6.h" diff --git a/subsys/net/ip/ipv6_nbr.c b/subsys/net/ip/ipv6_nbr.c index 67d4082eafc..b02c299a9e5 100644 --- a/subsys/net/ip/ipv6_nbr.c +++ b/subsys/net/ip/ipv6_nbr.c @@ -23,7 +23,6 @@ LOG_MODULE_DECLARE(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL); #include #include #include -#include #include "net_private.h" #include "connection.h" #include "icmpv6.h" diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index e8be39a938f..5d7c91e8046 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -22,7 +22,6 @@ LOG_MODULE_REGISTER(net_ctx, CONFIG_NET_CONTEXT_LOG_LEVEL); #include #include #include -#include #include #include diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index 20b5120451f..0ca5e9ce9b0 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -26,7 +26,6 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL); #include #include #include -#include #include #include diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index 0a07dc7ad42..4b14f12e0c1 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -37,7 +37,6 @@ LOG_MODULE_REGISTER(net_pkt, CONFIG_NET_PKT_LOG_LEVEL); #include #include #include -#include #include "net_private.h" #include "tcp_internal.h" diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 6a9dc185754..314a410ce7a 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -29,7 +29,6 @@ LOG_MODULE_REGISTER(net_shell, LOG_LEVEL_DBG); #include "connection.h" #if defined(CONFIG_NET_TCP) -#include #include "tcp_internal.h" #endif diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index eeb09d32305..4952c82ce0e 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -24,7 +24,6 @@ LOG_MODULE_REGISTER(net_tcp, CONFIG_NET_TCP_LOG_LEVEL); #include #include #include -#include #include #include "connection.h" @@ -1266,41 +1265,6 @@ bool net_tcp_validate_seq(struct net_tcp *tcp, struct net_tcp_hdr *tcp_hdr) + net_tcp_get_recv_wnd(tcp)) < 0); } -struct net_tcp_hdr *net_tcp_set_hdr(struct net_pkt *pkt, - struct net_tcp_hdr *hdr) -{ - NET_PKT_DATA_ACCESS_DEFINE(tcp_access, struct net_tcp_hdr); - struct net_pkt_cursor backup; - struct net_tcp_hdr *tcp_hdr; - bool overwrite; - - overwrite = net_pkt_is_being_overwritten(pkt); - net_pkt_set_overwrite(pkt, true); - - net_pkt_cursor_backup(pkt, &backup); - net_pkt_cursor_init(pkt); - - if (net_pkt_skip(pkt, net_pkt_ip_hdr_len(pkt) + - net_pkt_ipv6_ext_len(pkt))) { - tcp_hdr = NULL; - goto out; - } - - tcp_hdr = (struct net_tcp_hdr *)net_pkt_get_data_new(pkt, &tcp_access); - if (!tcp_hdr) { - goto out; - } - - memcpy(tcp_hdr, hdr, sizeof(struct net_tcp_hdr)); - - net_pkt_set_data(pkt, &tcp_access); -out: - net_pkt_cursor_restore(pkt, &backup); - net_pkt_set_overwrite(pkt, overwrite); - - return tcp_hdr == NULL ? NULL : hdr; -} - int net_tcp_finalize(struct net_pkt *pkt) { NET_PKT_DATA_ACCESS_DEFINE(tcp_access, struct net_tcp_hdr); diff --git a/subsys/net/ip/tcp_internal.h b/subsys/net/ip/tcp_internal.h index 9f3175dc99e..a359c5a0339 100644 --- a/subsys/net/ip/tcp_internal.h +++ b/subsys/net/ip/tcp_internal.h @@ -659,14 +659,6 @@ static inline int net_tcp_finalize(struct net_pkt *pkt) return 0; } -static inline struct net_tcp_hdr *net_tcp_set_hdr(struct net_pkt *pkt, - struct net_tcp_hdr *hdr) -{ - ARG_UNUSED(pkt); - ARG_UNUSED(hdr); - return NULL; -} - static inline int tcp_hdr_len(struct net_pkt *pkt) { ARG_UNUSED(pkt); diff --git a/tests/net/tcp/src/main.c b/tests/net/tcp/src/main.c index ede1ac977e4..68efc9cedf6 100644 --- a/tests/net/tcp/src/main.c +++ b/tests/net/tcp/src/main.c @@ -23,7 +23,6 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_TCP_LOG_LEVEL); #include #include #include -#include #include #include @@ -247,6 +246,41 @@ out: return tcp_hdr; } +struct net_tcp_hdr *net_tcp_set_hdr(struct net_pkt *pkt, + struct net_tcp_hdr *hdr) +{ + NET_PKT_DATA_ACCESS_DEFINE(tcp_access, struct net_tcp_hdr); + struct net_pkt_cursor backup; + struct net_tcp_hdr *tcp_hdr; + bool overwrite; + + overwrite = net_pkt_is_being_overwritten(pkt); + net_pkt_set_overwrite(pkt, true); + + net_pkt_cursor_backup(pkt, &backup); + net_pkt_cursor_init(pkt); + + if (net_pkt_skip(pkt, net_pkt_ip_hdr_len(pkt) + + net_pkt_ipv6_ext_len(pkt))) { + tcp_hdr = NULL; + goto out; + } + + tcp_hdr = (struct net_tcp_hdr *)net_pkt_get_data_new(pkt, &tcp_access); + if (!tcp_hdr) { + goto out; + } + + memcpy(tcp_hdr, hdr, sizeof(struct net_tcp_hdr)); + + net_pkt_set_data(pkt, &tcp_access); +out: + net_pkt_cursor_restore(pkt, &backup); + net_pkt_set_overwrite(pkt, overwrite); + + return tcp_hdr == NULL ? NULL : hdr; +} + struct ud { const struct sockaddr *remote_addr; const struct sockaddr *local_addr;