Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ 62eee823

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_AREATICK 1
56
#define DEFAULT_RFC1583 1        /* compatibility with rfc1583 */
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
};
87

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

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

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

    
125

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

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

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

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

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

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

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

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

    
275

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

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

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

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

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

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

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

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

    
356

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

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

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

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

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

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

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

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

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

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

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

    
441

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

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

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

    
508
struct ospf_area
509
{
510
  node n;
511
  u32 areaid;
512
  timer *disp_timer;                /* Area's dispatcher hear beat */
513
  int origrt;                        /* Rt lsa origination scheduled? */
514
  struct top_graph *gr;                /* LSA graph */
515
  slist lsal;                        /* List of all LSA's */
516
  struct top_hash_entry *rt;        /* My own router LSA */
517
  list cand;                        /* List of candidates for RT calc. */
518
  struct fib net_fib;                /* Networks to advertise or not */
519
  int stub;
520
  int trcap;                        /* Transit capability? */
521
  struct proto_ospf *po;
522
  unsigned tick;
523
  struct fib rtr;                /* Routing tables for routers */
524
  union options opt;            /* RFC2328 - A.2 */
525
};
526

    
527
struct proto_ospf
528
{
529
  struct proto proto;
530
  timer *disp_timer;                /* OSPF proto dispatcher */
531
  unsigned tick;
532
  int calcrt;                        /* Routing table calculation scheduled? */
533
  list iface_list;                /* Interfaces we really use */
534
  list area_list;
535
  int areano;                        /* Number of area I belong to */
536
  struct fib rtf;                /* Routing table */
537
  int rfc1583;                        /* RFC1583 compatibility */
538
  int ebit;                        /* Did I originate any ext lsa? */
539
  struct ospf_area *backbone;        /* If exists */
540
};
541

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

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

    
579
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
580
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
581
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
582

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

    
595
#endif /* _BIRD_OSPF_H_ */