]> git.ipfire.org Git - thirdparty/bird.git/blame - proto/ospf/ospf.h
Changes OSPF to generate stub networks for non-primary addresses.
[thirdparty/bird.git] / proto / ospf / ospf.h
CommitLineData
c1f8dc91
OF
1/*
2 * BIRD -- OSPF
3 *
e300066d 4 * (c) 1999--2005 Ondrej Filip <feela@network.cz>
c1f8dc91
OF
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
273fd2c1 12#define MAXNETS 10
e6ea2e37 13#define OSPF_VLINK_MTU 576 /* RFC2328 - A.1 */
94c42054
OF
14#define OSPF_MAX_PKT_SIZE 65536
15 /*
e300066d
OF
16 * RFC 2328 says, maximum packet size is 65535
17 * This could be too much for small systems, so I
18 * normally allocate 2*mtu - (I found one cisco
19 * sending packets mtu+16)
20 */
f14032ef
OF
21#ifdef LOCAL_DEBUG
22#define OSPF_FORCE_DEBUG 1
23#else
24#define OSPF_FORCE_DEBUG 0
25#endif
26#define OSPF_TRACE(flags, msg, args...) do { if ((p->debug & flags) || OSPF_FORCE_DEBUG) \
27 log(L_TRACE "%s: " msg, p->name , ## args ); } while(0)
6d2b3211 28
8298d780
OZ
29#define OSPF_PACKET(dumpfn, buffer, msg, args...) \
30do { if ((p->debug & D_PACKETS) || OSPF_FORCE_DEBUG) \
31{ log(L_TRACE "%s: " msg, p->name, ## args ); dumpfn(p, buffer); } } while(0)
32
33
4364b47e
OF
34#include "nest/bird.h"
35
36#include "lib/checksum.h"
6ba36f06
MM
37#include "lib/ip.h"
38#include "lib/lists.h"
30147b89 39#include "lib/slists.h"
6ba36f06
MM
40#include "lib/socket.h"
41#include "lib/timer.h"
42#include "lib/resource.h"
43#include "nest/protocol.h"
44#include "nest/iface.h"
4364b47e 45#include "nest/route.h"
a783e259 46#include "nest/cli.h"
f8f1e1f1 47#include "nest/locks.h"
4364b47e 48#include "conf/conf.h"
d345cda5 49#include "lib/string.h"
6ba36f06 50
5b1a92e6 51#define OSPF_PROTO 89
aec76c6e 52#ifndef IPV6
296ecb56 53#define OSPF_VERSION 2
5b1a92e6
OF
54#define AllSPFRouters ipa_from_u32(0xe0000005) /* 224.0.0.5 */
55#define AllDRouters ipa_from_u32(0xe0000006) /* 224.0.0.6 */
c6c56264 56#define DEFAULTDES ipa_from_u32(0)
aec76c6e 57#else
d631698e 58#error OSPF for IPv6 is not implemented (mail to Feela <feela@network.cz>)
aec76c6e
OF
59#endif
60
15087574 61
921a93f2 62#define LSREFRESHTIME 1800 /* 30 minutes */
15087574
OF
63#define MINLSINTERVAL 5
64#define MINLSARRIVAL 1
98ac6176 65#define LSINFINITY 0xffffff
d631698e 66
62eee823 67#define DEFAULT_OSPFTICK 1
3b16080c 68#define DEFAULT_RFC1583 0 /* compatibility with rfc1583 */
8d94a524 69#define DEFAULT_STUB_COST 1000
d631698e 70
15087574 71
2e10a170
OF
72struct ospf_config
73{
c1f8dc91 74 struct proto_config c;
b8f17cf1 75 unsigned tick;
3fa5722d 76 int rfc1583;
b36a0a79
OF
77 list area_list;
78};
79
2e10a170
OF
80struct nbma_node
81{
e5b5d18c
OF
82 node n;
83 ip_addr ip;
a190e720 84 int eligible;
e5b5d18c
OF
85};
86
98ac6176 87struct area_net_config
2e10a170 88{
c926eee7 89 node n;
66261211 90 struct prefix px;
c926eee7 91 int hidden;
98ac6176
OF
92};
93
94struct area_net
95{
96 struct fib_node fn;
97 int hidden;
66261211 98 int active;
60e04f04 99 u32 metric;
c926eee7
OF
100};
101
2e10a170
OF
102struct ospf_area_config
103{
b36a0a79
OF
104 node n;
105 u32 areaid;
106 int stub;
89d6782d 107 list patt_list;
3b16080c 108 list vlink_list;
c926eee7 109 list net_list;
c1f8dc91
OF
110};
111
621ccdfe
OF
112struct obits
113{
114#ifdef _BIG_ENDIAN
115 u8 unused2:2;
116 u8 dc:1;
117 u8 ea:1;
118 u8 np:1;
119 u8 mc:1;
120 u8 e:1;
121 u8 unused1:1;
122#else
123 u8 unused1:1;
124 u8 e:1;
125 u8 mc:1;
126 u8 np:1;
127 u8 ea:1;
128 u8 dc:1;
129 u8 unused2:2;
130#endif
131};
132
133union options
134{
135 u8 byte;
136 struct obits bit;
137};
138
139
2e10a170
OF
140struct ospf_iface
141{
b11d8a4f 142 node n;
2e10a170 143 struct iface *iface; /* Nest's iface */
30147b89 144 struct ospf_area *oa;
f8f1e1f1 145 struct object_lock *lock;
2e10a170
OF
146 sock *hello_sk; /* Hello socket */
147 sock *dr_sk; /* For states DR or BACKUP */
148 sock *ip_sk; /* IP socket (for DD ...) */
149 list neigh_list; /* List of neigbours */
9912fa51 150 u32 cost; /* Cost of iface */
7df86c25
OF
151 u32 waitint; /* number of sec before changing state from wait */
152 u32 rxmtint; /* number of seconds between LSA retransmissions */
153 u32 pollint; /* Poll interval */
d8c7d9e8 154 u32 dead; /* after "deadint" missing hellos is router dead */
98ac6176
OF
155 u32 vid; /* Id of peer of virtual link */
156 ip_addr vip; /* IP of peer of virtual link */
157 struct ospf_area *voa; /* Area wich the vlink goes through */
9912fa51
OF
158 u16 inftransdelay; /* The estimated number of seconds it takes to
159 transmit a Link State Update Packet over this
160 interface. LSAs contained in the update */
5b1a92e6 161 u16 autype;
621ccdfe 162 u16 helloint; /* number of seconds between hello sending */
3e2bd0f1 163 list *passwords;
024c310b
OZ
164 u32 csn; /* Last used crypt seq number */
165 bird_clock_t csn_use; /* Last time when packet with that CSN was sent */
2e10a170 166 ip_addr drip; /* Designated router */
aec76c6e 167 u32 drid;
2e10a170 168 ip_addr bdrip; /* Backup DR */
aec76c6e 169 u32 bdrid;
2e10a170 170 u8 type; /* OSPF view of type */
96f1b8ba 171#define OSPF_IT_BCAST 0
4c630a6d
OF
172#define OSPF_IT_NBMA 1
173#define OSPF_IT_PTP 2
96f1b8ba 174#define OSPF_IT_VLINK 3
aaaff776 175#define OSPF_IT_UNDEF 4
2e10a170
OF
176 u8 strictnbma; /* Can I talk with unknown neighbors? */
177 u8 stub; /* Inactive interface */
2e10a170
OF
178#define OSPF_I_OK 0 /* Everything OK */
179#define OSPF_I_MC 1 /* I didn't open MC socket */
180#define OSPF_I_IP 2 /* I didn't open IP socet */
181 u8 state; /* Interface state machine */
96f1b8ba
OF
182#define OSPF_IS_DOWN 0 /* Not working */
183#define OSPF_IS_LOOP 1 /* Should never happen */
184#define OSPF_IS_WAITING 2 /* Waiting for Wait timer */
185#define OSPF_IS_PTP 3 /* PTP operational */
186#define OSPF_IS_DROTHER 4 /* I'm on BCAST or NBMA and I'm not DR */
187#define OSPF_IS_BACKUP 5 /* I'm BDR */
188#define OSPF_IS_DR 6 /* I'm DR */
65112dd2
OF
189 timer *wait_timer; /* WAIT timer */
190 timer *hello_timer; /* HELLOINT timer */
a190e720 191 timer *poll_timer; /* Poll Interval - for NBMA */
5b1a92e6
OF
192/* Default values for interface parameters */
193#define COST_D 10
194#define RXMTINT_D 5
249fdef7 195#define INFTRANSDELAY_D 1
4c630a6d 196#define PRIORITY_D 1
5b1a92e6 197#define HELLOINT_D 10
a190e720 198#define POLLINT_D 20
35ff423d 199#define DEADC_D 4
2e10a170
OF
200#define WAIT_DMH 4 /* Value of Wait timer - not found it in RFC
201 * - using 4*HELLO
202 */
9bc1808a 203 struct top_hash_entry *nlsa; /* Originated net lsa */
2e10a170
OF
204 int orignet; /* Schedule network LSA origination */
205 int fadj; /* Number of full adjacent neigh */
e5b5d18c 206 list nbma_list;
621ccdfe
OF
207 u8 priority; /* A router priority for DR election */
208 u8 ioprob;
94c42054 209 u32 rxbuf;
5b1a92e6
OF
210};
211
3e2bd0f1
OF
212struct ospf_md5
213{
214 u16 zero;
215 u8 keyid;
216 u8 len;
217 u32 csn;
218};
219
220union ospf_auth
221{
222 u8 password[8];
223 struct ospf_md5 md5;
224};
225
2e10a170
OF
226struct ospf_packet
227{
296ecb56
OF
228 u8 version;
229 u8 type;
2e10a170
OF
230#define HELLO_P 1 /* Hello */
231#define DBDES_P 2 /* Database description */
232#define LSREQ_P 3 /* Link state request */
233#define LSUPD_P 4 /* Link state update */
234#define LSACK_P 5 /* Link state acknowledgement */
296ecb56
OF
235 u16 length;
236 u32 routerid;
237 u32 areaid;
2c971094 238#define BACKBONE 0
296ecb56
OF
239 u16 checksum;
240 u16 autype;
3e2bd0f1 241 union ospf_auth u;
296ecb56
OF
242};
243
2e10a170
OF
244struct ospf_hello_packet
245{
67ff9130
OF
246 struct ospf_packet ospf_packet;
247 ip_addr netmask;
35ff423d 248 u16 helloint;
296ecb56
OF
249 u8 options;
250 u8 priority;
251 u32 deadint;
423230f2
OF
252 ip_addr dr;
253 ip_addr bdr;
296ecb56
OF
254};
255
2e10a170
OF
256struct immsb
257{
c11007bc
OF
258#ifdef _BIG_ENDIAN
259 u8 padding:5;
260 u8 i:1;
261 u8 m:1;
262 u8 ms:1;
263#else
04c6319a
OF
264 u8 ms:1;
265 u8 m:1;
266 u8 i:1;
267 u8 padding:5;
c11007bc 268#endif
04c6319a
OF
269};
270
2e10a170
OF
271union imms
272{
04c6319a
OF
273 u8 byte;
274 struct immsb bit;
275};
276
2e10a170
OF
277struct ospf_dbdes_packet
278{
1af66415
OF
279 struct ospf_packet ospf_packet;
280 u16 iface_mtu;
2c1d1cc7 281 u8 options;
04c6319a 282 union imms imms; /* I, M, MS bits */
2c1d1cc7
OF
283#define DBDES_MS 1
284#define DBDES_M 2
285#define DBDES_I 4
286 u32 ddseq;
1af66415
OF
287};
288
ce17d4c1 289
2e10a170
OF
290struct ospf_lsa_header
291{
292 u16 age; /* LS Age */
293#define LSA_MAXAGE 3600 /* 1 hour */
294#define LSA_CHECKAGE 300 /* 5 minutes */
295#define LSA_MAXAGEDIFF 900 /* 15 minutes */
2c1d1cc7 296 u8 options;
ce17d4c1
OF
297 u8 type;
298 u32 id;
299#define LSA_T_RT 1
300#define LSA_T_NET 2
301#define LSA_T_SUM_NET 3
302#define LSA_T_SUM_RT 4
303#define LSA_T_EXT 5
2e10a170
OF
304 u32 rt; /* Advertising router */
305 s32 sn; /* LS Sequence number */
ce17d4c1
OF
306#define LSA_INITSEQNO 0x80000001
307#define LSA_MAXSEQNO 0x7fffffff
2c1d1cc7 308 u16 checksum;
2e10a170 309 u16 length;
ce17d4c1
OF
310};
311
2e10a170
OF
312struct vebb
313{
1a61882d
OF
314#ifdef _BIG_ENDIAN
315 u8 padding:5;
316 u8 v:1;
317 u8 e:1;
318 u8 b:1;
319#else
fdb19982
OF
320 u8 b:1;
321 u8 e:1;
322 u8 v:1;
323 u8 padding:5;
1a61882d 324#endif
fdb19982
OF
325};
326
2e10a170
OF
327union veb
328{
fdb19982
OF
329 u8 byte;
330 struct vebb bit;
331};
332
2e10a170
OF
333struct ospf_lsa_rt
334{
fdb19982 335 union veb veb;
ce17d4c1
OF
336 u8 padding;
337 u16 links;
338};
339
2e10a170
OF
340struct ospf_lsa_rt_link
341{
ce17d4c1
OF
342 u32 id;
343 u32 data;
344 u8 type;
345#define LSART_PTP 1
346#define LSART_NET 2
347#define LSART_STUB 3
348#define LSART_VLNK 4
349 u8 notos;
350 u16 metric;
351};
352
2e10a170
OF
353struct ospf_lsa_rt_link_tos
354{ /* Actually we ignore TOS. This is useless */
ce17d4c1
OF
355 u8 tos;
356 u8 padding;
357 u16 metric;
2c1d1cc7
OF
358};
359
2e10a170
OF
360struct ospf_lsa_net
361{
c6c56264 362 ip_addr netmask;
dfa9a53a
OF
363};
364
98ac6176 365struct ospf_lsa_sum
2e10a170 366{
c6c56264 367 ip_addr netmask;
ce17d4c1
OF
368};
369
98ac6176
OF
370
371struct ospf_lsa_ext
2e10a170 372{
98ac6176
OF
373 ip_addr netmask;
374};
375
376struct ospf_lsa_ext_etos
377{
378#ifdef _BIG_ENDIAN
379 u8 ebit:1;
380 u8 tos:7;
381 u8 padding1;
382 u16 padding2;
383#else
384 u16 padding2;
385 u8 padding1;
386 u8 tos:7;
387 u8 ebit:1;
388#endif
389};
390
391#define METRIC_MASK 0x00FFFFFF
392struct ospf_lsa_sum_tos
393{
394#ifdef _BIG_ENDIAN
ce17d4c1 395 u8 tos;
98ac6176
OF
396 u8 padding1;
397 u16 padding2;
398#else
399 u16 padding2;
400 u8 padding1;
401 u8 tos;
402#endif
ce17d4c1
OF
403};
404
98ac6176 405union ospf_lsa_sum_tm
2e10a170 406{
98ac6176
OF
407 struct ospf_lsa_sum_tos tos;
408 u32 metric;
409};
410
411union ospf_lsa_ext_etm
412{
413 struct ospf_lsa_ext_etos etos;
414 u32 metric;
ce17d4c1
OF
415};
416
2e10a170
OF
417struct ospf_lsa_ext_tos
418{
98ac6176 419 union ospf_lsa_ext_etm etm;
65a9c571 420 ip_addr fwaddr;
ce17d4c1
OF
421 u32 tag;
422};
423
2e10a170
OF
424struct ospf_lsreq_packet
425{
6d2b3211
OF
426 struct ospf_packet ospf_packet;
427};
428
2e10a170
OF
429struct ospf_lsreq_header
430{
6d2b3211
OF
431 u16 padd1;
432 u8 padd2;
433 u8 type;
434 u32 id;
2e10a170 435 u32 rt; /* Advertising router */
6d2b3211
OF
436};
437
2e10a170
OF
438struct l_lsr_head
439{
f45fd316
OF
440 node n;
441 struct ospf_lsreq_header lsh;
442};
443
2e10a170
OF
444struct ospf_lsupd_packet
445{
de769e24 446 struct ospf_packet ospf_packet;
2e10a170 447 u32 lsano; /* Number of LSA's */
de769e24
OF
448};
449
2e10a170
OF
450struct ospf_lsack_packet
451{
de769e24
OF
452 struct ospf_packet ospf_packet;
453};
454
455
c76674f0
OF
456struct ospf_neighbor
457{
e83dc0d7 458 node n;
035f6acb 459 pool *pool;
903a3f39 460 struct ospf_iface *ifa;
2c1d1cc7 461 u8 state;
c76674f0 462#define NEIGHBOR_DOWN 0
cd70d934
OF
463#define NEIGHBOR_ATTEMPT 1
464#define NEIGHBOR_INIT 2
465#define NEIGHBOR_2WAY 3
c76674f0 466#define NEIGHBOR_EXSTART 4
903a3f39
OF
467#define NEIGHBOR_EXCHANGE 5
468#define NEIGHBOR_LOADING 6
469#define NEIGHBOR_FULL 7
2e10a170 470 timer *inactim; /* Inactivity timer */
04c6319a 471 union imms imms; /* I, M, Master/slave received */
2e10a170
OF
472 u32 dds; /* DD Sequence number being sent */
473 u32 ddr; /* last Dat Des packet received */
04c6319a 474 union imms myimms; /* I, M Master/slave */
2e10a170
OF
475 u32 rid; /* Router ID */
476 ip_addr ip; /* IP of it's interface */
477 u8 priority; /* Priority */
478 u8 options; /* Options received */
479 ip_addr dr; /* Neigbour's idea of DR */
480 ip_addr bdr; /* Neigbour's idea of BDR */
481 u8 adj; /* built adjacency? */
482 siterator dbsi; /* Database summary list iterator */
483 slist lsrql; /* Link state request */
484 struct top_graph *lsrqh; /* LSA graph */
30147b89 485 siterator lsrqi;
2e10a170 486 slist lsrtl; /* Link state retransmission list */
30147b89 487 siterator lsrti;
921a93f2 488 struct top_graph *lsrth;
2e10a170
OF
489 void *ldbdes; /* Last database description packet */
490 timer *rxmt_timer; /* RXMT timer */
c76ba51a
OF
491 list ackl[2];
492#define ACKL_DIRECT 0
493#define ACKL_DELAY 1
2e10a170 494 timer *ackd_timer; /* Delayed ack timer */
3e2bd0f1 495 u32 csn; /* Last received crypt seq number (for MD5) */
c76674f0
OF
496};
497
96f1b8ba 498/* Definitions for interface state machine */
2e10a170
OF
499#define ISM_UP 0 /* Interface Up */
500#define ISM_WAITF 1 /* Wait timer fired */
501#define ISM_BACKS 2 /* Backup seen */
502#define ISM_NEICH 3 /* Neighbor change */
503#define ISM_LOOP 4 /* Loop indicated */
504#define ISM_UNLOOP 5 /* Unloop indicated */
505#define ISM_DOWN 6 /* Interface down */
96f1b8ba
OF
506
507/* Definitions for neighbor state machine */
2e10a170
OF
508#define INM_HELLOREC 0 /* Hello Received */
509#define INM_START 1 /* Neighbor start - for NBMA */
510#define INM_2WAYREC 2 /* 2-Way received */
511#define INM_NEGDONE 3 /* Negotiation done */
512#define INM_EXDONE 4 /* Exchange done */
513#define INM_BADLSREQ 5 /* Bad LS Request */
514#define INM_LOADDONE 6 /* Load done */
515#define INM_ADJOK 7 /* AdjOK? */
516#define INM_SEQMIS 8 /* Sequence number mismatch */
517#define INM_1WAYREC 9 /* 1-Way */
518#define INM_KILLNBR 10 /* Kill Neighbor */
519#define INM_INACTTIM 11 /* Inactivity timer */
520#define INM_LLDOWN 12 /* Line down */
521
522struct ospf_area
523{
8496b2e4 524 node n;
15087574 525 u32 areaid;
70a38319 526 int origrt; /* Rt lsa origination scheduled? */
de30342f 527 struct top_hash_entry *rt; /* My own router LSA */
dfa9a53a 528 list cand; /* List of candidates for RT calc. */
98ac6176 529 struct fib net_fib; /* Networks to advertise or not */
b36a0a79
OF
530 int stub;
531 int trcap; /* Transit capability? */
c45f48fb 532 struct proto_ospf *po;
98ac6176 533 struct fib rtr; /* Routing tables for routers */
621ccdfe 534 union options opt; /* RFC2328 - A.2 */
15087574
OF
535};
536
2e10a170
OF
537struct proto_ospf
538{
4364b47e 539 struct proto proto;
b8f17cf1
OF
540 timer *disp_timer; /* OSPF proto dispatcher */
541 unsigned tick;
86c84d76
OF
542 struct top_graph *gr; /* LSA graph */
543 slist lsal; /* List of all LSA's */
b8f17cf1 544 int calcrt; /* Routing table calculation scheduled? */
86c84d76 545 int cleanup; /* Should I cleanup after RT calculation? */
4364b47e 546 list iface_list; /* Interfaces we really use */
8496b2e4 547 list area_list;
15087574 548 int areano; /* Number of area I belong to */
98ac6176 549 struct fib rtf; /* Routing table */
fdb19982
OF
550 int rfc1583; /* RFC1583 compatibility */
551 int ebit; /* Did I originate any ext lsa? */
98ac6176 552 struct ospf_area *backbone; /* If exists */
3d15dcdb
OZ
553 void *lsab; /* LSA buffer used when originating router LSAs */
554 int lsab_size, lsab_used;
6ba36f06
MM
555};
556
2e10a170
OF
557struct ospf_iface_patt
558{
89d6782d 559 struct iface_patt i;
7df86c25
OF
560 u32 cost;
561 u32 helloint;
562 u32 rxmtint;
563 u32 pollint;
564 u32 inftransdelay;
565 u32 priority;
566 u32 waitint;
567 u32 deadc;
d8c7d9e8 568 u32 dead;
7df86c25
OF
569 u32 type;
570 u32 autype;
571 u32 strictnbma;
572 u32 stub;
98ac6176 573 u32 vid;
3e2bd0f1
OF
574#define OSPF_AUTH_NONE 0
575#define OSPF_AUTH_SIMPLE 1
576#define OSPF_AUTH_CRYPT 2
577#define OSPF_AUTH_CRYPT_SIZE 16
94c42054
OF
578 u32 rxbuf;
579#define OSPF_RXBUF_NORMAL 0
580#define OSPF_RXBUF_LARGE 1
581#define OSPF_RXBUF_MINSIZE 256 /* Minimal allowed size */
3e2bd0f1 582 list *passwords;
e5b5d18c 583 list nbma_list;
89d6782d
OF
584};
585
b8f17cf1 586int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
2e10a170 587 struct linpool *pool);
5919c66e
MM
588struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
589void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
70a38319 590void schedule_rt_lsa(struct ospf_area *oa);
b8f17cf1 591void schedule_rtcalc(struct proto_ospf *po);
b9ed99f7 592void schedule_net_lsa(struct ospf_iface *ifa);
c4f0f014 593void ospf_sh_neigh(struct proto *p, char *iff);
4ab4e977 594void ospf_sh(struct proto *p);
c4f0f014 595void ospf_sh_iface(struct proto *p, char *iff);
4364b47e 596
5919c66e
MM
597#define EA_OSPF_METRIC1 EA_CODE(EAP_OSPF, 0)
598#define EA_OSPF_METRIC2 EA_CODE(EAP_OSPF, 1)
599#define EA_OSPF_TAG EA_CODE(EAP_OSPF, 2)
600
98ac6176 601#include "proto/ospf/rt.h"
4364b47e
OF
602#include "proto/ospf/hello.h"
603#include "proto/ospf/packet.h"
604#include "proto/ospf/iface.h"
605#include "proto/ospf/neighbor.h"
606#include "proto/ospf/topology.h"
607#include "proto/ospf/dbdes.h"
6d2b3211 608#include "proto/ospf/lsreq.h"
f45fd316
OF
609#include "proto/ospf/lsupd.h"
610#include "proto/ospf/lsack.h"
611#include "proto/ospf/lsalib.h"
6ba36f06 612
c1f8dc91 613#endif /* _BIRD_OSPF_H_ */