]> git.ipfire.org Git - thirdparty/bird.git/blame - proto/ospf/ospf.h
RT calculation strongly simplified. Now, I don't need any
[thirdparty/bird.git] / proto / ospf / ospf.h
CommitLineData
c1f8dc91
OF
1/*
2 * BIRD -- OSPF
3 *
4 * (c) 1999 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
4364b47e
OF
12#define LOCAL_DEBUG
13
6d2b3211
OF
14#define SIPH 64 /* FIXME Size Of IP header */
15
4364b47e
OF
16#include "nest/bird.h"
17
18#include "lib/checksum.h"
6ba36f06
MM
19#include "lib/ip.h"
20#include "lib/lists.h"
30147b89 21#include "lib/slists.h"
6ba36f06
MM
22#include "lib/socket.h"
23#include "lib/timer.h"
24#include "lib/resource.h"
25#include "nest/protocol.h"
26#include "nest/iface.h"
4364b47e
OF
27#include "nest/route.h"
28#include "conf/conf.h"
6ba36f06 29
5b1a92e6 30#define OSPF_PROTO 89
aec76c6e 31#ifndef IPV6
296ecb56 32#define OSPF_VERSION 2
5b1a92e6
OF
33#define AllSPFRouters ipa_from_u32(0xe0000005) /* 224.0.0.5 */
34#define AllDRouters ipa_from_u32(0xe0000006) /* 224.0.0.6 */
aec76c6e 35#else
6376a961 36#error Multicast address not defined in IPv6
aec76c6e
OF
37#endif
38
15087574 39
921a93f2 40#define LSREFRESHTIME 1800 /* 30 minutes */
15087574
OF
41#define MINLSINTERVAL 5
42#define MINLSARRIVAL 1
15087574
OF
43#define LSINFINITY 0xffffff
44/*#define DEFAULTDES 0.0.0.0 FIXME: How to define it? */
15087574 45
c1f8dc91
OF
46struct ospf_config {
47 struct proto_config c;
b11d8a4f 48 u32 area; /* FIXME: Area ID !!! This is wrong !!!
aec76c6e 49 * Should respect interface */
c1f8dc91
OF
50};
51
5b1a92e6 52struct ospf_iface {
b11d8a4f 53 node n;
f7103dfc 54 struct proto_ospf *proto;
b11d8a4f 55 struct iface *iface; /* Nest's iface */
30147b89
OF
56 struct ospf_area *oa;
57 u32 an; /* Area number */
1af66415 58 sock *hello_sk; /* Hello socket */
2a092594 59 sock *dr_sk; /* For states DR or BACKUP */
1af66415 60 sock *ip_sk; /* IP socket (for DD ...) */
75b84c34 61 list neigh_list; /* List of neigbours */
5b1a92e6 62 u16 cost; /* Cost of iface */
2c1d1cc7
OF
63 u16 rxmtint; /* number of seconds between LSA retransmissions */
64 u16 iftransdelay; /* The estimated number of seconds it takes to
5b1a92e6
OF
65 transmit a Link State Update Packet over this
66 interface. LSAs contained in the update */
67 u8 priority; /* A router priority for DR election */
68 u16 helloint; /* number of seconds between hello sending */
96f1b8ba 69 u16 waitint; /* number of sec before changing state from wait */
35ff423d 70 u32 deadc; /* after "deadint" missing hellos is router dead */
5b1a92e6
OF
71 u16 autype;
72 u8 aukey[8];
73 u8 options;
aec76c6e
OF
74 ip_addr drip; /* Designated router */
75 u32 drid;
76 ip_addr bdrip; /* Backup DR */
77 u32 bdrid;
2c1d1cc7 78 u8 type; /* OSPF view of type */
96f1b8ba 79#define OSPF_IT_BCAST 0
4c630a6d
OF
80#define OSPF_IT_NBMA 1
81#define OSPF_IT_PTP 2
96f1b8ba 82#define OSPF_IT_VLINK 3
2c1d1cc7 83 u8 state; /* Interface state machine */
96f1b8ba
OF
84#define OSPF_IS_DOWN 0 /* Not working */
85#define OSPF_IS_LOOP 1 /* Should never happen */
86#define OSPF_IS_WAITING 2 /* Waiting for Wait timer */
87#define OSPF_IS_PTP 3 /* PTP operational */
88#define OSPF_IS_DROTHER 4 /* I'm on BCAST or NBMA and I'm not DR */
89#define OSPF_IS_BACKUP 5 /* I'm BDR */
90#define OSPF_IS_DR 6 /* I'm DR */
65112dd2
OF
91 timer *wait_timer; /* WAIT timer */
92 timer *hello_timer; /* HELLOINT timer */
5b1a92e6
OF
93/* Default values for interface parameters */
94#define COST_D 10
95#define RXMTINT_D 5
96#define IFTRANSDELAY_D 1
4c630a6d 97#define PRIORITY_D 1
5b1a92e6 98#define HELLOINT_D 10
35ff423d 99#define DEADC_D 4
96f1b8ba
OF
100#define WAIT_DMH 3 /* Value of Wait timer - not found it in RFC
101 * - using 3*HELLO
1af66415 102 */
5b1a92e6
OF
103};
104
296ecb56
OF
105struct ospf_packet {
106 u8 version;
107 u8 type;
108#define HELLO 1 /* Hello */
109#define DBDES 2 /* Database description */
110#define LSREQ 3 /* Link state request */
111#define LSUPD 4 /* Link state update */
112#define LSACK 5 /* Link state acknowledgement */
113 u16 length;
114 u32 routerid;
115 u32 areaid;
2c971094 116#define BACKBONE 0
296ecb56
OF
117 u16 checksum;
118 u16 autype;
119 u8 authetication[8];
120};
121
122struct ospf_hello_packet {
67ff9130
OF
123 struct ospf_packet ospf_packet;
124 ip_addr netmask;
35ff423d 125 u16 helloint;
296ecb56
OF
126 u8 options;
127 u8 priority;
128 u32 deadint;
129 u32 dr;
130 u32 bdr;
131};
132
04c6319a
OF
133struct immsb {
134 u8 ms:1;
135 u8 m:1;
136 u8 i:1;
137 u8 padding:5;
138};
139
140union imms {
141 u8 byte;
142 struct immsb bit;
143};
144
2c1d1cc7 145struct ospf_dbdes_packet {
1af66415
OF
146 struct ospf_packet ospf_packet;
147 u16 iface_mtu;
2c1d1cc7 148 u8 options;
04c6319a 149 union imms imms; /* I, M, MS bits */
2c1d1cc7
OF
150#define DBDES_MS 1
151#define DBDES_M 2
152#define DBDES_I 4
153 u32 ddseq;
1af66415
OF
154};
155
ce17d4c1
OF
156
157struct ospf_lsa_header {
158 u16 age; /* LS Age */
159#define LSA_MAXAGE 3600 /* 1 hour */
160#define LSA_CHECKAGE 300 /* 5 minutes */
161#define LSA_MAXAGEDIFF 900 /* 15 minutes */
2c1d1cc7 162 u8 options;
ce17d4c1
OF
163 u8 type;
164 u32 id;
165#define LSA_T_RT 1
166#define LSA_T_NET 2
167#define LSA_T_SUM_NET 3
168#define LSA_T_SUM_RT 4
169#define LSA_T_EXT 5
170 u32 rt; /* Advertising router */
910e557b 171 s32 sn; /* LS Sequence number */
ce17d4c1
OF
172#define LSA_INITSEQNO 0x80000001
173#define LSA_MAXSEQNO 0x7fffffff
2c1d1cc7 174 u16 checksum;
ce17d4c1
OF
175 u16 length;
176};
177
178struct ospf_lsa_rt {
179 u8 VEB;
180#define LSA_RT_V 5
181#define LSA_RT_E 6
182#define LSA_RT_B 7
183 u8 padding;
184 u16 links;
185};
186
187struct ospf_lsa_rt_link {
188 u32 id;
189 u32 data;
190 u8 type;
191#define LSART_PTP 1
192#define LSART_NET 2
193#define LSART_STUB 3
194#define LSART_VLNK 4
195 u8 notos;
196 u16 metric;
197};
198
199struct ospf_lsa_rt_link_tos { /* Actually we ignore TOS. This is useless */
200 u8 tos;
201 u8 padding;
202 u16 metric;
2c1d1cc7
OF
203};
204
dfa9a53a
OF
205struct ospf_lsa_net {
206 u32 netmask;
207};
208
ce17d4c1
OF
209struct ospf_lsa_summ {
210 u32 netmask;
211};
212
213struct ospf_lsa_summ_net {
214 u8 tos;
215 u8 padding;
216 u16 metric;
217};
218
219struct ospf_lsa_ext {
220 u32 netmask;
221};
222
223struct ospf_lsa_ext_tos {
224 u8 etos;
225 u8 padding;
f45fd316 226 u16 metric;
ce17d4c1
OF
227 u32 fwaddr;
228 u32 tag;
229};
230
6d2b3211
OF
231struct ospf_lsreq_packet {
232 struct ospf_packet ospf_packet;
233};
234
235struct ospf_lsreq_header {
236 u16 padd1;
237 u8 padd2;
238 u8 type;
239 u32 id;
240 u32 rt; /* Advertising router */
241};
242
f45fd316
OF
243struct l_lsr_head {
244 node n;
245 struct ospf_lsreq_header lsh;
246};
247
de769e24
OF
248struct ospf_lsupd_packet {
249 struct ospf_packet ospf_packet;
250 u32 lsano; /* Number of LSA's */
251};
252
253struct ospf_lsack_packet {
254 struct ospf_packet ospf_packet;
255};
256
257
c76674f0
OF
258struct ospf_neighbor
259{
e83dc0d7 260 node n;
903a3f39 261 struct ospf_iface *ifa;
2c1d1cc7 262 u8 state;
c76674f0 263#define NEIGHBOR_DOWN 0
cd70d934
OF
264#define NEIGHBOR_ATTEMPT 1
265#define NEIGHBOR_INIT 2
266#define NEIGHBOR_2WAY 3
c76674f0 267#define NEIGHBOR_EXSTART 4
903a3f39
OF
268#define NEIGHBOR_EXCHANGE 5
269#define NEIGHBOR_LOADING 6
270#define NEIGHBOR_FULL 7
c76674f0 271 timer *inactim; /* Inactivity timer */
04c6319a 272 union imms imms; /* I, M, Master/slave received */
c2250f91
OF
273 u32 dds; /* DD Sequence number being sent */
274 u32 ddr; /* last Dat Des packet received */
04c6319a 275 union imms myimms; /* I, M Master/slave */
c76674f0 276 u32 rid; /* Router ID */
986e3413 277 ip_addr ip; /* IP of it's interface */
2c1d1cc7 278 u8 priority; /* Priority */
986e3413 279 u8 options; /* Options received */
c76674f0
OF
280 u32 dr; /* Neigbour's idea of DR */
281 u32 bdr; /* Neigbour's idea of BDR */
e3121112 282 u8 adj; /* built adjacency? */
30147b89 283 siterator dbsi; /* Database summary list iterator */
95eb1dba
OF
284 slist lsrql; /* Link state request */
285 struct top_graph *lsrqh; /* LSA graph */
30147b89
OF
286 siterator lsrqi;
287 slist lsrtl; /* Link state retransmission list */
288 siterator lsrti;
921a93f2 289 struct top_graph *lsrth;
30147b89 290 void *ldbdes; /* Last database description packet */
6d2b3211
OF
291 timer *rxmt_timer; /* RXMT timer */
292 timer *lsrr_timer; /* Link state requiest retransmition timer */
67315ef6
OF
293 list ackl;
294 timer *ackd_timer; /* Delayed ack timer */
c76674f0
OF
295};
296
96f1b8ba
OF
297/* Definitions for interface state machine */
298#define ISM_UP 0 /* Interface Up */
299#define ISM_WAITF 1 /* Wait timer fired */
300#define ISM_BACKS 2 /* Backup seen */
301#define ISM_NEICH 3 /* Neighbor change */
302#define ISM_LOOP 4 /* Loop indicated */
303#define ISM_UNLOOP 5 /* Unloop indicated */
304#define ISM_DOWN 6 /* Interface down */
305
306/* Definitions for neighbor state machine */
307#define INM_HELLOREC 0 /* Hello Received */
308#define INM_START 1 /* Neighbor start - for NBMA */
309#define INM_2WAYREC 2 /* 2-Way received */
310#define INM_NEGDONE 3 /* Negotiation done */
311#define INM_EXDONE 4 /* Exchange done */
312#define INM_BADLSREQ 5 /* Bad LS Request */
313#define INM_LOADDONE 6 /* Load done */
314#define INM_ADJOK 7 /* AdjOK? */
315#define INM_SEQMIS 8 /* Sequence number mismatch */
316#define INM_1WAYREC 9 /* 1-Way */
6ba36f06 317#define INM_KILLNBR 10 /* Kill Neighbor */
96f1b8ba
OF
318#define INM_INACTTIM 11 /* Inactivity timer */
319#define INM_LLDOWN 12 /* Line down */
320
15087574 321struct ospf_area {
8496b2e4 322 node n;
15087574
OF
323 u32 areaid;
324 struct top_graph *gr; /* LSA graph */
30147b89 325 slist lsal; /* List of all LSA's */
de30342f 326 struct top_hash_entry *rt; /* My own router LSA */
dfa9a53a
OF
327 list cand; /* List of candidates for RT calc. */
328 u8 stub;
329 u8 trcap; /* Transit capability? */
15087574
OF
330};
331
4364b47e
OF
332struct proto_ospf {
333 struct proto proto;
334 list iface_list; /* Interfaces we really use */
8496b2e4 335 list area_list;
15087574 336 int areano; /* Number of area I belong to */
6ba36f06
MM
337};
338
4364b47e
OF
339static int ospf_start(struct proto *p);
340static void ospf_dump(struct proto *p);
341static struct proto *ospf_init(struct proto_config *c);
342static void ospf_preconfig(struct protocol *p, struct config *c);
343static void ospf_postconfig(struct proto_config *c);
344
345#include "proto/ospf/hello.h"
346#include "proto/ospf/packet.h"
347#include "proto/ospf/iface.h"
348#include "proto/ospf/neighbor.h"
349#include "proto/ospf/topology.h"
350#include "proto/ospf/dbdes.h"
6d2b3211 351#include "proto/ospf/lsreq.h"
f45fd316
OF
352#include "proto/ospf/lsupd.h"
353#include "proto/ospf/lsack.h"
354#include "proto/ospf/lsalib.h"
dfa9a53a 355#include "proto/ospf/rt.h"
6ba36f06 356
c1f8dc91 357#endif /* _BIRD_OSPF_H_ */