]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcImpl.c
MdeModulePkg: Update IP4 stack drivers for classless address unicast check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcImpl.c
index 72923f1b38a4641aee6e6569995118c4c6303d69..4746256fa0fcf1676df321d8e9a2faec585b83da 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Interface routines for PxeBc.\r
 \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -176,7 +176,9 @@ IcmpErrorListenHandlerDpc (
   }\r
 \r
   if (EFI_IP4 (RxData->Header->SourceAddress) != 0 &&\r
-      !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), 0)) {\r
+      (NTOHL (Mode->SubnetMask.Addr[0]) != 0) &&\r
+      IP4_NET_EQUAL (NTOHL(Mode->StationIp.Addr[0]), EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0])) &&\r
+      !NetIp4IsUnicast (EFI_NTOHL (RxData->Header->SourceAddress), NTOHL (Mode->SubnetMask.Addr[0]))) {\r
     //\r
     // The source address is not zero and it's not a unicast IP address, discard it.\r
     //\r
@@ -1163,7 +1165,9 @@ EfiPxeBcMtftp (
   if ((This == NULL)                                                          ||\r
       (Filename == NULL)                                                      ||\r
       (BufferSize == NULL)                                                    ||\r
-      ((ServerIp == NULL) || !NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 0)) ||\r
+      ((ServerIp == NULL) || \r
+       (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) || \r
+        IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0]))))                  ||\r
       ((BufferPtr == NULL) && DontUseBuffer)                                  ||\r
       ((BlockSize != NULL) && (*BlockSize < 512))) {\r
 \r
@@ -1378,7 +1382,7 @@ EfiPxeBcUdpWrite (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if ((GatewayIp != NULL) && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) {\r
+  if ((GatewayIp != NULL) && (IP4_IS_UNSPECIFIED (NTOHL (GatewayIp->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (GatewayIp->Addr[0])))) {\r
     //\r
     // Gateway is provided but it's not a unicast IP address.\r
     //\r
@@ -1435,7 +1439,9 @@ EfiPxeBcUdpWrite (
              &Private->StationIp.v4,\r
              &Private->SubnetMask.v4,\r
              &Private->GatewayIp.v4,\r
-             &Private->CurrentUdpSrcPort\r
+             &Private->CurrentUdpSrcPort,\r
+             Private->Mode.TTL,\r
+             Private->Mode.ToS\r
              );\r
   if (EFI_ERROR (Status)) {\r
     Private->CurrentUdpSrcPort = 0;\r
@@ -1962,9 +1968,11 @@ EfiPxeBcSetIpFilter (
       DEBUG ((EFI_D_ERROR, "There is broadcast address in NewFilter.\n"));\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-    if (NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) &&\r
-        ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)\r
-       ) {\r
+    if ((EFI_NTOHL(Mode->StationIp) != 0) &&\r
+        (EFI_NTOHL(Mode->SubnetMask) != 0) &&\r
+        IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r
+        NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&\r
+        ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)) {\r
       //\r
       // If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IP4 address is in IpList,\r
       // promiscuous mode is needed.\r
@@ -2306,11 +2314,11 @@ EfiPxeBcSetStationIP (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (NewStationIp != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0)) {\r
+  if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-\r
-  if (NewSubnetMask != NULL && !IP4_IS_VALID_NETMASK (NTOHL (NewSubnetMask->Addr[0]))) {\r
+  \r
+  if (NewStationIp != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0]))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -2902,9 +2910,14 @@ EfiPxeLoadFile (
   //\r
   if (Status == EFI_SUCCESS) {\r
     //\r
+    // The DHCP4 can have only one configured child instance so we need to stop\r
+    // reset the DHCP4 child before we return. Otherwise the other programs which \r
+    // also need to use DHCP4 will be impacted.\r
     // The functionality of PXE Base Code protocol will not be stopped,\r
     // when downloading is successfully.\r
     //\r
+    Private->Dhcp4->Stop (Private->Dhcp4);\r
+    Private->Dhcp4->Configure (Private->Dhcp4, NULL);\r
     return EFI_SUCCESS;\r
 \r
   } else if (Status == EFI_BUFFER_TOO_SMALL) {\r