dhcpv6_client.c File Reference

DHCPv6 client (Dynamic Host Configuration Protocol for IPv6) More...

#include <stdlib.h>
#include "core/net.h"
#include "ipv6/ipv6.h"
#include "ipv6/ipv6_misc.h"
#include "ipv6/ndp.h"
#include "dhcpv6/dhcpv6_client.h"
#include "dhcpv6/dhcpv6_common.h"
#include "dhcpv6/dhcpv6_debug.h"
#include "dns/dns_common.h"
#include "date_time.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   DHCPV6_TRACE_LEVEL
 

Functions

void dhcpv6ClientGetDefaultSettings (Dhcpv6ClientSettings *settings)
 Initialize settings with default values. More...
 
error_t dhcpv6ClientInit (Dhcpv6ClientContext *context, const Dhcpv6ClientSettings *settings)
 DHCPv6 client initialization. More...
 
error_t dhcpv6ClientStart (Dhcpv6ClientContext *context)
 Start DHCPv6 client. More...
 
error_t dhcpv6ClientStop (Dhcpv6ClientContext *context)
 Stop DHCPv6 client. More...
 
error_t dhcpv6ClientRelease (Dhcpv6ClientContext *context)
 Release DHCPv6 lease. More...
 
Dhcpv6State dhcpv6ClientGetState (Dhcpv6ClientContext *context)
 Retrieve current state. More...
 
void dhcpv6ClientTick (Dhcpv6ClientContext *context)
 DHCPv6 client timer handler. More...
 
void dhcpv6ClientLinkChangeEvent (Dhcpv6ClientContext *context)
 Callback function for link change event. More...
 
void dhcpv6ClientStateInit (Dhcpv6ClientContext *context)
 INIT state. More...
 
void dhcpv6ClientStateSolicit (Dhcpv6ClientContext *context)
 SOLICIT state. More...
 
void dhcpv6ClientStateRequest (Dhcpv6ClientContext *context)
 REQUEST state. More...
 
void dhcpv6ClientStateInitConfirm (Dhcpv6ClientContext *context)
 INIT-CONFIRM state. More...
 
void dhcpv6ClientStateConfirm (Dhcpv6ClientContext *context)
 CONFIRM state. More...
 
void dhcpv6ClientStateDad (Dhcpv6ClientContext *context)
 DAD state. More...
 
void dhcpv6ClientStateBound (Dhcpv6ClientContext *context)
 BOUND state. More...
 
void dhcpv6ClientStateRenew (Dhcpv6ClientContext *context)
 RENEW state. More...
 
void dhcpv6ClientStateRebind (Dhcpv6ClientContext *context)
 REBIND state. More...
 
void dhcpv6ClientStateRelease (Dhcpv6ClientContext *context)
 RELEASE state. More...
 
void dhcpv6ClientStateDecline (Dhcpv6ClientContext *context)
 DECLINE state. More...
 
error_t dhcpv6ClientSendMessage (Dhcpv6ClientContext *context, Dhcpv6MessageType type)
 Send Solicit message. More...
 
void dhcpv6ClientProcessMessage (NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *param)
 Process incoming DHCPv6 message. More...
 
void dhcpv6ClientParseAdvertise (Dhcpv6ClientContext *context, const Dhcpv6Message *message, size_t length)
 Parse Advertise message. More...
 
void dhcpv6ClientParseReply (Dhcpv6ClientContext *context, const Dhcpv6Message *message, size_t length)
 Parse Reply message. More...
 
error_t dhcpv6ClientParseIaNaOption (Dhcpv6ClientContext *context, const Dhcpv6Option *option)
 Parse IA_NA option. More...
 
error_t dhcpv6ClientParseIaAddrOption (Dhcpv6ClientContext *context, const Dhcpv6Option *option)
 Parse IA Address option. More...
 
void dhcpv6ClientAddAddr (Dhcpv6ClientContext *context, const Ipv6Addr *addr, uint32_t validLifetime, uint32_t preferredLifetime)
 Add an IPv6 address to the IA. More...
 
void dhcpv6ClientRemoveAddr (Dhcpv6ClientContext *context, const Ipv6Addr *addr)
 Remove an IPv6 address from the IA. More...
 
void dhcpv6ClientFlushAddrList (Dhcpv6ClientContext *context)
 Flush the list of IPv6 addresses from the IA. More...
 
error_t dhcpv6ClientGenerateDuid (Dhcpv6ClientContext *context)
 Generate client's DUID. More...
 
