]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * OSPF Flooding -- RFC2328 Section 13. | |
3 | * Copyright (C) 1999, 2000 Toshiaki Takada | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
896014f4 | 6 | * |
718e3744 | 7 | * GNU Zebra is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published | |
9 | * by the Free Software Foundation; either version 2, or (at your | |
10 | * option) any later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
23 | ||
cbf3e3eb | 24 | #include "monotime.h" |
718e3744 | 25 | #include "linklist.h" |
26 | #include "prefix.h" | |
27 | #include "if.h" | |
28 | #include "command.h" | |
29 | #include "table.h" | |
30 | #include "thread.h" | |
31 | #include "memory.h" | |
32 | #include "log.h" | |
33 | #include "zclient.h" | |
34 | ||
35 | #include "ospfd/ospfd.h" | |
36 | #include "ospfd/ospf_interface.h" | |
37 | #include "ospfd/ospf_ism.h" | |
38 | #include "ospfd/ospf_asbr.h" | |
39 | #include "ospfd/ospf_lsa.h" | |
40 | #include "ospfd/ospf_lsdb.h" | |
41 | #include "ospfd/ospf_neighbor.h" | |
42 | #include "ospfd/ospf_nsm.h" | |
43 | #include "ospfd/ospf_spf.h" | |
44 | #include "ospfd/ospf_flood.h" | |
45 | #include "ospfd/ospf_packet.h" | |
46 | #include "ospfd/ospf_abr.h" | |
47 | #include "ospfd/ospf_route.h" | |
48 | #include "ospfd/ospf_zebra.h" | |
49 | #include "ospfd/ospf_dump.h" | |
50 | ||
51 | extern struct zclient *zclient; | |
6b0655a2 | 52 | |
718e3744 | 53 | /* Do the LSA acking specified in table 19, Section 13.5, row 2 |
d62a17ae | 54 | * This get called from ospf_flood_out_interface. Declared inline |
718e3744 | 55 | * for speed. */ |
d62a17ae | 56 | static void ospf_flood_delayed_lsa_ack(struct ospf_neighbor *inbr, |
57 | struct ospf_lsa *lsa) | |
718e3744 | 58 | { |
d62a17ae | 59 | /* LSA is more recent than database copy, but was not |
60 | flooded back out receiving interface. Delayed | |
61 | acknowledgment sent. If interface is in Backup state | |
62 | delayed acknowledgment sent only if advertisement | |
63 | received from Designated Router, otherwise do nothing See | |
64 | RFC 2328 Section 13.5 */ | |
65 | ||
66 | /* Whether LSA is more recent or not, and whether this is in | |
67 | response to the LSA being sent out recieving interface has been | |
68 | worked out previously */ | |
69 | ||
70 | /* Deal with router as BDR */ | |
71 | if (inbr->oi->state == ISM_Backup && !NBR_IS_DR(inbr)) | |
72 | return; | |
73 | ||
74 | /* Schedule a delayed LSA Ack to be sent */ | |
75 | listnode_add(inbr->oi->ls_ack, | |
76 | ospf_lsa_lock(lsa)); /* delayed LSA Ack */ | |
718e3744 | 77 | } |
78 | ||
79 | /* Check LSA is related to external info. */ | |
b5a8894d CS |
80 | struct external_info *ospf_external_info_check(struct ospf *ospf, |
81 | struct ospf_lsa *lsa) | |
718e3744 | 82 | { |
d62a17ae | 83 | struct as_external_lsa *al; |
84 | struct prefix_ipv4 p; | |
85 | struct route_node *rn; | |
5af13f54 DL |
86 | struct list *ext_list; |
87 | struct listnode *node; | |
88 | struct ospf_external *ext; | |
d62a17ae | 89 | int type; |
90 | ||
91 | al = (struct as_external_lsa *)lsa->data; | |
92 | ||
93 | p.family = AF_INET; | |
94 | p.prefix = lsa->data->id; | |
95 | p.prefixlen = ip_masklen(al->mask); | |
96 | ||
fd9a1d5a | 97 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { |
d62a17ae | 98 | int redist_on = 0; |
99 | ||
100 | redist_on = | |
101 | is_prefix_default(&p) | |
49db7a7b RW |
102 | ? vrf_bitmap_check( |
103 | zclient->default_information[AFI_IP], | |
104 | ospf->vrf_id) | |
d62a17ae | 105 | : (zclient->mi_redist[AFI_IP][type].enabled |
106 | || vrf_bitmap_check( | |
107 | zclient->redist[AFI_IP][type], | |
b5a8894d | 108 | ospf->vrf_id)); |
d62a17ae | 109 | // Pending: check for MI above. |
110 | if (redist_on) { | |
de1ac5fd | 111 | ext_list = ospf->external[type]; |
d62a17ae | 112 | if (!ext_list) |
113 | continue; | |
114 | ||
115 | for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) { | |
116 | rn = NULL; | |
117 | if (ext->external_info) | |
118 | rn = route_node_lookup( | |
119 | ext->external_info, | |
120 | (struct prefix *)&p); | |
121 | if (rn) { | |
122 | route_unlock_node(rn); | |
123 | if (rn->info != NULL) | |
124 | return (struct external_info *) | |
125 | rn->info; | |
126 | } | |
127 | } | |
128 | } | |
129 | } | |
130 | ||
5af13f54 DL |
131 | if (is_prefix_default(&p) && ospf->external[DEFAULT_ROUTE]) { |
132 | ext_list = ospf->external[DEFAULT_ROUTE]; | |
133 | ||
134 | for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) { | |
135 | if (!ext->external_info) | |
136 | continue; | |
137 | ||
138 | rn = route_node_lookup(ext->external_info, | |
139 | (struct prefix *)&p); | |
140 | if (!rn) | |
141 | continue; | |
142 | route_unlock_node(rn); | |
143 | if (rn->info != NULL) | |
144 | return (struct external_info *)rn->info; | |
145 | } | |
146 | } | |
d62a17ae | 147 | return NULL; |
718e3744 | 148 | } |
149 | ||
d62a17ae | 150 | static void ospf_process_self_originated_lsa(struct ospf *ospf, |
151 | struct ospf_lsa *new, | |
152 | struct ospf_area *area) | |
718e3744 | 153 | { |
d62a17ae | 154 | struct ospf_interface *oi; |
155 | struct external_info *ei; | |
156 | struct listnode *node; | |
960417cf | 157 | struct as_external_lsa *al; |
158 | struct prefix_ipv4 p; | |
159 | struct ospf_external_aggr_rt *aggr; | |
d62a17ae | 160 | |
161 | if (IS_DEBUG_OSPF_EVENT) | |
162 | zlog_debug( | |
96b663a3 | 163 | "%s:LSA[Type%d:%pI4]: Process self-originated LSA seq 0x%x", |
868a0861 | 164 | ospf_get_name(ospf), new->data->type, |
96b663a3 | 165 | &new->data->id, ntohl(new->data->ls_seqnum)); |
d62a17ae | 166 | |
167 | /* If we're here, we installed a self-originated LSA that we received | |
168 | from a neighbor, i.e. it's more recent. We must see whether we want | |
169 | to originate it. | |
170 | If yes, we should use this LSA's sequence number and reoriginate | |
171 | a new instance. | |
172 | if not --- we must flush this LSA from the domain. */ | |
173 | switch (new->data->type) { | |
174 | case OSPF_ROUTER_LSA: | |
175 | /* Originate a new instance and schedule flooding */ | |
176 | if (area->router_lsa_self) | |
177 | area->router_lsa_self->data->ls_seqnum = | |
178 | new->data->ls_seqnum; | |
179 | ospf_router_lsa_update_area(area); | |
180 | return; | |
181 | case OSPF_NETWORK_LSA: | |
182 | case OSPF_OPAQUE_LINK_LSA: | |
183 | /* We must find the interface the LSA could belong to. | |
184 | If the interface is no more a broadcast type or we are no | |
185 | more | |
186 | the DR, we flush the LSA otherwise -- create the new instance | |
187 | and | |
188 | schedule flooding. */ | |
189 | ||
190 | /* Look through all interfaces, not just area, since interface | |
191 | could be moved from one area to another. */ | |
192 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) | |
193 | /* These are sanity check. */ | |
194 | if (IPV4_ADDR_SAME(&oi->address->u.prefix4, | |
195 | &new->data->id)) { | |
196 | if (oi->area != area | |
197 | || oi->type != OSPF_IFTYPE_BROADCAST | |
198 | || !IPV4_ADDR_SAME(&oi->address->u.prefix4, | |
199 | &DR(oi))) { | |
200 | ospf_schedule_lsa_flush_area(area, new); | |
201 | return; | |
202 | } | |
203 | ||
204 | if (new->data->type == OSPF_OPAQUE_LINK_LSA) { | |
205 | ospf_opaque_lsa_refresh(new); | |
206 | return; | |
207 | } | |
208 | ||
209 | if (oi->network_lsa_self) | |
210 | oi->network_lsa_self->data->ls_seqnum = | |
211 | new->data->ls_seqnum; | |
212 | /* Schedule network-LSA origination. */ | |
213 | ospf_network_lsa_update(oi); | |
214 | return; | |
215 | } | |
216 | break; | |
217 | case OSPF_SUMMARY_LSA: | |
218 | case OSPF_ASBR_SUMMARY_LSA: | |
219 | ospf_schedule_abr_task(ospf); | |
220 | break; | |
221 | case OSPF_AS_EXTERNAL_LSA: | |
222 | case OSPF_AS_NSSA_LSA: | |
223 | if ((new->data->type == OSPF_AS_EXTERNAL_LSA) | |
224 | && CHECK_FLAG(new->flags, OSPF_LSA_LOCAL_XLT)) { | |
225 | ospf_translated_nssa_refresh(ospf, NULL, new); | |
226 | return; | |
227 | } | |
960417cf | 228 | |
229 | al = (struct as_external_lsa *)new->data; | |
230 | p.family = AF_INET; | |
231 | p.prefixlen = ip_masklen(al->mask); | |
232 | p.prefix = new->data->id; | |
233 | ||
b5a8894d | 234 | ei = ospf_external_info_check(ospf, new); |
960417cf | 235 | if (ei) { |
236 | if (ospf_external_aggr_match(ospf, &ei->p)) { | |
237 | if (IS_DEBUG_OSPF(lsa, EXTNL_LSA_AGGR)) | |
238 | zlog_debug( | |
239 | "%s, Matching external aggregate route found for %pI4, so don't refresh it.", | |
240 | __func__, | |
241 | &ei->p.prefix); | |
242 | ||
243 | /* Aggregated external route shouldn't | |
244 | * be in LSDB. | |
245 | */ | |
246 | if (!IS_LSA_MAXAGE(new)) | |
247 | ospf_lsa_flush_as(ospf, new); | |
248 | ||
249 | return; | |
250 | } | |
251 | ||
d62a17ae | 252 | ospf_external_lsa_refresh(ospf, new, ei, |
63f0e941 | 253 | LSA_REFRESH_FORCE, false); |
960417cf | 254 | } else { |
255 | aggr = (struct ospf_external_aggr_rt *) | |
256 | ospf_extrenal_aggregator_lookup(ospf, &p); | |
257 | if (aggr) { | |
258 | struct external_info ei_aggr; | |
259 | ||
260 | memset(&ei_aggr, 0, | |
261 | sizeof(struct external_info)); | |
262 | ei_aggr.p = aggr->p; | |
263 | ei_aggr.tag = aggr->tag; | |
264 | ei_aggr.instance = ospf->instance; | |
265 | ei_aggr.route_map_set.metric = -1; | |
266 | ei_aggr.route_map_set.metric_type = -1; | |
267 | ||
268 | ospf_external_lsa_refresh(ospf, new, &ei_aggr, | |
269 | LSA_REFRESH_FORCE, true); | |
270 | } else | |
271 | ospf_lsa_flush_as(ospf, new); | |
272 | } | |
d62a17ae | 273 | break; |
274 | case OSPF_OPAQUE_AREA_LSA: | |
275 | ospf_opaque_lsa_refresh(new); | |
276 | break; | |
277 | case OSPF_OPAQUE_AS_LSA: | |
278 | ospf_opaque_lsa_refresh(new); | |
996c9314 | 279 | /* Reconsideration may needed. */ /* XXX */ |
d62a17ae | 280 | break; |
281 | default: | |
282 | break; | |
283 | } | |
718e3744 | 284 | } |
285 | ||
286 | /* OSPF LSA flooding -- RFC2328 Section 13.(5). */ | |
287 | ||
288 | /* Now Updated for NSSA operation, as follows: | |
289 | ||
290 | ||
291 | Type-5's have no change. Blocked to STUB or NSSA. | |
292 | ||
293 | Type-7's can be received, and if a DR | |
294 | they will also flood the local NSSA Area as Type-7's | |
295 | ||
d62a17ae | 296 | If a Self-Originated LSA (now an ASBR), |
718e3744 | 297 | The LSDB will be updated as Type-5's, (for continual re-fresh) |
298 | ||
299 | If an NSSA-IR it is installed/flooded as Type-7, P-bit on. | |
300 | if an NSSA-ABR it is installed/flooded as Type-7, P-bit off. | |
301 | ||
302 | Later, during the ABR TASK, if the ABR is the Elected NSSA | |
303 | translator, then All Type-7s (with P-bit ON) are Translated to | |
304 | Type-5's and flooded to all non-NSSA/STUB areas. | |
305 | ||
d62a17ae | 306 | During ASE Calculations, |
718e3744 | 307 | non-ABRs calculate external routes from Type-7's |
308 | ABRs calculate external routes from Type-5's and non-self Type-7s | |
309 | */ | |
d62a17ae | 310 | int ospf_flood(struct ospf *ospf, struct ospf_neighbor *nbr, |
311 | struct ospf_lsa *current, struct ospf_lsa *new) | |
718e3744 | 312 | { |
d62a17ae | 313 | struct ospf_interface *oi; |
314 | int lsa_ack_flag; | |
315 | ||
316 | /* Type-7 LSA's will be flooded throughout their native NSSA area, | |
317 | but will also be flooded as Type-5's into ABR capable links. */ | |
318 | ||
319 | if (IS_DEBUG_OSPF_EVENT) | |
320 | zlog_debug( | |
96b663a3 MS |
321 | "%s:LSA[Flooding]: start, NBR %pI4 (%s), cur(%p), New-LSA[%s]", |
322 | ospf_get_name(ospf), &nbr->router_id, | |
d62a17ae | 323 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL), |
324 | (void *)current, dump_lsa_key(new)); | |
325 | ||
326 | oi = nbr->oi; | |
327 | ||
328 | /* If there is already a database copy, and if the | |
329 | database copy was received via flooding and installed less | |
330 | than MinLSArrival seconds ago, discard the new LSA | |
331 | (without acknowledging it). */ | |
332 | if (current != NULL) /* -- endo. */ | |
333 | { | |
334 | if (IS_LSA_SELF(current) | |
335 | && (ntohs(current->data->ls_age) == 0 | |
336 | && ntohl(current->data->ls_seqnum) | |
337 | == OSPF_INITIAL_SEQUENCE_NUMBER)) { | |
338 | if (IS_DEBUG_OSPF_EVENT) | |
339 | zlog_debug( | |
868a0861 DS |
340 | "%s:LSA[Flooding]: Got a self-originated LSA, while local one is initial instance.", |
341 | ospf_get_name(ospf)); | |
d62a17ae | 342 | ; /* Accept this LSA for quick LSDB resynchronization. |
9d303b37 | 343 | */ |
d62a17ae | 344 | } else if (monotime_since(¤t->tv_recv, NULL) |
345 | < ospf->min_ls_arrival * 1000LL) { | |
346 | if (IS_DEBUG_OSPF_EVENT) | |
347 | zlog_debug( | |
868a0861 DS |
348 | "%s:LSA[Flooding]: LSA is received recently.", |
349 | ospf_get_name(ospf)); | |
d62a17ae | 350 | return -1; |
351 | } | |
352 | } | |
353 | ||
354 | /* Flood the new LSA out some subset of the router's interfaces. | |
355 | In some cases (e.g., the state of the receiving interface is | |
356 | DR and the LSA was received from a router other than the | |
357 | Backup DR) the LSA will be flooded back out the receiving | |
358 | interface. */ | |
359 | lsa_ack_flag = ospf_flood_through(ospf, nbr, new); | |
360 | ||
361 | /* Remove the current database copy from all neighbors' Link state | |
362 | retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does | |
363 | ^^^^^^^^^^^^^^^^^^^^^^^ | |
364 | not have area ID. | |
365 | All other (even NSSA's) do have area ID. */ | |
366 | if (current) { | |
367 | switch (current->data->type) { | |
368 | case OSPF_AS_EXTERNAL_LSA: | |
369 | case OSPF_OPAQUE_AS_LSA: | |
370 | ospf_ls_retransmit_delete_nbr_as(ospf, current); | |
371 | break; | |
372 | default: | |
45559c4d | 373 | ospf_ls_retransmit_delete_nbr_area(oi->area, current); |
d62a17ae | 374 | break; |
375 | } | |
376 | } | |
377 | ||
378 | /* Do some internal house keeping that is needed here */ | |
379 | SET_FLAG(new->flags, OSPF_LSA_RECEIVED); | |
752ee70b | 380 | (void)ospf_lsa_is_self_originated(ospf, new); /* Let it set the flag */ |
d62a17ae | 381 | |
ad686992 | 382 | /* Received Grace LSA */ |
383 | if (IS_GRACE_LSA(new)) { | |
384 | ||
385 | if (IS_LSA_MAXAGE(new)) { | |
386 | ||
387 | /* Handling Max age grace LSA.*/ | |
388 | if (IS_DEBUG_OSPF_GR_HELPER) | |
389 | zlog_debug( | |
96b663a3 | 390 | "%s, Received a maxage GRACE-LSA from router %pI4", |
ad686992 | 391 | __PRETTY_FUNCTION__, |
96b663a3 | 392 | &new->data->adv_router); |
ad686992 | 393 | |
394 | if (current) { | |
395 | ospf_process_maxage_grace_lsa(ospf, new, nbr); | |
396 | } else { | |
397 | if (IS_DEBUG_OSPF_GR_HELPER) | |
398 | zlog_debug( | |
399 | "%s, Grace LSA doesn't exist in lsdb, so discarding grace lsa", | |
400 | __PRETTY_FUNCTION__); | |
401 | return -1; | |
402 | } | |
403 | } else { | |
404 | if (IS_DEBUG_OSPF_GR_HELPER) | |
405 | zlog_debug( | |
96b663a3 | 406 | "%s, Received a GRACE-LSA from router %pI4", |
ad686992 | 407 | __PRETTY_FUNCTION__, |
96b663a3 | 408 | &new->data->adv_router); |
ad686992 | 409 | |
410 | if (ospf_process_grace_lsa(ospf, new, nbr) | |
411 | == OSPF_GR_NOT_HELPER) { | |
412 | if (IS_DEBUG_OSPF_GR_HELPER) | |
413 | zlog_debug( | |
414 | "%s, Not moving to HELPER role, So discarding grace LSA", | |
415 | __PRETTY_FUNCTION__); | |
416 | return -1; | |
417 | } | |
418 | } | |
419 | } | |
420 | ||
d62a17ae | 421 | /* Install the new LSA in the link state database |
422 | (replacing the current database copy). This may cause the | |
423 | routing table calculation to be scheduled. In addition, | |
424 | timestamp the new LSA with the current time. The flooding | |
425 | procedure cannot overwrite the newly installed LSA until | |
426 | MinLSArrival seconds have elapsed. */ | |
427 | ||
45559c4d | 428 | if (!(new = ospf_lsa_install(ospf, oi, new))) |
d62a17ae | 429 | return -1; /* unknown LSA type or any other error condition */ |
430 | ||
431 | /* Acknowledge the receipt of the LSA by sending a Link State | |
432 | Acknowledgment packet back out the receiving interface. */ | |
433 | if (lsa_ack_flag) | |
434 | ospf_flood_delayed_lsa_ack(nbr, new); | |
435 | ||
436 | /* If this new LSA indicates that it was originated by the | |
437 | receiving router itself, the router must take special action, | |
438 | either updating the LSA or in some cases flushing it from | |
439 | the routing domain. */ | |
440 | if (ospf_lsa_is_self_originated(ospf, new)) | |
441 | ospf_process_self_originated_lsa(ospf, new, oi->area); | |
442 | else | |
443 | /* Update statistics value for OSPF-MIB. */ | |
444 | ospf->rx_lsa_count++; | |
445 | ||
446 | return 0; | |
718e3744 | 447 | } |
448 | ||
449 | /* OSPF LSA flooding -- RFC2328 Section 13.3. */ | |
d62a17ae | 450 | static int ospf_flood_through_interface(struct ospf_interface *oi, |
451 | struct ospf_neighbor *inbr, | |
452 | struct ospf_lsa *lsa) | |
718e3744 | 453 | { |
d62a17ae | 454 | struct ospf_neighbor *onbr; |
455 | struct route_node *rn; | |
456 | int retx_flag; | |
96b663a3 | 457 | char buf[PREFIX_STRLEN]; |
d62a17ae | 458 | |
459 | if (IS_DEBUG_OSPF_EVENT) | |
460 | zlog_debug( | |
9d51b28c TA |
461 | "%s: considering int %s (%s), INBR(%s), LSA[%s] AGE %u", |
462 | __func__, IF_NAME(oi), ospf_get_name(oi->ospf), | |
463 | inbr ? inet_ntop(AF_INET, &inbr->router_id, buf, | |
464 | sizeof(buf)) | |
465 | : "NULL", | |
046460a1 | 466 | dump_lsa_key(lsa), ntohs(lsa->data->ls_age)); |
d62a17ae | 467 | |
468 | if (!ospf_if_is_enable(oi)) | |
469 | return 0; | |
470 | ||
96fad84a | 471 | /* Remember if new LSA is added to a retransmit list. */ |
d62a17ae | 472 | retx_flag = 0; |
473 | ||
474 | /* Each of the neighbors attached to this interface are examined, | |
475 | to determine whether they must receive the new LSA. The following | |
476 | steps are executed for each neighbor: */ | |
477 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
478 | struct ospf_lsa *ls_req; | |
479 | ||
480 | if (rn->info == NULL) | |
481 | continue; | |
482 | ||
483 | onbr = rn->info; | |
484 | if (IS_DEBUG_OSPF_EVENT) | |
485 | zlog_debug( | |
9d51b28c TA |
486 | "%s: considering nbr %pI4 via %s (%s), state: %s", |
487 | __func__, &onbr->router_id, IF_NAME(oi), | |
868a0861 | 488 | ospf_get_name(oi->ospf), |
d62a17ae | 489 | lookup_msg(ospf_nsm_state_msg, onbr->state, |
490 | NULL)); | |
491 | ||
492 | /* If the neighbor is in a lesser state than Exchange, it | |
493 | does not participate in flooding, and the next neighbor | |
494 | should be examined. */ | |
495 | if (onbr->state < NSM_Exchange) | |
496 | continue; | |
497 | ||
498 | /* If the adjacency is not yet full (neighbor state is | |
499 | Exchange or Loading), examine the Link state request | |
500 | list associated with this adjacency. If there is an | |
501 | instance of the new LSA on the list, it indicates that | |
502 | the neighboring router has an instance of the LSA | |
503 | already. Compare the new LSA to the neighbor's copy: */ | |
504 | if (onbr->state < NSM_Full) { | |
505 | if (IS_DEBUG_OSPF_EVENT) | |
506 | zlog_debug( | |
9d51b28c TA |
507 | "%s: adj to onbr %pI4 is not Full (%s)", |
508 | __func__, &onbr->router_id, | |
509 | lookup_msg(ospf_nsm_state_msg, | |
510 | onbr->state, NULL)); | |
d62a17ae | 511 | ls_req = ospf_ls_request_lookup(onbr, lsa); |
512 | if (ls_req != NULL) { | |
513 | int ret; | |
514 | ||
515 | ret = ospf_lsa_more_recent(ls_req, lsa); | |
516 | /* The new LSA is less recent. */ | |
517 | if (ret > 0) | |
518 | continue; | |
519 | /* The two copies are the same instance, then | |
520 | delete | |
521 | the LSA from the Link state request list. */ | |
522 | else if (ret == 0) { | |
523 | ospf_ls_request_delete(onbr, ls_req); | |
524 | ospf_check_nbr_loading(onbr); | |
525 | continue; | |
526 | } | |
527 | /* The new LSA is more recent. Delete the LSA | |
528 | from the Link state request list. */ | |
529 | else { | |
530 | ospf_ls_request_delete(onbr, ls_req); | |
531 | ospf_check_nbr_loading(onbr); | |
532 | } | |
533 | } | |
718e3744 | 534 | } |
d62a17ae | 535 | |
536 | if (IS_OPAQUE_LSA(lsa->data->type)) { | |
537 | if (!CHECK_FLAG(onbr->options, OSPF_OPTION_O)) { | |
538 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) | |
539 | zlog_debug( | |
9d51b28c TA |
540 | "%s: Skipping neighbor %s via %s -- Not Opaque-capable.", |
541 | __func__, IF_NAME(oi), | |
542 | inet_ntop(AF_INET, | |
543 | &onbr->router_id, buf, | |
544 | sizeof(buf))); | |
d62a17ae | 545 | continue; |
546 | } | |
718e3744 | 547 | } |
718e3744 | 548 | |
f573ec60 DS |
549 | /* If the new LSA was received from this neighbor, |
550 | examine the next neighbor. */ | |
d62a17ae | 551 | if (inbr) { |
552 | /* | |
553 | * Triggered by LSUpd message parser "ospf_ls_upd ()". | |
554 | * E.g., all LSAs handling here is received via network. | |
555 | */ | |
556 | if (IPV4_ADDR_SAME(&inbr->router_id, | |
557 | &onbr->router_id)) { | |
558 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) | |
559 | zlog_debug( | |
9d51b28c TA |
560 | "%s: Skipping neighbor %s via %s -- inbr == onbr.", |
561 | __func__, IF_NAME(oi), | |
562 | inet_ntop(AF_INET, | |
563 | &inbr->router_id, buf, | |
564 | sizeof(buf))); | |
d62a17ae | 565 | continue; |
566 | } | |
567 | } else { | |
568 | /* | |
569 | * Triggered by MaxAge remover, so far. | |
570 | * NULL "inbr" means flooding starts from this node. | |
571 | */ | |
572 | if (IPV4_ADDR_SAME(&lsa->data->adv_router, | |
573 | &onbr->router_id)) { | |
574 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) | |
575 | zlog_debug( | |
9d51b28c TA |
576 | "%s: Skipping neighbor %s via %s -- lsah->adv_router == onbr.", |
577 | __func__, IF_NAME(oi), | |
578 | inet_ntop(AF_INET, | |
579 | &onbr->router_id, buf, | |
580 | sizeof(buf))); | |
d62a17ae | 581 | continue; |
582 | } | |
583 | } | |
718e3744 | 584 | |
d62a17ae | 585 | /* Add the new LSA to the Link state retransmission list |
586 | for the adjacency. The LSA will be retransmitted | |
587 | at intervals until an acknowledgment is seen from | |
588 | the neighbor. */ | |
589 | ospf_ls_retransmit_add(onbr, lsa); | |
590 | retx_flag = 1; | |
718e3744 | 591 | } |
d62a17ae | 592 | |
593 | /* If in the previous step, the LSA was NOT added to any of | |
594 | the Link state retransmission lists, there is no need to | |
595 | flood the LSA out the interface. */ | |
596 | if (retx_flag == 0) { | |
597 | return (inbr && inbr->oi == oi); | |
598 | } | |
599 | ||
600 | /* if we've received the lsa on this interface we need to perform | |
601 | additional checking */ | |
602 | if (inbr && (inbr->oi == oi)) { | |
603 | /* If the new LSA was received on this interface, and it was | |
604 | received from either the Designated Router or the Backup | |
605 | Designated Router, chances are that all the neighbors have | |
606 | received the LSA already. */ | |
607 | if (NBR_IS_DR(inbr) || NBR_IS_BDR(inbr)) { | |
608 | if (IS_DEBUG_OSPF_NSSA) | |
9d51b28c TA |
609 | zlog_debug("%s: DR/BDR NOT SEND to int %s (%s)", |
610 | __func__, IF_NAME(oi), | |
611 | ospf_get_name(oi->ospf)); | |
d62a17ae | 612 | return 1; |
613 | } | |
614 | ||
615 | /* If the new LSA was received on this interface, and the | |
616 | interface state is Backup, examine the next interface. The | |
617 | Designated Router will do the flooding on this interface. | |
618 | However, if the Designated Router fails the router will | |
619 | end up retransmitting the updates. */ | |
620 | ||
621 | if (oi->state == ISM_Backup) { | |
622 | if (IS_DEBUG_OSPF_NSSA) | |
623 | zlog_debug( | |
9d51b28c TA |
624 | "%s: ISM_Backup NOT SEND to int %s (%s)", |
625 | __func__, IF_NAME(oi), | |
626 | ospf_get_name(oi->ospf)); | |
d62a17ae | 627 | return 1; |
628 | } | |
718e3744 | 629 | } |
d62a17ae | 630 | |
631 | /* The LSA must be flooded out the interface. Send a Link State | |
632 | Update packet (including the new LSA as contents) out the | |
633 | interface. The LSA's LS age must be incremented by InfTransDelay | |
634 | (which must be > 0) when it is copied into the outgoing Link | |
635 | State Update packet (until the LS age field reaches the maximum | |
636 | value of MaxAge). */ | |
637 | /* XXX HASSO: Is this IS_DEBUG_OSPF_NSSA really correct? */ | |
638 | if (IS_DEBUG_OSPF_NSSA) | |
9d51b28c TA |
639 | zlog_debug("%s: DR/BDR sending upd to int %s (%s)", __func__, |
640 | IF_NAME(oi), ospf_get_name(oi->ospf)); | |
d62a17ae | 641 | |
642 | /* RFC2328 Section 13.3 | |
643 | On non-broadcast networks, separate Link State Update | |
644 | packets must be sent, as unicasts, to each adjacent neighbor | |
645 | (i.e., those in state Exchange or greater). The destination | |
646 | IP addresses for these packets are the neighbors' IP | |
647 | addresses. */ | |
648 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
d62a17ae | 649 | struct ospf_neighbor *nbr; |
650 | ||
651 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
652 | if ((nbr = rn->info) != NULL) | |
653 | if (nbr != oi->nbr_self | |
654 | && nbr->state >= NSM_Exchange) | |
655 | ospf_ls_upd_send_lsa( | |
656 | nbr, lsa, | |
657 | OSPF_SEND_PACKET_DIRECT); | |
658 | } else | |
659 | ospf_ls_upd_send_lsa(oi->nbr_self, lsa, | |
660 | OSPF_SEND_PACKET_INDIRECT); | |
661 | ||
662 | return 0; | |
718e3744 | 663 | } |
664 | ||
d62a17ae | 665 | int ospf_flood_through_area(struct ospf_area *area, struct ospf_neighbor *inbr, |
666 | struct ospf_lsa *lsa) | |
718e3744 | 667 | { |
d62a17ae | 668 | struct listnode *node, *nnode; |
669 | struct ospf_interface *oi; | |
670 | int lsa_ack_flag = 0; | |
671 | ||
9b50aa1f | 672 | assert(area); |
d62a17ae | 673 | /* All other types are specific to a single area (Area A). The |
674 | eligible interfaces are all those interfaces attaching to the | |
675 | Area A. If Area A is the backbone, this includes all the virtual | |
676 | links. */ | |
677 | for (ALL_LIST_ELEMENTS(area->oiflist, node, nnode, oi)) { | |
678 | if (area->area_id.s_addr != OSPF_AREA_BACKBONE | |
679 | && oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
680 | continue; | |
681 | ||
682 | if ((lsa->data->type == OSPF_OPAQUE_LINK_LSA) | |
683 | && (lsa->oi != oi)) { | |
684 | /* | |
685 | * Link local scoped Opaque-LSA should only be flooded | |
686 | * for the link on which the LSA has received. | |
687 | */ | |
688 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) | |
689 | zlog_debug( | |
690 | "Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)", | |
691 | (void *)lsa->oi, (void *)oi); | |
692 | continue; | |
693 | } | |
694 | ||
695 | if (ospf_flood_through_interface(oi, inbr, lsa)) | |
696 | lsa_ack_flag = 1; | |
697 | } | |
698 | ||
699 | return (lsa_ack_flag); | |
718e3744 | 700 | } |
701 | ||
d62a17ae | 702 | int ospf_flood_through_as(struct ospf *ospf, struct ospf_neighbor *inbr, |
703 | struct ospf_lsa *lsa) | |
718e3744 | 704 | { |
d62a17ae | 705 | struct listnode *node; |
706 | struct ospf_area *area; | |
707 | int lsa_ack_flag; | |
708 | ||
709 | lsa_ack_flag = 0; | |
710 | ||
711 | /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA ) | |
712 | ||
713 | Divert the Type-5 LSA's to all non-NSSA/STUB areas | |
714 | ||
715 | Divert the Type-7 LSA's to all NSSA areas | |
716 | ||
717 | AS-external-LSAs are flooded throughout the entire AS, with the | |
718 | exception of stub areas (see Section 3.6). The eligible | |
719 | interfaces are all the router's interfaces, excluding virtual | |
720 | links and those interfaces attaching to stub areas. */ | |
721 | ||
722 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) /* Translated from 7 */ | |
723 | if (IS_DEBUG_OSPF_NSSA) | |
724 | zlog_debug("Flood/AS: NSSA TRANSLATED LSA"); | |
725 | ||
726 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
727 | int continue_flag = 0; | |
728 | struct listnode *if_node; | |
729 | struct ospf_interface *oi; | |
730 | ||
731 | switch (area->external_routing) { | |
732 | /* Don't send AS externals into stub areas. Various types | |
733 | of support for partial stub areas can be implemented | |
734 | here. NSSA's will receive Type-7's that have areas | |
735 | matching the originl LSA. */ | |
736 | case OSPF_AREA_NSSA: /* Sending Type 5 or 7 into NSSA area */ | |
737 | /* Type-7, flood NSSA area */ | |
738 | if (lsa->data->type == OSPF_AS_NSSA_LSA | |
739 | && area == lsa->area) | |
740 | /* We will send it. */ | |
741 | continue_flag = 0; | |
742 | else | |
743 | continue_flag = 1; /* Skip this NSSA area for | |
744 | Type-5's et al */ | |
745 | break; | |
746 | ||
747 | case OSPF_AREA_TYPE_MAX: | |
748 | case OSPF_AREA_STUB: | |
749 | continue_flag = 1; /* Skip this area. */ | |
750 | break; | |
751 | ||
752 | case OSPF_AREA_DEFAULT: | |
753 | default: | |
754 | /* No Type-7 into normal area */ | |
755 | if (lsa->data->type == OSPF_AS_NSSA_LSA) | |
756 | continue_flag = 1; /* skip Type-7 */ | |
757 | else | |
758 | continue_flag = 0; /* Do this area. */ | |
759 | break; | |
760 | } | |
718e3744 | 761 | |
d62a17ae | 762 | /* Do continue for above switch. Saves a big if then mess */ |
763 | if (continue_flag) | |
764 | continue; /* main for-loop */ | |
718e3744 | 765 | |
d62a17ae | 766 | /* send to every interface in this area */ |
718e3744 | 767 | |
d62a17ae | 768 | for (ALL_LIST_ELEMENTS_RO(area->oiflist, if_node, oi)) { |
769 | /* Skip virtual links */ | |
770 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK) | |
771 | if (ospf_flood_through_interface(oi, inbr, | |
772 | lsa)) /* lsa */ | |
773 | lsa_ack_flag = 1; | |
774 | } | |
775 | } /* main area for-loop */ | |
718e3744 | 776 | |
d62a17ae | 777 | return (lsa_ack_flag); |
778 | } | |
718e3744 | 779 | |
d62a17ae | 780 | int ospf_flood_through(struct ospf *ospf, struct ospf_neighbor *inbr, |
781 | struct ospf_lsa *lsa) | |
782 | { | |
783 | int lsa_ack_flag = 0; | |
718e3744 | 784 | |
f573ec60 DS |
785 | /* Type-7 LSA's for NSSA are flooded throughout the AS here, and |
786 | upon return are updated in the LSDB for Type-7's. Later, | |
787 | re-fresh will re-send them (and also, if ABR, packet code will | |
788 | translate to Type-5's) | |
718e3744 | 789 | |
f573ec60 DS |
790 | As usual, Type-5 LSA's (if not DISCARDED because we are STUB or |
791 | NSSA) are flooded throughout the AS, and are updated in the | |
792 | global table. */ | |
d62a17ae | 793 | /* |
794 | * At the common sub-sub-function "ospf_flood_through_interface()", | |
795 | * a parameter "inbr" will be used to distinguish the called context | |
796 | * whether the given LSA was received from the neighbor, or the | |
797 | * flooding for the LSA starts from this node (e.g. the LSA was self- | |
798 | * originated, or the LSA is going to be flushed from routing domain). | |
799 | * | |
800 | * So, for consistency reasons, this function "ospf_flood_through()" | |
801 | * should also allow the usage that the given "inbr" parameter to be | |
802 | * NULL. If we do so, corresponding AREA parameter should be referred | |
803 | * by "lsa->area", instead of "inbr->oi->area". | |
804 | */ | |
805 | switch (lsa->data->type) { | |
806 | case OSPF_AS_EXTERNAL_LSA: /* Type-5 */ | |
807 | case OSPF_OPAQUE_AS_LSA: | |
808 | lsa_ack_flag = ospf_flood_through_as(ospf, inbr, lsa); | |
809 | break; | |
810 | /* Type-7 Only received within NSSA, then flooded */ | |
811 | case OSPF_AS_NSSA_LSA: | |
812 | /* Any P-bit was installed with the Type-7. */ | |
813 | ||
814 | if (IS_DEBUG_OSPF_NSSA) | |
815 | zlog_debug( | |
816 | "ospf_flood_through: LOCAL NSSA FLOOD of Type-7."); | |
817 | /* Fallthrough */ | |
818 | default: | |
819 | lsa_ack_flag = ospf_flood_through_area(lsa->area, inbr, lsa); | |
820 | break; | |
718e3744 | 821 | } |
718e3744 | 822 | |
d62a17ae | 823 | return (lsa_ack_flag); |
824 | } | |
6b0655a2 | 825 | |
718e3744 | 826 | |
827 | /* Management functions for neighbor's Link State Request list. */ | |
d62a17ae | 828 | void ospf_ls_request_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
718e3744 | 829 | { |
d62a17ae | 830 | /* |
831 | * We cannot make use of the newly introduced callback function | |
832 | * "lsdb->new_lsa_hook" to replace debug output below, just because | |
833 | * it seems no simple and smart way to pass neighbor information to | |
834 | * the common function "ospf_lsdb_add()" -- endo. | |
835 | */ | |
836 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) | |
96b663a3 | 837 | zlog_debug("RqstL(%lu)++, NBR(%pI4(%s)), LSA[%s]", |
d62a17ae | 838 | ospf_ls_request_count(nbr), |
96b663a3 | 839 | &nbr->router_id, |
868a0861 | 840 | ospf_get_name(nbr->oi->ospf), dump_lsa_key(lsa)); |
d62a17ae | 841 | |
842 | ospf_lsdb_add(&nbr->ls_req, lsa); | |
718e3744 | 843 | } |
844 | ||
d62a17ae | 845 | unsigned long ospf_ls_request_count(struct ospf_neighbor *nbr) |
718e3744 | 846 | { |
d62a17ae | 847 | return ospf_lsdb_count_all(&nbr->ls_req); |
718e3744 | 848 | } |
849 | ||
d62a17ae | 850 | int ospf_ls_request_isempty(struct ospf_neighbor *nbr) |
718e3744 | 851 | { |
d62a17ae | 852 | return ospf_lsdb_isempty(&nbr->ls_req); |
718e3744 | 853 | } |
854 | ||
855 | /* Remove LSA from neighbor's ls-request list. */ | |
d62a17ae | 856 | void ospf_ls_request_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
718e3744 | 857 | { |
d62a17ae | 858 | if (nbr->ls_req_last == lsa) { |
859 | ospf_lsa_unlock(&nbr->ls_req_last); | |
860 | nbr->ls_req_last = NULL; | |
861 | } | |
862 | ||
863 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */ | |
96b663a3 | 864 | zlog_debug("RqstL(%lu)--, NBR(%pI4(%s)), LSA[%s]", |
d62a17ae | 865 | ospf_ls_request_count(nbr), |
96b663a3 | 866 | &nbr->router_id, |
868a0861 | 867 | ospf_get_name(nbr->oi->ospf), dump_lsa_key(lsa)); |
d62a17ae | 868 | |
869 | ospf_lsdb_delete(&nbr->ls_req, lsa); | |
718e3744 | 870 | } |
871 | ||
872 | /* Remove all LSA from neighbor's ls-requenst list. */ | |
d62a17ae | 873 | void ospf_ls_request_delete_all(struct ospf_neighbor *nbr) |
718e3744 | 874 | { |
d62a17ae | 875 | ospf_lsa_unlock(&nbr->ls_req_last); |
876 | nbr->ls_req_last = NULL; | |
877 | ospf_lsdb_delete_all(&nbr->ls_req); | |
718e3744 | 878 | } |
879 | ||
880 | /* Lookup LSA from neighbor's ls-request list. */ | |
d62a17ae | 881 | struct ospf_lsa *ospf_ls_request_lookup(struct ospf_neighbor *nbr, |
882 | struct ospf_lsa *lsa) | |
718e3744 | 883 | { |
d62a17ae | 884 | return ospf_lsdb_lookup(&nbr->ls_req, lsa); |
718e3744 | 885 | } |
886 | ||
d62a17ae | 887 | struct ospf_lsa *ospf_ls_request_new(struct lsa_header *lsah) |
718e3744 | 888 | { |
d62a17ae | 889 | struct ospf_lsa *new; |
718e3744 | 890 | |
5b3d4186 | 891 | new = ospf_lsa_new_and_data(OSPF_LSA_HEADER_SIZE); |
d62a17ae | 892 | memcpy(new->data, lsah, OSPF_LSA_HEADER_SIZE); |
718e3744 | 893 | |
d62a17ae | 894 | return new; |
718e3744 | 895 | } |
896 | ||
6b0655a2 | 897 | |
718e3744 | 898 | /* Management functions for neighbor's ls-retransmit list. */ |
d62a17ae | 899 | unsigned long ospf_ls_retransmit_count(struct ospf_neighbor *nbr) |
718e3744 | 900 | { |
d62a17ae | 901 | return ospf_lsdb_count_all(&nbr->ls_rxmt); |
718e3744 | 902 | } |
903 | ||
d62a17ae | 904 | unsigned long ospf_ls_retransmit_count_self(struct ospf_neighbor *nbr, |
905 | int lsa_type) | |
718e3744 | 906 | { |
d62a17ae | 907 | return ospf_lsdb_count_self(&nbr->ls_rxmt, lsa_type); |
718e3744 | 908 | } |
909 | ||
d62a17ae | 910 | int ospf_ls_retransmit_isempty(struct ospf_neighbor *nbr) |
718e3744 | 911 | { |
d62a17ae | 912 | return ospf_lsdb_isempty(&nbr->ls_rxmt); |
718e3744 | 913 | } |
914 | ||
915 | /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */ | |
d62a17ae | 916 | void ospf_ls_retransmit_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
718e3744 | 917 | { |
d62a17ae | 918 | struct ospf_lsa *old; |
718e3744 | 919 | |
d62a17ae | 920 | old = ospf_ls_retransmit_lookup(nbr, lsa); |
718e3744 | 921 | |
d62a17ae | 922 | if (ospf_lsa_more_recent(old, lsa) < 0) { |
923 | if (old) { | |
924 | old->retransmit_counter--; | |
868a0861 | 925 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) |
96b663a3 | 926 | zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]", |
868a0861 | 927 | ospf_ls_retransmit_count(nbr), |
96b663a3 | 928 | &nbr->router_id, |
868a0861 DS |
929 | ospf_get_name(nbr->oi->ospf), |
930 | dump_lsa_key(old)); | |
d62a17ae | 931 | ospf_lsdb_delete(&nbr->ls_rxmt, old); |
932 | } | |
933 | lsa->retransmit_counter++; | |
934 | /* | |
935 | * We cannot make use of the newly introduced callback function | |
936 | * "lsdb->new_lsa_hook" to replace debug output below, just | |
937 | * because | |
938 | * it seems no simple and smart way to pass neighbor information | |
939 | * to | |
940 | * the common function "ospf_lsdb_add()" -- endo. | |
941 | */ | |
942 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) | |
96b663a3 | 943 | zlog_debug("RXmtL(%lu)++, NBR(%pI4(%s)), LSA[%s]", |
d62a17ae | 944 | ospf_ls_retransmit_count(nbr), |
96b663a3 | 945 | &nbr->router_id, |
868a0861 | 946 | ospf_get_name(nbr->oi->ospf), |
d62a17ae | 947 | dump_lsa_key(lsa)); |
948 | ospf_lsdb_add(&nbr->ls_rxmt, lsa); | |
718e3744 | 949 | } |
718e3744 | 950 | } |
951 | ||
952 | /* Remove LSA from neibghbor's ls-retransmit list. */ | |
d62a17ae | 953 | void ospf_ls_retransmit_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa) |
718e3744 | 954 | { |
d62a17ae | 955 | if (ospf_ls_retransmit_lookup(nbr, lsa)) { |
956 | lsa->retransmit_counter--; | |
957 | if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */ | |
96b663a3 | 958 | zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]", |
d62a17ae | 959 | ospf_ls_retransmit_count(nbr), |
96b663a3 | 960 | &nbr->router_id, |
868a0861 | 961 | ospf_get_name(nbr->oi->ospf), |
d62a17ae | 962 | dump_lsa_key(lsa)); |
963 | ospf_lsdb_delete(&nbr->ls_rxmt, lsa); | |
964 | } | |
718e3744 | 965 | } |
966 | ||
967 | /* Clear neighbor's ls-retransmit list. */ | |
d62a17ae | 968 | void ospf_ls_retransmit_clear(struct ospf_neighbor *nbr) |
718e3744 | 969 | { |
d62a17ae | 970 | struct ospf_lsdb *lsdb; |
971 | int i; | |
718e3744 | 972 | |
d62a17ae | 973 | lsdb = &nbr->ls_rxmt; |
718e3744 | 974 | |
d62a17ae | 975 | for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++) { |
976 | struct route_table *table = lsdb->type[i].db; | |
977 | struct route_node *rn; | |
978 | struct ospf_lsa *lsa; | |
718e3744 | 979 | |
d62a17ae | 980 | for (rn = route_top(table); rn; rn = route_next(rn)) |
981 | if ((lsa = rn->info) != NULL) | |
982 | ospf_ls_retransmit_delete(nbr, lsa); | |
983 | } | |
718e3744 | 984 | |
d62a17ae | 985 | ospf_lsa_unlock(&nbr->ls_req_last); |
986 | nbr->ls_req_last = NULL; | |
718e3744 | 987 | } |
988 | ||
989 | /* Lookup LSA from neighbor's ls-retransmit list. */ | |
d62a17ae | 990 | struct ospf_lsa *ospf_ls_retransmit_lookup(struct ospf_neighbor *nbr, |
991 | struct ospf_lsa *lsa) | |
718e3744 | 992 | { |
d62a17ae | 993 | return ospf_lsdb_lookup(&nbr->ls_rxmt, lsa); |
718e3744 | 994 | } |
995 | ||
d62a17ae | 996 | static void ospf_ls_retransmit_delete_nbr_if(struct ospf_interface *oi, |
997 | struct ospf_lsa *lsa) | |
718e3744 | 998 | { |
d62a17ae | 999 | struct route_node *rn; |
1000 | struct ospf_neighbor *nbr; | |
1001 | struct ospf_lsa *lsr; | |
1002 | ||
1003 | if (ospf_if_is_enable(oi)) | |
1004 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
1005 | /* If LSA find in LS-retransmit list, then remove it. */ | |
1006 | if ((nbr = rn->info) != NULL) { | |
1007 | lsr = ospf_ls_retransmit_lookup(nbr, lsa); | |
1008 | ||
1009 | /* If LSA find in ls-retransmit list, remove it. | |
1010 | */ | |
1011 | if (lsr != NULL | |
1012 | && lsr->data->ls_seqnum | |
1013 | == lsa->data->ls_seqnum) | |
1014 | ospf_ls_retransmit_delete(nbr, lsr); | |
1015 | } | |
718e3744 | 1016 | } |
1017 | ||
d62a17ae | 1018 | void ospf_ls_retransmit_delete_nbr_area(struct ospf_area *area, |
1019 | struct ospf_lsa *lsa) | |
718e3744 | 1020 | { |
d62a17ae | 1021 | struct listnode *node, *nnode; |
1022 | struct ospf_interface *oi; | |
718e3744 | 1023 | |
d62a17ae | 1024 | for (ALL_LIST_ELEMENTS(area->oiflist, node, nnode, oi)) |
1025 | ospf_ls_retransmit_delete_nbr_if(oi, lsa); | |
68980084 | 1026 | } |
718e3744 | 1027 | |
d62a17ae | 1028 | void ospf_ls_retransmit_delete_nbr_as(struct ospf *ospf, struct ospf_lsa *lsa) |
68980084 | 1029 | { |
d62a17ae | 1030 | struct listnode *node, *nnode; |
1031 | struct ospf_interface *oi; | |
718e3744 | 1032 | |
d62a17ae | 1033 | for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi)) |
1034 | ospf_ls_retransmit_delete_nbr_if(oi, lsa); | |
718e3744 | 1035 | } |
1036 | ||
6b0655a2 | 1037 | |
d62a17ae | 1038 | /* Sets ls_age to MaxAge and floods throu the area. |
96fad84a | 1039 | When we implement ASE routing, there will be another function |
718e3744 | 1040 | flushing an LSA from the whole domain. */ |
d62a17ae | 1041 | void ospf_lsa_flush_area(struct ospf_lsa *lsa, struct ospf_area *area) |
718e3744 | 1042 | { |
d62a17ae | 1043 | /* Reset the lsa origination time such that it gives |
1044 | more time for the ACK to be received and avoid | |
1045 | retransmissions */ | |
1046 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); | |
046460a1 | 1047 | if (IS_DEBUG_OSPF_EVENT) |
96b663a3 MS |
1048 | zlog_debug("%s: MAXAGE set to LSA %pI4", __func__, |
1049 | &lsa->data->id); | |
d62a17ae | 1050 | monotime(&lsa->tv_recv); |
1051 | lsa->tv_orig = lsa->tv_recv; | |
1052 | ospf_flood_through_area(area, NULL, lsa); | |
1053 | ospf_lsa_maxage(area->ospf, lsa); | |
718e3744 | 1054 | } |
1055 | ||
d62a17ae | 1056 | void ospf_lsa_flush_as(struct ospf *ospf, struct ospf_lsa *lsa) |
718e3744 | 1057 | { |
d62a17ae | 1058 | /* Reset the lsa origination time such that it gives |
1059 | more time for the ACK to be received and avoid | |
1060 | retransmissions */ | |
1061 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); | |
1062 | monotime(&lsa->tv_recv); | |
1063 | lsa->tv_orig = lsa->tv_recv; | |
1064 | ospf_flood_through_as(ospf, NULL, lsa); | |
1065 | ospf_lsa_maxage(ospf, lsa); | |
718e3744 | 1066 | } |
02d942c9 | 1067 | |
d62a17ae | 1068 | void ospf_lsa_flush(struct ospf *ospf, struct ospf_lsa *lsa) |
02d942c9 | 1069 | { |
d62a17ae | 1070 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); |
1071 | ||
1072 | switch (lsa->data->type) { | |
1073 | case OSPF_ROUTER_LSA: | |
1074 | case OSPF_NETWORK_LSA: | |
1075 | case OSPF_SUMMARY_LSA: | |
1076 | case OSPF_ASBR_SUMMARY_LSA: | |
1077 | case OSPF_AS_NSSA_LSA: | |
1078 | case OSPF_OPAQUE_LINK_LSA: | |
1079 | case OSPF_OPAQUE_AREA_LSA: | |
1080 | ospf_lsa_flush_area(lsa, lsa->area); | |
1081 | break; | |
1082 | case OSPF_AS_EXTERNAL_LSA: | |
1083 | case OSPF_OPAQUE_AS_LSA: | |
1084 | ospf_lsa_flush_as(ospf, lsa); | |
1085 | break; | |
1086 | default: | |
1087 | zlog_info("%s: Unknown LSA type %u", __func__, lsa->data->type); | |
1088 | break; | |
1089 | } | |
02d942c9 | 1090 | } |