Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ 145368f5

History | View | Annotate | Download (20.9 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_MIN_PKT_SIZE 256
14
#define OSPF_MAX_PKT_SIZE 65535
15

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

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

    
28

    
29
#include "nest/bird.h"
30

    
31
#include "lib/checksum.h"
32
#include "lib/ip.h"
33
#include "lib/lists.h"
34
#include "lib/slists.h"
35
#include "lib/socket.h"
36
#include "lib/timer.h"
37
#include "lib/resource.h"
38
#include "nest/protocol.h"
39
#include "nest/iface.h"
40
#include "nest/route.h"
41
#include "nest/cli.h"
42
#include "nest/locks.h"
43
#include "nest/bfd.h"
44
#include "conf/conf.h"
45
#include "lib/string.h"
46

    
47
#define OSPF_PROTO 89
48

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

    
63

    
64
#define LSREFRESHTIME 1800        /* 30 minutes */
65
#define MINLSINTERVAL 5
66
#define MINLSARRIVAL 1
67
#define LSINFINITY 0xffffff
68

    
69
#define DEFAULT_OSPFTICK 1
70
#define DEFAULT_RFC1583 0        /* compatibility with rfc1583 */
71
#define DEFAULT_STUB_COST 1000
72
#define DEFAULT_ECMP_LIMIT 16
73
#define DEFAULT_TRANSINT 40
74

    
75
#define OSPF_VLINK_ID_OFFSET 0x80000000
76

    
77

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

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

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

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

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

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

    
141

    
142
/* Option flags */
143

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

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

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

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

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

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

    
175

    
176
struct ospf_iface
177
{
178
  node n;
179
  struct iface *iface;                /* Nest's iface (NULL for vlinks) */
180
  struct ifa *addr;                /* IP prefix associated with that OSPF iface */
181
  struct ospf_area *oa;
182
  struct ospf_iface_patt *cf;
183
  char *ifname;                        /* Interface name (iface->name), new one for vlinks */
184

    
185
  pool *pool;
186
  sock *sk;                        /* IP socket */
187
  list neigh_list;                /* List of neigbours */
188
  u32 cost;                        /* Cost of iface */
189
  u32 waitint;                        /* number of sec before changing state from wait */
190
  u32 rxmtint;                        /* number of seconds between LSA retransmissions */
191
  u32 pollint;                        /* Poll interval */
192
  u32 deadint;                        /* after "deadint" missing hellos is router dead */
193
  u32 iface_id;                        /* Interface ID (iface->index or new value for vlinks) */
194
  u32 vid;                        /* ID of peer of virtual link */
195
  ip_addr vip;                        /* IP of peer of virtual link */
196
  struct ospf_iface *vifa;        /* OSPF iface which the vlink goes through */
197
  struct ospf_area *voa;        /* OSPF area which the vlink goes through */
198
  u16 inftransdelay;                /* The estimated number of seconds it takes to
199
                                   transmit a Link State Update Packet over this
200
                                   interface.  LSAs contained in the update */
201
  u16 helloint;                        /* number of seconds between hello sending */
202

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

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

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

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

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

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

    
283
struct ospf_md5
284
{
285
  u16 zero;
286
  u8 keyid;
287
  u8 len;
288
  u32 csn;
289
};
290

    
291
union ospf_auth
292
{
293
  u8 password[8];
294
  struct ospf_md5 md5;
295
};
296

    
297

    
298
/* Packet types */
299
#define HELLO_P 1                /* Hello */
300
#define DBDES_P 2                /* Database description */
301
#define LSREQ_P 3                /* Link state request */
302
#define LSUPD_P 4                /* Link state update */
303
#define LSACK_P 5                /* Link state acknowledgement */
304

    
305
/* Area IDs */
306
#define BACKBONE 0
307

    
308

    
309
struct immsb
310
{
311
#ifdef CPU_BIG_ENDIAN
312
  u8 padding:5;
313
  u8 i:1;
314
  u8 m:1;
315
  u8 ms:1;
316
#else
317
  u8 ms:1;
318
  u8 m:1;
319
  u8 i:1;
320
  u8 padding:5;
321
#endif
322
};
323

    
324
union imms
325
{
326
  u8 byte;
327
  struct immsb bit;
328
};
329
#define DBDES_MS 1
330
#define DBDES_M 2
331
#define DBDES_I 4
332

    
333

    
334
#ifdef OSPFv2
335

    
336
struct ospf_packet
337
{
338
  u8 version;
339
  u8 type;
340
  u16 length;
341
  u32 routerid;
342
  u32 areaid;
343
  u16 checksum;
344
  u16 autype;
345
  union ospf_auth u;
346
};
347

    
348

    
349
#else /* OSPFv3 packet descriptions */
350

    
351
struct ospf_packet
352
{
353
  u8 version;
354
  u8 type;
355
  u16 length;
356
  u32 routerid;
357
  u32 areaid;
358
  u16 checksum;
359
  u8 instance_id;
360
  u8 zero;
361
};
362

    
363

    
364
#endif
365

    
366

    
367

    
368

    
369
struct ospf_lsa_header
370
{
371
  u16 age;                        /* LS Age */
372
#define LSA_MAXAGE 3600                /* 1 hour */
373
#define LSA_CHECKAGE 300        /* 5 minutes */
374
#define LSA_MAXAGEDIFF 900        /* 15 minutes */
375

    
376
#ifdef OSPFv2
377
  u8 options;
378
  u8 type;
379

    
380
#define LSA_T_RT        1
381
#define LSA_T_NET        2
382
#define LSA_T_SUM_NET        3
383
#define LSA_T_SUM_RT        4
384
#define LSA_T_EXT        5
385
#define LSA_T_NSSA        7
386

    
387
#define LSA_SCOPE_AREA        0x2000
388
#define LSA_SCOPE_AS        0x4000
389

    
390
#define LSA_SCOPE(lsa)        (((lsa)->type == LSA_T_EXT) ? LSA_SCOPE_AS : LSA_SCOPE_AREA)
391

    
392
#else /* OSPFv3 */
393
  u16 type;
394

    
395
#define LSA_T_RT        0x2001
396
#define LSA_T_NET        0x2002
397
#define LSA_T_SUM_NET        0x2003
398
#define LSA_T_SUM_RT        0x2004
399
#define LSA_T_EXT        0x4005
400
#define LSA_T_NSSA        0x2007
401
#define LSA_T_LINK        0x0008
402
#define LSA_T_PREFIX        0x2009
403

    
404
#define LSA_UBIT        0x8000
405

    
406
#define LSA_SCOPE_LINK        0x0000
407
#define LSA_SCOPE_AREA        0x2000
408
#define LSA_SCOPE_AS        0x4000
409
#define LSA_SCOPE_RES        0x6000
410
#define LSA_SCOPE_MASK        0x6000
411

    
412
#define LSA_SCOPE(lsa)        ((lsa)->type & LSA_SCOPE_MASK)
413
#endif
414

    
415
  u32 id;
416
  u32 rt;                        /* Advertising router */
417
  s32 sn;                        /* LS Sequence number */
418
#define LSA_INITSEQNO ((s32) 0x80000001)
419
#define LSA_MAXSEQNO ((s32) 0x7fffffff)
420
  u16 checksum;
421
  u16 length;
422
};
423

    
424

    
425
#define LSART_PTP 1
426
#define LSART_NET 2
427
#define LSART_STUB 3
428
#define LSART_VLNK 4
429

    
430

    
431
#ifdef OSPFv2
432

    
433
struct ospf_lsa_rt
434
{
435
#ifdef CPU_BIG_ENDIAN
436
  u16 options;        /* VEB flags only */
437
  u16 links;
438
#else
439
  u16 links;
440
  u16 options;        /* VEB flags only */
441
#endif
442
};
443

    
444
struct ospf_lsa_rt_link
445
{
446
  u32 id;
447
  u32 data;
448
#ifdef CPU_BIG_ENDIAN
449
  u8 type;
450
  u8 padding;
451
  u16 metric;
452
#else
453
  u16 metric;
454
  u8 padding;
455
  u8 type;
456
#endif
457
};
458

    
459
struct ospf_lsa_net
460
{
461
  ip_addr netmask;
462
  u32 routers[];
463
};
464

    
465
struct ospf_lsa_sum
466
{
467
  ip_addr netmask;
468
  u32 metric;
469
};
470

    
471
struct ospf_lsa_ext
472
{
473
  ip_addr netmask;
474
  u32 metric;
475
  ip_addr fwaddr;
476
  u32 tag;
477
};
478

    
479
#define LSA_SUM_TOS  0xFF000000
480
#define LSA_EXT_TOS  0x7F000000
481
#define LSA_EXT_EBIT 0x80000000
482

    
483
/* Endianity swap for lsa->type */
484
#define ntoht(x) x
485
#define htont(x) x
486

    
487

    
488
#else  /* OSPFv3 */
489

    
490
struct ospf_lsa_rt
491
{
492
  u32 options;
493
};
494

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

    
511
struct ospf_lsa_net
512
{
513
  u32 options;
514
  u32 routers[];
515
};
516

    
517
struct ospf_lsa_sum_net
518
{
519
  u32 metric;
520
  u32 prefix[];
521
};
522

    
523
struct ospf_lsa_sum_rt
524
{
525
  u32 options;
526
  u32 metric;
527
  u32 drid;
528
};
529

    
530
struct ospf_lsa_ext
531
{
532
  u32 metric;
533
  u32 rest[];
534
};
535

    
536
struct ospf_lsa_link
537
{
538
  u32 options;
539
  ip_addr lladdr;
540
  u32 pxcount;
541
  u32 rest[];
542
};
543

    
544
struct ospf_lsa_prefix
545
{
546
#ifdef CPU_BIG_ENDIAN
547
  u16 pxcount;
548
  u16 ref_type;
549
#else
550
  u16 ref_type;
551
  u16 pxcount;
552
#endif
553
  u32 ref_id;
554
  u32 ref_rt;
555
  u32 rest[];
556
};
557

    
558
#define LSA_EXT_EBIT 0x4000000
559
#define LSA_EXT_FBIT 0x2000000
560
#define LSA_EXT_TBIT 0x1000000
561

    
562
/* Endianity swap for lsa->type */
563
#define ntoht(x) ntohs(x)
564
#define htont(x) htons(x)
565

    
566
#endif
567

    
568
#define METRIC_MASK  0x00FFFFFF
569
#define OPTIONS_MASK 0x00FFFFFF
570

    
571
static inline unsigned
572
lsa_rt_count(struct ospf_lsa_header *lsa)
573
{
574
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_rt))
575
    / sizeof(struct ospf_lsa_rt_link);
576
}
577

    
578
static inline unsigned
579
lsa_net_count(struct ospf_lsa_header *lsa)
580
{
581
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net))
582
    / sizeof(u32);
