Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (20.9 KB)

1 c1f8dc91 Ondrej Filip
/*
2
 *        BIRD -- OSPF
3
 *
4 e300066d Ondrej Filip
 *        (c) 1999--2005 Ondrej Filip <feela@network.cz>
5 c1f8dc91 Ondrej Filip
 *
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 273fd2c1 Ondrej Filip
#define MAXNETS 10
13 48e5f32d Ondrej Zajicek
#define OSPF_MIN_PKT_SIZE 256
14 79f561a1 Ondrej Zajicek
#define OSPF_MAX_PKT_SIZE 65535
15
16 f14032ef Ondrej Filip
#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 6d2b3211 Ondrej Filip
24 8298d780 Ondrej Zajicek
#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 4364b47e Ondrej Filip
#include "nest/bird.h"
30
31
#include "lib/checksum.h"
32 6ba36f06 Martin Mares
#include "lib/ip.h"
33
#include "lib/lists.h"
34 30147b89 Ondrej Filip
#include "lib/slists.h"
35 6ba36f06 Martin Mares
#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 4364b47e Ondrej Filip
#include "nest/route.h"
41 a783e259 Ondrej Filip
#include "nest/cli.h"
42 f8f1e1f1 Ondrej Filip
#include "nest/locks.h"
43 1ec52253 Ondrej Zajicek
#include "nest/bfd.h"
44 4364b47e Ondrej Filip
#include "conf/conf.h"
45 d345cda5 Ondrej Filip
#include "lib/string.h"
46 6ba36f06 Martin Mares
47 5b1a92e6 Ondrej Filip
#define OSPF_PROTO 89
48 c3226991 Ondrej Zajicek
49 aec76c6e Ondrej Filip
#ifndef IPV6
50 c3226991 Ondrej Zajicek
#define OSPFv2 1
51 296ecb56 Ondrej Filip
#define OSPF_VERSION 2
52 d5356072 Ondrej Zajicek
#define OSPF_VLINK_MTU 576                        /* RFC 2328 A.1 */
53 5b1a92e6 Ondrej Filip
#define AllSPFRouters ipa_from_u32(0xe0000005)        /* 224.0.0.5 */
54
#define AllDRouters ipa_from_u32(0xe0000006)        /* 224.0.0.6 */
55 aec76c6e Ondrej Filip
#else
56 c3226991 Ondrej Zajicek
#define OSPFv3 1
57
#define OSPF_VERSION 3
58 d5356072 Ondrej Zajicek
#define OSPF_VLINK_MTU 1280                        /* RFC 5340 A.1 */
59 c3226991 Ondrej Zajicek
#define AllSPFRouters _MI(0xFF020000, 0, 0, 5)        /* FF02::5 */
60
#define AllDRouters   _MI(0xFF020000, 0, 0, 6)        /* FF02::6 */
61 aec76c6e Ondrej Filip
#endif
62
63 15087574 Ondrej Filip
64 921a93f2 Ondrej Filip
#define LSREFRESHTIME 1800        /* 30 minutes */
65 15087574 Ondrej Filip
#define MINLSINTERVAL 5
66
#define MINLSARRIVAL 1
67 98ac6176 Ondrej Filip
#define LSINFINITY 0xffffff
68 d631698e Ondrej Filip
69 62eee823 Ondrej Filip
#define DEFAULT_OSPFTICK 1
70 3b16080c Ondrej Filip
#define DEFAULT_RFC1583 0        /* compatibility with rfc1583 */
71 8d94a524 Ondrej Filip
#define DEFAULT_STUB_COST 1000
72 57c574d8 Ondrej Zajicek
#define DEFAULT_ECMP_LIMIT 16
73 ed317862 Ondrej Zajicek
#define DEFAULT_TRANSINT 40
74 d631698e Ondrej Filip
75 48e5f32d Ondrej Zajicek
#define OSPF_VLINK_ID_OFFSET 0x80000000
76
77 15087574 Ondrej Filip
78 2e10a170 Ondrej Filip
struct ospf_config
79
{
80 c1f8dc91 Ondrej Filip
  struct proto_config c;
81 b8f17cf1 Ondrej Filip
  unsigned tick;
82 8e48831a Ondrej Zajicek
  byte rfc1583;
83 f623ab98 Ondrej Zajicek
  byte stub_router;
84 8e48831a Ondrej Zajicek
  byte abr;
85 57c574d8 Ondrej Zajicek
  int ecmp;
86 a7f23f58 Ondrej Zajicek
  list area_list;                /* list of struct ospf_area_config */
87
  list vlink_list;                /* list of struct ospf_iface_patt */
88 b36a0a79 Ondrej Filip
};
89
90 2e10a170 Ondrej Filip
struct nbma_node
91
{
92 e5b5d18c Ondrej Filip
  node n;
93
  ip_addr ip;
94 919f5411 Ondrej Zajicek
  byte eligible;
95
  byte found; 
96 e5b5d18c Ondrej Filip
};
97
98 98ac6176 Ondrej Filip
struct area_net_config
99 2e10a170 Ondrej Filip
{
100 c926eee7 Ondrej Filip
  node n;
101 66261211 Ondrej Filip
  struct prefix px;
102 c926eee7 Ondrej Filip
  int hidden;
103 ed317862 Ondrej Zajicek
  u32 tag;
104 98ac6176 Ondrej Filip
};
105
106
struct area_net
107
{
108
  struct fib_node fn;
109
  int hidden;
110 66261211 Ondrej Filip
  int active;
111 60e04f04 Ondrej Filip
  u32 metric;
112 ed317862 Ondrej Zajicek
  u32 tag;
113 c926eee7 Ondrej Filip
};
114
115 38675202 Ondrej Zajicek
struct ospf_stubnet_config
116
{
117
  node n;
118
  struct prefix px;
119
  int hidden, summary;
120
  u32 cost;
121
};
122
123 2e10a170 Ondrej Filip
struct ospf_area_config
124
{
125 b36a0a79 Ondrej Filip
  node n;
126
  u32 areaid;
127 2918e610 Ondrej Zajicek
  u32 default_cost;                /* Cost of default route for stub areas */
128 41b612c3 Ondrej Zajicek
  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 2918e610 Ondrej Zajicek
  u8 default_nssa;                /* Generate default NSSA route for NSSA+summary area */
132 4160a9dd Ondrej Zajicek
  u8 translator;                /* Translator role, for NSSA ABR */
133
  u32 transint;                        /* Translator stability interval */
134 89d6782d Ondrej Filip
  list patt_list;
135 8e48831a Ondrej Zajicek
  list net_list;                      /* List of aggregate networks for that area */
136 ed317862 Ondrej Zajicek
  list enet_list;                      /* List of aggregate external (NSSA) networks */
137 8e48831a Ondrej Zajicek
  list stubnet_list;                /* List of stub networks added to Router LSA */
138 c1f8dc91 Ondrej Filip
};
139
140 c3226991 Ondrej Zajicek
141
/* Option flags */
142
143
#define OPT_E        0x02
144
#define OPT_N        0x08
145
#define OPT_DC        0x20
146
147
#ifdef OSPFv2
148 41b612c3 Ondrej Zajicek
#define OPT_P        0x08                /* flags P and N share position, see NSSA RFC */
149 c3226991 Ondrej Zajicek
#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 41b612c3 Ondrej Zajicek
#define OPT_RT_NT (0x10 << 8)
156 621ccdfe Ondrej Filip
#endif
157
158 c3226991 Ondrej Zajicek
#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 621ccdfe Ondrej Filip
174
175 2e10a170 Ondrej Filip
struct ospf_iface
176
{
177 b11d8a4f Ondrej Filip
  node n;
178 48e5f32d Ondrej Zajicek
  struct iface *iface;                /* Nest's iface (NULL for vlinks) */
179 48cff379 Ondrej Zajicek
  struct ifa *addr;                /* IP prefix associated with that OSPF iface */
180 30147b89 Ondrej Filip
  struct ospf_area *oa;
181 8e48831a Ondrej Zajicek
  struct ospf_iface_patt *cf;
182 48e5f32d Ondrej Zajicek
  char *ifname;                        /* Interface name (iface->name), new one for vlinks */
183
184 d9e7e1b1 Ondrej Zajicek
  pool *pool;
185 48e5f32d Ondrej Zajicek
  sock *sk;                        /* IP socket */
186 2e10a170 Ondrej Filip
  list neigh_list;                /* List of neigbours */
187 9912fa51 Ondrej Filip
  u32 cost;                        /* Cost of iface */
188 7df86c25 Ondrej Filip
  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 8e48831a Ondrej Zajicek
  u32 deadint;                        /* after "deadint" missing hellos is router dead */
192 dd4da6f6 Ondrej Zajicek
  u32 iface_id;                        /* Interface ID (iface->index or new value for vlinks) */
193
  u32 vid;                        /* ID of peer of virtual link */
194 98ac6176 Ondrej Filip
  ip_addr vip;                        /* IP of peer of virtual link */
195 0aad2b92 Ondrej Zajicek
  struct ospf_iface *vifa;        /* OSPF iface which the vlink goes through */
196
  struct ospf_area *voa;        /* OSPF area which the vlink goes through */
197 9912fa51 Ondrej Filip
  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 621ccdfe Ondrej Filip
  u16 helloint;                        /* number of seconds between hello sending */
201 c3226991 Ondrej Zajicek
202
#ifdef OSPFv2
203 3e2bd0f1 Ondrej Filip
  list *passwords;
204 c3226991 Ondrej Zajicek
  u16 autype;
205 024c310b Ondrej Zajicek
  u32 csn;                      /* Last used crypt seq number */
206
  bird_clock_t csn_use;         /* Last time when packet with that CSN was sent */
207 c3226991 Ondrej Zajicek
#endif
208
209 95127cbb Ondrej Zajicek
  ip_addr all_routers;                /*  */
210 2e10a170 Ondrej Filip
  ip_addr drip;                        /* Designated router */
211
  ip_addr bdrip;                /* Backup DR */
212 d9e7e1b1 Ondrej Zajicek
  u32 drid;
213 aec76c6e Ondrej Filip
  u32 bdrid;
214 e7b4948c Ondrej Zajicek
  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 c3226991 Ondrej Zajicek
217
#ifdef OSPFv3
218 e7b4948c Ondrej Zajicek
  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 c3226991 Ondrej Zajicek
  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 2e10a170 Ondrej Filip
  u8 type;                        /* OSPF view of type */
227 96f1b8ba Ondrej Filip
#define OSPF_IT_BCAST 0
228 4c630a6d Ondrej Filip
#define OSPF_IT_NBMA 1
229
#define OSPF_IT_PTP 2
230 919f5411 Ondrej Zajicek
#define OSPF_IT_PTMP 3
231
#define OSPF_IT_VLINK 4
232
#define OSPF_IT_UNDEF 5
233 2e10a170 Ondrej Filip
  u8 strictnbma;                /* Can I talk with unknown neighbors? */
234
  u8 stub;                        /* Inactive interface */
235
  u8 state;                        /* Interface state machine */
236 96f1b8ba Ondrej Filip
#define OSPF_IS_DOWN 0                /* Not working */
237 d9e7e1b1 Ondrej Zajicek
#define OSPF_IS_LOOP 1                /* Iface with no link */
238 96f1b8ba Ondrej Filip
#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 65112dd2 Ondrej Filip
  timer *wait_timer;                /* WAIT timer */
244
  timer *hello_timer;                /* HELLOINT timer */
245 a190e720 Ondrej Filip
  timer *poll_timer;                /* Poll Interval - for NBMA */
246 5b1a92e6 Ondrej Filip
/* Default values for interface parameters */
247
#define COST_D 10
248
#define RXMTINT_D 5
249 249fdef7 Ondrej Filip
#define INFTRANSDELAY_D 1
250 4c630a6d Ondrej Filip
#define PRIORITY_D 1
251 5b1a92e6 Ondrej Filip
#define HELLOINT_D 10
252 a190e720 Ondrej Filip
#define POLLINT_D 20
253 35ff423d Ondrej Filip
#define DEADC_D 4
254 c3226991 Ondrej Zajicek
#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 be862406 Ondrej Zajicek
  struct top_hash_entry *link_lsa;        /* Originated link LSA */
262 c3226991 Ondrej Zajicek
  struct top_hash_entry *pxn_lsa;        /* Originated prefix LSA */
263
#endif
264
  int fadj;                                /* Number of full adjacent neigh */
265 e5b5d18c Ondrej Filip
  list nbma_list;
266 353729f5 Ondrej Zajicek
  u8 priority;                        /* A router priority for DR election */
267 621ccdfe Ondrej Filip
  u8 ioprob;
268 0aad2b92 Ondrej Zajicek
#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 353729f5 Ondrej Zajicek
  u8 sk_dr;                         /* Socket is a member of DRouters group */
272 8e48831a Ondrej Zajicek
  u8 marked;                        /* Used in OSPF reconfigure */
273 d9e7e1b1 Ondrej Zajicek
  u16 rxbuf;                        /* Buffer size */
274 48e5f32d Ondrej Zajicek
  u16 tx_length;                /* Soft TX packet length limit, usually MTU */
275 391931d4 Ondrej Zajicek
  u8 check_link;                /* Whether iface link change is used */
276 57c574d8 Ondrej Zajicek
  u8 ecmp_weight;                /* Weight used for ECMP */
277 8df02847 Ondrej Zajicek
  u8 ptp_netmask;                /* Send real netmask for P2P */
278 70e212f9 Ondrej Zajicek
  u8 check_ttl;                        /* Check incoming packets for TTL 255 */
279 1ec52253 Ondrej Zajicek
  u8 bfd;                        /* Use BFD on iface */
280 5b1a92e6 Ondrej Filip
};
281
282 3e2bd0f1 Ondrej Filip
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 c3226991 Ondrej Zajicek
297
/* Packet types */
298 2e10a170 Ondrej Filip
#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 c3226991 Ondrej Zajicek
304
/* Area IDs */
305 2c971094 Ondrej Filip
#define BACKBONE 0
306 296ecb56 Ondrej Filip
307
308 2e10a170 Ondrej Filip
struct immsb
309
{
310 b082c1bf Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
311 c11007bc Ondrej Filip
  u8 padding:5;
312
  u8 i:1;
313
  u8 m:1;
314
  u8 ms:1;
315
#else
316 04c6319a Ondrej Filip
  u8 ms:1;
317
  u8 m:1;
318
  u8 i:1;
319
  u8 padding:5;
320 c11007bc Ondrej Filip
#endif
321 04c6319a Ondrej Filip
};
322
323 2e10a170 Ondrej Filip
union imms
324
{
325 04c6319a Ondrej Filip
  u8 byte;
326
  struct immsb bit;
327
};
328 2c1d1cc7 Ondrej Filip
#define DBDES_MS 1
329
#define DBDES_M 2
330
#define DBDES_I 4
331 c3226991 Ondrej Zajicek
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 1af66415 Ondrej Filip
};
361
362 ce17d4c1 Ondrej Filip
363 c3226991 Ondrej Zajicek
#endif
364
365
366
367
368 2e10a170 Ondrej Filip
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 c3226991 Ondrej Zajicek
375
#ifdef OSPFv2
376 2c1d1cc7 Ondrej Filip
  u8 options;
