]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.c
MdeModulePkg: Discard received broadcast message in DxeIpIoLib.
[mirror_edk2.git] / MdeModulePkg / Library / DxeIpIoLib / DxeIpIoLib.c
index cc93c2b89c01aaade9d1ef822348231d710acb18..abc07fb0ffa50bd968cb3e0ef20303b533e3e04f 100644 (file)
@@ -2,7 +2,7 @@
   IpIo Library.\r
 \r
 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
-Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 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
@@ -1028,43 +1028,65 @@ IpIoListenHandlerDpc (
   }\r
 \r
   if (IpIo->IpVersion == IP_VERSION_4) {\r
+    if (IP4_IS_LOCAL_BROADCAST (EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress))) {\r
+      //\r
+      // The source address is a broadcast address, discard it.\r
+      //\r
+      goto CleanUp;\r
+    }\r
     if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&\r
-      !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) {\r
+        (IpIo->SubnetMask != 0) &&\r
+        IP4_NET_EQUAL (IpIo->StationIp, EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), IpIo->SubnetMask) &&\r
+        !NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), IpIo->SubnetMask)) {\r
+      //\r
+      // The source address is not zero and it's not a unicast IP address, discard it.\r
+      //\r
+      goto CleanUp;\r
+    }\r
+\r
+    if (RxData->Ip4RxData.DataLength == 0) {\r
+      //\r
+      // Discard zero length data payload packet.\r
+      //\r
+      goto CleanUp;\r
+    }\r
+\r
     //\r
-    // The source address is not zero and it's not a unicast IP address, discard it.\r
+    // Create a netbuffer representing IPv4 packet\r
     //\r
-    goto CleanUp;\r
-  }\r
-\r
-  //\r
-  // Create a netbuffer representing IPv4 packet\r
-  //\r
-  Pkt = NetbufFromExt (\r
-          (NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,\r
-          RxData->Ip4RxData.FragmentCount,\r
-          0,\r
-          0,\r
-          IpIoExtFree,\r
-          RxData->Ip4RxData.RecycleSignal\r
-          );\r
-  if (NULL == Pkt) {\r
-    goto CleanUp;\r
-  }\r
+    Pkt = NetbufFromExt (\r
+            (NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,\r
+            RxData->Ip4RxData.FragmentCount,\r
+            0,\r
+            0,\r
+            IpIoExtFree,\r
+            RxData->Ip4RxData.RecycleSignal\r
+            );\r
+    if (NULL == Pkt) {\r
+      goto CleanUp;\r
+    }\r
 \r
-  //\r
-  // Create a net session\r
-  //\r
-  Session.Source.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress);\r
-  Session.Dest.Addr[0]   = EFI_IP4 (RxData->Ip4RxData.Header->DestinationAddress);\r
-  Session.IpHdr.Ip4Hdr   = RxData->Ip4RxData.Header;\r
-  Session.IpHdrLen       = RxData->Ip4RxData.HeaderLength;\r
-  Session.IpVersion      = IP_VERSION_4;\r
+    //\r
+    // Create a net session\r
+    //\r
+    Session.Source.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress);\r
+    Session.Dest.Addr[0]   = EFI_IP4 (RxData->Ip4RxData.Header->DestinationAddress);\r
+    Session.IpHdr.Ip4Hdr   = RxData->Ip4RxData.Header;\r
+    Session.IpHdrLen       = RxData->Ip4RxData.HeaderLength;\r
+    Session.IpVersion      = IP_VERSION_4;\r
   } else {\r
 \r
     if (!NetIp6IsValidUnicast(&RxData->Ip6RxData.Header->SourceAddress)) {\r
       goto CleanUp;\r
     }\r
     \r
+    if (RxData->Ip6RxData.DataLength == 0) {\r
+      //\r
+      // Discard zero length data payload packet.\r
+      //\r
+      goto CleanUp;\r
+    }\r
+    \r
     //\r
     // Create a netbuffer representing IPv6 packet\r
     //\r
@@ -1279,6 +1301,19 @@ IpIoOpen (
   // configure ip\r
   //\r
   if (IpVersion == IP_VERSION_4){\r
+    //\r
+    // RawData mode is no supported.\r
+    //\r
+    ASSERT (!OpenData->IpConfigData.Ip4CfgData.RawData);\r
+    if (OpenData->IpConfigData.Ip4CfgData.RawData) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+\r
+    if (!OpenData->IpConfigData.Ip4CfgData.UseDefaultAddress) {\r
+      IpIo->StationIp = EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.StationAddress);\r
+      IpIo->SubnetMask = EFI_NTOHL (OpenData->IpConfigData.Ip4CfgData.SubnetMask);\r
+    }\r
+    \r
     Status = IpIo->Ip.Ip4->Configure (\r
                              IpIo->Ip.Ip4,\r
                              &OpenData->IpConfigData.Ip4CfgData\r
@@ -1417,7 +1452,7 @@ IpIoStop (
   }\r
 \r
   //\r
-  // All pending send tokens should be flushed by reseting the IP instances.\r
+  // All pending send tokens should be flushed by resetting the IP instances.\r
   //\r
   ASSERT (IsListEmpty (&IpIo->PendingSndList));\r
 \r