]>
git.ipfire.org Git - thirdparty/bird.git/blob - proto/ospf/ospf.h
4 * (c) 1999--2005 Ondrej Filip <feela@network.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
13 #define OSPF_MAX_PKT_SIZE 65535
15 * RFC 2328 says, maximum packet size is 65535 (IP packet size
16 * limit). Really a bit less for OSPF, because this contains also IP
17 * header. This could be too much for small systems, so I normally
18 * allocate 2*mtu (i found one cisco sending packets mtu+16). OSPF
19 * packets are almost always sent small enough to not be fragmented.
23 #define OSPF_FORCE_DEBUG 1
25 #define OSPF_FORCE_DEBUG 0
27 #define OSPF_TRACE(flags, msg, args...) do { if ((p->debug & flags) || OSPF_FORCE_DEBUG) \
28 log(L_TRACE "%s: " msg, p->name , ## args ); } while(0)
30 #define OSPF_PACKET(dumpfn, buffer, msg, args...) \
31 do { if ((p->debug & D_PACKETS) || OSPF_FORCE_DEBUG) \
32 { log(L_TRACE "%s: " msg, p->name, ## args ); dumpfn(p, buffer); } } while(0)
35 #include "nest/bird.h"
37 #include "lib/checksum.h"
39 #include "lib/lists.h"
40 #include "lib/slists.h"
41 #include "lib/socket.h"
42 #include "lib/timer.h"
43 #include "lib/resource.h"
44 #include "nest/protocol.h"
45 #include "nest/iface.h"
46 #include "nest/route.h"
48 #include "nest/locks.h"
49 #include "conf/conf.h"
50 #include "lib/string.h"
56 #define OSPF_VERSION 2
57 #define OSPF_VLINK_MTU 576 /* RFC 2328 A.1 */
58 #define AllSPFRouters ipa_from_u32(0xe0000005) /* 224.0.0.5 */
59 #define AllDRouters ipa_from_u32(0xe0000006) /* 224.0.0.6 */
62 #define OSPF_VERSION 3
63 #define OSPF_VLINK_MTU 1280 /* RFC 5340 A.1 */
64 #define AllSPFRouters _MI(0xFF020000, 0, 0, 5) /* FF02::5 */
65 #define AllDRouters _MI(0xFF020000, 0, 0, 6) /* FF02::6 */
69 #define LSREFRESHTIME 1800 /* 30 minutes */
70 #define MINLSINTERVAL 5
71 #define MINLSARRIVAL 1
72 #define LSINFINITY 0xffffff
74 #define DEFAULT_OSPFTICK 1
75 #define DEFAULT_RFC1583 0 /* compatibility with rfc1583 */
76 #define DEFAULT_STUB_COST 1000
77 #define DEFAULT_ECMP_LIMIT 16
78 #define DEFAULT_TRANSINT 40
83 struct proto_config c
;
89 list area_list
; /* list of struct ospf_area_config */
90 list vlink_list
; /* list of struct ospf_iface_patt */
101 struct area_net_config
118 struct ospf_stubnet_config
126 struct ospf_area_config
130 u32 default_cost
; /* Cost of default route for stub areas */
131 u8 type
; /* Area type (standard, stub, NSSA), represented
132 by option flags (OPT_E, OPT_N) */
133 u8 summary
; /* Import summaries to this stub/NSSA area, valid for ABR */
134 u8 default_nssa
; /* Generate default NSSA route for NSSA+summary area */
135 u8 translator
; /* Translator role, for NSSA ABR */
136 u32 transint
; /* Translator stability interval */
138 list net_list
; /* List of aggregate networks for that area */
139 list enet_list
; /* List of aggregate external (NSSA) networks */
140 list stubnet_list
; /* List of stub networks added to Router LSA */
151 #define OPT_P 0x08 /* flags P and N share position, see NSSA RFC */
154 /* VEB flags are are stored independently in 'u16 options' */
155 #define OPT_RT_B (0x01 << 8)
156 #define OPT_RT_E (0x02 << 8)
157 #define OPT_RT_V (0x04 << 8)
158 #define OPT_RT_NT (0x10 << 8)
165 /* VEB flags are are stored together with options in 'u32 options' */
166 #define OPT_RT_B (0x01 << 24)
167 #define OPT_RT_E (0x02 << 24)
168 #define OPT_RT_V (0x04 << 24)
169 #define OPT_RT_NT (0x10 << 24)
171 #define OPT_PX_NU 0x01
172 #define OPT_PX_LA 0x02
173 #define OPT_PX_P 0x08
174 #define OPT_PX_DN 0x10
181 struct iface
*iface
; /* Nest's iface, non-NULL (unless type OSPF_IT_VLINK) */
182 struct ifa
*addr
; /* IP prefix associated with that OSPF iface */
183 struct ospf_area
*oa
;
184 struct ospf_iface_patt
*cf
;
186 sock
*sk
; /* IP socket (for DD ...) */
187 list neigh_list
; /* List of neigbours */
188 u32 cost
; /* Cost of iface */
189 u32 waitint
; /* number of sec before changing state from wait */
190 u32 rxmtint
; /* number of seconds between LSA retransmissions */
191 u32 pollint
; /* Poll interval */
192 u32 deadint
; /* after "deadint" missing hellos is router dead */
193 u32 iface_id
; /* Interface ID (iface->index or new value for vlinks) */
194 u32 vid
; /* ID of peer of virtual link */
195 ip_addr vip
; /* IP of peer of virtual link */
196 struct ospf_iface
*vifa
; /* OSPF iface which the vlink goes through */
197 struct ospf_area
*voa
; /* OSPF area which the vlink goes through */
198 u16 inftransdelay
; /* The estimated number of seconds it takes to
199 transmit a Link State Update Packet over this
200 interface. LSAs contained in the update */
201 u16 helloint
; /* number of seconds between hello sending */
206 u32 csn
; /* Last used crypt seq number */
207 bird_clock_t csn_use
; /* Last time when packet with that CSN was sent */
210 ip_addr all_routers
; /* */
211 ip_addr drip
; /* Designated router */
212 ip_addr bdrip
; /* Backup DR */
215 s16 rt_pos_beg
; /* Position of iface in Router-LSA, begin, inclusive */
216 s16 rt_pos_end
; /* Position of iface in Router-LSA, end, exclusive */
219 s16 px_pos_beg
; /* Position of iface in Rt Prefix-LSA, begin, inclusive */
220 s16 px_pos_end
; /* Position of iface in Rt Prefix-LSA, end, exclusive */
222 u32 dr_iface_id
; /* if drid is valid, this is iface_id of DR (for connecting network) */
223 u8 instance_id
; /* Used to differentiate between more OSPF
224 instances on one interface */
227 u8 type
; /* OSPF view of type */
228 #define OSPF_IT_BCAST 0
229 #define OSPF_IT_NBMA 1
230 #define OSPF_IT_PTP 2
231 #define OSPF_IT_PTMP 3
232 #define OSPF_IT_VLINK 4
233 #define OSPF_IT_UNDEF 5
234 u8 strictnbma
; /* Can I talk with unknown neighbors? */
235 u8 stub
; /* Inactive interface */
236 u8 state
; /* Interface state machine */
237 #define OSPF_IS_DOWN 0 /* Not working */
238 #define OSPF_IS_LOOP 1 /* Iface with no link */
239 #define OSPF_IS_WAITING 2 /* Waiting for Wait timer */
240 #define OSPF_IS_PTP 3 /* PTP operational */
241 #define OSPF_IS_DROTHER 4 /* I'm on BCAST or NBMA and I'm not DR */
242 #define OSPF_IS_BACKUP 5 /* I'm BDR */
243 #define OSPF_IS_DR 6 /* I'm DR */
244 timer
*wait_timer
; /* WAIT timer */
245 timer
*hello_timer
; /* HELLOINT timer */
246 timer
*poll_timer
; /* Poll Interval - for NBMA */
247 /* Default values for interface parameters */
250 #define INFTRANSDELAY_D 1
252 #define HELLOINT_D 10
256 /* Value of Wait timer - not found it in RFC * - using 4*HELLO */
258 struct top_hash_entry
*net_lsa
; /* Originated network LSA */
259 int orignet
; /* Schedule network LSA origination */
261 int origlink
; /* Schedule link LSA origination */
262 struct top_hash_entry
*link_lsa
; /* Originated link LSA */
263 struct top_hash_entry
*pxn_lsa
; /* Originated prefix LSA */
265 int fadj
; /* Number of full adjacent neigh */
267 u8 priority
; /* A router priority for DR election */
269 #define OSPF_I_OK 0 /* Everything OK */
270 #define OSPF_I_SK 1 /* Socket open failed */
271 #define OSPF_I_LL 2 /* Missing link-local address (OSPFv3) */
272 u8 sk_dr
; /* Socket is a member of DRouters group */
273 u8 marked
; /* Used in OSPF reconfigure */
274 u16 rxbuf
; /* Buffer size */
275 u8 check_link
; /* Whether iface link change is used */
276 u8 ecmp_weight
; /* Weight used for ECMP */
277 u8 ptp_netmask
; /* Send real netmask for P2P */
296 #define HELLO_P 1 /* Hello */
297 #define DBDES_P 2 /* Database description */
298 #define LSREQ_P 3 /* Link state request */
299 #define LSUPD_P 4 /* Link state update */
300 #define LSACK_P 5 /* Link state acknowledgement */
308 #ifdef CPU_BIG_ENDIAN
346 #else /* OSPFv3 packet descriptions */
366 struct ospf_lsa_header
368 u16 age
; /* LS Age */
369 #define LSA_MAXAGE 3600 /* 1 hour */
370 #define LSA_CHECKAGE 300 /* 5 minutes */
371 #define LSA_MAXAGEDIFF 900 /* 15 minutes */
379 #define LSA_T_SUM_NET 3
380 #define LSA_T_SUM_RT 4
384 #define LSA_SCOPE_AREA 0x2000
385 #define LSA_SCOPE_AS 0x4000
387 #define LSA_SCOPE(lsa) (((lsa)->type == LSA_T_EXT) ? LSA_SCOPE_AS : LSA_SCOPE_AREA)
392 #define LSA_T_RT 0x2001
393 #define LSA_T_NET 0x2002
394 #define LSA_T_SUM_NET 0x2003
395 #define LSA_T_SUM_RT 0x2004
396 #define LSA_T_EXT 0x4005
397 #define LSA_T_NSSA 0x2007
398 #define LSA_T_LINK 0x0008
399 #define LSA_T_PREFIX 0x2009
401 #define LSA_UBIT 0x8000
403 #define LSA_SCOPE_LINK 0x0000
404 #define LSA_SCOPE_AREA 0x2000
405 #define LSA_SCOPE_AS 0x4000
406 #define LSA_SCOPE_RES 0x6000
407 #define LSA_SCOPE_MASK 0x6000
409 #define LSA_SCOPE(lsa) ((lsa)->type & LSA_SCOPE_MASK)
413 u32 rt
; /* Advertising router */
414 s32 sn
; /* LS Sequence number */
415 #define LSA_INITSEQNO ((s32) 0x80000001)
416 #define LSA_MAXSEQNO ((s32) 0x7fffffff)
432 #ifdef CPU_BIG_ENDIAN
433 u16 options
; /* VEB flags only */
437 u16 options
; /* VEB flags only */
441 struct ospf_lsa_rt_link
445 #ifdef CPU_BIG_ENDIAN
476 #define LSA_SUM_TOS 0xFF000000
477 #define LSA_EXT_TOS 0x7F000000
478 #define LSA_EXT_EBIT 0x80000000
480 /* Endianity swap for lsa->type */
492 struct ospf_lsa_rt_link
494 #ifdef CPU_BIG_ENDIAN
503 u32 lif
; /* Local interface ID */
504 u32 nif
; /* Neighbor interface ID */
505 u32 id
; /* Neighbor router ID */
514 struct ospf_lsa_sum_net
520 struct ospf_lsa_sum_rt
541 struct ospf_lsa_prefix
543 #ifdef CPU_BIG_ENDIAN
555 #define LSA_EXT_EBIT 0x4000000
556 #define LSA_EXT_FBIT 0x2000000
557 #define LSA_EXT_TBIT 0x1000000
559 /* Endianity swap for lsa->type */
560 #define ntoht(x) ntohs(x)
561 #define htont(x) htons(x)
565 #define METRIC_MASK 0x00FFFFFF
566 #define OPTIONS_MASK 0x00FFFFFF
568 static inline unsigned
569 lsa_rt_count(struct ospf_lsa_header
*lsa
)
571 return (lsa
->length
- sizeof(struct ospf_lsa_header
) - sizeof(struct ospf_lsa_rt
))
572 / sizeof(struct ospf_lsa_rt_link
);
575 static inline unsigned
576 lsa_net_count(struct ospf_lsa_header
*lsa
)
578 return (lsa
->length
- sizeof(struct ospf_lsa_header
) - sizeof(struct ospf_lsa_net
))
585 #define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4)
586 #define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32)
589 lsa_get_ipv6_prefix(u32
*buf
, ip_addr
*addr
, int *pxlen
, u8
*pxopts
, u16
*rest
)
591 u8 pxl
= (*buf
>> 24);
592 *pxopts
= (*buf
>> 16);
608 /* Clean up remaining bits */
610 addr
->addr
[pxl
/ 32] &= u32_mkmask(pxl
% 32);
616 lsa_get_ipv6_addr(u32
*buf
, ip_addr
*addr
)
618 *addr
= *(ip_addr
*) buf
;
623 put_ipv6_prefix(u32
*buf
, ip_addr addr
, u8 pxlen
, u8 pxopts
, u16 lh
)
625 *buf
++ = ((pxlen
<< 24) | (pxopts
<< 16) | lh
);
639 put_ipv6_addr(u32
*buf
, ip_addr addr
)
641 *(ip_addr
*) buf
= addr
;
649 struct ospf_lsreq_header
653 u32 rt
; /* Advertising router */
659 struct ospf_lsreq_header lsh
;
667 struct ospf_iface
*ifa
;
669 #define NEIGHBOR_DOWN 0
670 #define NEIGHBOR_ATTEMPT 1
671 #define NEIGHBOR_INIT 2
672 #define NEIGHBOR_2WAY 3
673 #define NEIGHBOR_EXSTART 4
674 #define NEIGHBOR_EXCHANGE 5
675 #define NEIGHBOR_LOADING 6
676 #define NEIGHBOR_FULL 7
677 timer
*inactim
; /* Inactivity timer */
678 union imms imms
; /* I, M, Master/slave received */
679 u32 dds
; /* DD Sequence number being sent */
680 u32 ddr
; /* last Dat Des packet received */
681 union imms myimms
; /* I, M Master/slave */
682 u32 rid
; /* Router ID */
683 ip_addr ip
; /* IP of it's interface */
684 u8 priority
; /* Priority */
685 u8 adj
; /* built adjacency? */
686 u32 options
; /* Options received */
688 /* dr and bdr store IP address in OSPFv2 and router ID in OSPFv3,
689 we use the same type to simplify handling */
690 u32 dr
; /* Neigbour's idea of DR */
691 u32 bdr
; /* Neigbour's idea of BDR */
694 u32 iface_id
; /* ID of Neighbour's iface connected to common network */
697 siterator dbsi
; /* Database summary list iterator */
698 slist lsrql
; /* Link state request */
699 struct top_graph
*lsrqh
; /* LSA graph */
701 slist lsrtl
; /* Link state retransmission list */
703 struct top_graph
*lsrth
;
704 void *ldbdes
; /* Last database description packet */
705 timer
*rxmt_timer
; /* RXMT timer */
707 #define ACKL_DIRECT 0
709 timer
*ackd_timer
; /* Delayed ack timer */
710 u32 csn
; /* Last received crypt seq number (for MD5) */
713 /* Definitions for interface state machine */
714 #define ISM_UP 0 /* Interface Up */
715 #define ISM_WAITF 1 /* Wait timer fired */
716 #define ISM_BACKS 2 /* Backup seen */
717 #define ISM_NEICH 3 /* Neighbor change */
718 #define ISM_LOOP 4 /* Link down */
719 #define ISM_UNLOOP 5 /* Link up */
720 #define ISM_DOWN 6 /* Interface down */
722 /* Definitions for neighbor state machine */
723 #define INM_HELLOREC 0 /* Hello Received */
724 #define INM_START 1 /* Neighbor start - for NBMA */
725 #define INM_2WAYREC 2 /* 2-Way received */
726 #define INM_NEGDONE 3 /* Negotiation done */
727 #define INM_EXDONE 4 /* Exchange done */
728 #define INM_BADLSREQ 5 /* Bad LS Request */
729 #define INM_LOADDONE 6 /* Load done */
730 #define INM_ADJOK 7 /* AdjOK? */
731 #define INM_SEQMIS 8 /* Sequence number mismatch */
732 #define INM_1WAYREC 9 /* 1-Way */
733 #define INM_KILLNBR 10 /* Kill Neighbor */
734 #define INM_INACTTIM 11 /* Inactivity timer */
735 #define INM_LLDOWN 12 /* Line down */
741 struct ospf_area_config
*ac
; /* Related area config */
742 struct top_hash_entry
*rt
; /* My own router LSA */
743 struct top_hash_entry
*pxr_lsa
; /* Originated prefix LSA */
744 list cand
; /* List of candidates for RT calc. */
745 struct fib net_fib
; /* Networks to advertise or not */
746 struct fib enet_fib
; /* External networks for NSSAs */
747 u32 options
; /* Optional features */
748 byte origrt
; /* Rt lsa origination scheduled? */
749 byte trcap
; /* Transit capability? */
750 byte marked
; /* Used in OSPF reconfigure */
751 byte translate
; /* Translator state (TRANS_*), for NSSA ABR */
752 timer
*translator_timer
; /* For NSSA translator switch */
753 struct proto_ospf
*po
;
754 struct fib rtr
; /* Routing tables for routers */
759 #define TRANS_WAIT 2 /* Waiting before the end of translation */
764 timer
*disp_timer
; /* OSPF proto dispatcher */
766 struct top_graph
*gr
; /* LSA graph */
767 slist lsal
; /* List of all LSA's */
768 int calcrt
; /* Routing table calculation scheduled?
769 0=no, 1=normal, 2=forced reload */
770 list iface_list
; /* Interfaces we really use */
772 int areano
; /* Number of area I belong to */
773 struct fib rtf
; /* Routing table */
774 byte rfc1583
; /* RFC1583 compatibility */
775 byte stub_router
; /* Do not forward transit traffic */
776 byte ebit
; /* Did I originate any ext lsa? */
777 byte ecmp
; /* Maximal number of nexthops in ECMP route, or 0 */
778 struct ospf_area
*backbone
; /* If exists */
779 void *lsab
; /* LSA buffer used when originating router LSAs */
780 int lsab_size
, lsab_used
;
781 linpool
*nhpool
; /* Linpool used for next hops computed in SPF */
783 u32 last_vlink_id
; /* Interface IDs for vlinks (starts at 0x80000000) */
786 struct ospf_iface_patt
806 #define OSPF_RXBUF_NORMAL 0
807 #define OSPF_RXBUF_LARGE 1
808 #define OSPF_RXBUF_MINSIZE 256 /* Minimal allowed size */
809 u16 autype
; /* Not really used in OSPFv3 */
810 #define OSPF_AUTH_NONE 0
811 #define OSPF_AUTH_SIMPLE 1
812 #define OSPF_AUTH_CRYPT 2
813 #define OSPF_AUTH_CRYPT_SIZE 16
817 u8 real_bcast
; /* Not really used in OSPFv3 */
818 u8 ptp_netmask
; /* bool but 2 for unspecified */
829 int ospf_import_control(struct proto
*p
, rte
**new, ea_list
**attrs
,
830 struct linpool
*pool
);
831 struct ea_list
*ospf_make_tmp_attrs(struct rte
*rt
, struct linpool
*pool
);
832 void ospf_store_tmp_attrs(struct rte
*rt
, struct ea_list
*attrs
);
833 void schedule_rt_lsa(struct ospf_area
*oa
);
834 void schedule_rtcalc(struct proto_ospf
*po
);
835 void schedule_net_lsa(struct ospf_iface
*ifa
);
837 struct ospf_area
*ospf_find_area(struct proto_ospf
*po
, u32 aid
);
838 static inline struct ospf_area
*ospf_main_area(struct proto_ospf
*po
)
839 { return (po
->areano
== 1) ? HEAD(po
->area_list
) : po
->backbone
; }
841 static inline int oa_is_stub(struct ospf_area
*oa
)
842 { return (oa
->options
& (OPT_E
| OPT_N
)) == 0; }
843 static inline int oa_is_ext(struct ospf_area
*oa
)
844 { return oa
->options
& OPT_E
; }
845 static inline int oa_is_nssa(struct ospf_area
*oa
)
846 { return oa
->options
& OPT_N
; }
850 void schedule_link_lsa(struct ospf_iface
*ifa
);
852 static inline void schedule_link_lsa(struct ospf_iface
*ifa UNUSED
) {}
855 void ospf_sh_neigh(struct proto
*p
, char *iff
);
856 void ospf_sh(struct proto
*p
);
857 void ospf_sh_iface(struct proto
*p
, char *iff
);
858 void ospf_sh_state(struct proto
*p
, int verbose
, int reachable
);
860 #define SH_ROUTER_SELF 0xffffffff
862 struct lsadb_show_data
{
863 struct symbol
*name
; /* Protocol to request data from */
864 u16 type
; /* LSA Type, 0 -> all */
865 u16 scope
; /* Scope, 0 -> all, hack to handle link scope as 1 */
866 u32 area
; /* Specified for area scope */
867 u32 lsid
; /* LSA ID, 0 -> all */
868 u32 router
; /* Advertising router, 0 -> all */
871 void ospf_sh_lsadb(struct lsadb_show_data
*ld
);
874 #define EA_OSPF_METRIC1 EA_CODE(EAP_OSPF, 0)
875 #define EA_OSPF_METRIC2 EA_CODE(EAP_OSPF, 1)
876 #define EA_OSPF_TAG EA_CODE(EAP_OSPF, 2)
877 #define EA_OSPF_ROUTER_ID EA_CODE(EAP_OSPF, 3)
879 #include "proto/ospf/rt.h"
880 #include "proto/ospf/hello.h"
881 #include "proto/ospf/packet.h"
882 #include "proto/ospf/iface.h"
883 #include "proto/ospf/neighbor.h"
884 #include "proto/ospf/topology.h"
885 #include "proto/ospf/dbdes.h"
886 #include "proto/ospf/lsreq.h"
887 #include "proto/ospf/lsupd.h"
888 #include "proto/ospf/lsack.h"
889 #include "proto/ospf/lsalib.h"
891 #endif /* _BIRD_OSPF_H_ */