1 #ifndef __TCP_INTERNAL_H 2 #define __TCP_INTERNAL_H 10 #include <netinterface.h> 15 #include <ipv6/ipv6_frames.h> 16 #include <ipv6/ipv6_interface.h> 29 #define NEED_TOACK (1) 30 #define TCP_WANTS_TO_CLOSE (2) 31 #define TCP_FIN_SENT (4) 32 #define TCP_ZERO_PROBING (8) 33 #define TCP_USER_CLOSED (16) 34 #define TCP_INLISTENLIST (32) 35 #define TCP_INLISTENCNT (64) 36 #define TCP_SAW_SACK (128) 38 #define DEFAULT_MAX_OUTSTANDING_ACK_BUFFERS (10) 42 typedef socket_struct SOCKET;
43 typedef SOCKET *PSOCKET;
44 extern socket_struct sockets[TCP_SOCKET_STRUCTS];
46 class TcpCarrierPacket;
49 void DumpTcpPacket(TcpCarrierPacket &ptpkt, uint16_t len);
52 #define MAXTICKS (0xFFFFFFFF) 53 #define TCPTOTAL_HEADER_SIZE (20 + 20) 55 #define TCPTOTAL_V6_HEADER_SIZE (sizeof(IP6FRAME) + sizeof(TCPPKT)) 58 #define DT_STATE_CHANGE 1 63 #define DT_MAXRETRY_CLOSE 6 64 #define DT_RETRANSMIT 7 65 #define DT_EXTDOCLOSE 8 67 #define DT_SAVEDATA 10 68 #define DT_ReadCall 11 69 #define DT_ReadFail1 12 70 #define DT_ReadFail2 13 71 #define DT_ReadError 14 72 #define DT_ReadFail4 15 73 #define DT_SAVEZERO 16 74 #define DT_ERRORTIMO 17 78 int GetProperInterfaceForDestination(
const IPADDR &dst);
79 BOOL IsLocal(
const IPADDR &ip,
int ifc);
80 void RemoveFromUserCloseList(PSOCKET ps);
89 static uint16_t dbFlag __attribute__((unused));
90 void DebugTraceFunc(socket_struct *ss, TcpCarrierPacket *ptpkt, uint16_t why,
int line);
91 void RawDumpTcpDebug(PSOCKET psfilter);
93 #define DebugTrace(ss, t, why) \ 94 if (dbFlag) DebugTraceFunc(ss, t, why, __LINE__); 97 #define DebugTrace(w, x, y) ((void)0) 107 class TcpCarrierPacket
125 TcpCarrierPacket(
bool bIsV6 =
false);
126 TcpCarrierPacket(IPv6FrameProcessingStruct &p6proc);
127 void InitIPv6Carrier(IPv6FrameProcessingStruct &p6proc);
128 void InitBlank(PoolPtr pp,
bool bIsV6 =
false);
131 void InitBlank(PoolPtr pp);
133 TcpCarrierPacket(PoolPtr pp);
139 if (pp) FreeBuffer(pp);
142 inline PoolPtr Detach()
152 inline uint8_t Get_pp_flag()
154 if (pp)
return pp->bBufferFlag;
157 inline uint8_t GetInterface()
159 if (pp)
return pp->bInterfaceNumber;
162 inline MACADR GetMacSource() {
return GetEframe(pp)->src_addr; };
165 inline uint8_t GetFlags() {
return pTcp->flags; };
166 inline uint16_t GetDestPort()
168 if (pTcp)
return pTcp->dstPort;
171 inline uint16_t GetSourcePort()
173 if (pTcp)
return pTcp->srcPort;
176 inline uint16_t GetWindow()
178 if (pTcp)
return pTcp->window;
181 inline uint32_t GetSeq()
183 if (pTcp)
return pTcp->SeqNumber;
186 inline uint32_t GetAck()
188 if (pTcp)
return pTcp->AckNumber;
191 inline uint8_t GetHeaderLen()
193 if (pTcp)
return pTcp->header_len;
197 inline PTCPPKT GetpTcp() {
return pTcp; };
198 inline PoolPtr GetPP() {
return pp; };
200 uint16_t GetTcpDataLen() {
return nDataLen; };
201 puint8_t GetTcpData() {
return pData; };
202 void SetDataLen(uint16_t len) { nDataLen = len; };
204 void SetOutBoundSize(uint16_t data_len);
206 bool IsSourceIP(
const IPADDR &ip);
207 uint32_t GetSourceIpHash();
208 uint32_t GetDestinationIpHash();
209 IPADDR GetDestinationIP();
212 uint16_t GetDefMss(
const IPADDR &ip);
215 bool SourceShouldLoopBack();
217 inline bool IsV6() {
return bIsV6; };
218 friend void TcpSendwSum6(PSOCKET ps,
const IPADDR &IPto, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
219 friend void TcpSendwSumFrom6(
const IPADDR &IPto,
const IPADDR &IPfrom, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
220 friend void SumTCPV6(IPv6FrameProcessingStruct &p6proc, TcpCarrierPacket &pkt, uint32_t data_csum);
222 inline bool IsV6() {
return false; };
224 bool Valid() {
return (pTcp != 0); };
226 friend void TcpSendwSum4(PSOCKET ps, IPADDR4 to, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
229 struct socket_struct :
public TimeOutElement
231 PSOCKET m_pNextActive;
232 PSOCKET m_pPrevActive;
233 PSOCKET m_pListening;
235 volatile uint32_t next_retransmit;
242 uint32_t sent_and_acked;
243 uint32_t send_not_acked;
245 uint32_t my_last_window;
246 uint32_t last_seq_I_rxed;
255 fifo_buffer_storage TxBuffer;
256 fifo_buffer_storage RxBuffer;
258 PoolPtr buffers_tobe_acked_head;
259 PoolPtr buffers_tobe_acked_tail;
261 volatile PoolPtr buffers_out_of_order;
276 uint16_t largest_window_iveseen;
278 uint16_t TimeBackPointer;
279 volatile uint8_t state;
280 volatile uint8_t gpflags;
283 uint8_t nPendingCalls;
284 uint8_t max_listining_sockets;
285 uint8_t outstanding_acks;
286 uint8_t max_buffers_out_of_order;
287 volatile uint8_t cur_buffers_out_of_order;
292 bool checksumOffload;
294 IPv6Interface *m_Ip6IfShortCut;
297 uint8_t MAX_OUTSTANDING_ACK_BUFFERS;
298 tcp_notify_handler *pReadNotify;
299 tcp_notify_handler *pWriteNotify;
303 void process(TcpCarrierPacket &tpkt);
306 void processoptions(TcpCarrierPacket &tpkt);
309 void ProcessDataSegment(TcpCarrierPacket &tpkt, uint16_t data_len, puint8_t data);
311 void TestOutofOrder();
314 void SendState(uint16_t flags, PoolPtr pp =
NULL);
315 void SendState(uint16_t flags, TcpCarrierPacket &tpkt);
318 void SaveData(puint8_t data, uint16_t len, BOOL push);
322 void SetTimer(uint32_t timeout);
328 virtual void TimeElementEvent();
334 void ProcessAck(TcpCarrierPacket &ptpkt);
337 void CalcRTO(uint32_t txtime);
340 void DoRetransmit(BOOL count);
343 void SetUpNextRetransmit();
346 int DoClose(
int why);
349 void ProcessRST(
void);
352 void ProcessFIN(TcpCarrierPacket &ptpkt, uint16_t data_len);
355 void DoCleanup(
void);
357 void CleanUpDeletedListener();
359 void SetState(
int news);
361 void ClearPending(
int why);
364 uint16_t MyAdvertisedWindow(
void);
366 void OpenWindow(
void);
368 void CreateInitOutBoundPacket(TcpCarrierPacket &ptpkt, uint16_t flags, PoolPtr pp);
370 inline int GetMyFd() {
return ((
this - sockets) + TCP_SOCKET_OFFSET); };
374 uint8_t *GetTCPPayload(PoolPtr pp);
378 int SockSubmitTcpBuffer4Tx(uint32_t csum32bit, uint16_t length, puint8_t pBuffer);
380 tcp_data_handler *pDataHandle;
383 void init(uint16_t pos)
386 m_pNextActive =
NULL;
387 m_pPrevActive =
NULL;
390 TimeBackPointer = pos + 1;
394 TxBuffer.Init(TCP_BUFFER_SEGMENTS, 0);
395 RxBuffer.Init(TCP_BUFFER_SEGMENTS, 0);
396 buffers_tobe_acked_head =
NULL;
397 buffers_tobe_acked_tail =
NULL;
398 outstanding_acks = 0;
399 mac_shortcut = ENET_ZERO;
401 MAX_OUTSTANDING_ACK_BUFFERS = DEFAULT_MAX_OUTSTANDING_ACK_BUFFERS;
408 uint32_t GetFirstSeq();
409 bool PacketMatchesSocket(TcpCarrierPacket &tpkt);
411 int CoreConnect(
IPADDR addr, uint16_t localport, uint16_t remoteport,
IPADDR ipa);
413 void ShowSocketInfo();
414 static void ShowSocketsInfo(
bool includeClosed);
415 } __attribute__((packed));
417 PSOCKET GetTcpSocket(TcpCarrierPacket &pkt);
423 void Init(
void)
const;
424 PSOCKET findsocket(TcpCarrierPacket &pkt)
const;
425 void AddSocket(PSOCKET ps)
const;
426 void RemoveSocket(PSOCKET ps)
const;
434 #define SocketHashSize 37 437 class ShortSocketList
439 uint16_t m_slist[SocketHashSize];
440 ShortSocket *findsocket(TcpCarrierPacket &pkt)
const;
441 ShortSocket *GetFreeShort();
442 void FreeShort(ShortSocket *pShort)
const;
447 void AddSocket(PSOCKET ps);
448 int process(TcpCarrierPacket &pkt)
const;
449 void processTimeEvent();
452 extern OS_CRIT TCP_critical_section FAST_TCP_VAR;
453 extern OS_SEM TCP_TimerSemaphore FAST_TCP_VAR;
455 extern PSOCKET free_list_head;
456 extern PSOCKET user_closed_list_head;
457 extern PSOCKET listen_list_head;
459 extern HashSocketList active_list;
460 extern ShortSocketList semiactive_list;
462 int GetInterfaceNumberFromMyAddr(
IPADDR ip);
465 struct IPv6FrameProcessingStruct;
466 bool process_tcp6(IPv6FrameProcessingStruct &p6proc);
467 void TcpSendwSum6(PSOCKET ps,
const IPADDR &IPto, TcpCarrierPacket &pkt, BOOL keep, uint32_t data_sum);
468 void RetransmitV6Packet(PoolPtr pp, PSOCKET ps);
471 #endif // __TCP_INTERNAL_H void init()
System initialization. Normally called at the beginning of all applications.
Definition: init.cpp:22
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition: ipv6_addr.h:28
Semaphores are used to control access to shared resource critical section, or to communicate between ...
Definition: nbrtos.h:318
#define TCP_STATE_CLOSED
Socket Closed.
Definition: tcp.h:25
NetBurner File Descriptor Library API.
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition: nbrtos.h:893
#define NULL
Definition: nm_bsp.h:76