]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Update PXE driver to support PXEv6 boot cross subnet.
authorFu, Siyuan <siyuan.fu@intel.com>
Thu, 18 Sep 2014 11:44:36 +0000 (11:44 +0000)
committersfu5 <sfu5@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 18 Sep 2014 11:44:36 +0000 (11:44 +0000)
2. Update IP6 driver to use previous configured prefix length if a pre-exist IP6 address with unspecified prefix length.
3. Add NULL check for Dhcp protocol pointer before it decline the address in Ip6ConfigSetStatefulAddrCallback() function.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu, Siyuan <siyuan.fu@intel.com>
Reviewed-By: Ye, Ting (ting.ye@intel.com)
Reviewed-By: Wu, Jiaxin <jiaxin.wu@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16131 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/Ip6Dxe/Ip6ConfigImpl.c
NetworkPkg/UefiPxeBcDxe/PxeBcBoot.c
NetworkPkg/UefiPxeBcDxe/PxeBcDhcp4.c
NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.h
NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
NetworkPkg/UefiPxeBcDxe/PxeBcImpl.h

index ddb8dcd379846503cca842ca10010b61f300ea1c..9a1e3d076f6a021829a8b28310a5ae828fca7be3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of EFI IPv6 Configuration Protocol.\r
 \r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<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
@@ -1012,6 +1012,14 @@ Ip6ConfigSetMaunualAddress (
         128\r
         );\r
 \r
+      //\r
+      // If the new address's prefix length is not specified, just use the previous configured\r
+      // prefix length for this address.\r
+      //\r
+      if (NewAddress->PrefixLength == 0) {\r
+        NewAddress->PrefixLength = CurrentAddrInfo->PrefixLength;\r
+      }\r
+\r
       //\r
       // This manual address is already in use, see whether prefix length is changed.\r
       //\r