583
}
584

    
585

    
586
#ifdef OSPFv3
587

    
588
#define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
589
#define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
590

    
591
static inline u32 *
592
lsa_get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest)
593
{
594
  u8 pxl = (*buf >> 24);
595
  *pxopts = (*buf >> 16);
596
  *rest = *buf;
597
  *pxlen = pxl;
598
  buf++;
599

    
600
  *addr = IPA_NONE;
601

    
602
  if (pxl > 0)
603
    _I0(*addr) = *buf++;
604
  if (pxl > 32)
605
    _I1(*addr) = *buf++;
606
  if (pxl > 64)
607
    _I2(*addr) = *buf++;
608
  if (pxl > 96)
609
    _I3(*addr) = *buf++;
610

    
611
  /* Clean up remaining bits */
612
  if (pxl < 128)
613
    addr->addr[pxl / 32] &= u32_mkmask(pxl % 32);
614

    
615
  return buf;
616
}
617

    
618
static inline u32 *
619
lsa_get_ipv6_addr(u32 *buf, ip_addr *addr)
620
{
621
  *addr = *(ip_addr *) buf;
622
  return buf + 4;
623
}
624

    
625
static inline u32 *
626
put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh)
627
{
628
  *buf++ = ((pxlen << 24) | (pxopts << 16) | lh);
629

    
630
  if (pxlen > 0)
631
    *buf++ = _I0(addr);
632
  if (pxlen > 32)
633
    *buf++ = _I1(addr);
634
  if (pxlen > 64)
635
    *buf++ = _I2(addr);
636
  if (pxlen > 96)
637
    *buf++ = _I3(addr);
638
  return buf;
639
}
640

    
641
static inline u32 *
642
put_ipv6_addr(u32 *buf, ip_addr addr)
643
{
644
  *(ip_addr *) buf = addr;
645
  return buf + 4;
646
}
647

    
648
#endif
649

    
650

    
651

    
652
struct ospf_lsreq_header
653
{
654
  u32 type;
655
  u32 id;
656
  u32 rt;                        /* Advertising router */
657
};
658

    
659
struct l_lsr_head
660
{
661
  node n;
662
  struct ospf_lsreq_header lsh;
663
};
664

    
665

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

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

    
696
#ifdef OSPFv3
697
  u32 iface_id;                        /* ID of Neighbour's iface connected to common network */
