dhcpv6_common.h
Go to the documentation of this file.
1 /**
2  * @file dhcpv6_common.h
3  * @brief Definitions common to DHCPv6 client, server and relay agent
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2023 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.3.0
29  **/
30 
31 #ifndef _DHCPV6_COMMON_H
32 #define _DHCPV6_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/ethernet.h"
37 #include "ipv6/ipv6.h"
38 
39 //UDP ports used by DHCPv6 clients and servers
40 #define DHCPV6_CLIENT_PORT 546
41 #define DHCPV6_SERVER_PORT 547
42 
43 //Maximum DHCPv6 message size
44 #define DHCPV6_MAX_MSG_SIZE 1232
45 //Maximum DUID size (128 octets not including the type code)
46 #define DHCPV6_MAX_DUID_SIZE 130
47 
48 //Maximum hop count in a relay-forward message
49 #define DHCPV6_HOP_COUNT_LIMIT 8
50 //Highest server preference value
51 #define DHCPV6_MAX_SERVER_PREFERENCE 255
52 //Infinite lifetime representation
53 #define DHCPV6_INFINITE_TIME 0xFFFFFFFF
54 
55 //C++ guard
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 
61 /**
62  * @brief DUID types
63  **/
64 
65 typedef enum
66 {
69  DHCPV6_DUID_LL = 3
71 
72 
73 /**
74  * @brief Hardware types
75  **/
76 
77 typedef enum
78 {
82 
83 
84 /**
85  * @brief DHCPv6 message types
86  **/
87 
88 typedef enum
89 {
104 
105 
106 /**
107  * @brief DHCPv6 option codes
108  **/
109 
110 typedef enum
111 {
139 
140 
141 /**
142  * @brief Status code
143  **/
144 
145 typedef enum
146 {
154 
155 
156 //CodeWarrior or Win32 compiler?
157 #if defined(__CWCC__) || defined(_WIN32)
158  #pragma pack(push, 1)
159 #endif
160 
161 
162 /**
163  * @brief DUID-LLT structure
164  **/
165 
167 {
168  uint16_t type; //0-1
169  uint16_t hardwareType; //2-3
170  uint32_t time; //4-7
173 
174 
175 /**
176  * @brief DUID-EN structure
177  **/
178 
179 typedef __packed_struct
180 {
181  uint16_t type; //0-1
182  uint32_t enterpriseNumber; //2-5
183  uint8_t identifier[]; //6
185 
186 
187 /**
188  * @brief DUID-LL structure
189  **/
190 
191 typedef __packed_struct
192 {
193  uint16_t type; //0-1
194  uint16_t hardwareType; //2-3
195 #if (ETH_SUPPORT == ENABLED)
196  MacAddr linkLayerAddr; //4-9
197 #else
198  Eui64 linkLayerAddr; //4-11
199 #endif
201 
202 
203 /**
204  * @brief DHCPv6 message
205  **/
206 
207 typedef __packed_struct
208 {
209  uint8_t msgType; //0
210  uint8_t transactionId[3]; //1-3
211  uint8_t options[]; //4
213 
214 
215 /**
216  * @brief DHCPv6 relay agent message
217  **/
218 
219 typedef __packed_struct
220 {
221  uint8_t msgType; //0
222  uint8_t hopCount; //1
225  uint8_t options[]; //34
227 
228 
229 /**
230  * @brief DHCPv6 option
231  **/
232 
233 typedef __packed_struct
234 {
235  uint16_t code; //0-1
236  uint16_t length; //2-3
237  uint8_t value[]; //4
239 
240 
241 /**
242  * @brief Identity Association for Non-temporary Addresses option
243  **/
244 
245 typedef __packed_struct
246 {
247  uint32_t iaId; //0-3
248  uint32_t t1; //4-7
249  uint32_t t2; //8-11
250  uint8_t options[]; //12
252 
253 
254 /**
255  * @brief Identity Association for Temporary Addresses option
256  **/
257 
258 typedef __packed_struct
259 {
260  uint32_t iaId; //0-3
261  uint8_t options[]; //4
263 
264 
265 /**
266  * @brief IA Address option
267  **/
268 
269 typedef __packed_struct
270 {
271  Ipv6Addr address; //0-15
272  uint32_t preferredLifetime; //16-19
273  uint32_t validLifetime; //20-23
274  uint8_t options[]; //24
276 
277 
278 /**
279  * @brief Option Request option
280  **/
281 
282 typedef __packed_struct
283 {
284  uint16_t requestedOption[1]; //0-1
286 
287 
288 /**
289  * @brief Preference option
290  **/
291 
292 typedef __packed_struct
293 {
294  uint8_t value; //0
296 
297 
298 /**
299  * @brief Elapsed Time option
300  **/
301 
302 typedef __packed_struct
303 {
304  uint16_t value; //0-1
306 
307 
308 /**
309  * @brief Authentication option
310  **/
311 
312 typedef __packed_struct
313 {
314  uint8_t protocol; //0
315  uint8_t algorithm; //1
316  uint8_t rdm; //2
317  uint8_t replayDetection[8]; //3-10
318  uint8_t authInfo[]; //11
320 
321 
322 /**
323  * @brief Server Unicast option
324  **/
325 
326 typedef __packed_struct
327 {
328  Ipv6Addr serverAddr; //0-15
330 
331 
332 /**
333  * @brief Status Code option
334  **/
335 
336 typedef __packed_struct
337 {
338  uint16_t statusCode; //0-1
341 
342 
343 /**
344  * @brief Reconfigure Message option
345  **/
346 
347 typedef __packed_struct
348 {
349  uint8_t msgType; //0
351 
352 
353 /**
354  * @brief DNS Recursive Name Server option
355  **/
356 
357 typedef __packed_struct
358 {
359  Ipv6Addr address[1]; //0-15
361 
362 
363 /**
364  * @brief Domain Search List option
365  **/
366 
367 typedef __packed_struct
368 {
369  uint8_t searchList[1]; //0
371 
372 
373 /**
374  * @brief Identity Association for Prefix Delegation Option
375  **/
376 
377 typedef __packed_struct
378 {
379  uint32_t iaId; //0-3
380  uint32_t t1; //4-7
381  uint32_t t2; //8-11
382  uint8_t options[]; //12
384 
385 
386 /**
387  * @brief IA_PD Prefix option
388  **/
389 
390 typedef __packed_struct
391 {
392  uint32_t preferredLifetime; //0-3
393  uint32_t validLifetime; //4-7
394  uint8_t prefixLen; //8
395  Ipv6Addr prefix; //9-24
396  uint8_t options[]; //25
398 
399 
400 /**
401  * @brief Fully Qualified Domain Name option
402  **/
403 
404 typedef __packed_struct
405 {
406 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
407  uint8_t mbz : 5; //0
408  uint8_t n : 1;
409  uint8_t o : 1;
410  uint8_t s : 1;
411 #else
412  uint8_t s : 1; //0
413  uint8_t o : 1;
414  uint8_t n : 1;
415  uint8_t mbz : 5;
416 #endif
417  uint8_t domainName[]; //1
419 
420 
421 //CodeWarrior or Win32 compiler?
422 #if defined(__CWCC__) || defined(_WIN32)
423  #pragma pack(pop)
424 #endif
425 
426 //DHCPv6 related constants
428 extern const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR;
429 
430 //DHCPv6 related functions
431 Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length);
432 
433 Dhcpv6Option *dhcpv6AddOption(void *message, size_t *messageLen,
434  uint16_t optionCode, const void *optionValue, size_t optionLen);
435 
436 Dhcpv6Option *dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen,
437  uint16_t optionCode, const void *optionValue, size_t optionLen);
438 
439 Dhcpv6Option *dhcpv6GetOption(const uint8_t *options,
440  size_t optionsLength, uint16_t optionCode);
441 
442 //C++ guard
443 #ifdef __cplusplus
444 }
445 #endif
446 
447 #endif
Dhcpv6DuidLlt
IPv6 (Internet Protocol Version 6)
Ipv6Addr linkAddress
@ DHCPV6_OPT_FQDN
@ DHCPV6_MSG_TYPE_DECLINE
Definition: dhcpv6_common.h:98
uint8_t code
Definition: coap_common.h:177
@ DHCPV6_DUID_LLT
Definition: dhcpv6_common.h:67
@ DHCPV6_STATUS_NOT_ON_LINK
uint8_t options[]
uint8_t protocol
Definition: ipv4.h:294
Dhcpv6OroOption
Eui64
Definition: ethernet.h:208
@ DHCPV6_OPT_IA_ADDR
@ DHCPV6_MSG_TYPE_SOLICIT
Definition: dhcpv6_common.h:90
@ DHCPV6_OPT_IA_NA
uint8_t algorithm
uint8_t message[]
Definition: chap.h:152
uint8_t o
uint32_t preferredLifetime
@ DHCPV6_OPT_IA_TA
Ipv6Addr peerAddress
Dhcpv6Option * dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add a suboption under an existing base option.
@ DHCPV6_MSG_TYPE_REBIND
Definition: dhcpv6_common.h:95
@ DHCPV6_MSG_TYPE_RELAY_FORW
@ DHCPV6_DUID_EN
Definition: dhcpv6_common.h:68
Dhcpv6DnsServersOption
Ipv6Addr
Definition: ipv6.h:249
@ DHCPV6_STATUS_UNSPEC_FAILURE
uint8_t domainName[]
@ DHCPV6_OPT_IA_PD
Dhcpv6Message
Dhcpv6IaPrefixOption
uint8_t value[]
@ DHCPV6_OPT_AUTH
Dhcpv6ServerUnicastOption
Ipv6Addr prefix
Dhcpv6RelayMessage
@ DHCPV6_HARDWARE_TYPE_EUI64
Definition: dhcpv6_common.h:80
@ DHCPV6_OPT_DOMAIN_LIST
Ethernet.
MacAddr linkLayerAddr
@ DHCPV6_OPT_CLIENT_ID
@ DHCPV6_STATUS_NO_BINDING
@ DHCPV6_OPT_ELAPSED_TIME
Dhcpv6IaPdOption
@ DHCPV6_STATUS_SUCCESS
Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length)
Retrieve status code.
Definition: dhcpv6_common.c:73
@ DHCPV6_OPT_CAPTIVE_PORTAL
uint32_t enterpriseNumber
uint32_t validLifetime
Dhcpv6Option
Dhcpv6ElapsedTimeOption
@ DHCPV6_MSG_TYPE_RELEASE
Definition: dhcpv6_common.h:97
Dhcpv6AuthOption
Dhcpv6PreferenceOption
@ DHCPV6_MSG_TYPE_REPLY
Definition: dhcpv6_common.h:96
@ DHCPV6_OPT_INTERFACE_ID
Dhcpv6StatusCodeOption
@ DHCPV6_MSG_TYPE_RENEW
Definition: dhcpv6_common.h:94
Dhcpv6StatusCode
Status code.
uint32_t t2
const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR
Definition: dhcpv6_common.c:58
Dhcpv6DuidEn
@ DHCPV6_MSG_TYPE_ADVERTISE
Definition: dhcpv6_common.h:91
uint8_t replayDetection[8]
uint8_t hopCount
uint8_t transactionId[3]
MacAddr
Definition: ethernet.h:193
@ DHCPV6_OPT_UNICAST
Dhcpv6DomainListOption
uint8_t authInfo[]
const Ipv6Addr DHCPV6_ALL_RELAY_AGENTS_AND_SERVERS_ADDR
Definition: dhcpv6_common.c:54
uint8_t type
Definition: coap_common.h:174
@ DHCPV6_MSG_TYPE_INFO_REQUEST
@ DHCPV6_MSG_TYPE_RELAY_REPL
Dhcpv6DuidType
DUID types.
Definition: dhcpv6_common.h:66
Dhcpv6IaTaOption
Dhcpv6ReconfMessageOption
uint8_t prefixLen
char char_t
Definition: compiler_port.h:48
@ DHCPV6_OPT_USER_CLASS
uint32_t time
uint8_t msgType
uint32_t t1
@ DHCPV6_OPT_VENDOR_CLASS
uint16_t hardwareType
Dhcpv6MessageType
DHCPv6 message types.
Definition: dhcpv6_common.h:89
Dhcpv6IaAddrOption
uint8_t n
@ DHCPV6_STATUS_USE_MULTICAST
@ DHCPV6_OPT_RELAY_MSG
@ DHCPV6_OPT_RECONF_ACCEPT
Ipv6Addr address[]
Definition: ipv6.h:314
@ DHCPV6_STATUS_NO_ADDRS_AVAILABLE
@ DHCPV6_OPT_INFO_REFRESH_TIME
@ DHCPV6_OPT_PREFERENCE
Dhcpv6HardwareType
Hardware types.
Definition: dhcpv6_common.h:78
@ DHCPV6_OPT_DNS_SERVERS
uint8_t identifier[]
char_t statusMessage[]
typedef __packed_struct
DUID-LLT structure.
Dhcpv6IaNaOption
@ DHCPV6_MSG_TYPE_CONFIRM
Definition: dhcpv6_common.h:93
@ DHCPV6_OPT_IA_PREFIX
Dhcpv6Option * dhcpv6GetOption(const uint8_t *options, size_t optionsLength, uint16_t optionCode)
Search a DHCPv6 message for a given option.
uint8_t s
Definition: ndp.h:343
@ DHCPV6_OPT_ORO
@ DHCPV6_HARDWARE_TYPE_ETH
Definition: dhcpv6_common.h:79
uint8_t mbz
Dhcpv6OptionCode
DHCPv6 option codes.
@ DHCPV6_OPT_SERVER_ID
Dhcpv6FqdnOption
uint8_t rdm
@ DHCPV6_MSG_TYPE_RECONFIGURE
Definition: dhcpv6_common.h:99
uint16_t length
Dhcpv6Option * dhcpv6AddOption(void *message, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add an option to a DHCPv6 message.
TCP/IP stack core.
@ DHCPV6_OPT_RECONF_MSG
@ DHCPV6_OPT_STATUS_CODE
Dhcpv6DuidLl
@ DHCPV6_DUID_LL
Definition: dhcpv6_common.h:69
@ DHCPV6_MSG_TYPE_REQUEST
Definition: dhcpv6_common.h:92
@ DHCPV6_OPT_RAPID_COMMIT
@ DHCPV6_OPT_VENDOR_OPTS