TianoCore EDK2 master
Loading...
Searching...
No Matches
TcpIo.c
Go to the documentation of this file.
1
10#include "TcpMain.h"
11
25VOID
26EFIAPI
28 IN EFI_STATUS Status,
29 IN UINT8 IcmpErr,
30 IN EFI_NET_SESSION_DATA *NetSession,
31 IN NET_BUF *Pkt,
32 IN VOID *Context OPTIONAL
33 )
34{
35 if (EFI_SUCCESS == Status) {
36 TcpInput (Pkt, &NetSession->Source, &NetSession->Dest, NetSession->IpVersion);
37 } else {
39 Pkt,
40 IcmpErr,
41 &NetSession->Source,
42 &NetSession->Dest,
43 NetSession->IpVersion
44 );
45 }
46}
47
61INTN
63 IN TCP_CB *Tcb,
64 IN NET_BUF *Nbuf,
65 IN EFI_IP_ADDRESS *Src,
66 IN EFI_IP_ADDRESS *Dest,
67 IN UINT8 Version
68 )
69{
70 EFI_STATUS Status;
71 IP_IO *IpIo;
72 IP_IO_OVERRIDE Override;
73 SOCKET *Sock;
74 VOID *IpSender;
75 TCP_PROTO_DATA *TcpProto;
76
77 if (NULL == Tcb) {
78 IpIo = NULL;
79 IpSender = IpIoFindSender (&IpIo, Version, Src);
80
81 if (IpSender == NULL) {
82 DEBUG ((DEBUG_WARN, "TcpSendIpPacket: No appropriate IpSender.\n"));
83 return -1;
84 }
85
86 if (Version == IP_VERSION_6) {
87 //
88 // It's tricky here. EFI IPv6 Spec don't allow an instance overriding the
89 // destination address if the dest is already specified through the
90 // configuration data. Here we get the IpIo we need and use the default IP
91 // instance in this IpIo to send the packet. The dest address is configured
92 // to be the unspecified address for the default IP instance.
93 //
94 IpSender = NULL;
95 }
96 } else {
97 Sock = Tcb->Sk;
98 TcpProto = (TCP_PROTO_DATA *)Sock->ProtoReserved;
99 IpIo = TcpProto->TcpService->IpIo;
100 IpSender = Tcb->IpInfo;
101
102 if (Version == IP_VERSION_6) {
103 //
104 // It's IPv6 and this TCP segment belongs to a solid TCB, in such case
105 // the destination address can't be overridden, so reset the Dest to NULL.
106 //
107 if (!Tcb->RemoteIpZero) {
108 Dest = NULL;
109 }
110 }
111 }
112
113 ASSERT (Version == IpIo->IpVersion);
114
115 if (Version == IP_VERSION_4) {
116 Override.Ip4OverrideData.TypeOfService = 0;
117 Override.Ip4OverrideData.TimeToLive = 255;
118 Override.Ip4OverrideData.DoNotFragment = FALSE;
119 Override.Ip4OverrideData.Protocol = EFI_IP_PROTO_TCP;
120 ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));
121 CopyMem (&Override.Ip4OverrideData.SourceAddress, Src, sizeof (EFI_IPv4_ADDRESS));
122 } else {
123 Override.Ip6OverrideData.Protocol = EFI_IP_PROTO_TCP;
124 Override.Ip6OverrideData.HopLimit = 255;
125 Override.Ip6OverrideData.FlowLabel = 0;
126 }
127
128 Status = IpIoSend (IpIo, Nbuf, IpSender, NULL, NULL, Dest, &Override);
129
130 if (EFI_ERROR (Status)) {
131 DEBUG ((DEBUG_ERROR, "TcpSendIpPacket: return %r error\n", Status));
132 return -1;
133 }
134
135 return 0;
136}
137
158 IN TCP_CB *Tcb,
159 IN EFI_IP_ADDRESS *Neighbor,
160 IN UINT32 Timeout
161 )
162{
163 IP_IO *IpIo;
164 SOCKET *Sock;
165 TCP_PROTO_DATA *TcpProto;
166
167 if (NULL == Tcb) {
168 IpIo = NULL;
169 IpIoFindSender (&IpIo, IP_VERSION_6, Neighbor);
170
171 if (IpIo == NULL) {
172 DEBUG ((DEBUG_WARN, "Tcp6AddNeighbor: No appropriate IpIo.\n"));
173 return EFI_NOT_STARTED;
174 }
175 } else {
176 Sock = Tcb->Sk;
177 TcpProto = (TCP_PROTO_DATA *)Sock->ProtoReserved;
178 IpIo = TcpProto->TcpService->IpIo;
179 }
180
181 return IpIoRefreshNeighbor (IpIo, Neighbor, Timeout);
182}
INT64 INTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI IpIoRefreshNeighbor(IN IP_IO *IpIo, IN EFI_IP_ADDRESS *Neighbor, IN UINT32 Timeout)
Definition: DxeIpIoLib.c:2224
EFI_STATUS EFIAPI IpIoSend(IN OUT IP_IO *IpIo, IN OUT NET_BUF *Pkt, IN IP_IO_IP_INFO *Sender OPTIONAL, IN VOID *Context OPTIONAL, IN VOID *NotifyData OPTIONAL, IN EFI_IP_ADDRESS *Dest OPTIONAL, IN IP_IO_OVERRIDE *OverrideData OPTIONAL)
Definition: DxeIpIoLib.c:1578
IP_IO_IP_INFO *EFIAPI IpIoFindSender(IN OUT IP_IO **IpIo, IN UINT8 IpVersion, IN EFI_IP_ADDRESS *Src)
Definition: DxeIpIoLib.c:2043
#define NULL
Definition: Base.h:319
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID TcpIcmpInput(IN NET_BUF *Nbuf, IN UINT8 IcmpErr, IN EFI_IP_ADDRESS *Src, IN EFI_IP_ADDRESS *Dst, IN UINT8 Version)
Definition: TcpInput.c:1569
INTN TcpInput(IN NET_BUF *Nbuf, IN EFI_IP_ADDRESS *Src, IN EFI_IP_ADDRESS *Dst, IN UINT8 Version)
Definition: TcpInput.c:710
EFI_STATUS Tcp6RefreshNeighbor(IN TCP_CB *Tcb, IN EFI_IP_ADDRESS *Neighbor, IN UINT32 Timeout)
Definition: TcpIo.c:157
INTN TcpSendIpPacket(IN TCP_CB *Tcb, IN NET_BUF *Nbuf, IN EFI_IP_ADDRESS *Src, IN EFI_IP_ADDRESS *Dest, IN UINT8 Version)
Definition: TcpIo.c:62
VOID EFIAPI TcpRxCallback(IN EFI_STATUS Status, IN UINT8 IcmpErr, IN EFI_NET_SESSION_DATA *NetSession, IN NET_BUF *Pkt, IN VOID *Context OPTIONAL)
Definition: TcpIo.c:27
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT8 HopLimit
Hop-Limit override.
Definition: Ip6.h:466
UINT32 FlowLabel
Flow-Label override.
Definition: Ip6.h:467
UINT8 Protocol
Protocol type override.
Definition: Ip6.h:465
UINT8 ProtoReserved[PROTO_RESERVED_LEN]
Data fields reserved for protocol.
Definition: Socket.h:497