Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | /** @file
* @brief Route handler
*
* This is not to be included by the application.
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __ROUTE_H
#define __ROUTE_H
#include <kernel.h>
#include <misc/slist.h>
#include <net/net_ip.h>
#include "nbr.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(CONFIG_NET_ROUTE)
/**
* @brief Next hop entry for a given route.
*/
struct net_route_nexthop {
/** Pointer to nexthop that has same route to a specific
* neighbor.
*/
sys_snode_t node;
/** Next hop neighbor */
struct net_nbr *nbr;
};
/**
* @brief Route entry to a specific neighbor.
*/
struct net_route_entry {
/** Node information. The routes are also in separate list in
* order to keep track which one of them is the oldest so that
* we can remove it if we run out of available routes.
* The oldest one is the last entry in the list.
*/
sys_snode_t node;
/** List of neighbors that the routes go through. */
sys_slist_t nexthop;
/** Network interface for the route. */
struct net_if *iface;
/** IPv6 address/prefix of the route. */
struct in6_addr addr;
/** IPv6 address/prefix length. */
uint8_t prefix_len;
};
/**
* @brief Lookup route to a given destination.
*
* @param iface Network interface. If NULL, then check against all interfaces.
* @param dst Destination IPv6 address.
*
* @return Return route entry related to a given destination address, NULL
* if not found.
*/
struct net_route_entry *net_route_lookup(struct net_if *iface,
struct in6_addr *dst);
/**
* @brief Add a route to routing table.
*
* @param iface Network interface that this route is tied to.
* @param addr IPv6 address.
* @param prefix_len Length of the IPv6 address/prefix.
* @param nexthop IPv6 address of the Next hop device.
*
* @return Return created route entry, NULL if could not be created.
*/
struct net_route_entry *net_route_add(struct net_if *iface,
struct in6_addr *addr,
uint8_t prefix_len,
struct in6_addr *nexthop);
/**
* @brief Delete a route from routing table.
*
* @param entry Existing route entry.
*
* @return 0 if ok, <0 if error
*/
int net_route_del(struct net_route_entry *entry);
/**
* @brief Delete a route from routing table by nexthop.
*
* @param iface Network interface to use.
* @param nexthop IPv6 address of the nexthop device.
*
* @return number of routes deleted, <0 if error
*/
int net_route_del_by_nexthop(struct net_if *iface,
struct in6_addr *nexthop);
/**
* @brief Delete a route from routing table by nexthop if the routing engine
* specific data matches.
*
* @detail The routing engine specific data could be the RPL data.
*
* @param iface Network interface to use.
* @param nexthop IPv6 address of the nexthop device.
* @param data Routing engine specific data.
*
* @return number of routes deleted, <0 if error
*/
int net_route_del_by_nexthop_data(struct net_if *iface,
struct in6_addr *nexthop,
void *data);
/**
* @brief Get nexthop IPv6 address tied to this route.
*
* There can be multiple routes to a host but this function
* will only return the first one in this version.
*
* @param entry Route entry to use.
*
* @return IPv6 address of the nexthop, NULL if not found.
*/
struct in6_addr *net_route_get_nexthop(struct net_route_entry *entry);
/**
* @brief Get generic neighbor entry from route entry.
*
* @param route Pointer to routing entry.
*
* @return Generic neighbor entry.
*/
struct net_nbr *net_route_get_nbr(struct net_route_entry *route);
typedef void (*net_route_cb_t)(struct net_route_entry *entry,
void *user_data);
/**
* @brief Go through all the routing entries and call callback
* for each entry that is in use.
*
* @param cb User supplied callback function to call.
* @param user_data User specified data.
*
* @return Total number of routing entries found.
*/
int net_route_foreach(net_route_cb_t cb, void *user_data);
void net_route_init(void);
#if defined(CONFIG_NET_ROUTE_MCAST)
/**
* @brief Multicast route entry.
*/
struct net_route_entry_mcast {
/** Network interface for the route. */
struct net_if *iface;
/** Extra routing engine specific data */
void *data;
/** IPv6 multicast group of the route. */
struct in6_addr group;
/** Routing entry lifetime in seconds. */
uint32_t lifetime;
/** Is this entry in user or not */
bool is_used;
};
typedef void (*net_route_mcast_cb_t)(struct net_route_entry_mcast *entry,
void *user_data);
/**
* @brief Go through all the multicast routing entries and call callback
* for each entry that is in use.
*
* @param cb User supplied callback function to call.
* @param skip Do not call callback for this address.
* @param user_data User specified data.
*
* @return Total number of multicast routing entries that are in use.
*/
int net_route_mcast_foreach(net_route_mcast_cb_t cb,
struct in6_addr *skip,
void *user_data);
/**
* @brief Add a multicast routing entry.
*
* @param iface Network interface to use.
* @param group IPv6 multicast address.
*
* @return Multicast routing entry.
*/
struct net_route_entry_mcast *net_route_mcast_add(struct net_if *iface,
struct in6_addr *group);
/**
* @brief Delete a multicast routing entry.
*
* @param route Multicast routing entry.
*
* @return True if entry was deleted, false otherwise.
*/
bool net_route_mcast_del(struct net_route_entry_mcast *route);
/**
* @brief Lookup a multicast routing entry.
*
* @param group IPv6 multicast group address
*
* @return Routing entry corresponding this multicast group.
*/
struct net_route_entry_mcast *
net_route_mcast_lookup(struct in6_addr *group);
#endif /* CONFIG_NET_ROUTE_MCAST */
#else /* CONFIG_NET_ROUTE */
#define net_route_init(...)
#endif /* CONFIG_NET_ROUTE */
#ifdef __cplusplus
}
#endif
#endif /* __ROUTE_H */
|