Revision: 14039
          http://edk2.svn.sourceforge.net/edk2/?rev=14039&view=rev
Author:   sfu5
Date:     2013-01-08 08:28:11 +0000 (Tue, 08 Jan 2013)
Log Message:
-----------
Fix several RFC compliance issues in DHCP6 driver as below.
1. Client must ignore any Advertise message that includes a Status Code option 
containing the value NoAddrsAvail.
2. The elapsed-time should start from the current DHCP transaction.
3. Client should not change any information about addresses the client has 
recorded in the IA but not included in the IA from the server.
4. Client need to update to handle the error status code 
UnspecFail/UseMulticast/NotOnLink/NoBinding in the Reply message from server.
5. When the client receives a Reply message in response to a Renew/ Rebind 
message, the client examines each IA independently. For each IA in the original 
Renew/ Rebind message, the client sends a Renew/ Rebind if the IA is not in the 
Reply message.
6. Client should uses network byte order in IANA T1/T2 option
7. Client should discard any addresses for which the preferred lifetime is 
greater than the valid lifetime.

Signed-off-by: Fu Siyuan <[email protected]>
Reviewed-by: Ye Ting <[email protected]>
Reviewed-by: Ouyang Qian <[email protected]>

Modified Paths:
--------------
    trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
    trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h
    trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c
    trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c
    trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.h

Modified: trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
===================================================================
--- trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c  2013-01-08 02:07:14 UTC (rev 
14038)
+++ trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c  2013-01-08 08:28:11 UTC (rev 
14039)
@@ -104,12 +104,6 @@
   Instance->UdpSts = EFI_ALREADY_STARTED;
 
   //
-  // Need to clear initial time to make sure that elapsed-time
-  // is set to 0 for first Solicit.
-  //
-  Instance->StartTime = 0;
-
-  //
   // Send the solicit message to start S.A.R.R process.
   //
   Status = Dhcp6SendSolicitMsg (Instance);

Modified: trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h
===================================================================
--- trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h  2013-01-08 02:07:14 UTC (rev 
14038)
+++ trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h  2013-01-08 08:28:11 UTC (rev 
14039)
@@ -249,6 +249,10 @@
   volatile EFI_STATUS           UdpSts;
   BOOLEAN                       InDestroy;
   BOOLEAN                       MediaPresent;
+  //
+  // StartTime is used to calculate the 'elapsed-time' option. Refer to 
RFC3315,
+  // the elapsed-time is amount of time since the client began its current 
DHCP transaction. 
+  //
   UINT64                        StartTime;
 };
 

Modified: trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c
===================================================================
--- trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c    2013-01-08 02:07:14 UTC (rev 
14038)
+++ trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c    2013-01-08 08:28:11 UTC (rev 
14039)
@@ -593,6 +593,14 @@
   if (Instance->Config->IaDescriptor.Type == Dhcp6OptIana) {
     T1 = NTOHL (ReadUnaligned32 ((UINT32 *) (Option + 8)));
     T2 = NTOHL (ReadUnaligned32 ((UINT32 *) (Option + 12)));
+    //
+    // Refer to RFC3155 Chapter 22.4. If a client receives an IA_NA with T1 
greater than T2,
+    // and both T1 and T2 are greater than 0, the client discards the IA_NA 
option and processes
+    // the remainder of the message as though the server had not  included the 
invalid IA_NA option.
+    //
+    if (T1 > T2 && T2 > 0) {
+      return EFI_DEVICE_ERROR;
+    }
     IaInnerOpt = Option + 16;
     IaInnerLen = (UINT16) (NTOHS (ReadUnaligned16 ((UINT16 *) (Option + 2))) - 
12);
   } else {
@@ -697,7 +705,7 @@
               &Instance->Config->IaDescriptor
               );
   if (*Option == NULL) {
-    return EFI_DEVICE_ERROR;
+    return EFI_SUCCESS;
   }
 
   //
@@ -949,7 +957,8 @@
              Cursor,
              Instance->IaCb.Ia,
              Instance->IaCb.T1,
