slaac.h
Go to the documentation of this file.
1 /**
2  * @file slaac.h
3  * @brief IPv6 Stateless Address Autoconfiguration
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 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 1.9.6
29  **/
30 
31 #ifndef _SLAAC_H
32 #define _SLAAC_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ipv6/ndp.h"
37 
38 //SLAAC support
39 #ifndef SLAAC_SUPPORT
40  #define SLAAC_SUPPORT ENABLED
41 #elif (SLAAC_SUPPORT != ENABLED && SLAAC_SUPPORT != DISABLED)
42  #error SLAAC_SUPPORT parameter is not valid
43 #endif
44 
45 //Time constant
46 #define SLAAC_LIFETIME_2_HOURS (2 * 3600 * 1000)
47 
48 //Forward declaration of SlaacContext structure
49 struct _SlaacContext;
50 #define SlaacContext struct _SlaacContext
51 
52 //C++ guard
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 
58 /**
59  * @brief Link state change callback
60  **/
61 
62 typedef void (*SlaacLinkChangeCallback)(SlaacContext *context,
63  NetInterface *interface, bool_t linkState);
64 
65 
66 /**
67  * @brief Router Advertisement parsing callback
68  **/
69 
70 typedef void (*SlaacParseRouterAdvCallback)(SlaacContext *context,
72 
73 
74 /**
75  * @brief SLAAC settings
76  **/
77 
78 typedef struct
79 {
80  NetInterface *interface; ///<Network interface to configure
81  bool_t manualDnsConfig; ///<Force manual DNS configuration
82  SlaacLinkChangeCallback linkChangeEvent; ///<Link state change event
83  SlaacParseRouterAdvCallback parseRouterAdvCallback; ///<Router Advertisement parsing callback
85 
86 
87 /**
88  * @brief SLAAC context
89  **/
90 
92 {
93  SlaacSettings settings; ///<SLAAC settings
94  bool_t running; ///<SLAAC is currently running
95  bool_t configUpdated; ///<This flag is set when IPv6 configuration has been updated
96 };
97 
98 
99 //SLAAC related functions
100 void slaacGetDefaultSettings(SlaacSettings *settings);
101 error_t slaacInit(SlaacContext *context, const SlaacSettings *settings);
103 error_t slaacStop(SlaacContext *context);
104 
105 void slaacLinkChangeEvent(SlaacContext *context);
106 
107 void slaacParseRouterAdv(SlaacContext *context,
109 
111  NdpPrefixInfoOption *option);
112 
114 
115 void slaacDumpConfig(SlaacContext *context);
116 
117 //C++ guard
118 #ifdef __cplusplus
119 }
120 #endif
121 
122 #endif
void slaacDumpConfig(SlaacContext *context)
Dump IPv6 configuration for debugging purpose.
Definition: slaac.c:616
uint8_t length
Definition: dtls_misc.h:149
int bool_t
Definition: compiler_port.h:49
void slaacGetDefaultSettings(SlaacSettings *settings)
Initialize settings with default values.
Definition: slaac.c:61
SlaacLinkChangeCallback linkChangeEvent
Link state change event.
Definition: slaac.h:82
bool_t running
SLAAC is currently running.
Definition: slaac.h:94
SlaacParseRouterAdvCallback parseRouterAdvCallback
Router Advertisement parsing callback.
Definition: slaac.h:83
error_t slaacStart(SlaacContext *context)
Start SLAAC process.
Definition: slaac.c:122
bool_t configUpdated
This flag is set when IPv6 configuration has been updated.
Definition: slaac.h:95
void slaacLinkChangeEvent(SlaacContext *context)
Callback function for link change event.
Definition: slaac.c:202
__start_packed struct @197 NdpPrefixInfoOption
Prefix Information option (PIO)
#define SlaacContext
Definition: slaac.h:50
error_t
Error codes.
Definition: error.h:42
#define NetInterface
Definition: net.h:36
void slaacParsePrefixInfoOption(SlaacContext *context, NdpPrefixInfoOption *option)
Parse Prefix Information Option.
Definition: slaac.c:345
void slaacParseRouterAdv(SlaacContext *context, NdpRouterAdvMessage *message, size_t length)
Parse Router Advertisement message.
Definition: slaac.c:252
error_t slaacGenerateLinkLocalAddr(SlaacContext *context)
Generate a link-local address.
Definition: slaac.c:565
bool_t manualDnsConfig
Force manual DNS configuration.
Definition: slaac.h:81
error_t slaacStop(SlaacContext *context)
Stop SLAAC process.
Definition: slaac.c:174
NDP (Neighbor Discovery Protocol)
__start_packed struct @191 NdpRouterAdvMessage
Router Advertisement message.
void(* SlaacParseRouterAdvCallback)(SlaacContext *context, NdpRouterAdvMessage *message, size_t length)
Router Advertisement parsing callback.
Definition: slaac.h:70
error_t slaacInit(SlaacContext *context, const SlaacSettings *settings)
SLAAC initialization.
Definition: slaac.c:82
uint8_t message[]
Definition: chap.h:152
void(* SlaacLinkChangeCallback)(SlaacContext *context, NetInterface *interface, bool_t linkState)
Link state change callback.
Definition: slaac.h:62
NetInterface * interface
Network interface to configure.
Definition: slaac.h:80
TCP/IP stack core.
SlaacSettings settings
SLAAC settings.
Definition: slaac.h:93
SLAAC context.
Definition: slaac.h:91
SLAAC settings.
Definition: slaac.h:78