Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ 48e5f32d

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 abr;
85
  int ecmp;
86
  list area_list;                /* list of struct ospf_area_config */
87
  list vlink_list;                /* list of struct ospf_iface_patt */
88
};
89

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

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

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

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

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

    
140

    
141
/* Option flags */
142

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

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

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

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

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

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

    
174

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

    
184
  pool *pool;
185
  sock *sk;                        /* IP socket */
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
  u16 tx_length;                /* Soft TX packet length limit, usually MTU */
275
  u8 check_link;                /* Whether iface link change is used */
276
  u8 ecmp_weight;                /* Weight used for ECMP */
277
  u8 ptp_netmask;                /* Send real netmask for P2P */
278
  u8 check_ttl;                        /* Check incoming packets for TTL 255 */
279
  u8 bfd;                        /* Use BFD on iface */
280
};
281

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

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

    
296

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

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

    
307

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

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

    
332

    
333
#ifdef OSPFv2
334

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

    
347

    
348
#else /* OSPFv3 packet descriptions */
349

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

    
362

    
363
#endif
364

    
365

    
366

    
367

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

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

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

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

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

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

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

    
403
#define LSA_UBIT        0x8000
404

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

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

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

    
423

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

    
429

    
430
#ifdef OSPFv2
431

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

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

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

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

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

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

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

    
486

    
487
#else  /* OSPFv3 */
488

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

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

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

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

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

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

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

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

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

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

    
565
#endif
566

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

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

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

    
584

    
585
#ifdef OSPFv3
586

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

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

    
599
  *addr = IPA_NONE;
600

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

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

    
614
  return buf;
615
}
616

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

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

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

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

    
647
#endif
648

    
649

    
650

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

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

    
664

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

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

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

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

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

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

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

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

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

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

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

    
828
#ifdef OSPFv2
829
  list *passwords;
830
#endif
831

    
832
#ifdef OSPFv3
833
  u8 instance_id;
834
#endif
835
};
836

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

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

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

    
856

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

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

    
868
#define SH_ROUTER_SELF 0xffffffff
869

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

    
879
void ospf_sh_lsadb(struct lsadb_show_data *ld);
880

    
881

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

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

    
899
#endif /* _BIRD_OSPF_H_ */