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