377 ce17d4c1 Ondrej Filip
  u8 type;
378 c3226991 Ondrej Zajicek
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 41b612c3 Ondrej Zajicek
#define LSA_T_NSSA        7
385 c3226991 Ondrej Zajicek
386 98899244 Ondrej Zajicek
#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 c3226991 Ondrej Zajicek
#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 41b612c3 Ondrej Zajicek
#define LSA_T_NSSA        0x2007
400 c3226991 Ondrej Zajicek
#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 ce17d4c1 Ondrej Filip
  u32 id;
415 2e10a170 Ondrej Filip
  u32 rt;                        /* Advertising router */
416
  s32 sn;                        /* LS Sequence number */
417 b49e6f5a Ondrej Zajicek
#define LSA_INITSEQNO ((s32) 0x80000001)
418
#define LSA_MAXSEQNO ((s32) 0x7fffffff)
419 2c1d1cc7 Ondrej Filip
  u16 checksum;
420 2e10a170 Ondrej Filip
  u16 length;
421 ce17d4c1 Ondrej Filip
};
422
423 fdb19982 Ondrej Filip
424 c3226991 Ondrej Zajicek
#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 fdb19982 Ondrej Filip
432 2e10a170 Ondrej Filip
struct ospf_lsa_rt
433
{
434 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
435 c3226991 Ondrej Zajicek
  u16 options;        /* VEB flags only */
436 ce17d4c1 Ondrej Filip
  u16 links;
437 c15e5690 Ondrej Zajicek
#else
438
  u16 links;
439
  u16 options;        /* VEB flags only */
440
#endif
441 ce17d4c1 Ondrej Filip
};
442
443 2e10a170 Ondrej Filip
struct ospf_lsa_rt_link
444
{
445 ce17d4c1 Ondrej Filip
  u32 id;
446
  u32 data;
447 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
448 ce17d4c1 Ondrej Filip
  u8 type;
449 c15e5690 Ondrej Zajicek
  u8 padding;
450 ce17d4c1 Ondrej Filip
  u16 metric;
451 c15e5690 Ondrej Zajicek
#else
452
  u16 metric;
453
  u8 padding;
454
  u8 type;
455
#endif
456 ce17d4c1 Ondrej Filip
};
457
458 c3226991 Ondrej Zajicek
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 a6bc04d5 Ondrej Zajicek
#define LSA_SUM_TOS  0xFF000000
479
#define LSA_EXT_TOS  0x7F000000
480 c3226991 Ondrej Zajicek
#define LSA_EXT_EBIT 0x80000000
481
482 061ab802 Ondrej Zajicek
/* Endianity swap for lsa->type */
483
#define ntoht(x) x
484
#define htont(x) x
485
486 c3226991 Ondrej Zajicek
487
#else  /* OSPFv3 */
488
489
struct ospf_lsa_rt
490
{
491
  u32 options;
492
};
493
494
struct ospf_lsa_rt_link
495
{
496 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
497 c3226991 Ondrej Zajicek
  u8 type;
498 ce17d4c1 Ondrej Filip
  u8 padding;
499
  u16 metric;
500 c15e5690 Ondrej Zajicek
#else
501
  u16 metric;
502
  u8 padding;
503
  u8 type;
504
#endif
505 c3226991 Ondrej Zajicek
  u32 lif;        /* Local interface ID */
506
  u32 nif;        /* Neighbor interface ID */
507
  u32 id;        /* Neighbor router ID */
508 2c1d1cc7 Ondrej Filip
};
509
510 2e10a170 Ondrej Filip
struct ospf_lsa_net
511
{
512 c3226991 Ondrej Zajicek
  u32 options;
513
  u32 routers[];
514 dfa9a53a Ondrej Filip
};
515
516 c3226991 Ondrej Zajicek
struct ospf_lsa_sum_net
517 2e10a170 Ondrej Filip
{
518 c3226991 Ondrej Zajicek
  u32 metric;
519
  u32 prefix[];
520 ce17d4c1 Ondrej Filip
};
521
522 c3226991 Ondrej Zajicek
struct ospf_lsa_sum_rt
523
{
524
  u32 options;
525
  u32 metric;
526
  u32 drid;
527
};
528 98ac6176 Ondrej Filip
529
struct ospf_lsa_ext
530 2e10a170 Ondrej Filip
{
531 c3226991 Ondrej Zajicek
  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 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
546 c3226991 Ondrej Zajicek
  u16 pxcount;
547
  u16 ref_type;
548 c15e5690 Ondrej Zajicek
#else
549
  u16 ref_type;
550
  u16 pxcount;
551
#endif
552 c3226991 Ondrej Zajicek
  u32 ref_id;
553
  u32 ref_rt;
554
  u32 rest[];
555 98ac6176 Ondrej Filip
};
556
557 c3226991 Ondrej Zajicek
#define LSA_EXT_EBIT 0x4000000
558
#define LSA_EXT_FBIT 0x2000000
559
#define LSA_EXT_TBIT 0x1000000
560
561 061ab802 Ondrej Zajicek
/* Endianity swap for lsa->type */
562
#define ntoht(x) ntohs(x)
563
#define htont(x) htons(x)
564
565 c3226991 Ondrej Zajicek
#endif
566
567
#define METRIC_MASK  0x00FFFFFF
568
#define OPTIONS_MASK 0x00FFFFFF
569
570 b66abe8e Ondrej Zajicek
static inline unsigned
571
lsa_rt_count(struct ospf_lsa_header *lsa)
572 c3226991 Ondrej Zajicek
{
573
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_rt))
574
    / sizeof(struct ospf_lsa_rt_link);
