Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 1 | /* |
| 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 | * |
| 18 | Copyright (c) 2007, 2008 by Juliusz Chroboczek |
| 19 | Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek |
| 20 | |
| 21 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 22 | of this software and associated documentation files (the "Software"), to deal |
| 23 | in the Software without restriction, including without limitation the rights |
| 24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 25 | copies of the Software, and to permit persons to whom the Software is |
| 26 | furnished to do so, subject to the following conditions: |
| 27 | |
| 28 | The above copyright notice and this permission notice shall be included in |
| 29 | all copies or substantial portions of the Software. |
| 30 | |
| 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 37 | THE SOFTWARE. |
| 38 | */ |
| 39 | |
Matthieu Boutier | 1f39f46 | 2012-01-18 20:01:31 +0100 | [diff] [blame] | 40 | #ifndef BABEL_ROUTE_H |
| 41 | #define BABEL_ROUTE_H |
| 42 | |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 43 | #include "babel_interface.h" |
| 44 | #include "source.h" |
| 45 | |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 46 | struct babel_route { |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 47 | struct source *src; |
| 48 | unsigned short metric; |
| 49 | unsigned short refmetric; |
| 50 | unsigned short seqno; |
| 51 | struct neighbour *neigh; |
| 52 | unsigned char nexthop[16]; |
| 53 | time_t time; |
| 54 | unsigned short hold_time; /* in seconds */ |
| 55 | short installed; |
| 56 | }; |
| 57 | |
Matthieu Boutier | c7c53fa | 2012-01-08 16:43:08 +0100 | [diff] [blame] | 58 | static inline unsigned short |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 59 | route_metric(const struct babel_route *route) |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 60 | { |
| 61 | return route->metric; |
| 62 | } |
| 63 | |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 64 | extern struct babel_route *routes; |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 65 | extern int numroutes, maxroutes; |
| 66 | extern int kernel_metric, allow_duplicates; |
| 67 | |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 68 | struct babel_route *find_route(const unsigned char *prefix, unsigned char plen, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 69 | struct neighbour *neigh, const unsigned char *nexthop); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 70 | struct babel_route *find_installed_route(const unsigned char *prefix, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 71 | unsigned char plen); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 72 | void flush_route(struct babel_route *route); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 73 | void flush_neighbour_routes(struct neighbour *neigh); |
| 74 | void flush_interface_routes(struct interface *ifp, int v4only); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 75 | void install_route(struct babel_route *route); |
| 76 | void uninstall_route(struct babel_route *route); |
| 77 | void switch_route(struct babel_route *old, struct babel_route *new); |
| 78 | int route_feasible(struct babel_route *route); |
| 79 | int route_old(struct babel_route *route); |
| 80 | int route_expired(struct babel_route *route); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 81 | int update_feasible(struct source *src, |
| 82 | unsigned short seqno, unsigned short refmetric); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 83 | struct babel_route *find_best_route(const unsigned char *prefix, unsigned char plen, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 84 | int feasible, struct neighbour *exclude); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 85 | struct babel_route *install_best_route(const unsigned char prefix[16], |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 86 | unsigned char plen); |
| 87 | void update_neighbour_metric(struct neighbour *neigh, int change); |
| 88 | void update_interface_metric(struct interface *ifp); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 89 | void update_route_metric(struct babel_route *route); |
| 90 | struct babel_route *update_route(const unsigned char *a, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 91 | const unsigned char *p, unsigned char plen, |
| 92 | unsigned short seqno, unsigned short refmetric, |
| 93 | unsigned short interval, struct neighbour *neigh, |
| 94 | const unsigned char *nexthop); |
| 95 | void retract_neighbour_routes(struct neighbour *neigh); |
| 96 | void send_unfeasible_request(struct neighbour *neigh, int force, |
| 97 | unsigned short seqno, unsigned short metric, |
| 98 | struct source *src); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 99 | void send_triggered_update(struct babel_route *route, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 100 | struct source *oldsrc, unsigned oldmetric); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 101 | void route_changed(struct babel_route *route, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 102 | struct source *oldsrc, unsigned short oldmetric); |
| 103 | void route_lost(struct source *src, unsigned oldmetric); |
| 104 | void expire_routes(void); |
| 105 | |
| 106 | void babel_uninstall_all_routes(void); |
Denis Ovsienko | ef4de4d | 2012-01-08 15:29:19 +0400 | [diff] [blame] | 107 | struct babel_route *babel_route_get_by_source(struct source *src); |
Matthieu Boutier | 1f39f46 | 2012-01-18 20:01:31 +0100 | [diff] [blame] | 108 | |
| 109 | #endif |