]>
Commit | Line | Data |
---|---|---|
ca10883e DS |
1 | /* |
2 | Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef BABEL_INTERFACE_H | |
24 | #define BABEL_INTERFACE_H | |
25 | ||
26 | #include <zebra.h> | |
27 | #include "zclient.h" | |
28 | #include "vty.h" | |
29 | #include "distribute.h" | |
30 | ||
31 | #define CONFIG_DEFAULT 0 | |
32 | #define CONFIG_NO 1 | |
33 | #define CONFIG_YES 2 | |
34 | ||
0437e105 | 35 | /* babeld interface information */ |
ca10883e DS |
36 | struct babel_interface { |
37 | unsigned short flags; /* see below */ | |
38 | unsigned short cost; | |
39 | int channel; | |
40 | struct timeval hello_timeout; | |
41 | struct timeval update_timeout; | |
42 | struct timeval flush_timeout; | |
43 | struct timeval update_flush_timeout; | |
44 | unsigned char *ipv4; | |
45 | int buffered; | |
46 | int bufsize; | |
47 | /* Relative position of the Hello message in the send buffer, or | |
48 | (-1) if there is none. */ | |
49 | int buffered_hello; | |
50 | char have_buffered_id; | |
51 | char have_buffered_nh; | |
52 | char have_buffered_prefix; | |
01b08f09 | 53 | unsigned char buffered_id[8]; |
ca10883e DS |
54 | unsigned char buffered_nh[4]; |
55 | unsigned char buffered_prefix[16]; | |
56 | unsigned char *sendbuf; | |
57 | struct buffered_update *buffered_updates; | |
58 | int num_buffered_updates; | |
59 | int update_bufsize; | |
60 | time_t bucket_time; | |
61 | unsigned int bucket; | |
62 | time_t last_update_time; | |
63 | unsigned short hello_seqno; | |
64 | unsigned hello_interval; | |
65 | unsigned update_interval; | |
66 | /* A higher value means we forget old RTT samples faster. Must be | |
67 | between 1 and 256, inclusive. */ | |
68 | unsigned int rtt_decay; | |
69 | /* Parameters for computing the cost associated to RTT. */ | |
70 | unsigned int rtt_min; | |
71 | unsigned int rtt_max; | |
72 | unsigned int max_rtt_penalty; | |
73 | ||
74 | /* For filter type slot. */ | |
75 | struct access_list *list[DISTRIBUTE_MAX]; /* Access-list. */ | |
76 | struct prefix_list *prefix[DISTRIBUTE_MAX]; /* Prefix-list. */ | |
77 | }; | |
78 | ||
79 | typedef struct babel_interface babel_interface_nfo; | |
80 | static inline babel_interface_nfo* babel_get_if_nfo(struct interface *ifp) | |
81 | { | |
82 | return ((babel_interface_nfo*) ifp->info); | |
83 | } | |
84 | ||
85 | /* babel_interface_nfo flags */ | |
86 | #define BABEL_IF_IS_UP (1 << 0) | |
87 | #define BABEL_IF_WIRED (1 << 1) | |
88 | #define BABEL_IF_SPLIT_HORIZON (1 << 2) | |
89 | #define BABEL_IF_LQ (1 << 3) | |
90 | #define BABEL_IF_FARAWAY (1 << 4) | |
91 | #define BABEL_IF_TIMESTAMPS (1 << 5) | |
92 | ||
93 | /* Only INTERFERING can appear on the wire. */ | |
94 | #define BABEL_IF_CHANNEL_UNKNOWN 0 | |
95 | #define BABEL_IF_CHANNEL_INTERFERING 255 | |
96 | #define BABEL_IF_CHANNEL_NONINTERFERING -2 | |
97 | ||
98 | static inline int | |
99 | if_up(struct interface *ifp) | |
100 | { | |
101 | return (if_is_operative(ifp) && | |
102 | ifp->connected != NULL && | |
103 | (babel_get_if_nfo(ifp)->flags & BABEL_IF_IS_UP)); | |
104 | } | |
105 | ||
ca10883e DS |
106 | struct buffered_update { |
107 | unsigned char id[8]; | |
108 | unsigned char prefix[16]; | |
109 | unsigned char plen; | |
110 | unsigned char pad[3]; | |
111 | }; | |
112 | ||
ca10883e DS |
113 | /* init function */ |
114 | void babel_if_init(void); | |
115 | ||
116 | /* Callback functions for zebra client */ | |
117 | int babel_interface_up (int, struct zclient *, zebra_size_t, vrf_id_t); | |
118 | int babel_interface_down (int, struct zclient *, zebra_size_t, vrf_id_t); | |
119 | int babel_interface_add (int, struct zclient *, zebra_size_t, vrf_id_t); | |
120 | int babel_interface_delete (int, struct zclient *, zebra_size_t, vrf_id_t); | |
121 | int babel_interface_address_add (int, struct zclient *, zebra_size_t, vrf_id_t); | |
122 | int babel_interface_address_delete (int, struct zclient *, zebra_size_t, vrf_id_t); | |
123 | ||
138c5a74 DS |
124 | int babel_ifp_create(struct interface *ifp); |
125 | int babel_ifp_up(struct interface *ifp); | |
126 | int babel_ifp_down(struct interface *ifp); | |
127 | int babel_ifp_destroy(struct interface *ifp); | |
128 | ||
ca10883e DS |
129 | unsigned jitter(babel_interface_nfo *, int); |
130 | unsigned update_jitter(babel_interface_nfo *babel_ifp, int urgent); | |
131 | /* return "true" if "address" is one of our ipv6 addresses */ | |
132 | int is_interface_ll_address(struct interface *ifp, const unsigned char *address); | |
133 | /* Send retraction to all, and reset all interfaces statistics. */ | |
134 | void babel_interface_close_all(void); | |
135 | extern int babel_enable_if_config_write (struct vty *); | |
136 | ||
137 | ||
138 | #endif |