]>
git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/TcpDxe/TcpIo.c
2 Implementation of I/O interfaces between TCP and IpIoLib.
4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Packet receive callback function provided to IP_IO, used to call
14 the proper function to handle the packet received by IP.
16 @param[in] Status Result of the receive request.
17 @param[in] IcmpErr Valid when Status is EFI_ICMP_ERROR.
18 @param[in] NetSession The IP session for the received packet.
19 @param[in] Pkt Packet received.
20 @param[in] Context The data provided by the user for the received packet when
21 the callback is registered in IP_IO_OPEN_DATA::RcvdContext.
22 This is an optional parameter that may be NULL.
30 IN EFI_NET_SESSION_DATA
*NetSession
,
32 IN VOID
*Context OPTIONAL
35 if (EFI_SUCCESS
== Status
) {
36 TcpInput (Pkt
, &NetSession
->Source
, &NetSession
->Dest
, NetSession
->IpVersion
);
49 Send the segment to IP via IpIo function.
51 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
52 @param[in] Nbuf Pointer to the TCP segment to be sent.
53 @param[in] Src Source address of the TCP segment.
54 @param[in] Dest Destination address of the TCP segment.
55 @param[in] Version IP_VERSION_4 or IP_VERSION_6
57 @retval 0 The segment was sent out successfully.
58 @retval -1 The segment failed to send.
65 IN EFI_IP_ADDRESS
*Src
,
66 IN EFI_IP_ADDRESS
*Dest
,
72 IP_IO_OVERRIDE Override
;
75 TCP_PROTO_DATA
*TcpProto
;
80 IpSender
= IpIoFindSender (&IpIo
, Version
, Src
);
82 if (IpSender
== NULL
) {
83 DEBUG ((EFI_D_WARN
, "TcpSendIpPacket: No appropriate IpSender.\n"));
87 if (Version
== IP_VERSION_6
) {
89 // It's tricky here. EFI IPv6 Spec don't allow an instance overriding the
90 // destination address if the dest is already specified through the
91 // configuration data. Here we get the IpIo we need and use the default IP
92 // instance in this IpIo to send the packet. The dest address is configured
93 // to be the unspecified address for the default IP instance.
100 TcpProto
= (TCP_PROTO_DATA
*) Sock
->ProtoReserved
;
101 IpIo
= TcpProto
->TcpService
->IpIo
;
102 IpSender
= Tcb
->IpInfo
;
104 if (Version
== IP_VERSION_6
) {
106 // It's IPv6 and this TCP segment belongs to a solid TCB, in such case
107 // the destination address can't be overridden, so reset the Dest to NULL.
109 if (!Tcb
->RemoteIpZero
) {
115 ASSERT (Version
== IpIo
->IpVersion
);
117 if (Version
== IP_VERSION_4
) {
118 Override
.Ip4OverrideData
.TypeOfService
= 0;
119 Override
.Ip4OverrideData
.TimeToLive
= 255;
120 Override
.Ip4OverrideData
.DoNotFragment
= FALSE
;
121 Override
.Ip4OverrideData
.Protocol
= EFI_IP_PROTO_TCP
;
122 ZeroMem (&Override
.Ip4OverrideData
.GatewayAddress
, sizeof (EFI_IPv4_ADDRESS
));
123 CopyMem (&Override
.Ip4OverrideData
.SourceAddress
, Src
, sizeof (EFI_IPv4_ADDRESS
));
125 Override
.Ip6OverrideData
.Protocol
= EFI_IP_PROTO_TCP
;
126 Override
.Ip6OverrideData
.HopLimit
= 255;
127 Override
.Ip6OverrideData
.FlowLabel
= 0;
130 Status
= IpIoSend (IpIo
, Nbuf
, IpSender
, NULL
, NULL
, Dest
, &Override
);
132 if (EFI_ERROR (Status
)) {
133 DEBUG ((EFI_D_ERROR
, "TcpSendIpPacket: return %r error\n", Status
));
141 Refresh the remote peer's Neighbor Cache State if already exists.
143 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
144 @param[in] Neighbor Source address of the TCP segment.
145 @param[in] Timeout Time in 100-ns units that this entry will remain
146 in the neighbor cache. A value of zero means that
147 the entry is permanent. A value of non-zero means
148 that the entry is dynamic and will be deleted
151 @retval EFI_SUCCESS Successfully updated the neighbor relationship.
152 @retval EFI_NOT_STARTED The IpIo is not configured.
153 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
154 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.
155 @retval EFI_NOT_FOUND This entry is not in the neighbor table.
159 Tcp6RefreshNeighbor (
161 IN EFI_IP_ADDRESS
*Neighbor
,
167 TCP_PROTO_DATA
*TcpProto
;
171 IpIoFindSender (&IpIo
, IP_VERSION_6
, Neighbor
);
174 DEBUG ((EFI_D_WARN
, "Tcp6AddNeighbor: No appropriate IpIo.\n"));
175 return EFI_NOT_STARTED
;
180 TcpProto
= (TCP_PROTO_DATA
*) Sock
->ProtoReserved
;
181 IpIo
= TcpProto
->TcpService
->IpIo
;
184 return IpIoRefreshNeighbor (IpIo
, Neighbor
, Timeout
);