-             Instance->IaCb.T2
+             Instance->IaCb.T2,
+             Packet->Dhcp6.Header.MessageType
              );
 
   //
@@ -987,6 +996,10 @@
   // Dhcp6selecting.
   //
   Instance->IaCb.Ia->State = Dhcp6Selecting;
+  //
+  // Clear initial time for current transaction.
+  //
+  Instance->StartTime = 0;
 
   Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
 
@@ -1133,7 +1146,8 @@
              Cursor,
              Instance->IaCb.Ia,
              Instance->IaCb.T1,
-             Instance->IaCb.T2
+             Instance->IaCb.T2,
+             Packet->Dhcp6.Header.MessageType
              );
 
   //
@@ -1171,6 +1185,10 @@
   // Dhcp6requesting.
   //
   Instance->IaCb.Ia->State = Dhcp6Requesting;
+  //
+  // Clear initial time for current transaction.
+  //
+  Instance->StartTime = 0;
 
   Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
 
@@ -1282,7 +1300,7 @@
              ServerId->Duid
              );
 
-  Cursor = Dhcp6AppendIaOption (Cursor, DecIa, 0, 0);
+  Cursor = Dhcp6AppendIaOption (Cursor, DecIa, 0, 0, 
Packet->Dhcp6.Header.MessageType);
 
   //
   // Determine the size/length of packet.
@@ -1305,6 +1323,10 @@
   // Dhcp6declining.
   //
   Instance->IaCb.Ia->State = Dhcp6Declining;
+  //
+  // Clear initial time for current transaction.
+  //
+  Instance->StartTime = 0;
 
   Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
 
@@ -1415,7 +1437,7 @@
              &Elapsed
              );
 
-  Cursor = Dhcp6AppendIaOption (Cursor, RelIa, 0, 0);
+  Cursor = Dhcp6AppendIaOption (Cursor, RelIa, 0, 0, 
Packet->Dhcp6.Header.MessageType);
 
   //
   // Determine the size/length of packet
@@ -1540,7 +1562,8 @@
              Cursor,
              Instance->IaCb.Ia,
              Instance->IaCb.T1,
-             Instance->IaCb.T2
+             Instance->IaCb.T2,
+             Packet->Dhcp6.Header.MessageType
              );
 
   if (!RebindRequest) {
@@ -1612,6 +1635,10 @@
   //
   Instance->IaCb.Ia->State = State;
   Instance->IaCb.LeaseTime = (RebindRequest) ? Instance->IaCb.T2 : 
Instance->IaCb.T1;
+  //
+  // Clear initial time for current transaction.
+  //
+  Instance->StartTime = 0;
 
   Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
 
@@ -1844,6 +1871,11 @@
   //
   Packet->Length += (UINT32) (Cursor - Packet->Dhcp6.Option);
   ASSERT (Packet->Size > Packet->Length + 8);
+  
+  //
+  // Clear initial time for current transaction.
+  //
+  Instance->StartTime = 0;
 
   //
   // Send info-request packet with no state.
@@ -1941,7 +1973,8 @@
              Cursor,
              Instance->IaCb.Ia,
              Instance->IaCb.T1,
-             Instance->IaCb.T2
+             Instance->IaCb.T2,
+             Packet->Dhcp6.Header.MessageType
              );
 
   //
@@ -1978,6 +2011,10 @@
   // Dhcp6Confirming.
   //
   Instance->IaCb.Ia->State = Dhcp6Confirming;
+  //
+  // Clear initial time for current transaction.
+  //
+  Instance->StartTime = 0;
 
   Status = Dhcp6TransmitPacket (Instance, Packet, Elapsed);
 
@@ -2020,6 +2057,8 @@
   ASSERT (Instance->IaCb.Ia != NULL);
   ASSERT (Packet != NULL);
 
+  Status = EFI_SUCCESS;
+
   if (Packet->Dhcp6.Header.MessageType != Dhcp6MsgReply) {
     return EFI_DEVICE_ERROR;
   }