575
}
576
577 b66abe8e Ondrej Zajicek
static inline unsigned
578
lsa_net_count(struct ospf_lsa_header *lsa)
579 c3226991 Ondrej Zajicek
{
580
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net))
581
    / sizeof(u32);
582
}
583
584
585 b66abe8e Ondrej Zajicek
#ifdef OSPFv3
586
587 a6bc04d5 Ondrej Zajicek
#define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
588
#define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
589
590 b66abe8e Ondrej Zajicek
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 ab164971 Ondrej Zajicek
  /* Clean up remaining bits */
611
  if (pxl < 128)
612
    addr->addr[pxl / 32] &= u32_mkmask(pxl % 32);
613
614 b66abe8e Ondrej Zajicek
  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 a6bc04d5 Ondrej Zajicek
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 b66abe8e Ondrej Zajicek
#endif
648
649
650
651 2e10a170 Ondrej Filip
struct ospf_lsreq_header
652
{
653 c3226991 Ondrej Zajicek
  u32 type;
654 6d2b3211 Ondrej Filip
  u32 id;
655 2e10a170 Ondrej Filip
  u32 rt;                        /* Advertising router */
656 6d2b3211 Ondrej Filip
};
657
658 2e10a170 Ondrej Filip
struct l_lsr_head
659
{
660 f45fd316 Ondrej Filip
  node n;
661
  struct ospf_lsreq_header lsh;
662
};
663
664 de769e24 Ondrej Filip
665 c76674f0 Ondrej Filip
struct ospf_neighbor
666
{
667 e83dc0d7 Ondrej Filip
  node n;
668 035f6acb Ondrej Filip
  pool *pool;
669 903a3f39 Ondrej Filip
  struct ospf_iface *ifa;
670 2c1d1cc7 Ondrej Filip
  u8 state;
671 c76674f0 Ondrej Filip
#define NEIGHBOR_DOWN 0
672 cd70d934 Ondrej Filip
#define NEIGHBOR_ATTEMPT 1
673
#define NEIGHBOR_INIT 2
674
#define NEIGHBOR_2WAY 3
675 c76674f0 Ondrej Filip
#define NEIGHBOR_EXSTART 4
676 903a3f39 Ondrej Filip
#define NEIGHBOR_EXCHANGE 5
677
#define NEIGHBOR_LOADING 6
678
#define NEIGHBOR_FULL 7
679 2e10a170 Ondrej Filip
  timer *inactim;                /* Inactivity timer */
680 04c6319a Ondrej Filip
  union imms imms;                /* I, M, Master/slave received */
681 2e10a170 Ondrej Filip
  u32 dds;                        /* DD Sequence number being sent */
682
  u32 ddr;                        /* last Dat Des packet received */
683 04c6319a Ondrej Filip
  union imms myimms;                /* I, M Master/slave */
684 2e10a170 Ondrej Filip
  u32 rid;                        /* Router ID */
685
  ip_addr ip;                        /* IP of it's interface */
686
  u8 priority;                        /* Priority */
687
  u8 adj;                        /* built adjacency? */
688 c3226991 Ondrej Zajicek
  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 2e10a170 Ondrej Filip
  siterator dbsi;                /* Database summary list iterator */
700
  slist lsrql;                        /* Link state request */
701
  struct top_graph *lsrqh;        /* LSA graph */
702 30147b89 Ondrej Filip
  siterator lsrqi;
703 2e10a170 Ondrej Filip
  slist lsrtl;                        /* Link state retransmission list */
704 30147b89 Ondrej Filip
  siterator lsrti;
705 921a93f2 Ondrej Filip
  struct top_graph *lsrth;
706 2e10a170 Ondrej Filip
  timer *rxmt_timer;                /* RXMT timer */
707 c76ba51a Ondrej Filip
  list ackl[2];
708
#define ACKL_DIRECT 0
709
#define ACKL_DELAY 1
710 2e10a170 Ondrej Filip
  timer *ackd_timer;                /* Delayed ack timer */
711 1ec52253 Ondrej Zajicek
  struct bfd_request *bfd_req;        /* BFD request, if BFD is used */
712 48e5f32d Ondrej Zajicek
  void *ldd_buffer;                /* Last database description packet */
713
  u32 ldd_bsize;                /* Buffer size for ldd_buffer */
714 3e2bd0f1 Ondrej Filip
  u32 csn;                      /* Last received crypt seq number (for MD5) */
715 c76674f0 Ondrej Filip
};
716
717 96f1b8ba Ondrej Filip
/* Definitions for interface state machine */
718 2e10a170 Ondrej Filip
#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 d9e7e1b1 Ondrej Zajicek
#define ISM_LOOP 4                /* Link down */
723
#define ISM_UNLOOP 5                /* Link up */
724 2e10a170 Ondrej Filip
#define ISM_DOWN 6                /* Interface down */
725 96f1b8ba Ondrej Filip
726
/* Definitions for neighbor state machine */
727 2e10a170 Ondrej Filip
#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 8496b2e4 Ondrej Filip
  node n;
