Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ 60e04f04

History | View | Annotate | Download (12.5 KB)

1
/*
2
 *        BIRD -- OSPF
3
 *
4
 *        (c) 1999--2004 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 MAXNETS 10
13
#ifdef LOCAL_DEBUG
14
#define OSPF_FORCE_DEBUG 1
15
#else
16
#define OSPF_FORCE_DEBUG 0
17
#endif
18
#define OSPF_TRACE(flags, msg, args...) do { if ((p->debug & flags) || OSPF_FORCE_DEBUG) \
19
  log(L_TRACE "%s: " msg, p->name , ## args ); } while(0)
20

    
21
#include "nest/bird.h"
22

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

    
38
#define OSPF_PROTO 89
39
#ifndef IPV6
40
#define OSPF_VERSION 2
41
#define AllSPFRouters ipa_from_u32(0xe0000005)        /* 224.0.0.5 */
42
#define AllDRouters ipa_from_u32(0xe0000006)        /* 224.0.0.6 */
43
#define DEFAULTDES ipa_from_u32(0)
44
#else
45
#error OSPF for IPv6 is not implemented (mail to Feela <feela@network.cz>)
46
#endif
47

    
48

    
49
#define LSREFRESHTIME 1800        /* 30 minutes */
50
#define MINLSINTERVAL 5
51
#define MINLSARRIVAL 1
52
#define LSINFINITY 0xffffff
53

    
54
#define DEFAULT_OSPFTICK 1
55
#define DEFAULT_RFC1583 0        /* compatibility with rfc1583 */
56
#define DEFAULT_STUB_COST 1000
57

    
58

    
59
struct ospf_config
60
{
61
  struct proto_config c;
62
  unsigned tick;
63
  int rfc1583;
64
  list area_list;
65
};
66

    
67
struct nbma_node
68
{
69
  node n;
70
  ip_addr ip;
71
  int eligible;
72
};
73

    
74
struct area_net_config
75
{
76
  node n;
77
  struct prefix px;
78
  int hidden;
79
};
80

    
81
struct area_net
82
{
83
  struct fib_node fn;
84
  int hidden;
85
  int active;
86
  u32 metric;
87
};
88

    
89
struct ospf_area_config
90
{
91
  node n;
92
  u32 areaid;
93
  int stub;
94
  list patt_list;
95
  list vlink_list;
96
  list net_list;
97
};
98

    
99
struct obits
100
{
101
#ifdef _BIG_ENDIAN
102
  u8 unused2:2;
103
  u8 dc:1;
104
  u8 ea:1;
105
  u8 np:1;
106
  u8 mc:1;
107
  u8 e:1;
108
  u8 unused1:1;
109
#else
110
  u8 unused1:1;
111
  u8 e:1;
112
  u8 mc:1;
113
  u8 np:1;
114
  u8 ea:1;
115
  u8 dc:1;
116
  u8 unused2:2;
117
#endif
118
};
119

    
120
union options
121
{
122
  u8 byte;
123
  struct obits bit;
124
};
125

    
126

    
127
struct ospf_iface
128
{
129
  node n;
130
  struct iface *iface;                /* Nest's iface */
131
  struct ospf_area *oa;
132
  struct object_lock *lock;
133
  sock *hello_sk;                /* Hello socket */
134
  sock *dr_sk;                        /* For states DR or BACKUP */
135
  sock *ip_sk;                        /* IP socket (for DD ...) */
136
  list neigh_list;                /* List of neigbours */
137
  u32 cost;                        /* Cost of iface */
138
  u32 waitint;                        /* number of sec before changing state from wait */
139
  u32 rxmtint;                        /* number of seconds between LSA retransmissions */
140
  u32 pollint;                        /* Poll interval */
141
  u32 deadc;                        /* after "deadint" missing hellos is router dead */
142
  u32 vid;                        /* Id of peer of virtual link */
143
  ip_addr vip;                        /* IP of peer of virtual link */
144
  struct ospf_area *voa;        /* Area wich the vlink goes through */
145
  u16 inftransdelay;                /* The estimated number of seconds it takes to
146
                                   transmit a Link State Update Packet over this
147
                                   interface.  LSAs contained in the update */
148
  u16 autype;
149
  u16 helloint;                        /* number of seconds between hello sending */
150
  list *passwords;
151
  u32 csn;                      /* Crypt seq num. that will be sent net */
152
  ip_addr drip;                        /* Designated router */
153
  u32 drid;
154
  ip_addr bdrip;                /* Backup DR */
155
  u32 bdrid;
156
  u8 type;                        /* OSPF view of type */
157
#define OSPF_IT_BCAST 0
158
#define OSPF_IT_NBMA 1
159
#define OSPF_IT_PTP 2
160
#define OSPF_IT_VLINK 3
161
#define OSPF_IT_UNDEF 4
162
  u8 strictnbma;                /* Can I talk with unknown neighbors? */
163
  u8 stub;                        /* Inactive interface */
164
#define OSPF_I_OK 0                /* Everything OK */
165
#define OSPF_I_MC 1                /* I didn't open MC socket */
166
#define OSPF_I_IP 2                /* I didn't open IP socet */
167
  u8 state;                        /* Interface state machine */
168
#define OSPF_IS_DOWN 0                /* Not working */
169
#define OSPF_IS_LOOP 1                /* Should never happen */
170
#define OSPF_IS_WAITING 2        /* Waiting for Wait timer */
171
#define OSPF_IS_PTP 3                /* PTP operational */
172
#define OSPF_IS_DROTHER 4        /* I'm on BCAST or NBMA and I'm not DR */
173
#define OSPF_IS_BACKUP 5        /* I'm BDR */
174
#define OSPF_IS_DR 6                /* I'm DR */
175
  timer *wait_timer;                /* WAIT timer */
176
  timer *hello_timer;                /* HELLOINT timer */
177
  timer *poll_timer;                /* Poll Interval - for NBMA */
178
/* Default values for interface parameters */
179
#define COST_D 10
180
#define RXMTINT_D 5
181
#define INFTRANSDELAY_D 1
182
#define PRIORITY_D 1
183
#define HELLOINT_D 10
184
#define POLLINT_D 20
185
#define DEADC_D 4
186
#define WAIT_DMH 4                /* Value of Wait timer - not found it in RFC 
187
                                 * - using 4*HELLO
188
                                 */
189
  struct top_hash_entry *nlsa;        /* Originated net lsa */
190
  int orignet;                        /* Schedule network LSA origination */
191
  int fadj;                        /* Number of full adjacent neigh */
192
  list nbma_list;
193
  u8 priority;                        /* A router priority for DR election */
194
  u8 ioprob;
195
};
196

    
197
struct ospf_md5
198
{
199
  u16 zero;
200
  u8 keyid;
201
  u8 len;
202
  u32 csn;
203
};
204

    
205
union ospf_auth
206
{
207
  u8 password[8];
208
  struct ospf_md5 md5;
209
};
210

    
211
struct ospf_packet
212
{
213
  u8 version;
214
  u8 type;
215
#define HELLO_P 1                /* Hello */
216
#define DBDES_P 2                /* Database description */
217
#define LSREQ_P 3                /* Link state request */
218
#define LSUPD_P 4                /* Link state update */
219
#define LSACK_P 5                /* Link state acknowledgement */
220
  u16 length;
221
  u32 routerid;
222
  u32 areaid;
223
#define BACKBONE 0
224
  u16 checksum;
225
  u16 autype;
226
  union ospf_auth u;
227
};
228

    
229
struct ospf_hello_packet
230
{
231
  struct ospf_packet ospf_packet;
232
  ip_addr netmask;
233
  u16 helloint;
234
  u8 options;
235
  u8 priority;
236
  u32 deadint;
237
  ip_addr dr;
238
  ip_addr bdr;
239
};
240

    
241
struct immsb
242
{
243
#ifdef _BIG_ENDIAN
244
  u8 padding:5;
245
  u8 i:1;
246
  u8 m:1;
247
  u8 ms:1;
248
#else
249
  u8 ms:1;
250
  u8 m:1;
251
  u8 i:1;
252
  u8 padding:5;
253
#endif
254
};
255

    
256
union imms
257
{
258
  u8 byte;
259
  struct immsb bit;
260
};
261

    
262
struct ospf_dbdes_packet
263
{
264
  struct ospf_packet ospf_packet;
265
  u16 iface_mtu;
266
  u8 options;
267
  union imms imms;                /* I, M, MS bits */
268
#define DBDES_MS 1
269
#define DBDES_M 2
270
#define DBDES_I 4
271
  u32 ddseq;
272
};
273

    
274

    
275
struct ospf_lsa_header
276
{
277
  u16 age;                        /* LS Age */
278
#define LSA_MAXAGE 3600                /* 1 hour */
279
#define LSA_CHECKAGE 300        /* 5 minutes */
280
#define LSA_MAXAGEDIFF 900        /* 15 minutes */
281
  u8 options;
282
  u8 type;
283
  u32 id;
284
#define LSA_T_RT 1
285
#define LSA_T_NET 2
286
#define LSA_T_SUM_NET 3
287
#define LSA_T_SUM_RT 4
288
#define LSA_T_EXT 5
289
  u32 rt;                        /* Advertising router */
290
  s32 sn;                        /* LS Sequence number */
291
#define LSA_INITSEQNO 0x80000001
292
#define LSA_MAXSEQNO 0x7fffffff
293
  u16 checksum;
294
  u16 length;
295
};
296

    
297
struct vebb
298
{
299
#ifdef _BIG_ENDIAN
300
  u8 padding:5;
301
  u8 v:1;
302
  u8 e:1;
303
  u8 b:1;
304
#else
305
  u8 b:1;
306
  u8 e:1;
307
  u8 v:1;
308
  u8 padding:5;
309
#endif
310
};
311

    
312
union veb
313
{
314
  u8 byte;
315
  struct vebb bit;
316
};
317

    
318
struct ospf_lsa_rt
319
{
320
  union veb veb;
321
  u8 padding;
322
  u16 links;
323
};
324

    
325
struct ospf_lsa_rt_link
326
{
327
  u32 id;
328
  u32 data;
329
  u8 type;
330
#define LSART_PTP 1
331
#define LSART_NET 2
332
#define LSART_STUB 3
333
#define LSART_VLNK 4
334
  u8 notos;
335
  u16 metric;
336
};
337

    
338
struct ospf_lsa_rt_link_tos
339
{                                /* Actually we ignore TOS. This is useless */
340
  u8 tos;
341
  u8 padding;
342
  u16 metric;
343
};
344

    
345
struct ospf_lsa_net
346
{
347
  ip_addr netmask;
348
};
349

    
350
struct ospf_lsa_sum
351
{
352
  ip_addr netmask;
353
};
354

    
355

    
356
struct ospf_lsa_ext
357
{
358
  ip_addr netmask;
359
};
360

    
361
struct ospf_lsa_ext_etos 
362
{
363
#ifdef _BIG_ENDIAN
364
  u8 ebit:1;
365
  u8 tos:7;
366
  u8 padding1;
367
  u16 padding2;
368
#else
369
  u16 padding2;
370
  u8 padding1;
371
  u8 tos:7;
372
  u8 ebit:1;
373
#endif
374
};
375

    
376
#define METRIC_MASK 0x00FFFFFF
377
struct ospf_lsa_sum_tos 
378
{
379
#ifdef _BIG_ENDIAN
380
  u8 tos;
381
  u8 padding1;
382
  u16 padding2;
383
#else
384
  u16 padding2;
385
  u8 padding1;
386
  u8 tos;
387
#endif
388
};
389

    
390
union ospf_lsa_sum_tm
391
{
392
  struct ospf_lsa_sum_tos tos;
393
  u32 metric;
394
};
395

    
396
union ospf_lsa_ext_etm
397
{
398
  struct ospf_lsa_ext_etos etos;
399
  u32 metric;
400
};
401

    
402
struct ospf_lsa_ext_tos
403
{
404
  union ospf_lsa_ext_etm etm;
405
  ip_addr fwaddr;
406
  u32 tag;
407
};
408

    
409
struct ospf_lsreq_packet
410
{
411
  struct ospf_packet ospf_packet;
412
};
413

    
414
struct ospf_lsreq_header
415
{
416
  u16 padd1;
417
  u8 padd2;
418
  u8 type;
419
  u32 id;
420
  u32 rt;                        /* Advertising router */
421
};
422

    
423
struct l_lsr_head
424
{
425
  node n;
426
  struct ospf_lsreq_header lsh;
427
};
428

    
429
struct ospf_lsupd_packet
430
{
431
  struct ospf_packet ospf_packet;
432
  u32 lsano;                        /* Number of LSA's */
433
};
434

    
435
struct ospf_lsack_packet
436
{
437
  struct ospf_packet ospf_packet;
438
};
439

    
440

    
441
struct ospf_neighbor
442
{
443
  node n;
444
  pool *pool;
445
  struct ospf_iface *ifa;
446
  u8 state;
447
#define NEIGHBOR_DOWN 0
448
#define NEIGHBOR_ATTEMPT 1
449
#define NEIGHBOR_INIT 2
450
#define NEIGHBOR_2WAY 3
451
#define NEIGHBOR_EXSTART 4
452
#define NEIGHBOR_EXCHANGE 5
453
#define NEIGHBOR_LOADING 6
454
#define NEIGHBOR_FULL 7
455
  timer *inactim;                /* Inactivity timer */
456
  union imms imms;                /* I, M, Master/slave received */
457
  u32 dds;                        /* DD Sequence number being sent */
458
  u32 ddr;                        /* last Dat Des packet received */
459
  union imms myimms;                /* I, M Master/slave */
460
  u32 rid;                        /* Router ID */
461
  ip_addr ip;                        /* IP of it's interface */
462
  u8 priority;                        /* Priority */
463
  u8 options;                        /* Options received */
464
  ip_addr dr;                        /* Neigbour's idea of DR */
465
  ip_addr bdr;                        /* Neigbour's idea of BDR */
466
  u8 adj;                        /* built adjacency? */
467
  siterator dbsi;                /* Database summary list iterator */
468
  slist lsrql;                        /* Link state request */
469
  struct top_graph *lsrqh;        /* LSA graph */
470
  siterator lsrqi;
471
  slist lsrtl;                        /* Link state retransmission list */
472
  siterator lsrti;
473
  struct top_graph *lsrth;
474
  void *ldbdes;                        /* Last database description packet */
475
  timer *rxmt_timer;                /* RXMT timer */
476
  list ackl[2];
477
#define ACKL_DIRECT 0
478
#define ACKL_DELAY 1
479
  timer *ackd_timer;                /* Delayed ack timer */
480
  u32 csn;                      /* Last received crypt seq number (for MD5) */
481
};
482

    
483
/* Definitions for interface state machine */
484
#define ISM_UP 0                /* Interface Up */
485
#define ISM_WAITF 1                /* Wait timer fired */
486
#define ISM_BACKS 2                /* Backup seen */
487
#define ISM_NEICH 3                /* Neighbor change */
488
#define ISM_LOOP 4                /* Loop indicated */
489
#define ISM_UNLOOP 5                /* Unloop indicated */
490
#define ISM_DOWN 6                /* Interface down */
491

    
492
/* Definitions for neighbor state machine */
493
#define INM_HELLOREC 0                /* Hello Received */
494
#define INM_START 1                /* Neighbor start - for NBMA */
495
#define INM_2WAYREC 2                /* 2-Way received */
496
#define INM_NEGDONE 3                /* Negotiation done */
497
#define INM_EXDONE 4                /* Exchange done */
498
#define INM_BADLSREQ 5                /* Bad LS Request */
499
#define INM_LOADDONE 6                /* Load done */
500
#define INM_ADJOK 7                /* AdjOK? */
501
#define INM_SEQMIS 8                /* Sequence number mismatch */
502
#define INM_1WAYREC 9                /* 1-Way */
503
#define INM_KILLNBR 10                /* Kill Neighbor */
504
#define INM_INACTTIM 11                /* Inactivity timer */
505
#define INM_LLDOWN 12                /* Line down */
506

    
507
struct ospf_area
508
{
509
  node n;
510
  u32 areaid;
511
  int origrt;                        /* Rt lsa origination scheduled? */
512
  struct top_hash_entry *rt;        /* My own router LSA */
513
  list cand;                        /* List of candidates for RT calc. */
514
  struct fib net_fib;                /* Networks to advertise or not */
515
  int stub;
516
  int trcap;                        /* Transit capability? */
517
  struct proto_ospf *po;
518
  struct fib rtr;                /* Routing tables for routers */
519
  union options opt;            /* RFC2328 - A.2 */
520
};
521

    
522
struct proto_ospf
523
{
524
  struct proto proto;
525
  timer *disp_timer;                /* OSPF proto dispatcher */
526
  unsigned tick;
527
  struct top_graph *gr;                /* LSA graph */
528
  slist lsal;                        /* List of all LSA's */
529
  int calcrt;                        /* Routing table calculation scheduled? */
530
  int cleanup;                  /* Should I cleanup after RT calculation? */
531
  list iface_list;                /* Interfaces we really use */
532
  list area_list;
533
  int areano;                        /* Number of area I belong to */
534
  struct fib rtf;                /* Routing table */
535
  int rfc1583;                        /* RFC1583 compatibility */
536
  int ebit;                        /* Did I originate any ext lsa? */
537
  struct ospf_area *backbone;        /* If exists */
538
};
539

    
540
struct ospf_iface_patt
541
{
542
  struct iface_patt i;
543
  u32 cost;
544
  u32 helloint;
545
  u32 rxmtint;
546
  u32 pollint;
547
  u32 inftransdelay;
548
  u32 priority;
549
  u32 waitint;
550
  u32 deadc;
551
  u32 type;
552
  u32 autype;
553
  u32 strictnbma;
554
  u32 stub;
555
  u32 vid;
556
#define OSPF_AUTH_NONE 0
557
#define OSPF_AUTH_SIMPLE 1
558
#define OSPF_AUTH_CRYPT 2
559
#define OSPF_AUTH_CRYPT_SIZE 16
560
  list *passwords;
561
  list nbma_list;
562
};
563

    
564
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
565
                        struct linpool *pool);
566
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
567
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
568
void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,
569
                    ea_list * attrs);
570
void schedule_rt_lsa(struct ospf_area *oa);
571
void schedule_rtcalc(struct proto_ospf *po);
572
void schedule_net_lsa(struct ospf_iface *ifa);
573
void ospf_sh_neigh(struct proto *p, char *iff);
574
void ospf_sh(struct proto *p);
575
void ospf_sh_iface(struct proto *p, char *iff);
576

    
577
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
578
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
579
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
580

    
581
#include "proto/ospf/rt.h"
582
#include "proto/ospf/hello.h"
583
#include "proto/ospf/packet.h"
584
#include "proto/ospf/iface.h"
585
#include "proto/ospf/neighbor.h"
586
#include "proto/ospf/topology.h"
587
#include "proto/ospf/dbdes.h"
588
#include "proto/ospf/lsreq.h"
589
#include "proto/ospf/lsupd.h"
590
#include "proto/ospf/lsack.h"
591
#include "proto/ospf/lsalib.h"
592

    
593
#endif /* _BIRD_OSPF_H_ */