]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/ospf/ospf.h
Implements protocol templates.
[thirdparty/bird.git] / proto / ospf / ospf.h
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 */
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 vid; /* Id of peer of virtual link */
193 ip_addr vip; /* IP of peer of virtual link */
194 struct ospf_iface *vifa; /* OSPF iface which the vlink goes through */
195 struct ospf_area *voa; /* OSPF area which the vlink goes through */
196 u16 inftransdelay; /* The estimated number of seconds it takes to
197 transmit a Link State Update Packet over this
198 interface. LSAs contained in the update */
199 u16 helloint; /* number of seconds between hello sending */
200
201 #ifdef OSPFv2
202 list *passwords;
203 u16 autype;
204 u32 csn; /* Last used crypt seq number */
205 bird_clock_t csn_use; /* Last time when packet with that CSN was sent */
206 #endif
207
208 ip_addr drip; /* Designated router */
209 ip_addr bdrip; /* Backup DR */
210 u32 drid;
211 u32 bdrid;
212 s16 rt_pos_beg; /* Position of iface in Router-LSA, begin, inclusive */
213 s16 rt_pos_end; /* Position of iface in Router-LSA, end, exclusive */
214
215 #ifdef OSPFv3
216 s16 px_pos_beg; /* Position of iface in Rt Prefix-LSA, begin, inclusive */
217 s16 px_pos_end; /* Position of iface in Rt Prefix-LSA, end, exclusive */
218
219 u32 dr_iface_id; /* if drid is valid, this is iface_id of DR (for connecting network) */
220 u8 instance_id; /* Used to differentiate between more OSPF
221 instances on one interface */
222 #endif
223
224 u8 type; /* OSPF view of type */
225 #define OSPF_IT_BCAST 0
226 #define OSPF_IT_NBMA 1
227 #define OSPF_IT_PTP 2
228 #define OSPF_IT_PTMP 3
229 #define OSPF_IT_VLINK 4
230 #define OSPF_IT_UNDEF 5
231 u8 strictnbma; /* Can I talk with unknown neighbors? */
232 u8 stub; /* Inactive interface */
233 u8 state; /* Interface state machine */
234 #define OSPF_IS_DOWN 0 /* Not working */
235 #define OSPF_IS_LOOP 1 /* Iface with no link */
236 #define OSPF_IS_WAITING 2 /* Waiting for Wait timer */
237 #define OSPF_IS_PTP 3 /* PTP operational */
238 #define OSPF_IS_DROTHER 4 /* I'm on BCAST or NBMA and I'm not DR */
239 #define OSPF_IS_BACKUP 5 /* I'm BDR */
240 #define OSPF_IS_DR 6 /* I'm DR */
241 timer *wait_timer; /* WAIT timer */
242 timer *hello_timer; /* HELLOINT timer */
243 timer *poll_timer; /* Poll Interval - for NBMA */
244 /* Default values for interface parameters */
245 #define COST_D 10
246 #define RXMTINT_D 5
247 #define INFTRANSDELAY_D 1
248 #define PRIORITY_D 1
249 #define HELLOINT_D 10
250 #define POLLINT_D 20
251 #define DEADC_D 4
252 #define WAIT_DMH 4
253 /* Value of Wait timer - not found it in RFC * - using 4*HELLO */
254
255 struct top_hash_entry *net_lsa; /* Originated network LSA */
256 int orignet; /* Schedule network LSA origination */
257 #ifdef OSPFv3
258 int origlink; /* Schedule link LSA origination */
259 struct top_hash_entry *link_lsa; /* Originated link LSA */
260 struct top_hash_entry *pxn_lsa; /* Originated prefix LSA */
261 #endif
262 int fadj; /* Number of full adjacent neigh */
263 list nbma_list;
264 u8 priority; /* A router priority for DR election */
265 u8 ioprob;
266 #define OSPF_I_OK 0 /* Everything OK */
267 #define OSPF_I_SK 1 /* Socket open failed */
268 #define OSPF_I_LL 2 /* Missing link-local address (OSPFv3) */
269 u8 sk_dr; /* Socket is a member of DRouters group */
270 u8 marked; /* Used in OSPF reconfigure */
271 u16 rxbuf; /* Buffer size */
272 u8 check_link; /* Whether iface link change is used */
273 u8 ecmp_weight; /* Weight used for ECMP */
274 };
275
276 struct ospf_md5
277 {
278 u16 zero;
279 u8 keyid;
280 u8 len;
281 u32 csn;
282 };
283
284 union ospf_auth
285 {
286 u8 password[8];
287 struct ospf_md5 md5;
288 };
289
290
291 /* Packet types */
292 #define HELLO_P 1 /* Hello */
293 #define DBDES_P 2 /* Database description */
294 #define LSREQ_P 3 /* Link state request */
295 #define LSUPD_P 4 /* Link state update */
296 #define LSACK_P 5 /* Link state acknowledgement */
297
298 /* Area IDs */
299 #define BACKBONE 0
300
301
302 struct immsb
303 {
304 #ifdef CPU_BIG_ENDIAN
305 u8 padding:5;
306 u8 i:1;
307 u8 m:1;
308 u8 ms:1;
309 #else
310 u8 ms:1;
311 u8 m:1;
312 u8 i:1;
313 u8 padding:5;
314 #endif
315 };
316
317 union imms
318 {
319 u8 byte;
320 struct immsb bit;
321 };
322 #define DBDES_MS 1
323 #define DBDES_M 2
324 #define DBDES_I 4
325
326
327 #ifdef OSPFv2
328
329 struct ospf_packet
330 {
331 u8 version;
332 u8 type;
333 u16 length;
334 u32 routerid;
335 u32 areaid;
336 u16 checksum;
337 u16 autype;
338 union ospf_auth u;
339 };
340
341
342 #else /* OSPFv3 packet descriptions */
343
344 struct ospf_packet
345 {
346 u8 version;
347 u8 type;
348 u16 length;
349 u32 routerid;
350 u32 areaid;
351 u16 checksum;
352 u8 instance_id;
353 u8 zero;
354 };
355
356
357 #endif
358
359
360
361
362 struct ospf_lsa_header
363 {
364 u16 age; /* LS Age */
365 #define LSA_MAXAGE 3600 /* 1 hour */
366 #define LSA_CHECKAGE 300 /* 5 minutes */
367 #define LSA_MAXAGEDIFF 900 /* 15 minutes */
368
369 #ifdef OSPFv2
370 u8 options;
371 u8 type;
372
373 #define LSA_T_RT 1
374 #define LSA_T_NET 2
375 #define LSA_T_SUM_NET 3
376 #define LSA_T_SUM_RT 4
377 #define LSA_T_EXT 5
378 #define LSA_T_NSSA 7
379
380 #define LSA_SCOPE_AREA 0x2000
381 #define LSA_SCOPE_AS 0x4000
382
383 #define LSA_SCOPE(lsa) (((lsa)->type == LSA_T_EXT) ? LSA_SCOPE_AS : LSA_SCOPE_AREA)
384
385 #else /* OSPFv3 */
386 u16 type;
387
388 #define LSA_T_RT 0x2001
389 #define LSA_T_NET 0x2002
390 #define LSA_T_SUM_NET 0x2003
391 #define LSA_T_SUM_RT 0x2004
392 #define LSA_T_EXT 0x4005
393 #define LSA_T_NSSA 0x2007
394 #define LSA_T_LINK 0x0008
395 #define LSA_T_PREFIX 0x2009
396
397 #define LSA_UBIT 0x8000
398
399 #define LSA_SCOPE_LINK 0x0000
400 #define LSA_SCOPE_AREA 0x2000
401 #define LSA_SCOPE_AS 0x4000
402 #define LSA_SCOPE_RES 0x6000
403 #define LSA_SCOPE_MASK 0x6000
404
405 #define LSA_SCOPE(lsa) ((lsa)->type & LSA_SCOPE_MASK)
406 #endif
407
408 u32 id;
409 u32 rt; /* Advertising router */
410 s32 sn; /* LS Sequence number */
411 #define LSA_INITSEQNO ((s32) 0x80000001)
412 #define LSA_MAXSEQNO ((s32) 0x7fffffff)
413 u16 checksum;
414 u16 length;
415 };
416
417
418 #define LSART_PTP 1
419 #define LSART_NET 2
420 #define LSART_STUB 3
421 #define LSART_VLNK 4
422
423
424 #ifdef OSPFv2
425
426 struct ospf_lsa_rt
427 {
428 #ifdef CPU_BIG_ENDIAN
429 u16 options; /* VEB flags only */
430 u16 links;
431 #else
432 u16 links;
433 u16 options; /* VEB flags only */
434 #endif
435 };
436
437 struct ospf_lsa_rt_link
438 {
439 u32 id;
440 u32 data;
441 #ifdef CPU_BIG_ENDIAN
442 u8 type;
443 u8 padding;
444 u16 metric;
445 #else
446 u16 metric;
447 u8 padding;
448 u8 type;
449 #endif
450 };
451
452 struct ospf_lsa_net
453 {
454 ip_addr netmask;
455 u32 routers[];
456 };
457
458 struct ospf_lsa_sum
459 {
460 ip_addr netmask;
461 u32 metric;
462 };
463
464 struct ospf_lsa_ext
465 {
466 ip_addr netmask;
467 u32 metric;
468 ip_addr fwaddr;
469 u32 tag;
470 };
471
472 #define LSA_SUM_TOS 0xFF000000
473 #define LSA_EXT_TOS 0x7F000000
474 #define LSA_EXT_EBIT 0x80000000
475
476 /* Endianity swap for lsa->type */
477 #define ntoht(x) x
478 #define htont(x) x
479
480
481 #else /* OSPFv3 */
482
483 struct ospf_lsa_rt
484 {
485 u32 options;
486 };
487
488 struct ospf_lsa_rt_link
489 {
490 #ifdef CPU_BIG_ENDIAN
491 u8 type;
492 u8 padding;
493 u16 metric;
494 #else
495 u16 metric;
496 u8 padding;
497 u8 type;
498 #endif
499 u32 lif; /* Local interface ID */
500 u32 nif; /* Neighbor interface ID */
501 u32 id; /* Neighbor router ID */
502 };
503
504 struct ospf_lsa_net
505 {
506 u32 options;
507 u32 routers[];
508 };
509
510 struct ospf_lsa_sum_net
511 {
512 u32 metric;
513 u32 prefix[];
514 };
515
516 struct ospf_lsa_sum_rt
517 {
518 u32 options;
519 u32 metric;
520 u32 drid;
521 };
522
523 struct ospf_lsa_ext
524 {
525 u32 metric;
526 u32 rest[];
527 };
528
529 struct ospf_lsa_link
530 {
531 u32 options;
532 ip_addr lladdr;
533 u32 pxcount;
534 u32 rest[];
535 };
536
537 struct ospf_lsa_prefix
538 {
539 #ifdef CPU_BIG_ENDIAN
540 u16 pxcount;
541 u16 ref_type;
542 #else
543 u16 ref_type;
544 u16 pxcount;
545 #endif
546 u32 ref_id;
547 u32 ref_rt;
548 u32 rest[];
549 };
550
551 #define LSA_EXT_EBIT 0x4000000
552 #define LSA_EXT_FBIT 0x2000000
553 #define LSA_EXT_TBIT 0x1000000
554
555 /* Endianity swap for lsa->type */
556 #define ntoht(x) ntohs(x)
557 #define htont(x) htons(x)
558
559 #endif
560
561 #define METRIC_MASK 0x00FFFFFF
562 #define OPTIONS_MASK 0x00FFFFFF
563
564 static inline unsigned
565 lsa_rt_count(struct ospf_lsa_header *lsa)
566 {
567 return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_rt))
568 / sizeof(struct ospf_lsa_rt_link);
569 }
570
571 static inline unsigned
572 lsa_net_count(struct ospf_lsa_header *lsa)
573 {
574 return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net))
575 / sizeof(u32);
576 }
577
578
579 #ifdef OSPFv3
580
581 #define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
582 #define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
583
584 static inline u32 *
585 lsa_get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest)
586 {
587 u8 pxl = (*buf >> 24);
588 *pxopts = (*buf >> 16);
589 *rest = *buf;
590 *pxlen = pxl;
591 buf++;
592
593 *addr = IPA_NONE;
594
595 if (pxl > 0)
596 _I0(*addr) = *buf++;
597 if (pxl > 32)
598 _I1(*addr) = *buf++;
599 if (pxl > 64)
600 _I2(*addr) = *buf++;
601 if (pxl > 96)
602 _I3(*addr) = *buf++;
603
604 /* Clean up remaining bits */
605 if (pxl < 128)
606 addr->addr[pxl / 32] &= u32_mkmask(pxl % 32);
607
608 return buf;
609 }
610
611 static inline u32 *
612 lsa_get_ipv6_addr(u32 *buf, ip_addr *addr)
613 {
614 *addr = *(ip_addr *) buf;
615 return buf + 4;
616 }
617
618 static inline u32 *
619 put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh)
620 {
621 *buf++ = ((pxlen << 24) | (pxopts << 16) | lh);
622
623 if (pxlen > 0)
624 *buf++ = _I0(addr);
625 if (pxlen > 32)
626 *buf++ = _I1(addr);
627 if (pxlen > 64)
628 *buf++ = _I2(addr);
629 if (pxlen > 96)
630 *buf++ = _I3(addr);
631 return buf;
632 }
633
634 static inline u32 *
635 put_ipv6_addr(u32 *buf, ip_addr addr)
636 {
637 *(ip_addr *) buf = addr;
638 return buf + 4;
639 }
640
641 #endif
642
643
644
645 struct ospf_lsreq_header
646 {
647 u32 type;
648 u32 id;
649 u32 rt; /* Advertising router */
650 };
651
652 struct l_lsr_head
653 {
654 node n;
655 struct ospf_lsreq_header lsh;
656 };
657
658
659 struct ospf_neighbor
660 {
661 node n;
662 pool *pool;
663 struct ospf_iface *ifa;
664 u8 state;
665 #define NEIGHBOR_DOWN 0
666 #define NEIGHBOR_ATTEMPT 1
667 #define NEIGHBOR_INIT 2
668 #define NEIGHBOR_2WAY 3
669 #define NEIGHBOR_EXSTART 4
670 #define NEIGHBOR_EXCHANGE 5
671 #define NEIGHBOR_LOADING 6
672 #define NEIGHBOR_FULL 7
673 timer *inactim; /* Inactivity timer */
674 union imms imms; /* I, M, Master/slave received */
675 u32 dds; /* DD Sequence number being sent */
676 u32 ddr; /* last Dat Des packet received */
677 union imms myimms; /* I, M Master/slave */
678 u32 rid; /* Router ID */
679 ip_addr ip; /* IP of it's interface */
680 u8 priority; /* Priority */
681 u8 adj; /* built adjacency? */
682 u32 options; /* Options received */
683
684 /* dr and bdr store IP address in OSPFv2 and router ID in OSPFv3,
685 we use the same type to simplify handling */
686 u32 dr; /* Neigbour's idea of DR */
687 u32 bdr; /* Neigbour's idea of BDR */
688
689 #ifdef OSPFv3
690 u32 iface_id; /* ID of Neighbour's iface connected to common network */
691 #endif
692
693 siterator dbsi; /* Database summary list iterator */
694 slist lsrql; /* Link state request */
695 struct top_graph *lsrqh; /* LSA graph */
696 siterator lsrqi;
697 slist lsrtl; /* Link state retransmission list */
698 siterator lsrti;
699 struct top_graph *lsrth;
700 void *ldbdes; /* Last database description packet */
701 timer *rxmt_timer; /* RXMT timer */
702 list ackl[2];
703 #define ACKL_DIRECT 0
704 #define ACKL_DELAY 1
705 timer *ackd_timer; /* Delayed ack timer */
706 u32 csn; /* Last received crypt seq number (for MD5) */
707 };
708
709 /* Definitions for interface state machine */
710 #define ISM_UP 0 /* Interface Up */
711 #define ISM_WAITF 1 /* Wait timer fired */
712 #define ISM_BACKS 2 /* Backup seen */
713 #define ISM_NEICH 3 /* Neighbor change */
714 #define ISM_LOOP 4 /* Link down */
715 #define ISM_UNLOOP 5 /* Link up */
716 #define ISM_DOWN 6 /* Interface down */
717
718 /* Definitions for neighbor state machine */
719 #define INM_HELLOREC 0 /* Hello Received */
720 #define INM_START 1 /* Neighbor start - for NBMA */
721 #define INM_2WAYREC 2 /* 2-Way received */
722 #define INM_NEGDONE 3 /* Negotiation done */
723 #define INM_EXDONE 4 /* Exchange done */
724 #define INM_BADLSREQ 5 /* Bad LS Request */
725 #define INM_LOADDONE 6 /* Load done */
726 #define INM_ADJOK 7 /* AdjOK? */
727 #define INM_SEQMIS 8 /* Sequence number mismatch */
728 #define INM_1WAYREC 9 /* 1-Way */
729 #define INM_KILLNBR 10 /* Kill Neighbor */
730 #define INM_INACTTIM 11 /* Inactivity timer */
731 #define INM_LLDOWN 12 /* Line down */
732
733 struct ospf_area
734 {
735 node n;
736 u32 areaid;
737 struct ospf_area_config *ac; /* Related area config */
738 struct top_hash_entry *rt; /* My own router LSA */
739 struct top_hash_entry *pxr_lsa; /* Originated prefix LSA */
740 list cand; /* List of candidates for RT calc. */
741 struct fib net_fib; /* Networks to advertise or not */
742 struct fib enet_fib; /* External networks for NSSAs */
743 u32 options; /* Optional features */
744 byte origrt; /* Rt lsa origination scheduled? */
745 byte trcap; /* Transit capability? */
746 byte marked; /* Used in OSPF reconfigure */
747 byte translate; /* Translator state (TRANS_*), for NSSA ABR */
748 timer *translator_timer; /* For NSSA translator switch */
749 struct proto_ospf *po;
750 struct fib rtr; /* Routing tables for routers */
751 };
752
753 #define TRANS_OFF 0
754 #define TRANS_ON 1
755 #define TRANS_WAIT 2 /* Waiting before the end of translation */
756
757 struct proto_ospf
758 {
759 struct proto proto;
760 timer *disp_timer; /* OSPF proto dispatcher */
761 unsigned tick;
762 struct top_graph *gr; /* LSA graph */
763 slist lsal; /* List of all LSA's */
764 int calcrt; /* Routing table calculation scheduled?
765 0=no, 1=normal, 2=forced reload */
766 list iface_list; /* Interfaces we really use */
767 list area_list;
768 int areano; /* Number of area I belong to */
769 struct fib rtf; /* Routing table */
770 byte rfc1583; /* RFC1583 compatibility */
771 byte ebit; /* Did I originate any ext lsa? */
772 byte ecmp; /* Maximal number of nexthops in ECMP route, or 0 */
773 struct ospf_area *backbone; /* If exists */
774 void *lsab; /* LSA buffer used when originating router LSAs */
775 int lsab_size, lsab_used;
776 linpool *nhpool; /* Linpool used for next hops computed in SPF */
777 u32 router_id;
778 };
779
780 struct ospf_iface_patt
781 {
782 struct iface_patt i;
783 u32 type;
784 u32 stub;
785 u32 cost;
786 u32 helloint;
787 u32 rxmtint;
788 u32 pollint;
789 u32 waitint;
790 u32 deadc;
791 u32 deadint;
792 u32 inftransdelay;
793 u32 priority;
794 u32 strictnbma;
795 list nbma_list;
796 u32 voa;
797 u32 vid;
798 u16 rxbuf;
799 u8 check_link;
800 u8 ecmp_weight;
801 #define OSPF_RXBUF_NORMAL 0
802 #define OSPF_RXBUF_LARGE 1
803 #define OSPF_RXBUF_MINSIZE 256 /* Minimal allowed size */
804 u32 autype; /* Not really used in OSPFv3 */
805 #define OSPF_AUTH_NONE 0
806 #define OSPF_AUTH_SIMPLE 1
807 #define OSPF_AUTH_CRYPT 2
808 #define OSPF_AUTH_CRYPT_SIZE 16
809
810 #ifdef OSPFv2
811 list *passwords;
812 #endif
813
814 #ifdef OSPFv3
815 u8 instance_id;
816 #endif
817 };
818
819 int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
820 struct linpool *pool);
821 struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
822 void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
823 void schedule_rt_lsa(struct ospf_area *oa);
824 void schedule_rtcalc(struct proto_ospf *po);
825 void schedule_net_lsa(struct ospf_iface *ifa);
826
827 struct ospf_area *ospf_find_area(struct proto_ospf *po, u32 aid);
828 static inline struct ospf_area *ospf_main_area(struct proto_ospf *po)
829 { return (po->areano == 1) ? HEAD(po->area_list) : po->backbone; }
830
831 static inline int oa_is_stub(struct ospf_area *oa)
832 { return (oa->options & (OPT_E | OPT_N)) == 0; }
833 static inline int oa_is_ext(struct ospf_area *oa)
834 { return oa->options & OPT_E; }
835 static inline int oa_is_nssa(struct ospf_area *oa)
836 { return oa->options & OPT_N; }
837
838
839 #ifdef OSPFv3
840 void schedule_link_lsa(struct ospf_iface *ifa);
841 #else
842 static inline void schedule_link_lsa(struct ospf_iface *ifa UNUSED) {}
843 #endif
844
845 void ospf_sh_neigh(struct proto *p, char *iff);
846 void ospf_sh(struct proto *p);
847 void ospf_sh_iface(struct proto *p, char *iff);
848 void ospf_sh_state(struct proto *p, int verbose, int reachable);
849 void ospf_sh_lsadb(struct proto *p);
850
851
852 #define EA_OSPF_METRIC1 EA_CODE(EAP_OSPF, 0)
853 #define EA_OSPF_METRIC2 EA_CODE(EAP_OSPF, 1)
854 #define EA_OSPF_TAG EA_CODE(EAP_OSPF, 2)
855 #define EA_OSPF_ROUTER_ID EA_CODE(EAP_OSPF, 3)
856
857 #include "proto/ospf/rt.h"
858 #include "proto/ospf/hello.h"
859 #include "proto/ospf/packet.h"
860 #include "proto/ospf/iface.h"
861 #include "proto/ospf/neighbor.h"
862 #include "proto/ospf/topology.h"
863 #include "proto/ospf/dbdes.h"
864 #include "proto/ospf/lsreq.h"
865 #include "proto/ospf/lsupd.h"
866 #include "proto/ospf/lsack.h"
867 #include "proto/ospf/lsalib.h"
868
869 #endif /* _BIRD_OSPF_H_ */