/** @file
Dhcp6 support functions implementation.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Dhcp6Impl.h"
/**
Generate client Duid in the format of Duid-llt.
@param[in] Mode The pointer to the mode of SNP.
@retval NULL If it failed to generate a client Id.
@retval others The pointer to the new client id.
**/
)
{
//
// Attempt to get client Id from variable to keep it constant.
// See details in section-9 of rfc-3315.
//
return Duid;
}
//
// The format of client identifier option:
//
// 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_CLIENTID | option-len |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// . .
// . DUID .
// . (variable length) .
// . .
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
//
// If System UUID is found from SMBIOS Table, use DUID-UUID type.
//
//
//
// The format of DUID-UUID:
//
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | DUID-Type (4) | UUID (128 bits) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
// | |
// | |
// | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
//
// sizeof (option-len + Duid-type + UUID-size) = 20 bytes
//
return NULL;
}
//
// sizeof (Duid-type + UUID-size) = 18 bytes
//
//
// Set the Duid-type and copy UUID.
//
} else {
//
//
// The format of DUID-LLT:
//
// 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
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Duid type (1) | hardware type (16 bits) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | time (32 bits) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// . .
// . link-layer address (variable length) .
// . .
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
//
//
(
(((((Time.Year - 2000) * 360 + (Time.Month - 1)) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) *
60 +
);
//
// sizeof (option-len + Duid-type + hardware-type + time) = 10 bytes
//
return NULL;
}
//
// sizeof (Duid-type + hardware-type + time) = 8 bytes
//
//
// Set the Duid-type, hardware-type, time and copy the hardware address.
//
}
L"ClientId",
);
return Duid;
}
/**
Copy the Dhcp6 configure data.
@param[in] DstCfg The pointer to the destination configure data.
@param[in] SorCfg The pointer to the source configure data.
@retval EFI_SUCCESS Copy the content from SorCfg from DstCfg successfully.
@retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
**/
)
{
//
// Allocate another buffer for solicitretransmission, and copy it.
//
//
// Error will be handled out of this function.
//
return EFI_OUT_OF_RESOURCES;
}
CopyMem (
sizeof (EFI_DHCP6_RETRANSMISSION)
);
}
//
// Error will be handled out of this function.
//
return EFI_OUT_OF_RESOURCES;
}
//
// Error will be handled out of this function.
//
return EFI_OUT_OF_RESOURCES;
}
CopyMem (
);
}
}
return EFI_SUCCESS;
}
/**
Clean up the configure data.
@param[in, out] CfgData The pointer to the configure data.
**/
)
{
//
// Clean up all fields in config data including the reference buffers, but do
// not free the config data buffer itself.
//
}
}
}
}
}
/**
Clean up the mode data.
@param[in, out] ModeData The pointer to the mode data.
**/
)
{
//
// Clean up all fields in mode data including the reference buffers, but do
// not free the mode data buffer itself.
//
}
}
}
}
/**
Calculate the expire time by the algorithm defined in rfc.
@param[in] Base The base value of the time.
@param[in] IsFirstRt If TRUE, it is the first time to calculate expire time.
@param[in] NeedSigned If TRUE, the the signed factor is needed.
@return Expire The calculated result for the new expire time.
**/
)
{
//
// Take the 10bits of microsecond in system time as a uniform distribution.
// Take the 10th bit as a flag to determine it's signed or not.
//
//
// Calculate expire by the following algo:
// 1. base + base * (-0.1 ~ 0) for the first solicit
// 2. base + base * (-0.1 ~ 0.1) for the first other messages
// 3. 2 * base + base * (-0.1 ~ 0.1) for the subsequent all messages
// 4. base + base * (-0.1 ~ 0) for the more than mrt timeout
//
// The (Seed / 0x3ff / 10) is used to a random range (0, 0.1).
//
} else {
}
return Expire;
}
/**
Calculate the lease time by the algorithm defined in rfc.
@param[in] IaCb The pointer to the Ia control block.
**/
)
{
MaxLt = 0;
//
// Calculate minlt as min of all valid life time, and maxlt as max of all
// valid life time.
//
}
//
// Take 50% minlt as t1, and 80% maxlt as t2 if Dhcp6 server doesn't offer
// such information.
//
}
/**
Check whether the addresses are all included by the configured Ia.
@param[in] Ia The pointer to the Ia.
@param[in] AddressCount The number of addresses.
@param[in] Addresses The pointer to the addresses buffer.
@retval EFI_SUCCESS The addresses are all included by the configured IA.
@retval EFI_NOT_FOUND The addresses are not included by the configured IA.
**/
)
{
//
// Check whether the addresses are all included by the configured IA. And it
// will return success if address count is zero, which means all addresses.
//
if (CompareMem (
sizeof (EFI_IPv6_ADDRESS)
) == 0) {
break;
}
}
if (!Found) {
return EFI_NOT_FOUND;
}
}
return EFI_SUCCESS;
}
/**
Deprive the addresses from current Ia, and generate another eliminated Ia.
@param[in] Ia The pointer to the Ia.
@param[in] AddressCount The number of addresses.
@param[in] Addresses The pointer to the addresses buffer.
@retval NULL If it failed to generate the deprived Ia.
@retval others The pointer to the deprived Ia.
**/
)
{
if (AddressCount == 0) {
//
// It means release all Ia addresses if address count is zero.
//
}
ASSERT (AddressCount != 0);
return NULL;
}
//
// If release all Ia addresses, just copy the configured Ia and then set
// its address count as zero.
// other infor such as Ia state will be updated when receiving reply.
//
Ia->IaAddressCount = 0;
return IaCopy;
}
//
// Move the addresses from the Ia of instance to the deprived Ia.
//
if (CompareMem (
sizeof (EFI_IPv6_ADDRESS)
) == 0) {
//
// Copy the deprived address to the copy of Ia
//
CopyMem (
sizeof (EFI_DHCP6_IA_ADDRESS)
);
//
// Delete the deprived address from the instance Ia
//
CopyMem (
);
}
break;
}
}
}
return IaCopy;
}
/**
The dummy ext buffer free callback routine.
@param[in] Arg The pointer to the parameter.
**/
)
{
}
/**
The callback routine once message transmitted.
@param[in] Wrap The pointer to the received net buffer.
@param[in] EndPoint The pointer to the udp end point.
@param[in] IoStatus The return status from udp io.
@param[in] Context The opaque parameter to the function.
**/
)
{
NetbufFree (Wrap);
}
/**
Append the option to Buf, and move Buf to the end.
@param[in, out] Buf The pointer to the buffer.
@param[in] OptType The option type.
@param[in] OptLen The length of option contents.
@param[in] Data The pointer to the option content.
@return Buf The position to append the next option.
**/
UINT8 *
)
{
//
// The format of Dhcp6 option:
//
// 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-code | option-len (option data) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | option-data |
// | (option-len octets) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
Buf += 2;
Buf += 2;
return Buf;
}
/**
Append the appointed Ia option to Buf, and move Buf to the end.
@param[in, out] Buf The pointer to the position to append.
@param[in] Ia The pointer to the Ia.
@param[in] T1 The time of T1.
@param[in] T2 The time of T2.
@return Buf The position to append the next Ia option.
**/
UINT8 *
)
{
//
// The format of IA_NA and IA_TA option:
//
// 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_IA_NA | option-len |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | IAID (4 octets) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | T1 (only for IA_NA) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | T2 (only for IA_NA) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | |
// . IA_NA-options/IA_TA-options .
// . .
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
//
// Fill the value of Ia option type
//
Buf += 2;
//
// Fill the len of Ia option later, keep the pointer first
//
Buf += 2;
//
// Fill the value of iaid
//
Buf += 4;
//
// Fill the value of t1 and t2 if iana, keep it 0xffffffff if no specified.
//
Buf += 4;
Buf += 4;
}
//
// Fill all the addresses belong to the Ia
//
Buf = Dhcp6AppendOption (
Buf,
);
}
//
// Fill the value of Ia option length
//
return Buf;
}
/**
Append the appointed Elapsed time option to Buf, and move Buf to the end.
@param[in, out] Buf The pointer to the position to append.
@param[in] Instance The pointer to the Dhcp6 instance.
@param[out] Elapsed The pointer to the elapsed time value in
the generated packet.
@return Buf The position to append the next Ia option.
**/
UINT8 *
)
{
//
// The format of elapsed time option:
//
// 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_ELAPSED_TIME | option-len |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | elapsed-time |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
//
// Fill the value of elapsed-time option type.
//
Buf += 2;
//
// Fill the len of elapsed-time option, which is fixed.
//
Buf += 2;
//
// Fill in elapsed time value with 0 value for now. The actual value is
// filled in later just before the packet is transmitted.
//
Buf += 2;
return Buf;
}
/**
Set the elapsed time based on the given instance and the pointer to the
elapsed time option.
@param[in] Elapsed The pointer to the position to append.
@param[in] Instance The pointer to the Dhcp6 instance.
**/
)
{
//
//
CurrentStamp = (UINT64)
(
);
//
// 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
// gets 0 elapsed-time. Otherwise, calculate based on StartTime.
//
ElapsedTimeValue = 0;
} else {
//
// If elapsed time cannot fit in two bytes, set it to 0xffff.
//
if (ElapsedTimeValue > 0xffff) {
ElapsedTimeValue = 0xffff;
}
}
}
/**
Seek the address of the first byte of the option header.
@param[in] Buf The pointer to the buffer.
@param[in] SeekLen The length to seek.
@param[in] OptType The option type.
@retval NULL If it failed to seek the option.
@retval others The position to the option.
**/
UINT8 *
)
{
//
// The format of Dhcp6 option refers to Dhcp6AppendOption().
//
break;
}
}
return Option;
}
/**
Seek the address of the first byte of the Ia option header.
@param[in] Buf The pointer to the buffer.
@param[in] SeekLen The length to seek.
@param[in] IaDesc The pointer to the Ia descriptor.
@retval NULL If it failed to seek the Ia option.
@retval others The position to the Ia option.
**/
UINT8 *
)
{
//
// The format of IA_NA and IA_TA option refers to Dhcp6AppendIaOption().
//
break;
}
}
return Option;
}
/**
Parse the address option and update the address infomation.
@param[in] IaInnerOpt The pointer to the buffer.
@param[in] IaInnerLen The length to parse.
@param[out] AddrNum The number of addresses.
@param[in, out] AddrBuf The pointer to the address buffer.
**/
)
{
//
// The format of the IA Address option:
//
// 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 .
// . .
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//
//
// Two usage model:
//
// 1. Pass addrbuf == null, to get the addrnum over the Ia inner options.
// 2. Pass addrbuf != null, to resolve the addresses over the Ia inner
// options to the addrbuf.
//
Cursor = IaInnerOpt;
*AddrNum = 0;
//
// Count the Ia address option with non-0 valid time.
//
}
(*AddrNum)++;
}
}
}
/**
Create a control blcok for the Ia according to the corresponding options.
@param[in] Instance The pointer to DHCP6 Instance.
@param[in] IaInnerOpt The pointer to the inner options in the Ia option.
@param[in] IaInnerLen The length of all the inner options in the Ia option.
@param[in] T1 T1 time in the Ia option.
@param[in] T2 T2 time in the Ia option.
@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.
**/
)
{
return EFI_NOT_FOUND;
}
//
// Calculate the number of addresses for this Ia, excluding the addresses with
// the value 0 of valid lifetime.
//
if (AddrNum == 0) {
return EFI_NOT_FOUND;
}
//
// Allocate for new IA.
//
return EFI_OUT_OF_RESOURCES;
}
//
// Fill up this new IA fields.
//
//
// Free original IA resource.
//
}
//
// Update IaCb to use new IA.
//
//
// Fill in IaCb fields. Such as T1, T2, AllExpireTime and LeaseTime.
//
return EFI_SUCCESS;
}
/**
Cache the current IA configuration information.
@param[in] Instance The pointer to DHCP6 Instance.
@retval EFI_SUCCESS Cache the current IA successfully.
@retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
**/
)
{
//
// Cache the current IA.
//
return EFI_OUT_OF_RESOURCES;
}
}
return EFI_SUCCESS;
}
/**
Append CacheIa to the currrent IA. Meanwhile, clear CacheIa.ValidLifetime to 0.
@param[in] Instance The pointer to DHCP6 instance.
**/
)
{
//
// There are old addresses existing. Merge with current addresses.
//
NewIaSize = sizeof (EFI_DHCP6_IA) + (Ia->IaAddressCount + CacheIa->IaAddressCount - 1) * sizeof (EFI_DHCP6_IA_ADDRESS);
return;
}
//
// Clear old address.ValidLifetime
//
}
//
// Migrate to the NewIa and free previous.
//
}
}