Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / ospf.h @ 035f6acb

History | View | Annotate | Download (11.1 KB)

1 c1f8dc91 Ondrej Filip
/*
2
 *        BIRD -- OSPF
3
 *
4 7ab3ff6a Ondrej Filip
 *        (c) 1999 - 2000 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 3df89cef Ondrej Filip
#define SIPH SIZE_OF_IP_HEADER
13 273fd2c1 Ondrej Filip
#define MAXNETS 10
14 f14032ef Ondrej Filip
#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 6d2b3211 Ondrej Filip
22 4364b47e Ondrej Filip
#include "nest/bird.h"
23
24
#include "lib/checksum.h"
25 6ba36f06 Martin Mares
#include "lib/ip.h"
26
#include "lib/lists.h"
27 30147b89 Ondrej Filip
#include "lib/slists.h"
28 6ba36f06 Martin Mares
#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 4364b47e Ondrej Filip
#include "nest/route.h"
34 a783e259 Ondrej Filip
#include "nest/cli.h"
35 f8f1e1f1 Ondrej Filip
#include "nest/locks.h"
36 4364b47e Ondrej Filip
#include "conf/conf.h"
37 d345cda5 Ondrej Filip
#include "lib/string.h"
38 6ba36f06 Martin Mares
39 5b1a92e6 Ondrej Filip
#define OSPF_PROTO 89
40 aec76c6e Ondrej Filip
#ifndef IPV6
41 296ecb56 Ondrej Filip
#define OSPF_VERSION 2
42 5b1a92e6 Ondrej Filip
#define AllSPFRouters ipa_from_u32(0xe0000005)        /* 224.0.0.5 */
43
#define AllDRouters ipa_from_u32(0xe0000006)        /* 224.0.0.6 */
44 c6c56264 Ondrej Filip
#define DEFAULTDES ipa_from_u32(0)
45 aec76c6e Ondrej Filip
#else
46 6376a961 Ondrej Filip
#error Multicast address not defined in IPv6
47 aec76c6e Ondrej Filip
#endif
48
49 15087574 Ondrej Filip
50 921a93f2 Ondrej Filip
#define LSREFRESHTIME 1800        /* 30 minutes */
51 15087574 Ondrej Filip
#define MINLSINTERVAL 5
52
#define MINLSARRIVAL 1
53 c6c56264 Ondrej Filip
#define LSINFINITY 0xffff        /* RFC says 0xffffff ??? */
54 b4af36e0 Ondrej Filip
#define DISPTICK 7
55 15087574 Ondrej Filip
56 c1f8dc91 Ondrej Filip
struct ospf_config {
57
  struct proto_config c;
58 3fa5722d Ondrej Filip
  int rfc1583;
59 b36a0a79 Ondrej Filip
  list area_list;
60
};
61
62 e5b5d18c Ondrej Filip
struct nbma_node {
63
  node n;
64
  ip_addr ip;
65 a190e720 Ondrej Filip
  int eligible;
66 e5b5d18c Ondrej Filip
};
67
68 c926eee7 Ondrej Filip
struct area_net {
69
  node n;
70
  ip_addr net;
71
  int mlen;
72
  int hidden;
73
};
74
75 b36a0a79 Ondrej Filip
struct ospf_area_config {
76
  node n;
77
  u32 areaid;
78
  int stub;
79
  unsigned tick;
80 89d6782d Ondrej Filip
  list patt_list;
81 c926eee7 Ondrej Filip
  list net_list;
82 c1f8dc91 Ondrej Filip
};
83
84 5b1a92e6 Ondrej Filip
struct ospf_iface {
85 b11d8a4f Ondrej Filip
  node n;
86 f7103dfc Ondrej Filip
  struct proto_ospf *proto;
87 b11d8a4f Ondrej Filip
  struct iface *iface;        /* Nest's iface */
88 30147b89 Ondrej Filip
  struct ospf_area *oa;
89 f8f1e1f1 Ondrej Filip
  struct object_lock *lock;
90 30147b89 Ondrej Filip
  u32 an;                /* Area number */
91 1af66415 Ondrej Filip
  sock *hello_sk;        /* Hello socket */
92 2a092594 Ondrej Filip
  sock *dr_sk;                /* For states DR or BACKUP */
93 1af66415 Ondrej Filip
  sock *ip_sk;                /* IP socket (for DD ...) */
94 75b84c34 Ondrej Filip
  list neigh_list;        /* List of neigbours */
95 5b1a92e6 Ondrej Filip
  u16 cost;                /* Cost of iface */
96 2c1d1cc7 Ondrej Filip
  u16 rxmtint;                /* number of seconds between LSA retransmissions */
97 249fdef7 Ondrej Filip
  u16 inftransdelay;        /* The estimated number of seconds it takes to
98 5b1a92e6 Ondrej Filip
                           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 96f1b8ba Ondrej Filip
  u16 waitint;                /* number of sec before changing state from wait */
103 a190e720 Ondrej Filip
  u16 pollint;                /* Poll interval */
104 35ff423d Ondrej Filip
  u32 deadc;                /* after "deadint" missing hellos is router dead */
105 5b1a92e6 Ondrej Filip
  u16 autype;
106
  u8 aukey[8];
107
  u8 options;
108 aec76c6e Ondrej Filip
  ip_addr drip;                /* Designated router */
109
  u32 drid;
110
  ip_addr bdrip;        /* Backup DR */
111
  u32 bdrid;
112 2c1d1cc7 Ondrej Filip
  u8 type;                /* OSPF view of type */
113 96f1b8ba Ondrej Filip
#define OSPF_IT_BCAST 0
114 4c630a6d Ondrej Filip
#define OSPF_IT_NBMA 1
115
#define OSPF_IT_PTP 2
116 96f1b8ba Ondrej Filip
#define OSPF_IT_VLINK 3
117 aaaff776 Ondrej Filip
#define OSPF_IT_UNDEF 4
118 b02e4011 Ondrej Filip
  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 2c1d1cc7 Ondrej Filip
  u8 state;                /* Interface state machine */
125 96f1b8ba Ondrej Filip
#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 65112dd2 Ondrej Filip
  timer *wait_timer;                /* WAIT timer */
133
  timer *hello_timer;                /* HELLOINT timer */
134 a190e720 Ondrej Filip
  timer *poll_timer;                /* Poll Interval - for NBMA */
135 5b1a92e6 Ondrej Filip
/* Default values for interface parameters */
136
#define COST_D 10
137
#define RXMTINT_D 5
138 249fdef7 Ondrej Filip
#define INFTRANSDELAY_D 1
139 4c630a6d Ondrej Filip
#define PRIORITY_D 1
140 5b1a92e6 Ondrej Filip
#define HELLOINT_D 10
141 a190e720 Ondrej Filip
#define POLLINT_D 20
142 35ff423d Ondrej Filip
#define DEADC_D 4
143 aaaff776 Ondrej Filip
#define WAIT_DMH 4        /* Value of Wait timer - not found it in RFC 
144
                         * - using 4*HELLO
145 1af66415 Ondrej Filip
                         */
146 9bc1808a Ondrej Filip
  struct top_hash_entry *nlsa;        /* Originated net lsa */
147 78e2c6cc Ondrej Filip
  int orignet;                /* Schedule network LSA origination */
148 9bc1808a Ondrej Filip
  int fadj;                /* Number of full adjacent neigh */
149 e5b5d18c Ondrej Filip
  list nbma_list;
150 5b1a92e6 Ondrej Filip
};
151
152 296ecb56 Ondrej Filip
struct ospf_packet {
153
  u8 version;
154
  u8 type;
155 89d6782d Ondrej Filip
#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 296ecb56 Ondrej Filip
  u16 length;
161
  u32 routerid;
162
  u32 areaid;
163 2c971094 Ondrej Filip
#define BACKBONE 0
164 296ecb56 Ondrej Filip
  u16 checksum;
165
  u16 autype;
166
  u8 authetication[8];
167
};
168
169
struct ospf_hello_packet {
170 67ff9130 Ondrej Filip
  struct ospf_packet ospf_packet;
171
  ip_addr netmask;
172 35ff423d Ondrej Filip
  u16 helloint;
173 296ecb56 Ondrej Filip
  u8 options;
174
  u8 priority;
175
  u32 deadint;
176 423230f2 Ondrej Filip
  ip_addr dr;
177
  ip_addr bdr;
178 296ecb56 Ondrej Filip
};
179
180 04c6319a Ondrej Filip
struct immsb {
181 c11007bc Ondrej Filip
#ifdef _BIG_ENDIAN
182
  u8 padding:5;
183
  u8 i:1;
184
  u8 m:1;
185
  u8 ms:1;
186
#else
187 04c6319a Ondrej Filip
  u8 ms:1;
188
  u8 m:1;
189
  u8 i:1;
190
  u8 padding:5;
191 c11007bc Ondrej Filip
#endif
192 04c6319a Ondrej Filip
};
193
194
union imms {
195
  u8 byte;
196
  struct immsb bit;
197
};
198
199 2c1d1cc7 Ondrej Filip
struct ospf_dbdes_packet {
200 1af66415 Ondrej Filip
  struct ospf_packet ospf_packet;
201
  u16 iface_mtu;
202 2c1d1cc7 Ondrej Filip
  u8 options;
203 04c6319a Ondrej Filip
  union imms imms;                /* I, M, MS bits */
204 2c1d1cc7 Ondrej Filip
#define DBDES_MS 1
205
#define DBDES_M 2
206
#define DBDES_I 4
207
  u32 ddseq;
208 1af66415 Ondrej Filip
};
209
210 ce17d4c1 Ondrej Filip
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 2c1d1cc7 Ondrej Filip
  u8 options;
