]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Add Link MTU support to IP4 and TCP4 driver.
authortye <tye@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 11 Nov 2009 07:06:27 +0000 (07:06 +0000)
committertye <tye@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 11 Nov 2009 07:06:27 +0000 (07:06 +0000)
2. Integrate IPsec functionality to IP4 driver.
3. Move IP_VERSION_4/IP_VERSION_6 definition from IpIoLib to NetLib.
4. Move the Ip6/Udp6 protocol declaration from driver INF to Library INF (DxeIpIoLib and DxeUdpIoLib) for better readability.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9413 6f19259b-4bc3-4df7-8a09-765794883524

17 files changed:
MdeModulePkg/Include/Library/IpIoLib.h
MdeModulePkg/Include/Library/NetLib.h
MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf
MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.h
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.h
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Output.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Output.h
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf

index 14f6884d1530cd145c66f3fcb08def14b9f9adf4..e079fe1f795aef4e1c323c96dba2fd786b0db94b 100644 (file)
@@ -81,8 +81,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 extern EFI_IP4_CONFIG_DATA  mIp4IoDefaultIpConfigData;\r
 extern EFI_IP6_CONFIG_DATA  mIp6IoDefaultIpConfigData;\r
 \r
-#define IP_VERSION_4 4\r
-#define IP_VERSION_6 6\r
 \r
 ///\r
 /// This error will be delivered to the\r
index 07bf2cbc9f568eba2e00f63e6c097963463935df..2eab4a33295c8355c7b275ae36ce3e2f85c2f552 100644 (file)
@@ -51,6 +51,8 @@ typedef UINT16          TCP_PORTNO;
 #define  IP6_ESP               50\r
 #define  IP6_NO_NEXT_HEADER    59\r
 \r
+#define  IP_VERSION_4          4\r
+#define  IP_VERSION_6          6\r
 \r
 #pragma pack(1)\r
 \r
index 1e83b67df77f4373aae1af9ddaebe55cc1cc6f61..133aad775b18453d6547106e92a9f072652b5153 100644 (file)
@@ -4,7 +4,7 @@
   This module provides IP services by consuming EFI IP4 Service Binding Protocol and\r
   EFI IP4 Protocol.\r
 \r
-Copyright (c) 2006, Intel Corporation.<BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -46,3 +46,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   MemoryAllocationLib\r
   BaseMemoryLib\r
   DpcLib\r
+\r
+[Protocols]\r
+  gEfiIp4ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIp4ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIp6ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIp6ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
+\r
index 1a6115615d9fddf55ec13c1f56231b9885a41922..a1da076f18047482f17577c4174a9b95432e9d3b 100644 (file)
@@ -4,7 +4,7 @@
   This module provides UDP services by consuming EFI UDP4 Service Binding Protocol and\r
   EFI UDP4 Protocol.\r
   \r
-Copyright (c) 2008, Intel Corporation.<BR>\r
+Copyright (c) 2008 - 2009, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -50,3 +50,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 [Protocols]\r
   gEfiUdp4ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
   gEfiUdp4ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiUdp6ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiUdp6ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
+  \r
index 44c9d84bdbfcea792637a5130be955a966e3c386..f95dfed5acea594b285cc6f707f3da710b35a289 100644 (file)
@@ -1,7 +1,7 @@
 #/** @file\r
 # Component name for module Dhcp4\r
 #\r
-# Copyright (c) 2007 - 2009, Intel Corporation\r
+# Copyright (c) 2007, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -63,6 +63,4 @@
   gEfiDhcp4ServiceBindingProtocolGuid           # PROTOCOL ALWAYS_CONSUMED\r
   gEfiUdp4ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
   gEfiDhcp4ProtocolGuid                         # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiUdp6ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiUdp6ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
 \r
index 7a0f18af28c7684e3ab7b4f4fa045d83ec0f4e70..79c5bae0f3491d7b5ef02c5802f3c449de6b2cf2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The driver binding and service binding protocol for IP4 driver.\r
   \r
