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.4
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
IPv6 (Internet Protocol Version 6)
int bool_t
Definition: compiler_port.h:53
uint32_t reachableTime
Value of the Reachable Time field.
uint8_t message[]
Definition: chap.h:154
void(* NdpRouterAddOptionsCallback)(NdpRouterAdvContext *context, NdpRouterAdvMessage *message, size_t *length)
Add Router Advertisement options callback.
uint8_t preference
Value of the Router Selection Preferences field.
Ipv6Addr
Definition: ipv6.h:260
RA service context.
error_t ndpRouterAdvStop(NdpRouterAdvContext *context)
Stop RA service.
bool_t homeAgentFlag
Mobile IPv6 Home Agent flag.
bool_t proxyFlag
Value of the Neighbor Discovery Proxy flag.
void ndpRouterAdvGetDefaultSettings(NdpRouterAdvSettings *settings)
Initialize settings with default values.
uint32_t linkMtu
Recommended MTU for the link (MTU option)
IPv6 prefix information.
NdpRouterAdvRouteInfo * routeList
List of routes (RIO option)
NdpRouterAdvSettings settings
RA service settings.
Route information.
#define NdpRouterAdvContext
uint16_t defaultLifetime
Value of the Router Lifetime field.
NdpRouterAdvMessage
Definition: ndp.h:310
error_t
Error codes.
Definition: error.h:43
bool_t managedFlag
Managed Address Configuration flag.
uint_t routerAdvCount
Router Advertisement message counter.
#define NetInterface
Definition: net.h:36
#define NDP_ROUTER_ADV_PRIVATE_CONTEXT
NdpRouterAddOptionsCallback addOptionsCallback
Add Router Advertisement options callback.
systime_t timeout
Timeout value.
uint8_t length
Definition: tcp.h:368
error_t ndpRouterAdvStart(NdpRouterAdvContext *context)
Start RA service.
NdpRouterAdvContextInfo * contextList
List of compression contexts (6CO option)
Context information for 6LoWPAN header compression.
uint32_t systime_t
System time.
uint32_t retransTimer
Value of the Retrans Timer field.
RA service settings.
systime_t minRtrAdvInterval
Maximum time between unsolicited Router Advertisements.
uint8_t curHopLimit
Value of the Cur Hop Limit field.
bool_t otherConfigFlag
Other Configuration flag.
uint_t routeListLength
Number of routes in the list.
systime_t timestamp
Timestamp to manage retransmissions.
NetInterface * interface
Underlying network interface.
uint_t contextListLength
Number of compression contexts in the list.
error_t ndpRouterAdvInit(NdpRouterAdvContext *context, const NdpRouterAdvSettings *settings)
RA service initialization.
uint_t prefixListLength
Number of prefixes in the list.
systime_t maxRtrAdvInterval
Minimum time between unsolicited Router Advertisements.
unsigned int uint_t
Definition: compiler_port.h:50
bool_t running
This flag tells whether the RA service is running.
TCP/IP stack core.
systime_t ndpRouterAdvTickCounter
NdpRouterAdvPrefixInfo * prefixList
List of prefixes (PIO option)