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-2024 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.4.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 //CC-RX, CodeWarrior or Win32 compiler?
157 #if defined(__CCRX__)
158  #pragma pack
159 #elif defined(__CWCC__) || defined(_WIN32)
160  #pragma pack(push, 1)
161 #endif
162 
163 
164 /**
165  * @brief DUID-LLT structure
166  **/
167 
169 {
170  uint16_t type; //0-1
171  uint16_t hardwareType; //2-3
172  uint32_t time; //4-7
175 
176 
177 /**
178  * @brief DUID-EN structure
179  **/
180 
181 typedef __packed_struct
182 {
183  uint16_t type; //0-1
184  uint32_t enterpriseNumber; //2-5
185  uint8_t identifier[]; //6
187 
188 
189 /**
190  * @brief DUID-LL structure
191  **/
192 
193 typedef __packed_struct
194 {
195  uint16_t type; //0-1
196  uint16_t hardwareType; //2-3
197 #if (ETH_SUPPORT == ENABLED)
198  MacAddr linkLayerAddr; //4-9
199 #else
200  Eui64 linkLayerAddr; //4-11
201 #endif
203 
204 
205 /**
206  * @brief DHCPv6 message
207  **/
208 
209 typedef __packed_struct
210 {
211  uint8_t msgType; //0
212  uint8_t transactionId[3]; //1-3
213  uint8_t options[]; //4
215 
216 
217 /**
218  * @brief DHCPv6 relay agent message
219  **/
220 
221 typedef __packed_struct
222 {
223  uint8_t msgType; //0
224  uint8_t hopCount; //1
227  uint8_t options[]; //34
229 
230 
231 /**
232  * @brief DHCPv6 option
233  **/
234 
235 typedef __packed_struct
236 {
237  uint16_t code; //0-1
238  uint16_t length; //2-3
239  uint8_t value[]; //4
241 
242 
243 /**
244  * @brief Identity Association for Non-temporary Addresses option
245  **/
246 
247 typedef __packed_struct
248 {
249  uint32_t iaId; //0-3
250  uint32_t t1; //4-7
251  uint32_t t2; //8-11
252  uint8_t options[]; //12
254 
255 
256 /**
257  * @brief Identity Association for Temporary Addresses option
258  **/
259 
260 typedef __packed_struct
261 {
262  uint32_t iaId; //0-3
263  uint8_t options[]; //4
265 
266 
267 /**
268  * @brief IA Address option
269  **/
270 
271 typedef __packed_struct
272 {
273  Ipv6Addr address; //0-15
274  uint32_t preferredLifetime; //16-19
275  uint32_t validLifetime; //20-23
276  uint8_t options[]; //24
278 
279 
280 /**
281  * @brief Option Request option
282  **/
283 
284 typedef __packed_struct
285 {
286  uint16_t requestedOption[1]; //0-1
288 
289 
290 /**
291  * @brief Preference option
292  **/
293 
294 typedef __packed_struct
295 {
296  uint8_t value; //0
298 
299 
300 /**
301  * @brief Elapsed Time option
302  **/
303 
304 typedef __packed_struct
305 {
306  uint16_t value; //0-1
308 
309 
310 /**
311  * @brief Authentication option
312  **/
313 
314 typedef __packed_struct
315 {
316  uint8_t protocol; //0
317  uint8_t algorithm; //1
318  uint8_t rdm; //2
319  uint8_t replayDetection[8]; //3-10
320  uint8_t authInfo[]; //11
322 
323 
324 /**
325  * @brief Server Unicast option
326  **/
327 
328 typedef __packed_struct
329 {
330  Ipv6Addr serverAddr; //0-15
332 
333 
334 /**
335  * @brief Status Code option
336  **/
337 
338 typedef __packed_struct
339 {
340  uint16_t statusCode; //0-1
343 
344 
345 /**
346  * @brief Reconfigure Message option
347  **/
348 
349 typedef __packed_struct
350 {
351  uint8_t msgType; //0
353 
354 
355 /**
356  * @brief DNS Recursive Name Server option
357  **/
358 
359 typedef __packed_struct
360 {
361  Ipv6Addr address[1]; //0-15
363 
364 
365 /**
366  * @brief Domain Search List option
367  **/
368 
369 typedef __packed_struct
370 {
371  uint8_t searchList[1]; //0
373 
374 
375 /**
376  * @brief Identity Association for Prefix Delegation Option
377  **/
378 
379 typedef __packed_struct
380 {
381  uint32_t iaId; //0-3
382  uint32_t t1; //4-7
383  uint32_t t2; //8-11
384  uint8_t options[]; //12
386 
387 
388 /**
389  * @brief IA_PD Prefix option
390  **/
391 
392 typedef __packed_struct
393 {
394  uint32_t preferredLifetime; //0-3
395  uint32_t validLifetime; //4-7
396  uint8_t prefixLen; //8
397  Ipv6Addr prefix; //9-24
398  uint8_t options[]; //25
400 
401 
402 /**
403  * @brief Fully Qualified Domain Name option
404  **/
405 
406 typedef __packed_struct
407 {
408 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
409  uint8_t mbz : 5; //0
410  uint8_t n : 1;
411  uint8_t o : 1;
412  uint8_t s : 1;
413 #else
414  uint8_t s : 1; //0
415  uint8_t o : 1;
416  uint8_t n : 1;
417  uint8_t mbz : 5;
418 #endif
419  uint8_t domainName[]; //1
421 
422 
423 //CC-RX, CodeWarrior or Win32 compiler?
424 #if defined(__CCRX__)
425  #pragma unpack
426 #elif defined(__CWCC__) || defined(_WIN32)
427  #pragma pack(pop)
428 #endif
429 
430 //DHCPv6 related constants
432 extern const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR;
433 
434 //DHCPv6 related functions
435 Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length);
436 
437 Dhcpv6Option *dhcpv6AddOption(void *message, size_t *messageLen,
438  uint16_t optionCode, const void *optionValue, size_t optionLen);
439 
440 Dhcpv6Option *dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen,
441  uint16_t optionCode, const void *optionValue, size_t optionLen);
442 
443 Dhcpv6Option *dhcpv6GetOption(const uint8_t *options,
444  size_t optionsLength, uint16_t optionCode);
445 
446 //C++ guard
447 #ifdef __cplusplus
448 }
449 #endif
450 
451 #endif
uint8_t message[]
Definition: chap.h:154
uint8_t type
Definition: coap_common.h:176
uint8_t code
Definition: coap_common.h:179
char char_t
Definition: compiler_port.h:48
Dhcpv6DuidLlt
Ipv6Addr peerAddress
uint16_t length
Dhcpv6ReconfMessageOption
uint32_t enterpriseNumber
uint8_t authInfo[]
uint16_t hardwareType
Dhcpv6Option
Dhcpv6Option * dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add a suboption under an existing base option.
const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR
Definition: dhcpv6_common.c:58
Dhcpv6ServerUnicastOption
Dhcpv6DuidEn
Dhcpv6IaTaOption
uint32_t preferredLifetime
uint32_t validLifetime
uint8_t n
uint8_t transactionId[3]
Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length)
Retrieve status code.
Definition: dhcpv6_common.c:73
char_t statusMessage[]
Dhcpv6PreferenceOption
Dhcpv6StatusCodeOption
Dhcpv6Option * dhcpv6GetOption(const uint8_t *options, size_t optionsLength, uint16_t optionCode)
Search a DHCPv6 message for a given option.
uint8_t algorithm
Dhcpv6FqdnOption
uint32_t t1
Dhcpv6HardwareType
Hardware types.
Definition: dhcpv6_common.h:78
@ DHCPV6_HARDWARE_TYPE_ETH
Definition: dhcpv6_common.h:79
@ DHCPV6_HARDWARE_TYPE_EUI64
Definition: dhcpv6_common.h:80
uint8_t o
Dhcpv6Message
uint8_t identifier[]
Ipv6Addr linkAddress
uint8_t options[]
Dhcpv6IaPrefixOption
Ipv6Addr prefix
Dhcpv6IaNaOption
uint8_t mbz
MacAddr linkLayerAddr
uint8_t hopCount
Dhcpv6OroOption
uint32_t t2
Dhcpv6AuthOption
uint8_t replayDetection[8]
uint8_t domainName[]
Dhcpv6RelayMessage
uint8_t prefixLen
Dhcpv6DuidType
DUID types.
Definition: dhcpv6_common.h:66
@ DHCPV6_DUID_LLT
Definition: dhcpv6_common.h:67
@ DHCPV6_DUID_EN
Definition: dhcpv6_common.h:68
@ DHCPV6_DUID_LL
Definition: dhcpv6_common.h:69
Dhcpv6Option * dhcpv6AddOption(void *message, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add an option to a DHCPv6 message.
Dhcpv6DomainListOption
typedef __packed_struct
DUID-LLT structure.
Dhcpv6DuidLl
Dhcpv6OptionCode
DHCPv6 option codes.
@ DHCPV6_OPT_RECONF_ACCEPT
@ DHCPV6_OPT_STATUS_CODE
@ DHCPV6_OPT_RELAY_MSG
@ DHCPV6_OPT_PREFERENCE
@ DHCPV6_OPT_DNS_SERVERS
@ DHCPV6_OPT_INFO_REFRESH_TIME
@ DHCPV6_OPT_CAPTIVE_PORTAL
@ DHCPV6_OPT_IA_PREFIX
@ DHCPV6_OPT_RAPID_COMMIT
@ DHCPV6_OPT_IA_NA
@ DHCPV6_OPT_SERVER_ID
@ DHCPV6_OPT_USER_CLASS
@ DHCPV6_OPT_UNICAST
@ DHCPV6_OPT_FQDN
@ DHCPV6_OPT_INTERFACE_ID
@ DHCPV6_OPT_VENDOR_OPTS
@ DHCPV6_OPT_RECONF_MSG
@ DHCPV6_OPT_IA_PD
@ DHCPV6_OPT_CLIENT_ID
@ DHCPV6_OPT_DOMAIN_LIST
@ DHCPV6_OPT_ORO
@ DHCPV6_OPT_ELAPSED_TIME
@ DHCPV6_OPT_IA_ADDR
@ DHCPV6_OPT_AUTH
@ DHCPV6_OPT_VENDOR_CLASS
@ DHCPV6_OPT_IA_TA
Dhcpv6IaPdOption
uint8_t rdm
Dhcpv6ElapsedTimeOption
uint8_t value[]
Dhcpv6StatusCode
Status code.
@ DHCPV6_STATUS_NO_BINDING
@ DHCPV6_STATUS_NOT_ON_LINK
@ DHCPV6_STATUS_UNSPEC_FAILURE
@ DHCPV6_STATUS_USE_MULTICAST
@ DHCPV6_STATUS_SUCCESS
@ DHCPV6_STATUS_NO_ADDRS_AVAILABLE
uint32_t time
Dhcpv6DnsServersOption
Dhcpv6MessageType
DHCPv6 message types.
Definition: dhcpv6_common.h:89
@ DHCPV6_MSG_TYPE_RELAY_REPL
@ DHCPV6_MSG_TYPE_INFO_REQUEST
@ DHCPV6_MSG_TYPE_RELAY_FORW
@ DHCPV6_MSG_TYPE_RECONFIGURE
Definition: dhcpv6_common.h:99
@ DHCPV6_MSG_TYPE_DECLINE
Definition: dhcpv6_common.h:98
@ DHCPV6_MSG_TYPE_CONFIRM
Definition: dhcpv6_common.h:93
@ DHCPV6_MSG_TYPE_REBIND
Definition: dhcpv6_common.h:95
@ DHCPV6_MSG_TYPE_REQUEST
Definition: dhcpv6_common.h:92
@ DHCPV6_MSG_TYPE_REPLY
Definition: dhcpv6_common.h:96
@ DHCPV6_MSG_TYPE_RELEASE
Definition: dhcpv6_common.h:97
@ DHCPV6_MSG_TYPE_RENEW
Definition: dhcpv6_common.h:94
@ DHCPV6_MSG_TYPE_ADVERTISE
Definition: dhcpv6_common.h:91
@ DHCPV6_MSG_TYPE_SOLICIT
Definition: dhcpv6_common.h:90
Dhcpv6IaAddrOption
const Ipv6Addr DHCPV6_ALL_RELAY_AGENTS_AND_SERVERS_ADDR
Definition: dhcpv6_common.c:54
Ethernet.
Eui64
Definition: ethernet.h:210
MacAddr
Definition: ethernet.h:195
uint8_t protocol
Definition: ipv4.h:296
IPv6 (Internet Protocol Version 6)
Ipv6Addr
Definition: ipv6.h:251
Ipv6Addr address[]
Definition: ipv6.h:316
uint8_t msgType
uint8_t s
Definition: ndp.h:345
TCP/IP stack core.