error_t dhcpv6ClientGenerateFqdn (Dhcpv6ClientContext *context)
 Generate client's fully qualified domain name. More...
 
error_t dhcpv6ClientGenerateLinkLocalAddr (Dhcpv6ClientContext *context)
 Generate a link-local address. More...
 
bool_t dhcpv6ClientCheckServerId (Dhcpv6ClientContext *context, Dhcpv6Option *serverIdOption)
 Check the Server Identifier option. More...
 
void dhcpv6ClientCheckTimeout (Dhcpv6ClientContext *context)
 Manage DHCPv6 configuration timeout. More...
 
uint16_t dhcpv6ClientComputeElapsedTime (Dhcpv6ClientContext *context)
 Compute the time elapsed since the client sent the first message. More...
 
void dhcpv6ClientChangeState (Dhcpv6ClientContext *context, Dhcpv6State newState, systime_t delay)
 Update DHCPv6 FSM state. More...
 
void dhcpv6ClientDumpConfig (Dhcpv6ClientContext *context)
 Dump DHCPv6 configuration for debugging purpose. More...
 

Variables

systime_t dhcpv6ClientTickCounter
 

Detailed Description

DHCPv6 client (Dynamic Host Configuration Protocol for IPv6)

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

The Dynamic Host Configuration Protocol for IPv6 enables DHCP servers to pass configuration parameters such as IPv6 network addresses to IPv6 nodes. This protocol is a stateful counterpart to IPv6 Stateless Address Autoconfiguration (RFC 2462), and can be used separately or concurrently with the latter to obtain configuration parameters. Refer to RFC 3315

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file dhcpv6_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   DHCPV6_TRACE_LEVEL

Definition at line 38 of file dhcpv6_client.c.

Function Documentation

◆ dhcpv6ClientAddAddr()

void dhcpv6ClientAddAddr ( Dhcpv6ClientContext context,
const Ipv6Addr addr,
uint32_t  validLifetime,
uint32_t  preferredLifetime 
)

Add an IPv6 address to the IA.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]addrIPv6 address to be added
[in]validLifetimeValid lifetime, in seconds
[in]preferredLifetimePreferred lifetime, in seconds

Definition at line 2154 of file dhcpv6_client.c.

◆ dhcpv6ClientChangeState()

void dhcpv6ClientChangeState ( Dhcpv6ClientContext context,
Dhcpv6State  newState,
systime_t  delay 
)

Update DHCPv6 FSM state.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]newStateNew DHCPv6 state to switch to
[in]delayInitial delay

Definition at line 2504 of file dhcpv6_client.c.

◆ dhcpv6ClientCheckServerId()

bool_t dhcpv6ClientCheckServerId ( Dhcpv6ClientContext context,
Dhcpv6Option serverIdOption 
)

Check the Server Identifier option.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]serverIdOptionPointer to the Server Identifier option
Returns
TRUE if the option matches the server’s DUID, else FALSE

Definition at line 2407 of file dhcpv6_client.c.

◆ dhcpv6ClientCheckTimeout()

void dhcpv6ClientCheckTimeout ( Dhcpv6ClientContext context)

Manage DHCPv6 configuration timeout.

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 2430 of file dhcpv6_client.c.

◆ dhcpv6ClientComputeElapsedTime()

uint16_t dhcpv6ClientComputeElapsedTime ( Dhcpv6ClientContext context)

Compute the time elapsed since the client sent the first message.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
The elapsed time expressed in hundredths of a second

Definition at line 2471 of file dhcpv6_client.c.

◆ dhcpv6ClientDumpConfig()

void dhcpv6ClientDumpConfig ( Dhcpv6ClientContext context)

Dump DHCPv6 configuration for debugging purpose.

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 2570 of file dhcpv6_client.c.

◆ dhcpv6ClientFlushAddrList()

void dhcpv6ClientFlushAddrList ( Dhcpv6ClientContext context)

Flush the list of IPv6 addresses from the IA.

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 2246 of file dhcpv6_client.c.

◆ dhcpv6ClientGenerateDuid()

error_t dhcpv6ClientGenerateDuid ( Dhcpv6ClientContext context)

Generate client's DUID.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
Error code

Definition at line 2281 of file dhcpv6_client.c.

◆ dhcpv6ClientGenerateFqdn()

error_t dhcpv6ClientGenerateFqdn ( Dhcpv6ClientContext context)

