X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4Impl.c;h=86648d579c45a3fd94b52345d10709144b7d2b76;hb=e798cd87ca9a3a30c4cea50c5f5de84e10a8bc5a;hp=4788d403fe0836f639164d5888787e928c443aeb;hpb=f6b7393ceb34c9b3a27434268bf2ce517047641f;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c index 4788d403fe..86648d579c 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c @@ -1,6 +1,6 @@ /** @file -Copyright (c) 2005 - 2009, Intel Corporation.
+Copyright (c) 2005 - 2010, Intel Corporation.
All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -13,9 +13,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "Ip4Impl.h" +EFI_IPSEC_PROTOCOL *mIpSec = NULL; + /** Gets the current operational settings for this instance of the EFI IPv4 Protocol driver. - + The GetModeData() function returns the current operational mode data for this driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This function is used optionally to retrieve the operational mode data of underlying @@ -39,10 +41,10 @@ EfiIp4GetModeData ( OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL ); - + /** Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance. - + The Configure() function is used to set, change, or reset the operational parameters and filter settings for this EFI IPv4 Protocol instance. Until these parameters have been set, no network traffic can be sent or received by this @@ -51,14 +53,14 @@ EfiIp4GetModeData ( parameters have been set again. Each EFI IPv4 Protocol instance can be started and stopped independently of each other by enabling or disabling their receive filter settings with the Configure() function. - + When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will be appended as an alias address into the addresses list in the EFI IPv4 Protocol driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL to retrieve the default IPv4 address if it is not available yet. Clients could frequently call GetModeData() to check the status to ensure that the default IPv4 address is ready. - + If operational parameters are reset or changed, any pending transmit and receive requests will be cancelled. Their completion token status will be set to EFI_ABORTED and their events will be signaled. @@ -89,14 +91,14 @@ EfiIp4Configure ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL ); - + /** Joins and leaves multicast groups. - + The Groups() function is used to join and leave multicast group sessions. Joining a group will enable reception of matching multicast packets. Leaving a group will disable the multicast packet reception. - + If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left. @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. @@ -127,25 +129,25 @@ EfiIp4Groups ( IN BOOLEAN JoinFlag, IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL ); - + /** Adds and deletes routing table entries. The Routes() function adds a route to or deletes a route from the routing table. - + Routes are determined by comparing the SubnetAddress with the destination IPv4 address arithmetically AND-ed with the SubnetMask. The gateway address must be on the same subnet as the configured station address. - + The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0. The default route matches all destination IPv4 addresses that do not match any other routes. - + A GatewayAddress that is zero is a nonroute. Packets are sent to the destination IP address if it can be found in the ARP cache or on the local subnet. One automatic nonroute entry will be inserted into the routing table for outgoing packets that are addressed to a local subnet (gateway address of 0.0.0.0). - + Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI IPv4 Protocol instances that use the default IPv4 address will also have copies of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these @@ -176,7 +178,7 @@ EfiIp4Groups ( @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE). @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when DeleteRoute is FALSE). - + **/ EFI_STATUS EFIAPI @@ -187,7 +189,7 @@ EfiIp4Routes ( IN EFI_IPv4_ADDRESS *SubnetMask, IN EFI_IPv4_ADDRESS *GatewayAddress ); - + /** Places outgoing data packets into the transmit queue. @@ -206,7 +208,7 @@ EfiIp4Routes ( @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event was already in the transmit queue. @retval EFI_NOT_READY The completion token could not be queued because the transmit - queue is full. + queue is full. @retval EFI_NOT_FOUND Not route is found to destination address. @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data. @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too @@ -223,13 +225,13 @@ EfiIp4Transmit ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_COMPLETION_TOKEN *Token ); - + /** Places a receiving request into the receiving queue. - + The Receive() function places a completion token into the receive packet queue. This function is always asynchronous. - + The Token.Event field in the completion token must be filled in by the caller and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event @@ -262,10 +264,10 @@ EfiIp4Receive ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_COMPLETION_TOKEN *Token ); - + /** Abort an asynchronous transmit or receive request. - + The Cancel() function is used to abort a pending transmit or receive request. If the token is in the transmit or receive request queues, after calling this function, Token->Status will be set to EFI_ABORTED and then Token->Event will @@ -298,15 +300,15 @@ EfiIp4Cancel ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL ); - + /** Polls for incoming data packets and processes outgoing data packets. - + The Poll() function polls for incoming data packets and processes outgoing data packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll() function to increase the rate that data packets are moved between the communications device and the transmit and receive queues. - + In some systems the periodic timer event may not poll the underlying communications device fast enough to transmit and/or receive all data packets without missing incoming packets or dropping outgoing packets. Drivers and applications that are @@ -346,7 +348,7 @@ mEfiIp4ProtocolTemplete = { /** Gets the current operational settings for this instance of the EFI IPv4 Protocol driver. - + The GetModeData() function returns the current operational mode data for this driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This function is used optionally to retrieve the operational mode data of underlying @@ -404,6 +406,8 @@ EfiIp4GetModeData ( Ip4ModeData->RouteTable = NULL; Ip4ModeData->RouteCount = 0; + Ip4ModeData->MaxPacketSize = IpSb->MaxPacketSize; + // // return the current station address for this IP child. So, // the user can get the default address through this. Some @@ -436,16 +440,13 @@ EfiIp4GetModeData ( } } - if (MnpConfigData != NULL) { - CopyMem (MnpConfigData, &IpSb->MnpConfigData, sizeof (*MnpConfigData)); - } - - if (SnpModeData != NULL) { - CopyMem (SnpModeData, &IpSb->SnpMode, sizeof (*SnpModeData)); - } + // + // Get fresh mode data from MNP, since underlying media status may change + // + Status = IpSb->Mnp->GetModeData (IpSb->Mnp, MnpConfigData, SnpModeData); gBS->RestoreTPL (OldTpl); - return EFI_SUCCESS; + return Status; } @@ -557,6 +558,10 @@ Ip4AutoConfigCallBackDpc ( EFI_STATUS Status; UINTN Len; UINT32 Index; + IP4_ADDR StationAddress; + IP4_ADDR SubnetMask; + IP4_ADDR SubnetAddress; + IP4_ADDR GatewayAddress; IpSb = (IP4_SERVICE *) Context; NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE); @@ -642,11 +647,9 @@ Ip4AutoConfigCallBackDpc ( // Set the default interface's address, then add a directed // route for it, that is, the route whose nexthop is zero. // - Status = Ip4SetAddress ( - IpIf, - EFI_NTOHL (Data->StationAddress), - EFI_NTOHL (Data->SubnetMask) - ); + StationAddress = EFI_NTOHL (Data->StationAddress); + SubnetMask = EFI_NTOHL (Data->SubnetMask); + Status = Ip4SetAddress (IpIf, StationAddress, SubnetMask); if (EFI_ERROR (Status)) { goto ON_EXIT; @@ -654,8 +657,8 @@ Ip4AutoConfigCallBackDpc ( Ip4AddRoute ( IpSb->DefaultRouteTable, - EFI_NTOHL (Data->StationAddress), - EFI_NTOHL (Data->SubnetMask), + StationAddress, + SubnetMask, IP4_ALLZERO_ADDRESS ); @@ -665,12 +668,10 @@ Ip4AutoConfigCallBackDpc ( for (Index = 0; Index < Data->RouteTableSize; Index++) { RouteEntry = &Data->RouteTable[Index]; - Ip4AddRoute ( - IpSb->DefaultRouteTable, - EFI_NTOHL (RouteEntry->SubnetAddress), - EFI_NTOHL (RouteEntry->SubnetMask), - EFI_NTOHL (RouteEntry->GatewayAddress) - ); + SubnetAddress = EFI_NTOHL (RouteEntry->SubnetAddress); + SubnetMask = EFI_NTOHL (RouteEntry->SubnetMask); + GatewayAddress = EFI_NTOHL (RouteEntry->GatewayAddress); + Ip4AddRoute (IpSb->DefaultRouteTable, SubnetAddress, SubnetMask, GatewayAddress); } IpSb->State = IP4_SERVICE_CONFIGED; @@ -678,12 +679,12 @@ Ip4AutoConfigCallBackDpc ( Ip4SetVariableData (IpSb); ON_EXIT: - gBS->FreePool (Data); + FreePool (Data); } /** Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK. - + @param Event The event that is signalled. @param Context The IP4 service binding instance. @@ -1041,13 +1042,13 @@ Ip4CleanProtocol ( } if (IpInstance->EfiRouteTable != NULL) { - gBS->FreePool (IpInstance->EfiRouteTable); + FreePool (IpInstance->EfiRouteTable); IpInstance->EfiRouteTable = NULL; IpInstance->EfiRouteCount = 0; } if (IpInstance->Groups != NULL) { - gBS->FreePool (IpInstance->Groups); + FreePool (IpInstance->Groups); IpInstance->Groups = NULL; IpInstance->GroupCount = 0; } @@ -1122,7 +1123,7 @@ Ip4StationAddressValid ( /** Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance. - + The Configure() function is used to set, change, or reset the operational parameters and filter settings for this EFI IPv4 Protocol instance. Until these parameters have been set, no network traffic can be sent or received by this @@ -1131,14 +1132,14 @@ Ip4StationAddressValid ( parameters have been set again. Each EFI IPv4 Protocol instance can be started and stopped independently of each other by enabling or disabling their receive filter settings with the Configure() function. - + When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will be appended as an alias address into the addresses list in the EFI IPv4 Protocol driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL to retrieve the default IPv4 address if it is not available yet. Clients could frequently call GetModeData() to check the status to ensure that the default IPv4 address is ready. - + If operational parameters are reset or changed, any pending transmit and receive requests will be cancelled. Their completion token status will be set to EFI_ABORTED and their events will be signaled. @@ -1314,7 +1315,7 @@ Ip4Groups ( // host byte order // if (JoinFlag) { - // + // // When JoinFlag is TRUE, GroupAddress shouldn't be NULL. // ASSERT (GroupAddress != NULL); @@ -1333,12 +1334,12 @@ Ip4Groups ( } if (EFI_ERROR (Ip4JoinGroup (IpInstance, NTOHL (Group)))) { - gBS->FreePool (Members); + FreePool (Members); return EFI_DEVICE_ERROR; } if (IpInstance->Groups != NULL) { - gBS->FreePool (IpInstance->Groups); + FreePool (IpInstance->Groups); } IpInstance->Groups = Members; @@ -1366,7 +1367,7 @@ Ip4Groups ( if (IpInstance->GroupCount == 0) { ASSERT (Index == 1); - gBS->FreePool (IpInstance->Groups); + FreePool (IpInstance->Groups); IpInstance->Groups = NULL; } @@ -1382,11 +1383,11 @@ Ip4Groups ( /** Joins and leaves multicast groups. - + The Groups() function is used to join and leave multicast group sessions. Joining a group will enable reception of matching multicast packets. Leaving a group will disable the multicast packet reception. - + If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left. @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. @@ -1460,20 +1461,20 @@ ON_EXIT: Adds and deletes routing table entries. The Routes() function adds a route to or deletes a route from the routing table. - + Routes are determined by comparing the SubnetAddress with the destination IPv4 address arithmetically AND-ed with the SubnetMask. The gateway address must be on the same subnet as the configured station address. - + The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0. The default route matches all destination IPv4 addresses that do not match any other routes. - + A GatewayAddress that is zero is a nonroute. Packets are sent to the destination IP address if it can be found in the ARP cache or on the local subnet. One automatic nonroute entry will be inserted into the routing table for outgoing packets that are addressed to a local subnet (gateway address of 0.0.0.0). - + Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI IPv4 Protocol instances that use the default IPv4 address will also have copies of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these @@ -1504,7 +1505,7 @@ ON_EXIT: @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE). @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when DeleteRoute is FALSE). - + **/ EFI_STATUS EFIAPI @@ -1598,6 +1599,7 @@ ON_EXIT: **/ EFI_STATUS +EFIAPI Ip4TokenExist ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -1689,7 +1691,7 @@ Ip4TxTokenValid ( // Check the source and gateway: they must be a valid unicast. // Gateway must also be on the connected network. // - if (TxData->OverrideData) { + if (TxData->OverrideData != NULL) { Override = TxData->OverrideData; CopyMem (&Src, &Override->SourceAddress, sizeof (IP4_ADDR)); @@ -1755,6 +1757,7 @@ Ip4TxTokenValid ( **/ VOID +EFIAPI Ip4FreeTxToken ( IN VOID *Context ) @@ -1764,6 +1767,13 @@ Ip4FreeTxToken ( Wrap = (IP4_TXTOKEN_WRAP *) Context; + // + // Signal IpSecRecycleEvent to inform IPsec free the memory + // + if (Wrap->IpSecRecycleSignal != NULL) { + gBS->SignalEvent (Wrap->IpSecRecycleSignal); + } + // // Find the token in the instance's map. EfiIp4Transmit put the // token to the map. If that failed, NetMapFindKey will return NULL. @@ -1783,7 +1793,7 @@ Ip4FreeTxToken ( DispatchDpc (); } - gBS->FreePool (Wrap); + FreePool (Wrap); } @@ -1846,7 +1856,7 @@ Ip4OnPacketSent ( @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event was already in the transmit queue. @retval EFI_NOT_READY The completion token could not be queued because the transmit - queue is full. + queue is full. @retval EFI_NOT_FOUND Not route is found to destination address. @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data. @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too @@ -1925,7 +1935,7 @@ EfiIp4Transmit ( CopyMem (&Head.Dst, &TxData->DestinationAddress, sizeof (IP4_ADDR)); Head.Dst = NTOHL (Head.Dst); - if (TxData->OverrideData) { + if (TxData->OverrideData != NULL) { Override = TxData->OverrideData; Head.Protocol = Override->Protocol; Head.Tos = Override->TypeOfService; @@ -1947,12 +1957,12 @@ EfiIp4Transmit ( } Head.Fragment = IP4_HEAD_FRAGMENT_FIELD (DontFragment, FALSE, 0); - HeadLen = sizeof (IP4_HEAD) + ((TxData->OptionsLength + 3) &~0x03); + HeadLen = (TxData->OptionsLength + 3) & (~0x03); // // If don't fragment and fragment needed, return error // - if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->SnpMode.MaxPacketSize)) { + if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->MaxPacketSize)) { Status = EFI_BAD_BUFFER_SIZE; goto ON_EXIT; } @@ -1981,7 +1991,7 @@ EfiIp4Transmit ( ); if (Wrap->Packet == NULL) { - gBS->FreePool (Wrap); + FreePool (Wrap); goto ON_EXIT; } @@ -2028,10 +2038,10 @@ ON_EXIT: /** Places a receiving request into the receiving queue. - + The Receive() function places a completion token into the receive packet queue. This function is always asynchronous. - + The Token.Event field in the completion token must be filled in by the caller and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event @@ -2136,6 +2146,7 @@ ON_EXIT: **/ EFI_STATUS +EFIAPI Ip4CancelTxTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -2191,6 +2202,7 @@ Ip4CancelTxTokens ( **/ EFI_STATUS +EFIAPI Ip4CancelRxTokens ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item, @@ -2299,7 +2311,7 @@ Ip4Cancel ( /** Abort an asynchronous transmit or receive request. - + The Cancel() function is used to abort a pending transmit or receive request. If the token is in the transmit or receive request queues, after calling this function, Token->Status will be set to EFI_ABORTED and then Token->Event will @@ -2365,12 +2377,12 @@ ON_EXIT: /** Polls for incoming data packets and processes outgoing data packets. - + The Poll() function polls for incoming data packets and processes outgoing data packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll() function to increase the rate that data packets are moved between the communications device and the transmit and receive queues. - + In some systems the periodic timer event may not poll the underlying communications device fast enough to transmit and/or receive all data packets without missing incoming packets or dropping outgoing packets. Drivers and applications that are @@ -2433,6 +2445,7 @@ EfiIp4Poll ( **/ EFI_STATUS +EFIAPI Ip4SentPacketTicking ( IN NET_MAP *Map, IN NET_MAP_ITEM *Item,