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-2021 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.1.2
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 32
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
57extern "C" {
58#endif
59
60
61/**
62 * @brief DUID types
63 **/
64
65typedef enum
66{
71
72
73/**
74 * @brief Hardware types
75 **/
76
77typedef enum
78{
82
83
84/**
85 * @brief DHCPv6 message types
86 **/
87
88typedef enum
89{
104
105
106/**
107 * @brief DHCPv6 option codes
108 **/
109
110typedef enum
111{
138
139
140/**
141 * @brief Status code
142 **/
143
144typedef enum
145{
153
154
155//CodeWarrior or Win32 compiler?
156#if defined(__CWCC__) || defined(_WIN32)
157 #pragma pack(push, 1)
158#endif
159
160
161/**
162 * @brief DUID-LLT structure
163 **/
164
165typedef __start_packed struct
166{
167 uint16_t type; //0-1
168 uint16_t hardwareType; //2-3
169 uint32_t time; //4-7
172
173
174/**
175 * @brief DUID-EN structure
176 **/
177
178typedef __start_packed struct
179{
180 uint16_t type; //0-1
181 uint32_t enterpriseNumber; //2-5
182 uint8_t identifier[]; //6
184
185
186/**
187 * @brief DUID-LL structure
188 **/
189
190typedef __start_packed struct
191{
192 uint16_t type; //0-1
193 uint16_t hardwareType; //2-3
194#if (ETH_SUPPORT == ENABLED)
196#else
197 Eui64 linkLayerAddr; //4-11
198#endif
200
201
202/**
203 * @brief DHCPv6 message
204 **/
205
206typedef __start_packed struct
207{
208 uint8_t msgType; //0
209 uint8_t transactionId[3]; //1-3
210 uint8_t options[]; //4
212
213
214/**
215 * @brief DHCPv6 relay agent message
216 **/
217
218typedef __start_packed struct
219{
220 uint8_t msgType; //0
221 uint8_t hopCount; //1
224 uint8_t options[]; //34
226
227
228/**
229 * @brief DHCPv6 option
230 **/
231
232typedef __start_packed struct
233{
234 uint16_t code; //0-1
235 uint16_t length; //2-3
236 uint8_t value[]; //4
238
239
240/**
241 * @brief Identity Association for Non-temporary Addresses option
242 **/
243
244typedef __start_packed struct
245{
246 uint32_t iaId; //0-3
247 uint32_t t1; //4-7
248 uint32_t t2; //8-11
249 uint8_t options[]; //12
251
252
253/**
254 * @brief Identity Association for Temporary Addresses option
255 **/
256
257typedef __start_packed struct
258{
259 uint32_t iaId; //0-3
260 uint8_t options[]; //4
262
263
264/**
265 * @brief IA Address option
266 **/
267
268typedef __start_packed struct
269{
271 uint32_t preferredLifetime; //16-19
272 uint32_t validLifetime; //20-23
273 uint8_t options[]; //24
275
276
277/**
278 * @brief Option Request option
279 **/
280
281typedef __start_packed struct
282{
283 uint16_t requestedOption[1]; //0-1
285
286
287/**
288 * @brief Preference option
289 **/
290
291typedef __start_packed struct
292{
293 uint8_t value; //0
295
296
297/**
298 * @brief Elapsed Time option
299 **/
300
301typedef __start_packed struct
302{
303 uint16_t value; //0-1
305
306
307/**
308 * @brief Authentication option
309 **/
310
311typedef __start_packed struct
312{
313 uint8_t protocol; //0
314 uint8_t algorithm; //1
315 uint8_t rdm; //2
316 uint8_t replayDetection[8]; //3-10
317 uint8_t authInfo[]; //11
319
320
321/**
322 * @brief Server Unicast option
323 **/
324
325typedef __start_packed struct
326{
329
330
331/**
332 * @brief Status Code option
333 **/
334
335typedef __start_packed struct
336{
337 uint16_t statusCode; //0-1
340
341
342/**
343 * @brief Reconfigure Message option
344 **/
345
346typedef __start_packed struct
347{
348 uint8_t msgType; //0
350
351
352/**
353 * @brief DNS Recursive Name Server option
354 **/
355
356typedef __start_packed struct
357{
358 Ipv6Addr address[1]; //0-15
360
361
362/**
363 * @brief Domain Search List option
364 **/
365
366typedef __start_packed struct
367{
368 uint8_t searchList[1]; //0
370
371
372/**
373 * @brief Identity Association for Prefix Delegation Option
374 **/
375
376typedef __start_packed struct
377{
378 uint32_t iaId; //0-3
379 uint32_t t1; //4-7
380 uint32_t t2; //8-11
381 uint8_t options[]; //12
383
384
385/**
386 * @brief IA_PD Prefix option
387 **/
388
389typedef __start_packed struct
390{
391 uint32_t preferredLifetime; //0-3
392 uint32_t validLifetime; //4-7
393 uint8_t prefixLen; //8
395 uint8_t options[]; //25
397
398
399/**
400 * @brief Fully Qualified Domain Name option
401 **/
402
403typedef __start_packed struct
404{
405#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
406 uint8_t mbz : 5; //0
407 uint8_t n : 1;
408 uint8_t o : 1;
409 uint8_t s : 1;
410#else
411 uint8_t s : 1; //0
412 uint8_t o : 1;
413 uint8_t n : 1;
414 uint8_t mbz : 5;
415#endif
416 uint8_t domainName[]; //1
418
419
420//CodeWarrior or Win32 compiler?
421#if defined(__CWCC__) || defined(_WIN32)
422 #pragma pack(pop)
423#endif
424
425
426//DHCPv6 related constants
429
430//DHCPv6 related functions
431Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length);
432
433Dhcpv6Option *dhcpv6AddOption(void *message, size_t *messageLen,
434 uint16_t optionCode, const void *optionValue, size_t optionLen);
435
436Dhcpv6Option *dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen,
437 uint16_t optionCode, const void *optionValue, size_t optionLen);
438
439Dhcpv6Option *dhcpv6GetOption(const uint8_t *options,
440 size_t optionsLength, uint16_t optionCode);
441
442int32_t dhcpv6Rand(int32_t value);
443int32_t dhcpv6RandRange(int32_t min, int32_t max);
444
445//C++ guard
446#ifdef __cplusplus
447}
448#endif
449
450#endif
uint8_t message[]
Definition: chap.h:152
char char_t
Definition: compiler_port.h:43
Ipv6Addr peerAddress
__start_packed struct @142 Dhcpv6IaAddrOption
IA Address option.
Ipv6Addr serverAddr
uint8_t value[]
__start_packed struct @138 Dhcpv6RelayMessage
DHCPv6 relay agent message.
uint16_t length
uint32_t enterpriseNumber
uint8_t authInfo[]
__start_packed struct @140 Dhcpv6IaNaOption
Identity Association for Non-temporary Addresses option.
__start_packed struct @153 Dhcpv6IaPrefixOption
IA_PD Prefix option.
uint16_t hardwareType
__start_packed struct @144 Dhcpv6PreferenceOption
Preference option.
const Ipv6Addr DHCPV6_ALL_SERVERS_ADDR
Definition: dhcpv6_common.c:55
__start_packed struct @143 Dhcpv6OroOption
Option Request option.
uint32_t preferredLifetime
__start_packed struct @152 Dhcpv6IaPdOption
Identity Association for Prefix Delegation Option.
Dhcpv6Option * dhcpv6AddOption(void *message, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add an option to a DHCPv6 message.
uint8_t s
__start_packed struct @141 Dhcpv6IaTaOption
Identity Association for Temporary Addresses option.
uint8_t n
uint8_t transactionId[3]
Dhcpv6StatusCode dhcpv6GetStatusCode(const uint8_t *options, size_t length)
Retrieve status code.
Definition: dhcpv6_common.c:70
char_t statusMessage[]
uint8_t algorithm
__start_packed struct @137 Dhcpv6Message
DHCPv6 message.
uint8_t identifier[]
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
Dhcpv6Option * dhcpv6GetOption(const uint8_t *options, size_t optionsLength, uint16_t optionCode)
Find the specified option in a DHCPv6 message.
__start_packed struct @150 Dhcpv6DnsServersOption
DNS Recursive Name Server option.
uint32_t validLifetime
uint16_t code
uint16_t requestedOption[1]
Ipv6Addr linkAddress
__start_packed struct @151 Dhcpv6DomainListOption
Domain Search List option.
uint8_t options[]
Ipv6Addr prefix
Dhcpv6Option * dhcpv6AddSubOption(Dhcpv6Option *baseOption, size_t *messageLen, uint16_t optionCode, const void *optionValue, size_t optionLen)
Add a suboption under an existing base option.
uint8_t searchList[1]
uint8_t mbz
__start_packed struct @134 Dhcpv6DuidLlt
DUID-LLT structure.
__start_packed struct @147 Dhcpv6ServerUnicastOption
Server Unicast option.
MacAddr linkLayerAddr
uint8_t hopCount
__start_packed struct @136 Dhcpv6DuidLl
DUID-LL structure.
uint8_t msgType
__start_packed struct @135 Dhcpv6DuidEn
DUID-EN structure.
uint32_t iaId
uint32_t t2
uint8_t replayDetection[8]
Ipv6Addr address
uint8_t domainName[]
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
int32_t dhcpv6RandRange(int32_t min, int32_t max)
Get a random value in the specified range.
uint16_t type
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_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
__start_packed struct @145 Dhcpv6ElapsedTimeOption
Elapsed Time option.
uint8_t protocol
__start_packed struct @149 Dhcpv6ReconfMessageOption
Reconfigure Message option.
uint8_t rdm
__start_packed struct @154 Dhcpv6FqdnOption
Fully Qualified Domain Name option.
uint16_t statusCode
int32_t dhcpv6Rand(int32_t value)
Multiplication by a randomization factor.
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
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
__start_packed struct @148 Dhcpv6StatusCodeOption
Status Code option.
__start_packed struct @139 Dhcpv6Option
DHCPv6 option.
__start_packed struct @146 Dhcpv6AuthOption
Authentication option.
const Ipv6Addr DHCPV6_ALL_RELAY_AGENTS_AND_SERVERS_ADDR
Definition: dhcpv6_common.c:51
Ethernet.
__start_packed struct @117 Eui64
EUI-64 identifier.
__start_packed struct @116 MacAddr
MAC address.
__start_packed struct _Ipv4Header __end_packed
IPv6 (Internet Protocol Version 6)
__start_packed struct @188 Ipv6Addr
IPv6 network address.
TCP/IP stack core.