diff --git a/MdeModulePkg/Include/Library/UdpIoLib.h b/MdeModulePkg/Include/Library/UdpIoLib.h index e0b44ce18e..9bfa80e143 100644 --- a/MdeModulePkg/Include/Library/UdpIoLib.h +++ b/MdeModulePkg/Include/Library/UdpIoLib.h @@ -2,7 +2,7 @@ This library is used to share code between UEFI network stack modules. It provides the helper routines to access UDP service. It is used by both DHCP and MTFTP. -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, 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
@@ -197,7 +197,9 @@ BOOLEAN /** Cancel all the sent datagram that pass the selection criteria of ToCancel. + If ToCancel is NULL, all the datagrams are cancelled. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). @param[in] UdpIo The UDP_IO to cancel packet. @param[in] IoStatus The IoStatus to return to the packet owners. @@ -212,13 +214,16 @@ UdpIoCancelDgrams ( IN UDP_IO *UdpIo, IN EFI_STATUS IoStatus, IN UDP_IO_TO_CANCEL ToCancel, OPTIONAL - IN VOID *Context + IN VOID *Context OPTIONAL ); /** Creates a UDP_IO to access the UDP service. It creates and configures a UDP child. + If Configure is NULL, then ASSERT(). + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + It locates the UDP service binding prototype on the Controller parameter uses the UDP service binding prototype to create a UDP child (also known as a UDP instance) configures the UDP child by calling Configure function prototype. @@ -247,11 +252,14 @@ UdpIoCreateIo ( /** Free the UDP_IO and all its related resources. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + The function cancels all sent datagrams and receive requests. @param[in] UdpIo The UDP_IO to free. @retval EFI_SUCCESS The UDP_IO is freed. + @retval Others Failed to free UDP_IO. **/ EFI_STATUS @@ -264,6 +272,8 @@ UdpIoFreeIo ( Cleans up the UDP_IO without freeing it. Call this function if you intend to later re-use the UDP_IO. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + This function releases all transmitted datagrams and receive requests and configures NULL for the UDP instance. @param[in] UdpIo The UDP_IO to clean up. @@ -278,6 +288,8 @@ UdpIoCleanIo ( /** Send a packet through the UDP_IO. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be called when the packet is sent. The optional parameter EndPoint overrides the default address pair if specified. @@ -324,6 +336,8 @@ UdpIoCancelSentDatagram ( /** Issue a receive request to the UDP_IO. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + This function is called when upper-layer needs packet from UDP for processing. Only one receive request is acceptable at a time. Therefore, one common usage model is to invoke this function inside its Callback function when the former packet diff --git a/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c b/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c index 4861095435..d8edfe19f5 100644 --- a/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c +++ b/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c @@ -1,7 +1,7 @@ /** @file Help functions to access UDP service, it is used by both the DHCP and MTFTP. -Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2018, 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
@@ -410,6 +410,9 @@ UdpIoCreateRxToken ( /** Wrap a transmit request into a new created UDP_TX_TOKEN. + If Packet is NULL, then ASSERT(). + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + @param[in] UdpIo The UdpIo to send packet to. @param[in] Packet The user's packet. @param[in] EndPoint The local and remote access point. @@ -580,6 +583,9 @@ UdpIoCreateTxToken ( Creates a UDP_IO to access the UDP service. It creates and configures a UDP child. + If Configure is NULL, then ASSERT(). + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + It locates the UDP service binding prototype on the Controller parameter uses the UDP service binding prototype to create a UDP child (also known as a UDP instance) configures the UDP child by calling Configure function prototype. @@ -749,7 +755,9 @@ FREE_MEM: /** Cancel all the sent datagram that pass the selection criteria of ToCancel. + If ToCancel is NULL, all the datagrams are cancelled. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). @param[in] UdpIo The UDP_IO to cancel packet. @param[in] IoStatus The IoStatus to return to the packet owners. @@ -764,7 +772,7 @@ UdpIoCancelDgrams ( IN UDP_IO *UdpIo, IN EFI_STATUS IoStatus, IN UDP_IO_TO_CANCEL ToCancel, OPTIONAL - IN VOID *Context + IN VOID *Context OPTIONAL ) { LIST_ENTRY *Entry; @@ -791,11 +799,14 @@ UdpIoCancelDgrams ( /** Free the UDP_IO and all its related resources. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + The function will cancel all sent datagram and receive request. @param[in] UdpIo The UDP_IO to free. @retval EFI_SUCCESS The UDP_IO is freed. + @retval Others Failed to free UDP_IO. **/ EFI_STATUS @@ -804,6 +815,7 @@ UdpIoFreeIo ( IN UDP_IO *UdpIo ) { + EFI_STATUS Status; UDP_RX_TOKEN *RxToken; ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) || @@ -822,50 +834,68 @@ UdpIoFreeIo ( if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) { if ((RxToken = UdpIo->RecvRequest) != NULL) { - UdpIo->Protocol.Udp4->Cancel (UdpIo->Protocol.Udp4, &RxToken->Token.Udp4); + Status = UdpIo->Protocol.Udp4->Cancel (UdpIo->Protocol.Udp4, &RxToken->Token.Udp4); + if (EFI_ERROR (Status)) { + return Status; + } } // // Close then destroy the Udp4 child // - gBS->CloseProtocol ( - UdpIo->UdpHandle, - &gEfiUdp4ProtocolGuid, - UdpIo->Image, - UdpIo->Controller - ); + Status = gBS->CloseProtocol ( + UdpIo->UdpHandle, + &gEfiUdp4ProtocolGuid, + UdpIo->Image, + UdpIo->Controller + ); + if (EFI_ERROR (Status)) { + return Status; + } - NetLibDestroyServiceChild ( - UdpIo->Controller, - UdpIo->Image, - &gEfiUdp4ServiceBindingProtocolGuid, - UdpIo->UdpHandle - ); + Status = NetLibDestroyServiceChild ( + UdpIo->Controller, + UdpIo->Image, + &gEfiUdp4ServiceBindingProtocolGuid, + UdpIo->UdpHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } } else { if ((RxToken = UdpIo->RecvRequest) != NULL) { - UdpIo->Protocol.Udp6->Cancel (UdpIo->Protocol.Udp6, &RxToken->Token.Udp6); + Status = UdpIo->Protocol.Udp6->Cancel (UdpIo->Protocol.Udp6, &RxToken->Token.Udp6); + if (EFI_ERROR (Status)) { + return Status; + } } // // Close then destroy the Udp6 child // - gBS->CloseProtocol ( - UdpIo->UdpHandle, - &gEfiUdp6ProtocolGuid, - UdpIo->Image, - UdpIo->Controller - ); - - NetLibDestroyServiceChild ( - UdpIo->Controller, - UdpIo->Image, - &gEfiUdp6ServiceBindingProtocolGuid, - UdpIo->UdpHandle - ); + Status = gBS->CloseProtocol ( + UdpIo->UdpHandle, + &gEfiUdp6ProtocolGuid, + UdpIo->Image, + UdpIo->Controller + ); + if (EFI_ERROR (Status)) { + return Status; } + Status = NetLibDestroyServiceChild ( + UdpIo->Controller, + UdpIo->Image, + &gEfiUdp6ServiceBindingProtocolGuid, + UdpIo->UdpHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + if (!IsListEmpty(&UdpIo->Link)) { RemoveEntryList (&UdpIo->Link); } @@ -879,6 +909,8 @@ UdpIoFreeIo ( Clean up the UDP_IO without freeing it. The function is called when user wants to re-use the UDP_IO later. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + It will release all the transmitted datagrams and receive request. It will also configure NULL for the UDP instance. @@ -920,6 +952,8 @@ UdpIoCleanIo ( /** Send a packet through the UDP_IO. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be called when the packet is sent. The optional parameter EndPoint overrides the default address pair if specified. @@ -1030,6 +1064,8 @@ UdpIoCancelSentDatagram ( /** Issue a receive request to the UDP_IO. + If Udp version is not UDP_IO_UDP4_VERSION or UDP_IO_UDP6_VERSION, then ASSERT(). + This function is called when upper-layer needs packet from UDP for processing. Only one receive request is acceptable at a time so a common usage model is to invoke this function inside its Callback function when the former packet