2 * OSPF Flooding -- RFC2328 Section 13.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
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.
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.
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
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"
51 extern struct zclient
*zclient
;
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
56 static void ospf_flood_delayed_lsa_ack(struct ospf_neighbor
*inbr
,
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 */
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 */
70 /* Deal with router as BDR */
71 if (inbr
->oi
->state
== ISM_Backup
&& !NBR_IS_DR(inbr
))
74 /* Schedule a delayed LSA Ack to be sent */
75 listnode_add(inbr
->oi
->ls_ack
,
76 ospf_lsa_lock(lsa
)); /* delayed LSA Ack */
79 /* Check LSA is related to external info. */
80 struct external_info
*ospf_external_info_check(struct ospf_lsa
*lsa
)
82 struct as_external_lsa
*al
;
84 struct route_node
*rn
;
87 al
= (struct as_external_lsa
*)lsa
->data
;
90 p
.prefix
= lsa
->data
->id
;
91 p
.prefixlen
= ip_masklen(al
->mask
);
93 for (type
= 0; type
<= ZEBRA_ROUTE_MAX
; type
++) {
98 ? vrf_bitmap_check(zclient
->default_information
,
100 : (zclient
->mi_redist
[AFI_IP
][type
].enabled
102 zclient
->redist
[AFI_IP
][type
],
104 // Pending: check for MI above.
106 struct list
*ext_list
;
107 struct listnode
*node
;
108 struct ospf_external
*ext
;
110 ext_list
= om
->external
[type
];
114 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
116 if (ext
->external_info
)
117 rn
= route_node_lookup(
119 (struct prefix
*)&p
);
121 route_unlock_node(rn
);
122 if (rn
->info
!= NULL
)
123 return (struct external_info
*)
133 static void ospf_process_self_originated_lsa(struct ospf
*ospf
,
134 struct ospf_lsa
*new,
135 struct ospf_area
*area
)
137 struct ospf_interface
*oi
;
138 struct external_info
*ei
;
139 struct listnode
*node
;
141 if (IS_DEBUG_OSPF_EVENT
)
143 "LSA[Type%d:%s]: Process self-originated LSA seq 0x%x",
144 new->data
->type
, inet_ntoa(new->data
->id
),
145 ntohl(new->data
->ls_seqnum
));
147 /* If we're here, we installed a self-originated LSA that we received
148 from a neighbor, i.e. it's more recent. We must see whether we want
150 If yes, we should use this LSA's sequence number and reoriginate
152 if not --- we must flush this LSA from the domain. */
153 switch (new->data
->type
) {
154 case OSPF_ROUTER_LSA
:
155 /* Originate a new instance and schedule flooding */
156 if (area
->router_lsa_self
)
157 area
->router_lsa_self
->data
->ls_seqnum
=
158 new->data
->ls_seqnum
;
159 ospf_router_lsa_update_area(area
);
161 case OSPF_NETWORK_LSA
:
162 case OSPF_OPAQUE_LINK_LSA
:
163 /* We must find the interface the LSA could belong to.
164 If the interface is no more a broadcast type or we are no
166 the DR, we flush the LSA otherwise -- create the new instance
168 schedule flooding. */
170 /* Look through all interfaces, not just area, since interface
171 could be moved from one area to another. */
172 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
173 /* These are sanity check. */
174 if (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
,
177 || oi
->type
!= OSPF_IFTYPE_BROADCAST
178 || !IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
,
180 ospf_schedule_lsa_flush_area(area
, new);
184 if (new->data
->type
== OSPF_OPAQUE_LINK_LSA
) {
185 ospf_opaque_lsa_refresh(new);
189 if (oi
->network_lsa_self
)
190 oi
->network_lsa_self
->data
->ls_seqnum
=
191 new->data
->ls_seqnum
;
192 /* Schedule network-LSA origination. */
193 ospf_network_lsa_update(oi
);
197 case OSPF_SUMMARY_LSA
:
198 case OSPF_ASBR_SUMMARY_LSA
:
199 ospf_schedule_abr_task(ospf
);
201 case OSPF_AS_EXTERNAL_LSA
:
202 case OSPF_AS_NSSA_LSA
:
203 if ((new->data
->type
== OSPF_AS_EXTERNAL_LSA
)
204 && CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
)) {
205 ospf_translated_nssa_refresh(ospf
, NULL
, new);
208 ei
= ospf_external_info_check(new);
210 ospf_external_lsa_refresh(ospf
, new, ei
,
213 ospf_lsa_flush_as(ospf
, new);
215 case OSPF_OPAQUE_AREA_LSA
:
216 ospf_opaque_lsa_refresh(new);
218 case OSPF_OPAQUE_AS_LSA
:
219 ospf_opaque_lsa_refresh(new);
220 /* Reconsideration may needed. */ /* XXX */
227 /* OSPF LSA flooding -- RFC2328 Section 13.(5). */
229 /* Now Updated for NSSA operation, as follows:
232 Type-5's have no change. Blocked to STUB or NSSA.
234 Type-7's can be received, and if a DR
235 they will also flood the local NSSA Area as Type-7's
237 If a Self-Originated LSA (now an ASBR),
238 The LSDB will be updated as Type-5's, (for continual re-fresh)
240 If an NSSA-IR it is installed/flooded as Type-7, P-bit on.
241 if an NSSA-ABR it is installed/flooded as Type-7, P-bit off.
243 Later, during the ABR TASK, if the ABR is the Elected NSSA
244 translator, then All Type-7s (with P-bit ON) are Translated to
245 Type-5's and flooded to all non-NSSA/STUB areas.
247 During ASE Calculations,
248 non-ABRs calculate external routes from Type-7's
249 ABRs calculate external routes from Type-5's and non-self Type-7s
251 int ospf_flood(struct ospf
*ospf
, struct ospf_neighbor
*nbr
,
252 struct ospf_lsa
*current
, struct ospf_lsa
*new)
254 struct ospf_interface
*oi
;
257 /* Type-7 LSA's will be flooded throughout their native NSSA area,
258 but will also be flooded as Type-5's into ABR capable links. */
260 if (IS_DEBUG_OSPF_EVENT
)
262 "LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
263 inet_ntoa(nbr
->router_id
),
264 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
),
265 (void *)current
, dump_lsa_key(new));
269 /* If there is already a database copy, and if the
270 database copy was received via flooding and installed less
271 than MinLSArrival seconds ago, discard the new LSA
272 (without acknowledging it). */
273 if (current
!= NULL
) /* -- endo. */
275 if (IS_LSA_SELF(current
)
276 && (ntohs(current
->data
->ls_age
) == 0
277 && ntohl(current
->data
->ls_seqnum
)
278 == OSPF_INITIAL_SEQUENCE_NUMBER
)) {
279 if (IS_DEBUG_OSPF_EVENT
)
281 "LSA[Flooding]: Got a self-originated LSA, "
282 "while local one is initial instance.");
283 ; /* Accept this LSA for quick LSDB resynchronization.
285 } else if (monotime_since(¤t
->tv_recv
, NULL
)
286 < ospf
->min_ls_arrival
* 1000LL) {
287 if (IS_DEBUG_OSPF_EVENT
)
289 "LSA[Flooding]: LSA is received recently.");
294 /* Flood the new LSA out some subset of the router's interfaces.
295 In some cases (e.g., the state of the receiving interface is
296 DR and the LSA was received from a router other than the
297 Backup DR) the LSA will be flooded back out the receiving
299 lsa_ack_flag
= ospf_flood_through(ospf
, nbr
, new);
301 /* Remove the current database copy from all neighbors' Link state
302 retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
303 ^^^^^^^^^^^^^^^^^^^^^^^
305 All other (even NSSA's) do have area ID. */
307 switch (current
->data
->type
) {
308 case OSPF_AS_EXTERNAL_LSA
:
309 case OSPF_OPAQUE_AS_LSA
:
310 ospf_ls_retransmit_delete_nbr_as(ospf
, current
);
313 ospf_ls_retransmit_delete_nbr_area(nbr
->oi
->area
,
319 /* Do some internal house keeping that is needed here */
320 SET_FLAG(new->flags
, OSPF_LSA_RECEIVED
);
321 ospf_lsa_is_self_originated(ospf
, new); /* Let it set the flag */
323 /* Install the new LSA in the link state database
324 (replacing the current database copy). This may cause the
325 routing table calculation to be scheduled. In addition,
326 timestamp the new LSA with the current time. The flooding
327 procedure cannot overwrite the newly installed LSA until
328 MinLSArrival seconds have elapsed. */
330 if (!(new = ospf_lsa_install(ospf
, nbr
->oi
, new)))
331 return -1; /* unknown LSA type or any other error condition */
333 /* Acknowledge the receipt of the LSA by sending a Link State
334 Acknowledgment packet back out the receiving interface. */
336 ospf_flood_delayed_lsa_ack(nbr
, new);
338 /* If this new LSA indicates that it was originated by the
339 receiving router itself, the router must take special action,
340 either updating the LSA or in some cases flushing it from
341 the routing domain. */
342 if (ospf_lsa_is_self_originated(ospf
, new))
343 ospf_process_self_originated_lsa(ospf
, new, oi
->area
);
345 /* Update statistics value for OSPF-MIB. */
346 ospf
->rx_lsa_count
++;
351 /* OSPF LSA flooding -- RFC2328 Section 13.3. */
352 static int ospf_flood_through_interface(struct ospf_interface
*oi
,
353 struct ospf_neighbor
*inbr
,
354 struct ospf_lsa
*lsa
)
356 struct ospf_neighbor
*onbr
;
357 struct route_node
*rn
;
360 if (IS_DEBUG_OSPF_EVENT
)
362 "ospf_flood_through_interface(): "
363 "considering int %s, INBR(%s), LSA[%s]",
364 IF_NAME(oi
), inbr
? inet_ntoa(inbr
->router_id
) : "NULL",
367 if (!ospf_if_is_enable(oi
))
370 /* Remember if new LSA is aded to a retransmit list. */
373 /* Each of the neighbors attached to this interface are examined,
374 to determine whether they must receive the new LSA. The following
375 steps are executed for each neighbor: */
376 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
377 struct ospf_lsa
*ls_req
;
379 if (rn
->info
== NULL
)
383 if (IS_DEBUG_OSPF_EVENT
)
385 "ospf_flood_through_interface(): considering nbr %s (%s)",
386 inet_ntoa(onbr
->router_id
),
387 lookup_msg(ospf_nsm_state_msg
, onbr
->state
,
390 /* If the neighbor is in a lesser state than Exchange, it
391 does not participate in flooding, and the next neighbor
392 should be examined. */
393 if (onbr
->state
< NSM_Exchange
)
396 /* If the adjacency is not yet full (neighbor state is
397 Exchange or Loading), examine the Link state request
398 list associated with this adjacency. If there is an
399 instance of the new LSA on the list, it indicates that
400 the neighboring router has an instance of the LSA
401 already. Compare the new LSA to the neighbor's copy: */
402 if (onbr
->state
< NSM_Full
) {
403 if (IS_DEBUG_OSPF_EVENT
)
405 "ospf_flood_through_interface(): nbr adj is not Full");
406 ls_req
= ospf_ls_request_lookup(onbr
, lsa
);
407 if (ls_req
!= NULL
) {
410 ret
= ospf_lsa_more_recent(ls_req
, lsa
);
411 /* The new LSA is less recent. */
414 /* The two copies are the same instance, then
416 the LSA from the Link state request list. */
418 ospf_ls_request_delete(onbr
, ls_req
);
419 ospf_check_nbr_loading(onbr
);
422 /* The new LSA is more recent. Delete the LSA
423 from the Link state request list. */
425 ospf_ls_request_delete(onbr
, ls_req
);
426 ospf_check_nbr_loading(onbr
);
431 if (IS_OPAQUE_LSA(lsa
->data
->type
)) {
432 if (!CHECK_FLAG(onbr
->options
, OSPF_OPTION_O
)) {
433 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
435 "Skip this neighbor: Not Opaque-capable.");
440 /* If the new LSA was received from this neighbor,
441 examine the next neighbor. */
442 #ifdef ORIGINAL_CODING
444 if (IPV4_ADDR_SAME(&inbr
->router_id
, &onbr
->router_id
))
446 #else /* ORIGINAL_CODING */
449 * Triggered by LSUpd message parser "ospf_ls_upd ()".
450 * E.g., all LSAs handling here is received via network.
452 if (IPV4_ADDR_SAME(&inbr
->router_id
,
454 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
456 "Skip this neighbor: inbr == onbr");
461 * Triggered by MaxAge remover, so far.
462 * NULL "inbr" means flooding starts from this node.
464 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
466 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
468 "Skip this neighbor: lsah->adv_router == onbr");
472 #endif /* ORIGINAL_CODING */
474 /* Add the new LSA to the Link state retransmission list
475 for the adjacency. The LSA will be retransmitted
476 at intervals until an acknowledgment is seen from
478 ospf_ls_retransmit_add(onbr
, lsa
);
482 /* If in the previous step, the LSA was NOT added to any of
483 the Link state retransmission lists, there is no need to
484 flood the LSA out the interface. */
485 if (retx_flag
== 0) {
486 return (inbr
&& inbr
->oi
== oi
);
489 /* if we've received the lsa on this interface we need to perform
490 additional checking */
491 if (inbr
&& (inbr
->oi
== oi
)) {
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 if (IS_DEBUG_OSPF_NSSA
)
499 "ospf_flood_through_interface(): "
500 "DR/BDR NOT SEND to int %s",
505 /* If the new LSA was received on this interface, and the
506 interface state is Backup, examine the next interface. The
507 Designated Router will do the flooding on this interface.
508 However, if the Designated Router fails the router will
509 end up retransmitting the updates. */
511 if (oi
->state
== ISM_Backup
) {
512 if (IS_DEBUG_OSPF_NSSA
)
514 "ospf_flood_through_interface(): "
515 "ISM_Backup NOT SEND to int %s",
521 /* The LSA must be flooded out the interface. Send a Link State
522 Update packet (including the new LSA as contents) out the
523 interface. The LSA's LS age must be incremented by InfTransDelay
524 (which must be > 0) when it is copied into the outgoing Link
525 State Update packet (until the LS age field reaches the maximum
527 /* XXX HASSO: Is this IS_DEBUG_OSPF_NSSA really correct? */
528 if (IS_DEBUG_OSPF_NSSA
)
530 "ospf_flood_through_interface(): "
531 "DR/BDR sending upd to int %s",
534 /* RFC2328 Section 13.3
535 On non-broadcast networks, separate Link State Update
536 packets must be sent, as unicasts, to each adjacent neighbor
537 (i.e., those in state Exchange or greater). The destination
538 IP addresses for these packets are the neighbors' IP
540 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
541 struct route_node
*rn
;
542 struct ospf_neighbor
*nbr
;
544 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
545 if ((nbr
= rn
->info
) != NULL
)
546 if (nbr
!= oi
->nbr_self
547 && nbr
->state
>= NSM_Exchange
)
548 ospf_ls_upd_send_lsa(
550 OSPF_SEND_PACKET_DIRECT
);
552 ospf_ls_upd_send_lsa(oi
->nbr_self
, lsa
,
553 OSPF_SEND_PACKET_INDIRECT
);
558 int ospf_flood_through_area(struct ospf_area
*area
, struct ospf_neighbor
*inbr
,
559 struct ospf_lsa
*lsa
)
561 struct listnode
*node
, *nnode
;
562 struct ospf_interface
*oi
;
563 int lsa_ack_flag
= 0;
565 /* All other types are specific to a single area (Area A). The
566 eligible interfaces are all those interfaces attaching to the
567 Area A. If Area A is the backbone, this includes all the virtual
569 for (ALL_LIST_ELEMENTS(area
->oiflist
, node
, nnode
, oi
)) {
570 if (area
->area_id
.s_addr
!= OSPF_AREA_BACKBONE
571 && oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
574 if ((lsa
->data
->type
== OSPF_OPAQUE_LINK_LSA
)
575 && (lsa
->oi
!= oi
)) {
577 * Link local scoped Opaque-LSA should only be flooded
578 * for the link on which the LSA has received.
580 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
582 "Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)",
583 (void *)lsa
->oi
, (void *)oi
);
587 if (ospf_flood_through_interface(oi
, inbr
, lsa
))
591 return (lsa_ack_flag
);
594 int ospf_flood_through_as(struct ospf
*ospf
, struct ospf_neighbor
*inbr
,
595 struct ospf_lsa
*lsa
)
597 struct listnode
*node
;
598 struct ospf_area
*area
;
603 /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
605 Divert the Type-5 LSA's to all non-NSSA/STUB areas
607 Divert the Type-7 LSA's to all NSSA areas
609 AS-external-LSAs are flooded throughout the entire AS, with the
610 exception of stub areas (see Section 3.6). The eligible
611 interfaces are all the router's interfaces, excluding virtual
612 links and those interfaces attaching to stub areas. */
614 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) /* Translated from 7 */
615 if (IS_DEBUG_OSPF_NSSA
)
616 zlog_debug("Flood/AS: NSSA TRANSLATED LSA");
618 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
619 int continue_flag
= 0;
620 struct listnode
*if_node
;
621 struct ospf_interface
*oi
;
623 switch (area
->external_routing
) {
624 /* Don't send AS externals into stub areas. Various types
625 of support for partial stub areas can be implemented
626 here. NSSA's will receive Type-7's that have areas
627 matching the originl LSA. */
628 case OSPF_AREA_NSSA
: /* Sending Type 5 or 7 into NSSA area */
629 /* Type-7, flood NSSA area */
630 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
631 && area
== lsa
->area
)
632 /* We will send it. */
635 continue_flag
= 1; /* Skip this NSSA area for
639 case OSPF_AREA_TYPE_MAX
:
641 continue_flag
= 1; /* Skip this area. */
644 case OSPF_AREA_DEFAULT
:
646 /* No Type-7 into normal area */
647 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
648 continue_flag
= 1; /* skip Type-7 */
650 continue_flag
= 0; /* Do this area. */
654 /* Do continue for above switch. Saves a big if then mess */
656 continue; /* main for-loop */
658 /* send to every interface in this area */
660 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, if_node
, oi
)) {
661 /* Skip virtual links */
662 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
663 if (ospf_flood_through_interface(oi
, inbr
,
667 } /* main area for-loop */
669 return (lsa_ack_flag
);
672 int ospf_flood_through(struct ospf
*ospf
, struct ospf_neighbor
*inbr
,
673 struct ospf_lsa
*lsa
)
675 int lsa_ack_flag
= 0;
677 /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
678 upon return are updated in the LSDB for Type-7's. Later,
679 re-fresh will re-send them (and also, if ABR, packet code will
680 translate to Type-5's)
682 As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
683 NSSA) are flooded throughout the AS, and are updated in the
685 #ifdef ORIGINAL_CODING
686 switch (lsa
->data
->type
) {
687 case OSPF_ROUTER_LSA
:
688 case OSPF_NETWORK_LSA
:
689 case OSPF_SUMMARY_LSA
:
690 case OSPF_ASBR_SUMMARY_LSA
:
691 case OSPF_OPAQUE_LINK_LSA
: /* ospf_flood_through_interface ? */
692 case OSPF_OPAQUE_AREA_LSA
:
694 ospf_flood_through_area(inbr
->oi
->area
, inbr
, lsa
);
696 case OSPF_AS_EXTERNAL_LSA
: /* Type-5 */
697 case OSPF_OPAQUE_AS_LSA
:
698 lsa_ack_flag
= ospf_flood_through_as(ospf
, inbr
, lsa
);
700 /* Type-7 Only received within NSSA, then flooded */
701 case OSPF_AS_NSSA_LSA
:
702 /* Any P-bit was installed with the Type-7. */
704 ospf_flood_through_area(inbr
->oi
->area
, inbr
, lsa
);
706 if (IS_DEBUG_OSPF_NSSA
)
708 "ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
713 #else /* ORIGINAL_CODING */
715 * At the common sub-sub-function "ospf_flood_through_interface()",
716 * a parameter "inbr" will be used to distinguish the called context
717 * whether the given LSA was received from the neighbor, or the
718 * flooding for the LSA starts from this node (e.g. the LSA was self-
719 * originated, or the LSA is going to be flushed from routing domain).
721 * So, for consistency reasons, this function "ospf_flood_through()"
722 * should also allow the usage that the given "inbr" parameter to be
723 * NULL. If we do so, corresponding AREA parameter should be referred
724 * by "lsa->area", instead of "inbr->oi->area".
726 switch (lsa
->data
->type
) {
727 case OSPF_AS_EXTERNAL_LSA
: /* Type-5 */
728 case OSPF_OPAQUE_AS_LSA
:
729 lsa_ack_flag
= ospf_flood_through_as(ospf
, inbr
, lsa
);
731 /* Type-7 Only received within NSSA, then flooded */
732 case OSPF_AS_NSSA_LSA
:
733 /* Any P-bit was installed with the Type-7. */
735 if (IS_DEBUG_OSPF_NSSA
)
737 "ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
740 lsa_ack_flag
= ospf_flood_through_area(lsa
->area
, inbr
, lsa
);
743 #endif /* ORIGINAL_CODING */
745 return (lsa_ack_flag
);
749 /* Management functions for neighbor's Link State Request list. */
750 void ospf_ls_request_add(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
753 * We cannot make use of the newly introduced callback function
754 * "lsdb->new_lsa_hook" to replace debug output below, just because
755 * it seems no simple and smart way to pass neighbor information to
756 * the common function "ospf_lsdb_add()" -- endo.
758 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
759 zlog_debug("RqstL(%lu)++, NBR(%s), LSA[%s]",
760 ospf_ls_request_count(nbr
),
761 inet_ntoa(nbr
->router_id
), dump_lsa_key(lsa
));
763 ospf_lsdb_add(&nbr
->ls_req
, lsa
);
766 unsigned long ospf_ls_request_count(struct ospf_neighbor
*nbr
)
768 return ospf_lsdb_count_all(&nbr
->ls_req
);
771 int ospf_ls_request_isempty(struct ospf_neighbor
*nbr
)
773 return ospf_lsdb_isempty(&nbr
->ls_req
);
776 /* Remove LSA from neighbor's ls-request list. */
777 void ospf_ls_request_delete(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
779 if (nbr
->ls_req_last
== lsa
) {
780 ospf_lsa_unlock(&nbr
->ls_req_last
);
781 nbr
->ls_req_last
= NULL
;
784 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
)) /* -- endo. */
785 zlog_debug("RqstL(%lu)--, NBR(%s), LSA[%s]",
786 ospf_ls_request_count(nbr
),
787 inet_ntoa(nbr
->router_id
), dump_lsa_key(lsa
));
789 ospf_lsdb_delete(&nbr
->ls_req
, lsa
);
792 /* Remove all LSA from neighbor's ls-requenst list. */
793 void ospf_ls_request_delete_all(struct ospf_neighbor
*nbr
)
795 ospf_lsa_unlock(&nbr
->ls_req_last
);
796 nbr
->ls_req_last
= NULL
;
797 ospf_lsdb_delete_all(&nbr
->ls_req
);
800 /* Lookup LSA from neighbor's ls-request list. */
801 struct ospf_lsa
*ospf_ls_request_lookup(struct ospf_neighbor
*nbr
,
802 struct ospf_lsa
*lsa
)
804 return ospf_lsdb_lookup(&nbr
->ls_req
, lsa
);
807 struct ospf_lsa
*ospf_ls_request_new(struct lsa_header
*lsah
)
809 struct ospf_lsa
*new;
811 new = ospf_lsa_new();
812 new->data
= ospf_lsa_data_new(OSPF_LSA_HEADER_SIZE
);
813 memcpy(new->data
, lsah
, OSPF_LSA_HEADER_SIZE
);
819 /* Management functions for neighbor's ls-retransmit list. */
820 unsigned long ospf_ls_retransmit_count(struct ospf_neighbor
*nbr
)
822 return ospf_lsdb_count_all(&nbr
->ls_rxmt
);
825 unsigned long ospf_ls_retransmit_count_self(struct ospf_neighbor
*nbr
,
828 return ospf_lsdb_count_self(&nbr
->ls_rxmt
, lsa_type
);
831 int ospf_ls_retransmit_isempty(struct ospf_neighbor
*nbr
)
833 return ospf_lsdb_isempty(&nbr
->ls_rxmt
);
836 /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
837 void ospf_ls_retransmit_add(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
839 struct ospf_lsa
*old
;
841 old
= ospf_ls_retransmit_lookup(nbr
, lsa
);
843 if (ospf_lsa_more_recent(old
, lsa
) < 0) {
845 old
->retransmit_counter
--;
846 ospf_lsdb_delete(&nbr
->ls_rxmt
, old
);
848 lsa
->retransmit_counter
++;
850 * We cannot make use of the newly introduced callback function
851 * "lsdb->new_lsa_hook" to replace debug output below, just
853 * it seems no simple and smart way to pass neighbor information
855 * the common function "ospf_lsdb_add()" -- endo.
857 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
858 zlog_debug("RXmtL(%lu)++, NBR(%s), LSA[%s]",
859 ospf_ls_retransmit_count(nbr
),
860 inet_ntoa(nbr
->router_id
),
862 ospf_lsdb_add(&nbr
->ls_rxmt
, lsa
);
866 /* Remove LSA from neibghbor's ls-retransmit list. */
867 void ospf_ls_retransmit_delete(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
869 if (ospf_ls_retransmit_lookup(nbr
, lsa
)) {
870 lsa
->retransmit_counter
--;
871 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
)) /* -- endo. */
872 zlog_debug("RXmtL(%lu)--, NBR(%s), LSA[%s]",
873 ospf_ls_retransmit_count(nbr
),
874 inet_ntoa(nbr
->router_id
),
876 ospf_lsdb_delete(&nbr
->ls_rxmt
, lsa
);
880 /* Clear neighbor's ls-retransmit list. */
881 void ospf_ls_retransmit_clear(struct ospf_neighbor
*nbr
)
883 struct ospf_lsdb
*lsdb
;
886 lsdb
= &nbr
->ls_rxmt
;
888 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++) {
889 struct route_table
*table
= lsdb
->type
[i
].db
;
890 struct route_node
*rn
;
891 struct ospf_lsa
*lsa
;
893 for (rn
= route_top(table
); rn
; rn
= route_next(rn
))
894 if ((lsa
= rn
->info
) != NULL
)
895 ospf_ls_retransmit_delete(nbr
, lsa
);
898 ospf_lsa_unlock(&nbr
->ls_req_last
);
899 nbr
->ls_req_last
= NULL
;
902 /* Lookup LSA from neighbor's ls-retransmit list. */
903 struct ospf_lsa
*ospf_ls_retransmit_lookup(struct ospf_neighbor
*nbr
,
904 struct ospf_lsa
*lsa
)
906 return ospf_lsdb_lookup(&nbr
->ls_rxmt
, lsa
);
909 static void ospf_ls_retransmit_delete_nbr_if(struct ospf_interface
*oi
,
910 struct ospf_lsa
*lsa
)
912 struct route_node
*rn
;
913 struct ospf_neighbor
*nbr
;
914 struct ospf_lsa
*lsr
;
916 if (ospf_if_is_enable(oi
))
917 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
918 /* If LSA find in LS-retransmit list, then remove it. */
919 if ((nbr
= rn
->info
) != NULL
) {
920 lsr
= ospf_ls_retransmit_lookup(nbr
, lsa
);
922 /* If LSA find in ls-retransmit list, remove it.
925 && lsr
->data
->ls_seqnum
926 == lsa
->data
->ls_seqnum
)
927 ospf_ls_retransmit_delete(nbr
, lsr
);
931 void ospf_ls_retransmit_delete_nbr_area(struct ospf_area
*area
,
932 struct ospf_lsa
*lsa
)
934 struct listnode
*node
, *nnode
;
935 struct ospf_interface
*oi
;
937 for (ALL_LIST_ELEMENTS(area
->oiflist
, node
, nnode
, oi
))
938 ospf_ls_retransmit_delete_nbr_if(oi
, lsa
);
941 void ospf_ls_retransmit_delete_nbr_as(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
943 struct listnode
*node
, *nnode
;
944 struct ospf_interface
*oi
;
946 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
947 ospf_ls_retransmit_delete_nbr_if(oi
, lsa
);
951 /* Sets ls_age to MaxAge and floods throu the area.
952 When we implement ASE routing, there will be anothe function
953 flushing an LSA from the whole domain. */
954 void ospf_lsa_flush_area(struct ospf_lsa
*lsa
, struct ospf_area
*area
)
956 /* Reset the lsa origination time such that it gives
957 more time for the ACK to be received and avoid
959 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
960 monotime(&lsa
->tv_recv
);
961 lsa
->tv_orig
= lsa
->tv_recv
;
962 ospf_flood_through_area(area
, NULL
, lsa
);
963 ospf_lsa_maxage(area
->ospf
, lsa
);
966 void ospf_lsa_flush_as(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
968 /* Reset the lsa origination time such that it gives
969 more time for the ACK to be received and avoid
971 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
972 monotime(&lsa
->tv_recv
);
973 lsa
->tv_orig
= lsa
->tv_recv
;
974 ospf_flood_through_as(ospf
, NULL
, lsa
);
975 ospf_lsa_maxage(ospf
, lsa
);
978 void ospf_lsa_flush(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
980 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
982 switch (lsa
->data
->type
) {
983 case OSPF_ROUTER_LSA
:
984 case OSPF_NETWORK_LSA
:
985 case OSPF_SUMMARY_LSA
:
986 case OSPF_ASBR_SUMMARY_LSA
:
987 case OSPF_AS_NSSA_LSA
:
988 case OSPF_OPAQUE_LINK_LSA
:
989 case OSPF_OPAQUE_AREA_LSA
:
990 ospf_lsa_flush_area(lsa
, lsa
->area
);
992 case OSPF_AS_EXTERNAL_LSA
:
993 case OSPF_OPAQUE_AS_LSA
:
994 ospf_lsa_flush_as(ospf
, lsa
);
997 zlog_info("%s: Unknown LSA type %u", __func__
, lsa
->data
->type
);