From nobody Fri Dec 27 18:09:46 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1501050525514429.8461198719625; Tue, 25 Jul 2017 23:28:45 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AECA821D0B65B; Tue, 25 Jul 2017 23:26:38 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 116A621AEB0D9 for ; Tue, 25 Jul 2017 23:26:37 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP; 25 Jul 2017 23:28:39 -0700 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.131]) by orsmga003.jf.intel.com with ESMTP; 25 Jul 2017 23:28:37 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,413,1496127600"; d="scan'208";a="997280367" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Wed, 26 Jul 2017 14:28:30 +0800 Message-Id: <1501050511-16884-3-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1501050511-16884-1-git-send-email-jiaxin.wu@intel.com> References: <1501050511-16884-1-git-send-email-jiaxin.wu@intel.com> Subject: [edk2] [Patch 2/3] MdeModulePkg/Ip4Dxe: Support SetData interface to clear specific configuration X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" UEFI Spec 2.7 adds the clarification on SetData interface usage to clear sp= ecific individual data types. This patch is to support this feature. Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin --- .../Universal/Network/Ip4Dxe/Ip4Config2Impl.c | 285 ++++++++++++++---= ---- 1 file changed, 190 insertions(+), 95 deletions(-) diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c b/MdeMo= dulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c index 3e38085..26530e3 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Config2Impl.c @@ -1239,63 +1239,127 @@ Ip4Config2SetManualAddress ( EFI_STATUS Status; IP4_ADDR StationAddress; IP4_ADDR SubnetMask; VOID *Ptr; IP4_SERVICE *IpSb; + IP4_INTERFACE *IpIf; + IP4_ROUTE_TABLE *RouteTable; + + DataItem =3D NULL; + Status =3D EFI_SUCCESS; + Ptr =3D NULL; + IpIf =3D NULL; + RouteTable =3D NULL; =20 IpSb =3D IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); =20 ASSERT (Instance->DataItem[Ip4Config2DataTypeManualAddress].Status !=3D = EFI_NOT_READY); =20 - if (((DataSize % sizeof (EFI_IP4_CONFIG2_MANUAL_ADDRESS)) !=3D 0) || (Da= taSize =3D=3D 0)) { + if ((DataSize !=3D 0) && ((DataSize % sizeof (EFI_IP4_CONFIG2_MANUAL_ADD= RESS)) !=3D 0)) { return EFI_BAD_BUFFER_SIZE; } =20 if (Instance->Policy !=3D Ip4Config2PolicyStatic) { return EFI_WRITE_PROTECTED; } =20 - NewAddress =3D *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data); + DataItem =3D &Instance->DataItem[Ip4Config2DataTypeManualAddress]; =20 - StationAddress =3D EFI_NTOHL (NewAddress.Address); - SubnetMask =3D EFI_NTOHL (NewAddress.SubnetMask); + if (Data !=3D NULL && DataSize !=3D 0) { + NewAddress =3D *((EFI_IP4_CONFIG2_MANUAL_ADDRESS *) Data); =20 - // - // Check whether the StationAddress/SubnetMask pair is valid. - // - if (!Ip4StationAddressValid (StationAddress, SubnetMask)) { - return EFI_INVALID_PARAMETER; - } + StationAddress =3D EFI_NTOHL (NewAddress.Address); + SubnetMask =3D EFI_NTOHL (NewAddress.SubnetMask); =20 - // - // Store the new data, and init the DataItem status to EFI_NOT_READY bec= ause - // we may have an asynchronous configuration process. - // - Ptr =3D AllocateCopyPool (DataSize, Data); - if (Ptr =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } + // + // Check whether the StationAddress/SubnetMask pair is valid. + // + if (!Ip4StationAddressValid (StationAddress, SubnetMask)) { + return EFI_INVALID_PARAMETER; + } =20 - DataItem =3D &Instance->DataItem[Ip4Config2DataTypeManualAddress]; - if (DataItem->Data.Ptr !=3D NULL) { - FreePool (DataItem->Data.Ptr); - } - =20 - DataItem->Data.Ptr =3D Ptr; - DataItem->DataSize =3D DataSize; - DataItem->Status =3D EFI_NOT_READY; + // + // Store the new data, and init the DataItem status to EFI_NOT_READY b= ecause + // we may have an asynchronous configuration process. + // + Ptr =3D AllocateCopyPool (DataSize, Data); + if (Ptr =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } =20 - IpSb->Reconfig =3D TRUE; - Status =3D Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask); + if (DataItem->Data.Ptr !=3D NULL) { + FreePool (DataItem->Data.Ptr); + } + =20 + DataItem->Data.Ptr =3D Ptr; + DataItem->DataSize =3D DataSize; + DataItem->Status =3D EFI_NOT_READY; + + IpSb->Reconfig =3D TRUE; + Status =3D Ip4Config2SetDefaultAddr (IpSb, StationAddress, SubnetMask); =20 - DataItem->Status =3D Status;=20 + DataItem->Status =3D Status; =20 - if (EFI_ERROR (DataItem->Status) && DataItem->Status !=3D EFI_NOT_READY)= { - if (Ptr !=3D NULL) { - FreePool (Ptr); + if (EFI_ERROR (DataItem->Status) && DataItem->Status !=3D EFI_NOT_READ= Y) { + if (Ptr !=3D NULL) { + FreePool (Ptr); + } + DataItem->Data.Ptr =3D NULL;=20 + } + } else { + // + // DataSize is 0 and Data is NULL, clean up the manual address. + // + if (DataItem->Data.Ptr !=3D NULL) { + FreePool (DataItem->Data.Ptr); + } + DataItem->Data.Ptr =3D NULL; + DataItem->DataSize =3D 0; + DataItem->Status =3D EFI_NOT_FOUND; + + // + // Free the default router table and Interface, clean up the assemble = table. + // + if (IpSb->DefaultInterface !=3D NULL) { + if (IpSb->DefaultRouteTable !=3D NULL) { + Ip4FreeRouteTable (IpSb->DefaultRouteTable); + IpSb->DefaultRouteTable =3D NULL; =20 + } + + Ip4CancelReceive (IpSb->DefaultInterface); + + Ip4FreeInterface (IpSb->DefaultInterface, NULL); + IpSb->DefaultInterface =3D NULL; + } + + Ip4CleanAssembleTable (&IpSb->Assemble); + + // + // Create new default interface and route table. + // =20 + IpIf =3D Ip4CreateInterface (IpSb->Mnp, IpSb->Controller, IpSb->Image); + if (IpIf =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + RouteTable =3D Ip4CreateRouteTable (); + if (RouteTable =3D=3D NULL) { + Ip4FreeInterface (IpIf, NULL); + return EFI_OUT_OF_RESOURCES; + } + =20 + IpSb->DefaultInterface =3D IpIf; + InsertHeadList (&IpSb->Interfaces, &IpIf->Link); + IpSb->DefaultRouteTable =3D RouteTable; + Ip4ReceiveFrame (IpIf, NULL, Ip4AccpetFrame, IpSb); + + // + // Reset the State to unstarted.=20 + // + if (IpSb->State =3D=3D IP4_SERVICE_CONFIGED || IpSb->State =3D=3D IP4_= SERVICE_STARTED) { + IpSb->State =3D IP4_SERVICE_UNSTARTED; } - DataItem->Data.Ptr =3D NULL;=20 } =20 return Status; } =20 @@ -1340,98 +1404,114 @@ Ip4Config2SetGateway ( UINTN NewGatewayCount; BOOLEAN OneRemoved; BOOLEAN OneAdded; VOID *Tmp; =20 - if ((DataSize % sizeof (EFI_IPv4_ADDRESS) !=3D 0) || (DataSize =3D=3D 0)= ) { + OldGateway =3D NULL; + NewGateway =3D NULL; + OneRemoved =3D FALSE; + OneAdded =3D FALSE; + Tmp =3D NULL; + + if ((DataSize !=3D 0) && (DataSize % sizeof (EFI_IPv4_ADDRESS) !=3D 0)) { return EFI_BAD_BUFFER_SIZE; } =20 if (Instance->Policy !=3D Ip4Config2PolicyStatic) { return EFI_WRITE_PROTECTED; } =20 IpSb =3D IP4_SERVICE_FROM_IP4_CONFIG2_INSTANCE (Instance); =20 - NewGateway =3D (EFI_IPv4_ADDRESS *) Data; - NewGatewayCount =3D DataSize / sizeof (EFI_IPv4_ADDRESS); - for (Index1 =3D 0; Index1 < NewGatewayCount; Index1++) { - CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR)); - - if ((IpSb->DefaultInterface->SubnetMask !=3D 0) &&=20 - !NetIp4IsUnicast (NTOHL (Gateway), IpSb->DefaultInterface->SubnetM= ask)) { - return EFI_INVALID_PARAMETER; - } - - for (Index2 =3D Index1 + 1; Index2 < NewGatewayCount; Index2++) { - if (EFI_IP4_EQUAL (NewGateway + Index1, NewGateway + Index2)) { - return EFI_INVALID_PARAMETER; - } - } - } -=20 - DataItem =3D &Instance->DataItem[Ip4Config2DataTypeGateway]; + DataItem =3D &Instance->DataItem[Ip4Config2DataTypeGateway]; OldGateway =3D DataItem->Data.Gateway; OldGatewayCount =3D DataItem->DataSize / sizeof (EFI_IPv4_ADDRESS); - OneRemoved =3D FALSE; - OneAdded =3D FALSE; - - if (NewGatewayCount !=3D OldGatewayCount) { - Tmp =3D AllocatePool (DataSize); - if (Tmp =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - } else { - Tmp =3D NULL; - } =20 for (Index1 =3D 0; Index1 < OldGatewayCount; Index1++) { // - // Remove this route entry. + // Remove the old route entry. // CopyMem (&Gateway, OldGateway + Index1, sizeof (IP4_ADDR)); Ip4DelRoute ( IpSb->DefaultRouteTable, IP4_ALLZERO_ADDRESS, IP4_ALLZERO_ADDRESS, NTOHL (Gateway) ); OneRemoved =3D TRUE; - } =20 - for (Index1 =3D 0; Index1 < NewGatewayCount; Index1++) { - CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR)); - Ip4AddRoute ( - IpSb->DefaultRouteTable, - IP4_ALLZERO_ADDRESS, - IP4_ALLZERO_ADDRESS, - NTOHL (Gateway) - ); =20 - - OneAdded =3D TRUE; - } + if (Data !=3D NULL && DataSize !=3D 0) { + NewGateway =3D (EFI_IPv4_ADDRESS *) Data; + NewGatewayCount =3D DataSize / sizeof (EFI_IPv4_ADDRESS); + for (Index1 =3D 0; Index1 < NewGatewayCount; Index1++) { + CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR)); =20 + if ((IpSb->DefaultInterface->SubnetMask !=3D 0) &&=20 + !NetIp4IsUnicast (NTOHL (Gateway), IpSb->DefaultInterface->Subne= tMask)) { + return EFI_INVALID_PARAMETER; + } =20 - if (!OneRemoved && !OneAdded) { - DataItem->Status =3D EFI_SUCCESS; - return EFI_ABORTED; - } else { + for (Index2 =3D Index1 + 1; Index2 < NewGatewayCount; Index2++) { + if (EFI_IP4_EQUAL (NewGateway + Index1, NewGateway + Index2)) { + return EFI_INVALID_PARAMETER; + } + } + } =20 - if (Tmp !=3D NULL) { - if (DataItem->Data.Ptr !=3D NULL) { - FreePool (DataItem->Data.Ptr); + if (NewGatewayCount !=3D OldGatewayCount) { + Tmp =3D AllocatePool (DataSize); + if (Tmp =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; } - DataItem->Data.Ptr =3D Tmp; + } else { + Tmp =3D NULL; } =20 - CopyMem (DataItem->Data.Ptr, Data, DataSize); - DataItem->DataSize =3D DataSize; - DataItem->Status =3D EFI_SUCCESS; - return EFI_SUCCESS; + for (Index1 =3D 0; Index1 < NewGatewayCount; Index1++) { + // + // Add the new route entry. + // + CopyMem (&Gateway, NewGateway + Index1, sizeof (IP4_ADDR)); + Ip4AddRoute ( + IpSb->DefaultRouteTable, + IP4_ALLZERO_ADDRESS, + IP4_ALLZERO_ADDRESS, + NTOHL (Gateway) + ); =20 + + OneAdded =3D TRUE; + } + + if (!OneRemoved && !OneAdded) { + DataItem->Status =3D EFI_SUCCESS; + return EFI_ABORTED; + } else { + if (Tmp !=3D NULL) { + if (DataItem->Data.Ptr !=3D NULL) { + FreePool (DataItem->Data.Ptr); + } + DataItem->Data.Ptr =3D Tmp; + } + + CopyMem (DataItem->Data.Ptr, Data, DataSize); + DataItem->DataSize =3D DataSize; + DataItem->Status =3D EFI_SUCCESS; + } + } else { + // + // DataSize is 0 and Data is NULL, clean up the Gateway address. + // + if (DataItem->Data.Ptr !=3D NULL) { + FreePool (DataItem->Data.Ptr); + } + DataItem->Data.Ptr =3D NULL; + DataItem->DataSize =3D 0; + DataItem->Status =3D EFI_NOT_FOUND; } =20 + return EFI_SUCCESS; } =20 /** The work function is to set the DNS server list for the EFI IPv4 network=20 stack running on the communication device that this EFI_IP4_CONFIG2_PROT= OCOL=20 @@ -1459,13 +1539,15 @@ Ip4Config2SetDnsServer ( IN IP4_CONFIG2_INSTANCE *Instance, IN UINTN DataSize, IN VOID *Data ) { - IP4_CONFIG2_DATA_ITEM *Item; + EFI_STATUS Status; + IP4_CONFIG2_DATA_ITEM *Item; =20 - Item =3D NULL; + Status =3D EFI_SUCCESS; + Item =3D NULL; =20 if (Instance->Policy !=3D Ip4Config2PolicyStatic) { return EFI_WRITE_PROTECTED; } =20 @@ -1473,11 +1555,25 @@ Ip4Config2SetDnsServer ( =20 if (DATA_ATTRIB_SET (Item->Attribute, DATA_ATTRIB_VOLATILE)) { REMOVE_DATA_ATTRIB (Item->Attribute, DATA_ATTRIB_VOLATILE); } =20 - return Ip4Config2SetDnsServerWorker (Instance, DataSize, Data); + if (Data !=3D NULL && DataSize !=3D 0) { + Status =3D Ip4Config2SetDnsServerWorker (Instance, DataSize, Data); + } else { + // + // DataSize is 0 and Data is NULL, clean up the DnsServer address.=20 + // + if (Item->Data.Ptr !=3D NULL) { + FreePool (Item->Data.Ptr); + } + Item->Data.Ptr =3D NULL; + Item->DataSize =3D 0; + Item->Status =3D EFI_NOT_FOUND; + } + =20 + return Status; } =20 /** Generate the operational state of the interface this IP4 config2 instanc= e manages and output in EFI_IP4_CONFIG2_INTERFACE_INFO. @@ -1552,13 +1648,12 @@ Ip4Config2OnDhcp4Event ( =20 @retval EFI_SUCCESS The specified configuration data for the E= FI IPv6 network stack was set successfully. @retval EFI_INVALID_PARAMETER One or more of the following are TRUE: - This is NULL. - - Data is NULL. - - One or more fields in Data do not match = the requirement of the - data type indicated by DataType. + - One or more fields in Data and DataSize = do not match the=20 + requirement of the data type indicated b= y DataType. @retval EFI_WRITE_PROTECTED The specified configuration data is read-o= nly or the specified configuration data cannot be set under the= current policy. @retval EFI_ACCESS_DENIED Another set operation on the specified con= figuration data is already in process. @retval EFI_NOT_READY An asynchronous process was invoked to set= the specified @@ -1582,11 +1677,11 @@ EfiIp4Config2SetData ( EFI_TPL OldTpl; EFI_STATUS Status; IP4_CONFIG2_INSTANCE *Instance; IP4_SERVICE *IpSb; =20 - if ((This =3D=3D NULL) || (Data =3D=3D NULL)) { + if ((This =3D=3D NULL) || (Data =3D=3D NULL && DataSize !=3D 0) || (Data= !=3D NULL && DataSize =3D=3D 0)) { return EFI_INVALID_PARAMETER; } =20 if (DataType >=3D Ip4Config2DataTypeMaximum) { return EFI_UNSUPPORTED; --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel