X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=StdLib%2FEfiSocketLib%2FUdp4.c;h=ef2f9e321b2d50f856009233e21ffcd733b6a1e6;hp=414e3fe321a4c076c9f0d64d4f252b9a65f093ff;hb=c581e5037dca6e1446972aed194f13c9cdd0b01b;hpb=884ed923564f35084c45a8f3f132c076b26f2423 diff --git a/StdLib/EfiSocketLib/Udp4.c b/StdLib/EfiSocketLib/Udp4.c index 414e3fe321..ef2f9e321b 100644 --- a/StdLib/EfiSocketLib/Udp4.c +++ b/StdLib/EfiSocketLib/Udp4.c @@ -1,7 +1,7 @@ /** @file Implement the UDP4 driver support for the socket layer. - Copyright (c) 2011, Intel Corporation + Copyright (c) 2011 - 2015, 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 @@ -266,7 +266,7 @@ EslUdp4PortAllocate ( pConfig->AcceptBroadcast = FALSE; pConfig->AcceptPromiscuous = FALSE; pConfig->AllowDuplicatePort = TRUE; - pConfig->DoNotFragment = TRUE; + pConfig->DoNotFragment = FALSE; Status = EFI_SUCCESS; // @@ -867,63 +867,62 @@ EslUdp4TxBuffer ( RAISE_TPL ( TplPrevious, TPL_SOCKETS ); // - // Stop transmission after an error + // Display the request // - if ( !EFI_ERROR ( pSocket->TxError )) { - // - // Display the request - // - DEBUG (( DEBUG_TX, - "Send %d %s bytes from 0x%08x\r\n", - BufferLength, - pBuffer )); - - // - // Queue the data for transmission - // - pPacket->pNext = NULL; - pPreviousPacket = pSocket->pTxPacketListTail; - if ( NULL == pPreviousPacket ) { - pSocket->pTxPacketListHead = pPacket; - } - else { - pPreviousPacket->pNext = pPacket; - } - pSocket->pTxPacketListTail = pPacket; - DEBUG (( DEBUG_TX, - "0x%08x: Packet on transmit list\r\n", - pPacket )); - - // - // Account for the buffered data - // - *pTxBytes += BufferLength; - *pDataLength = BufferLength; + DEBUG (( DEBUG_TX, + "Send %d bytes from 0x%08x to %d.%d.%d.%d:%d\r\n", + BufferLength, + pBuffer, + pTxData->Session.DestinationAddress.Addr[0], + pTxData->Session.DestinationAddress.Addr[1], + pTxData->Session.DestinationAddress.Addr[2], + pTxData->Session.DestinationAddress.Addr[3], + pTxData->Session.DestinationPort )); - // - // Start the transmit engine if it is idle - // - if ( NULL != pPort->pTxFree ) { - EslSocketTxStart ( pPort, - &pSocket->pTxPacketListHead, - &pSocket->pTxPacketListTail, - &pPort->pTxActive, - &pPort->pTxFree ); - } + // + // Queue the data for transmission + // + pPacket->pNext = NULL; + pPreviousPacket = pSocket->pTxPacketListTail; + if ( NULL == pPreviousPacket ) { + pSocket->pTxPacketListHead = pPacket; } else { - // - // Previous transmit error - // Stop transmission - // - Status = pSocket->TxError; - pSocket->errno = EIO; + pPreviousPacket->pNext = pPacket; + } + pSocket->pTxPacketListTail = pPacket; + DEBUG (( DEBUG_TX, + "0x%08x: Packet on transmit list\r\n", + pPacket )); + + // + // Account for the buffered data + // + *pTxBytes += BufferLength; + *pDataLength = BufferLength; + + // + // Start the transmit engine if it is idle + // + if ( NULL != pPort->pTxFree ) { + pPacket = pSocket->pTxPacketListHead; + EslSocketTxStart ( pPort, + &pSocket->pTxPacketListHead, + &pSocket->pTxPacketListTail, + &pPort->pTxActive, + &pPort->pTxFree ); // - // Free the packet + // Ignore any transmit error // - EslSocketPacketFree ( pPacket, DEBUG_TX ); - break; + if ( EFI_ERROR ( pSocket->TxError )) { + DEBUG (( DEBUG_TX, + "0x%08x: Transmit error, Packet: 0x%08x, Status: %r\r\n", + pPort, + pPacket, + pSocket->TxError )); + } + pSocket->TxError = EFI_SUCCESS; } // @@ -1004,6 +1003,18 @@ EslUdp4TxComplete ( pSocket->TxBytes -= LengthInBytes; Status = pIo->Token.Udp4Tx.Status; + // + // Ignore the transmit error + // + if ( EFI_ERROR ( Status )) { + DEBUG (( DEBUG_TX, + "0x%08x: Transmit completion error, Packet: 0x%08x, Status: %r\r\n", + pPort, + pPacket, + Status )); + Status = EFI_SUCCESS; + } + // // Complete the transmit operation // @@ -1019,6 +1030,165 @@ EslUdp4TxComplete ( } +/** + Verify the adapter's IP address + + This support routine is called by EslSocketBindTest. + + @param [in] pPort Address of an ::ESL_PORT structure. + @param [in] pConfigData Address of the configuration data + + @retval EFI_SUCCESS - The IP address is valid + @retval EFI_NOT_STARTED - The IP address is invalid + + **/ +EFI_STATUS +EslUdp4VerifyLocalIpAddress ( + IN ESL_PORT * pPort, + IN EFI_UDP4_CONFIG_DATA * pConfigData + ) +{ + UINTN DataSize; + EFI_IP4_CONFIG2_INTERFACE_INFO * pIfInfo; + EFI_IP4_CONFIG2_PROTOCOL * pIpConfig2Protocol; + ESL_SERVICE * pService; + EFI_STATUS Status; + + DBG_ENTER ( ); + + // + // Use break instead of goto + // + pIfInfo = NULL; + for ( ; ; ) { + // + // Determine if the IP address is specified + // + DEBUG (( DEBUG_BIND, + "UseDefaultAddress: %s\r\n", + pConfigData->UseDefaultAddress ? L"TRUE" : L"FALSE" )); + DEBUG (( DEBUG_BIND, + "Requested IP address: %d.%d.%d.%d\r\n", + pConfigData->StationAddress.Addr [ 0 ], + pConfigData->StationAddress.Addr [ 1 ], + pConfigData->StationAddress.Addr [ 2 ], + pConfigData->StationAddress.Addr [ 3 ])); + if ( pConfigData->UseDefaultAddress + || (( 0 == pConfigData->StationAddress.Addr [ 0 ]) + && ( 0 == pConfigData->StationAddress.Addr [ 1 ]) + && ( 0 == pConfigData->StationAddress.Addr [ 2 ]) + && ( 0 == pConfigData->StationAddress.Addr [ 3 ]))) + { + Status = EFI_SUCCESS; + break; + } + + // + // Open the configuration protocol + // + pService = pPort->pService; + Status = gBS->OpenProtocol ( + pService->Controller, + &gEfiIp4Config2ProtocolGuid, + (VOID **)&pIpConfig2Protocol, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if ( EFI_ERROR ( Status )) { + DEBUG (( DEBUG_ERROR, + "ERROR - IP Configuration Protocol not available, Status: %r\r\n", + Status )); + break; + } + + // + // Get the interface information size + // + DataSize = 0; + Status = pIpConfig2Protocol->GetData ( + pIpConfig2Protocol, + Ip4Config2DataTypeInterfaceInfo, + &DataSize, + NULL + ); + if ( EFI_BUFFER_TOO_SMALL != Status ) { + DEBUG (( DEBUG_ERROR, + "ERROR - Failed to get the interface information size, Status: %r\r\n", + Status )); + break; + } + + // + // Allocate the interface information buffer + // + pIfInfo = AllocatePool ( DataSize ); + if ( NULL == pIfInfo ) { + DEBUG (( DEBUG_ERROR, + "ERROR - Not enough memory to allocate the interface information buffer!\r\n" )); + Status = EFI_OUT_OF_RESOURCES; + break; + } + + // + // Get the interface info. + // + Status = pIpConfig2Protocol->GetData ( + pIpConfig2Protocol, + Ip4Config2DataTypeInterfaceInfo, + &DataSize, + pIfInfo + ); + if ( EFI_ERROR ( Status )) { + DEBUG (( DEBUG_ERROR, + "ERROR - Failed to return the interface info, Status: %r\r\n", + Status )); + break; + } + + // + // Display the current configuration + // + DEBUG (( DEBUG_BIND, + "Actual adapter IP address: %d.%d.%d.%d\r\n", + pIfInfo->StationAddress.Addr [ 0 ], + pIfInfo->StationAddress.Addr [ 1 ], + pIfInfo->StationAddress.Addr [ 2 ], + pIfInfo->StationAddress.Addr [ 3 ])); + + // + // Assume the port is not configured + // + Status = EFI_SUCCESS; + if (( pConfigData->StationAddress.Addr [ 0 ] == pIfInfo->StationAddress.Addr [ 0 ]) + && ( pConfigData->StationAddress.Addr [ 1 ] == pIfInfo->StationAddress.Addr [ 1 ]) + && ( pConfigData->StationAddress.Addr [ 2 ] == pIfInfo->StationAddress.Addr [ 2 ]) + && ( pConfigData->StationAddress.Addr [ 3 ] == pIfInfo->StationAddress.Addr [ 3 ])) { + break; + } + + // + // The IP address did not match + // + Status = EFI_NOT_STARTED; + break; + } + + // + // Free the buffer if necessary + // + if ( NULL != pIfInfo ) { + FreePool ( pIfInfo ); + } + + // + // Return the IP address status + // + DBG_EXIT_STATUS ( Status ); + return Status; +} + + /** Interface between the socket layer and the network specific code that supports SOCK_DGRAM sockets over UDPv4. @@ -1057,5 +1227,6 @@ CONST ESL_PROTOCOL_API cEslUdp4Api = { NULL, // RxStart EslUdp4TxBuffer, EslUdp4TxComplete, - NULL // TxOobComplete + NULL, // TxOobComplete + (PFN_API_VERIFY_LOCAL_IP_ADDRESS)EslUdp4VerifyLocalIpAddress };