@@ -1594,11 +1602,13 @@ Ip6ConfigSetStatefulAddrCallback (
       //\r
       // Decline those duplicates.\r
       //\r
-      Instance->Dhcp6->Decline (\r
-                         Instance->Dhcp6,\r
-                         Instance->DeclineAddressCount,\r
-                         Instance->DeclineAddress\r
-                         );\r
+      if (Instance->Dhcp6 != NULL) {\r
+        Instance->Dhcp6->Decline (\r
+                           Instance->Dhcp6,\r
+                           Instance->DeclineAddressCount,\r
+                           Instance->DeclineAddress\r
+                           );\r
+      }\r
     }\r
 \r
     if (Instance->DeclineAddress != NULL) {\r
index 84031e40e05f65c24a3c03855dd443a8a1004f98..253115308e8159d9f38ef773148b4acace8d7f57 100644 (file)
@@ -632,6 +632,14 @@ PxeBcDhcp6BootInfo (
     return Status;\r
   }\r
 \r
+  //\r
+  // Set the station address to IP layer.\r
+  //\r
+  Status = PxeBcSetIp6Address (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
   //\r
   // Parse the value of boot file size.\r
   //\r
index b113505d9758851650b558806b9a59e2933b333c..df171598b1b19f3bf356ab8560e5df57300af580 100644 (file)
@@ -512,7 +512,7 @@ PxeBcParseDhcp4Packet (
   }\r
 \r
   //\r
-  // The offer with "yiaddr" is a proxy offer.\r
+  // The offer with zero "yiaddr" is a proxy offer.\r
   //\r
   if (Offer->Dhcp4.Header.YourAddr.Addr[0] == 0) {\r
     IsProxyOffer = TRUE;\r
index c93bad94342c28267f102f5c938090c97c26d580..b71998b405552c4ab08027840561511c3645afff 100644 (file)
@@ -488,7 +488,7 @@ PxeBcParseDhcp6Packet (
   }\r
 \r
   //\r
-  // The offer with assigned client address is a proxy offer.\r
+  // The offer with assigned client address is NOT a proxy offer.\r
   // An ia_na option, embeded with valid ia_addr option and a status_code of success.\r
   //\r
   Option = Options[PXEBC_DHCP6_IDX_IA_NA];\r
@@ -1235,9 +1235,128 @@ PxeBcUnregisterIp6Address (
   }\r
 }\r
 \r
+/**\r
+  Check whether IP driver could route the message which will be sent to ServerIp address.\r
+  \r
+  This function will check the IP6 route table every 1 seconds until specified timeout is expired, if a valid\r
+  route is found in IP6 route table, the address will be filed in GatewayAddr and return.\r
+\r
+  @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.\r
+  @param[in]  TimeOutInSecond     Timeout value in seconds.\r
+  @param[out] GatewayAddr         Pointer to store the gateway IP address.\r
+\r
+  @retval     EFI_SUCCESS         Found a valid gateway address successfully.\r
+  @retval     EFI_TIMEOUT         The operation is time out.\r
+  @retval     Other               Unexpect error happened.\r
+  \r
+**/\r
+EFI_STATUS\r
+PxeBcCheckRouteTable (\r
+  IN  PXEBC_PRIVATE_DATA            *Private,\r
+  IN  UINTN                         TimeOutInSecond,\r
+  OUT EFI_IPv6_ADDRESS              *GatewayAddr\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_IP6_PROTOCOL                 *Ip6;\r
+  EFI_IP6_MODE_DATA                Ip6ModeData;\r
+  UINTN                            Index;\r
+  EFI_EVENT                        TimeOutEvt;\r
+  UINTN                            RetryCount;\r
+  BOOLEAN                          GatewayIsFound;\r
+\r
+  ASSERT (GatewayAddr != NULL);\r
+  ASSERT (Private != NULL);\r
+\r
+  Ip6            = Private->Ip6;\r
+  GatewayIsFound = FALSE;\r
+  RetryCount     = 0;\r
+  TimeOutEvt     = NULL;\r
+  ZeroMem (GatewayAddr, sizeof (EFI_IPv6_ADDRESS));\r
+\r
+  while (TRUE) {\r
+    Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+\r
+    //\r
+    // Find out the gateway address which can route the message whcih send to ServerIp.\r
+    //\r
+    for (Index = 0; Index < Ip6ModeData.RouteCount; Index++) {\r
+      if (NetIp6IsNetEqual (&Private->ServerIp.v6, &Ip6ModeData.RouteTable[Index].Destination, Ip6ModeData.RouteTable[Index].PrefixLength)) {\r
+        IP6_COPY_ADDRESS (GatewayAddr, &Ip6ModeData.RouteTable[Index].Gateway);\r
+        GatewayIsFound = TRUE;\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (Ip6ModeData.AddressList != NULL) {\r
+      FreePool (Ip6ModeData.AddressList);\r
+    }\r
+    if (Ip6ModeData.GroupTable != NULL) {\r
+      FreePool (Ip6ModeData.GroupTable);\r
+    }\r
+    if (Ip6ModeData.RouteTable != NULL) {\r
+      FreePool (Ip6ModeData.RouteTable);\r
+    }\r
+    if (Ip6ModeData.NeighborCache != NULL) {\r
+      FreePool (Ip6ModeData.NeighborCache);\r
+    }\r
+    if (Ip6ModeData.PrefixTable != NULL) {\r
+      FreePool (Ip6ModeData.PrefixTable);\r
+    }\r
+    if (Ip6ModeData.IcmpTypeList != NULL) {\r
+      FreePool (Ip6ModeData.IcmpTypeList);\r
+    }\r
+    \r
+    if (GatewayIsFound || RetryCount == TimeOutInSecond) {\r
+      break;\r
+    }\r
+    \r
+    RetryCount++;\r
+    \r
+    //\r
+    // Delay 1 second then recheck it again.\r
+    //\r
+    if (TimeOutEvt == NULL) {\r
+      Status = gBS->CreateEvent (\r
+                      EVT_TIMER,\r
+                      TPL_CALLBACK,\r
+                      NULL,\r
+                      NULL,\r
+                      &TimeOutEvt\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        goto ON_EXIT;\r
+      }\r
+    }\r
+\r
+    Status = gBS->SetTimer (TimeOutEvt, TimerRelative, TICKS_PER_SECOND);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+    while (EFI_ERROR (gBS->CheckEvent (TimeOutEvt))) {\r
+      Ip6->Poll (Ip6);\r
+    }\r
+  }\r
+  \r
+ON_EXIT:\r
+  if (TimeOutEvt != NULL) {\r
+    gBS->CloseEvent (TimeOutEvt);\r
+  }\r
+  \r
+  if (GatewayIsFound) {\r
+    Status = EFI_SUCCESS;\r
+  } else if (RetryCount == TimeOutInSecond) {\r
+    Status = EFI_TIMEOUT;\r
+  }\r
+\r
+  return Status; \r
+}\r
 \r
 /**\r
-  Register the ready address by Ip6Config protocol.\r
+  Register the ready station address and gateway by Ip6Config protocol.\r
 \r
   @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.\r
   @param[in]  Address             The pointer to the ready address.\r
@@ -1256,6 +1375,7 @@ PxeBcRegisterIp6Address (
   EFI_IP6_CONFIG_PROTOCOL          *Ip6Cfg;\r
   EFI_IP6_CONFIG_POLICY            Policy;\r
   EFI_IP6_CONFIG_MANUAL_ADDRESS    CfgAddr;\r
+  EFI_IPv6_ADDRESS                 GatewayAddr;\r
   UINTN                            DataSize;\r
   EFI_EVENT                        TimeOutEvt;\r
   EFI_EVENT                        MappedEvt;\r
@@ -1273,19 +1393,19 @@ PxeBcRegisterIp6Address (
   ZeroMem (&CfgAddr, sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS));\r
   CopyMem (&CfgAddr.Address, Address, sizeof (EFI_IPv6_ADDRESS));\r
 \r
+  Status = Ip6->Configure (Ip6, &Private->Ip6CfgData);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_EXIT;\r
+  }\r
+\r
   //\r
-  // Get and store the current policy of IP6 driver.\r
+  // Retrieve the gateway address from IP6 route table.\r
   //\r
-  Status = Ip6Cfg->GetData (\r
-                     Ip6Cfg,\r
-                     Ip6ConfigDataTypePolicy,\r
-                     &DataSize,\r
-                     &Private->Ip6Policy\r
-                     );\r
+  Status = PxeBcCheckRouteTable (Private, PXEBC_IP6_ROUTE_TABLE_TIMEOUT, &GatewayAddr);\r
   if (EFI_ERROR (Status)) {\r
     goto ON_EXIT;\r
   }\r
-\r
+  \r
   //\r
   // There is no channel between IP6 and PXE driver about address setting,\r
   // so it has to set the new address by Ip6ConfigProtocol manually.\r
@@ -1381,6 +1501,21 @@ PxeBcRegisterIp6Address (
     }\r
   }\r
 \r
+  //\r
+  // Set the default gateway address back if needed.\r
+  //\r
+  if (!NetIp6IsUnspecifiedAddr (&GatewayAddr)) {\r
+    Status = Ip6Cfg->SetData (\r
+                       Ip6Cfg,\r
+                       Ip6ConfigDataTypeGateway,\r
+                       sizeof (EFI_IPv6_ADDRESS),\r
+                       &GatewayAddr\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
+\r
 ON_EXIT:\r
   if (MappedEvt != NULL) {\r
     Ip6Cfg->UnregisterDataNotify (\r
@@ -1396,6 +1531,100 @@ ON_EXIT:
   return Status;\r
 }\r
 \r
+/**\r
+  Set the IP6 policy to Automatic.\r
+\r
+  @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.\r
+\r
+  @retval     EFI_SUCCESS         Switch the IP policy succesfully.\r
+  @retval     Others              Unexpect error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+PxeBcSetIp6Policy (\r
+  IN PXEBC_PRIVATE_DATA            *Private\r
+  )\r
+{\r
+  EFI_IP6_CONFIG_POLICY            Policy;\r
+  EFI_STATUS                       Status;\r
+  EFI_IP6_CONFIG_PROTOCOL          *Ip6Cfg;\r
+  UINTN                            DataSize;\r
+\r
+  Ip6Cfg      = Private->Ip6Cfg;\r
+  DataSize    = sizeof (EFI_IP6_CONFIG_POLICY);\r
+\r
+  //\r
+  // Get and store the current policy of IP6 driver.\r
+  //\r
+  Status = Ip6Cfg->GetData (\r
+                     Ip6Cfg,\r
+                     Ip6ConfigDataTypePolicy,\r
+                     &DataSize,\r
+                     &Private->Ip6Policy\r
+                     );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (Private->Ip6Policy == Ip6ConfigPolicyManual) {\r
+    Policy = Ip6ConfigPolicyAutomatic;\r
+    Status = Ip6Cfg->SetData (\r
+                       Ip6Cfg,\r
+                       Ip6ConfigDataTypePolicy,\r
+                       sizeof(EFI_IP6_CONFIG_POLICY),\r
+                       &Policy\r
+                       );\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // There is no need to recover later.\r
+      //\r
+      Private->Ip6Policy = PXEBC_IP6_POLICY_MAX;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function will register the station IP address and flush IP instance to start using the new IP address.\r
+  \r
+  @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.\r
+\r
+  @retval     EFI_SUCCESS         The new IP address has been configured successfully.\r
+  @retval     Others              Failed to configure the address.\r
+\r
+**/\r
+EFI_STATUS\r
+PxeBcSetIp6Address (\r
+  IN  PXEBC_PRIVATE_DATA              *Private\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_DHCP6_PROTOCOL          *Dhcp6;\r
+    \r
+  Dhcp6 = Private->Dhcp6;\r
+\r
+  CopyMem (&Private->StationIp.v6, &Private->TmpStationIp.v6, sizeof (EFI_IPv6_ADDRESS));\r
+  CopyMem (&Private->PxeBc.Mode->StationIp.v6, &Private->StationIp.v6, sizeof (EFI_IPv6_ADDRESS));\r
+\r
+  Status = PxeBcRegisterIp6Address (Private, &Private->StationIp.v6);\r
+  if (EFI_ERROR (Status)) {\r
+    Dhcp6->Stop (Dhcp6);\r
+    return Status;\r
+  }\r
+\r
+  Status = PxeBcFlushStationIp (Private, &Private->StationIp, NULL);\r
+  if (EFI_ERROR (Status)) {\r
+    PxeBcUnregisterIp6Address (Private);\r
+    Dhcp6->Stop (Dhcp6);\r
+    return Status;\r
+  }\r
+\r
+  AsciiPrint ("\n  Station IP address is ");\r
+  PxeBcShowIp6Addr (&Private->StationIp.v6);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   EFI_DHCP6_CALLBACK is provided by the consumer of the EFI DHCPv6 Protocol driver\r
@@ -1843,36 +2072,23 @@ PxeBcDhcp6Sarr (
   }\r
 \r
   ASSERT (Mode.Ia->State == Dhcp6Bound);\r
-  CopyMem (&Private->StationIp.v6, &Mode.Ia->IaAddress[0].IpAddress, sizeof (EFI_IPv6_ADDRESS));\r
-  CopyMem (&PxeMode->StationIp.v6, &Private->StationIp.v6, sizeof (EFI_IPv6_ADDRESS));\r
-\r
-  Status = PxeBcRegisterIp6Address (Private, &Private->StationIp.v6);\r
-  if (EFI_ERROR (Status)) {\r
-    Dhcp6->Stop (Dhcp6);\r
-    return Status;\r
-  }\r
-\r
-  Status = PxeBcFlushStationIp (Private, &Private->StationIp, NULL);\r
-  if (EFI_ERROR (Status)) {\r
-    PxeBcUnregisterIp6Address (Private);\r
-    Dhcp6->Stop (Dhcp6);\r
-    return Status;\r
-  }\r
+  //\r
+  // DHCP6 doesn't have an option to specify the router address on the subnet, the only way to get the\r
+  // router address in IP6 is the router discovery mechanism (the RS and RA, which only be handled when\r
+  // the IP policy is Automatic). So we just hold the station IP address here and leave the IP policy as\r
+  // Automatic, until we get the server IP address. This could let IP6 driver finish the router discovery \r
+  // to find a valid router address.\r
+  //\r
+  CopyMem (&Private->TmpStationIp.v6, &Mode.Ia->IaAddress[0].IpAddress, sizeof (EFI_IPv6_ADDRESS));\r
 \r
   //\r
   // Check the selected offer whether BINL retry is needed.\r
   //\r
   Status = PxeBcHandleDhcp6Offer (Private);\r
   if (EFI_ERROR (Status)) {\r
-    PxeBcUnregisterIp6Address (Private);\r
     Dhcp6->Stop (Dhcp6);\r
     return Status;\r
   }\r
-\r
-  AsciiPrint ("\n  Station IP address is ");\r
-\r
-  PxeBcShowIp6Addr (&Private->StationIp.v6);\r
-\r
+  \r
   return EFI_SUCCESS;\r
 }\r
-\r
index bb8ad65b6300e2788dd11a789f515df1eee9b9a6..38bf26564d0865f40e63bce52b9ca700a2621cdc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Functions declaration related with DHCPv6 for UefiPxeBc Driver.\r
 \r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<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
@@ -20,6 +20,7 @@
 #define PXEBC_DHCP6_OPTION_MAX_SIZE       312\r
 #define PXEBC_DHCP6_PACKET_MAX_SIZE       1472\r
 #define PXEBC_IP6_POLICY_MAX              0xff\r
+#define PXEBC_IP6_ROUTE_TABLE_TIMEOUT     10\r
 \r
 #define PXEBC_DHCP6_S_PORT                547\r
 #define PXEBC_DHCP6_C_PORT                546\r
@@ -254,6 +255,33 @@ PxeBcDhcp6Discover (
   IN  EFI_IP_ADDRESS                *DestIp\r
   );\r
 \r
+/**\r
+  Set the IP6 policy to Automatic.\r
+\r
+  @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.\r
+\r
+  @retval     EFI_SUCCESS         Switch the IP policy succesfully.\r
+  @retval     Others              Unexpect error happened.\r
+\r
+**/\r
+EFI_STATUS\r
+PxeBcSetIp6Policy (\r
+  IN PXEBC_PRIVATE_DATA            *Private\r
+  );\r
+\r
+/**\r
+  This function will register the station IP address and flush IP instance to start using the new IP address.\r
+  \r
+  @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.\r
+\r
+  @retval     EFI_SUCCESS         The new IP address has been configured successfully.\r
+  @retval     Others              Failed to configure the address.\r
+\r
+**/\r
+EFI_STATUS\r
+PxeBcSetIp6Address (\r
+  IN  PXEBC_PRIVATE_DATA              *Private\r
+  );\r
 \r
 /**\r
   Start the DHCPv6 S.A.R.R. process to acquire the IPv6 address and other PXE boot information.\r
index be3d248fa9f11e4dbb5570b96f584ec168084031..89d43f8e69a4947048b85f892a7ccc7def8304d2 100644 (file)
@@ -124,6 +124,14 @@ EfiPxeBcStart (
     if (EFI_ERROR (Status)) {\r
       goto ON_ERROR;\r
     }\r
+\r
+    //\r
+    // Set Ip6 policy to Automatic to start the IP6 router discovery.\r
+    //\r
+    Status = PxeBcSetIp6Policy (Private);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_ERROR;\r
+    }\r
   } else {\r
     AsciiPrint ("\n>>Start PXE over IPv4");\r
     //\r
index 1d4381a1f5612823ee0a08329599b1e753ab82c8..8f754e0b3b7ca47d50783578e6a705d0c16b91ce 100644 (file)
@@ -160,6 +160,7 @@ struct _PXEBC_PRIVATE_DATA {
   BOOLEAN                                   IsProxyRecved;\r
   BOOLEAN                                   IsDoDiscover;\r
 \r
+  EFI_IP_ADDRESS                            TmpStationIp;\r
   EFI_IP_ADDRESS                            StationIp;\r
   EFI_IP_ADDRESS                            SubnetMask;\r
   EFI_IP_ADDRESS                            GatewayIp;\r