Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ f623ab98

History | View | Annotate | Download (20.7 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 79f561a1 Ondrej Zajicek
#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 f14032ef Ondrej Filip
#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 6d2b3211 Ondrej Filip
30 8298d780 Ondrej Zajicek
#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 4364b47e Ondrej Filip
#include "nest/bird.h"
36
37
#include "lib/checksum.h"
38 6ba36f06 Martin Mares
#include "lib/ip.h"
39
#include "lib/lists.h"
40 30147b89 Ondrej Filip
#include "lib/slists.h"
41 6ba36f06 Martin Mares
#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 4364b47e Ondrej Filip
#include "nest/route.h"
47 a783e259 Ondrej Filip
#include "nest/cli.h"
48 f8f1e1f1 Ondrej Filip
#include "nest/locks.h"
49 4364b47e Ondrej Filip
#include "conf/conf.h"
50 d345cda5 Ondrej Filip
#include "lib/string.h"
51 6ba36f06 Martin Mares
52 5b1a92e6 Ondrej Filip
#define OSPF_PROTO 89
53 c3226991 Ondrej Zajicek
54 aec76c6e Ondrej Filip
#ifndef IPV6
55 c3226991 Ondrej Zajicek
#define OSPFv2 1
56 296ecb56 Ondrej Filip
#define OSPF_VERSION 2
57 d5356072 Ondrej Zajicek
#define OSPF_VLINK_MTU 576                        /* RFC 2328 A.1 */
58 5b1a92e6 Ondrej Filip
#define AllSPFRouters ipa_from_u32(0xe0000005)        /* 224.0.0.5 */
59
#define AllDRouters ipa_from_u32(0xe0000006)        /* 224.0.0.6 */
60 aec76c6e Ondrej Filip
#else
61 c3226991 Ondrej Zajicek
#define OSPFv3 1
62
#define OSPF_VERSION 3
63 d5356072 Ondrej Zajicek
#define OSPF_VLINK_MTU 1280                        /* RFC 5340 A.1 */
64 c3226991 Ondrej Zajicek
#define AllSPFRouters _MI(0xFF020000, 0, 0, 5)        /* FF02::5 */
65
#define AllDRouters   _MI(0xFF020000, 0, 0, 6)        /* FF02::6 */
66 aec76c6e Ondrej Filip
#endif
67
68 15087574 Ondrej Filip
69 921a93f2 Ondrej Filip
#define LSREFRESHTIME 1800        /* 30 minutes */
70 15087574 Ondrej Filip
#define MINLSINTERVAL 5
71
#define MINLSARRIVAL 1
72 98ac6176 Ondrej Filip
#define LSINFINITY 0xffffff
73 d631698e Ondrej Filip
74 62eee823 Ondrej Filip
#define DEFAULT_OSPFTICK 1
75 3b16080c Ondrej Filip
#define DEFAULT_RFC1583 0        /* compatibility with rfc1583 */
76 8d94a524 Ondrej Filip
#define DEFAULT_STUB_COST 1000
77 57c574d8 Ondrej Zajicek
#define DEFAULT_ECMP_LIMIT 16
78 ed317862 Ondrej Zajicek
#define DEFAULT_TRANSINT 40
79 d631698e Ondrej Filip
80 15087574 Ondrej Filip
81 2e10a170 Ondrej Filip
struct ospf_config
82
{
83 c1f8dc91 Ondrej Filip
  struct proto_config c;
84 b8f17cf1 Ondrej Filip
  unsigned tick;
85 8e48831a Ondrej Zajicek
  byte rfc1583;
86 f623ab98 Ondrej Zajicek
  byte stub_router;
87 8e48831a Ondrej Zajicek
  byte abr;
88 57c574d8 Ondrej Zajicek
  int ecmp;
89 a7f23f58 Ondrej Zajicek
  list area_list;                /* list of struct ospf_area_config */
90
  list vlink_list;                /* list of struct ospf_iface_patt */
91 b36a0a79 Ondrej Filip
};
92
93 2e10a170 Ondrej Filip
struct nbma_node
94
{
95 e5b5d18c Ondrej Filip
  node n;
96
  ip_addr ip;
97 919f5411 Ondrej Zajicek
  byte eligible;
98
  byte found; 
99 e5b5d18c Ondrej Filip
};
100
101 98ac6176 Ondrej Filip
struct area_net_config
102 2e10a170 Ondrej Filip
{
103 c926eee7 Ondrej Filip
  node n;
104 66261211 Ondrej Filip
  struct prefix px;
105 c926eee7 Ondrej Filip
  int hidden;
106 ed317862 Ondrej Zajicek
  u32 tag;
107 98ac6176 Ondrej Filip
};
108
109
struct area_net
110
{
111
  struct fib_node fn;
112
  int hidden;
113 66261211 Ondrej Filip
  int active;
114 60e04f04 Ondrej Filip
  u32 metric;
115 ed317862 Ondrej Zajicek
  u32 tag;
116 c926eee7 Ondrej Filip
};
117
118 38675202 Ondrej Zajicek
struct ospf_stubnet_config
119
{
120
  node n;
121
  struct prefix px;
122
  int hidden, summary;
123
  u32 cost;
124
};
125
126 2e10a170 Ondrej Filip
struct ospf_area_config
127
{
128 b36a0a79 Ondrej Filip
  node n;
129
  u32 areaid;
130 2918e610 Ondrej Zajicek
  u32 default_cost;                /* Cost of default route for stub areas */
131 41b612c3 Ondrej Zajicek
  u8 type;                        /* Area type (standard, stub, NSSA), represented
132
                                   by option flags (OPT_E, OPT_N) */
133
  u8 summary;                        /* Import summaries to this stub/NSSA area, valid for ABR */
134 2918e610 Ondrej Zajicek
  u8 default_nssa;                /* Generate default NSSA route for NSSA+summary area */
135 4160a9dd Ondrej Zajicek
  u8 translator;                /* Translator role, for NSSA ABR */
136
  u32 transint;                        /* Translator stability interval */
137 89d6782d Ondrej Filip
  list patt_list;
138 8e48831a Ondrej Zajicek
  list net_list;                      /* List of aggregate networks for that area */
139 ed317862 Ondrej Zajicek
  list enet_list;                      /* List of aggregate external (NSSA) networks */
140 8e48831a Ondrej Zajicek
  list stubnet_list;                /* List of stub networks added to Router LSA */
141 c1f8dc91 Ondrej Filip
};
142
143 c3226991 Ondrej Zajicek
144
/* Option flags */
145
146
#define OPT_E        0x02
147
#define OPT_N        0x08
148
#define OPT_DC        0x20
149
150
#ifdef OSPFv2
151 41b612c3 Ondrej Zajicek
#define OPT_P        0x08                /* flags P and N share position, see NSSA RFC */
152 c3226991 Ondrej Zajicek
#define OPT_EA        0x10
153
154
/* VEB flags are are stored independently in 'u16 options' */
155
#define OPT_RT_B  (0x01 << 8)
156
#define OPT_RT_E  (0x02 << 8)
157
#define OPT_RT_V  (0x04 << 8)
158 41b612c3 Ondrej Zajicek
#define OPT_RT_NT (0x10 << 8)
159 621ccdfe Ondrej Filip
#endif
160
161 c3226991 Ondrej Zajicek
#ifdef OSPFv3
162
#define OPT_V6        0x01
163
#define OPT_R        0x10
164
165
/* VEB flags are are stored together with options in 'u32 options' */
166
#define OPT_RT_B  (0x01 << 24)
167
#define OPT_RT_E  (0x02 << 24)
168
#define OPT_RT_V  (0x04 << 24)
169
#define OPT_RT_NT (0x10 << 24)
170
171
#define OPT_PX_NU 0x01
172
#define OPT_PX_LA 0x02
173
#define OPT_PX_P  0x08
174
#define OPT_PX_DN 0x10
175
#endif
176 621ccdfe Ondrej Filip
177
178 2e10a170 Ondrej Filip
struct ospf_iface
179
{
180 b11d8a4f Ondrej Filip
  node n;
181 5c78e0e3 Ondrej Zajicek
  struct iface *iface;                /* Nest's iface, non-NULL (unless type OSPF_IT_VLINK) */
182 48cff379 Ondrej Zajicek
  struct ifa *addr;                /* IP prefix associated with that OSPF iface */
183 30147b89 Ondrej Filip
  struct ospf_area *oa;
184 8e48831a Ondrej Zajicek
  struct ospf_iface_patt *cf;
185 d9e7e1b1 Ondrej Zajicek
  pool *pool;
186 f9c799a0 Ondrej Zajicek
  sock *sk;                        /* IP socket (for DD ...) */
187 2e10a170 Ondrej Filip
  list neigh_list;                /* List of neigbours */
188 9912fa51 Ondrej Filip
  u32 cost;                        /* Cost of iface */
189 7df86c25 Ondrej Filip
  u32 waitint;                        /* number of sec before changing state from wait */
190
  u32 rxmtint;                        /* number of seconds between LSA retransmissions */
191
  u32 pollint;                        /* Poll interval */
192 8e48831a Ondrej Zajicek
  u32 deadint;                        /* after "deadint" missing hellos is router dead */
193 dd4da6f6 Ondrej Zajicek
  u32 iface_id;                        /* Interface ID (iface->index or new value for vlinks) */
194
  u32 vid;                        /* ID of peer of virtual link */
195 98ac6176 Ondrej Filip
  ip_addr vip;                        /* IP of peer of virtual link */
196 0aad2b92 Ondrej Zajicek
  struct ospf_iface *vifa;        /* OSPF iface which the vlink goes through */
197
  struct ospf_area *voa;        /* OSPF area which the vlink goes through */
198 9912fa51 Ondrej Filip
  u16 inftransdelay;                /* The estimated number of seconds it takes to
199
                                   transmit a Link State Update Packet over this
200
                                   interface.  LSAs contained in the update */
201 621ccdfe Ondrej Filip
  u16 helloint;                        /* number of seconds between hello sending */
202 c3226991 Ondrej Zajicek
203
#ifdef OSPFv2
204 3e2bd0f1 Ondrej Filip
  list *passwords;
205 c3226991 Ondrej Zajicek
  u16 autype;
206 024c310b Ondrej Zajicek
  u32 csn;                      /* Last used crypt seq number */
207
  bird_clock_t csn_use;         /* Last time when packet with that CSN was sent */
208 c3226991 Ondrej Zajicek
#endif
209
210 95127cbb Ondrej Zajicek
  ip_addr all_routers;                /*  */
211 2e10a170 Ondrej Filip
  ip_addr drip;                        /* Designated router */
212
  ip_addr bdrip;                /* Backup DR */
213 d9e7e1b1 Ondrej Zajicek
  u32 drid;
214 aec76c6e Ondrej Filip
  u32 bdrid;
215 e7b4948c Ondrej Zajicek
  s16 rt_pos_beg;                /* Position of iface in Router-LSA, begin, inclusive */
216
  s16 rt_pos_end;                /* Position of iface in Router-LSA, end, exclusive */
217 c3226991 Ondrej Zajicek
218
#ifdef OSPFv3
219 e7b4948c Ondrej Zajicek
  s16 px_pos_beg;                /* Position of iface in Rt Prefix-LSA, begin, inclusive */
220
  s16 px_pos_end;                /* Position of iface in Rt Prefix-LSA, end, exclusive */
221
222 c3226991 Ondrej Zajicek
  u32 dr_iface_id;                /* if drid is valid, this is iface_id of DR (for connecting network) */
223
  u8 instance_id;                /* Used to differentiate between more OSPF
224
                                   instances on one interface */
225
#endif
226
227 2e10a170 Ondrej Filip
  u8 type;                        /* OSPF view of type */
228 96f1b8ba Ondrej Filip
#define OSPF_IT_BCAST 0
229 4c630a6d Ondrej Filip
#define OSPF_IT_NBMA 1
230
#define OSPF_IT_PTP 2
231 919f5411 Ondrej Zajicek
#define OSPF_IT_PTMP 3
232
#define OSPF_IT_VLINK 4
233
#define OSPF_IT_UNDEF 5
234 2e10a170 Ondrej Filip
  u8 strictnbma;                /* Can I talk with unknown neighbors? */
235
  u8 stub;                        /* Inactive interface */
236
  u8 state;                        /* Interface state machine */
237 96f1b8ba Ondrej Filip
#define OSPF_IS_DOWN 0                /* Not working */
238 d9e7e1b1 Ondrej Zajicek
#define OSPF_IS_LOOP 1                /* Iface with no link */
239 96f1b8ba Ondrej Filip
#define OSPF_IS_WAITING 2        /* Waiting for Wait timer */
240
#define OSPF_IS_PTP 3                /* PTP operational */
241
#define OSPF_IS_DROTHER 4        /* I'm on BCAST or NBMA and I'm not DR */
242
#define OSPF_IS_BACKUP 5        /* I'm BDR */
243
#define OSPF_IS_DR 6                /* I'm DR */
244 65112dd2 Ondrej Filip
  timer *wait_timer;                /* WAIT timer */
245
  timer *hello_timer;                /* HELLOINT timer */
246 a190e720 Ondrej Filip
  timer *poll_timer;                /* Poll Interval - for NBMA */
247 5b1a92e6 Ondrej Filip
/* Default values for interface parameters */
248
#define COST_D 10
249
#define RXMTINT_D 5
250 249fdef7 Ondrej Filip
#define INFTRANSDELAY_D 1
251 4c630a6d Ondrej Filip
#define PRIORITY_D 1
252 5b1a92e6 Ondrej Filip
#define HELLOINT_D 10
253 a190e720 Ondrej Filip
#define POLLINT_D 20
254 35ff423d Ondrej Filip
#define DEADC_D 4
255 c3226991 Ondrej Zajicek
#define WAIT_DMH 4                
256
  /* Value of Wait timer - not found it in RFC * - using 4*HELLO */
257
258
  struct top_hash_entry *net_lsa;        /* Originated network LSA */
259
  int orignet;                                /* Schedule network LSA origination */
260
#ifdef OSPFv3
261
  int origlink;                                /* Schedule link LSA origination */
262 be862406 Ondrej Zajicek
  struct top_hash_entry *link_lsa;        /* Originated link LSA */
263 c3226991 Ondrej Zajicek
  struct top_hash_entry *pxn_lsa;        /* Originated prefix LSA */
264
#endif
265
  int fadj;                                /* Number of full adjacent neigh */
266 e5b5d18c Ondrej Filip
  list nbma_list;
267 353729f5 Ondrej Zajicek
  u8 priority;                        /* A router priority for DR election */
268 621ccdfe Ondrej Filip
  u8 ioprob;
269 0aad2b92 Ondrej Zajicek
#define OSPF_I_OK 0                /* Everything OK */
270
#define OSPF_I_SK 1                /* Socket open failed */
271
#define OSPF_I_LL 2                /* Missing link-local address (OSPFv3) */
272 353729f5 Ondrej Zajicek
  u8 sk_dr;                         /* Socket is a member of DRouters group */
273 8e48831a Ondrej Zajicek
  u8 marked;                        /* Used in OSPF reconfigure */
274 d9e7e1b1 Ondrej Zajicek
  u16 rxbuf;                        /* Buffer size */
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 5b1a92e6 Ondrej Filip
};
279
280 3e2bd0f1 Ondrej Filip
struct ospf_md5
281
{
282
  u16 zero;
283
  u8 keyid;
284
  u8 len;
285
  u32 csn;
286
};
287
288
union ospf_auth
289
{
290
  u8 password[8];
291
  struct ospf_md5 md5;
292
};
293
294 c3226991 Ondrej Zajicek
295
/* Packet types */
296 2e10a170 Ondrej Filip
#define HELLO_P 1                /* Hello */
297
#define DBDES_P 2                /* Database description */
298
#define LSREQ_P 3                /* Link state request */
299
#define LSUPD_P 4                /* Link state update */
300
#define LSACK_P 5                /* Link state acknowledgement */
301 c3226991 Ondrej Zajicek
302
/* Area IDs */
303 2c971094 Ondrej Filip
#define BACKBONE 0
304 296ecb56 Ondrej Filip
305
306 2e10a170 Ondrej Filip
struct immsb
307
{
308 b082c1bf Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
309 c11007bc Ondrej Filip
  u8 padding:5;
310
  u8 i:1;
311
  u8 m:1;
312
  u8 ms:1;
313
#else
314 04c6319a Ondrej Filip
  u8 ms:1;
315
  u8 m:1;
316
  u8 i:1;
317
  u8 padding:5;
318 c11007bc Ondrej Filip
#endif
319 04c6319a Ondrej Filip
};
320
321 2e10a170 Ondrej Filip
union imms
322
{
323 04c6319a Ondrej Filip
  u8 byte;
324
  struct immsb bit;
325
};
326 2c1d1cc7 Ondrej Filip
#define DBDES_MS 1
327
#define DBDES_M 2
328
#define DBDES_I 4
329 c3226991 Ondrej Zajicek
330
331
#ifdef OSPFv2
332
333
struct ospf_packet
334
{
335
  u8 version;
336
  u8 type;
337
  u16 length;
338
  u32 routerid;
339
  u32 areaid;
340
  u16 checksum;
341
  u16 autype;
342
  union ospf_auth u;
343
};
344
345
346
#else /* OSPFv3 packet descriptions */
347
348
struct ospf_packet
349
{
350
  u8 version;
351
  u8 type;
352
  u16 length;
353
  u32 routerid;
354
  u32 areaid;
355
  u16 checksum;
356
  u8 instance_id;
357
  u8 zero;
358 1af66415 Ondrej Filip
};
359
360 ce17d4c1 Ondrej Filip
361 c3226991 Ondrej Zajicek
#endif
362
363
364
365
366 2e10a170 Ondrej Filip
struct ospf_lsa_header
367
{
368
  u16 age;                        /* LS Age */
369
#define LSA_MAXAGE 3600                /* 1 hour */
370
#define LSA_CHECKAGE 300        /* 5 minutes */
371
#define LSA_MAXAGEDIFF 900        /* 15 minutes */
372 c3226991 Ondrej Zajicek
373
#ifdef OSPFv2
374 2c1d1cc7 Ondrej Filip
  u8 options;
375 ce17d4c1 Ondrej Filip
  u8 type;
376 c3226991 Ondrej Zajicek
377
#define LSA_T_RT        1
378
#define LSA_T_NET        2
379
#define LSA_T_SUM_NET        3
380
#define LSA_T_SUM_RT        4
381
#define LSA_T_EXT        5
382 41b612c3 Ondrej Zajicek
#define LSA_T_NSSA        7
383 c3226991 Ondrej Zajicek
384 98899244 Ondrej Zajicek
#define LSA_SCOPE_AREA        0x2000
385
#define LSA_SCOPE_AS        0x4000
386
387
#define LSA_SCOPE(lsa)        (((lsa)->type == LSA_T_EXT) ? LSA_SCOPE_AS : LSA_SCOPE_AREA)
388
389 c3226991 Ondrej Zajicek
#else /* OSPFv3 */
390
  u16 type;
391
392
#define LSA_T_RT        0x2001
393
#define LSA_T_NET        0x2002
394
#define LSA_T_SUM_NET        0x2003
395
#define LSA_T_SUM_RT        0x2004
396
#define LSA_T_EXT        0x4005
397 41b612c3 Ondrej Zajicek
#define LSA_T_NSSA        0x2007
398 c3226991 Ondrej Zajicek
#define LSA_T_LINK        0x0008
399
#define LSA_T_PREFIX        0x2009
400
401
#define LSA_UBIT        0x8000
402
403
#define LSA_SCOPE_LINK        0x0000
404
#define LSA_SCOPE_AREA        0x2000
405
#define LSA_SCOPE_AS        0x4000
406
#define LSA_SCOPE_RES        0x6000
407
#define LSA_SCOPE_MASK        0x6000
408
409
#define LSA_SCOPE(lsa)        ((lsa)->type & LSA_SCOPE_MASK)
410
#endif
411
412 ce17d4c1 Ondrej Filip
  u32 id;
413 2e10a170 Ondrej Filip
  u32 rt;                        /* Advertising router */
414
  s32 sn;                        /* LS Sequence number */
415 b49e6f5a Ondrej Zajicek
#define LSA_INITSEQNO ((s32) 0x80000001)
416
#define LSA_MAXSEQNO ((s32) 0x7fffffff)
417 2c1d1cc7 Ondrej Filip
  u16 checksum;
418 2e10a170 Ondrej Filip
  u16 length;
419 ce17d4c1 Ondrej Filip
};
420
421 fdb19982 Ondrej Filip
422 c3226991 Ondrej Zajicek
#define LSART_PTP 1
423
#define LSART_NET 2
424
#define LSART_STUB 3
425
#define LSART_VLNK 4
426
427
428
#ifdef OSPFv2
429 fdb19982 Ondrej Filip
430 2e10a170 Ondrej Filip
struct ospf_lsa_rt
431
{
432 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
433 c3226991 Ondrej Zajicek
  u16 options;        /* VEB flags only */
434 ce17d4c1 Ondrej Filip
  u16 links;
435 c15e5690 Ondrej Zajicek
#else
436
  u16 links;
437
  u16 options;        /* VEB flags only */
438
#endif
439 ce17d4c1 Ondrej Filip
};
440
441 2e10a170 Ondrej Filip
struct ospf_lsa_rt_link
442
{
443 ce17d4c1 Ondrej Filip
  u32 id;
444
  u32 data;
445 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
446 ce17d4c1 Ondrej Filip
  u8 type;
447 c15e5690 Ondrej Zajicek
  u8 padding;
448 ce17d4c1 Ondrej Filip
  u16 metric;
449 c15e5690 Ondrej Zajicek
#else
450
  u16 metric;
451
  u8 padding;
452
  u8 type;
453
#endif
454 ce17d4c1 Ondrej Filip
};
455
456 c3226991 Ondrej Zajicek
struct ospf_lsa_net
457
{
458
  ip_addr netmask;
459
  u32 routers[];
460
};
461
462
struct ospf_lsa_sum
463
{
464
  ip_addr netmask;
465
  u32 metric;
466
};
467
468
struct ospf_lsa_ext
469
{
470
  ip_addr netmask;
471
  u32 metric;
472
  ip_addr fwaddr;
473
  u32 tag;
474
};
475
476 a6bc04d5 Ondrej Zajicek
#define LSA_SUM_TOS  0xFF000000
477
#define LSA_EXT_TOS  0x7F000000
478 c3226991 Ondrej Zajicek
#define LSA_EXT_EBIT 0x80000000
479
480 061ab802 Ondrej Zajicek
/* Endianity swap for lsa->type */
481
#define ntoht(x) x
482
#define htont(x) x
483
484 c3226991 Ondrej Zajicek
485
#else  /* OSPFv3 */
486
487
struct ospf_lsa_rt
488
{
489
  u32 options;
490
};
491
492
struct ospf_lsa_rt_link
493
{
494 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
495 c3226991 Ondrej Zajicek
  u8 type;
496 ce17d4c1 Ondrej Filip
  u8 padding;
497
  u16 metric;
498 c15e5690 Ondrej Zajicek
#else
499
  u16 metric;
500
  u8 padding;
501
  u8 type;
502
#endif
503 c3226991 Ondrej Zajicek
  u32 lif;        /* Local interface ID */
504
  u32 nif;        /* Neighbor interface ID */
505
  u32 id;        /* Neighbor router ID */
506 2c1d1cc7 Ondrej Filip
};
507
508 2e10a170 Ondrej Filip
struct ospf_lsa_net
509
{
510 c3226991 Ondrej Zajicek
  u32 options;
511
  u32 routers[];
512 dfa9a53a Ondrej Filip
};
513
514 c3226991 Ondrej Zajicek
struct ospf_lsa_sum_net
515 2e10a170 Ondrej Filip
{
516 c3226991 Ondrej Zajicek
  u32 metric;
517
  u32 prefix[];
518 ce17d4c1 Ondrej Filip
};
519
520 c3226991 Ondrej Zajicek
struct ospf_lsa_sum_rt
521
{
522
  u32 options;
523
  u32 metric;
524
  u32 drid;
525
};
526 98ac6176 Ondrej Filip
527
struct ospf_lsa_ext
528 2e10a170 Ondrej Filip
{
529 c3226991 Ondrej Zajicek
  u32 metric;
530
  u32 rest[];
531
};
532
533
struct ospf_lsa_link
534
{
535
  u32 options;
536
  ip_addr lladdr;
537
  u32 pxcount;
538
  u32 rest[];
539
};
540
541
struct ospf_lsa_prefix
542
{
543 c15e5690 Ondrej Zajicek
#ifdef CPU_BIG_ENDIAN
544 c3226991 Ondrej Zajicek
  u16 pxcount;
545
  u16 ref_type;
546 c15e5690 Ondrej Zajicek
#else
547
  u16 ref_type;
548
  u16 pxcount;
549
#endif
550 c3226991 Ondrej Zajicek
  u32 ref_id;
551
  u32 ref_rt;
552
  u32 rest[];
553 98ac6176 Ondrej Filip
};
554
555 c3226991 Ondrej Zajicek
#define LSA_EXT_EBIT 0x4000000
556
#define LSA_EXT_FBIT 0x2000000
557
#define LSA_EXT_TBIT 0x1000000
558
559 061ab802 Ondrej Zajicek
/* Endianity swap for lsa->type */
560
#define ntoht(x) ntohs(x)
561
#define htont(x) htons(x)
562
563 c3226991 Ondrej Zajicek
#endif
564
565
#define METRIC_MASK  0x00FFFFFF
566
#define OPTIONS_MASK 0x00FFFFFF
567
568 b66abe8e Ondrej Zajicek
static inline unsigned
569
lsa_rt_count(struct ospf_lsa_header *lsa)
570 c3226991 Ondrej Zajicek
{
571
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_rt))
572
    / sizeof(struct ospf_lsa_rt_link);
