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 <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2019-02-01 21:50:41 +01:00 committed by Anas Nashif
parent 869427c8bc
commit fd1401495b
14 changed files with 35 additions and 106 deletions

View File

@ -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 <zephyr/types.h>
#include <net/net_core.h>
#include <net/net_ip.h>
#include <net/net_pkt.h>
#include <net/net_context.h>
#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_ */

View File

@ -17,7 +17,6 @@ LOG_MODULE_REGISTER(net_conn, CONFIG_NET_CONN_LOG_LEVEL);
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/udp.h>
#include <net/tcp.h>
#include <net/ethernet.h>
#include <net/socket_can.h>

View File

@ -16,7 +16,6 @@ LOG_MODULE_REGISTER(net_ipv4, CONFIG_NET_IPV4_LOG_LEVEL);
#include <net/net_pkt.h>
#include <net/net_stats.h>
#include <net/net_context.h>
#include <net/tcp.h>
#include "net_private.h"
#include "connection.h"
#include "net_stats.h"

View File

@ -23,7 +23,6 @@ LOG_MODULE_REGISTER(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL);
#include <net/net_stats.h>
#include <net/net_context.h>
#include <net/net_mgmt.h>
#include <net/tcp.h>
#include "net_private.h"
#include "connection.h"
#include "icmpv6.h"

View File

@ -17,7 +17,6 @@ LOG_MODULE_DECLARE(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL);
#include <net/net_stats.h>
#include <net/net_context.h>
#include <net/net_mgmt.h>
#include <net/tcp.h>
#include "net_private.h"
#include "connection.h"
#include "icmpv6.h"

View File

@ -17,7 +17,6 @@ LOG_MODULE_DECLARE(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL);
#include <net/net_stats.h>
#include <net/net_context.h>
#include <net/net_mgmt.h>
#include <net/tcp.h>
#include "net_private.h"
#include "connection.h"
#include "icmpv6.h"

View File

@ -23,7 +23,6 @@ LOG_MODULE_DECLARE(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL);
#include <net/net_stats.h>
#include <net/net_context.h>
#include <net/net_mgmt.h>
#include <net/tcp.h>
#include "net_private.h"
#include "connection.h"
#include "icmpv6.h"

View File

@ -22,7 +22,6 @@ LOG_MODULE_REGISTER(net_ctx, CONFIG_NET_CONTEXT_LOG_LEVEL);
#include <net/net_ip.h>
#include <net/net_context.h>
#include <net/net_offload.h>
#include <net/tcp.h>
#include <net/ethernet.h>
#include <net/socket_can.h>

View File

@ -26,7 +26,6 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL);
#include <net/net_pkt.h>
#include <net/net_core.h>
#include <net/dns_resolve.h>
#include <net/tcp.h>
#include <net/gptp.h>
#include <net/lldp.h>

View File

@ -37,7 +37,6 @@ LOG_MODULE_REGISTER(net_pkt, CONFIG_NET_PKT_LOG_LEVEL);
#include <net/net_pkt.h>
#include <net/ethernet.h>
#include <net/udp.h>
#include <net/tcp.h>
#include "net_private.h"
#include "tcp_internal.h"

View File

@ -29,7 +29,6 @@ LOG_MODULE_REGISTER(net_shell, LOG_LEVEL_DBG);
#include "connection.h"
#if defined(CONFIG_NET_TCP)
#include <net/tcp.h>
#include "tcp_internal.h"
#endif

View File

@ -24,7 +24,6 @@ LOG_MODULE_REGISTER(net_tcp, CONFIG_NET_TCP_LOG_LEVEL);
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/net_context.h>
#include <net/tcp.h>
#include <misc/byteorder.h>
#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);

View File

@ -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);

View File

@ -23,7 +23,6 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_TCP_LOG_LEVEL);
#include <net/net_core.h>
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/tcp.h>
#include <net/dummy.h>
#include <tc_util.h>
@ -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;