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 2011 by Matthieu Boutier and Juliusz Chroboczek |
| 19 | |
| 20 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 21 | of this software and associated documentation files (the "Software"), to deal |
| 22 | in the Software without restriction, including without limitation the rights |
| 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 24 | copies of the Software, and to permit persons to whom the Software is |
| 25 | furnished to do so, subject to the following conditions: |
| 26 | |
| 27 | The above copyright notice and this permission notice shall be included in |
| 28 | all copies or substantial portions of the Software. |
| 29 | |
| 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 36 | THE SOFTWARE. |
| 37 | */ |
| 38 | |
| 39 | #ifndef BABEL_INTERFACE_H |
| 40 | #define BABEL_INTERFACE_H |
| 41 | |
| 42 | #include <zebra.h> |
| 43 | #include "zclient.h" |
Denis Ovsienko | a14ef5e | 2012-02-11 21:06:16 +0400 | [diff] [blame^] | 44 | #include "vty.h" |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 45 | |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 46 | #define CONFIG_DEFAULT 0 |
| 47 | #define CONFIG_NO 1 |
| 48 | #define CONFIG_YES 2 |
| 49 | |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 50 | /* babeld interface informations */ |
| 51 | struct babel_interface { |
| 52 | unsigned short flags; /* see below */ |
| 53 | unsigned short cost; |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 54 | int channel; |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 55 | struct timeval hello_timeout; |
| 56 | struct timeval update_timeout; |
| 57 | struct timeval flush_timeout; |
| 58 | struct timeval update_flush_timeout; |
| 59 | unsigned char *ipv4; |
| 60 | int buffered; |
| 61 | int bufsize; |
| 62 | char have_buffered_hello; |
| 63 | char have_buffered_id; |
| 64 | char have_buffered_nh; |
| 65 | char have_buffered_prefix; |
| 66 | unsigned char buffered_id[16]; |
| 67 | unsigned char buffered_nh[4]; |
| 68 | unsigned char buffered_prefix[16]; |
| 69 | unsigned char *sendbuf; |
| 70 | struct buffered_update *buffered_updates; |
| 71 | int num_buffered_updates; |
| 72 | int update_bufsize; |
| 73 | time_t bucket_time; |
| 74 | unsigned int bucket; |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 75 | time_t last_update_time; |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 76 | unsigned short hello_seqno; |
| 77 | unsigned hello_interval; |
| 78 | unsigned update_interval; |
| 79 | |
| 80 | /* For filter type slot. */ |
| 81 | #define BABEL_FILTER_IN 0 |
| 82 | #define BABEL_FILTER_OUT 1 |
| 83 | #define BABEL_FILTER_MAX 2 |
| 84 | struct access_list *list[BABEL_FILTER_MAX]; /* Access-list. */ |
| 85 | struct prefix_list *prefix[BABEL_FILTER_MAX]; /* Prefix-list. */ |
| 86 | }; |
| 87 | |
| 88 | typedef struct babel_interface babel_interface_nfo; |
| 89 | static inline babel_interface_nfo* babel_get_if_nfo(struct interface *ifp) |
| 90 | { |
| 91 | return ((babel_interface_nfo*) ifp->info); |
| 92 | } |
| 93 | |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 94 | #define IF_CONF(_ifp, _field) babel_get_if_nfo(_ifp)->_field |
| 95 | |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 96 | /* babel_interface_nfo flags */ |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 97 | #define BABEL_IF_IS_UP (1 << 0) |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 98 | #define BABEL_IF_WIRED (1 << 1) |
| 99 | #define BABEL_IF_SPLIT_HORIZON (1 << 2) |
| 100 | #define BABEL_IF_LQ (1 << 3) |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 101 | #define BABEL_IF_FARAWAY (1 << 4) |
Matthieu Boutier | c35fafd | 2012-01-23 23:46:32 +0100 | [diff] [blame] | 102 | |
| 103 | /* Only INTERFERING can appear on the wire. */ |
| 104 | #define BABEL_IF_CHANNEL_UNKNOWN 0 |
| 105 | #define BABEL_IF_CHANNEL_INTERFERING 255 |
| 106 | #define BABEL_IF_CHANNEL_NONINTERFERING -2 |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 107 | |
| 108 | static inline int |
| 109 | if_up(struct interface *ifp) |
| 110 | { |
Matthieu Boutier | 0ee8a1f | 2012-01-18 00:52:06 +0100 | [diff] [blame] | 111 | return (if_is_operative(ifp) && |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 112 | ifp->connected != NULL && |
Matthieu Boutier | 8c4e57a | 2012-01-28 00:29:51 +0100 | [diff] [blame] | 113 | (babel_get_if_nfo(ifp)->flags & BABEL_IF_IS_UP)); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* types: |
| 117 | struct interface _ifp, struct listnode node */ |
| 118 | #define FOR_ALL_INTERFACES(_ifp, _node) \ |
| 119 | for(ALL_LIST_ELEMENTS_RO(iflist, _node, _ifp)) |
| 120 | |
| 121 | /* types: |
| 122 | struct interface *ifp, struct connected *_connected, struct listnode *node */ |
| 123 | #define FOR_ALL_INTERFACES_ADDRESSES(ifp, _connected, _node) \ |
| 124 | for(ALL_LIST_ELEMENTS_RO(ifp->connected, _node, _connected)) |
| 125 | |
| 126 | struct buffered_update { |
| 127 | unsigned char id[8]; |
| 128 | unsigned char prefix[16]; |
| 129 | unsigned char plen; |
| 130 | unsigned char pad[3]; |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | /* init function */ |
| 135 | void babel_if_init(void); |
| 136 | |
| 137 | /* Callback functions for zebra client */ |
| 138 | int babel_interface_up (int, struct zclient *, zebra_size_t); |
| 139 | int babel_interface_down (int, struct zclient *, zebra_size_t); |
| 140 | int babel_interface_add (int, struct zclient *, zebra_size_t); |
| 141 | int babel_interface_delete (int, struct zclient *, zebra_size_t); |
| 142 | int babel_interface_address_add (int, struct zclient *, zebra_size_t); |
| 143 | int babel_interface_address_delete (int, struct zclient *, zebra_size_t); |
| 144 | |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 145 | unsigned jitter(babel_interface_nfo *, int); |
| 146 | unsigned update_jitter(babel_interface_nfo *babel_ifp, int urgent); |
| 147 | /* return "true" if "address" is one of our ipv6 addresses */ |
| 148 | int is_interface_ll_address(struct interface *ifp, const unsigned char *address); |
| 149 | /* Send retraction to all, and reset all interfaces statistics. */ |
| 150 | void babel_interface_close_all(void); |
Denis Ovsienko | a14ef5e | 2012-02-11 21:06:16 +0400 | [diff] [blame^] | 151 | extern int babel_enable_if_config_write (struct vty *); |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 152 | |
| 153 | |
| 154 | #endif |