uip-ds6.h

Go to the documentation of this file.
00001 /**
00002  * \addtogroup uip6
00003  * @{
00004  */
00005 
00006 /**
00007  * \file
00008  *         Network interface and stateless autoconfiguration (RFC 4862)
00009  * \author Mathilde Durvy <mdurvy@cisco.com>
00010  * \author Julien Abeille <jabeille@cisco.com>
00011  *
00012  */
00013 /*
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions
00017  * are met:
00018  * 1. Redistributions of source code must retain the above copyright
00019  *    notice, this list of conditions and the following disclaimer.
00020  * 2. Redistributions in binary form must reproduce the above copyright
00021  *    notice, this list of conditions and the following disclaimer in the
00022  *    documentation and/or other materials provided with the distribution.
00023  * 3. Neither the name of the Institute nor the names of its contributors
00024  *    may be used to endorse or promote products derived from this software
00025  *    without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00028  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00031  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00033  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00034  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00035  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00036  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00037  * SUCH DAMAGE.
00038  *
00039  *
00040  */
00041 
00042 #ifndef __UIP_DS6_H__
00043 #define __UIP_DS6_H__
00044 
00045 #include "net/uip.h"
00046 #include "sys/stimer.h"
00047 
00048 /*--------------------------------------------------*/
00049 /** Configuration. For all tables (Neighbor cache, Prefix List, Routing Table,
00050  * Default Router List, Unicast address list, multicast address list, anycast address list),
00051  * we define:
00052  * - the number of elements requested by the user in contiki configuration (name suffixed by _NBU)
00053  * - the number of elements assigned by the system (name suffixed by _NBS)
00054  * - the total number of elements is the sum (name suffixed by _NB)
00055 */
00056 /* Neighbor cache */
00057 #define UIP_DS6_NBR_NBS 0
00058 #ifndef UIP_CONF_DS6_NBR_NBU
00059 #define UIP_DS6_NBR_NBU  4
00060 #else
00061 #define UIP_DS6_NBR_NBU UIP_CONF_DS6_NBR_NBU
00062 #endif
00063 #define UIP_DS6_NBR_NB UIP_DS6_NBR_NBS + UIP_DS6_NBR_NBU
00064 
00065 /* Default router list */
00066 #define UIP_DS6_DEFRT_NBS 0
00067 #ifndef UIP_CONF_DS6_DEFRT_NBU
00068 #define UIP_DS6_DEFRT_NBU 2
00069 #else
00070 #define UIP_DS6_DEFRT_NBU UIP_CONF_DS6_DEFRT_NBU
00071 #endif
00072 #define UIP_DS6_DEFRT_NB UIP_DS6_DEFRT_NBS + UIP_DS6_DEFRT_NBU
00073 
00074 /* Prefix list */
00075 #define UIP_DS6_PREFIX_NBS  1
00076 #ifndef UIP_CONF_DS6_PREFIX_NBU
00077 #define UIP_DS6_PREFIX_NBU  2
00078 #else
00079 #define UIP_DS6_PREFIX_NBU UIP_CONF_DS6_PREFIX_NBU
00080 #endif
00081 #define UIP_DS6_PREFIX_NB UIP_DS6_PREFIX_NBS + UIP_DS6_PREFIX_NBU
00082 
00083 /* Routing table */
00084 #define UIP_DS6_ROUTE_NBS 0
00085 #ifndef UIP_CONF_DS6_ROUTE_NBU
00086 #define UIP_DS6_ROUTE_NBU 4
00087 #else
00088 #define UIP_DS6_ROUTE_NBU UIP_CONF_DS6_ROUTE_NBU
00089 #endif
00090 #define UIP_DS6_ROUTE_NB UIP_DS6_ROUTE_NBS + UIP_DS6_ROUTE_NBU
00091 
00092 /* Unicast address list*/
00093 #define UIP_DS6_ADDR_NBS 1
00094 #ifndef UIP_CONF_DS6_ADDR_NBU
00095 #define UIP_DS6_ADDR_NBU 2
00096 #else
00097 #define UIP_DS6_ADDR_NBU UIP_CONF_DS6_ADDR_NBU
00098 #endif
00099 #define UIP_DS6_ADDR_NB UIP_DS6_ADDR_NBS + UIP_DS6_ADDR_NBU
00100 
00101 /* Multicast address list */
00102 #if UIP_CONF_ROUTER
00103 #define UIP_DS6_MADDR_NBS 2 + UIP_DS6_ADDR_NB   /* all routers + all nodes + one solicited per unicast */
00104 #else
00105 #define UIP_DS6_MADDR_NBS 1 + UIP_DS6_ADDR_NB   /* all nodes + one solicited per unicast */
00106 #endif
00107 #ifndef UIP_CONF_DS6_MADDR_NBU
00108 #define UIP_DS6_MADDR_NBU 0
00109 #else
00110 #define UIP_DS6_MADDR_NBU UIP_CONF_DS6_MADDR_NBU
00111 #endif
00112 #define UIP_DS6_MADDR_NB UIP_DS6_MADDR_NBS + UIP_DS6_MADDR_NBU
00113 
00114 /* Anycast address list */
00115 #if UIP_CONF_ROUTER
00116 #define UIP_DS6_AADDR_NBS UIP_DS6_PREFIX_NB - 1 /* One per non link local prefix (subnet prefix anycast address) */
00117 #else
00118 #define UIP_DS6_AADDR_NBS 0
00119 #endif
00120 #ifndef UIP_CONF_DS6_AADDR_NBU
00121 #define UIP_DS6_AADDR_NBU 0
00122 #else
00123 #define UIP_DS6_AADDR_NBU UIP_CONF_DS6_AADDR_NBU
00124 #endif
00125 #define UIP_DS6_AADDR_NB UIP_DS6_AADDR_NBS + UIP_DS6_AADDR_NBU
00126 
00127 
00128 /*--------------------------------------------------*/
00129 /** \brief Possible states for the nbr cache entries */
00130 #define  NBR_INCOMPLETE 0
00131 #define  NBR_REACHABLE 1
00132 #define  NBR_STALE 2
00133 #define  NBR_DELAY 3
00134 #define  NBR_PROBE 4
00135 
00136 /** \brief Possible states for the an address  (RFC 4862) */
00137 #define ADDR_TENTATIVE 0
00138 #define ADDR_PREFERRED 1
00139 #define ADDR_DEPRECATED 2
00140 
00141 /** \brief How the address was acquired: Autoconf, DHCP or manually */
00142 #define  ADDR_ANYTYPE 0
00143 #define  ADDR_AUTOCONF 1
00144 #define  ADDR_DHCP 2
00145 #define  ADDR_MANUAL 3
00146 
00147 /** \brief General DS6 definitions */
00148 #define UIP_DS6_PERIOD   (CLOCK_SECOND/10)  /** Period for uip-ds6 periodic task*/
00149 #define FOUND 0
00150 #define FREESPACE 1
00151 #define NOSPACE 2
00152 
00153 
00154 /*--------------------------------------------------*/
00155 #if UIP_CONF_IPV6_QUEUE_PKT
00156 #include "net/uip-packetqueue.h"
00157 #endif                          /*UIP_CONF_QUEUE_PKT */
00158 /** \brief An entry in the nbr cache */
00159 typedef struct uip_ds6_nbr {
00160   uint8_t isused;
00161   uip_ipaddr_t ipaddr;
00162   uip_lladdr_t lladdr;
00163   struct stimer reachable;
00164   struct stimer sendns;
00165   clock_time_t last_lookup;
00166   uint8_t nscount;
00167   uint8_t isrouter;
00168   uint8_t state;
00169 #if UIP_CONF_IPV6_QUEUE_PKT
00170   struct uip_packetqueue_handle packethandle;
00171 #define UIP_DS6_NBR_PACKET_LIFETIME CLOCK_SECOND * 4
00172 #endif                          /*UIP_CONF_QUEUE_PKT */
00173 } uip_ds6_nbr_t;
00174 
00175 /** \brief An entry in the default router list */
00176 typedef struct uip_ds6_defrt {
00177   uint8_t isused;
00178   uip_ipaddr_t ipaddr;
00179   struct stimer lifetime;
00180   uint8_t isinfinite;
00181 } uip_ds6_defrt_t;
00182 
00183 /** \brief A prefix list entry */
00184 #if UIP_CONF_ROUTER
00185 typedef struct uip_ds6_prefix {
00186   uint8_t isused;
00187   uip_ipaddr_t ipaddr;
00188   uint8_t length;
00189   uint8_t advertise;
00190   u32_t vlifetime;
00191   u32_t plifetime;
00192   uint8_t l_a_reserved; /**< on-link and autonomous flags + 6 reserved bits */
00193 } uip_ds6_prefix_t;
00194 #else /* UIP_CONF_ROUTER */
00195 typedef struct uip_ds6_prefix {
00196   uint8_t isused;
00197   uip_ipaddr_t ipaddr;
00198   uint8_t length;
00199   struct stimer vlifetime;
00200   uint8_t isinfinite;
00201 } uip_ds6_prefix_t;
00202 #endif /*UIP_CONF_ROUTER */
00203 
00204 /** * \brief Unicast address structure */
00205 typedef struct uip_ds6_addr {
00206   uint8_t isused;
00207   uip_ipaddr_t ipaddr;
00208   uint8_t state;
00209   uint8_t type;
00210   uint8_t isinfinite;
00211   struct stimer vlifetime;
00212   struct timer dadtimer;
00213   uint8_t dadnscount;
00214 } uip_ds6_addr_t;
00215 
00216 /** \brief Anycast address  */
00217 typedef struct uip_ds6_aaddr {
00218   uint8_t isused;
00219   uip_ipaddr_t ipaddr;
00220 } uip_ds6_aaddr_t;
00221 
00222 /** \brief A multicast address */
00223 typedef struct uip_ds6_maddr {
00224   uint8_t isused;
00225   uip_ipaddr_t ipaddr;
00226 } uip_ds6_maddr_t;
00227 
00228 /** \brief define some additional RPL related route state and
00229  *  neighbor callback for RPL - if not a DS6_ROUTE_STATE is already set */
00230 #ifndef UIP_DS6_ROUTE_STATE_TYPE
00231 #define UIP_DS6_ROUTE_STATE_TYPE rpl_route_entry_t
00232 /* Needed for the extended route entry state when using ContikiRPL */
00233 typedef struct rpl_route_entry {
00234   uint32_t lifetime;
00235   uint32_t saved_lifetime;
00236   void *dag;
00237   uint8_t learned_from;
00238 } rpl_route_entry_t;
00239 #endif /* UIP_DS6_ROUTE_STATE_TYPE */
00240 
00241 /* only define the callback if RPL is active */
00242 #if UIP_CONF_IPV6_RPL
00243 #ifndef UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED
00244 #define UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED rpl_ipv6_neighbor_callback
00245 #endif /* UIP_CONF_DS6_NEIGHBOR_STATE_CHANGED */
00246 #endif /* UIP_CONF_IPV6_RPL */
00247 
00248 
00249 
00250 /** \brief An entry in the routing table */
00251 typedef struct uip_ds6_route {
00252   uint8_t isused;
00253   uip_ipaddr_t ipaddr;
00254   uint8_t length;
00255   uint8_t metric;
00256   uip_ipaddr_t nexthop;
00257 #ifdef UIP_DS6_ROUTE_STATE_TYPE
00258   UIP_DS6_ROUTE_STATE_TYPE state;
00259 #endif
00260 } uip_ds6_route_t;
00261 
00262 /** \brief  Interface structure (contains all the interface variables) */
00263 typedef struct uip_ds6_netif {
00264   uint32_t link_mtu;
00265   uint8_t cur_hop_limit;
00266   uint32_t base_reachable_time; /* in msec */
00267   uint32_t reachable_time;      /* in msec */
00268   uint32_t retrans_timer;       /* in msec */
00269   uint8_t maxdadns;
00270   uip_ds6_addr_t addr_list[UIP_DS6_ADDR_NB];
00271   uip_ds6_aaddr_t aaddr_list[UIP_DS6_AADDR_NB];
00272   uip_ds6_maddr_t maddr_list[UIP_DS6_MADDR_NB];
00273 } uip_ds6_netif_t;
00274 
00275 /** \brief Generic type for a DS6, to use a common loop though all DS */
00276 typedef struct uip_ds6_element {
00277   uint8_t isused;
00278   uip_ipaddr_t ipaddr;
00279 } uip_ds6_element_t;
00280 
00281 
00282 /*---------------------------------------------------------------------------*/
00283 extern uip_ds6_netif_t uip_ds6_if;
00284 extern struct etimer uip_ds6_timer_periodic;
00285 
00286 #if UIP_CONF_ROUTER
00287 extern uip_ds6_prefix_t uip_ds6_prefix_list[UIP_DS6_PREFIX_NB];
00288 #else /* UIP_CONF_ROUTER */
00289 extern struct etimer uip_ds6_timer_rs;
00290 #endif /* UIP_CONF_ROUTER */
00291 
00292 
00293 /*---------------------------------------------------------------------------*/
00294 /** \brief Initialize data structures */
00295 void uip_ds6_init(void);
00296 
00297 /** \brief Periodic processing of data structures */
00298 void uip_ds6_periodic(void);
00299 
00300 /** \brief Generic loop routine on an abstract data structure, which generalizes
00301  * all data structures used in DS6 */
00302 uint8_t uip_ds6_list_loop(uip_ds6_element_t *list, uint8_t size,
00303                           uint16_t elementsize, uip_ipaddr_t *ipaddr,
00304                           uint8_t ipaddrlen,
00305                           uip_ds6_element_t **out_element);
00306 
00307 /** \name Neighbor Cache basic routines */
00308 /** @{ */
00309 uip_ds6_nbr_t *uip_ds6_nbr_add(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr,
00310                                uint8_t isrouter, uint8_t state);
00311 void uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr);
00312 uip_ds6_nbr_t *uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr);
00313 
00314 /** @} */
00315 
00316 /** \name Default router list basic routines */
00317 /** @{ */
00318 uip_ds6_defrt_t *uip_ds6_defrt_add(uip_ipaddr_t *ipaddr,
00319                                    unsigned long interval);
00320 void uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt);
00321 uip_ds6_defrt_t *uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr);
00322 uip_ipaddr_t *uip_ds6_defrt_choose(void);
00323 
00324 /** @} */
00325 
00326 /** \name Prefix list basic routines */
00327 /** @{ */
00328 #if UIP_CONF_ROUTER
00329 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
00330                                      uint8_t advertise, uint8_t flags,
00331                                      unsigned long vtime,
00332                                      unsigned long ptime);
00333 #else /* UIP_CONF_ROUTER */
00334 uip_ds6_prefix_t *uip_ds6_prefix_add(uip_ipaddr_t *ipaddr, uint8_t length,
00335                                      unsigned long interval);
00336 #endif /* UIP_CONF_ROUTER */
00337 void uip_ds6_prefix_rm(uip_ds6_prefix_t *prefix);
00338 uip_ds6_prefix_t *uip_ds6_prefix_lookup(uip_ipaddr_t *ipaddr,
00339                                         uint8_t ipaddrlen);
00340 uint8_t uip_ds6_is_addr_onlink(uip_ipaddr_t *ipaddr);
00341 
00342 /** @} */
00343 
00344 /** \name Unicast address list basic routines */
00345 /** @{ */
00346 uip_ds6_addr_t *uip_ds6_addr_add(uip_ipaddr_t *ipaddr,
00347                                  unsigned long vlifetime, uint8_t type);
00348 void uip_ds6_addr_rm(uip_ds6_addr_t *addr);
00349 uip_ds6_addr_t *uip_ds6_addr_lookup(uip_ipaddr_t *ipaddr);
00350 uip_ds6_addr_t *uip_ds6_get_link_local(int8_t state);
00351 uip_ds6_addr_t *uip_ds6_get_global(int8_t state);
00352 
00353 /** @} */
00354 
00355 /** \name Multicast address list basic routines */
00356 /** @{ */
00357 uip_ds6_maddr_t *uip_ds6_maddr_add(uip_ipaddr_t *ipaddr);
00358 void uip_ds6_maddr_rm(uip_ds6_maddr_t *maddr);
00359 uip_ds6_maddr_t *uip_ds6_maddr_lookup(uip_ipaddr_t *ipaddr);
00360 
00361 /** @} */
00362 
00363 /** \name Anycast address list basic routines */
00364 /** @{ */
00365 uip_ds6_aaddr_t *uip_ds6_aaddr_add(uip_ipaddr_t *ipaddr);
00366 void uip_ds6_aaddr_rm(uip_ds6_aaddr_t *aaddr);
00367 uip_ds6_aaddr_t *uip_ds6_aaddr_lookup(uip_ipaddr_t *ipaddr);
00368 
00369 /** @} */
00370 
00371 
00372 /** \name Routing Table basic routines */
00373 /** @{ */
00374 uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
00375 uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
00376                                    uip_ipaddr_t *next_hop, uint8_t metric);
00377 void uip_ds6_route_rm(uip_ds6_route_t *route);
00378 void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);
00379 
00380 /** @} */
00381 
00382 /** \brief set the last 64 bits of an IP address based on the MAC address */
00383 void uip_ds6_set_addr_iid(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr);
00384 
00385 /** \brief Get the number of matching bits of two addresses */
00386 uint8_t get_match_length(uip_ipaddr_t * src, uip_ipaddr_t * dst);
00387 
00388 /** \brief Perform Duplicate Address Selection on one address */
00389 void uip_ds6_dad(uip_ds6_addr_t * ifaddr);
00390 
00391 /** \brief Callback when DAD failed */
00392 int uip_ds6_dad_failed(uip_ds6_addr_t * ifaddr);
00393 
00394 /** \brief Source address selection, see RFC 3484 */
00395 void uip_ds6_select_src(uip_ipaddr_t * src, uip_ipaddr_t * dst);
00396 
00397 #if UIP_CONF_ROUTER
00398 #if UIP_ND6_SEND_RA
00399 /** \brief Send a RA as an asnwer to a RS */
00400 void uip_ds6_send_ra_sollicited(void);
00401 
00402 /** \brief Send a periodic RA */
00403 void uip_ds6_send_ra_periodic(void);
00404 #endif /* UIP_ND6_SEND_RA */
00405 #else /* UIP_CONF_ROUTER */
00406 /** \brief Send periodic RS to find router */
00407 void uip_ds6_send_rs(void);
00408 #endif /* UIP_CONF_ROUTER */
00409 
00410 /** \brief Compute the reachable time based on base reachable time, see RFC 4861*/
00411 uint32_t uip_ds6_compute_reachable_time(void); /** \brief compute random reachable timer */
00412 
00413 /** \name Macros to check if an IP address (unicast, multicast or anycast) is mine */
00414 /** @{ */
00415 #define uip_ds6_is_my_addr(addr)  (uip_ds6_addr_lookup(addr) != NULL)
00416 #define uip_ds6_is_my_maddr(addr) (uip_ds6_maddr_lookup(addr) != NULL)
00417 #define uip_ds6_is_my_aaddr(addr) (uip_ds6_aaddr_lookup(addr) != NULL)
00418 /** @} */
00419 /** @} */
00420 
00421 #endif /* __UIP_DS6_H__ */

Generated on Mon Apr 11 14:23:32 2011 for Contiki 2.5 by  doxygen 1.6.1