9 #include <adt.h> // tRingBuffer
10 #include <timers.h> // tTimer
11 #include <semaphore.h> // tSemaphore
13 typedef struct sTCPHeader tTCPHeader;
14 typedef struct sTCPListener tTCPListener;
15 typedef struct sTCPStoredPacket tTCPStoredPacket;
16 typedef struct sTCPConnection tTCPConnection;
22 Uint32 SequenceNumber;
23 Uint32 AcknowlegementNumber;
25 struct { // Lowest to highest
27 unsigned DataOffset: 4; // Size of the header in 32-bit words
28 } __attribute__ ((packed));
33 struct { // Lowest to Highest
34 unsigned FIN: 1; // Last packet
35 unsigned SYN: 1; // Synchronise Sequence Numbers
36 unsigned RST: 1; // Reset Connection
37 unsigned PSH: 1; // Push Function
38 unsigned ACK: 1; // Acknowlegement field is significant
39 unsigned URG: 1; // Urgent pointer is significant
40 unsigned ECE: 1; // ECN-Echo
41 unsigned CWR: 1; // Congestion Window Reduced
42 } __attribute__ ((packed)) Flags;
52 } __attribute__ ((packed));
68 struct sTCPListener *Next; //!< Next server in the list
69 Uint16 Port; //!< Listening port (0 disables the server)
70 tInterface *Interface; //!< Listening Interface
71 tVFS_Node Node; //!< Server Directory node
72 int NextID; //!< Name of the next connection
73 tSemaphore WaitingConnections;
74 tShortSpinlock lConnections; //!< Spinlock for connections
75 tTCPConnection *Connections; //!< Connections (linked list)
76 tTCPConnection *volatile NewConnections;
77 tTCPConnection *ConnectionsTail;
80 struct sTCPStoredPacket
82 struct sTCPStoredPacket *Next;
88 enum eTCPConnectionState
90 TCP_ST_CLOSED, // 0 - Connection invalid
92 TCP_ST_SYN_SENT, // 1 - SYN sent by local, waiting for SYN-ACK
93 TCP_ST_SYN_RCVD, // 2 - SYN recieved, SYN-ACK sent
95 TCP_ST_OPEN, // 3 - Connection open
98 TCP_ST_FIN_WAIT1, // 4 - FIN sent, waiting for reply (ACK or FIN)
99 TCP_ST_FIN_WAIT2, // 5 - sent FIN acked, waiting for FIN from peer
100 TCP_ST_CLOSING, // 6 - Waiting for ACK of FIN (FIN sent and recieved)
101 TCP_ST_TIME_WAIT, // 7 - Waiting for timeout after local close
103 TCP_ST_CLOSE_WAIT, // 8 - FIN recieved, waiting for user to close (error set, wait for node close)
104 TCP_ST_LAST_ACK, // 9 - FIN sent and recieved, waiting for ACK
105 TCP_ST_FINISHED // 10 - Essentially closed, all packets are invalid
108 struct sTCPConnection
110 struct sTCPConnection *Next;
111 enum eTCPConnectionState State; //!< Connection state (see ::eTCPConnectionState)
112 Uint16 LocalPort; //!< Local port
113 Uint16 RemotePort; //!< Remote port
114 tInterface *Interface; //!< Listening Interface
115 tVFS_Node Node; //!< Node
117 Uint32 NextSequenceSend; //!< Next sequence value for outbound packets
118 Uint32 NextSequenceRcv; //!< Next expected sequence value for inbound
120 // Deferred ACK handling
121 Uint32 LastACKSequence;
122 tTimer *DeferredACKTimer;
126 * \brief Non-ACKed packets
130 tMutex lNonACKedPackets;
131 tTCPStoredPacket *SentPackets; //!< Non-acknowleged packets
138 * \brief Unread Packets
142 tMutex lRecievedPackets;
143 tRingBuffer *RecievedBuffer;
149 * \brief Out of sequence packets
150 * \note Sorted list to improve times
151 * \todo Convert this to a ring buffer and a bitmap of valid bytes
154 #if CACHE_FUTURE_PACKETS_OR_BYTES == bytes
155 Uint32 HighestSequenceRcvd; //!< Highest sequence number (within window) recieved
156 Uint8 *FuturePacketData; //!< Future packet data (indexed by sequence number)
157 Uint8 *FuturePacketValidBytes; //!< Valid byte bitmap (WINDOW_SIZE/8 bytes)
159 tShortSpinlock lFuturePackets; //!< Future packets spinlock
160 tTCPStoredPacket *FuturePackets; //!< Out of sequence packets
169 } RemoteIP; //!< Remote IP Address
170 // Type is determined by LocalInterface->Type