573
}
574
575 b66abe8e Ondrej Zajicek
static inline unsigned
576
lsa_net_count(struct ospf_lsa_header *lsa)
577 c3226991 Ondrej Zajicek
{
578
  return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net))
579
    / sizeof(u32);
580
}
581
582
583 b66abe8e Ondrej Zajicek
#ifdef OSPFv3
584
585 a6bc04d5 Ondrej Zajicek
#define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
586
#define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
587
588 b66abe8e Ondrej Zajicek
static inline u32 *
589
lsa_get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest)
590
{
591
  u8 pxl = (*buf >> 24);
592
  *pxopts = (*buf >> 16);
593
  *rest = *buf;
594
  *pxlen = pxl;
595
  buf++;
596
597
  *addr = IPA_NONE;
598
599
  if (pxl > 0)
600
    _I0(*addr) = *buf++;
601
  if (pxl > 32)
602
    _I1(*addr) = *buf++;
603
  if (pxl > 64)
604
    _I2(*addr) = *buf++;
605
  if (pxl > 96)
606
    _I3(*addr) = *buf++;
607
608 ab164971 Ondrej Zajicek
  /* Clean up remaining bits */
609
  if (pxl < 128)
610
    addr->addr[pxl / 32] &= u32_mkmask(pxl % 32);
611
612 b66abe8e Ondrej Zajicek
  return buf;
613
}
614
615
static inline u32 *
616
lsa_get_ipv6_addr(u32 *buf, ip_addr *addr)
617
{
618
  *addr = *(ip_addr *) buf;
619
  return buf + 4;
620
}
621
622 a6bc04d5 Ondrej Zajicek
static inline u32 *
623
put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh)
624
{
625
  *buf++ = ((pxlen << 24) | (pxopts << 16) | lh);
626
627
  if (pxlen > 0)
628
    *buf++ = _I0(addr);
629
  if (pxlen > 32)
630
    *buf++ = _I1(addr);
631
  if (pxlen > 64)
632
    *buf++ = _I2(addr);
633
  if (pxlen > 96)
634
    *buf++ = _I3(addr);
635
  return buf;
636
}
637
638
static inline u32 *
639
put_ipv6_addr(u32 *buf, ip_addr addr)
640
{
641
  *(ip_addr *) buf = addr;
642
  return buf + 4;
643
}
644
645 b66abe8e Ondrej Zajicek
#endif
646
647
648
649 2e10a170 Ondrej Filip
struct ospf_lsreq_header
650
{
651 c3226991 Ondrej Zajicek
  u32 type;
652 6d2b3211 Ondrej Filip
  u32 id;
653 2e10a170 Ondrej Filip
  u32 rt;                        /* Advertising router */
654 6d2b3211 Ondrej Filip
};
655
656 2e10a170 Ondrej Filip
struct l_lsr_head
657
{
658 f45fd316 Ondrej Filip
  node n;
659
  struct ospf_lsreq_header lsh;
660
};
661
662 de769e24 Ondrej Filip
663 c76674f0 Ondrej Filip
struct ospf_neighbor
664
{
665 e83dc0d7 Ondrej Filip
  node n;
666 035f6acb Ondrej Filip
  pool *pool;
667 903a3f39 Ondrej Filip
  struct ospf_iface *ifa;
668 2c1d1cc7 Ondrej Filip
  u8 state;
669 c76674f0 Ondrej Filip
#define NEIGHBOR_DOWN 0
670 cd70d934 Ondrej Filip
#define NEIGHBOR_ATTEMPT 1
671
#define NEIGHBOR_INIT 2
672
#define NEIGHBOR_2WAY 3
673 c76674f0 Ondrej Filip
#define NEIGHBOR_EXSTART 4
674 903a3f39 Ondrej Filip
#define NEIGHBOR_EXCHANGE 5
675
#define NEIGHBOR_LOADING 6
676
#define NEIGHBOR_FULL 7
677 2e10a170 Ondrej Filip
  timer *inactim;                /* Inactivity timer */
678 04c6319a Ondrej Filip
  union imms imms;                /* I, M, Master/slave received */
679 2e10a170 Ondrej Filip
  u32 dds;                        /* DD Sequence number being sent */
680
  u32 ddr;                        /* last Dat Des packet received */
681 04c6319a Ondrej Filip
  union imms myimms;                /* I, M Master/slave */
682 2e10a170 Ondrej Filip
  u32 rid;                        /* Router ID */
683
  ip_addr ip;                        /* IP of it's interface */
684
  u8 priority;                        /* Priority */
685
  u8 adj;                        /* built adjacency? */
686 c3226991 Ondrej Zajicek
  u32 options;                        /* Options received */
687
688
  /* dr and bdr store IP address in OSPFv2 and router ID in OSPFv3,
689
     we use the same type to simplify handling */
690
  u32 dr;                        /* Neigbour's idea of DR */
691
  u32 bdr;                        /* Neigbour's idea of BDR */
692
693
#ifdef OSPFv3
694
  u32 iface_id;                        /* ID of Neighbour's iface connected to common network */
695
#endif
696
697 2e10a170 Ondrej Filip
  siterator dbsi;                /* Database summary list iterator */
698
  slist lsrql;                        /* Link state request */
699
  struct top_graph *lsrqh;        /* LSA graph */
700 30147b89 Ondrej Filip
  siterator lsrqi;
701 2e10a170 Ondrej Filip
  slist lsrtl;                        /* Link state retransmission list */
702 30147b89 Ondrej Filip
  siterator lsrti;
703 921a93f2 Ondrej Filip
  struct top_graph *lsrth;
704 2e10a170 Ondrej Filip
  void *ldbdes;                        /* Last database description packet */
705
  timer *rxmt_timer;                /* RXMT timer */
706 c76ba51a Ondrej Filip
  list ackl[2];
707
#define ACKL_DIRECT 0
708
#define ACKL_DELAY 1
709 2e10a170 Ondrej Filip
  timer *ackd_timer;                /* Delayed ack timer */
710 3e2bd0f1 Ondrej Filip
  u32 csn;                      /* Last received crypt seq number (for MD5) */
711 c76674f0 Ondrej Filip
};
712
713 96f1b8ba Ondrej Filip
/* Definitions for interface state machine */
714 2e10a170 Ondrej Filip
#define ISM_UP 0                /* Interface Up */
715
#define ISM_WAITF 1                /* Wait timer fired */
716
#define ISM_BACKS 2                /* Backup seen */
717
#define ISM_NEICH 3                /* Neighbor change */
718 d9e7e1b1 Ondrej Zajicek
#define ISM_LOOP 4                /* Link down */
719
#define ISM_UNLOOP 5                /* Link up */
720 2e10a170 Ondrej Filip
#define ISM_DOWN 6                /* Interface down */
721 96f1b8ba Ondrej Filip
722
/* Definitions for neighbor state machine */
723 2e10a170 Ondrej Filip
#define INM_HELLOREC 0                /* Hello Received */
724
#define INM_START 1                /* Neighbor start - for NBMA */
725
#define INM_2WAYREC 2                /* 2-Way received */
726
#define INM_NEGDONE 3                /* Negotiation done */
727
#define INM_EXDONE 4                /* Exchange done */
728
#define INM_BADLSREQ 5                /* Bad LS Request */
729
#define INM_LOADDONE 6                /* Load done */
730
#define INM_ADJOK 7                /* AdjOK? */
731
#define INM_SEQMIS 8                /* Sequence number mismatch */
732
#define INM_1WAYREC 9                /* 1-Way */
733
#define INM_KILLNBR 10                /* Kill Neighbor */
734
#define INM_INACTTIM 11                /* Inactivity timer */
735
#define INM_LLDOWN 12                /* Line down */
736
737
struct ospf_area
738
{
739 8496b2e4 Ondrej Filip
  node n;
740 15087574 Ondrej Filip
  u32 areaid;
741 41b612c3 Ondrej Zajicek
  struct ospf_area_config *ac;        /* Related area config */
742 de30342f Ondrej Filip
  struct top_hash_entry *rt;        /* My own router LSA */
743 c3226991 Ondrej Zajicek
  struct top_hash_entry *pxr_lsa; /* Originated prefix LSA */
744 dfa9a53a Ondrej Filip
  list cand;                        /* List of candidates for RT calc. */
745 98ac6176 Ondrej Filip
  struct fib net_fib;                /* Networks to advertise or not */
746 ed317862 Ondrej Zajicek
  struct fib enet_fib;                /* External networks for NSSAs */
747 c3226991 Ondrej Zajicek
  u32 options;                        /* Optional features */
748 8e48831a Ondrej Zajicek
  byte origrt;                        /* Rt lsa origination scheduled? */
749
  byte trcap;                        /* Transit capability? */
750
  byte marked;                        /* Used in OSPF reconfigure */
751 4160a9dd Ondrej Zajicek
  byte translate;                /* Translator state (TRANS_*), for NSSA ABR  */
752
  timer *translator_timer;        /* For NSSA translator switch */
753 c45f48fb Ondrej Filip
  struct proto_ospf *po;
754 98ac6176 Ondrej Filip
  struct fib rtr;                /* Routing tables for routers */
755 15087574 Ondrej Filip
};
756
757 4160a9dd Ondrej Zajicek
#define TRANS_OFF        0
758
#define TRANS_ON        1
759
#define TRANS_WAIT        2        /* Waiting before the end of translation */
760
761 2e10a170 Ondrej Filip
struct proto_ospf
762
{
763 4364b47e Ondrej Filip
  struct proto proto;
764 b8f17cf1 Ondrej Filip
  timer *disp_timer;                /* OSPF proto dispatcher */
765
  unsigned tick;
766 86c84d76 Ondrej Filip
  struct top_graph *gr;                /* LSA graph */
767
  slist lsal;                        /* List of all LSA's */
768 f7574707 Ondrej Zajicek
  int calcrt;                        /* Routing table calculation scheduled?
769
                                   0=no, 1=normal, 2=forced reload */
770 4364b47e Ondrej Filip
  list iface_list;                /* Interfaces we really use */
771 8496b2e4 Ondrej Filip
  list area_list;
772 15087574 Ondrej Filip
  int areano;                        /* Number of area I belong to */
773 98ac6176 Ondrej Filip
  struct fib rtf;                /* Routing table */
774 57c574d8 Ondrej Zajicek
  byte rfc1583;                        /* RFC1583 compatibility */
775 f623ab98 Ondrej Zajicek
  byte stub_router;                /* Do not forward transit traffic */
776 57c574d8 Ondrej Zajicek
  byte ebit;                        /* Did I originate any ext lsa? */
777
  byte ecmp;                        /* Maximal number of nexthops in ECMP route, or 0 */
778 98ac6176 Ondrej Filip
  struct ospf_area *backbone;        /* If exists */
779 3d15dcdb Ondrej Zajicek
  void *lsab;                        /* LSA buffer used when originating router LSAs */
780
  int lsab_size, lsab_used;
781 57c574d8 Ondrej Zajicek
  linpool *nhpool;                /* Linpool used for next hops computed in SPF */
782 8a70a13e Ondrej Zajicek
  u32 router_id;
783 dd4da6f6 Ondrej Zajicek
  u32 last_vlink_id;                /* Interface IDs for vlinks (starts at 0x80000000) */
784 6ba36f06 Martin Mares
};
785
786 2e10a170 Ondrej Filip
struct ospf_iface_patt
787
{
788 89d6782d Ondrej Filip
  struct iface_patt i;
789 8e48831a Ondrej Zajicek
  u32 type;
790
  u32 stub;
791 7df86c25 Ondrej Filip
  u32 cost;
792
  u32 helloint;
793
  u32 rxmtint;
794
  u32 pollint;
795
  u32 waitint;
796
  u32 deadc;
797 8e48831a Ondrej Zajicek
  u32 deadint;
798
  u32 inftransdelay;
799
  list nbma_list;
800 95127cbb Ondrej Zajicek
  u32 priority;
801 8e48831a Ondrej Zajicek
  u32 voa;
802 98ac6176 Ondrej Filip
  u32 vid;
803 d9e7e1b1 Ondrej Zajicek
  u16 rxbuf;
804 94c42054 Ondrej Filip
#define OSPF_RXBUF_NORMAL 0
805
#define OSPF_RXBUF_LARGE 1
806
#define OSPF_RXBUF_MINSIZE 256        /* Minimal allowed size */
807 95127cbb Ondrej Zajicek
  u16 autype;                        /* Not really used in OSPFv3 */
808 c3226991 Ondrej Zajicek
#define OSPF_AUTH_NONE 0
809
#define OSPF_AUTH_SIMPLE 1
810
#define OSPF_AUTH_CRYPT 2
811
#define OSPF_AUTH_CRYPT_SIZE 16
812 95127cbb Ondrej Zajicek
  u8 strictnbma;
813
  u8 check_link;
814
  u8 ecmp_weight;
815
  u8 real_bcast;                /* Not really used in OSPFv3 */
816 8df02847 Ondrej Zajicek
  u8 ptp_netmask;                /* bool but 2 for unspecified */
817 c3226991 Ondrej Zajicek
818
#ifdef OSPFv2
819
  list *passwords;
820
#endif
821
822
#ifdef OSPFv3
823
  u8 instance_id;
824
#endif
825 89d6782d Ondrej Filip
};
826
827 b8f17cf1 Ondrej Filip
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
828 2e10a170 Ondrej Filip
                        struct linpool *pool);