744 15087574 Ondrej Filip
  u32 areaid;
745 41b612c3 Ondrej Zajicek
  struct ospf_area_config *ac;        /* Related area config */
746 de30342f Ondrej Filip
  struct top_hash_entry *rt;        /* My own router LSA */
747 c3226991 Ondrej Zajicek
  struct top_hash_entry *pxr_lsa; /* Originated prefix LSA */
748 dfa9a53a Ondrej Filip
  list cand;                        /* List of candidates for RT calc. */
749 98ac6176 Ondrej Filip
  struct fib net_fib;                /* Networks to advertise or not */
750 ed317862 Ondrej Zajicek
  struct fib enet_fib;                /* External networks for NSSAs */
751 c3226991 Ondrej Zajicek
  u32 options;                        /* Optional features */
752 8e48831a Ondrej Zajicek
  byte origrt;                        /* Rt lsa origination scheduled? */
753
  byte trcap;                        /* Transit capability? */
754
  byte marked;                        /* Used in OSPF reconfigure */
755 4160a9dd Ondrej Zajicek
  byte translate;                /* Translator state (TRANS_*), for NSSA ABR  */
756
  timer *translator_timer;        /* For NSSA translator switch */
757 c45f48fb Ondrej Filip
  struct proto_ospf *po;
