Statistics
| Branch: | Revision:

iof-bird-daemon / proto / babel / babel.h @ 153f02da

History | View | Annotate | Download (7.59 KB)

1 937e75d8 Ondrej Zajicek (work)
/*
2
 *        BIRD -- The Babel protocol
3
 *
4
 *        Copyright (c) 2015--2016 Toke Hoiland-Jorgensen
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 *
8
 *        This file contains the data structures used by Babel.
9
 */
10
11
#ifndef _BIRD_BABEL_H_
12
#define _BIRD_BABEL_H_
13
14
#include "nest/bird.h"
15
#include "nest/cli.h"
16
#include "nest/iface.h"
17
#include "nest/route.h"
18
#include "nest/protocol.h"
19
#include "nest/locks.h"
20
#include "lib/resource.h"
21
#include "lib/lists.h"
22
#include "lib/socket.h"
23
#include "lib/string.h"
24 f7f70bed Jan Moskyto Matejka
#include "sysdep/unix/timer.h"
25 937e75d8 Ondrej Zajicek (work)
26
#define EA_BABEL_METRIC                EA_CODE(EAP_BABEL, 0)
27
#define EA_BABEL_ROUTER_ID        EA_CODE(EAP_BABEL, 1)
28
29
#define BABEL_MAGIC                42
30
#define BABEL_VERSION                2
31
#define BABEL_PORT                6696
32
#define BABEL_INFINITY                0xFFFF
33
34
35
#define BABEL_HELLO_INTERVAL_WIRED        4        /* Default hello intervals in seconds */
36
#define BABEL_HELLO_INTERVAL_WIRELESS        4
37
#define BABEL_UPDATE_INTERVAL_FACTOR        4
38
#define BABEL_IHU_INTERVAL_FACTOR        3
39
#define BABEL_IHU_EXPIRY_FACTOR(X)        ((X)*3/2)        /* 1.5 */
40
#define BABEL_HELLO_EXPIRY_FACTOR(X)        ((X)*3/2)        /* 1.5 */
41
#define BABEL_ROUTE_EXPIRY_FACTOR(X)        ((X)*7/2)        /* 3.5 */
42
#define BABEL_ROUTE_REFRESH_INTERVAL        2        /* Seconds before route expiry to send route request */
43
#define BABEL_HOLD_TIME                        10        /* Expiry time for our own routes */
44
#define BABEL_RXCOST_WIRED                96
45
#define BABEL_RXCOST_WIRELESS                256
46
#define BABEL_INITIAL_HOP_COUNT                255
47
#define BABEL_MAX_SEND_INTERVAL                5
48
#define BABEL_TIME_UNITS                100        /* On-wire times are counted in centiseconds */
49
#define BABEL_SEQNO_REQUEST_EXPIRY        60
50
#define BABEL_GARBAGE_INTERVAL                300
51
52 321ff8c4 Ondrej Zajicek (work)
/* Max interval that will not overflow when carried as 16-bit centiseconds */
53
#define BABEL_MAX_INTERVAL                (0xFFFF/BABEL_TIME_UNITS)
54
55 5e8df049 Ondrej Zajicek (work)
#define BABEL_OVERHEAD                (IP6_HEADER_LENGTH+UDP_HEADER_LENGTH)
56 937e75d8 Ondrej Zajicek (work)
#define BABEL_MIN_MTU                (512 + BABEL_OVERHEAD)
57
58
59
enum babel_tlv_type {
60
  BABEL_TLV_PAD1                = 0,
61
  BABEL_TLV_PADN                = 1,
62
  BABEL_TLV_ACK_REQ                = 2,
63
  BABEL_TLV_ACK                        = 3,
64
  BABEL_TLV_HELLO                = 4,
65
  BABEL_TLV_IHU                 = 5,
66
  BABEL_TLV_ROUTER_ID                = 6,
67
  BABEL_TLV_NEXT_HOP                = 7,
68
  BABEL_TLV_UPDATE                = 8,
69
  BABEL_TLV_ROUTE_REQUEST        = 9,
70
  BABEL_TLV_SEQNO_REQUEST        = 10,
71
  /* extensions - not implemented
72
  BABEL_TLV_TS_PC                = 11,
73
  BABEL_TLV_HMAC                = 12,
74
  BABEL_TLV_SS_UPDATE                = 13,
75
  BABEL_TLV_SS_REQUEST                = 14,
76
  BABEL_TLV_SS_SEQNO_REQUEST        = 15,
77
  */
78
  BABEL_TLV_MAX
79
};
80
81 145ebfa1 Ondrej Zajicek (work)
enum babel_subtlv_type {
82
  BABEL_SUBTLV_PAD1                = 0,
83
  BABEL_SUBTLV_PADN                = 1
84
};
85
86 937e75d8 Ondrej Zajicek (work)
enum babel_iface_type {
87
  /* In practice, UNDEF and WIRED give equivalent behaviour */
88
  BABEL_IFACE_TYPE_UNDEF        = 0,
89
  BABEL_IFACE_TYPE_WIRED        = 1,
90
  BABEL_IFACE_TYPE_WIRELESS        = 2,
91
  BABEL_IFACE_TYPE_MAX
92
};
93
94
enum babel_ae_type {
95
  BABEL_AE_WILDCARD                = 0,
96
  BABEL_AE_IP4                        = 1,
97
  BABEL_AE_IP6                        = 2,
98
  BABEL_AE_IP6_LL                = 3,
99
  BABEL_AE_MAX
100
};
101
102
103
struct babel_config {
104
  struct proto_config c;
105
106
  list iface_list;              /* Patterns configured -- keep it first; see babel_reconfigure why */
107
};
108
109
struct babel_iface_config {
110
  struct iface_patt i;
111
112
  u16 rxcost;
113
  u8 type;
114
  u8 check_link;
115 3e236955 Jan Moskyto Matejka
  uint port;
116 937e75d8 Ondrej Zajicek (work)
  u16 hello_interval;
117
  u16 ihu_interval;
118
  u16 update_interval;
119
120
  u16 rx_buffer;                        /* RX buffer size, 0 for MTU */
121
  u16 tx_length;                        /* TX packet length limit (including headers), 0 for MTU */
122
  int tx_tos;
123
  int tx_priority;
124 4324025f Ondrej Zajicek (work)
125
  ip_addr next_hop_ip4;
126
  ip_addr next_hop_ip6;
127 937e75d8 Ondrej Zajicek (work)
};
128
129
struct babel_proto {
130
  struct proto p;
131
  timer *timer;
132 4324025f Ondrej Zajicek (work)
  struct fib ip4_rtable;
133
  struct fib ip6_rtable;
134
135
  struct channel *ip4_channel;
136
  struct channel *ip6_channel;
137
138 937e75d8 Ondrej Zajicek (work)
  list interfaces;                        /* Interfaces we really know about (struct babel_iface) */
139
  u64 router_id;
140
  u16 update_seqno;                        /* To be increased on request */
141
  u8 triggered;                                /* For triggering global updates */
142
143
  slab *route_slab;
144
  slab *source_slab;
145
  slab *msg_slab;
146
147
  slab *seqno_slab;
148
  list seqno_cache;                        /* Seqno requests in the cache (struct babel_seqno_request) */
149
150
  struct tbf log_pkt_tbf;                /* TBF for packet messages */
151
};
152
153
struct babel_iface {
154
  node n;
155
156
  struct babel_proto *proto;
157
  struct iface *iface;
158
159
  struct babel_iface_config *cf;
160
161
  u8 up;
162
163
  pool *pool;
164
  char *ifname;
165
  sock *sk;
166
  ip_addr addr;
167 4324025f Ondrej Zajicek (work)
  ip_addr next_hop_ip4;
168
  ip_addr next_hop_ip6;
169 937e75d8 Ondrej Zajicek (work)
  int tx_length;
170
  list neigh_list;                        /* List of neighbors seen on this iface (struct babel_neighbor) */
171
  list msg_queue;
172
173
  u16 hello_seqno;                        /* To be increased on each hello */
174
175
  bird_clock_t next_hello;
176
  bird_clock_t next_regular;
177
  bird_clock_t next_triggered;
178
  bird_clock_t want_triggered;
179
180
  timer *timer;
181
  event *send_event;
182
};
183
184
struct babel_neighbor {
185
  node n;
186
  struct babel_iface *ifa;
187
188
  ip_addr addr;
189
  u16 txcost;
190
  u8 hello_cnt;
191
  u16 hello_map;
192
  u16 next_hello_seqno;
193
  /* expiry timers */
194
  bird_clock_t hello_expiry;
195
  bird_clock_t ihu_expiry;
196
197
  list routes;                                /* Routes this neighbour has sent us (struct babel_route) */
198
};
199
200
struct babel_source {
201
  node n;
202
203
  u64 router_id;
204
  u16 seqno;
205
  u16 metric;
206
  bird_clock_t expires;
207
};
208
209
struct babel_route {
210
  node n;
211
  node neigh_route;
212
  struct babel_entry    *e;
213
  struct babel_neighbor *neigh;
214
215
  u16 seqno;
216
  u16 advert_metric;
217
  u16 metric;
218
  u64 router_id;
219
  ip_addr next_hop;
220
  bird_clock_t refresh_time;
221
  bird_clock_t expires;
222
  u16 expiry_interval;
223
};
224
225
struct babel_entry {
226
  struct babel_proto *proto;
227
  struct babel_route *selected_in;
228
  struct babel_route *selected_out;
229
230
  bird_clock_t updated;
231
232
  list sources;                                /* Source entries for this prefix (struct babel_source). */
233
  list routes;                                /* Routes for this prefix (struct babel_route) */
234 5e8df049 Ondrej Zajicek (work)
235
  struct fib_node n;
236 937e75d8 Ondrej Zajicek (work)
};
237
238
/* Stores forwarded seqno requests for duplicate suppression. */
239
struct babel_seqno_request {
240
  node n;
241 5e8df049 Ondrej Zajicek (work)
  net_addr net;
242 937e75d8 Ondrej Zajicek (work)
  u64 router_id;
243
  u16 seqno;
244
  bird_clock_t updated;
245
};
246
247
248
/*
249
 *        Internal TLV messages
250
 */
