Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ 8df02847

History | View | Annotate | Download (20.6 KB)

1
/*
2
 *        BIRD -- OSPF
3
 *
4
 *        (c) 1999--2005 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
#define OSPF_MAX_PKT_SIZE 65535
14
/*
15
 * RFC 2328 says, maximum packet size is 65535 (IP packet size
16
 * limit). Really a bit less for OSPF, because this contains also IP
17
 * header. This could be too much for small systems, so I normally
18
 * allocate 2*mtu (i found one cisco sending packets mtu+16). OSPF
19
 * packets are almost always sent small enough to not be fragmented.
20
 */
21

    
22
#ifdef LOCAL_DEBUG
23
#define OSPF_FORCE_DEBUG 1
24
#else
25
#define OSPF_FORCE_DEBUG 0
26
#endif
27
#define OSPF_TRACE(flags, msg, args...) do { if ((p->debug & flags) || OSPF_FORCE_DEBUG) \
28
  log(L_TRACE "%s: " msg, p->name , ## args ); } while(0)
29

    
30
#define OSPF_PACKET(dumpfn, buffer, msg, args...) \
31
do { if ((p->debug & D_PACKETS) || OSPF_FORCE_DEBUG) \
32
{ log(L_TRACE "%s: " msg, p->name, ## args ); dumpfn(p, buffer); } } while(0)
33

    
34

    
35
#include "nest/bird.h"
36

    
37
#include "lib/checksum.h"
38
#include "lib/ip.h"
39
#include "lib/lists.h"
40
#include "lib/slists.h"
41
#include "lib/socket.h"
42
#include "lib/timer.h"
43
#include "lib/resource.h"
44
#include "nest/protocol.h"
45
#include "nest/iface.h"
46
#include "nest/route.h"
47
#include "nest/cli.h"
48
#include "nest/locks.h"
49
#include "conf/conf.h"
50
#include "lib/string.h"
51

    
52
#define OSPF_PROTO 89
53

    
54
#ifndef IPV6
55
#define OSPFv2 1
56
#define OSPF_VERSION 2
57
#define OSPF_VLINK_MTU 576                        /* RFC 2328 A.1 */
58
#define AllSPFRouters ipa_from_u32(0xe0000005)        /* 224.0.0.5 */
59
#define AllDRouters ipa_from_u32(0xe0000006)        /* 224.0.0.6 */
60
#else
61
#define OSPFv3 1
62
#define OSPF_VERSION 3
63
#define OSPF_VLINK_MTU 1280                        /* RFC 5340 A.1 */
64
#define AllSPFRouters _MI(0xFF020000, 0, 0, 5)        /* FF02::5 */
65
#define AllDRouters   _MI(0xFF020000, 0, 0, 6)        /* FF02::6 */
66
#endif
67

    
68

    
69
#define LSREFRESHTIME 1800        /* 30 minutes */
70
#define MINLSINTERVAL 5
71
#define MINLSARRIVAL 1
72
#define LSINFINITY 0xffffff
73

    
74
#define DEFAULT_OSPFTICK 1
75
#define DEFAULT_RFC1583 0        /* compatibility with rfc1583 */
76
#define DEFAULT_STUB_COST 1000
77
#define DEFAULT_ECMP_LIMIT 16
78
#define DEFAULT_TRANSINT 40
79

    
80

    
81
struct ospf_config
82
{
83
  struct proto_config c;
84
  unsigned tick;
85
  byte rfc1583;
86
  byte abr;
87
  int ecmp;
88
  list area_list;                /* list of struct ospf_area_config */
89
  list vlink_list;                /* list of struct ospf_iface_patt */
90
};
91

    
92
struct nbma_node
93
{
94
  node n;
95
  ip_addr ip;
96
  byte eligible;
97
  byte found; 
98
};
99

    
100
struct area_net_config
101
{
102
  node n;
103
  struct prefix px;
104
  int hidden;
105
  u32 tag;
106
};
107

    
108
struct area_net
109
{
110
  struct fib_node fn;
111
  int hidden;
112
  int active;
113
  u32 metric;
114
  u32 tag;
115
};
116

    
117
struct ospf_stubnet_config
118
{
119
  node n;
120
  struct prefix px;
121
  int hidden, summary;
122
  u32 cost;
123
};
124

    
125
struct ospf_area_config
126
{
127
  node n;
128
  u32 areaid;
129
  u32 default_cost;                /* Cost of default route for stub areas */
130
  u8 type;                        /* Area type (standard, stub, NSSA), represented
131
                                   by option flags (OPT_E, OPT_N) */
132
  u8 summary;                        /* Import summaries to this stub/NSSA area, valid for ABR */
133
  u8 default_nssa;                /* Generate default NSSA route for NSSA+summary area */
134
  u8 translator;                /* Translator role, for NSSA ABR */
135
  u32 transint;                        /* Translator stability interval */
136
  list patt_list;
137
  list net_list;                      /* List of aggregate networks for that area */
138
  list enet_list;                      /* List of aggregate external (NSSA) networks */
139
  list stubnet_list;                /* List of stub networks added to Router LSA */
140
};
141

    
142

    
143
/* Option flags */
144

    
145
#define OPT_E        0x02
146
#define OPT_N        0x08
147
#define OPT_DC        0x20
148

    
149
#ifdef OSPFv2
150
#define OPT_P        0x08                /* flags P and N share position, see NSSA RFC */
151
#define OPT_EA        0x10
152

    
153
/* VEB flags are are stored independently in 'u16 options' */
154
#define OPT_RT_B  (0x01 << 8)
155
#define OPT_RT_E  (0x02 << 8)
156
#define OPT_RT_V  (0x04 << 8)
157
#define OPT_RT_NT (0x10 << 8)
158
#endif
159

    
160
#ifdef OSPFv3
161
#define OPT_V6        0x01
162
#define OPT_R        0x10
163

    
164
/* VEB flags are are stored together with options in 'u32 options' */
165
#define OPT_RT_B  (0x01 << 24)
166
#define OPT_RT_E  (0x02 << 24)
167
#define OPT_RT_V  (0x04 << 24)
168
#define OPT_RT_NT (0x10 << 24)
169

    
170
#define OPT_PX_NU 0x01
171
#define OPT_PX_LA 0x02
172
#define OPT_PX_P  0x08
173
#define OPT_PX_DN 0x10
174
#endif
175

    
176

    
177
struct ospf_iface
178
{
179
  node n;
180
  struct iface *iface;                /* Nest's iface, non-NULL (unless type OSPF_IT_VLINK) */
181
  struct ifa *addr;                /* IP prefix associated with that OSPF iface */
182
  struct ospf_area *oa;
183
  struct ospf_iface_patt *cf;
184
  pool *pool;
185
  sock *sk;                        /* IP socket (for DD ...) */
186
  list neigh_list;                /* List of neigbours */
187
  u32 cost;                        /* Cost of iface */
188
  u32 waitint;                        /* number of sec before changing state from wait */
189
  u32 rxmtint;                        /* number of seconds between LSA retransmissions */
190
  u32 pollint;                        /* Poll interval */
191
  u32 deadint;                        /* after "deadint" missing hellos is router dead */
192
  u32 iface_id;                        /* Interface ID (iface->index or new value for vlinks) */
193
  u32 vid;                        /* ID of peer of virtual link */
194
  ip_addr vip;                        /* IP of peer of virtual link */
195
  struct ospf_iface *vifa;        /* OSPF iface which the vlink goes through */
196
  struct ospf_area *voa;        /* OSPF area which the vlink goes through */
197
  u16 inftransdelay;                /* The estimated number of seconds it takes to
198
                                   transmit a Link State Update Packet over this
199
                                   interface.  LSAs contained in the update */
200
  u16 helloint;                        /* number of seconds between hello sending */
201

    
202
#ifdef OSPFv2
203
  list *passwords;
204
  u16 autype;
205
  u32 csn;                      /* Last used crypt seq number */
206
  bird_clock_t csn_use;         /* Last time when packet with that CSN was sent */
207
#endif
208

    
209
  ip_addr all_routers;                /*  */
210
  ip_addr drip;                        /* Designated router */
211
  ip_addr bdrip;                /* Backup DR */
212
  u32 drid;
213
  u32 bdrid;
214
  s16 rt_pos_beg;                /* Position of iface in Router-LSA, begin, inclusive */
215
  s16 rt_pos_end;                /* Position of iface in Router-LSA, end, exclusive */
216

    
217
#ifdef OSPFv3
218
  s16 px_pos_beg;                /* Position of iface in Rt Prefix-LSA, begin, inclusive */
219
  s16 px_pos_end;                /* Position of iface in Rt Prefix-LSA, end, exclusive */
220

    
221
  u32 dr_iface_id;                /* if drid is valid, this is iface_id of DR (for connecting network) */
222
  u8 instance_id;                /* Used to differentiate between more OSPF
223
                                   instances on one interface */
224
#endif
225

    
226
  u8 type;                        /* OSPF view of type */
227
#define OSPF_IT_BCAST 0
228
#define OSPF_IT_NBMA 1
229
#define OSPF_IT_PTP 2
230
#define OSPF_IT_PTMP 3
231
#define OSPF_IT_VLINK 4
232
#define OSPF_IT_UNDEF 5
233
  u8 strictnbma;                /* Can I talk with unknown neighbors? */
234
  u8 stub;                        /* Inactive interface */
235
  u8 state;                        /* Interface state machine */
236
#define OSPF_IS_DOWN 0                /* Not working */
237
#define OSPF_IS_LOOP 1                /* Iface with no link */
238
#define OSPF_IS_WAITING 2        /* Waiting for Wait timer */
239
#define OSPF_IS_PTP 3                /* PTP operational */
240
#define OSPF_IS_DROTHER 4        /* I'm on BCAST or NBMA and I'm not DR */
241
#define OSPF_IS_BACKUP 5        /* I'm BDR */
242
#define OSPF_IS_DR 6                /* I'm DR */
243
  timer *wait_timer;                /* WAIT timer */
244
  timer *hello_timer;                /* HELLOINT timer */
245
  timer *poll_timer;                /* Poll Interval - for NBMA */
246
/* Default values for interface parameters */
247
#define COST_D 10
248
#define RXMTINT_D 5
249
#define INFTRANSDELAY_D 1
250
#define PRIORITY_D 1
251
#define HELLOINT_D 10
252
#define POLLINT_D 20
253
#define DEADC_D 4
254
#define WAIT_DMH 4                
255
  /* Value of Wait timer - not found it in RFC * - using 4*HELLO */
256

    
257
  struct top_hash_entry *net_lsa;        /* Originated network LSA */
258
  int orignet;                                /* Schedule network LSA origination */
259
#ifdef OSPFv3
260
  int origlink;                                /* Schedule link LSA origination */
261
  struct top_hash_entry *link_lsa;        /* Originated link LSA */
262
  struct top_hash_entry *pxn_lsa;        /* Originated prefix LSA */
263
#endif
264
  int fadj;                                /* Number of full adjacent neigh */
265
  list nbma_list;
266
  u8 priority;                        /* A router priority for DR election */
267
  u8 ioprob;
268
#define OSPF_I_OK 0                /* Everything OK */
269
#define OSPF_I_SK 1                /* Socket open failed */
270
#define OSPF_I_LL 2                /* Missing link-local address (OSPFv3) */
271
  u8 sk_dr;                         /* Socket is a member of DRouters group */
272
  u8 marked;                        /* Used in OSPF reconfigure */
273
  u16 rxbuf;                        /* Buffer size */
274
  u8 check_link;                /* Whether iface link change is used */
275
  u8 ecmp_weight;                /* Weight used for ECMP */
276
  u8 ptp_netmask;                /* Send real netmask for P2P */
277
};
278

    
279
struct ospf_md5
280
{
281
  u16 zero;
282
  u8 keyid;
283
  u8 len;
284
  u32 csn;
285
};
286

    
287
union ospf_auth
288
{
289
  u8 password[8];
290
  struct ospf_md5 md5;
291
};
292

    
293

    
294
/* Packet types */
295
#define HELLO_P 1                /* Hello */
296
#define DBDES_P 2                /* Database description */
297
#define LSREQ_P 3                /* Link state request */
298
#define LSUPD_P 4                /* Link state update */
299
#define LSACK_P 5                /* Link state acknowledgement */
300

    
301
/* Area IDs */
302
#define BACKBONE 0
303

    
304

    
305
struct immsb
306
{
307
#ifdef CPU_BIG_ENDIAN
308
  u8 padding:5;
309
  u8 i:1;
310
  u8 m:1;
311
  u8 ms:1;
312
#else
313
  u8 ms:1;
314
  u8 m:1;
315
  u8 i:1;
316
  u8 padding:5;
317
#endif
318
};
319

    
320
union imms
321
{
322
  u8 byte;
323
  struct immsb bit;
324
};
325
#define DBDES_MS 1
326
#define DBDES_M 2
327
#define DBDES_I 4
328

    
329

    
330
#ifdef OSPFv2
331

    
332
struct ospf_packet
333
{
334
  u8 version;
335
  u8 type;
336
  u16 length;
337
  u32 routerid;
338
  u32 areaid;
339
  u16 checksum;
340
  u16 autype;
341
  union ospf_auth u;
342
};
343

    
344

    
345
#else /* OSPFv3 packet descriptions */
346

    
347
struct ospf_packet
348
{
349
  u8 version;
350
  u8 type;
351
  u16 length;
352
  u32 routerid;
353
  u32 areaid;
354
  u16 checksum;
355
  u8 instance_id;
356
  u8 zero;
357
};
358

    
359

    
360
#endif
361

    
362

    
363

    
364

    
365
struct ospf_lsa_header
366
{
367
  u16 age;                        /* LS Age */
368
#define LSA_MAXAGE 3600                /* 1 hour */
369
#define LSA_CHECKAGE 300        /* 5 minutes */
370
#define LSA_MAXAGEDIFF 900        /* 15 minutes */
371

    
372
#ifdef OSPFv2
373
  u8 options;
374
  u8 type;
375

    
376
#define LSA_T_RT        1
377
#define LSA_T_NET        2
378
#define LSA_T_SUM_NET        3
379
#define LSA_T_SUM_RT        4
380
#define LSA_T_EXT        5
381
#define LSA_T_NSSA        7
382

    
383
#define LSA_SCOPE_AREA        0x2000
384
#define LSA_SCOPE_AS        0x4000
385

    
386
#define LSA_SCOPE(lsa)        (((lsa)->type == LSA_T_EXT) ? LSA_SCOPE_AS : LSA_SCOPE_AREA)
387

    
388
#else /* OSPFv3 */
389
  u16 type;
390

    
391
#define LSA_T_RT        0x2001
392
#define LSA_T_NET        0x2002
393
#define LSA_T_SUM_NET        0x2003
394
#define LSA_T_SUM_RT        0x2004
395
#define LSA_T_EXT        0x4005
396
#define LSA_T_NSSA        0x2007
397
#define LSA_T_LINK        0x0008
398
#define LSA_T_PREFIX        0x2009
399

    
400
#define LSA_UBIT        0x8000
401

    
402
#define LSA_SCOPE_LINK        0x0000
403
#define LSA_SCOPE_AREA        0x2000
404
#define LSA_SCOPE_AS        0x4000
405
#define LSA_SCOPE_RES        0x6000
406
#define LSA_SCOPE_MASK        0x6000
407

    
408
#define LSA_SCOPE(lsa)        ((lsa)->type & LSA_SCOPE_MASK)
409
#endif
410

    
411
  u32 id;
412
  u32 rt;                        /* Advertising router */
413
  s32 sn;                        /* LS Sequence number */
414
#define LSA_INITSEQNO ((s32) 0x80000001)
415
#define LSA_MAXSEQNO ((s32) 0x7fffffff)
416
  u16 checksum;
417
  u16 length;
418
};
419

    
420

    
421
#define LSART_PTP 1
422
#define LSART_NET 2
423
#define LSART_STUB 3
424
#define LSART_VLNK 4
425

    
426

    
427
#ifdef OSPFv2
428

    
429
struct ospf_lsa_rt
430
{
431
#ifdef CPU_BIG_ENDIAN
432
  u16 options;        /* VEB flags only */
433
  u16 links;
434
#else
435
  u16 links;
436
  u16 options;        /* VEB flags only */
437
#endif
438
};
439

    
440
struct ospf_lsa_rt_link
441
{
442
  u32 id;
443
  u32 data;
444
#ifdef CPU_BIG_ENDIAN
445
  u8 type;
446
  u8 padding;
447
  u16 metric;
448
#else
449
  u16 metric;
450
  u8 padding;
451
  u8 type;
452
#endif
453
};
454

    
455
struct ospf_lsa_net
456
{
457
  ip_addr netmask;
458
  u32 routers[];
459
};
460

    
461
struct ospf_lsa_sum
462
{
463
  ip_addr netmask;
464
  u32 metric;
465
};
466

    
467
struct ospf_lsa_ext
468
{
469
  ip_addr netmask;
470
  u32 metric;
471
  ip_addr fwaddr;
472
  u32 tag;
473
};
474

    
475
#define LSA_SUM_TOS  0xFF000000
476
#define LSA_EXT_TOS  0x7F000000
477
#define LSA_EXT_EBIT 0x80000000
478

    
479
/* Endianity swap for lsa->type */
480
#define ntoht(x) x
481
#define htont(x) x
482

    
483

    
484
#else  /* OSPFv3 */
485

    
486
struct ospf_lsa_rt
487
{
488
  u32 options;
489
};
490

    
491
struct ospf_lsa_rt_link
492
{
493
#ifdef CPU_BIG_ENDIAN
494
  u8 type;
495
  u8 padding;
496
  u16 metric;
497
#else
498
  u16 metric;
499
  u8 padding;
500
  u8 type;
501
#endif
502
  u32 lif;        /* Local interface ID */
503
  u32 nif;        /* Neighbor interface ID */
504
  u32 id;        /* Neighbor router ID */
505
};
506

    
507
struct ospf_lsa_net
508
{
509
  u32 options;
510
  u32 routers[];
511
};
512

    
513
struct ospf_lsa_sum_net
514
{
515
  u32 metric;
516
  u32 prefix[];
517
};
518

    
519
struct ospf_lsa_sum_rt
520
{
521
  u32 options;
522
  u32 metric;
523
  u32 drid;
524
};
525

    
526
struct ospf_lsa_ext
527
{
528
  u32 metric;
529
  u32 rest[];
530
};
531

    
532
struct ospf_lsa_link
533
{
534
  u32 options;
535
  ip_addr lladdr;
536
  u32 pxcount;
537
  u32 rest[];
538
};
539

    
540
struct ospf_lsa_prefix
541
{
542
#ifdef CPU_BIG_ENDIAN
543
  u16 pxcount;
544
  u16 ref_type;
545
#else
546
  u16 ref_type;
547
  u16 pxcount;
548
#endif
549
  u32 ref_id;
550
  u32 ref_rt;
551
  u32 rest[];
552
};
553

    
554
#define LSA_EXT_EBIT 0x4000000
555
#define LSA_EXT_FBIT 0x2000000
556
#define LSA_EXT_TBIT 0x1000000
557

    
558
/* Endianity swap for lsa->type */
559
#define ntoht(x) ntohs(x)
560
#define htont(x) htons(x)
561

    
562
#endif
563

    
564
#define METRIC_MASK  0x00FFFFFF
565
#define OPTIONS_MASK 0x00FFFFFF
566

    
567
static inline unsigned
568
lsa_rt_count(struct ospf_lsa_header *lsa)
569
{
570
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_rt))
571
    / sizeof(struct ospf_lsa_rt_link);
572
}
573

    
574
static inline unsigned
575
lsa_net_count(struct ospf_lsa_header *lsa)
576
{
577
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net))
578
    / sizeof(u32);
579
}
580

    
581

    
582
#ifdef OSPFv3
583

    
584
#define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
585
#define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
586

    
587
static inline u32 *
588
lsa_get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest)
589
{
590
  u8 pxl = (*buf >> 24);
591
  *pxopts = (*buf >> 16);
592
  *rest = *buf;
593
  *pxlen = pxl;
594
  buf++;
595

    
596
  *addr = IPA_NONE;
597

    
598
  if (pxl > 0)
599
    _I0(*addr) = *buf++;
600
  if (pxl > 32)
601
    _I1(*addr) = *buf++;
602
  if (pxl > 64)
603
    _I2(*addr) = *buf++;
604
  if (pxl > 96)
605
    _I3(*addr) = *buf++;
606

    
607
  /* Clean up remaining bits */
608
  if (pxl < 128)
609
    addr->addr[pxl / 32] &= u32_mkmask(pxl % 32);
610

    
611
  return buf;
612
}
613

    
614
static inline u32 *
615
lsa_get_ipv6_addr(u32 *buf, ip_addr *addr)
616
{
617
  *addr = *(ip_addr *) buf;
618
  return buf + 4;
619
}
620

    
621
static inline u32 *
622
put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh)
623
{
624
  *buf++ = ((pxlen << 24) | (pxopts << 16) | lh);
625

    
626
  if (pxlen > 0)
627
    *buf++ = _I0(addr);
628
  if (pxlen > 32)
629
    *buf++ = _I1(addr);
630
  if (pxlen > 64)
631
    *buf++ = _I2(addr);
632
  if (pxlen > 96)
633
    *buf++ = _I3(addr);
634
  return buf;
635
}
636

    
637
static inline u32 *
638
put_ipv6_addr(u32 *buf, ip_addr addr)
639
{
640
  *(ip_addr *) buf = addr;
641
  return buf + 4;
642
}
643

    
644
#endif
645

    
646

    
647

    
648
struct ospf_lsreq_header
649
{
650
  u32 type;
651
  u32 id;
652
  u32 rt;                        /* Advertising router */
653
};
654

    
655
struct l_lsr_head
656
{
657
  node n;
658
  struct ospf_lsreq_header lsh;
659
};
660

    
661

    
662
struct ospf_neighbor
663
{
664
  node n;
665
  pool *pool;
666
  struct ospf_iface *ifa;
667
  u8 state;
668
#define NEIGHBOR_DOWN 0
669
#define NEIGHBOR_ATTEMPT 1
670
#define NEIGHBOR_INIT 2
671
#define NEIGHBOR_2WAY 3
672
#define NEIGHBOR_EXSTART 4
673
#define NEIGHBOR_EXCHANGE 5
674
#define NEIGHBOR_LOADING 6
675
#define NEIGHBOR_FULL 7
676
  timer *inactim;                /* Inactivity timer */
677
  union imms imms;                /* I, M, Master/slave received */
678
  u32 dds;                        /* DD Sequence number being sent */
679
  u32 ddr;                        /* last Dat Des packet received */
680
  union imms myimms;                /* I, M Master/slave */
681
  u32 rid;                        /* Router ID */
682
  ip_addr ip;                        /* IP of it's interface */
683
  u8 priority;                        /* Priority */
684
  u8 adj;                        /* built adjacency? */
685
  u32 options;                        /* Options received */
686

    
687
  /* dr and bdr store IP address in OSPFv2 and router ID in OSPFv3,
688
     we use the same type to simplify handling */
689
  u32 dr;                        /* Neigbour's idea of DR */
690
  u32 bdr;                        /* Neigbour's idea of BDR */
691

    
692
#ifdef OSPFv3
693
  u32 iface_id;                        /* ID of Neighbour's iface connected to common network */
694
#endif
695

    
696
  siterator dbsi;                /* Database summary list iterator */
697
  slist lsrql;                        /* Link state request */
698
  struct top_graph *lsrqh;        /* LSA graph */
699
  siterator lsrqi;
700
  slist lsrtl;                        /* Link state retransmission list */
701
  siterator lsrti;
702
  struct top_graph *lsrth;
703
  void *ldbdes;                        /* Last database description packet */
704
  timer *rxmt_timer;                /* RXMT timer */
705
  list ackl[2];
706
#define ACKL_DIRECT 0
707
#define ACKL_DELAY 1
708
  timer *ackd_timer;                /* Delayed ack timer */
709
  u32 csn;                      /* Last received crypt seq number (for MD5) */
710
};
711

    
712
/* Definitions for interface state machine */
713
#define ISM_UP 0                /* Interface Up */
714
#define ISM_WAITF 1                /* Wait timer fired */
715
#define ISM_BACKS 2                /* Backup seen */
716
#define ISM_NEICH 3                /* Neighbor change */
717
#define ISM_LOOP 4                /* Link down */
718
#define ISM_UNLOOP 5                /* Link up */
719
#define ISM_DOWN 6                /* Interface down */
720

    
721
/* Definitions for neighbor state machine */
722
#define INM_HELLOREC 0                /* Hello Received */
723
#define INM_START 1                /* Neighbor start - for NBMA */
724
#define INM_2WAYREC 2                /* 2-Way received */
725
#define INM_NEGDONE 3                /* Negotiation done */
726
#define INM_EXDONE 4                /* Exchange done */
727
#define INM_BADLSREQ 5                /* Bad LS Request */
728
#define INM_LOADDONE 6                /* Load done */
729
#define INM_ADJOK 7                /* AdjOK? */
730
#define INM_SEQMIS 8                /* Sequence number mismatch */
731
#define INM_1WAYREC 9                /* 1-Way */
732
#define INM_KILLNBR 10                /* Kill Neighbor */
733
#define INM_INACTTIM 11                /* Inactivity timer */
734
#define INM_LLDOWN 12                /* Line down */
735

    
736
struct ospf_area
737
{
738
  node n;
739
  u32 areaid;
740
  struct ospf_area_config *ac;        /* Related area config */
741
  struct top_hash_entry *rt;        /* My own router LSA */
742
  struct top_hash_entry *pxr_lsa; /* Originated prefix LSA */
743
  list cand;                        /* List of candidates for RT calc. */
744
  struct fib net_fib;                /* Networks to advertise or not */
745
  struct fib enet_fib;                /* External networks for NSSAs */
746
  u32 options;                        /* Optional features */
747
  byte origrt;                        /* Rt lsa origination scheduled? */
748
  byte trcap;                        /* Transit capability? */
749
  byte marked;                        /* Used in OSPF reconfigure */
750
  byte translate;                /* Translator state (TRANS_*), for NSSA ABR  */
751
  timer *translator_timer;        /* For NSSA translator switch */
752
  struct proto_ospf *po;
753
  struct fib rtr;                /* Routing tables for routers */
754
};
755

    
756
#define TRANS_OFF        0
757
#define TRANS_ON        1
758
#define TRANS_WAIT        2        /* Waiting before the end of translation */
759

    
760
struct proto_ospf
761
{
762
  struct proto proto;
763
  timer *disp_timer;                /* OSPF proto dispatcher */
764
  unsigned tick;
765
  struct top_graph *gr;                /* LSA graph */
766
  slist lsal;                        /* List of all LSA's */
767
  int calcrt;                        /* Routing table calculation scheduled?
768
                                   0=no, 1=normal, 2=forced reload */
769
  list iface_list;                /* Interfaces we really use */
770
  list area_list;
771
  int areano;                        /* Number of area I belong to */
772
  struct fib rtf;                /* Routing table */
773
  byte rfc1583;                        /* RFC1583 compatibility */
774
  byte ebit;                        /* Did I originate any ext lsa? */
775
  byte ecmp;                        /* Maximal number of nexthops in ECMP route, or 0 */
776
  struct ospf_area *backbone;        /* If exists */
777
  void *lsab;                        /* LSA buffer used when originating router LSAs */
778
  int lsab_size, lsab_used;
779
  linpool *nhpool;                /* Linpool used for next hops computed in SPF */
780
  u32 router_id;
781
  u32 last_vlink_id;                /* Interface IDs for vlinks (starts at 0x80000000) */
782
};
783

    
784
struct ospf_iface_patt
785
{
786
  struct iface_patt i;
787
  u32 type;
788
  u32 stub;
789
  u32 cost;
790
  u32 helloint;
791
  u32 rxmtint;
792
  u32 pollint;
793
  u32 waitint;
794
  u32 deadc;
795
  u32 deadint;
796
  u32 inftransdelay;
797
  list nbma_list;
798
  u32 priority;
799
  u32 voa;
800
  u32 vid;
801
  u16 rxbuf;
802
#define OSPF_RXBUF_NORMAL 0
803
#define OSPF_RXBUF_LARGE 1
804
#define OSPF_RXBUF_MINSIZE 256        /* Minimal allowed size */
805
  u16 autype;                        /* Not really used in OSPFv3 */
806
#define OSPF_AUTH_NONE 0
807
#define OSPF_AUTH_SIMPLE 1
808
#define OSPF_AUTH_CRYPT 2
809
#define OSPF_AUTH_CRYPT_SIZE 16
810
  u8 strictnbma;
811
  u8 check_link;
812
  u8 ecmp_weight;
813
  u8 real_bcast;                /* Not really used in OSPFv3 */
814
  u8 ptp_netmask;                /* bool but 2 for unspecified */
815

    
816
#ifdef OSPFv2
817
  list *passwords;
818
#endif
819

    
820
#ifdef OSPFv3
821
  u8 instance_id;
822
#endif
823
};
824

    
825
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
826
                        struct linpool *pool);