758 98ac6176 Ondrej Filip
  struct fib rtr;                /* Routing tables for routers */
759 15087574 Ondrej Filip
};
760
761 4160a9dd Ondrej Zajicek
#define TRANS_OFF        0
762
#define TRANS_ON        1
763
#define TRANS_WAIT        2        /* Waiting before the end of translation */
764
765 2e10a170 Ondrej Filip
struct proto_ospf
766
{
767 4364b47e Ondrej Filip
  struct proto proto;
768 b8f17cf1 Ondrej Filip
  timer *disp_timer;                /* OSPF proto dispatcher */
769
  unsigned tick;
770 86c84d76 Ondrej Filip
  struct top_graph *gr;                /* LSA graph */
771
  slist lsal;                        /* List of all LSA's */
772 f7574707 Ondrej Zajicek
  int calcrt;                        /* Routing table calculation scheduled?
773
                                   0=no, 1=normal, 2=forced reload */
774 4364b47e Ondrej Filip
  list iface_list;                /* Interfaces we really use */
775 8496b2e4 Ondrej Filip
  list area_list;
776 15087574 Ondrej Filip
  int areano;                        /* Number of area I belong to */
777 98ac6176 Ondrej Filip
  struct fib rtf;                /* Routing table */
778 57c574d8 Ondrej Zajicek
  byte rfc1583;                        /* RFC1583 compatibility */
779 f623ab98 Ondrej Zajicek
  byte stub_router;                /* Do not forward transit traffic */
780 57c574d8 Ondrej Zajicek
  byte ebit;                        /* Did I originate any ext lsa? */
781
  byte ecmp;                        /* Maximal number of nexthops in ECMP route, or 0 */
782 98ac6176 Ondrej Filip
  struct ospf_area *backbone;        /* If exists */
783 3d15dcdb Ondrej Zajicek
  void *lsab;                        /* LSA buffer used when originating router LSAs */
784
  int lsab_size, lsab_used;
785 57c574d8 Ondrej Zajicek
  linpool *nhpool;                /* Linpool used for next hops computed in SPF */
786 48e5f32d Ondrej Zajicek
  sock *vlink_sk;                /* IP socket used for vlink TX */
787 8a70a13e Ondrej Zajicek
  u32 router_id;
788 dd4da6f6 Ondrej Zajicek
  u32 last_vlink_id;                /* Interface IDs for vlinks (starts at 0x80000000) */
789 6ba36f06 Martin Mares
};
790
791 2e10a170 Ondrej Filip
struct ospf_iface_patt
792
{
793 89d6782d Ondrej Filip
  struct iface_patt i;
794 8e48831a Ondrej Zajicek
  u32 type;
795
  u32 stub;
796 7df86c25 Ondrej Filip
  u32 cost;
797
  u32 helloint;
798
  u32 rxmtint;
799
  u32 pollint;
800
  u32 waitint;
801
  u32 deadc;
802 8e48831a Ondrej Zajicek
  u32 deadint;
803
  u32 inftransdelay;
804
  list nbma_list;
805 95127cbb Ondrej Zajicek
  u32 priority;
806 8e48831a Ondrej Zajicek
  u32 voa;
807 98ac6176 Ondrej Filip
  u32 vid;
808 ef4a50be Ondrej Zajicek
  int tx_tos;
809
  int tx_priority;
810 48e5f32d Ondrej Zajicek
  u16 tx_length;
811
  u16 rx_buffer;
812
813 94c42054 Ondrej Filip
#define OSPF_RXBUF_MINSIZE 256        /* Minimal allowed size */
814 95127cbb Ondrej Zajicek
  u16 autype;                        /* Not really used in OSPFv3 */
815 c3226991 Ondrej Zajicek
#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 95127cbb Ondrej Zajicek
  u8 strictnbma;
820
  u8 check_link;
821
  u8 ecmp_weight;
822
  u8 real_bcast;                /* Not really used in OSPFv3 */
823 70e212f9 Ondrej Zajicek
  u8 ptp_netmask;                /* bool + 2 for unspecified */
824
  u8 ttl_security;                /* bool + 2 for TX only */
825 1ec52253 Ondrej Zajicek
  u8 bfd;
826 48e5f32d Ondrej Zajicek
  u8 bsd_secondary;
827 c3226991 Ondrej Zajicek
828
#ifdef OSPFv2
829
  list *passwords;
830
#endif
831
832
#ifdef OSPFv3
833
  u8 instance_id;
834
#endif
835 89d6782d Ondrej Filip
};
836
837 b8f17cf1 Ondrej Filip
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
838 2e10a170 Ondrej Filip
                        struct linpool *pool);
