dhcpv6_client.h
Go to the documentation of this file.
1 /**
2  * @file dhcpv6_client.h
3  * @brief DHCPv6 client (Dynamic Host Configuration Protocol for IPv6)
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _DHCPV6_CLIENT_H
30 #define _DHCPV6_CLIENT_H
31 
32 //Dependencies
33 #include "dhcpv6/dhcpv6_common.h"
34 #include "core/socket.h"
35 
36 //DHCPv6 client support
37 #ifndef DHCPV6_CLIENT_SUPPORT
38  #define DHCPV6_CLIENT_SUPPORT DISABLED
39 #elif (DHCPV6_CLIENT_SUPPORT != ENABLED && DHCPV6_CLIENT_SUPPORT != DISABLED)
40  #error DHCPV6_CLIENT_SUPPORT parameter is not valid
41 #endif
42 
43 //DHCPv6 client tick interval
44 #ifndef DHCPV6_CLIENT_TICK_INTERVAL
45  #define DHCPV6_CLIENT_TICK_INTERVAL 200
46 #elif (DHCPV6_CLIENT_TICK_INTERVAL < 10)
47  #error DHCPV6_CLIENT_TICK_INTERVAL parameter is not valid
48 #endif
49 
50 //Maximum number of IPv6 addresses in the client's IA
51 #ifndef DHCPV6_CLIENT_ADDR_LIST_SIZE
52  #define DHCPV6_CLIENT_ADDR_LIST_SIZE 2
53 #elif (DHCPV6_CLIENT_ADDR_LIST_SIZE < 1)
54  #error DHCPV6_CLIENT_ADDR_LIST_SIZE parameter is not valid
55 #endif
56 
57 //Maximum size of the client's FQDN
58 #ifndef DHCPV6_CLIENT_MAX_FQDN_SIZE
59  #define DHCPV6_CLIENT_MAX_FQDN_SIZE 16
60 #elif (DHCPV6_CLIENT_MAX_FQDN_SIZE < 1)
61  #error DHCPV6_CLIENT_MAX_FQDN_SIZE parameter is not valid
62 #endif
63 
64 //Max delay of first Solicit
65 #ifndef DHCPV6_CLIENT_SOL_MAX_DELAY
66  #define DHCPV6_CLIENT_SOL_MAX_DELAY 1000
67 #elif (DHCPV6_CLIENT_SOL_MAX_DELAY < 100)
68  #error DHCPV6_CLIENT_SOL_MAX_DELAY parameter is not valid
69 #endif
70 
71 //Initial Solicit timeout
72 #ifndef DHCPV6_CLIENT_SOL_TIMEOUT
73  #define DHCPV6_CLIENT_SOL_TIMEOUT 1000
74 #elif (DHCPV6_CLIENT_SOL_TIMEOUT < 100)
75  #error DHCPV6_CLIENT_SOL_TIMEOUT parameter is not valid
76 #endif
77 
78 //Max Solicit timeout value
79 #ifndef DHCPV6_CLIENT_SOL_MAX_RT
80  #define DHCPV6_CLIENT_SOL_MAX_RT 120000
81 #elif (DHCPV6_CLIENT_SOL_MAX_RT < 100)
82  #error DHCPV6_CLIENT_SOL_MAX_RT parameter is not valid
83 #endif
84 
85 //Initial Request timeout
86 #ifndef DHCPV6_CLIENT_REQ_TIMEOUT
87  #define DHCPV6_CLIENT_REQ_TIMEOUT 1000
88 #elif (DHCPV6_CLIENT_REQ_TIMEOUT < 100)
89  #error DHCPV6_CLIENT_REQ_TIMEOUT parameter is not valid
90 #endif
91 
92 //Max Request timeout value
93 #ifndef DHCPV6_CLIENT_REQ_MAX_RT
94  #define DHCPV6_CLIENT_REQ_MAX_RT 30000
95 #elif (DHCPV6_CLIENT_REQ_MAX_RT < 100)
96  #error DHCPV6_CLIENT_REQ_MAX_RT parameter is not valid
97 #endif
98 
99 //Max Request retry attempts
100 #ifndef DHCPV6_CLIENT_REQ_MAX_RC
101  #define DHCPV6_CLIENT_REQ_MAX_RC 10
102 #elif (DHCPV6_CLIENT_REQ_MAX_RC < 1)
103  #error DHCPV6_CLIENT_REQ_MAX_RC parameter is not valid
104 #endif
105 
106 //Max delay of first Confirm
107 #ifndef DHCPV6_CLIENT_CNF_MAX_DELAY
108  #define DHCPV6_CLIENT_CNF_MAX_DELAY 1000
109 #elif (DHCPV6_CLIENT_CNF_MAX_DELAY < 100)
110  #error DHCPV6_CLIENT_CNF_MAX_DELAY parameter is not valid
111 #endif
112 
113 //Initial Confirm timeout
114 #ifndef DHCPV6_CLIENT_CNF_TIMEOUT
115  #define DHCPV6_CLIENT_CNF_TIMEOUT 1000
116 #elif (DHCPV6_CLIENT_CNF_TIMEOUT < 100)
117  #error DHCPV6_CLIENT_CNF_TIMEOUT parameter is not valid
118 #endif
119 
120 //Max Confirm timeout
121 #ifndef DHCPV6_CLIENT_CNF_MAX_RT
122  #define DHCPV6_CLIENT_CNF_MAX_RT 4000
123 #elif (DHCPV6_CLIENT_CNF_MAX_RT < 100)
124  #error DHCPV6_CLIENT_CNF_MAX_RT parameter is not valid
125 #endif
126 
127 //Max Confirm duration
128 #ifndef DHCPV6_CLIENT_CNF_MAX_RD
129  #define DHCPV6_CLIENT_CNF_MAX_RD 10000
130 #elif (DHCPV6_CLIENT_CNF_MAX_RD < 100)
131  #error DHCPV6_CLIENT_CNF_MAX_RD parameter is not valid
132 #endif
133 
134 //Initial Renew timeout
135 #ifndef DHCPV6_CLIENT_REN_TIMEOUT
136  #define DHCPV6_CLIENT_REN_TIMEOUT 10000
137 #elif (DHCPV6_CLIENT_REN_TIMEOUT < 100)
138  #error DHCPV6_CLIENT_REN_TIMEOUT parameter is not valid
139 #endif
140 
141 //Max Renew timeout value
142 #ifndef DHCPV6_CLIENT_REN_MAX_RT
143  #define DHCPV6_CLIENT_REN_MAX_RT 600000
144 #elif (DHCPV6_CLIENT_REN_MAX_RT < 100)
145  #error DHCPV6_CLIENT_REN_MAX_RT parameter is not valid
146 #endif
147 
148 //Initial Rebind timeout
149 #ifndef DHCPV6_CLIENT_REB_TIMEOUT
150  #define DHCPV6_CLIENT_REB_TIMEOUT 10000
151 #elif (DHCPV6_CLIENT_REB_TIMEOUT < 100)
152  #error DHCPV6_CLIENT_REB_TIMEOUT parameter is not valid
153 #endif
154 
155 //Max Rebind timeout value
156 #ifndef DHCPV6_CLIENT_REB_MAX_RT
157  #define DHCPV6_CLIENT_REB_MAX_RT 600000
158 #elif (DHCPV6_CLIENT_REB_MAX_RT < 100)
159  #error DHCPV6_CLIENT_REB_MAX_RT parameter is not valid
160 #endif
161 
162 //Max delay of first Information-request
163 #ifndef DHCPV6_CLIENT_INF_MAX_DELAY
164  #define DHCPV6_CLIENT_INF_MAX_DELAY 1000
165 #elif (DHCPV6_CLIENT_INF_MAX_DELAY < 100)
166  #error DHCPV6_CLIENT_INF_MAX_DELAY parameter is not valid
167 #endif
168 
169 //Initial Information-request timeout
170 #ifndef DHCPV6_CLIENT_INF_TIMEOUT
171  #define DHCPV6_CLIENT_INF_TIMEOUT 1000
172 #elif (DHCPV6_CLIENT_INF_TIMEOUT < 100)
173  #error DHCPV6_CLIENT_INF_TIMEOUT parameter is not valid
174 #endif
175 
176 //Max Information-request timeout value
177 #ifndef DHCPV6_CLIENT_INF_MAX_RT
178  #define DHCPV6_CLIENT_INF_MAX_RT 120000
179 #elif (DHCPV6_CLIENT_INF_MAX_RT < 1000)
180  #error DHCPV6_CLIENT_INF_MAX_RT parameter is not valid
181 #endif
182 
183 //Initial Release timeout
184 #ifndef DHCPV6_CLIENT_REL_TIMEOUT
185  #define DHCPV6_CLIENT_REL_TIMEOUT 1000
186 #elif (DHCPV6_CLIENT_REL_TIMEOUT < 100)
187  #error DHCPV6_CLIENT_REL_TIMEOUT parameter is not valid
188 #endif
189 
190 //Max Release attempts
191 #ifndef DHCPV6_CLIENT_REL_MAX_RC
192  #define DHCPV6_CLIENT_REL_MAX_RC 5
193 #elif (DHCPV6_CLIENT_REL_MAX_RC < 1)
194  #error DHCPV6_CLIENT_REL_MAX_RC parameter is not valid
195 #endif
196 
197 //Initial Decline timeout
198 #ifndef DHCPV6_CLIENT_DEC_TIMEOUT
199  #define DHCPV6_CLIENT_DEC_TIMEOUT 1000
200 #elif (DHCPV6_CLIENT_DEC_TIMEOUT < 100)
201  #error DHCPV6_CLIENT_DEC_TIMEOUT parameter is not valid
202 #endif
203 
204 //Max Decline attempts
205 #ifndef DHCPV6_CLIENT_DEC_MAX_RC
206  #define DHCPV6_CLIENT_DEC_MAX_RC 5
207 #elif (DHCPV6_CLIENT_DEC_MAX_RC < 1)
208  #error DHCPV6_CLIENT_DEC_MAX_RC parameter is not valid
209 #endif
210 
211 //Initial Reconfigure timeout
212 #ifndef DHCPV6_CLIENT_REC_TIMEOUT
213  #define DHCPV6_CLIENT_REC_TIMEOUT 2000
214 #elif (DHCPV6_CLIENT_REC_TIMEOUT < 100)
215  #error DHCPV6_CLIENT_REC_TIMEOUT parameter is not valid
216 #endif
217 
218 //Max Reconfigure attempts
219 #ifndef DHCPV6_CLIENT_REC_MAX_RC
220  #define DHCPV6_CLIENT_REC_MAX_RC 8
221 #elif (DHCPV6_CLIENT_REC_MAX_RC < 1)
222  #error DHCPV6_CLIENT_REC_MAX_RC parameter is not valid
223 #endif
224 
225 //Forward declaration of Dhcpv6ClientContext structure
226 struct _Dhcpv6ClientContext;
227 #define Dhcpv6ClientContext struct _Dhcpv6ClientContext
228 
229 //C++ guard
230 #ifdef __cplusplus
231  extern "C" {
232 #endif
233 
234 
235 /**
236  * @brief DHCPv6 client FSM states
237  **/
238 
239 typedef enum
240 {
252 } Dhcpv6State;
253 
254 
255 /**
256  * @brief DHCPv6 configuration timeout callback
257  **/
258 
260  NetInterface *interface);
261 
262 
263 /**
264  * @brief Link state change callback
265  **/
266 
268  NetInterface *interface, bool_t linkState);
269 
270 
271 /**
272  * @brief FSM state change callback
273  **/
274 
276  NetInterface *interface, Dhcpv6State state);
277 
278 
279 /**
280  * @brief DHCPv6 client settings
281  **/
282 
283 typedef struct
284 {
285  NetInterface *interface; ///<Network interface to configure
286  bool_t rapidCommit; ///<Quick configuration using rapid commit
287  bool_t manualDnsConfig; ///<Force manual DNS configuration
288  systime_t timeout; ///<DHCPv6 configuration timeout
289  Dhcpv6TimeoutCallback timeoutEvent; ///<DHCPv6 configuration timeout event
290  Dhcpv6LinkChangeCallback linkChangeEvent; ///<Link state change event
291  Dhcpv6StateChangeCallback stateChangeEvent; ///<FSM state change event
293 
294 
295 /**
296  * @brief IA address entry
297  **/
298 
299 typedef struct
300 {
301  Ipv6Addr addr; ///<IPv6 address
302  uint32_t validLifetime; ///<Valid lifetime
303  uint32_t preferredLifetime; ///<Preferred lifetime
305 
306 
307 /**
308  * @brief Client's IA (Identity Association)
309  **/
310 
311 typedef struct
312 {
313  uint32_t t1; ///<T1 parameter
314  uint32_t t2; ///<T2 parameter
315  Dhcpv6ClientAddrEntry addrList[DHCPV6_CLIENT_ADDR_LIST_SIZE]; ///<Set of IPv6 addresses
317 
318 
319 /**
320  * @brief DHCPv6 client context
321  **/
322 
324 {
325  Dhcpv6ClientSettings settings; ///<DHCPv6 client settings
326  bool_t running; ///<This flag tells whether the DHCP client is running or not
327  Dhcpv6State state; ///<Current state of the FSM
328  bool_t timeoutEventDone; ///<Timeout callback function has been called
329  systime_t timestamp; ///<Timestamp to manage retransmissions
330  systime_t timeout; ///<Timeout value
331  uint_t retransmitCount; ///<Retransmission counter
332  uint8_t clientId[DHCPV6_MAX_DUID_SIZE]; ///<Client DUID
333  size_t clientIdLength; ///<Length of the client DUID
334  uint8_t clientFqdn[DHCPV6_CLIENT_MAX_FQDN_SIZE]; ///<Client's fully qualified domain name
335  size_t clientFqdnLength; ///<Length of the client's FQDN
336  uint8_t serverId[DHCPV6_MAX_DUID_SIZE]; ///<Server DUID
337  size_t serverIdLength; ///<Length of the server DUID
338  int_t serverPreference; ///<Preference value for the server
339  uint32_t transactionId; ///<Value to match requests with replies
340  systime_t configStartTime; ///<Address acquisition or renewal process start time
341  systime_t exchangeStartTime; ///<Time at which the client sent the first message
342  systime_t leaseStartTime; ///<Lease start time
343  Dhcpv6ClientIa ia; ///<Identity association
344 };
345 
346 
347 //Tick counter to handle periodic operations
349 
350 //DHCPv6 client related functions
357 
360 
372 
375 
377  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
378  const NetBuffer *buffer, size_t offset, void *param);
379 
381  const Dhcpv6Message *message, size_t length);
382 
384  const Dhcpv6Message *message, size_t length);
385 
387  const Dhcpv6Option *option);
388 
390  const Dhcpv6Option *option);
391 
393  uint32_t validLifetime, uint32_t preferredLifetime);
394 
396 
398 
402 
404  Dhcpv6Option *serverIdOption);
405 
407 
409 
411  Dhcpv6State newState, systime_t delay);
412 
414 
415 //C++ guard
416 #ifdef __cplusplus
417  }
418 #endif
419 
420 #endif
__start_packed struct @134 Dhcpv6Option
DHCPv6 option.
uint32_t systime_t
Definition: compiler_port.h:44
uint32_t validLifetime
void dhcpv6ClientStateRebind(Dhcpv6ClientContext *context)
REBIND state.
uint16_t dhcpv6ClientComputeElapsedTime(Dhcpv6ClientContext *context)
Compute the time elapsed since the client sent the first message.
void dhcpv6ClientStateRenew(Dhcpv6ClientContext *context)
RENEW state.
#define DHCPV6_CLIENT_ADDR_LIST_SIZE
Definition: dhcpv6_client.h:52
error_t dhcpv6ClientGenerateFqdn(Dhcpv6ClientContext *context)
Generate client&#39;s fully qualified domain name.
systime_t configStartTime
Address acquisition or renewal process start time.
void dhcpv6ClientRemoveAddr(Dhcpv6ClientContext *context, const Ipv6Addr *addr)
Remove an IPv6 address from the IA.
uint8_t serverId[DHCPV6_MAX_DUID_SIZE]
Server DUID.
error_t dhcpv6ClientGenerateLinkLocalAddr(Dhcpv6ClientContext *context)
Generate a link-local address.
Dhcpv6TimeoutCallback timeoutEvent
DHCPv6 configuration timeout event.
systime_t timestamp
Timestamp to manage retransmissions.
uint8_t message[]
Definition: chap.h:150
void dhcpv6ClientLinkChangeEvent(Dhcpv6ClientContext *context)
Callback function for link change event.
void dhcpv6ClientStateInitConfirm(Dhcpv6ClientContext *context)
INIT-CONFIRM state.
#define DHCPV6_MAX_DUID_SIZE
Definition: dhcpv6_common.h:44
Dhcpv6LinkChangeCallback linkChangeEvent
Link state change event.
NetInterface * interface
Network interface to configure.
error_t dhcpv6ClientParseIaNaOption(Dhcpv6ClientContext *context, const Dhcpv6Option *option)
Parse IA_NA option.
__start_packed struct @183 Ipv6Addr
IPv6 network address.
void dhcpv6ClientFlushAddrList(Dhcpv6ClientContext *context)
Flush the list of IPv6 addresses from the IA.
Dhcpv6State dhcpv6ClientGetState(Dhcpv6ClientContext *context)
Retrieve current state.
Ipv6Addr addr
IPv6 address.
char_t type
uint8_t clientFqdn[DHCPV6_CLIENT_MAX_FQDN_SIZE]
Client&#39;s fully qualified domain name.
systime_t timeout
Timeout value.
#define Dhcpv6ClientContext
void dhcpv6ClientStateInit(Dhcpv6ClientContext *context)
INIT state.
systime_t exchangeStartTime
Time at which the client sent the first message.
DHCPv6 client context.
void dhcpv6ClientStateConfirm(Dhcpv6ClientContext *context)
CONFIRM state.
uint32_t preferredLifetime
Preferred lifetime.
error_t dhcpv6ClientStop(Dhcpv6ClientContext *context)
Stop DHCPv6 client.
uint32_t validLifetime
Valid lifetime.
void dhcpv6ClientStateBound(Dhcpv6ClientContext *context)
BOUND state.
IA address entry.
Definitions common to DHCPv6 client, server and relay agent.
void dhcpv6ClientDumpConfig(Dhcpv6ClientContext *context)
Dump DHCPv6 configuration for debugging purpose.
signed int int_t
Definition: compiler_port.h:42
Dhcpv6ClientIa ia
Identity association.
void dhcpv6ClientParseAdvertise(Dhcpv6ClientContext *context, const Dhcpv6Message *message, size_t length)
Parse Advertise message.
void(* Dhcpv6LinkChangeCallback)(Dhcpv6ClientContext *context, NetInterface *interface, bool_t linkState)
Link state change callback.
bool_t dhcpv6ClientCheckServerId(Dhcpv6ClientContext *context, Dhcpv6Option *serverIdOption)
Check the Server Identifier option.
size_t clientIdLength
Length of the client DUID.
void dhcpv6ClientCheckTimeout(Dhcpv6ClientContext *context)
Manage DHCPv6 configuration timeout.
#define DHCPV6_CLIENT_MAX_FQDN_SIZE
Definition: dhcpv6_client.h:59
bool_t running
This flag tells whether the DHCP client is running or not.
__start_packed struct @126 UdpHeader
UDP header.
void(* Dhcpv6TimeoutCallback)(Dhcpv6ClientContext *context, NetInterface *interface)
DHCPv6 configuration timeout callback.
systime_t dhcpv6ClientTickCounter
Definition: dhcpv6_client.c:57
systime_t timeout
DHCPv6 configuration timeout.
void dhcpv6ClientParseReply(Dhcpv6ClientContext *context, const Dhcpv6Message *message, size_t length)
Parse Reply message.
void(* Dhcpv6StateChangeCallback)(Dhcpv6ClientContext *context, NetInterface *interface, Dhcpv6State state)
FSM state change callback.
error_t dhcpv6ClientParseIaAddrOption(Dhcpv6ClientContext *context, const Dhcpv6Option *option)
Parse IA Address option.
void dhcpv6ClientProcessMessage(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, void *param)
Process incoming DHCPv6 message.
void dhcpv6ClientGetDefaultSettings(Dhcpv6ClientSettings *settings)
Initialize settings with default values.
Definition: dhcpv6_client.c:73
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
Dhcpv6StateChangeCallback stateChangeEvent
FSM state change event.
bool_t rapidCommit
Quick configuration using rapid commit.
size_t serverIdLength
Length of the server DUID.
void dhcpv6ClientStateDecline(Dhcpv6ClientContext *context)
DECLINE state.
error_t dhcpv6ClientSendMessage(Dhcpv6ClientContext *context, Dhcpv6MessageType type)
Send Solicit message.
uint32_t preferredLifetime
systime_t leaseStartTime
Lease start time.
bool_t manualDnsConfig
Force manual DNS configuration.
error_t dhcpv6ClientInit(Dhcpv6ClientContext *context, const Dhcpv6ClientSettings *settings)
DHCPv6 client initialization.
uint8_t clientId[DHCPV6_MAX_DUID_SIZE]
Client DUID.
size_t clientFqdnLength
Length of the client&#39;s FQDN.
void dhcpv6ClientStateSolicit(Dhcpv6ClientContext *context)
SOLICIT state.
int_t serverPreference
Preference value for the server.
error_t
Error codes.
Definition: error.h:40
void dhcpv6ClientStateDad(Dhcpv6ClientContext *context)
DAD state.
error_t dhcpv6ClientRelease(Dhcpv6ClientContext *context)
Release DHCPv6 lease.
unsigned int uint_t
Definition: compiler_port.h:43
#define NetInterface
Definition: net.h:34
error_t dhcpv6ClientGenerateDuid(Dhcpv6ClientContext *context)
Generate client&#39;s DUID.
void dhcpv6ClientChangeState(Dhcpv6ClientContext *context, Dhcpv6State newState, systime_t delay)
Update DHCPv6 FSM state.
Dhcpv6State
DHCPv6 client FSM states.
uint32_t t1
T1 parameter.
IP pseudo header.
Definition: ip.h:76
void dhcpv6ClientStateRelease(Dhcpv6ClientContext *context)
RELEASE state.
Client&#39;s IA (Identity Association)
Dhcpv6State state
Current state of the FSM.
Dhcpv6ClientSettings settings
DHCPv6 client settings.
error_t dhcpv6ClientStart(Dhcpv6ClientContext *context)
Start DHCPv6 client.
Dhcpv6MessageType
DHCPv6 message types.
Definition: dhcpv6_common.h:86
void dhcpv6ClientTick(Dhcpv6ClientContext *context)
DHCPv6 client timer handler.
uint32_t t2
T2 parameter.
uint32_t transactionId
Value to match requests with replies.
void dhcpv6ClientAddAddr(Dhcpv6ClientContext *context, const Ipv6Addr *addr, uint32_t validLifetime, uint32_t preferredLifetime)
Add an IPv6 address to the IA.
Socket API.
uint8_t length
Definition: dtls_misc.h:140
void dhcpv6ClientStateRequest(Dhcpv6ClientContext *context)
REQUEST state.
int bool_t
Definition: compiler_port.h:47
__start_packed struct @132 Dhcpv6Message
DHCPv6 message.
bool_t timeoutEventDone
Timeout callback function has been called.
Ipv4Addr addr
Definition: nbns_common.h:119
uint_t retransmitCount
Retransmission counter.
DHCPv6 client settings.