Statistics
| Branch: | Revision:

iof-bird-daemon / proto / babel / babel.h @ 4324025f

History | View | Annotate | Download (7.51 KB)

1
/*
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
#include "sysdep/unix/timer.h"
25

    
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
/* Max interval that will not overflow when carried as 16-bit centiseconds */
53
#define BABEL_MAX_INTERVAL                (0xFFFF/BABEL_TIME_UNITS)
54

    
55
#define BABEL_OVERHEAD                (IP6_HEADER_LENGTH+UDP_HEADER_LENGTH)
56
#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
enum babel_iface_type {
82
  /* In practice, UNDEF and WIRED give equivalent behaviour */
83
  BABEL_IFACE_TYPE_UNDEF        = 0,
84
  BABEL_IFACE_TYPE_WIRED        = 1,
85
  BABEL_IFACE_TYPE_WIRELESS        = 2,
86
  BABEL_IFACE_TYPE_MAX
87
};
88

    
89
enum babel_ae_type {
90
  BABEL_AE_WILDCARD                = 0,
91
  BABEL_AE_IP4                        = 1,
92
  BABEL_AE_IP6                        = 2,
93
  BABEL_AE_IP6_LL                = 3,
94
  BABEL_AE_MAX
95
};
96

    
97

    
98
struct babel_config {
99
  struct proto_config c;
100

    
101
  list iface_list;              /* Patterns configured -- keep it first; see babel_reconfigure why */
102
};
103

    
104
struct babel_iface_config {
105
  struct iface_patt i;
106

    
107
  u16 rxcost;
108
  u8 type;
109
  u8 check_link;
110
  uint port;
111
  u16 hello_interval;
112
  u16 ihu_interval;
113
  u16 update_interval;
114

    
115
  u16 rx_buffer;                        /* RX buffer size, 0 for MTU */
116
  u16 tx_length;                        /* TX packet length limit (including headers), 0 for MTU */
117
  int tx_tos;
118
  int tx_priority;
119

    
120
  ip_addr next_hop_ip4;
121
  ip_addr next_hop_ip6;
122
};
123

    
124
struct babel_proto {
125
  struct proto p;
126
  timer *timer;
127
  struct fib ip4_rtable;
128
  struct fib ip6_rtable;
129

    
130
  struct channel *ip4_channel;
131
  struct channel *ip6_channel;
132

    
133
  list interfaces;                        /* Interfaces we really know about (struct babel_iface) */
134
  u64 router_id;
135
  u16 update_seqno;                        /* To be increased on request */
136
  u8 triggered;                                /* For triggering global updates */
137

    
138
  slab *route_slab;
139
  slab *source_slab;
140
  slab *msg_slab;
141

    
142
  slab *seqno_slab;
143
  list seqno_cache;                        /* Seqno requests in the cache (struct babel_seqno_request) */
144

    
145
  struct tbf log_pkt_tbf;                /* TBF for packet messages */
146
};
147

    
148
struct babel_iface {
149
  node n;
150

    
151
  struct babel_proto *proto;
152
  struct iface *iface;
153

    
154
  struct babel_iface_config *cf;
155

    
156
  u8 up;
157

    
158
  pool *pool;
159
  char *ifname;
160
  sock *sk;
161
  ip_addr addr;
162
  ip_addr next_hop_ip4;
163
  ip_addr next_hop_ip6;
164
  int tx_length;
165
  list neigh_list;                        /* List of neighbors seen on this iface (struct babel_neighbor) */
166
  list msg_queue;
167

    
168
  u16 hello_seqno;                        /* To be increased on each hello */
169

    
170
  bird_clock_t next_hello;
171
  bird_clock_t next_regular;
172
  bird_clock_t next_triggered;
173
  bird_clock_t want_triggered;
174

    
175
  timer *timer;
176
  event *send_event;
177
};
178

    
179
struct babel_neighbor {
180
  node n;
181
  struct babel_iface *ifa;
182

    
183
  ip_addr addr;
184
  u16 txcost;
185
  u8 hello_cnt;
186
  u16 hello_map;
187
  u16 next_hello_seqno;
188
  /* expiry timers */
189
  bird_clock_t hello_expiry;
190
  bird_clock_t ihu_expiry;
191

    
192
  list routes;                                /* Routes this neighbour has sent us (struct babel_route) */
193
};
194

    
195
struct babel_source {
196
  node n;
197

    
198
  u64 router_id;
199
  u16 seqno;
200
  u16 metric;
201
  bird_clock_t expires;
202
};
203

    
204
struct babel_route {
205
  node n;
206
  node neigh_route;
207
  struct babel_entry    *e;
208
  struct babel_neighbor *neigh;
209

    
210
  u16 seqno;
211
  u16 advert_metric;
212
  u16 metric;
213
  u64 router_id;
214
  ip_addr next_hop;
215
  bird_clock_t refresh_time;
216
  bird_clock_t expires;
217
  u16 expiry_interval;
218
};
219

    
220
struct babel_entry {
221
  struct babel_proto *proto;
222
  struct babel_route *selected_in;
223
  struct babel_route *selected_out;
224

    
225
  bird_clock_t updated;
226

    
227
  list sources;                                /* Source entries for this prefix (struct babel_source). */
228
  list routes;                                /* Routes for this prefix (struct babel_route) */
229

    
230
  struct fib_node n;
231
};
232

    
233
/* Stores forwarded seqno requests for duplicate suppression. */
234
struct babel_seqno_request {
235
  node n;
236
  net_addr net;
237
  u64 router_id;
238
  u16 seqno;
239
  bird_clock_t updated;
240
};
241

    
242

    
243
/*
244
 *        Internal TLV messages
245
 */
