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