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