]>
Commit | Line | Data |
---|---|---|
c1f8dc91 OF |
1 | /* |
2 | * BIRD -- OSPF | |
3 | * | |
e300066d | 4 | * (c) 1999--2005 Ondrej Filip <feela@network.cz> |
70945cb6 OZ |
5 | * (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org> |
6 | * (c) 2009--2014 CZ.NIC z.s.p.o. | |
c1f8dc91 OF |
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 | ||
4364b47e OF |
14 | #include "nest/bird.h" |
15 | ||
16 | #include "lib/checksum.h" | |
74c838a8 | 17 | #include "lib/idm.h" |
6ba36f06 | 18 | #include "lib/lists.h" |
30147b89 | 19 | #include "lib/slists.h" |
6ba36f06 | 20 | #include "lib/socket.h" |
a6f79ca5 | 21 | #include "lib/timer.h" |
6ba36f06 MM |
22 | #include "lib/resource.h" |
23 | #include "nest/protocol.h" | |
24 | #include "nest/iface.h" | |
4364b47e | 25 | #include "nest/route.h" |
a783e259 | 26 | #include "nest/cli.h" |
f8f1e1f1 | 27 | #include "nest/locks.h" |
1ec52253 | 28 | #include "nest/bfd.h" |
4364b47e | 29 | #include "conf/conf.h" |
d345cda5 | 30 | #include "lib/string.h" |
6ba36f06 | 31 | |
c3226991 | 32 | |
70945cb6 OZ |
33 | #ifdef LOCAL_DEBUG |
34 | #define OSPF_FORCE_DEBUG 1 | |
35 | #else | |
36 | #define OSPF_FORCE_DEBUG 0 | |
37 | #endif | |
38 | ||
39 | ||
70945cb6 | 40 | #define OSPF_TRACE(flags, msg, args...) \ |
f8fefde3 OZ |
41 | do { if ((p->p.debug & flags) || OSPF_FORCE_DEBUG) \ |
42 | log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0) | |
70945cb6 OZ |
43 | |
44 | #define OSPF_PACKET(dumpfn, buffer, msg, args...) \ | |
f8fefde3 OZ |
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) | |
47 | ||
48 | #define LOG_PKT(msg, args...) \ | |
49 | log_rl(&p->log_pkt_tbf, L_REMOTE "%s: " msg, p->p.name, args) | |
50 | ||
51 | #define LOG_PKT_AUTH(msg, args...) \ | |
52 | log_rl(&p->log_pkt_tbf, L_AUTH "%s: " msg, p->p.name, args) | |
53 | ||
54 | #define LOG_PKT_WARN(msg, args...) \ | |
55 | log_rl(&p->log_pkt_tbf, L_WARN "%s: " msg, p->p.name, args) | |
56 | ||
57 | #define LOG_LSA1(msg, args...) \ | |
58 | log_rl(&p->log_lsa_tbf, L_REMOTE "%s: " msg, p->p.name, args) | |
59 | ||
60 | #define LOG_LSA2(msg, args...) \ | |
574b2324 | 61 | do { if (! p->log_lsa_tbf.drop) \ |
f8fefde3 | 62 | log(L_REMOTE "%s: " msg, p->p.name, args); } while(0) |
70945cb6 OZ |
63 | |
64 | ||
65 | #define OSPF_PROTO 89 | |
15087574 | 66 | |
b32d557a OZ |
67 | #define LSREFRESHTIME 1800 /* 30 minutes */ |
68 | #define MINLSINTERVAL (5 S_) | |
69 | #define MINLSARRIVAL (1 S_) | |
70 | #define LSINFINITY 0xffffff | |
d631698e | 71 | |
4727d1db OZ |
72 | #define OSPF_PKT_TYPES 5 /* HELLO_P .. LSACK_P */ |
73 | #define OSPF3_CRYPTO_ID 1 /* OSPFv3 Cryptographic Protocol ID */ | |
74 | ||
70945cb6 OZ |
75 | #define OSPF_DEFAULT_TICK 1 |
76 | #define OSPF_DEFAULT_STUB_COST 1000 | |
77 | #define OSPF_DEFAULT_ECMP_LIMIT 16 | |
78 | #define OSPF_DEFAULT_TRANSINT 40 | |
79 | ||
80 | #define OSPF_MIN_PKT_SIZE 256 | |
81 | #define OSPF_MAX_PKT_SIZE 65535 | |
d631698e | 82 | |
48e5f32d OZ |
83 | #define OSPF_VLINK_ID_OFFSET 0x80000000 |
84 | ||
2e10a170 OF |
85 | struct ospf_config |
86 | { | |
c1f8dc91 | 87 | struct proto_config c; |
a7a7372a | 88 | uint tick; |
178a197a | 89 | u8 ospf2; |
d3f4f92b OZ |
90 | u8 af_ext; |
91 | u8 af_mc; | |
178a197a OZ |
92 | u8 rfc1583; |
93 | u8 stub_router; | |
94 | u8 merge_external; | |
95 | u8 instance_id; | |
d3f4f92b | 96 | u8 instance_id_set; |
178a197a OZ |
97 | u8 abr; |
98 | u8 asbr; | |
57c574d8 | 99 | int ecmp; |
a7a7372a OZ |
100 | list area_list; /* list of area configs (struct ospf_area_config) */ |
101 | list vlink_list; /* list of configured vlinks (struct ospf_iface_patt) */ | |
b36a0a79 OF |
102 | }; |
103 | ||
a7a7372a | 104 | struct ospf_area_config |
2e10a170 | 105 | { |
e5b5d18c | 106 | node n; |
a7a7372a OZ |
107 | u32 areaid; |
108 | u32 default_cost; /* Cost of default route for stub areas | |
109 | (With possible LSA_EXT3_EBIT for NSSA areas) */ | |
110 | u8 type; /* Area type (standard, stub, NSSA), represented | |
111 | by option flags (OPT_E, OPT_N) */ | |
112 | u8 summary; /* Import summaries to this stub/NSSA area, valid for ABR */ | |
113 | u8 default_nssa; /* Generate default NSSA route for NSSA+summary area */ | |
114 | u8 translator; /* Translator role, for NSSA ABR */ | |
115 | u32 transint; /* Translator stability interval */ | |
116 | list patt_list; /* List of iface configs (struct ospf_iface_patt) */ | |
742029eb OZ |
117 | list net_list; /* List of aggregate networks for that area */ |
118 | list enet_list; /* List of aggregate external (NSSA) networks */ | |
a7a7372a | 119 | list stubnet_list; /* List of stub networks added to Router LSA */ |
e5b5d18c OF |
120 | }; |
121 | ||
98ac6176 | 122 | struct area_net_config |
2e10a170 | 123 | { |
c926eee7 | 124 | node n; |
d44e686e | 125 | net_addr prefix; |
ed317862 | 126 | u32 tag; |
70945cb6 | 127 | u8 hidden; |
98ac6176 OF |
128 | }; |
129 | ||
130 | struct area_net | |
131 | { | |
70945cb6 | 132 | u32 metric; /* With possible LSA_EXT3_EBIT for NSSA area nets */ |
ed317862 | 133 | u32 tag; |
70945cb6 OZ |
134 | u8 hidden; |
135 | u8 active; | |
fe9f1a6d | 136 | struct fib_node fn; |
c926eee7 OF |
137 | }; |
138 | ||
38675202 OZ |
139 | struct ospf_stubnet_config |
140 | { | |
141 | node n; | |
d44e686e | 142 | net_addr prefix; |
38675202 | 143 | u32 cost; |
70945cb6 OZ |
144 | u8 hidden; |
145 | u8 summary; | |
38675202 OZ |
146 | }; |
147 | ||
a7a7372a | 148 | struct nbma_node |
2e10a170 | 149 | { |
b36a0a79 | 150 | node n; |
a7a7372a OZ |
151 | ip_addr ip; |
152 | byte eligible; | |
742029eb | 153 | byte found; |
c1f8dc91 OF |
154 | }; |
155 | ||
a7a7372a OZ |
156 | struct ospf_iface_patt |
157 | { | |
158 | struct iface_patt i; | |
159 | u32 type; | |
160 | u32 stub; | |
161 | u32 cost; | |
162 | u32 helloint; | |
163 | u32 rxmtint; | |
164 | u32 pollint; | |
165 | u32 waitint; | |
166 | u32 deadc; | |
167 | u32 deadint; | |
168 | u32 inftransdelay; | |
169 | list nbma_list; | |
170 | u32 priority; | |
171 | u32 voa; | |
172 | u32 vid; | |
173 | int tx_tos; | |
174 | int tx_priority; | |
175 | u16 tx_length; | |
176 | u16 rx_buffer; | |
a7a7372a OZ |
177 | #define OSPF_RXBUF_MINSIZE 256 /* Minimal allowed size */ |
178 | u8 instance_id; | |
d3f4f92b | 179 | u8 instance_id_set; |
29239ba2 | 180 | u8 autype; /* OSPF_AUTH_*, not really used in OSPFv3 */ |
a7a7372a OZ |
181 | u8 strictnbma; |
182 | u8 check_link; | |
183 | u8 ecmp_weight; | |
184 | u8 link_lsa_suppression; | |
185 | u8 real_bcast; /* Not really used in OSPFv3 */ | |
186 | u8 ptp_netmask; /* bool + 2 for unspecified */ | |
187 | u8 ttl_security; /* bool + 2 for TX only */ | |
188 | u8 bfd; | |
a7a7372a OZ |
189 | list *passwords; |
190 | }; | |
70945cb6 OZ |
191 | |
192 | /* Default values for interface parameters */ | |
193 | #define COST_D 10 | |
194 | #define RXMTINT_D 5 | |
195 | #define INFTRANSDELAY_D 1 | |
196 | #define PRIORITY_D 1 | |
197 | #define HELLOINT_D 10 | |
198 | #define POLLINT_D 20 | |
199 | #define DEADC_D 4 | |
742029eb | 200 | #define WAIT_DMH 4 |
70945cb6 | 201 | /* Value of Wait timer - not found it in RFC * - using 4*HELLO */ |
621ccdfe OF |
202 | |
203 | ||
a7a7372a OZ |
204 | |
205 | struct ospf_proto | |
206 | { | |
207 | struct proto p; | |
208 | timer *disp_timer; /* OSPF proto dispatcher */ | |
209 | uint tick; | |
210 | struct top_graph *gr; /* LSA graph */ | |
211 | slist lsal; /* List of all LSA's */ | |
212 | int calcrt; /* Routing table calculation scheduled? | |
213 | 0=no, 1=normal, 2=forced reload */ | |
214 | list iface_list; /* List of OSPF interfaces (struct ospf_iface) */ | |
215 | list area_list; /* List of OSPF areas (struct ospf_area) */ | |
216 | int areano; /* Number of area I belong to */ | |
217 | int padj; /* Number of neighbors in Exchange or Loading state */ | |
218 | struct fib rtf; /* Routing table */ | |
74c838a8 | 219 | struct idm idm; /* OSPFv3 LSA ID map */ |
d3f4f92b OZ |
220 | u8 ospf2; /* OSPF v2 or v3 */ |
221 | u8 af_ext; /* OSPFv3-AF extension */ | |
222 | u8 af_mc; /* OSPFv3-AF multicast */ | |
223 | u8 rfc1583; /* RFC1583 compatibility */ | |
224 | u8 stub_router; /* Do not forward transit traffic */ | |
225 | u8 merge_external; /* Should i merge external routes? */ | |
5a50a989 | 226 | u8 instance_id; /* Differentiate between more OSPF instances */ |
d3f4f92b OZ |
227 | u8 asbr; /* May i originate any ext/NSSA lsa? */ |
228 | u8 ecmp; /* Maximal number of nexthops in ECMP route, or 0 */ | |
4727d1db | 229 | u64 csn64; /* Last used cryptographic sequence number */ |
a7a7372a | 230 | struct ospf_area *backbone; /* If exists */ |
6f8bbaa1 | 231 | event *flood_event; /* Event for flooding LS updates */ |
a7a7372a OZ |
232 | void *lsab; /* LSA buffer used when originating router LSAs */ |
233 | int lsab_size, lsab_used; | |
234 | linpool *nhpool; /* Linpool used for next hops computed in SPF */ | |
235 | sock *vlink_sk; /* IP socket used for vlink TX */ | |
236 | u32 router_id; | |
237 | u32 last_vlink_id; /* Interface IDs for vlinks (starts at 0x80000000) */ | |
f8fefde3 OZ |
238 | struct tbf log_pkt_tbf; /* TBF for packet messages */ |
239 | struct tbf log_lsa_tbf; /* TBF for LSA messages */ | |
a7a7372a OZ |
240 | }; |
241 | ||
242 | struct ospf_area | |
243 | { | |
244 | node n; | |
245 | u32 areaid; | |
246 | struct ospf_area_config *ac; /* Related area config */ | |
247 | struct top_hash_entry *rt; /* My own router LSA */ | |
248 | struct top_hash_entry *pxr_lsa; /* Originated prefix LSA */ | |
249 | list cand; /* List of candidates for RT calc. */ | |
250 | struct fib net_fib; /* Networks to advertise or not */ | |
251 | struct fib enet_fib; /* External networks for NSSAs */ | |
252 | u32 options; /* Optional features */ | |
253 | u8 update_rt_lsa; /* Rt lsa origination scheduled? */ | |
254 | u8 trcap; /* Transit capability? */ | |
255 | u8 marked; /* Used in OSPF reconfigure */ | |
256 | u8 translate; /* Translator state (TRANS_*), for NSSA ABR */ | |
257 | timer *translator_timer; /* For NSSA translator switch */ | |
258 | struct ospf_proto *po; | |
259 | struct fib rtr; /* Routing tables for routers */ | |
260 | }; | |
261 | ||
2e10a170 OF |
262 | struct ospf_iface |
263 | { | |
b11d8a4f | 264 | node n; |
48e5f32d | 265 | struct iface *iface; /* Nest's iface (NULL for vlinks) */ |
48cff379 | 266 | struct ifa *addr; /* IP prefix associated with that OSPF iface */ |
30147b89 | 267 | struct ospf_area *oa; |
8e48831a | 268 | struct ospf_iface_patt *cf; |
48e5f32d OZ |
269 | char *ifname; /* Interface name (iface->name), new one for vlinks */ |
270 | ||
d9e7e1b1 | 271 | pool *pool; |
48e5f32d | 272 | sock *sk; /* IP socket */ |
f8fefde3 | 273 | list neigh_list; /* List of neighbors (struct ospf_neighbor) */ |
9912fa51 | 274 | u32 cost; /* Cost of iface */ |
cc881bd1 OZ |
275 | u32 waitint; /* Number of seconds before changing state from wait */ |
276 | u32 rxmtint; /* Number of seconds between LSA retransmissions */ | |
277 | u32 pollint; /* Poll interval in seconds */ | |
278 | u32 deadint; /* After deadint seconds without hellos is router dead */ | |
dd4da6f6 OZ |
279 | u32 iface_id; /* Interface ID (iface->index or new value for vlinks) */ |
280 | u32 vid; /* ID of peer of virtual link */ | |
98ac6176 | 281 | ip_addr vip; /* IP of peer of virtual link */ |
0aad2b92 OZ |
282 | struct ospf_iface *vifa; /* OSPF iface which the vlink goes through */ |
283 | struct ospf_area *voa; /* OSPF area which the vlink goes through */ | |
9912fa51 OF |
284 | u16 inftransdelay; /* The estimated number of seconds it takes to |
285 | transmit a Link State Update Packet over this | |
286 | interface. LSAs contained in the update */ | |
621ccdfe | 287 | u16 helloint; /* number of seconds between hello sending */ |
3e2bd0f1 | 288 | list *passwords; |
b32d557a OZ |
289 | u32 csn; /* Last used crypt seq number */ |
290 | btime csn_use; /* Last time when packet with that CSN was sent */ | |
70945cb6 OZ |
291 | ip_addr all_routers; /* Multicast (or broadcast) address for all routers */ |
292 | ip_addr des_routers; /* Multicast (or NULL) address for designated routers */ | |
293 | ip_addr drip; /* Designated router IP */ | |
294 | ip_addr bdrip; /* Backup DR IP */ | |
295 | u32 drid; /* DR Router ID */ | |
296 | u32 bdrid; /* BDR Router ID */ | |
e7b4948c OZ |
297 | s16 rt_pos_beg; /* Position of iface in Router-LSA, begin, inclusive */ |
298 | s16 rt_pos_end; /* Position of iface in Router-LSA, end, exclusive */ | |
e7b4948c OZ |
299 | s16 px_pos_beg; /* Position of iface in Rt Prefix-LSA, begin, inclusive */ |
300 | s16 px_pos_end; /* Position of iface in Rt Prefix-LSA, end, exclusive */ | |
c3226991 OZ |
301 | u32 dr_iface_id; /* if drid is valid, this is iface_id of DR (for connecting network) */ |
302 | u8 instance_id; /* Used to differentiate between more OSPF | |
303 | instances on one interface */ | |
70945cb6 OZ |
304 | u8 autype; /* Authentication type (OSPF_AUTH_*) */ |
305 | u8 type; /* OSPF view of type (OSPF_IT_*) */ | |
2e10a170 OF |
306 | u8 strictnbma; /* Can I talk with unknown neighbors? */ |
307 | u8 stub; /* Inactive interface */ | |
70945cb6 | 308 | u8 state; /* Interface state machine (OSPF_IS_*) */ |
65112dd2 OF |
309 | timer *wait_timer; /* WAIT timer */ |
310 | timer *hello_timer; /* HELLOINT timer */ | |
a190e720 | 311 | timer *poll_timer; /* Poll Interval - for NBMA */ |
c3226991 | 312 | |
be862406 | 313 | struct top_hash_entry *link_lsa; /* Originated link LSA */ |
70945cb6 | 314 | struct top_hash_entry *net_lsa; /* Originated network LSA */ |
c3226991 | 315 | struct top_hash_entry *pxn_lsa; /* Originated prefix LSA */ |
6f8bbaa1 | 316 | struct top_hash_entry **flood_queue; /* LSAs queued for LSUPD */ |
70945cb6 OZ |
317 | u8 update_link_lsa; |
318 | u8 update_net_lsa; | |
6f8bbaa1 OZ |
319 | u16 flood_queue_used; /* The current number of LSAs in flood_queue */ |
320 | u16 flood_queue_size; /* The maximum number of LSAs in flood_queue */ | |
70945cb6 | 321 | int fadj; /* Number of fully adjacent neighbors */ |
e5b5d18c | 322 | list nbma_list; |
353729f5 | 323 | u8 priority; /* A router priority for DR election */ |
621ccdfe | 324 | u8 ioprob; |
0aad2b92 OZ |
325 | #define OSPF_I_OK 0 /* Everything OK */ |
326 | #define OSPF_I_SK 1 /* Socket open failed */ | |
327 | #define OSPF_I_LL 2 /* Missing link-local address (OSPFv3) */ | |
742029eb | 328 | u8 sk_dr; /* Socket is a member of designated routers group */ |
70945cb6 | 329 | u8 marked; /* Used in OSPF reconfigure, 2 for force restart */ |
d9e7e1b1 | 330 | u16 rxbuf; /* Buffer size */ |
48e5f32d | 331 | u16 tx_length; /* Soft TX packet length limit, usually MTU */ |
29239ba2 | 332 | u16 tx_hdrlen; /* Expected packet header length, less than tx_length */ |
391931d4 | 333 | u8 check_link; /* Whether iface link change is used */ |
57c574d8 | 334 | u8 ecmp_weight; /* Weight used for ECMP */ |
70945cb6 | 335 | u8 link_lsa_suppression; /* Suppression of Link-LSA origination */ |
8df02847 | 336 | u8 ptp_netmask; /* Send real netmask for P2P */ |
70e212f9 | 337 | u8 check_ttl; /* Check incoming packets for TTL 255 */ |
1ec52253 | 338 | u8 bfd; /* Use BFD on iface */ |
5b1a92e6 OF |
339 | }; |
340 | ||
a7a7372a OZ |
341 | struct ospf_neighbor |
342 | { | |
343 | node n; | |
344 | pool *pool; | |
345 | struct ospf_iface *ifa; | |
346 | u8 state; | |
347 | timer *inactim; /* Inactivity timer */ | |
348 | u8 imms; /* I, M, Master/slave received */ | |
349 | u8 myimms; /* I, M Master/slave */ | |
350 | u32 dds; /* DD Sequence number being sent */ | |
351 | u32 ddr; /* last Dat Des packet received */ | |
352 | ||
353 | u32 rid; /* Router ID */ | |
354 | ip_addr ip; /* IP of it's interface */ | |
355 | u8 priority; /* Priority */ | |
a7a7372a OZ |
356 | u32 options; /* Options received */ |
357 | ||
358 | /* Entries dr and bdr store IP addresses in OSPFv2 and router IDs in | |
359 | OSPFv3, we use the same type to simplify handling */ | |
f8fefde3 OZ |
360 | u32 dr; /* Neighbor's idea of DR */ |
361 | u32 bdr; /* Neighbor's idea of BDR */ | |
a7a7372a OZ |
362 | u32 iface_id; /* ID of Neighbour's iface connected to common network */ |
363 | ||
364 | /* Database summary list iterator, controls initial dbdes exchange. | |
365 | * Advances in the LSA list as dbdes packets are sent. | |
366 | */ | |
367 | siterator dbsi; /* iterator of po->lsal */ | |
368 | ||
369 | /* Link state request list, controls initial LSA exchange. | |
370 | * Entries added when received in dbdes packets, removed as sent in lsreq packets. | |
371 | */ | |
372 | slist lsrql; /* slist of struct top_hash_entry from n->lsrqh */ | |
373 | struct top_graph *lsrqh; | |
6f8bbaa1 | 374 | struct top_hash_entry *lsrqi; /* Pointer to the first unsent node in lsrql */ |
a7a7372a OZ |
375 | |
376 | /* Link state retransmission list, controls LSA retransmission during flood. | |
377 | * Entries added as sent in lsupd packets, removed when received in lsack packets. | |
378 | * These entries hold ret_count in appropriate LSA entries. | |
379 | */ | |
380 | slist lsrtl; /* slist of struct top_hash_entry from n->lsrth */ | |
381 | struct top_graph *lsrth; | |
6f8bbaa1 OZ |
382 | timer *dbdes_timer; /* DBDES exchange timer */ |
383 | timer *lsrq_timer; /* LSA request timer */ | |
384 | timer *lsrt_timer; /* LSA retransmission timer */ | |
a7a7372a OZ |
385 | list ackl[2]; |
386 | #define ACKL_DIRECT 0 | |
387 | #define ACKL_DELAY 1 | |
388 | timer *ackd_timer; /* Delayed ack timer */ | |
389 | struct bfd_request *bfd_req; /* BFD request, if BFD is used */ | |
390 | void *ldd_buffer; /* Last database description packet */ | |
391 | u32 ldd_bsize; /* Buffer size for ldd_buffer */ | |
4727d1db OZ |
392 | u32 csn; /* OSPFv2: Last received crypt seq number */ |
393 | u64 csn64[OSPF_PKT_TYPES]; /* OSPFv3: Last received CSN for each type of packet */ | |
a7a7372a OZ |
394 | }; |
395 | ||
396 | ||
397 | /* OSPF interface types */ | |
398 | #define OSPF_IT_BCAST 0 | |
399 | #define OSPF_IT_NBMA 1 | |
400 | #define OSPF_IT_PTP 2 | |
401 | #define OSPF_IT_PTMP 3 | |
402 | #define OSPF_IT_VLINK 4 | |
403 | #define OSPF_IT_UNDEF 5 | |
404 | ||
405 | /* OSPF interface states */ | |
406 | #define OSPF_IS_DOWN 0 /* Not active */ | |
407 | #define OSPF_IS_LOOP 1 /* Iface with no link */ | |
408 | #define OSPF_IS_WAITING 2 /* Waiting for Wait timer */ | |
409 | #define OSPF_IS_PTP 3 /* PTP operational */ | |
410 | #define OSPF_IS_DROTHER 4 /* I'm on BCAST or NBMA and I'm not DR */ | |
411 | #define OSPF_IS_BACKUP 5 /* I'm BDR */ | |
412 | #define OSPF_IS_DR 6 /* I'm DR */ | |
413 | ||
414 | /* Definitions for interface state machine */ | |
415 | #define ISM_UP 0 /* Interface Up */ | |
416 | #define ISM_WAITF 1 /* Wait timer fired */ | |
417 | #define ISM_BACKS 2 /* Backup seen */ | |
418 | #define ISM_NEICH 3 /* Neighbor change */ | |
419 | #define ISM_LOOP 4 /* Link down */ | |
420 | #define ISM_UNLOOP 5 /* Link up */ | |
421 | #define ISM_DOWN 6 /* Interface down */ | |
422 | ||
29239ba2 OZ |
423 | /* OSPF authentication types */ |
424 | #define OSPF_AUTH_NONE 0 | |
425 | #define OSPF_AUTH_SIMPLE 1 | |
426 | #define OSPF_AUTH_CRYPT 2 | |
427 | ||
4727d1db | 428 | #define OSPF3_AUTH_HMAC 1 /* HMAC Cryptographic Authentication */ |
a7a7372a OZ |
429 | |
430 | /* OSPF neighbor states */ | |
431 | #define NEIGHBOR_DOWN 0 | |
432 | #define NEIGHBOR_ATTEMPT 1 | |
433 | #define NEIGHBOR_INIT 2 | |
434 | #define NEIGHBOR_2WAY 3 | |
435 | #define NEIGHBOR_EXSTART 4 | |
436 | #define NEIGHBOR_EXCHANGE 5 | |
437 | #define NEIGHBOR_LOADING 6 | |
438 | #define NEIGHBOR_FULL 7 | |
439 | ||
440 | /* Definitions for neighbor state machine */ | |
441 | #define INM_HELLOREC 0 /* Hello Received */ | |
442 | #define INM_START 1 /* Neighbor start - for NBMA */ | |
443 | #define INM_2WAYREC 2 /* 2-Way received */ | |
444 | #define INM_NEGDONE 3 /* Negotiation done */ | |
445 | #define INM_EXDONE 4 /* Exchange done */ | |
446 | #define INM_BADLSREQ 5 /* Bad LS Request */ | |
447 | #define INM_LOADDONE 6 /* Load done */ | |
448 | #define INM_ADJOK 7 /* AdjOK? */ | |
449 | #define INM_SEQMIS 8 /* Sequence number mismatch */ | |
450 | #define INM_1WAYREC 9 /* 1-Way */ | |
451 | #define INM_KILLNBR 10 /* Kill Neighbor */ | |
452 | #define INM_INACTTIM 11 /* Inactivity timer */ | |
453 | #define INM_LLDOWN 12 /* Line down */ | |
454 | ||
455 | #define TRANS_OFF 0 | |
456 | #define TRANS_ON 1 | |
457 | #define TRANS_WAIT 2 /* Waiting before the end of translation */ | |
458 | ||
459 | ||
a7a7372a | 460 | /* Generic option flags */ |
d3f4f92b OZ |
461 | #define OPT_V6 0x0001 /* OSPFv3, LSA relevant for IPv6 routing calculation */ |
462 | #define OPT_E 0x0002 /* Related to AS-external LSAs */ | |
463 | #define OPT_MC 0x0004 /* Related to MOSPF, not used and obsolete */ | |
464 | #define OPT_N 0x0008 /* Related to NSSA */ | |
465 | #define OPT_P 0x0008 /* OSPFv2, flags P and N share position, see NSSA RFC */ | |
4727d1db | 466 | #define OPT_L_V2 0x0010 /* OSPFv2, link-local signaling, not used */ |
d3f4f92b OZ |
467 | #define OPT_R 0x0010 /* OSPFv3, originator is active router */ |
468 | #define OPT_DC 0x0020 /* Related to demand circuits, not used */ | |
5a50a989 | 469 | #define OPT_O 0x0040 /* OSPFv2 Opaque LSA (RFC 5250) */ |
d3f4f92b | 470 | #define OPT_AF 0x0100 /* OSPFv3 Address Families (RFC 5838) */ |
4727d1db OZ |
471 | #define OPT_L_V3 0x0200 /* OSPFv3, link-local signaling */ |
472 | #define OPT_AT 0x0400 /* OSPFv3, authentication trailer */ | |
a7a7372a OZ |
473 | |
474 | /* Router-LSA VEB flags are are stored together with links (OSPFv2) or options (OSPFv3) */ | |
475 | #define OPT_RT_B (0x01 << 24) | |
476 | #define OPT_RT_E (0x02 << 24) | |
477 | #define OPT_RT_V (0x04 << 24) | |
478 | #define OPT_RT_NT (0x10 << 24) | |
479 | ||
480 | /* Prefix flags, specific for OSPFv3 */ | |
481 | #define OPT_PX_NU 0x01 | |
482 | #define OPT_PX_LA 0x02 | |
483 | #define OPT_PX_P 0x08 | |
484 | #define OPT_PX_DN 0x10 | |
485 | ||
486 | ||
487 | struct ospf_packet | |
488 | { | |
489 | u8 version; | |
490 | u8 type; | |
491 | u16 length; | |
492 | u32 routerid; | |
493 | u32 areaid; | |
494 | u16 checksum; | |
495 | u8 instance_id; /* See RFC 6549 */ | |
496 | u8 autype; /* Undefined for OSPFv3 */ | |
497 | }; | |
498 | ||
4727d1db OZ |
499 | struct ospf_lls |
500 | { | |
501 | u16 checksum; | |
502 | u16 length; | |
503 | byte data[0]; | |
504 | }; | |
505 | ||
29239ba2 | 506 | struct ospf_auth_crypto |
3e2bd0f1 OF |
507 | { |
508 | u16 zero; | |
509 | u8 keyid; | |
510 | u8 len; | |
4727d1db | 511 | u32 csn; /* Cryptographic sequence number (32-bit) */ |
3e2bd0f1 OF |
512 | }; |
513 | ||
4727d1db | 514 | union ospf_auth2 |
3e2bd0f1 OF |
515 | { |
516 | u8 password[8]; | |
29239ba2 | 517 | struct ospf_auth_crypto c32; |
3e2bd0f1 OF |
518 | }; |
519 | ||
4727d1db OZ |
520 | struct ospf_auth3 |
521 | { | |
522 | u16 type; /* Authentication type (OSPF3_AUTH_*) */ | |
523 | u16 length; /* Authentication trailer length (header + data) */ | |
524 | u16 reserved; | |
525 | u16 sa_id; /* Security association identifier (key_id) */ | |
526 | u64 csn; /* Cryptographic sequence number (64-bit) */ | |
527 | byte data[0]; /* Authentication data */ | |
528 | }; | |
529 | ||
530 | ||
c3226991 | 531 | /* Packet types */ |
70945cb6 OZ |
532 | #define HELLO_P 1 /* Hello */ |
533 | #define DBDES_P 2 /* Database description */ | |
534 | #define LSREQ_P 3 /* Link state request */ | |
535 | #define LSUPD_P 4 /* Link state update */ | |
536 | #define LSACK_P 5 /* Link state acknowledgement */ | |
c3226991 | 537 | |
c3226991 | 538 | |
70945cb6 OZ |
539 | #define DBDES_I 4 /* Init bit */ |
540 | #define DBDES_M 2 /* More bit */ | |
541 | #define DBDES_MS 1 /* Master/Slave bit */ | |
542 | #define DBDES_IMMS (DBDES_I | DBDES_M | DBDES_MS) | |
c3226991 | 543 | |
c3226991 | 544 | |
5a50a989 OZ |
545 | /* OSPFv3 LSA Types / LSA Function Codes */ |
546 | /* https://www.iana.org/assignments/ospfv3-parameters/ospfv3-parameters.xhtml#ospfv3-parameters-3 */ | |
547 | #define LSA_T_RT 0x2001 | |
548 | #define LSA_T_NET 0x2002 | |
549 | #define LSA_T_SUM_NET 0x2003 | |
550 | #define LSA_T_SUM_RT 0x2004 | |
551 | #define LSA_T_EXT 0x4005 | |
552 | #define LSA_T_NSSA 0x2007 | |
553 | #define LSA_T_LINK 0x0008 | |
554 | #define LSA_T_PREFIX 0x2009 | |
555 | #define LSA_T_RI_ 0x000C | |
556 | #define LSA_T_RI_LINK 0x800C | |
557 | #define LSA_T_RI_AREA 0xA00C | |
558 | #define LSA_T_RI_AS 0xC00C | |
559 | #define LSA_T_OPAQUE_ 0x1FFF | |
560 | #define LSA_T_OPAQUE_LINK 0x9FFF | |
561 | #define LSA_T_OPAQUE_AREA 0xBFFF | |
562 | #define LSA_T_OPAQUE_AS 0xDFFF | |
563 | ||
564 | #define LSA_T_V2_OPAQUE_ 0x0009 | |
565 | #define LSA_T_V2_MASK 0x00ff | |
566 | ||
567 | /* OSPFv2 Opaque LSA Types */ | |
568 | /* https://www.iana.org/assignments/ospf-opaque-types/ospf-opaque-types.xhtml#ospf-opaque-types-2 */ | |
569 | #define LSA_OT_RI 0x04 | |
570 | ||
571 | #define LSA_FUNCTION_MASK 0x1FFF | |
572 | #define LSA_FUNCTION(type) ((type) & LSA_FUNCTION_MASK) | |
573 | ||
574 | #define LSA_UBIT 0x8000 | |
575 | ||
576 | #define LSA_SCOPE_LINK 0x0000 | |
577 | #define LSA_SCOPE_AREA 0x2000 | |
578 | #define LSA_SCOPE_AS 0x4000 | |
579 | #define LSA_SCOPE_RES 0x6000 | |
580 | #define LSA_SCOPE_MASK 0x6000 | |
581 | #define LSA_SCOPE(type) ((type) & LSA_SCOPE_MASK) | |
582 | #define LSA_SCOPE_ORDER(type) (((type) >> 13) & 0x3) | |
c3226991 | 583 | |
70945cb6 OZ |
584 | |
585 | #define LSA_MAXAGE 3600 /* 1 hour */ | |
586 | #define LSA_CHECKAGE 300 /* 5 minutes */ | |
587 | #define LSA_MAXAGEDIFF 900 /* 15 minutes */ | |
588 | ||
589 | #define LSA_ZEROSEQNO ((s32) 0x80000000) | |
590 | #define LSA_INITSEQNO ((s32) 0x80000001) | |
591 | #define LSA_MAXSEQNO ((s32) 0x7fffffff) | |
592 | ||
593 | #define LSA_METRIC_MASK 0x00FFFFFF | |
594 | #define LSA_OPTIONS_MASK 0x00FFFFFF | |
595 | ||
596 | ||
597 | #define LSART_PTP 1 | |
598 | #define LSART_NET 2 | |
599 | #define LSART_STUB 3 | |
600 | #define LSART_VLNK 4 | |
601 | ||
602 | #define LSA_RT2_LINKS 0x0000FFFF | |
603 | ||
604 | #define LSA_SUM2_TOS 0xFF000000 | |
605 | ||
606 | #define LSA_EXT2_TOS 0x7F000000 | |
607 | #define LSA_EXT2_EBIT 0x80000000 | |
608 | ||
5a50a989 OZ |
609 | #define LSA_EXT3_EBIT 0x04000000 |
610 | #define LSA_EXT3_FBIT 0x02000000 | |
611 | #define LSA_EXT3_TBIT 0x01000000 | |
612 | ||
613 | /* OSPF Router Information (RI) TLVs */ | |
614 | /* https://www.iana.org/assignments/ospf-parameters/ospf-parameters.xhtml#ri-tlv */ | |
615 | #define LSA_RI_RIC 1 | |
616 | #define LSA_RI_RFC 2 | |
617 | ||
618 | /* OSPF Router Informational Capability Bits */ | |
619 | /* https://www.iana.org/assignments/ospf-parameters/ospf-parameters.xhtml#router-informational-capability */ | |
620 | #define LSA_RIC_GR_CAPABLE 0 | |
621 | #define LSA_RIC_GR_HELPER 1 | |
622 | #define LSA_RIC_STUB_ROUTER 2 | |
70945cb6 OZ |
623 | |
624 | ||
625 | struct ospf_lsa_header | |
626 | { | |
627 | u16 age; /* LS Age */ | |
628 | u16 type_raw; /* Type, mixed with options on OSPFv2 */ | |
c3226991 | 629 | |
ce17d4c1 | 630 | u32 id; |
2e10a170 OF |
631 | u32 rt; /* Advertising router */ |
632 | s32 sn; /* LS Sequence number */ | |
2c1d1cc7 | 633 | u16 checksum; |
2e10a170 | 634 | u16 length; |
ce17d4c1 OF |
635 | }; |
636 | ||
fdb19982 | 637 | |
70945cb6 OZ |
638 | /* In OSPFv2, options are embedded in higher half of type_raw */ |
639 | static inline u8 lsa_get_options(struct ospf_lsa_header *lsa) | |
640 | { return lsa->type_raw >> 8; } | |
c3226991 | 641 | |
70945cb6 OZ |
642 | static inline void lsa_set_options(struct ospf_lsa_header *lsa, u16 options) |
643 | { lsa->type_raw = (lsa->type_raw & 0xff) | (options << 8); } | |
c3226991 | 644 | |
fdb19982 | 645 | |
2e10a170 OF |
646 | struct ospf_lsa_rt |
647 | { | |
70945cb6 | 648 | u32 options; /* VEB flags, mixed with link count for OSPFv2 and options for OSPFv3 */ |
ce17d4c1 OF |
649 | }; |
650 | ||
70945cb6 | 651 | struct ospf_lsa_rt2_link |
2e10a170 | 652 | { |
ce17d4c1 OF |
653 | u32 id; |
654 | u32 data; | |
c15e5690 | 655 | #ifdef CPU_BIG_ENDIAN |
ce17d4c1 | 656 | u8 type; |
70945cb6 | 657 | u8 no_tos; |
ce17d4c1 | 658 | u16 metric; |
c15e5690 OZ |
659 | #else |
660 | u16 metric; | |
70945cb6 | 661 | u8 no_tos; |
c15e5690 OZ |
662 | u8 type; |
663 | #endif | |
ce17d4c1 OF |
664 | }; |
665 | ||
70945cb6 | 666 | struct ospf_lsa_rt2_tos |
c3226991 | 667 | { |
70945cb6 OZ |
668 | #ifdef CPU_BIG_ENDIAN |
669 | u8 tos; | |
670 | u8 padding; | |
671 | u16 metric; | |
672 | #else | |
673 | u16 metric; | |
674 | u8 padding; | |
675 | u8 tos; | |
676 | #endif | |
c3226991 OZ |
677 | }; |
678 | ||
70945cb6 | 679 | struct ospf_lsa_rt3_link |
c3226991 | 680 | { |
c15e5690 | 681 | #ifdef CPU_BIG_ENDIAN |
c3226991 | 682 | u8 type; |
ce17d4c1 OF |
683 | u8 padding; |
684 | u16 metric; | |
c15e5690 OZ |
685 | #else |
686 | u16 metric; | |
687 | u8 padding; | |
688 | u8 type; | |
689 | #endif | |
c3226991 OZ |
690 | u32 lif; /* Local interface ID */ |
691 | u32 nif; /* Neighbor interface ID */ | |
692 | u32 id; /* Neighbor router ID */ | |
2c1d1cc7 OF |
693 | }; |
694 | ||
70945cb6 | 695 | |
2e10a170 OF |
696 | struct ospf_lsa_net |
697 | { | |
70945cb6 | 698 | u32 optx; /* Netmask for OSPFv2, options for OSPFv3 */ |
c3226991 | 699 | u32 routers[]; |
dfa9a53a OF |
700 | }; |
701 | ||
70945cb6 OZ |
702 | struct ospf_lsa_sum2 |
703 | { | |
704 | u32 netmask; | |
705 | u32 metric; | |
706 | }; | |
707 | ||
708 | struct ospf_lsa_sum3_net | |
2e10a170 | 709 | { |
c3226991 OZ |
710 | u32 metric; |
711 | u32 prefix[]; | |
ce17d4c1 OF |
712 | }; |
713 | ||
70945cb6 | 714 | struct ospf_lsa_sum3_rt |
c3226991 OZ |
715 | { |
716 | u32 options; | |
717 | u32 metric; | |
718 | u32 drid; | |
719 | }; | |
98ac6176 | 720 | |
70945cb6 OZ |
721 | struct ospf_lsa_ext2 |
722 | { | |
723 | u32 netmask; | |
724 | u32 metric; | |
725 | u32 fwaddr; | |
726 | u32 tag; | |
727 | }; | |
728 | ||
729 | struct ospf_lsa_ext3 | |
2e10a170 | 730 | { |
c3226991 OZ |
731 | u32 metric; |
732 | u32 rest[]; | |
733 | }; | |
734 | ||
70945cb6 OZ |
735 | struct ospf_lsa_ext_local |
736 | { | |
fe9f1a6d OZ |
737 | net_addr net; |
738 | ip_addr fwaddr; | |
70945cb6 OZ |
739 | u32 metric, ebit, fbit, tag, propagate; |
740 | u8 pxopts; | |
741 | }; | |
742 | ||
c3226991 OZ |
743 | struct ospf_lsa_link |
744 | { | |
745 | u32 options; | |
70945cb6 | 746 | ip6_addr lladdr; |
c3226991 OZ |
747 | u32 pxcount; |
748 | u32 rest[]; | |
749 | }; | |
750 | ||
751 | struct ospf_lsa_prefix | |
752 | { | |
c15e5690 | 753 | #ifdef CPU_BIG_ENDIAN |
c3226991 OZ |
754 | u16 pxcount; |
755 | u16 ref_type; | |
c15e5690 OZ |
756 | #else |
757 | u16 ref_type; | |
758 | u16 pxcount; | |
759 | #endif | |
c3226991 OZ |
760 | u32 ref_id; |
761 | u32 ref_rt; | |
762 | u32 rest[]; | |
98ac6176 OF |
763 | }; |
764 | ||
5a50a989 OZ |
765 | struct ospf_tlv |
766 | { | |
767 | #ifdef CPU_BIG_ENDIAN | |
768 | u16 type; | |
769 | u16 length; | |
770 | #else | |
771 | u16 length; | |
772 | u16 type; | |
773 | #endif | |
774 | u32 data[]; | |
775 | }; | |
776 | ||
c3226991 | 777 | |
a7a7372a | 778 | static inline uint |
b66abe8e | 779 | lsa_net_count(struct ospf_lsa_header *lsa) |
c3226991 OZ |
780 | { |
781 | return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net)) | |
782 | / sizeof(u32); | |
783 | } | |
784 | ||
70945cb6 OZ |
785 | /* In ospf_area->rtr we store paths to routers, but we use RID (and not IP address) |
786 | as index, so we need to encapsulate RID to IP address */ | |
787 | ||
fe9f1a6d OZ |
788 | #define net_from_rid(x) NET_ADDR_IP4(ip4_from_u32(x), IP4_MAX_PREFIX_LENGTH) |
789 | #define rid_from_net(x) ip4_to_u32(((net_addr_ip4 *) x)->prefix) | |
c3226991 | 790 | |
a6bc04d5 OZ |
791 | #define IPV6_PREFIX_SPACE(x) ((((x) + 63) / 32) * 4) |
792 | #define IPV6_PREFIX_WORDS(x) (((x) + 63) / 32) | |
793 | ||
88a183c6 | 794 | |
d7661fbe JMM |
795 | static inline int |
796 | ospf_valid_prefix(net_addr *n) | |
797 | { | |
d3f4f92b OZ |
798 | /* |
799 | * In OSPFv2, prefix is stored as netmask; ip4_masklen() returns 255 for | |
800 | * invalid one. But OSPFv3-AF may receive IPv4 net with 32 < pxlen < 128. | |
801 | */ | |
802 | uint max = (n->type == NET_IP4) ? IP4_MAX_PREFIX_LENGTH : IP6_MAX_PREFIX_LENGTH; | |
803 | return n->pxlen <= max; | |
d7661fbe JMM |
804 | } |
805 | ||
d3f4f92b OZ |
806 | /* |
807 | * In OSPFv3-AF (RFC 5835), IPv4 address is encoded by just placing it in the | |
808 | * first 32 bits of IPv6 address and setting remaining bits to zero. Likewise | |
809 | * for IPv4 prefix, where remaining bits do not matter. We use following | |
810 | * functions to convert between IPv4 and IPv4-in-IPv6 representations: | |
811 | */ | |
812 | ||
813 | static inline ip4_addr ospf3_6to4(ip6_addr a) | |
814 | { return _MI4(_I0(a)); } | |
815 | ||
816 | static inline ip6_addr ospf3_4to6(ip4_addr a) | |
817 | { return _MI6(_I(a), 0, 0, 0); } | |
818 | ||
819 | ||
b66abe8e | 820 | static inline u32 * |
d3f4f92b | 821 | ospf3_get_prefix(u32 *buf, int af, net_addr *n, u8 *pxopts, u16 *rest) |
b66abe8e | 822 | { |
d3f4f92b OZ |
823 | ip6_addr px = IP6_NONE; |
824 | uint pxlen = (*buf >> 24); | |
fe9f1a6d OZ |
825 | *pxopts = (*buf >> 16) & 0xff; |
826 | if (rest) *rest = *buf & 0xffff; | |
b66abe8e OZ |
827 | buf++; |
828 | ||
fe9f1a6d | 829 | if (pxlen > 0) |
d3f4f92b | 830 | _I0(px) = *buf++; |
fe9f1a6d | 831 | if (pxlen > 32) |
d3f4f92b | 832 | _I1(px) = *buf++; |
fe9f1a6d | 833 | if (pxlen > 64) |
d3f4f92b | 834 | _I2(px) = *buf++; |
fe9f1a6d | 835 | if (pxlen > 96) |
d3f4f92b | 836 | _I3(px) = *buf++; |
b66abe8e | 837 | |
ab164971 | 838 | /* Clean up remaining bits */ |
fe9f1a6d | 839 | if (pxlen < 128) |
d3f4f92b | 840 | px.addr[pxlen / 32] &= u32_mkmask(pxlen % 32); |
ab164971 | 841 | |
d3f4f92b OZ |
842 | if (af == NET_IP4) |
843 | net_fill_ip4(n, ospf3_6to4(px), pxlen); | |
844 | else | |
845 | net_fill_ip6(n, px, pxlen); | |
b66abe8e | 846 | |
d3f4f92b | 847 | return buf; |
b66abe8e OZ |
848 | } |
849 | ||
a6bc04d5 | 850 | static inline u32 * |
d3f4f92b | 851 | ospf3_put_prefix(u32 *buf, net_addr *n, u8 pxopts, u16 rest) |
a6bc04d5 | 852 | { |
d3f4f92b OZ |
853 | ip6_addr px = (n->type == NET_IP4) ? ospf3_4to6(net4_prefix(n)) : net6_prefix(n); |
854 | uint pxlen = n->pxlen; | |
fe9f1a6d OZ |
855 | |
856 | *buf++ = ((pxlen << 24) | (pxopts << 16) | rest); | |
a6bc04d5 OZ |
857 | |
858 | if (pxlen > 0) | |
d3f4f92b | 859 | *buf++ = _I0(px); |
a6bc04d5 | 860 | if (pxlen > 32) |
d3f4f92b | 861 | *buf++ = _I1(px); |
a6bc04d5 | 862 | if (pxlen > 64) |
d3f4f92b | 863 | *buf++ = _I2(px); |
a6bc04d5 | 864 | if (pxlen > 96) |
d3f4f92b | 865 | *buf++ = _I3(px); |
fe9f1a6d | 866 | |
a6bc04d5 OZ |
867 | return buf; |
868 | } | |
869 | ||
870 | static inline u32 * | |
d3f4f92b | 871 | ospf3_get_addr(u32 *buf, int af, ip_addr *addr) |
a6bc04d5 | 872 | { |
d3f4f92b OZ |
873 | ip6_addr a; |
874 | memcpy(&a, buf, 16); | |
875 | *addr = (af == NET_IP4) ? ipa_from_ip4(ospf3_6to4(a)) : ipa_from_ip6(a); | |
876 | return buf + 4; | |
877 | } | |
878 | ||
879 | static inline u32 * | |
880 | ospf3_put_addr(u32 *buf, ip_addr addr) | |
881 | { | |
882 | ip6_addr a = ipa_is_ip4(addr) ? ospf3_4to6(ipa_to_ip4(addr)) : ipa_to_ip6(addr); | |
883 | memcpy(buf, &a, 16); | |
a6bc04d5 OZ |
884 | return buf + 4; |
885 | } | |
886 | ||
b66abe8e | 887 | |
2e10a170 OF |
888 | struct ospf_lsreq_header |
889 | { | |
c3226991 | 890 | u32 type; |
6d2b3211 | 891 | u32 id; |
70945cb6 | 892 | u32 rt; |
f45fd316 OF |
893 | }; |
894 | ||
de769e24 | 895 | |
20ab192b OZ |
896 | |
897 | #define SH_ROUTER_SELF 0xffffffff | |
898 | ||
899 | struct lsadb_show_data { | |
900 | struct symbol *name; /* Protocol to request data from */ | |
901 | u16 type; /* LSA Type, 0 -> all */ | |
902 | u16 scope; /* Scope, 0 -> all, hack to handle link scope as 1 */ | |
903 | u32 area; /* Specified for area scope */ | |
904 | u32 lsid; /* LSA ID, 0 -> all */ | |
905 | u32 router; /* Advertising router, 0 -> all */ | |
906 | }; | |
907 | ||
4364b47e | 908 | |
ee7e2ffd JMM |
909 | #define EA_OSPF_METRIC1 EA_CODE(PROTOCOL_OSPF, 0) |
910 | #define EA_OSPF_METRIC2 EA_CODE(PROTOCOL_OSPF, 1) | |
911 | #define EA_OSPF_TAG EA_CODE(PROTOCOL_OSPF, 2) | |
912 | #define EA_OSPF_ROUTER_ID EA_CODE(PROTOCOL_OSPF, 3) | |
5919c66e | 913 | |
70945cb6 OZ |
914 | |
915 | /* ospf.c */ | |
a7a7372a | 916 | void ospf_schedule_rtcalc(struct ospf_proto *p); |
70945cb6 OZ |
917 | |
918 | static inline void ospf_notify_rt_lsa(struct ospf_area *oa) | |
919 | { oa->update_rt_lsa = 1; } | |
920 | ||
921 | static inline void ospf_notify_net_lsa(struct ospf_iface *ifa) | |
922 | { ifa->update_net_lsa = 1; } | |
923 | ||
924 | static inline void ospf_notify_link_lsa(struct ospf_iface *ifa) | |
925 | { ifa->update_link_lsa = 1; } | |
926 | ||
70945cb6 OZ |
927 | static inline int ospf_is_v2(struct ospf_proto *p) |
928 | { return p->ospf2; } | |
929 | ||
930 | static inline int ospf_is_v3(struct ospf_proto *p) | |
931 | { return ! p->ospf2; } | |
23c212e7 | 932 | |
70945cb6 OZ |
933 | static inline int ospf_get_version(struct ospf_proto *p) |
934 | { return ospf_is_v2(p) ? 2 : 3; } | |
935 | ||
d3f4f92b OZ |
936 | static inline int ospf_is_ip4(struct ospf_proto *p) |
937 | { return p->p.net_type == NET_IP4; } | |
938 | ||
939 | static inline int ospf_is_ip6(struct ospf_proto *p) | |
940 | { return p->p.net_type == NET_IP6; } | |
941 | ||
942 | static inline int ospf_get_af(struct ospf_proto *p) | |
943 | { return p->p.net_type; } | |
944 | ||
70945cb6 OZ |
945 | struct ospf_area *ospf_find_area(struct ospf_proto *p, u32 aid); |
946 | ||
947 | static inline struct ospf_area *ospf_main_area(struct ospf_proto *p) | |
948 | { return (p->areano == 1) ? HEAD(p->area_list) : p->backbone; } | |
949 | ||
950 | static inline int oa_is_stub(struct ospf_area *oa) | |
951 | { return (oa->options & (OPT_E | OPT_N)) == 0; } | |
952 | ||
953 | static inline int oa_is_ext(struct ospf_area *oa) | |
954 | { return oa->options & OPT_E; } | |
955 | ||
956 | static inline int oa_is_nssa(struct ospf_area *oa) | |
957 | { return oa->options & OPT_N; } | |
958 | ||
959 | void ospf_sh_neigh(struct proto *P, char *iff); | |
960 | void ospf_sh(struct proto *P); | |
961 | void ospf_sh_iface(struct proto *P, char *iff); | |
962 | void ospf_sh_state(struct proto *P, int verbose, int reachable); | |
963 | ||
964 | void ospf_sh_lsadb(struct lsadb_show_data *ld); | |
965 | ||
966 | /* iface.c */ | |
967 | void ospf_iface_chstate(struct ospf_iface *ifa, u8 state); | |
968 | void ospf_iface_sm(struct ospf_iface *ifa, int event); | |
969 | struct ospf_iface *ospf_iface_find(struct ospf_proto *p, struct iface *what); | |
970 | void ospf_if_notify(struct proto *P, uint flags, struct iface *iface); | |
971 | void ospf_ifa_notify2(struct proto *P, uint flags, struct ifa *a); | |
972 | void ospf_ifa_notify3(struct proto *P, uint flags, struct ifa *a); | |
973 | void ospf_iface_info(struct ospf_iface *ifa); | |
974 | void ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *ip); | |
975 | void ospf_iface_new_vlink(struct ospf_proto *p, struct ospf_iface_patt *ip); | |
976 | void ospf_iface_remove(struct ospf_iface *ifa); | |
977 | void ospf_iface_shutdown(struct ospf_iface *ifa); | |
978 | int ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen); | |
979 | int ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new); | |
980 | void ospf_reconfigure_ifaces(struct ospf_proto *p); | |
981 | void ospf_open_vlink_sk(struct ospf_proto *p); | |
982 | struct nbma_node *find_nbma_node_(list *nnl, ip_addr ip); | |
983 | ||
984 | static inline struct nbma_node * find_nbma_node(struct ospf_iface *ifa, ip_addr ip) | |
985 | { return find_nbma_node_(&ifa->nbma_list, ip); } | |
986 | ||
987 | /* neighbor.c */ | |
988 | struct ospf_neighbor *ospf_neighbor_new(struct ospf_iface *ifa); | |
989 | void ospf_neigh_sm(struct ospf_neighbor *n, int event); | |
990 | void ospf_dr_election(struct ospf_iface *ifa); | |
991 | struct ospf_neighbor *find_neigh(struct ospf_iface *ifa, u32 rid); | |
992 | struct ospf_neighbor *find_neigh_by_ip(struct ospf_iface *ifa, ip_addr ip); | |
70945cb6 OZ |
993 | void ospf_neigh_update_bfd(struct ospf_neighbor *n, int use_bfd); |
994 | void ospf_sh_neigh_info(struct ospf_neighbor *n); | |
995 | ||
996 | /* packet.c */ | |
997 | void ospf_pkt_fill_hdr(struct ospf_iface *ifa, void *buf, u8 h_type); | |
3e236955 | 998 | int ospf_rx_hook(sock * sk, uint size); |
70945cb6 OZ |
999 | // void ospf_tx_hook(sock * sk); |
1000 | void ospf_err_hook(sock * sk, int err); | |
1001 | void ospf_verr_hook(sock *sk, int err); | |
1002 | void ospf_send_to(struct ospf_iface *ifa, ip_addr ip); | |
1003 | void ospf_send_to_agt(struct ospf_iface *ifa, u8 state); | |
1004 | void ospf_send_to_bdr(struct ospf_iface *ifa); | |
1005 | ||
29239ba2 OZ |
1006 | static inline uint ospf_pkt_maxsize(struct ospf_iface *ifa) |
1007 | { return ifa->tx_length - ifa->tx_hdrlen; } | |
1008 | ||
70945cb6 OZ |
1009 | static inline void ospf_send_to_all(struct ospf_iface *ifa) |
1010 | { ospf_send_to(ifa, ifa->all_routers); } | |
1011 | ||
1012 | static inline void ospf_send_to_des(struct ospf_iface *ifa) | |
1013 | { | |
1014 | if (ipa_nonzero(ifa->des_routers)) | |
1015 | ospf_send_to(ifa, ifa->des_routers); | |
1016 | else | |
1017 | ospf_send_to_bdr(ifa); | |
1018 | } | |
1019 | ||
304ac2e8 | 1020 | #ifndef PARSER |
f8fefde3 OZ |
1021 | #define DROP(DSC,VAL) do { err_dsc = DSC; err_val = VAL; goto drop; } while(0) |
1022 | #define DROP1(DSC) do { err_dsc = DSC; goto drop; } while(0) | |
1023 | #define SKIP(DSC) do { err_dsc = DSC; goto skip; } while(0) | |
304ac2e8 | 1024 | #endif |
f8fefde3 | 1025 | |
70945cb6 | 1026 | static inline uint ospf_pkt_hdrlen(struct ospf_proto *p) |
4727d1db | 1027 | { return ospf_is_v2(p) ? (sizeof(struct ospf_packet) + sizeof(union ospf_auth2)) : sizeof(struct ospf_packet); } |
70945cb6 OZ |
1028 | |
1029 | static inline void * ospf_tx_buffer(struct ospf_iface *ifa) | |
1030 | { return ifa->sk->tbuf; } | |
1031 | ||
1032 | /* hello.c */ | |
1033 | #define OHS_HELLO 0 | |
1034 | #define OHS_POLL 1 | |
1035 | #define OHS_SHUTDOWN 2 | |
1036 | ||
1037 | void ospf_send_hello(struct ospf_iface *ifa, int kind, struct ospf_neighbor *dirn); | |
1038 | void ospf_receive_hello(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n, ip_addr faddr); | |
4727d1db | 1039 | uint ospf_hello3_options(struct ospf_packet *pkt); |
70945cb6 OZ |
1040 | |
1041 | /* dbdes.c */ | |
f8fefde3 OZ |
1042 | void ospf_send_dbdes(struct ospf_proto *p, struct ospf_neighbor *n); |
1043 | void ospf_rxmt_dbdes(struct ospf_proto *p, struct ospf_neighbor *n); | |
70945cb6 | 1044 | void ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n); |
4727d1db | 1045 | uint ospf_dbdes3_options(struct ospf_packet *pkt); |
70945cb6 OZ |
1046 | |
1047 | /* lsreq.c */ | |
1048 | void ospf_send_lsreq(struct ospf_proto *p, struct ospf_neighbor *n); | |
1049 | void ospf_receive_lsreq(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n); | |
1050 | ||
1051 | /* lsupd.c */ | |
1052 | void ospf_dump_lsahdr(struct ospf_proto *p, struct ospf_lsa_header *lsa_n); | |
1053 | void ospf_dump_common(struct ospf_proto *p, struct ospf_packet *pkt); | |
6f8bbaa1 | 1054 | void ospf_lsa_lsrt_down_(struct top_hash_entry *en, struct ospf_neighbor *n, struct top_hash_entry *ret); |
a7a7372a | 1055 | void ospf_add_flushed_to_lsrt(struct ospf_proto *p, struct ospf_neighbor *n); |
6f8bbaa1 | 1056 | void ospf_flood_event(void *ptr); |
a7a7372a | 1057 | int ospf_flood_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_neighbor *from); |
70945cb6 OZ |
1058 | int ospf_send_lsupd(struct ospf_proto *p, struct top_hash_entry **lsa_list, uint lsa_count, struct ospf_neighbor *n); |
1059 | void ospf_rxmt_lsupd(struct ospf_proto *p, struct ospf_neighbor *n); | |
1060 | void ospf_receive_lsupd(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n); | |
1061 | ||
1062 | /* lsack.c */ | |
1063 | void ospf_enqueue_lsack(struct ospf_neighbor *n, struct ospf_lsa_header *h_n, int queue); | |
1064 | void ospf_reset_lsack_queue(struct ospf_neighbor *n); | |
a7a7372a | 1065 | void ospf_send_lsack(struct ospf_proto *p, struct ospf_neighbor *n, int queue); |
70945cb6 OZ |
1066 | void ospf_receive_lsack(struct ospf_packet *pkt, struct ospf_iface *ifa, struct ospf_neighbor *n); |
1067 | ||
1068 | ||
98ac6176 | 1069 | #include "proto/ospf/rt.h" |
4364b47e | 1070 | #include "proto/ospf/topology.h" |
f45fd316 | 1071 | #include "proto/ospf/lsalib.h" |
6ba36f06 | 1072 | |
c1f8dc91 | 1073 | #endif /* _BIRD_OSPF_H_ */ |