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