3 * The olsr.org Optimized Link-State Routing daemon version 2 (olsrd2)
4 * Copyright (c) 2004-2015, the olsr.org team - see HISTORY file
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of olsr.org, olsrd nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * Visit http://www.olsr.org for more information.
36 * If you find this software useful feel free to make a donation
37 * to the project. For more information see the website or contact
38 * the copyright holders.
46 #ifndef OLSRV2_ROUTING_H_
47 #define OLSRV2_ROUTING_H_
49 #include "common/avl.h"
50 #include "common/common_types.h"
51 #include "common/list.h"
52 #include "common/netaddr.h"
54 #include "subsystems/os_routing.h"
56 #include "nhdp/nhdp.h"
57 #include "nhdp/nhdp_db.h"
58 #include "nhdp/nhdp_domain.h"
60 /*! minimum time between two dijkstra calculations in milliseconds */
61 enum { OLSRv2_DIJKSTRA_RATE_LIMITATION = 1000 };
64 * representation of a node in the dijkstra tree
66 struct olsrv2_dijkstra_node {
67 /*! hook into the working list of the dijkstra */
68 struct avl_node _node;
70 /*! total path cost */
73 /*! path hops to the target */
76 /*! hopcount to be inserted into the route */
79 /*! originator address of the router responsible for the prefix */
80 const struct netaddr *originator;
82 /*! pointer to nhpd neighbor that represents the first hop */
83 struct nhdp_neighbor *first_hop;
86 * address of the last originator in the routing tree before
89 const struct netaddr *last_originator;
91 /*! true if route is single-hop */
94 /*! true if this node is ourself */
97 /*! true if node already has been processed */
102 * representation of one target in the routing entry set
104 struct olsrv2_routing_entry {
105 /*! Settings for the kernel route */
106 struct os_route route;
108 /*! nhdp domain of route */
109 struct nhdp_domain *domain;
111 /*! path cost to reach the target */
114 /*! path hops to the target */
117 /*! originator of node that announced the route */
118 struct netaddr originator;
120 /*! originator address of next hop */
121 struct netaddr next_originator;
123 /*! originator of last hop before target */
124 struct netaddr last_originator;
127 * true if the entry represents a route that should be in the kernel,
128 * false if the entry should be removed from the kernel
132 /*! true if this route is being processed by the kernel at the moment */
135 /*! old values of route before current dijstra run */
136 struct os_route_parameter _old;
138 /*! hook into working queues */
139 struct list_entity _working_node;
142 struct avl_node _node;
146 * routing domain specific parameters
148 struct olsrv2_routing_domain {
149 /*! true if IPv4 routes should set a source IP */
150 bool use_srcip_in_routes;
152 /*! protocol number for routes */
155 /*! routing table number for routes */
158 /*! metric value that should be used for routes */
161 /*! domain uses source specific routing */
162 bool source_specific;
166 * A filter that can modify or drop the result of the Dijkstra algorithm
168 struct olsrv2_routing_filter {
170 * callback for routing filter, return false to drop route modification.
171 * filter can modify all parameters of the route.
172 * @param domain NHDP domain
173 * @param route_param operation system route parameters
174 * @return true if route should still be set/removed, false if it should be ignored
176 bool (*filter)(struct nhdp_domain *domain , struct os_route_parameter *route_param, bool set);
178 /*! node to hold all routing filters together */
179 struct list_entity _node;
182 int olsrv2_routing_init(void);
183 void olsrv2_routing_initiate_shutdown(void);
184 void olsrv2_routing_cleanup(void);
186 void olsrv2_routing_dijkstra_node_init(
187 struct olsrv2_dijkstra_node *, const struct netaddr *originator);
189 EXPORT uint16_t olsrv2_routing_get_ansn(void);
190 EXPORT void olsrv2_routing_force_ansn_increment(uint16_t increment);
192 EXPORT void olsrv2_routing_set_domain_parameter(struct nhdp_domain *domain,
193 struct olsrv2_routing_domain *parameter);
195 EXPORT void olsrv2_routing_domain_changed(struct nhdp_domain *domain);
196 EXPORT void olsrv2_routing_force_update(bool skip_wait);
197 EXPORT void olsrv2_routing_trigger_update(void);
199 EXPORT void olsrv2_routing_freeze_routes(bool freeze);
201 EXPORT const struct olsrv2_routing_domain *
202 olsrv2_routing_get_parameters(struct nhdp_domain *);
204 EXPORT struct avl_tree *olsrv2_routing_get_tree(struct nhdp_domain *domain);
205 EXPORT struct list_entity *olsrv2_routing_get_filter_list(void);
208 * Add a routing filter to the dijkstra processing list
209 * @param filter pointer to routing filter
212 olsrv2_routing_filter_add(struct olsrv2_routing_filter *filter) {
213 list_add_tail(olsrv2_routing_get_filter_list(), &filter->_node);
217 * Remove a routing filter from the dijkstra processing list
218 * @param filter pointer to routing filter
221 olsrv2_routing_filter_remove(struct olsrv2_routing_filter *filter) {
222 list_remove(&filter->_node);
225 #endif /* OLSRV2_ROUTING_SET_H_ */