Contiki-NG
uip-ds6.h
Go to the documentation of this file.
1 /**
2  * \addtogroup uip
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/ipv6/uip.h"
47 #include "sys/stimer.h"
48 /* The size of uip_ds6_addr_t depends on UIP_ND6_DEF_MAXDADNS. Include uip-nd6.h to define it. */
49 #include "net/ipv6/uip-nd6.h"
50 #include "net/ipv6/uip-ds6-nbr.h"
51 #include "net/ipv6/uip-ds6-route.h"
52 
53 /*--------------------------------------------------*/
54 /** Configuration. For all tables (Neighbor cache, Prefix List, Routing Table,
55  * Default Router List, Unicast address list, multicast address list, anycast address list),
56  * we define:
57  * - the number of elements requested by the user in contiki configuration (name suffixed by _NBU)
58  * - the number of elements assigned by the system (name suffixed by _NBS)
59  * - the total number of elements is the sum (name suffixed by _NB)
60  * The routing table definitions can be found in uip-ds6-route.h
61  * The Neighbor cache definitions can be found in nbr-table.h
62 */
63 
64 /* Default router list */
65 #define UIP_DS6_DEFRT_NBS 0
66 #ifndef UIP_CONF_DS6_DEFRT_NBU
67 #define UIP_DS6_DEFRT_NBU 2
68 #else
69 #define UIP_DS6_DEFRT_NBU UIP_CONF_DS6_DEFRT_NBU
70 #endif
71 #define UIP_DS6_DEFRT_NB UIP_DS6_DEFRT_NBS + UIP_DS6_DEFRT_NBU
72 
73 /* Default prefix */
74 #ifdef UIP_CONF_DS6_DEFAULT_PREFIX
75 #define UIP_DS6_DEFAULT_PREFIX UIP_CONF_DS6_DEFAULT_PREFIX
76 #else
77 /* From RFC4193, section 3.1:
78  * | 7 bits |1| 40 bits | 16 bits | 64 bits |
79  * +--------+-+------------+-----------+----------------------------+
80  * | Prefix |L| Global ID | Subnet ID | Interface ID |
81  * +--------+-+------------+-----------+----------------------------+
82  * Prefix FC00::/7 prefix to identify Local IPv6 unicast
83  * addresses.
84  * L Set to 1 if the prefix is locally assigned.
85  * Set to 0 may be defined in the future. See
86  * Section 3.2 for additional information.
87  * Global ID 40-bit global identifier used to create a
88  * globally unique prefix. See Section 3.2 for
89  * additional information.
90  *
91  * We set prefix to 0xfc00 and set the local bit, resulting in 0xfd00.
92  * For high probability of network uniqueness, Global ID must be generated
93  * pseudo-randomly. As this is a hard-coded default prefix, we simply use
94  * a Global ID of 0. For real deployments, make sure to install a pseudo-random
95  * Global ID, e.g. in a RPL network, by configuring it at the root.
96  */
97 #define UIP_DS6_DEFAULT_PREFIX 0xfd00
98 #endif /* UIP_CONF_DS6_DEFAULT_PREFIX */
99 
100 #define UIP_DS6_DEFAULT_PREFIX_0 ((UIP_DS6_DEFAULT_PREFIX >> 8) & 0xff)
101 #define UIP_DS6_DEFAULT_PREFIX_1 (UIP_DS6_DEFAULT_PREFIX & 0xff)
102 
103 /* Prefix list */
104 #define UIP_DS6_PREFIX_NBS 1
105 #ifndef UIP_CONF_DS6_PREFIX_NBU
106 #define UIP_DS6_PREFIX_NBU 2
107 #else
108 #define UIP_DS6_PREFIX_NBU UIP_CONF_DS6_PREFIX_NBU
109 #endif
110 #define UIP_DS6_PREFIX_NB UIP_DS6_PREFIX_NBS + UIP_DS6_PREFIX_NBU
111 
112 /* Unicast address list*/
113 #define UIP_DS6_ADDR_NBS 1
114 #ifndef UIP_CONF_DS6_ADDR_NBU
115 #define UIP_DS6_ADDR_NBU 2
116 #else
117 #define UIP_DS6_ADDR_NBU UIP_CONF_DS6_ADDR_NBU
118 #endif
119 #define UIP_DS6_ADDR_NB UIP_DS6_ADDR_NBS + UIP_DS6_ADDR_NBU
120 
121 /* Multicast address list */
122 #if UIP_CONF_ROUTER
123 #define UIP_DS6_MADDR_NBS 2 + UIP_DS6_ADDR_NB /* all routers + all nodes + one solicited per unicast */
124 #else
125 #define UIP_DS6_MADDR_NBS 1 + UIP_DS6_ADDR_NB /* all nodes + one solicited per unicast */
126 #endif
127 #ifndef UIP_CONF_DS6_MADDR_NBU
128 #define UIP_DS6_MADDR_NBU 0
129 #else
130 #define UIP_DS6_MADDR_NBU UIP_CONF_DS6_MADDR_NBU
131 #endif
132 #define UIP_DS6_MADDR_NB UIP_DS6_MADDR_NBS + UIP_DS6_MADDR_NBU
133 
134 /* Anycast address list */
135 #if UIP_CONF_ROUTER
136 #define UIP_DS6_AADDR_NBS UIP_DS6_PREFIX_NB - 1 /* One per non link local prefix (subnet prefix anycast address) */
137 #else
138 #define UIP_DS6_AADDR_NBS 0
139 #endif
140 #ifndef UIP_CONF_DS6_AADDR_NBU
141 #define UIP_DS6_AADDR_NBU 0
142 #else
143 #define UIP_DS6_AADDR_NBU UIP_CONF_DS6_AADDR_NBU
144 #endif
145 #define UIP_DS6_AADDR_NB UIP_DS6_AADDR_NBS + UIP_DS6_AADDR_NBU
146 
147 /*--------------------------------------------------*/
148 /* Should we use LinkLayer acks in NUD ?*/
149 #ifndef UIP_CONF_DS6_LL_NUD
150 #define UIP_DS6_LL_NUD 0
151 #else
152 #define UIP_DS6_LL_NUD UIP_CONF_DS6_LL_NUD
153 #endif
154 
155 /** \brief Possible states for the an address (RFC 4862) */
156 #define ADDR_TENTATIVE 0
157 #define ADDR_PREFERRED 1
158 #define ADDR_DEPRECATED 2
159 
160 /** \brief How the address was acquired: Autoconf, DHCP or manually */
161 #define ADDR_ANYTYPE 0
162 #define ADDR_AUTOCONF 1
163 #define ADDR_DHCP 2
164 #define ADDR_MANUAL 3
165 
166 /** \brief General DS6 definitions */
167 /** Period for uip-ds6 periodic task*/
168 #ifndef UIP_DS6_CONF_PERIOD
169 #define UIP_DS6_PERIOD (60 * CLOCK_SECOND)
170 #else
171 #define UIP_DS6_PERIOD UIP_DS6_CONF_PERIOD
172 #endif
173 
174 #define FOUND 0
175 #define FREESPACE 1
176 #define NOSPACE 2
177 /*--------------------------------------------------*/
178 
179 #if UIP_CONF_IPV6_QUEUE_PKT
180 #include "net/ipv6/uip-packetqueue.h"
181 #endif /*UIP_CONF_QUEUE_PKT */
182 
183 /** \brief A prefix list entry */
184 #if UIP_CONF_ROUTER
185 typedef struct uip_ds6_prefix {
186  uint8_t isused;
187  uip_ipaddr_t ipaddr;
188  uint8_t length;
189  uint8_t advertise;
190  uint32_t vlifetime;
191  uint32_t plifetime;
192  uint8_t l_a_reserved; /**< on-link and autonomous flags + 6 reserved bits */
194 #else /* UIP_CONF_ROUTER */
195 typedef struct uip_ds6_prefix {
196  uint8_t isused;
197  uip_ipaddr_t ipaddr;
198  uint8_t length;
199  struct stimer vlifetime;
200  uint8_t isinfinite;
202 #endif /*UIP_CONF_ROUTER */
203 
204 /** * \brief Unicast address structure */
205 typedef struct uip_ds6_addr {
206  uint8_t isused;
207  uip_ipaddr_t ipaddr;
208  uint8_t state;
209  uint8_t type;
210  uint8_t isinfinite;
211  struct stimer vlifetime;
212 #if UIP_ND6_DEF_MAXDADNS > 0
213  struct timer dadtimer;
214  uint8_t dadnscount;
215 #endif /* UIP_ND6_DEF_MAXDADNS > 0 */
217 
218 /** \brief Anycast address */
219 typedef struct uip_ds6_aaddr {
220  uint8_t isused;
221  uip_ipaddr_t ipaddr;
223 
224 /** \brief A multicast address */
225 typedef struct uip_ds6_maddr {
226  uint8_t isused;
227  uip_ipaddr_t ipaddr;
229 
230 /** \brief Interface structure (contains all the interface variables) */
231 typedef struct uip_ds6_netif {
232  uint32_t link_mtu;
233  uint8_t cur_hop_limit;
234  uint32_t base_reachable_time; /* in msec */
235  uint32_t reachable_time; /* in msec */
236  uint32_t retrans_timer; /* in msec */
237  uint8_t maxdadns;
238 #if UIP_DS6_ADDR_NB
239  uip_ds6_addr_t addr_list[UIP_DS6_ADDR_NB];
240 #endif /* UIP_DS6_ADDR_NB */
241 #if UIP_DS6_AADDR_NB
242  uip_ds6_aaddr_t aaddr_list[UIP_DS6_AADDR_NB];
243 #endif /* UIP_DS6_AADDR_NB */
244 #if UIP_DS6_MADDR_NB
245  uip_ds6_maddr_t maddr_list[UIP_DS6_MADDR_NB];
246 #endif /* UIP_DS6_MADDR_NB */
248 
249 /** \brief Generic type for a DS6, to use a common loop though all DS */
250 typedef struct uip_ds6_element {
251  uint8_t isused;
252  uip_ipaddr_t ipaddr;
254 
255 
256 /*---------------------------------------------------------------------------*/
258 extern struct etimer uip_ds6_timer_periodic;
259 
260 #if UIP_CONF_ROUTER
261 extern uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB];
262 #else /* UIP_CONF_ROUTER */
263 extern struct etimer uip_ds6_timer_rs;
264 #endif /* UIP_CONF_ROUTER */
265 
266 
267 /*---------------------------------------------------------------------------*/
268 /** \brief Initialize data structures */
269 void uip_ds6_init(void);
270 
271 /** \brief Periodic processing of data structures */
272 void uip_ds6_periodic(void);
273 
274 /** \brief Generic loop routine on an abstract data structure, which generalizes
275  * all data structures used in DS6 */
276 uint8_t uip_ds6_list_loop(uip_ds6_element_t *list, uint8_t size,
277  uint16_t elementsize, uip_ipaddr_t *ipaddr,
278  uint8_t ipaddrlen,
279  uip_ds6_element_t **out_element);
280 
281 /** @} */
282 
283 
284 /** \name Prefix list basic routines */
285 /** @{ */
286 #if UIP_CONF_ROUTER
287 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
288  uint8_t advertise, uint8_t flags,
289  unsigned long vtime,
290  unsigned long ptime);
291 #else /* UIP_CONF_ROUTER */
292 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
293  unsigned long interval);
294 #endif /* UIP_CONF_ROUTER */
295 void uip_ds6_prefix_rm(uip_ds6_prefix_t *prefix);
296 uip_ds6_prefix_t *uip_ds6_prefix_lookup(uip_ipaddr_t *ipaddr,
297  uint8_t ipaddrlen);
298 uint8_t uip_ds6_is_addr_onlink(uip_ipaddr_t *ipaddr);
299 
300 /**
301  * \brief Retrieve the Default IPv6 prefix
302  * \retval A pointer to the default prefix
303  */
304 const uip_ip6addr_t *uip_ds6_default_prefix(void);
305 
306 /**
307  * \brief Set the Default IPv6 prefix
308  * \param prefix A pointer to the new default prefix
309  *
310  * uip_ds6_init() will set the default prefix to UIP_DS6_DEFAULT_PREFIX
311  * unless this function here has been called beforehand to set a new default
312  * prefix.
313  */
314 void uip_ds6_set_default_prefix(const uip_ip6addr_t *prefix);
315 
316 /** @} */
317 
318 /** \name Unicast address list basic routines */
319 /** @{ */
320 /** \brief Add a unicast address to the interface */
321 uip_ds6_addr_t *uip_ds6_addr_add(uip_ipaddr_t *ipaddr,
322  unsigned long vlifetime, uint8_t type);
323 void uip_ds6_addr_rm(uip_ds6_addr_t *addr);
324 uip_ds6_addr_t *uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr);
325 uip_ds6_addr_t *uip_ds6_get_link_local(int8_t state);
326 uip_ds6_addr_t *uip_ds6_get_global(int8_t state);
327 
328 /** @} */
329 
330 /** \name Multicast address list basic routines */
331 /** @{ */
332 uip_ds6_maddr_t *uip_ds6_maddr_add(const uip_ipaddr_t *ipaddr);
333 void uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr);
334 uip_ds6_maddr_t *uip_ds6_maddr_lookup(const uip_ipaddr_t *ipaddr);
335 
336 /** @} */
337 
338 /** \name Anycast address list basic routines */
339 /** @{ */
340 uip_ds6_aaddr_t *uip_ds6_aaddr_add(uip_ipaddr_t *ipaddr);
341 void uip_ds6_aaddr_rm(uip_ds6_aaddr_t *aaddr);
342 uip_ds6_aaddr_t *uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr);
343 
344 /** @} */
345 
346 
347 /** \brief set the last 64 bits of an IP address based on the MAC address */
348 void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr);
349 
350 /** \brief Build a link-layer address from an IPv6 address based on its UUID64 */
351 void uip_ds6_set_lladdr_from_iid(uip_lladdr_t *lladdr, const uip_ipaddr_t *ipaddr);
352 
353 /** \brief Get the number of matching bits of two addresses */
354 uint8_t get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst);
355 
356 #if UIP_ND6_DEF_MAXDADNS >0
357 /** \brief Perform Duplicate Address Selection on one address */
358 void uip_ds6_dad(uip_ds6_addr_t *ifaddr);
359 
360 /** \brief Callback when DAD failed */
362 #endif /* UIP_ND6_DEF_MAXDADNS */
363 
364 /** \brief Source address selection, see RFC 3484 */
365 void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst);
366 
367 #if UIP_CONF_ROUTER
368 #if UIP_ND6_SEND_RA
369 /** \brief Send a RA as an asnwer to a RS */
370 void uip_ds6_send_ra_sollicited(void);
371 
372 /** \brief Send a periodic RA */
373 void uip_ds6_send_ra_periodic(void);
374 #endif /* UIP_ND6_SEND_RA */
375 #else /* UIP_CONF_ROUTER */
376 /** \brief Send periodic RS to find router */
377 void uip_ds6_send_rs(void);
378 #endif /* UIP_CONF_ROUTER */
379 
380 /** \brief Compute the reachable time based on base reachable time, see RFC 4861*/
381 uint32_t uip_ds6_compute_reachable_time(void); /** \brief compute random reachable timer */
382 
383 /** \name Macros to check if an IP address (unicast, multicast or anycast) is mine */
384 /** @{ */
385 #define uip_ds6_is_my_addr(addr) (uip_ds6_addr_lookup(addr) != NULL)
386 #define uip_ds6_is_my_maddr(addr) (uip_ds6_maddr_lookup(addr) != NULL)
387 #define uip_ds6_is_my_aaddr(addr) (uip_ds6_aaddr_lookup(addr) != NULL)
388 /** @} */
389 /** @} */
390 
391 #endif /* UIP_DS6_H_ */
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition: uip-nd6.c:116
struct uip_ds6_addr uip_ds6_addr_t
Unicast address structure.
void uip_ds6_send_rs(void)
Send periodic RS to find router.
Definition: uip-ds6.c:733
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107
void uip_ds6_init(void)
Initialize data structures.
Definition: uip-ds6.c:116
Generic type for a DS6, to use a common loop though all DS.
Definition: uip-ds6.h:250
IPv6 Neighbor cache (link-layer/IPv6 address mapping)
void uip_ds6_set_lladdr_from_iid(uip_lladdr_t *lladdr, const uip_ipaddr_t *ipaddr)
Build a link-layer address from an IPv6 address based on its UUID64.
Definition: uip-ds6.c:597
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:611
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:576
struct uip_ds6_netif uip_ds6_netif_t
Interface structure (contains all the interface variables)
A timer.
Definition: timer.h:82
void uip_ds6_dad(uip_ds6_addr_t *ifaddr)
Perform Duplicate Address Selection on one address.
Definition: uip-ds6.c:638
uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB]
Prefix list.
Definition: uip-ds6.c:76
int uip_ds6_dad_failed(uip_ds6_addr_t *ifaddr)
Callback when DAD failed.
Definition: uip-ds6.c:666
struct uip_ds6_element uip_ds6_element_t
Generic type for a DS6, to use a common loop though all DS.
struct uip_ds6_aaddr uip_ds6_aaddr_t
Anycast address.
This header file contains configuration directives for uIPv6 multicast support.
void uip_ds6_set_default_prefix(const uip_ip6addr_t *prefix)
Set the Default IPv6 prefix.
Definition: uip-ds6.c:110
const uip_ip6addr_t * uip_ds6_default_prefix(void)
Retrieve the Default IPv6 prefix.
Definition: uip-ds6.c:104
A timer.
Definition: stimer.h:81
Second timer library header file.
struct uip_ds6_maddr uip_ds6_maddr_t
A multicast address.
Unicast address structure.
Definition: uip-ds6.h:205
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:360
A timer.
Definition: etimer.h:76
void uip_ds6_periodic(void)
Periodic processing of data structures.
Definition: uip-ds6.c:177
Header file for the uIP TCP/IP stack.
Header file for IPv6 Neighbor discovery (RFC 4861)
uip_ds6_netif_t uip_ds6_if
The single interface.
Definition: uip-ds6.c:75
A prefix list entry.
Definition: uip-ds6.h:195
Header file for routing table manipulation.
Interface structure (contains all the interface variables)
Definition: uip-ds6.h:231
Anycast address.
Definition: uip-ds6.h:219
A multicast address.
Definition: uip-ds6.h:225
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:235
struct uip_ds6_prefix uip_ds6_prefix_t
A prefix list entry.
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
Definition: uip-ds6.c:538
uint32_t uip_ds6_compute_reachable_time(void)
Compute the reachable time based on base reachable time, see RFC 4861.
Definition: uip-ds6.c:753