829 5919c66e Martin Mares
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
830
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
831 70a38319 Ondrej Filip
void schedule_rt_lsa(struct ospf_area *oa);
832 b8f17cf1 Ondrej Filip
void schedule_rtcalc(struct proto_ospf *po);
833 b9ed99f7 Ondrej Filip
void schedule_net_lsa(struct ospf_iface *ifa);
834 be862406 Ondrej Zajicek
835 8e48831a Ondrej Zajicek
struct ospf_area *ospf_find_area(struct proto_ospf *po, u32 aid);
836 41b612c3 Ondrej Zajicek
static inline struct ospf_area *ospf_main_area(struct proto_ospf *po)
837
{ return (po->areano == 1) ? HEAD(po->area_list) : po->backbone; }
838
839
static inline int oa_is_stub(struct ospf_area *oa)
840
{ return (oa->options & (OPT_E | OPT_N)) == 0; }
841
static inline int oa_is_ext(struct ospf_area *oa)
842
{ return oa->options & OPT_E; }
843
static inline int oa_is_nssa(struct ospf_area *oa)
844
{ return oa->options & OPT_N; }
845
846 8e48831a Ondrej Zajicek
847 be862406 Ondrej Zajicek
#ifdef OSPFv3
848
void schedule_link_lsa(struct ospf_iface *ifa);
849
#else
850 e81b440f Ondrej Zajicek
static inline void schedule_link_lsa(struct ospf_iface *ifa UNUSED) {}
851 be862406 Ondrej Zajicek
#endif
852
853 c4f0f014 Ondrej Filip
void ospf_sh_neigh(struct proto *p, char *iff);
854 4ab4e977 Ondrej Filip
void ospf_sh(struct proto *p);
855 c4f0f014 Ondrej Filip
void ospf_sh_iface(struct proto *p, char *iff);
856 0ea8fb4a Ondrej Zajicek
void ospf_sh_state(struct proto *p, int verbose, int reachable);
857 20ab192b Ondrej Zajicek
858
#define SH_ROUTER_SELF 0xffffffff
859
860
struct lsadb_show_data {
861
  struct symbol *name;        /* Protocol to request data from */
862
  u16 type;                /* LSA Type, 0 -> all */
863
  u16 scope;                /* Scope, 0 -> all, hack to handle link scope as 1 */
864
  u32 area;                /* Specified for area scope */
865
  u32 lsid;                /* LSA ID, 0 -> all */
866
  u32 router;                /* Advertising router, 0 -> all */
867
};
868
869
void ospf_sh_lsadb(struct lsadb_show_data *ld);
870 05198c12 Ondrej Zajicek
871 4364b47e Ondrej Filip
872 5919c66e Martin Mares
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
873
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
874
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
875 c27b2449 Ondrej Zajicek
#define EA_OSPF_ROUTER_ID EA_CODE(EAP_OSPF, 3)
876 5919c66e Martin Mares
877 98ac6176 Ondrej Filip
#include "proto/ospf/rt.h"
878 4364b47e Ondrej Filip
#include "proto/ospf/hello.h"
879
#include "proto/ospf/packet.h"
880
#include "proto/ospf/iface.h"
881
#include "proto/ospf/neighbor.h"
882
#include "proto/ospf/topology.h"
883
#include "proto/ospf/dbdes.h"
884 6d2b3211 Ondrej Filip
#include "proto/ospf/lsreq.h"
885 f45fd316 Ondrej Filip
#include "proto/ospf/lsupd.h"
886
#include "proto/ospf/lsack.h"
887
#include "proto/ospf/lsalib.h"
888 6ba36f06 Martin Mares
889 c1f8dc91 Ondrej Filip
#endif /* _BIRD_OSPF_H_ */