]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
Code clean up in NetLib:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Impl.c
index 84a39656f6a10e3e92dc4d37edc0e13dec4f8170..05fd96d634cd98c2badf90b214265316fe543c65 100644 (file)
@@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "Ip4Impl.h"\r
 \r
+EFI_IPSEC_PROTOCOL    *mIpSec = NULL;\r
+\r
 /**\r
   Gets the current operational settings for this instance of the EFI IPv4 Protocol driver.\r
   \r
@@ -404,6 +406,8 @@ EfiIp4GetModeData (
     Ip4ModeData->RouteTable    = NULL;\r
     Ip4ModeData->RouteCount    = 0;\r
 \r
+    Ip4ModeData->MaxPacketSize = IpSb->MaxPacketSize;\r
+\r
     //\r
     // return the current station address for this IP child. So,\r
     // the user can get the default address through this. Some\r
@@ -557,6 +561,10 @@ Ip4AutoConfigCallBackDpc (
   EFI_STATUS                Status;\r
   UINTN                     Len;\r
   UINT32                    Index;\r
+  IP4_ADDR                  StationAddress;\r
+  IP4_ADDR                  SubnetMask;\r
+  IP4_ADDR                  SubnetAddress;\r
+  IP4_ADDR                  GatewayAddress;\r
 \r
   IpSb      = (IP4_SERVICE *) Context;\r
   NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE);\r
@@ -642,11 +650,9 @@ Ip4AutoConfigCallBackDpc (
   // Set the default interface's address, then add a directed\r
   // route for it, that is, the route whose nexthop is zero.\r
   //\r
-  Status = Ip4SetAddress (\r
-             IpIf,\r
-             EFI_NTOHL (Data->StationAddress),\r
-             EFI_NTOHL (Data->SubnetMask)\r
-             );\r
+  StationAddress = EFI_NTOHL (Data->StationAddress);\r
+  SubnetMask = EFI_NTOHL (Data->SubnetMask);\r
+  Status = Ip4SetAddress (IpIf, StationAddress, SubnetMask);\r
 \r
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
@@ -654,8 +660,8 @@ Ip4AutoConfigCallBackDpc (
 \r
   Ip4AddRoute (\r
     IpSb->DefaultRouteTable,\r
-    EFI_NTOHL (Data->StationAddress),\r
-    EFI_NTOHL (Data->SubnetMask),\r
+    StationAddress,\r
+    SubnetMask,\r
     IP4_ALLZERO_ADDRESS\r
     );\r
 \r
@@ -665,12 +671,10 @@ Ip4AutoConfigCallBackDpc (
   for (Index = 0; Index < Data->RouteTableSize; Index++) {\r
     RouteEntry = &Data->RouteTable[Index];\r
 \r
-    Ip4AddRoute (\r
-      IpSb->DefaultRouteTable,\r
-      EFI_NTOHL (RouteEntry->SubnetAddress),\r
-      EFI_NTOHL (RouteEntry->SubnetMask),\r
-      EFI_NTOHL (RouteEntry->GatewayAddress)\r
-      );\r
+    SubnetAddress = EFI_NTOHL (RouteEntry->SubnetAddress);\r
+    SubnetMask = EFI_NTOHL (RouteEntry->SubnetMask);\r
+    GatewayAddress = EFI_NTOHL (RouteEntry->GatewayAddress);\r
+    Ip4AddRoute (IpSb->DefaultRouteTable, SubnetAddress, SubnetMask, GatewayAddress);\r
   }\r
 \r
   IpSb->State = IP4_SERVICE_CONFIGED;\r
@@ -678,7 +682,7 @@ Ip4AutoConfigCallBackDpc (
   Ip4SetVariableData (IpSb);\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (Data);\r
+  FreePool (Data);\r
 }\r
 \r
 /**\r
@@ -703,7 +707,7 @@ Ip4AutoConfigCallBack (
   //\r
   // Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK\r
   //\r
-  NetLibQueueDpc (TPL_CALLBACK, Ip4AutoConfigCallBackDpc, Context);\r
+  QueueDpc (TPL_CALLBACK, Ip4AutoConfigCallBackDpc, Context);\r
 }\r
 \r
 \r
@@ -1041,13 +1045,13 @@ Ip4CleanProtocol (
   }\r
 \r
   if (IpInstance->EfiRouteTable != NULL) {\r
-    gBS->FreePool (IpInstance->EfiRouteTable);\r
+    FreePool (IpInstance->EfiRouteTable);\r
     IpInstance->EfiRouteTable = NULL;\r
     IpInstance->EfiRouteCount = 0;\r
   }\r
 \r
   if (IpInstance->Groups != NULL) {\r
-    gBS->FreePool (IpInstance->Groups);\r
+    FreePool (IpInstance->Groups);\r
     IpInstance->Groups      = NULL;\r
     IpInstance->GroupCount  = 0;\r
   }\r
@@ -1333,12 +1337,12 @@ Ip4Groups (
     }\r
 \r
     if (EFI_ERROR (Ip4JoinGroup (IpInstance, NTOHL (Group)))) {\r
-      gBS->FreePool (Members);\r
+      FreePool (Members);\r
       return EFI_DEVICE_ERROR;\r
     }\r
 \r
     if (IpInstance->Groups != NULL) {\r
-      gBS->FreePool (IpInstance->Groups);\r
+      FreePool (IpInstance->Groups);\r
     }\r
 \r
     IpInstance->Groups = Members;\r
@@ -1366,7 +1370,7 @@ Ip4Groups (
       if (IpInstance->GroupCount == 0) {\r
         ASSERT (Index == 1);\r
 \r
-        gBS->FreePool (IpInstance->Groups);\r
+        FreePool (IpInstance->Groups);\r
         IpInstance->Groups = NULL;\r
       }\r
 \r
@@ -1764,6 +1768,13 @@ Ip4FreeTxToken (
 \r
   Wrap = (IP4_TXTOKEN_WRAP *) Context;\r
 \r
+  //\r
+  // Signal IpSecRecycleEvent to inform IPsec free the memory\r
+  //\r
+  if (Wrap->IpSecRecycleSignal != NULL) {\r
+    gBS->SignalEvent (Wrap->IpSecRecycleSignal);\r
+  }\r
+\r
   //\r
   // Find the token in the instance's map. EfiIp4Transmit put the\r
   // token to the map. If that failed, NetMapFindKey will return NULL.\r
@@ -1780,10 +1791,10 @@ Ip4FreeTxToken (
     //\r
     // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r
     //\r
-    NetLibDispatchDpc ();\r
+    DispatchDpc ();\r
   }\r
 \r
-  gBS->FreePool (Wrap);\r
+  FreePool (Wrap);\r
 }\r
 \r
 \r
@@ -1947,12 +1958,12 @@ EfiIp4Transmit (
   }\r
 \r
   Head.Fragment = IP4_HEAD_FRAGMENT_FIELD (DontFragment, FALSE, 0);\r
-  HeadLen       = sizeof (IP4_HEAD) + ((TxData->OptionsLength + 3) &~0x03);\r
+  HeadLen       = (TxData->OptionsLength + 3) & (~0x03);\r
 \r
   //\r
   // If don't fragment and fragment needed, return error\r
   //\r
-  if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->SnpMode.MaxPacketSize)) {\r
+  if (DontFragment && (TxData->TotalDataLength + HeadLen > IpSb->MaxPacketSize)) {\r
     Status = EFI_BAD_BUFFER_SIZE;\r
     goto ON_EXIT;\r
   }\r
@@ -1962,7 +1973,7 @@ EfiIp4Transmit (
   // a IP4_TXTOKEN_WRAP and the data in a netbuf\r
   //\r
   Status = EFI_OUT_OF_RESOURCES;\r
-  Wrap   = AllocatePool (sizeof (IP4_TXTOKEN_WRAP));\r
+  Wrap   = AllocateZeroPool (sizeof (IP4_TXTOKEN_WRAP));\r
   if (Wrap == NULL) {\r
     goto ON_EXIT;\r
   }\r
@@ -1981,7 +1992,7 @@ EfiIp4Transmit (
                         );\r
 \r
   if (Wrap->Packet == NULL) {\r
-    gBS->FreePool (Wrap);\r
+    FreePool (Wrap);\r
     goto ON_EXIT;\r
   }\r
 \r
@@ -2110,7 +2121,7 @@ EfiIp4Receive (
   // Dispatch the DPC queued by the NotifyFunction of this instane's receive\r
   // event.\r
   //\r
-  NetLibDispatchDpc ();\r
+  DispatchDpc ();\r
 \r
 ON_EXIT:\r
   gBS->RestoreTPL (OldTpl);\r
@@ -2266,7 +2277,7 @@ Ip4Cancel (
   // Dispatch the DPCs queued by the NotifyFunction of the canceled rx token's\r
   // events.\r
   //\r
-  NetLibDispatchDpc ();\r
+  DispatchDpc ();\r
   if (EFI_ERROR (Status)) {\r
     if ((Token != NULL) && (Status == EFI_ABORTED)) {\r
       return EFI_SUCCESS;\r