]>
git.ipfire.org Git - thirdparty/bird.git/blob - proto/ospf/ospf.h
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.
8 * Can be freely distributed and used under the terms of the GNU GPL.
14 #include "nest/bird.h"
16 #include "lib/checksum.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"
27 #include "nest/locks.h"
29 #include "conf/conf.h"
30 #include "lib/string.h"
34 #define OSPF_FORCE_DEBUG 1
36 #define OSPF_FORCE_DEBUG 0
40 #define OSPF_TRACE(flags, msg, args...) \
41 do { if ((p->p.debug & flags) || OSPF_FORCE_DEBUG) \
42 log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
44 #define OSPF_PACKET(dumpfn, buffer, msg, args...) \
45 do { if ((p->p.debug & D_PACKETS) || OSPF_FORCE_DEBUG) \
46 { log(L_TRACE "%s: " msg, p->p.name, ## args ); dumpfn(p, buffer); } } while(0)
48 #define LOG_PKT(msg, args...) \
49 log_rl(&p->log_pkt_tbf, L_REMOTE "%s: " msg, p->p.name, args)
51 #define LOG_PKT_AUTH(msg, args...) \
52 log_rl(&p->log_pkt_tbf, L_AUTH "%s: " msg, p->p.name, args)
54 #define LOG_PKT_WARN(msg, args...) \
55 log_rl(&p->log_pkt_tbf, L_WARN "%s: " msg, p->p.name, args)
57 #define LOG_LSA1(msg, args...) \
58 log_rl(&p->log_lsa_tbf, L_REMOTE "%s: " msg, p->p.name, args)
60 #define LOG_LSA2(msg, args...) \
61 do { if (! p->log_lsa_tbf.drop) \
62 log(L_REMOTE "%s: " msg, p->p.name, args); } while(0)
67 #define LSREFRESHTIME 1800 /* 30 minutes */
68 #define MINLSINTERVAL (5 S_)
69 #define MINLSARRIVAL (1 S_)
70 #define LSINFINITY 0xffffff
72 #define OSPF_PKT_TYPES 5 /* HELLO_P .. LSACK_P */
73 #define OSPF3_CRYPTO_ID 1 /* OSPFv3 Cryptographic Protocol ID */
75 #define OSPF_DEFAULT_TICK 1
76 #define OSPF_DEFAULT_STUB_COST 1000
77 #define OSPF_DEFAULT_ECMP_LIMIT 16
78 #define OSPF_DEFAULT_GR_TIME 120
79 #define OSPF_DEFAULT_TRANSINT 40
81 #define OSPF_MIN_PKT_SIZE 256
82 #define OSPF_MAX_PKT_SIZE 65535
84 #define OSPF_VLINK_ID_OFFSET 0x80000000
86 #define OSPF_GR_ABLE 1
87 #define OSPF_GR_AWARE 2
91 struct proto_config c
;
104 u8 gr_mode
; /* Graceful restart mode (OSPF_GR_*) */
105 uint gr_time
; /* Graceful restart interval */
107 list area_list
; /* list of area configs (struct ospf_area_config) */
108 list vlink_list
; /* list of configured vlinks (struct ospf_iface_patt) */
111 struct ospf_area_config
115 u32 default_cost
; /* Cost of default route for stub areas
116 (With possible LSA_EXT3_EBIT for NSSA areas) */
117 u8 type
; /* Area type (standard, stub, NSSA), represented
118 by option flags (OPT_E, OPT_N) */
119 u8 summary
; /* Import summaries to this stub/NSSA area, valid for ABR */
120 u8 default_nssa
; /* Generate default NSSA route for NSSA+summary area */
121 u8 translator
; /* Translator role, for NSSA ABR */
122 u32 transint
; /* Translator stability interval */
123 list patt_list
; /* List of iface configs (struct ospf_iface_patt) */
124 list net_list
; /* List of aggregate networks for that area */
125 list enet_list
; /* List of aggregate external (NSSA) networks */
126 list stubnet_list
; /* List of stub networks added to Router LSA */
129 struct area_net_config
139 u32 metric
; /* With possible LSA_EXT3_EBIT for NSSA area nets */
146 struct ospf_stubnet_config
163 struct ospf_iface_patt
184 #define OSPF_RXBUF_MINSIZE 256 /* Minimal allowed size */
187 u8 autype
; /* OSPF_AUTH_*, not really used in OSPFv3 */
191 u8 link_lsa_suppression
;
192 u8 real_bcast
; /* Not really used in OSPFv3 */
193 u8 ptp_netmask
; /* bool + 2 for unspecified */
194 u8 ttl_security
; /* bool + 2 for TX only */
199 /* Default values for interface parameters */
202 #define INFTRANSDELAY_D 1
204 #define HELLOINT_D 10
208 /* Value of Wait timer - not found it in RFC * - using 4*HELLO */
215 timer
*disp_timer
; /* OSPF proto dispatcher */
217 struct top_graph
*gr
; /* LSA graph */
218 slist lsal
; /* List of all LSA's */
219 int calcrt
; /* Routing table calculation scheduled?
220 0=no, 1=normal, 2=forced reload */
221 list iface_list
; /* List of OSPF interfaces (struct ospf_iface) */
222 list area_list
; /* List of OSPF areas (struct ospf_area) */
223 int areano
; /* Number of area I belong to */
224 int padj
; /* Number of neighbors in Exchange or Loading state */
225 int gr_count
; /* Number of neighbors in graceful restart state */
226 u8 gr_recovery
; /* Graceful restart recovery is active */
227 u8 gr_cleanup
; /* GR cleanup scheduled */
228 btime gr_timeout
; /* The end time of grace restart recovery */
229 struct fib rtf
; /* Routing table */
230 struct idm idm
; /* OSPFv3 LSA ID map */
231 u8 ospf2
; /* OSPF v2 or v3 */
232 u8 af_ext
; /* OSPFv3-AF extension */
233 u8 af_mc
; /* OSPFv3-AF multicast */
234 u8 rfc1583
; /* RFC1583 compatibility */
235 u8 stub_router
; /* Do not forward transit traffic */
236 u8 merge_external
; /* Should i merge external routes? */
237 u8 instance_id
; /* Differentiate between more OSPF instances */
238 u8 asbr
; /* May i originate any ext/NSSA lsa? */
239 u8 vpn_pe
; /* Should we do VPN PE specific behavior (RFC 4577)? */
240 u8 ecmp
; /* Maximal number of nexthops in ECMP route, or 0 */
241 u8 gr_mode
; /* Graceful restart mode (OSPF_GR_*) */
242 uint gr_time
; /* Graceful restart interval */
243 u64 csn64
; /* Last used cryptographic sequence number */
244 struct ospf_area
*backbone
; /* If exists */
245 event
*flood_event
; /* Event for flooding LS updates */
246 void *lsab
; /* LSA buffer used when originating router LSAs */
247 int lsab_size
, lsab_used
;
248 linpool
*nhpool
; /* Linpool used for next hops computed in SPF */
249 sock
*vlink_sk
; /* IP socket used for vlink TX */
251 u32 last_vlink_id
; /* Interface IDs for vlinks (starts at 0x80000000) */
252 struct tbf log_pkt_tbf
; /* TBF for packet messages */
253 struct tbf log_lsa_tbf
; /* TBF for LSA messages */
260 struct ospf_area_config
*ac
; /* Related area config */
261 struct top_hash_entry
*rt
; /* My own router LSA */
262 struct top_hash_entry
*pxr_lsa
; /* Originated prefix LSA */
263 list cand
; /* List of candidates for RT calc. */
264 struct fib net_fib
; /* Networks to advertise or not */
265 struct fib enet_fib
; /* External networks for NSSAs */
266 u32 options
; /* Optional features */
267 u8 update_rt_lsa
; /* Rt lsa origination scheduled? */
268 u8 trcap
; /* Transit capability? */
269 u8 marked
; /* Used in OSPF reconfigure */
270 u8 translate
; /* Translator state (TRANS_*), for NSSA ABR */
271 timer
*translator_timer
; /* For NSSA translator switch */
272 struct ospf_proto
*po
;
273 struct fib rtr
; /* Routing tables for routers */
279 struct iface
*iface
; /* Nest's iface (NULL for vlinks) */
280 struct ifa
*addr
; /* IP prefix associated with that OSPF iface */
281 struct ospf_area
*oa
;
282 struct ospf_iface_patt
*cf
;
283 char *ifname
; /* Interface name (iface->name), new one for vlinks */
286 sock
*sk
; /* IP socket */
287 list neigh_list
; /* List of neighbors (struct ospf_neighbor) */
288 u32 cost
; /* Cost of iface */
289 u32 waitint
; /* Number of seconds before changing state from wait */
290 u32 rxmtint
; /* Number of seconds between LSA retransmissions */
291 u32 pollint
; /* Poll interval in seconds */
292 u32 deadint
; /* After deadint seconds without hellos is router dead */
293 u32 iface_id
; /* Interface ID (iface->index or new value for vlinks) */
294 u32 vid
; /* ID of peer of virtual link */
295 ip_addr vip
; /* IP of peer of virtual link */
296 struct ospf_iface
*vifa
; /* OSPF iface which the vlink goes through */
297 struct ospf_area
*voa
; /* OSPF area which the vlink goes through */
298 u16 inftransdelay
; /* The estimated number of seconds it takes to
299 transmit a Link State Update Packet over this
300 interface. LSAs contained in the update */
301 u16 helloint
; /* number of seconds between hello sending */
303 u32 csn
; /* Last used crypt seq number */
304 btime csn_use
; /* Last time when packet with that CSN was sent */
305 ip_addr all_routers
; /* Multicast (or broadcast) address for all routers */
306 ip_addr des_routers
; /* Multicast (or NULL) address for designated routers */
307 ip_addr drip
; /* Designated router IP */
308 ip_addr bdrip
; /* Backup DR IP */
309 u32 drid
; /* DR Router ID */
310 u32 bdrid
; /* BDR Router ID */
311 s16 rt_pos_beg
; /* Position of iface in Router-LSA, begin, inclusive */
312 s16 rt_pos_end
; /* Position of iface in Router-LSA, end, exclusive */
313 s16 px_pos_beg
; /* Position of iface in Rt Prefix-LSA, begin, inclusive */
314 s16 px_pos_end
; /* Position of iface in Rt Prefix-LSA, end, exclusive */
315 u32 dr_iface_id
; /* if drid is valid, this is iface_id of DR (for connecting network) */
316 u8 instance_id
; /* Used to differentiate between more OSPF
317 instances on one interface */
318 u8 autype
; /* Authentication type (OSPF_AUTH_*) */
319 u8 type
; /* OSPF view of type (OSPF_IT_*) */
320 u8 strictnbma
; /* Can I talk with unknown neighbors? */
321 u8 stub
; /* Inactive interface */
322 u8 state
; /* Interface state machine (OSPF_IS_*) */
323 timer
*wait_timer
; /* WAIT timer */
324 timer
*hello_timer
; /* HELLOINT timer */
325 timer
*poll_timer
; /* Poll Interval - for NBMA */
327 struct top_hash_entry
*link_lsa
; /* Originated link LSA */
328 struct top_hash_entry
*net_lsa
; /* Originated network LSA */
329 struct top_hash_entry
*pxn_lsa
; /* Originated prefix LSA */
330 struct top_hash_entry
**flood_queue
; /* LSAs queued for LSUPD */
333 u16 flood_queue_used
; /* The current number of LSAs in flood_queue */
334 u16 flood_queue_size
; /* The maximum number of LSAs in flood_queue */
335 int fadj
; /* Number of fully adjacent neighbors */
337 u8 priority
; /* A router priority for DR election */
339 #define OSPF_I_OK 0 /* Everything OK */
340 #define OSPF_I_SK 1 /* Socket open failed */
341 #define OSPF_I_LL 2 /* Missing link-local address (OSPFv3) */
342 u8 sk_dr
; /* Socket is a member of designated routers group */
343 u8 marked
; /* Used in OSPF reconfigure, 2 for force restart */
344 u16 rxbuf
; /* Buffer size */
345 u16 tx_length
; /* Soft TX packet length limit, usually MTU */
346 u16 tx_hdrlen
; /* Expected packet header length, less than tx_length */
347 u8 check_link
; /* Whether iface link change is used */
348 u8 ecmp_weight
; /* Weight used for ECMP */
349 u8 link_lsa_suppression
; /* Suppression of Link-LSA origination */
350 u8 ptp_netmask
; /* Send real netmask for P2P */
351 u8 check_ttl
; /* Check incoming packets for TTL 255 */
352 u8 bfd
; /* Use BFD on iface */
359 struct ospf_iface
*ifa
;
361 u8 gr_active
; /* We act as GR helper for the neighbor */
362 u8 got_my_rt_lsa
; /* Received my Rt-LSA in DBDES exchanged */
363 timer
*inactim
; /* Inactivity timer */
364 u8 imms
; /* I, M, Master/slave received */
365 u8 myimms
; /* I, M Master/slave */
366 u32 dds
; /* DD Sequence number being sent */
367 u32 ddr
; /* last Dat Des packet received */
369 u32 rid
; /* Router ID */
370 ip_addr ip
; /* IP of it's interface */
371 u8 priority
; /* Priority */
372 u32 options
; /* Options received */
374 /* Entries dr and bdr store IP addresses in OSPFv2 and router IDs in
375 OSPFv3, we use the same type to simplify handling */
376 u32 dr
; /* Neighbor's idea of DR */
377 u32 bdr
; /* Neighbor's idea of BDR */
378 u32 iface_id
; /* ID of Neighbour's iface connected to common network */
380 /* Database summary list iterator, controls initial dbdes exchange.
381 * Advances in the LSA list as dbdes packets are sent.
383 siterator dbsi
; /* iterator of po->lsal */
385 /* Link state request list, controls initial LSA exchange.
386 * Entries added when received in dbdes packets, removed as sent in lsreq packets.
388 slist lsrql
; /* slist of struct top_hash_entry from n->lsrqh */
389 struct top_graph
*lsrqh
;
390 struct top_hash_entry
*lsrqi
; /* Pointer to the first unsent node in lsrql */
392 /* Link state retransmission list, controls LSA retransmission during flood.
393 * Entries added as sent in lsupd packets, removed when received in lsack packets.
394 * These entries hold ret_count in appropriate LSA entries.
396 slist lsrtl
; /* slist of struct top_hash_entry from n->lsrth */
397 struct top_graph
*lsrth
;
398 timer
*dbdes_timer
; /* DBDES exchange timer */
399 timer
*lsrq_timer
; /* LSA request timer */
400 timer
*lsrt_timer
; /* LSA retransmission timer */
402 #define ACKL_DIRECT 0
404 timer
*ackd_timer
; /* Delayed ack timer */
405 timer
*gr_timer
; /* Graceful restart timer, non-NULL only if gr_active */
406 struct bfd_request
*bfd_req
; /* BFD request, if BFD is used */
407 void *ldd_buffer
; /* Last database description packet */
408 u32 ldd_bsize
; /* Buffer size for ldd_buffer */
409 u32 csn
; /* OSPFv2: Last received crypt seq number */
410 u64 csn64
[OSPF_PKT_TYPES
]; /* OSPFv3: Last received CSN for each type of packet */
414 /* OSPF interface types */
415 #define OSPF_IT_BCAST 0
416 #define OSPF_IT_NBMA 1
417 #define OSPF_IT_PTP 2
418 #define OSPF_IT_PTMP 3
419 #define OSPF_IT_VLINK 4
420 #define OSPF_IT_UNDEF 5
422 /* OSPF interface states */
423 #define OSPF_IS_DOWN 0 /* Not active */
424 #define OSPF_IS_LOOP 1 /* Iface with no link */
425 #define OSPF_IS_WAITING 2 /* Waiting for Wait timer */
426 #define OSPF_IS_PTP 3 /* PTP operational */
427 #define OSPF_IS_DROTHER 4 /* I'm on BCAST or NBMA and I'm not DR */
428 #define OSPF_IS_BACKUP 5 /* I'm BDR */
429 #define OSPF_IS_DR 6 /* I'm DR */
431 /* Definitions for interface state machine */
432 #define ISM_UP 0 /* Interface Up */
433 #define ISM_WAITF 1 /* Wait timer fired */
434 #define ISM_BACKS 2 /* Backup seen */
435 #define ISM_NEICH 3 /* Neighbor change */
436 #define ISM_LOOP 4 /* Link down */
437 #define ISM_UNLOOP 5 /* Link up */
438 #define ISM_DOWN 6 /* Interface down */
440 /* OSPF authentication types */
441 #define OSPF_AUTH_NONE 0
442 #define OSPF_AUTH_SIMPLE 1
443 #define OSPF_AUTH_CRYPT 2
445 #define OSPF3_AUTH_HMAC 1 /* HMAC Cryptographic Authentication */
447 /* OSPF neighbor states */
448 #define NEIGHBOR_DOWN 0
449 #define NEIGHBOR_ATTEMPT 1
450 #define NEIGHBOR_INIT 2
451 #define NEIGHBOR_2WAY 3
452 #define NEIGHBOR_EXSTART 4
453 #define NEIGHBOR_EXCHANGE 5
454 #define NEIGHBOR_LOADING 6
455 #define NEIGHBOR_FULL 7
457 /* Definitions for neighbor state machine */
458 #define INM_HELLOREC 0 /* Hello Received */
459 #define INM_START 1 /* Neighbor start - for NBMA */
460 #define INM_2WAYREC 2 /* 2-Way received */
461 #define INM_NEGDONE 3 /* Negotiation done */
462 #define INM_EXDONE 4 /* Exchange done */
463 #define INM_BADLSREQ 5 /* Bad LS Request */
464 #define INM_LOADDONE 6 /* Load done */
465 #define INM_ADJOK 7 /* AdjOK? */
466 #define INM_SEQMIS 8 /* Sequence number mismatch */
467 #define INM_1WAYREC 9 /* 1-Way */
468 #define INM_KILLNBR 10 /* Kill Neighbor */
469 #define INM_INACTTIM 11 /* Inactivity timer */
470 #define INM_LLDOWN 12 /* Line down */
474 #define TRANS_WAIT 2 /* Waiting before the end of translation */
477 /* Generic option flags */
478 #define OPT_V6 0x0001 /* OSPFv3, LSA relevant for IPv6 routing calculation */
479 #define OPT_E 0x0002 /* Related to AS-external LSAs */
480 #define OPT_MC 0x0004 /* Related to MOSPF, not used and obsolete */
481 #define OPT_N 0x0008 /* Related to NSSA */
482 #define OPT_P 0x0008 /* OSPFv2, flags P and N share position, see NSSA RFC */
483 #define OPT_L_V2 0x0010 /* OSPFv2, link-local signaling, not used */
484 #define OPT_R 0x0010 /* OSPFv3, originator is active router */
485 #define OPT_DC 0x0020 /* Related to demand circuits, not used */
486 #define OPT_O 0x0040 /* OSPFv2 Opaque LSA (RFC 5250) */
487 #define OPT_DN 0x0080 /* OSPFv2 VPN loop prevention (RFC 4576) */
488 #define OPT_AF 0x0100 /* OSPFv3 Address Families (RFC 5838) */
489 #define OPT_L_V3 0x0200 /* OSPFv3, link-local signaling */
490 #define OPT_AT 0x0400 /* OSPFv3, authentication trailer */
492 #define HELLO2_OPT_MASK (OPT_E | OPT_N | OPT_L_V2)
493 #define DBDES2_OPT_MASK (OPT_E | OPT_L_V2 | OPT_O)
495 #define HELLO3_OPT_MASK (OPT_V6 | OPT_E | OPT_N | OPT_R | OPT_AF | OPT_L_V3 | OPT_AT )
496 #define DBDES3_OPT_MASK (OPT_V6 | OPT_E | OPT_R | OPT_AF | OPT_L_V3 | OPT_AT )
498 /* Router-LSA VEB flags are are stored together with links (OSPFv2) or options (OSPFv3) */
499 #define OPT_RT_B (0x01 << 24)
500 #define OPT_RT_E (0x02 << 24)
501 #define OPT_RT_V (0x04 << 24)
502 #define OPT_RT_NT (0x10 << 24)
504 /* Prefix flags, specific for OSPFv3 */
505 #define OPT_PX_NU 0x01
506 #define OPT_PX_LA 0x02
507 #define OPT_PX_P 0x08
508 #define OPT_PX_DN 0x10
519 u8 instance_id
; /* See RFC 6549 */
520 u8 autype
; /* Undefined for OSPFv3 */
530 struct ospf_auth_crypto
535 u32 csn
; /* Cryptographic sequence number (32-bit) */
541 struct ospf_auth_crypto c32
;
546 u16 type
; /* Authentication type (OSPF3_AUTH_*) */
547 u16 length
; /* Authentication trailer length (header + data) */
549 u16 sa_id
; /* Security association identifier (key_id) */
550 u64 csn
; /* Cryptographic sequence number (64-bit) */
551 byte data
[0]; /* Authentication data */
556 #define HELLO_P 1 /* Hello */
557 #define DBDES_P 2 /* Database description */
558 #define LSREQ_P 3 /* Link state request */
559 #define LSUPD_P 4 /* Link state update */
560 #define LSACK_P 5 /* Link state acknowledgement */
563 #define DBDES_I 4 /* Init bit */
564 #define DBDES_M 2 /* More bit */
565 #define DBDES_MS 1 /* Master/Slave bit */
566 #define DBDES_IMMS (DBDES_I | DBDES_M | DBDES_MS)
569 /* OSPFv3 LSA Types / LSA Function Codes */
570 /* https://www.iana.org/assignments/ospfv3-parameters/ospfv3-parameters.xhtml#ospfv3-parameters-3 */
571 #define LSA_T_RT 0x2001
572 #define LSA_T_NET 0x2002
573 #define LSA_T_SUM_NET 0x2003
574 #define LSA_T_SUM_RT 0x2004
575 #define LSA_T_EXT 0x4005
576 #define LSA_T_NSSA 0x2007
577 #define LSA_T_LINK 0x0008
578 #define LSA_T_PREFIX 0x2009
579 #define LSA_T_GR 0x000B
580 #define LSA_T_RI_ 0x000C
581 #define LSA_T_RI_LINK 0x800C
582 #define LSA_T_RI_AREA 0xA00C
583 #define LSA_T_RI_AS 0xC00C
584 #define LSA_T_OPAQUE_ 0x1FFF
585 #define LSA_T_OPAQUE_LINK 0x9FFF
586 #define LSA_T_OPAQUE_AREA 0xBFFF
587 #define LSA_T_OPAQUE_AS 0xDFFF
589 #define LSA_T_V2_OPAQUE_ 0x0009
590 #define LSA_T_V2_MASK 0x00ff
592 /* OSPFv2 Opaque LSA Types */
593 /* https://www.iana.org/assignments/ospf-opaque-types/ospf-opaque-types.xhtml#ospf-opaque-types-2 */
594 #define LSA_OT_GR 0x03
595 #define LSA_OT_RI 0x04
597 #define LSA_FUNCTION_MASK 0x1FFF
598 #define LSA_FUNCTION(type) ((type) & LSA_FUNCTION_MASK)
600 #define LSA_UBIT 0x8000
602 #define LSA_SCOPE_LINK 0x0000
603 #define LSA_SCOPE_AREA 0x2000
604 #define LSA_SCOPE_AS 0x4000
605 #define LSA_SCOPE_RES 0x6000
606 #define LSA_SCOPE_MASK 0x6000
607 #define LSA_SCOPE(type) ((type) & LSA_SCOPE_MASK)
608 #define LSA_SCOPE_ORDER(type) (((type) >> 13) & 0x3)
611 #define LSA_MAXAGE 3600 /* 1 hour */
612 #define LSA_CHECKAGE 300 /* 5 minutes */
613 #define LSA_MAXAGEDIFF 900 /* 15 minutes */
615 #define LSA_ZEROSEQNO ((s32) 0x80000000)
616 #define LSA_INITSEQNO ((s32) 0x80000001)
617 #define LSA_MAXSEQNO ((s32) 0x7fffffff)
619 #define LSA_METRIC_MASK 0x00FFFFFF
620 #define LSA_OPTIONS_MASK 0x00FFFFFF
628 #define LSA_RT2_LINKS 0x0000FFFF
630 #define LSA_SUM2_TOS 0xFF000000
632 #define LSA_EXT2_TOS 0x7F000000
633 #define LSA_EXT2_EBIT 0x80000000
635 #define LSA_EXT3_EBIT 0x04000000
636 #define LSA_EXT3_FBIT 0x02000000
637 #define LSA_EXT3_TBIT 0x01000000
639 /* OSPF Grace LSA (GR) TLVs */
640 /* https://www.iana.org/assignments/ospfv2-parameters/ospfv2-parameters.xhtml#ospfv2-parameters-13 */
641 #define LSA_GR_PERIOD 1
642 #define LSA_GR_REASON 2
643 #define LSA_GR_ADDRESS 3
645 /* OSPF Router Information (RI) TLVs */
646 /* https://www.iana.org/assignments/ospf-parameters/ospf-parameters.xhtml#ri-tlv */
650 /* OSPF Router Informational Capability Bits */
651 /* https://www.iana.org/assignments/ospf-parameters/ospf-parameters.xhtml#router-informational-capability */
652 #define LSA_RIC_GR_CAPABLE 0
653 #define LSA_RIC_GR_HELPER 1
654 #define LSA_RIC_STUB_ROUTER 2
657 struct ospf_lsa_header
659 u16 age
; /* LS Age */
660 u16 type_raw
; /* Type, mixed with options on OSPFv2 */
663 u32 rt
; /* Advertising router */
664 s32 sn
; /* LS Sequence number */
670 /* In OSPFv2, options are embedded in higher half of type_raw */
671 static inline u8
lsa_get_options(struct ospf_lsa_header
*lsa
)
672 { return lsa
->type_raw
>> 8; }
674 static inline void lsa_set_options(struct ospf_lsa_header
*lsa
, u16 options
)
675 { lsa
->type_raw
= (lsa
->type_raw
& 0xff) | (options
<< 8); }
680 u32 options
; /* VEB flags, mixed with link count for OSPFv2 and options for OSPFv3 */
683 struct ospf_lsa_rt2_link
687 #ifdef CPU_BIG_ENDIAN
698 struct ospf_lsa_rt2_tos
700 #ifdef CPU_BIG_ENDIAN
711 struct ospf_lsa_rt3_link
713 #ifdef CPU_BIG_ENDIAN
722 u32 lif
; /* Local interface ID */
723 u32 nif
; /* Neighbor interface ID */
724 u32 id
; /* Neighbor router ID */
730 u32 optx
; /* Netmask for OSPFv2, options for OSPFv3 */
740 struct ospf_lsa_sum3_net
746 struct ospf_lsa_sum3_rt
767 struct ospf_lsa_ext_local
771 u32 metric
, ebit
, fbit
, tag
, propagate
, downwards
;
783 struct ospf_lsa_prefix
785 #ifdef CPU_BIG_ENDIAN
799 #ifdef CPU_BIG_ENDIAN
811 lsa_net_count(struct ospf_lsa_header
*lsa
)
813 return (lsa
->length
- sizeof(struct ospf_lsa_header
) - sizeof(struct ospf_lsa_net
))
817 /* In ospf_area->rtr we store paths to routers, but we use RID (and not IP address)
818 as index, so we need to encapsulate RID to IP address */
820 #define net_from_rid(x) NET_ADDR_IP4(ip4_from_u32(x), IP4_MAX_PREFIX_LENGTH)
821 #define rid_from_net(x) ip4_to_u32(((net_addr_ip4 *) x)->prefix)
823 #define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
824 #define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
828 ospf_valid_prefix(net_addr
*n
)
831 * In OSPFv2, prefix is stored as netmask; ip4_masklen() returns 255 for
832 * invalid one. But OSPFv3-AF may receive IPv4 net with 32 < pxlen < 128.
834 uint max
= (n
->type
== NET_IP4
) ? IP4_MAX_PREFIX_LENGTH
: IP6_MAX_PREFIX_LENGTH
;
835 return n
->pxlen
<= max
;
839 * In OSPFv3-AF (RFC 5835), IPv4 address is encoded by just placing it in the
840 * first 32 bits of IPv6 address and setting remaining bits to zero. Likewise
841 * for IPv4 prefix, where remaining bits do not matter. We use following
842 * functions to convert between IPv4 and IPv4-in-IPv6 representations:
845 static inline ip4_addr
ospf3_6to4(ip6_addr a
)
846 { return _MI4(_I0(a
)); }
848 static inline ip6_addr
ospf3_4to6(ip4_addr a
)
849 { return _MI6(_I(a
), 0, 0, 0); }
853 ospf3_get_prefix(u32
*buf
, int af
, net_addr
*n
, u8
*pxopts
, u16
*rest
)
855 ip6_addr px
= IP6_NONE
;
856 uint pxlen
= (*buf
>> 24);
857 *pxopts
= (*buf
>> 16) & 0xff;
858 if (rest
) *rest
= *buf
& 0xffff;
870 /* Clean up remaining bits */
872 px
.addr
[pxlen
/ 32] &= u32_mkmask(pxlen
% 32);
875 net_fill_ip4(n
, ospf3_6to4(px
), pxlen
);
877 net_fill_ip6(n
, px
, pxlen
);
883 ospf3_put_prefix(u32
*buf
, net_addr
*n
, u8 pxopts
, u16 rest
)
885 ip6_addr px
= (n
->type
== NET_IP4
) ? ospf3_4to6(net4_prefix(n
)) : net6_prefix(n
);
886 uint pxlen
= n
->pxlen
;
888 *buf
++ = ((pxlen
<< 24) | (pxopts
<< 16) | rest
);
903 ospf3_get_addr(u32
*buf
, int af
, ip_addr
*addr
)
907 *addr
= (af
== NET_IP4
) ? ipa_from_ip4(ospf3_6to4(a
)) : ipa_from_ip6(a
);
912 ospf3_put_addr(u32
*buf
, ip_addr addr
)
914 ip6_addr a
= ipa_is_ip4(addr
) ? ospf3_4to6(ipa_to_ip4(addr
)) : ipa_to_ip6(addr
);
920 struct ospf_lsreq_header
929 #define SH_ROUTER_SELF 0xffffffff
931 struct lsadb_show_data
{
932 struct ospf_proto
*proto
; /* Protocol to request data from */
933 u16 type
; /* LSA Type, 0 -> all */
934 u16 scope
; /* Scope, 0 -> all, hack to handle link scope as 1 */
935 u32 area
; /* Specified for area scope */
936 u32 lsid
; /* LSA ID, 0 -> all */
937 u32 router
; /* Advertising router, 0 -> all */
941 #define EA_OSPF_METRIC1 EA_CODE(PROTOCOL_OSPF, 0)
942 #define EA_OSPF_METRIC2 EA_CODE(PROTOCOL_OSPF, 1)
943 #define EA_OSPF_TAG EA_CODE(PROTOCOL_OSPF, 2)
944 #define EA_OSPF_ROUTER_ID EA_CODE(PROTOCOL_OSPF, 3)
948 void ospf_schedule_rtcalc(struct ospf_proto
*p
);
950 static inline void ospf_notify_rt_lsa(struct ospf_area
*oa
)
951 { oa
->update_rt_lsa
= 1; }
953 static inline void ospf_notify_net_lsa(struct ospf_iface
*ifa
)
954 { ifa
->update_net_lsa
= 1; }
956 static inline void ospf_notify_link_lsa(struct ospf_iface
*ifa
)
957 { ifa
->update_link_lsa
= 1; }
959 static inline int ospf_is_v2(struct ospf_proto
*p
)
962 static inline int ospf_is_v3(struct ospf_proto
*p
)
963 { return ! p
->ospf2
; }
965 static inline int ospf_get_version(struct ospf_proto
*p
)
966 { return ospf_is_v2(p
) ? 2 : 3; }
968 static inline int ospf_is_ip4(struct ospf_proto
*p
)
969 { return p
->p
.net_type
== NET_IP4
; }
971 static inline int ospf_is_ip6(struct ospf_proto
*p
)
972 { return p
->p
.net_type
== NET_IP6
; }
974 static inline int ospf_get_af(struct ospf_proto
*p
)
975 { return p
->p
.net_type
; }
977 struct ospf_area
*ospf_find_area(struct ospf_proto
*p
, u32 aid
);
979 static inline struct ospf_area
*ospf_main_area(struct ospf_proto
*p
)
980 { return (p
->areano
== 1) ? HEAD(p
->area_list
) : p
->backbone
; }
982 static inline int oa_is_stub(struct ospf_area
*oa
)
983 { return (oa
->options
& (OPT_E
| OPT_N
)) == 0; }
985 static inline int oa_is_ext(struct ospf_area
*oa
)
986 { return oa
->options
& OPT_E
; }
988 static inline int oa_is_nssa(struct ospf_area
*oa
)
989 { return oa
->options
& OPT_N
; }
991 void ospf_stop_gr_recovery(struct ospf_proto
*p
);
993 void ospf_sh_neigh(struct proto
*P
, char *iff
);
994 void ospf_sh(struct proto
*P
);
995 void ospf_sh_iface(struct proto
*P
, char *iff
);
996 void ospf_sh_state(struct proto
*P
, int verbose
, int reachable
);
998 void ospf_sh_lsadb(struct lsadb_show_data
*ld
);
1001 void ospf_iface_chstate(struct ospf_iface
*ifa
, u8 state
);
1002 void ospf_iface_sm(struct ospf_iface
*ifa
, int event
);
1003 struct ospf_iface
*ospf_iface_find(struct ospf_proto
*p
, struct iface
*what
);
1004 void ospf_if_notify(struct proto
*P
, uint flags
, struct iface
*iface
);
1005 void ospf_ifa_notify2(struct proto
*P
, uint flags
, struct ifa
*a
);
1006 void ospf_ifa_notify3(struct proto
*P
, uint flags
, struct ifa
*a
);
1007 void ospf_iface_info(struct ospf_iface
*ifa
);
1008 void ospf_iface_new(struct ospf_area
*oa
, struct ifa
*addr
, struct ospf_iface_patt
*ip
);
1009 void ospf_iface_new_vlink(struct ospf_proto
*p
, struct ospf_iface_patt
*ip
);
1010 void ospf_iface_remove(struct ospf_iface
*ifa
);
1011 void ospf_iface_shutdown(struct ospf_iface
*ifa
);
1012 int ospf_iface_assure_bufsize(struct ospf_iface
*ifa
, uint plen
);
1013 int ospf_iface_reconfigure(struct ospf_iface
*ifa
, struct ospf_iface_patt
*new);
1014 void ospf_reconfigure_ifaces(struct ospf_proto
*p
);
1015 void ospf_open_vlink_sk(struct ospf_proto
*p
);
1016 struct nbma_node
*find_nbma_node_(list
*nnl
, ip_addr ip
);
1018 static inline struct nbma_node
* find_nbma_node(struct ospf_iface
*ifa
, ip_addr ip
)
1019 { return find_nbma_node_(&ifa
->nbma_list
, ip
); }
1022 struct ospf_neighbor
*ospf_neighbor_new(struct ospf_iface
*ifa
);
1023 void ospf_neigh_sm(struct ospf_neighbor
*n
, int event
);
1024 void ospf_neigh_cancel_graceful_restart(struct ospf_neighbor
*n
);
1025 void ospf_neigh_notify_grace_lsa(struct ospf_neighbor
*n
, struct top_hash_entry
*en
);
1026 void ospf_neigh_lsadb_changed_(struct ospf_proto
*p
, struct top_hash_entry
*en
);
1027 void ospf_dr_election(struct ospf_iface
*ifa
);
1028 struct ospf_neighbor
*find_neigh(struct ospf_iface
*ifa
, u32 rid
);
1029 struct ospf_neighbor
*find_neigh_by_ip(struct ospf_iface
*ifa
, ip_addr ip
);
1030 void ospf_neigh_update_bfd(struct ospf_neighbor
*n
, int use_bfd
);
1031 void ospf_sh_neigh_info(struct ospf_neighbor
*n
);
1033 static inline void ospf_neigh_lsadb_changed(struct ospf_proto
*p
, struct top_hash_entry
*en
)
1034 { if (p
->gr_count
) ospf_neigh_lsadb_changed_(p
, en
); }
1037 void ospf_pkt_fill_hdr(struct ospf_iface
*ifa
, void *buf
, u8 h_type
);
1038 int ospf_rx_hook(sock
* sk
, uint size
);
1039 // void ospf_tx_hook(sock * sk);
1040 void ospf_err_hook(sock
* sk
, int err
);
1041 void ospf_verr_hook(sock
*sk
, int err
);
1042 void ospf_send_to(struct ospf_iface
*ifa
, ip_addr ip
);
1043 void ospf_send_to_agt(struct ospf_iface
*ifa
, u8 state
);
1044 void ospf_send_to_bdr(struct ospf_iface
*ifa
);
1046 static inline uint
ospf_pkt_maxsize(struct ospf_iface
*ifa
)
1047 { return ifa
->tx_length
- ifa
->tx_hdrlen
; }
1049 static inline void ospf_send_to_all(struct ospf_iface
*ifa
)
1050 { ospf_send_to(ifa
, ifa
->all_routers
); }
1052 static inline void ospf_send_to_des(struct ospf_iface
*ifa
)
1054 if (ipa_nonzero(ifa
->des_routers
))
1055 ospf_send_to(ifa
, ifa
->des_routers
);
1057 ospf_send_to_bdr(ifa
);
1061 #define DROP(DSC,VAL) do { err_dsc = DSC; err_val = VAL; goto drop; } while(0)
1062 #define DROP1(DSC) do { err_dsc = DSC; goto drop; } while(0)
1063 #define SKIP(DSC) do { err_dsc = DSC; goto skip; } while(0)
1066 static inline uint
ospf_pkt_hdrlen(struct ospf_proto
*p
)
1067 { return ospf_is_v2(p
) ? (sizeof(struct ospf_packet
) + sizeof(union ospf_auth2
)) : sizeof(struct ospf_packet
); }
1069 static inline void * ospf_tx_buffer(struct ospf_iface
*ifa
)
1070 { return ifa
->sk
->tbuf
; }
1075 #define OHS_SHUTDOWN 2
1077 void ospf_send_hello(struct ospf_iface
*ifa
, int kind
, struct ospf_neighbor
*dirn
);
1078 void ospf_receive_hello(struct ospf_packet
*pkt
, struct ospf_iface
*ifa
, struct ospf_neighbor
*n
, ip_addr faddr
);
1079 uint
ospf_hello3_options(struct ospf_packet
*pkt
);
1082 void ospf_send_dbdes(struct ospf_proto
*p
, struct ospf_neighbor
*n
);
1083 void ospf_rxmt_dbdes(struct ospf_proto
*p
, struct ospf_neighbor
*n
);
1084 void ospf_reset_ldd(struct ospf_proto
*p
, struct ospf_neighbor
*n
);
1085 void ospf_receive_dbdes(struct ospf_packet
*pkt
, struct ospf_iface
*ifa
, struct ospf_neighbor
*n
);
1086 uint
ospf_dbdes3_options(struct ospf_packet
*pkt
);
1089 void ospf_send_lsreq(struct ospf_proto
*p
, struct ospf_neighbor
*n
);
1090 void ospf_receive_lsreq(struct ospf_packet
*pkt
, struct ospf_iface
*ifa
, struct ospf_neighbor
*n
);
1093 void ospf_dump_lsahdr(struct ospf_proto
*p
, struct ospf_lsa_header
*lsa_n
);
1094 void ospf_dump_common(struct ospf_proto
*p
, struct ospf_packet
*pkt
);
1095 void ospf_lsa_lsrt_down_(struct top_hash_entry
*en
, struct ospf_neighbor
*n
, struct top_hash_entry
*ret
);
1096 void ospf_add_flushed_to_lsrt(struct ospf_proto
*p
, struct ospf_neighbor
*n
);
1097 void ospf_flood_event(void *ptr
);
1098 int ospf_flood_lsa(struct ospf_proto
*p
, struct top_hash_entry
*en
, struct ospf_neighbor
*from
);
1099 int ospf_send_lsupd(struct ospf_proto
*p
, struct top_hash_entry
**lsa_list
, uint lsa_count
, struct ospf_neighbor
*n
);
1100 void ospf_rxmt_lsupd(struct ospf_proto
*p
, struct ospf_neighbor
*n
);
1101 void ospf_receive_lsupd(struct ospf_packet
*pkt
, struct ospf_iface
*ifa
, struct ospf_neighbor
*n
);
1104 void ospf_enqueue_lsack(struct ospf_neighbor
*n
, struct ospf_lsa_header
*h_n
, int queue
);
1105 void ospf_reset_lsack_queue(struct ospf_neighbor
*n
);
1106 void ospf_send_lsack(struct ospf_proto
*p
, struct ospf_neighbor
*n
, int queue
);
1107 void ospf_receive_lsack(struct ospf_packet
*pkt
, struct ospf_iface
*ifa
, struct ospf_neighbor
*n
);
1110 #include "proto/ospf/rt.h"
1111 #include "proto/ospf/topology.h"
1112 #include "proto/ospf/lsalib.h"
1114 #endif /* _BIRD_OSPF_H_ */