246

    
247
struct babel_msg_ack_req {
248
  u8 type;
249
  u16 nonce;
250
  u16 interval;
251
  ip_addr sender;
252
};
253

    
254
struct babel_msg_ack {
255
  u8 type;
256
  u16 nonce;
257
};
258

    
259
struct babel_msg_hello {
260
  u8 type;
261
  u16 seqno;
262
  u16 interval;
263
  ip_addr sender;
264
};
265

    
266
struct babel_msg_ihu {
267
  u8 type;
268
  u8 ae;
269
  u16 rxcost;
270
  u16 interval;
271
  ip_addr addr;
272
  ip_addr sender;
273
};
274

    
275
struct babel_msg_update {
276
  u8 type;
277
  u8 wildcard;
278
  u16 interval;
279
  u16 seqno;
280
  u16 metric;
281
  u64 router_id;
282
  net_addr net;
283
  ip_addr next_hop;
284
  ip_addr sender;
285
};
286

    
287
struct babel_msg_route_request {
288
  u8 type;
289
  u8 full;
290
  net_addr net;
291
};
292

    
293
struct babel_msg_seqno_request {
294
  u8 type;
295
  u8 hop_count;
296
  u16 seqno;
297
  u64 router_id;
298
  net_addr net;
299
  ip_addr sender;
300
};
301

    
302
union babel_msg {
303
  u8 type;
304
  struct babel_msg_ack_req ack_req;
305
  struct babel_msg_ack ack;
306
  struct babel_msg_hello hello;
307
  struct babel_msg_ihu ihu;
308
  struct babel_msg_update update;
309
  struct babel_msg_route_request route_request;
310
  struct babel_msg_seqno_request seqno_request;
311
};
312

    
313
struct babel_msg_node {
314
  node n;
315
  union babel_msg msg;
316
};
317

    
318

    
319
/* babel.c */
320
void babel_handle_ack_req(union babel_msg *msg, struct babel_iface *ifa);
321
void babel_handle_ack(union babel_msg *msg, struct babel_iface *ifa);
322
void babel_handle_hello(union babel_msg *msg, struct babel_iface *ifa);
323
void babel_handle_ihu(union babel_msg *msg, struct babel_iface *ifa);
324
void babel_handle_router_id(union babel_msg *msg, struct babel_iface *ifa);
325
void babel_handle_update(union babel_msg *msg, struct babel_iface *ifa);
326
void babel_handle_route_request(union babel_msg *msg, struct babel_iface *ifa);
327
void babel_handle_seqno_request(union babel_msg *msg, struct babel_iface *ifa);
328

    
329
void babel_show_interfaces(struct proto *P, char *iff);
330
void babel_show_neighbors(struct proto *P, char *iff);
331
void babel_show_entries(struct proto *P);
332

    
333
/* packets.c */
334
void babel_enqueue(union babel_msg *msg, struct babel_iface *ifa);
335
void babel_send_unicast(union babel_msg *msg, struct babel_iface *ifa, ip_addr dest);
336
int babel_open_socket(struct babel_iface *ifa);
337
void babel_send_queue(void *arg);
338

    
339

    
340
#endif