Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ 1a61882d

History | View | Annotate | Download (11.3 KB)

1
/*
2
 *        BIRD -- OSPF
3
 *
4
 *        (c) 1999 - 2000 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

    
12
#define SIPH SIZE_OF_IP_HEADER
13
#define MAXNETS 10
14
#ifdef LOCAL_DEBUG
15
#define OSPF_FORCE_DEBUG 1
16
#else
17
#define OSPF_FORCE_DEBUG 0
18
#endif
19
#define OSPF_TRACE(flags, msg, args...) do { if ((p->debug & flags) || OSPF_FORCE_DEBUG) \
20
  log(L_TRACE "%s: " msg, p->name , ## args ); } while(0)
21

    
22
#include "nest/bird.h"
23

    
24
#include "lib/checksum.h"
25
#include "lib/ip.h"
26
#include "lib/lists.h"
27
#include "lib/slists.h"
28
#include "lib/socket.h"
29
#include "lib/timer.h"
30
#include "lib/resource.h"
31
#include "nest/protocol.h"
32
#include "nest/iface.h"
33
#include "nest/route.h"
34
#include "nest/cli.h"
35
#include "nest/locks.h"
36
#include "conf/conf.h"
37
#include "lib/string.h"
38

    
39
#define OSPF_PROTO 89
40
#ifndef IPV6
41
#define OSPF_VERSION 2
42
#define AllSPFRouters ipa_from_u32(0xe0000005)        /* 224.0.0.5 */
43
#define AllDRouters ipa_from_u32(0xe0000006)        /* 224.0.0.6 */
44
#define DEFAULTDES ipa_from_u32(0)
45
#else
46
#error OSPF for IPv6 is not implemented (mail to Feela <feela@network.cz>)
47
#endif
48

    
49

    
50
#define LSREFRESHTIME 1800        /* 30 minutes */
51
#define MINLSINTERVAL 5
52
#define MINLSARRIVAL 1
53
#define LSINFINITY 0xffff        /* RFC says 0xffffff ??? */
54

    
55
#define DEFAULT_OSPFTICK 5
56
#define DEFAULT_AREATICK 4
57
#define DEFAULT_RFC1583 1        /* compatibility with rfc1583 */
58

    
59

    
60
struct ospf_config
61
{
62
  struct proto_config c;
63
  unsigned tick;
64
  int rfc1583;
65
  list area_list;
66
};
67

    
68
struct nbma_node
69
{
70
  node n;
71
  ip_addr ip;
72
  int eligible;
73
};
74

    
75
struct area_net
76
{
77
  node n;
78
  struct prefix px;
79
  int hidden;
80
  int active;
81
  int oldactive;
82
};
83

    
84
struct ospf_area_config
85
{
86
  node n;
87
  u32 areaid;
88
  int stub;
89
  unsigned tick;
90
  list patt_list;
91
  list net_list;
92
};
93

    
94
struct ospf_iface
95
{
96
  node n;
97
  struct proto_ospf *proto;
98
  struct iface *iface;                /* Nest's iface */
99
  struct ospf_area *oa;
100
  struct object_lock *lock;
101
  u32 an;                        /* Area number */
102
  sock *hello_sk;                /* Hello socket */
103
  sock *dr_sk;                        /* For states DR or BACKUP */
104
  sock *ip_sk;                        /* IP socket (for DD ...) */
105
  list neigh_list;                /* List of neigbours */
106
  u16 cost;                        /* Cost of iface */
107
  u16 inftransdelay;                /* The estimated number of seconds it takes to
108
                                   transmit a Link State Update Packet over this
109
                                   interface.  LSAs contained in the update */
110
  u8 priority;                        /* A router priority for DR election */
111
  u16 helloint;                        /* number of seconds between hello sending */
112
  u32 waitint;                        /* number of sec before changing state from wait */
113
  u32 rxmtint;                        /* number of seconds between LSA retransmissions */
114
  u32 pollint;                        /* Poll interval */
115
  u32 deadc;                        /* after "deadint" missing hellos is router dead */
116
  u16 autype;
117
  u8 aukey[8];
118
  u8 options;
119
  ip_addr drip;                        /* Designated router */
120
  u32 drid;
121
  ip_addr bdrip;                /* Backup DR */
122
  u32 bdrid;
123
  u8 type;                        /* OSPF view of type */
124
#define OSPF_IT_BCAST 0
125
#define OSPF_IT_NBMA 1
126
#define OSPF_IT_PTP 2
127
#define OSPF_IT_VLINK 3
128
#define OSPF_IT_UNDEF 4
129
  u8 strictnbma;                /* Can I talk with unknown neighbors? */
130
  u8 stub;                        /* Inactive interface */
131
  u8 ioprob;
132
#define OSPF_I_OK 0                /* Everything OK */
133
#define OSPF_I_MC 1                /* I didn't open MC socket */
134
#define OSPF_I_IP 2                /* I didn't open IP socet */
135
  u8 state;                        /* Interface state machine */
136
#define OSPF_IS_DOWN 0                /* Not working */
137
#define OSPF_IS_LOOP 1                /* Should never happen */
138
#define OSPF_IS_WAITING 2        /* Waiting for Wait timer */
139
#define OSPF_IS_PTP 3                /* PTP operational */
140
#define OSPF_IS_DROTHER 4        /* I'm on BCAST or NBMA and I'm not DR */
141
#define OSPF_IS_BACKUP 5        /* I'm BDR */
142
#define OSPF_IS_DR 6                /* I'm DR */
143
  timer *wait_timer;                /* WAIT timer */
144
  timer *hello_timer;                /* HELLOINT timer */
145
  timer *poll_timer;                /* Poll Interval - for NBMA */
146
/* Default values for interface parameters */
147
#define COST_D 10
148
#define RXMTINT_D 5
149
#define INFTRANSDELAY_D 1
150
#define PRIORITY_D 1
151
#define HELLOINT_D 10
152
#define POLLINT_D 20
153
#define DEADC_D 4
154
#define WAIT_DMH 4                /* Value of Wait timer - not found it in RFC 
155
                                 * - using 4*HELLO
156
                                 */
157
  struct top_hash_entry *nlsa;        /* Originated net lsa */
158
  int orignet;                        /* Schedule network LSA origination */
159
  int fadj;                        /* Number of full adjacent neigh */
160
  list nbma_list;
161
};
162

    
163
struct ospf_packet
164
{
165
  u8 version;
166
  u8 type;
167
#define HELLO_P 1                /* Hello */
168
#define DBDES_P 2                /* Database description */
169
#define LSREQ_P 3                /* Link state request */
170
#define LSUPD_P 4                /* Link state update */
171
#define LSACK_P 5                /* Link state acknowledgement */
172
  u16 length;
173
  u32 routerid;
174
  u32 areaid;
175
#define BACKBONE 0
176
  u16 checksum;
177
  u16 autype;
178
  u8 authetication[8];
179
};
180

    
181
struct ospf_hello_packet
182
{
183
  struct ospf_packet ospf_packet;
184
  ip_addr netmask;
185
  u16 helloint;
186
  u8 options;
187
  u8 priority;
188
  u32 deadint;
189
  ip_addr dr;
190
  ip_addr bdr;
191
};
192

    
193
struct immsb
194
{
195
#ifdef _BIG_ENDIAN
196
  u8 padding:5;
197
  u8 i:1;
198
  u8 m:1;
199
  u8 ms:1;
200
#else
201
  u8 ms:1;
202
  u8 m:1;
203
  u8 i:1;
204
  u8 padding:5;
205
#endif
206
};
207

    
208
union imms
209
{
210
  u8 byte;
211
  struct immsb bit;
212
};
213

    
214
struct ospf_dbdes_packet
215
{
216
  struct ospf_packet ospf_packet;
217
  u16 iface_mtu;
218
  u8 options;
219
  union imms imms;                /* I, M, MS bits */
220
#define DBDES_MS 1
221
#define DBDES_M 2
222
#define DBDES_I 4
223
  u32 ddseq;
224
};
225

    
226

    
227
struct ospf_lsa_header
228
{
229
  u16 age;                        /* LS Age */
230
#define LSA_MAXAGE 3600                /* 1 hour */
231
#define LSA_CHECKAGE 300        /* 5 minutes */
232
#define LSA_MAXAGEDIFF 900        /* 15 minutes */
233
  u8 options;
234
  u8 type;
235
  u32 id;
236
#define LSA_T_RT 1
237
#define LSA_T_NET 2
238
#define LSA_T_SUM_NET 3
239
#define LSA_T_SUM_RT 4
240
#define LSA_T_EXT 5
241
  u32 rt;                        /* Advertising router */
242
  s32 sn;                        /* LS Sequence number */
243
#define LSA_INITSEQNO 0x80000001
244
#define LSA_MAXSEQNO 0x7fffffff
245
  u16 checksum;
246
  u16 length;
247
};
248

    
249
struct vebb
250
{
251
#ifdef _BIG_ENDIAN
252
  u8 padding:5;
253
  u8 v:1;
254
  u8 e:1;
255
  u8 b:1;
256
#else
257
  u8 b:1;
258
  u8 e:1;
259
  u8 v:1;
260
  u8 padding:5;
261
#endif
262
};
263

    
264
union veb
265
{
266
  u8 byte;
267
  struct vebb bit;
268
};
269

    
270
struct ospf_lsa_rt
271
{
272
  union veb veb;
273
  u8 padding;
274
  u16 links;
275
};
276

    
277
struct ospf_lsa_rt_link
278
{
279
  u32 id;
280
  u32 data;
281
  u8 type;
282
#define LSART_PTP 1
283
#define LSART_NET 2
284
#define LSART_STUB 3
285
#define LSART_VLNK 4
286
  u8 notos;
287
  u16 metric;
288
};
289

    
290
struct ospf_lsa_rt_link_tos
291
{                                /* Actually we ignore TOS. This is useless */
292
  u8 tos;
293
  u8 padding;
294
  u16 metric;
295
};
296

    
297
struct ospf_lsa_net
298
{
299
  ip_addr netmask;
300
};
301

    
302
struct ospf_lsa_summ
303
{
304
  ip_addr netmask;
305
};
306

    
307
struct ospf_lsa_summ_net
308
{
309
  u8 tos;
310
  u8 padding;
311
  u16 metric;
312
};
313

    
314
struct ospf_lsa_ext
315
{
316
  ip_addr netmask;
317
};
318

    
319
struct ospf_lsa_ext_tos
320
{
321
  u8 etos;
322
  u8 padding;
323
  u16 metric;
324
  ip_addr fwaddr;
325
  u32 tag;
326
};
327

    
328
struct ospf_lsreq_packet
329
{
330
  struct ospf_packet ospf_packet;
331
};
332

    
333
struct ospf_lsreq_header
334
{
335
  u16 padd1;
336
  u8 padd2;
337
  u8 type;
338
  u32 id;
339
  u32 rt;                        /* Advertising router */
340
};
341

    
342
struct l_lsr_head
343
{
344
  node n;
345
  struct ospf_lsreq_header lsh;
346
};
347

    
348
struct ospf_lsupd_packet
349
{
350
  struct ospf_packet ospf_packet;
351
  u32 lsano;                        /* Number of LSA's */
352
};
353

    
354
struct ospf_lsack_packet
355
{
356
  struct ospf_packet ospf_packet;
357
};
358

    
359

    
360
struct ospf_neighbor
361
{
362
  node n;
363
  pool *pool;
364
  struct ospf_iface *ifa;
365
  u8 state;
366
#define NEIGHBOR_DOWN 0
367
#define NEIGHBOR_ATTEMPT 1
368
#define NEIGHBOR_INIT 2
369
#define NEIGHBOR_2WAY 3
370
#define NEIGHBOR_EXSTART 4
371
#define NEIGHBOR_EXCHANGE 5
372
#define NEIGHBOR_LOADING 6
373
#define NEIGHBOR_FULL 7
374
  timer *inactim;                /* Inactivity timer */
375
  union imms imms;                /* I, M, Master/slave received */
376
  u32 dds;                        /* DD Sequence number being sent */
377
  u32 ddr;                        /* last Dat Des packet received */
378
  union imms myimms;                /* I, M Master/slave */
379
  u32 rid;                        /* Router ID */
380
  ip_addr ip;                        /* IP of it's interface */
381
  u8 priority;                        /* Priority */
382
  u8 options;                        /* Options received */
383
  ip_addr dr;                        /* Neigbour's idea of DR */
384
  ip_addr bdr;                        /* Neigbour's idea of BDR */
385
  u8 adj;                        /* built adjacency? */
386
  siterator dbsi;                /* Database summary list iterator */
387
  slist lsrql;                        /* Link state request */
388
  struct top_graph *lsrqh;        /* LSA graph */
389
  siterator lsrqi;
390
  slist lsrtl;                        /* Link state retransmission list */
391
  siterator lsrti;
392
  struct top_graph *lsrth;
393
  void *ldbdes;                        /* Last database description packet */
394
  timer *rxmt_timer;                /* RXMT timer */
395
  list ackl[2];
396
#define ACKL_DIRECT 0
397
#define ACKL_DELAY 1
398
  timer *ackd_timer;                /* Delayed ack timer */
399
};
400

    
401
/* Definitions for interface state machine */
402
#define ISM_UP 0                /* Interface Up */
403
#define ISM_WAITF 1                /* Wait timer fired */
404
#define ISM_BACKS 2                /* Backup seen */
405
#define ISM_NEICH 3                /* Neighbor change */
406
#define ISM_LOOP 4                /* Loop indicated */
407
#define ISM_UNLOOP 5                /* Unloop indicated */
408
#define ISM_DOWN 6                /* Interface down */
409

    
410
/* Definitions for neighbor state machine */
411
#define INM_HELLOREC 0                /* Hello Received */
412
#define INM_START 1                /* Neighbor start - for NBMA */
413
#define INM_2WAYREC 2                /* 2-Way received */
414
#define INM_NEGDONE 3                /* Negotiation done */
415
#define INM_EXDONE 4                /* Exchange done */
416
#define INM_BADLSREQ 5                /* Bad LS Request */
417
#define INM_LOADDONE 6                /* Load done */
418
#define INM_ADJOK 7                /* AdjOK? */
419
#define INM_SEQMIS 8                /* Sequence number mismatch */
420
#define INM_1WAYREC 9                /* 1-Way */
421
#define INM_KILLNBR 10                /* Kill Neighbor */
422
#define INM_INACTTIM 11                /* Inactivity timer */
423
#define INM_LLDOWN 12                /* Line down */
424

    
425
struct ospf_area
426
{
427
  node n;
428
  u32 areaid;
429
  timer *disp_timer;                /* Area's dispatcher hear beat */
430
  int origrt;                        /* Rt lsa origination scheduled? */
431
  struct top_graph *gr;                /* LSA graph */
432
  slist lsal;                        /* List of all LSA's */
433
  struct top_hash_entry *rt;        /* My own router LSA */
434
  list cand;                        /* List of candidates for RT calc. */
435
  list net_list;                /* Networks to advertise or not */
436
  int stub;
437
  int trcap;                        /* Transit capability? */
438
  struct proto_ospf *po;
439
  unsigned tick;
440
};
441

    
442
struct proto_ospf
443
{
444
  struct proto proto;
445
  timer *disp_timer;                /* OSPF proto dispatcher */
446
  unsigned tick;
447
  int calcrt;                        /* Routing table calculation scheduled? */
448
  list iface_list;                /* Interfaces we really use */
449
  list area_list;
450
  int areano;                        /* Number of area I belong to */
451
  struct fib rtf[2];                /* Routing tables */
452
  int rfc1583;                        /* RFC1583 compatibility */
453
  int ebit;                        /* Did I originate any ext lsa? */
454
};
455

    
456
struct ospf_iface_patt
457
{
458
  struct iface_patt i;
459
  u32 cost;
460
  u32 helloint;
461
  u32 rxmtint;
462
  u32 pollint;
463
  u32 inftransdelay;
464
  u32 priority;
465
  u32 waitint;
466
  u32 deadc;
467
  u32 type;
468
  u32 autype;
469
  u32 strictnbma;
470
  u32 stub;
471
/* must be in network byte order */
472
#define AU_NONE htons(0)
473
#define AU_SIMPLE htons(1)
474
#define AU_CRYPT htons(2)
475
  u8 password[8];
476
  list nbma_list;
477
};
478

    
479
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
480
                        struct linpool *pool);
481
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
482
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
483
void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,
484
                    ea_list * attrs);
485
void schedule_rt_lsa(struct ospf_area *oa);
486
void schedule_rtcalc(struct proto_ospf *po);
487
void schedule_net_lsa(struct ospf_iface *ifa);
488
void ospf_sh_neigh(struct proto *p, char *iff);
489
void ospf_sh(struct proto *p);
490
void ospf_sh_iface(struct proto *p, char *iff);
491

    
492
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
493
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
494
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
495

    
496
#include "proto/ospf/hello.h"
497
#include "proto/ospf/packet.h"
498
#include "proto/ospf/iface.h"
499
#include "proto/ospf/neighbor.h"
500
#include "proto/ospf/topology.h"
501
#include "proto/ospf/dbdes.h"
502
#include "proto/ospf/lsreq.h"
503
#include "proto/ospf/lsupd.h"
504
#include "proto/ospf/lsack.h"
505
#include "proto/ospf/lsalib.h"
506
#include "proto/ospf/rt.h"
507

    
508
#endif /* _BIRD_OSPF_H_ */