mirror of
https://github.com/espressif/openthread.git
synced 2026-09-01 23:09:53 +00:00
[dhcp6] style fixes and minor enhancements (#11543)
This commit contains style fixes and smaller enhancements in DHCP6-related definitions and types. Mainly, the DHCP6 `Option` sub-classes are renamed to include the `Option` suffix (e.g., `IaAddressOption`), harmonizing the naming style with `Tlv` and other `Option` classes (e.g., `Nd6` or `Dns` options).
This commit is contained in:
+132
-170
@@ -39,11 +39,10 @@
|
||||
#if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE || OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE
|
||||
|
||||
#include "common/clearable.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/equatable.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/random.hpp"
|
||||
#include "mac/mac_types.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Dhcp6 {
|
||||
@@ -57,62 +56,51 @@ namespace Dhcp6 {
|
||||
* @{
|
||||
*/
|
||||
|
||||
constexpr uint16_t kDhcpClientPort = 546;
|
||||
constexpr uint16_t kDhcpServerPort = 547;
|
||||
constexpr uint16_t kHardwareTypeEui64 = 27;
|
||||
constexpr uint16_t kHardwareTypeEthernet = 1;
|
||||
constexpr uint16_t kDhcpClientPort = 546; ///< DHCP Client port number.
|
||||
constexpr uint16_t kDhcpServerPort = 547; ///< DHCP Server port number.
|
||||
|
||||
/**
|
||||
* DHCPv6 Message Types
|
||||
* DHCPv6 Message Types.
|
||||
*/
|
||||
enum Type : uint8_t
|
||||
enum MsgType : uint8_t
|
||||
{
|
||||
kTypeNone = 0,
|
||||
kTypeSolicit = 1,
|
||||
kTypeAdvertise = 2,
|
||||
kTypeRequest = 3,
|
||||
kTypeConfirm = 4,
|
||||
kTypeRenew = 5,
|
||||
kTypeRebind = 6,
|
||||
kTypeReply = 7,
|
||||
kTypeRelease = 8,
|
||||
kTypeDecline = 9,
|
||||
kTypeReconfigure = 10,
|
||||
kTypeInformationRequest = 11,
|
||||
kTypeRelayForward = 12,
|
||||
kTypeRelayReply = 13,
|
||||
kTypeLeaseQuery = 14,
|
||||
kTypeLeaseQueryReply = 15,
|
||||
kMsgTypeSolicit = 1, ///< Solicit message (client sends to locate servers).
|
||||
kMsgTypeAdvertise = 2, ///< Advertise message (server sends to indicate it is available).
|
||||
kMsgTypeRequest = 3, ///< Request message (client sends to request config parameters).
|
||||
kMsgTypeConfirm = 4, ///< Confirm message (client sends to determine if addresses are still valid).
|
||||
kMsgTypeRenew = 5, ///< Renew message (client sends to extend lifetime).
|
||||
kMsgTypeRebind = 6, ///< Rebind message (client sends to extend leases or update config).
|
||||
kMsgTypeReply = 7, ///< Reply message (server sends to reply to client)
|
||||
kMsgTypeRelease = 8, ///< Release message (client sends to release assigned leases).
|
||||
kMsgTypeDecline = 9, ///< Decline message (client sends to decline one or more addresses).
|
||||
kMsgTypeReconfigure = 10, ///< Reconfigure message (server sends to inform of new config).
|
||||
kMsgTypeInformationRequest = 11, ///< Information-request message (client sends to request without lease).
|
||||
kMsgTypeRelayForward = 12, ///< Relay-forward message (sent by a relay agent).
|
||||
kMsgTypeRelayReply = 13, ///< Relay-reply message (sent by a relay agent).
|
||||
kMsgTypeLeaseQuery = 14, ///< Lease query message (sent to server to obtain info about a client lease).
|
||||
kMsgTypeLeaseQueryReply = 15, ///< Lease query reply message (server sends to reply to lease query).
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a DHCP6 transaction identifier.
|
||||
* Represents a DHCPv6 transaction identifier.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class TransactionId : public Equatable<TransactionId>, public Clearable<TransactionId>
|
||||
{
|
||||
public:
|
||||
static constexpr uint16_t kSize = 3; ///< Transaction Id size (in bytes).
|
||||
|
||||
/**
|
||||
* Generates a cryptographically secure random sequence to populate the transaction identifier.
|
||||
*
|
||||
* @retval kErrorNone Successfully generated a random transaction identifier.
|
||||
* @retval kErrorFailed Failed to generate random sequence.
|
||||
*/
|
||||
Error GenerateRandom(void)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(m8);
|
||||
|
||||
return Random::Crypto::Fill(*this);
|
||||
}
|
||||
void GenerateRandom(void) { SuccessOrAssert(Random::Crypto::Fill(m8)); }
|
||||
|
||||
private:
|
||||
static constexpr uint16_t kSize = 3;
|
||||
|
||||
uint8_t m8[kSize];
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Implements DHCPv6 header.
|
||||
* Represents a DHCPv6 header.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class Header : public Clearable<Header>
|
||||
@@ -123,14 +111,14 @@ public:
|
||||
*
|
||||
* @returns The DHCPv6 message type.
|
||||
*/
|
||||
Type GetType(void) const { return mType; }
|
||||
uint8_t GetMsgType(void) const { return mMsgType; }
|
||||
|
||||
/**
|
||||
* Sets the DHCPv6 message type.
|
||||
*
|
||||
* @param[in] aType The DHCPv6 message type.
|
||||
*/
|
||||
void SetType(Type aType) { mType = aType; }
|
||||
void SetMsgType(MsgType aType) { mMsgType = aType; }
|
||||
|
||||
/**
|
||||
* Returns the DHCPv6 message transaction identifier.
|
||||
@@ -147,68 +135,61 @@ public:
|
||||
void SetTransactionId(const TransactionId &aTransactionId) { mTransactionId = aTransactionId; }
|
||||
|
||||
private:
|
||||
Type mType;
|
||||
uint8_t mMsgType;
|
||||
TransactionId mTransactionId;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* DHCPv6 Option Codes.
|
||||
*/
|
||||
enum Code : uint16_t
|
||||
{
|
||||
kOptionClientIdentifier = 1,
|
||||
kOptionServerIdentifier = 2,
|
||||
kOptionIaNa = 3,
|
||||
kOptionIaTa = 4,
|
||||
kOptionIaAddress = 5,
|
||||
kOptionRequestOption = 6,
|
||||
kOptionPreference = 7,
|
||||
kOptionElapsedTime = 8,
|
||||
kOptionRelayMessage = 9,
|
||||
kOptionAuthentication = 11,
|
||||
kOptionServerUnicast = 12,
|
||||
kOptionStatusCode = 13,
|
||||
kOptionRapidCommit = 14,
|
||||
kOptionUserClass = 15,
|
||||
kOptionVendorClass = 16,
|
||||
kOptionVendorSpecificInformation = 17,
|
||||
kOptionInterfaceId = 18,
|
||||
kOptionReconfigureMessage = 19,
|
||||
kOptionReconfigureAccept = 20,
|
||||
kOptionLeaseQuery = 44,
|
||||
kOptionClientData = 45,
|
||||
kOptionClientLastTransactionTime = 46,
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements DHCPv6 option.
|
||||
* Represents a DHCPv6 option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class Option
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the DHCPv6 option to all zeros.
|
||||
* Represents the DHCPv6 Option Codes.
|
||||
*/
|
||||
void Init(void)
|
||||
enum Code : uint16_t
|
||||
{
|
||||
mCode = 0;
|
||||
mLength = 0;
|
||||
}
|
||||
kClientId = 1, ///< Client Identifier Option.
|
||||
kServerId = 2, ///< Server Identifier Option.
|
||||
kIaNa = 3, ///< Identity Association for Non-temporary Addresses Option.
|
||||
kIaTa = 4, ///< Identity Association for Temporary Addresses Option.
|
||||
kIaAddress = 5, ///< Identity Association Address Option.
|
||||
kRequestOption = 6, ///< Option Request Option.
|
||||
kPreference = 7, ///< Preference Option.
|
||||
kElapsedTime = 8, ///< Elapsed Time Option.
|
||||
kRelayMessage = 9, ///< Relay Message Option.
|
||||
kAuthentication = 11, ///< Authentication Option.
|
||||
kServerUnicast = 12, ///< Server Unicast Option.
|
||||
kStatusCode = 13, ///< Status Code Option.
|
||||
kRapidCommit = 14, ///< Rapid Commit Option.
|
||||
kUserClass = 15, ///< User Class Option.
|
||||
kVendorClass = 16, ///< Vendor Class Option.
|
||||
kVendorSpecificInformation = 17, ///< Vendor-specific Information Option.
|
||||
kInterfaceId = 18, ///< Interface-Id Option.
|
||||
kReconfigureMessage = 19, ///< Reconfigure Message Option.
|
||||
kReconfigureAccept = 20, ///< Reconfigure Accept Option.
|
||||
kIaPd = 25, ///< Identity Association for Prefix Delegation Option.
|
||||
kIaPrefix = 26, ///< IA Prefix Option.
|
||||
kLeaseQuery = 44, ///< Lease Query Option.
|
||||
kClientData = 45, ///< Client Data Option.
|
||||
kClientLastTransactionTime = 46, ///< Client Last Transaction Time Option.
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the DHCPv6 option code.
|
||||
*
|
||||
* @returns The DHCPv6 option code.
|
||||
*/
|
||||
Code GetCode(void) const { return static_cast<Code>(BigEndian::HostSwap16(mCode)); }
|
||||
uint16_t GetCode(void) const { return BigEndian::HostSwap16(mCode); }
|
||||
|
||||
/**
|
||||
* Sets the DHCPv6 option code.
|
||||
*
|
||||
* @param[in] aCode The DHCPv6 option code.
|
||||
*/
|
||||
void SetCode(Code aCode) { mCode = BigEndian::HostSwap16(static_cast<uint16_t>(aCode)); }
|
||||
void SetCode(Code aCode) { mCode = BigEndian::HostSwap16(aCode); }
|
||||
|
||||
/**
|
||||
* Returns the length of DHCPv6 option.
|
||||
@@ -230,27 +211,36 @@ private:
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* DHCP6 Unique Identifier (DUID) Type.
|
||||
* DHCPv6 Unique Identifier (DUID) Type.
|
||||
*/
|
||||
enum DuidType : uint16_t
|
||||
{
|
||||
kDuidLinkLayerAddressPlusTime = 1, ///< Link-layer address plus time (DUID-LLT).
|
||||
kDuidEnterpriseNumber = 2, ///< Vendor-assigned unique ID based on Enterprise Number (DUID-EN).
|
||||
kDuidLinkLayerAddress = 3, ///< Link-layer address (DUID-LL).
|
||||
kDuidUniversallyUniqueId = 4, ///< Universally Unique Identifier (DUID-UUID).
|
||||
};
|
||||
|
||||
/**
|
||||
* DHCPv6 Unique Identifier (DUID) Hardware Type.
|
||||
*/
|
||||
enum HardwareType : uint16_t
|
||||
{
|
||||
kHardwareTypeEthernet = 1, ///< Ethernet HW Type.
|
||||
kHardwareTypeEui64 = 27, ///< EUI64 HW Type.
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a Client Identifier Option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class ClientIdentifier : public Option
|
||||
class ClientIdOption : public Option
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the DHCPv6 Option.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetCode(kOptionClientIdentifier);
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
}
|
||||
void Init(void) { SetCode(kClientId), SetLength(sizeof(*this) - sizeof(Option)); }
|
||||
|
||||
/**
|
||||
* Returns the client DUID Type.
|
||||
@@ -267,24 +257,21 @@ public:
|
||||
void SetDuidType(DuidType aDuidType) { mDuidType = BigEndian::HostSwap16(static_cast<uint16_t>(aDuidType)); }
|
||||
|
||||
/**
|
||||
* Returns the client Duid HardwareType.
|
||||
* Returns the client DUID HardwareType.
|
||||
*
|
||||
* @returns The client Duid HardwareType.
|
||||
* @returns The client DUID HardwareType.
|
||||
*/
|
||||
uint16_t GetDuidHardwareType(void) const { return BigEndian::HostSwap16(mDuidHardwareType); }
|
||||
|
||||
/**
|
||||
* Sets the client Duid HardwareType.
|
||||
* Sets the client DUID HardwareType.
|
||||
*
|
||||
* @param[in] aDuidHardwareType The client Duid HardwareType.
|
||||
* @param[in] aHardwareType The client DUID HardwareType.
|
||||
*/
|
||||
void SetDuidHardwareType(uint16_t aDuidHardwareType)
|
||||
{
|
||||
mDuidHardwareType = BigEndian::HostSwap16(aDuidHardwareType);
|
||||
}
|
||||
void SetDuidHardwareType(uint16_t aHardwareType) { mDuidHardwareType = BigEndian::HostSwap16(aHardwareType); }
|
||||
|
||||
/**
|
||||
* Returns the client LinkLayerAddress.
|
||||
* Returns the client link-layer address.
|
||||
*
|
||||
* @returns The link-layer address.
|
||||
*/
|
||||
@@ -293,12 +280,9 @@ public:
|
||||
/**
|
||||
* Sets the client LinkLayerAddress.
|
||||
*
|
||||
* @param[in] aDuidLinkLayerAddress The client LinkLayerAddress.
|
||||
* @param[in] aAddress The client LinkLayerAddress.
|
||||
*/
|
||||
void SetDuidLinkLayerAddress(const Mac::ExtAddress &aDuidLinkLayerAddress)
|
||||
{
|
||||
mDuidLinkLayerAddress = aDuidLinkLayerAddress;
|
||||
}
|
||||
void SetDuidLinkLayerAddress(const Mac::ExtAddress &aAddress) { mDuidLinkLayerAddress = aAddress; }
|
||||
|
||||
private:
|
||||
uint16_t mDuidType;
|
||||
@@ -306,18 +290,17 @@ private:
|
||||
Mac::ExtAddress mDuidLinkLayerAddress;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Represents a Server Identifier Option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class ServerIdentifier : public Option
|
||||
class ServerIdOption : public Option
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the DHCPv6 Option.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetCode(kOptionServerIdentifier);
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
}
|
||||
void Init(void) { SetCode(kServerId), SetLength(sizeof(*this) - sizeof(Option)); }
|
||||
|
||||
/**
|
||||
* Returns the server DUID Type.
|
||||
@@ -341,31 +324,25 @@ public:
|
||||
uint16_t GetDuidHardwareType(void) const { return BigEndian::HostSwap16(mDuidHardwareType); }
|
||||
|
||||
/**
|
||||
* Sets the server DUID HardwareType.
|
||||
* Sets the server DUID Hardware Type.
|
||||
*
|
||||
* @param[in] aDuidHardwareType The server DUID HardwareType.
|
||||
* @param[in] aHardwareType The server DUID HardwareType.
|
||||
*/
|
||||
void SetDuidHardwareType(uint16_t aDuidHardwareType)
|
||||
{
|
||||
mDuidHardwareType = BigEndian::HostSwap16(aDuidHardwareType);
|
||||
}
|
||||
void SetDuidHardwareType(uint16_t aHardwareType) { mDuidHardwareType = BigEndian::HostSwap16(aHardwareType); }
|
||||
|
||||
/**
|
||||
* Returns the server LinkLayerAddress.
|
||||
* Returns the server link-layer address.
|
||||
*
|
||||
* @returns The link-layer address.
|
||||
*/
|
||||
const Mac::ExtAddress &GetDuidLinkLayerAddress(void) const { return mDuidLinkLayerAddress; }
|
||||
|
||||
/**
|
||||
* Sets the server LinkLayerAddress.
|
||||
* Sets the server link-layer address.
|
||||
*
|
||||
* @param[in] aDuidLinkLayerAddress The server LinkLayerAddress.
|
||||
* @param[in] aAddress The server link-layer address.
|
||||
*/
|
||||
void SetDuidLinkLayerAddress(const Mac::ExtAddress &aDuidLinkLayerAddress)
|
||||
{
|
||||
mDuidLinkLayerAddress = aDuidLinkLayerAddress;
|
||||
}
|
||||
void SetDuidLinkLayerAddress(const Mac::ExtAddress &aAddress) { mDuidLinkLayerAddress = aAddress; }
|
||||
|
||||
private:
|
||||
uint16_t mDuidType;
|
||||
@@ -374,10 +351,10 @@ private:
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Represents an Identity Association for Non-temporary Address DHCPv6 option.
|
||||
* Represents an Identity Association for Non-temporary Address DHCPv6 Option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class IaNa : public Option
|
||||
class IaNaOption : public Option
|
||||
{
|
||||
public:
|
||||
static constexpr uint32_t kDefaultT1 = 0xffffffffU; ///< Default T1 value.
|
||||
@@ -386,11 +363,7 @@ public:
|
||||
/**
|
||||
* Initializes the DHCPv6 Option.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetCode(kOptionIaNa);
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
}
|
||||
void Init(void) { SetCode(kIaNa), SetLength(sizeof(*this) - sizeof(Option)); }
|
||||
|
||||
/**
|
||||
* Returns client IAID.
|
||||
@@ -441,10 +414,10 @@ private:
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Represents an Identity Association Address DHCPv6 option.
|
||||
* Represents an Identity Association Address DHCPv6 Option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class IaAddress : public Option
|
||||
class IaAddressOption : public Option
|
||||
{
|
||||
public:
|
||||
static constexpr uint32_t kDefaultPreferredLifetime = 0xffffffffU; ///< Default preferred lifetime.
|
||||
@@ -453,11 +426,7 @@ public:
|
||||
/**
|
||||
* Initializes the DHCPv6 Option.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetCode(kOptionIaAddress);
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
}
|
||||
void Init(void) { SetCode(kIaAddress), SetLength(sizeof(*this) - sizeof(Option)); }
|
||||
|
||||
/**
|
||||
* Returns a reference to the IPv6 address.
|
||||
@@ -518,20 +487,16 @@ private:
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Represents an Elapsed Time DHCPv6 option.
|
||||
* Represents an Elapsed Time DHCPv6 Option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class ElapsedTime : public Option
|
||||
class ElapsedTimeOption : public Option
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the DHCPv6 Option.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetCode(kOptionElapsedTime);
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
}
|
||||
void Init(void) { SetCode(kElapsedTime), SetLength(sizeof(*this) - sizeof(Option)); }
|
||||
|
||||
/**
|
||||
* Returns the elapsed time since solicit starts.
|
||||
@@ -552,51 +517,48 @@ private:
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Status Code.
|
||||
*/
|
||||
enum Status : uint16_t
|
||||
{
|
||||
kStatusSuccess = 0,
|
||||
kStatusUnspecFail = 1,
|
||||
kStatusNoAddrsAvail = 2,
|
||||
kStatusNoBinding = 3,
|
||||
kStatusNotOnLink = 4,
|
||||
kStatusUseMulticast = 5,
|
||||
kUnknownQueryType = 7,
|
||||
kMalformedQuery = 8,
|
||||
kNotConfigured = 9,
|
||||
kNotAllowed = 10,
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents an Status Code DHCPv6 option.
|
||||
* Represents an Status Code DHCPv6 Option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class StatusCode : public Option
|
||||
class StatusCodeOption : public Option
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Status Code.
|
||||
*/
|
||||
enum Status : uint16_t
|
||||
{
|
||||
kSuccess = 0, ///< Success.
|
||||
kUnspecFail = 1, ///< Failure, reason unspecified.
|
||||
kNoAddrsAvail = 2, ///< No addresses available.
|
||||
kNoBinding = 3, ///< Client record (binding) unavailable.
|
||||
kNotOnLink = 4, ///< The prefix is not appropriate for the link.
|
||||
kUseMulticast = 5, ///< Force the client to send messages using All-DHCP multicast address.
|
||||
kNoPrefixAvail = 6, ///< Server has no prefixes available to assign.
|
||||
kUnknownQueryType = 7, ///< The query-type is unknown to or not supported by the server.
|
||||
kMalformedQuery = 8, ///< The query is not valid.
|
||||
kNotConfigured = 9, ///< The server does not have the target address or link in its configuration.
|
||||
kNotAllowed = 10, ///< The server does not allow the requestor to issue this LEASEQUERY.
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the DHCPv6 Option.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetCode(kOptionStatusCode);
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
}
|
||||
void Init(void) { SetCode(kStatusCode), SetLength(sizeof(*this) - sizeof(Option)); }
|
||||
|
||||
/**
|
||||
* Returns the status code.
|
||||
*
|
||||
* @returns The status code.
|
||||
*/
|
||||
Status GetStatusCode(void) const { return static_cast<Status>(BigEndian::HostSwap16(mStatus)); }
|
||||
uint16_t GetStatusCode(void) const { return BigEndian::HostSwap16(mStatus); }
|
||||
|
||||
/**
|
||||
* Sets the status code.
|
||||
*
|
||||
* @param[in] aStatus The status code.
|
||||
*/
|
||||
void SetStatusCode(Status aStatus) { mStatus = BigEndian::HostSwap16(static_cast<uint16_t>(aStatus)); }
|
||||
void SetStatusCode(Status aStatus) { mStatus = BigEndian::HostSwap16(aStatus); }
|
||||
|
||||
private:
|
||||
uint16_t mStatus;
|
||||
@@ -606,19 +568,19 @@ private:
|
||||
* Represents an Rapid Commit DHCPv6 option.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class RapidCommit : public Option
|
||||
class RapidCommitOption : public Option
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the DHCPv6 Option.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetCode(kOptionRapidCommit);
|
||||
SetLength(sizeof(*this) - sizeof(Option));
|
||||
}
|
||||
void Init(void) { SetCode(kRapidCommit), SetLength(sizeof(*this) - sizeof(Option)); }
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Dhcp6
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -188,8 +188,7 @@ bool Client::ProcessNextIdentityAssociation(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
// new transaction id
|
||||
IgnoreError(mTransactionId.GenerateRandom());
|
||||
mTransactionId.GenerateRandom();
|
||||
|
||||
mIdentityAssociationCurrent = &idAssociation;
|
||||
|
||||
@@ -253,12 +252,12 @@ void Client::Solicit(uint16_t aRloc16)
|
||||
VerifyOrExit((message = mSocket.NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = AppendHeader(*message));
|
||||
SuccessOrExit(error = AppendElapsedTime(*message));
|
||||
SuccessOrExit(error = AppendClientIdentifier(*message));
|
||||
SuccessOrExit(error = AppendIaNa(*message, aRloc16));
|
||||
SuccessOrExit(error = AppendElapsedTimeOption(*message));
|
||||
SuccessOrExit(error = AppendClientIdOption(*message));
|
||||
SuccessOrExit(error = AppendIaNaOption(*message, aRloc16));
|
||||
// specify which prefixes to solicit
|
||||
SuccessOrExit(error = AppendIaAddress(*message, aRloc16));
|
||||
SuccessOrExit(error = AppendRapidCommit(*message));
|
||||
SuccessOrExit(error = AppendIaAddressOption(*message, aRloc16));
|
||||
SuccessOrExit(error = AppendRapidCommitOption(*message));
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_MULTICAST_SOLICIT
|
||||
messageInfo.GetPeerAddr().SetToRealmLocalAllRoutersMulticast();
|
||||
@@ -284,24 +283,24 @@ Error Client::AppendHeader(Message &aMessage)
|
||||
Header header;
|
||||
|
||||
header.Clear();
|
||||
header.SetType(kTypeSolicit);
|
||||
header.SetMsgType(kMsgTypeSolicit);
|
||||
header.SetTransactionId(mTransactionId);
|
||||
return aMessage.Append(header);
|
||||
}
|
||||
|
||||
Error Client::AppendElapsedTime(Message &aMessage)
|
||||
Error Client::AppendElapsedTimeOption(Message &aMessage)
|
||||
{
|
||||
ElapsedTime option;
|
||||
ElapsedTimeOption option;
|
||||
|
||||
option.Init();
|
||||
option.SetElapsedTime(static_cast<uint16_t>(Time::MsecToSec(TimerMilli::GetNow() - mStartTime)));
|
||||
return aMessage.Append(option);
|
||||
}
|
||||
|
||||
Error Client::AppendClientIdentifier(Message &aMessage)
|
||||
Error Client::AppendClientIdOption(Message &aMessage)
|
||||
{
|
||||
ClientIdentifier option;
|
||||
Mac::ExtAddress eui64;
|
||||
ClientIdOption option;
|
||||
Mac::ExtAddress eui64;
|
||||
|
||||
Get<Radio>().GetIeeeEui64(eui64);
|
||||
|
||||
@@ -313,12 +312,12 @@ Error Client::AppendClientIdentifier(Message &aMessage)
|
||||
return aMessage.Append(option);
|
||||
}
|
||||
|
||||
Error Client::AppendIaNa(Message &aMessage, uint16_t aRloc16)
|
||||
Error Client::AppendIaNaOption(Message &aMessage, uint16_t aRloc16)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint8_t count = 0;
|
||||
uint16_t length = 0;
|
||||
IaNa option;
|
||||
Error error = kErrorNone;
|
||||
uint8_t count = 0;
|
||||
uint16_t length = 0;
|
||||
IaNaOption option;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationCurrent != nullptr, error = kErrorDrop);
|
||||
|
||||
@@ -336,7 +335,7 @@ Error Client::AppendIaNa(Message &aMessage, uint16_t aRloc16)
|
||||
}
|
||||
|
||||
// compute the right length
|
||||
length = sizeof(IaNa) + sizeof(IaAddress) * count - sizeof(Option);
|
||||
length = sizeof(IaNaOption) + sizeof(IaAddressOption) * count - sizeof(Option);
|
||||
|
||||
option.Init();
|
||||
option.SetLength(length);
|
||||
@@ -349,10 +348,10 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Client::AppendIaAddress(Message &aMessage, uint16_t aRloc16)
|
||||
Error Client::AppendIaAddressOption(Message &aMessage, uint16_t aRloc16)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
IaAddress option;
|
||||
Error error = kErrorNone;
|
||||
IaAddressOption option;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationCurrent, error = kErrorDrop);
|
||||
|
||||
@@ -374,9 +373,9 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Client::AppendRapidCommit(Message &aMessage)
|
||||
Error Client::AppendRapidCommitOption(Message &aMessage)
|
||||
{
|
||||
RapidCommit option;
|
||||
RapidCommitOption option;
|
||||
|
||||
option.Init();
|
||||
return aMessage.Append(option);
|
||||
@@ -391,7 +390,7 @@ void Client::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag
|
||||
SuccessOrExit(aMessage.Read(aMessage.GetOffset(), header));
|
||||
aMessage.MoveOffset(sizeof(header));
|
||||
|
||||
if ((header.GetType() == kTypeReply) && (header.GetTransactionId() == mTransactionId))
|
||||
if ((header.GetMsgType() == kMsgTypeReply) && (header.GetTransactionId() == mTransactionId))
|
||||
{
|
||||
ProcessReply(aMessage);
|
||||
}
|
||||
@@ -406,25 +405,25 @@ void Client::ProcessReply(Message &aMessage)
|
||||
uint16_t length = aMessage.GetLength() - aMessage.GetOffset();
|
||||
uint16_t optionOffset;
|
||||
|
||||
if ((optionOffset = FindOption(aMessage, offset, length, kOptionStatusCode)) > 0)
|
||||
if ((optionOffset = FindOption(aMessage, offset, length, Option::kStatusCode)) > 0)
|
||||
{
|
||||
SuccessOrExit(ProcessStatusCode(aMessage, optionOffset));
|
||||
SuccessOrExit(ProcessStatusCodeOption(aMessage, optionOffset));
|
||||
}
|
||||
|
||||
// Server Identifier
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, kOptionServerIdentifier)) > 0);
|
||||
SuccessOrExit(ProcessServerIdentifier(aMessage, optionOffset));
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, Option::kServerId)) > 0);
|
||||
SuccessOrExit(ProcessServerIdOption(aMessage, optionOffset));
|
||||
|
||||
// Client Identifier
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, kOptionClientIdentifier)) > 0);
|
||||
SuccessOrExit(ProcessClientIdentifier(aMessage, optionOffset));
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, Option::kClientId)) > 0);
|
||||
SuccessOrExit(ProcessClientIdOption(aMessage, optionOffset));
|
||||
|
||||
// Rapid Commit
|
||||
VerifyOrExit(FindOption(aMessage, offset, length, kOptionRapidCommit) > 0);
|
||||
VerifyOrExit(FindOption(aMessage, offset, length, Option::kRapidCommit) > 0);
|
||||
|
||||
// IA_NA
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, kOptionIaNa)) > 0);
|
||||
SuccessOrExit(ProcessIaNa(aMessage, optionOffset));
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, Option::kIaNa)) > 0);
|
||||
SuccessOrExit(ProcessIaNaOption(aMessage, optionOffset));
|
||||
|
||||
HandleTrickleTimer();
|
||||
|
||||
@@ -432,7 +431,7 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t Client::FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Dhcp6::Code aCode)
|
||||
uint16_t Client::FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Option::Code aCode)
|
||||
{
|
||||
uint32_t offset = aOffset;
|
||||
uint16_t end = aOffset + aLength;
|
||||
@@ -456,10 +455,10 @@ exit:
|
||||
return rval;
|
||||
}
|
||||
|
||||
Error Client::ProcessServerIdentifier(Message &aMessage, uint16_t aOffset)
|
||||
Error Client::ProcessServerIdOption(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
ServerIdentifier option;
|
||||
Error error = kErrorNone;
|
||||
ServerIdOption option;
|
||||
|
||||
SuccessOrExit(aMessage.Read(aOffset, option));
|
||||
VerifyOrExit(((option.GetDuidType() == kDuidLinkLayerAddressPlusTime) &&
|
||||
@@ -472,11 +471,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Client::ProcessClientIdentifier(Message &aMessage, uint16_t aOffset)
|
||||
Error Client::ProcessClientIdOption(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
ClientIdentifier option;
|
||||
Mac::ExtAddress eui64;
|
||||
Error error = kErrorNone;
|
||||
ClientIdOption option;
|
||||
Mac::ExtAddress eui64;
|
||||
|
||||
Get<Radio>().GetIeeeEui64(eui64);
|
||||
|
||||
@@ -489,12 +488,12 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Client::ProcessIaNa(Message &aMessage, uint16_t aOffset)
|
||||
Error Client::ProcessIaNaOption(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
IaNa option;
|
||||
uint16_t optionOffset;
|
||||
uint16_t length;
|
||||
Error error = kErrorNone;
|
||||
IaNaOption option;
|
||||
uint16_t optionOffset;
|
||||
uint16_t length;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, option));
|
||||
|
||||
@@ -503,45 +502,46 @@ Error Client::ProcessIaNa(Message &aMessage, uint16_t aOffset)
|
||||
|
||||
VerifyOrExit(length <= aMessage.GetLength() - aOffset, error = kErrorParse);
|
||||
|
||||
if ((optionOffset = FindOption(aMessage, aOffset, length, kOptionStatusCode)) > 0)
|
||||
if ((optionOffset = FindOption(aMessage, aOffset, length, Option::kStatusCode)) > 0)
|
||||
{
|
||||
SuccessOrExit(error = ProcessStatusCode(aMessage, optionOffset));
|
||||
SuccessOrExit(error = ProcessStatusCodeOption(aMessage, optionOffset));
|
||||
}
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
if ((optionOffset = FindOption(aMessage, aOffset, length, kOptionIaAddress)) == 0)
|
||||
if ((optionOffset = FindOption(aMessage, aOffset, length, Option::kIaAddress)) == 0)
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
SuccessOrExit(error = ProcessIaAddress(aMessage, optionOffset));
|
||||
SuccessOrExit(error = ProcessIaAddressOption(aMessage, optionOffset));
|
||||
|
||||
length -= ((optionOffset - aOffset) + sizeof(IaAddress));
|
||||
aOffset = optionOffset + sizeof(IaAddress);
|
||||
length -= ((optionOffset - aOffset) + sizeof(IaAddressOption));
|
||||
aOffset = optionOffset + sizeof(IaAddressOption);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Client::ProcessStatusCode(Message &aMessage, uint16_t aOffset)
|
||||
Error Client::ProcessStatusCodeOption(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
StatusCode option;
|
||||
Error error = kErrorNone;
|
||||
StatusCodeOption option;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, option));
|
||||
VerifyOrExit((option.GetLength() >= sizeof(option) - sizeof(Option)) && (option.GetStatusCode() == kStatusSuccess),
|
||||
VerifyOrExit((option.GetLength() >= sizeof(option) - sizeof(Option)) &&
|
||||
(option.GetStatusCode() == StatusCodeOption::kSuccess),
|
||||
error = kErrorParse);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Client::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
|
||||
Error Client::ProcessIaAddressOption(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
Error error;
|
||||
IaAddress option;
|
||||
Error error;
|
||||
IaAddressOption option;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, option));
|
||||
VerifyOrExit(option.GetLength() == sizeof(option) - sizeof(Option), error = kErrorParse);
|
||||
|
||||
@@ -110,21 +110,21 @@ private:
|
||||
bool ProcessNextIdentityAssociation(void);
|
||||
|
||||
Error AppendHeader(Message &aMessage);
|
||||
Error AppendClientIdentifier(Message &aMessage);
|
||||
Error AppendIaNa(Message &aMessage, uint16_t aRloc16);
|
||||
Error AppendIaAddress(Message &aMessage, uint16_t aRloc16);
|
||||
Error AppendElapsedTime(Message &aMessage);
|
||||
Error AppendRapidCommit(Message &aMessage);
|
||||
Error AppendClientIdOption(Message &aMessage);
|
||||
Error AppendIaNaOption(Message &aMessage, uint16_t aRloc16);
|
||||
Error AppendIaAddressOption(Message &aMessage, uint16_t aRloc16);
|
||||
Error AppendElapsedTimeOption(Message &aMessage);
|
||||
Error AppendRapidCommitOption(Message &aMessage);
|
||||
|
||||
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
void ProcessReply(Message &aMessage);
|
||||
uint16_t FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Code aCode);
|
||||
Error ProcessServerIdentifier(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessClientIdentifier(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessIaNa(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessStatusCode(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessIaAddress(Message &aMessage, uint16_t aOffset);
|
||||
uint16_t FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Option::Code aCode);
|
||||
Error ProcessServerIdOption(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessClientIdOption(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessIaNaOption(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessStatusCodeOption(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessIaAddressOption(Message &aMessage, uint16_t aOffset);
|
||||
|
||||
static void HandleTrickleTimer(TrickleTimer &aTrickleTimer);
|
||||
void HandleTrickleTimer(void);
|
||||
|
||||
@@ -175,8 +175,7 @@ void Server::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag
|
||||
SuccessOrExit(aMessage.Read(aMessage.GetOffset(), header));
|
||||
aMessage.MoveOffset(sizeof(header));
|
||||
|
||||
// discard if not solicit type
|
||||
VerifyOrExit((header.GetType() == kTypeSolicit));
|
||||
VerifyOrExit((header.GetMsgType() == kMsgTypeSolicit));
|
||||
|
||||
ProcessSolicit(aMessage, aMessageInfo.GetPeerAddr(), header.GetTransactionId());
|
||||
|
||||
@@ -186,31 +185,31 @@ exit:
|
||||
|
||||
void Server::ProcessSolicit(Message &aMessage, const Ip6::Address &aDst, const TransactionId &aTransactionId)
|
||||
{
|
||||
IaNa iana;
|
||||
ClientIdentifier clientIdentifier;
|
||||
uint16_t optionOffset;
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
uint16_t length = aMessage.GetLength() - aMessage.GetOffset();
|
||||
IaNaOption iana;
|
||||
ClientIdOption clientIdentifier;
|
||||
uint16_t optionOffset;
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
uint16_t length = aMessage.GetLength() - aMessage.GetOffset();
|
||||
|
||||
// Client Identifier (discard if not present)
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, kOptionClientIdentifier)) > 0);
|
||||
SuccessOrExit(ProcessClientIdentifier(aMessage, optionOffset, clientIdentifier));
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, Option::kClientId)) > 0);
|
||||
SuccessOrExit(ProcessClientIdOption(aMessage, optionOffset, clientIdentifier));
|
||||
|
||||
// Server Identifier (assuming Rapid Commit, discard if present)
|
||||
VerifyOrExit(FindOption(aMessage, offset, length, kOptionServerIdentifier) == 0);
|
||||
VerifyOrExit(FindOption(aMessage, offset, length, Option::kServerId) == 0);
|
||||
|
||||
// Rapid Commit (assuming Rapid Commit, discard if not present)
|
||||
VerifyOrExit(FindOption(aMessage, offset, length, kOptionRapidCommit) > 0);
|
||||
VerifyOrExit(FindOption(aMessage, offset, length, Option::kRapidCommit) > 0);
|
||||
|
||||
// Elapsed Time if present
|
||||
if ((optionOffset = FindOption(aMessage, offset, length, kOptionElapsedTime)) > 0)
|
||||
if ((optionOffset = FindOption(aMessage, offset, length, Option::kElapsedTime)) > 0)
|
||||
{
|
||||
SuccessOrExit(ProcessElapsedTime(aMessage, optionOffset));
|
||||
SuccessOrExit(ProcessElapsedTimeOption(aMessage, optionOffset));
|
||||
}
|
||||
|
||||
// IA_NA (discard if not present)
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, kOptionIaNa)) > 0);
|
||||
SuccessOrExit(ProcessIaNa(aMessage, optionOffset, iana));
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, offset, length, Option::kIaNa)) > 0);
|
||||
SuccessOrExit(ProcessIaNaOption(aMessage, optionOffset, iana));
|
||||
|
||||
SuccessOrExit(SendReply(aDst, aTransactionId, clientIdentifier, iana));
|
||||
|
||||
@@ -218,7 +217,7 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t Server::FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Code aCode)
|
||||
uint16_t Server::FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Option::Code aCode)
|
||||
{
|
||||
uint16_t end = aOffset + aLength;
|
||||
uint16_t rval = 0;
|
||||
@@ -240,23 +239,23 @@ uint16_t Server::FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLengt
|
||||
exit:
|
||||
return rval;
|
||||
}
|
||||
Error Server::ProcessClientIdentifier(Message &aMessage, uint16_t aOffset, ClientIdentifier &aClientId)
|
||||
Error Server::ProcessClientIdOption(Message &aMessage, uint16_t aOffset, ClientIdOption &aClientIdOption)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, aClientId));
|
||||
VerifyOrExit((aClientId.GetLength() == sizeof(aClientId) - sizeof(Option)) &&
|
||||
(aClientId.GetDuidType() == kDuidLinkLayerAddress) &&
|
||||
(aClientId.GetDuidHardwareType() == kHardwareTypeEui64),
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, aClientIdOption));
|
||||
VerifyOrExit((aClientIdOption.GetLength() == sizeof(aClientIdOption) - sizeof(Option)) &&
|
||||
(aClientIdOption.GetDuidType() == kDuidLinkLayerAddress) &&
|
||||
(aClientIdOption.GetDuidHardwareType() == kHardwareTypeEui64),
|
||||
error = kErrorParse);
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Server::ProcessElapsedTime(Message &aMessage, uint16_t aOffset)
|
||||
Error Server::ProcessElapsedTimeOption(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
ElapsedTime option;
|
||||
Error error = kErrorNone;
|
||||
ElapsedTimeOption option;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, option));
|
||||
VerifyOrExit(option.GetLength() == sizeof(option) - sizeof(Option), error = kErrorParse);
|
||||
@@ -264,16 +263,16 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Server::ProcessIaNa(Message &aMessage, uint16_t aOffset, IaNa &aIaNa)
|
||||
Error Server::ProcessIaNaOption(Message &aMessage, uint16_t aOffset, IaNaOption &aIaNaOption)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint16_t optionOffset;
|
||||
uint16_t length;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, aIaNa));
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, aIaNaOption));
|
||||
|
||||
aOffset += sizeof(aIaNa);
|
||||
length = aIaNa.GetLength() + sizeof(Option) - sizeof(IaNa);
|
||||
aOffset += sizeof(aIaNaOption);
|
||||
length = aIaNaOption.GetLength() + sizeof(Option) - sizeof(IaNaOption);
|
||||
|
||||
VerifyOrExit(length <= aMessage.GetLength() - aOffset, error = kErrorParse);
|
||||
|
||||
@@ -281,21 +280,21 @@ Error Server::ProcessIaNa(Message &aMessage, uint16_t aOffset, IaNa &aIaNa)
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, aOffset, length, kOptionIaAddress)) > 0);
|
||||
SuccessOrExit(error = ProcessIaAddress(aMessage, optionOffset));
|
||||
VerifyOrExit((optionOffset = FindOption(aMessage, aOffset, length, Option::kIaAddress)) > 0);
|
||||
SuccessOrExit(error = ProcessIaAddressOption(aMessage, optionOffset));
|
||||
|
||||
length -= ((optionOffset - aOffset) + sizeof(IaAddress));
|
||||
aOffset = optionOffset + sizeof(IaAddress);
|
||||
length -= ((optionOffset - aOffset) + sizeof(IaAddressOption));
|
||||
aOffset = optionOffset + sizeof(IaAddressOption);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Server::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
|
||||
Error Server::ProcessIaAddressOption(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
IaAddress option;
|
||||
Error error = kErrorNone;
|
||||
IaAddressOption option;
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aOffset, option));
|
||||
VerifyOrExit(option.GetLength() == sizeof(option) - sizeof(Option), error = kErrorParse);
|
||||
@@ -316,8 +315,8 @@ exit:
|
||||
|
||||
Error Server::SendReply(const Ip6::Address &aDst,
|
||||
const TransactionId &aTransactionId,
|
||||
ClientIdentifier &aClientId,
|
||||
IaNa &aIaNa)
|
||||
ClientIdOption &aClientIdOption,
|
||||
IaNaOption &aIaNaOption)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Ip6::MessageInfo messageInfo;
|
||||
@@ -325,12 +324,12 @@ Error Server::SendReply(const Ip6::Address &aDst,
|
||||
|
||||
VerifyOrExit((message = mSocket.NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
SuccessOrExit(error = AppendHeader(*message, aTransactionId));
|
||||
SuccessOrExit(error = AppendServerIdentifier(*message));
|
||||
SuccessOrExit(error = AppendClientIdentifier(*message, aClientId));
|
||||
SuccessOrExit(error = AppendIaNa(*message, aIaNa));
|
||||
SuccessOrExit(error = AppendStatusCode(*message, kStatusSuccess));
|
||||
SuccessOrExit(error = AppendIaAddress(*message, aClientId));
|
||||
SuccessOrExit(error = AppendRapidCommit(*message));
|
||||
SuccessOrExit(error = AppendServerIdOption(*message));
|
||||
SuccessOrExit(error = AppendClientIdOption(*message, aClientIdOption));
|
||||
SuccessOrExit(error = AppendIaNaOption(*message, aIaNaOption));
|
||||
SuccessOrExit(error = AppendStatusCodeOption(*message, StatusCodeOption::kSuccess));
|
||||
SuccessOrExit(error = AppendIaAddressOption(*message, aClientIdOption));
|
||||
SuccessOrExit(error = AppendRapidCommitOption(*message));
|
||||
|
||||
messageInfo.SetPeerAddr(aDst);
|
||||
messageInfo.SetPeerPort(kDhcpClientPort);
|
||||
@@ -346,21 +345,21 @@ Error Server::AppendHeader(Message &aMessage, const TransactionId &aTransactionI
|
||||
Header header;
|
||||
|
||||
header.Clear();
|
||||
header.SetType(kTypeReply);
|
||||
header.SetMsgType(kMsgTypeReply);
|
||||
header.SetTransactionId(aTransactionId);
|
||||
return aMessage.Append(header);
|
||||
}
|
||||
|
||||
Error Server::AppendClientIdentifier(Message &aMessage, ClientIdentifier &aClientId)
|
||||
Error Server::AppendClientIdOption(Message &aMessage, ClientIdOption &aClientIdOption)
|
||||
{
|
||||
return aMessage.Append(aClientId);
|
||||
return aMessage.Append(aClientIdOption);
|
||||
}
|
||||
|
||||
Error Server::AppendServerIdentifier(Message &aMessage)
|
||||
Error Server::AppendServerIdOption(Message &aMessage)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
ServerIdentifier option;
|
||||
Mac::ExtAddress eui64;
|
||||
Error error = kErrorNone;
|
||||
ServerIdOption option;
|
||||
Mac::ExtAddress eui64;
|
||||
|
||||
Get<Radio>().GetIeeeEui64(eui64);
|
||||
|
||||
@@ -374,7 +373,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Server::AppendIaNa(Message &aMessage, IaNa &aIaNa)
|
||||
Error Server::AppendIaNaOption(Message &aMessage, IaNaOption &aIaNaOption)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
uint16_t length = 0;
|
||||
@@ -385,36 +384,36 @@ Error Server::AppendIaNa(Message &aMessage, IaNa &aIaNa)
|
||||
{
|
||||
if (mPrefixAgentsMask & (1 << i))
|
||||
{
|
||||
length += sizeof(IaAddress);
|
||||
length += sizeof(IaAddressOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
length += sizeof(IaAddress) * mPrefixAgentsCount;
|
||||
length += sizeof(IaAddressOption) * mPrefixAgentsCount;
|
||||
}
|
||||
|
||||
length += sizeof(IaNa) + sizeof(StatusCode) - sizeof(Option);
|
||||
length += sizeof(IaNaOption) + sizeof(StatusCodeOption) - sizeof(Option);
|
||||
|
||||
aIaNa.SetLength(length);
|
||||
aIaNa.SetT1(IaNa::kDefaultT1);
|
||||
aIaNa.SetT2(IaNa::kDefaultT2);
|
||||
SuccessOrExit(error = aMessage.Append(aIaNa));
|
||||
aIaNaOption.SetLength(length);
|
||||
aIaNaOption.SetT1(IaNaOption::kDefaultT1);
|
||||
aIaNaOption.SetT2(IaNaOption::kDefaultT2);
|
||||
SuccessOrExit(error = aMessage.Append(aIaNaOption));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Server::AppendStatusCode(Message &aMessage, Status aStatusCode)
|
||||
Error Server::AppendStatusCodeOption(Message &aMessage, StatusCodeOption::Status aStatusCode)
|
||||
{
|
||||
StatusCode option;
|
||||
StatusCodeOption option;
|
||||
|
||||
option.Init();
|
||||
option.SetStatusCode(aStatusCode);
|
||||
return aMessage.Append(option);
|
||||
}
|
||||
|
||||
Error Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClientId)
|
||||
Error Server::AppendIaAddressOption(Message &aMessage, ClientIdOption &aClientIdOption)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
@@ -425,7 +424,8 @@ Error Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClientId)
|
||||
{
|
||||
if (mPrefixAgentsMask & (1 << i))
|
||||
{
|
||||
SuccessOrExit(error = AddIaAddress(aMessage, mPrefixAgents[i].GetPrefixAsAddress(), aClientId));
|
||||
SuccessOrExit(error =
|
||||
AddIaAddressOption(aMessage, mPrefixAgents[i].GetPrefixAsAddress(), aClientIdOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,7 +436,7 @@ Error Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClientId)
|
||||
{
|
||||
if (prefixAgent.IsValid())
|
||||
{
|
||||
SuccessOrExit(error = AddIaAddress(aMessage, prefixAgent.GetPrefixAsAddress(), aClientId));
|
||||
SuccessOrExit(error = AddIaAddressOption(aMessage, prefixAgent.GetPrefixAsAddress(), aClientIdOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,25 +445,25 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Server::AddIaAddress(Message &aMessage, const Ip6::Address &aPrefix, ClientIdentifier &aClientId)
|
||||
Error Server::AddIaAddressOption(Message &aMessage, const Ip6::Address &aPrefix, ClientIdOption &aClientIdOption)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
IaAddress option;
|
||||
Error error = kErrorNone;
|
||||
IaAddressOption option;
|
||||
|
||||
option.Init();
|
||||
option.GetAddress().SetPrefix(aPrefix.mFields.m8, OT_IP6_PREFIX_BITSIZE);
|
||||
option.GetAddress().GetIid().SetFromExtAddress(aClientId.GetDuidLinkLayerAddress());
|
||||
option.SetPreferredLifetime(IaAddress::kDefaultPreferredLifetime);
|
||||
option.SetValidLifetime(IaAddress::kDefaultValidLifetime);
|
||||
option.GetAddress().GetIid().SetFromExtAddress(aClientIdOption.GetDuidLinkLayerAddress());
|
||||
option.SetPreferredLifetime(IaAddressOption::kDefaultPreferredLifetime);
|
||||
option.SetValidLifetime(IaAddressOption::kDefaultValidLifetime);
|
||||
SuccessOrExit(error = aMessage.Append(option));
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Server::AppendRapidCommit(Message &aMessage)
|
||||
Error Server::AppendRapidCommitOption(Message &aMessage)
|
||||
{
|
||||
RapidCommit option;
|
||||
RapidCommitOption option;
|
||||
|
||||
option.Init();
|
||||
return aMessage.Append(option);
|
||||
|
||||
@@ -171,28 +171,28 @@ private:
|
||||
void AddPrefixAgent(const Ip6::Prefix &aIp6Prefix, const Lowpan::Context &aContext);
|
||||
|
||||
Error AppendHeader(Message &aMessage, const TransactionId &aTransactionId);
|
||||
Error AppendClientIdentifier(Message &aMessage, ClientIdentifier &aClientId);
|
||||
Error AppendServerIdentifier(Message &aMessage);
|
||||
Error AppendIaNa(Message &aMessage, IaNa &aIaNa);
|
||||
Error AppendStatusCode(Message &aMessage, Status aStatusCode);
|
||||
Error AppendIaAddress(Message &aMessage, ClientIdentifier &aClientId);
|
||||
Error AppendRapidCommit(Message &aMessage);
|
||||
Error AppendClientIdOption(Message &aMessage, ClientIdOption &aClientIdOption);
|
||||
Error AppendServerIdOption(Message &aMessage);
|
||||
Error AppendIaNaOption(Message &aMessage, IaNaOption &aIaNaOption);
|
||||
Error AppendStatusCodeOption(Message &aMessage, StatusCodeOption::Status aStatusCode);
|
||||
Error AppendIaAddressOption(Message &aMessage, ClientIdOption &aClientIdOption);
|
||||
Error AppendRapidCommitOption(Message &aMessage);
|
||||
Error AppendVendorSpecificInformation(Message &aMessage);
|
||||
|
||||
Error AddIaAddress(Message &aMessage, const Ip6::Address &aPrefix, ClientIdentifier &aClientId);
|
||||
Error AddIaAddressOption(Message &aMessage, const Ip6::Address &aPrefix, ClientIdOption &aClientIdOption);
|
||||
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
void ProcessSolicit(Message &aMessage, const Ip6::Address &aDst, const TransactionId &aTransactionId);
|
||||
|
||||
uint16_t FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Code aCode);
|
||||
Error ProcessClientIdentifier(Message &aMessage, uint16_t aOffset, ClientIdentifier &aClientId);
|
||||
Error ProcessIaNa(Message &aMessage, uint16_t aOffset, IaNa &aIaNa);
|
||||
Error ProcessIaAddress(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessElapsedTime(Message &aMessage, uint16_t aOffset);
|
||||
uint16_t FindOption(Message &aMessage, uint16_t aOffset, uint16_t aLength, Option::Code aCode);
|
||||
Error ProcessClientIdOption(Message &aMessage, uint16_t aOffset, ClientIdOption &aClientIdOption);
|
||||
Error ProcessIaNaOption(Message &aMessage, uint16_t aOffset, IaNaOption &aIaNaOption);
|
||||
Error ProcessIaAddressOption(Message &aMessage, uint16_t aOffset);
|
||||
Error ProcessElapsedTimeOption(Message &aMessage, uint16_t aOffset);
|
||||
|
||||
Error SendReply(const Ip6::Address &aDst,
|
||||
const TransactionId &aTransactionId,
|
||||
ClientIdentifier &aClientId,
|
||||
IaNa &aIaNa);
|
||||
ClientIdOption &aClientIdOption,
|
||||
IaNaOption &aIaNaOption);
|
||||
|
||||
using ServerSocket = Ip6::Udp::SocketIn<Server, &Server::HandleUdpReceive>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user