Generate client's fully qualified domain name.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
Error code

Definition at line 2324 of file dhcpv6_client.c.

◆ dhcpv6ClientGenerateLinkLocalAddr()

error_t dhcpv6ClientGenerateLinkLocalAddr ( Dhcpv6ClientContext context)

Generate a link-local address.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
Error code

Definition at line 2356 of file dhcpv6_client.c.

◆ dhcpv6ClientGetDefaultSettings()

void dhcpv6ClientGetDefaultSettings ( Dhcpv6ClientSettings settings)

Initialize settings with default values.

Parameters
[out]settingsStructure that contains DHCPv6 client settings

Definition at line 73 of file dhcpv6_client.c.

◆ dhcpv6ClientGetState()

Dhcpv6State dhcpv6ClientGetState ( Dhcpv6ClientContext context)

Retrieve current state.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
Current DHCPv6 client state

Definition at line 313 of file dhcpv6_client.c.

◆ dhcpv6ClientInit()

error_t dhcpv6ClientInit ( Dhcpv6ClientContext context,
const Dhcpv6ClientSettings settings 
)

DHCPv6 client initialization.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]settingsDHCPv6 client specific settings
Returns
Error code

Definition at line 100 of file dhcpv6_client.c.

◆ dhcpv6ClientLinkChangeEvent()

void dhcpv6ClientLinkChangeEvent ( Dhcpv6ClientContext context)

Callback function for link change event.

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 434 of file dhcpv6_client.c.

◆ dhcpv6ClientParseAdvertise()

void dhcpv6ClientParseAdvertise ( Dhcpv6ClientContext context,
const Dhcpv6Message message,
size_t  length 
)

Parse Advertise message.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]messagePointer to the incoming message to parse
[in]lengthLength of the incoming message

Definition at line 1495 of file dhcpv6_client.c.

◆ dhcpv6ClientParseIaAddrOption()

error_t dhcpv6ClientParseIaAddrOption ( Dhcpv6ClientContext context,
const Dhcpv6Option option 
)

Parse IA Address option.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]optionPointer to the IA Address option to parse
Returns
Error code

Definition at line 2092 of file dhcpv6_client.c.

◆ dhcpv6ClientParseIaNaOption()

error_t dhcpv6ClientParseIaNaOption ( Dhcpv6ClientContext context,
const Dhcpv6Option option 
)

Parse IA_NA option.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]optionPointer to the IA_NA option to parse
Returns
Error code

Definition at line 1979 of file dhcpv6_client.c.

◆ dhcpv6ClientParseReply()

void dhcpv6ClientParseReply ( Dhcpv6ClientContext context,
const Dhcpv6Message message,
size_t  length 
)

Parse Reply message.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]messagePointer to the incoming message to parse
[in]lengthLength of the incoming message

Definition at line 1654 of file dhcpv6_client.c.

◆ dhcpv6ClientProcessMessage()

void dhcpv6ClientProcessMessage ( NetInterface interface,
const IpPseudoHeader pseudoHeader,
const UdpHeader udpHeader,
const NetBuffer buffer,
size_t  offset,
void *  param 
)

Process incoming DHCPv6 message.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderUDP pseudo header
[in]udpHeaderUDP header
[in]bufferMulti-part buffer containing the incoming DHCPv6 message
[in]offsetOffset to the first byte of the DHCPv6 message
[in]paramPointer to the DHCPv6 client context

Definition at line 1439 of file dhcpv6_client.c.

◆ dhcpv6ClientRelease()

error_t dhcpv6ClientRelease ( Dhcpv6ClientContext context)

Release DHCPv6 lease.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
Error code

Definition at line 247 of file dhcpv6_client.c.

◆ dhcpv6ClientRemoveAddr()

void dhcpv6ClientRemoveAddr ( Dhcpv6ClientContext context,
const Ipv6Addr addr 
)

Remove an IPv6 address from the IA.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]addrIPv6 address to be removed

Definition at line 2208 of file dhcpv6_client.c.

◆ dhcpv6ClientSendMessage()

error_t dhcpv6ClientSendMessage ( Dhcpv6ClientContext context,
Dhcpv6MessageType  type 
)

Send Solicit message.

Parameters
[in]contextPointer to the DHCPv6 client context
[in]typeDHCPv6 message type
Returns
Error code

Definition at line 1242 of file dhcpv6_client.c.

◆ dhcpv6ClientStart()

