blob: dbb205d189dffaed918afef818364c2f58ed3138 [file] [log] [blame]
Paul Jakma57345092011-12-25 17:52:09 +01001/*
2 * This file is free software: you may copy, redistribute and/or modify it
3 * under the terms of the GNU General Public License as published by the
4 * Free Software Foundation, either version 2 of the License, or (at your
5 * option) any later version.
6 *
7 * This file is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 * This file incorporates work covered by the following copyright and
16 * permission notice:
17 *
18Copyright (c) 2007, 2008 by Juliusz Chroboczek
19Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
20
21Permission is hereby granted, free of charge, to any person obtaining a copy
22of this software and associated documentation files (the "Software"), to deal
23in the Software without restriction, including without limitation the rights
24to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25copies of the Software, and to permit persons to whom the Software is
26furnished to do so, subject to the following conditions:
27
28The above copyright notice and this permission notice shall be included in
29all copies or substantial portions of the Software.
30
31THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
37THE SOFTWARE.
38*/
39
40#include "babel_interface.h"
41#include "source.h"
42
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040043struct babel_route {
Paul Jakma57345092011-12-25 17:52:09 +010044 struct source *src;
45 unsigned short metric;
46 unsigned short refmetric;
47 unsigned short seqno;
48 struct neighbour *neigh;
49 unsigned char nexthop[16];
50 time_t time;
51 unsigned short hold_time; /* in seconds */
52 short installed;
53};
54
55static inline int
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040056route_metric(const struct babel_route *route)
Paul Jakma57345092011-12-25 17:52:09 +010057{
58 return route->metric;
59}
60
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040061extern struct babel_route *routes;
Paul Jakma57345092011-12-25 17:52:09 +010062extern int numroutes, maxroutes;
63extern int kernel_metric, allow_duplicates;
64
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040065struct babel_route *find_route(const unsigned char *prefix, unsigned char plen,
Paul Jakma57345092011-12-25 17:52:09 +010066 struct neighbour *neigh, const unsigned char *nexthop);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040067struct babel_route *find_installed_route(const unsigned char *prefix,
Paul Jakma57345092011-12-25 17:52:09 +010068 unsigned char plen);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040069void flush_route(struct babel_route *route);
Paul Jakma57345092011-12-25 17:52:09 +010070void flush_neighbour_routes(struct neighbour *neigh);
71void flush_interface_routes(struct interface *ifp, int v4only);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040072void install_route(struct babel_route *route);
73void uninstall_route(struct babel_route *route);
74void switch_route(struct babel_route *old, struct babel_route *new);
75int route_feasible(struct babel_route *route);
76int route_old(struct babel_route *route);
77int route_expired(struct babel_route *route);
Paul Jakma57345092011-12-25 17:52:09 +010078int update_feasible(struct source *src,
79 unsigned short seqno, unsigned short refmetric);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040080struct babel_route *find_best_route(const unsigned char *prefix, unsigned char plen,
Paul Jakma57345092011-12-25 17:52:09 +010081 int feasible, struct neighbour *exclude);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040082struct babel_route *install_best_route(const unsigned char prefix[16],
Paul Jakma57345092011-12-25 17:52:09 +010083 unsigned char plen);
84void update_neighbour_metric(struct neighbour *neigh, int change);
85void update_interface_metric(struct interface *ifp);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040086void update_route_metric(struct babel_route *route);
87struct babel_route *update_route(const unsigned char *a,
Paul Jakma57345092011-12-25 17:52:09 +010088 const unsigned char *p, unsigned char plen,
89 unsigned short seqno, unsigned short refmetric,
90 unsigned short interval, struct neighbour *neigh,
91 const unsigned char *nexthop);
92void retract_neighbour_routes(struct neighbour *neigh);
93void send_unfeasible_request(struct neighbour *neigh, int force,
94 unsigned short seqno, unsigned short metric,
95 struct source *src);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040096void send_triggered_update(struct babel_route *route,
Paul Jakma57345092011-12-25 17:52:09 +010097 struct source *oldsrc, unsigned oldmetric);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +040098void route_changed(struct babel_route *route,
Paul Jakma57345092011-12-25 17:52:09 +010099 struct source *oldsrc, unsigned short oldmetric);
100void route_lost(struct source *src, unsigned oldmetric);
101void expire_routes(void);
102
103void babel_uninstall_all_routes(void);
Denis Ovsienkoef4de4d2012-01-08 15:29:19 +0400104struct babel_route *babel_route_get_by_source(struct source *src);