1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * OSPF Flooding -- RFC2328 Section 13.
4 * Copyright (C) 1999, 2000 Toshiaki Takada
20 #include "ospfd/ospfd.h"
21 #include "ospfd/ospf_interface.h"
22 #include "ospfd/ospf_ism.h"
23 #include "ospfd/ospf_asbr.h"
24 #include "ospfd/ospf_lsa.h"
25 #include "ospfd/ospf_lsdb.h"
26 #include "ospfd/ospf_neighbor.h"
27 #include "ospfd/ospf_nsm.h"
28 #include "ospfd/ospf_spf.h"
29 #include "ospfd/ospf_flood.h"
30 #include "ospfd/ospf_packet.h"
31 #include "ospfd/ospf_abr.h"
32 #include "ospfd/ospf_route.h"
33 #include "ospfd/ospf_zebra.h"
34 #include "ospfd/ospf_dump.h"
36 extern struct zclient
*zclient
;
38 /* Do the LSA acking specified in table 19, Section 13.5, row 2
39 * This get called from ospf_flood_out_interface. Declared inline
41 static void ospf_flood_delayed_lsa_ack(struct ospf_neighbor
*inbr
,
44 /* LSA is more recent than database copy, but was not
45 flooded back out receiving interface. Delayed
46 acknowledgment sent. If interface is in Backup state
47 delayed acknowledgment sent only if advertisement
48 received from Designated Router, otherwise do nothing See
49 RFC 2328 Section 13.5 */
51 /* Whether LSA is more recent or not, and whether this is in
52 response to the LSA being sent out recieving interface has been
53 worked out previously */
55 /* Deal with router as BDR */
56 if (inbr
->oi
->state
== ISM_Backup
&& !NBR_IS_DR(inbr
))
59 /* Schedule a delayed LSA Ack to be sent */
60 listnode_add(inbr
->oi
->ls_ack
,
61 ospf_lsa_lock(lsa
)); /* delayed LSA Ack */
64 /* Check LSA is related to external info. */
65 struct external_info
*ospf_external_info_check(struct ospf
*ospf
,
68 struct as_external_lsa
*al
;
70 struct route_node
*rn
;
71 struct list
*ext_list
;
72 struct listnode
*node
;
73 struct ospf_external
*ext
;
76 al
= (struct as_external_lsa
*)lsa
->data
;
79 p
.prefix
= lsa
->data
->id
;
80 p
.prefixlen
= ip_masklen(al
->mask
);
82 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
86 is_default_prefix4(&p
)
88 zclient
->default_information
[AFI_IP
],
90 : (zclient
->mi_redist
[AFI_IP
][type
].enabled
92 zclient
->redist
[AFI_IP
][type
],
94 // Pending: check for MI above.
96 ext_list
= ospf
->external
[type
];
100 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
102 if (ext
->external_info
)
103 rn
= route_node_lookup(
105 (struct prefix
*)&p
);
107 route_unlock_node(rn
);
108 if (rn
->info
!= NULL
)
109 return (struct external_info
*)
116 if (is_default_prefix4(&p
) && ospf
->external
[DEFAULT_ROUTE
]) {
117 ext_list
= ospf
->external
[DEFAULT_ROUTE
];
119 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
120 if (!ext
->external_info
)
123 rn
= route_node_lookup(ext
->external_info
,
124 (struct prefix
*)&p
);
127 route_unlock_node(rn
);
128 if (rn
->info
!= NULL
)
129 return (struct external_info
*)rn
->info
;
135 static void ospf_process_self_originated_lsa(struct ospf
*ospf
,
136 struct ospf_lsa
*new,
137 struct ospf_area
*area
)
139 struct ospf_interface
*oi
;
140 struct external_info
*ei
;
141 struct listnode
*node
;
142 struct as_external_lsa
*al
;
143 struct prefix_ipv4 p
;
144 struct ospf_external_aggr_rt
*aggr
;
146 if (IS_DEBUG_OSPF_EVENT
)
148 "%s:LSA[Type%d:%pI4]: Process self-originated LSA seq 0x%x",
149 ospf_get_name(ospf
), new->data
->type
,
150 &new->data
->id
, ntohl(new->data
->ls_seqnum
));
152 /* If we're here, we installed a self-originated LSA that we received
153 from a neighbor, i.e. it's more recent. We must see whether we want
155 If yes, we should use this LSA's sequence number and reoriginate
157 if not --- we must flush this LSA from the domain. */
158 switch (new->data
->type
) {
159 case OSPF_ROUTER_LSA
:
160 /* Originate a new instance and schedule flooding */
161 if (area
->router_lsa_self
)
162 area
->router_lsa_self
->data
->ls_seqnum
=
163 new->data
->ls_seqnum
;
164 ospf_router_lsa_update_area(area
);
166 case OSPF_NETWORK_LSA
:
167 case OSPF_OPAQUE_LINK_LSA
:
168 /* We must find the interface the LSA could belong to.
169 If the interface is no more a broadcast type or we are no
171 the DR, we flush the LSA otherwise -- create the new instance
173 schedule flooding. */
175 /* Look through all interfaces, not just area, since interface
176 could be moved from one area to another. */
177 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
178 /* These are sanity check. */
179 if (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
,
182 || oi
->type
!= OSPF_IFTYPE_BROADCAST
183 || !IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
,
185 ospf_schedule_lsa_flush_area(area
, new);
189 if (new->data
->type
== OSPF_OPAQUE_LINK_LSA
) {
190 ospf_opaque_lsa_refresh(new);
194 if (oi
->network_lsa_self
)
195 oi
->network_lsa_self
->data
->ls_seqnum
=
196 new->data
->ls_seqnum
;
197 /* Schedule network-LSA origination. */
198 ospf_network_lsa_update(oi
);
202 case OSPF_SUMMARY_LSA
:
203 case OSPF_ASBR_SUMMARY_LSA
:
204 ospf_schedule_abr_task(ospf
);
206 case OSPF_AS_EXTERNAL_LSA
:
207 case OSPF_AS_NSSA_LSA
:
208 if ((new->data
->type
== OSPF_AS_EXTERNAL_LSA
)
209 && CHECK_FLAG(new->flags
, OSPF_LSA_LOCAL_XLT
)) {
210 ospf_translated_nssa_refresh(ospf
, NULL
, new);
214 al
= (struct as_external_lsa
*)new->data
;
216 p
.prefixlen
= ip_masklen(al
->mask
);
217 p
.prefix
= new->data
->id
;
219 ei
= ospf_external_info_check(ospf
, new);
221 if (ospf_external_aggr_match(ospf
, &ei
->p
)) {
222 if (IS_DEBUG_OSPF(lsa
, EXTNL_LSA_AGGR
))
224 "%s, Matching external aggregate route found for %pI4, so don't refresh it.",
228 /* Aggregated external route shouldn't
231 if (!IS_LSA_MAXAGE(new))
232 ospf_lsa_flush_as(ospf
, new);
237 ospf_external_lsa_refresh(ospf
, new, ei
,
238 LSA_REFRESH_FORCE
, false);
240 aggr
= (struct ospf_external_aggr_rt
*)
241 ospf_extrenal_aggregator_lookup(ospf
, &p
);
243 struct external_info ei_aggr
;
246 sizeof(struct external_info
));
248 ei_aggr
.tag
= aggr
->tag
;
249 ei_aggr
.instance
= ospf
->instance
;
250 ei_aggr
.route_map_set
.metric
= -1;
251 ei_aggr
.route_map_set
.metric_type
= -1;
253 ospf_external_lsa_refresh(ospf
, new, &ei_aggr
,
254 LSA_REFRESH_FORCE
, true);
255 SET_FLAG(aggr
->flags
,
256 OSPF_EXTERNAL_AGGRT_ORIGINATED
);
258 ospf_lsa_flush_as(ospf
, new);
261 case OSPF_OPAQUE_AREA_LSA
:
262 ospf_opaque_lsa_refresh(new);
264 case OSPF_OPAQUE_AS_LSA
:
265 ospf_opaque_lsa_refresh(new);
266 /* Reconsideration may needed. */ /* XXX */
273 /* OSPF LSA flooding -- RFC2328 Section 13.(5). */
275 /* Now Updated for NSSA operation, as follows:
278 Type-5's have no change. Blocked to STUB or NSSA.
280 Type-7's can be received, and if a DR
281 they will also flood the local NSSA Area as Type-7's
283 If a Self-Originated LSA (now an ASBR),
284 The LSDB will be updated as Type-5's, (for continual re-fresh)
286 If an NSSA-IR it is installed/flooded as Type-7, P-bit on.
287 if an NSSA-ABR it is installed/flooded as Type-7, P-bit off.
289 Later, during the ABR TASK, if the ABR is the Elected NSSA
290 translator, then All Type-7s (with P-bit ON) are Translated to
291 Type-5's and flooded to all non-NSSA/STUB areas.
293 During ASE Calculations,
294 non-ABRs calculate external routes from Type-7's
295 ABRs calculate external routes from Type-5's and non-self Type-7s
297 int ospf_flood(struct ospf
*ospf
, struct ospf_neighbor
*nbr
,
298 struct ospf_lsa
*current
, struct ospf_lsa
*new)
300 struct ospf_interface
*oi
;
303 /* Type-7 LSA's will be flooded throughout their native NSSA area,
304 but will also be flooded as Type-5's into ABR capable links. */
306 if (IS_DEBUG_OSPF_EVENT
)
308 "%s:LSA[Flooding]: start, NBR %pI4 (%s), cur(%p), New-LSA[%s]",
309 ospf_get_name(ospf
), &nbr
->router_id
,
310 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
),
311 (void *)current
, dump_lsa_key(new));
315 /* If there is already a database copy, and if the
316 database copy was received via flooding and installed less
317 than MinLSArrival seconds ago, discard the new LSA
318 (without acknowledging it). */
319 if (current
!= NULL
) /* -- endo. */
321 if (IS_LSA_SELF(current
)
322 && (ntohs(current
->data
->ls_age
) == 0
323 && ntohl(current
->data
->ls_seqnum
)
324 == OSPF_INITIAL_SEQUENCE_NUMBER
)) {
325 if (IS_DEBUG_OSPF_EVENT
)
327 "%s:LSA[Flooding]: Got a self-originated LSA, while local one is initial instance.",
328 ospf_get_name(ospf
));
329 ; /* Accept this LSA for quick LSDB resynchronization.
331 } else if (monotime_since(¤t
->tv_recv
, NULL
)
332 < ospf
->min_ls_arrival
* 1000LL) {
333 if (IS_DEBUG_OSPF_EVENT
)
335 "%s:LSA[Flooding]: LSA is received recently.",
336 ospf_get_name(ospf
));
341 /* Flood the new LSA out some subset of the router's interfaces.
342 In some cases (e.g., the state of the receiving interface is
343 DR and the LSA was received from a router other than the
344 Backup DR) the LSA will be flooded back out the receiving
346 lsa_ack_flag
= ospf_flood_through(ospf
, nbr
, new);
348 /* Remove the current database copy from all neighbors' Link state
349 retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
350 ^^^^^^^^^^^^^^^^^^^^^^^
352 All other (even NSSA's) do have area ID. */
354 switch (current
->data
->type
) {
355 case OSPF_AS_EXTERNAL_LSA
:
356 case OSPF_OPAQUE_AS_LSA
:
357 ospf_ls_retransmit_delete_nbr_as(ospf
, current
);
360 ospf_ls_retransmit_delete_nbr_area(oi
->area
, current
);
365 /* Do some internal house keeping that is needed here */
366 SET_FLAG(new->flags
, OSPF_LSA_RECEIVED
);
367 (void)ospf_lsa_is_self_originated(ospf
, new); /* Let it set the flag */
369 /* Received non-self-originated Grace LSA */
370 if (IS_GRACE_LSA(new) && !IS_LSA_SELF(new)) {
372 if (IS_LSA_MAXAGE(new)) {
374 /* Handling Max age grace LSA.*/
375 if (IS_DEBUG_OSPF_GR
)
377 "%s, Received a maxage GRACE-LSA from router %pI4",
378 __func__
, &new->data
->adv_router
);
381 ospf_process_maxage_grace_lsa(ospf
, new, nbr
);
383 if (IS_DEBUG_OSPF_GR
)
385 "%s, Grace LSA doesn't exist in lsdb, so discarding grace lsa",
390 if (IS_DEBUG_OSPF_GR
)
392 "%s, Received a GRACE-LSA from router %pI4",
393 __func__
, &new->data
->adv_router
);
395 if (ospf_process_grace_lsa(ospf
, new, nbr
)
396 == OSPF_GR_NOT_HELPER
) {
397 if (IS_DEBUG_OSPF_GR
)
399 "%s, Not moving to HELPER role, So discarding grace LSA",
406 /* Install the new LSA in the link state database
407 (replacing the current database copy). This may cause the
408 routing table calculation to be scheduled. In addition,
409 timestamp the new LSA with the current time. The flooding
410 procedure cannot overwrite the newly installed LSA until
411 MinLSArrival seconds have elapsed. */
413 if (!(new = ospf_lsa_install(ospf
, oi
, new)))
414 return -1; /* unknown LSA type or any other error condition */
416 /* Acknowledge the receipt of the LSA by sending a Link State
417 Acknowledgment packet back out the receiving interface. */
419 ospf_flood_delayed_lsa_ack(nbr
, new);
421 /* If this new LSA indicates that it was originated by the
422 receiving router itself, the router must take special action,
423 either updating the LSA or in some cases flushing it from
424 the routing domain. */
425 if (ospf_lsa_is_self_originated(ospf
, new))
426 ospf_process_self_originated_lsa(ospf
, new, oi
->area
);
428 /* Update statistics value for OSPF-MIB. */
429 ospf
->rx_lsa_count
++;
434 /* OSPF LSA flooding -- RFC2328 Section 13.3. */
435 int ospf_flood_through_interface(struct ospf_interface
*oi
,
436 struct ospf_neighbor
*inbr
,
437 struct ospf_lsa
*lsa
)
439 struct ospf_neighbor
*onbr
;
440 struct route_node
*rn
;
443 if (IS_DEBUG_OSPF_EVENT
)
445 "%s: considering int %s (%s), INBR(%pI4), LSA[%s] AGE %u",
446 __func__
, IF_NAME(oi
), ospf_get_name(oi
->ospf
),
447 inbr
? &inbr
->router_id
: NULL
, dump_lsa_key(lsa
),
448 ntohs(lsa
->data
->ls_age
));
450 if (!ospf_if_is_enable(oi
))
453 /* Remember if new LSA is added to a retransmit list. */
456 /* Each of the neighbors attached to this interface are examined,
457 to determine whether they must receive the new LSA. The following
458 steps are executed for each neighbor: */
459 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
460 struct ospf_lsa
*ls_req
;
462 if (rn
->info
== NULL
)
466 if (IS_DEBUG_OSPF_EVENT
)
468 "%s: considering nbr %pI4 via %s (%s), state: %s",
469 __func__
, &onbr
->router_id
, IF_NAME(oi
),
470 ospf_get_name(oi
->ospf
),
471 lookup_msg(ospf_nsm_state_msg
, onbr
->state
,
474 /* If the neighbor is in a lesser state than Exchange, it
475 does not participate in flooding, and the next neighbor
476 should be examined. */
477 if (onbr
->state
< NSM_Exchange
)
480 /* If the adjacency is not yet full (neighbor state is
481 Exchange or Loading), examine the Link state request
482 list associated with this adjacency. If there is an
483 instance of the new LSA on the list, it indicates that
484 the neighboring router has an instance of the LSA
485 already. Compare the new LSA to the neighbor's copy: */
486 if (onbr
->state
< NSM_Full
) {
487 if (IS_DEBUG_OSPF_EVENT
)
489 "%s: adj to onbr %pI4 is not Full (%s)",
490 __func__
, &onbr
->router_id
,
491 lookup_msg(ospf_nsm_state_msg
,
493 ls_req
= ospf_ls_request_lookup(onbr
, lsa
);
494 if (ls_req
!= NULL
) {
497 ret
= ospf_lsa_more_recent(ls_req
, lsa
);
498 /* The new LSA is less recent. */
501 /* The two copies are the same instance, then
503 the LSA from the Link state request list. */
505 ospf_ls_request_delete(onbr
, ls_req
);
506 ospf_check_nbr_loading(onbr
);
509 /* The new LSA is more recent. Delete the LSA
510 from the Link state request list. */
512 ospf_ls_request_delete(onbr
, ls_req
);
513 ospf_check_nbr_loading(onbr
);
518 if (IS_OPAQUE_LSA(lsa
->data
->type
)) {
519 if (!CHECK_FLAG(onbr
->options
, OSPF_OPTION_O
)) {
520 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
522 "%s: Skipping neighbor %s via %pI4 -- Not Opaque-capable.",
523 __func__
, IF_NAME(oi
),
529 /* If the new LSA was received from this neighbor,
530 examine the next neighbor. */
533 * Triggered by LSUpd message parser "ospf_ls_upd ()".
534 * E.g., all LSAs handling here is received via network.
536 if (IPV4_ADDR_SAME(&inbr
->router_id
,
538 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
540 "%s: Skipping neighbor %s via %pI4 -- inbr == onbr.",
541 __func__
, IF_NAME(oi
),
547 * Triggered by MaxAge remover, so far.
548 * NULL "inbr" means flooding starts from this node.
550 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
552 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
554 "%s: Skipping neighbor %s via %pI4 -- lsah->adv_router == onbr.",
555 __func__
, IF_NAME(oi
),
561 /* Add the new LSA to the Link state retransmission list
562 for the adjacency. The LSA will be retransmitted
563 at intervals until an acknowledgment is seen from
565 ospf_ls_retransmit_add(onbr
, lsa
);
569 /* If in the previous step, the LSA was NOT added to any of
570 the Link state retransmission lists, there is no need to
571 flood the LSA out the interface. */
572 if (retx_flag
== 0) {
573 return (inbr
&& inbr
->oi
== oi
);
576 /* if we've received the lsa on this interface we need to perform
577 additional checking */
578 if (inbr
&& (inbr
->oi
== oi
)) {
579 /* If the new LSA was received on this interface, and it was
580 received from either the Designated Router or the Backup
581 Designated Router, chances are that all the neighbors have
582 received the LSA already. */
583 if (NBR_IS_DR(inbr
) || NBR_IS_BDR(inbr
)) {
584 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
585 zlog_debug("%s: DR/BDR NOT SEND to int %s (%s)",
586 __func__
, IF_NAME(oi
),
587 ospf_get_name(oi
->ospf
));
591 /* If the new LSA was received on this interface, and the
592 interface state is Backup, examine the next interface. The
593 Designated Router will do the flooding on this interface.
594 However, if the Designated Router fails the router will
595 end up retransmitting the updates. */
597 if (oi
->state
== ISM_Backup
) {
598 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
600 "%s: ISM_Backup NOT SEND to int %s (%s)",
601 __func__
, IF_NAME(oi
),
602 ospf_get_name(oi
->ospf
));
607 /* The LSA must be flooded out the interface. Send a Link State
608 Update packet (including the new LSA as contents) out the
609 interface. The LSA's LS age must be incremented by InfTransDelay
610 (which must be > 0) when it is copied into the outgoing Link
611 State Update packet (until the LS age field reaches the maximum
613 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
614 zlog_debug("%s: DR/BDR sending upd to int %s (%s)", __func__
,
615 IF_NAME(oi
), ospf_get_name(oi
->ospf
));
617 /* RFC2328 Section 13.3
618 On non-broadcast networks, separate Link State Update
619 packets must be sent, as unicasts, to each adjacent neighbor
620 (i.e., those in state Exchange or greater). The destination
621 IP addresses for these packets are the neighbors' IP
623 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
624 struct ospf_neighbor
*nbr
;
626 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
631 if (nbr
!= oi
->nbr_self
&& nbr
->state
>= NSM_Exchange
)
632 ospf_ls_upd_send_lsa(nbr
, lsa
,
633 OSPF_SEND_PACKET_DIRECT
);
636 /* Optimization: for P2MP interfaces,
637 don't send back out the incoming interface immediately,
638 allow time to rx multicast ack to the rx'ed (multicast)
640 if (retx_flag
!= 1 ||
641 oi
->type
!= OSPF_IFTYPE_POINTOMULTIPOINT
|| inbr
== NULL
||
643 ospf_ls_upd_send_lsa(oi
->nbr_self
, lsa
,
644 OSPF_SEND_PACKET_INDIRECT
);
649 int ospf_flood_through_area(struct ospf_area
*area
, struct ospf_neighbor
*inbr
,
650 struct ospf_lsa
*lsa
)
652 struct listnode
*node
, *nnode
;
653 struct ospf_interface
*oi
;
654 int lsa_ack_flag
= 0;
657 /* All other types are specific to a single area (Area A). The
658 eligible interfaces are all those interfaces attaching to the
659 Area A. If Area A is the backbone, this includes all the virtual
661 for (ALL_LIST_ELEMENTS(area
->oiflist
, node
, nnode
, oi
)) {
662 if (area
->area_id
.s_addr
!= OSPF_AREA_BACKBONE
663 && oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
666 if ((lsa
->data
->type
== OSPF_OPAQUE_LINK_LSA
)
667 && (lsa
->oi
!= oi
)) {
669 * Link local scoped Opaque-LSA should only be flooded
670 * for the link on which the LSA has received.
672 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
674 "Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)",
675 (void *)lsa
->oi
, (void *)oi
);
679 if (ospf_flood_through_interface(oi
, inbr
, lsa
))
683 return (lsa_ack_flag
);
686 int ospf_flood_through_as(struct ospf
*ospf
, struct ospf_neighbor
*inbr
,
687 struct ospf_lsa
*lsa
)
689 struct listnode
*node
;
690 struct ospf_area
*area
;
695 /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
697 Divert the Type-5 LSA's to all non-NSSA/STUB areas
699 Divert the Type-7 LSA's to all NSSA areas
701 AS-external-LSAs are flooded throughout the entire AS, with the
702 exception of stub areas (see Section 3.6). The eligible
703 interfaces are all the router's interfaces, excluding virtual
704 links and those interfaces attaching to stub areas. */
706 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) /* Translated from 7 */
707 if (IS_DEBUG_OSPF_NSSA
)
708 zlog_debug("Flood/AS: NSSA TRANSLATED LSA");
710 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
711 int continue_flag
= 0;
712 struct listnode
*if_node
;
713 struct ospf_interface
*oi
;
715 switch (area
->external_routing
) {
716 /* Don't send AS externals into stub areas. Various types
717 of support for partial stub areas can be implemented
718 here. NSSA's will receive Type-7's that have areas
719 matching the originl LSA. */
720 case OSPF_AREA_NSSA
: /* Sending Type 5 or 7 into NSSA area */
721 /* Type-7, flood NSSA area */
722 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
723 && area
== lsa
->area
)
724 /* We will send it. */
727 continue_flag
= 1; /* Skip this NSSA area for
731 case OSPF_AREA_TYPE_MAX
:
733 continue_flag
= 1; /* Skip this area. */
736 case OSPF_AREA_DEFAULT
:
738 /* No Type-7 into normal area */
739 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
740 continue_flag
= 1; /* skip Type-7 */
742 continue_flag
= 0; /* Do this area. */
746 /* Do continue for above switch. Saves a big if then mess */
748 continue; /* main for-loop */
750 /* send to every interface in this area */
752 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, if_node
, oi
)) {
753 /* Skip virtual links */
754 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
755 if (ospf_flood_through_interface(oi
, inbr
,
759 } /* main area for-loop */
761 return (lsa_ack_flag
);
764 int ospf_flood_through(struct ospf
*ospf
, struct ospf_neighbor
*inbr
,
765 struct ospf_lsa
*lsa
)
767 int lsa_ack_flag
= 0;
769 /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
770 upon return are updated in the LSDB for Type-7's. Later,
771 re-fresh will re-send them (and also, if ABR, packet code will
772 translate to Type-5's)
774 As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
775 NSSA) are flooded throughout the AS, and are updated in the
778 * At the common sub-sub-function "ospf_flood_through_interface()",
779 * a parameter "inbr" will be used to distinguish the called context
780 * whether the given LSA was received from the neighbor, or the
781 * flooding for the LSA starts from this node (e.g. the LSA was self-
782 * originated, or the LSA is going to be flushed from routing domain).
784 * So, for consistency reasons, this function "ospf_flood_through()"
785 * should also allow the usage that the given "inbr" parameter to be
786 * NULL. If we do so, corresponding AREA parameter should be referred
787 * by "lsa->area", instead of "inbr->oi->area".
789 switch (lsa
->data
->type
) {
790 case OSPF_AS_EXTERNAL_LSA
: /* Type-5 */
791 case OSPF_OPAQUE_AS_LSA
:
792 lsa_ack_flag
= ospf_flood_through_as(ospf
, inbr
, lsa
);
794 /* Type-7 Only received within NSSA, then flooded */
795 case OSPF_AS_NSSA_LSA
:
796 /* Any P-bit was installed with the Type-7. */
798 if (IS_DEBUG_OSPF_NSSA
)
799 zlog_debug("%s: LOCAL NSSA FLOOD of Type-7.", __func__
);
802 lsa_ack_flag
= ospf_flood_through_area(lsa
->area
, inbr
, lsa
);
806 /* always need to send ack when incoming intf is PTP or P2MP */
807 if (inbr
!= NULL
&& (inbr
->oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
||
808 inbr
->oi
->type
== OSPF_IFTYPE_POINTOPOINT
))
811 return (lsa_ack_flag
);
815 /* Management functions for neighbor's Link State Request list. */
816 void ospf_ls_request_add(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
819 * We cannot make use of the newly introduced callback function
820 * "lsdb->new_lsa_hook" to replace debug output below, just because
821 * it seems no simple and smart way to pass neighbor information to
822 * the common function "ospf_lsdb_add()" -- endo.
824 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
825 zlog_debug("RqstL(%lu)++, NBR(%pI4(%s)), LSA[%s]",
826 ospf_ls_request_count(nbr
),
828 ospf_get_name(nbr
->oi
->ospf
), dump_lsa_key(lsa
));
830 ospf_lsdb_add(&nbr
->ls_req
, lsa
);
833 unsigned long ospf_ls_request_count(struct ospf_neighbor
*nbr
)
835 return ospf_lsdb_count_all(&nbr
->ls_req
);
838 int ospf_ls_request_isempty(struct ospf_neighbor
*nbr
)
840 return ospf_lsdb_isempty(&nbr
->ls_req
);
843 /* Remove LSA from neighbor's ls-request list. */
844 void ospf_ls_request_delete(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
846 if (nbr
->ls_req_last
== lsa
) {
847 ospf_lsa_unlock(&nbr
->ls_req_last
);
848 nbr
->ls_req_last
= NULL
;
851 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
)) /* -- endo. */
852 zlog_debug("RqstL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
853 ospf_ls_request_count(nbr
),
855 ospf_get_name(nbr
->oi
->ospf
), dump_lsa_key(lsa
));
857 ospf_lsdb_delete(&nbr
->ls_req
, lsa
);
860 /* Remove all LSA from neighbor's ls-requenst list. */
861 void ospf_ls_request_delete_all(struct ospf_neighbor
*nbr
)
863 ospf_lsa_unlock(&nbr
->ls_req_last
);
864 nbr
->ls_req_last
= NULL
;
865 ospf_lsdb_delete_all(&nbr
->ls_req
);
868 /* Lookup LSA from neighbor's ls-request list. */
869 struct ospf_lsa
*ospf_ls_request_lookup(struct ospf_neighbor
*nbr
,
870 struct ospf_lsa
*lsa
)
872 return ospf_lsdb_lookup(&nbr
->ls_req
, lsa
);
875 struct ospf_lsa
*ospf_ls_request_new(struct lsa_header
*lsah
)
877 struct ospf_lsa
*new;
879 new = ospf_lsa_new_and_data(OSPF_LSA_HEADER_SIZE
);
880 memcpy(new->data
, lsah
, OSPF_LSA_HEADER_SIZE
);
886 /* Management functions for neighbor's ls-retransmit list. */
887 unsigned long ospf_ls_retransmit_count(struct ospf_neighbor
*nbr
)
889 return ospf_lsdb_count_all(&nbr
->ls_rxmt
);
892 unsigned long ospf_ls_retransmit_count_self(struct ospf_neighbor
*nbr
,
895 return ospf_lsdb_count_self(&nbr
->ls_rxmt
, lsa_type
);
898 int ospf_ls_retransmit_isempty(struct ospf_neighbor
*nbr
)
900 return ospf_lsdb_isempty(&nbr
->ls_rxmt
);
903 /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
904 void ospf_ls_retransmit_add(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
906 struct ospf_lsa
*old
;
908 old
= ospf_ls_retransmit_lookup(nbr
, lsa
);
910 if (ospf_lsa_more_recent(old
, lsa
) < 0) {
912 old
->retransmit_counter
--;
913 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
914 zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
915 ospf_ls_retransmit_count(nbr
),
917 ospf_get_name(nbr
->oi
->ospf
),
919 ospf_lsdb_delete(&nbr
->ls_rxmt
, old
);
921 lsa
->retransmit_counter
++;
923 * We cannot make use of the newly introduced callback function
924 * "lsdb->new_lsa_hook" to replace debug output below, just
926 * it seems no simple and smart way to pass neighbor information
928 * the common function "ospf_lsdb_add()" -- endo.
930 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
931 zlog_debug("RXmtL(%lu)++, NBR(%pI4(%s)), LSA[%s]",
932 ospf_ls_retransmit_count(nbr
),
934 ospf_get_name(nbr
->oi
->ospf
),
936 ospf_lsdb_add(&nbr
->ls_rxmt
, lsa
);
940 /* Remove LSA from neibghbor's ls-retransmit list. */
941 void ospf_ls_retransmit_delete(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
943 if (ospf_ls_retransmit_lookup(nbr
, lsa
)) {
944 lsa
->retransmit_counter
--;
945 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
)) /* -- endo. */
946 zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
947 ospf_ls_retransmit_count(nbr
),
949 ospf_get_name(nbr
->oi
->ospf
),
951 ospf_lsdb_delete(&nbr
->ls_rxmt
, lsa
);
955 /* Clear neighbor's ls-retransmit list. */
956 void ospf_ls_retransmit_clear(struct ospf_neighbor
*nbr
)
958 struct ospf_lsdb
*lsdb
;
961 lsdb
= &nbr
->ls_rxmt
;
963 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++) {
964 struct route_table
*table
= lsdb
->type
[i
].db
;
965 struct route_node
*rn
;
966 struct ospf_lsa
*lsa
;
968 for (rn
= route_top(table
); rn
; rn
= route_next(rn
))
969 if ((lsa
= rn
->info
) != NULL
)
970 ospf_ls_retransmit_delete(nbr
, lsa
);
973 ospf_lsa_unlock(&nbr
->ls_req_last
);
974 nbr
->ls_req_last
= NULL
;
977 /* Lookup LSA from neighbor's ls-retransmit list. */
978 struct ospf_lsa
*ospf_ls_retransmit_lookup(struct ospf_neighbor
*nbr
,
979 struct ospf_lsa
*lsa
)
981 return ospf_lsdb_lookup(&nbr
->ls_rxmt
, lsa
);
984 static void ospf_ls_retransmit_delete_nbr_if(struct ospf_interface
*oi
,
985 struct ospf_lsa
*lsa
)
987 struct route_node
*rn
;
988 struct ospf_neighbor
*nbr
;
989 struct ospf_lsa
*lsr
;
991 if (ospf_if_is_enable(oi
))
992 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
993 /* If LSA find in LS-retransmit list, then remove it. */
999 lsr
= ospf_ls_retransmit_lookup(nbr
, lsa
);
1001 /* If LSA find in ls-retransmit list, remove it. */
1003 lsr
->data
->ls_seqnum
== lsa
->data
->ls_seqnum
)
1004 ospf_ls_retransmit_delete(nbr
, lsr
);
1008 void ospf_ls_retransmit_delete_nbr_area(struct ospf_area
*area
,
1009 struct ospf_lsa
*lsa
)
1011 struct listnode
*node
, *nnode
;
1012 struct ospf_interface
*oi
;
1014 for (ALL_LIST_ELEMENTS(area
->oiflist
, node
, nnode
, oi
))
1015 ospf_ls_retransmit_delete_nbr_if(oi
, lsa
);
1018 void ospf_ls_retransmit_delete_nbr_as(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1020 struct listnode
*node
, *nnode
;
1021 struct ospf_interface
*oi
;
1023 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
1024 ospf_ls_retransmit_delete_nbr_if(oi
, lsa
);
1028 /* Sets ls_age to MaxAge and floods throu the area.
1029 When we implement ASE routing, there will be another function
1030 flushing an LSA from the whole domain. */
1031 void ospf_lsa_flush_area(struct ospf_lsa
*lsa
, struct ospf_area
*area
)
1033 struct ospf
*ospf
= area
->ospf
;
1035 if (ospf_lsa_is_self_originated(ospf
, lsa
)
1036 && ospf
->gr_info
.restart_in_progress
) {
1037 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1039 "%s:LSA[Type%d:%pI4]: Graceful Restart in progress -- not flushing self-originated LSA",
1040 ospf_get_name(ospf
), lsa
->data
->type
,
1045 /* Reset the lsa origination time such that it gives
1046 more time for the ACK to be received and avoid
1048 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1049 if (IS_DEBUG_OSPF_EVENT
)
1050 zlog_debug("%s: MaxAge set to LSA[%s]", __func__
,
1052 monotime(&lsa
->tv_recv
);
1053 lsa
->tv_orig
= lsa
->tv_recv
;
1054 ospf_flood_through_area(area
, NULL
, lsa
);
1055 ospf_lsa_maxage(ospf
, lsa
);
1058 void ospf_lsa_flush_as(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1060 if (ospf_lsa_is_self_originated(ospf
, lsa
)
1061 && ospf
->gr_info
.restart_in_progress
) {
1062 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1064 "%s:LSA[Type%d:%pI4]: Graceful Restart in progress -- not flushing self-originated LSA",
1065 ospf_get_name(ospf
), lsa
->data
->type
,
1070 /* Reset the lsa origination time such that it gives
1071 more time for the ACK to be received and avoid
1073 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1074 if (IS_DEBUG_OSPF_EVENT
)
1075 zlog_debug("%s: MaxAge set to LSA[%s]", __func__
,
1077 monotime(&lsa
->tv_recv
);
1078 lsa
->tv_orig
= lsa
->tv_recv
;
1079 ospf_flood_through_as(ospf
, NULL
, lsa
);
1080 ospf_lsa_maxage(ospf
, lsa
);
1083 void ospf_lsa_flush(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1085 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1087 switch (lsa
->data
->type
) {
1088 case OSPF_ROUTER_LSA
:
1089 case OSPF_NETWORK_LSA
:
1090 case OSPF_SUMMARY_LSA
:
1091 case OSPF_ASBR_SUMMARY_LSA
:
1092 case OSPF_AS_NSSA_LSA
:
1093 case OSPF_OPAQUE_LINK_LSA
:
1094 case OSPF_OPAQUE_AREA_LSA
:
1095 ospf_lsa_flush_area(lsa
, lsa
->area
);
1097 case OSPF_AS_EXTERNAL_LSA
:
1098 case OSPF_OPAQUE_AS_LSA
:
1099 ospf_lsa_flush_as(ospf
, lsa
);
1102 zlog_info("%s: Unknown LSA type %u", __func__
, lsa
->data
->type
);