error_t dhcpv6ClientStart ( Dhcpv6ClientContext context)

Start DHCPv6 client.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
Error code

Definition at line 162 of file dhcpv6_client.c.

◆ dhcpv6ClientStateBound()

void dhcpv6ClientStateBound ( Dhcpv6ClientContext context)

BOUND state.

Client has a valid lease and is in its normal operating state

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 898 of file dhcpv6_client.c.

◆ dhcpv6ClientStateConfirm()

void dhcpv6ClientStateConfirm ( Dhcpv6ClientContext context)

CONFIRM state.

Whenever a client may have moved to a new link, the prefixes from the addresses assigned to the interfaces on that link may no longer be appropriate for the link to which the client is attached. In such the client must initiate a Confirm/Reply message exchange

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 759 of file dhcpv6_client.c.

◆ dhcpv6ClientStateDad()

void dhcpv6ClientStateDad ( Dhcpv6ClientContext context)

DAD state.

The client perform duplicate address detection on each of the addresses in any IAs it receives in the Reply message before using that address for traffic

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 844 of file dhcpv6_client.c.

◆ dhcpv6ClientStateDecline()

void dhcpv6ClientStateDecline ( Dhcpv6ClientContext context)

DECLINE state.

If a client detects that one or more addresses assigned to it by a server are already in use by another node, the client sends a Decline message to the server to inform it that the address is suspect

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 1181 of file dhcpv6_client.c.

◆ dhcpv6ClientStateInit()

void dhcpv6ClientStateInit ( Dhcpv6ClientContext context)

INIT state.

This is the initialization state, where a client begins the process of acquiring a lease. It also returns here when a lease ends, or when a lease negotiation fails

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 511 of file dhcpv6_client.c.

◆ dhcpv6ClientStateInitConfirm()

void dhcpv6ClientStateInitConfirm ( Dhcpv6ClientContext context)

INIT-CONFIRM state.

When a client that already has a valid lease starts up after a power-down or reboot, it starts here instead of the INIT state

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 713 of file dhcpv6_client.c.

◆ dhcpv6ClientStateRebind()

void dhcpv6ClientStateRebind ( Dhcpv6ClientContext context)

REBIND state.

The client sends a Rebind message to any available server to extend the lifetimes on the addresses assigned to the client and to update other configuration parameters. This message is sent after a client receives no response to a Renew message

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 1026 of file dhcpv6_client.c.

◆ dhcpv6ClientStateRelease()

void dhcpv6ClientStateRelease ( Dhcpv6ClientContext context)

RELEASE state.

To release one or more addresses, a client sends a Release message to the server

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 1114 of file dhcpv6_client.c.

◆ dhcpv6ClientStateRenew()

void dhcpv6ClientStateRenew ( Dhcpv6ClientContext context)

RENEW state.

The client sends a Renew message to the server that originally provided the client's addresses and configuration parameters to extend the lifetimes on the addresses assigned to the client and to update other configuration parameters

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 940 of file dhcpv6_client.c.

◆ dhcpv6ClientStateRequest()

void dhcpv6ClientStateRequest ( Dhcpv6ClientContext context)

REQUEST state.

The client uses a Request message to populate IAs with addresses and obtain other configuration information. The client includes one or more more IA options in the Request message. The server then returns addresses and other information about the IAs to the client in IA options in a Reply message

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 639 of file dhcpv6_client.c.

◆ dhcpv6ClientStateSolicit()

void dhcpv6ClientStateSolicit ( Dhcpv6ClientContext context)

SOLICIT state.

A client uses the Solicit message to discover DHCPv6 servers

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 557 of file dhcpv6_client.c.

◆ dhcpv6ClientStop()

error_t dhcpv6ClientStop ( Dhcpv6ClientContext context)

Stop DHCPv6 client.

Parameters
[in]contextPointer to the DHCPv6 client context
Returns
Error code

Definition at line 216 of file dhcpv6_client.c.

◆ dhcpv6ClientTick()

void dhcpv6ClientTick ( Dhcpv6ClientContext context)

DHCPv6 client timer handler.

This routine must be periodically called by the TCP/IP stack to manage DHCPv6 client operation

Parameters
[in]contextPointer to the DHCPv6 client context

Definition at line 339 of file dhcpv6_client.c.

Variable Documentation

◆ dhcpv6ClientTickCounter

systime_t dhcpv6ClientTickCounter

Definition at line 57 of file dhcpv6_client.c.