ospf.h 11.3 KB
Newer Older
1 2 3
/*
 *	BIRD -- OSPF
 *
4
 *	(c) 1999 - 2000 Ondrej Filip <feela@network.cz>
5 6 7 8 9 10 11
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

#ifndef _BIRD_OSPF_H_
#define _BIRD_OSPF_H_

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

22 23 24
#include "nest/bird.h"

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

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

49

Ondřej Filip's avatar
Ondřej Filip committed
50
#define LSREFRESHTIME 1800	/* 30 minutes */
51 52
#define MINLSINTERVAL 5
#define MINLSARRIVAL 1
53
#define LSINFINITY 0xffff	/* RFC says 0xffffff ??? */
Ondřej Filip's avatar
Ondřej Filip committed
54 55

#define DEFAULT_OSPFTICK 5
56 57
#define DEFAULT_AREATICK 4
#define DEFAULT_RFC1583 1	/* compatibility with rfc1583 */
Ondřej Filip's avatar
Ondřej Filip committed
58

59

Ondřej Filip's avatar
Ondřej Filip committed
60 61
struct ospf_config
{
62
  struct proto_config c;
63
  unsigned tick;
64
  int rfc1583;
Ondřej Filip's avatar
Ondřej Filip committed
65 66 67
  list area_list;
};

Ondřej Filip's avatar
Ondřej Filip committed
68 69
struct nbma_node
{
70 71
  node n;
  ip_addr ip;
72
  int eligible;
73 74
};

Ondřej Filip's avatar
Ondřej Filip committed
75 76
struct area_net
{
77
  node n;
Ondřej Filip's avatar
Ondřej Filip committed
78
  struct prefix px;
79
  int hidden;
Ondřej Filip's avatar
Ondřej Filip committed
80 81
  int active;
  int oldactive;
82 83
};

Ondřej Filip's avatar
Ondřej Filip committed
84 85
struct ospf_area_config
{
Ondřej Filip's avatar
Ondřej Filip committed
86 87 88 89
  node n;
  u32 areaid;
  int stub;
  unsigned tick;
Ondřej Filip's avatar
Ondřej Filip committed
90
  list patt_list;
91
  list net_list;
92 93
};

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

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

Ondřej Filip's avatar
Ondřej Filip committed
181 182
struct ospf_hello_packet
{
183 184
  struct ospf_packet ospf_packet;
  ip_addr netmask;
185
  u16 helloint;
186 187 188
  u8 options;
  u8 priority;
  u32 deadint;
189 190
  ip_addr dr;
  ip_addr bdr;
191 192
};

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

Ondřej Filip's avatar
Ondřej Filip committed
208 209
union imms
{
210 211 212 213
  u8 byte;
  struct immsb bit;
};

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

226

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

Ondřej Filip's avatar
Ondřej Filip committed
249 250
struct vebb
{
251 252 253 254 255 256
  u8 b:1;
  u8 e:1;
  u8 v:1;
  u8 padding:5;
};

Ondřej Filip's avatar
Ondřej Filip committed
257 258
union veb
{
259 260 261 262
  u8 byte;
  struct vebb bit;
};

Ondřej Filip's avatar
Ondřej Filip committed
263 264
struct ospf_lsa_rt
{
265
  union veb veb;
266 267 268 269 270 271 272
#define LSA_RT_V 5
#define LSA_RT_E 6
#define LSA_RT_B 7
  u8 padding;
  u16 links;
};

Ondřej Filip's avatar
Ondřej Filip committed
273 274
struct ospf_lsa_rt_link
{
275 276 277 278 279 280 281 282 283 284 285
  u32 id;
  u32 data;
  u8 type;
#define LSART_PTP 1
#define LSART_NET 2
#define LSART_STUB 3
#define LSART_VLNK 4
  u8 notos;
  u16 metric;
};

Ondřej Filip's avatar
Ondřej Filip committed
286 287
struct ospf_lsa_rt_link_tos
{				/* Actually we ignore TOS. This is useless */
288 289 290
  u8 tos;
  u8 padding;
  u16 metric;
291 292
};

Ondřej Filip's avatar
Ondřej Filip committed
293 294
struct ospf_lsa_net
{
295
  ip_addr netmask;
296 297
};

Ondřej Filip's avatar
Ondřej Filip committed
298 299
struct ospf_lsa_summ
{
300
  ip_addr netmask;
301 302
};

Ondřej Filip's avatar
Ondřej Filip committed
303 304
struct ospf_lsa_summ_net
{
305 306 307 308 309
  u8 tos;
  u8 padding;
  u16 metric;
};

Ondřej Filip's avatar
Ondřej Filip committed
310 311
struct ospf_lsa_ext
{
312
  ip_addr netmask;
313 314
};

