10 typedef struct sTCPHeader tTCPHeader;
11 typedef struct sTCPListener tTCPListener;
12 typedef struct sTCPStoredPacket tTCPStoredPacket;
13 typedef struct sTCPConnection tTCPConnection;
19 Uint32 SequenceNumber;
20 Uint32 AcknowlegementNumber;
22 struct { // Lowest to highest
24 unsigned DataOffset: 4; // Size of the header in 32-bit words
25 } __attribute__ ((packed));
30 struct { // Lowest to Highest
31 unsigned FIN: 1; // Last packet
32 unsigned SYN: 1; // Synchronise Sequence Numbers
33 unsigned RST: 1; // Reset Connection
34 unsigned PSH: 1; // Push Function
35 unsigned ACK: 1; // Acknowlegement field is significant
36 unsigned URG: 1; // Urgent pointer is significant
37 unsigned ECE: 1; // ECN-Echo
38 unsigned CWR: 1; // Congestion Window Reduced
39 } __attribute__ ((packed)) Flags;
49 } __attribute__ ((packed));
65 struct sTCPListener *Next; //!< Next server in the list
66 Uint16 Port; //!< Listening port (0 disables the server)
67 tInterface *Interface; //!< Listening Interface
68 tVFS_Node Node; //!< Server Directory node
69 int NextID; //!< Name of the next connection
70 tShortSpinlock lConnections; //!< Spinlock for connections
71 tTCPConnection *Connections; //!< Connections (linked list)
72 tTCPConnection *volatile NewConnections;
73 tTCPConnection *ConnectionsTail;
76 struct sTCPStoredPacket
78 struct sTCPStoredPacket *Next;
84 enum eTCPConnectionState
86 TCP_ST_CLOSED, // 0 - Connection invalid
88 TCP_ST_SYN_SENT, // 1 - SYN sent by local, waiting for SYN-ACK
89 TCP_ST_SYN_RCVD, // 2 - SYN recieved, SYN-ACK sent
91 TCP_ST_OPEN, // 3 - Connection open
94 TCP_ST_FIN_WAIT1, // 4 - FIN sent, waiting for reply (ACK or FIN)
95 TCP_ST_FIN_WAIT2, // 5 - sent FIN acked, waiting for FIN from peer
96 TCP_ST_CLOSING, // 6 - Waiting for ACK of FIN (FIN sent and recieved)
97 TCP_ST_TIME_WAIT, // 7 - Waiting for timeout after local close
99 TCP_ST_CLOSE_WAIT, // 8 - FIN recieved, waiting for user to close (error set, wait for node close)
100 TCP_ST_LAST_ACK, // 9 - FIN sent and recieved, waiting for ACK
101 TCP_ST_FINISHED // 10 - Essentially closed, all packets are invalid
104 struct sTCPConnection
106 struct sTCPConnection *Next;
107 enum eTCPConnectionState State; //!< Connection state (see ::eTCPConnectionState)
108 Uint16 LocalPort; //!< Local port
109 Uint16 RemotePort; //!< Remote port
110 tInterface *Interface; //!< Listening Interface
111 tVFS_Node Node; //!< Node
113 Uint32 NextSequenceSend; //!< Next sequence value for outbound packets
114 Uint32 NextSequenceRcv; //!< Next expected sequence value for inbound
118 * \brief Non-ACKed packets
122 tMutex lNonACKedPackets;
123 tTCPStoredPacket *SentPackets; //!< Non-acknowleged packets
130 * \brief Unread Packets
134 tMutex lRecievedPackets;
135 tRingBuffer *RecievedBuffer;
141 * \brief Out of sequence packets
142 * \note Sorted list to improve times
143 * \todo Convert this to a ring buffer and a bitmap of valid bytes
146 #if CACHE_FUTURE_PACKETS_OR_BYTES == bytes
147 Uint32 HighestSequenceRcvd; //!< Highest sequence number (within window) recieved
148 Uint8 *FuturePacketData; //!< Future packet data (indexed by sequence number)
149 Uint8 *FuturePacketValidBytes; //!< Valid byte bitmap (WINDOW_SIZE/8 bytes)
151 tShortSpinlock lFuturePackets; //!< Future packets spinlock
152 tTCPStoredPacket *FuturePackets; //!< Out of sequence packets
161 } RemoteIP; //!< Remote IP Address
162 // Type is determined by LocalInterface->Type