@@ -2056,7 +2095,7 @@
                &Instance->Config->IaDescriptor
                );
     if (Option == NULL) {
-      return EFI_DEVICE_ERROR;
+      return EFI_SUCCESS;
     }
   }
 
@@ -2070,19 +2109,6 @@
   }
 
   //
-  // Dequeue the sent packet from retransmit list since reply received.
-  //
-  Status = Dhcp6DequeueRetry (
-             Instance,
-             Packet->Dhcp6.Header.TransactionId,
-             FALSE
-             );
-
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
   // When receive a valid reply packet in response to a decline/release packet,
   // the client considers the decline/release event completed regardless of the
   // status code.
@@ -2115,7 +2141,8 @@
     //
     Instance->StartTime       = 0;
 
-    return EFI_SUCCESS;
+    Status = EFI_SUCCESS;
+    goto ON_EXIT;
   }
 
   //
@@ -2132,55 +2159,63 @@
 
   if (!EFI_ERROR (Status)) {
     //
-    // Reset start time for next exchange.
-    //
-    Instance->StartTime       = 0;
-
-    //
     // No status code or no error status code means succeed to reply.
     //
     Status = Dhcp6UpdateIaInfo (Instance, Packet);
+    if (!EFI_ERROR (Status)) {
+      //
+      // Reset start time for next exchange.
+      //
+      Instance->StartTime       = 0;
 
-    if (EFI_ERROR (Status)) {
-      return Status;
-    }
+      //
+      // Set bound state and store the reply packet.
+      //
+      if (Instance->IaCb.Ia->ReplyPacket != NULL) {
+        FreePool (Instance->IaCb.Ia->ReplyPacket);
+      }
 
-    //
-    // Set bound state and store the reply packet.
-    //
-    if (Instance->IaCb.Ia->ReplyPacket != NULL) {
-      FreePool (Instance->IaCb.Ia->ReplyPacket);
-    }
+      Instance->IaCb.Ia->ReplyPacket = AllocateZeroPool (Packet->Size);
 
-    Instance->IaCb.Ia->ReplyPacket = AllocateZeroPool (Packet->Size);
+      if (Instance->IaCb.Ia->ReplyPacket == NULL) {
+        Status = EFI_OUT_OF_RESOURCES;
+        goto ON_EXIT;
+      }
 
-    if (Instance->IaCb.Ia->ReplyPacket == NULL) {
-      return EFI_OUT_OF_RESOURCES;
-    }
+      CopyMem (Instance->IaCb.Ia->ReplyPacket, Packet, Packet->Size);
 
-    CopyMem (Instance->IaCb.Ia->ReplyPacket, Packet, Packet->Size);
+      Instance->IaCb.Ia->State = Dhcp6Bound;
 
-    Instance->IaCb.Ia->State = Dhcp6Bound;
+      //
+      // For sync, set the success flag out of polling in start/renewrebind.
+      //
+      Instance->UdpSts         = EFI_SUCCESS;
 
-    //
-    // For sync, set the success flag out of polling in start/renewrebind.
-    //
-    Instance->UdpSts         = EFI_SUCCESS;
+      //
+      // Maybe this is a new round DHCP process due to some reason, such as 
NotOnLink
+      // ReplyMsg for ConfirmMsg should triger new round to acquire new 
address. In that
+      // case, clear old address.ValidLifetime and append to new address. 
Therefore, DHCP
+      // consumers can be notified to flush old address.
+      //
+      Dhcp6AppendCacheIa (Instance);
 
-    //
-    // Maybe this is a new round DHCP process due to some reason, such as 
NotOnLink
-    // ReplyMsg for ConfirmMsg should triger new round to acquire new address. 
In that
-    // case, clear old address.ValidLifetime and append to new address. 
Therefore, DHCP
-    // consumers can be notified to flush old address.
-    //
-    Dhcp6AppendCacheIa (Instance);
-
-    //
-    // For async, signal the Ia event to inform Ia infomation update.
-    //
-    if (Instance->Config->IaInfoEvent != NULL) {
-      gBS->SignalEvent (Instance->Config->IaInfoEvent);
+      //
+      // For async, signal the Ia event to inform Ia infomation update.
+      //
+      if (Instance->Config->IaInfoEvent != NULL) {
+        gBS->SignalEvent (Instance->Config->IaInfoEvent);
+      }
+    } else if (Status == EFI_NOT_FOUND) {
+      //
+      // Refer to RFC3315 Chapter 18.1.8, for each IA in the original Renew or 
Rebind message, 
+      // the client sends a Renew or Rebind if the IA is not in the Reply 
message.
+      // Return EFI_SUCCESS so we can continue to restart the Renew/Rebind 
process.
+      //
+      return EFI_SUCCESS;
     }
+    
+    goto ON_EXIT;
+    
   } else if (Option != NULL) {
     //
     // Any error status code option is found.
@@ -2226,6 +2261,19 @@
       }
       break;
 
+    case Dhcp6StsNoBinding:
+      if (Instance->IaCb.Ia->State == Dhcp6Renewing || 
Instance->IaCb.Ia->State == Dhcp6Rebinding) {
+        //
+        // Refer to RFC3315 Chapter 18.1.8, for each IA in the original Renew 
or Rebind message, the client 
+        // sends a Request message if the IA contained a Status Code option 
with the NoBinding status.
+        //
+        Status = Dhcp6SendRequestMsg(Instance);
+        if (EFI_ERROR (Status)) {
+          return Status;
+        }
+      }
+      break;
+
     default:
       //
       // The other status code, just restart solicitation.
@@ -2235,6 +2283,18 @@
   }
 
   return EFI_SUCCESS;