Ondřej Filip's avatar
Ondřej Filip committed
315 316
struct ospf_lsa_ext_tos
{
317 318
  u8 etos;
  u8 padding;
319
  u16 metric;
320
  ip_addr fwaddr;
321 322 323
  u32 tag;
};

Ondřej Filip's avatar
Ondřej Filip committed
324 325
struct ospf_lsreq_packet
{
Ondřej Filip's avatar
Ondřej Filip committed
326 327 328
  struct ospf_packet ospf_packet;
};

Ondřej Filip's avatar
Ondřej Filip committed
329 330
struct ospf_lsreq_header
{
Ondřej Filip's avatar
Ondřej Filip committed
331 332 333 334
  u16 padd1;
  u8 padd2;
  u8 type;
  u32 id;
Ondřej Filip's avatar
Ondřej Filip committed
335
  u32 rt;			/* Advertising router */
Ondřej Filip's avatar
Ondřej Filip committed
336 337
};

Ondřej Filip's avatar
Ondřej Filip committed
338 339
struct l_lsr_head
{
340 341 342 343
  node n;
  struct ospf_lsreq_header lsh;
};

Ondřej Filip's avatar
Ondřej Filip committed
344 345
struct ospf_lsupd_packet
{
346
  struct ospf_packet ospf_packet;
Ondřej Filip's avatar
Ondřej Filip committed
347
  u32 lsano;			/* Number of LSA's */
348 349
};

Ondřej Filip's avatar
Ondřej Filip committed
350 351
struct ospf_lsack_packet
{
352 353 354 355
  struct ospf_packet ospf_packet;
};


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

397
/* Definitions for interface state machine */
Ondřej Filip's avatar
Ondřej Filip committed
398 399 400 401 402 403 404
#define ISM_UP 0		/* Interface Up */
#define ISM_WAITF 1		/* Wait timer fired */
#define ISM_BACKS 2		/* Backup seen */
#define ISM_NEICH 3		/* Neighbor change */
#define ISM_LOOP 4		/* Loop indicated */
#define ISM_UNLOOP 5		/* Unloop indicated */
#define ISM_DOWN 6		/* Interface down */
405 406

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

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

Ondřej Filip's avatar
Ondřej Filip committed
439 440
struct proto_ospf
{
441
  struct proto proto;
442 443 444
  timer *disp_timer;		/* OSPF proto dispatcher */
  unsigned tick;
  int calcrt;			/* Routing table calculation scheduled? */
445
  list iface_list;		/* Interfaces we really use */
446
  list area_list;
447
  int areano;			/* Number of area I belong to */
448
  struct fib efib;		/* FIB for external routes */
449 450
  int rfc1583;			/* RFC1583 compatibility */
  int ebit;			/* Did I originate any ext lsa? */
451 452
};

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

476
int ospf_import_control(struct proto *p, rte **new, ea_list **attrs,
Ondřej Filip's avatar
Ondřej Filip committed
477
			struct linpool *pool);
478 479
struct ea_list *ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
void ospf_store_tmp_attrs(struct rte *rt, struct ea_list *attrs);
480
void ospf_rt_notify(struct proto *p, net *n, rte *new, rte *old,
Ondřej Filip's avatar
Ondřej Filip committed
481
		    ea_list * attrs);
482
void schedule_rt_lsa(struct ospf_area *oa);
483
void schedule_rtcalc(struct proto_ospf *po);
Ondřej Filip's avatar
Ondřej Filip committed
484
void schedule_net_lsa(struct ospf_iface *ifa);
485
void ospf_sh_neigh(struct proto *p, char *iff);
Ondřej Filip's avatar
Ondřej Filip committed
486
void ospf_sh(struct proto *p);
487
void ospf_sh_iface(struct proto *p, char *iff);
488

489 490 491 492
#define EA_OSPF_METRIC1	EA_CODE(EAP_OSPF, 0)
#define EA_OSPF_METRIC2	EA_CODE(EAP_OSPF, 1)
#define EA_OSPF_TAG	EA_CODE(EAP_OSPF, 2)

493 494 495 496 497 498
#include "proto/ospf/hello.h"
#include "proto/ospf/packet.h"
#include "proto/ospf/iface.h"
#include "proto/ospf/neighbor.h"
#include "proto/ospf/topology.h"
#include "proto/ospf/dbdes.h"
Ondřej Filip's avatar
Ondřej Filip committed
499
#include "proto/ospf/lsreq.h"
500 501 502
#include "proto/ospf/lsupd.h"
#include "proto/ospf/lsack.h"
#include "proto/ospf/lsalib.h"
503
#include "proto/ospf/rt.h"
504

505
#endif /* _BIRD_OSPF_H_ */