217 ce17d4c1 Ondrej Filip
  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 910e557b Ondrej Filip
  s32 sn;                /* LS Sequence number */
226 ce17d4c1 Ondrej Filip
#define LSA_INITSEQNO 0x80000001
227
#define LSA_MAXSEQNO 0x7fffffff
228 2c1d1cc7 Ondrej Filip
  u16 checksum;
229 ce17d4c1 Ondrej Filip
  u16 length;  
230
};
231
232 fdb19982 Ondrej Filip
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 ce17d4c1 Ondrej Filip
struct ospf_lsa_rt {
245 fdb19982 Ondrej Filip
  union veb veb;
246 ce17d4c1 Ondrej Filip
#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 2c1d1cc7 Ondrej Filip
};
270
271 dfa9a53a Ondrej Filip
struct ospf_lsa_net {
272 c6c56264 Ondrej Filip
  ip_addr netmask;
273 dfa9a53a Ondrej Filip
};
274
275 ce17d4c1 Ondrej Filip
struct ospf_lsa_summ {
276 c6c56264 Ondrej Filip
  ip_addr netmask;
277 ce17d4c1 Ondrej Filip
};
278
279
struct ospf_lsa_summ_net {
280
  u8 tos;
281
  u8 padding;
282
  u16 metric;
283
};
284
285
struct ospf_lsa_ext {
286 c6c56264 Ondrej Filip
  ip_addr netmask;
287 ce17d4c1 Ondrej Filip
};
288
289
struct ospf_lsa_ext_tos {
290
  u8 etos;
291
  u8 padding;
292 f45fd316 Ondrej Filip
  u16 metric;
293 65a9c571 Ondrej Filip
  ip_addr fwaddr;
294 ce17d4c1 Ondrej Filip
  u32 tag;
295
};
296
297 6d2b3211 Ondrej Filip
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 f45fd316 Ondrej Filip
struct l_lsr_head {
310
  node n;
311
  struct ospf_lsreq_header lsh;
312
};
313
314 de769e24 Ondrej Filip
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 c76674f0 Ondrej Filip
struct ospf_neighbor
325
{
326 e83dc0d7 Ondrej Filip
  node n;
327 035f6acb Ondrej Filip
  pool *pool;
328 903a3f39 Ondrej Filip
  struct ospf_iface *ifa;
329 2c1d1cc7 Ondrej Filip
  u8 state;
330 c76674f0 Ondrej Filip
#define NEIGHBOR_DOWN 0
331 cd70d934 Ondrej Filip
#define NEIGHBOR_ATTEMPT 1
332
#define NEIGHBOR_INIT 2
333
#define NEIGHBOR_2WAY 3
334 c76674f0 Ondrej Filip
#define NEIGHBOR_EXSTART 4
335 903a3f39 Ondrej Filip
#define NEIGHBOR_EXCHANGE 5
336
#define NEIGHBOR_LOADING 6
337
#define NEIGHBOR_FULL 7
338 c76674f0 Ondrej Filip
  timer *inactim;        /* Inactivity timer */
339 04c6319a Ondrej Filip
  union imms imms;                /* I, M, Master/slave received */
340 c2250f91 Ondrej Filip
  u32 dds;                /* DD Sequence number being sent */
341
  u32 ddr;                /* last Dat Des packet received */
342 04c6319a Ondrej Filip
  union imms myimms;                /* I, M Master/slave */
343 c76674f0 Ondrej Filip
  u32 rid;                /* Router ID */
344 986e3413 Ondrej Filip
  ip_addr ip;                /* IP of it's interface */
345 2c1d1cc7 Ondrej Filip
  u8 priority;                /* Priority */
346 986e3413 Ondrej Filip
  u8 options;                /* Options received */
347 423230f2 Ondrej Filip
  ip_addr dr;                /* Neigbour's idea of DR */
348
  ip_addr bdr;                /* Neigbour's idea of BDR */
349 e3121112 Ondrej Filip
  u8 adj;                /* built adjacency? */
350 30147b89 Ondrej Filip
  siterator dbsi;        /* Database summary list iterator */
351 95eb1dba Ondrej Filip
  slist lsrql;                /* Link state request */
352
  struct top_graph *lsrqh;                /* LSA graph */
353 30147b89 Ondrej Filip
  siterator lsrqi;
354
  slist lsrtl;                /* Link state retransmission list */
355
  siterator lsrti;
356 921a93f2 Ondrej Filip
  struct top_graph *lsrth;
357 30147b89 Ondrej Filip
  void *ldbdes;                /* Last database description packet */
358 6d2b3211 Ondrej Filip
  timer *rxmt_timer;        /* RXMT timer */
359 43e75f38 Ondrej Filip
  timer *lsrr_timer;        /* Link state request retransmition timer */
360 67315ef6 Ondrej Filip
  list ackl;
361
  timer *ackd_timer;        /* Delayed ack timer */
362 c76674f0 Ondrej Filip
};
363
364 96f1b8ba Ondrej Filip
/* Definitions for interface state machine */
365
#define ISM_UP 0        /* Interface Up */
366
#define ISM_WAITF 1        /* Wait timer fired */
367
#define ISM_BACKS 2        /* Backup seen */
368
#define ISM_NEICH 3        /* Neighbor change */
369
#define ISM_LOOP 4        /* Loop indicated */
370
#define ISM_UNLOOP 5        /* Unloop indicated */
371
#define ISM_DOWN 6        /* Interface down */
372
373
/* Definitions for neighbor state machine */
374
#define INM_HELLOREC 0        /* Hello Received */
375
#define INM_START 1        /* Neighbor start - for NBMA */
376
#define INM_2WAYREC 2        /* 2-Way received */
377
#define INM_NEGDONE 3        /* Negotiation done */
378
#define INM_EXDONE 4        /* Exchange done */
379
#define INM_BADLSREQ 5        /* Bad LS Request */
380
#define INM_LOADDONE 6        /* Load done */
381
#define INM_ADJOK 7        /* AdjOK? */
382
#define INM_SEQMIS 8        /* Sequence number mismatch */
383
#define INM_1WAYREC 9        /* 1-Way */
384 6ba36f06 Martin Mares
#define INM_KILLNBR 10        /* Kill Neighbor */
385 96f1b8ba Ondrej Filip
#define INM_INACTTIM 11        /* Inactivity timer */
386
#define INM_LLDOWN 12        /* Line down */
387
388 15087574 Ondrej Filip
struct ospf_area {
389 8496b2e4 Ondrej Filip
  node n;
390 15087574 Ondrej Filip
  u32 areaid;
391 70a38319 Ondrej Filip
  timer *disp_timer;                /* Area's dispatcher hear beat */
392
  int calcrt;                        /* Routing table calculation scheduled? */
393
  int origrt;                        /* Rt lsa origination scheduled? */
394 15087574 Ondrej Filip
  struct top_graph *gr;                /* LSA graph */
395 30147b89 Ondrej Filip
  slist lsal;                        /* List of all LSA's */
396 de30342f Ondrej Filip
  struct top_hash_entry *rt;        /* My own router LSA */
397 dfa9a53a Ondrej Filip
  list cand;                        /* List of candidates for RT calc. */
398 c926eee7 Ondrej Filip
  list net_list;                /* Networks to advertise or not */
399 b36a0a79 Ondrej Filip
  int stub;
400
  int trcap;                        /* Transit capability? */
401 c45f48fb Ondrej Filip
  struct proto_ospf *po;
402 d345cda5 Ondrej Filip
  struct fib infib;                /* FIB for intra-area routes */
403 3b580a23 Ondrej Filip
  unsigned tick;
404 15087574 Ondrej Filip
};
405
406 4364b47e Ondrej Filip
struct proto_ospf {
407
  struct proto proto;
408
  list iface_list;                /* Interfaces we really use */
409 8496b2e4 Ondrej Filip
  list area_list;
410 15087574 Ondrej Filip
  int areano;                        /* Number of area I belong to */
411 aa1e082c Ondrej Filip
  struct fib efib;                /* FIB for external routes */
412 fdb19982 Ondrej Filip
  int rfc1583;                        /* RFC1583 compatibility */
413
  int ebit;                        /* Did I originate any ext lsa? */
414 6ba36f06 Martin Mares
};
415
416 89d6782d Ondrej Filip
struct ospf_iface_patt {
417
  struct iface_patt i;
418
  int cost;
419
  int helloint;
420
  int rxmtint;
421 a190e720 Ondrej Filip
  int pollint;
422 aaaff776 Ondrej Filip
  int inftransdelay; 
423
  int priority; 
424
  int waitint;
425
  int deadc;
426
  int type;
427 c1824c4d Ondrej Filip
  int autype;
428 a190e720 Ondrej Filip
  int strictnbma;
429 e3bc10fd Ondrej Filip
  int stub;
430 4ef3dccf Martin Mares
/* must be in network byte order */
431
#define AU_NONE htons(0)
432
#define AU_SIMPLE htons(1)
433
#define AU_CRYPT htons(2)
434 c1824c4d Ondrej Filip
  u8 password[8];
435 e5b5d18c Ondrej Filip
  list nbma_list;
436 89d6782d Ondrej Filip
};
437
438 e8085aba Ondrej Filip
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
439
  struct linpool *pool);
