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
*ospf
,
83 struct as_external_lsa
*al
;
85 struct route_node
*rn
;
86 struct list
*ext_list
;
87 struct listnode
*node
;
88 struct ospf_external
*ext
;
91 al
= (struct as_external_lsa
*)lsa
->data
;
94 p
.prefix
= lsa
->data
->id
;
95 p
.prefixlen
= ip_masklen(al
->mask
);
97 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++) {
101 is_default_prefix4(&p
)
103 zclient
->default_information
[AFI_IP
],
105 : (zclient
->mi_redist
[AFI_IP
][type
].enabled
107 zclient
->redist
[AFI_IP
][type
],
109 // Pending: check for MI above.
111 ext_list
= ospf
->external
[type
];
115 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
117 if (ext
->external_info
)
118 rn
= route_node_lookup(
120 (struct prefix
*)&p
);
122 route_unlock_node(rn
);
123 if (rn
->info
!= NULL
)
124 return (struct external_info
*)
131 if (is_default_prefix4(&p
) && ospf
->external
[DEFAULT_ROUTE
]) {
132 ext_list
= ospf
->external
[DEFAULT_ROUTE
];
134 for (ALL_LIST_ELEMENTS_RO(ext_list
, node
, ext
)) {
135 if (!ext
->external_info
)
138 rn
= route_node_lookup(ext
->external_info
,
139 (struct prefix
*)&p
);
142 route_unlock_node(rn
);
143 if (rn
->info
!= NULL
)
144 return (struct external_info
*)rn
->info
;
150 static void ospf_process_self_originated_lsa(struct ospf
*ospf
,
151 struct ospf_lsa
*new,
152 struct ospf_area
*area
)
154 struct ospf_interface
*oi
;
155 struct external_info
*ei
;
156 struct listnode
*node
;
157 struct as_external_lsa
*al
;
158 struct prefix_ipv4 p
;
159 struct ospf_external_aggr_rt
*aggr
;
161 if (IS_DEBUG_OSPF_EVENT
)
163 "%s:LSA[Type%d:%pI4]: Process self-originated LSA seq 0x%x",
164 ospf_get_name(ospf
), new->data
->type
,
165 &new->data
->id
, ntohl(new->data
->ls_seqnum
));
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
170 If yes, we should use this LSA's sequence number and reoriginate
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
);
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
186 the DR, we flush the LSA otherwise -- create the new instance
188 schedule flooding. */
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
,
197 || oi
->type
!= OSPF_IFTYPE_BROADCAST
198 || !IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
,
200 ospf_schedule_lsa_flush_area(area
, new);
204 if (new->data
->type
== OSPF_OPAQUE_LINK_LSA
) {
205 ospf_opaque_lsa_refresh(new);
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
);
217 case OSPF_SUMMARY_LSA
:
218 case OSPF_ASBR_SUMMARY_LSA
:
219 ospf_schedule_abr_task(ospf
);
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);
229 al
= (struct as_external_lsa
*)new->data
;
231 p
.prefixlen
= ip_masklen(al
->mask
);
232 p
.prefix
= new->data
->id
;
234 ei
= ospf_external_info_check(ospf
, new);
236 if (ospf_external_aggr_match(ospf
, &ei
->p
)) {
237 if (IS_DEBUG_OSPF(lsa
, EXTNL_LSA_AGGR
))
239 "%s, Matching external aggregate route found for %pI4, so don't refresh it.",
243 /* Aggregated external route shouldn't
246 if (!IS_LSA_MAXAGE(new))
247 ospf_lsa_flush_as(ospf
, new);
252 ospf_external_lsa_refresh(ospf
, new, ei
,
253 LSA_REFRESH_FORCE
, false);
255 aggr
= (struct ospf_external_aggr_rt
*)
256 ospf_extrenal_aggregator_lookup(ospf
, &p
);
258 struct external_info ei_aggr
;
261 sizeof(struct external_info
));
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;
268 ospf_external_lsa_refresh(ospf
, new, &ei_aggr
,
269 LSA_REFRESH_FORCE
, true);
271 ospf_lsa_flush_as(ospf
, new);
274 case OSPF_OPAQUE_AREA_LSA
:
275 ospf_opaque_lsa_refresh(new);
277 case OSPF_OPAQUE_AS_LSA
:
278 ospf_opaque_lsa_refresh(new);
279 /* Reconsideration may needed. */ /* XXX */
286 /* OSPF LSA flooding -- RFC2328 Section 13.(5). */
288 /* Now Updated for NSSA operation, as follows:
291 Type-5's have no change. Blocked to STUB or NSSA.
293 Type-7's can be received, and if a DR
294 they will also flood the local NSSA Area as Type-7's
296 If a Self-Originated LSA (now an ASBR),
297 The LSDB will be updated as Type-5's, (for continual re-fresh)
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.
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.
306 During ASE Calculations,
307 non-ABRs calculate external routes from Type-7's
308 ABRs calculate external routes from Type-5's and non-self Type-7s
310 int ospf_flood(struct ospf
*ospf
, struct ospf_neighbor
*nbr
,
311 struct ospf_lsa
*current
, struct ospf_lsa
*new)
313 struct ospf_interface
*oi
;
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. */
319 if (IS_DEBUG_OSPF_EVENT
)
321 "%s:LSA[Flooding]: start, NBR %pI4 (%s), cur(%p), New-LSA[%s]",
322 ospf_get_name(ospf
), &nbr
->router_id
,
323 lookup_msg(ospf_nsm_state_msg
, nbr
->state
, NULL
),
324 (void *)current
, dump_lsa_key(new));
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. */
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
)
340 "%s:LSA[Flooding]: Got a self-originated LSA, while local one is initial instance.",
341 ospf_get_name(ospf
));
342 ; /* Accept this LSA for quick LSDB resynchronization.
344 } else if (monotime_since(¤t
->tv_recv
, NULL
)
345 < ospf
->min_ls_arrival
* 1000LL) {
346 if (IS_DEBUG_OSPF_EVENT
)
348 "%s:LSA[Flooding]: LSA is received recently.",
349 ospf_get_name(ospf
));
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
359 lsa_ack_flag
= ospf_flood_through(ospf
, nbr
, new);
361 /* Remove the current database copy from all neighbors' Link state
362 retransmission lists. AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
363 ^^^^^^^^^^^^^^^^^^^^^^^
365 All other (even NSSA's) do have area ID. */
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
);
373 ospf_ls_retransmit_delete_nbr_area(oi
->area
, current
);
378 /* Do some internal house keeping that is needed here */
379 SET_FLAG(new->flags
, OSPF_LSA_RECEIVED
);
380 (void)ospf_lsa_is_self_originated(ospf
, new); /* Let it set the flag */
382 /* Received non-self-originated Grace LSA */
383 if (IS_GRACE_LSA(new) && !IS_LSA_SELF(new)) {
385 if (IS_LSA_MAXAGE(new)) {
387 /* Handling Max age grace LSA.*/
388 if (IS_DEBUG_OSPF_GR
)
390 "%s, Received a maxage GRACE-LSA from router %pI4",
391 __func__
, &new->data
->adv_router
);
394 ospf_process_maxage_grace_lsa(ospf
, new, nbr
);
396 if (IS_DEBUG_OSPF_GR
)
398 "%s, Grace LSA doesn't exist in lsdb, so discarding grace lsa",
403 if (IS_DEBUG_OSPF_GR
)
405 "%s, Received a GRACE-LSA from router %pI4",
406 __func__
, &new->data
->adv_router
);
408 if (ospf_process_grace_lsa(ospf
, new, nbr
)
409 == OSPF_GR_NOT_HELPER
) {
410 if (IS_DEBUG_OSPF_GR
)
412 "%s, Not moving to HELPER role, So discarding grace LSA",
419 /* Install the new LSA in the link state database
420 (replacing the current database copy). This may cause the
421 routing table calculation to be scheduled. In addition,
422 timestamp the new LSA with the current time. The flooding
423 procedure cannot overwrite the newly installed LSA until
424 MinLSArrival seconds have elapsed. */
426 if (!(new = ospf_lsa_install(ospf
, oi
, new)))
427 return -1; /* unknown LSA type or any other error condition */
429 /* Acknowledge the receipt of the LSA by sending a Link State
430 Acknowledgment packet back out the receiving interface. */
432 ospf_flood_delayed_lsa_ack(nbr
, new);
434 /* If this new LSA indicates that it was originated by the
435 receiving router itself, the router must take special action,
436 either updating the LSA or in some cases flushing it from
437 the routing domain. */
438 if (ospf_lsa_is_self_originated(ospf
, new))
439 ospf_process_self_originated_lsa(ospf
, new, oi
->area
);
441 /* Update statistics value for OSPF-MIB. */
442 ospf
->rx_lsa_count
++;
447 /* OSPF LSA flooding -- RFC2328 Section 13.3. */
448 int ospf_flood_through_interface(struct ospf_interface
*oi
,
449 struct ospf_neighbor
*inbr
,
450 struct ospf_lsa
*lsa
)
452 struct ospf_neighbor
*onbr
;
453 struct route_node
*rn
;
455 char buf
[PREFIX_STRLEN
];
457 if (IS_DEBUG_OSPF_EVENT
)
459 "%s: considering int %s (%s), INBR(%s), LSA[%s] AGE %u",
460 __func__
, IF_NAME(oi
), ospf_get_name(oi
->ospf
),
461 inbr
? inet_ntop(AF_INET
, &inbr
->router_id
, buf
,
464 dump_lsa_key(lsa
), ntohs(lsa
->data
->ls_age
));
466 if (!ospf_if_is_enable(oi
))
469 /* Remember if new LSA is added to a retransmit list. */
472 /* Each of the neighbors attached to this interface are examined,
473 to determine whether they must receive the new LSA. The following
474 steps are executed for each neighbor: */
475 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
)) {
476 struct ospf_lsa
*ls_req
;
478 if (rn
->info
== NULL
)
482 if (IS_DEBUG_OSPF_EVENT
)
484 "%s: considering nbr %pI4 via %s (%s), state: %s",
485 __func__
, &onbr
->router_id
, IF_NAME(oi
),
486 ospf_get_name(oi
->ospf
),
487 lookup_msg(ospf_nsm_state_msg
, onbr
->state
,
490 /* If the neighbor is in a lesser state than Exchange, it
491 does not participate in flooding, and the next neighbor
492 should be examined. */
493 if (onbr
->state
< NSM_Exchange
)
496 /* If the adjacency is not yet full (neighbor state is
497 Exchange or Loading), examine the Link state request
498 list associated with this adjacency. If there is an
499 instance of the new LSA on the list, it indicates that
500 the neighboring router has an instance of the LSA
501 already. Compare the new LSA to the neighbor's copy: */
502 if (onbr
->state
< NSM_Full
) {
503 if (IS_DEBUG_OSPF_EVENT
)
505 "%s: adj to onbr %pI4 is not Full (%s)",
506 __func__
, &onbr
->router_id
,
507 lookup_msg(ospf_nsm_state_msg
,
509 ls_req
= ospf_ls_request_lookup(onbr
, lsa
);
510 if (ls_req
!= NULL
) {
513 ret
= ospf_lsa_more_recent(ls_req
, lsa
);
514 /* The new LSA is less recent. */
517 /* The two copies are the same instance, then
519 the LSA from the Link state request list. */
521 ospf_ls_request_delete(onbr
, ls_req
);
522 ospf_check_nbr_loading(onbr
);
525 /* The new LSA is more recent. Delete the LSA
526 from the Link state request list. */
528 ospf_ls_request_delete(onbr
, ls_req
);
529 ospf_check_nbr_loading(onbr
);
534 if (IS_OPAQUE_LSA(lsa
->data
->type
)) {
535 if (!CHECK_FLAG(onbr
->options
, OSPF_OPTION_O
)) {
536 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
538 "%s: Skipping neighbor %s via %pI4 -- Not Opaque-capable.",
539 __func__
, IF_NAME(oi
),
545 /* If the new LSA was received from this neighbor,
546 examine the next neighbor. */
549 * Triggered by LSUpd message parser "ospf_ls_upd ()".
550 * E.g., all LSAs handling here is received via network.
552 if (IPV4_ADDR_SAME(&inbr
->router_id
,
554 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
556 "%s: Skipping neighbor %s via %pI4 -- inbr == onbr.",
557 __func__
, IF_NAME(oi
),
563 * Triggered by MaxAge remover, so far.
564 * NULL "inbr" means flooding starts from this node.
566 if (IPV4_ADDR_SAME(&lsa
->data
->adv_router
,
568 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
570 "%s: Skipping neighbor %s via %pI4 -- lsah->adv_router == onbr.",
571 __func__
, IF_NAME(oi
),
577 /* Add the new LSA to the Link state retransmission list
578 for the adjacency. The LSA will be retransmitted
579 at intervals until an acknowledgment is seen from
581 ospf_ls_retransmit_add(onbr
, lsa
);
585 /* If in the previous step, the LSA was NOT added to any of
586 the Link state retransmission lists, there is no need to
587 flood the LSA out the interface. */
588 if (retx_flag
== 0) {
589 return (inbr
&& inbr
->oi
== oi
);
592 /* if we've received the lsa on this interface we need to perform
593 additional checking */
594 if (inbr
&& (inbr
->oi
== oi
)) {
595 /* If the new LSA was received on this interface, and it was
596 received from either the Designated Router or the Backup
597 Designated Router, chances are that all the neighbors have
598 received the LSA already. */
599 if (NBR_IS_DR(inbr
) || NBR_IS_BDR(inbr
)) {
600 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
601 zlog_debug("%s: DR/BDR NOT SEND to int %s (%s)",
602 __func__
, IF_NAME(oi
),
603 ospf_get_name(oi
->ospf
));
607 /* If the new LSA was received on this interface, and the
608 interface state is Backup, examine the next interface. The
609 Designated Router will do the flooding on this interface.
610 However, if the Designated Router fails the router will
611 end up retransmitting the updates. */
613 if (oi
->state
== ISM_Backup
) {
614 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
616 "%s: ISM_Backup NOT SEND to int %s (%s)",
617 __func__
, IF_NAME(oi
),
618 ospf_get_name(oi
->ospf
));
623 /* The LSA must be flooded out the interface. Send a Link State
624 Update packet (including the new LSA as contents) out the
625 interface. The LSA's LS age must be incremented by InfTransDelay
626 (which must be > 0) when it is copied into the outgoing Link
627 State Update packet (until the LS age field reaches the maximum
629 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
630 zlog_debug("%s: DR/BDR sending upd to int %s (%s)", __func__
,
631 IF_NAME(oi
), ospf_get_name(oi
->ospf
));
633 /* RFC2328 Section 13.3
634 On non-broadcast networks, separate Link State Update
635 packets must be sent, as unicasts, to each adjacent neighbor
636 (i.e., those in state Exchange or greater). The destination
637 IP addresses for these packets are the neighbors' IP
639 if (oi
->type
== OSPF_IFTYPE_NBMA
) {
640 struct ospf_neighbor
*nbr
;
642 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
643 if ((nbr
= rn
->info
) != NULL
)
644 if (nbr
!= oi
->nbr_self
645 && nbr
->state
>= NSM_Exchange
)
646 ospf_ls_upd_send_lsa(
648 OSPF_SEND_PACKET_DIRECT
);
650 ospf_ls_upd_send_lsa(oi
->nbr_self
, lsa
,
651 OSPF_SEND_PACKET_INDIRECT
);
656 int ospf_flood_through_area(struct ospf_area
*area
, struct ospf_neighbor
*inbr
,
657 struct ospf_lsa
*lsa
)
659 struct listnode
*node
, *nnode
;
660 struct ospf_interface
*oi
;
661 int lsa_ack_flag
= 0;
664 /* All other types are specific to a single area (Area A). The
665 eligible interfaces are all those interfaces attaching to the
666 Area A. If Area A is the backbone, this includes all the virtual
668 for (ALL_LIST_ELEMENTS(area
->oiflist
, node
, nnode
, oi
)) {
669 if (area
->area_id
.s_addr
!= OSPF_AREA_BACKBONE
670 && oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
673 if ((lsa
->data
->type
== OSPF_OPAQUE_LINK_LSA
)
674 && (lsa
->oi
!= oi
)) {
676 * Link local scoped Opaque-LSA should only be flooded
677 * for the link on which the LSA has received.
679 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
681 "Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)",
682 (void *)lsa
->oi
, (void *)oi
);
686 if (ospf_flood_through_interface(oi
, inbr
, lsa
))
690 return (lsa_ack_flag
);
693 int ospf_flood_through_as(struct ospf
*ospf
, struct ospf_neighbor
*inbr
,
694 struct ospf_lsa
*lsa
)
696 struct listnode
*node
;
697 struct ospf_area
*area
;
702 /* The incoming LSA is type 5 or type 7 (AS-EXTERNAL or AS-NSSA )
704 Divert the Type-5 LSA's to all non-NSSA/STUB areas
706 Divert the Type-7 LSA's to all NSSA areas
708 AS-external-LSAs are flooded throughout the entire AS, with the
709 exception of stub areas (see Section 3.6). The eligible
710 interfaces are all the router's interfaces, excluding virtual
711 links and those interfaces attaching to stub areas. */
713 if (CHECK_FLAG(lsa
->flags
, OSPF_LSA_LOCAL_XLT
)) /* Translated from 7 */
714 if (IS_DEBUG_OSPF_NSSA
)
715 zlog_debug("Flood/AS: NSSA TRANSLATED LSA");
717 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
718 int continue_flag
= 0;
719 struct listnode
*if_node
;
720 struct ospf_interface
*oi
;
722 switch (area
->external_routing
) {
723 /* Don't send AS externals into stub areas. Various types
724 of support for partial stub areas can be implemented
725 here. NSSA's will receive Type-7's that have areas
726 matching the originl LSA. */
727 case OSPF_AREA_NSSA
: /* Sending Type 5 or 7 into NSSA area */
728 /* Type-7, flood NSSA area */
729 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
730 && area
== lsa
->area
)
731 /* We will send it. */
734 continue_flag
= 1; /* Skip this NSSA area for
738 case OSPF_AREA_TYPE_MAX
:
740 continue_flag
= 1; /* Skip this area. */
743 case OSPF_AREA_DEFAULT
:
745 /* No Type-7 into normal area */
746 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
747 continue_flag
= 1; /* skip Type-7 */
749 continue_flag
= 0; /* Do this area. */
753 /* Do continue for above switch. Saves a big if then mess */
755 continue; /* main for-loop */
757 /* send to every interface in this area */
759 for (ALL_LIST_ELEMENTS_RO(area
->oiflist
, if_node
, oi
)) {
760 /* Skip virtual links */
761 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
762 if (ospf_flood_through_interface(oi
, inbr
,
766 } /* main area for-loop */
768 return (lsa_ack_flag
);
771 int ospf_flood_through(struct ospf
*ospf
, struct ospf_neighbor
*inbr
,
772 struct ospf_lsa
*lsa
)
774 int lsa_ack_flag
= 0;
776 /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
777 upon return are updated in the LSDB for Type-7's. Later,
778 re-fresh will re-send them (and also, if ABR, packet code will
779 translate to Type-5's)
781 As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
782 NSSA) are flooded throughout the AS, and are updated in the
785 * At the common sub-sub-function "ospf_flood_through_interface()",
786 * a parameter "inbr" will be used to distinguish the called context
787 * whether the given LSA was received from the neighbor, or the
788 * flooding for the LSA starts from this node (e.g. the LSA was self-
789 * originated, or the LSA is going to be flushed from routing domain).
791 * So, for consistency reasons, this function "ospf_flood_through()"
792 * should also allow the usage that the given "inbr" parameter to be
793 * NULL. If we do so, corresponding AREA parameter should be referred
794 * by "lsa->area", instead of "inbr->oi->area".
796 switch (lsa
->data
->type
) {
797 case OSPF_AS_EXTERNAL_LSA
: /* Type-5 */
798 case OSPF_OPAQUE_AS_LSA
:
799 lsa_ack_flag
= ospf_flood_through_as(ospf
, inbr
, lsa
);
801 /* Type-7 Only received within NSSA, then flooded */
802 case OSPF_AS_NSSA_LSA
:
803 /* Any P-bit was installed with the Type-7. */
805 if (IS_DEBUG_OSPF_NSSA
)
807 "ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
810 lsa_ack_flag
= ospf_flood_through_area(lsa
->area
, inbr
, lsa
);
814 return (lsa_ack_flag
);
818 /* Management functions for neighbor's Link State Request list. */
819 void ospf_ls_request_add(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
822 * We cannot make use of the newly introduced callback function
823 * "lsdb->new_lsa_hook" to replace debug output below, just because
824 * it seems no simple and smart way to pass neighbor information to
825 * the common function "ospf_lsdb_add()" -- endo.
827 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
828 zlog_debug("RqstL(%lu)++, NBR(%pI4(%s)), LSA[%s]",
829 ospf_ls_request_count(nbr
),
831 ospf_get_name(nbr
->oi
->ospf
), dump_lsa_key(lsa
));
833 ospf_lsdb_add(&nbr
->ls_req
, lsa
);
836 unsigned long ospf_ls_request_count(struct ospf_neighbor
*nbr
)
838 return ospf_lsdb_count_all(&nbr
->ls_req
);
841 int ospf_ls_request_isempty(struct ospf_neighbor
*nbr
)
843 return ospf_lsdb_isempty(&nbr
->ls_req
);
846 /* Remove LSA from neighbor's ls-request list. */
847 void ospf_ls_request_delete(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
849 if (nbr
->ls_req_last
== lsa
) {
850 ospf_lsa_unlock(&nbr
->ls_req_last
);
851 nbr
->ls_req_last
= NULL
;
854 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
)) /* -- endo. */
855 zlog_debug("RqstL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
856 ospf_ls_request_count(nbr
),
858 ospf_get_name(nbr
->oi
->ospf
), dump_lsa_key(lsa
));
860 ospf_lsdb_delete(&nbr
->ls_req
, lsa
);
863 /* Remove all LSA from neighbor's ls-requenst list. */
864 void ospf_ls_request_delete_all(struct ospf_neighbor
*nbr
)
866 ospf_lsa_unlock(&nbr
->ls_req_last
);
867 nbr
->ls_req_last
= NULL
;
868 ospf_lsdb_delete_all(&nbr
->ls_req
);
871 /* Lookup LSA from neighbor's ls-request list. */
872 struct ospf_lsa
*ospf_ls_request_lookup(struct ospf_neighbor
*nbr
,
873 struct ospf_lsa
*lsa
)
875 return ospf_lsdb_lookup(&nbr
->ls_req
, lsa
);
878 struct ospf_lsa
*ospf_ls_request_new(struct lsa_header
*lsah
)
880 struct ospf_lsa
*new;
882 new = ospf_lsa_new_and_data(OSPF_LSA_HEADER_SIZE
);
883 memcpy(new->data
, lsah
, OSPF_LSA_HEADER_SIZE
);
889 /* Management functions for neighbor's ls-retransmit list. */
890 unsigned long ospf_ls_retransmit_count(struct ospf_neighbor
*nbr
)
892 return ospf_lsdb_count_all(&nbr
->ls_rxmt
);
895 unsigned long ospf_ls_retransmit_count_self(struct ospf_neighbor
*nbr
,
898 return ospf_lsdb_count_self(&nbr
->ls_rxmt
, lsa_type
);
901 int ospf_ls_retransmit_isempty(struct ospf_neighbor
*nbr
)
903 return ospf_lsdb_isempty(&nbr
->ls_rxmt
);
906 /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
907 void ospf_ls_retransmit_add(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
909 struct ospf_lsa
*old
;
911 old
= ospf_ls_retransmit_lookup(nbr
, lsa
);
913 if (ospf_lsa_more_recent(old
, lsa
) < 0) {
915 old
->retransmit_counter
--;
916 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
917 zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
918 ospf_ls_retransmit_count(nbr
),
920 ospf_get_name(nbr
->oi
->ospf
),
922 ospf_lsdb_delete(&nbr
->ls_rxmt
, old
);
924 lsa
->retransmit_counter
++;
926 * We cannot make use of the newly introduced callback function
927 * "lsdb->new_lsa_hook" to replace debug output below, just
929 * it seems no simple and smart way to pass neighbor information
931 * the common function "ospf_lsdb_add()" -- endo.
933 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
))
934 zlog_debug("RXmtL(%lu)++, NBR(%pI4(%s)), LSA[%s]",
935 ospf_ls_retransmit_count(nbr
),
937 ospf_get_name(nbr
->oi
->ospf
),
939 ospf_lsdb_add(&nbr
->ls_rxmt
, lsa
);
943 /* Remove LSA from neibghbor's ls-retransmit list. */
944 void ospf_ls_retransmit_delete(struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
946 if (ospf_ls_retransmit_lookup(nbr
, lsa
)) {
947 lsa
->retransmit_counter
--;
948 if (IS_DEBUG_OSPF(lsa
, LSA_FLOODING
)) /* -- endo. */
949 zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
950 ospf_ls_retransmit_count(nbr
),
952 ospf_get_name(nbr
->oi
->ospf
),
954 ospf_lsdb_delete(&nbr
->ls_rxmt
, lsa
);
958 /* Clear neighbor's ls-retransmit list. */
959 void ospf_ls_retransmit_clear(struct ospf_neighbor
*nbr
)
961 struct ospf_lsdb
*lsdb
;
964 lsdb
= &nbr
->ls_rxmt
;
966 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++) {
967 struct route_table
*table
= lsdb
->type
[i
].db
;
968 struct route_node
*rn
;
969 struct ospf_lsa
*lsa
;
971 for (rn
= route_top(table
); rn
; rn
= route_next(rn
))
972 if ((lsa
= rn
->info
) != NULL
)
973 ospf_ls_retransmit_delete(nbr
, lsa
);
976 ospf_lsa_unlock(&nbr
->ls_req_last
);
977 nbr
->ls_req_last
= NULL
;
980 /* Lookup LSA from neighbor's ls-retransmit list. */
981 struct ospf_lsa
*ospf_ls_retransmit_lookup(struct ospf_neighbor
*nbr
,
982 struct ospf_lsa
*lsa
)
984 return ospf_lsdb_lookup(&nbr
->ls_rxmt
, lsa
);
987 static void ospf_ls_retransmit_delete_nbr_if(struct ospf_interface
*oi
,
988 struct ospf_lsa
*lsa
)
990 struct route_node
*rn
;
991 struct ospf_neighbor
*nbr
;
992 struct ospf_lsa
*lsr
;
994 if (ospf_if_is_enable(oi
))
995 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
996 /* If LSA find in LS-retransmit list, then remove it. */
997 if ((nbr
= rn
->info
) != NULL
) {
998 lsr
= ospf_ls_retransmit_lookup(nbr
, lsa
);
1000 /* If LSA find in ls-retransmit list, remove it.
1003 && lsr
->data
->ls_seqnum
1004 == lsa
->data
->ls_seqnum
)
1005 ospf_ls_retransmit_delete(nbr
, lsr
);
1009 void ospf_ls_retransmit_delete_nbr_area(struct ospf_area
*area
,
1010 struct ospf_lsa
*lsa
)
1012 struct listnode
*node
, *nnode
;
1013 struct ospf_interface
*oi
;
1015 for (ALL_LIST_ELEMENTS(area
->oiflist
, node
, nnode
, oi
))
1016 ospf_ls_retransmit_delete_nbr_if(oi
, lsa
);
1019 void ospf_ls_retransmit_delete_nbr_as(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1021 struct listnode
*node
, *nnode
;
1022 struct ospf_interface
*oi
;
1024 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
1025 ospf_ls_retransmit_delete_nbr_if(oi
, lsa
);
1029 /* Sets ls_age to MaxAge and floods throu the area.
1030 When we implement ASE routing, there will be another function
1031 flushing an LSA from the whole domain. */
1032 void ospf_lsa_flush_area(struct ospf_lsa
*lsa
, struct ospf_area
*area
)
1034 struct ospf
*ospf
= area
->ospf
;
1036 if (ospf_lsa_is_self_originated(ospf
, lsa
)
1037 && ospf
->gr_info
.restart_in_progress
) {
1038 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1040 "%s:LSA[Type%d:%pI4]: Graceful Restart in progress -- not flushing self-originated LSA",
1041 ospf_get_name(ospf
), lsa
->data
->type
,
1046 /* Reset the lsa origination time such that it gives
1047 more time for the ACK to be received and avoid
1049 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1050 if (IS_DEBUG_OSPF_EVENT
)
1051 zlog_debug("%s: MaxAge set to LSA[%s]", __func__
,
1053 monotime(&lsa
->tv_recv
);
1054 lsa
->tv_orig
= lsa
->tv_recv
;
1055 ospf_flood_through_area(area
, NULL
, lsa
);
1056 ospf_lsa_maxage(ospf
, lsa
);
1059 void ospf_lsa_flush_as(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1061 if (ospf_lsa_is_self_originated(ospf
, lsa
)
1062 && ospf
->gr_info
.restart_in_progress
) {
1063 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1065 "%s:LSA[Type%d:%pI4]: Graceful Restart in progress -- not flushing self-originated LSA",
1066 ospf_get_name(ospf
), lsa
->data
->type
,
1071 /* Reset the lsa origination time such that it gives
1072 more time for the ACK to be received and avoid
1074 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1075 if (IS_DEBUG_OSPF_EVENT
)
1076 zlog_debug("%s: MaxAge set to LSA[%s]", __func__
,
1078 monotime(&lsa
->tv_recv
);
1079 lsa
->tv_orig
= lsa
->tv_recv
;
1080 ospf_flood_through_as(ospf
, NULL
, lsa
);
1081 ospf_lsa_maxage(ospf
, lsa
);
1084 void ospf_lsa_flush(struct ospf
*ospf
, struct ospf_lsa
*lsa
)
1086 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1088 switch (lsa
->data
->type
) {
1089 case OSPF_ROUTER_LSA
:
1090 case OSPF_NETWORK_LSA
:
1091 case OSPF_SUMMARY_LSA
:
1092 case OSPF_ASBR_SUMMARY_LSA
:
1093 case OSPF_AS_NSSA_LSA
:
1094 case OSPF_OPAQUE_LINK_LSA
:
1095 case OSPF_OPAQUE_AREA_LSA
:
1096 ospf_lsa_flush_area(lsa
, lsa
->area
);
1098 case OSPF_AS_EXTERNAL_LSA
:
1099 case OSPF_OPAQUE_AS_LSA
:
1100 ospf_lsa_flush_as(ospf
, lsa
);
1103 zlog_info("%s: Unknown LSA type %u", __func__
, lsa
->data
->type
);