]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Output.c
2 TCP output process routines.
4 Copyright (c) 2005 - 2009, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php<BR>
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 UINT8 mTcpOutFlag
[] = {
20 TCP_FLG_SYN
, // TCP_SYN_SENT
21 TCP_FLG_SYN
| TCP_FLG_ACK
, // TCP_SYN_RCVD
22 TCP_FLG_ACK
, // TCP_ESTABLISHED
23 TCP_FLG_FIN
| TCP_FLG_ACK
, // TCP_FIN_WAIT_1
24 TCP_FLG_ACK
, // TCP_FIN_WAIT_2
25 TCP_FLG_ACK
| TCP_FLG_FIN
, // TCP_CLOSING
26 TCP_FLG_ACK
, // TCP_TIME_WAIT
27 TCP_FLG_ACK
, // TCP_CLOSE_WAIT
28 TCP_FLG_FIN
| TCP_FLG_ACK
// TCP_LAST_ACK
33 Compute the sequence space left in the old receive window.
35 @param Tcb Pointer to the TCP_CB of this TCP instance.
37 @return The sequence space left in the old receive window.
49 if (TCP_SEQ_GT (Tcb
->RcvWl2
+ Tcb
->RcvWnd
, Tcb
->RcvNxt
)) {
51 OldWin
= TCP_SUB_SEQ (
52 Tcb
->RcvWl2
+ Tcb
->RcvWnd
,
62 Compute the current receive window.
64 @param Tcb Pointer to the TCP_CB of this TCP instance.
66 @return The size of the current receive window, in bytes.
82 OldWin
= TcpRcvWinOld (Tcb
);
84 Win
= SockGetFreeSpace (Sk
, SOCK_RCV_BUF
);
88 Increase
= Win
- OldWin
;
92 // Receiver's SWS: don't advertise a bigger window
93 // unless it can be increased by at least one Mss or
94 // half of the receive buffer.
96 if ((Increase
> Tcb
->SndMss
) ||
97 (2 * Increase
>= GET_RCV_BUFFSIZE (Sk
))) {
107 Compute the value to fill in the window size field of the outgoing segment.
109 @param Tcb Pointer to the TCP_CB of this TCP instance.
110 @param Syn The flag to indicate whether the outgoing segment is a SYN
113 @return The value of the local receive window size used to fill the outing segment.
125 // RFC requires that initial window not be scaled
129 Wnd
= GET_RCV_BUFFSIZE (Tcb
->Sk
);
132 Wnd
= TcpRcvWinNow (Tcb
);
137 Wnd
= MIN (Wnd
>> Tcb
->RcvWndScale
, 0xffff);
138 return NTOHS ((UINT16
) Wnd
);
143 Get the maximum SndNxt.
145 @param Tcb Pointer to the TCP_CB of this TCP instance.
147 @return The sequence number of the maximum SndNxt.
158 if (IsListEmpty (&Tcb
->SndQue
)) {
162 Entry
= Tcb
->SndQue
.BackLink
;
163 Nbuf
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
165 ASSERT (TCP_SEQ_GEQ (TCPSEG_NETBUF (Nbuf
)->End
, Tcb
->SndNxt
));
166 return TCPSEG_NETBUF (Nbuf
)->End
;
171 Compute how much data to send.
173 @param Tcb Pointer to the TCP_CB of this TCP instance.
174 @param Force Whether to ignore the sender's SWS avoidance algorithm and send
177 @return The length of the data can be sent, if 0, no data can be sent.
196 // TCP should NOT send data beyond the send window
197 // and congestion window. The right edge of send
198 // window is defined as SND.WL2 + SND.WND. The right
199 // edge of congestion window is defined as SND.UNA +
203 Limit
= Tcb
->SndWl2
+ Tcb
->SndWnd
;
205 if (TCP_SEQ_GT (Limit
, Tcb
->SndUna
+ Tcb
->CWnd
)) {
207 Limit
= Tcb
->SndUna
+ Tcb
->CWnd
;
210 if (TCP_SEQ_GT (Limit
, Tcb
->SndNxt
)) {
211 Win
= TCP_SUB_SEQ (Limit
, Tcb
->SndNxt
);
215 // The data to send contains two parts: the data on the
216 // socket send queue, and the data on the TCB's send
217 // buffer. The later can be non-zero if the peer shrinks
218 // its advertised window.
220 Left
= GET_SND_DATASIZE (Sk
) +
221 TCP_SUB_SEQ (TcpGetMaxSndNxt (Tcb
), Tcb
->SndNxt
);
223 Len
= MIN (Win
, Left
);
225 if (Len
> Tcb
->SndMss
) {
229 if ((Force
!= 0)|| (Len
== 0 && Left
== 0)) {
233 if (Len
== 0 && Left
!= 0) {
234 goto SetPersistTimer
;
238 // Sender's SWS avoidance: Don't send a small segment unless
239 // a)A full-sized segment can be sent,
240 // b)at least one-half of the maximum sized windows that
241 // the other end has ever advertised.
242 // c)It can send everything it has and either it isn't
243 // expecting an ACK or the Nagle algorithm is disabled.
245 if ((Len
== Tcb
->SndMss
) || (2 * Len
>= Tcb
->SndWndMax
)) {
251 ((Tcb
->SndNxt
== Tcb
->SndUna
) ||
252 TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_NO_NAGLE
))) {
258 // RFC1122 suggests to set a timer when SWSA forbids TCP
259 // sending more data, and combine it with probe timer.
262 if (!TCP_TIMER_ON (Tcb
->EnabledTimer
, TCP_TIMER_REXMIT
)) {
266 "TcpDataToSend: enter persistent state for TCB %p\n",
270 TcpSetProbeTimer (Tcb
);
278 Build the TCP header of the TCP segment and transmit the segment by IP.
280 @param Tcb Pointer to the TCP_CB of this TCP instance.
281 @param Nbuf Pointer to the buffer containing the segment to be sent out.
283 @retval 0 The segment is sent out successfully.
284 @retval other Error condition occurred.
299 ASSERT ((Nbuf
!= NULL
) && (Nbuf
->Tcp
== NULL
) && (TcpVerifySegment (Nbuf
) != 0));
301 DataLen
= Nbuf
->TotalSize
;
303 Seg
= TCPSEG_NETBUF (Nbuf
);
304 Syn
= TCP_FLG_ON (Seg
->Flag
, TCP_FLG_SYN
);
308 Len
= TcpSynBuildOption (Tcb
, Nbuf
);
311 Len
= TcpBuildOption (Tcb
, Nbuf
);
314 ASSERT ((Len
% 4 == 0) && (Len
<= 40));
316 Len
+= sizeof (TCP_HEAD
);
318 Head
= (TCP_HEAD
*) NetbufAllocSpace (
324 ASSERT (Head
!= NULL
);
328 Head
->SrcPort
= Tcb
->LocalEnd
.Port
;
329 Head
->DstPort
= Tcb
->RemoteEnd
.Port
;
330 Head
->Seq
= NTOHL (Seg
->Seq
);
331 Head
->Ack
= NTOHL (Tcb
->RcvNxt
);
332 Head
->HeadLen
= (UINT8
) (Len
>> 2);
334 Head
->Wnd
= TcpComputeWnd (Tcb
, Syn
);
338 // Check whether to set the PSH flag.
340 TCP_CLEAR_FLG (Seg
->Flag
, TCP_FLG_PSH
);
343 if (TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_SND_PSH
) &&
344 TCP_SEQ_BETWEEN (Seg
->Seq
, Tcb
->SndPsh
, Seg
->End
)) {
346 TCP_SET_FLG (Seg
->Flag
, TCP_FLG_PSH
);
347 TCP_CLEAR_FLG (Tcb
->CtrlFlag
, TCP_CTRL_SND_PSH
);
349 } else if ((Seg
->End
== Tcb
->SndNxt
) &&
350 (GET_SND_DATASIZE (Tcb
->Sk
) == 0)) {
352 TCP_SET_FLG (Seg
->Flag
, TCP_FLG_PSH
);
357 // Check whether to set the URG flag and the urgent pointer.
359 TCP_CLEAR_FLG (Seg
->Flag
, TCP_FLG_URG
);
361 if (TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_SND_URG
) &&
362 TCP_SEQ_LEQ (Seg
->Seq
, Tcb
->SndUp
)) {
364 TCP_SET_FLG (Seg
->Flag
, TCP_FLG_URG
);
366 if (TCP_SEQ_LT (Tcb
->SndUp
, Seg
->End
)) {
368 Seg
->Urg
= (UINT16
) TCP_SUB_SEQ (Tcb
->SndUp
, Seg
->Seq
);
371 Seg
->Urg
= (UINT16
) MIN (
372 TCP_SUB_SEQ (Tcb
->SndUp
,
379 Head
->Flag
= Seg
->Flag
;
380 Head
->Urg
= NTOHS (Seg
->Urg
);
381 Head
->Checksum
= TcpChecksum (Nbuf
, Tcb
->HeadSum
);
384 // update the TCP session's control information
386 Tcb
->RcvWl2
= Tcb
->RcvNxt
;
388 Tcb
->RcvWnd
= NTOHS (Head
->Wnd
);
392 // clear delayedack flag
396 return TcpSendIpPacket (Tcb
, Nbuf
, Tcb
->LocalEnd
.Ip
, Tcb
->RemoteEnd
.Ip
);
401 Get a segment from the Tcb's SndQue.
403 @param Tcb Pointer to the TCP_CB of this TCP instance.
404 @param Seq The sequence number of the segment.
405 @param Len The maximum length of the segment.
407 @return Pointer to the segment, if NULL some error occurred.
411 TcpGetSegmentSndQue (
428 ASSERT ((Tcb
!= NULL
) && TCP_SEQ_LEQ (Seq
, Tcb
->SndNxt
) && (Len
> 0));
431 // Find the segment that contains the Seq.
438 NET_LIST_FOR_EACH (Cur
, Head
) {
439 Node
= NET_LIST_USER_STRUCT (Cur
, NET_BUF
, List
);
440 Seg
= TCPSEG_NETBUF (Node
);
442 if (TCP_SEQ_LT (Seq
, Seg
->End
) && TCP_SEQ_LEQ (Seg
->Seq
, Seq
)) {
448 ASSERT (Cur
!= Head
);
449 ASSERT (Node
!= NULL
);
450 ASSERT (Seg
!= NULL
);
453 // Return the buffer if it can be returned without
456 if ((Seg
->Seq
== Seq
) &&
457 TCP_SEQ_LEQ (Seg
->End
, Seg
->Seq
+ Len
) &&
458 !NET_BUF_SHARED (Node
)) {
465 // Create a new buffer and copy data there.
467 Nbuf
= NetbufAlloc (Len
+ TCP_MAX_HEAD
);
473 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
478 if (TCP_SEQ_LT (Seq
+ Len
, Seg
->End
)) {
482 CopyLen
= TCP_SUB_SEQ (End
, Seq
);
483 Offset
= TCP_SUB_SEQ (Seq
, Seg
->Seq
);
486 // If SYN is set and out of the range, clear the flag.
487 // Becuase the sequence of the first byte is SEG.SEQ+1,
488 // adjust Offset by -1. If SYN is in the range, copy
491 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_SYN
)) {
493 if (TCP_SEQ_LT (Seg
->Seq
, Seq
)) {
495 TCP_CLEAR_FLG (Flag
, TCP_FLG_SYN
);
504 // If FIN is set and in the range, copy one byte less,
505 // and if it is out of the range, clear the flag.
507 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_FIN
)) {
509 if (Seg
->End
== End
) {
514 TCP_CLEAR_FLG (Flag
, TCP_FLG_FIN
);
518 ASSERT (CopyLen
>= 0);
521 // copy data to the segment
524 Data
= NetbufAllocSpace (Nbuf
, CopyLen
, NET_BUF_TAIL
);
525 ASSERT (Data
!= NULL
);
527 if ((INT32
) NetbufCopy (Node
, Offset
, CopyLen
, Data
) != CopyLen
) {
532 CopyMem (TCPSEG_NETBUF (Nbuf
), Seg
, sizeof (TCP_SEG
));
534 TCPSEG_NETBUF (Nbuf
)->Seq
= Seq
;
535 TCPSEG_NETBUF (Nbuf
)->End
= End
;
536 TCPSEG_NETBUF (Nbuf
)->Flag
= Flag
;
547 Get a segment from the Tcb's socket buffer.
549 @param Tcb Pointer to the TCP_CB of this TCP instance.
550 @param Seq The sequence number of the segment.
551 @param Len The maximum length of the segment.
553 @return Pointer to the segment, if NULL some error occurred.
567 ASSERT ((Tcb
!= NULL
) && (Tcb
->Sk
!= NULL
));
569 Nbuf
= NetbufAlloc (Len
+ TCP_MAX_HEAD
);
572 DEBUG ((EFI_D_ERROR
, "TcpGetSegmentSock: failed to allocate "
573 "a netbuf for TCB %p\n",Tcb
));
578 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
584 // copy data to the segment.
586 Data
= NetbufAllocSpace (Nbuf
, Len
, NET_BUF_TAIL
);
587 ASSERT (Data
!= NULL
);
589 DataGet
= SockGetDataToSend (Tcb
->Sk
, 0, Len
, Data
);
594 TCPSEG_NETBUF (Nbuf
)->Seq
= Seq
;
595 TCPSEG_NETBUF (Nbuf
)->End
= Seq
+ Len
;
597 InsertTailList (&(Tcb
->SndQue
), &(Nbuf
->List
));
601 SockDataSent (Tcb
->Sk
, DataGet
);
609 Get a segment starting from sequence Seq of a maximum
612 @param Tcb Pointer to the TCP_CB of this TCP instance.
613 @param Seq The sequence number of the segment.
614 @param Len The maximum length of the segment.
616 @return Pointer to the segment, if NULL some error occurred.
628 ASSERT (Tcb
!= NULL
);
631 // Compare the SndNxt with the max sequence number sent.
633 if ((Len
!= 0) && TCP_SEQ_LT (Seq
, TcpGetMaxSndNxt (Tcb
))) {
635 Nbuf
= TcpGetSegmentSndQue (Tcb
, Seq
, Len
);
638 Nbuf
= TcpGetSegmentSock (Tcb
, Seq
, Len
);
641 ASSERT (TcpVerifySegment (Nbuf
) != 0);
647 Retransmit the segment from sequence Seq.
649 @param Tcb Pointer to the TCP_CB of this TCP instance.
650 @param Seq The sequence number of the segment to be retransmitted.
652 @retval 0 Retransmission succeeded.
653 @retval -1 Error condition occurred.
666 // Compute the maxium length of retransmission. It is
667 // limited by three factors:
668 // 1. Less than SndMss
669 // 2. must in the current send window
670 // 3. will not change the boundaries of queued segments.
672 if (TCP_SEQ_LT (Tcb
->SndWl2
+ Tcb
->SndWnd
, Seq
)) {
673 DEBUG ((EFI_D_WARN
, "TcpRetransmit: retransmission cancelled "
674 "because send window too small for TCB %p\n", Tcb
));
679 Len
= TCP_SUB_SEQ (Tcb
->SndWl2
+ Tcb
->SndWnd
, Seq
);
680 Len
= MIN (Len
, Tcb
->SndMss
);
682 Nbuf
= TcpGetSegmentSndQue (Tcb
, Seq
, Len
);
687 ASSERT (TcpVerifySegment (Nbuf
) != 0);
689 if (TcpTransmitSegment (Tcb
, Nbuf
) != 0) {
694 // The retransmitted buffer may be on the SndQue,
695 // trim TCP head because all the buffer on SndQue
698 ASSERT (Nbuf
->Tcp
!= NULL
);
699 NetbufTrim (Nbuf
, (Nbuf
->Tcp
->HeadLen
<< 2), NET_BUF_HEAD
);
715 Check whether to send data/SYN/FIN and piggy back an ACK.
717 @param Tcb Pointer to the TCP_CB of this TCP instance.
718 @param Force Whether to ignore the sender's SWS avoidance algorithm and send
721 @return The number of bytes sent.
738 ASSERT ((Tcb
!= NULL
) && (Tcb
->Sk
!= NULL
) && (Tcb
->State
!= TCP_LISTEN
));
742 if ((Tcb
->State
== TCP_CLOSED
) ||
743 TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_FIN_SENT
)) {
750 // compute how much data can be sent
752 Len
= TcpDataToSend (Tcb
, Force
);
755 ASSERT ((Tcb
->State
) < (sizeof (mTcpOutFlag
) / sizeof (mTcpOutFlag
[0])));
756 Flag
= mTcpOutFlag
[Tcb
->State
];
758 if ((Flag
& TCP_FLG_SYN
) != 0) {
765 // only send a segment without data if SYN or
769 ((Flag
& (TCP_FLG_SYN
| TCP_FLG_FIN
)) == 0)) {
773 Nbuf
= TcpGetSegment (Tcb
, Seq
, Len
);
778 "TcpToSendData: failed to get a segment for TCB %p\n",
785 Seg
= TCPSEG_NETBUF (Nbuf
);
788 // Set the TcpSeg in Nbuf.
790 Len
= Nbuf
->TotalSize
;
792 if (TCP_FLG_ON (Flag
, TCP_FLG_SYN
)) {
796 if ((Flag
& TCP_FLG_FIN
) != 0) {
798 // Send FIN if all data is sent, and FIN is
801 if ((TcpGetMaxSndNxt (Tcb
) == Tcb
->SndNxt
) &&
802 (GET_SND_DATASIZE (Tcb
->Sk
) == 0) &&
803 TCP_SEQ_LT (End
+ 1, Tcb
->SndWnd
+ Tcb
->SndWl2
)) {
807 "TcpToSendData: send FIN "
808 "to peer for TCB %p in state %s\n",
810 mTcpStateName
[Tcb
->State
])
815 TCP_CLEAR_FLG (Flag
, TCP_FLG_FIN
);
823 ASSERT (TcpVerifySegment (Nbuf
) != 0);
824 ASSERT (TcpCheckSndQue (&Tcb
->SndQue
) != 0);
827 // don't send an empty segment here.
829 if (Seg
->End
== Seg
->Seq
) {
830 DEBUG ((EFI_D_WARN
, "TcpToSendData: created a empty"
831 " segment for TCB %p, free it now\n", Tcb
));
837 if (TcpTransmitSegment (Tcb
, Nbuf
) != 0) {
838 NetbufTrim (Nbuf
, (Nbuf
->Tcp
->HeadLen
<< 2), NET_BUF_HEAD
);
841 if ((Flag
& TCP_FLG_FIN
) != 0) {
842 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_FIN_SENT
);
848 Sent
+= TCP_SUB_SEQ (End
, Seq
);
851 // All the buffer in the SndQue is headless
853 ASSERT (Nbuf
->Tcp
!= NULL
);
855 NetbufTrim (Nbuf
, (Nbuf
->Tcp
->HeadLen
<< 2), NET_BUF_HEAD
);
861 // update status in TCB
865 if ((Flag
& TCP_FLG_FIN
) != 0) {
866 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_FIN_SENT
);
869 if (TCP_SEQ_GT (End
, Tcb
->SndNxt
)) {
873 if (!TCP_TIMER_ON (Tcb
->EnabledTimer
, TCP_TIMER_REXMIT
)) {
874 TcpSetTimer (Tcb
, TCP_TIMER_REXMIT
, Tcb
->Rto
);
878 // Enable RTT measurement only if not in retransmit.
879 // Karn's algorithm reqires not to update RTT when in loss.
881 if ((Tcb
->CongestState
== TCP_CONGEST_OPEN
) &&
882 !TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_RTT_ON
)) {
884 DEBUG ((EFI_D_INFO
, "TcpToSendData: set RTT measure "
885 "sequence %d for TCB %p\n", Seq
, Tcb
));
887 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_RTT_ON
);
892 if (Len
== Tcb
->SndMss
) {
908 Send an ACK immediately.
910 @param Tcb Pointer to the TCP_CB of this TCP instance.
921 Nbuf
= NetbufAlloc (TCP_MAX_HEAD
);
927 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
929 Seg
= TCPSEG_NETBUF (Nbuf
);
930 Seg
->Seq
= Tcb
->SndNxt
;
931 Seg
->End
= Tcb
->SndNxt
;
932 Seg
->Flag
= TCP_FLG_ACK
;
934 if (TcpTransmitSegment (Tcb
, Nbuf
) == 0) {
935 TCP_CLEAR_FLG (Tcb
->CtrlFlag
, TCP_CTRL_ACK_NOW
);
944 Send a zero probe segment. It can be used by keepalive and zero window probe.
946 @param Tcb Pointer to the TCP_CB of this TCP instance.
948 @retval 0 The zero probe segment was sent out successfully.
949 @retval other Error condition occurred.
961 Nbuf
= NetbufAlloc (TCP_MAX_HEAD
);
967 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
970 // SndNxt-1 is out of window. The peer should respond
973 Seg
= TCPSEG_NETBUF (Nbuf
);
974 Seg
->Seq
= Tcb
->SndNxt
- 1;
975 Seg
->End
= Tcb
->SndNxt
- 1;
976 Seg
->Flag
= TCP_FLG_ACK
;
978 Result
= TcpTransmitSegment (Tcb
, Nbuf
);
986 Check whether to send an ACK or delayed ACK.
988 @param Tcb Pointer to the TCP_CB of this TCP instance.
998 TcpNow
= TcpRcvWinNow (Tcb
);
1000 // Generally, TCP should send a delayed ACK unless:
1001 // 1. ACK at least every other FULL sized segment received,
1002 // 2. Packets received out of order
1003 // 3. Receiving window is open
1005 if (TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_ACK_NOW
) ||
1006 (Tcb
->DelayedAck
>= 1) ||
1007 (TcpNow
> TcpRcvWinOld (Tcb
))) {
1012 DEBUG ((EFI_D_INFO
, "TcpToSendAck: scheduled a delayed"
1013 " ACK for TCB %p\n", Tcb
));
1016 // schedule a delayed ACK
1023 Send a RESET segment in response to the segment received.
1025 @param Tcb Pointer to the TCP_CB of this TCP instance, may be NULL.
1026 @param Head TCP header of the segment that triggers the reset.
1027 @param Len Length of the segment that triggers the reset.
1028 @param Local Local IP address.
1029 @param Remote Remote peer's IP address.
1031 @retval 0 A reset is sent or no need to send it.
1032 @retval -1 No reset is sent.
1049 // Don't respond to a Reset with reset
1051 if ((Head
->Flag
& TCP_FLG_RST
) != 0) {
1055 Nbuf
= NetbufAlloc (TCP_MAX_HEAD
);
1061 Nhead
= (TCP_HEAD
*) NetbufAllocSpace (
1067 ASSERT (Nhead
!= NULL
);
1070 Nhead
->Flag
= TCP_FLG_RST
;
1073 // Derive Seq/ACK from the segment if no TCB
1074 // associated with it, otherwise from the Tcb
1078 if (TCP_FLG_ON (Head
->Flag
, TCP_FLG_ACK
)) {
1079 Nhead
->Seq
= Head
->Ack
;
1083 TCP_SET_FLG (Nhead
->Flag
, TCP_FLG_ACK
);
1084 Nhead
->Ack
= HTONL (NTOHL (Head
->Seq
) + Len
);
1088 Nhead
->Seq
= HTONL (Tcb
->SndNxt
);
1089 Nhead
->Ack
= HTONL (Tcb
->RcvNxt
);
1090 TCP_SET_FLG (Nhead
->Flag
, TCP_FLG_ACK
);
1093 Nhead
->SrcPort
= Head
->DstPort
;
1094 Nhead
->DstPort
= Head
->SrcPort
;
1095 Nhead
->HeadLen
= (sizeof (TCP_HEAD
) >> 2);
1097 Nhead
->Wnd
= HTONS (0xFFFF);
1098 Nhead
->Checksum
= 0;
1101 HeadSum
= NetPseudoHeadChecksum (Local
, Remote
, 6, 0);
1102 Nhead
->Checksum
= TcpChecksum (Nbuf
, HeadSum
);
1104 TcpSendIpPacket (Tcb
, Nbuf
, Local
, Remote
);
1112 Verify that the segment is in good shape.
1114 @param Nbuf Buffer that contains the segment to be checked.
1116 @retval 0 The segment is broken.
1117 @retval 1 The segment is in good shape.
1133 NET_CHECK_SIGNATURE (Nbuf
, NET_BUF_SIGNATURE
);
1135 Seg
= TCPSEG_NETBUF (Nbuf
);
1136 Len
= Nbuf
->TotalSize
;
1140 if (Head
->Flag
!= Seg
->Flag
) {
1144 Len
-= (Head
->HeadLen
<< 2);
1147 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_SYN
)) {
1151 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_FIN
)) {
1155 if (Seg
->Seq
+ Len
!= Seg
->End
) {
1164 Verify that all the segments in SndQue are in good shape.
1166 @param Head Pointer to the head node of the SndQue.
1168 @retval 0 At least one segment is broken.
1169 @retval 1 All segments in the specific queue are in good shape.
1181 if (IsListEmpty (Head
)) {
1185 // Initialize the Seq
1187 Entry
= Head
->ForwardLink
;
1188 Nbuf
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
1189 Seq
= TCPSEG_NETBUF (Nbuf
)->Seq
;
1191 NET_LIST_FOR_EACH (Entry
, Head
) {
1192 Nbuf
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
1194 if (TcpVerifySegment (Nbuf
) == 0) {
1199 // All the node in the SndQue should has:
1200 // SEG.SEQ = LAST_SEG.END
1202 if (Seq
!= TCPSEG_NETBUF (Nbuf
)->Seq
) {
1206 Seq
= TCPSEG_NETBUF (Nbuf
)->End
;