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