-Copyright (c) 2005 - 2006, Intel Corporation.<BR>\r
+Copyright (c) 2005 - 2009, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -290,6 +290,7 @@ Ip4CreateService (
 \r
   InsertHeadList (&IpSb->Interfaces, &IpSb->DefaultInterface->Link);\r
 \r
+  IpSb->MaxPacketSize = IpSb->SnpMode.MaxPacketSize - sizeof (IP4_HEAD);\r
   IpSb->MacString = NULL;\r
 \r
   *Service = IpSb;\r
index 121fb17b77764095e7388dd484c77c17f18a6172..0d0ea9146d4cb7df2e751c7f2ed976fb16361c52 100644 (file)
@@ -1,7 +1,7 @@
 #/** @file\r
 # Component name for module Ip4\r
 #\r
-# Copyright (c) 2007, Intel Corporation\r
+# Copyright (c) 2007 - 2009, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -80,3 +80,5 @@
   gEfiIp4ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
   gEfiManagedNetworkProtocolGuid                # PROTOCOL ALWAYS_CONSUMED\r
   gEfiArpProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiIpSecProtocolGuid\r
+  
\ No newline at end of file
index 4788d403fe0836f639164d5888787e928c443aeb..bb5b0ef1103814dd2c90708454f457270c1c11bf 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
@@ -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
@@ -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
index 8b2e286f0c364adc314cd9b4950347a8428b620c..43d6765add8910f7a84bf0e3a6c941f98e52f39c 100644 (file)
@@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Uefi.h>\r
 \r
+#include <Protocol/IpSec.h>\r
 #include <Protocol/Ip4.h>\r
 #include <Protocol/Ip4Config.h>\r
 #include <Protocol/Arp.h>\r
@@ -80,11 +81,23 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 typedef struct {\r
   IP4_PROTOCOL              *IpInstance;\r
   EFI_IP4_COMPLETION_TOKEN  *Token;\r
+  EFI_EVENT                 IpSecRecycleSignal;\r
   NET_BUF                   *Packet;\r
   BOOLEAN                   Sent;\r
   INTN                      Life;\r
 } IP4_TXTOKEN_WRAP;\r
 \r
+///\r
+/// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet\r
+/// will be released after it has been processed by the receiver. Upon then,\r
+/// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled\r
+/// to notice IPsec to free the resources.\r
+///\r
+typedef struct {\r
+  EFI_EVENT                 IpSecRecycleSignal;\r
+  NET_BUF                   *Packet;\r
+} IP4_IPSEC_WRAP;\r
+\r
 ///\r
 /// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the\r
 /// upper layers. The received packet is kept in the Packet.\r
@@ -110,7 +123,7 @@ struct _IP4_PROTOCOL {
   INTN                      State;\r
 \r
   IP4_SERVICE               *Service;\r
-  LIST_ENTRY                Link; // Link to all the IP protocol from the service\r
+  LIST_ENTRY                Link;       // Link to all the IP protocol from the service\r
 \r
   //\r
   // User's transmit/receive tokens, and received/deliverd packets\r
@@ -136,7 +149,7 @@ struct _IP4_PROTOCOL {
   //\r
   // IGMP data for this instance\r
   //\r
-  IP4_ADDR                  *Groups;  // stored in network byte order\r
+  IP4_ADDR                  *Groups;    // stored in network byte order\r
   UINT32                    GroupCount;\r
 \r
   EFI_IP4_CONFIG_DATA       ConfigData;\r
@@ -194,6 +207,8 @@ struct _IP4_SERVICE {
   // NIC this IP4_SERVICE works on.\r
   //\r
   CHAR16                          *MacString;\r
+  UINT32                          MaxPacketSize;\r
+  UINT32                          OldMaxPacketSize; ///< The MTU before IPsec enable.\r
 };\r
 \r
 #define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \\r
@@ -335,4 +350,33 @@ Ip4SentPacketTicking (
   IN NET_MAP_ITEM           *Item,\r
   IN VOID                   *Context\r
   );\r
+\r
+/**\r
+  The callback function for the net buffer which wraps the user's\r
+  transmit token. Although it seems this function is pretty simple,\r
+  there are some subtle things.\r
+  When user requests the IP to transmit a packet by passing it a\r
+  token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r
+  is wrapped in an net buffer. the net buffer's Free function is\r
+  set to Ip4FreeTxToken. The Token and token wrap are added to the\r
+  IP child's TxToken map. Then the buffer is passed to Ip4Output for\r
+  transmission. If something error happened before that, the buffer\r
+  is freed, which in turn will free the token wrap. The wrap may\r
+  have been added to the TxToken map or not, and the user's event\r
+  shouldn't be fired because we are still in the EfiIp4Transmit. If\r
+  the buffer has been sent by Ip4Output, it should be removed from\r
+  the TxToken map and user's event signaled. The token wrap and buffer\r
+  are bound together. Check the comments in Ip4Output for information\r
+  about IP fragmentation.\r
+\r
+  @param[in]  Context                The token's wrap\r
+\r
+**/\r
+VOID\r
+Ip4FreeTxToken (\r
+  IN VOID                   *Context\r
+  );\r
+\r
+extern EFI_IPSEC_PROTOCOL   *mIpSec;\r
+\r
 #endif\r
index 725735330129ae820cea598dc5077dde3f07f4da..779dd496a5a55e32e842f5736885d8647673893c 100644 (file)
@@ -429,6 +429,219 @@ DROP:
   return NULL;\r
 }\r
 \r
+/**\r
+  The callback function for the net buffer which wraps the packet processed by \r
+  IPsec. It releases the wrap packet and also signals IPsec to free the resources. \r
+\r
+  @param[in]  Arg       The wrap context\r
+\r
+**/\r
+VOID\r
+Ip4IpSecFree (\r
+  IN VOID                   *Arg\r
+  )\r
+{\r
+  IP4_IPSEC_WRAP            *Wrap;\r
+\r
+  Wrap = (IP4_IPSEC_WRAP *) Arg;\r
+\r
+  if (Wrap->IpSecRecycleSignal != NULL) {\r
+    gBS->SignalEvent (Wrap->IpSecRecycleSignal);\r
+  }\r
+\r
+  NetbufFree (Wrap->Packet);\r
+\r
+  FreePool (Wrap);\r
+\r
+  return;\r
+}\r
+\r
+/**\r
+  The work function to locate IPsec protocol to process the inbound or \r
+  outbound IP packets. The process routine handls the packet with following\r
+  actions: bypass the packet, discard the packet, or protect the packet.       \r
+\r
+  @param[in]       IpSb          The IP4 service instance\r
+  @param[in]       Head          The The caller supplied IP4 header.\r
+  @param[in, out]  Netbuf        The IP4 packet to be processed by IPsec\r
+  @param[in]       Options       The caller supplied options\r
+  @param[in]       OptionsLen    The length of the option\r
+  @param[in]       Direction     The directionality in an SPD entry, \r
+                                 EfiIPsecInBound or EfiIPsecOutBound\r
+  @param[in]       Context       The token's wrap\r
+\r
+  @retval EFI_SUCCESS            The IPsec protocol is not available or disabled.\r
+  @retval EFI_SUCCESS            The packet was bypassed and all buffers remain the same.\r
+  @retval EFI_SUCCESS            The packet was protected.\r
+  @retval EFI_ACCESS_DENIED      The packet was discarded.  \r
+  @retval EFI_OUT_OF_RESOURCES   There is no suffcient resource to complete the operation.\r
+  @retval EFI_BUFFER_TOO_SMALL   The number of non-empty block is bigger than the \r
+                                 number of input data blocks when build a fragment table.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip4IpSecProcessPacket (\r
+  IN IP4_SERVICE            *IpSb,\r
+  IN IP4_HEAD               *Head,\r
+  IN OUT NET_BUF            **Netbuf,\r
+  IN UINT8                  *Options,\r
+  IN UINT32                 OptionsLen,\r
+  IN EFI_IPSEC_TRAFFIC_DIR  Direction,\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  NET_FRAGMENT              *FragmentTable;\r
+  UINT32                    FragmentCount;\r
+  EFI_EVENT                 RecycleEvent;\r
+  NET_BUF                   *Packet;\r
+  IP4_TXTOKEN_WRAP          *TxWrap;\r
+  IP4_IPSEC_WRAP            *IpSecWrap;\r
+  EFI_STATUS                Status;\r
+\r
+  Status        = EFI_SUCCESS;\r
+  Packet        = *Netbuf;\r
+  RecycleEvent  = NULL;\r
+  IpSecWrap     = NULL;\r
+  FragmentTable = NULL;\r
+  TxWrap        = (IP4_TXTOKEN_WRAP *) Context; \r
+  FragmentCount = Packet->BlockOpNum;\r
+  \r
+  if (mIpSec == NULL) {\r
+    gBS->LocateProtocol (&gEfiIpSecProtocolGuid, NULL, (VOID **) &mIpSec);\r
+    if (mIpSec != NULL) {\r
+      //\r
+      // Save the original MTU\r
+      //\r
+      IpSb->OldMaxPacketSize = IpSb->MaxPacketSize; \r
+    }\r
+  }\r
+\r
+  //\r
+  // Check whether the IPsec protocol is available.\r
+  //\r
+  if (mIpSec == NULL) {\r
+    goto ON_EXIT;\r
+  }\r
+  //\r
+  // Check whether the IPsec enable variable is set.\r
+  //\r
+  if (mIpSec->DisabledFlag) {\r
+    //\r
+    // If IPsec is disabled, restore the original MTU\r
+    //   \r
+    IpSb->MaxPacketSize = IpSb->OldMaxPacketSize;\r
+    goto ON_EXIT;\r
+  } else {\r
+    //\r
+    // If IPsec is enabled, use the MTU which reduce the IPsec header length.  \r
+    //\r
+    IpSb->MaxPacketSize = IpSb->OldMaxPacketSize - IP4_MAX_IPSEC_HEADLEN;   \r
+  }\r
+\r
+  //\r
+  // Rebuild fragment table from netbuf to ease IPsec process.\r
+  //\r
+  FragmentTable = AllocateZeroPool (FragmentCount * sizeof (NET_FRAGMENT));\r
+\r
+  if (FragmentTable == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_EXIT;\r
+  }\r
\r
+  Status = NetbufBuildExt (Packet, FragmentTable, &FragmentCount);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (FragmentTable);\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  //\r
+  // Convert host byte order to network byte order\r
+  //\r
+  Ip4NtohHead (Head);\r
+  \r
+  Status = mIpSec->Process (\r
+                     mIpSec,\r
+                     IpSb->Controller,\r
+                     IP_VERSION_4,\r
+                     (VOID *) Head,\r
+                     &Head->Protocol,\r
+                     NULL,\r
+                     0,\r
+                     (EFI_IPSEC_FRAGMENT_DATA **) (&FragmentTable),\r
+                     &FragmentCount,\r
+                     Direction,\r
+                     &RecycleEvent\r
+                     );\r
+  //\r
+  // Convert back to host byte order\r
+  //\r
+  Ip4NtohHead (Head);\r
+  \r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (Direction == EfiIPsecOutBound && TxWrap != NULL) {\r
+  \r
+    TxWrap->IpSecRecycleSignal = RecycleEvent;\r
+    TxWrap->Packet             = NetbufFromExt (\r
+                                   FragmentTable,\r
+                                   FragmentCount,\r
+                                   IP4_MAX_HEADLEN,\r
+                                   0,\r
+                                   Ip4FreeTxToken,\r
+                                   TxWrap\r
+                                   );\r
+    if (TxWrap->Packet == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto ON_EXIT;\r
+    }\r
+\r
+    *Netbuf = TxWrap->Packet;\r
+    \r
+  } else {\r
+  \r
+    IpSecWrap = AllocateZeroPool (sizeof (IP4_IPSEC_WRAP));\r
+  \r
+    if (IpSecWrap == NULL) {\r
+      goto ON_EXIT;\r
+    }\r
+    \r
+    IpSecWrap->IpSecRecycleSignal = RecycleEvent;\r
+    IpSecWrap->Packet             = Packet;\r
+    Packet                        = NetbufFromExt (\r
+                                      FragmentTable, \r
+                                      FragmentCount, \r
+                                      IP4_MAX_HEADLEN, \r
+                                      0, \r
+                                      Ip4IpSecFree, \r
+                                      IpSecWrap\r
+                                      );\r
+  \r
+    if (Packet == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto ON_EXIT;\r
+    }\r
+\r
+    if (Direction == EfiIPsecInBound) {\r
+      Ip4PrependHead (Packet, Head, Options, OptionsLen);\r
+      Ip4NtohHead (Packet->Ip.Ip4);\r
+      NetbufTrim (Packet, (Head->HeadLen << 2), TRUE);\r
+\r
+      CopyMem (\r
+        IP4_GET_CLIP_INFO (Packet),\r
+        IP4_GET_CLIP_INFO (IpSecWrap->Packet),\r
+        sizeof (IP4_CLIP_INFO)\r
+        );\r
+    }\r
+\r
+    *Netbuf = Packet;\r
+  }\r
+\r
+ON_EXIT:\r
+  return Status;\r
+}\r
 \r
 /**\r
   The IP4 input routine. It is called by the IP4_INTERFACE when a\r
@@ -459,6 +672,7 @@ Ip4AccpetFrame (
   UINT32                    OptionLen;\r
   UINT32                    TotalLen;\r
   UINT16                    Checksum;\r
+  EFI_STATUS                Status;\r
 \r
   IpSb = (IP4_SERVICE *) Context;\r
 \r
@@ -566,6 +780,22 @@ Ip4AccpetFrame (
   }\r
 \r
   //\r
+  // After trim off, the packet is a esp/ah/udp/tcp/icmp6 net buffer,\r
+  // and no need consider any other ahead ext headers.\r
+  //\r
+  Status = Ip4IpSecProcessPacket (\r
+             IpSb, \r
+             Head, \r
+             &Packet, \r
+             NULL,\r
+             0, \r
+             EfiIPsecInBound,\r
+             NULL\r
+             );\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    goto RESTART;\r
+  }\r
   // Packet may have been changed. Head, HeadLen, TotalLen, and\r
   // info must be reloaded bofore use. The ownership of the packet\r
   // is transfered to the packet process logic.\r
index cd1367b01251c97173f101956c918f557a949671..ceffece8fbdbf563867cc5e442edae5d3f4ee7c1 100644 (file)
@@ -16,6 +16,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define IP4_MIN_HEADLEN        20\r
 #define IP4_MAX_HEADLEN        60\r
+///\r
+/// 8(ESP header) + 16(max IV) + 16(max padding) + 2(ESP tail) + 12(max ICV) = 54 \r
+///\r
+#define IP4_MAX_IPSEC_HEADLEN  54\r
 \r
 #define IP4_ASSEMLE_HASH_SIZE  31\r
 #define IP4_FRAGMENT_LIFE      120\r
@@ -203,4 +207,38 @@ Ip4PacketTimerTicking (
   IN IP4_SERVICE            *IpSb\r
   );\r
 \r
+/**\r
+  The work function to locate IPsec protocol to process the inbound or \r
+  outbound IP packets. The process routine handls the packet with following\r
+  actions: bypass the packet, discard the packet, or protect the packet.       \r
+\r
+  @param[in]       IpSb          The IP4 service instance\r
+  @param[in]       Head          The The caller supplied IP4 header.\r
+  @param[in, out]  Netbuf        The IP4 packet to be processed by IPsec\r
+  @param[in]       Options       The caller supplied options\r
+  @param[in]       OptionsLen    The length of the option\r
+  @param[in]       Direction     The directionality in an SPD entry, \r
+                                 EfiIPsecInBound or EfiIPsecOutBound\r
+  @param[in]       Context       The token's wrap\r
+\r
+  @retval EFI_SUCCESS            The IPsec protocol is not available or disabled.\r
+  @retval EFI_SUCCESS            The packet was bypassed and all buffers remain the same.\r
+  @retval EFI_SUCCESS            The packet was protected.\r
+  @retval EFI_ACCESS_DENIED      The packet was discarded.  \r
+  @retval EFI_OUT_OF_RESOURCES   There is no suffcient resource to complete the operation.\r
+  @retval EFI_BUFFER_TOO_SMALL   The number of non-empty block is bigger than the \r
+                                 number of input data blocks when build a fragment table.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip4IpSecProcessPacket (\r
+  IN IP4_SERVICE            *IpSb,\r
+  IN IP4_HEAD               *Head,\r
+  IN OUT NET_BUF            **Netbuf,\r
+  IN UINT8                  *Options,\r
+  IN UINT32                 OptionsLen,\r
+  IN EFI_IPSEC_TRAFFIC_DIR  Direction,\r
+  IN VOID                   *Context\r
+  );\r
+\r
 #endif\r
index 53317c829b7bdb38e5031444ce99806d316e508c..a8a6261cfd4203c444f0703145a0fdd58d6ad628 100644 (file)
@@ -291,9 +291,29 @@ Ip4Output (
     }\r
   }\r
 \r
+  //\r
+  // TODO: currently Option/OptLen are not included into encryption scope.\r
+  //\r
+  Status = Ip4IpSecProcessPacket (\r
+             IpSb, \r
+             Head, \r
+             &Packet, \r
+             Option, \r
+             OptLen, \r
+             EfiIPsecOutBound,\r
+             Context\r
+             );\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // OK, selected the source and route, fragment the packet then send\r
   // them. Tag each fragment other than the first one as spawn from it.\r
+\r
+  //\r
+  // IPsec payload has been appended, so use IpSb->SnpMode.MaxPacketSize here.\r
   //\r
   Mtu            = IpSb->SnpMode.MaxPacketSize;\r
   HeadLen        = sizeof (IP4_HEAD) + ((OptLen + 3) & (~0x03));\r
index 8bd2ad8a54bd962dd35d7d898585b078334c56d7..3f0485f631e65f9df9548674e9875aff46beb498 100644 (file)
@@ -95,5 +95,32 @@ Ip4CancelPacket (
   IN EFI_STATUS       IoStatus\r
   );\r
 \r
+/**\r
+  Prepend an IP4 head to the Packet. It will copy the options and\r
+  build the IP4 header fields. Used for IP4 fragmentation.\r
+\r
+  @param  Packet           The packet to prepend IP4 header to\r
+  @param  Head             The caller supplied header. The caller should set\r
+                           the following header fields: Tos, TotalLen, Id,\r
+                           Fragment, Ttl, Protocol, Src and Dst. All the fields\r
+                           are in host byte order. This function will fill in\r
+                           the Ver, HeadLen, and checksum.\r
+  @param  Option           The orginal IP4 option to copy from\r
+  @param  OptLen           The length of the IP4 option\r
+\r
+  @retval EFI_BAD_BUFFER_SIZE  There is no enought room in the head space of\r
+                               Packet.\r
+  @retval EFI_SUCCESS          The IP4 header is successfully added to the packet.\r
+\r
+**/\r
+EFI_STATUS\r
+Ip4PrependHead (\r
+  IN OUT NET_BUF                *Packet,\r
+  IN     IP4_HEAD               *Head,\r
+  IN     UINT8                  *Option,\r
+  IN     UINT32                 OptLen\r
+  );\r
+\r
 extern UINT16  mIp4Id;\r
+\r
 #endif\r
index feb1594b25b33bfa8854d0189bd99ab8da4b107a..b45914d3af39d15008deab22f7abfe1ba6fd545c 100644 (file)
@@ -1,7 +1,7 @@
 #/** @file\r
 # Component name for module Mtftp4\r
 #\r
-# Copyright (c) 2007 - 2009, Intel Corporation\r
+# Copyright (c) 2007, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -67,6 +67,4 @@
   gEfiMtftp4ProtocolGuid                        # PROTOCOL ALWAYS_CONSUMED\r
   gEfiUdp4ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
   gEfiUdp4ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiUdp6ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiUdp6ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
 \r
index c298f2db0b86d7f797cc78129f61260f3601e6aa..ba1274dfa8779e319ac00b9f5ea013adb86b2af2 100644 (file)
@@ -2,7 +2,7 @@
 # Component name for module Tcp4\r
 #\r
 # FIX ME!\r
-# Copyright (c) 2006 - 2009, Intel Corporation.\r
+# Copyright (c) 2006, Intel Corporation.\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -77,6 +77,4 @@
   gEfiTcp4ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
   gEfiIp4ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
   gEfiTcp4ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiIp6ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiIp6ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
   \r
index ce66231e226cd3e215f128705586be8320dcfec4..f565d2f3d0eda06f3055c303b8c24240da31e80e 100644 (file)
@@ -471,7 +471,7 @@ TcpGetRcvMss (
   IN SOCKET  *Sock\r
   )\r
 {\r
-  EFI_SIMPLE_NETWORK_MODE SnpMode;\r
+  EFI_IP4_MODE_DATA       Ip4Mode;\r
   TCP4_PROTO_DATA         *TcpProto;\r
   EFI_IP4_PROTOCOL        *Ip;\r
 \r
@@ -481,9 +481,9 @@ TcpGetRcvMss (
   Ip       = (EFI_IP4_PROTOCOL *) (TcpProto->TcpService->IpIo->Ip);\r
   ASSERT (Ip != NULL);\r
 \r
-  Ip->GetModeData (Ip, NULL, NULL, &SnpMode);\r
+  Ip->GetModeData (Ip, &Ip4Mode, NULL, NULL);\r
 \r
-  return (UINT16) (SnpMode.MaxPacketSize - 40);\r
+  return (UINT16) (Ip4Mode.MaxPacketSize - sizeof (TCP_HEAD));\r
 }\r
 \r
 \r
index eae8c2031c7cd594a679feb3dc2185d2b9d81d7a..8303672d613f275eb5e32cd9790b712ec6d57070 100644 (file)
@@ -2,7 +2,7 @@
 # Component name for module Udp4\r
 #\r
 # FIX ME!\r
-# Copyright (c) 2006 - 2009, Intel Corporation.\r
+# Copyright (c) 2006, Intel Corporation.\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -63,6 +63,4 @@
   gEfiUdp4ServiceBindingProtocolGuid            # PROTOCOL ALWAYS_CONSUMED\r
   gEfiIp4ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
   gEfiUdp4ProtocolGuid                          # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiIp6ProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiIp6ServiceBindingProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
   \r