Contiki-NG
Loading...
Searching...
No Matches
uip-ds6-nbr.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *
30 */
31
32/**
33 * \addtogroup uip
34 * @{
35 */
36
37/**
38 * \file
39 * IPv6 Neighbor cache (link-layer/IPv6 address mapping)
40 * \author Mathilde Durvy <mdurvy@cisco.com>
41 * \author Julien Abeille <jabeille@cisco.com>
42 * \author Simon Duquennoy <simonduq@sics.se>
43 *
44 */
45
46#ifndef UIP_DS6_NEIGHBOR_H_
47#define UIP_DS6_NEIGHBOR_H_
48
49#include "contiki.h"
50#include "net/ipv6/uip.h"
51#include "net/ipv6/uip-nd6.h"
52#include "net/nbr-table.h"
53#include "sys/stimer.h"
54#if UIP_CONF_IPV6_QUEUE_PKT
55#include "net/ipv6/uip-packetqueue.h"
56#endif /*UIP_CONF_QUEUE_PKT */
57#if UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS
58#include "lib/assert.h"
59#include "lib/list.h"
60#endif
61
62/*--------------------------------------------------*/
63/** \brief Possible states for the nbr cache entries */
64#define NBR_INCOMPLETE 0
65#define NBR_REACHABLE 1
66#define NBR_STALE 2
67#define NBR_DELAY 3
68#define NBR_PROBE 4
69
70/** \brief Set non-zero (1) to enable multiple IPv6 addresses to be
71 * associated with a link-layer address */
72#ifdef UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS
73#define UIP_DS6_NBR_MULTI_IPV6_ADDRS UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS
74#else
75#define UIP_DS6_NBR_MULTI_IPV6_ADDRS 0
76#endif /* UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS */
77
78/** \brief Set the maximum number of IPv6 addresses per link-layer
79 * address */
80#ifdef UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR
81#define UIP_DS6_NBR_MAX_6ADDRS_PER_NBR UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR
82#else
83#define UIP_DS6_NBR_MAX_6ADDRS_PER_NBR 2
84#endif /* UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR */
85
86/** \brief Set the maximum number of neighbor cache entries */
87#ifdef UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES
88#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES
89#else
90#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES \
91 (NBR_TABLE_MAX_NEIGHBORS * UIP_DS6_NBR_MAX_6ADDRS_PER_NBR)
92#endif /* UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES */
93
94#if UIP_DS6_NBR_MULTI_IPV6_ADDRS
95/** \brief nbr_table entry when UIP_DS6_NBR_MULTI_IPV6_ADDRS is
96 * enabled. uip_ds6_nbrs is a list of uip_ds6_nbr_t objects */
97typedef struct {
98 LIST_STRUCT(uip_ds6_nbrs);
99} uip_ds6_nbr_entry_t;
100#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */
101
102/** \brief The default nbr_table entry (when
103 * UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr
104 * cache */
105typedef struct uip_ds6_nbr {
106#if UIP_DS6_NBR_MULTI_IPV6_ADDRS
107 struct uip_ds6_nbr *next;
108 uip_ds6_nbr_entry_t *nbr_entry;
109#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */
110 uip_ipaddr_t ipaddr;
111 uint8_t isrouter;
112 uint8_t state;
113#if UIP_ND6_SEND_NS || UIP_ND6_SEND_RA
114 struct stimer reachable;
115 struct stimer sendns;
116 uint8_t nscount;
117#endif /* UIP_ND6_SEND_NS || UIP_ND6_SEND_RA */
118#if UIP_CONF_IPV6_QUEUE_PKT
119 struct uip_packetqueue_handle packethandle;
120#define UIP_DS6_NBR_PACKET_LIFETIME CLOCK_SECOND * 4
121#endif /*UIP_CONF_QUEUE_PKT */
123
124void uip_ds6_neighbors_init(void);
125
126/**
127 * Add a neighbor cache for a specified IPv6 address, which is
128 * associated with a specified link-layer address
129 * \param ipaddr IPv6 address of a neighbor to add
130 * \param lladdr Link-layer address to associate with ipaddr
131 * \param isrouter Set 1 if the neighbor is a router
132 * \param state Set the initial neighbor cache state (e.g.,
133 * NBR_INCOMPLETE)
134 * \param reason Set a reason of the addition (e.g.,
135 * NBR_TABLE_REASON_RPL_DIO)
136 * \param data Set data associated with the nbr cache
137 * \return the address of a newly added nbr cache on success, NULL on
138 * failure
139 */
140uip_ds6_nbr_t *uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr,
141 const uip_lladdr_t *lladdr,
142 uint8_t isrouter, uint8_t state,
143 nbr_table_reason_t reason, void *data);
144
145/**
146 * Remove a neighbor cache
147 * \param nbr the address of a neighbor cache to remove
148 * \return 1 on success, 0 on failure (nothing was removed)
149 */
151
152/**
153 * Get the link-layer address associated with a specified nbr cache
154 * \param nbr the address of a neighbor cache
155 * \return pointer to the link-layer address on success, NULL on failure
156 */
157const uip_lladdr_t *uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr);
158
159/**
160 * Get the link-layer address associated with a specified IPv6 address
161 * \param ipaddr an IPv6 address used as a search key
162 * \return the pointer to the link-layer address on success, NULL on failure
163 */
164const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr);
165
166/**
167 * Update the link-layer address associated with an IPv6 address
168 * \param nbr the double pointer to a neighbor cache which has the
169 * target IPv6 address
170 * \param new_ll_addr the new link-layer address of the IPv6 address
171 * return 0 on success, -1 on failure
172 */
173int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr, const uip_lladdr_t *new_ll_addr);
174
175/**
176 * Get an IPv6 address of a neighbor cache
177 * \param nbr the pointer to a neighbor cache
178 * \return the pointer to an IPv6 address associated with the neighbor cache
179 * \note This returns the first IPv6 address found in the neighbor
180 * cache when UIP_DS6_NBR_MULTI_IPV6_ADDRS is enabled
181 */
182const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr);
183
184/**
185 * Get an IPv6 address associated with a specified link-layer address
186 * \param lladdr a link-layer address used as a search key
187 * \return the pointer to an IPv6 address associated with the neighbor cache
188 * \note This returns the first IPv6 address found in the neighbor
189 * cache when UIP_DS6_NBR_MULTI_IPV6_ADDRS is enabled
190 */
191uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr);
192
193/**
194 * Get the neighbor cache associated with a specified IPv6 address
195 * \param ipaddr an IPv6 address used as a search key
196 * \return the pointer to a neighbor cache on success, NULL on failure
197 */
198uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr);
199
200/**
201 * Get the neighbor cache associated with a specified link-layer address
202 * \param lladdr a link-layer address used as a search key
203 * \return the pointer to a neighbor cache on success, NULL on failure
204 */
205uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr);
206
207/**
208 * Return the number of neighbor caches
209 * \return the number of neighbor caches in use
210 */
211int uip_ds6_nbr_num(void);
212
213/**
214 * Get the first neighbor cache in nbr_table
215 * \return the pointer to the first neighbor cache entry
216 */
218
219/**
220 * Get the next neighbor cache of a specified one
221 * \param nbr the pointer to a neighbor cache
222 * \return the pointer to the next one on success, NULL on failure
223 */
225
226/**
227 * The callback function to update link-layer stats in a neighbor
228 * cache
229 * \param status MAC return value defined in mac.h
230 * \param numtx the number of transmissions happened for a packet
231 */
232void uip_ds6_link_callback(int status, int numtx);
233
234/**
235 * The housekeeping function called periodically
236 */
238
239#if UIP_ND6_SEND_NS
240/**
241 * \brief Refresh the reachable state of a neighbor. This function
242 * may be called when a node receives an IPv6 message that confirms the
243 * reachability of a neighbor.
244 * \param ipaddr pointer to the IPv6 address whose neighbor reachability state
245 * should be refreshed.
246 */
247void uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr);
248#endif /* UIP_ND6_SEND_NS */
249
250#endif /* UIP_DS6_NEIGHBOR_H_ */
251/** @} */
#define LIST_STRUCT(name)
Declare a linked list inside a structure declaraction.
Definition list.h:112
const uip_lladdr_t * uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr)
Get the link-layer address associated with a specified nbr cache.
uip_ds6_nbr_t * uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, uint8_t isrouter, uint8_t state, nbr_table_reason_t reason, void *data)
Add a neighbor cache for a specified IPv6 address, which is associated with a specified link-layer ad...
uip_ds6_nbr_t * uip_ds6_nbr_head(void)
Get the first neighbor cache in nbr_table.
uip_ds6_nbr_t * uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr)
Get the neighbor cache associated with a specified link-layer address.
int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr_pp, const uip_lladdr_t *new_ll_addr)
Update the link-layer address associated with an IPv6 address.
int uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr)
Remove a neighbor cache.
uip_ds6_nbr_t * uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr)
Get the neighbor cache associated with a specified IPv6 address.
void uip_ds6_neighbor_periodic(void)
The housekeeping function called periodically.
const uip_ipaddr_t * uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr)
Get an IPv6 address of a neighbor cache.
int uip_ds6_nbr_num(void)
Return the number of neighbor caches.
void uip_ds6_link_callback(int status, int numtx)
The callback function to update link-layer stats in a neighbor cache.
struct uip_ds6_nbr uip_ds6_nbr_t
The default nbr_table entry (when UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr cach...
const uip_lladdr_t * uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr)
Get the link-layer address associated with a specified IPv6 address.
uip_ds6_nbr_t * uip_ds6_nbr_next(uip_ds6_nbr_t *nbr)
Get the next neighbor cache of a specified one.
uip_ipaddr_t * uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr)
Get an IPv6 address associated with a specified link-layer address.
Linked list manipulation routines.
Second timer library header file.
A timer.
Definition stimer.h:83
The default nbr_table entry (when UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr cach...
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
Definition uip-nd6.c:106
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition uip-nd6.c:116
Header file for IPv6 Neighbor discovery (RFC 4861)
Header file for the uIP TCP/IP stack.