827
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
828
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
829
void schedule_rt_lsa(struct ospf_area *oa);
830
void schedule_rtcalc(struct proto_ospf *po);
831
void schedule_net_lsa(struct ospf_iface *ifa);
832

    
833
struct ospf_area *ospf_find_area(struct proto_ospf *po, u32 aid);
834
static inline struct ospf_area *ospf_main_area(struct proto_ospf *po)
835
{ return (po->areano == 1) ? HEAD(po->area_list) : po->backbone; }
836

    
837
static inline int oa_is_stub(struct ospf_area *oa)
838
{ return (oa->options & (OPT_E | OPT_N)) == 0; }
839
static inline int oa_is_ext(struct ospf_area *oa)
840
{ return oa->options & OPT_E; }
841
static inline int oa_is_nssa(struct ospf_area *oa)
842
{ return oa->options & OPT_N; }
843

    
844

    
845
#ifdef OSPFv3
846
void schedule_link_lsa(struct ospf_iface *ifa);
847
#else
848
static inline void schedule_link_lsa(struct ospf_iface *ifa UNUSED) {}
849
#endif
850

    
851
void ospf_sh_neigh(struct proto *p, char *iff);
852
void ospf_sh(struct proto *p);
853
void ospf_sh_iface(struct proto *p, char *iff);
854
void ospf_sh_state(struct proto *p, int verbose, int reachable);
855

    
856
#define SH_ROUTER_SELF 0xffffffff
857

    
858
struct lsadb_show_data {
859
  struct symbol *name;        /* Protocol to request data from */
860
  u16 type;                /* LSA Type, 0 -> all */
861
  u16 scope;                /* Scope, 0 -> all, hack to handle link scope as 1 */
862
  u32 area;                /* Specified for area scope */
863
  u32 lsid;                /* LSA ID, 0 -> all */
864
  u32 router;                /* Advertising router, 0 -> all */
865
};
866

    
867
void ospf_sh_lsadb(struct lsadb_show_data *ld);
868

    
869

    
870
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
871
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
872
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
873
#define EA_OSPF_ROUTER_ID EA_CODE(EAP_OSPF, 3)
874

    
875
#include "proto/ospf/rt.h"
876
#include "proto/ospf/hello.h"
877
#include "proto/ospf/packet.h"
878
#include "proto/ospf/iface.h"
879
#include "proto/ospf/neighbor.h"
880
#include "proto/ospf/topology.h"
881
#include "proto/ospf/dbdes.h"
882
#include "proto/ospf/lsreq.h"
883
#include "proto/ospf/lsupd.h"
884
#include "proto/ospf/lsack.h"
885
#include "proto/ospf/lsalib.h"
886

    
887
#endif /* _BIRD_OSPF_H_ */