251
252
struct babel_msg_ack_req {
253
  u8 type;
254
  u16 nonce;
255
  u16 interval;
256
  ip_addr sender;
257
};
258
259
struct babel_msg_ack {
260
  u8 type;
261
  u16 nonce;
262
};
263
264
struct babel_msg_hello {
265
  u8 type;
266
  u16 seqno;
267
  u16 interval;
268
  ip_addr sender;
269
};
270
271
struct babel_msg_ihu {
272
  u8 type;
273
  u8 ae;
274
  u16 rxcost;
275
  u16 interval;
276
  ip_addr addr;
277
  ip_addr sender;
278
};
279
280
struct babel_msg_update {
281
  u8 type;
282 5d6ca220 Ondrej Zajicek (work)
  u8 wildcard;
283 937e75d8 Ondrej Zajicek (work)
  u16 interval;
284
  u16 seqno;
285
  u16 metric;
286
  u64 router_id;
287 5e8df049 Ondrej Zajicek (work)
  net_addr net;
288 937e75d8 Ondrej Zajicek (work)
  ip_addr next_hop;
289
  ip_addr sender;
290
};
291
292
struct babel_msg_route_request {
293
  u8 type;
294
  u8 full;
295 5e8df049 Ondrej Zajicek (work)
  net_addr net;
296 937e75d8 Ondrej Zajicek (work)
};
297
298
struct babel_msg_seqno_request {
299
  u8 type;
300
  u8 hop_count;
301 5e8df049 Ondrej Zajicek (work)
  u16 seqno;
302 937e75d8 Ondrej Zajicek (work)
  u64 router_id;
303 5e8df049 Ondrej Zajicek (work)
  net_addr net;
304 937e75d8 Ondrej Zajicek (work)
  ip_addr sender;
305
};
306
307
union babel_msg {
308
  u8 type;
309
  struct babel_msg_ack_req ack_req;
310
  struct babel_msg_ack ack;
311
  struct babel_msg_hello hello;
312
  struct babel_msg_ihu ihu;
313
  struct babel_msg_update update;
314
  struct babel_msg_route_request route_request;
315
  struct babel_msg_seqno_request seqno_request;
316
};
317
318
struct babel_msg_node {
319
  node n;
320
  union babel_msg msg;
321
};
322
323
324
/* babel.c */
325
void babel_handle_ack_req(union babel_msg *msg, struct babel_iface *ifa);
326
void babel_handle_ack(union babel_msg *msg, struct babel_iface *ifa);
327
void babel_handle_hello(union babel_msg *msg, struct babel_iface *ifa);
328
void babel_handle_ihu(union babel_msg *msg, struct babel_iface *ifa);
329
void babel_handle_router_id(union babel_msg *msg, struct babel_iface *ifa);
330
void babel_handle_update(union babel_msg *msg, struct babel_iface *ifa);
331
void babel_handle_route_request(union babel_msg *msg, struct babel_iface *ifa);
332
void babel_handle_seqno_request(union babel_msg *msg, struct babel_iface *ifa);
333
334
void babel_show_interfaces(struct proto *P, char *iff);
335
void babel_show_neighbors(struct proto *P, char *iff);
336
void babel_show_entries(struct proto *P);
337
338
/* packets.c */
339
void babel_enqueue(union babel_msg *msg, struct babel_iface *ifa);
340
void babel_send_unicast(union babel_msg *msg, struct babel_iface *ifa, ip_addr dest);
341
int babel_open_socket(struct babel_iface *ifa);
342
void babel_send_queue(void *arg);
343
344
345
#endif