[tcp] remove extraneous #define and restrict inclusion of TCPlp headers (#7570)

* remove extraneous #define
* restrict inclusion of `third_party/tcplp/tcplp.h`
This commit is contained in:
Sam Kumar
2022-04-07 10:42:17 -07:00
committed by GitHub
parent 97a7910172
commit cda71d1b25
7 changed files with 84 additions and 40 deletions
+55 -4
View File
@@ -57,6 +57,17 @@ using ot::Encoding::BigEndian::HostSwap32;
RegisterLogModule("Tcp");
static_assert(sizeof(struct tcpcb) == sizeof(Tcp::Endpoint::mTcb), "mTcb field in otTcpEndpoint is sized incorrectly");
static_assert(alignof(struct tcpcb) == alignof(decltype(Tcp::Endpoint::mTcb)),
"mTcb field in otTcpEndpoint is aligned incorrectly");
static_assert(offsetof(Tcp::Endpoint, mTcb) == 0, "mTcb field in otTcpEndpoint has nonzero offset");
static_assert(sizeof(struct tcpcb_listen) == sizeof(Tcp::Listener::mTcbListen),
"mTcbListen field in otTcpListener is sized incorrectly");
static_assert(alignof(struct tcpcb_listen) == alignof(decltype(Tcp::Listener::mTcbListen)),
"mTcbListen field in otTcpListener is aligned incorrectly");
static_assert(offsetof(Tcp::Listener, mTcbListen) == 0, "mTcbListen field in otTcpEndpoint has nonzero offset");
Tcp::Tcp(Instance &aInstance)
: InstanceLocator(aInstance)
, mTimer(aInstance, Tcp::HandleTimer)
@@ -259,6 +270,11 @@ exit:
return error;
}
bool Tcp::Endpoint::IsClosed(void) const
{
return GetTcb().t_state == TCP6S_CLOSED;
}
uint8_t Tcp::Endpoint::TimerFlagToIndex(uint8_t aTimerFlag)
{
uint8_t timerIndex = 0;
@@ -412,6 +428,26 @@ exit:
return calledUserCallback;
}
Address &Tcp::Endpoint::GetLocalIp6Address(void)
{
return *reinterpret_cast<Address *>(&GetTcb().laddr);
}
const Address &Tcp::Endpoint::GetLocalIp6Address(void) const
{
return *reinterpret_cast<const Address *>(&GetTcb().laddr);
}
Address &Tcp::Endpoint::GetForeignIp6Address(void)
{
return *reinterpret_cast<Address *>(&GetTcb().faddr);
}
const Address &Tcp::Endpoint::GetForeignIp6Address(void) const
{
return *reinterpret_cast<const Address *>(&GetTcb().faddr);
}
bool Tcp::Endpoint::Matches(const MessageInfo &aMessageInfo) const
{
bool matches = false;
@@ -494,6 +530,21 @@ exit:
return error;
}
bool Tcp::Listener::IsClosed(void) const
{
return GetTcbListen().t_state == TCP6S_CLOSED;
}
Address &Tcp::Listener::GetLocalIp6Address(void)
{
return *reinterpret_cast<Address *>(&GetTcbListen().laddr);
}
const Address &Tcp::Listener::GetLocalIp6Address(void) const
{
return *reinterpret_cast<const Address *>(&GetTcbListen().laddr);
}
bool Tcp::Listener::Matches(const MessageInfo &aMessageInfo) const
{
bool matches = false;
@@ -551,9 +602,9 @@ Error Tcp::HandleMessage(ot::Ip6::Header &aIp6Header, Message &aMessage, Message
endpoint = mEndpoints.FindMatching(aMessageInfo, endpointPrev);
if (endpoint != nullptr)
{
struct signals sig;
int nextAction;
struct tcpcb * tp = &endpoint->GetTcb();
struct tcplp_signals sig;
int nextAction;
struct tcpcb * tp = &endpoint->GetTcb();
otLinkedBuffer *priorHead = lbuf_head(&tp->sendbuf);
@@ -583,7 +634,7 @@ exit:
return error;
}
void Tcp::ProcessSignals(Endpoint &aEndpoint, otLinkedBuffer *aPriorHead, struct signals &aSignals)
void Tcp::ProcessSignals(Endpoint &aEndpoint, otLinkedBuffer *aPriorHead, struct tcplp_signals &aSignals)
{
VerifyOrExit(IsInitialized(aEndpoint) && !aEndpoint.IsClosed());
if (aEndpoint.mSendDoneCallback != nullptr)
+21 -26
View File
@@ -47,7 +47,17 @@
#include "net/ip6_headers.hpp"
#include "net/socket.hpp"
#include "../../third_party/tcplp/tcplp.h"
/*
* These structures and functions are forward-declared here to avoid
* #includ'ing third_party/tcplp/tcplp.h in this header file.
*/
extern "C" {
struct tcpcb;
struct tcpcb_listen;
struct tcplp_signals;
void tcplp_sys_set_timer(struct tcpcb *aTcb, uint8_t aTimerFlag, uint32_t aDelay);
void tcplp_sys_stop_timer(struct tcpcb *aTcb, uint8_t aTimerFlag);
}
namespace ot {
namespace Ip6 {
@@ -352,12 +362,11 @@ public:
/**
* Checks if this Endpoint is in the closed state.
*/
bool IsClosed(void) const { return GetTcb().t_state == TCP6S_CLOSED; }
bool IsClosed(void) const;
private:
friend void ::tcplp_sys_set_timer(struct tcpcb *aTcb, uint8_t aTimerFlag, uint32_t aDelay);
friend void ::tcplp_sys_stop_timer(struct tcpcb *aTcb, uint8_t aTimerFlag);
friend void ::tcplp_sys_connection_lost(struct tcpcb *aTcb, uint8_t aErrNum);
enum : uint8_t
{
@@ -375,18 +384,13 @@ public:
void CancelTimer(uint8_t aTimerFlag);
bool FirePendingTimers(TimeMilli aNow, bool &aHasFutureTimer, TimeMilli &aEarliestFutureExpiry);
Address & GetLocalIp6Address(void) { return *reinterpret_cast<Address *>(&GetTcb().laddr); }
const Address &GetLocalIp6Address(void) const { return *reinterpret_cast<const Address *>(&GetTcb().laddr); }
Address & GetForeignIp6Address(void) { return *reinterpret_cast<Address *>(&GetTcb().faddr); }
const Address &GetForeignIp6Address(void) const { return *reinterpret_cast<const Address *>(&GetTcb().faddr); }
Address & GetLocalIp6Address(void);
const Address &GetLocalIp6Address(void) const;
Address & GetForeignIp6Address(void);
const Address &GetForeignIp6Address(void) const;
bool Matches(const MessageInfo &aMessageInfo) const;
};
static_assert(sizeof(struct tcpcb) == sizeof(Endpoint::mTcb), "mTcb field in otTcpEndpoint is sized incorrectly");
static_assert(alignof(struct tcpcb) == alignof(decltype(Endpoint::mTcb)),
"mTcb field in otTcpEndpoint is aligned incorrectly");
static_assert(offsetof(Endpoint, mTcb) == 0, "mTcb field in otTcpEndpoint has nonzero offset");
/**
* This class represents a TCP/IPv6 listener.
*
@@ -506,23 +510,14 @@ public:
/**
* Checks if this Listener is in the closed state.
*/
bool IsClosed(void) const { return GetTcbListen().t_state == TCP6S_CLOSED; }
bool IsClosed(void) const;
private:
Address & GetLocalIp6Address(void) { return *reinterpret_cast<Address *>(&GetTcbListen().laddr); }
const Address &GetLocalIp6Address(void) const
{
return *reinterpret_cast<const Address *>(&GetTcbListen().laddr);
}
bool Matches(const MessageInfo &aMessageInfo) const;
Address & GetLocalIp6Address(void);
const Address &GetLocalIp6Address(void) const;
bool Matches(const MessageInfo &aMessageInfo) const;
};
static_assert(sizeof(struct tcpcb_listen) == sizeof(Listener::mTcbListen),
"mTcbListen field in otTcpListener is sized incorrectly");
static_assert(alignof(struct tcpcb_listen) == alignof(decltype(Listener::mTcbListen)),
"mTcbListen field in otTcpListener is aligned incorrectly");
static_assert(offsetof(Listener, mTcbListen) == 0, "mTcbListen field in otTcpEndpoint has nonzero offset");
/**
* This class implements TCP header parsing.
*
@@ -661,7 +656,7 @@ private:
kDynamicPortMax = 65535, ///< Service Name and Transport Protocol Port Number Registry
};
void ProcessSignals(Endpoint &aEndpoint, otLinkedBuffer *aPriorHead, struct signals &aSignals);
void ProcessSignals(Endpoint &aEndpoint, otLinkedBuffer *aPriorHead, struct tcplp_signals &aSignals);
static Error BsdErrorToOtError(int aBsdError);
bool CanBind(const SockAddr &aSockName);
-2
View File
@@ -43,8 +43,6 @@
#include <stdint.h>
#include <stdio.h>
#define __func__ "BSD TCP function"
#define KASSERT(COND, MSG) if (!(COND)) tcplp_sys_panic MSG
typedef uint32_t tcp_seq;
+3 -3
View File
@@ -103,7 +103,7 @@ static void tcp_dooptions(struct tcpopt *, uint8_t *, int, int);
static void
tcp_do_segment(struct ip6_hdr* ip6, struct tcphdr *th, otMessage* msg,
struct tcpcb *tp, int drop_hdrlen, int tlen, uint8_t iptos,
struct signals* sig);
struct tcplp_signals* sig);
static void tcp_xmit_timer(struct tcpcb *, int);
void tcp_hc_get(/*struct in_conninfo *inc*/ struct tcpcb* tp, struct hc_metrics_lite *hc_metrics_lite);
static void tcp_newreno_partial_ack(struct tcpcb *, struct tcphdr *);
@@ -431,7 +431,7 @@ tcp_dropwithreset(struct ip6_hdr* ip6, struct tcphdr *th, struct tcpcb *tp, otIn
/* NOTE: tcp_fields_to_host(th) must be called before this function is called. */
int
tcp_input(struct ip6_hdr* ip6, struct tcphdr* th, otMessage* msg, struct tcpcb* tp, struct tcpcb_listen* tpl,
struct signals* sig)
struct tcplp_signals* sig)
{
/*
* samkumar: I significantly modified this function, compared to the
@@ -948,7 +948,7 @@ drop:
static void
tcp_do_segment(struct ip6_hdr* ip6, struct tcphdr *th, otMessage* msg,
struct tcpcb *tp, int drop_hdrlen, int tlen, uint8_t iptos,
struct signals* sig)
struct tcplp_signals* sig)
{
/*
* samkumar: All code pertaining to locks, stats, and debug has been
+1 -1
View File
@@ -51,7 +51,7 @@
* not need to update it if only part of the segment is trimmed off.
*/
int
tcp_reass(struct tcpcb* tp, struct tcphdr* th, int* tlenp, otMessage* data, off_t data_offset, struct signals* sig)
tcp_reass(struct tcpcb* tp, struct tcphdr* th, int* tlenp, otMessage* data, off_t data_offset, struct tcplp_signals* sig)
{
size_t mergeable, written;
size_t offset;
+3 -3
View File
@@ -161,7 +161,7 @@ struct tcpcb_listen {
#define SACKHOLE_POOL_SIZE MAX_SACKHOLES
#define SACKHOLE_BMP_SIZE BITS_TO_BYTES(SACKHOLE_POOL_SIZE)
struct signals;
struct tcplp_signals;
/*
* Tcp control block, one per tcp; fields:
@@ -577,14 +577,14 @@ int tcp_twcheck(struct tcpcb*, struct tcphdr *, int);
void tcp_dropwithreset(struct ip6_hdr* ip6, struct tcphdr *th, struct tcpcb *tp, otInstance* instance,
int tlen, int rstreason);
int tcp_input(struct ip6_hdr* ip6, struct tcphdr* th, otMessage* msg, struct tcpcb* tp, struct tcpcb_listen* tpl,
struct signals* sig);
struct tcplp_signals* sig);
int tcp_output(struct tcpcb *);
void tcpip_maketemplate(struct tcpcb *, struct tcptemp*);
void tcpip_fillheaders(struct tcpcb *, otMessageInfo *, void *);
uint64_t tcp_maxmtu6(struct tcpcb*, struct tcp_ifcap *);
int tcp_addoptions(struct tcpopt *, uint8_t *);
int tcp_mssopt(struct tcpcb*);
int tcp_reass(struct tcpcb *, struct tcphdr *, int *, otMessage *, off_t, struct signals*);
int tcp_reass(struct tcpcb *, struct tcphdr *, int *, otMessage *, off_t, struct tcplp_signals*);
void tcp_sack_init(struct tcpcb *); // Sam: new function that I added
void tcp_sack_doack(struct tcpcb *, struct tcpopt *, tcp_seq);
void tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
#define RELOOKUP_REQUIRED -1
#define CONN_LOST_NORMAL 0
struct signals {
struct tcplp_signals {
int links_popped;
bool conn_established;
bool recvbuf_notempty;