Contiki 3.x
uip-ds6.h
Go to the documentation of this file.
1 /**
2  * \addtogroup uip6
3  * @{
4  */
5 
6 /**
7  * \file
8  * Network interface and stateless autoconfiguration (RFC 4862)
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 /* Prefix list */
71 #define UIP_DS6_PREFIX_NBS 1
72 #ifndef UIP_CONF_DS6_PREFIX_NBU
73 #define UIP_DS6_PREFIX_NBU 2
74 #else
75 #define UIP_DS6_PREFIX_NBU UIP_CONF_DS6_PREFIX_NBU
76 #endif
77 #define UIP_DS6_PREFIX_NB UIP_DS6_PREFIX_NBS + UIP_DS6_PREFIX_NBU
78 
79 /* Unicast address list*/
80 #define UIP_DS6_ADDR_NBS 1
81 #ifndef UIP_CONF_DS6_ADDR_NBU
82 #define UIP_DS6_ADDR_NBU 2
83 #else
84 #define UIP_DS6_ADDR_NBU UIP_CONF_DS6_ADDR_NBU
85 #endif
86 #define UIP_DS6_ADDR_NB UIP_DS6_ADDR_NBS + UIP_DS6_ADDR_NBU
87 
88 /* Multicast address list */
89 #if UIP_CONF_ROUTER
90 #define UIP_DS6_MADDR_NBS 2 + UIP_DS6_ADDR_NB /* all routers + all nodes + one solicited per unicast */
91 #else
92 #define UIP_DS6_MADDR_NBS 1 + UIP_DS6_ADDR_NB /* all nodes + one solicited per unicast */
93 #endif
94 #ifndef UIP_CONF_DS6_MADDR_NBU
95 #define UIP_DS6_MADDR_NBU 0
96 #else
97 #define UIP_DS6_MADDR_NBU UIP_CONF_DS6_MADDR_NBU
98 #endif
99 #define UIP_DS6_MADDR_NB UIP_DS6_MADDR_NBS + UIP_DS6_MADDR_NBU
100 
101 /* Anycast address list */
102 #if UIP_CONF_ROUTER
103 #define UIP_DS6_AADDR_NBS UIP_DS6_PREFIX_NB - 1 /* One per non link local prefix (subnet prefix anycast address) */
104 #else
105 #define UIP_DS6_AADDR_NBS 0
106 #endif
107 #ifndef UIP_CONF_DS6_AADDR_NBU
108 #define UIP_DS6_AADDR_NBU 0
109 #else
110 #define UIP_DS6_AADDR_NBU UIP_CONF_DS6_AADDR_NBU
111 #endif
112 #define UIP_DS6_AADDR_NB UIP_DS6_AADDR_NBS + UIP_DS6_AADDR_NBU
113 
114 /*--------------------------------------------------*/
115 /* Should we use LinkLayer acks in NUD ?*/
116 #ifndef UIP_CONF_DS6_LL_NUD
117 #define UIP_DS6_LL_NUD 0
118 #else
119 #define UIP_DS6_LL_NUD UIP_CONF_DS6_LL_NUD
120 #endif
121 
122 /** \brief Possible states for the an address (RFC 4862) */
123 #define ADDR_TENTATIVE 0
124 #define ADDR_PREFERRED 1
125 #define ADDR_DEPRECATED 2
126 
127 /** \brief How the address was acquired: Autoconf, DHCP or manually */
128 #define ADDR_ANYTYPE 0
129 #define ADDR_AUTOCONF 1
130 #define ADDR_DHCP 2
131 #define ADDR_MANUAL 3
132 
133 /** \brief General DS6 definitions */
134 /** Period for uip-ds6 periodic task*/
135 #ifndef UIP_DS6_CONF_PERIOD
136 #define UIP_DS6_PERIOD (CLOCK_SECOND/10)
137 #else
138 #define UIP_DS6_PERIOD UIP_DS6_CONF_PERIOD
139 #endif
140 
141 #define FOUND 0
142 #define FREESPACE 1
143 #define NOSPACE 2
144 /*--------------------------------------------------*/
145 
146 #if UIP_CONF_IPV6_QUEUE_PKT
147 #include "net/ip/uip-packetqueue.h"
148 #endif /*UIP_CONF_QUEUE_PKT */
149 
150 /** \brief A prefix list entry */
151 #if UIP_CONF_ROUTER
152 typedef struct uip_ds6_prefix {
153  uint8_t isused;
154  uip_ipaddr_t ipaddr;
155  uint8_t length;
156  uint8_t advertise;
157  uint32_t vlifetime;
158  uint32_t plifetime;
159  uint8_t l_a_reserved; /**< on-link and autonomous flags + 6 reserved bits */
161 #else /* UIP_CONF_ROUTER */
162 typedef struct uip_ds6_prefix {
163  uint8_t isused;
164  uip_ipaddr_t ipaddr;
165  uint8_t length;
166  struct stimer vlifetime;
167  uint8_t isinfinite;
169 #endif /*UIP_CONF_ROUTER */
170 
171 /** * \brief Unicast address structure */
172 typedef struct uip_ds6_addr {
173  uint8_t isused;
174  uip_ipaddr_t ipaddr;
175  uint8_t state;
176  uint8_t type;
177  uint8_t isinfinite;
178  struct stimer vlifetime;
179 #if UIP_ND6_DEF_MAXDADNS > 0
180  struct timer dadtimer;
181  uint8_t dadnscount;
182 #endif /* UIP_ND6_DEF_MAXDADNS > 0 */
184 
185 /** \brief Anycast address */
186 typedef struct uip_ds6_aaddr {
187  uint8_t isused;
188  uip_ipaddr_t ipaddr;
190 
191 /** \brief A multicast address */
192 typedef struct uip_ds6_maddr {
193  uint8_t isused;
194  uip_ipaddr_t ipaddr;
196 
197 /* only define the callback if RPL is active */
198 #if UIP_CONF_IPV6_RPL
199 #ifndef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED
200 #define UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED rpl_ipv6_neighbor_callback
201 #endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */
202 #endif /* UIP_CONF_IPV6_RPL */
203 
204 #if UIP_CONF_IPV6_RPL
205 #ifndef UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK
206 #define UIP_CONF_DS6_LINK_NEIGHBOR_CALLBACK rpl_link_neighbor_callback
207 #endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */
208 #endif /* UIP_CONF_IPV6_RPL */
209 
210 
211 /** \brief Interface structure (contains all the interface variables) */
212 typedef struct uip_ds6_netif {
213  uint32_t link_mtu;
214  uint8_t cur_hop_limit;
215  uint32_t base_reachable_time; /* in msec */
216  uint32_t reachable_time; /* in msec */
217  uint32_t retrans_timer; /* in msec */
218  uint8_t maxdadns;
219  uip_ds6_addr_t addr_list[UIP_DS6_ADDR_NB];
220  uip_ds6_aaddr_t aaddr_list[UIP_DS6_AADDR_NB];
221  uip_ds6_maddr_t maddr_list[UIP_DS6_MADDR_NB];
223 
224 /** \brief Generic type for a DS6, to use a common loop though all DS */
225 typedef struct uip_ds6_element {
226  uint8_t isused;
227  uip_ipaddr_t ipaddr;
229 
230 
231 /*---------------------------------------------------------------------------*/
232 extern uip_ds6_netif_t uip_ds6_if;
233 extern struct etimer uip_ds6_timer_periodic;
234 
235 #if UIP_CONF_ROUTER
236 extern uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB];
237 #else /* UIP_CONF_ROUTER */
238 extern struct etimer uip_ds6_timer_rs;
239 #endif /* UIP_CONF_ROUTER */
240 
241 
242 /*---------------------------------------------------------------------------*/
243 /** \brief Initialize data structures */
244 void uip_ds6_init(void);
245 
246 /** \brief Periodic processing of data structures */
247 void uip_ds6_periodic(void);
248 
249 /** \brief Generic loop routine on an abstract data structure, which generalizes
250  * all data structures used in DS6 */
251 uint8_t uip_ds6_list_loop(uip_ds6_element_t *list, uint8_t size,
252  uint16_t elementsize, uip_ipaddr_t *ipaddr,
253  uint8_t ipaddrlen,
254  uip_ds6_element_t **out_element);
255 
256 /** @} */
257 
258 
259 /** \name Prefix list basic routines */
260 /** @{ */
261 #if UIP_CONF_ROUTER
262 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
263  uint8_t advertise, uint8_t flags,
264  unsigned long vtime,
265  unsigned long ptime);
266 #else /* UIP_CONF_ROUTER */
267 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
268  unsigned long interval);
269 #endif /* UIP_CONF_ROUTER */
270 void uip_ds6_prefix_rm(uip_ds6_prefix_t *prefix);
271 uip_ds6_prefix_t *uip_ds6_prefix_lookup(uip_ipaddr_t *ipaddr,
272  uint8_t ipaddrlen);
273 uint8_t uip_ds6_is_addr_onlink(uip_ipaddr_t *ipaddr);
274 
275 /** @} */
276 
277 /** \name Unicast address list basic routines */
278 /** @{ */
279 uip_ds6_addr_t *uip_ds6_addr_add(uip_ipaddr_t *ipaddr,
280  unsigned long vlifetime, uint8_t type);
281 void uip_ds6_addr_rm(uip_ds6_addr_t *addr);
282 uip_ds6_addr_t *uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr);
283 uip_ds6_addr_t *uip_ds6_get_link_local(int8_t state);
284 uip_ds6_addr_t *uip_ds6_get_global(int8_t state);
285 
286 /** @} */
287 
288 /** \name Multicast address list basic routines */
289 /** @{ */
290 uip_ds6_maddr_t *uip_ds6_maddr_add(const uip_ipaddr_t *ipaddr);
291 void uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr);
292 uip_ds6_maddr_t *uip_ds6_maddr_lookup(const uip_ipaddr_t *ipaddr);
293 
294 /** @} */
295 
296 /** \name Anycast address list basic routines */
297 /** @{ */
298 uip_ds6_aaddr_t *uip_ds6_aaddr_add(uip_ipaddr_t *ipaddr);
299 void uip_ds6_aaddr_rm(uip_ds6_aaddr_t *aaddr);
300 uip_ds6_aaddr_t *uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr);
301 
302 /** @} */
303 
304 
305 /** \brief set the last 64 bits of an IP address based on the MAC address */
306 void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr);
307 
308 /** \brief Get the number of matching bits of two addresses */
309 uint8_t get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst);
310 
311 #if UIP_ND6_DEF_MAXDADNS >0
312 /** \brief Perform Duplicate Address Selection on one address */
313 void uip_ds6_dad(uip_ds6_addr_t *ifaddr);
314 
315 /** \brief Callback when DAD failed */
316 int uip_ds6_dad_failed(uip_ds6_addr_t *ifaddr);
317 #endif /* UIP_ND6_DEF_MAXDADNS */
318 
319 /** \brief Source address selection, see RFC 3484 */
320 void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst);
321 
322 #if UIP_CONF_ROUTER
323 #if UIP_ND6_SEND_RA
324 /** \brief Send a RA as an asnwer to a RS */
325 void uip_ds6_send_ra_sollicited(void);
326 
327 /** \brief Send a periodic RA */
328 void uip_ds6_send_ra_periodic(void);
329 #endif /* UIP_ND6_SEND_RA */
330 #else /* UIP_CONF_ROUTER */
331 /** \brief Send periodic RS to find router */
332 void uip_ds6_send_rs(void);
333 #endif /* UIP_CONF_ROUTER */
334 
335 /** \brief Compute the reachable time based on base reachable time, see RFC 4861*/
336 uint32_t uip_ds6_compute_reachable_time(void); /** \brief compute random reachable timer */
337 
338 /** \name Macros to check if an IP address (unicast, multicast or anycast) is mine */
339 /** @{ */
340 #define uip_ds6_is_my_addr(addr) (uip_ds6_addr_lookup(addr) != NULL)
341 #define uip_ds6_is_my_maddr(addr) (uip_ds6_maddr_lookup(addr) != NULL)
342 #define uip_ds6_is_my_aaddr(addr) (uip_ds6_aaddr_lookup(addr) != NULL)
343 /** @} */
344 /** @} */
345 
346 #endif /* UIP_DS6_H_ */
struct uip_ds6_addr uip_ds6_addr_t
Unicast address structure.
Second timer library header file.
struct uip_ds6_element uip_ds6_element_t
Generic type for a DS6, to use a common loop though all DS.
Neighbor discovery (RFC 4861)
A timer.
Definition: timer.h:86
struct uip_ds6_netif uip_ds6_netif_t
Interface structure (contains all the interface variables)
struct uip_ds6_prefix uip_ds6_prefix_t
A prefix list entry.
Unicast address structure.
Definition: uip-ds6.h:172
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:203
struct uip_ds6_aaddr uip_ds6_aaddr_t
Anycast address.
Header file for the uIP TCP/IP stack.
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:535
struct etimer uip_ds6_timer_rs
Timer for maintenance of data structures.
Definition: uip-ds6.c:67
void uip_ds6_periodic(void)
Periodic processing of data structures.
Definition: uip-ds6.c:147
A multicast address.
Definition: uip-ds6.h:192
A prefix list entry.
Definition: uip-ds6.h:162
uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB]
The single interface.
Definition: uip-ds6.c:74
Generic type for a DS6, to use a common loop though all DS.
Definition: uip-ds6.h:225
struct uip_ds6_maddr uip_ds6_maddr_t
A multicast address.
802.3 address
Definition: uip.h:135
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
Definition: uip-ds6.c:497
A timer.
Definition: stimer.h:81
void uip_ds6_send_rs(void)
Send periodic RS to find router.
Definition: uip-ds6.c:677
Interface structure (contains all the interface variables)
Definition: uip-ds6.h:212
IPv6 Neighbor cache (link-layer/IPv6 address mapping)
void uip_ds6_init(void)
Initialize data structures.
Definition: uip-ds6.c:93
uint32_t uip_ds6_compute_reachable_time(void)
Compute the reachable time based on base reachable time, see RFC 4861.
Definition: uip-ds6.c:697
A timer.
Definition: etimer.h:76
Anycast address.
Definition: uip-ds6.h:186
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:555