Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (11.4 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 Multicast address not defined in IPv6
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
#define DISPTICK 7
55

    
56
struct ospf_config {
57
  struct proto_config c;
58
  int rfc1583;
59
  list area_list;
60
};
61

    
62
struct nbma_node {
63
  node n;
64
  ip_addr ip;
65
  int eligible;
66
};
67

    
68
struct area_net {
69
  node n;
70
  ip_addr net;
71
  int mlen;
72
  int hidden;
73
};
74

    
75
struct ospf_area_config {
76
  node n;
77
  u32 areaid;
78
  int stub;
79
  unsigned tick;
80
  list patt_list;
81
  list net_list;
82
};
83

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

    
152
struct ospf_packet {
153
  u8 version;
154
  u8 type;
155
#define HELLO_P 1 /* Hello */
156
#define DBDES_P 2 /* Database description */
157
#define LSREQ_P 3 /* Link state request */
158
#define LSUPD_P 4 /* Link state update */
159
#define LSACK_P 5 /* Link state acknowledgement */
160
  u16 length;
161
  u32 routerid;
162
  u32 areaid;
163
#define BACKBONE 0
164
  u16 checksum;
165
  u16 autype;
166
  u8 authetication[8];
167
};
168

    
169
struct ospf_hello_packet {
170
  struct ospf_packet ospf_packet;
171
  ip_addr netmask;
172
  u16 helloint;
173
  u8 options;
174
  u8 priority;
175
  u32 deadint;
176
  ip_addr dr;
177
  ip_addr bdr;
178
};
179

    
180
struct immsb {
181
#ifdef _BIG_ENDIAN
182
  u8 padding:5;
183
  u8 i:1;
184
  u8 m:1;
185
  u8 ms:1;
186
#else
187
  u8 ms:1;
188
  u8 m:1;
189
  u8 i:1;
190
  u8 padding:5;
191
#endif
192
};
193

    
194
union imms {
195
  u8 byte;
196
  struct immsb bit;
197
};
198

    
199
struct ospf_dbdes_packet {
200
  struct ospf_packet ospf_packet;
201
  u16 iface_mtu;
202
  u8 options;
203
  union imms imms;                /* I, M, MS bits */
204
#define DBDES_MS 1
205
#define DBDES_M 2
206
#define DBDES_I 4
207
  u32 ddseq;
208
};
209

    
210

    
211
struct ospf_lsa_header {
212
  u16 age;        /* LS Age */
213
#define LSA_MAXAGE 3600                 /* 1 hour */
214
#define LSA_CHECKAGE 300                /* 5 minutes */
215
#define LSA_MAXAGEDIFF 900              /* 15 minutes */
216
  u8 options;
217
  u8 type;
218
  u32 id;
219
#define LSA_T_RT 1
220
#define LSA_T_NET 2
221
#define LSA_T_SUM_NET 3
222
#define LSA_T_SUM_RT 4
223
#define LSA_T_EXT 5
224
  u32 rt;                /* Advertising router */
225
  s32 sn;                /* LS Sequence number */
226
#define LSA_INITSEQNO 0x80000001
227
#define LSA_MAXSEQNO 0x7fffffff
228
  u16 checksum;
229
  u16 length;  
230
};
231

    
232
struct vebb {
233
  u8 b:1;
234
  u8 e:1;
235
  u8 v:1;
236
  u8 padding:5;
237
};
238

    
239
union veb {
240
  u8 byte;
241
  struct vebb bit;
242
};
243

    
244
struct ospf_lsa_rt {
245
  union veb veb;
246
#define LSA_RT_V 5
247
#define LSA_RT_E 6
248
#define LSA_RT_B 7
249
  u8 padding;
250
  u16 links;
251
};
252

    
253
struct ospf_lsa_rt_link {
254
  u32 id;
255
  u32 data;
256
  u8 type;
257
#define LSART_PTP 1
258
#define LSART_NET 2
259
#define LSART_STUB 3
260
#define LSART_VLNK 4
261
  u8 notos;
262
  u16 metric;
263
};
264

    
265
struct ospf_lsa_rt_link_tos {        /* Actually we ignore TOS. This is useless */
266
  u8 tos;
267
  u8 padding;
268
  u16 metric;
269
};
270

    
271
struct ospf_lsa_net {
272
  ip_addr netmask;
273
};
274

    
275
struct ospf_lsa_summ {
276
  ip_addr netmask;
277
};
278

    
279
struct ospf_lsa_summ_net {
280
  u8 tos;
281
  u8 padding;
282
  u16 metric;
283
};
284

    
285
struct ospf_lsa_ext {
286
  ip_addr netmask;
287
};
288

    
289
struct ospf_lsa_ext_tos {
290
  u8 etos;
291
  u8 padding;
292
  u16 metric;
293
  ip_addr fwaddr;
294
  u32 tag;
295
};
296

    
297
struct ospf_lsreq_packet {
298
  struct ospf_packet ospf_packet;
299
};
300

    
301
struct ospf_lsreq_header {
302
  u16 padd1;
303
  u8 padd2;
304
  u8 type;
305
  u32 id;
306
  u32 rt;                /* Advertising router */
307
};
308

    
309
struct l_lsr_head {
310
  node n;
311
  struct ospf_lsreq_header lsh;
312
};
313

    
314
struct ospf_lsupd_packet {
315
  struct ospf_packet ospf_packet;
316
  u32 lsano;                /* Number of LSA's */
317
};
318

    
319
struct ospf_lsack_packet {
320
  struct ospf_packet ospf_packet;
321
};
322

    
323

    
324
struct ospf_neighbor
325
{
326
  node n;
327
  struct ospf_iface *ifa;
328
  u8 state;
329
#define NEIGHBOR_DOWN 0
330
#define NEIGHBOR_ATTEMPT 1
331
#define NEIGHBOR_INIT 2
332
#define NEIGHBOR_2WAY 3
333
#define NEIGHBOR_EXSTART 4
334
#define NEIGHBOR_EXCHANGE 5
335
#define NEIGHBOR_LOADING 6
336
#define NEIGHBOR_FULL 7
337
  timer *inactim;        /* Inactivity timer */
338
  union imms imms;                /* I, M, Master/slave received */
339
  u32 dds;                /* DD Sequence number being sent */
340
  u32 ddr;                /* last Dat Des packet received */
341
  union imms myimms;                /* I, M Master/slave */
342
  u32 rid;                /* Router ID */
343
  ip_addr ip;                /* IP of it's interface */
344
  u8 priority;                /* Priority */
345
  u8 options;                /* Options received */
346
  ip_addr dr;                /* Neigbour's idea of DR */
347
  ip_addr bdr;                /* Neigbour's idea of BDR */
348
  u8 adj;                /* built adjacency? */
349
  siterator dbsi;        /* Database summary list iterator */
350
  slist lsrql;                /* Link state request */
351
  struct top_graph *lsrqh;                /* LSA graph */
352
  siterator lsrqi;
353
  slist lsrtl;                /* Link state retransmission list */
354
  siterator lsrti;
355
  struct top_graph *lsrth;
356
  void *ldbdes;                /* Last database description packet */
357
  timer *rxmt_timer;        /* RXMT timer */
358
  timer *lsrr_timer;        /* Link state request retransmition timer */
359
  list ackl;
360
  timer *ackd_timer;        /* Delayed ack timer */
361
};
362

    
363
/* Definitions for interface state machine */
364
#define ISM_UP 0        /* Interface Up */
365
#define ISM_WAITF 1        /* Wait timer fired */
366
#define ISM_BACKS 2        /* Backup seen */
367
#define ISM_NEICH 3        /* Neighbor change */
368
#define ISM_LOOP 4        /* Loop indicated */
369
#define ISM_UNLOOP 5        /* Unloop indicated */
370
#define ISM_DOWN 6        /* Interface down */
371

    
372
/* Definitions for neighbor state machine */
373
#define INM_HELLOREC 0        /* Hello Received */
374
#define INM_START 1        /* Neighbor start - for NBMA */
375
#define INM_2WAYREC 2        /* 2-Way received */
376
#define INM_NEGDONE 3        /* Negotiation done */
377
#define INM_EXDONE 4        /* Exchange done */
378
#define INM_BADLSREQ 5        /* Bad LS Request */
379
#define INM_LOADDONE 6        /* Load done */
380
#define INM_ADJOK 7        /* AdjOK? */
381
#define INM_SEQMIS 8        /* Sequence number mismatch */
382
#define INM_1WAYREC 9        /* 1-Way */
383
#define INM_KILLNBR 10        /* Kill Neighbor */
384
#define INM_INACTTIM 11        /* Inactivity timer */
385
#define INM_LLDOWN 12        /* Line down */
386

    
387
struct ospf_area {
388
  node n;
389
  u32 areaid;
390
  timer *disp_timer;                /* Area's dispatcher hear beat */
391
  int calcrt;                        /* Routing table calculation scheduled? */
392
  int origrt;                        /* Rt lsa origination scheduled? */
393
  struct top_graph *gr;                /* LSA graph */
394
  slist lsal;                        /* List of all LSA's */
395
  struct top_hash_entry *rt;        /* My own router LSA */
396
  list cand;                        /* List of candidates for RT calc. */
397
  list net_list;                /* Networks to advertise or not */
398
  int stub;
399
  int trcap;                        /* Transit capability? */
400
  struct proto_ospf *po;
401
  struct fib infib;                /* FIB for intra-area routes */
402
  unsigned tick;
403
};
404

    
405
struct proto_ospf {
406
  struct proto proto;
407
  list iface_list;                /* Interfaces we really use */
408
  list area_list;
409
  int areano;                        /* Number of area I belong to */
410
  struct fib efib;                /* FIB for external routes */
411
  int rfc1583;                        /* RFC1583 compatibility */
412
  int ebit;                        /* Did I originate any ext lsa? */
413
};
414

    
415
struct ospf_iface_patt {
416
  struct iface_patt i;
417
  int cost;
418
  int helloint;
419
  int rxmtint;
420
  int pollint;
421
  int inftransdelay; 
422
  int priority; 
423
  int waitint;
424
  int deadc;
425
  int type;
426
  int autype;
427
  int strictnbma;
428
  int stub;
429
#define AU_NONE 0
430
#define AU_SIMPLE 1
431
#define AU_CRYPT 2
432
  u8 password[8];
433
  list nbma_list;
434
};
435

    
436
static int ospf_start(struct proto *p);
437
static void ospf_dump(struct proto *p);
438
static struct proto *ospf_init(struct proto_config *c);
439
static void ospf_preconfig(struct protocol *p, struct config *c);
440
static void ospf_postconfig(struct proto_config *c);
441
static int ospf_rte_better(struct rte *new, struct rte *old);
442
static int ospf_rte_same(struct rte *new, struct rte *old);
443
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
444
  struct linpool *pool);
445
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
446
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
447
void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,ea_list *attrs);
448
void area_disp(timer *timer);
449
void schedule_rt_lsa(struct ospf_area *oa);
450
void schedule_rtcalc(struct ospf_area *oa);
451
void ospf_sh_neigh(struct proto *p, char *iff);
452
void ospf_sh(struct proto *p);
453
void ospf_sh_iface(struct proto *p, char *iff);
454

    
455
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
456
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
457
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
458

    
459
#include "proto/ospf/hello.h"
460
#include "proto/ospf/packet.h"
461
#include "proto/ospf/iface.h"
462
#include "proto/ospf/neighbor.h"
463
#include "proto/ospf/topology.h"
464
#include "proto/ospf/dbdes.h"
465
#include "proto/ospf/lsreq.h"
466
#include "proto/ospf/lsupd.h"
467
#include "proto/ospf/lsack.h"
468
#include "proto/ospf/lsalib.h"
469
#include "proto/ospf/rt.h"
470

    
471
#endif /* _BIRD_OSPF_H_ */