Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ cadbb827

History | View | Annotate | Download (10.5 KB)

1
/*
2
 *        BIRD -- OSPF
3
 *
4
 *        (c) 1999-2000 Ondrej Filip <feela@network.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#ifndef _BIRD_OSPF_H_
10
#define _BIRD_OSPF_H_
11

    
12
#define SIPH SIZE_OF_IP_HEADER
13
#define MAXNETS 10
14
#ifdef LOCAL_DEBUG
15
#define OSPF_FORCE_DEBUG 1
16
#else
17
#define OSPF_FORCE_DEBUG 0
18
#endif
19
#define OSPF_TRACE(flags, msg, args...) do { if ((p->debug & flags) || OSPF_FORCE_DEBUG) \
20
  log(L_TRACE "%s: " msg, p->name , ## args ); } while(0)
21

    
22
#include "nest/bird.h"
23

    
24
#include "lib/checksum.h"
25
#include "lib/ip.h"
26
#include "lib/lists.h"
27
#include "lib/slists.h"
28
#include "lib/socket.h"
29
#include "lib/timer.h"
30
#include "lib/resource.h"
31
#include "nest/protocol.h"
32
#include "nest/iface.h"
33
#include "nest/route.h"
34
#include "nest/cli.h"
35
#include "nest/locks.h"
36
#include "conf/conf.h"
37
#include "lib/string.h"
38

    
39
#define OSPF_PROTO 89
40
#ifndef IPV6
41
#define OSPF_VERSION 2
42
#define AllSPFRouters ipa_from_u32(0xe0000005)        /* 224.0.0.5 */
43
#define AllDRouters ipa_from_u32(0xe0000006)        /* 224.0.0.6 */
44
#define DEFAULTDES ipa_from_u32(0)
45
#else
46
#error Multicast address not defined in IPv6
47
#endif
48

    
49

    
50
#define LSREFRESHTIME 1800        /* 30 minutes */
51
#define MINLSINTERVAL 5
52
#define MINLSARRIVAL 1
53
#define LSINFINITY 0xffff        /* RFC says 0xffffff ??? */
54
#define DISPTICK 7                /* FIXME What's good value? */
55

    
56
struct ospf_config {
57
  struct proto_config c;
58
  int rfc1583;
59
  list area_list;
60
};
61

    
62
struct nbma_node {
63
  node n;
64
  ip_addr ip;
65
};
66

    
67
struct ospf_area_config {
68
  node n;
69
  u32 areaid;
70
  int stub;
71
  unsigned tick;
72
  list patt_list;
73
};
74

    
75
struct ospf_iface {
76
  node n;
77
  struct proto_ospf *proto;
78
  struct iface *iface;        /* Nest's iface */
79
  struct ospf_area *oa;
80
  struct object_lock *lock;
81
  u32 an;                /* Area number */
82
  sock *hello_sk;        /* Hello socket */
83
  sock *dr_sk;                /* For states DR or BACKUP */
84
  sock *ip_sk;                /* IP socket (for DD ...) */
85
  list neigh_list;        /* List of neigbours */
86
  u16 cost;                /* Cost of iface */
87
  u16 rxmtint;                /* number of seconds between LSA retransmissions */
88
  u16 inftransdelay;        /* The estimated number of seconds it takes to
89
                           transmit a Link State Update Packet over this
90
                           interface.  LSAs contained in the update */
91
  u8 priority;                /* A router priority for DR election */
92
  u16 helloint;                /* number of seconds between hello sending */
93
  u16 waitint;                /* number of sec before changing state from wait */
94
  u32 deadc;                /* after "deadint" missing hellos is router dead */
95
  u16 autype;
96
  u8 aukey[8];
97
  u8 options;
98
  ip_addr drip;                /* Designated router */
99
  u32 drid;
100
  ip_addr bdrip;        /* Backup DR */
101
  u32 bdrid;
102
  u8 type;                /* OSPF view of type */
103
#define OSPF_IT_BCAST 0
104
#define OSPF_IT_NBMA 1
105
#define OSPF_IT_PTP 2
106
#define OSPF_IT_VLINK 3
107
#define OSPF_IT_UNDEF 4
108
  u8 state;                /* Interface state machine */
109
#define OSPF_IS_DOWN 0                /* Not working */
110
#define OSPF_IS_LOOP 1                /* Should never happen */
111
#define OSPF_IS_WAITING 2        /* Waiting for Wait timer */
112
#define OSPF_IS_PTP 3                /* PTP operational */
113
#define OSPF_IS_DROTHER 4        /* I'm on BCAST or NBMA and I'm not DR */
114
#define OSPF_IS_BACKUP 5        /* I'm BDR */
115
#define OSPF_IS_DR 6                /* I'm DR */
116
  timer *wait_timer;                /* WAIT timer */
117
  timer *hello_timer;                /* HELLOINT timer */
118
/* Default values for interface parameters */
119
#define COST_D 10
120
#define RXMTINT_D 5
121
#define INFTRANSDELAY_D 1
122
#define PRIORITY_D 1
123
#define HELLOINT_D 10
124
#define DEADC_D 4
125
#define WAIT_DMH 4        /* Value of Wait timer - not found it in RFC 
126
                         * - using 4*HELLO
127
                         */
128
  struct top_hash_entry *nlsa;        /* Originated net lsa */
129
  int fadj;                /* Number of full adjacent neigh */
130
  list nbma_list;
131
};
132

    
133
struct ospf_packet {
134
  u8 version;
135
  u8 type;
136
#define HELLO_P 1 /* Hello */
137
#define DBDES_P 2 /* Database description */
138
#define LSREQ_P 3 /* Link state request */
139
#define LSUPD_P 4 /* Link state update */
140
#define LSACK_P 5 /* Link state acknowledgement */
141
  u16 length;
142
  u32 routerid;
143
  u32 areaid;
144
#define BACKBONE 0
145
  u16 checksum;
146
  u16 autype;
147
  u8 authetication[8];
148
};
149

    
150
struct ospf_hello_packet {
151
  struct ospf_packet ospf_packet;
152
  ip_addr netmask;
153
  u16 helloint;
154
  u8 options;
155
  u8 priority;
156
  u32 deadint;
157
  u32 dr;
158
  u32 bdr;
159
};
160

    
161
struct immsb {
162
  u8 ms:1;
163
  u8 m:1;
164
  u8 i:1;
165
  u8 padding:5;
166
};
167

    
168
union imms {
169
  u8 byte;
170
  struct immsb bit;
171
};
172

    
173
struct ospf_dbdes_packet {
174
  struct ospf_packet ospf_packet;
175
  u16 iface_mtu;
176
  u8 options;
177
  union imms imms;                /* I, M, MS bits */
178
#define DBDES_MS 1
179
#define DBDES_M 2
180
#define DBDES_I 4
181
  u32 ddseq;
182
};
183

    
184

    
185
struct ospf_lsa_header {
186
  u16 age;        /* LS Age */
187
#define LSA_MAXAGE 3600                 /* 1 hour */
188
#define LSA_CHECKAGE 300                /* 5 minutes */
189
#define LSA_MAXAGEDIFF 900              /* 15 minutes */
190
  u8 options;
191
  u8 type;
192
  u32 id;
193
#define LSA_T_RT 1
194
#define LSA_T_NET 2
195
#define LSA_T_SUM_NET 3
196
#define LSA_T_SUM_RT 4
197
#define LSA_T_EXT 5
198
  u32 rt;                /* Advertising router */
199
  s32 sn;                /* LS Sequence number */
200
#define LSA_INITSEQNO 0x80000001
201
#define LSA_MAXSEQNO 0x7fffffff
202
  u16 checksum;
203
  u16 length;  
204
};
205

    
206
struct ospf_lsa_rt {
207
  u8 VEB;
208
#define LSA_RT_V 5
209
#define LSA_RT_E 6
210
#define LSA_RT_B 7
211
  u8 padding;
212
  u16 links;
213
};
214

    
215
struct ospf_lsa_rt_link {
216
  u32 id;
217
  u32 data;
218
  u8 type;
219
#define LSART_PTP 1
220
#define LSART_NET 2
221
#define LSART_STUB 3
222
#define LSART_VLNK 4
223
  u8 notos;
224
  u16 metric;
225
};
226

    
227
struct ospf_lsa_rt_link_tos {        /* Actually we ignore TOS. This is useless */
228
  u8 tos;
229
  u8 padding;
230
  u16 metric;
231
};
232

    
233
struct ospf_lsa_net {
234
  ip_addr netmask;
235
};
236

    
237
struct ospf_lsa_summ {
238
  ip_addr netmask;
239
};
240

    
241
struct ospf_lsa_summ_net {
242
  u8 tos;
243
  u8 padding;
244
  u16 metric;
245
};
246

    
247
struct ospf_lsa_ext {
248
  ip_addr netmask;
249
};
250

    
251
struct ospf_lsa_ext_tos {
252
  u8 etos;
253
  u8 padding;
254
  u16 metric;
255
  ip_addr fwaddr;
256
  u32 tag;
257
};
258

    
259
struct ospf_lsreq_packet {
260
  struct ospf_packet ospf_packet;
261
};
262

    
263
struct ospf_lsreq_header {
264
  u16 padd1;
265
  u8 padd2;
266
  u8 type;
267
  u32 id;
268
  u32 rt;                /* Advertising router */
269
};
270

    
271
struct l_lsr_head {
272
  node n;
273
  struct ospf_lsreq_header lsh;
274
};
275

    
276
struct ospf_lsupd_packet {
277
  struct ospf_packet ospf_packet;
278
  u32 lsano;                /* Number of LSA's */
279
};
280

    
281
struct ospf_lsack_packet {
282
  struct ospf_packet ospf_packet;
283
};
284

    
285

    
286
struct ospf_neighbor
287
{
288
  node n;
289
  struct ospf_iface *ifa;
290
  u8 state;
291
#define NEIGHBOR_DOWN 0
292
#define NEIGHBOR_ATTEMPT 1
293
#define NEIGHBOR_INIT 2
294
#define NEIGHBOR_2WAY 3
295
#define NEIGHBOR_EXSTART 4
296
#define NEIGHBOR_EXCHANGE 5
297
#define NEIGHBOR_LOADING 6
298
#define NEIGHBOR_FULL 7
299
  timer *inactim;        /* Inactivity timer */
300
  union imms imms;                /* I, M, Master/slave received */
301
  u32 dds;                /* DD Sequence number being sent */
302
  u32 ddr;                /* last Dat Des packet received */
303
  union imms myimms;                /* I, M Master/slave */
304
  u32 rid;                /* Router ID */
305
  ip_addr ip;                /* IP of it's interface */
306
  u8 priority;                /* Priority */
307
  u8 options;                /* Options received */
308
  u32 dr;                /* Neigbour's idea of DR */
309
  u32 bdr;                /* Neigbour's idea of BDR */
310
  u8 adj;                /* built adjacency? */
311
  siterator dbsi;        /* Database summary list iterator */
312
  slist lsrql;                /* Link state request */
313
  struct top_graph *lsrqh;                /* LSA graph */
314
  siterator lsrqi;
315
  slist lsrtl;                /* Link state retransmission list */
316
  siterator lsrti;
317
  struct top_graph *lsrth;
318
  void *ldbdes;                /* Last database description packet */
319
  timer *rxmt_timer;        /* RXMT timer */
320
  timer *lsrr_timer;        /* Link state request retransmition timer */
321
  list ackl;
322
  timer *ackd_timer;        /* Delayed ack timer */
323
};
324

    
325
/* Definitions for interface state machine */
326
#define ISM_UP 0        /* Interface Up */
327
#define ISM_WAITF 1        /* Wait timer fired */
328
#define ISM_BACKS 2        /* Backup seen */
329
#define ISM_NEICH 3        /* Neighbor change */
330
#define ISM_LOOP 4        /* Loop indicated */
331
#define ISM_UNLOOP 5        /* Unloop indicated */
332
#define ISM_DOWN 6        /* Interface down */
333

    
334
/* Definitions for neighbor state machine */
335
#define INM_HELLOREC 0        /* Hello Received */
336
#define INM_START 1        /* Neighbor start - for NBMA */
337
#define INM_2WAYREC 2        /* 2-Way received */
338
#define INM_NEGDONE 3        /* Negotiation done */
339
#define INM_EXDONE 4        /* Exchange done */
340
#define INM_BADLSREQ 5        /* Bad LS Request */
341
#define INM_LOADDONE 6        /* Load done */
342
#define INM_ADJOK 7        /* AdjOK? */
343
#define INM_SEQMIS 8        /* Sequence number mismatch */
344
#define INM_1WAYREC 9        /* 1-Way */
345
#define INM_KILLNBR 10        /* Kill Neighbor */
346
#define INM_INACTTIM 11        /* Inactivity timer */
347
#define INM_LLDOWN 12        /* Line down */
348

    
349
struct ospf_area {
350
  node n;
351
  u32 areaid;
352
  timer *disp_timer;                /* Area's dispatcher hear beat */
353
  bird_clock_t lage;                /* Time of last aging */
354
  int calcrt;                        /* Routing table calculation scheduled? */
355
  int origrt;                        /* Rt lsa origination scheduled? */
356
  struct top_graph *gr;                /* LSA graph */
357
  slist lsal;                        /* List of all LSA's */
358
  struct top_hash_entry *rt;        /* My own router LSA */
359
  list cand;                        /* List of candidates for RT calc. */
360
  int stub;
361
  int trcap;                        /* Transit capability? */
362
  struct proto_ospf *po;
363
  struct fib infib;                /* FIB for intra-area routes */
364
  unsigned tick;
365
};
366

    
367
struct proto_ospf {
368
  struct proto proto;
369
  list iface_list;                /* Interfaces we really use */
370
  list area_list;
371
  int areano;                        /* Number of area I belong to */
372
  struct fib efib;                /* FIB for external routes */
373
  int rfc1583;
374
};
375

    
376
struct ospf_iface_patt {
377
  struct iface_patt i;
378
  int cost;
379
  int helloint;
380
  int rxmtint;
381
  int inftransdelay; 
382
  int priority; 
383
  int waitint;
384
  int deadc;
385
  int type;
386
  int autype;
387
#define AU_NONE 0
388
#define AU_SIMPLE 1
389
#define AU_CRYPT 2
390
  u8 password[8];
391
  list nbma_list;
392
};
393

    
394
static int ospf_start(struct proto *p);
395
static void ospf_dump(struct proto *p);
396
static struct proto *ospf_init(struct proto_config *c);
397
static void ospf_preconfig(struct protocol *p, struct config *c);
398
static void ospf_postconfig(struct proto_config *c);
399
static int ospf_rte_better(struct rte *new, struct rte *old);
400
static int ospf_rte_same(struct rte *new, struct rte *old);
401
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
402
  struct linpool *pool);
403
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
404
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
405
void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,ea_list *attrs);
406
void area_disp(timer *timer);
407
void schedule_rt_lsa(struct ospf_area *oa);
408
void schedule_rtcalc(struct ospf_area *oa);
409
void ospf_sh_neigh(struct proto *p, char *iff);
410
void ospf_sh(struct proto *p);
411
void ospf_sh_iface(struct proto *p, char *iff);
412

    
413
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
414
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
415
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
416

    
417
#include "proto/ospf/hello.h"
418
#include "proto/ospf/packet.h"
419
#include "proto/ospf/iface.h"
420
#include "proto/ospf/neighbor.h"
421
#include "proto/ospf/topology.h"
422
#include "proto/ospf/dbdes.h"
423
#include "proto/ospf/lsreq.h"
424
#include "proto/ospf/lsupd.h"
425
#include "proto/ospf/lsack.h"
426
#include "proto/ospf/lsalib.h"
427
#include "proto/ospf/rt.h"
428

    
429
#endif /* _BIRD_OSPF_H_ */