698
#endif
699

    
700
  siterator dbsi;                /* Database summary list iterator */
701
  slist lsrql;                        /* Link state request */
702
  struct top_graph *lsrqh;        /* LSA graph */
703
  siterator lsrqi;
704
  slist lsrtl;                        /* Link state retransmission list */
705
  siterator lsrti;
706
  struct top_graph *lsrth;
707
  timer *rxmt_timer;                /* RXMT timer */
708
  list ackl[2];
709
#define ACKL_DIRECT 0
710
#define ACKL_DELAY 1
711
  timer *ackd_timer;                /* Delayed ack timer */
712
  struct bfd_request *bfd_req;        /* BFD request, if BFD is used */
713
  void *ldd_buffer;                /* Last database description packet */
714
  u32 ldd_bsize;                /* Buffer size for ldd_buffer */
715
  u32 csn;                      /* Last received crypt seq number (for MD5) */
716
};
717

    
718
/* Definitions for interface state machine */
719
#define ISM_UP 0                /* Interface Up */
720
#define ISM_WAITF 1                /* Wait timer fired */
721
#define ISM_BACKS 2                /* Backup seen */
722
#define ISM_NEICH 3                /* Neighbor change */
723
#define ISM_LOOP 4                /* Link down */
724
#define ISM_UNLOOP 5                /* Link up */
725
#define ISM_DOWN 6                /* Interface down */
726

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

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

    
762
#define TRANS_OFF        0
763
#define TRANS_ON        1
764
#define TRANS_WAIT        2        /* Waiting before the end of translation */
765

    
766
struct proto_ospf
767
{
768
  struct proto proto;
769
  timer *disp_timer;                /* OSPF proto dispatcher */
770
  unsigned tick;
771
  struct top_graph *gr;                /* LSA graph */
772
  slist lsal;                        /* List of all LSA's */
773
  int calcrt;                        /* Routing table calculation scheduled?
774
                                   0=no, 1=normal, 2=forced reload */
775
  list iface_list;                /* Interfaces we really use */
776
  list area_list;
777
  int areano;                        /* Number of area I belong to */
778
  struct fib rtf;                /* Routing table */
779
  byte rfc1583;                        /* RFC1583 compatibility */
780
  byte stub_router;                /* Do not forward transit traffic */
781
  byte merge_external;                /* Should i merge external routes? */
782
  byte ebit;                        /* Did I originate any ext lsa? */
783
  byte ecmp;                        /* Maximal number of nexthops in ECMP route, or 0 */
784
  struct ospf_area *backbone;        /* If exists */
785
  void *lsab;                        /* LSA buffer used when originating router LSAs */
786
  int lsab_size, lsab_used;
787
  linpool *nhpool;                /* Linpool used for next hops computed in SPF */
788
  sock *vlink_sk;                /* IP socket used for vlink TX */
789
  u32 router_id;
790
  u32 last_vlink_id;                /* Interface IDs for vlinks (starts at 0x80000000) */
791
};
792

    
793
struct ospf_iface_patt
794
{
795
  struct iface_patt i;
796
  u32 type;
797
  u32 stub;
798
  u32 cost;
799
  u32 helloint;
800
  u32 rxmtint;
801
  u32 pollint;
802
  u32 waitint;
803
  u32 deadc;
804
  u32 deadint;
805
  u32 inftransdelay;
806
  list nbma_list;
807
  u32 priority;
808
  u32 voa;
809
  u32 vid;
810
  int tx_tos;
811
  int tx_priority;
812
  u16 tx_length;
813
  u16 rx_buffer;
814

    
815
#define OSPF_RXBUF_MINSIZE 256        /* Minimal allowed size */
816
  u16 autype;                        /* Not really used in OSPFv3 */
817
#define OSPF_AUTH_NONE 0
818
#define OSPF_AUTH_SIMPLE 1
819
#define OSPF_AUTH_CRYPT 2
820
#define OSPF_AUTH_CRYPT_SIZE 16
821
  u8 strictnbma;
822
  u8 check_link;
823
  u8 ecmp_weight;
824
  u8 real_bcast;                /* Not really used in OSPFv3 */
825
  u8 ptp_netmask;                /* bool + 2 for unspecified */
826
  u8 ttl_security;                /* bool + 2 for TX only */
827
  u8 bfd;
828
  u8 bsd_secondary;
829

    
830
#ifdef OSPFv2
831
  list *passwords;
832
#endif
833

    
834
#ifdef OSPFv3
835
  u8 instance_id;
836
#endif
837
};
838

    
839
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
840
                        struct linpool *pool);
