Contiki 3.x
uip-ds6.h
Go to the documentation of this file.
1 /**
2  * \addtogroup uip6
3  * @{
4  */
5 
6 /**
7  * \file
8  * Header file for IPv6-related data structures
9  * \author Mathilde Durvy <mdurvy@cisco.com>
10  * \author Julien Abeille <jabeille@cisco.com>
11  *
12  */
13 /*
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in the
22  * documentation and/or other materials provided with the distribution.
23  * 3. Neither the name of the Institute nor the names of its contributors
24  * may be used to endorse or promote products derived from this software
25  * without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *
40  */
41 
42 #ifndef UIP_DS6_H_
43 #define UIP_DS6_H_
44 
45 #include "net/ip/uip.h"
46 #include "sys/stimer.h"
47 /* The size of uip_ds6_addr_t depends on UIP_ND6_DEF_MAXDADNS. Include uip-nd6.h to define it. */
48 #include "net/ipv6/uip-nd6.h"
49 #include "net/ipv6/uip-ds6-route.h"
50 #include "net/ipv6/uip-ds6-nbr.h"
51 
52 /*--------------------------------------------------*/
53 /** Configuration. For all tables (Neighbor cache, Prefix List, Routing Table,
54  * Default Router List, Unicast address list, multicast address list, anycast address list),
55  * we define:
56  * - the number of elements requested by the user in contiki configuration (name suffixed by _NBU)
57  * - the number of elements assigned by the system (name suffixed by _NBS)
58  * - the total number of elements is the sum (name suffixed by _NB)
59 */
60 
61 /* Default router list */
62 #define UIP_DS6_DEFRT_NBS 0
63 #ifndef UIP_CONF_DS6_DEFRT_NBU
64 #define UIP_DS6_DEFRT_NBU 2
65 #else
66 #define UIP_DS6_DEFRT_NBU UIP_CONF_DS6_DEFRT_NBU
67 #endif
68 #define UIP_DS6_DEFRT_NB UIP_DS6_DEFRT_NBS + UIP_DS6_DEFRT_NBU
69 
70 /* Default prefix */
71 #ifdef UIP_CONF_DS6_DEFAULT_PREFIX
72 #define UIP_DS6_DEFAULT_PREFIX UIP_CONF_DS6_DEFAULT_PREFIX
73 #else
74 /* From RFC4193, section 3.1:
75  * | 7 bits |1| 40 bits | 16 bits | 64 bits |
76  * +--------+-+------------+-----------+----------------------------+
77  * | Prefix |L| Global ID | Subnet ID | Interface ID |
78  * +--------+-+------------+-----------+----------------------------+
79  * Prefix FC00::/7 prefix to identify Local IPv6 unicast
80  * addresses.
81  * L Set to 1 if the prefix is locally assigned.
82  * Set to 0 may be defined in the future. See
83  * Section 3.2 for additional information.
84  * Global ID 40-bit global identifier used to create a
85  * globally unique prefix. See Section 3.2 for
86  * additional information.
87  *
88  * We set prefix to 0xfc00 and set the local bit, resulting in 0xfd00.
89  * For high probability of network uniqueness, Global ID must be generated
90  * pseudo-randomly. As this is a hard-coded default prefix, we simply use
91  * a Global ID of 0. For real deployments, make sure to install a pseudo-random
92  * Global ID, e.g. in a RPL network, by configuring it at the root.
93  */
94 #define UIP_DS6_DEFAULT_PREFIX 0xfd00
95 #endif /* UIP_CONF_DS6_DEFAULT_PREFIX */
96 
97 #define UIP_DS6_DEFAULT_PREFIX_0 ((UIP_DS6_DEFAULT_PREFIX >> 8) & 0xff)
98 #define UIP_DS6_DEFAULT_PREFIX_1 (UIP_DS6_DEFAULT_PREFIX & 0xff)
99 
100 /* Prefix list */
101 #define UIP_DS6_PREFIX_NBS 1
102 #ifndef UIP_CONF_DS6_PREFIX_NBU
103 #define UIP_DS6_PREFIX_NBU 2
104 #else
105 #define UIP_DS6_PREFIX_NBU UIP_CONF_DS6_PREFIX_NBU
106 #endif
107 #define UIP_DS6_PREFIX_NB UIP_DS6_PREFIX_NBS + UIP_DS6_PREFIX_NBU
108 
109 /* Unicast address list*/
110 #define UIP_DS6_ADDR_NBS 1
111 #ifndef UIP_CONF_DS6_ADDR_NBU
112 #define UIP_DS6_ADDR_NBU 2
113 #else
114 #define UIP_DS6_ADDR_NBU UIP_CONF_DS6_ADDR_NBU
115 #endif
116 #define UIP_DS6_ADDR_NB UIP_DS6_ADDR_NBS + UIP_DS6_ADDR_NBU
117 
118 /* Multicast address list */
119 #if UIP_CONF_ROUTER
120 #define UIP_DS6_MADDR_NBS 2 + UIP_DS6_ADDR_NB /* all routers + all nodes + one solicited per unicast */
121 #else
122 #define UIP_DS6_MADDR_NBS 1 + UIP_DS6_ADDR_NB /* all nodes + one solicited per unicast */
123 #endif
124 #ifndef UIP_CONF_DS6_MADDR_NBU
125 #define UIP_DS6_MADDR_NBU 0
126 #else
127 #define UIP_DS6_MADDR_NBU UIP_CONF_DS6_MADDR_NBU
128 #endif
129 #define UIP_DS6_MADDR_NB UIP_DS6_MADDR_NBS + UIP_DS6_MADDR_NBU
130 
131 /* Anycast address list */
132 #if UIP_CONF_ROUTER
133 #define UIP_DS6_AADDR_NBS UIP_DS6_PREFIX_NB - 1 /* One per non link local prefix (subnet prefix anycast address) */
134 #else
135 #define UIP_DS6_AADDR_NBS 0
136 #endif
137 #ifndef UIP_CONF_DS6_AADDR_NBU
138 #define UIP_DS6_AADDR_NBU 0
139 #else
140 #define UIP_DS6_AADDR_NBU UIP_CONF_DS6_AADDR_NBU
141 #endif
142 #define UIP_DS6_AADDR_NB UIP_DS6_AADDR_NBS + UIP_DS6_AADDR_NBU
143 
144 /*--------------------------------------------------*/
145 /* Should we use LinkLayer acks in NUD ?*/
146 #ifndef UIP_CONF_DS6_LL_NUD
147 #define UIP_DS6_LL_NUD 0
148 #else
149 #define UIP_DS6_LL_NUD UIP_CONF_DS6_LL_NUD
150 #endif
151 
152 /** \brief Possible states for the an address (RFC 4862) */
153 #define ADDR_TENTATIVE 0
154 #define ADDR_PREFERRED 1
155 #define ADDR_DEPRECATED 2
156 
157 /** \brief How the address was acquired: Autoconf, DHCP or manually */
158 #define ADDR_ANYTYPE 0
159 #define ADDR_AUTOCONF 1
160 #define ADDR_DHCP 2
161 #define ADDR_MANUAL 3
162 
163 /** \brief General DS6 definitions */
164 /** Period for uip-ds6 periodic task*/
165 #ifndef UIP_DS6_CONF_PERIOD
166 #define UIP_DS6_PERIOD (CLOCK_SECOND/10)
167 #else
168 #define UIP_DS6_PERIOD UIP_DS6_CONF_PERIOD
169 #endif
170 
171 #define FOUND 0
172 #define FREESPACE 1
173 #define NOSPACE 2
174 /*--------------------------------------------------*/
175 
176 #if UIP_CONF_IPV6_QUEUE_PKT
177 #include "net/ip/uip-packetqueue.h"
178 #endif /*UIP_CONF_QUEUE_PKT */
179 
180 /** \brief A prefix list entry */
181 #if UIP_CONF_ROUTER
182 typedef struct uip_ds6_prefix {
183  uint8_t isused;
184  uip_ipaddr_t ipaddr;
185  uint8_t length;
186  uint8_t advertise;
187  uint32_t vlifetime;
188  uint32_t plifetime;
189  uint8_t l_a_reserved; /**< on-link and autonomous flags + 6 reserved bits */
191 #else /* UIP_CONF_ROUTER */
192 typedef struct uip_ds6_prefix {
193  uint8_t isused;
194  uip_ipaddr_t ipaddr;
195  uint8_t length;
196  struct stimer vlifetime;
197  uint8_t isinfinite;
199 #endif /*UIP_CONF_ROUTER */
200 
201 /** * \brief Unicast address structure */
202 typedef struct uip_ds6_addr {
203  uint8_t isused;
204  uip_ipaddr_t ipaddr;
205  uint8_t state;
206  uint8_t type;
207  uint8_t isinfinite;
208  struct stimer vlifetime;
209 #if UIP_ND6_DEF_MAXDADNS > 0
210  struct timer dadtimer;
211  uint8_t dadnscount;
212 #endif /* UIP_ND6_DEF_MAXDADNS > 0 */
214 
215 /** \brief Anycast address */
216 typedef struct uip_ds6_aaddr {
217  uint8_t isused;
218  uip_ipaddr_t ipaddr;
220 
221 /** \brief A multicast address */
222 typedef struct uip_ds6_maddr {
223  uint8_t isused;
224  uip_ipaddr_t ipaddr;
226 
227 /* only define the callback if RPL is active */
228 #if UIP_CONF_IPV6_RPL
229 #ifndef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED
230 #define UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED rpl_ipv6_neighbor_callback
231 #endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */
232 #endif /* UIP_CONF_IPV6_RPL */
233 
234 #if UIP_CONF_IPV6_RPL
235 #ifndef UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK
236 #define UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK rpl_link_neighbor_callback
237 #endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */
238 #endif /* UIP_CONF_IPV6_RPL */
239 
240 
241 /** \brief Interface structure (contains all the interface variables) */
242 typedef struct uip_ds6_netif {
243  uint32_t link_mtu;
244  uint8_t cur_hop_limit;
245  uint32_t base_reachable_time; /* in msec */
246  uint32_t reachable_time; /* in msec */
247  uint32_t retrans_timer; /* in msec */
248  uint8_t maxdadns;
249 #if UIP_DS6_ADDR_NB
250  uip_ds6_addr_t addr_list[UIP_DS6_ADDR_NB];
251 #endif /* UIP_DS6_ADDR_NB */
252 #if UIP_DS6_AADDR_NB
253  uip_ds6_aaddr_t aaddr_list[UIP_DS6_AADDR_NB];
254 #endif /* UIP_DS6_AADDR_NB */
255 #if UIP_DS6_MADDR_NB
256  uip_ds6_maddr_t maddr_list[UIP_DS6_MADDR_NB];
257 #endif /* UIP_DS6_MADDR_NB */
259 
260 /** \brief Generic type for a DS6, to use a common loop though all DS */
261 typedef struct uip_ds6_element {
262  uint8_t isused;
263  uip_ipaddr_t ipaddr;
265 
266 
267 /*---------------------------------------------------------------------------*/
269 extern struct etimer uip_ds6_timer_periodic;
270 
271 #if UIP_CONF_ROUTER
272 extern uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB];
273 #else /* UIP_CONF_ROUTER */
274 extern struct etimer uip_ds6_timer_rs;
275 #endif /* UIP_CONF_ROUTER */
276 
277 
278 /*---------------------------------------------------------------------------*/
279 /** \brief Initialize data structures */
280 void uip_ds6_init(void);
281 
282 /** \brief Periodic processing of data structures */
283 void uip_ds6_periodic(void);
284 
285 /** \brief Generic loop routine on an abstract data structure, which generalizes
286  * all data structures used in DS6 */
287 uint8_t uip_ds6_list_loop(uip_ds6_element_t *list, uint8_t size,
288  uint16_t elementsize, uip_ipaddr_t *ipaddr,
289  uint8_t ipaddrlen,
290  uip_ds6_element_t **out_element);
291 
292 /** @} */
293 
294 
295 /** \name Prefix list basic routines */
296 /** @{ */
297 #if UIP_CONF_ROUTER
298 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
299  uint8_t advertise, uint8_t flags,
300  unsigned long vtime,
301  unsigned long ptime);
302 #else /* UIP_CONF_ROUTER */
303 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
304  unsigned long interval);
305 #endif /* UIP_CONF_ROUTER */
306 void uip_ds6_prefix_rm(uip_ds6_prefix_t *prefix);
307 uip_ds6_prefix_t *uip_ds6_prefix_lookup(uip_ipaddr_t *ipaddr,
308  uint8_t ipaddrlen);
309 uint8_t uip_ds6_is_addr_onlink(uip_ipaddr_t *ipaddr);
310 
311 /** @} */
312 
313 /** \name Unicast address list basic routines */
314 /** @{ */
315 /** \brief Add a unicast address to the interface */
316 uip_ds6_addr_t *uip_ds6_addr_add(uip_ipaddr_t *ipaddr,
317  unsigned long vlifetime, uint8_t type);
318 void uip_ds6_addr_rm(uip_ds6_addr_t *addr);
319 uip_ds6_addr_t *uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr);
320 uip_ds6_addr_t *uip_ds6_get_link_local(int8_t state);
321 uip_ds6_addr_t *uip_ds6_get_global(int8_t state);
322 
323 /** @} */
324 
325 /** \name Multicast address list basic routines */
326 /** @{ */
327 uip_ds6_maddr_t *uip_ds6_maddr_add(const uip_ipaddr_t *ipaddr);
328 void uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr);
329 uip_ds6_maddr_t *uip_ds6_maddr_lookup(const uip_ipaddr_t *ipaddr);
330 
331 /** @} */
332 
333 /** \name Anycast address list basic routines */
334 /** @{ */
335 uip_ds6_aaddr_t *uip_ds6_aaddr_add(uip_ipaddr_t *ipaddr);
336 void uip_ds6_aaddr_rm(uip_ds6_aaddr_t *aaddr);
337 uip_ds6_aaddr_t *uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr);
338 
339 /** @} */
340 
341 
342 /** \brief set the last 64 bits of an IP address based on the MAC address */
343 void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr);
344 
345 /** \brief Get the number of matching bits of two addresses */
346 uint8_t get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst);
347 
348 #if UIP_ND6_DEF_MAXDADNS >0
349 /** \brief Perform Duplicate Address Selection on one address */
350 void uip_ds6_dad(uip_ds6_addr_t *ifaddr);
351 
352 /** \brief Callback when DAD failed */
354 #endif /* UIP_ND6_DEF_MAXDADNS */
355 
356 /** \brief Source address selection, see RFC 3484 */
357 void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst);
358 
359 #if UIP_CONF_ROUTER
360 #if UIP_ND6_SEND_RA
361 /** \brief Send a RA as an asnwer to a RS */
362 void uip_ds6_send_ra_sollicited(void);
363 
364 /** \brief Send a periodic RA */
365 void uip_ds6_send_ra_periodic(void);
366 #endif /* UIP_ND6_SEND_RA */
367 #else /* UIP_CONF_ROUTER */
368 /** \brief Send periodic RS to find router */
369 void uip_ds6_send_rs(void);
370 #endif /* UIP_CONF_ROUTER */
371 
372 /** \brief Compute the reachable time based on base reachable time, see RFC 4861*/
373 uint32_t uip_ds6_compute_reachable_time(void); /** \brief compute random reachable timer */
374 
375 /** \name Macros to check if an IP address (unicast, multicast or anycast) is mine */
376 /** @{ */
377 #define uip_ds6_is_my_addr(addr) (uip_ds6_addr_lookup(addr) != NULL)
378 #define uip_ds6_is_my_maddr(addr) (uip_ds6_maddr_lookup(addr) != NULL)
379 #define uip_ds6_is_my_aaddr(addr) (uip_ds6_aaddr_lookup(addr) != NULL)
380 /** @} */
381 /** @} */
382 
383 #endif /* UIP_DS6_H_ */
Header file for IPv6 Neighbor discovery (RFC 4861)
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition: uip-nd6.c:129
struct uip_ds6_addr uip_ds6_addr_t
Unicast address structure.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
Definition: uip-nd6.c:124
A prefix list entry.
Definition: uip-ds6.h:192
Header file for routing table manipulation.
void uip_ds6_send_rs(void)
Send periodic RS to find router.
Definition: uip-ds6.c:684
uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB]
Prefix list.
Definition: uip-ds6.c:72
A timer.
Definition: timer.h:86
A timer.
Definition: etimer.h:76
int uip_ds6_dad_failed(uip_ds6_addr_t *ifaddr)
Callback when DAD failed.
Definition: uip-ds6.c:617
struct uip_ds6_element uip_ds6_element_t
Generic type for a DS6, to use a common loop though all DS.
IPv6 Neighbor cache (link-layer/IPv6 address mapping)
struct uip_ds6_prefix uip_ds6_prefix_t
A prefix list entry.
uint8_t uip_ds6_list_loop(uip_ds6_element_t *list, uint8_t size, uint16_t elementsize, uip_ipaddr_t *ipaddr, uint8_t ipaddrlen, uip_ds6_element_t **out_element)
Generic loop routine on an abstract data structure, which generalizes all data structures used in DS6...
Definition: uip-ds6.c:205
struct etimer uip_ds6_timer_periodic
Timer for maintenance of data structures.
Definition: uip-ds6.c:56
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
Definition: uip-ds6.c:504
Second timer library header file.
Unicast address structure.
Definition: uip-ds6.h:202
uint32_t uip_ds6_compute_reachable_time(void)
Compute the reachable time based on base reachable time, see RFC 4861.
Definition: uip-ds6.c:704
Interface structure (contains all the interface variables)
Definition: uip-ds6.h:242
struct uip_ds6_maddr uip_ds6_maddr_t
A multicast address.
struct etimer uip_ds6_timer_rs
RS timer, to schedule RS sending.
Definition: uip-ds6.c:65
802.3 address
Definition: uip.h:129
void uip_ds6_periodic(void)
Periodic processing of data structures.
Definition: uip-ds6.c:147
Header file for the uIP TCP/IP stack.
A multicast address.
Definition: uip-ds6.h:222
A timer.
Definition: stimer.h:81
void uip_ds6_dad(uip_ds6_addr_t *ifaddr)
Perform Duplicate Address Selection on one address.
Definition: uip-ds6.c:589
uip_ds6_addr_t * uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
Add a unicast address to the interface.
Definition: uip-ds6.c:326
struct uip_ds6_netif uip_ds6_netif_t
Interface structure (contains all the interface variables)
void uip_ds6_init(void)
Initialize data structures.
Definition: uip-ds6.c:93
uip_ds6_netif_t uip_ds6_if
The single interface.
Definition: uip-ds6.c:71
Anycast address.
Definition: uip-ds6.h:216
Generic type for a DS6, to use a common loop though all DS.
Definition: uip-ds6.h:261
uint8_t get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Get the number of matching bits of two addresses.
Definition: uip-ds6.c:562
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
Definition: uip-ds6.c:542
struct uip_ds6_aaddr uip_ds6_aaddr_t
Anycast address.