/** @file\r
IP4 input process.\r
- \r
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
-(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
\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
-http://opensource.org/licenses/bsd-license.php\r
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\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
+ 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
\r
/**\r
- The work function to locate IPsec protocol to process the inbound or \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
+ actions: bypass the packet, discard the packet, or protect the packet.\r
\r
@param[in] IpSb The IP4 service instance.\r
@param[in, out] Head The The caller supplied IP4 header.\r
@param[in, out] Netbuf The IP4 packet to be processed by IPsec.\r
@param[in, out] Options The caller supplied options.\r
@param[in, out] OptionsLen The length of the option.\r
- @param[in] Direction The directionality in an SPD entry, \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_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
+ @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
if (!mIpSec2Installed) {\r
goto ON_EXIT;\r
}\r
- \r
+ ASSERT (mIpSec != NULL);\r
+\r
Packet = *Netbuf;\r
RecycleEvent = NULL;\r
IpSecWrap = NULL;\r
FragmentTable = NULL;\r
- TxWrap = (IP4_TXTOKEN_WRAP *) Context; \r
+ TxWrap = (IP4_TXTOKEN_WRAP *) Context;\r
FragmentCount = Packet->BlockOpNum;\r
\r
ZeroMem (&ZeroHead, sizeof (IP4_HEAD));\r
- \r
- if (mIpSec == NULL) {\r
- gBS->LocateProtocol (&gEfiIpSec2ProtocolGuid, NULL, (VOID **) &mIpSec);\r
- if (mIpSec == NULL) {\r
- goto ON_EXIT;\r
- }\r
- }\r
\r
//\r
// Check whether the IPsec enable variable is set.\r
if (mIpSec->DisabledFlag) {\r
//\r
// If IPsec is disabled, restore the original MTU\r
- // \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
+ // If IPsec is enabled, use the MTU which reduce the IPsec header length.\r
//\r
- IpSb->MaxPacketSize = IpSb->OldMaxPacketSize - IP4_MAX_IPSEC_HEADLEN; \r
+ IpSb->MaxPacketSize = IpSb->OldMaxPacketSize - IP4_MAX_IPSEC_HEADLEN;\r
}\r
\r
//\r
Status = EFI_OUT_OF_RESOURCES;\r
goto ON_EXIT;\r
}\r
- \r
+\r
Status = NetbufBuildExt (Packet, FragmentTable, &FragmentCount);\r
- \r
+\r
//\r
// Record the original FragmentTable and count.\r
//\r
// Convert host byte order to network byte order\r
//\r
Ip4NtohHead (*Head);\r
- \r
+\r
Status = mIpSec->ProcessExt (\r
mIpSec,\r
IpSb->Controller,\r
// Convert back to host byte order\r
//\r
Ip4NtohHead (*Head);\r
- \r
+\r
if (EFI_ERROR (Status)) {\r
FreePool (OriginalFragmentTable);\r
goto ON_EXIT;\r
}\r
\r
if (Direction == EfiIPsecOutBound && TxWrap != NULL) {\r
- \r
+\r
TxWrap->IpSecRecycleSignal = RecycleEvent;\r
TxWrap->Packet = NetbufFromExt (\r
FragmentTable,\r
//\r
NetIpSecNetbufFree (*Netbuf);\r
*Netbuf = TxWrap->Packet;\r
- \r
+\r
} else {\r
- \r
+\r
IpSecWrap = AllocateZeroPool (sizeof (IP4_IPSEC_WRAP));\r
- \r
+\r
if (IpSecWrap == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
gBS->SignalEvent (RecycleEvent);\r
goto ON_EXIT;\r
}\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
+ FragmentTable,\r
+ FragmentCount,\r
+ IP4_MAX_HEADLEN,\r
+ 0,\r
+ Ip4IpSecFree,\r
IpSecWrap\r
);\r
- \r
+\r
if (Packet == NULL) {\r
Packet = IpSecWrap->Packet;\r
gBS->SignalEvent (RecycleEvent);\r
/**\r
Pre-process the IPv4 packet. First validates the IPv4 packet, and\r
then reassembles packet if it is necessary.\r
- \r
+\r
@param[in] IpSb Pointer to IP4_SERVICE.\r
@param[in, out] Packet Pointer to the Packet to be processed.\r
@param[in] Head Pointer to the IP4_HEAD.\r
as multicast.\r
\r
@retval EFI_SEUCCESS The recieved packet is in well form.\r
- @retval EFI_INVAILD_PARAMETER The recieved packet is malformed. \r
+ @retval EFI_INVAILD_PARAMETER The recieved packet is malformed.\r
\r
**/\r
EFI_STATUS\r
IN OUT NET_BUF **Packet,\r
IN IP4_HEAD *Head,\r
IN UINT8 *Option,\r
- IN UINT32 OptionLen, \r
+ IN UINT32 OptionLen,\r
IN UINT32 Flag\r
- ) \r
+ )\r
{\r
IP4_CLIP_INFO *Info;\r
UINT32 HeadLen;\r
if ((*Packet)->TotalSize < IP4_MIN_HEADLEN) {\r
return EFI_INVALID_PARAMETER;\r
}\r
- \r
+\r
HeadLen = (Head->HeadLen << 2);\r
TotalLen = NTOHS (Head->TotalLen);\r
\r
// Validate the options. Don't call the Ip4OptionIsValid if\r
// there is no option to save some CPU process.\r
//\r
- \r
+\r
if ((OptionLen > 0) && !Ip4OptionIsValid (Option, OptionLen, TRUE)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
return EFI_INVALID_PARAMETER;\r
}\r
}\r
- \r
+\r
return EFI_SUCCESS;\r
}\r
\r
IP4_HEAD ZeroHead;\r
UINT8 *Option;\r
UINT32 OptionLen;\r
- \r
+\r
IpSb = (IP4_SERVICE *) Context;\r
Option = NULL;\r
\r
// Validate packet format and reassemble packet if it is necessary.\r
//\r
Status = Ip4PreProcessPacket (\r
- IpSb, \r
- &Packet, \r
- Head, \r
+ IpSb,\r
+ &Packet,\r
+ Head,\r
Option,\r
- OptionLen, \r
+ OptionLen,\r
Flag\r
);\r
\r
if (EFI_ERROR (Status)) {\r
goto RESTART;\r
}\r
- \r
+\r
//\r
// If the packet is protected by tunnel mode, parse the inner Ip Packet.\r
//\r
goto RESTART;\r
}\r
}\r
- \r
+\r
ASSERT (Packet != NULL);\r
Head = Packet->Ip.Ip4;\r
IP4_GET_CLIP_INFO (Packet)->Status = EFI_SUCCESS;\r
//\r
Head = NetbufAllocSpace (Dup, IP4_MAX_HEADLEN, NET_BUF_HEAD);\r
ASSERT (Head != NULL);\r
- \r
+\r
Dup->Ip.Ip4 = (IP4_HEAD *) Head;\r
\r
CopyMem (Head, Packet->Ip.Ip4, Packet->Ip.Ip4->HeadLen << 2);\r
@param[in] Head The header of the received packet.\r
@param[in] Packet The data of the received packet.\r
@param[in] Option Point to the IP4 packet header options.\r
- @param[in] OptionLen Length of the IP4 packet header options. \r
+ @param[in] OptionLen Length of the IP4 packet header options.\r
@param[in] IpIf The interface to enqueue the packet to.\r
\r
@return The number of the IP4 children that accepts the packet\r