841
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
842
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
843
void schedule_rt_lsa(struct ospf_area *oa);
844
void schedule_rtcalc(struct proto_ospf *po);
845
void schedule_net_lsa(struct ospf_iface *ifa);
846

    
847
struct ospf_area *ospf_find_area(struct proto_ospf *po, u32 aid);
848
static inline struct ospf_area *ospf_main_area(struct proto_ospf *po)
849
{ return (po->areano == 1) ? HEAD(po->area_list) : po->backbone; }
850

    
851
static inline int oa_is_stub(struct ospf_area *oa)
852
{ return (oa->options & (OPT_E | OPT_N)) == 0; }
853
static inline int oa_is_ext(struct ospf_area *oa)
854
{ return oa->options & OPT_E; }
855
static inline int oa_is_nssa(struct ospf_area *oa)
856
{ return oa->options & OPT_N; }
857

    
858

    
859
#ifdef OSPFv3
860
void schedule_link_lsa(struct ospf_iface *ifa);
861
#else
862
static inline void schedule_link_lsa(struct ospf_iface *ifa UNUSED) {}
863
#endif
864

    
865
void ospf_sh_neigh(struct proto *p, char *iff);
866
void ospf_sh(struct proto *p);
867
void ospf_sh_iface(struct proto *p, char *iff);
868
void ospf_sh_state(struct proto *p, int verbose, int reachable);
869

    
870
#define SH_ROUTER_SELF 0xffffffff
871

    
872
struct lsadb_show_data {
873
  struct symbol *name;        /* Protocol to request data from */
874
  u16 type;                /* LSA Type, 0 -> all */
875
  u16 scope;                /* Scope, 0 -> all, hack to handle link scope as 1 */
876
  u32 area;                /* Specified for area scope */
877
  u32 lsid;                /* LSA ID, 0 -> all */
878
  u32 router;                /* Advertising router, 0 -> all */
879
};
880

    
881
void ospf_sh_lsadb(struct lsadb_show_data *ld);
882

    
883

    
884
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
885
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
886
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
887
#define EA_OSPF_ROUTER_ID EA_CODE(EAP_OSPF, 3)
888

    
889
#include "proto/ospf/rt.h"
890
#include "proto/ospf/hello.h"
891
#include "proto/ospf/packet.h"
892
#include "proto/ospf/iface.h"
893
#include "proto/ospf/neighbor.h"
894
#include "proto/ospf/topology.h"
895
#include "proto/ospf/dbdes.h"
896
#include "proto/ospf/lsreq.h"
897
#include "proto/ospf/lsupd.h"
898
#include "proto/ospf/lsack.h"
899
#include "proto/ospf/lsalib.h"
900

    
901
#endif /* _BIRD_OSPF_H_ */