+  
+ON_EXIT:
+
+  if (!EFI_ERROR(Status)) {
+    Status = Dhcp6DequeueRetry (
+               Instance,
+               Packet->Dhcp6.Header.TransactionId,
+               FALSE
+               );
+  }
+  
+  return Status;
 }
 
 
@@ -2378,17 +2438,13 @@
   // display the associated status message to the user.
   // See the details in the section-17.1.3 of rfc-3315.
   //
-  Option = Dhcp6SeekOption(
-             Packet->Dhcp6.Option,
-             Packet->Length - 4,
-             Dhcp6OptStatusCode
+  Status = Dhcp6SeekStsOption (
+             Instance,
+             Packet,
+             &Option
              );
-
-  if (Option != NULL) {
-    StsCode = NTOHS (ReadUnaligned16 ((UINT16 *) (Option + 4)));
-    if (StsCode != Dhcp6StsSuccess) {
-      return EFI_DEVICE_ERROR;
-    }
+  if (EFI_ERROR (Status)) {
+    return EFI_DEVICE_ERROR;
   }
 
   //

Modified: trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c
===================================================================
--- trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c       2013-01-08 02:07:14 UTC 
(rev 14038)
+++ trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c       2013-01-08 08:28:11 UTC 
(rev 14039)
@@ -647,7 +647,76 @@
   return Buf;
 }
 
+/**
+  Append the appointed IA Address option to Buf, and move Buf to the end.
 
+  @param[in, out] Buf           The pointer to the position to append.
+  @param[in]      IaAddr        The pointer to the IA Address.
+  @param[in]      MessageType   Message type of DHCP6 package.
+
+  @return         Buf           The position to append the next option.
+
+**/
+UINT8 *
+Dhcp6AppendIaAddrOption (
+  IN OUT UINT8                  *Buf,
+  IN     EFI_DHCP6_IA_ADDRESS   *IaAddr,
+  IN     UINT32                 MessageType
+)
+{
+
+  //  The format of the IA Address option is:
+  //
+  //       0                   1                   2                   3
+  //       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+  //      |          OPTION_IAADDR        |          option-len           |
+  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+  //      |                                                               |
+  //      |                         IPv6 address                          |
+  //      |                                                               |
+  //      |                                                               |
+  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+  //      |                      preferred-lifetime                       |
+  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+  //      |                        valid-lifetime                         |
+  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+  //      .                                                               .
+  //      .                        IAaddr-options                         .
+  //      .                                                               .
+  //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+  
+  //
+  // Fill the value of Ia Address option type
+  //
+  WriteUnaligned16 ((UINT16 *) Buf, HTONS (Dhcp6OptIaAddr));
+  Buf                     += 2;
+
+  WriteUnaligned16 ((UINT16 *) Buf, HTONS (sizeof (EFI_DHCP6_IA_ADDRESS)));
+  Buf                     += 2;
+
+  CopyMem (Buf, &IaAddr->IpAddress, sizeof(EFI_IPv6_ADDRESS));
+  Buf                     += sizeof(EFI_IPv6_ADDRESS);
+
+  //
+  // Fill the value of preferred-lifetime and valid-lifetime.
+  // According to RFC3315 Chapter 18.1.2, the preferred-lifetime and 
valid-lifetime fields
+  // should set to 0 when initiate a Confirm message.
+  //
+  if (MessageType != Dhcp6MsgConfirm) {
+    WriteUnaligned32 ((UINT32 *) Buf, HTONL (IaAddr->PreferredLifetime));
+  }
+  Buf                     += 4;
+
+  if (MessageType != Dhcp6MsgConfirm) {
+    WriteUnaligned32 ((UINT32 *) Buf, HTONL (IaAddr->ValidLifetime));
+  }
+  Buf                     += 4;
+
+  return Buf;
+}
+
+
 /**
   Append the appointed Ia option to Buf, and move Buf to the end.
 
@@ -655,6 +724,7 @@
   @param[in]      Ia            The pointer to the Ia.
   @param[in]      T1            The time of T1.
   @param[in]      T2            The time of T2.
+  @param[in]      MessageType   Message type of DHCP6 package.
 
   @return         Buf           The position to append the next Ia option.
 
@@ -664,13 +734,13 @@
   IN OUT UINT8                  *Buf,
   IN     EFI_DHCP6_IA           *Ia,
   IN     UINT32                 T1,
-  IN     UINT32                 T2
+  IN     UINT32                 T2,
+  IN     UINT32                 MessageType
   )
 {
   UINT8                     *AddrOpt;
   UINT16                    *Len;
   UINTN                     Index;
-  UINT16                    Length;
 
   //
   //  The format of IA_NA and IA_TA option:
@@ -713,9 +783,9 @@
   // Fill the value of t1 and t2 if iana, keep it 0xffffffff if no specified.
   //
   if (Ia->Descriptor.Type == Dhcp6OptIana) {
-    WriteUnaligned32 ((UINT32 *) Buf, ((T1 != 0) ? T1 : 0xffffffff));
+    WriteUnaligned32 ((UINT32 *) Buf, HTONL ((T1 != 0) ? T1 : 0xffffffff));
     Buf                   += 4;
-    WriteUnaligned32 ((UINT32 *) Buf, ((T2 != 0) ? T2 : 0xffffffff));
+    WriteUnaligned32 ((UINT32 *) Buf, HTONL ((T2 != 0) ? T2 : 0xffffffff));
     Buf                   += 4;
   }
 
@@ -723,15 +793,8 @@
   // Fill all the addresses belong to the Ia
   //
   for (Index = 0; Index < Ia->IaAddressCount; Index++) {
-
-     AddrOpt = (UINT8 *) Ia->IaAddress + Index * sizeof (EFI_DHCP6_IA_ADDRESS);
-     Length  = HTONS ((UINT16) sizeof (EFI_DHCP6_IA_ADDRESS));
-     Buf     = Dhcp6AppendOption (
-                 Buf,
-                 HTONS (Dhcp6OptIaAddr),
-                 Length,
-                 AddrOpt
-                 );
+    AddrOpt = (UINT8 *) Ia->IaAddress + Index * sizeof (EFI_DHCP6_IA_ADDRESS);
+    Buf = Dhcp6AppendIaAddrOption (Buf, (EFI_DHCP6_IA_ADDRESS *) AddrOpt, 
MessageType);
   }
 
   //
@@ -827,7 +890,7 @@
 
   //
   // Sentinel value of 0 means that this is the first DHCP packet that we are
-  // sending and that we need to initialize the value.  First DHCP Solicit
+  // sending and that we need to initialize the value.  First DHCP message
   // gets 0 elapsed-time.  Otherwise, calculate based on StartTime.
   //
   if (Instance->StartTime == 0) {
@@ -934,10 +997,39 @@
   return Option;
 }
 
+/**
+  Check whether the incoming IPv6 address in IaAddr is one of the maintained 
+  addresses in the IA control blcok.
 
+  @param[in]  IaAddr            The pointer to the IA Address to be checked.
+  @param[in]  CurrentIa         The pointer to the IA in IA control block.
+
+  @retval     TRUE              Yes, this Address is already in IA control 
block.
+  @retval     FALSE             No, this Address is NOT in IA control block.
+
+**/
+BOOLEAN
+Dhcp6AddrIsInCurrentIa (
+  IN    EFI_DHCP6_IA_ADDRESS      *IaAddr,
+  IN    EFI_DHCP6_IA              *CurrentIa
+  )
+{
+  UINT32    Index;
+
+  ASSERT (IaAddr != NULL && CurrentIa != NULL);
+  
+  for (Index = 0; Index < CurrentIa->IaAddressCount; Index++) {
+    if (EFI_IP6_EQUAL(&IaAddr->IpAddress, 
&CurrentIa->IaAddress[Index].IpAddress)) {
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
 /**
   Parse the address option and update the address infomation.
 
+  @param[in]      CurrentIa     The pointer to the Ia Address in control blcok.
   @param[in]      IaInnerOpt    The pointer to the buffer.
   @param[in]      IaInnerLen    The length to parse.
   @param[out]     AddrNum       The number of addresses.
@@ -946,6 +1038,7 @@
 **/
 VOID
 Dhcp6ParseAddrOption (
+  IN     EFI_DHCP6_IA            *CurrentIa,
   IN     UINT8                   *IaInnerOpt,
   IN     UINT16                  IaInnerLen,
      OUT UINT32                  *AddrNum,
@@ -956,6 +1049,8 @@
   UINT16                      DataLen;
   UINT16                      OpCode;
   UINT32                      ValidLt;
+  UINT32                      PreferredLt;
+  EFI_DHCP6_IA_ADDRESS        *IaAddr;
 
   //
   //  The format of the IA Address option:
@@ -992,19 +1087,21 @@
 
   while (Cursor < IaInnerOpt + IaInnerLen) {
     //
-    // Count the Ia address option with non-0 valid time.
+    // Refer to RFC3315 Chapter 18.1.8, we need to update lifetimes for any 
addresses in the IA option
+    // that the client already has recorded in the IA, and discard the Ia 
address option with 0 valid time.
     //
     OpCode  = ReadUnaligned16 ((UINT16 *) Cursor);
-    ValidLt = ReadUnaligned32 ((UINT32 *) (Cursor + 24));
-    if (OpCode == HTONS (Dhcp6OptIaAddr) && ValidLt != 0) {
-
+    PreferredLt = NTOHL (ReadUnaligned32 ((UINT32 *) (Cursor + 20)));
+    ValidLt = NTOHL (ReadUnaligned32 ((UINT32 *) (Cursor + 24)));
+    IaAddr = (EFI_DHCP6_IA_ADDRESS *) (Cursor + 4);
+    if (OpCode == HTONS (Dhcp6OptIaAddr) && ValidLt >= PreferredLt &&
+        (Dhcp6AddrIsInCurrentIa(IaAddr, CurrentIa) || ValidLt !=0)) {
       if (AddrBuf != NULL) {
-        CopyMem (AddrBuf, Cursor + 4, sizeof (EFI_DHCP6_IA_ADDRESS));
-        AddrBuf->PreferredLifetime = NTOHL (AddrBuf->PreferredLifetime);
-        AddrBuf->ValidLifetime     = NTOHL (AddrBuf->ValidLifetime);
+        CopyMem (AddrBuf, IaAddr, sizeof (EFI_DHCP6_IA_ADDRESS));
+        AddrBuf->PreferredLifetime = PreferredLt;
+        AddrBuf->ValidLifetime     = ValidLt;
         AddrBuf = (EFI_DHCP6_IA_ADDRESS *) ((UINT8 *) AddrBuf + sizeof 
(EFI_DHCP6_IA_ADDRESS));
       }
-
       (*AddrNum)++;
     }
     DataLen = NTOHS (ReadUnaligned16 ((UINT16 *) (Cursor + 2)));
@@ -1025,6 +1122,7 @@
   @retval     EFI_NOT_FOUND         No valid IA option is found.
   @retval     EFI_SUCCESS           Create an IA control block successfully.
   @retval     EFI_OUT_OF_RESOURCES  Required system resources could not be 
allocated.
+  @retval     EFI_DEVICE_ERROR      An unexpected error.
 
 **/
 EFI_STATUS
@@ -1041,14 +1139,14 @@
   EFI_DHCP6_IA                 *Ia;
 
   if (Instance->IaCb.Ia == NULL) {
-    return EFI_NOT_FOUND;
+    return EFI_DEVICE_ERROR;
   }
 
   //
   // Calculate the number of addresses for this Ia, excluding the addresses 
with
   // the value 0 of valid lifetime.
   //
-  Dhcp6ParseAddrOption (IaInnerOpt, IaInnerLen, &AddrNum, NULL);
+  Dhcp6ParseAddrOption (Instance->IaCb.Ia, IaInnerOpt, IaInnerLen, &AddrNum, 
NULL);
 
   if (AddrNum == 0) {
     return EFI_NOT_FOUND;
@@ -1070,7 +1168,7 @@
   Ia->State          = Instance->IaCb.Ia->State;
   Ia->IaAddressCount = AddrNum;
   CopyMem (&Ia->Descriptor, &Instance->Config->IaDescriptor, sizeof 
(EFI_DHCP6_IA_DESCRIPTOR));
-  Dhcp6ParseAddrOption (IaInnerOpt, IaInnerLen, &AddrNum, Ia->IaAddress);
+  Dhcp6ParseAddrOption (Instance->IaCb.Ia, IaInnerOpt, IaInnerLen, &AddrNum, 
Ia->IaAddress);
 
   //
   // Free original IA resource.

Modified: trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.h
===================================================================
--- trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.h       2013-01-08 02:07:14 UTC 
(rev 14038)
+++ trunk/edk2/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.h       2013-01-08 08:28:11 UTC 
(rev 14039)
@@ -192,6 +192,7 @@
   @param[in]      Ia            The pointer to the Ia.
   @param[in]      T1            The time of T1.
   @param[in]      T2            The time of T2.
+  @param[in]      MessageType   Message type of DHCP6 package.
 
   @return         Buf           The position to append the next Ia option.
 
@@ -201,7 +202,8 @@
   IN OUT UINT8                  *Buf,
   IN     EFI_DHCP6_IA           *Ia,
   IN     UINT32                 T1,
-  IN     UINT32                 T2
+  IN     UINT32                 T2,
+  IN     UINT32                 MessageType
   );
 
 /**
@@ -274,6 +276,7 @@
 /**
   Parse the address option and update the address info.
 
+  @param[in]      CurrentIa     The pointer to the Ia Address in control blcok.
   @param[in]      IaInnerOpt    The pointer to the buffer.
   @param[in]      IaInnerLen    The length to parse.
   @param[out]     AddrNum       The number of addresses.
@@ -282,6 +285,7 @@
 **/
 VOID
 Dhcp6ParseAddrOption (
+  IN     EFI_DHCP6_IA            *CurrentIa,
   IN     UINT8                   *IaInnerOpt,
   IN     UINT16                  IaInnerLen,
      OUT UINT32                  *AddrNum,
@@ -300,6 +304,7 @@
   @retval     EFI_NOT_FOUND         No valid IA option is found.
   @retval     EFI_SUCCESS           Create an IA control block successfully.
   @retval     EFI_OUT_OF_RESOURCES  Required system resources could not be 
allocated.
+  @retval     EFI_DEVICE_ERROR      An unexpected error.
 
 **/
 EFI_STATUS

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to