839 5919c66e Martin Mares
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 70a38319 Ondrej Filip
void schedule_rt_lsa(struct ospf_area *oa);
842 b8f17cf1 Ondrej Filip
void schedule_rtcalc(struct proto_ospf *po);
843 b9ed99f7 Ondrej Filip
void schedule_net_lsa(struct ospf_iface *ifa);
844 be862406 Ondrej Zajicek
845 8e48831a Ondrej Zajicek
struct ospf_area *ospf_find_area(struct proto_ospf *po, u32 aid);
846 41b612c3 Ondrej Zajicek
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 8e48831a Ondrej Zajicek
857 be862406 Ondrej Zajicek
#ifdef OSPFv3
858
void schedule_link_lsa(struct ospf_iface *ifa);
859
#else
860 e81b440f Ondrej Zajicek
static inline void schedule_link_lsa(struct ospf_iface *ifa UNUSED) {}
861 be862406 Ondrej Zajicek
#endif
862
863 c4f0f014 Ondrej Filip
void ospf_sh_neigh(struct proto *p, char *iff);
864 4ab4e977 Ondrej Filip
void ospf_sh(struct proto *p);
865 c4f0f014 Ondrej Filip
void ospf_sh_iface(struct proto *p, char *iff);
866 0ea8fb4a Ondrej Zajicek
void ospf_sh_state(struct proto *p, int verbose, int reachable);
867 20ab192b Ondrej Zajicek
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 05198c12 Ondrej Zajicek
881 4364b47e Ondrej Filip
882 5919c66e Martin Mares
#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 c27b2449 Ondrej Zajicek
#define EA_OSPF_ROUTER_ID EA_CODE(EAP_OSPF, 3)
886 5919c66e Martin Mares
887 98ac6176 Ondrej Filip
#include "proto/ospf/rt.h"
888 4364b47e Ondrej Filip
#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 6d2b3211 Ondrej Filip
#include "proto/ospf/lsreq.h"
895 f45fd316 Ondrej Filip
#include "proto/ospf/lsupd.h"
896
#include "proto/ospf/lsack.h"
897
#include "proto/ospf/lsalib.h"
898 6ba36f06 Martin Mares
899 c1f8dc91 Ondrej Filip
#endif /* _BIRD_OSPF_H_ */