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