blob: 7a6efb937eaeb1193afbb7034d919b690b4029ae [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
45/* babeld interface informations */
46struct babel_interface {
47 unsigned short flags; /* see below */
48 unsigned short cost;
49 struct timeval hello_timeout;
50 struct timeval update_timeout;
51 struct timeval flush_timeout;
52 struct timeval update_flush_timeout;
53 unsigned char *ipv4;
54 int buffered;
55 int bufsize;
56 char have_buffered_hello;
57 char have_buffered_id;
58 char have_buffered_nh;
59 char have_buffered_prefix;
60 unsigned char buffered_id[16];
61 unsigned char buffered_nh[4];
62 unsigned char buffered_prefix[16];
63 unsigned char *sendbuf;
64 struct buffered_update *buffered_updates;
65 int num_buffered_updates;
66 int update_bufsize;
67 time_t bucket_time;
68 unsigned int bucket;
69 time_t activity_time;
70 unsigned short hello_seqno;
71 unsigned hello_interval;
72 unsigned update_interval;
73
74 /* For filter type slot. */
75#define BABEL_FILTER_IN 0
76#define BABEL_FILTER_OUT 1
77#define BABEL_FILTER_MAX 2
78 struct access_list *list[BABEL_FILTER_MAX]; /* Access-list. */
79 struct prefix_list *prefix[BABEL_FILTER_MAX]; /* Prefix-list. */
80};
81
82typedef struct babel_interface babel_interface_nfo;
83static inline babel_interface_nfo* babel_get_if_nfo(struct interface *ifp)
84{
85 return ((babel_interface_nfo*) ifp->info);
86}
87
88/* babel_interface_nfo flags */
89#define BABEL_IF_WIRED (1 << 1)
90#define BABEL_IF_SPLIT_HORIZON (1 << 2)
91#define BABEL_IF_LQ (1 << 3)
92#define BABEL_IF_IS_ENABLE (1 << 4)
93
94static inline int
95if_up(struct interface *ifp)
96{
97 return (if_is_up(ifp) &&
98 ifp->connected != NULL &&
99 (babel_get_if_nfo(ifp)->flags & BABEL_IF_IS_ENABLE));
100}
101
102/* types:
103 struct interface _ifp, struct listnode node */
104#define FOR_ALL_INTERFACES(_ifp, _node) \
105 for(ALL_LIST_ELEMENTS_RO(iflist, _node, _ifp))
106
107/* types:
108 struct interface *ifp, struct connected *_connected, struct listnode *node */
109#define FOR_ALL_INTERFACES_ADDRESSES(ifp, _connected, _node) \
110 for(ALL_LIST_ELEMENTS_RO(ifp->connected, _node, _connected))
111
112struct buffered_update {
113 unsigned char id[8];
114 unsigned char prefix[16];
115 unsigned char plen;
116 unsigned char pad[3];
117};
118
119
120/* init function */
121void babel_if_init(void);
122
123/* Callback functions for zebra client */
124int babel_interface_up (int, struct zclient *, zebra_size_t);
125int babel_interface_down (int, struct zclient *, zebra_size_t);
126int babel_interface_add (int, struct zclient *, zebra_size_t);
127int babel_interface_delete (int, struct zclient *, zebra_size_t);
128int babel_interface_address_add (int, struct zclient *, zebra_size_t);
129int babel_interface_address_delete (int, struct zclient *, zebra_size_t);
130
131/* others functions */
132int interface_idle(babel_interface_nfo *);
133unsigned jitter(babel_interface_nfo *, int);
134unsigned update_jitter(babel_interface_nfo *babel_ifp, int urgent);
135/* return "true" if "address" is one of our ipv6 addresses */
136int is_interface_ll_address(struct interface *ifp, const unsigned char *address);
137/* Send retraction to all, and reset all interfaces statistics. */
138void babel_interface_close_all(void);
139
140
141#endif