STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
nd6.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2010 Inico Technologies Ltd.
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without modification,
14  * are permitted provided that the following conditions are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  * 3. The name of the author may not be used to endorse or promote products
22  * derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33  * OF SUCH DAMAGE.
34  *
35  * This file is part of the lwIP TCP/IP stack.
36  *
37  * Author: Ivan Delamer <delamer@inicotech.com>
38  *
39  *
40  * Please coordinate changes and requests with Ivan Delamer
41  * <delamer@inicotech.com>
42  */
43 
44 #ifndef LWIP_HDR_ND6_H
45 #define LWIP_HDR_ND6_H
46 
47 #include "lwip/opt.h"
48 
49 #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
50 
51 #include "lwip/pbuf.h"
52 #include "lwip/ip6.h"
53 #include "lwip/ip6_addr.h"
54 #include "lwip/netif.h"
55 
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 /* Struct for tables. */
62 struct nd6_neighbor_cache_entry {
63  ip6_addr_t next_hop_address;
64  struct netif * netif;
65  u8_t lladdr[NETIF_MAX_HWADDR_LEN];
66  /*u32_t pmtu;*/
67 #if LWIP_ND6_QUEUEING
68 
69  struct nd6_q_entry *q;
70 #else /* LWIP_ND6_QUEUEING */
71 
72  struct pbuf *q;
73 #endif /* LWIP_ND6_QUEUEING */
74  u8_t state;
75  u8_t isrouter;
76  union {
77  u32_t reachable_time;
78  u32_t delay_time;
79  u32_t probes_sent;
80  u32_t stale_time;
81  } counter;
82 };
83 
84 struct nd6_destination_cache_entry {
85  ip6_addr_t destination_addr;
86  ip6_addr_t next_hop_addr;
87  u16_t pmtu;
88  u32_t age;
89 };
90 
91 struct nd6_prefix_list_entry {
92  ip6_addr_t prefix;
93  struct netif * netif;
94  u32_t invalidation_timer;
95 #if LWIP_IPV6_AUTOCONFIG
96  u8_t flags;
97 #define ND6_PREFIX_AUTOCONFIG_AUTONOMOUS 0x01
98 #define ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED 0x02
99 #define ND6_PREFIX_AUTOCONFIG_ADDRESS_DUPLICATE 0x04
100 #endif /* LWIP_IPV6_AUTOCONFIG */
101 };
102 
103 struct nd6_router_list_entry {
104  struct nd6_neighbor_cache_entry * neighbor_entry;
105  u32_t invalidation_timer;
106  u8_t flags;
107 };
108 
109 
110 enum nd6_neighbor_cache_entry_state {
111  ND6_NO_ENTRY = 0,
112  ND6_INCOMPLETE,
113  ND6_REACHABLE,
114  ND6_STALE,
115  ND6_DELAY,
116  ND6_PROBE
117 };
118 
119 #if LWIP_ND6_QUEUEING
120 
123 struct nd6_q_entry {
124  struct nd6_q_entry *next;
125  struct pbuf *p;
126 };
127 #endif /* LWIP_ND6_QUEUEING */
128 
130 #ifdef PACK_STRUCT_USE_INCLUDES
131 # include "arch/bpstruct.h"
132 #endif
134 struct ns_header {
135  PACK_STRUCT_FLD_8(u8_t type);
136  PACK_STRUCT_FLD_8(u8_t code);
137  PACK_STRUCT_FIELD(u16_t chksum);
138  PACK_STRUCT_FIELD(u32_t reserved);
139  PACK_STRUCT_FLD_S(ip6_addr_p_t target_address);
140  /* Options follow. */
143 #ifdef PACK_STRUCT_USE_INCLUDES
144 # include "arch/epstruct.h"
145 #endif
146 
148 #ifdef PACK_STRUCT_USE_INCLUDES
149 # include "arch/bpstruct.h"
150 #endif
152 struct na_header {
153  PACK_STRUCT_FLD_8(u8_t type);
154  PACK_STRUCT_FLD_8(u8_t code);
155  PACK_STRUCT_FIELD(u16_t chksum);
156  PACK_STRUCT_FLD_8(u8_t flags);
157  PACK_STRUCT_FLD_8(u8_t reserved[3]);
158  PACK_STRUCT_FLD_S(ip6_addr_p_t target_address);
159  /* Options follow. */
162 #ifdef PACK_STRUCT_USE_INCLUDES
163 # include "arch/epstruct.h"
164 #endif
165 #define ND6_FLAG_ROUTER (0x80)
166 #define ND6_FLAG_SOLICITED (0x40)
167 #define ND6_FLAG_OVERRIDE (0x20)
168 
170 #ifdef PACK_STRUCT_USE_INCLUDES
171 # include "arch/bpstruct.h"
172 #endif
174 struct rs_header {
175  PACK_STRUCT_FLD_8(u8_t type);
176  PACK_STRUCT_FLD_8(u8_t code);
177  PACK_STRUCT_FIELD(u16_t chksum);
178  PACK_STRUCT_FIELD(u32_t reserved);
179  /* Options follow. */
182 #ifdef PACK_STRUCT_USE_INCLUDES
183 # include "arch/epstruct.h"
184 #endif
185 
187 #define ND6_RA_FLAG_MANAGED_ADDR_CONFIG (0x80)
188 #define ND6_RA_FLAG_OTHER_CONFIG (0x40)
189 #define ND6_RA_FLAG_HOME_AGENT (0x20)
190 #define ND6_RA_PREFERENCE_MASK (0x18)
191 #define ND6_RA_PREFERENCE_HIGH (0x08)
192 #define ND6_RA_PREFERENCE_MEDIUM (0x00)
193 #define ND6_RA_PREFERENCE_LOW (0x18)
194 #define ND6_RA_PREFERENCE_DISABLED (0x10)
195 #ifdef PACK_STRUCT_USE_INCLUDES
196 # include "arch/bpstruct.h"
197 #endif
199 struct ra_header {
200  PACK_STRUCT_FLD_8(u8_t type);
201  PACK_STRUCT_FLD_8(u8_t code);
202  PACK_STRUCT_FIELD(u16_t chksum);
203  PACK_STRUCT_FLD_8(u8_t current_hop_limit);
204  PACK_STRUCT_FLD_8(u8_t flags);
205  PACK_STRUCT_FIELD(u16_t router_lifetime);
206  PACK_STRUCT_FIELD(u32_t reachable_time);
207  PACK_STRUCT_FIELD(u32_t retrans_timer);
208  /* Options follow. */
211 #ifdef PACK_STRUCT_USE_INCLUDES
212 # include "arch/epstruct.h"
213 #endif
214 
216 #ifdef PACK_STRUCT_USE_INCLUDES
217 # include "arch/bpstruct.h"
218 #endif
220 struct redirect_header {
221  PACK_STRUCT_FLD_8(u8_t type);
222  PACK_STRUCT_FLD_8(u8_t code);
223  PACK_STRUCT_FIELD(u16_t chksum);
224  PACK_STRUCT_FIELD(u32_t reserved);
225  PACK_STRUCT_FLD_S(ip6_addr_p_t target_address);
226  PACK_STRUCT_FLD_S(ip6_addr_p_t destination_address);
227  /* Options follow. */
230 #ifdef PACK_STRUCT_USE_INCLUDES
231 # include "arch/epstruct.h"
232 #endif
233 
235 #define ND6_OPTION_TYPE_SOURCE_LLADDR (0x01)
236 #define ND6_OPTION_TYPE_TARGET_LLADDR (0x02)
237 #ifdef PACK_STRUCT_USE_INCLUDES
238 # include "arch/bpstruct.h"
239 #endif
241 struct lladdr_option {
242  PACK_STRUCT_FLD_8(u8_t type);
243  PACK_STRUCT_FLD_8(u8_t length);
247 #ifdef PACK_STRUCT_USE_INCLUDES
248 # include "arch/epstruct.h"
249 #endif
250 
252 #define ND6_OPTION_TYPE_PREFIX_INFO (0x03)
253 #define ND6_PREFIX_FLAG_ON_LINK (0x80)
254 #define ND6_PREFIX_FLAG_AUTONOMOUS (0x40)
255 #define ND6_PREFIX_FLAG_ROUTER_ADDRESS (0x20)
256 #define ND6_PREFIX_FLAG_SITE_PREFIX (0x10)
257 #ifdef PACK_STRUCT_USE_INCLUDES
258 # include "arch/bpstruct.h"
259 #endif
261 struct prefix_option {
262  PACK_STRUCT_FLD_8(u8_t type);
263  PACK_STRUCT_FLD_8(u8_t length);
264  PACK_STRUCT_FLD_8(u8_t prefix_length);
265  PACK_STRUCT_FLD_8(u8_t flags);
266  PACK_STRUCT_FIELD(u32_t valid_lifetime);
267  PACK_STRUCT_FIELD(u32_t preferred_lifetime);
268  PACK_STRUCT_FLD_8(u8_t reserved2[3]);
269  PACK_STRUCT_FLD_8(u8_t site_prefix_length);
270  PACK_STRUCT_FLD_S(ip6_addr_p_t prefix);
273 #ifdef PACK_STRUCT_USE_INCLUDES
274 # include "arch/epstruct.h"
275 #endif
276 
278 #define ND6_OPTION_TYPE_REDIR_HDR (0x04)
279 #ifdef PACK_STRUCT_USE_INCLUDES
280 # include "arch/bpstruct.h"
281 #endif
283 struct redirected_header_option {
284  PACK_STRUCT_FLD_8(u8_t type);
285  PACK_STRUCT_FLD_8(u8_t length);
286  PACK_STRUCT_FLD_8(u8_t reserved[6]);
287  /* Portion of redirected packet follows. */
288  /* PACK_STRUCT_FLD_8(u8_t redirected[8]); */
291 #ifdef PACK_STRUCT_USE_INCLUDES
292 # include "arch/epstruct.h"
293 #endif
294 
296 #define ND6_OPTION_TYPE_MTU (0x05)
297 #ifdef PACK_STRUCT_USE_INCLUDES
298 # include "arch/bpstruct.h"
299 #endif
301 struct mtu_option {
302  PACK_STRUCT_FLD_8(u8_t type);
303  PACK_STRUCT_FLD_8(u8_t length);
304  PACK_STRUCT_FIELD(u16_t reserved);
308 #ifdef PACK_STRUCT_USE_INCLUDES
309 # include "arch/epstruct.h"
310 #endif
311 
313 #define ND6_OPTION_TYPE_ROUTE_INFO (24)
314 #ifdef PACK_STRUCT_USE_INCLUDES
315 # include "arch/bpstruct.h"
316 #endif
318 struct route_option {
319  PACK_STRUCT_FLD_8(u8_t type);
320  PACK_STRUCT_FLD_8(u8_t length);
321  PACK_STRUCT_FLD_8(u8_t prefix_length);
322  PACK_STRUCT_FLD_8(u8_t preference);
323  PACK_STRUCT_FIELD(u32_t route_lifetime);
324  PACK_STRUCT_FLD_S(ip6_addr_p_t prefix);
327 #ifdef PACK_STRUCT_USE_INCLUDES
328 # include "arch/epstruct.h"
329 #endif
330 
332 #define ND6_TMR_INTERVAL 1000
333 
334 /* Router tables. */
335 /* TODO make these static? and entries accessible through API? */
336 extern struct nd6_neighbor_cache_entry neighbor_cache[];
337 extern struct nd6_destination_cache_entry destination_cache[];
338 extern struct nd6_prefix_list_entry prefix_list[];
339 extern struct nd6_router_list_entry default_router_list[];
340 
341 /* Default values, can be updated by a RA message. */
342 extern u32_t reachable_time;
343 extern u32_t retrans_timer;
344 
345 void nd6_tmr(void);
346 void nd6_input(struct pbuf *p, struct netif *inp);
347 s8_t nd6_get_next_hop_entry(const ip6_addr_t * ip6addr, struct netif * netif);
348 s8_t nd6_select_router(const ip6_addr_t * ip6addr, struct netif * netif);
349 u16_t nd6_get_destination_mtu(const ip6_addr_t * ip6addr, struct netif * netif);
350 err_t nd6_queue_packet(s8_t neighbor_index, struct pbuf * p);
351 #if LWIP_ND6_TCP_REACHABILITY_HINTS
352 void nd6_reachability_hint(const ip6_addr_t * ip6addr);
353 #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */
354 
355 #ifdef __cplusplus
356 }
357 #endif
358 
359 #endif /* LWIP_IPV6 */
360 
361 #endif /* LWIP_HDR_ND6_H */
362 
u8_t flags
Definition: netif.h:269
#define PACK_STRUCT_STRUCT
Definition: arch.h:68
signed char s8_t
Definition: cc.h:39
#define PACK_STRUCT_FLD_8(x)
Definition: arch.h:78
#define PACK_STRUCT_FIELD(x)
Definition: arch.h:72
#define NETIF_MAX_HWADDR_LEN
Definition: netif.h:68
unsigned long u32_t
Definition: cc.h:42
Definition: pbuf.h:108
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
#define PACK_STRUCT_FLD_S(x)
Definition: arch.h:84
#define PACK_STRUCT_BEGIN
Definition: arch.h:60
unsigned char u8_t
Definition: cc.h:38
#define PACK_STRUCT_END
Definition: arch.h:64
unsigned short u16_t
Definition: cc.h:40