2012-11-26 18:53:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, Thingsquare, http://www.thingsquare.com/.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
2015-02-15 18:02:07 +00:00
|
|
|
/**
|
2017-09-29 20:18:48 +00:00
|
|
|
* \addtogroup uip
|
2015-02-15 18:02:07 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Header file for routing table manipulation
|
|
|
|
*/
|
2012-11-26 18:53:38 +00:00
|
|
|
#ifndef UIP_DS6_ROUTE_H
|
|
|
|
#define UIP_DS6_ROUTE_H
|
|
|
|
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip.h"
|
2015-09-21 16:32:42 +00:00
|
|
|
#include "net/nbr-table.h"
|
2013-09-10 00:48:11 +00:00
|
|
|
#include "sys/stimer.h"
|
2013-07-03 17:45:56 +00:00
|
|
|
#include "lib/list.h"
|
2017-06-10 12:35:39 +00:00
|
|
|
|
|
|
|
#ifdef UIP_CONF_MAX_ROUTES
|
2017-12-10 18:51:05 +00:00
|
|
|
|
2017-06-10 12:35:39 +00:00
|
|
|
#define UIP_MAX_ROUTES UIP_CONF_MAX_ROUTES
|
2017-12-10 18:51:05 +00:00
|
|
|
|
2017-06-10 12:35:39 +00:00
|
|
|
#else /* UIP_CONF_MAX_ROUTES */
|
2017-12-10 18:51:05 +00:00
|
|
|
|
2017-12-10 20:20:24 +00:00
|
|
|
#if ROUTING_CONF_RPL_LITE
|
2017-12-10 18:51:05 +00:00
|
|
|
#define UIP_MAX_ROUTES 0 /* RPL Lite only supports non-storing, no routes */
|
2017-12-10 20:20:24 +00:00
|
|
|
#elif ROUTING_CONF_RPL_CLASSIC
|
2017-12-10 18:51:05 +00:00
|
|
|
|
|
|
|
#include "net/routing/rpl-classic/rpl-conf.h"
|
2017-06-10 12:35:39 +00:00
|
|
|
#if RPL_WITH_STORING
|
2017-06-30 16:03:58 +00:00
|
|
|
#define UIP_MAX_ROUTES NETSTACK_MAX_ROUTE_ENTRIES
|
2017-12-10 18:51:05 +00:00
|
|
|
#else /* RPL_WITH_STORING */
|
|
|
|
#define UIP_MAX_ROUTES 0 /* No storing mode, no need for routes */
|
|
|
|
#endif /* RPL_WITH_STORING */
|
|
|
|
|
|
|
|
#else /* Not RPL Lite nor RPL Classic */
|
|
|
|
#define UIP_MAX_ROUTES NETSTACK_MAX_ROUTE_ENTRIES
|
2017-06-10 12:35:39 +00:00
|
|
|
#endif
|
2017-12-10 18:51:05 +00:00
|
|
|
|
2017-06-10 12:35:39 +00:00
|
|
|
#endif /* UIP_CONF_MAX_ROUTES */
|
2013-07-03 17:45:56 +00:00
|
|
|
|
2015-09-21 16:32:42 +00:00
|
|
|
NBR_TABLE_DECLARE(nbr_routes);
|
|
|
|
|
2012-11-26 18:53:38 +00:00
|
|
|
void uip_ds6_route_init(void);
|
|
|
|
|
2013-05-15 10:11:56 +00:00
|
|
|
#ifndef UIP_CONF_UIP_DS6_NOTIFICATIONS
|
2017-06-10 12:35:39 +00:00
|
|
|
#define UIP_DS6_NOTIFICATIONS (UIP_MAX_ROUTES != 0)
|
2013-05-15 10:11:56 +00:00
|
|
|
#else
|
|
|
|
#define UIP_DS6_NOTIFICATIONS UIP_CONF_UIP_DS6_NOTIFICATIONS
|
|
|
|
#endif
|
2012-11-26 18:53:38 +00:00
|
|
|
|
2013-05-15 10:11:56 +00:00
|
|
|
#if UIP_DS6_NOTIFICATIONS
|
2012-11-26 18:53:38 +00:00
|
|
|
/* Event constants for the uip-ds6 route notification interface. The
|
|
|
|
notification interface allows for a user program to be notified via
|
|
|
|
a callback when a route has been added or removed and when the
|
|
|
|
system has added or removed a default route. */
|
|
|
|
#define UIP_DS6_NOTIFICATION_DEFRT_ADD 0
|
|
|
|
#define UIP_DS6_NOTIFICATION_DEFRT_RM 1
|
|
|
|
#define UIP_DS6_NOTIFICATION_ROUTE_ADD 2
|
|
|
|
#define UIP_DS6_NOTIFICATION_ROUTE_RM 3
|
|
|
|
|
|
|
|
typedef void (* uip_ds6_notification_callback)(int event,
|
|
|
|
uip_ipaddr_t *route,
|
|
|
|
uip_ipaddr_t *nexthop,
|
|
|
|
int num_routes);
|
|
|
|
struct uip_ds6_notification {
|
|
|
|
struct uip_ds6_notification *next;
|
|
|
|
uip_ds6_notification_callback callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
void uip_ds6_notification_add(struct uip_ds6_notification *n,
|
|
|
|
uip_ds6_notification_callback c);
|
|
|
|
|
2013-05-15 10:11:56 +00:00
|
|
|
void uip_ds6_notification_rm(struct uip_ds6_notification *n);
|
|
|
|
/*--------------------------------------------------*/
|
|
|
|
#endif
|
2012-11-26 18:53:38 +00:00
|
|
|
|
|
|
|
/* Routing table */
|
2017-06-10 12:35:39 +00:00
|
|
|
#ifdef UIP_MAX_ROUTES
|
|
|
|
#define UIP_DS6_ROUTE_NB UIP_MAX_ROUTES
|
|
|
|
#else /* UIP_MAX_ROUTES */
|
2016-07-07 10:03:53 +00:00
|
|
|
#define UIP_DS6_ROUTE_NB 4
|
2017-06-10 12:35:39 +00:00
|
|
|
#endif /* UIP_MAX_ROUTES */
|
2012-11-26 18:53:38 +00:00
|
|
|
|
|
|
|
/** \brief define some additional RPL related route state and
|
|
|
|
* neighbor callback for RPL - if not a DS6_ROUTE_STATE is already set */
|
|
|
|
#ifndef UIP_DS6_ROUTE_STATE_TYPE
|
|
|
|
#define UIP_DS6_ROUTE_STATE_TYPE rpl_route_entry_t
|
|
|
|
/* Needed for the extended route entry state when using ContikiRPL */
|
2015-08-19 13:50:20 +00:00
|
|
|
#define RPL_ROUTE_ENTRY_NOPATH_RECEIVED 0x01
|
|
|
|
#define RPL_ROUTE_ENTRY_DAO_PENDING 0x02
|
|
|
|
#define RPL_ROUTE_ENTRY_DAO_NACK 0x04
|
|
|
|
|
|
|
|
#define RPL_ROUTE_IS_NOPATH_RECEIVED(route) \
|
|
|
|
(((route)->state.state_flags & RPL_ROUTE_ENTRY_NOPATH_RECEIVED) != 0)
|
|
|
|
#define RPL_ROUTE_SET_NOPATH_RECEIVED(route) do { \
|
|
|
|
(route)->state.state_flags |= RPL_ROUTE_ENTRY_NOPATH_RECEIVED; \
|
|
|
|
} while(0)
|
2015-10-02 05:38:52 +00:00
|
|
|
#define RPL_ROUTE_CLEAR_NOPATH_RECEIVED(route) do { \
|
|
|
|
(route)->state.state_flags &= ~RPL_ROUTE_ENTRY_NOPATH_RECEIVED; \
|
|
|
|
} while(0)
|
2015-08-19 13:50:20 +00:00
|
|
|
|
|
|
|
#define RPL_ROUTE_IS_DAO_PENDING(route) \
|
|
|
|
((route->state.state_flags & RPL_ROUTE_ENTRY_DAO_PENDING) != 0)
|
|
|
|
#define RPL_ROUTE_SET_DAO_PENDING(route) do { \
|
|
|
|
(route)->state.state_flags |= RPL_ROUTE_ENTRY_DAO_PENDING; \
|
|
|
|
} while(0)
|
|
|
|
#define RPL_ROUTE_CLEAR_DAO_PENDING(route) do { \
|
|
|
|
(route)->state.state_flags &= ~RPL_ROUTE_ENTRY_DAO_PENDING; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define RPL_ROUTE_IS_DAO_NACKED(route) \
|
|
|
|
((route->state.state_flags & RPL_ROUTE_ENTRY_DAO_NACK) != 0)
|
|
|
|
#define RPL_ROUTE_SET_DAO_NACKED(route) do { \
|
|
|
|
(route)->state.state_flags |= RPL_ROUTE_ENTRY_DAO_NACK; \
|
|
|
|
} while(0)
|
2016-03-26 19:12:52 +00:00
|
|
|
#define RPL_ROUTE_CLEAR_DAO_NACKED(route) do { \
|
|
|
|
(route)->state.state_flags &= ~RPL_ROUTE_ENTRY_DAO_NACK; \
|
|
|
|
} while(0)
|
2015-08-19 13:50:20 +00:00
|
|
|
|
|
|
|
#define RPL_ROUTE_CLEAR_DAO(route) do { \
|
|
|
|
(route)->state.state_flags &= ~(RPL_ROUTE_ENTRY_DAO_NACK|RPL_ROUTE_ENTRY_DAO_PENDING); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
struct rpl_dag;
|
2012-11-26 18:53:38 +00:00
|
|
|
typedef struct rpl_route_entry {
|
|
|
|
uint32_t lifetime;
|
2015-08-19 13:50:20 +00:00
|
|
|
struct rpl_dag *dag;
|
|
|
|
uint8_t dao_seqno_out;
|
|
|
|
uint8_t dao_seqno_in;
|
|
|
|
uint8_t state_flags;
|
2012-11-26 18:53:38 +00:00
|
|
|
} rpl_route_entry_t;
|
|
|
|
#endif /* UIP_DS6_ROUTE_STATE_TYPE */
|
|
|
|
|
2013-08-11 22:22:21 +00:00
|
|
|
/** \brief The neighbor routes hold a list of routing table entries
|
|
|
|
that are attached to a specific neihbor. */
|
|
|
|
struct uip_ds6_route_neighbor_routes {
|
|
|
|
LIST_STRUCT(route_list);
|
|
|
|
};
|
2012-11-26 18:53:38 +00:00
|
|
|
|
|
|
|
/** \brief An entry in the routing table */
|
|
|
|
typedef struct uip_ds6_route {
|
|
|
|
struct uip_ds6_route *next;
|
2013-08-11 22:22:21 +00:00
|
|
|
/* Each route entry belongs to a specific neighbor. That neighbor
|
|
|
|
holds a list of all routing entries that go through it. The
|
|
|
|
routes field point to the uip_ds6_route_neighbor_routes that
|
|
|
|
belong to the neighbor table entry that this routing table entry
|
|
|
|
uses. */
|
2013-11-22 14:28:46 +00:00
|
|
|
struct uip_ds6_route_neighbor_routes *neighbor_routes;
|
2012-11-26 18:53:38 +00:00
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
#ifdef UIP_DS6_ROUTE_STATE_TYPE
|
|
|
|
UIP_DS6_ROUTE_STATE_TYPE state;
|
|
|
|
#endif
|
2013-07-03 17:45:56 +00:00
|
|
|
uint8_t length;
|
2012-11-26 18:53:38 +00:00
|
|
|
} uip_ds6_route_t;
|
|
|
|
|
2013-11-22 14:28:46 +00:00
|
|
|
/** \brief A neighbor route list entry, used on the
|
|
|
|
uip_ds6_route->neighbor_routes->route_list list. */
|
|
|
|
struct uip_ds6_route_neighbor_route {
|
|
|
|
struct uip_ds6_route_neighbor_route *next;
|
|
|
|
struct uip_ds6_route *route;
|
|
|
|
};
|
2012-11-26 18:53:38 +00:00
|
|
|
|
|
|
|
/** \brief An entry in the default router list */
|
|
|
|
typedef struct uip_ds6_defrt {
|
|
|
|
struct uip_ds6_defrt *next;
|
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
struct stimer lifetime;
|
|
|
|
uint8_t isinfinite;
|
|
|
|
} uip_ds6_defrt_t;
|
|
|
|
|
|
|
|
/** \name Default router list basic routines */
|
|
|
|
/** @{ */
|
2017-01-13 13:42:08 +00:00
|
|
|
uip_ds6_defrt_t *uip_ds6_defrt_head(void);
|
2012-11-26 18:53:38 +00:00
|
|
|
uip_ds6_defrt_t *uip_ds6_defrt_add(uip_ipaddr_t *ipaddr,
|
|
|
|
unsigned long interval);
|
|
|
|
void uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt);
|
|
|
|
uip_ds6_defrt_t *uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr);
|
|
|
|
uip_ipaddr_t *uip_ds6_defrt_choose(void);
|
|
|
|
|
|
|
|
void uip_ds6_defrt_periodic(void);
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
|
|
|
|
/** \name Routing Table basic routines */
|
|
|
|
/** @{ */
|
|
|
|
uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr);
|
|
|
|
uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length,
|
2013-07-03 17:45:56 +00:00
|
|
|
uip_ipaddr_t *next_hop);
|
2012-11-26 18:53:38 +00:00
|
|
|
void uip_ds6_route_rm(uip_ds6_route_t *route);
|
|
|
|
void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop);
|
|
|
|
|
2013-07-03 17:45:56 +00:00
|
|
|
uip_ipaddr_t *uip_ds6_route_nexthop(uip_ds6_route_t *);
|
2012-11-26 18:53:38 +00:00
|
|
|
int uip_ds6_route_num_routes(void);
|
2013-07-03 17:45:56 +00:00
|
|
|
uip_ds6_route_t *uip_ds6_route_head(void);
|
|
|
|
uip_ds6_route_t *uip_ds6_route_next(uip_ds6_route_t *);
|
2016-03-26 19:12:52 +00:00
|
|
|
int uip_ds6_route_is_nexthop(const uip_ipaddr_t *ipaddr);
|
2012-11-26 18:53:38 +00:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
#endif /* UIP_DS6_ROUTE_H */
|
2015-02-15 18:02:07 +00:00
|
|
|
/** @} */
|