TianoCore EDK2 master
Loading...
Searching...
No Matches
TcpProto.h
Go to the documentation of this file.
1
10#ifndef _TCP_PROTO_H_
11#define _TCP_PROTO_H_
12
17#define TCP_CLOSED 0
18#define TCP_LISTEN 1
19#define TCP_SYN_SENT 2
20#define TCP_SYN_RCVD 3
21#define TCP_ESTABLISHED 4
22#define TCP_FIN_WAIT_1 5
23#define TCP_FIN_WAIT_2 6
24#define TCP_CLOSING 7
25#define TCP_TIME_WAIT 8
26#define TCP_CLOSE_WAIT 9
27#define TCP_LAST_ACK 10
28
32#define TCP_FLG_FIN 0x01
33#define TCP_FLG_SYN 0x02
34#define TCP_FLG_RST 0x04
35#define TCP_FLG_PSH 0x08
36#define TCP_FLG_ACK 0x10
37#define TCP_FLG_URG 0x20
38
39//
40// mask for all the flags
41//
42#define TCP_FLG_FLAG 0x3F
43
44#define TCP_CONNECT_REFUSED (-1)
45#define TCP_CONNECT_RESET (-2)
46#define TCP_CONNECT_CLOSED (-3)
47
48//
49// Current congestion status as suggested by RFC3782.
50//
51#define TCP_CONGEST_RECOVER 1
52#define TCP_CONGEST_LOSS 2
53#define TCP_CONGEST_OPEN 3
54
55//
56// TCP control flags
57//
58#define TCP_CTRL_NO_NAGLE 0x0001
59#define TCP_CTRL_NO_KEEPALIVE 0x0002
60#define TCP_CTRL_NO_WS 0x0004
61#define TCP_CTRL_RCVD_WS 0x0008
62#define TCP_CTRL_NO_TS 0x0010
63#define TCP_CTRL_RCVD_TS 0x0020
64#define TCP_CTRL_SND_TS 0x0040
65#define TCP_CTRL_SND_URG 0x0080
66#define TCP_CTRL_RCVD_URG 0x0100
67#define TCP_CTRL_SND_PSH 0x0200
68#define TCP_CTRL_FIN_SENT 0x0400
69#define TCP_CTRL_FIN_ACKED 0x0800
70#define TCP_CTRL_TIMER_ON 0x1000
71#define TCP_CTRL_RTT_ON 0x2000
72#define TCP_CTRL_ACK_NOW 0x4000
73
74//
75// Timer related values
76//
77#define TCP_TIMER_CONNECT 0
78#define TCP_TIMER_REXMIT 1
79#define TCP_TIMER_PROBE 2
80#define TCP_TIMER_KEEPALIVE 3
81#define TCP_TIMER_FINWAIT2 4
82#define TCP_TIMER_2MSL 5
83#define TCP_TIMER_NUMBER 6
84#define TCP_TICK 200
85#define TCP_TICK_HZ 5
86#define TCP_RTT_SHIFT 3
87#define TCP_RTO_MIN TCP_TICK_HZ
88#define TCP_RTO_MAX (TCP_TICK_HZ * 60)
89#define TCP_FOLD_RTT 4
90
91//
92// Default values for some timers
93//
94#define TCP_MAX_LOSS 12
95#define TCP_KEEPALIVE_IDLE_MIN (TCP_TICK_HZ * 60 * 60 * 2)
96#define TCP_KEEPALIVE_PERIOD (TCP_TICK_HZ * 60)
97#define TCP_MAX_KEEPALIVE 8
98#define TCP_FIN_WAIT2_TIME (2 * TCP_TICK_HZ)
99#define TCP_TIME_WAIT_TIME (2 * TCP_TICK_HZ)
100#define TCP_PAWS_24DAY (24 * 24 * 60 * 60 * TCP_TICK_HZ)
101#define TCP_CONNECT_TIME (75 * TCP_TICK_HZ)
102
103//
104// The header space to be reserved before TCP data to accommodate:
105// 60byte IP head + 60byte TCP head + link layer head
106//
107#define TCP_MAX_HEAD 192
108
109//
110// Value ranges for some control option
111//
112#define TCP_RCV_BUF_SIZE (2 * 1024 * 1024)
113#define TCP_RCV_BUF_SIZE_MIN (8 * 1024)
114#define TCP_SND_BUF_SIZE (2 * 1024 * 1024)
115#define TCP_SND_BUF_SIZE_MIN (8 * 1024)
116#define TCP_BACKLOG 10
117#define TCP_BACKLOG_MIN 5
118#define TCP_MAX_LOSS_MIN 6
119#define TCP_CONNECT_TIME_MIN (60 * TCP_TICK_HZ)
120#define TCP_MAX_KEEPALIVE_MIN 4
121#define TCP_KEEPALIVE_IDLE_MAX (TCP_TICK_HZ * 60 * 60 * 4)
122#define TCP_KEEPALIVE_PERIOD_MIN (TCP_TICK_HZ * 30)
123#define TCP_FIN_WAIT2_TIME_MAX (4 * TCP_TICK_HZ)
124#define TCP_TIME_WAIT_TIME_MAX (60 * TCP_TICK_HZ)
125
129#define TCP_CONNECTED(state) ((state) > TCP_SYN_RCVD)
130
131#define TCP_FIN_RCVD(State) \
132 ( \
133 ((State) == TCP_CLOSE_WAIT) || \
134 ((State) == TCP_LAST_ACK) || \
135 ((State) == TCP_CLOSING) || \
136 ((State) == TCP_TIME_WAIT) \
137 )
138
139#define TCP_LOCAL_CLOSED(State) \
140 ( \
141 ((State) == TCP_FIN_WAIT_1) || \
142 ((State) == TCP_FIN_WAIT_2) || \
143 ((State) == TCP_CLOSING) || \
144 ((State) == TCP_TIME_WAIT) || \
145 ((State) == TCP_LAST_ACK) \
146 )
147
148//
149// Get the TCP_SEG point from a net buffer's ProtoData.
150//
151#define TCPSEG_NETBUF(NBuf) ((TCP_SEG *) ((NBuf)->ProtoData))
152
153//
154// Macros to compare sequence no
155//
156#define TCP_SEQ_LT(SeqA, SeqB) ((INT32) ((SeqA) - (SeqB)) < 0)
157#define TCP_SEQ_LEQ(SeqA, SeqB) ((INT32) ((SeqA) - (SeqB)) <= 0)
158#define TCP_SEQ_GT(SeqA, SeqB) ((INT32) ((SeqB) - (SeqA)) < 0)
159#define TCP_SEQ_GEQ(SeqA, SeqB) ((INT32) ((SeqB) - (SeqA)) <= 0)
160
161//
162// TCP_SEQ_BETWEEN return whether b <= m <= e
163//
164#define TCP_SEQ_BETWEEN(b, m, e) ((e) - (b) >= (m) - (b))
165
166//
167// TCP_SUB_SEQ returns Seq1 - Seq2. Make sure Seq1 >= Seq2
168//
169#define TCP_SUB_SEQ(Seq1, Seq2) ((UINT32) ((Seq1) - (Seq2)))
170
171//
172// Check whether Flag is on
173//
174#define TCP_FLG_ON(Value, Flag) ((BOOLEAN) (((Value) & (Flag)) != 0))
175//
176// Set and Clear operation on a Flag
177//
178#define TCP_SET_FLG(Value, Flag) ((Value) |= (Flag))
179#define TCP_CLEAR_FLG(Value, Flag) ((Value) &= ~(Flag))
180
181//
182// Test whether two peers are equal
183//
184#define TCP_PEER_EQUAL(Pa, Pb, Ver) \
185 (((Pa)->Port == (Pb)->Port) && TcpIsIpEqual(&((Pa)->Ip), &((Pb)->Ip), Ver))
186
187//
188// Test whether Pa matches Pb, or Pa is more specific
189// than pb. Zero means wildcard.
190//
191#define TCP_PEER_MATCH(Pa, Pb, Ver) \
192 ( \
193 (((Pb)->Port == 0) || ((Pb)->Port == (Pa)->Port)) && \
194 (TcpIsIpZero (&((Pb)->Ip), Ver) || TcpIsIpEqual (&((Pb)->Ip), &((Pa)->Ip), Ver)) \
195 )
196
197#define TCP_TIMER_ON(Flag, Timer) ((Flag) & (1 << (Timer)))
198#define TCP_SET_TIMER(Flag, Timer) ((Flag) = (UINT16) ((Flag) | (1 << (Timer))))
199#define TCP_CLEAR_TIMER(Flag, Timer) ((Flag) = (UINT16) ((Flag) & (~(1 << (Timer)))))
200
201#define TCP_TIME_LT(Ta, Tb) ((INT32) ((Ta) - (Tb)) < 0)
202#define TCP_TIME_LEQ(Ta, Tb) ((INT32) ((Ta) - (Tb)) <= 0)
203#define TCP_SUB_TIME(Ta, Tb) ((UINT32) ((Ta) - (Tb)))
204
205#define TCP_MAX_WIN 0xFFFFU
206
210typedef struct _TCP_SEG {
211 TCP_SEQNO Seq;
212 TCP_SEQNO End;
213 TCP_SEQNO Ack;
214 UINT8 Flag;
215 UINT16 Urg;
216 UINT32 Wnd;
218
222typedef struct _TCP_PEER {
224 TCP_PORTNO Port;
226
227typedef struct _TCP_CONTROL_BLOCK TCP_CB;
228
235
239
242 UINT32 CtrlFlag;
243 INT32 Error;
244
245 //
246 // RFC793 and RFC1122 defined variables
247 //
248 UINT8 State;
250 UINT16 HeadSum;
253
254 TCP_SEQNO Iss;
255 TCP_SEQNO SndUna;
256 TCP_SEQNO SndNxt;
257 TCP_SEQNO SndPsh;
258 TCP_SEQNO SndUp;
259 UINT32 SndWnd;
260 UINT32 SndWndMax;
261 TCP_SEQNO SndWl1;
262 TCP_SEQNO SndWl2;
263 UINT16 SndMss;
264 TCP_SEQNO RcvNxt;
265 UINT32 RcvWnd;
266 TCP_SEQNO RcvWl2;
268
269 TCP_SEQNO RcvUp;
270 TCP_SEQNO Irs;
271 UINT16 RcvMss;
275 UINT32 Idle;
276 UINT32 ProbeTime;
277 BOOLEAN ProbeTimerOn;
278
279 //
280 // RFC7323 defined variables, about window scale,
281 // timestamp and PAWS
282 //
285 UINT32 TsRecent;
286 UINT32 TsRecentAge;
287
288 //
289 // RFC2988 defined variables. about RTT measurement
290 //
291 TCP_SEQNO RttSeq;
292 UINT32 RttMeasure;
293 UINT32 SRtt;
294 UINT32 RttVar;
295 UINT32 Rto;
296
297 //
298 // RFC2581, and 3782 variables.
299 // Congestion control + NewReno fast recovery.
300 //
301 UINT32 CWnd;
302 UINT32 Ssthresh;
303 TCP_SEQNO Recover;
304 UINT16 DupAck;
306 UINT8 LossTimes;
307 TCP_SEQNO LossRecover;
308
309 //
310 // RFC7323
311 // Addressing Window Retraction for TCP Window Scale Option.
312 //
313 TCP_SEQNO RetxmitSeqMax;
314
315 //
316 // configuration parameters, for EFI_TCP4_PROTOCOL specification
317 //
322 UINT16 MaxRexmit;
326
327 //
328 // configuration for tcp provided by user
329 //
330 BOOLEAN UseDefaultAddr;
331 UINT8 Tos;
332 UINT8 Ttl;
333 EFI_IPv4_ADDRESS SubnetMask;
334
335 BOOLEAN RemoteIpZero;
337 UINT32 Tick;
338};
339
340#endif
#define TCP_TIMER_NUMBER
The total number of the TCP timer.
Definition: TcpProto.h:83
struct _TCP_SEG TCP_SEG
struct _TCP_PEER TCP_PEER
UINT32 KeepAlivePeriod
Interval for subsequent keep alive probe.
Definition: TcpProto.h:319
UINT8 LossTimes
Number of retxmit timeouts in a row.
Definition: TcpProto.h:306
TCP_SEQNO SndUna
First unacknowledged data.
Definition: TcpProto.h:255
UINT32 Tick
1 tick = 200ms
Definition: TcpProto.h:337
UINT8 SndWndScale
Wndscale received from the peer.
Definition: TcpProto.h:283
TCP_PEER RemoteEnd
Remote endpoint.
Definition: TcpProto.h:238
TCP_SEQNO LossRecover
Recover point for retxmit.
Definition: TcpProto.h:307
UINT16 MaxRexmit
The maximum number of retxmit before abort.
Definition: TcpProto.h:322
UINT8 MaxKeepAlive
Maximum keep alive probe times.
Definition: TcpProto.h:320
INT32 Error
Soft error status, such as TCP_CONNECT_RESET.
Definition: TcpProto.h:243
TCP_SEQNO RcvWl2
Definition: TcpProto.h:266
UINT32 RttMeasure
Currently measured RTT in heartbeats.
Definition: TcpProto.h:292
UINT8 DelayedAck
Number of delayed ACKs.
Definition: TcpProto.h:249
TCP_SEQNO RcvNxt
Next sequence no to receive.
Definition: TcpProto.h:264
UINT32 Ssthresh
Slow start threshold.
Definition: TcpProto.h:302
TCP_CB * Parent
The parent TCP_CB structure.
Definition: TcpProto.h:234
INT32 NextExpire
Countdown offset for the nearest timer.
Definition: TcpProto.h:274
TCP_SEQNO Irs
Initial Receiving Sequence.
Definition: TcpProto.h:270
UINT32 Timer[TCP_TIMER_NUMBER]
When the timer will expire.
Definition: TcpProto.h:273
UINT16 EnabledTimer
Which timer is currently enabled.
Definition: TcpProto.h:272
UINT8 RcvWndScale
Wndscale used to scale local buffer.
Definition: TcpProto.h:284
UINT32 Idle
How long the connection is in idle.
Definition: TcpProto.h:275
TCP_SEQNO SndWl2
Ack no of last window update.
Definition: TcpProto.h:262
UINT32 RcvWnd
Window advertised by the local peer.
Definition: TcpProto.h:265
UINT8 CongestState
The current congestion state(RFC3782).
Definition: TcpProto.h:305
UINT32 TimeWaitTimeout
The TIME_WAIT timeout.
Definition: TcpProto.h:324
TCP_SEQNO SndUp
Send urgent point.
Definition: TcpProto.h:258
BOOLEAN ProbeTimerOn
If TRUE, the probe time is on.
Definition: TcpProto.h:277
UINT32 RttVar
RTT variance, scaled by 8.
Definition: TcpProto.h:294
TCP_SEQNO RttSeq
The seq of measured segment now.
Definition: TcpProto.h:291
UINT16 RcvMss
Max receive segment size.
Definition: TcpProto.h:271
TCP_SEQNO Recover
Recover point for NewReno.
Definition: TcpProto.h:303
UINT32 Rto
Current RTO, not scaled.
Definition: TcpProto.h:295
TCP_SEQNO Iss
Initial Sending Sequence.
Definition: TcpProto.h:254
UINT32 SndWndMax
Max send window advertised by the peer.
Definition: TcpProto.h:260
UINT8 State
TCP state, such as SYN_SENT, LISTEN.
Definition: TcpProto.h:248
TCP_SEQNO SndPsh
Send PUSH point.
Definition: TcpProto.h:257
UINT32 KeepAliveIdle
Idle time before sending first probe.
Definition: TcpProto.h:318
LIST_ENTRY RcvQue
Reassemble queue.
Definition: TcpProto.h:241
UINT16 SndMss
Max send segment size.
Definition: TcpProto.h:263
TCP_SEQNO SndWl1
Seq number used for last window update.
Definition: TcpProto.h:261
UINT8 KeepAliveProbes
The number of keep alive probe.
Definition: TcpProto.h:321
UINT32 FinWait2Timeout
The FIN_WAIT_2 timeout.
Definition: TcpProto.h:323
UINT16 DupAck
Number of duplicate ACKs.
Definition: TcpProto.h:304
UINT32 ConnectTimeout
The connect establishment timeout.
Definition: TcpProto.h:325
UINT32 SRtt
Smoothed RTT, scaled by 8.
Definition: TcpProto.h:293
SOCKET * Sk
The socket it controlled.
Definition: TcpProto.h:236
TCP_PEER LocalEnd
Local endpoint.
Definition: TcpProto.h:237
IP_IO_IP_INFO * IpInfo
Pointer reference to Ip used to send pkt.
Definition: TcpProto.h:336
LIST_ENTRY List
Back and forward link entry.
Definition: TcpProto.h:233
UINT32 ProbeTime
The time out value for current window prober.
Definition: TcpProto.h:276
TCP_SEQNO RcvUp
Urgent point;.
Definition: TcpProto.h:269
UINT32 TsRecentAge
When this TsRecent is updated.
Definition: TcpProto.h:286
BOOLEAN RemoteIpZero
RemoteEnd.Ip is ZERO when configured.
Definition: TcpProto.h:335
TCP_SEQNO RetxmitSeqMax
Max Seq number in previous retransmission.
Definition: TcpProto.h:313
UINT32 CtrlFlag
Control flags, such as NO_NAGLE.
Definition: TcpProto.h:242
TCP_SEQNO SndNxt
Next data sequence to send.
Definition: TcpProto.h:256
UINT32 TsRecent
TsRecent to echo to the remote peer.
Definition: TcpProto.h:285
UINT32 CWnd
Sender's congestion window.
Definition: TcpProto.h:301
LIST_ENTRY SndQue
Retxmission queue.
Definition: TcpProto.h:240
UINT32 SndWnd
Window advertised by the remote peer.
Definition: TcpProto.h:259
EFI_IP_ADDRESS Ip
IP address, in network byte order.
Definition: TcpProto.h:223
TCP_PORTNO Port
Port number, in network byte order.
Definition: TcpProto.h:224
TCP_SEQNO Seq
Starting sequence number.
Definition: TcpProto.h:211
TCP_SEQNO End
The sequence of the last byte + 1, include SYN/FIN. End-Seq = SEG.LEN.
Definition: TcpProto.h:212
UINT8 Flag
TCP header flags.
Definition: TcpProto.h:214
UINT16 Urg
Valid if URG flag is set.
Definition: TcpProto.h:215
TCP_SEQNO Ack
ACK field in the segment.
Definition: TcpProto.h:213
UINT32 Wnd
TCP window size field.
Definition: TcpProto.h:216