440 5919c66e Martin Mares
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
441
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
442 e8085aba Ondrej Filip
void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,ea_list *attrs);
443 70a38319 Ondrej Filip
void area_disp(timer *timer);
444
void schedule_rt_lsa(struct ospf_area *oa);
445
void schedule_rtcalc(struct ospf_area *oa);
446 c4f0f014 Ondrej Filip
void ospf_sh_neigh(struct proto *p, char *iff);
447 4ab4e977 Ondrej Filip
void ospf_sh(struct proto *p);
448 c4f0f014 Ondrej Filip
void ospf_sh_iface(struct proto *p, char *iff);
449 4364b47e Ondrej Filip
450 5919c66e Martin Mares
#define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)
451
#define EA_OSPF_METRIC2        EA_CODE(EAP_OSPF, 1)
452
#define EA_OSPF_TAG        EA_CODE(EAP_OSPF, 2)
453
454 4364b47e Ondrej Filip
#include "proto/ospf/hello.h"
455
#include "proto/ospf/packet.h"
456
#include "proto/ospf/iface.h"
457
#include "proto/ospf/neighbor.h"
458
#include "proto/ospf/topology.h"
459
#include "proto/ospf/dbdes.h"
460 6d2b3211 Ondrej Filip
#include "proto/ospf/lsreq.h"
461 f45fd316 Ondrej Filip
#include "proto/ospf/lsupd.h"
462
#include "proto/ospf/lsack.h"
463
#include "proto/ospf/lsalib.h"
464 dfa9a53a Ondrej Filip
#include "proto/ospf/rt.h"
465 6ba36f06 Martin Mares
466 c1f8dc91 Ondrej Filip
#endif /* _BIRD_OSPF_H_ */