ndp_router_adv.h
Go to the documentation of this file.
1 /**
2  * @file ndp_router_adv.h
3  * @brief Router advertisement service
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 _NDP_ROUTER_ADV_H
32 #define _NDP_ROUTER_ADV_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ipv6/ipv6.h"
37 
38 //RA service support
39 #ifndef NDP_ROUTER_ADV_SUPPORT
40  #define NDP_ROUTER_ADV_SUPPORT DISABLED
41 #elif (NDP_ROUTER_ADV_SUPPORT != ENABLED && NDP_ROUTER_ADV_SUPPORT != DISABLED)
42  #error NDP_ROUTER_ADV_SUPPORT parameter is not valid
43 #endif
44 
45 //RA service tick interval
46 #ifndef NDP_ROUTER_ADV_TICK_INTERVAL
47  #define NDP_ROUTER_ADV_TICK_INTERVAL 100
48 #elif (NDP_ROUTER_ADV_TICK_INTERVAL < 10)
49  #error NDP_ROUTER_ADV_TICK_INTERVAL parameter is not valid
50 #endif
51 
52 //Application specific context
53 #ifndef NDP_ROUTER_ADV_PRIVATE_CONTEXT
54  #define NDP_ROUTER_ADV_PRIVATE_CONTEXT
55 #endif
56 
57 //Forward declaration of NdpRouterAdvContext structure
59 #define NdpRouterAdvContext struct _NdpRouterAdvContext
60 
61 //C++ guard
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 
67 /**
68  * @brief Add Router Advertisement options callback
69  **/
70 
73 
74 
75 /**
76  * @brief IPv6 prefix information
77  **/
78 
79 typedef struct
80 {
82  uint8_t length;
85  uint32_t validLifetime;
88 
89 
90 /**
91  * @brief Route information
92  **/
93 
94 typedef struct
95 {
97  uint8_t length;
98  uint8_t preference;
99  uint32_t routeLifetime;
101 
102 
103 /**
104  * @brief Context information for 6LoWPAN header compression
105  **/
106 
107 typedef struct
108 {
109  uint8_t cid;
111  uint8_t length;
113  uint16_t validLifetime;
115 
116 
117 /**
118  * @brief RA service settings
119  **/
120 
121 typedef struct
122 {
123  NetInterface *interface; ///<Underlying network interface
124  systime_t maxRtrAdvInterval; ///<Minimum time between unsolicited Router Advertisements
125  systime_t minRtrAdvInterval; ///<Maximum time between unsolicited Router Advertisements
126  uint8_t curHopLimit; ///<Value of the Cur Hop Limit field
127  bool_t managedFlag; ///<Managed Address Configuration flag
128  bool_t otherConfigFlag; ///<Other Configuration flag
129  bool_t homeAgentFlag; ///<Mobile IPv6 Home Agent flag
130  uint8_t preference; ///<Value of the Router Selection Preferences field
131  bool_t proxyFlag; ///<Value of the Neighbor Discovery Proxy flag
132  uint16_t defaultLifetime; ///<Value of the Router Lifetime field
133  uint32_t reachableTime; ///<Value of the Reachable Time field
134  uint32_t retransTimer; ///<Value of the Retrans Timer field
135  uint32_t linkMtu; ///<Recommended MTU for the link (MTU option)
136  NdpRouterAdvPrefixInfo *prefixList; ///<List of prefixes (PIO option)
137  uint_t prefixListLength; ///<Number of prefixes in the list
138  NdpRouterAdvRouteInfo *routeList; ///<List of routes (RIO option)
139  uint_t routeListLength; ///<Number of routes in the list
140  NdpRouterAdvContextInfo *contextList; ///<List of compression contexts (6CO option)
141  uint_t contextListLength; ///<Number of compression contexts in the list
142  NdpRouterAddOptionsCallback addOptionsCallback; ///<Add Router Advertisement options callback
144 
145 
146 /**
147  * @brief RA service context
148  **/
149 
151 {
152  NdpRouterAdvSettings settings; ///<RA service settings
153  bool_t running; ///<This flag tells whether the RA service is running
154  systime_t timestamp; ///<Timestamp to manage retransmissions
155  systime_t timeout; ///<Timeout value
156  uint_t routerAdvCount; ///<Router Advertisement message counter
157  NDP_ROUTER_ADV_PRIVATE_CONTEXT ///<Application specific context
158 };
159 
160 
161 //Tick counter to handle periodic operations
163 
164 //RA service related functions
166 
168  const NdpRouterAdvSettings *settings);
169 
172 
173 //C++ guard
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif
uint8_t message[]
Definition: chap.h:154
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
error_t
Error codes.
Definition: error.h:43
IPv6 (Internet Protocol Version 6)
Ipv6Addr
Definition: ipv6.h:251
NdpRouterAdvMessage
Definition: ndp.h:310
error_t ndpRouterAdvInit(NdpRouterAdvContext *context, const NdpRouterAdvSettings *settings)
RA service initialization.
#define NDP_ROUTER_ADV_PRIVATE_CONTEXT
systime_t ndpRouterAdvTickCounter
error_t ndpRouterAdvStart(NdpRouterAdvContext *context)
Start RA service.
void(* NdpRouterAddOptionsCallback)(NdpRouterAdvContext *context, NdpRouterAdvMessage *message, size_t *length)
Add Router Advertisement options callback.
void ndpRouterAdvGetDefaultSettings(NdpRouterAdvSettings *settings)
Initialize settings with default values.
#define NdpRouterAdvContext
error_t ndpRouterAdvStop(NdpRouterAdvContext *context)
Stop RA service.
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
uint32_t systime_t
System time.
RA service context.
uint_t routerAdvCount
Router Advertisement message counter.
systime_t timestamp
Timestamp to manage retransmissions.
bool_t running
This flag tells whether the RA service is running.
systime_t timeout
Timeout value.
NdpRouterAdvSettings settings
RA service settings.
Context information for 6LoWPAN header compression.
IPv6 prefix information.
Route information.
RA service settings.
systime_t maxRtrAdvInterval
Minimum time between unsolicited Router Advertisements.
uint32_t linkMtu
Recommended MTU for the link (MTU option)
uint16_t defaultLifetime
Value of the Router Lifetime field.
NdpRouterAdvContextInfo * contextList
List of compression contexts (6CO option)
uint_t prefixListLength
Number of prefixes in the list.
NdpRouterAdvPrefixInfo * prefixList
List of prefixes (PIO option)
bool_t proxyFlag
Value of the Neighbor Discovery Proxy flag.
uint_t routeListLength
Number of routes in the list.
NdpRouterAddOptionsCallback addOptionsCallback
Add Router Advertisement options callback.
uint8_t curHopLimit
Value of the Cur Hop Limit field.
bool_t managedFlag
Managed Address Configuration flag.
bool_t homeAgentFlag
Mobile IPv6 Home Agent flag.
uint32_t reachableTime
Value of the Reachable Time field.
uint32_t retransTimer
Value of the Retrans Timer field.
bool_t otherConfigFlag
Other Configuration flag.
systime_t minRtrAdvInterval
Maximum time between unsolicited Router Advertisements.
uint_t contextListLength
Number of compression contexts in the list.
uint8_t preference
Value of the Router Selection Preferences field.
NdpRouterAdvRouteInfo * routeList
List of routes (RIO option)
NetInterface * interface
Underlying network interface.
uint8_t length
Definition: tcp.h:368