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