]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Output.c
2 TCP output process routines.
4 Copyright (c) 2005 - 2006, 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
);
451 // Return the buffer if it can be returned without
454 if ((Seg
->Seq
== Seq
) &&
455 TCP_SEQ_LEQ (Seg
->End
, Seg
->Seq
+ Len
) &&
456 !NET_BUF_SHARED (Node
)) {
463 // Create a new buffer and copy data there.
465 Nbuf
= NetbufAlloc (Len
+ TCP_MAX_HEAD
);
471 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
476 if (TCP_SEQ_LT (Seq
+ Len
, Seg
->End
)) {
480 CopyLen
= TCP_SUB_SEQ (End
, Seq
);
481 Offset
= TCP_SUB_SEQ (Seq
, Seg
->Seq
);
484 // If SYN is set and out of the range, clear the flag.
485 // Becuase the sequence of the first byte is SEG.SEQ+1,
486 // adjust Offset by -1. If SYN is in the range, copy
489 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_SYN
)) {
491 if (TCP_SEQ_LT (Seg
->Seq
, Seq
)) {
493 TCP_CLEAR_FLG (Flag
, TCP_FLG_SYN
);
502 // If FIN is set and in the range, copy one byte less,
503 // and if it is out of the range, clear the flag.
505 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_FIN
)) {
507 if (Seg
->End
== End
) {
512 TCP_CLEAR_FLG (Flag
, TCP_FLG_FIN
);
516 ASSERT (CopyLen
>= 0);
519 // copy data to the segment
522 Data
= NetbufAllocSpace (Nbuf
, CopyLen
, NET_BUF_TAIL
);
523 ASSERT (Data
!= NULL
);
525 if ((INT32
) NetbufCopy (Node
, Offset
, CopyLen
, Data
) != CopyLen
) {
530 CopyMem (TCPSEG_NETBUF (Nbuf
), Seg
, sizeof (TCP_SEG
));
532 TCPSEG_NETBUF (Nbuf
)->Seq
= Seq
;
533 TCPSEG_NETBUF (Nbuf
)->End
= End
;
534 TCPSEG_NETBUF (Nbuf
)->Flag
= Flag
;
545 Get a segment from the Tcb's socket buffer.
547 @param Tcb Pointer to the TCP_CB of this TCP instance.
548 @param Seq The sequence number of the segment.
549 @param Len The maximum length of the segment.
551 @return Pointer to the segment, if NULL some error occurred.
565 ASSERT ((Tcb
!= NULL
) && (Tcb
->Sk
!= NULL
));
567 Nbuf
= NetbufAlloc (Len
+ TCP_MAX_HEAD
);
570 DEBUG ((EFI_D_ERROR
, "TcpGetSegmentSock: failed to allocate "
571 "a netbuf for TCB %p\n",Tcb
));
576 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
582 // copy data to the segment.
584 Data
= NetbufAllocSpace (Nbuf
, Len
, NET_BUF_TAIL
);
585 ASSERT (Data
!= NULL
);
587 DataGet
= SockGetDataToSend (Tcb
->Sk
, 0, Len
, Data
);
592 TCPSEG_NETBUF (Nbuf
)->Seq
= Seq
;
593 TCPSEG_NETBUF (Nbuf
)->End
= Seq
+ Len
;
595 InsertTailList (&(Tcb
->SndQue
), &(Nbuf
->List
));
599 SockDataSent (Tcb
->Sk
, DataGet
);
607 Get a segment starting from sequence Seq of a maximum
610 @param Tcb Pointer to the TCP_CB of this TCP instance.
611 @param Seq The sequence number of the segment.
612 @param Len The maximum length of the segment.
614 @return Pointer to the segment, if NULL some error occurred.
626 ASSERT (Tcb
!= NULL
);
629 // Compare the SndNxt with the max sequence number sent.
631 if ((Len
!= 0) && TCP_SEQ_LT (Seq
, TcpGetMaxSndNxt (Tcb
))) {
633 Nbuf
= TcpGetSegmentSndQue (Tcb
, Seq
, Len
);
636 Nbuf
= TcpGetSegmentSock (Tcb
, Seq
, Len
);
639 ASSERT (TcpVerifySegment (Nbuf
) != 0);
645 Retransmit the segment from sequence Seq.
647 @param Tcb Pointer to the TCP_CB of this TCP instance.
648 @param Seq The sequence number of the segment to be retransmitted.
650 @retval 0 Retransmission succeeded.
651 @retval -1 Error condition occurred.
664 // Compute the maxium length of retransmission. It is
665 // limited by three factors:
666 // 1. Less than SndMss
667 // 2. must in the current send window
668 // 3. will not change the boundaries of queued segments.
670 if (TCP_SEQ_LT (Tcb
->SndWl2
+ Tcb
->SndWnd
, Seq
)) {
671 DEBUG ((EFI_D_WARN
, "TcpRetransmit: retransmission cancelled "
672 "because send window too small for TCB %p\n", Tcb
));
677 Len
= TCP_SUB_SEQ (Tcb
->SndWl2
+ Tcb
->SndWnd
, Seq
);
678 Len
= MIN (Len
, Tcb
->SndMss
);
680 Nbuf
= TcpGetSegmentSndQue (Tcb
, Seq
, Len
);
685 ASSERT (TcpVerifySegment (Nbuf
) != 0);
687 if (TcpTransmitSegment (Tcb
, Nbuf
) != 0) {
692 // The retransmitted buffer may be on the SndQue,
693 // trim TCP head because all the buffer on SndQue
696 ASSERT (Nbuf
->Tcp
!= NULL
);
697 NetbufTrim (Nbuf
, (Nbuf
->Tcp
->HeadLen
<< 2), NET_BUF_HEAD
);
713 Check whether to send data/SYN/FIN and piggy back an ACK.
715 @param Tcb Pointer to the TCP_CB of this TCP instance.
716 @param Force Whether to ignore the sender's SWS avoidance algorithm and send
719 @return The number of bytes sent.
736 ASSERT ((Tcb
!= NULL
) && (Tcb
->Sk
!= NULL
) && (Tcb
->State
!= TCP_LISTEN
));
740 if ((Tcb
->State
== TCP_CLOSED
) ||
741 TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_FIN_SENT
)) {
748 // compute how much data can be sent
750 Len
= TcpDataToSend (Tcb
, Force
);
753 Flag
= mTcpOutFlag
[Tcb
->State
];
755 if ((Flag
& TCP_FLG_SYN
) != 0) {
762 // only send a segment without data if SYN or
766 ((Flag
& (TCP_FLG_SYN
| TCP_FLG_FIN
)) == 0)) {
770 Nbuf
= TcpGetSegment (Tcb
, Seq
, Len
);
775 "TcpToSendData: failed to get a segment for TCB %p\n",
782 Seg
= TCPSEG_NETBUF (Nbuf
);
785 // Set the TcpSeg in Nbuf.
787 Len
= Nbuf
->TotalSize
;
789 if (TCP_FLG_ON (Flag
, TCP_FLG_SYN
)) {
793 if ((Flag
& TCP_FLG_FIN
) != 0) {
795 // Send FIN if all data is sent, and FIN is
798 if ((TcpGetMaxSndNxt (Tcb
) == Tcb
->SndNxt
) &&
799 (GET_SND_DATASIZE (Tcb
->Sk
) == 0) &&
800 TCP_SEQ_LT (End
+ 1, Tcb
->SndWnd
+ Tcb
->SndWl2
)) {
804 "TcpToSendData: send FIN "
805 "to peer for TCB %p in state %s\n",
807 mTcpStateName
[Tcb
->State
])
812 TCP_CLEAR_FLG (Flag
, TCP_FLG_FIN
);
820 ASSERT (TcpVerifySegment (Nbuf
) != 0);
821 ASSERT (TcpCheckSndQue (&Tcb
->SndQue
) != 0);
824 // don't send an empty segment here.
826 if (Seg
->End
== Seg
->Seq
) {
827 DEBUG ((EFI_D_WARN
, "TcpToSendData: created a empty"
828 " segment for TCB %p, free it now\n", Tcb
));
834 if (TcpTransmitSegment (Tcb
, Nbuf
) != 0) {
835 NetbufTrim (Nbuf
, (Nbuf
->Tcp
->HeadLen
<< 2), NET_BUF_HEAD
);
838 if ((Flag
& TCP_FLG_FIN
) != 0) {
839 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_FIN_SENT
);
845 Sent
+= TCP_SUB_SEQ (End
, Seq
);
848 // All the buffer in the SndQue is headless
850 ASSERT (Nbuf
->Tcp
!= NULL
);
852 NetbufTrim (Nbuf
, (Nbuf
->Tcp
->HeadLen
<< 2), NET_BUF_HEAD
);
858 // update status in TCB
862 if ((Flag
& TCP_FLG_FIN
) != 0) {
863 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_FIN_SENT
);
866 if (TCP_SEQ_GT (End
, Tcb
->SndNxt
)) {
870 if (!TCP_TIMER_ON (Tcb
->EnabledTimer
, TCP_TIMER_REXMIT
)) {
871 TcpSetTimer (Tcb
, TCP_TIMER_REXMIT
, Tcb
->Rto
);
875 // Enable RTT measurement only if not in retransmit.
876 // Karn's algorithm reqires not to update RTT when in loss.
878 if ((Tcb
->CongestState
== TCP_CONGEST_OPEN
) &&
879 !TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_RTT_ON
)) {
881 DEBUG ((EFI_D_INFO
, "TcpToSendData: set RTT measure "
882 "sequence %d for TCB %p\n", Seq
, Tcb
));
884 TCP_SET_FLG (Tcb
->CtrlFlag
, TCP_CTRL_RTT_ON
);
889 if (Len
== Tcb
->SndMss
) {
905 Send an ACK immediately.
907 @param Tcb Pointer to the TCP_CB of this TCP instance.
918 Nbuf
= NetbufAlloc (TCP_MAX_HEAD
);
924 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
926 Seg
= TCPSEG_NETBUF (Nbuf
);
927 Seg
->Seq
= Tcb
->SndNxt
;
928 Seg
->End
= Tcb
->SndNxt
;
929 Seg
->Flag
= TCP_FLG_ACK
;
931 if (TcpTransmitSegment (Tcb
, Nbuf
) == 0) {
932 TCP_CLEAR_FLG (Tcb
->CtrlFlag
, TCP_CTRL_ACK_NOW
);
941 Send a zero probe segment. It can be used by keepalive and zero window probe.
943 @param Tcb Pointer to the TCP_CB of this TCP instance.
945 @retval 0 The zero probe segment was sent out successfully.
946 @retval other Error condition occurred.
958 Nbuf
= NetbufAlloc (TCP_MAX_HEAD
);
964 NetbufReserve (Nbuf
, TCP_MAX_HEAD
);
967 // SndNxt-1 is out of window. The peer should respond
970 Seg
= TCPSEG_NETBUF (Nbuf
);
971 Seg
->Seq
= Tcb
->SndNxt
- 1;
972 Seg
->End
= Tcb
->SndNxt
- 1;
973 Seg
->Flag
= TCP_FLG_ACK
;
975 Result
= TcpTransmitSegment (Tcb
, Nbuf
);
983 Check whether to send an ACK or delayed ACK.
985 @param Tcb Pointer to the TCP_CB of this TCP instance.
995 TcpNow
= TcpRcvWinNow (Tcb
);
997 // Generally, TCP should send a delayed ACK unless:
998 // 1. ACK at least every other FULL sized segment received,
999 // 2. Packets received out of order
1000 // 3. Receiving window is open
1002 if (TCP_FLG_ON (Tcb
->CtrlFlag
, TCP_CTRL_ACK_NOW
) ||
1003 (Tcb
->DelayedAck
>= 1) ||
1004 (TcpNow
> TcpRcvWinOld (Tcb
))) {
1009 DEBUG ((EFI_D_INFO
, "TcpToSendAck: scheduled a delayed"
1010 " ACK for TCB %p\n", Tcb
));
1013 // schedule a delayed ACK
1020 Send a RESET segment in response to the segment received.
1022 @param Tcb Pointer to the TCP_CB of this TCP instance, may be NULL.
1023 @param Head TCP header of the segment that triggers the reset.
1024 @param Len Length of the segment that triggers the reset.
1025 @param Local Local IP address.
1026 @param Remote Remote peer's IP address.
1028 @retval 0 A reset is sent or no need to send it.
1029 @retval -1 No reset is sent.
1046 // Don't respond to a Reset with reset
1048 if ((Head
->Flag
& TCP_FLG_RST
) != 0) {
1052 Nbuf
= NetbufAlloc (TCP_MAX_HEAD
);
1058 Nhead
= (TCP_HEAD
*) NetbufAllocSpace (
1064 ASSERT (Nhead
!= NULL
);
1067 Nhead
->Flag
= TCP_FLG_RST
;
1070 // Derive Seq/ACK from the segment if no TCB
1071 // associated with it, otherwise from the Tcb
1075 if (TCP_FLG_ON (Head
->Flag
, TCP_FLG_ACK
)) {
1076 Nhead
->Seq
= Head
->Ack
;
1080 TCP_SET_FLG (Nhead
->Flag
, TCP_FLG_ACK
);
1081 Nhead
->Ack
= HTONL (NTOHL (Head
->Seq
) + Len
);
1085 Nhead
->Seq
= HTONL (Tcb
->SndNxt
);
1086 Nhead
->Ack
= HTONL (Tcb
->RcvNxt
);
1087 TCP_SET_FLG (Nhead
->Flag
, TCP_FLG_ACK
);
1090 Nhead
->SrcPort
= Head
->DstPort
;
1091 Nhead
->DstPort
= Head
->SrcPort
;
1092 Nhead
->HeadLen
= (sizeof (TCP_HEAD
) >> 2);
1094 Nhead
->Wnd
= HTONS (0xFFFF);
1095 Nhead
->Checksum
= 0;
1098 HeadSum
= NetPseudoHeadChecksum (Local
, Remote
, 6, 0);
1099 Nhead
->Checksum
= TcpChecksum (Nbuf
, HeadSum
);
1101 TcpSendIpPacket (Tcb
, Nbuf
, Local
, Remote
);
1109 Verify that the segment is in good shape.
1111 @param Nbuf Buffer that contains the segment to be checked.
1113 @retval 0 The segment is broken.
1114 @retval 1 The segment is in good shape.
1130 NET_CHECK_SIGNATURE (Nbuf
, NET_BUF_SIGNATURE
);
1132 Seg
= TCPSEG_NETBUF (Nbuf
);
1133 Len
= Nbuf
->TotalSize
;
1137 if (Head
->Flag
!= Seg
->Flag
) {
1141 Len
-= (Head
->HeadLen
<< 2);
1144 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_SYN
)) {
1148 if (TCP_FLG_ON (Seg
->Flag
, TCP_FLG_FIN
)) {
1152 if (Seg
->Seq
+ Len
!= Seg
->End
) {
1161 Verify that all the segments in SndQue are in good shape.
1163 @param Head Pointer to the head node of the SndQue.
1165 @retval 0 At least one segment is broken.
1166 @retval 1 All segments in the specific queue are in good shape.
1178 if (IsListEmpty (Head
)) {
1182 // Initialize the Seq
1184 Entry
= Head
->ForwardLink
;
1185 Nbuf
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
1186 Seq
= TCPSEG_NETBUF (Nbuf
)->Seq
;
1188 NET_LIST_FOR_EACH (Entry
, Head
) {
1189 Nbuf
= NET_LIST_USER_STRUCT (Entry
, NET_BUF
, List
);
1191 if (TcpVerifySegment (Nbuf
) == 0) {
1196 // All the node in the SndQue should has:
1197 // SEG.SEQ = LAST_SEG.END
1199 if (Seq
!= TCPSEG_NETBUF (Nbuf
)->Seq
) {
1203 Seq
= TCPSEG_NETBUF (Nbuf
)->End
;