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