]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/ospf/ospf.h
f464a3ed7f3c93e332bfe74d4e6594d2257ca856
[thirdparty/bird.git] / proto / ospf / ospf.h
1 /*
2 * BIRD -- OSPF
3 *
4 * (c) 1999--2005 Ondrej Filip <feela@network.cz>
5 * (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
6 * (c) 2009--2014 CZ.NIC z.s.p.o.
7 *
8 * Can be freely distributed and used under the terms of the GNU GPL.
9 */
10
11 #ifndef _BIRD_OSPF_H_
12 #define _BIRD_OSPF_H_
13
14 #include "nest/bird.h"
15
16 #include "lib/checksum.h"
17 #include "lib/ip.h"
18 #include "lib/lists.h"
19 #include "lib/slists.h"
20 #include "lib/socket.h"
21 #include "lib/timer.h"
22 #include "lib/resource.h"
23 #include "nest/protocol.h"
24 #include "nest/iface.h"
25 #include "nest/route.h"
26 #include "nest/cli.h"
27 #include "nest/locks.h"
28 #include "nest/bfd.h"
29 #include "conf/conf.h"
30 #include "lib/string.h"
31
32
33 #ifdef LOCAL_DEBUG
34 #define OSPF_FORCE_DEBUG 1
35 #else
36 #define OSPF_FORCE_DEBUG 0
37 #endif
38
39
40 #define IP4_MIN_MTU 576
41 #define IP6_MIN_MTU 1280
42
43 #define IP4_OSPF_ALL_ROUTERS ipa_build4(224, 0, 0, 5)
44 #define IP4_OSPF_DES_ROUTERS ipa_build4(224, 0, 0, 6)
45
46 #define IP6_OSPF_ALL_ROUTERS ipa_build6(0xFF020000, 0, 0, 5)
47 #define IP6_OSPF_DES_ROUTERS ipa_build6(0xFF020000, 0, 0, 6)
48
49 #ifdef IPV6
50 #define ip4_addr u32
51 #define ip6_addr ip_addr
52 #define _MI6(x1,x2,x3,x4) _MI(x1, x2, x3, x4)
53 #define ipa_is_link_local(x) ipa_has_link_scope(x)
54 #define ipa_from_u32(x) _MI6(0,0,0xffff,x)
55 #define ipa_to_u32(x) _I3(x)
56 #define ipa_build4(a,b,c,d) IPA_NONE
57 #define ipa_build6(a,b,c,d) _MI6(a,b,c,d)
58 #define OSPF_IS_V2 0
59 #else
60 #define ip4_addr u32
61 #define ip6_addr ip_addr
62 #define _I0(X) 0
63 #define _I1(X) 0
64 #define _I2(X) 0
65 #define _I3(X) 0
66 #define _MI6(x1,x2,x3,x4) IPA_NONE
67 #define ipa_is_link_local(x) 0
68 #define ipa_build4(a,b,c,d) _MI(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
69 #define ipa_build6(a,b,c,d) IPA_NONE
70 #define OSPF_IS_V2 1
71 #endif
72
73 // FIXME: MAX_PREFIX_LENGTH
74
75 #define OSPF_TRACE(flags, msg, args...) \
76 do { if ((p->p.debug & flags) || OSPF_FORCE_DEBUG) \
77 log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
78
79 #define OSPF_PACKET(dumpfn, buffer, msg, args...) \
80 do { if ((p->p.debug & D_PACKETS) || OSPF_FORCE_DEBUG) \
81 { log(L_TRACE "%s: " msg, p->p.name, ## args ); dumpfn(p, buffer); } } while(0)
82
83
84 #define OSPF_PROTO 89
85
86 #define LSREFRESHTIME 1800 /* 30 minutes */
87 #define MINLSINTERVAL 5
88 #define MINLSARRIVAL 1
89 #define LSINFINITY 0xffffff
90
91 #define OSPF_DEFAULT_TICK 1
92 #define OSPF_DEFAULT_STUB_COST 1000
93 #define OSPF_DEFAULT_ECMP_LIMIT 16
94 #define OSPF_DEFAULT_TRANSINT 40
95
96 #define OSPF_MIN_PKT_SIZE 256
97 #define OSPF_MAX_PKT_SIZE 65535
98
99 #define OSPF_VLINK_ID_OFFSET 0x80000000
100
101
102 struct ospf_config
103 {
104 struct proto_config c;
105 uint tick;
106 u8 ospf2;
107 u8 rfc1583;
108 u8 stub_router;
109 u8 merge_external;
110 u8 instance_id;
111 u8 abr;
112 u8 asbr;
113 int ecmp;
114 list area_list; /* list of area configs (struct ospf_area_config) */
115 list vlink_list; /* list of configured vlinks (struct ospf_iface_patt) */
116 };
117
118 struct ospf_area_config
119 {
120 node n;
121 u32 areaid;
122 u32 default_cost; /* Cost of default route for stub areas
123 (With possible LSA_EXT3_EBIT for NSSA areas) */
124 u8 type; /* Area type (standard, stub, NSSA), represented
125 by option flags (OPT_E, OPT_N) */
126 u8 summary; /* Import summaries to this stub/NSSA area, valid for ABR */
127 u8 default_nssa; /* Generate default NSSA route for NSSA+summary area */
128 u8 translator; /* Translator role, for NSSA ABR */
129 u32 transint; /* Translator stability interval */
130 list patt_list; /* List of iface configs (struct ospf_iface_patt) */
131 list net_list; /* List of aggregate networks for that area */
132 list enet_list; /* List of aggregate external (NSSA) networks */
133 list stubnet_list; /* List of stub networks added to Router LSA */
134 };
135
136 struct area_net_config
137 {
138 node n;
139 struct prefix px;
140 u32 tag;
141 u8 hidden;
142 };
143
144 struct area_net
145 {
146 struct fib_node fn;
147 u32 metric; /* With possible LSA_EXT3_EBIT for NSSA area nets */
148 u32 tag;
149 u8 hidden;
150 u8 active;
151 };
152
153 struct ospf_stubnet_config
154 {
155 node n;
156 struct prefix px;
157 u32 cost;
158 u8 hidden;
159 u8 summary;
160 };
161
162 struct nbma_node
163 {
164 node n;
165 ip_addr ip;
166 byte eligible;
167 byte found;
168 };
169
170 struct ospf_iface_patt
171 {
172 struct iface_patt i;
173 u32 type;
174 u32 stub;
175 u32 cost;
176 u32 helloint;
177 u32 rxmtint;
178 u32 pollint;
179 u32 waitint;
180 u32 deadc;
181 u32 deadint;
182 u32 inftransdelay;
183 list nbma_list;
184 u32 priority;
185 u32 voa;
186 u32 vid;
187 int tx_tos;
188 int tx_priority;
189 u16 tx_length;
190 u16 rx_buffer;
191
192 #define OSPF_RXBUF_MINSIZE 256 /* Minimal allowed size */
193 u8 instance_id;
194 u8 autype; /* Not really used in OSPFv3 */
195 #define OSPF_AUTH_NONE 0
196 #define OSPF_AUTH_SIMPLE 1
197 #define OSPF_AUTH_CRYPT 2
198 #define OSPF_AUTH_CRYPT_SIZE 16
199 u8 strictnbma;
200 u8 check_link;
201 u8 ecmp_weight;
202 u8 link_lsa_suppression;
203 u8 real_bcast; /* Not really used in OSPFv3 */
204 u8 ptp_netmask; /* bool + 2 for unspecified */
205 u8 ttl_security; /* bool + 2 for TX only */
206 u8 bfd;
207 u8 bsd_secondary;
208 list *passwords;
209 };
210
211 /* Default values for interface parameters */
212 #define COST_D 10
213 #define RXMTINT_D 5
214 #define INFTRANSDELAY_D 1
215 #define PRIORITY_D 1
216 #define HELLOINT_D 10
217 #define POLLINT_D 20
218 #define DEADC_D 4
219 #define WAIT_DMH 4
220 /* Value of Wait timer - not found it in RFC * - using 4*HELLO */
221
222
223
224 struct ospf_proto
225 {
226 struct proto p;
227 timer *disp_timer; /* OSPF proto dispatcher */
228 uint tick;
229 struct top_graph *gr; /* LSA graph */
230 slist lsal; /* List of all LSA's */
231 int calcrt; /* Routing table calculation scheduled?
232 0=no, 1=normal, 2=forced reload */
233 list iface_list; /* List of OSPF interfaces (struct ospf_iface) */
234 list area_list; /* List of OSPF areas (struct ospf_area) */
235 int areano; /* Number of area I belong to */
236 int padj; /* Number of neighbors in Exchange or Loading state */
237 struct fib rtf; /* Routing table */
238 byte ospf2; /* OSPF v2 or v3 */
239 byte rfc1583; /* RFC1583 compatibility */
240 byte stub_router; /* Do not forward transit traffic */
241 byte merge_external; /* Should i merge external routes? */
242 byte asbr; /* May i originate any ext/NSSA lsa? */
243 byte ecmp; /* Maximal number of nexthops in ECMP route, or 0 */
244 struct ospf_area *backbone; /* If exists */
245 void *lsab; /* LSA buffer used when originating router LSAs */
246 int lsab_size, lsab_used;
247 linpool *nhpool; /* Linpool used for next hops computed in SPF */
248 sock *vlink_sk; /* IP socket used for vlink TX */
249 u32 router_id;
250 u32 last_vlink_id; /* Interface IDs for vlinks (starts at 0x80000000) */
251 };
252
253 struct ospf_area
254 {
255 node n;
256 u32 areaid;
257 struct ospf_area_config *ac; /* Related area config */
258 struct top_hash_entry *rt; /* My own router LSA */
259 struct top_hash_entry *pxr_lsa; /* Originated prefix LSA */
260 list cand; /* List of candidates for RT calc. */
261 struct fib net_fib; /* Networks to advertise or not */
262 struct fib enet_fib; /* External networks for NSSAs */
263 u32 options; /* Optional features */
264 u8 update_rt_lsa; /* Rt lsa origination scheduled? */
265 u8 trcap; /* Transit capability? */
266 u8 marked; /* Used in OSPF reconfigure */
267 u8 translate; /* Translator state (TRANS_*), for NSSA ABR */
268 timer *translator_timer; /* For NSSA translator switch */
269 struct ospf_proto *po;
270 struct fib rtr; /* Routing tables for routers */
271 };
272
273
274
275 struct ospf_iface
276 {
277 node n;
278 struct iface *iface; /* Nest's iface (NULL for vlinks) */
279 struct ifa *addr; /* IP prefix associated with that OSPF iface */
280 struct ospf_area *oa;
281 struct ospf_iface_patt *cf;
282 char *ifname; /* Interface name (iface->name), new one for vlinks */
283
284 pool *pool;
285 sock *sk; /* IP socket */
286 list neigh_list; /* List of neigbours (struct ospf_neighbor) */
287 u32 cost; /* Cost of iface */
288 u32 waitint; /* number of sec before changing state from wait */
289 u32 rxmtint; /* number of seconds between LSA retransmissions */
290 u32 pollint; /* Poll interval */
291 u32 deadint; /* after "deadint" missing hellos is router dead */
292 u32 iface_id; /* Interface ID (iface->index or new value for vlinks) */
293 u32 vid; /* ID of peer of virtual link */
294 ip_addr vip; /* IP of peer of virtual link */
295 struct ospf_iface *vifa; /* OSPF iface which the vlink goes through */
296 struct ospf_area *voa; /* OSPF area which the vlink goes through */
297 u16 inftransdelay; /* The estimated number of seconds it takes to
298 transmit a Link State Update Packet over this
299 interface. LSAs contained in the update */
300 u16 helloint; /* number of seconds between hello sending */
301 list *passwords;
302 u32 csn; /* Last used crypt seq number */
303 bird_clock_t csn_use; /* Last time when packet with that CSN was sent */
304 ip_addr all_routers; /* Multicast (or broadcast) address for all routers */
305 ip_addr des_routers; /* Multicast (or NULL) address for designated routers */
306 ip_addr drip; /* Designated router IP */
307 ip_addr bdrip; /* Backup DR IP */
308 u32 drid; /* DR Router ID */
309 u32 bdrid; /* BDR Router ID */
310 s16 rt_pos_beg; /* Position of iface in Router-LSA, begin, inclusive */
311 s16 rt_pos_end; /* Position of iface in Router-LSA, end, exclusive */
312 s16 px_pos_beg; /* Position of iface in Rt Prefix-LSA, begin, inclusive */
313 s16 px_pos_end; /* Position of iface in Rt Prefix-LSA, end, exclusive */
314 u32 dr_iface_id; /* if drid is valid, this is iface_id of DR (for connecting network) */
315 u8 instance_id; /* Used to differentiate between more OSPF
316 instances on one interface */
317 u8 autype; /* Authentication type (OSPF_AUTH_*) */
318 u8 type; /* OSPF view of type (OSPF_IT_*) */
319 u8 strictnbma; /* Can I talk with unknown neighbors? */
320 u8 stub; /* Inactive interface */
321 u8 state; /* Interface state machine (OSPF_IS_*) */
322 timer *wait_timer; /* WAIT timer */
323 timer *hello_timer; /* HELLOINT timer */
324 timer *poll_timer; /* Poll Interval - for NBMA */
325
326 struct top_hash_entry *link_lsa; /* Originated link LSA */
327 struct top_hash_entry *net_lsa; /* Originated network LSA */
328 struct top_hash_entry *pxn_lsa; /* Originated prefix LSA */
329 u8 update_link_lsa;
330 u8 update_net_lsa;
331 int fadj; /* Number of fully adjacent neighbors */
332 list nbma_list;
333 u8 priority; /* A router priority for DR election */
334 u8 ioprob;
335 #define OSPF_I_OK 0 /* Everything OK */
336 #define OSPF_I_SK 1 /* Socket open failed */
337 #define OSPF_I_LL 2 /* Missing link-local address (OSPFv3) */
338 u8 sk_dr; /* Socket is a member of designated routers group */
339 u8 marked; /* Used in OSPF reconfigure, 2 for force restart */
340 u16 rxbuf; /* Buffer size */
341 u16 tx_length; /* Soft TX packet length limit, usually MTU */
342 u8 check_link; /* Whether iface link change is used */
343 u8 ecmp_weight; /* Weight used for ECMP */
344 u8 link_lsa_suppression; /* Suppression of Link-LSA origination */
345 u8 ptp_netmask; /* Send real netmask for P2P */
346 u8 check_ttl; /* Check incoming packets for TTL 255 */
347 u8 bfd; /* Use BFD on iface */
348 };
349
350 struct ospf_neighbor
351 {
352 node n;
353 pool *pool;
354 struct ospf_iface *ifa;
355 u8 state;
356 timer *inactim; /* Inactivity timer */
357 u8 imms; /* I, M, Master/slave received */
358 u8 myimms; /* I, M Master/slave */
359 u32 dds; /* DD Sequence number being sent */
360 u32 ddr; /* last Dat Des packet received */
361
362 u32 rid; /* Router ID */
363 ip_addr ip; /* IP of it's interface */
364 u8 priority; /* Priority */
365 u8 adj; /* built adjacency? */
366 u8 want_lsreq; /* Set to 1 when lsrql was shortened during LSUPD */
367 u32 options; /* Options received */
368
369 /* Entries dr and bdr store IP addresses in OSPFv2 and router IDs in
370 OSPFv3, we use the same type to simplify handling */
371 u32 dr; /* Neigbour's idea of DR */
372 u32 bdr; /* Neigbour's idea of BDR */
373 u32 iface_id; /* ID of Neighbour's iface connected to common network */
374
375 /* Database summary list iterator, controls initial dbdes exchange.
376 * Advances in the LSA list as dbdes packets are sent.
377 */
378 siterator dbsi; /* iterator of po->lsal */
379
380 /* Link state request list, controls initial LSA exchange.
381 * Entries added when received in dbdes packets, removed as sent in lsreq packets.
382 */
383 slist lsrql; /* slist of struct top_hash_entry from n->lsrqh */
384 struct top_graph *lsrqh;
385
386 /* Link state retransmission list, controls LSA retransmission during flood.
387 * Entries added as sent in lsupd packets, removed when received in lsack packets.
388 * These entries hold ret_count in appropriate LSA entries.
389 */
390 slist lsrtl; /* slist of struct top_hash_entry from n->lsrth */
391 struct top_graph *lsrth;
392 timer *rxmt_timer; /* RXMT timer */
393 list ackl[2];
394 #define ACKL_DIRECT 0
395 #define ACKL_DELAY 1
396 timer *ackd_timer; /* Delayed ack timer */
397 struct bfd_request *bfd_req; /* BFD request, if BFD is used */
398 void *ldd_buffer; /* Last database description packet */
399 u32 ldd_bsize; /* Buffer size for ldd_buffer */
400 u32 csn; /* Last received crypt seq number (for MD5) */
401 };
402
403
404 /* OSPF interface types */
405 #define OSPF_IT_BCAST 0
406 #define OSPF_IT_NBMA 1
407 #define OSPF_IT_PTP 2
408 #define OSPF_IT_PTMP 3
409 #define OSPF_IT_VLINK 4
410 #define OSPF_IT_UNDEF 5
411
412 /* OSPF interface states */
413 #define OSPF_IS_DOWN 0 /* Not active */
414 #define OSPF_IS_LOOP 1 /* Iface with no link */
415 #define OSPF_IS_WAITING 2 /* Waiting for Wait timer */
416 #define OSPF_IS_PTP 3 /* PTP operational */
417 #define OSPF_IS_DROTHER 4 /* I'm on BCAST or NBMA and I'm not DR */
418 #define OSPF_IS_BACKUP 5 /* I'm BDR */
419 #define OSPF_IS_DR 6 /* I'm DR */
420
421 /* Definitions for interface state machine */
422 #define ISM_UP 0 /* Interface Up */
423 #define ISM_WAITF 1 /* Wait timer fired */
424 #define ISM_BACKS 2 /* Backup seen */
425 #define ISM_NEICH 3 /* Neighbor change */
426 #define ISM_LOOP 4 /* Link down */
427 #define ISM_UNLOOP 5 /* Link up */
428 #define ISM_DOWN 6 /* Interface down */
429
430
431 /* OSPF neighbor states */
432 #define NEIGHBOR_DOWN 0
433 #define NEIGHBOR_ATTEMPT 1
434 #define NEIGHBOR_INIT 2
435 #define NEIGHBOR_2WAY 3
436 #define NEIGHBOR_EXSTART 4
437 #define NEIGHBOR_EXCHANGE 5
438 #define NEIGHBOR_LOADING 6
439 #define NEIGHBOR_FULL 7
440
441 /* Definitions for neighbor state machine */
442 #define INM_HELLOREC 0 /* Hello Received */
443 #define INM_START 1 /* Neighbor start - for NBMA */
444 #define INM_2WAYREC 2 /* 2-Way received */
445 #define INM_NEGDONE 3 /* Negotiation done */
446 #define INM_EXDONE 4 /* Exchange done */
447 #define INM_BADLSREQ 5 /* Bad LS Request */
448 #define INM_LOADDONE 6 /* Load done */
449 #define INM_ADJOK 7 /* AdjOK? */
450 #define INM_SEQMIS 8 /* Sequence number mismatch */
451 #define INM_1WAYREC 9 /* 1-Way */
452 #define INM_KILLNBR 10 /* Kill Neighbor */
453 #define INM_INACTTIM 11 /* Inactivity timer */
454 #define INM_LLDOWN 12 /* Line down */
455
456 #define TRANS_OFF 0
457 #define TRANS_ON 1
458 #define TRANS_WAIT 2 /* Waiting before the end of translation */
459
460
461
462 /* Generic option flags */
463 #define OPT_V6 0x01 /* OSPFv3, LSA relevant for IPv6 routing calculation */
464 #define OPT_E 0x02 /* Related to AS-external LSAs */
465 #define OPT_MC 0x04 /* Related to MOSPF, not used and obsolete */
466 #define OPT_N 0x08 /* Related to NSSA */
467 #define OPT_P 0x08 /* OSPFv2, flags P and N share position, see NSSA RFC */
468 #define OPT_EA 0x10 /* OSPFv2, external attributes, not used and obsolete */
469 #define OPT_R 0x10 /* OSPFv3, originator is active router */
470 #define OPT_DC 0x20 /* Related to demand circuits, not used */
471
472 /* Router-LSA VEB flags are are stored together with links (OSPFv2) or options (OSPFv3) */
473 #define OPT_RT_B (0x01 << 24)
474 #define OPT_RT_E (0x02 << 24)
475 #define OPT_RT_V (0x04 << 24)
476 #define OPT_RT_NT (0x10 << 24)
477
478 /* Prefix flags, specific for OSPFv3 */
479 #define OPT_PX_NU 0x01
480 #define OPT_PX_LA 0x02
481 #define OPT_PX_P 0x08
482 #define OPT_PX_DN 0x10
483
484
485 struct ospf_packet
486 {
487 u8 version;
488 u8 type;
489 u16 length;
490 u32 routerid;
491 u32 areaid;
492 u16 checksum;
493 u8 instance_id; /* See RFC 6549 */
494 u8 autype; /* Undefined for OSPFv3 */
495 };
496
497 struct ospf_md5
498 {
499 u16 zero;
500 u8 keyid;
501 u8 len;
502 u32 csn;
503 };
504
505 union ospf_auth
506 {
507 u8 password[8];
508 struct ospf_md5 md5;
509 };
510
511 /* Packet types */
512 #define HELLO_P 1 /* Hello */
513 #define DBDES_P 2 /* Database description */
514 #define LSREQ_P 3 /* Link state request */
515 #define LSUPD_P 4 /* Link state update */
516 #define LSACK_P 5 /* Link state acknowledgement */
517
518
519 #define DBDES_I 4 /* Init bit */
520 #define DBDES_M 2 /* More bit */
521 #define DBDES_MS 1 /* Master/Slave bit */
522 #define DBDES_IMMS (DBDES_I | DBDES_M | DBDES_MS)
523
524
525 #define LSA_T_RT 0x2001
526 #define LSA_T_NET 0x2002
527 #define LSA_T_SUM_NET 0x2003
528 #define LSA_T_SUM_RT 0x2004
529 #define LSA_T_EXT 0x4005
530 #define LSA_T_NSSA 0x2007
531 #define LSA_T_LINK 0x0008
532 #define LSA_T_PREFIX 0x2009
533
534 #define LSA_T_V2_MASK 0x00ff
535
536 #define LSA_UBIT 0x8000
537
538 #define LSA_SCOPE_LINK 0x0000
539 #define LSA_SCOPE_AREA 0x2000
540 #define LSA_SCOPE_AS 0x4000
541 #define LSA_SCOPE_RES 0x6000
542 #define LSA_SCOPE_MASK 0x6000
543 #define LSA_SCOPE(type) ((type) & LSA_SCOPE_MASK)
544
545
546 #define LSA_MAXAGE 3600 /* 1 hour */
547 #define LSA_CHECKAGE 300 /* 5 minutes */
548 #define LSA_MAXAGEDIFF 900 /* 15 minutes */
549
550 #define LSA_ZEROSEQNO ((s32) 0x80000000)
551 #define LSA_INITSEQNO ((s32) 0x80000001)
552 #define LSA_MAXSEQNO ((s32) 0x7fffffff)
553
554 #define LSA_METRIC_MASK 0x00FFFFFF
555 #define LSA_OPTIONS_MASK 0x00FFFFFF
556
557
558 #define LSART_PTP 1
559 #define LSART_NET 2
560 #define LSART_STUB 3
561 #define LSART_VLNK 4
562
563 #define LSA_RT2_LINKS 0x0000FFFF
564
565 #define LSA_SUM2_TOS 0xFF000000
566
567 #define LSA_EXT2_TOS 0x7F000000
568 #define LSA_EXT2_EBIT 0x80000000
569
570 #define LSA_EXT3_EBIT 0x4000000
571 #define LSA_EXT3_FBIT 0x2000000
572 #define LSA_EXT3_TBIT 0x1000000
573
574
575 struct ospf_lsa_header
576 {
577 u16 age; /* LS Age */
578 u16 type_raw; /* Type, mixed with options on OSPFv2 */
579
580 u32 id;
581 u32 rt; /* Advertising router */
582 s32 sn; /* LS Sequence number */
583 u16 checksum;
584 u16 length;
585 };
586
587
588 /* In OSPFv2, options are embedded in higher half of type_raw */
589 static inline u8 lsa_get_options(struct ospf_lsa_header *lsa)
590 { return lsa->type_raw >> 8; }
591
592 static inline void lsa_set_options(struct ospf_lsa_header *lsa, u16 options)
593 { lsa->type_raw = (lsa->type_raw & 0xff) | (options << 8); }
594
595
596 struct ospf_lsa_rt
597 {
598 u32 options; /* VEB flags, mixed with link count for OSPFv2 and options for OSPFv3 */
599 };
600
601 struct ospf_lsa_rt2_link
602 {
603 u32 id;
604 u32 data;
605 #ifdef CPU_BIG_ENDIAN
606 u8 type;
607 u8 no_tos;
608 u16 metric;
609 #else
610 u16 metric;
611 u8 no_tos;
612 u8 type;
613 #endif
614 };
615
616 struct ospf_lsa_rt2_tos
617 {
618 #ifdef CPU_BIG_ENDIAN
619 u8 tos;
620 u8 padding;
621 u16 metric;
622 #else
623 u16 metric;
624 u8 padding;
625 u8 tos;
626 #endif
627 };
628
629 struct ospf_lsa_rt3_link
630 {
631 #ifdef CPU_BIG_ENDIAN
632 u8 type;
633 u8 padding;
634 u16 metric;
635 #else
636 u16 metric;
637 u8 padding;
638 u8 type;
639 #endif
640 u32 lif; /* Local interface ID */
641 u32 nif; /* Neighbor interface ID */
642 u32 id; /* Neighbor router ID */
643 };
644
645
646 struct ospf_lsa_net
647 {
648 u32 optx; /* Netmask for OSPFv2, options for OSPFv3 */
649 u32 routers[];
650 };
651
652 struct ospf_lsa_sum2
653 {
654 u32 netmask;
655 u32 metric;
656 };
657
658 struct ospf_lsa_sum3_net
659 {
660 u32 metric;
661 u32 prefix[];
662 };
663
664 struct ospf_lsa_sum3_rt
665 {
666 u32 options;
667 u32 metric;
668 u32 drid;
669 };
670
671 struct ospf_lsa_ext2
672 {
673 u32 netmask;
674 u32 metric;
675 u32 fwaddr;
676 u32 tag;
677 };
678
679 struct ospf_lsa_ext3
680 {
681 u32 metric;
682 u32 rest[];
683 };
684
685 struct ospf_lsa_ext_local
686 {
687 ip_addr ip, fwaddr;
688 int pxlen;
689 u32 metric, ebit, fbit, tag, propagate;
690 u8 pxopts;
691 };
692
693 struct ospf_lsa_link
694 {
695 u32 options;
696 ip6_addr lladdr;
697 u32 pxcount;
698 u32 rest[];
699 };
700
701 struct ospf_lsa_prefix
702 {
703 #ifdef CPU_BIG_ENDIAN
704 u16 pxcount;
705 u16 ref_type;
706 #else
707 u16 ref_type;
708 u16 pxcount;
709 #endif
710 u32 ref_id;
711 u32 ref_rt;
712 u32 rest[];
713 };
714
715
716 static inline uint
717 lsa_net_count(struct ospf_lsa_header *lsa)
718 {
719 return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net))
720 / sizeof(u32);
721 }
722
723 /* In ospf_area->rtr we store paths to routers, but we use RID (and not IP address)
724 as index, so we need to encapsulate RID to IP address */
725
726 #define ipa_from_rid(x) ipa_from_u32(x)
727 #define ipa_to_rid(x) ipa_to_u32(x)
728
729
730 #define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
731 #define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
732
733 static inline u32 *
734 lsa_get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest)
735 {
736 u8 pxl = (*buf >> 24);
737 *pxopts = (*buf >> 16);
738 *rest = *buf;
739 *pxlen = pxl;
740 buf++;
741
742 *addr = IPA_NONE;
743
744 #ifdef IPV6
745 if (pxl > 0)
746 _I0(*addr) = *buf++;
747 if (pxl > 32)
748 _I1(*addr) = *buf++;
749 if (pxl > 64)
750 _I2(*addr) = *buf++;
751 if (pxl > 96)
752 _I3(*addr) = *buf++;
753
754 /* Clean up remaining bits */
755 if (pxl < 128)
756 addr->addr[pxl / 32] &= u32_mkmask(pxl % 32);
757 #endif
758
759 return buf;
760 }
761
762 static inline u32 *
763 lsa_get_ipv6_addr(u32 *buf, ip_addr *addr)
764 {
765 *addr = *(ip_addr *) buf;
766 return buf + 4;
767 }
768
769 static inline u32 *
770 put_ipv6_prefix(u32 *buf, ip_addr addr, u8 pxlen, u8 pxopts, u16 lh)
771 {
772 *buf++ = ((pxlen << 24) | (pxopts << 16) | lh);
773
774 if (pxlen > 0)
775 *buf++ = _I0(addr);
776 if (pxlen > 32)
777 *buf++ = _I1(addr);
778 if (pxlen > 64)
779 *buf++ = _I2(addr);
780 if (pxlen > 96)
781 *buf++ = _I3(addr);
782 return buf;
783 }
784
785 static inline u32 *
786 put_ipv6_addr(u32 *buf, ip_addr addr)
787 {
788 *(ip_addr *) buf = addr;
789 return buf + 4;
790 }
791
792
793 struct ospf_lsreq_header
794 {
795 u32 type;
796 u32 id;
797 u32 rt;
798 };
799
800
801
802 #define SH_ROUTER_SELF 0xffffffff
803
804 struct lsadb_show_data {
805 struct symbol *name; /* Protocol to request data from */
806 u16 type; /* LSA Type, 0 -> all */
807 u16 scope; /* Scope, 0 -> all, hack to handle link scope as 1 */
808 u32 area; /* Specified for area scope */
809 u32 lsid; /* LSA ID, 0 -> all */
810 u32 router; /* Advertising router, 0 -> all */
811 };
812
813
814 #define EA_OSPF_METRIC1 EA_CODE(EAP_OSPF, 0)
815 #define EA_OSPF_METRIC2 EA_CODE(EAP_OSPF, 1)
816 #define EA_OSPF_TAG EA_CODE(EAP_OSPF, 2)
817 #define EA_OSPF_ROUTER_ID EA_CODE(EAP_OSPF, 3)
818
819
820 /* ospf.c */
821 void ospf_schedule_rtcalc(struct ospf_proto *p);
822
823 static inline void ospf_notify_rt_lsa(struct ospf_area *oa)
824 { oa->update_rt_lsa = 1; }
825
826 static inline void ospf_notify_net_lsa(struct ospf_iface *ifa)
827 { ifa->update_net_lsa = 1; }
828
829 static inline void ospf_notify_link_lsa(struct ospf_iface *ifa)
830 { ifa->update_link_lsa = 1; }
831
832
833 #define ospf_is_v2(X) OSPF_IS_V2
834 #define ospf_is_v3(X) (!OSPF_IS_V2)
835 /*
836 static inline int ospf_is_v2(struct ospf_proto *p)
837 { return p->ospf2; }
838
839 static inline int ospf_is_v3(struct ospf_proto *p)
840 { return ! p->ospf2; }
841 */
842 static inline int ospf_get_version(struct ospf_proto *p)
843 { return ospf_is_v2(p) ? 2 : 3; }
844
845 struct ospf_area *ospf_find_area(struct ospf_proto *p, u32 aid);
846
847 static inline struct ospf_area *ospf_main_area(struct ospf_proto *p)
848 { return (p->areano == 1) ? HEAD(p->area_list) : p->backbone; }
849
850 static inline int oa_is_stub(struct ospf_area *oa)
851 { return (oa->options & (OPT_E | OPT_N)) == 0; }
852
853 static inline int oa_is_ext(struct ospf_area *oa)
854 { return oa->options & OPT_E; }
855
856 static inline int oa_is_nssa(struct ospf_area *oa)
857 { return oa->options & OPT_N; }
858
859 void ospf_sh_neigh(struct proto *P, char *iff);
860 void ospf_sh(struct proto *P);
861 void ospf_sh_iface(struct proto *P, char *iff);
862 void ospf_sh_state(struct proto *P, int verbose, int reachable);
863
864 void ospf_sh_lsadb(struct lsadb_show_data *ld);
865
866 /* iface.c */
867 void ospf_iface_chstate(struct ospf_iface *ifa, u8 state);
868 void ospf_iface_sm(struct ospf_iface *ifa, int event);
869 struct ospf_iface *ospf_iface_find(struct ospf_proto *p, struct iface *what);
870 void ospf_if_notify(struct proto *P, uint flags, struct iface *iface);
871 void ospf_ifa_notify2(struct proto *P, uint flags, struct ifa *a);
872 void ospf_ifa_notify3(struct proto *P, uint flags, struct ifa *a);
873 void ospf_iface_info(struct ospf_iface *ifa);
874 void ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *ip);
875 void ospf_iface_new_vlink(struct ospf_proto *p, struct ospf_iface_patt *ip);
876 void ospf_iface_remove(struct ospf_iface *ifa);
877 void ospf_iface_shutdown(struct ospf_iface *ifa);
878 int ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen);
879 int ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new);
880 void ospf_reconfigure_ifaces(struct ospf_proto *p);
881 void ospf_open_vlink_sk(struct ospf_proto *p);
882 struct nbma_node *find_nbma_node_(list *nnl, ip_addr ip);
883
884 static inline struct nbma_node * find_nbma_node(struct ospf_iface *ifa, ip_addr ip)
885 { return find_nbma_node_(&ifa->nbma_list, ip); }
886
887 /* neighbor.c */
888 struct ospf_neighbor *ospf_neighbor_new(struct ospf_iface *ifa);
889 void ospf_neigh_sm(struct ospf_neighbor *n, int event);
890 void ospf_dr_election(struct ospf_iface *ifa);
891 struct ospf_neighbor *find_neigh(struct ospf_iface *ifa, u32 rid);
892 struct ospf_neighbor *find_neigh_by_ip(struct ospf_iface *ifa, ip_addr ip);
893 void ospf_neigh_remove(struct ospf_neighbor *n);
894 void ospf_neigh_update_bfd(struct ospf_neighbor *n, int use_bfd);
895 void ospf_sh_neigh_info(struct ospf_neighbor *n);
896
897 /* packet.c */
898 void ospf_pkt_fill_hdr(struct ospf_iface *ifa, void *buf, u8 h_type);
899 uint ospf_pkt_maxsize(struct ospf_iface *ifa);
900 int ospf_rx_hook(sock * sk, int size);
901 // void ospf_tx_hook(sock * sk);
902 void ospf_err_hook(sock * sk, int err);
903 void ospf_verr_hook(sock *sk, int err);
904 void ospf_send_to(struct ospf_iface *ifa, ip_addr ip);
905 void ospf_send_to_agt(struct ospf_iface *ifa, u8 state);
906 void ospf_send_to_bdr(struct ospf_iface *ifa);
907
908 static inline void ospf_send_to_all(struct ospf_iface *ifa)
909 { ospf_send_to(ifa, ifa->all_routers); }
910
911 static inline void ospf_send_to_des(struct ospf_iface *ifa)
912 {
913 if (ipa_nonzero(ifa->des_routers))
914 ospf_send_to(ifa, ifa->des_routers);
915 else
916 ospf_send_to_bdr(ifa);
917 }
918
919 static inline uint ospf_pkt_hdrlen(struct ospf_proto *p)
920 { return ospf_is_v2(p) ? (sizeof(struct ospf_packet) + sizeof(union ospf_auth)) : sizeof(struct ospf_packet); }
921
922 static inline void * ospf_tx_buffer(struct ospf_iface *ifa)
923 { return ifa->sk->tbuf; }
924
925 /* hello.c */
926 #define OHS_HELLO 0
927 #define OHS_POLL 1
928 #define OHS_SHUTDOWN 2
929
930 void ospf_send_hello(struct ospf_iface *ifa, int kind, struct ospf_neighbor *dirn);
931 void ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n, ip_addr faddr);
932
933 /* dbdes.c */
934 void ospf_send_dbdes(struct ospf_proto *p, struct ospf_neighbor *n, int next);
935 void ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n);
936
937 /* lsreq.c */
938 void ospf_send_lsreq(struct ospf_proto *p, struct ospf_neighbor *n);
939 void ospf_receive_lsreq(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n);
940
941 /* lsupd.c */
942 void ospf_dump_lsahdr(struct ospf_proto *p, struct ospf_lsa_header *lsa_n);
943 void ospf_dump_common(struct ospf_proto *p, struct ospf_packet *pkt);
944 void ospf_add_flushed_to_lsrt(struct ospf_proto *p, struct ospf_neighbor *n);
945 int ospf_flood_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_neighbor *from);
946 int ospf_send_lsupd(struct ospf_proto *p, struct top_hash_entry **lsa_list, uint lsa_count, struct ospf_neighbor *n);
947 void ospf_rxmt_lsupd(struct ospf_proto *p, struct ospf_neighbor *n);
948 void ospf_receive_lsupd(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n);
949
950 /* lsack.c */
951 void ospf_enqueue_lsack(struct ospf_neighbor *n, struct ospf_lsa_header *h_n, int queue);
952 void ospf_reset_lsack_queue(struct ospf_neighbor *n);
953 void ospf_send_lsack(struct ospf_proto *p, struct ospf_neighbor *n, int queue);
954 void ospf_receive_lsack(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n);
955
956
957 #include "proto/ospf/rt.h"
958 #include "proto/ospf/topology.h"
959 #include "proto/ospf/lsalib.h"
960
961 #endif /* _BIRD_OSPF_H_ */